/* Track the number of active stream iterator. */
stream_iter->trace->session->lttng_live_msg_iter->active_stream_iter--;
- /*
- * Ensure we poke the trace metadata in the future, which is
- * required to release the metadata reference on the trace.
- */
- stream_iter->trace->new_metadata_needed = true;
g_free(stream_iter);
}
trace->stream_iterators = g_ptr_array_new_with_free_func(
(GDestroyNotify) lttng_live_stream_iterator_destroy);
BT_ASSERT(trace->stream_iterators);
- trace->new_metadata_needed = true;
+ trace->metadata_stream_state = LTTNG_LIVE_METADATA_STREAM_STATE_NEEDED;
g_ptr_array_add(session->traces, trace);
goto end;
enum lttng_live_stream_state orig_state = lttng_live_stream->state;
struct packet_index index;
- if (lttng_live_stream->trace->new_metadata_needed) {
+ if (lttng_live_stream->trace->metadata_stream_state ==
+ LTTNG_LIVE_METADATA_STREAM_STATE_NEEDED) {
ret = LTTNG_LIVE_ITERATOR_STATUS_CONTINUE;
goto end;
}
trace_idx++) {
struct lttng_live_trace *trace =
g_ptr_array_index(session->traces, trace_idx);
- trace->new_metadata_needed = true;
+
+ BT_ASSERT(trace->metadata_stream_state !=
+ LTTNG_LIVE_METADATA_STREAM_STATE_CLOSED);
+
+ trace->metadata_stream_state = LTTNG_LIVE_METADATA_STREAM_STATE_NEEDED;
}
}
}
trace_idx++) {
struct lttng_live_trace *trace =
g_ptr_array_index(session->traces, trace_idx);
- if (trace->new_metadata_needed) {
+ if (trace->metadata_stream_state == LTTNG_LIVE_METADATA_STREAM_STATE_NEEDED) {
ret = LTTNG_LIVE_ITERATOR_STATUS_CONTINUE;
goto end;
}
bt_logging_level log_level;
bt_self_component *self_comp;
- /* Weak reference. */
- struct lttng_live_trace *trace;
-
uint64_t stream_id;
/* Weak reference. */
struct ctf_metadata_decoder *decoder;
};
+enum lttng_live_metadata_stream_state {
+ /*
+ * The metadata needs to be updated. This is either because we just
+ * created the trace and haven't asked yet, or the relay specifically
+ * told us that new metadata is available.
+ */
+ LTTNG_LIVE_METADATA_STREAM_STATE_NEEDED,
+ /*
+ * The metadata was updated and the relay has not told us we need to
+ * update it yet.
+ */
+ LTTNG_LIVE_METADATA_STREAM_STATE_NOT_NEEDED,
+ /*
+ * The relay has closed this metadata stream. We set this in reaction
+ * to a LTTNG_VIEWER_METADATA_ERR reply to a LTTNG_VIEWER_GET_METADATA
+ * command to the relay. If this field is set, we have received all the
+ * metadata that we are ever going to get for that metadata stream.
+ */
+ LTTNG_LIVE_METADATA_STREAM_STATE_CLOSED,
+};
+
struct lttng_live_trace {
bt_logging_level log_level;
bt_self_component *self_comp;
/* Owned by this. */
GPtrArray *stream_iterators;
- bool new_metadata_needed;
+ enum lttng_live_metadata_stream_state metadata_stream_state;
};
struct lttng_live_session {
goto end;
}
- if (!metadata->trace) {
- trace->new_metadata_needed = false;
- }
-
- if (!trace->new_metadata_needed) {
+ if (trace->metadata_stream_state != LTTNG_LIVE_METADATA_STREAM_STATE_NEEDED) {
goto end;
}
BT_COMP_LOGD("Metadata stream was closed by the Relay, the trace is no longer active: "
"trace-id=%"PRIu64", metadata-stream-id=%"PRIu64,
trace->id, metadata->stream_id);
+ /*
+ * The stream was closed and we received everything
+ * there was to receive for this metadata stream.
+ * We go on with the decoding of what we received. So
+ * that data stream can be decoded.
+ */
keep_receiving = false;
+ trace->metadata_stream_state = LTTNG_LIVE_METADATA_STREAM_STATE_CLOSED;
break;
case LTTNG_LIVE_GET_ONE_METADATA_STATUS_ERROR:
BT_COMP_LOGE_APPEND_CAUSE(self_comp,
}
}
- /*
- * A closed metadata stream means the trace is no longer active. Return
- * _END so that the caller can remove the trace from its list.
- */
- if (metadata_status == LTTNG_LIVE_GET_ONE_METADATA_STATUS_CLOSED) {
- status = LTTNG_LIVE_ITERATOR_STATUS_END;
- goto end;
- }
-
/* The memory buffer `metadata_buf` contains all the metadata. */
if (bt_close_memstream(&metadata_buf, &size, fp)) {
BT_COMP_LOGW_ERRNO("Metadata bt_close_memstream", ".");
status = LTTNG_LIVE_ITERATOR_STATUS_AGAIN;
goto end;
}
- trace->new_metadata_needed = false;
+
+ /* The relay sent zero bytes of metdata. */
+ trace->metadata_stream_state = LTTNG_LIVE_METADATA_STREAM_STATE_NOT_NEEDED;
goto end;
}
trace->clock_class =
borrow_any_clock_class(trace->trace_class);
}
- trace->new_metadata_needed = false;
+
+ /* The metadata was updated succesfully. */
+ trace->metadata_stream_state = LTTNG_LIVE_METADATA_STREAM_STATE_NOT_NEEDED;
break;
case CTF_METADATA_DECODER_STATUS_INCOMPLETE:
"Failed to borrow trace");
goto error;
}
- metadata->trace = trace;
trace->metadata = metadata;
return 0;
if (flags & LTTNG_VIEWER_FLAG_NEW_METADATA) {
BT_COMP_LOGD("Received get_next_index response: new metadata needed");
- trace->new_metadata_needed = true;
+ trace->metadata_stream_state = LTTNG_LIVE_METADATA_STREAM_STATE_NEEDED;
}
if (flags & LTTNG_VIEWER_FLAG_NEW_STREAM) {
BT_COMP_LOGD("Received get_next_index response: new streams needed");
case LTTNG_VIEWER_GET_PACKET_ERR:
if (flags & LTTNG_VIEWER_FLAG_NEW_METADATA) {
BT_COMP_LOGD("get_data_packet: new metadata needed, try again later");
- trace->new_metadata_needed = true;
+ trace->metadata_stream_state = LTTNG_LIVE_METADATA_STREAM_STATE_NEEDED;
}
if (flags & LTTNG_VIEWER_FLAG_NEW_STREAM) {
BT_COMP_LOGD("get_data_packet: new streams needed, try again later");