1 /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
3 #ident "$Id$"
4 /*======
5 This file is part of PerconaFT.
6
7
8 Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved.
9
10 PerconaFT is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License, version 2,
12 as published by the Free Software Foundation.
13
14 PerconaFT is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with PerconaFT. If not, see <http://www.gnu.org/licenses/>.
21
22 ----------------------------------------
23
24 PerconaFT is free software: you can redistribute it and/or modify
25 it under the terms of the GNU Affero General Public License, version 3,
26 as published by the Free Software Foundation.
27
28 PerconaFT is distributed in the hope that it will be useful,
29 but WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 GNU Affero General Public License for more details.
32
33 You should have received a copy of the GNU Affero General Public License
34 along with PerconaFT. If not, see <http://www.gnu.org/licenses/>.
35 ======= */
36
37 #ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved."
38
39 #include "test.h"
40
41 static void
test_cachetable_def_flush(int n)42 test_cachetable_def_flush (int n) {
43 CACHETABLE_WRITE_CALLBACK wc = def_write_callback(NULL);
44 const int test_limit = 2*n;
45 int r;
46 CACHETABLE ct;
47 toku_cachetable_create(&ct, test_limit, ZERO_LSN, nullptr);
48 toku_os_recursive_delete(TOKU_TEST_FILENAME);
49 r = toku_os_mkdir(TOKU_TEST_FILENAME, S_IRWXU);
50 assert_zero(r);
51 char fname1[TOKU_PATH_MAX+1];
52 unlink(toku_path_join(fname1, 2, TOKU_TEST_FILENAME, "test1.dat"));
53 CACHEFILE f1;
54 r = toku_cachetable_openf(&f1, ct, fname1, O_RDWR|O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO); assert(r == 0);
55
56 char fname2[TOKU_PATH_MAX+1];
57 unlink(toku_path_join(fname2, 2, TOKU_TEST_FILENAME, "test2.dat"));
58 CACHEFILE f2;
59 r = toku_cachetable_openf(&f2, ct, fname2, O_RDWR|O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO); assert(r == 0);
60
61 // insert keys 0..n-1
62 int i;
63 for (i=0; i<n; i++) {
64 uint32_t hi;
65 hi = toku_cachetable_hash(f1, make_blocknum(i));
66 toku_cachetable_put(f1, make_blocknum(i), hi, (void *)(long)i, make_pair_attr(1), wc, put_callback_nop);
67 r = toku_test_cachetable_unpin(f1, make_blocknum(i), hi, CACHETABLE_CLEAN, make_pair_attr(1));
68 assert(r == 0);
69 hi = toku_cachetable_hash(f2, make_blocknum(i));
70 toku_cachetable_put(f2, make_blocknum(i), hi, (void *)(long)i, make_pair_attr(1), wc, put_callback_nop);
71 r = toku_test_cachetable_unpin(f2, make_blocknum(i), hi, CACHETABLE_CLEAN, make_pair_attr(1));
72 assert(r == 0);
73 }
74 toku_cachetable_verify(ct);
75
76 // verify keys exists
77 for (i=0; i<n; i++) {
78 uint32_t hi;
79 void *v;
80 hi = toku_cachetable_hash(f1, make_blocknum(i));
81 r = toku_cachetable_maybe_get_and_pin(f1, make_blocknum(i), hi, PL_WRITE_EXPENSIVE, &v);
82 assert(r == 0 && v == (void *)(long)i);
83 r = toku_test_cachetable_unpin(f1, make_blocknum(i), hi, CACHETABLE_CLEAN, make_pair_attr(1));
84 assert(r == 0);
85 hi = toku_cachetable_hash(f2, make_blocknum(i));
86 r = toku_cachetable_maybe_get_and_pin(f2, make_blocknum(i), hi, PL_WRITE_EXPENSIVE, &v);
87 assert(r == 0 && v == (void *)(long)i);
88 r = toku_test_cachetable_unpin(f2, make_blocknum(i), hi, CACHETABLE_CLEAN, make_pair_attr(1));
89 assert(r == 0);
90 }
91
92 // def_flush
93 toku_cachefile_close(&f1, false, ZERO_LSN);
94 toku_cachefile_verify(f2);
95
96 // verify keys exist in f2
97 for (i=0; i<n; i++) {
98 uint32_t hi;
99 void *v;
100 hi = toku_cachetable_hash(f2, make_blocknum(i));
101 r = toku_cachetable_maybe_get_and_pin(f2, make_blocknum(i), hi, PL_WRITE_EXPENSIVE, &v);
102 assert(r == 0);
103 r = toku_test_cachetable_unpin(f2, make_blocknum(i), hi, CACHETABLE_CLEAN, make_pair_attr(1));
104 assert(r == 0);
105 }
106
107 toku_cachefile_close(&f2, false, ZERO_LSN);
108 toku_cachetable_close(&ct);
109 }
110
111 int
test_main(int argc,const char * argv[])112 test_main(int argc, const char *argv[]) {
113 default_parse_args(argc, argv);
114 test_cachetable_def_flush(8);
115 return 0;
116 }
117