* is already at the rotate position (produced == consumed), we flag it as
* ready for rotation. The rotation of ready streams occurs after we have
* replied to the session daemon that we have finished sampling the positions.
+ * Must be called with RCU read-side lock held to ensure existence of channel.
*
* Returns 0 on success, < 0 on error
*/
-int lttng_consumer_rotate_channel(uint64_t key, const char *path,
- uint64_t relayd_id, uint32_t metadata, uint64_t new_chunk_id,
+int lttng_consumer_rotate_channel(struct lttng_consumer_channel *channel,
+ uint64_t key, const char *path, uint64_t relayd_id,
+ uint32_t metadata, uint64_t new_chunk_id,
struct lttng_consumer_local_data *ctx)
{
int ret;
- struct lttng_consumer_channel *channel;
struct lttng_consumer_stream *stream;
struct lttng_ht_iter iter;
struct lttng_ht *ht = consumer_data.stream_per_chan_id_ht;
rcu_read_lock();
- channel = consumer_find_channel(key);
- if (!channel) {
- ERR("No channel found for key %" PRIu64, key);
- ret = -1;
- goto end;
- }
-
pthread_mutex_lock(&channel->lock);
channel->current_chunk_id = new_chunk_id;
* This is especially important for low throughput streams that have already
* been consumed, we cannot wait for their next packet to perform the
* rotation.
+ * Need to be called with RCU read-side lock held to ensure existence of
+ * channel.
*
* Returns 0 on success, < 0 on error
*/
-int lttng_consumer_rotate_ready_streams(uint64_t key,
- struct lttng_consumer_local_data *ctx)
+int lttng_consumer_rotate_ready_streams(struct lttng_consumer_channel *channel,
+ uint64_t key, struct lttng_consumer_local_data *ctx)
{
int ret;
- struct lttng_consumer_channel *channel;
struct lttng_consumer_stream *stream;
struct lttng_ht_iter iter;
struct lttng_ht *ht = consumer_data.stream_per_chan_id_ht;
DBG("Consumer rotate ready streams in channel %" PRIu64, key);
- channel = consumer_find_channel(key);
- if (!channel) {
- ERR("No channel found for key %" PRIu64, key);
- ret = -1;
- goto end;
- }
-
cds_lfht_for_each_entry_duplicate(ht->ht,
ht->hash_fct(&channel->key, lttng_ht_seed),
ht->match_fct, &channel->key, &iter.iter,
void consumer_add_metadata_stream(struct lttng_consumer_stream *stream);
void consumer_del_stream_for_metadata(struct lttng_consumer_stream *stream);
int consumer_create_index_file(struct lttng_consumer_stream *stream);
-int lttng_consumer_rotate_channel(uint64_t key, const char *path,
- uint64_t relayd_id, uint32_t metadata,
- uint64_t new_chunk_id, struct lttng_consumer_local_data *ctx);
+int lttng_consumer_rotate_channel(struct lttng_consumer_channel *channel,
+ uint64_t key, const char *path, uint64_t relayd_id,
+ uint32_t metadata, uint64_t new_chunk_id,
+ struct lttng_consumer_local_data *ctx);
int lttng_consumer_stream_is_rotate_ready(struct lttng_consumer_stream *stream);
int lttng_consumer_rotate_stream(struct lttng_consumer_local_data *ctx,
struct lttng_consumer_stream *stream, bool *rotated);
-int lttng_consumer_rotate_ready_streams(uint64_t key,
- struct lttng_consumer_local_data *ctx);
+int lttng_consumer_rotate_ready_streams(struct lttng_consumer_channel *channel,
+ uint64_t key, struct lttng_consumer_local_data *ctx);
int lttng_consumer_rotate_rename(const char *current_path, const char *new_path,
uid_t uid, gid_t gid, uint64_t relayd_id);
int lttng_consumer_check_rotation_pending_local(uint64_t session_id,
}
case LTTNG_CONSUMER_ROTATE_CHANNEL:
{
- DBG("Consumer rotate channel %" PRIu64, msg.u.rotate_channel.key);
+ struct lttng_consumer_channel *channel;
+ uint64_t key = msg.u.rotate_channel.key;
- /*
- * Sample the rotate position of all the streams in this channel.
- */
- ret = lttng_consumer_rotate_channel(msg.u.rotate_channel.key,
- msg.u.rotate_channel.pathname,
- msg.u.rotate_channel.relayd_id,
- msg.u.rotate_channel.metadata,
- msg.u.rotate_channel.new_chunk_id,
- ctx);
- if (ret < 0) {
- ERR("Rotate channel failed");
- ret_code = LTTCOMM_CONSUMERD_CHAN_NOT_FOUND;
- }
+ DBG("Consumer rotate channel %" PRIu64, key);
- health_code_update();
+ channel = consumer_find_channel(key);
+ if (!channel) {
+ ERR("Channel %" PRIu64 " not found", key);
+ ret_code = LTTCOMM_CONSUMERD_CHAN_NOT_FOUND;
+ } else {
+ /*
+ * Sample the rotate position of all the streams in this channel.
+ */
+ ret = lttng_consumer_rotate_channel(channel, key,
+ msg.u.rotate_channel.pathname,
+ msg.u.rotate_channel.relayd_id,
+ msg.u.rotate_channel.metadata,
+ msg.u.rotate_channel.new_chunk_id,
+ ctx);
+ if (ret < 0) {
+ ERR("Rotate channel failed");
+ ret_code = LTTCOMM_CONSUMERD_ROTATION_FAIL;
+ }
+ health_code_update();
+ }
ret = consumer_send_status_msg(sock, ret_code);
if (ret < 0) {
/* Somehow, the session daemon is not responding anymore. */
goto end_nosignal;
}
-
- /* Rotate the streams that are ready right now. */
- ret = lttng_consumer_rotate_ready_streams(
- msg.u.rotate_channel.key, ctx);
- if (ret < 0) {
- ERR("Rotate ready streams failed");
+ if (channel) {
+ /* Rotate the streams that are ready right now. */
+ ret = lttng_consumer_rotate_ready_streams(
+ channel, key, ctx);
+ if (ret < 0) {
+ ERR("Rotate ready streams failed");
+ }
}
break;
msg.u.rotate_rename.relayd_id);
if (ret < 0) {
ERR("Rotate rename failed");
- ret_code = LTTCOMM_CONSUMERD_CHAN_NOT_FOUND;
+ ret_code = LTTCOMM_CONSUMERD_ROTATE_RENAME_FAILED;
}
health_code_update();
msg.u.check_rotation_pending_local.chunk_id);
if (pending < 0) {
ERR("Local rotation pending check failed with code %i", pending);
- ret_code = LTTCOMM_CONSUMERD_CHAN_NOT_FOUND;
+ ret_code = LTTCOMM_CONSUMERD_ROTATION_PENDING_LOCAL_FAILED;
} else {
pending_reply = !!pending;
}
msg.u.check_rotation_pending_relay.chunk_id);
if (pending < 0) {
ERR("Relayd rotation pending check failed with code %i", pending);
- ret_code = LTTCOMM_CONSUMERD_CHAN_NOT_FOUND;
+ ret_code = LTTCOMM_CONSUMERD_ROTATION_PENDING_RELAY_FAILED;
} else {
pending_reply = !!pending;
}
msg.u.mkdir.relayd_id);
if (ret < 0) {
ERR("consumer mkdir failed");
- ret_code = LTTCOMM_CONSUMERD_CHAN_NOT_FOUND;
+ ret_code = LTTCOMM_CONSUMERD_MKDIR_FAILED;
}
health_code_update();
LTTCOMM_CONSUMERD_CHANNEL_FAIL, /* Channel creation failed. */
LTTCOMM_CONSUMERD_CHAN_NOT_FOUND, /* Channel not found. */
LTTCOMM_CONSUMERD_ALREADY_SET, /* Resource already set. */
+ LTTCOMM_CONSUMERD_ROTATION_FAIL, /* Rotation has failed. */
+ LTTCOMM_CONSUMERD_ROTATE_RENAME_FAILED, /* Rotation rename has failed. */
+ LTTCOMM_CONSUMERD_ROTATION_PENDING_LOCAL_FAILED, /* Rotation pending relay failed. */
+ LTTCOMM_CONSUMERD_ROTATION_PENDING_RELAY_FAILED, /* Rotation pending relay failed. */
+ LTTCOMM_CONSUMERD_MKDIR_FAILED, /* mkdir has failed. */
/* MUST be last element */
LTTCOMM_NR, /* Last element */
}
case LTTNG_CONSUMER_ROTATE_CHANNEL:
{
- /*
- * Sample the rotate position of all the streams in this channel.
- */
- ret = lttng_consumer_rotate_channel(msg.u.rotate_channel.key,
- msg.u.rotate_channel.pathname,
- msg.u.rotate_channel.relayd_id,
- msg.u.rotate_channel.metadata,
- msg.u.rotate_channel.new_chunk_id,
- ctx);
- if (ret < 0) {
- ERR("Rotate channel failed");
- ret_code = LTTCOMM_CONSUMERD_CHAN_NOT_FOUND;
- }
+ struct lttng_consumer_channel *channel;
+ uint64_t key = msg.u.rotate_channel.key;
- health_code_update();
+ channel = consumer_find_channel(key);
+ if (!channel) {
+ DBG("Channel %" PRIu64 " not found", key);
+ ret_code = LTTCOMM_CONSUMERD_CHAN_NOT_FOUND;
+ } else {
+ /*
+ * Sample the rotate position of all the streams in
+ * this channel.
+ */
+ ret = lttng_consumer_rotate_channel(channel, key,
+ msg.u.rotate_channel.pathname,
+ msg.u.rotate_channel.relayd_id,
+ msg.u.rotate_channel.metadata,
+ msg.u.rotate_channel.new_chunk_id,
+ ctx);
+ if (ret < 0) {
+ ERR("Rotate channel failed");
+ ret_code = LTTCOMM_CONSUMERD_ROTATION_FAIL;
+ }
+ health_code_update();
+ }
ret = consumer_send_status_msg(sock, ret_code);
if (ret < 0) {
/* Somehow, the session daemon is not responding anymore. */
* handle this, but it needs to be after the
* consumer_send_status_msg() call.
*/
- ret = lttng_consumer_rotate_ready_streams(
- msg.u.rotate_channel.key, ctx);
- if (ret < 0) {
- ERR("Rotate channel failed");
+ if (channel) {
+ ret = lttng_consumer_rotate_ready_streams(
+ channel, key, ctx);
+ if (ret < 0) {
+ ERR("Rotate channel failed");
+ }
}
break;
}
msg.u.rotate_rename.relayd_id);
if (ret < 0) {
ERR("Rotate rename failed");
- ret_code = LTTCOMM_CONSUMERD_RELAYD_FAIL;
+ ret_code = LTTCOMM_CONSUMERD_ROTATE_RENAME_FAILED;
}
health_code_update();
msg.u.check_rotation_pending_local.chunk_id);
if (pending < 0) {
ERR("Local rotation pending check failed with code %i", pending);
- ret_code = LTTCOMM_CONSUMERD_CHAN_NOT_FOUND;
+ ret_code = LTTCOMM_CONSUMERD_ROTATION_PENDING_LOCAL_FAILED;
} else {
pending_reply = !!pending;
}
msg.u.check_rotation_pending_relay.chunk_id);
if (pending < 0) {
ERR("Relayd rotation pending check failed with code %i", pending);
- ret_code = LTTCOMM_CONSUMERD_CHAN_NOT_FOUND;
+ ret_code = LTTCOMM_CONSUMERD_ROTATION_PENDING_RELAY_FAILED;
} else {
pending_reply = !!pending;
}
msg.u.mkdir.relayd_id);
if (ret < 0) {
ERR("consumer mkdir failed");
- ret_code = LTTCOMM_CONSUMERD_RELAYD_FAIL;
+ ret_code = LTTCOMM_CONSUMERD_MKDIR_FAILED;
}
health_code_update();