rotate pending working on the relay
[deliverable/lttng-tools.git] / src / bin / lttng-sessiond / cmd.c
index 88f33c1568a77b21630f57d9486deafd61536763..cb32f7f7fb63419373af1be65635576a13cfc49a 100644 (file)
@@ -4177,6 +4177,32 @@ int cmd_rotate_session(struct ltt_session *session,
                goto error;
        }
 
+       /*
+        * If the user did not wait for the previous rotation to complete
+        * (--no-wait), we have to ensure now that the relay had time to
+        * receive all the data pending from the previous rotation.
+        */
+       if (session->rotate_pending_relay) {
+               ret = relay_rotate_pending(session,
+                               session->rotate_count - 1);
+               if (ret == 0) {
+                       DBG("Previous rotation completed on the relay for session %s"
+                                       ", rotate_id %" PRIu64,
+                                       session->name,
+                                       session->rotate_count);
+                       session->rotate_pending_relay = 0;
+               } else if (ret == 1) {
+                       DBG("Session %s, rotate_id %" PRIu64 " still pending "
+                                       "on the relay",
+                                       session->name, session->rotate_count);
+                       ret = -LTTNG_ERR_ROTATE_PENDING;
+                       goto error;
+               } else {
+                       ERR("Failed to check rotate pending on the relay");
+                       ret = -LTTNG_ERR_UNK;
+               }
+       }
+
        /* Special case for the first rotation. */
        if (session->rotate_count == 0) {
                const char *base_path = NULL;
@@ -4310,16 +4336,22 @@ int cmd_rotate_pending(struct ltt_session *session,
                } else {
                        /*
                         * The consumer finished the rotation, but we don't
-                        * know if the relay still has data pending. We need
-                        * to find one consumer_output to talk to the relay
-                        * and ask it.
+                        * know if the relay still has data pending. We need to
+                        * find one consumer_output to talk to the relay and
+                        * ask it.
+                        *
+                        * (rotate_count - 1) is the chunk id that we want to
+                        * make sure is completely flushed to disk on the
+                        * relay.
                         */
-                       ret = relay_rotate_pending(session);
+                       ret = relay_rotate_pending(session,
+                                       session->rotate_count - 1);
                        if (ret == 0) {
                                DBG("Rotate completed on the relay for session %s"
                                                ", rotate_id %" PRIu64,
                                                session->name,
                                                session->rotate_count);
+                               session->rotate_pending_relay = 0;
                                (*pending_return)->status = LTTNG_ROTATE_COMPLETED;
                                snprintf((*pending_return)->output_path, PATH_MAX, "%s",
                                                session->rotation_chunk.current_rotate_path);
This page took 0.024541 seconds and 5 git commands to generate.