summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRonnie Sahlberg <ronniesahlberg@gmail.com>2011-08-23 12:43:16 +1000
committerRonnie Sahlberg <ronniesahlberg@gmail.com>2011-08-23 12:43:16 +1000
commitaf19b5acfff144f79218ed1ea37862beb9456b39 (patch)
treea93f086f674d1caaca2d8e49e4635a83910f3218
parent1cf1670f0a78aa30f0f177b3a7c012543edae87b (diff)
downloadsamba-af19b5acfff144f79218ed1ea37862beb9456b39.tar.gz
samba-af19b5acfff144f79218ed1ea37862beb9456b39.tar.xz
samba-af19b5acfff144f79218ed1ea37862beb9456b39.zip
LibCTDB: add commands where an application can query how many commands are active
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. (This used to be ctdb commit 8d89bfdfd1f55dfeb22890b8bb0f08f31d1fa91a)
-rw-r--r--ctdb/include/ctdb.h39
-rw-r--r--ctdb/libctdb/ctdb.c29
2 files changed, 68 insertions, 0 deletions
diff --git a/ctdb/include/ctdb.h b/ctdb/include/ctdb.h
index fad3233ba6..ae62a178d1 100644
--- a/ctdb/include/ctdb.h
+++ b/ctdb/include/ctdb.h
@@ -116,6 +116,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.
*
diff --git a/ctdb/libctdb/ctdb.c b/ctdb/libctdb/ctdb.c
index e407910a30..d51f4a11d3 100644
--- a/ctdb/libctdb/ctdb.c
+++ b/ctdb/libctdb/ctdb.c
@@ -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);
+}
+