-
Notifications
You must be signed in to change notification settings - Fork 3
/
testrans.cxx
86 lines (79 loc) · 2.06 KB
/
testrans.cxx
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
79
80
81
82
83
84
85
86
#include "avltree.h"
#include <time.h>
USE_POST_NAMESPACE
class record : public object, public l2elem {
public:
char buf[4000];
int code;
record(int i) { prune(); code = i; }
CLASSINFO(record, NO_REFS);
};
REGISTER(record);
const size_t max_storage_size = 64*1024*1024;
storage tstor("testrans", max_storage_size);
int main(int argc, char* argv[])
{
SEN_TRY {
int code;
if (tstor.open(storage::use_transaction_log)) {
const int n_records = 10000;
int i, n;
time_t start_time;
record* root = (record*)tstor.get_root_object();
if (root == NULL) {
start_time = time(NULL);
printf("Initializing database...\n");
root = new_in(tstor, record)(0);
tstor.set_root_object(root);
for (i = 1; i < n_records; i++) {
(new_in(tstor, record)(i))->link_after(root);
}
tstor.commit();
printf("Elapsed time for initialization = %d\n",
int(time(NULL) - start_time));
}
l2elem* rp = root;
i = 1;
printf("Checking database consistency...\n");
while ((rp = rp->next) != root) {
i += 1;
assert(rp->prev->next==rp && ((record*)rp)->code < n_records);
if ((i & 1023) == 0) {
((record*)rp)->code = -1;
}
}
new_in(tstor, record)(n_records);
assert(i == n_records);
printf("Checking rollback...\n");
tstor.rollback();
i = 1;
while ((rp = rp->next) != root) {
i += 1;
assert(rp->prev->next==rp && ((record*)rp)->code < n_records);
}
assert(i == n_records);
if (argc > 1) {
n = atoi(argv[1]);
} else {
n = 100;
}
printf("Performing %d transactions...\n", n);
start_time = time(NULL);
for (i = 0; i < n; i++) {
rp = root->next;
rp->unlink();
rp->link_before(root);
tstor.commit();
}
printf("Elapsed time for %d transactions: %d\n",
n, int(time(NULL) - start_time));
tstor.close();
code = EXIT_SUCCESS;
} else {
printf("Failed to open storage\n");
code = EXIT_FAILURE;
}
return code;
} SEN_ACCESS_VIOLATION_HANDLER();
return EXIT_FAILURE;
}