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 CACHETABLE ct;
43
44 CACHEFILE f1;
45
46 static void
run_test(void)47 run_test (void) {
48 const int test_limit = 20;
49 int r;
50 ct = NULL;
51 toku_cachetable_create(&ct, test_limit, ZERO_LSN, nullptr);
52 const char *fname1 = TOKU_TEST_FILENAME;
53 unlink(fname1);
54 f1 = NULL;
55 r = toku_cachetable_openf(&f1, ct, fname1, O_RDWR|O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO); assert(r == 0);
56 create_dummy_functions(f1);
57
58 void* v1;
59 void* v2;
60
61 r = toku_cachetable_get_and_pin(f1, make_blocknum(1), 1, &v1, def_write_callback(NULL), def_fetch, def_pf_req_callback, def_pf_callback, true, NULL);
62 r = toku_test_cachetable_unpin(f1, make_blocknum(1), 1, CACHETABLE_CLEAN, make_pair_attr(8)); assert(r==0);
63
64 for (int i = 0; i < 20; i++) {
65 r = toku_cachetable_get_and_pin(f1, make_blocknum(2), 2, &v2, def_write_callback(NULL), def_fetch, def_pf_req_callback, def_pf_callback, true, NULL);
66 r = toku_test_cachetable_unpin(f1, make_blocknum(2), 2, CACHETABLE_CLEAN, make_pair_attr(8)); assert(r==0);
67 }
68
69 r = toku_cachetable_get_and_pin(f1, make_blocknum(1), 1, &v2, def_write_callback(NULL), def_fetch, def_pf_req_callback, def_pf_callback, true, NULL);
70 CHECKPOINTER cp = toku_cachetable_get_checkpointer(ct);
71 toku_cachetable_begin_checkpoint(cp, NULL);
72 // mark nodes as pending a checkpoint, so that get_and_pin_nonblocking on block 1 will return TOKUDB_TRY_AGAIN
73 r = toku_test_cachetable_unpin(f1, make_blocknum(1), 1, CACHETABLE_CLEAN, make_pair_attr(8)); assert(r==0);
74
75 r = toku_cachetable_get_and_pin_nonblocking(
76 f1,
77 make_blocknum(1),
78 1,
79 &v1,
80 def_write_callback(NULL),
81 def_fetch,
82 def_pf_req_callback,
83 def_pf_callback,
84 PL_WRITE_EXPENSIVE,
85 NULL,
86 NULL
87 );
88 assert(r==0);
89 r = toku_test_cachetable_unpin(f1, make_blocknum(1), 1, CACHETABLE_CLEAN, make_pair_attr(8)); assert(r==0);
90
91 toku_cachetable_end_checkpoint(
92 cp,
93 NULL,
94 NULL,
95 NULL
96 );
97 assert(r==0);
98
99 toku_cachetable_verify(ct);
100 toku_cachefile_close(&f1, false, ZERO_LSN);
101 toku_cachetable_close(&ct);
102
103
104 }
105
106 int
test_main(int argc,const char * argv[])107 test_main(int argc, const char *argv[]) {
108 default_parse_args(argc, argv);
109 run_test();
110 return 0;
111 }
112