ctdbd: Set num_clients statistic from ctdb->num_clients
authorAmitay Isaacs <amitay@gmail.com>
Fri, 19 Apr 2013 03:29:04 +0000 (13:29 +1000)
committerAmitay Isaacs <amitay@gmail.com>
Mon, 22 Apr 2013 04:00:51 +0000 (14:00 +1000)
This fixes the problem of "ctdb statisticsreset" clearing the number of
clients even when there are active clients.

Values returned in statistics for frozen, recovering, memory_used are based on
the current state of CTDB and are not maintained as statistics.  This should
include num_clients as well.

Currently ctdb->num_clients is unused. So use that to track the number of
clients and fill in statistics field only when requested.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
(This used to be ctdb commit dc4ca816630ed44b419108da53421331243fb8c7)

ctdb/server/ctdb_control.c
ctdb/server/ctdb_daemon.c

index 99b3dc431476f931d08db9950de04448a91fd8b2..affb9dd00d3ed1f2fdab03d77e26d061899f6692 100644 (file)
@@ -100,6 +100,7 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
                int i;
                CHECK_CONTROL_DATA_SIZE(0);
                ctdb->statistics.memory_used = talloc_total_size(NULL);
+               ctdb->statistics.num_clients = ctdb->num_clients;
                ctdb->statistics.frozen = 0;
                for (i=1; i<= NUM_DB_PRIORITIES; i++) {
                        if (ctdb->freeze_mode[i] == CTDB_FREEZE_FROZEN) {
@@ -204,7 +205,7 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
 
        case CTDB_CONTROL_PING:
                CHECK_CONTROL_DATA_SIZE(0);
-               return ctdb->statistics.num_clients;
+               return ctdb->num_clients;
 
        case CTDB_CONTROL_SET_DB_READONLY: {
                uint32_t db_id;
index d2aae5a010f1e02c7df6f8829c639d548ba7366c..2bd934601065d3fd5c07e4755548b11dc7de2a5f 100644 (file)
@@ -245,7 +245,7 @@ static int ctdb_client_destructor(struct ctdb_client *client)
 
        ctdb_takeover_client_destructor_hook(client);
        ctdb_reqid_remove(client->ctdb, client->client_id);
-       CTDB_DECREMENT_STAT(client->ctdb, num_clients);
+       client->ctdb->num_clients--;
 
        if (client->num_persistent_updates != 0) {
                DEBUG(DEBUG_ERR,(__location__ " Client disconnecting with %u persistent updates in flight. Starting recovery\n", client->num_persistent_updates));
@@ -974,7 +974,7 @@ static void ctdb_accept_client(struct event_context *ev, struct fd_event *fde,
 
        talloc_set_destructor(client, ctdb_client_destructor);
        talloc_set_destructor(client_pid, ctdb_clientpid_destructor);
-       CTDB_INCREMENT_STAT(ctdb, num_clients);
+       ctdb->num_clients++;
 }