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
43 static void
clone_callback(void * UU (value_data),void ** cloned_value_data,long * clone_size,PAIR_ATTR * new_attr,bool UU (for_checkpoint),void * UU (write_extraargs))44 clone_callback(void* UU(value_data), void** cloned_value_data, long* clone_size, PAIR_ATTR* new_attr, bool UU(for_checkpoint), void* UU(write_extraargs))
45 {
46 *cloned_value_data = (void *)1;
47 *clone_size = 8;
48 new_attr->is_valid = false;
49 }
50
51 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))52 flush (
53 CACHEFILE f __attribute__((__unused__)),
54 int UU(fd),
55 CACHEKEY k __attribute__((__unused__)),
56 void *v __attribute__((__unused__)),
57 void** UU(dd),
58 void *e __attribute__((__unused__)),
59 PAIR_ATTR s __attribute__((__unused__)),
60 PAIR_ATTR* new_size __attribute__((__unused__)),
61 bool w __attribute__((__unused__)),
62 bool keep __attribute__((__unused__)),
63 bool c __attribute__((__unused__)),
64 bool UU(is_clone)
65 )
66 {
67 }
68
69
70 // this test verifies that a partial fetch will wait for a cloned pair to complete
71 // writing to disk
72 static void
cachetable_test(enum cachetable_dirty dirty,bool cloneable)73 cachetable_test (enum cachetable_dirty dirty, bool cloneable) {
74 const int test_limit = 12;
75 int r;
76 CACHETABLE ct;
77 toku_cachetable_create(&ct, test_limit, ZERO_LSN, nullptr);
78 const char *fname1 = TOKU_TEST_FILENAME;
79 unlink(fname1);
80 CACHEFILE f1;
81 r = toku_cachetable_openf(&f1, ct, fname1, O_RDWR|O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO); assert(r == 0);
82 create_dummy_functions(f1);
83
84 void* v1;
85 CACHETABLE_WRITE_CALLBACK wc = def_write_callback(NULL);
86 wc.clone_callback = cloneable ? clone_callback : NULL;
87 wc.flush_callback = flush;
88
89 r = toku_cachetable_get_and_pin(f1, make_blocknum(1), 1, &v1, wc, def_fetch, def_pf_req_callback, def_pf_callback, true, NULL);
90 r = toku_test_cachetable_unpin(f1, make_blocknum(1), 1, dirty, make_pair_attr(8));
91
92 // test that having a pin that passes false for may_modify_value does not stall behind checkpoint
93 CHECKPOINTER cp = toku_cachetable_get_checkpointer(ct);
94 toku_cachetable_begin_checkpoint(cp, NULL);
95 r = toku_cachetable_get_and_pin_nonblocking(f1, make_blocknum(1), 1, &v1, wc, def_fetch, def_pf_req_callback, def_pf_callback, PL_READ, NULL, NULL);
96 assert(r == 0);
97 r = toku_test_cachetable_unpin(f1, make_blocknum(1), 1, CACHETABLE_CLEAN, make_pair_attr(8));
98 assert(r == 0);
99
100 r = toku_cachetable_get_and_pin_nonblocking(f1, make_blocknum(1), 1, &v1, wc, def_fetch, def_pf_req_callback, def_pf_callback, PL_WRITE_EXPENSIVE, NULL, NULL);
101 assert(r == 0);
102 r = toku_test_cachetable_unpin(f1, make_blocknum(1), 1, CACHETABLE_CLEAN, make_pair_attr(8));
103
104 toku_cachetable_end_checkpoint(
105 cp,
106 NULL,
107 NULL,
108 NULL
109 );
110
111 toku_cachetable_verify(ct);
112 toku_cachefile_close(&f1, false, ZERO_LSN);
113 toku_cachetable_close(&ct);
114 }
115
116 int
test_main(int argc,const char * argv[])117 test_main(int argc, const char *argv[]) {
118 default_parse_args(argc, argv);
119 cachetable_test(CACHETABLE_DIRTY, true);
120 cachetable_test(CACHETABLE_DIRTY, false);
121 cachetable_test(CACHETABLE_CLEAN, true);
122 cachetable_test(CACHETABLE_CLEAN, false);
123 return 0;
124 }
125