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:21:49 +0000 (14:21 +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>
(cherry picked from commit dc4ca816630ed44b419108da53421331243fb8c7)

server/ctdb_control.c
server/ctdb_daemon.c

index 5968b3e124c99c041bf76a5c1485640cd3ead89e..e01e046e3676e62d967c7adabe1ec4471c0d85e2 100644 (file)
@@ -101,6 +101,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) {
@@ -192,7 +193,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 b95995367cf29edd4883ef5ff9ad5429a43367df..300f3242940f5ae175dff7fefc7e358abc052891 100644 (file)
@@ -247,7 +247,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));
@@ -981,7 +981,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++;
 }