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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
#ident "$Id$"
#ident "Copyright (c) 2007-2012 Tokutek Inc. All rights reserved."
#include <unistd.h>
#include <stdlib.h>
#include <libgen.h>
#include <sys/time.h>
#include "test.h"
#include "ft-flusher.h"
#include "includes.h"
#include "checkpoint.h"
static TOKUTXN const null_txn = NULL;
static DB * const null_db = NULL;
static int
noop_getf(ITEMLEN UU(keylen), bytevec UU(key), ITEMLEN UU(vallen), bytevec UU(val), void *extra, bool UU(lock_only))
{
int *CAST_FROM_VOIDP(calledp, extra);
(*calledp)++;
return 0;
}
static int
get_one_value(FT_HANDLE t, CACHETABLE UU(ct), void *UU(extra))
{
int r;
int called;
FT_CURSOR cursor;
r = toku_ft_cursor(t, &cursor, null_txn, false, false);
CKERR(r);
called = 0;
r = toku_ft_cursor_first(cursor, noop_getf, &called);
CKERR(r);
assert(called == 1);
r = toku_ft_cursor_close(cursor);
CKERR(r);
return 0;
}
static int
progress(void *extra, float fraction)
{
float *CAST_FROM_VOIDP(stop_at, extra);
if (fraction > *stop_at) {
return 1;
} else {
return 0;
}
}
static int
do_hot_optimize(FT_HANDLE t, CACHETABLE UU(ct), void *extra)
{
float *CAST_FROM_VOIDP(fraction, extra);
int r = toku_ft_hot_optimize(t, progress, extra);
if (*fraction < 1.0) {
CKERR2(r, 1);
} else {
CKERR(r);
}
return 0;
}
static int
insert_something(FT_HANDLE t, CACHETABLE UU(ct), void *UU(extra))
{
assert(t);
int r = 0;
unsigned int dummy_value = 1U << 31;
DBT key;
DBT val;
toku_fill_dbt(&key, &dummy_value, sizeof(unsigned int));
toku_fill_dbt(&val, &dummy_value, sizeof(unsigned int));
r = toku_ft_insert (t, &key, &val, 0);
CKERR(r);
return 0;
}
typedef int (*tree_cb)(FT_HANDLE t, CACHETABLE ct, void *extra);
static int
with_open_tree(const char *fname, tree_cb cb, void *cb_extra)
{
int r, r2;
FT_HANDLE t;
CACHETABLE ct;
r = toku_create_cachetable(&ct, 16*(1<<20), ZERO_LSN, NULL_LOGGER);
CKERR(r);
r = toku_open_ft_handle(fname,
0,
&t,
4*(1<<20),
128*(1<<10),
TOKU_DEFAULT_COMPRESSION_METHOD,
ct,
null_txn,
toku_builtin_compare_fun
);
CKERR(r);
r2 = cb(t, ct, cb_extra);
r = toku_verify_ft(t);
CKERR(r);
CHECKPOINTER cp = toku_cachetable_get_checkpointer(ct);
r = toku_checkpoint(cp, NULL, NULL, NULL, NULL, NULL, CLIENT_CHECKPOINT);
CKERR(r);
r = toku_close_ft_handle_nolsn(t, 0);
CKERR(r);
r = toku_cachetable_close(&ct);
CKERR(r);
return r2;
}
#define TMPFTFMT "%s-tmpdata.ft"
static const char *origft_6_0 = TOKUSVNROOT "/tokudb.data/upgrade_test_data.ft.6.0.gz";
static const char *origft_5_0 = TOKUSVNROOT "/tokudb.data/upgrade_test_data.ft.5.0.gz";
static const char *origft_4_2 = TOKUSVNROOT "/tokudb.data/upgrade_test_data.ft.4.2.gz";
static const char *not_flat_4_2 = TOKUSVNROOT "/tokudb.data/upgrade_test_data.ft.4.2.not.flat.gz";
static int
run_test(const char *prog, const char *origft) {
int r;
char *fullprog = toku_strdup(__FILE__);
char *progdir = dirname(fullprog);
size_t templen = strlen(progdir) + strlen(prog) + strlen(TMPFTFMT) - 1;
char tempft[templen + 1];
snprintf(tempft, templen + 1, TMPFTFMT, prog);
toku_free(fullprog);
{
size_t len = 13 + strlen(origft) + strlen(tempft);
char buf[len + 1];
snprintf(buf, len + 1, "gunzip -c %s > %s", origft, tempft);
r = system(buf);
CKERR(r);
}
r = with_open_tree(tempft, get_one_value, NULL);
CKERR(r);
r = with_open_tree(tempft, insert_something, NULL);
CKERR(r);
float fraction = 0.5;
r = with_open_tree(tempft, do_hot_optimize, &fraction);
CKERR(r);
fraction = 1.0;
r = with_open_tree(tempft, do_hot_optimize, &fraction);
CKERR(r);
r = unlink(tempft);
CKERR(r);
return r;
}
int
test_main(int argc __attribute__((__unused__)), const char *argv[])
{
int r;
r = run_test(argv[0], origft_6_0);
CKERR(r);
r = run_test(argv[0], origft_5_0);
CKERR(r);
r = run_test(argv[0], origft_4_2);
CKERR(r);
r = run_test(argv[0], not_flat_4_2);
CKERR(r);
return r;
}