+ /*
+ * The rotation-pending check timer of a session is launched in
+ * one-shot mode. If the rotation is incomplete, the rotation
+ * thread will re-enable the pending-check timer.
+ *
+ * The timer thread can't stop the timer itself since it is involved
+ * in the check for the timer's quiescence.
+ */
+ ret = timer_session_rotation_pending_check_stop(session);
+ if (ret) {
+ goto end;
+ }
+
+ 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;
+ }
+ }
+
+ DBG("[rotation-thread] Rotation of trace archive %" PRIu64 " completed for "
+ "session %s", session->current_archive_id - 1,
+ session->name);
+
+ /* Rename the completed trace archive's location. */
+ now = time(NULL);
+ if (now == (time_t) -1) {
+ ret = session_reset_rotation_state(session,
+ LTTNG_ROTATION_STATE_ERROR);
+ if (ret) {
+ ERR("Failed to reset rotation state of session \"%s\"",
+ session->name);
+ }
+ ret = LTTNG_ERR_UNK;
+ goto end;
+ }
+
+ ret = rename_completed_chunk(session, now);