daemon: Reset database statistics when resetting statistics
authorAmitay Isaacs <amitay@gmail.com>
Thu, 2 Apr 2015 02:53:09 +0000 (13:53 +1100)
committerAmitay Isaacs <amitay@gmail.com>
Fri, 7 Aug 2015 07:41:40 +0000 (17:41 +1000)
When the ctdb statistics is reset, reset per database statistics to keep
it consistent with ctdb statistics.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
(Imported from commit 7949ce103f2062aa703a24f72e11be96dc497a7a)

include/ctdb_private.h
server/ctdb_control.c
server/ctdb_ltdb_server.c

index 9f04fcd5219d86e06535f424b8fc373fb31e2be3..ccf20568ae3c609db4e31a71eec44b8651ecd407 100644 (file)
@@ -1559,6 +1559,8 @@ int ctdb_fetch_func(struct ctdb_call_info *call);
 
 int ctdb_fetch_with_header_func(struct ctdb_call_info *call);
 
+void ctdb_db_statistics_reset(struct ctdb_db_context *ctdb_db);
+
 int32_t ctdb_control_get_db_statistics(struct ctdb_context *ctdb,
                                uint32_t db_id,
                                TDB_DATA *outdata);
index 7cd57958ab36f4c2b65d6d12556361cab01fc9c8..a872e262a9276258d0ecb4fa91e96b5931c085b6 100644 (file)
@@ -151,8 +151,15 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
        }
 
        case CTDB_CONTROL_STATISTICS_RESET: {
+               struct ctdb_db_context *ctdb_db;
+
                CHECK_CONTROL_DATA_SIZE(0);
                ZERO_STRUCT(ctdb->statistics);
+               for (ctdb_db = ctdb->db_list;
+                    ctdb_db != NULL;
+                    ctdb_db = ctdb_db->next) {
+                       ctdb_db_statistics_reset(ctdb_db);
+               }
                ctdb->statistics.statistics_start_time = timeval_current();
                return 0;
        }
index a7ae81350fc36ec2a21821cd3f7d6f57544e4748..b4ac6df9464d65e4402dd728108ea45e6e9ff94a 100644 (file)
@@ -1600,6 +1600,20 @@ int ctdb_set_db_sticky(struct ctdb_context *ctdb, struct ctdb_db_context *ctdb_d
        return 0;
 }
 
+void ctdb_db_statistics_reset(struct ctdb_db_context *ctdb_db)
+{
+       struct ctdb_db_statistics *s = &ctdb_db->statistics;
+       int i;
+
+       for (i=0; i<MAX_HOT_KEYS; i++) {
+               if (s->hot_keys[i].key.dsize > 0) {
+                       talloc_free(s->hot_keys[i].key.dptr);
+               }
+       }
+
+       ZERO_STRUCT(ctdb_db->statistics);
+}
+
 int32_t ctdb_control_get_db_statistics(struct ctdb_context *ctdb,
                                uint32_t db_id,
                                TDB_DATA *outdata)