ctdbd: Remove incomplete ctdb_db_statistics_wire structure
authorAmitay Isaacs <amitay@gmail.com>
Mon, 15 Jul 2013 05:24:11 +0000 (15:24 +1000)
committerAmitay Isaacs <amitay@gmail.com>
Mon, 29 Jul 2013 06:00:46 +0000 (16:00 +1000)
Instead of maintaining another structure, add an element as place holder for
marshall buffer of hot keys.  This avoids duplication of the structure.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
include/ctdb_protocol.h
libctdb/control.c
server/ctdb_ltdb_server.c

index 10f643bb7ff9b1e10533cf24667ca4970e75bb54..f72381f7db9d1c6722ec36012e5941b6a3e199cf 100644 (file)
@@ -714,10 +714,6 @@ struct ctdb_statistics_wire {
 /*
  * db statistics
  */
-struct ctdb_db_hot_key {
-       uint32_t count;
-       TDB_DATA key;
-};
 struct ctdb_db_statistics {
        struct {
                uint32_t num_calls;
@@ -731,14 +727,11 @@ struct ctdb_db_statistics {
        uint32_t db_ro_revokes;
        uint32_t hop_count_bucket[MAX_COUNT_BUCKETS];
        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];
+       struct {
+               uint32_t count;
+               TDB_DATA key;
+       } hot_keys[MAX_HOT_KEYS];
+       char hot_keys_wire[1];
 };
 
 /*
index 64cc80e3643958dc4fc23c9cd53ecb0ca1a47d58..447a1d1275c15ba5f719666178c14c776a98b17d 100644 (file)
@@ -124,8 +124,7 @@ 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;
+       struct ctdb_db_statistics *s, *wire;
        int i;
        char *ptr;
 
@@ -137,31 +136,21 @@ 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_wire, hot_keys)) {
+       if (reply->datalen < offsetof(struct ctdb_db_statistics, hot_keys_wire)) {
                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;
        }
 
-       wire = (struct ctdb_db_statistics_wire *)reply->data;
+       wire = (struct ctdb_db_statistics *)reply->data;
 
-       s = malloc(offsetof(struct ctdb_db_statistics, hot_keys) + sizeof(struct ctdb_db_hot_key) * wire->num_hot_keys);
+       s = malloc(sizeof(struct ctdb_db_statistics));
        if (!s) {
                return false;
        }
-       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 = *wire;
+       ptr = &wire->hot_keys_wire[0];
+       for (i = 0; i < wire->num_hot_keys; i++) {
                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;
index 6ad1ff5de11a24baff0fb2107a10f21d9ca642b9..1701483826b98256ecc879a14495dcb2107308f2 100644 (file)
@@ -1508,7 +1508,7 @@ int32_t ctdb_control_get_db_statistics(struct ctdb_context *ctdb,
                                TDB_DATA *outdata)
 {
        struct ctdb_db_context *ctdb_db;
-       struct ctdb_db_statistics_wire *stats;
+       struct ctdb_db_statistics *stats;
        int i;
        int len;
        char *ptr;
@@ -1519,33 +1519,25 @@ int32_t ctdb_control_get_db_statistics(struct ctdb_context *ctdb,
                return -1;
        }
 
-       len = offsetof(struct ctdb_db_statistics_wire, hot_keys);
+       len = offsetof(struct ctdb_db_statistics, hot_keys_wire);
        for (i = 0; i < MAX_HOT_KEYS; i++) {
-               len += 8 + ctdb_db->statistics.hot_keys[i].key.dsize;
+               len += 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"));
+               DEBUG(DEBUG_ERR,("Failed to allocate db statistics 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 = ctdb_db->statistics;
+
        stats->num_hot_keys = MAX_HOT_KEYS;
 
-       ptr = &stats->hot_keys[0];
+       ptr = &stats->hot_keys_wire[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);
+               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;
        }