-
Notifications
You must be signed in to change notification settings - Fork 24
/
xdbexit.c
73 lines (67 loc) · 1.81 KB
/
xdbexit.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* Copyright (c) 2016--2021 Wu, Xingbo <[email protected]>
*
* All rights reserved. No warranty, explicit or implicit, provided.
*/
#define _GNU_SOURCE
#include "lib.h"
#include "kv.h"
#include "sst.h"
#include "xdb.h"
int
main(int argc, char** argv)
{
if (argc < 4) {
printf("Usage: <dirname> <mt-mb> <cache-mb>\n");
return 0;
}
struct xdb * const xdb = remixdb_open(argv[1], a2u64(argv[2]), a2u64(argv[3]), true);
if (!xdb) {
fprintf(stderr, "xdb_open failed\n");
return 0;
}
struct xdb_ref * const ref = remixdb_ref(xdb);
struct xdb_iter * const iter = remixdb_iter_create(ref);
u64 kid = 0;
remixdb_iter_seek(iter, "", 0);
remixdb_iter_skip(iter, 1000);
u8 key[20];
u8 keycmp[20];
u32 klen = 0;
while (remixdb_iter_valid(iter)) {
kid += 1000;
remixdb_iter_peek(iter, key, &klen, NULL, NULL);
strdec_64(keycmp, kid);
if (memcmp(key, keycmp, 20)) {
printf("key mismatch at %lu; delete %s and restart the loop\n", kid, argv[1]);
exit(0);
}
remixdb_iter_skip(iter, 1000);
}
u64 count = kid;
remixdb_iter_seek(iter, "", 0);
remixdb_iter_skip(iter, kid);
while (remixdb_iter_valid(iter)) {
remixdb_iter_peek(iter, key, &klen, NULL, NULL);
remixdb_iter_skip1(iter);
strdec_64(keycmp, count);
count++;
if (memcmp(key, keycmp, 20)) {
printf("key mismatch at %lu; delete %s and restart loop again\n", count, argv[1]);
exit(0);
}
}
printf("found %lu keys, last %.20s OK\n", count, key);
remixdb_iter_destroy(iter);
u8 value[1024];
memset(value, 0x11, 1024);
#define NEW ((100000))
for (u64 i = 0; i < NEW; i++) {
strdec_64(key, count + i);
remixdb_put(ref, key, 20, value, 1024);
}
printf("insert [%lu, %lu]; now exit()\n", count, count + NEW - 1);
remixdb_sync(ref);
exit(0);
return 0;
}