Fix end condition on rotate with live reading
authorJulien Desfossez <jdesfossez@efficios.com>
Fri, 15 Nov 2013 02:30:26 +0000 (21:30 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Fri, 15 Nov 2013 15:16:44 +0000 (10:16 -0500)
We need to know what is the last tracefile to read on live with
tracefile_count.

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
src/bin/lttng-relayd/live.c
src/bin/lttng-relayd/lttng-relayd.h
src/bin/lttng-relayd/main.c

index a2fd09e32812fc322ac9299fa16f558ad39637ad..851be9f8e3165c85eb4bcf69bfbeb3d29508dade 100644 (file)
@@ -698,6 +698,7 @@ int init_viewer_stream(struct relay_stream *stream, int seek_last)
                        LTTNG_VIEWER_NAME_MAX);
        viewer_stream->tracefile_count = stream->tracefile_count;
        viewer_stream->metadata_flag = stream->metadata_flag;
+       viewer_stream->tracefile_count_last = -1ULL;
        if (seek_last) {
                viewer_stream->tracefile_count_current =
                        stream->tracefile_count_current;
@@ -764,7 +765,7 @@ error:
 /*
  * Rotate a stream to the next tracefile.
  *
- * Returns 0 on success, a negative value on error.
+ * Returns 0 on success, 1 on EOF, a negative value on error.
  */
 static
 int rotate_viewer_stream(struct relay_viewer_stream *viewer_stream,
@@ -777,6 +778,15 @@ int rotate_viewer_stream(struct relay_viewer_stream *viewer_stream,
 
        tracefile_id = (viewer_stream->tracefile_count_current + 1) %
                viewer_stream->tracefile_count;
+       /*
+        * Detect the last tracefile to open.
+        */
+       if (viewer_stream->tracefile_count_last != -1ULL &&
+                       viewer_stream->tracefile_count_last ==
+                       viewer_stream->tracefile_count_current) {
+               ret = 1;
+               goto end;
+       }
 
        if (stream) {
                pthread_mutex_lock(&stream->viewer_stream_rotation_lock);
@@ -832,6 +842,7 @@ int rotate_viewer_stream(struct relay_viewer_stream *viewer_stream,
 
        ret = 0;
 
+end:
 error:
        return ret;
 }
@@ -1130,6 +1141,9 @@ int viewer_get_next_index(struct relay_command *cmd,
                        ret = rotate_viewer_stream(vstream, rstream);
                        if (ret < 0) {
                                goto end_unlock;
+                       } else if (ret == 1) {
+                               viewer_index.status = htobe32(VIEWER_INDEX_HUP);
+                               goto send_reply;
                        }
                }
                pthread_mutex_lock(&rstream->viewer_stream_rotation_lock);
@@ -1180,6 +1194,9 @@ int viewer_get_next_index(struct relay_command *cmd,
                ret = rotate_viewer_stream(vstream, rstream);
                if (ret < 0) {
                        goto end_unlock;
+               } else if (ret == 1) {
+                       viewer_index.status = htobe32(VIEWER_INDEX_HUP);
+                       goto send_reply;
                }
                goto send_reply;
        }
@@ -1196,6 +1213,9 @@ int viewer_get_next_index(struct relay_command *cmd,
                        ret = rotate_viewer_stream(vstream, rstream);
                        if (ret < 0) {
                                goto end_unlock;
+                       } else if (ret == 1) {
+                               viewer_index.status = htobe32(VIEWER_INDEX_HUP);
+                               goto send_reply;
                        }
                } else {
                        PERROR("Relay reading index file %d",
index c17a67ea806a6c36f069f85801927e0c1721ca45..f22b115c9d037e78c0737b10f2f7861e9efeb21e 100644 (file)
@@ -163,6 +163,8 @@ struct relay_viewer_stream {
        uint64_t total_index_received;
        uint64_t tracefile_count;
        uint64_t tracefile_count_current;
+       /* Stop after reading this tracefile. */
+       uint64_t tracefile_count_last;
        struct lttng_ht_node_u64 stream_n;
        struct rcu_head rcu_node;
        struct ctf_trace *ctf_trace;
index 70a1948c328cc690e39e4add4d67f4a2a8f2fe44..b8e2f72e6706bc194be2d095ddca89f65abb0dca 100644 (file)
@@ -851,6 +851,7 @@ static void destroy_stream(struct relay_stream *stream)
                 */
                pthread_mutex_lock(&stream->viewer_stream_rotation_lock);
                vstream->total_index_received = stream->total_index_received;
+               vstream->tracefile_count_last = stream->tracefile_count_current;
                vstream->close_write_flag = 1;
                pthread_mutex_unlock(&stream->viewer_stream_rotation_lock);
        }
This page took 0.040095 seconds and 4 git commands to generate.