Fix: consumer: do not flush on transition from NULL chunk
[lttng-tools.git] / src / common / consumer / consumer.c
index d81d0fc7a1da1bf0f57c3a670b216f95fdc7af68..fbbe8ea8fe8907b71db0a59cc5737faad192b04a 100644 (file)
@@ -3940,15 +3940,23 @@ int consumer_flush_buffer(struct lttng_consumer_stream *stream, int producer_act
 
        switch (consumer_data.type) {
        case LTTNG_CONSUMER_KERNEL:
-               ret = kernctl_buffer_flush(stream->wait_fd);
-               if (ret < 0) {
-                       ERR("Failed to flush kernel stream");
-                       goto end;
+               if (producer_active) {
+                       ret = kernctl_buffer_flush(stream->wait_fd);
+                       if (ret < 0) {
+                               ERR("Failed to flush kernel stream");
+                               goto end;
+                       }
+               } else {
+                       ret = kernctl_buffer_flush_empty(stream->wait_fd);
+                       if (ret < 0) {
+                               ERR("Failed to flush kernel stream");
+                               goto end;
+                       }
                }
                break;
        case LTTNG_CONSUMER32_UST:
        case LTTNG_CONSUMER64_UST:
-               lttng_ustctl_flush_buffer(stream, producer_active);
+               lttng_ustconsumer_flush_buffer(stream, producer_active);
                break;
        default:
                ERR("Unknown consumer_data type");
@@ -4017,14 +4025,23 @@ int lttng_consumer_rotate_channel(struct lttng_consumer_channel *channel,
                }
 
                /*
-                * Active flush; has no effect if the production position
-                * is at a packet boundary.
+                * Do not flush an empty packet when rotating from a NULL trace
+                * chunk. The stream has no means to output data, and the prior
+                * rotation which rotated to NULL performed that side-effect already.
                 */
-               ret = consumer_flush_buffer(stream, 1);
-               if (ret < 0) {
-                       ERR("Failed to flush stream %" PRIu64 " during channel rotation",
-                                       stream->key);
-                       goto end_unlock_stream;
+               if (stream->trace_chunk) {
+                       /*
+                        * For metadata stream, do an active flush, which does not
+                        * produce empty packets. For data streams, empty-flush;
+                        * ensures we have at least one packet in each stream per trace
+                        * chunk, even if no data was produced.
+                        */
+                       ret = consumer_flush_buffer(stream, stream->metadata_flag ? 1 : 0);
+                       if (ret < 0) {
+                               ERR("Failed to flush stream %" PRIu64 " during channel rotation",
+                                               stream->key);
+                               goto end_unlock_stream;
+                       }
                }
 
                ret = lttng_consumer_take_snapshot(stream);
This page took 0.024003 seconds and 4 git commands to generate.