Skip to content

Commit 5c1745a

Browse files
committed
mdbx: добавление гистограммы количества multi-значений/дубликатов в chk.
1 parent 23a417f commit 5c1745a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

mdbx.h

+2
Original file line numberDiff line numberDiff line change
@@ -6541,6 +6541,8 @@ typedef struct MDBX_chk_table {
65416541
struct MDBX_chk_histogram key_len;
65426542
/// Values length histogram
65436543
struct MDBX_chk_histogram val_len;
6544+
/// Number of multi-values (aka duplicates) histogram
6545+
struct MDBX_chk_histogram multival;
65446546
} histogram;
65456547
} MDBX_chk_table_t;
65466548

src/chk.c

+18-1
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,7 @@ __cold static int chk_db(MDBX_chk_scope_t *const scope, MDBX_dbi dbi, MDBX_chk_t
11391139
const size_t maxkeysize = mdbx_env_get_maxkeysize_ex(env, tbl->flags);
11401140
MDBX_val prev_key = {nullptr, 0}, prev_data = {nullptr, 0};
11411141
MDBX_val key, data;
1142+
size_t dups_count = 0;
11421143
err = mdbx_cursor_get(cursor, &key, &data, MDBX_FIRST);
11431144
while (err == MDBX_SUCCESS) {
11441145
err = chk_check_break(scope);
@@ -1162,6 +1163,12 @@ __cold static int chk_db(MDBX_chk_scope_t *const scope, MDBX_dbi dbi, MDBX_chk_t
11621163
}
11631164

11641165
if (prev_key.iov_base) {
1166+
if (key.iov_base == prev_key.iov_base)
1167+
dups_count += 1;
1168+
else {
1169+
histogram_acc(dups_count, &tbl->histogram.multival);
1170+
dups_count = 0;
1171+
}
11651172
if (prev_data.iov_base && !bad_data && (tbl->flags & MDBX_DUPFIXED) && prev_data.iov_len != data.iov_len) {
11661173
chk_object_issue(scope, "entry", record_count, "different data length", "%" PRIuPTR " != %" PRIuPTR,
11671174
prev_data.iov_len, data.iov_len);
@@ -1248,17 +1255,27 @@ __cold static int chk_db(MDBX_chk_scope_t *const scope, MDBX_dbi dbi, MDBX_chk_t
12481255
err = mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT);
12491256
}
12501257

1258+
if (prev_key.iov_base)
1259+
histogram_acc(dups_count, &tbl->histogram.multival);
1260+
12511261
err = (err != MDBX_NOTFOUND) ? chk_error_rc(scope, err, "mdbx_cursor_get") : MDBX_SUCCESS;
12521262
if (err == MDBX_SUCCESS && record_count != db->items)
12531263
chk_scope_issue(scope, "different number of entries %" PRIuSIZE " != %" PRIu64, record_count, db->items);
12541264
bailout:
12551265
if (cursor) {
12561266
if (handler) {
1257-
if (tbl->histogram.key_len.count) {
1267+
if (record_count) {
12581268
MDBX_chk_line_t *line = chk_line_begin(scope, MDBX_chk_info);
12591269
line = histogram_dist(line, &tbl->histogram.key_len, "key length density", "0/1", false);
12601270
chk_line_feed(line);
12611271
line = histogram_dist(line, &tbl->histogram.val_len, "value length density", "0/1", false);
1272+
if (tbl->histogram.multival.amount) {
1273+
chk_line_feed(line);
1274+
line = histogram_dist(line, &tbl->histogram.multival, "number of multi-values density", "single", false);
1275+
chk_line_feed(line);
1276+
line = chk_print(line, "number of keys %" PRIuSIZE ", average values per key %.1f",
1277+
tbl->histogram.multival.count, record_count / (double)tbl->histogram.multival.count);
1278+
}
12621279
chk_line_end(line);
12631280
}
12641281
if (scope->stage == MDBX_chk_maindb)

0 commit comments

Comments
 (0)