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 <toku_portability.h>
40 #include <string.h>
41
42 #include "test.h"
43
44 #include "ft/ule.h"
45 #include "ft/ule-internal.h"
46
init_empty_ule(ULE ule)47 static void init_empty_ule(ULE ule) {
48 ule->num_cuxrs = 0;
49 ule->num_puxrs = 0;
50 ule->uxrs = ule->uxrs_static;
51 }
52
add_committed_entry(ULE ule,DBT * val,TXNID xid)53 static void add_committed_entry(ULE ule, DBT *val, TXNID xid) {
54 uint32_t index = ule->num_cuxrs;
55 ule->num_cuxrs++;
56 ule->uxrs[index].type = XR_INSERT;
57 ule->uxrs[index].vallen = val->size;
58 ule->uxrs[index].valp = val->data;
59 ule->uxrs[index].xid = xid;
60 }
61
62 //Test all the different things that can happen to a
63 //committed leafentry (logical equivalent of a committed insert).
64 static void
run_test(void)65 run_test(void) {
66 ULE_S ule_initial;
67 ULE ule = &ule_initial;
68 ule_initial.uxrs = ule_initial.uxrs_static;
69 int r;
70 DBT key;
71 DBT val;
72 uint64_t key_data = 1;
73 uint64_t val_data_one = 1;
74 uint64_t val_data_two = 2;
75 uint64_t val_data_three = 3;
76 uint32_t keysize = 8;
77 uint32_t valsize = 8;
78
79 toku_fill_dbt(&key, &key_data, keysize);
80 toku_fill_dbt(&val, &val_data_one, valsize);
81
82 // test case where we apply a message and the innermost child_id
83 // is the same as the innermost committed TXNID
84 XIDS root_xids = toku_xids_get_root_xids();
85 TXNID root_txnid = 1000;
86 TXNID child_id = 10;
87 XIDS msg_xids_1;
88 XIDS msg_xids_2;
89 r = toku_xids_create_child(root_xids, &msg_xids_1, root_txnid);
90 assert(r==0);
91 r = toku_xids_create_child(msg_xids_1, &msg_xids_2, child_id);
92 assert(r==0);
93
94 init_empty_ule(&ule_initial);
95 add_committed_entry(&ule_initial, &val, 0);
96 val.data = &val_data_two;
97 // make the TXNID match the child id of xids
98 add_committed_entry(&ule_initial, &val, 10);
99
100 // now do the application of xids to the ule
101 // do a commit
102 {
103 ft_msg msg(&key, &val, FT_COMMIT_ANY, ZERO_MSN, msg_xids_2);
104 test_msg_modify_ule(&ule_initial, msg);
105 assert(ule->num_cuxrs == 2);
106 assert(ule->uxrs[0].xid == TXNID_NONE);
107 assert(ule->uxrs[1].xid == 10);
108 assert(ule->uxrs[0].valp == &val_data_one);
109 assert(ule->uxrs[1].valp == &val_data_two);
110 }
111
112 // do an abort
113 {
114 ft_msg msg(&key, &val, FT_ABORT_ANY, ZERO_MSN, msg_xids_2);
115 test_msg_modify_ule(&ule_initial, msg);
116 assert(ule->num_cuxrs == 2);
117 assert(ule->uxrs[0].xid == TXNID_NONE);
118 assert(ule->uxrs[1].xid == 10);
119 assert(ule->uxrs[0].valp == &val_data_one);
120 assert(ule->uxrs[1].valp == &val_data_two);
121 }
122
123 // do an insert
124 val.data = &val_data_three;
125 {
126 ft_msg msg(&key, &val, FT_INSERT, ZERO_MSN, msg_xids_2);
127 test_msg_modify_ule(&ule_initial, msg);
128 // now that message applied, verify that things are good
129 assert(ule->num_cuxrs == 2);
130 assert(ule->num_puxrs == 2);
131 assert(ule->uxrs[0].xid == TXNID_NONE);
132 assert(ule->uxrs[1].xid == 10);
133 assert(ule->uxrs[2].xid == 1000);
134 assert(ule->uxrs[3].xid == 10);
135 assert(ule->uxrs[0].valp == &val_data_one);
136 assert(ule->uxrs[1].valp == &val_data_two);
137 assert(ule->uxrs[2].type == XR_PLACEHOLDER);
138 assert(ule->uxrs[3].valp == &val_data_three);
139 }
140
141 toku_xids_destroy(&msg_xids_2);
142 toku_xids_destroy(&msg_xids_1);
143 toku_xids_destroy(&root_xids);
144
145 }
146
147
148 int
test_main(int argc,const char * argv[])149 test_main (int argc __attribute__((__unused__)), const char *argv[] __attribute__((__unused__))) {
150 run_test();
151 return 0;
152 }
153
154