sophia-ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.gitmodules +3 -0
  4. data/Gemfile +6 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +29 -0
  7. data/Rakefile +22 -0
  8. data/ext/extconf.rb +13 -0
  9. data/ext/sophia.c +220 -0
  10. data/lib/sophia-ruby.rb +1 -0
  11. data/lib/sophia/version.rb +3 -0
  12. data/sophia-ruby.gemspec +47 -0
  13. data/test/test_sophia.rb +33 -0
  14. data/vendor/sophia/.gitignore +18 -0
  15. data/vendor/sophia/COPYRIGHT +29 -0
  16. data/vendor/sophia/README +5 -0
  17. data/vendor/sophia/db/a.h +58 -0
  18. data/vendor/sophia/db/cat.c +195 -0
  19. data/vendor/sophia/db/cat.h +32 -0
  20. data/vendor/sophia/db/core.h +129 -0
  21. data/vendor/sophia/db/crc.c +343 -0
  22. data/vendor/sophia/db/crc.h +14 -0
  23. data/vendor/sophia/db/cursor.c +551 -0
  24. data/vendor/sophia/db/cursor.h +47 -0
  25. data/vendor/sophia/db/e.c +49 -0
  26. data/vendor/sophia/db/e.h +49 -0
  27. data/vendor/sophia/db/file.c +355 -0
  28. data/vendor/sophia/db/file.h +106 -0
  29. data/vendor/sophia/db/gc.c +71 -0
  30. data/vendor/sophia/db/gc.h +14 -0
  31. data/vendor/sophia/db/i.c +368 -0
  32. data/vendor/sophia/db/i.h +155 -0
  33. data/vendor/sophia/db/list.h +91 -0
  34. data/vendor/sophia/db/lock.h +77 -0
  35. data/vendor/sophia/db/macro.h +20 -0
  36. data/vendor/sophia/db/makefile +44 -0
  37. data/vendor/sophia/db/merge.c +662 -0
  38. data/vendor/sophia/db/merge.h +14 -0
  39. data/vendor/sophia/db/meta.h +87 -0
  40. data/vendor/sophia/db/recover.c +433 -0
  41. data/vendor/sophia/db/recover.h +14 -0
  42. data/vendor/sophia/db/ref.h +111 -0
  43. data/vendor/sophia/db/rep.c +128 -0
  44. data/vendor/sophia/db/rep.h +120 -0
  45. data/vendor/sophia/db/sophia.h +84 -0
  46. data/vendor/sophia/db/sp.c +626 -0
  47. data/vendor/sophia/db/sp.h +50 -0
  48. data/vendor/sophia/db/task.h +70 -0
  49. data/vendor/sophia/db/track.h +99 -0
  50. data/vendor/sophia/db/util.c +105 -0
  51. data/vendor/sophia/db/util.h +25 -0
  52. data/vendor/sophia/makefile +7 -0
  53. data/vendor/sophia/sophia.gyp +30 -0
  54. data/vendor/sophia/test/common.c +870 -0
  55. data/vendor/sophia/test/crash.c +492 -0
  56. data/vendor/sophia/test/i.c +403 -0
  57. data/vendor/sophia/test/limit.c +65 -0
  58. data/vendor/sophia/test/makefile +30 -0
  59. data/vendor/sophia/test/merge.c +890 -0
  60. data/vendor/sophia/test/recover.c +1550 -0
  61. data/vendor/sophia/test/test.h +66 -0
  62. metadata +134 -0
