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 #include "cachetable-test.h"
41
42 CACHEFILE f1;
43
44 bool flush_called;
45
46 static void
flush(CACHEFILE f,int UU (fd),CACHEKEY k,void * v,void ** UU (dd),void * e,PAIR_ATTR s,PAIR_ATTR * new_size,bool w,bool keep,bool c,bool UU (is_clone))47 flush (CACHEFILE f __attribute__((__unused__)),
48 int UU(fd),
49 CACHEKEY k __attribute__((__unused__)),
50 void *v __attribute__((__unused__)),
51 void** UU(dd),
52 void *e __attribute__((__unused__)),
53 PAIR_ATTR s __attribute__((__unused__)),
54 PAIR_ATTR* new_size __attribute__((__unused__)),
55 bool w __attribute__((__unused__)),
56 bool keep __attribute__((__unused__)),
57 bool c __attribute__((__unused__)),
58 bool UU(is_clone)
59 ) {
60 /* Do nothing */
61 if (verbose) { printf("FLUSH: %d\n", (int)k.b); }
62 //usleep (5*1024*1024);
63 PAIR_ATTR attr = make_pair_attr(8);
64 attr.cache_pressure_size = 0;
65 *new_size = attr;
66 if (w) {
67 assert(!flush_called);
68 assert(c);
69 flush_called = true;
70 }
71 }
72
73 bool cleaner_called;
74
75 static int
cleaner_callback(void * UU (ftnode_pv),BLOCKNUM blocknum,uint32_t fullhash,void * UU (extraargs))76 cleaner_callback(
77 void* UU(ftnode_pv),
78 BLOCKNUM blocknum,
79 uint32_t fullhash,
80 void* UU(extraargs)
81 )
82 {
83 assert(blocknum.b == 1);
84 assert(fullhash == 1);
85 assert(!cleaner_called);
86 assert(flush_called);
87 cleaner_called = true;
88 int r = toku_test_cachetable_unpin(f1, blocknum, fullhash, CACHETABLE_CLEAN, make_pair_attr(8));
89 assert_zero(r);
90 return 0;
91 }
92
93
94 static void
cachetable_test(void)95 cachetable_test (void) {
96 const int test_limit = 12;
97 int r;
98 CACHETABLE ct;
99 toku_cachetable_create(&ct, test_limit, ZERO_LSN, nullptr);
100 const char *fname1 = TOKU_TEST_FILENAME;
101 unlink(fname1);
102 r = toku_cachetable_openf(&f1, ct, fname1, O_RDWR|O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO); assert(r == 0);
103 create_dummy_functions(f1);
104
105 void* v1;
106 CACHETABLE_WRITE_CALLBACK wc = def_write_callback(NULL);
107 wc.flush_callback = flush;
108 wc.cleaner_callback = cleaner_callback;
109 r = toku_cachetable_get_and_pin(f1, make_blocknum(1), 1, &v1, wc, def_fetch, def_pf_req_callback, def_pf_callback, true, NULL);
110 PAIR_ATTR attr = make_pair_attr(8);
111 attr.cache_pressure_size = 8;
112 r = toku_test_cachetable_unpin(f1, make_blocknum(1), 1, CACHETABLE_DIRTY, attr);
113
114 cleaner_called = false;
115 CHECKPOINTER cp = toku_cachetable_get_checkpointer(ct);
116 toku_cachetable_begin_checkpoint(cp, NULL);
117 assert_zero(r);
118 toku_cleaner_thread_for_test(ct);
119 assert(!cleaner_called);
120 toku_cachetable_end_checkpoint(
121 cp,
122 NULL,
123 NULL,
124 NULL
125 );
126 assert(r==0);
127
128 toku_cachetable_verify(ct);
129 toku_cachefile_close(&f1, false, ZERO_LSN);
130 toku_cachetable_close(&ct);
131
132
133 }
134
135 int
test_main(int argc,const char * argv[])136 test_main(int argc, const char *argv[]) {
137 default_parse_args(argc, argv);
138 cachetable_test();
139 return 0;
140 }
141