+ cds_lfht_first(session->kernel_session->consumer->socks->ht,
+ &iter);
+ output = session->kernel_session->consumer;
+ }
+ assert(cds_lfht_iter_get_node(&iter));
+
+ socket = caa_container_of(cds_lfht_iter_get_node(&iter),
+ typeof(*socket), node.node);
+
+ pthread_mutex_lock(socket->lock);
+ DBG("[rotation-thread] Checking for pending relay rotation on session \"%s\", trace archive %" PRIu64 " through the %s consumer",
+ session->name, session->current_archive_id - 1,
+ lttng_consumer_type_str(socket->type));
+ ret = consumer_check_rotation_pending_relay(socket,
+ output,
+ session->id,
+ session->current_archive_id - 1);
+ pthread_mutex_unlock(socket->lock);
+
+ if (ret == 0) {
+ /* Rotation was completed on the relay. */
+ DBG("[rotation-thread] Relay rotation of trace archive %" PRIu64 " of session \"%s\" was completed",
+ session->current_archive_id - 1,
+ session->name);
+ } else if (ret == 1) {
+ /* Rotation pending on relay. */
+ DBG("[rotation-thread] Relay rotation of trace archive %" PRIu64 " of session \"%s\" is pending",
+ session->current_archive_id - 1,
+ session->name);
+ rotation_completed = false;
+ } else {
+ /* Not a fatal error. */
+ ERR("[rotation-thread] Encountered an error when checking if rotation of trace archive %" PRIu64 " of session \"%s\" is pending on the relay",
+ session->current_archive_id - 1,
+ session->name);
+ ret = session_reset_rotation_state(session,
+ LTTNG_ROTATION_STATE_ERROR);
+ if (ret) {
+ ERR("Failed to reset rotation state of session \"%s\"",
+ session->name);
+ }
+ rotation_completed = false;
+ }
+
+ rcu_read_unlock();
+
+ if (rotation_completed) {
+ DBG("[rotation-thread] Rotation of trace archive %" PRIu64 " of session \"%s\" is complete on the relay",
+ session->current_archive_id - 1,
+ session->name);
+ session->rotation_pending_relay = false;
+ }
+ return 0;
+}
+
+/*
+ * Check if the last rotation was completed, called with session lock held.
+ */
+static
+int check_session_rotation_pending(struct ltt_session *session,
+ struct notification_thread_handle *notification_thread_handle)
+{
+ int ret;
+ struct lttng_trace_archive_location *location;
+ time_t now;
+
+ DBG("[rotation-thread] Checking for pending rotation on session \"%s\", trace archive %" PRIu64,
+ session->name, session->current_archive_id - 1);
+
+ if (session->rotation_pending_local) {
+ /* Updates session->rotation_pending_local as needed. */
+ ret = check_session_rotation_pending_local(session);
+ if (ret) {
+ goto end;
+ }
+
+ /*
+ * No need to check for a pending rotation on the relay
+ * since the rotation is not even completed locally yet.
+ */
+ if (session->rotation_pending_local) {
+ goto end;
+ }
+ }
+
+ if (session->rotation_pending_relay) {
+ /* Updates session->rotation_pending_relay as needed. */
+ ret = check_session_rotation_pending_relay(session);
+ if (ret) {
+ goto end;
+ }
+
+ if (session->rotation_pending_relay) {
+ goto end;
+ }