Fix: Make sure we have all the metadata streams before adding new traces
authorJulien Desfossez <jdesfossez@efficios.com>
Thu, 23 Nov 2017 23:00:14 +0000 (18:00 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 30 Jan 2018 21:53:35 +0000 (16:53 -0500)
The add_one_trace function needs to have a metadata stream for all the
known traces. If it does not, we could end up in situations where we
fetch new streams while adding a trace which causes a lot of problems.

Now we ensure we have all the metadata streams before adding the traces.

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Acked-by: Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
Tested-by: Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
formats/lttng-live/lttng-live-comm.c

index 0e51c0c2ab5b1f2ab8519bb94e67e7305199e5b8..b61371fc5dba65523eb46f5f1e69b391d2103990 100644 (file)
@@ -1572,6 +1572,56 @@ end:
        return ret;
 }
 
+/*
+ * Make sure all the traces we know have a metadata stream or loop on
+ * ask_new_streams until it is done. This must be called before we call
+ * add_one_trace.
+ *
+ * Return 0 when all known traces have a metadata stream, a negative value
+ * on error.
+ */
+static
+int check_traces_metadata(struct lttng_live_ctx *ctx)
+{
+       int ret;
+       struct lttng_live_ctf_trace *trace;
+       GHashTableIter it;
+       gpointer key;
+       gpointer value;
+
+retry:
+       g_hash_table_iter_init(&it, ctx->session->ctf_traces);
+       while (g_hash_table_iter_next(&it, &key, &value)) {
+               trace = (struct lttng_live_ctf_trace *) value;
+               printf_verbose("Check trace %" PRIu64 " metadata\n", trace->ctf_trace_id);
+               while (!trace->metadata_stream) {
+                       printf_verbose("Waiting for metadata stream\n");
+                       if (lttng_live_should_quit()) {
+                               ret = 0;
+                               goto end;
+                       }
+                       ret = ask_new_streams(ctx);
+                       if (ret < 0) {
+                               goto end;
+                       } else if (ret == 0) {
+                               (void) poll(NULL, 0, ACTIVE_POLL_DELAY);
+                       } else {
+                               /*
+                                * If ask_new_stream got streams from a trace we did not know
+                                * about until now, we have to reinitialize the iterator.
+                                */
+                               goto retry;
+                       }
+               }
+       }
+
+       ret = 0;
+
+end:
+       printf_verbose("End check traces metadata\n");
+       return ret;
+}
+
 static
 int add_traces(struct lttng_live_ctx *ctx)
 {
@@ -1582,6 +1632,12 @@ int add_traces(struct lttng_live_ctx *ctx)
        gpointer value;
 
        printf_verbose("Begin add traces\n");
+
+       ret = check_traces_metadata(ctx);
+       if (ret < 0) {
+               goto end;
+       }
+
        g_hash_table_iter_init(&it, ctx->session->ctf_traces);
        while (g_hash_table_iter_next(&it, &key, &value)) {
                trace = (struct lttng_live_ctf_trace *) value;
This page took 0.025688 seconds and 4 git commands to generate.