LibCTDB: add commands where an application can query how many commands are active
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Tue, 23 Aug 2011 02:43:16 +0000 (12:43 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Tue, 23 Aug 2011 02:43:16 +0000 (12:43 +1000)
and we have not yet received a reply to.
Applications may use this command to query if it is "safe" to stop the event system and sleep
or whether it should first wait for all activity to ctdb daemons to cease first.

include/ctdb.h
libctdb/ctdb.c

index fad3233ba657e05f206a8329a1e98088072f049f..ae62a178d135339ed7113af6a3959d099886fd74 100644 (file)
@@ -115,6 +115,45 @@ void ctdb_disconnect(struct ctdb_connection *ctdb);
  *
  ***/
 
+/**
+ * ctdb_num_active - get the number of active commands
+ * @ctdb: the ctdb_connection from ctdb_connect.
+ *
+ * This command can be used to find the number of active commands we have
+ * issued. An active command is a command we have queued, or sent
+ * to the ctdb daemon but which we have not yet received a reply to.
+ *
+ * See Also:
+ *     ctdb_num_in_flight(), ctdb_num_out_queue()
+ */
+int ctdb_num_active(struct ctdb_connection *ctdb);
+
+/**
+ * ctdb_num_in_flight - get the number of commands in flight.
+ * @ctdb: the ctdb_connection from ctdb_connect.
+ *
+ * This command can be used to find the number of commands we have
+ * sent to the ctdb daemon to which we have not yet received/processed
+ * the reply.
+ *
+ * See Also:
+ *     ctdb_num_out_queue(), ctdb_num_active()
+ */
+int ctdb_num_in_flight(struct ctdb_connection *ctdb);
+
+/**
+ * ctdb_num_out_queue - get the number of commands in the out queue
+ * @ctdb: the ctdb_connection from ctdb_connect.
+ *
+ * This command can be used to find the number of commands we have
+ * queued for delivery to the ctdb daemon but have not yet been
+ * written to the domain socket.
+ *
+ * See Also:
+ *     ctdb_num_in_flight(), ctdb_num_active()
+ */
+int ctdb_num_out_queue(struct ctdb_connection *ctdb);
+
 /**
  * ctdb_get_fd - get the filedescriptor to select/poll on
  * @ctdb: the ctdb_connection from ctdb_connect.
index e407910a30761f7c18a785c87ffa6a834082f4de..d51f4a11d3e65ee40695fe2e6d780fc62cb69d9e 100644 (file)
@@ -1133,3 +1133,32 @@ bool ctdb_traverse_async(struct ctdb_db *ctdb_db,
 
        return true;
 }
+
+int ctdb_num_out_queue(struct ctdb_connection *ctdb)
+{
+       struct ctdb_request *req;
+       int i;
+
+       for (i = 0, req = ctdb->outq; req; req = req->next, i++)
+               ;
+
+       return i;
+}
+
+int ctdb_num_in_flight(struct ctdb_connection *ctdb)
+{
+       struct ctdb_request *req;
+       int i;
+
+       for (i = 0, req = ctdb->doneq; req; req = req->next, i++)
+               ;
+
+       return i;
+}
+
+int ctdb_num_active(struct ctdb_connection *ctdb)
+{
+       return ctdb_num_out_queue(ctdb)
+                + ctdb_num_in_flight(ctdb);
+}
+