/*
* db statistics
*/
-struct ctdb_db_hot_key {
- uint32_t count;
- TDB_DATA key;
-};
struct ctdb_db_statistics {
struct {
uint32_t num_calls;
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];
};
/*
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;
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;
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;
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;
}