relayd: replace lttng_index_file with relay_index_file
[lttng-tools.git] / src / bin / lttng-relayd / stream.h
CommitLineData
7591bab1
MD
1#ifndef _STREAM_H
2#define _STREAM_H
3
2a174661
DG
4/*
5 * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
6 * David Goulet <dgoulet@efficios.com>
7591bab1 7 * 2015 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
2a174661
DG
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License, version 2 only, as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * this program; if not, write to the Free Software Foundation, Inc., 51
20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
2a174661
DG
23#include <limits.h>
24#include <inttypes.h>
25#include <pthread.h>
26#include <urcu/list.h>
27
28#include <common/hashtable/hashtable.h>
29
30#include "session.h"
7591bab1 31#include "stream-fd.h"
a44ca2ca 32#include "tracefile-array.h"
2b508613 33#include "index-file.h"
2a174661 34
81164b6b
JG
35struct relay_stream_chunk_id {
36 bool is_set;
37 uint64_t value;
38};
39
2a174661
DG
40/*
41 * Represents a stream in the relay
42 */
43struct relay_stream {
44 uint64_t stream_handle;
7591bab1 45
7591bab1
MD
46 struct urcu_ref ref;
47 /* Back reference to trace. Protected by refcount on trace object. */
48 struct ctf_trace *trace;
2a174661 49
7591bab1
MD
50 /*
51 * To protect from concurrent read/update. The viewer stream
52 * lock nests inside the stream lock. The stream lock nests
53 * inside the ctf_trace lock.
54 */
55 pthread_mutex_t lock;
56 uint64_t prev_seq; /* previous data sequence number encountered. */
57 uint64_t last_net_seq_num; /* seq num to encounter before closing. */
58
59 /* FD on which to write the stream data. */
60 struct stream_fd *stream_fd;
f8f3885c 61 /* index file on which to write the index data. */
2b508613 62 struct relay_index_file *index_file;
2a174661
DG
63
64 char *path_name;
65 char *channel_name;
7591bab1
MD
66
67 /* On-disk circular buffer of tracefiles. */
2a174661
DG
68 uint64_t tracefile_size;
69 uint64_t tracefile_size_current;
70 uint64_t tracefile_count;
7591bab1 71
d3ecc550
JD
72 /*
73 * Position in the tracefile where we have the full index also on disk.
74 */
75 uint64_t pos_after_last_complete_data_index;
76
a44ca2ca
MD
77 /*
78 * Counts the number of received indexes. The "tag" associated
79 * with an index is taken before incrementing this seqcount.
80 * Therefore, the sequence tag associated with the last index
81 * received is always index_received_seqcount - 1.
82 */
83 uint64_t index_received_seqcount;
2a174661 84
a44ca2ca
MD
85 /*
86 * Tracefile array is an index of the stream trace files,
87 * indexed by position. It allows keeping track of the oldest
88 * available indexes when overwriting trace files in tracefile
89 * rotation.
90 */
91 struct tracefile_array *tfa;
2a174661 92
bda7c7b9
JG
93 bool closed; /* Stream is closed. */
94 bool close_requested; /* Close command has been received. */
2a174661
DG
95
96 /*
7591bab1
MD
97 * Counts number of indexes in indexes_ht. Redundant info.
98 * Protected by stream lock.
6e7241fe
JD
99 */
100 int indexes_in_flight;
7591bab1
MD
101 struct lttng_ht *indexes_ht;
102
528f2ffa 103 /*
7591bab1
MD
104 * If the stream is inactive, this field is updated with the
105 * live beacon timestamp end, when it is active, this
106 * field == -1ULL.
528f2ffa 107 */
7591bab1
MD
108 uint64_t beacon_ts_end;
109
110 /* CTF stream ID, -1ULL when unset (first packet not received yet). */
528f2ffa 111 uint64_t ctf_stream_id;
2a174661 112
7591bab1
MD
113 /* Indicate if the stream was initialized for a data pending command. */
114 bool data_pending_check_done;
115
116 /* Is this stream a metadata stream ? */
117 int32_t is_metadata;
118 /* Amount of metadata received (bytes). */
119 uint64_t metadata_received;
120
2a174661 121 /*
7591bab1
MD
122 * Member of the stream list in struct ctf_trace.
123 * Updates are protected by the stream_list_lock.
124 * Traversals are protected by RCU.
2a174661 125 */
7591bab1 126 struct cds_list_head stream_node;
2a174661 127 /*
7591bab1
MD
128 * Temporary list belonging to the connection until all streams
129 * are received for that connection.
130 * Member of the stream recv list in the connection.
131 * Updates are protected by the stream_recv_list_lock.
132 * Traversals are protected by RCU.
2a174661 133 */
7591bab1
MD
134 bool in_recv_list;
135 struct cds_list_head recv_node;
136 bool published; /* Protected by session lock. */
2a174661 137 /*
7591bab1 138 * Node of stream within global stream hash table.
2a174661 139 */
7591bab1 140 struct lttng_ht_node_u64 node;
77f7bd85 141 bool in_stream_ht; /* is stream in stream hash table. */
7591bab1 142 struct rcu_head rcu_node; /* For call_rcu teardown. */
d3ecc550
JD
143 /*
144 * When we have written the data and index corresponding to this
145 * seq_num, rotate the tracefile (session rotation). The path_name is
146 * already up-to-date.
147 * This is set to -1ULL when no rotation is pending.
148 *
149 * Always access with stream lock held.
150 */
151 uint64_t rotate_at_seq_num;
152 /*
153 * This is the id of the chunk where we are writing to if no rotation is
154 * pending (rotate_at_seq_num == -1ULL). If a rotation is pending, this
155 * is the chunk_id we will have after the rotation. It must be updated
156 * atomically with rotate_at_seq_num.
157 *
158 * Always access with stream lock held.
81164b6b
JG
159 *
160 * This attribute is not set if the stream is created by a pre-2.11
161 * consumer.
d3ecc550 162 */
81164b6b 163 struct relay_stream_chunk_id current_chunk_id;
2a174661
DG
164};
165
7591bab1
MD
166struct relay_stream *stream_create(struct ctf_trace *trace,
167 uint64_t stream_handle, char *path_name,
168 char *channel_name, uint64_t tracefile_size,
81164b6b 169 uint64_t tracefile_count, const struct relay_stream_chunk_id *chunk_id);
7591bab1
MD
170
171struct relay_stream *stream_get_by_id(uint64_t stream_id);
172bool stream_get(struct relay_stream *stream);
173void stream_put(struct relay_stream *stream);
bda7c7b9 174void try_stream_close(struct relay_stream *stream);
7591bab1
MD
175void stream_publish(struct relay_stream *stream);
176void print_relay_streams(void);
2a174661
DG
177
178#endif /* _STREAM_H */
This page took 0.052845 seconds and 5 git commands to generate.