X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-relayd%2Findex.h;h=e882ed97d2552b71225fee0517698fcdf0143475;hp=e7f9cdbd07d98ebafacc1dfb122fb525e18778f3;hb=7591bab11eceedc6a0d1e02fd6f85592267a63b5;hpb=d77dded285b058e4242c8a3d2233f80e725ceefc diff --git a/src/bin/lttng-relayd/index.h b/src/bin/lttng-relayd/index.h index e7f9cdbd0..e882ed97d 100644 --- a/src/bin/lttng-relayd/index.h +++ b/src/bin/lttng-relayd/index.h @@ -1,6 +1,10 @@ +#ifndef _RELAY_INDEX_H +#define _RELAY_INDEX_H + /* * Copyright (C) 2013 - Julien Desfossez * David Goulet + * 2015 - Mathieu Desnoyers * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License, version 2 only, as @@ -16,42 +20,56 @@ * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef _RELAY_INDEX_H -#define _RELAY_INDEX_H - #include #include #include #include +#include "stream-fd.h" + +struct relay_stream; + struct relay_index { - /* FD on which to write the index data. */ - int fd; /* - * When destroying this object, this fd is checked and if valid, close it - * so this is basically a lazy close of the previous fd corresponding to - * the same stream id. This is used for the rotate file feature. + * index lock nests inside stream lock. */ - int to_close_fd; + pthread_mutex_t reflock; /* Protects refcounting. */ + struct urcu_ref ref; /* Reference from getters. */ + struct relay_stream *stream; /* Back ref to stream */ + + pthread_mutex_t lock; + /* + * FD on which to write the index data. May differ from + * stream->index_fd due to tracefile rotation. + */ + struct stream_fd *index_fd; /* Index packet data. This is the data that is written on disk. */ struct ctf_packet_index index_data; - /* key1 = stream_id, key2 = net_seq_num */ - struct lttng_ht_node_two_u64 index_n; - struct rcu_head rcu_node; - pthread_mutex_t mutex; + bool has_index_data; + bool flushed; + bool in_hash_table; + + /* + * Node within indexes_ht that corresponds to this struct + * relay_index. Indexed by net_seq_num, which is unique for this + * index across the stream. + */ + struct lttng_ht_node_u64 index_n; + struct rcu_head rcu_node; /* For call_rcu teardown. */ }; -struct relay_index *relay_index_create(uint64_t stream_id, +struct relay_index *relay_index_get_by_id_or_create(struct relay_stream *stream, uint64_t net_seq_num); -struct relay_index *relay_index_find(uint64_t stream_id, uint64_t net_seq_num); -void relay_index_add(struct relay_index *index, struct relay_index **_index); -int relay_index_write(int fd, struct relay_index *index); -void relay_index_free(struct relay_index *index); -void relay_index_free_safe(struct relay_index *index); -void relay_index_delete(struct relay_index *index); -void relay_index_destroy_by_stream_id(uint64_t stream_id); +void relay_index_put(struct relay_index *index); +int relay_index_set_fd(struct relay_index *index, struct stream_fd *index_fd, + uint64_t data_offset); +int relay_index_set_data(struct relay_index *index, + const struct ctf_packet_index *data); +int relay_index_try_flush(struct relay_index *index); + +void relay_index_close_all(struct relay_stream *stream); #endif /* _RELAY_INDEX_H */