@@ -0,0 +1,1550 @@
1
+
2
+ /*
3
+ * sophia database
4
+ * sphia.org
5
+ *
6
+ * Copyright (c) Dmitry Simonenko
7
+ * BSD License
8
+ */
9
+
10
+ #include <sophia.h>
11
+ #include "test.h"
12
+
13
+ static char *dbrep = "./rep";
14
+
15
+ static inline int
16
+ cmp(char *a, size_t asz, char *b, size_t bsz, void *arg) {
17
+ register uint32_t av = *(uint32_t*)a;
18
+ register uint32_t bv = *(uint32_t*)b;
19
+ if (av == bv)
20
+ return 0;
21
+ return (av > bv) ? 1 : -1;
22
+ }
23
+
24
+ static void
25
+ recover_log_set_get(void) {
26
+ void *env = sp_env();
27
+ t( env != NULL );
28
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
29
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
30
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
31
+ void *db = sp_open(env);
32
+ t( db != NULL );
33
+ uint32_t k = 1, v = 1;
34
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
35
+ k = 2;
36
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
37
+ k = 3;
38
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
39
+ t( sp_destroy(db) == 0 );
40
+ db = sp_open(env);
41
+ t( db != NULL );
42
+ size_t vsize = 0;
43
+ void *vp = NULL;
44
+ k = 1;
45
+ t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
46
+ t( vsize == sizeof(v) );
47
+ t( *(uint32_t*)vp == v );
48
+ free(vp);
49
+ k = 2;
50
+ t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
51
+ t( vsize == sizeof(v) );
52
+ t( *(uint32_t*)vp == v );
53
+ free(vp);
54
+ k = 3;
55
+ t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
56
+ t( vsize == sizeof(v) );
57
+ t( *(uint32_t*)vp == v );
58
+ free(vp);
59
+ t( sp_destroy(db) == 0 );
60
+ t( sp_destroy(env) == 0 );
61
+ t( rmrf(dbrep) == 0 );
62
+ }
63
+
64
+ static void
65
+ recover_log_replace_get(void) {
66
+ void *env = sp_env();
67
+ t( env != NULL );
68
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
69
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
70
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
71
+ void *db = sp_open(env);
72
+ t( db != NULL );
73
+ uint32_t k = 1, v = 1;
74
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
75
+ v = 2;
76
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
77
+ v = 3;
78
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
79
+ t( sp_destroy(db) == 0 );
80
+ db = sp_open(env);
81
+ t( db != NULL );
82
+ size_t vsize = 0;
83
+ void *vp = NULL;
84
+ k = 1;
85
+ t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
86
+ t( vsize == sizeof(v) );
87
+ t( *(uint32_t*)vp == 3 );
88
+ free(vp);
89
+ t( sp_destroy(db) == 0 );
90
+ t( sp_destroy(env) == 0 );
91
+ t( rmrf(dbrep) == 0 );
92
+ }
93
+
94
+ static void
95
+ recover_log_set_get_replace_get(void) {
96
+ void *env = sp_env();
97
+ t( env != NULL );
98
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
99
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
100
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
101
+ void *db = sp_open(env);
102
+ t( db != NULL );
103
+ uint32_t k = 1, v = 1;
104
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
105
+ t( sp_destroy(db) == 0 );
106
+ db = sp_open(env);
107
+ t( db != NULL );
108
+ size_t vsize = 0;
109
+ void *vp = NULL;
110
+ k = 1;
111
+ t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
112
+ t( vsize == sizeof(v) );
113
+ t( *(uint32_t*)vp == 1 );
114
+ free(vp);
115
+ v = 2;
116
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
117
+ vsize = 0;
118
+ vp = NULL;
119
+ t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
120
+ t( vsize == sizeof(v) );
121
+ t( *(uint32_t*)vp == 2 );
122
+ free(vp);
123
+ t( sp_destroy(db) == 0 );
124
+ db = sp_open(env);
125
+ t( db != NULL );
126
+ vsize = 0;
127
+ vp = NULL;
128
+ k = 1;
129
+ t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
130
+ t( vsize == sizeof(v) );
131
+ t( *(uint32_t*)vp == 2 );
132
+ free(vp);
133
+ t( sp_destroy(db) == 0 );
134
+ t( sp_destroy(env) == 0 );
135
+ t( rmrf(dbrep) == 0 );
136
+ }
137
+
138
+ static void
139
+ recover_log_delete_get(void) {
140
+ void *env = sp_env();
141
+ t( env != NULL );
142
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
143
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
144
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
145
+ void *db = sp_open(env);
146
+ t( db != NULL );
147
+ uint32_t k = 1, v = 1;
148
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
149
+ t( sp_delete(db, &k, sizeof(k)) == 0 );
150
+ t( sp_destroy(db) == 0 );
151
+ db = sp_open(env);
152
+ t( db != NULL );
153
+ size_t vsize = 0;
154
+ void *vp = NULL;
155
+ t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 0 );
156
+ t( sp_destroy(db) == 0 );
157
+ t( sp_destroy(env) == 0 );
158
+ t( rmrf(dbrep) == 0 );
159
+ }
160
+
161
+ static void
162
+ recover_log_delete_set_get(void) {
163
+ void *env = sp_env();
164
+ t( env != NULL );
165
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
166
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
167
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
168
+ void *db = sp_open(env);
169
+ t( db != NULL );
170
+ uint32_t k = 1, v = 1;
171
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
172
+ t( sp_delete(db, &k, sizeof(k)) == 0 );
173
+ t( sp_destroy(db) == 0 );
174
+ db = sp_open(env);
175
+ t( db != NULL );
176
+ size_t vsize = 0;
177
+ void *vp = NULL;
178
+ t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 0 );
179
+ v = 2;
180
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
181
+ t( sp_destroy(db) == 0 );
182
+ db = sp_open(env);
183
+ t( db != NULL );
184
+ vsize = 0;
185
+ vp = NULL;
186
+ t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
187
+ t( vsize == sizeof(v) );
188
+ t( *(uint32_t*)vp == 2 );
189
+ free(vp);
190
+ t( sp_destroy(db) == 0 );
191
+ t( sp_destroy(env) == 0 );
192
+ t( rmrf(dbrep) == 0 );
193
+ }
194
+
195
+ static void
196
+ recover_log_fetch_gte(void) {
197
+ void *env = sp_env();
198
+ t( env != NULL );
199
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
200
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
201
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
202
+ void *db = sp_open(env);
203
+ t( db != NULL );
204
+ uint32_t k = 1, v = 2;
205
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
206
+ k = 2;
207
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
208
+ k = 3;
209
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
210
+ t( sp_destroy(db) == 0 );
211
+ db = sp_open(env);
212
+ t( db != NULL );
213
+ void *cur = sp_cursor(db, SPGTE, NULL, 0);
214
+ t( cur != NULL );
215
+ t( sp_fetch(cur) == 1 );
216
+ t( *(uint32_t*)sp_key(cur) == 1 );
217
+ t( sp_keysize(cur) == sizeof(k) );
218
+ t( *(uint32_t*)sp_value(cur) == 2 );
219
+ t( sp_valuesize(cur) == sizeof(v) );
220
+ t( sp_fetch(cur) == 1 );
221
+ t( *(uint32_t*)sp_key(cur) == 2 );
222
+ t( sp_keysize(cur) == sizeof(k) );
223
+ t( *(uint32_t*)sp_value(cur) == 2 );
224
+ t( sp_valuesize(cur) == sizeof(v) );
225
+ t( sp_fetch(cur) == 1 );
226
+ t( *(uint32_t*)sp_key(cur) == 3 );
227
+ t( sp_keysize(cur) == sizeof(k) );
228
+ t( *(uint32_t*)sp_value(cur) == 2 );
229
+ t( sp_valuesize(cur) == sizeof(v) );
230
+ t( sp_fetch(cur) == 0 );
231
+ t( sp_fetch(cur) == 0 );
232
+ t( sp_destroy(cur) == 0 );
233
+ t( sp_destroy(db) == 0 );
234
+ t( sp_destroy(env) == 0 );
235
+ t( rmrf(dbrep) == 0 );
236
+ }
237
+
238
+ static void
239
+ recover_log_fetch_lte(void) {
240
+ void *env = sp_env();
241
+ t( env != NULL );
242
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
243
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
244
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
245
+ void *db = sp_open(env);
246
+ t( db != NULL );
247
+ uint32_t k = 1, v = 2;
248
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
249
+ k = 2;
250
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
251
+ k = 3;
252
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
253
+ t( sp_destroy(db) == 0 );
254
+ db = sp_open(env);
255
+ t( db != NULL );
256
+ void *cur = sp_cursor(db, SPLTE, NULL, 0);
257
+ t( cur != NULL );
258
+ t( sp_fetch(cur) == 1 );
259
+ t( *(uint32_t*)sp_key(cur) == 3 );
260
+ t( sp_keysize(cur) == sizeof(k) );
261
+ t( *(uint32_t*)sp_value(cur) == 2 );
262
+ t( sp_valuesize(cur) == sizeof(v) );
263
+ t( sp_fetch(cur) == 1 );
264
+ t( *(uint32_t*)sp_key(cur) == 2 );
265
+ t( sp_keysize(cur) == sizeof(k) );
266
+ t( *(uint32_t*)sp_value(cur) == 2 );
267
+ t( sp_valuesize(cur) == sizeof(v) );
268
+ t( sp_fetch(cur) == 1 );
269
+ t( *(uint32_t*)sp_key(cur) == 1 );
270
+ t( sp_keysize(cur) == sizeof(k) );
271
+ t( *(uint32_t*)sp_value(cur) == 2 );
272
+ t( sp_valuesize(cur) == sizeof(v) );
273
+ t( sp_fetch(cur) == 0 );
274
+ t( sp_fetch(cur) == 0 );
275
+ t( sp_destroy(cur) == 0 );
276
+ t( sp_destroy(db) == 0 );
277
+ t( sp_destroy(env) == 0 );
278
+ t( rmrf(dbrep) == 0 );
279
+ }
280
+
281
+ static void
282
+ recover_log_fetch_kgte(void) {
283
+ void *env = sp_env();
284
+ t( env != NULL );
285
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
286
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
287
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
288
+ void *db = sp_open(env);
289
+ t( db != NULL );
290
+ uint32_t k = 1, v = 2;
291
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
292
+ k = 2;
293
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
294
+ k = 3;
295
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
296
+ t( sp_destroy(db) == 0 );
297
+ db = sp_open(env);
298
+ t( db != NULL );
299
+ k = 2;
300
+ void *cur = sp_cursor(db, SPGTE, &k, sizeof(k));
301
+ t( cur != NULL );
302
+ t( sp_fetch(cur) == 1 );
303
+ t( *(uint32_t*)sp_key(cur) == 2 );
304
+ t( sp_keysize(cur) == sizeof(k) );
305
+ t( *(uint32_t*)sp_value(cur) == 2 );
306
+ t( sp_valuesize(cur) == sizeof(v) );
307
+ t( sp_fetch(cur) == 1 );
308
+ t( *(uint32_t*)sp_key(cur) == 3 );
309
+ t( sp_keysize(cur) == sizeof(k) );
310
+ t( *(uint32_t*)sp_value(cur) == 2 );
311
+ t( sp_valuesize(cur) == sizeof(v) );
312
+ t( sp_fetch(cur) == 0 );
313
+ t( sp_fetch(cur) == 0 );
314
+ t( sp_destroy(cur) == 0 );
315
+ t( sp_destroy(db) == 0 );
316
+ t( sp_destroy(env) == 0 );
317
+ t( rmrf(dbrep) == 0 );
318
+ }
319
+
320
+ static void
321
+ recover_log_fetch_kgt(void) {
322
+ void *env = sp_env();
323
+ t( env != NULL );
324
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
325
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
326
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
327
+ void *db = sp_open(env);
328
+ t( db != NULL );
329
+ uint32_t k = 1, v = 2;
330
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
331
+ k = 2;
332
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
333
+ k = 3;
334
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
335
+ t( sp_destroy(db) == 0 );
336
+ db = sp_open(env);
337
+ t( db != NULL );
338
+ k = 2;
339
+ void *cur = sp_cursor(db, SPGT, &k, sizeof(k));
340
+ t( cur != NULL );
341
+ t( sp_fetch(cur) == 1 );
342
+ t( *(uint32_t*)sp_key(cur) == 3 );
343
+ t( sp_keysize(cur) == sizeof(k) );
344
+ t( *(uint32_t*)sp_value(cur) == 2 );
345
+ t( sp_valuesize(cur) == sizeof(v) );
346
+ t( sp_fetch(cur) == 0 );
347
+ t( sp_fetch(cur) == 0 );
348
+ t( sp_destroy(cur) == 0 );
349
+ t( sp_destroy(db) == 0 );
350
+ t( sp_destroy(env) == 0 );
351
+ t( rmrf(dbrep) == 0 );
352
+ }
353
+
354
+ static void
355
+ recover_log_fetch_klte(void) {
356
+ void *env = sp_env();
357
+ t( env != NULL );
358
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
359
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
360
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
361
+ void *db = sp_open(env);
362
+ t( db != NULL );
363
+ uint32_t k = 1, v = 2;
364
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
365
+ k = 2;
366
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
367
+ k = 3;
368
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
369
+ t( sp_destroy(db) == 0 );
370
+ db = sp_open(env);
371
+ t( db != NULL );
372
+ k = 2;
373
+ void *cur = sp_cursor(db, SPLTE, &k, sizeof(k));
374
+ t( cur != NULL );
375
+ t( sp_fetch(cur) == 1 );
376
+ t( *(uint32_t*)sp_key(cur) == 2 );
377
+ t( sp_keysize(cur) == sizeof(k) );
378
+ t( *(uint32_t*)sp_value(cur) == 2 );
379
+ t( sp_valuesize(cur) == sizeof(v) );
380
+ t( sp_fetch(cur) == 1 );
381
+ t( *(uint32_t*)sp_key(cur) == 1 );
382
+ t( sp_keysize(cur) == sizeof(k) );
383
+ t( *(uint32_t*)sp_value(cur) == 2 );
384
+ t( sp_valuesize(cur) == sizeof(v) );
385
+ t( sp_fetch(cur) == 0 );
386
+ t( sp_fetch(cur) == 0 );
387
+ t( sp_destroy(cur) == 0 );
388
+ t( sp_destroy(db) == 0 );
389
+ t( sp_destroy(env) == 0 );
390
+ t( rmrf(dbrep) == 0 );
391
+ }
392
+
393
+ static void
394
+ recover_log_fetch_klt(void) {
395
+ void *env = sp_env();
396
+ t( env != NULL );
397
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
398
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
399
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
400
+ void *db = sp_open(env);
401
+ t( db != NULL );
402
+ uint32_t k = 1, v = 2;
403
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
404
+ k = 2;
405
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
406
+ k = 3;
407
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
408
+ t( sp_destroy(db) == 0 );
409
+ db = sp_open(env);
410
+ t( db != NULL );
411
+ k = 2;
412
+ void *cur = sp_cursor(db, SPLT, &k, sizeof(k));
413
+ t( cur != NULL );
414
+ t( sp_fetch(cur) == 1 );
415
+ t( *(uint32_t*)sp_key(cur) == 1 );
416
+ t( sp_keysize(cur) == sizeof(k) );
417
+ t( *(uint32_t*)sp_value(cur) == 2 );
418
+ t( sp_valuesize(cur) == sizeof(v) );
419
+ t( sp_fetch(cur) == 0 );
420
+ t( sp_keysize(cur) == 0 );
421
+ t( sp_key(cur) == NULL );
422
+ t( sp_valuesize(cur) == 0 );
423
+ t( sp_value(cur) == NULL );
424
+ t( sp_fetch(cur) == 0 );
425
+ t( sp_keysize(cur) == 0 );
426
+ t( sp_key(cur) == NULL );
427
+ t( sp_valuesize(cur) == 0 );
428
+ t( sp_value(cur) == NULL );
429
+ t( sp_destroy(cur) == 0 );
430
+ t( sp_destroy(db) == 0 );
431
+ t( sp_destroy(env) == 0 );
432
+ t( rmrf(dbrep) == 0 );
433
+ }
434
+
435
+ static void
436
+ recover_log_n_get(void) {
437
+ void *env = sp_env();
438
+ t( env != NULL );
439
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
440
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
441
+ t( sp_ctl(env, SPGC, 0) == 0 );
442
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
443
+ void *db = sp_open(env);
444
+ t( db != NULL );
445
+ uint32_t k = 0, v;
446
+ while (k < 12) {
447
+ v = k;
448
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
449
+ k++;
450
+ }
451
+ t( sp_destroy(db) == 0 );
452
+ t( exists(dbrep, 1, "log") == 1 );
453
+ db = sp_open(env);
454
+ t( db != NULL );
455
+ k = 0;
456
+ while (k < 12) {
457
+ size_t vsize = 0;
458
+ void *vp = NULL;
459
+ t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
460
+ t( vsize == sizeof(v) );
461
+ t( *(uint32_t*)vp == k );
462
+ free(vp);
463
+ k++;
464
+ }
465
+ t( sp_destroy(db) == 0 );
466
+ t( sp_destroy(env) == 0 );
467
+ t( rmrf(dbrep) == 0 );
468
+ }
469
+
470
+ static void
471
+ recover_log_n_replace(void) {
472
+ void *env = sp_env();
473
+ t( env != NULL );
474
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
475
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
476
+ t( sp_ctl(env, SPGC, 0) == 0 );
477
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
478
+ void *db = sp_open(env);
479
+ t( exists(dbrep, 1, "log.incomplete") == 1 );
480
+ t( db != NULL );
481
+ uint32_t k = 0, v = 1;
482
+ while (k < 12) {
483
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
484
+ k++;
485
+ }
486
+ k = 0;
487
+ v = 2;
488
+ while (k < 12) {
489
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
490
+ k++;
491
+ }
492
+ t( sp_destroy(db) == 0 );
493
+ t( exists(dbrep, 1, "log") == 1 );
494
+ db = sp_open(env);
495
+ t( exists(dbrep, 1, "log") == 1 );
496
+ t( exists(dbrep, 2, "log.incomplete") == 1 );
497
+ t( db != NULL );
498
+ k = 0;
499
+ while (k < 12) {
500
+ size_t vsize = 0;
501
+ void *vp = NULL;
502
+ t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
503
+ t( vsize == sizeof(v) );
504
+ t( *(uint32_t*)vp == 2 );
505
+ free(vp);
506
+ k++;
507
+ }
508
+ t( sp_destroy(db) == 0 );
509
+ t( exists(dbrep, 1, "log") == 1 );
510
+ t( exists(dbrep, 2, "log") == 0 );
511
+ t( exists(dbrep, 2, "log.incomplete") == 0 );
512
+ t( sp_destroy(env) == 0 );
513
+ t( rmrf(dbrep) == 0 );
514
+ }
515
+
516
+ static void
517
+ recover_page_set_get(void) {
518
+ void *env = sp_env();
519
+ t( env != NULL );
520
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
521
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
522
+ t( sp_ctl(env, SPGC, 0) == 0 );
523
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
524
+ void *db = sp_open(env);
525
+ t( db != NULL );
526
+ uint32_t k = 1, v = 1;
527
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
528
+ k = 2;
529
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
530
+ k = 3;
531
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
532
+ t( sp_ctl(db, SPMERGEFORCE) == 0 );
533
+
534
+ t( exists(dbrep, 1, "log.incomplete") == 0 );
535
+ t( exists(dbrep, 1, "log") == 0 );
536
+ t( exists(dbrep, 1, "db") == 1 );
537
+ t( exists(dbrep, 2, "log.incomplete") == 1 );
538
+ t( sp_destroy(db) == 0 );
539
+ t( exists(dbrep, 1, "db") == 1 );
540
+ t( exists(dbrep, 2, "log") == 0 );
541
+ t( exists(dbrep, 2, "log.incomplete") == 0 );
542
+ db = sp_open(env);
543
+ t( db != NULL );
544
+ size_t vsize = 0;
545
+ void *vp = NULL;
546
+ k = 1;
547
+ t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
548
+ t( vsize == sizeof(v) );
549
+ t( *(uint32_t*)vp == v );
550
+ free(vp);
551
+ k = 2;
552
+ t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
553
+ t( vsize == sizeof(v) );
554
+ t( *(uint32_t*)vp == v );
555
+ free(vp);
556
+ k = 3;
557
+ t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
558
+ t( vsize == sizeof(v) );
559
+ t( *(uint32_t*)vp == v );
560
+ free(vp);
561
+ t( sp_destroy(db) == 0 );
562
+ t( sp_destroy(env) == 0 );
563
+ t( rmrf(dbrep) == 0 );
564
+ }
565
+
566
+ static void
567
+ recover_page_replace_get(void) {
568
+ void *env = sp_env();
569
+ t( env != NULL );
570
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
571
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
572
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
573
+ t( sp_ctl(env, SPGC, 0) == 0 );
574
+ void *db = sp_open(env);
575
+ t( db != NULL );
576
+ uint32_t k = 1, v = 1;
577
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
578
+ v = 2;
579
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
580
+ v = 3;
581
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
582
+ t( sp_ctl(db, SPMERGEFORCE) == 0 );
583
+ t( exists(dbrep, 1, "log.incomplete") == 0 );
584
+ t( exists(dbrep, 1, "log") == 0 );
585
+ t( exists(dbrep, 2, "log.incomplete") == 1 );
586
+ t( exists(dbrep, 2, "log") == 0 );
587
+ t( exists(dbrep, 1, "db") == 1 );
588
+ t( sp_destroy(db) == 0 );
589
+ db = sp_open(env);
590
+ t( db != NULL );
591
+ size_t vsize = 0;
592
+ void *vp = NULL;
593
+ k = 1;
594
+ t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
595
+ t( vsize == sizeof(v) );
596
+ t( *(uint32_t*)vp == 3 );
597
+ free(vp);
598
+ t( sp_destroy(db) == 0 );
599
+ t( sp_destroy(env) == 0 );
600
+ t( rmrf(dbrep) == 0 );
601
+ }
602
+
603
+ static void
604
+ recover_page_set_get_replace_get(void) {
605
+ void *env = sp_env();
606
+ t( env != NULL );
607
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
608
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
609
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
610
+ t( sp_ctl(env, SPGC, 0) == 0 );
611
+ void *db = sp_open(env);
612
+ t( db != NULL );
613
+ uint32_t k = 1, v = 1;
614
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
615
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
616
+ v = 8;
617
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
618
+ t( sp_ctl(db, SPMERGEFORCE) == 0 );
619
+ t( sp_destroy(db) == 0 );
620
+ db = sp_open(env);
621
+ t( db != NULL );
622
+ size_t vsize = 0;
623
+ void *vp = NULL;
624
+ k = 1;
625
+ t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
626
+ t( vsize == sizeof(v) );
627
+ t( *(uint32_t*)vp == 8 );
628
+ free(vp);
629
+ v = 2;
630
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
631
+ k = 2;
632
+ v = 3;
633
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
634
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
635
+ vsize = 0;
636
+ vp = NULL;
637
+ t( sp_ctl(db, SPMERGEFORCE) == 0 );
638
+ k = 1;
639
+ t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
640
+ t( vsize == sizeof(v) );
641
+ t( *(uint32_t*)vp == 2 );
642
+ free(vp);
643
+ k = 2;
644
+ t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
645
+ t( vsize == sizeof(v) );
646
+ t( *(uint32_t*)vp == 3 );
647
+ free(vp);
648
+ t( sp_destroy(db) == 0 );
649
+ db = sp_open(env);
650
+ t( db != NULL );
651
+ vsize = 0;
652
+ vp = NULL;
653
+ k = 1;
654
+ t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
655
+ t( vsize == sizeof(v) );
656
+ t( *(uint32_t*)vp == 2 );
657
+ free(vp);
658
+ k = 2;
659
+ t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
660
+ t( vsize == sizeof(v) );
661
+ t( *(uint32_t*)vp == 3 );
662
+ free(vp);
663
+ t( sp_destroy(db) == 0 );
664
+ t( sp_destroy(env) == 0 );
665
+ t( rmrf(dbrep) == 0 );
666
+ }
667
+
668
+ static void
669
+ recover_page_delete_get(void) {
670
+ void *env = sp_env();
671
+ t( env != NULL );
672
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
673
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
674
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
675
+ t( sp_ctl(env, SPGC, 0) == 0 );
676
+ void *db = sp_open(env);
677
+ t( db != NULL );
678
+ uint32_t k = 1, v = 1;
679
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
680
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
681
+ t( sp_delete(db, &k, sizeof(k)) == 0 );
682
+ t( sp_ctl(db, SPMERGEFORCE) == 0 );
683
+ t( exists(dbrep, 1, "log.incomplete") == 0 );
684
+ t( exists(dbrep, 1, "log") == 0 );
685
+ t( exists(dbrep, 1, "db.incomplete") == 0 );
686
+ t( exists(dbrep, 1, "db") == 0 );
687
+ t( exists(dbrep, 2, "log.incomplete") == 1 );
688
+ t( exists(dbrep, 2, "log") == 0 );
689
+ t( sp_destroy(db) == 0 );
690
+ db = sp_open(env);
691
+ t( db != NULL );
692
+ size_t vsize = 0;
693
+ void *vp = NULL;
694
+ t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 0 );
695
+ t( sp_destroy(db) == 0 );
696
+ t( sp_destroy(env) == 0 );
697
+ t( rmrf(dbrep) == 0 );
698
+ }
699
+
700
+ static void
701
+ recover_page_delete_set_get(void) {
702
+ void *env = sp_env();
703
+ t( env != NULL );
704
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
705
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
706
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
707
+ t( sp_ctl(env, SPGC, 0) == 0 );
708
+ void *db = sp_open(env);
709
+ t( db != NULL );
710
+ uint32_t k = 1, v = 1;
711
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
712
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
713
+ t( sp_delete(db, &k, sizeof(k)) == 0 );
714
+ t( sp_ctl(db, SPMERGEFORCE) == 0 );
715
+ t( exists(dbrep, 1, "log.incomplete") == 0 );
716
+ t( exists(dbrep, 1, "log") == 0 );
717
+ t( exists(dbrep, 1, "db.incomplete") == 0 );
718
+ t( exists(dbrep, 1, "db") == 0 );
719
+ t( exists(dbrep, 2, "log.incomplete") == 1 );
720
+ t( exists(dbrep, 2, "log") == 0 );
721
+ t( sp_destroy(db) == 0 );
722
+ t( exists(dbrep, 1, "log.incomplete") == 0 );
723
+ t( exists(dbrep, 1, "log") == 0 );
724
+ t( exists(dbrep, 1, "db.incomplete") == 0 );
725
+ t( exists(dbrep, 1, "db") == 0 );
726
+ t( exists(dbrep, 2, "log.incomplete") == 0 );
727
+ t( exists(dbrep, 2, "log") == 0 );
728
+ db = sp_open(env);
729
+ t( db != NULL );
730
+ size_t vsize = 0;
731
+ void *vp = NULL;
732
+ t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 0 );
733
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
734
+ k = 2;
735
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
736
+ t( sp_delete(db, &k, sizeof(k)) == 0 );
737
+ t( sp_ctl(db, SPMERGEFORCE) == 0 );
738
+ t( exists(dbrep, 1, "log.incomplete") == 0 );
739
+ t( exists(dbrep, 1, "log") == 0 );
740
+ t( exists(dbrep, 1, "db.incomplete") == 0 );
741
+ t( exists(dbrep, 1, "db") == 1 );
742
+ t( exists(dbrep, 2, "log.incomplete") == 1 );
743
+ t( exists(dbrep, 2, "log") == 0 );
744
+ t( sp_destroy(db) == 0 );
745
+ db = sp_open(env);
746
+ t( db != NULL );
747
+ vsize = 0;
748
+ vp = NULL;
749
+ k = 1;
750
+ t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
751
+ t( vsize == sizeof(v) );
752
+ t( *(uint32_t*)vp == 1 );
753
+ free(vp);
754
+ k = 2;
755
+ t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 0 );
756
+ t( sp_destroy(db) == 0 );
757
+ t( sp_destroy(env) == 0 );
758
+ t( rmrf(dbrep) == 0 );
759
+ }
760
+
761
+ static void
762
+ recover_page_fetch_gte(void) {
763
+ void *env = sp_env();
764
+ t( env != NULL );
765
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
766
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
767
+ t( sp_ctl(env, SPGC, 0) == 0 );
768
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
769
+ void *db = sp_open(env);
770
+ t( db != NULL );
771
+ uint32_t k = 1, v = 2;
772
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
773
+ k = 2;
774
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
775
+ k = 3;
776
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
777
+ t( sp_ctl(db, SPMERGEFORCE) == 0 );
778
+ t( sp_destroy(db) == 0 );
779
+ db = sp_open(env);
780
+ t( db != NULL );
781
+ void *cur = sp_cursor(db, SPGTE, NULL, 0);
782
+ t( cur != NULL );
783
+ t( sp_fetch(cur) == 1 );
784
+ t( *(uint32_t*)sp_key(cur) == 1 );
785
+ t( sp_keysize(cur) == sizeof(k) );
786
+ t( *(uint32_t*)sp_value(cur) == 2 );
787
+ t( sp_valuesize(cur) == sizeof(v) );
788
+ t( sp_fetch(cur) == 1 );
789
+ t( *(uint32_t*)sp_key(cur) == 2 );
790
+ t( sp_keysize(cur) == sizeof(k) );
791
+ t( *(uint32_t*)sp_value(cur) == 2 );
792
+ t( sp_valuesize(cur) == sizeof(v) );
793
+ t( sp_fetch(cur) == 1 );
794
+ t( *(uint32_t*)sp_key(cur) == 3 );
795
+ t( sp_keysize(cur) == sizeof(k) );
796
+ t( *(uint32_t*)sp_value(cur) == 2 );
797
+ t( sp_valuesize(cur) == sizeof(v) );
798
+ t( sp_fetch(cur) == 0 );
799
+ t( sp_fetch(cur) == 0 );
800
+ t( sp_destroy(cur) == 0 );
801
+ t( sp_destroy(db) == 0 );
802
+ t( sp_destroy(env) == 0 );
803
+ t( rmrf(dbrep) == 0 );
804
+ }
805
+
806
+ static void
807
+ recover_page_fetch_lte(void) {
808
+ void *env = sp_env();
809
+ t( env != NULL );
810
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
811
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
812
+ t( sp_ctl(env, SPGC, 0) == 0 );
813
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
814
+ void *db = sp_open(env);
815
+ t( db != NULL );
816
+ uint32_t k = 1, v = 2;
817
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
818
+ k = 2;
819
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
820
+ k = 3;
821
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
822
+ t( sp_ctl(db, SPMERGEFORCE) == 0 );
823
+ t( sp_destroy(db) == 0 );
824
+ db = sp_open(env);
825
+ t( db != NULL );
826
+ void *cur = sp_cursor(db, SPLTE, NULL, 0);
827
+ t( cur != NULL );
828
+ t( sp_fetch(cur) == 1 );
829
+ t( *(uint32_t*)sp_key(cur) == 3 );
830
+ t( sp_keysize(cur) == sizeof(k) );
831
+ t( *(uint32_t*)sp_value(cur) == 2 );
832
+ t( sp_valuesize(cur) == sizeof(v) );
833
+ t( sp_fetch(cur) == 1 );
834
+ t( *(uint32_t*)sp_key(cur) == 2 );
835
+ t( sp_keysize(cur) == sizeof(k) );
836
+ t( *(uint32_t*)sp_value(cur) == 2 );
837
+ t( sp_valuesize(cur) == sizeof(v) );
838
+ t( sp_fetch(cur) == 1 );
839
+ t( *(uint32_t*)sp_key(cur) == 1 );
840
+ t( sp_keysize(cur) == sizeof(k) );
841
+ t( *(uint32_t*)sp_value(cur) == 2 );
842
+ t( sp_valuesize(cur) == sizeof(v) );
843
+ t( sp_fetch(cur) == 0 );
844
+ t( sp_fetch(cur) == 0 );
845
+ t( sp_destroy(cur) == 0 );
846
+ t( sp_destroy(db) == 0 );
847
+ t( sp_destroy(env) == 0 );
848
+ t( rmrf(dbrep) == 0 );
849
+ }
850
+
851
+ static void
852
+ recover_page_fetch_kgte(void) {
853
+ void *env = sp_env();
854
+ t( env != NULL );
855
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
856
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
857
+ t( sp_ctl(env, SPGC, 0) == 0 );
858
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
859
+ void *db = sp_open(env);
860
+ t( db != NULL );
861
+ uint32_t k = 1, v = 2;
862
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
863
+ k = 2;
864
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
865
+ k = 3;
866
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
867
+ t( sp_ctl(db, SPMERGEFORCE) == 0 );
868
+ t( sp_destroy(db) == 0 );
869
+ db = sp_open(env);
870
+ t( db != NULL );
871
+ k = 2;
872
+ void *cur = sp_cursor(db, SPGTE, &k, sizeof(k));
873
+ t( cur != NULL );
874
+ t( sp_fetch(cur) == 1 );
875
+ t( *(uint32_t*)sp_key(cur) == 2 );
876
+ t( sp_keysize(cur) == sizeof(k) );
877
+ t( *(uint32_t*)sp_value(cur) == 2 );
878
+ t( sp_valuesize(cur) == sizeof(v) );
879
+ t( sp_fetch(cur) == 1 );
880
+ t( *(uint32_t*)sp_key(cur) == 3 );
881
+ t( sp_keysize(cur) == sizeof(k) );
882
+ t( *(uint32_t*)sp_value(cur) == 2 );
883
+ t( sp_valuesize(cur) == sizeof(v) );
884
+ t( sp_fetch(cur) == 0 );
885
+ t( sp_fetch(cur) == 0 );
886
+ t( sp_destroy(cur) == 0 );
887
+ t( sp_destroy(db) == 0 );
888
+ t( sp_destroy(env) == 0 );
889
+ t( rmrf(dbrep) == 0 );
890
+ }
891
+
892
+ static void
893
+ recover_page_fetch_kgt(void) {
894
+ void *env = sp_env();
895
+ t( env != NULL );
896
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
897
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
898
+ t( sp_ctl(env, SPGC, 0) == 0 );
899
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
900
+ void *db = sp_open(env);
901
+ t( db != NULL );
902
+ uint32_t k = 1, v = 2;
903
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
904
+ k = 2;
905
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
906
+ k = 3;
907
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
908
+ t( sp_ctl(db, SPMERGEFORCE) == 0 );
909
+ t( sp_destroy(db) == 0 );
910
+ db = sp_open(env);
911
+ t( db != NULL );
912
+ k = 2;
913
+ void *cur = sp_cursor(db, SPGT, &k, sizeof(k));
914
+ t( cur != NULL );
915
+ t( sp_fetch(cur) == 1 );
916
+ t( *(uint32_t*)sp_key(cur) == 3 );
917
+ t( sp_keysize(cur) == sizeof(k) );
918
+ t( *(uint32_t*)sp_value(cur) == 2 );
919
+ t( sp_valuesize(cur) == sizeof(v) );
920
+ t( sp_fetch(cur) == 0 );
921
+ t( sp_fetch(cur) == 0 );
922
+ t( sp_destroy(cur) == 0 );
923
+ t( sp_destroy(db) == 0 );
924
+ t( sp_destroy(env) == 0 );
925
+ t( rmrf(dbrep) == 0 );
926
+ }
927
+
928
+ static void
929
+ recover_page_fetch_klte(void) {
930
+ void *env = sp_env();
931
+ t( env != NULL );
932
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
933
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
934
+ t( sp_ctl(env, SPGC, 0) == 0 );
935
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
936
+ void *db = sp_open(env);
937
+ t( db != NULL );
938
+ uint32_t k = 1, v = 2;
939
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
940
+ k = 2;
941
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
942
+ k = 3;
943
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
944
+ t( sp_ctl(db, SPMERGEFORCE) == 0 );
945
+ t( sp_destroy(db) == 0 );
946
+ db = sp_open(env);
947
+ t( db != NULL );
948
+ k = 2;
949
+ void *cur = sp_cursor(db, SPLTE, &k, sizeof(k));
950
+ t( cur != NULL );
951
+ t( sp_fetch(cur) == 1 );
952
+ t( *(uint32_t*)sp_key(cur) == 2 );
953
+ t( sp_keysize(cur) == sizeof(k) );
954
+ t( *(uint32_t*)sp_value(cur) == 2 );
955
+ t( sp_valuesize(cur) == sizeof(v) );
956
+ t( sp_fetch(cur) == 1 );
957
+ t( *(uint32_t*)sp_key(cur) == 1 );
958
+ t( sp_keysize(cur) == sizeof(k) );
959
+ t( *(uint32_t*)sp_value(cur) == 2 );
960
+ t( sp_valuesize(cur) == sizeof(v) );
961
+ t( sp_fetch(cur) == 0 );
962
+ t( sp_fetch(cur) == 0 );
963
+ t( sp_destroy(cur) == 0 );
964
+ t( sp_destroy(db) == 0 );
965
+ t( sp_destroy(env) == 0 );
966
+ t( rmrf(dbrep) == 0 );
967
+ }
968
+
969
+ static void
970
+ recover_page_fetch_klt(void) {
971
+ void *env = sp_env();
972
+ t( env != NULL );
973
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
974
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
975
+ t( sp_ctl(env, SPGC, 0) == 0 );
976
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
977
+ void *db = sp_open(env);
978
+ t( db != NULL );
979
+ uint32_t k = 1, v = 2;
980
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
981
+ k = 2;
982
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
983
+ k = 3;
984
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
985
+ t( sp_ctl(db, SPMERGEFORCE) == 0 );
986
+ t( sp_destroy(db) == 0 );
987
+ db = sp_open(env);
988
+ t( db != NULL );
989
+ k = 2;
990
+ void *cur = sp_cursor(db, SPLT, &k, sizeof(k));
991
+ t( cur != NULL );
992
+ t( sp_fetch(cur) == 1 );
993
+ t( *(uint32_t*)sp_key(cur) == 1 );
994
+ t( sp_keysize(cur) == sizeof(k) );
995
+ t( *(uint32_t*)sp_value(cur) == 2 );
996
+ t( sp_valuesize(cur) == sizeof(v) );
997
+ t( sp_fetch(cur) == 0 );
998
+ t( sp_fetch(cur) == 0 );
999
+ t( sp_destroy(cur) == 0 );
1000
+ t( sp_destroy(db) == 0 );
1001
+ t( sp_destroy(env) == 0 );
1002
+ t( rmrf(dbrep) == 0 );
1003
+ }
1004
+
1005
+ static void
1006
+ recover_page_n_get(void) {
1007
+ void *env = sp_env();
1008
+ t( env != NULL );
1009
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
1010
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
1011
+ t( sp_ctl(env, SPGC, 0) == 0 );
1012
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
1013
+ void *db = sp_open(env);
1014
+ t( db != NULL );
1015
+ uint32_t k = 0, v;
1016
+ while (k < 12) {
1017
+ v = k;
1018
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
1019
+ k++;
1020
+ }
1021
+ t( sp_ctl(db, SPMERGEFORCE) == 0 );
1022
+ t( sp_destroy(db) == 0 );
1023
+ t( exists(dbrep, 1, "db") == 1 );
1024
+ t( exists(dbrep, 1, "log.incomplete") == 0 );
1025
+ t( exists(dbrep, 1, "log") == 0 );
1026
+ db = sp_open(env);
1027
+ t( db != NULL );
1028
+ k = 0;
1029
+ while (k < 12) {
1030
+ size_t vsize = 0;
1031
+ void *vp = NULL;
1032
+ t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
1033
+ t( vsize == sizeof(v) );
1034
+ t( *(uint32_t*)vp == k );
1035
+ free(vp);
1036
+ k++;
1037
+ }
1038
+ t( sp_destroy(db) == 0 );
1039
+ t( sp_destroy(env) == 0 );
1040
+ t( rmrf(dbrep) == 0 );
1041
+ }
1042
+
1043
+ static void
1044
+ recover_page_n_replace(void) {
1045
+ void *env = sp_env();
1046
+ t( env != NULL );
1047
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
1048
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
1049
+ t( sp_ctl(env, SPGC, 0) == 0 );
1050
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
1051
+ void *db = sp_open(env);
1052
+ t( db != NULL );
1053
+ uint32_t k = 0, v = 1;
1054
+ while (k < 12) {
1055
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
1056
+ k++;
1057
+ }
1058
+ t( sp_ctl(db, SPMERGEFORCE) == 0 );
1059
+ t( exists(dbrep, 1, "db") == 1 );
1060
+ k = 0;
1061
+ v = 2;
1062
+ while (k < 12) {
1063
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
1064
+ k++;
1065
+ }
1066
+ t( sp_ctl(db, SPMERGEFORCE) == 0 );
1067
+ t( sp_destroy(db) == 0 );
1068
+ t( exists(dbrep, 2, "db") == 1 );
1069
+ t( exists(dbrep, 1, "log") == 0 );
1070
+ t( exists(dbrep, 2, "log") == 0 );
1071
+ db = sp_open(env);
1072
+ t( db != NULL );
1073
+ k = 0;
1074
+ while (k < 12) {
1075
+ size_t vsize = 0;
1076
+ void *vp = NULL;
1077
+ t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
1078
+ t( vsize == sizeof(v) );
1079
+ t( *(uint32_t*)vp == 2 );
1080
+ free(vp);
1081
+ k++;
1082
+ }
1083
+ t( sp_destroy(db) == 0 );
1084
+ t( sp_destroy(env) == 0 );
1085
+ t( rmrf(dbrep) == 0 );
1086
+ }
1087
+
1088
+ static void
1089
+ recover_page_log_fetch_gte(void) {
1090
+ void *env = sp_env();
1091
+ t( env != NULL );
1092
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
1093
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
1094
+ t( sp_ctl(env, SPGC, 0) == 0 );
1095
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
1096
+ void *db = sp_open(env);
1097
+ t( db != NULL );
1098
+ uint32_t k = 1, v = 2;
1099
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1100
+ k = 2;
1101
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1102
+ k = 3;
1103
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1104
+ t( sp_ctl(db, SPMERGEFORCE) == 0 );
1105
+ k = 4;
1106
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1107
+ k = 5;
1108
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1109
+ k = 6;
1110
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1111
+ t( sp_destroy(db) == 0 );
1112
+ db = sp_open(env);
1113
+ t( db != NULL );
1114
+ void *cur = sp_cursor(db, SPGTE, NULL, 0);
1115
+ t( cur != NULL );
1116
+ t( sp_fetch(cur) == 1 );
1117
+ t( *(uint32_t*)sp_key(cur) == 1 );
1118
+ t( sp_keysize(cur) == sizeof(k) );
1119
+ t( *(uint32_t*)sp_value(cur) == 2 );
1120
+ t( sp_valuesize(cur) == sizeof(v) );
1121
+ t( sp_fetch(cur) == 1 );
1122
+ t( *(uint32_t*)sp_key(cur) == 2 );
1123
+ t( sp_keysize(cur) == sizeof(k) );
1124
+ t( *(uint32_t*)sp_value(cur) == 2 );
1125
+ t( sp_valuesize(cur) == sizeof(v) );
1126
+ t( sp_fetch(cur) == 1 );
1127
+ t( *(uint32_t*)sp_key(cur) == 3 );
1128
+ t( sp_keysize(cur) == sizeof(k) );
1129
+ t( *(uint32_t*)sp_value(cur) == 2 );
1130
+ t( sp_valuesize(cur) == sizeof(v) );
1131
+ t( sp_fetch(cur) == 1 );
1132
+ t( *(uint32_t*)sp_key(cur) == 4 );
1133
+ t( sp_keysize(cur) == sizeof(k) );
1134
+ t( *(uint32_t*)sp_value(cur) == 2 );
1135
+ t( sp_valuesize(cur) == sizeof(v) );
1136
+ t( sp_fetch(cur) == 1 );
1137
+ t( *(uint32_t*)sp_key(cur) == 5 );
1138
+ t( sp_keysize(cur) == sizeof(k) );
1139
+ t( *(uint32_t*)sp_value(cur) == 2 );
1140
+ t( sp_valuesize(cur) == sizeof(v) );
1141
+ t( sp_fetch(cur) == 1 );
1142
+ t( *(uint32_t*)sp_key(cur) == 6 );
1143
+ t( sp_keysize(cur) == sizeof(k) );
1144
+ t( *(uint32_t*)sp_value(cur) == 2 );
1145
+ t( sp_valuesize(cur) == sizeof(v) );
1146
+ t( sp_fetch(cur) == 0 );
1147
+ t( sp_destroy(cur) == 0 );
1148
+ t( sp_destroy(db) == 0 );
1149
+ t( sp_destroy(env) == 0 );
1150
+ t( rmrf(dbrep) == 0 );
1151
+ }
1152
+
1153
+ static void
1154
+ recover_page_log_fetch_lte(void) {
1155
+ void *env = sp_env();
1156
+ t( env != NULL );
1157
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
1158
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
1159
+ t( sp_ctl(env, SPGC, 0) == 0 );
1160
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
1161
+ void *db = sp_open(env);
1162
+ t( db != NULL );
1163
+ uint32_t k = 1, v = 2;
1164
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1165
+ k = 2;
1166
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1167
+ k = 3;
1168
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1169
+ t( sp_ctl(db, SPMERGEFORCE) == 0 );
1170
+ k = 4;
1171
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1172
+ k = 5;
1173
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1174
+ k = 6;
1175
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1176
+ t( sp_destroy(db) == 0 );
1177
+ db = sp_open(env);
1178
+ t( db != NULL );
1179
+ void *cur = sp_cursor(db, SPLTE, NULL, 0);
1180
+ t( cur != NULL );
1181
+ t( sp_fetch(cur) == 1 );
1182
+ t( *(uint32_t*)sp_key(cur) == 6 );
1183
+ t( sp_keysize(cur) == sizeof(k) );
1184
+ t( *(uint32_t*)sp_value(cur) == 2 );
1185
+ t( sp_valuesize(cur) == sizeof(v) );
1186
+ t( sp_fetch(cur) == 1 );
1187
+ t( *(uint32_t*)sp_key(cur) == 5 );
1188
+ t( sp_keysize(cur) == sizeof(k) );
1189
+ t( *(uint32_t*)sp_value(cur) == 2 );
1190
+ t( sp_valuesize(cur) == sizeof(v) );
1191
+ t( sp_fetch(cur) == 1 );
1192
+ t( *(uint32_t*)sp_key(cur) == 4 );
1193
+ t( sp_keysize(cur) == sizeof(k) );
1194
+ t( *(uint32_t*)sp_value(cur) == 2 );
1195
+ t( sp_valuesize(cur) == sizeof(v) );
1196
+ t( sp_fetch(cur) == 1 );
1197
+ t( *(uint32_t*)sp_key(cur) == 3 );
1198
+ t( sp_keysize(cur) == sizeof(k) );
1199
+ t( *(uint32_t*)sp_value(cur) == 2 );
1200
+ t( sp_valuesize(cur) == sizeof(v) );
1201
+ t( sp_fetch(cur) == 1 );
1202
+ t( *(uint32_t*)sp_key(cur) == 2 );
1203
+ t( sp_keysize(cur) == sizeof(k) );
1204
+ t( *(uint32_t*)sp_value(cur) == 2 );
1205
+ t( sp_valuesize(cur) == sizeof(v) );
1206
+ t( sp_fetch(cur) == 1 );
1207
+ t( *(uint32_t*)sp_key(cur) == 1 );
1208
+ t( sp_keysize(cur) == sizeof(k) );
1209
+ t( *(uint32_t*)sp_value(cur) == 2 );
1210
+ t( sp_valuesize(cur) == sizeof(v) );
1211
+ t( sp_fetch(cur) == 0 );
1212
+ t( sp_destroy(cur) == 0 );
1213
+ t( sp_destroy(db) == 0 );
1214
+ t( sp_destroy(env) == 0 );
1215
+ t( rmrf(dbrep) == 0 );
1216
+ }
1217
+
1218
+ static void
1219
+ recover_page_log_fetch_kgte(void) {
1220
+ void *env = sp_env();
1221
+ t( env != NULL );
1222
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
1223
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
1224
+ t( sp_ctl(env, SPGC, 0) == 0 );
1225
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
1226
+ void *db = sp_open(env);
1227
+ t( db != NULL );
1228
+ uint32_t k = 1, v = 2;
1229
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1230
+ k = 2;
1231
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1232
+ k = 3;
1233
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1234
+ t( sp_ctl(db, SPMERGEFORCE) == 0 );
1235
+ k = 4;
1236
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1237
+ k = 5;
1238
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1239
+ k = 6;
1240
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1241
+ t( sp_destroy(db) == 0 );
1242
+ db = sp_open(env);
1243
+ t( db != NULL );
1244
+ k = 2;
1245
+ void *cur = sp_cursor(db, SPGTE, &k, sizeof(k));
1246
+ t( cur != NULL );
1247
+ t( sp_fetch(cur) == 1 );
1248
+ t( *(uint32_t*)sp_key(cur) == 2 );
1249
+ t( sp_keysize(cur) == sizeof(k) );
1250
+ t( *(uint32_t*)sp_value(cur) == 2 );
1251
+ t( sp_valuesize(cur) == sizeof(v) );
1252
+ t( sp_fetch(cur) == 1 );
1253
+ t( *(uint32_t*)sp_key(cur) == 3 );
1254
+ t( sp_keysize(cur) == sizeof(k) );
1255
+ t( *(uint32_t*)sp_value(cur) == 2 );
1256
+ t( sp_valuesize(cur) == sizeof(v) );
1257
+ t( sp_fetch(cur) == 1 );
1258
+ t( *(uint32_t*)sp_key(cur) == 4 );
1259
+ t( sp_keysize(cur) == sizeof(k) );
1260
+ t( *(uint32_t*)sp_value(cur) == 2 );
1261
+ t( sp_valuesize(cur) == sizeof(v) );
1262
+ t( sp_fetch(cur) == 1 );
1263
+ t( *(uint32_t*)sp_key(cur) == 5 );
1264
+ t( sp_keysize(cur) == sizeof(k) );
1265
+ t( *(uint32_t*)sp_value(cur) == 2 );
1266
+ t( sp_valuesize(cur) == sizeof(v) );
1267
+ t( sp_fetch(cur) == 1 );
1268
+ t( *(uint32_t*)sp_key(cur) == 6 );
1269
+ t( sp_keysize(cur) == sizeof(k) );
1270
+ t( *(uint32_t*)sp_value(cur) == 2 );
1271
+ t( sp_valuesize(cur) == sizeof(v) );
1272
+ t( sp_fetch(cur) == 0 );
1273
+ t( sp_fetch(cur) == 0 );
1274
+ t( sp_destroy(cur) == 0 );
1275
+ t( sp_destroy(db) == 0 );
1276
+ t( sp_destroy(env) == 0 );
1277
+ t( rmrf(dbrep) == 0 );
1278
+ }
1279
+
1280
+ static void
1281
+ recover_page_log_fetch_kgt(void) {
1282
+ void *env = sp_env();
1283
+ t( env != NULL );
1284
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
1285
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
1286
+ t( sp_ctl(env, SPGC, 0) == 0 );
1287
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
1288
+ void *db = sp_open(env);
1289
+ t( db != NULL );
1290
+ uint32_t k = 1, v = 2;
1291
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1292
+ k = 2;
1293
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1294
+ k = 3;
1295
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1296
+ t( sp_ctl(db, SPMERGEFORCE) == 0 );
1297
+ k = 4;
1298
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1299
+ k = 5;
1300
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1301
+ k = 6;
1302
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1303
+ t( sp_destroy(db) == 0 );
1304
+ db = sp_open(env);
1305
+ t( db != NULL );
1306
+ k = 2;
1307
+ void *cur = sp_cursor(db, SPGT, &k, sizeof(k));
1308
+ t( cur != NULL );
1309
+ t( sp_fetch(cur) == 1 );
1310
+ t( *(uint32_t*)sp_key(cur) == 3 );
1311
+ t( sp_keysize(cur) == sizeof(k) );
1312
+ t( *(uint32_t*)sp_value(cur) == 2 );
1313
+ t( sp_valuesize(cur) == sizeof(v) );
1314
+ t( sp_fetch(cur) == 1 );
1315
+ t( *(uint32_t*)sp_key(cur) == 4 );
1316
+ t( sp_keysize(cur) == sizeof(k) );
1317
+ t( *(uint32_t*)sp_value(cur) == 2 );
1318
+ t( sp_valuesize(cur) == sizeof(v) );
1319
+ t( sp_fetch(cur) == 1 );
1320
+ t( *(uint32_t*)sp_key(cur) == 5 );
1321
+ t( sp_keysize(cur) == sizeof(k) );
1322
+ t( *(uint32_t*)sp_value(cur) == 2 );
1323
+ t( sp_valuesize(cur) == sizeof(v) );
1324
+ t( sp_fetch(cur) == 1 );
1325
+ t( *(uint32_t*)sp_key(cur) == 6 );
1326
+ t( sp_keysize(cur) == sizeof(k) );
1327
+ t( *(uint32_t*)sp_value(cur) == 2 );
1328
+ t( sp_valuesize(cur) == sizeof(v) );
1329
+ t( sp_fetch(cur) == 0 );
1330
+ t( sp_fetch(cur) == 0 );
1331
+ t( sp_destroy(cur) == 0 );
1332
+ t( sp_destroy(db) == 0 );
1333
+ t( sp_destroy(env) == 0 );
1334
+ t( rmrf(dbrep) == 0 );
1335
+ }
1336
+
1337
+ static void
1338
+ recover_page_log_fetch_klte(void) {
1339
+ void *env = sp_env();
1340
+ t( env != NULL );
1341
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
1342
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
1343
+ t( sp_ctl(env, SPGC, 0) == 0 );
1344
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
1345
+ void *db = sp_open(env);
1346
+ t( db != NULL );
1347
+ uint32_t k = 1, v = 2;
1348
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1349
+ k = 2;
1350
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1351
+ k = 3;
1352
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1353
+ t( sp_ctl(db, SPMERGEFORCE) == 0 );
1354
+ k = 4;
1355
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1356
+ k = 5;
1357
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1358
+ k = 6;
1359
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1360
+ t( sp_destroy(db) == 0 );
1361
+ db = sp_open(env);
1362
+ t( db != NULL );
1363
+ k = 4;
1364
+ void *cur = sp_cursor(db, SPLTE, &k, sizeof(k));
1365
+ t( cur != NULL );
1366
+ t( sp_fetch(cur) == 1 );
1367
+ t( *(uint32_t*)sp_key(cur) == 4 );
1368
+ t( sp_keysize(cur) == sizeof(k) );
1369
+ t( *(uint32_t*)sp_value(cur) == 2 );
1370
+ t( sp_valuesize(cur) == sizeof(v) );
1371
+ t( sp_fetch(cur) == 1 );
1372
+ t( *(uint32_t*)sp_key(cur) == 3 );
1373
+ t( sp_keysize(cur) == sizeof(k) );
1374
+ t( *(uint32_t*)sp_value(cur) == 2 );
1375
+ t( sp_valuesize(cur) == sizeof(v) );
1376
+ t( sp_fetch(cur) == 1 );
1377
+ t( *(uint32_t*)sp_key(cur) == 2 );
1378
+ t( sp_keysize(cur) == sizeof(k) );
1379
+ t( *(uint32_t*)sp_value(cur) == 2 );
1380
+ t( sp_valuesize(cur) == sizeof(v) );
1381
+ t( sp_fetch(cur) == 1 );
1382
+ t( *(uint32_t*)sp_key(cur) == 1 );
1383
+ t( sp_keysize(cur) == sizeof(k) );
1384
+ t( *(uint32_t*)sp_value(cur) == 2 );
1385
+ t( sp_valuesize(cur) == sizeof(v) );
1386
+ t( sp_fetch(cur) == 0 );
1387
+ t( sp_fetch(cur) == 0 );
1388
+ t( sp_destroy(cur) == 0 );
1389
+ t( sp_destroy(db) == 0 );
1390
+ t( sp_destroy(env) == 0 );
1391
+ t( rmrf(dbrep) == 0 );
1392
+ }
1393
+
1394
+ static void
1395
+ recover_page_log_fetch_klt(void) {
1396
+ void *env = sp_env();
1397
+ t( env != NULL );
1398
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
1399
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
1400
+ t( sp_ctl(env, SPGC, 0) == 0 );
1401
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
1402
+ void *db = sp_open(env);
1403
+ t( db != NULL );
1404
+ uint32_t k = 1, v = 2;
1405
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1406
+ k = 2;
1407
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1408
+ k = 3;
1409
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1410
+ t( sp_ctl(db, SPMERGEFORCE) == 0 );
1411
+ k = 4;
1412
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1413
+ k = 5;
1414
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1415
+ k = 6;
1416
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0 );
1417
+ t( sp_destroy(db) == 0 );
1418
+ db = sp_open(env);
1419
+ t( db != NULL );
1420
+ k = 4;
1421
+ void *cur = sp_cursor(db, SPLT, &k, sizeof(k));
1422
+ t( cur != NULL );
1423
+ t( sp_fetch(cur) == 1 );
1424
+ t( *(uint32_t*)sp_key(cur) == 3 );
1425
+ t( sp_keysize(cur) == sizeof(k) );
1426
+ t( *(uint32_t*)sp_value(cur) == 2 );
1427
+ t( sp_valuesize(cur) == sizeof(v) );
1428
+ t( sp_fetch(cur) == 1 );
1429
+ t( *(uint32_t*)sp_key(cur) == 2 );
1430
+ t( sp_keysize(cur) == sizeof(k) );
1431
+ t( *(uint32_t*)sp_value(cur) == 2 );
1432
+ t( sp_valuesize(cur) == sizeof(v) );
1433
+ t( sp_fetch(cur) == 1 );
1434
+ t( *(uint32_t*)sp_key(cur) == 1 );
1435
+ t( sp_keysize(cur) == sizeof(k) );
1436
+ t( *(uint32_t*)sp_value(cur) == 2 );
1437
+ t( sp_valuesize(cur) == sizeof(v) );
1438
+ t( sp_fetch(cur) == 0 );
1439
+ t( sp_fetch(cur) == 0 );
1440
+ t( sp_destroy(cur) == 0 );
1441
+ t( sp_destroy(db) == 0 );
1442
+ t( sp_destroy(env) == 0 );
1443
+ t( rmrf(dbrep) == 0 );
1444
+ }
1445
+
1446
+ static void
1447
+ recover_page_log_n_replace(void) {
1448
+ void *env = sp_env();
1449
+ t( env != NULL );
1450
+ t( sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, dbrep) == 0 );
1451
+ t( sp_ctl(env, SPCMP, cmp, NULL) == 0 );
1452
+ t( sp_ctl(env, SPGC, 0) == 0 );
1453
+ t( sp_ctl(env, SPMERGE, 0) == 0 );
1454
+ void *db = sp_open(env);
1455
+ t( db != NULL );
1456
+ uint32_t k = 0, v = 1;
1457
+ while (k < 12) {
1458
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
1459
+ if (k > 0 && k % 3 == 0)
1460
+ t( sp_ctl(db, SPMERGEFORCE) == 0 );
1461
+ k++;
1462
+ }
1463
+ k = 0;
1464
+ v = 2;
1465
+ while (k < 12) {
1466
+ t( sp_set(db, &k, sizeof(k), &v, sizeof(v)) == 0);
1467
+ k++;
1468
+ }
1469
+ t( sp_destroy(db) == 0 );
1470
+ t( exists(dbrep, 1, "db") == 1 );
1471
+ t( exists(dbrep, 2, "db") == 1 );
1472
+ t( exists(dbrep, 3, "db") == 1 );
1473
+ t( exists(dbrep, 4, "log") == 1 );
1474
+ db = sp_open(env);
1475
+ t( db != NULL );
1476
+ k = 0;
1477
+ while (k < 12) {
1478
+ size_t vsize = 0;
1479
+ void *vp = NULL;
1480
+ t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
1481
+ t( vsize == sizeof(v) );
1482
+ t( *(uint32_t*)vp == 2 );
1483
+ free(vp);
1484
+ k++;
1485
+ }
1486
+ t( sp_destroy(db) == 0 );
1487
+ db = sp_open(env);
1488
+ t( db != NULL );
1489
+ t( sp_ctl(db, SPMERGEFORCE) == 0 );
1490
+ t( exists(dbrep, 5, "db") == 1 );
1491
+ t( exists(dbrep, 5, "log") == 0 );
1492
+ t( exists(dbrep, 5, "log.incomplete") == 0 );
1493
+ t( exists(dbrep, 6, "log.incomplete") == 1 );
1494
+ k = 0;
1495
+ while (k < 12) {
1496
+ size_t vsize = 0;
1497
+ void *vp = NULL;
1498
+ t( sp_get(db, &k, sizeof(k), &vp, &vsize) == 1 );
1499
+ t( vsize == sizeof(v) );
1500
+ t( *(uint32_t*)vp == 2 );
1501
+ free(vp);
1502
+ k++;
1503
+ }
1504
+ t( sp_destroy(db) == 0 );
1505
+ t( sp_destroy(env) == 0 );
1506
+ t( rmrf(dbrep) == 0 );
1507
+ }
1508
+
1509
+ int
1510
+ main(int argc, char *argv[])
1511
+ {
1512
+ rmrf(dbrep);
1513
+
1514
+ test(recover_log_set_get);
1515
+ test(recover_log_replace_get);
1516
+ test(recover_log_set_get_replace_get);
1517
+ test(recover_log_delete_get);
1518
+ test(recover_log_delete_set_get);
1519
+ test(recover_log_fetch_gte);
1520
+ test(recover_log_fetch_lte);
1521
+ test(recover_log_fetch_kgte);
1522
+ test(recover_log_fetch_kgt);
1523
+ test(recover_log_fetch_klte);
1524
+ test(recover_log_fetch_klt);
1525
+ test(recover_log_n_get);
1526
+ test(recover_log_n_replace);
1527
+
1528
+ test(recover_page_set_get);
1529
+ test(recover_page_replace_get);
1530
+ test(recover_page_set_get_replace_get);
1531
+ test(recover_page_delete_get);
1532
+ test(recover_page_delete_set_get);
1533
+ test(recover_page_fetch_gte);
1534
+ test(recover_page_fetch_lte);
1535
+ test(recover_page_fetch_kgte);
1536
+ test(recover_page_fetch_kgt);
1537
+ test(recover_page_fetch_klte);
1538
+ test(recover_page_fetch_klt);
1539
+ test(recover_page_n_get);
1540
+ test(recover_page_n_replace);
1541
+
1542
+ test(recover_page_log_fetch_gte);
1543
+ test(recover_page_log_fetch_lte);
1544
+ test(recover_page_log_fetch_kgte);
1545
+ test(recover_page_log_fetch_kgt);
1546
+ test(recover_page_log_fetch_klte);
1547
+ test(recover_page_log_fetch_klt);
1548
+ test(recover_page_log_n_replace);
1549
+ return 0;
1550
+ }