| 1 | #ifndef _VIEWER_STREAM_H |
| 2 | #define _VIEWER_STREAM_H |
| 3 | |
| 4 | /* |
| 5 | * Copyright (C) 2013 Julien Desfossez <jdesfossez@efficios.com> |
| 6 | * Copyright (C) 2013 David Goulet <dgoulet@efficios.com> |
| 7 | * Copyright (C) 2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 8 | * |
| 9 | * SPDX-License-Identifier: GPL-2.0-only |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include "ctf-trace.hpp" |
| 14 | #include "lttng-viewer-abi.hpp" |
| 15 | #include "stream.hpp" |
| 16 | |
| 17 | #include <common/hashtable/hashtable.hpp> |
| 18 | |
| 19 | #include <inttypes.h> |
| 20 | #include <limits.h> |
| 21 | #include <pthread.h> |
| 22 | |
| 23 | struct relay_stream; |
| 24 | |
| 25 | /* |
| 26 | * The viewer stream's lifetime is the intersection of their viewer connection's |
| 27 | * lifetime and the duration during which at least: |
| 28 | * a) their input source is still active |
| 29 | * b) they still have data left to send to the client. |
| 30 | * |
| 31 | * This means that both the sessiond/consumerd connection or the viewer |
| 32 | * connection may tear down (and unpublish) a relay_viewer_stream. |
| 33 | * |
| 34 | * Viewer stream updates are protected by their associated stream's lock. |
| 35 | */ |
| 36 | struct relay_viewer_stream { |
| 37 | struct urcu_ref ref; |
| 38 | |
| 39 | /* Back ref to stream. */ |
| 40 | struct relay_stream *stream; |
| 41 | |
| 42 | struct { |
| 43 | struct fs_handle *handle; |
| 44 | struct lttng_trace_chunk *trace_chunk; |
| 45 | } stream_file; |
| 46 | /* index file from which to read the index data. */ |
| 47 | struct lttng_index_file *index_file; |
| 48 | /* |
| 49 | * Last seen rotation count in stream. |
| 50 | * |
| 51 | * Sampled on every change to the viewer stream trace chunk, |
| 52 | * this allows the live server to determine if it saw the latest |
| 53 | * rotation that occurred on the receiving end. |
| 54 | */ |
| 55 | uint64_t last_seen_rotation_count; |
| 56 | |
| 57 | char *path_name; |
| 58 | char *channel_name; |
| 59 | |
| 60 | uint64_t current_tracefile_id; |
| 61 | |
| 62 | /* |
| 63 | * Counts the number of sent indexes. The "tag" associated |
| 64 | * with an index to send is the current index_received_seqcount, |
| 65 | * because we increment index_received_seqcount after sending |
| 66 | * each index. This index_received_seqcount counter can also be |
| 67 | * updated when catching up with the producer. |
| 68 | */ |
| 69 | uint64_t index_sent_seqcount; |
| 70 | |
| 71 | /* Indicates if this stream has been sent to a viewer client. */ |
| 72 | bool sent_flag; |
| 73 | /* For metadata stream, how much metadata has been sent. */ |
| 74 | uint64_t metadata_sent; |
| 75 | |
| 76 | struct lttng_ht_node_u64 stream_n; |
| 77 | struct rcu_head rcu_node; |
| 78 | }; |
| 79 | |
| 80 | struct relay_viewer_stream *viewer_stream_create(struct relay_stream *stream, |
| 81 | struct lttng_trace_chunk *viewer_trace_chunk, |
| 82 | enum lttng_viewer_seek seek_t); |
| 83 | |
| 84 | struct relay_viewer_stream *viewer_stream_get_by_id(uint64_t id); |
| 85 | bool viewer_stream_get(struct relay_viewer_stream *vstream); |
| 86 | void viewer_stream_put(struct relay_viewer_stream *vstream); |
| 87 | int viewer_stream_rotate(struct relay_viewer_stream *vstream); |
| 88 | bool viewer_stream_is_tracefile_seq_readable(struct relay_viewer_stream *vstream, uint64_t seq); |
| 89 | void print_viewer_streams(void); |
| 90 | void viewer_stream_close_files(struct relay_viewer_stream *vstream); |
| 91 | void viewer_stream_sync_tracefile_array_tail(struct relay_viewer_stream *vstream); |
| 92 | |
| 93 | #endif /* _VIEWER_STREAM_H */ |