-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbexit.c
More file actions
78 lines (71 loc) · 1.91 KB
/
dbexit.c
File metadata and controls
78 lines (71 loc) · 1.91 KB
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
74
75
76
77
78
/*
* Copyright (c) 2016--2021 Wu, Xingbo <wuxb45@gmail.com>
*
* 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)
{
const struct kvmap_api * api = NULL;
void * map = NULL;
if (kvmap_api_helper(argc-1, argv+1, NULL, &api, &map) < 0) {
fprintf(stderr, "usage: api ...\n");
kvmap_api_helper_message();
exit(0);
}
if (!api->sync) {
fprintf(stderr, "api->sync is NULL. Abort.\n");
exit(0);
}
void * const ref = kvmap_ref(api, map);
void * const iter = api->iter_create(ref);
u32 kid = 0;
api->iter_seek(iter, kref_null());
api->iter_skip(iter, 1000);
struct kv * const tmp = malloc(2048);
while (api->iter_valid(iter)) {
kid += 1000;
struct kv * const kv = api->iter_peek(iter, NULL);
debug_assert(kv);
kv_refill_hex64(tmp, kid, "", 0);
if (!kv_match(tmp, kv)) {
printf("key mismatch at %u; clean up and restart the loop\n", kid);
exit(0);
}
free(kv);
api->iter_skip(iter, 1000);
}
u32 count = kid; // we already have that many keys, now check the last 1000
api->iter_seek(iter, kref_null());
api->iter_skip(iter, kid);
while (api->iter_valid(iter)) {
struct kv * const kv = api->iter_peek(iter, NULL);
debug_assert(kv);
kv_refill_hex64(tmp, count, "", 0);
if (!kv_match(tmp, kv)) {
printf("key mismatch at %u; clean up and restart loop again\n", count);
exit(0);
}
count++;
api->iter_skip1(iter);
free(kv);
}
printf("found %u keys. OK.\n", count);
api->iter_destroy(iter);
memset(tmp, 0x11, 2048);
#define NEW ((100000))
for (u64 i = 0; i < NEW; i++) {
kv_refill_hex64(tmp, count + i, "AAAAZZZZ", 8);
api->put(ref, tmp);
}
free(tmp);
printf("insert [%u, %u]; now exit()\n", count, count + NEW - 1);
api->sync(ref);
exit(0);
return 0;
}