goto send_reply;
}
+ fprintf(stderr, "name: %s\n", session_name);
session = session_create(session_name, hostname, live_timer,
snapshot, conn->major, conn->minor);
if (!session) {
sizeof(session->hostname))) {
goto error;
}
+ fprintf(stderr, "hostname; %s\n", hostname);
session->ctf_traces_ht = lttng_ht_new(0, LTTNG_HT_TYPE_STRING);
if (!session->ctf_traces_ht) {
goto error;
* an eventual session rotation call.
*/
if (!session->has_been_started) {
- session->session_start_ts = time(NULL);
- if (session->session_start_ts == (time_t) -1) {
+ session->current_chunk_start_ts = time(NULL);
+ if (session->current_chunk_start_ts == (time_t) -1) {
PERROR("Get start time");
ret = LTTNG_ERR_FATAL;
goto error;
return 0;
}
-static
-int rename_first_chunk(struct ltt_session *session,
- struct consumer_output *consumer, char *datetime)
-{
- int ret;
- char *tmppath = NULL, *tmppath2 = NULL;
-
- tmppath = zmalloc(PATH_MAX * sizeof(char));
- if (!tmppath) {
- ret = -LTTNG_ERR_NOMEM;
- goto error;
- }
- tmppath2 = zmalloc(PATH_MAX * sizeof(char));
- if (!tmppath2) {
- ret = -LTTNG_ERR_NOMEM;
- goto error;
- }
-
- /* Current domain path: <session>/kernel */
- snprintf(tmppath, PATH_MAX, "%s/%s",
- consumer->dst.session_root_path, consumer->subdir);
- /* New domain path: <session>/<start-date>-/kernel */
- snprintf(tmppath2, PATH_MAX, "%s/%s-/%s",
- consumer->dst.session_root_path, datetime,
- consumer->subdir);
- /*
- * Move the per-domain folder inside the first rotation
- * folder.
- */
- ret = session_rename_chunk(session, tmppath, tmppath2, 1);
- if (ret < 0) {
- PERROR("Rename first trace directory");
- ret = -LTTNG_ERR_ROTATE_NO_DATA;
- goto error;
- }
-
- ret = 0;
-
-error:
- free(tmppath);
- free(tmppath2);
-
- return ret;
-}
-
/*
* Command LTTNG_ROTATE_SESSION from the lttng-ctl library.
*
/* Special case for the first rotation. */
if (session->rotate_count == 0) {
- timeinfo = localtime(&session->session_start_ts);
- strftime(datetime, sizeof(datetime), "%Y%m%d-%H%M%S", timeinfo);
/* Either one of the two sessions is enough to get the root path. */
if (session->kernel_session) {
snprintf(session->rotation_chunk.current_rotate_path,
- PATH_MAX, "%s/%s-",
- session->kernel_session->consumer->dst.session_root_path,
- datetime);
+ PATH_MAX, "%s",
+ session->kernel_session->consumer->dst.session_root_path);
} else if (session->ust_session) {
snprintf(session->rotation_chunk.current_rotate_path,
- PATH_MAX, "%s/%s-",
- session->ust_session->consumer->dst.session_root_path,
- datetime);
+ PATH_MAX, "%s",
+ session->ust_session->consumer->dst.session_root_path);
} else {
assert(0);
}
-
- /*
- * Create the first rotation folder to move the existing
- * kernel/ust folders into.
- */
- ret = run_as_mkdir_recursive(session->rotation_chunk.current_rotate_path,
- S_IRWXU | S_IRWXG, session->uid, session->gid);
- if (ret < 0) {
- if (errno != EEXIST) {
- ERR("Trace directory creation error");
- ret = -LTTNG_ERR_ROTATE_NOT_AVAILABLE;
- goto error;
- }
- }
- if (session->kernel_session) {
- ret = rename_first_chunk(session,
- session->kernel_session->consumer,
- datetime);
- if (ret < 0) {
- goto error;
- }
- }
- if (session->ust_session) {
- ret = rename_first_chunk(session,
- session->ust_session->consumer,
- datetime);
- if (ret < 0) {
- goto error;
- }
- }
} else {
/*
* The currently active tracing path is now the folder we
ret = -LTTNG_ERR_ROTATE_NOT_AVAILABLE;
goto error;
}
+ session->last_chunk_start_ts = session->current_chunk_start_ts;
+ session->current_chunk_start_ts = now;
timeinfo = localtime(&now);
strftime(datetime, sizeof(datetime), "%Y%m%d-%H%M%S", timeinfo);
msg.u.rotate_channel.key = key;
msg.u.rotate_channel.metadata = metadata;
+
if (output->type == CONSUMER_DST_NET) {
- ERR("TODO");
- ret = -1;
- goto error;
- /*
- msg.u.rotate_channel.relayd_id = output->consumer->net_seq_index;
- ret = snprintf(msg.u.rotate_channel.pathname,
- sizeof(msg.u.rotate_channel.pathname),
- "%s/%s-%s-%" PRIu64 "%s", output->consumer->subdir,
- output->name, output->datetime, output->nb_rotate,
- session_path);
- if (ret < 0) {
- ret = -LTTNG_ERR_NOMEM;
- goto error;
- }
- */
+ fprintf(stderr, "SUBDIR: %s\n", output->subdir);
+ msg.u.rotate_channel.relayd_id = output->net_seq_index;
+ snprintf(msg.u.rotate_channel.pathname, PATH_MAX, "%s/%s/%s",
+ output->subdir,
+ output->chunk_path, tmp);
} else {
msg.u.rotate_channel.relayd_id = (uint64_t) -1ULL;
snprintf(msg.u.rotate_channel.pathname, PATH_MAX, "%s/%s/%s",
fprintf(stderr, "rotate to %s\n",
msg.u.rotate_channel.pathname);
- /* Create directory. Ignore if exist. */
- /* FIXME: not sure this is useful */
- ret = run_as_mkdir_recursive(msg.u.rotate_channel.pathname,
- S_IRWXU | S_IRWXG, uid, gid);
- if (ret < 0) {
- if (errno != EEXIST) {
- ERR("Trace directory creation error");
- goto error;
- }
- }
}
health_code_update();
msg.u.rotate_rename.gid = gid;
if (output->type == CONSUMER_DST_NET) {
+ fprintf(stderr, "SUBDIR: %s\n", output->subdir);
+ fprintf(stderr, "SUBDIR: %s\n", output->dst.net.control.subdir);
ERR("TODO");
ret = -1;
msg.u.rotate_rename.relayd_id = output->net_seq_index;
return ret;
}
+static
+int rename_first_chunk(struct ltt_session *session,
+ struct consumer_output *consumer, char *new_path)
+{
+ int ret;
+ char *tmppath = NULL, *tmppath2 = NULL;
+
+ tmppath = zmalloc(PATH_MAX * sizeof(char));
+ if (!tmppath) {
+ ret = -LTTNG_ERR_NOMEM;
+ goto error;
+ }
+ tmppath2 = zmalloc(PATH_MAX * sizeof(char));
+ if (!tmppath2) {
+ ret = -LTTNG_ERR_NOMEM;
+ goto error;
+ }
+
+ /* Current domain path: <session>/kernel */
+ snprintf(tmppath, PATH_MAX, "%s/%s",
+ consumer->dst.session_root_path, consumer->subdir);
+ /* New domain path: <session>/<start-date>-<end-date>-<rotate-count>/kernel */
+ snprintf(tmppath2, PATH_MAX, "%s/%s",
+ new_path, consumer->subdir);
+ /*
+ * Move the per-domain folder inside the first rotation
+ * folder.
+ */
+ ret = session_rename_chunk(session, tmppath, tmppath2, 1);
+ if (ret < 0) {
+ PERROR("Rename first trace directory");
+ ret = -LTTNG_ERR_ROTATE_NO_DATA;
+ goto error;
+ }
+
+ ret = 0;
+
+error:
+ free(tmppath);
+ free(tmppath2);
+
+ return ret;
+}
+
int rename_complete_chunk(struct ltt_session *session, time_t ts)
{
struct tm *timeinfo;
char datetime[16];
- char *tmppath = NULL;
+ char *new_path = NULL;
int ret;
+ /*
+ * TODO 2: on first rotate, the current_rotate_path is the session root
+ * path, so move the kernel/ and ust/ folders inside the
+ * "session->last_chunk_start_ts-now()"
+ */
+
timeinfo = localtime(&ts);
strftime(datetime, sizeof(datetime), "%Y%m%d-%H%M%S", timeinfo);
- tmppath = zmalloc(PATH_MAX * sizeof(char));
- if (!tmppath) {
- ERR("Alloc tmppath");
+ new_path = zmalloc(PATH_MAX * sizeof(char));
+ if (!new_path) {
+ ERR("Alloc new_path");
ret = -1;
goto end;
}
- snprintf(tmppath, PATH_MAX, "%s%s-%" PRIu64,
- session->rotation_chunk.current_rotate_path,
- datetime, session->rotate_count);
+ fprintf(stderr, "COUNT: %d\n", session->rotate_count);
- fprintf(stderr, "rename %s to %s\n", session->rotation_chunk.current_rotate_path,
- tmppath);
+ if (session->rotate_count == 1) {
+ char start_time[16];
- ret = session_rename_chunk(session,
- session->rotation_chunk.current_rotate_path,
- tmppath, 0);
- if (ret) {
- ERR("Session rename");
- ret = -1;
- goto end;
+ timeinfo = localtime(&session->last_chunk_start_ts);
+ strftime(start_time, sizeof(start_time), "%Y%m%d-%H%M%S", timeinfo);
+
+ /*
+ * On the first rotation, the current_rotate_path is the
+ * session_root_path, so we need to create the chunk folder
+ * and move the domain-specific folders inside it.
+ */
+ snprintf(new_path, PATH_MAX, "%s/%s-%s-%" PRIu64,
+ session->rotation_chunk.current_rotate_path,
+ start_time,
+ datetime, session->rotate_count);
+
+ if (session->kernel_session) {
+ fprintf(stderr, "rename %s/kernel to %s\n",
+ session->rotation_chunk.current_rotate_path,
+ new_path);
+ ret = rename_first_chunk(session,
+ session->kernel_session->consumer,
+ new_path);
+ if (ret) {
+ ERR("Rename kernel session");
+ ret = -1;
+ goto end;
+ }
+ }
+ if (session->ust_session) {
+ fprintf(stderr, "rename %s/kernel to %s\n",
+ session->rotation_chunk.current_rotate_path,
+ new_path);
+ ret = rename_first_chunk(session,
+ session->ust_session->consumer,
+ new_path);
+ if (ret) {
+ ERR("Rename ust session");
+ ret = -1;
+ goto end;
+ }
+ }
+ } else {
+ /*
+ * After the first rotation, all the trace data is already in
+ * its own chunk folder, we just need to append the suffix.
+ */
+ snprintf(new_path, PATH_MAX, "%s%s-%" PRIu64,
+ session->rotation_chunk.current_rotate_path,
+ datetime, session->rotate_count);
+
+ fprintf(stderr, "rename %s to %s\n",
+ session->rotation_chunk.current_rotate_path,
+ new_path);
+
+ ret = session_rename_chunk(session,
+ session->rotation_chunk.current_rotate_path,
+ new_path, 0);
+ if (ret) {
+ ERR("Session rename");
+ ret = -1;
+ goto end;
+ }
}
/*
* rotation is started.
*/
snprintf(session->rotation_chunk.current_rotate_path, PATH_MAX,
- "%s", tmppath);
+ "%s", new_path);
session->rotate_pending = 0;
end:
- free(tmppath);
+ free(new_path);
return ret;
}
if (revents & (LPOLLERR | LPOLLHUP | LPOLLRDHUP)) {
ret = lttng_poll_del(&state->events, fd);
if (ret) {
- ERR("[rotation-thread] Failed to remove consumer rotation pipe from poll set");
+ ERR("[rotation-thread] Failed to remove consumer "
+ "rotation pipe from poll set");
}
goto end;
}
* session rotation.
*/
char active_tracing_path[PATH_MAX];
- time_t rotate_start_time;
- time_t rotate_end_time;
};
/*
unsigned int nr_chan_rotate_pending;
struct ltt_session_chunk rotation_chunk;
/*
- * Store the timestamp when the session started for an eventual
- * session rotation call.
+ * The timestamp of the beginning of the previous chunk. For the
+ * first chunk, this is the "lttng start" timestamp. For the
+ * subsequent ones, this copies the current_chunk_start_ts value when
+ * a new rotation starts. This value is used to set the name of a
+ * complete chunk directory, ex: "last_chunk_start_ts-now()".
*/
- time_t session_start_ts;
+ time_t last_chunk_start_ts;
+ /*
+ * This is the timestamp when a new chunk starts. When a new rotation
+ * starts, we copy this value to last_chunk_start_ts and override it
+ * with the current timestamp.
+ */
+ time_t current_chunk_start_ts;
time_t session_last_stop_ts;
time_t last_begin_rotation_ts;
};
ht->hash_fct(&channel->key, lttng_ht_seed),
ht->match_fct, &channel->key, &iter.iter,
stream, node_channel_id.node) {
+ uint64_t consumed_pos;
+
health_code_update();
/*
* Lock stream because we are about to change its state.
*/
pthread_mutex_lock(&stream->lock);
+ ret = utils_mkdir_recursive(channel->pathname, S_IRWXU | S_IRWXG,
+ stream->uid, stream->gid);
+ if (ret < 0) {
+ if (errno != EEXIST) {
+ ERR("Trace directory creation error");
+ goto end_unlock;
+ }
+ }
+
memcpy(stream->channel_ro_pathname, channel->pathname, PATH_MAX);
ret = lttng_consumer_sample_snapshot_positions(stream);
if (ret < 0) {
ERR("Taking kernel snapshot positions");
goto end_unlock;
- } else {
- uint64_t consumed_pos;
+ }
- ret = lttng_consumer_get_produced_snapshot(stream,
- &stream->rotate_position);
- if (ret < 0) {
- ERR("Produced kernel snapshot position");
- goto end_unlock;
- }
- fprintf(stderr, "Stream %lu should rotate after %lu to %s\n",
- stream->key, stream->rotate_position,
- channel->pathname);
- lttng_consumer_get_consumed_snapshot(stream,
- &consumed_pos);
- fprintf(stderr, "consumed %lu\n", consumed_pos);
- if (consumed_pos == stream->rotate_position) {
- stream->rotate_ready = 1;
- fprintf(stderr, "Stream %lu ready to rotate to %s\n",
- stream->key, channel->pathname);
- }
+ ret = lttng_consumer_get_produced_snapshot(stream,
+ &stream->rotate_position);
+ if (ret < 0) {
+ ERR("Produced kernel snapshot position");
+ goto end_unlock;
+ }
+ fprintf(stderr, "Stream %lu should rotate after %lu to %s\n",
+ stream->key, stream->rotate_position,
+ channel->pathname);
+ lttng_consumer_get_consumed_snapshot(stream,
+ &consumed_pos);
+ fprintf(stderr, "consumed %lu\n", consumed_pos);
+ if (consumed_pos == stream->rotate_position) {
+ stream->rotate_ready = 1;
+ fprintf(stderr, "Stream %lu ready to rotate to %s\n",
+ stream->key, channel->pathname);
}
channel->nr_stream_rotate_pending++;