Maintain a channel-per-session_id hash table in the consumers
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 21 May 2019 23:44:30 +0000 (19:44 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 18 Jul 2019 19:58:24 +0000 (15:58 -0400)
Add and maintain an hash table indexed by `session_id` that allows the
consumer daemons to perform actions on a set of channels belonging to
a given session.

This hash table holds no ownership of the channels; it is merely an
"index" to the existing set of channels maintained in the channel_ht.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/common/consumer/consumer.c
src/common/consumer/consumer.h

index c70d95a58bfc91a3a053c1d160be6ec1f8a0bba6..9d25d83a341e2c853026f2fb6a4b4a25b10bd2dc 100644 (file)
@@ -393,6 +393,10 @@ void consumer_del_channel(struct lttng_consumer_channel *channel)
        iter.iter.node = &channel->node.node;
        ret = lttng_ht_del(consumer_data.channel_ht, &iter);
        assert(!ret);
+
+       iter.iter.node = &channel->channels_by_session_id_ht_node.node;
+       ret = lttng_ht_del(consumer_data.channels_by_session_id_ht, &iter);
+       assert(!ret);
        rcu_read_unlock();
 
        call_rcu(&channel->node.head, free_channel_rcu);
@@ -1035,6 +1039,8 @@ struct lttng_consumer_channel *consumer_allocate_channel(uint64_t key,
        }
 
        lttng_ht_node_init_u64(&channel->node, channel->key);
+       lttng_ht_node_init_u64(&channel->channels_by_session_id_ht_node,
+                       channel->session_id);
 
        channel->wait_fd = -1;
 
@@ -1067,6 +1073,8 @@ int consumer_add_channel(struct lttng_consumer_channel *channel,
 
        rcu_read_lock();
        lttng_ht_add_unique_u64(consumer_data.channel_ht, &channel->node);
+       lttng_ht_add_u64(consumer_data.channels_by_session_id_ht,
+                       &channel->channels_by_session_id_ht_node);
        rcu_read_unlock();
 
        pthread_mutex_unlock(&channel->timer_lock);
@@ -1225,6 +1233,7 @@ void lttng_consumer_cleanup(void)
        rcu_read_unlock();
 
        lttng_ht_destroy(consumer_data.channel_ht);
+       lttng_ht_destroy(consumer_data.channels_by_session_id_ht);
 
        cleanup_relayd_ht();
 
@@ -3423,6 +3432,12 @@ int lttng_consumer_init(void)
                goto error;
        }
 
+       consumer_data.channels_by_session_id_ht =
+                       lttng_ht_new(0, LTTNG_HT_TYPE_U64);
+       if (!consumer_data.channels_by_session_id_ht) {
+               goto error;
+       }
+
        consumer_data.relayd_ht = lttng_ht_new(0, LTTNG_HT_TYPE_U64);
        if (!consumer_data.relayd_ht) {
                goto error;
index b940036f6f074ed60cbfeac3daa6f29c1a85095e..1c1d01de911fee38edcbb3c9c089b0f5a7b11e8c 100644 (file)
@@ -112,6 +112,8 @@ struct consumer_metadata_cache;
 struct lttng_consumer_channel {
        /* HT node used for consumer_data.channel_ht */
        struct lttng_ht_node_u64 node;
+       /* HT node used for consumer_data.channels_by_session_id_ht */
+       struct lttng_ht_node_u64 channels_by_session_id_ht_node;
        /* Indexed key. Incremented value in the consumer. */
        uint64_t key;
        /* Number of streams referencing this channel */
@@ -621,6 +623,8 @@ struct lttng_consumer_global_data {
 
        /* Channel hash table protected by consumer_data.lock. */
        struct lttng_ht *channel_ht;
+       /* Channel hash table indexed by session id. */
+       struct lttng_ht *channels_by_session_id_ht;
        /*
         * Flag specifying if the local array of FDs needs update in the
         * poll function. Protected by consumer_data.lock.
This page took 0.028823 seconds and 4 git commands to generate.