Revert "ctdbd: Remove incomplete ctdb_db_statistics_wire structure"
authorAmitay Isaacs <amitay@gmail.com>
Mon, 15 Jul 2013 04:52:07 +0000 (14:52 +1000)
committerAmitay Isaacs <amitay@gmail.com>
Mon, 29 Jul 2013 06:00:46 +0000 (16:00 +1000)
The structure cannot be removed without adding support for marshalling keys
for hot records.

This reverts commit 26a4653df594d351ca0dc1bd5f5b2f5b0eb0a9a5.

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

ctdb/include/ctdb_private.h
ctdb/include/ctdb_protocol.h
ctdb/libctdb/control.c
ctdb/server/ctdb_control.c
ctdb/server/ctdb_ltdb_server.c

index cbaff97d919310cca1c8554d01aa8e5f68ed5214..9c78440c2a76ab991d4aa046d53536687f35125b 100644 (file)
@@ -1561,6 +1561,10 @@ int ctdb_fetch_func(struct ctdb_call_info *call);
 
 int ctdb_fetch_with_header_func(struct ctdb_call_info *call);
 
+int32_t ctdb_control_get_db_statistics(struct ctdb_context *ctdb,
+                               uint32_t db_id,
+                               TDB_DATA *outdata);
+
 int ctdb_set_db_sticky(struct ctdb_context *ctdb, struct ctdb_db_context *ctdb_db);
 
 /*
index 9e95f4db6ae460957699b7890ebe08b79318f026..10f643bb7ff9b1e10533cf24667ca4970e75bb54 100644 (file)
@@ -733,6 +733,13 @@ struct ctdb_db_statistics {
        uint32_t num_hot_keys;
        struct ctdb_db_hot_key hot_keys[MAX_HOT_KEYS];
 };
+struct ctdb_db_statistics_wire {
+       uint32_t db_ro_delegations;
+       uint32_t db_ro_revokes;
+       uint32_t hop_count_bucket[MAX_COUNT_BUCKETS];
+       uint32_t num_hot_keys;
+       char hot_keys[1];
+};
 
 /*
  * wire format for interface list
index 2a7db95787a3a0fc9ae13a3807dcef303c579115..64cc80e3643958dc4fc23c9cd53ecb0ca1a47d58 100644 (file)
@@ -124,6 +124,10 @@ bool ctdb_getdbstat_recv(struct ctdb_connection *ctdb,
                         struct ctdb_db_statistics **stat)
 {
        struct ctdb_reply_control *reply;
+       struct ctdb_db_statistics *s;
+       struct ctdb_db_statistics_wire *wire;
+       int i;
+       char *ptr;
 
        reply = unpack_reply_control(req, CTDB_CONTROL_GET_DB_STATISTICS);
        if (!reply) {
@@ -133,16 +137,37 @@ bool ctdb_getdbstat_recv(struct ctdb_connection *ctdb,
                DEBUG(ctdb, LOG_ERR, "ctdb_getpnn_recv: status -1");
                return false;
        }
-       if (reply->datalen < offsetof(struct ctdb_db_statistics, hot_keys)) {
+       if (reply->datalen < offsetof(struct ctdb_db_statistics_wire, hot_keys)) {
                DEBUG(ctdb, LOG_ERR, "ctdb_getdbstat_recv: returned data is %d bytes but should be >= %d", reply->datalen, (int)sizeof(struct ctdb_db_statistics));
                return false;
        }
 
-       *stat = malloc(reply->datalen);
-       if (*stat == NULL) {
+       wire = (struct ctdb_db_statistics_wire *)reply->data;
+
+       s = malloc(offsetof(struct ctdb_db_statistics, hot_keys) + sizeof(struct ctdb_db_hot_key) * wire->num_hot_keys);
+       if (!s) {
                return false;
        }
-       memcpy(*stat, reply->data, reply->datalen);
+       s->db_ro_delegations = wire->db_ro_delegations;
+       s->db_ro_revokes     = wire->db_ro_revokes;
+       for (i = 0; i < MAX_COUNT_BUCKETS; i++) {
+               s->hop_count_bucket[i] = wire->hop_count_bucket[i];
+       }
+       s->num_hot_keys      = wire->num_hot_keys;
+       ptr = &wire->hot_keys[0];
+       for (i = 0; i < wire->num_hot_keys; i++) {
+               s->hot_keys[i].count = *(uint32_t *)ptr;
+               ptr += 4;
+
+               s->hot_keys[i].key.dsize = *(uint32_t *)ptr;
+               ptr += 4;
+
+               s->hot_keys[i].key.dptr = malloc(s->hot_keys[i].key.dsize);
+               memcpy(s->hot_keys[i].key.dptr, ptr, s->hot_keys[i].key.dsize);
+               ptr += s->hot_keys[i].key.dsize;
+       }
+
+       *stat = s;
 
        return true;
 }
index 690608eef6b02807f51245da2adb869698a0bb88..a8771f317663be846679b8c57b5c5711c7ab4f0e 100644 (file)
@@ -651,18 +651,9 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
                CHECK_CONTROL_DATA_SIZE(size);
                return ctdb_control_schedule_for_deletion(ctdb, indata);
        }
-       case CTDB_CONTROL_GET_DB_STATISTICS: {
-               uint32_t db_id;
-               struct ctdb_db_context *ctdb_db;
-
-               CHECK_CONTROL_DATA_SIZE(sizeof(db_id));
-               db_id = *(uint32_t *)indata.dptr;
-               ctdb_db = find_ctdb_db(ctdb, db_id);
-               if (ctdb_db == NULL) return -1;
-               outdata->dptr = (uint8_t *)&ctdb_db->statistics;
-               outdata->dsize = sizeof(ctdb_db->statistics);
-               return 0;
-       }
+       case CTDB_CONTROL_GET_DB_STATISTICS:
+               CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
+               return ctdb_control_get_db_statistics(ctdb, *(uint32_t *)indata.dptr, outdata);
 
        case CTDB_CONTROL_RELOAD_PUBLIC_IPS:
                CHECK_CONTROL_DATA_SIZE(0);
index 57e0d68b71d868ce52c6b6a8108e689e0e5b6b6a..6ad1ff5de11a24baff0fb2107a10f21d9ca642b9 100644 (file)
@@ -1502,3 +1502,55 @@ int ctdb_set_db_sticky(struct ctdb_context *ctdb, struct ctdb_db_context *ctdb_d
 
        return 0;
 }
+
+int32_t ctdb_control_get_db_statistics(struct ctdb_context *ctdb,
+                               uint32_t db_id,
+                               TDB_DATA *outdata)
+{
+       struct ctdb_db_context *ctdb_db;
+       struct ctdb_db_statistics_wire *stats;
+       int i;
+       int len;
+       char *ptr;
+
+       ctdb_db = find_ctdb_db(ctdb, db_id);
+       if (!ctdb_db) {
+               DEBUG(DEBUG_ERR,("Unknown db_id 0x%x in get_db_statistics\n", db_id));
+               return -1;
+       }
+
+       len = offsetof(struct ctdb_db_statistics_wire, hot_keys);
+       for (i = 0; i < MAX_HOT_KEYS; i++) {
+               len += 8 + ctdb_db->statistics.hot_keys[i].key.dsize;
+       }
+
+       stats = talloc_size(outdata, len);
+       if (stats == NULL) {
+               DEBUG(DEBUG_ERR,("Failed to allocate db statistics wire structure\n"));
+               return -1;
+       }
+
+       stats->db_ro_delegations = ctdb_db->statistics.db_ro_delegations;
+       stats->db_ro_revokes     = ctdb_db->statistics.db_ro_revokes;
+       for (i = 0; i < MAX_COUNT_BUCKETS; i++) {
+               stats->hop_count_bucket[i] = ctdb_db->statistics.hop_count_bucket[i];
+       }
+       stats->num_hot_keys = MAX_HOT_KEYS;
+
+       ptr = &stats->hot_keys[0];
+       for (i = 0; i < MAX_HOT_KEYS; i++) {
+               *(uint32_t *)ptr = ctdb_db->statistics.hot_keys[i].count;
+               ptr += 4;
+
+               *(uint32_t *)ptr = ctdb_db->statistics.hot_keys[i].key.dsize;
+               ptr += 4;
+
+               memcpy(ptr, ctdb_db->statistics.hot_keys[i].key.dptr, ctdb_db->statistics.hot_keys[i].key.dsize);
+               ptr += ctdb_db->statistics.hot_keys[i].key.dsize;
+       }
+
+       outdata->dptr  = (uint8_t *)stats;
+       outdata->dsize = len;
+
+       return 0;
+}