You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

576 lines
26 KiB

12 years ago
  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. COPYING CONDITIONS NOTICE:
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of version 2 of the GNU General Public License as
  8. published by the Free Software Foundation, and provided that the
  9. following conditions are met:
  10. * Redistributions of source code must retain this COPYING
  11. CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
  12. DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
  13. PATENT MARKING NOTICE (below), and the PATENT RIGHTS
  14. GRANT (below).
  15. * Redistributions in binary form must reproduce this COPYING
  16. CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
  17. DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
  18. PATENT MARKING NOTICE (below), and the PATENT RIGHTS
  19. GRANT (below) in the documentation and/or other materials
  20. provided with the distribution.
  21. You should have received a copy of the GNU General Public License
  22. along with this program; if not, write to the Free Software
  23. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  24. 02110-1301, USA.
  25. COPYRIGHT NOTICE:
  26. TokuFT, Tokutek Fractal Tree Indexing Library.
  27. Copyright (C) 2007-2013 Tokutek, Inc.
  28. DISCLAIMER:
  29. This program is distributed in the hope that it will be useful, but
  30. WITHOUT ANY WARRANTY; without even the implied warranty of
  31. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  32. General Public License for more details.
  33. UNIVERSITY PATENT NOTICE:
  34. The technology is licensed by the Massachusetts Institute of
  35. Technology, Rutgers State University of New Jersey, and the Research
  36. Foundation of State University of New York at Stony Brook under
  37. United States of America Serial No. 11/760379 and to the patents
  38. and/or patent applications resulting from it.
  39. PATENT MARKING NOTICE:
  40. This software is covered by US Patent No. 8,185,551.
  41. This software is covered by US Patent No. 8,489,638.
  42. PATENT RIGHTS GRANT:
  43. "THIS IMPLEMENTATION" means the copyrightable works distributed by
  44. Tokutek as part of the Fractal Tree project.
  45. "PATENT CLAIMS" means the claims of patents that are owned or
  46. licensable by Tokutek, both currently or in the future; and that in
  47. the absence of this license would be infringed by THIS
  48. IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
  49. "PATENT CHALLENGE" shall mean a challenge to the validity,
  50. patentability, enforceability and/or non-infringement of any of the
  51. PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
  52. Tokutek hereby grants to you, for the term and geographical scope of
  53. the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
  54. irrevocable (except as stated in this section) patent license to
  55. make, have made, use, offer to sell, sell, import, transfer, and
  56. otherwise run, modify, and propagate the contents of THIS
  57. IMPLEMENTATION, where such license applies only to the PATENT
  58. CLAIMS. This grant does not include claims that would be infringed
  59. only as a consequence of further modifications of THIS
  60. IMPLEMENTATION. If you or your agent or licensee institute or order
  61. or agree to the institution of patent litigation against any entity
  62. (including a cross-claim or counterclaim in a lawsuit) alleging that
  63. THIS IMPLEMENTATION constitutes direct or contributory patent
  64. infringement, or inducement of patent infringement, then any rights
  65. granted to you under this License shall terminate as of the date
  66. such litigation is filed. If you or your agent or exclusive
  67. licensee institute or order or agree to the institution of a PATENT
  68. CHALLENGE, then Tokutek may terminate any rights granted to you
  69. under this License.
  70. */
  71. #ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
  72. #ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
  73. /* Verify an FT. */
  74. /* Check:
  75. * The tree is of uniform depth (and the height is correct at every node)
  76. * For each pivot key: the max of the stuff to the left is <= the pivot key < the min of the stuff to the right.
  77. * For each leaf node: All the keys are in strictly increasing order.
  78. * For each nonleaf node: All the messages have keys that are between the associated pivot keys ( left_pivot_key < message <= right_pivot_key)
  79. */
  80. #include <config.h>
  81. #include "ft/serialize/block_table.h"
  82. #include "ft/ft.h"
  83. #include "ft/ft-cachetable-wrappers.h"
  84. #include "ft/ft-internal.h"
  85. #include "ft/node.h"
  86. static int
  87. compare_pairs (FT_HANDLE ft_handle, const DBT *a, const DBT *b) {
  88. return ft_handle->ft->cmp(a, b);
  89. }
  90. static int
  91. compare_pair_to_key (FT_HANDLE ft_handle, const DBT *a, const void *key, uint32_t keylen) {
  92. DBT y;
  93. return ft_handle->ft->cmp(a, toku_fill_dbt(&y, key, keylen));
  94. }
  95. static int
  96. verify_msg_in_child_buffer(FT_HANDLE ft_handle, enum ft_msg_type type, MSN msn, const void *key, uint32_t keylen, const void *UU(data), uint32_t UU(datalen), XIDS UU(xids), const DBT *lesser_pivot, const DBT *greatereq_pivot)
  97. __attribute__((warn_unused_result));
  98. UU()
  99. static int
  100. verify_msg_in_child_buffer(FT_HANDLE ft_handle, enum ft_msg_type type, MSN msn, const void *key, uint32_t keylen, const void *UU(data), uint32_t UU(datalen), XIDS UU(xids), const DBT *lesser_pivot, const DBT *greatereq_pivot) {
  101. int result = 0;
  102. if (msn.msn == ZERO_MSN.msn)
  103. result = EINVAL;
  104. switch (type) {
  105. default:
  106. break;
  107. case FT_INSERT:
  108. case FT_INSERT_NO_OVERWRITE:
  109. case FT_DELETE_ANY:
  110. case FT_ABORT_ANY:
  111. case FT_COMMIT_ANY:
  112. // verify key in bounds
  113. if (lesser_pivot) {
  114. int compare = compare_pair_to_key(ft_handle, lesser_pivot, key, keylen);
  115. if (compare >= 0)
  116. result = EINVAL;
  117. }
  118. if (result == 0 && greatereq_pivot) {
  119. int compare = compare_pair_to_key(ft_handle, greatereq_pivot, key, keylen);
  120. if (compare < 0)
  121. result = EINVAL;
  122. }
  123. break;
  124. }
  125. return result;
  126. }
  127. static DBT
  128. get_ith_key_dbt (BASEMENTNODE bn, int i) {
  129. DBT kdbt;
  130. int r = bn->data_buffer.fetch_key_and_len(i, &kdbt.size, &kdbt.data);
  131. invariant_zero(r); // this is a bad failure if it happens.
  132. return kdbt;
  133. }
  134. #define VERIFY_ASSERTION(predicate, i, string) ({ \
  135. if(!(predicate)) { \
  136. (void) verbose; \
  137. if (true) { \
  138. fprintf(stderr, "%s:%d: Looking at child %d of block %" PRId64 ": %s\n", __FILE__, __LINE__, i, blocknum.b, string); \
  139. } \
  140. result = TOKUDB_NEEDS_REPAIR; \
  141. if (!keep_going_on_failure) goto done; \
  142. }})
  143. struct count_msgs_extra {
  144. int count;
  145. MSN msn;
  146. message_buffer *msg_buffer;
  147. };
  148. // template-only function, but must be extern
  149. int count_msgs(const int32_t &offset, const uint32_t UU(idx), struct count_msgs_extra *const e)
  150. __attribute__((nonnull(3)));
  151. int count_msgs(const int32_t &offset, const uint32_t UU(idx), struct count_msgs_extra *const e)
  152. {
  153. MSN msn;
  154. e->msg_buffer->get_message_key_msn(offset, nullptr, &msn);
  155. if (msn.msn == e->msn.msn) {
  156. e->count++;
  157. }
  158. return 0;
  159. }
  160. struct verify_message_tree_extra {
  161. message_buffer *msg_buffer;
  162. bool broadcast;
  163. bool is_fresh;
  164. int i;
  165. int verbose;
  166. BLOCKNUM blocknum;
  167. int keep_going_on_failure;
  168. bool messages_have_been_moved;
  169. };
  170. int verify_message_tree(const int32_t &offset, const uint32_t UU(idx), struct verify_message_tree_extra *const e) __attribute__((nonnull(3)));
  171. int verify_message_tree(const int32_t &offset, const uint32_t UU(idx), struct verify_message_tree_extra *const e)
  172. {
  173. int verbose = e->verbose;
  174. BLOCKNUM blocknum = e->blocknum;
  175. int keep_going_on_failure = e->keep_going_on_failure;
  176. int result = 0;
  177. DBT k, v;
  178. ft_msg msg = e->msg_buffer->get_message(offset, &k, &v);
  179. bool is_fresh = e->msg_buffer->get_freshness(offset);
  180. if (e->broadcast) {
  181. VERIFY_ASSERTION(ft_msg_type_applies_all((enum ft_msg_type) msg.type()) || ft_msg_type_does_nothing((enum ft_msg_type) msg.type()),
  182. e->i, "message found in broadcast list that is not a broadcast");
  183. } else {
  184. VERIFY_ASSERTION(ft_msg_type_applies_once((enum ft_msg_type) msg.type()),
  185. e->i, "message found in fresh or stale message tree that does not apply once");
  186. if (e->is_fresh) {
  187. if (e->messages_have_been_moved) {
  188. VERIFY_ASSERTION(is_fresh,
  189. e->i, "message found in fresh message tree that is not fresh");
  190. }
  191. } else {
  192. VERIFY_ASSERTION(!is_fresh,
  193. e->i, "message found in stale message tree that is fresh");
  194. }
  195. }
  196. done:
  197. return result;
  198. }
  199. int error_on_iter(const int32_t &UU(offset), const uint32_t UU(idx), void *UU(e));
  200. int error_on_iter(const int32_t &UU(offset), const uint32_t UU(idx), void *UU(e)) {
  201. return TOKUDB_NEEDS_REPAIR;
  202. }
  203. int verify_marked_messages(const int32_t &offset, const uint32_t UU(idx), struct verify_message_tree_extra *const e) __attribute__((nonnull(3)));
  204. int verify_marked_messages(const int32_t &offset, const uint32_t UU(idx), struct verify_message_tree_extra *const e)
  205. {
  206. int verbose = e->verbose;
  207. BLOCKNUM blocknum = e->blocknum;
  208. int keep_going_on_failure = e->keep_going_on_failure;
  209. int result = 0;
  210. bool is_fresh = e->msg_buffer->get_freshness(offset);
  211. VERIFY_ASSERTION(!is_fresh, e->i, "marked message found in the fresh message tree that is fresh");
  212. done:
  213. return result;
  214. }
  215. template<typename verify_omt_t>
  216. static int
  217. verify_sorted_by_key_msn(FT_HANDLE ft_handle, message_buffer *msg_buffer, const verify_omt_t &mt) {
  218. int result = 0;
  219. size_t last_offset = 0;
  220. for (uint32_t i = 0; i < mt.size(); i++) {
  221. int32_t offset;
  222. int r = mt.fetch(i, &offset);
  223. assert_zero(r);
  224. if (i > 0) {
  225. struct toku_msg_buffer_key_msn_cmp_extra extra(ft_handle->ft->cmp, msg_buffer);
  226. if (toku_msg_buffer_key_msn_cmp(extra, last_offset, offset) >= 0) {
  227. result = TOKUDB_NEEDS_REPAIR;
  228. break;
  229. }
  230. }
  231. last_offset = offset;
  232. }
  233. return result;
  234. }
  235. template<typename count_omt_t>
  236. static int
  237. count_eq_key_msn(FT_HANDLE ft_handle, message_buffer *msg_buffer, const count_omt_t &mt, const DBT *key, MSN msn) {
  238. struct toku_msg_buffer_key_msn_heaviside_extra extra(ft_handle->ft->cmp, msg_buffer, key, msn);
  239. int r = mt.template find_zero<struct toku_msg_buffer_key_msn_heaviside_extra, toku_msg_buffer_key_msn_heaviside>(extra, nullptr, nullptr);
  240. int count;
  241. if (r == 0) {
  242. count = 1;
  243. } else {
  244. assert(r == DB_NOTFOUND);
  245. count = 0;
  246. }
  247. return count;
  248. }
  249. void
  250. toku_get_node_for_verify(
  251. BLOCKNUM blocknum,
  252. FT_HANDLE ft_handle,
  253. FTNODE* nodep
  254. )
  255. {
  256. uint32_t fullhash = toku_cachetable_hash(ft_handle->ft->cf, blocknum);
  257. ftnode_fetch_extra bfe;
  258. bfe.create_for_full_read(ft_handle->ft);
  259. toku_pin_ftnode(
  260. ft_handle->ft,
  261. blocknum,
  262. fullhash,
  263. &bfe,
  264. PL_WRITE_EXPENSIVE, // may_modify_node
  265. nodep,
  266. false
  267. );
  268. }
  269. struct verify_msg_fn {
  270. FT_HANDLE ft_handle;
  271. NONLEAF_CHILDINFO bnc;
  272. const DBT *curr_less_pivot;
  273. const DBT *curr_geq_pivot;
  274. BLOCKNUM blocknum;
  275. MSN this_msn;
  276. int verbose;
  277. int keep_going_on_failure;
  278. bool messages_have_been_moved;
  279. MSN last_msn;
  280. int msg_i;
  281. int result = 0; // needed by VERIFY_ASSERTION
  282. verify_msg_fn(FT_HANDLE handle, NONLEAF_CHILDINFO nl, const DBT *less, const DBT *geq,
  283. BLOCKNUM b, MSN tmsn, int v, int k, bool m) :
  284. ft_handle(handle), bnc(nl), curr_less_pivot(less), curr_geq_pivot(geq),
  285. blocknum(b), this_msn(tmsn), verbose(v), keep_going_on_failure(k), messages_have_been_moved(m), last_msn(ZERO_MSN), msg_i(0) {
  286. }
  287. int operator()(const ft_msg &msg, bool is_fresh) {
  288. enum ft_msg_type type = (enum ft_msg_type) msg.type();
  289. MSN msn = msg.msn();
  290. XIDS xid = msg.xids();
  291. const void *key = msg.kdbt()->data;
  292. const void *data = msg.vdbt()->data;
  293. uint32_t keylen = msg.kdbt()->size;
  294. uint32_t datalen = msg.vdbt()->size;
  295. int r = verify_msg_in_child_buffer(ft_handle, type, msn, key, keylen, data, datalen, xid,
  296. curr_less_pivot,
  297. curr_geq_pivot);
  298. VERIFY_ASSERTION(r == 0, msg_i, "A message in the buffer is out of place");
  299. VERIFY_ASSERTION((msn.msn > last_msn.msn), msg_i, "msn per msg must be monotonically increasing toward newer messages in buffer");
  300. VERIFY_ASSERTION((msn.msn <= this_msn.msn), msg_i, "all messages must have msn within limit of this node's max_msn_applied_to_node_in_memory");
  301. if (ft_msg_type_applies_once(type)) {
  302. int count;
  303. DBT keydbt;
  304. toku_fill_dbt(&keydbt, key, keylen);
  305. int total_count = 0;
  306. count = count_eq_key_msn(ft_handle, &bnc->msg_buffer, bnc->fresh_message_tree, toku_fill_dbt(&keydbt, key, keylen), msn);
  307. total_count += count;
  308. if (is_fresh) {
  309. VERIFY_ASSERTION(count == 1, msg_i, "a fresh message was not found in the fresh message tree");
  310. } else if (messages_have_been_moved) {
  311. VERIFY_ASSERTION(count == 0, msg_i, "a stale message was found in the fresh message tree");
  312. }
  313. VERIFY_ASSERTION(count <= 1, msg_i, "a message was found multiple times in the fresh message tree");
  314. count = count_eq_key_msn(ft_handle, &bnc->msg_buffer, bnc->stale_message_tree, &keydbt, msn);
  315. total_count += count;
  316. if (is_fresh) {
  317. VERIFY_ASSERTION(count == 0, msg_i, "a fresh message was found in the stale message tree");
  318. } else if (messages_have_been_moved) {
  319. VERIFY_ASSERTION(count == 1, msg_i, "a stale message was not found in the stale message tree");
  320. }
  321. VERIFY_ASSERTION(count <= 1, msg_i, "a message was found multiple times in the stale message tree");
  322. VERIFY_ASSERTION(total_count <= 1, msg_i, "a message was found in both message trees (or more than once in a single tree)");
  323. VERIFY_ASSERTION(total_count >= 1, msg_i, "a message was not found in either message tree");
  324. } else {
  325. VERIFY_ASSERTION(ft_msg_type_applies_all(type) || ft_msg_type_does_nothing(type), msg_i, "a message was found that does not apply either to all or to only one key");
  326. struct count_msgs_extra extra = { .count = 0, .msn = msn, .msg_buffer = &bnc->msg_buffer };
  327. bnc->broadcast_list.iterate<struct count_msgs_extra, count_msgs>(&extra);
  328. VERIFY_ASSERTION(extra.count == 1, msg_i, "a broadcast message was not found in the broadcast list");
  329. }
  330. last_msn = msn;
  331. msg_i++;
  332. done:
  333. return result;
  334. }
  335. };
  336. static int
  337. toku_verify_ftnode_internal(FT_HANDLE ft_handle,
  338. MSN rootmsn, MSN parentmsn_with_messages, bool messages_exist_above,
  339. FTNODE node, int height,
  340. const DBT *lesser_pivot, // Everything in the subtree should be > lesser_pivot. (lesser_pivot==NULL if there is no lesser pivot.)
  341. const DBT *greatereq_pivot, // Everything in the subtree should be <= lesser_pivot. (lesser_pivot==NULL if there is no lesser pivot.)
  342. int verbose, int keep_going_on_failure, bool messages_have_been_moved)
  343. {
  344. int result=0;
  345. MSN this_msn;
  346. BLOCKNUM blocknum = node->blocknum;
  347. //printf("%s:%d pin %p\n", __FILE__, __LINE__, node_v);
  348. toku_ftnode_assert_fully_in_memory(node);
  349. this_msn = node->max_msn_applied_to_node_on_disk;
  350. if (height >= 0) {
  351. invariant(height == node->height); // this is a bad failure if wrong
  352. }
  353. if (node->height > 0 && messages_exist_above) {
  354. VERIFY_ASSERTION((parentmsn_with_messages.msn >= this_msn.msn), 0, "node msn must be descending down tree, newest messages at top");
  355. }
  356. // Verify that all the pivot keys are in order.
  357. for (int i = 0; i < node->n_children-2; i++) {
  358. DBT x, y;
  359. int compare = compare_pairs(ft_handle, node->pivotkeys.fill_pivot(i, &x), node->pivotkeys.fill_pivot(i + 1, &y));
  360. VERIFY_ASSERTION(compare < 0, i, "Value is >= the next value");
  361. }
  362. // Verify that all the pivot keys are lesser_pivot < pivot <= greatereq_pivot
  363. for (int i = 0; i < node->n_children-1; i++) {
  364. DBT x;
  365. if (lesser_pivot) {
  366. int compare = compare_pairs(ft_handle, lesser_pivot, node->pivotkeys.fill_pivot(i, &x));
  367. VERIFY_ASSERTION(compare < 0, i, "Pivot is >= the lower-bound pivot");
  368. }
  369. if (greatereq_pivot) {
  370. int compare = compare_pairs(ft_handle, greatereq_pivot, node->pivotkeys.fill_pivot(i, &x));
  371. VERIFY_ASSERTION(compare >= 0, i, "Pivot is < the upper-bound pivot");
  372. }
  373. }
  374. for (int i = 0; i < node->n_children; i++) {
  375. DBT x, y;
  376. const DBT *curr_less_pivot = (i==0) ? lesser_pivot : node->pivotkeys.fill_pivot(i - 1, &x);
  377. const DBT *curr_geq_pivot = (i==node->n_children-1) ? greatereq_pivot : node->pivotkeys.fill_pivot(i, &y);
  378. if (node->height > 0) {
  379. NONLEAF_CHILDINFO bnc = BNC(node, i);
  380. // Verify that messages in the buffers are in the right place.
  381. VERIFY_ASSERTION(verify_sorted_by_key_msn(ft_handle, &bnc->msg_buffer, bnc->fresh_message_tree) == 0, i, "fresh_message_tree");
  382. VERIFY_ASSERTION(verify_sorted_by_key_msn(ft_handle, &bnc->msg_buffer, bnc->stale_message_tree) == 0, i, "stale_message_tree");
  383. verify_msg_fn verify_msg(ft_handle, bnc, curr_less_pivot, curr_geq_pivot,
  384. blocknum, this_msn, verbose, keep_going_on_failure, messages_have_been_moved);
  385. int r = bnc->msg_buffer.iterate(verify_msg);
  386. if (r != 0) { result = r; goto done; }
  387. struct verify_message_tree_extra extra = { .msg_buffer = &bnc->msg_buffer, .broadcast = false, .is_fresh = true, .i = i, .verbose = verbose, .blocknum = node->blocknum, .keep_going_on_failure = keep_going_on_failure, .messages_have_been_moved = messages_have_been_moved };
  388. r = bnc->fresh_message_tree.iterate<struct verify_message_tree_extra, verify_message_tree>(&extra);
  389. if (r != 0) { result = r; goto done; }
  390. extra.is_fresh = false;
  391. r = bnc->stale_message_tree.iterate<struct verify_message_tree_extra, verify_message_tree>(&extra);
  392. if (r != 0) { result = r; goto done; }
  393. bnc->fresh_message_tree.verify_marks_consistent();
  394. if (messages_have_been_moved) {
  395. VERIFY_ASSERTION(!bnc->fresh_message_tree.has_marks(), i, "fresh message tree still has marks after moving messages");
  396. r = bnc->fresh_message_tree.iterate_over_marked<void, error_on_iter>(nullptr);
  397. if (r != 0) { result = r; goto done; }
  398. }
  399. else {
  400. r = bnc->fresh_message_tree.iterate_over_marked<struct verify_message_tree_extra, verify_marked_messages>(&extra);
  401. if (r != 0) { result = r; goto done; }
  402. }
  403. extra.broadcast = true;
  404. r = bnc->broadcast_list.iterate<struct verify_message_tree_extra, verify_message_tree>(&extra);
  405. if (r != 0) { result = r; goto done; }
  406. }
  407. else {
  408. BASEMENTNODE bn = BLB(node, i);
  409. for (uint32_t j = 0; j < bn->data_buffer.num_klpairs(); j++) {
  410. VERIFY_ASSERTION((rootmsn.msn >= this_msn.msn), 0, "leaf may have latest msn, but cannot be greater than root msn");
  411. DBT kdbt = get_ith_key_dbt(bn, j);
  412. if (curr_less_pivot) {
  413. int compare = compare_pairs(ft_handle, curr_less_pivot, &kdbt);
  414. VERIFY_ASSERTION(compare < 0, j, "The leafentry is >= the lower-bound pivot");
  415. }
  416. if (curr_geq_pivot) {
  417. int compare = compare_pairs(ft_handle, curr_geq_pivot, &kdbt);
  418. VERIFY_ASSERTION(compare >= 0, j, "The leafentry is < the upper-bound pivot");
  419. }
  420. if (0 < j) {
  421. DBT prev_key_dbt = get_ith_key_dbt(bn, j-1);
  422. int compare = compare_pairs(ft_handle, &prev_key_dbt, &kdbt);
  423. VERIFY_ASSERTION(compare < 0, j, "Adjacent leafentries are out of order");
  424. }
  425. }
  426. }
  427. }
  428. done:
  429. return result;
  430. }
  431. // input is a pinned node, on exit, node is unpinned
  432. int
  433. toku_verify_ftnode (FT_HANDLE ft_handle,
  434. MSN rootmsn, MSN parentmsn_with_messages, bool messages_exist_above,
  435. FTNODE node, int height,
  436. const DBT *lesser_pivot, // Everything in the subtree should be > lesser_pivot. (lesser_pivot==NULL if there is no lesser pivot.)
  437. const DBT *greatereq_pivot, // Everything in the subtree should be <= lesser_pivot. (lesser_pivot==NULL if there is no lesser pivot.)
  438. int (*progress_callback)(void *extra, float progress), void *progress_extra,
  439. int recurse, int verbose, int keep_going_on_failure)
  440. {
  441. MSN this_msn;
  442. //printf("%s:%d pin %p\n", __FILE__, __LINE__, node_v);
  443. toku_ftnode_assert_fully_in_memory(node);
  444. this_msn = node->max_msn_applied_to_node_on_disk;
  445. int result = 0;
  446. int result2 = 0;
  447. if (node->height > 0) {
  448. // Otherwise we'll just do the next call
  449. result = toku_verify_ftnode_internal(
  450. ft_handle, rootmsn, parentmsn_with_messages, messages_exist_above, node, height, lesser_pivot, greatereq_pivot,
  451. verbose, keep_going_on_failure, false);
  452. if (result != 0 && (!keep_going_on_failure || result != TOKUDB_NEEDS_REPAIR)) goto done;
  453. }
  454. if (node->height > 0) {
  455. toku_move_ftnode_messages_to_stale(ft_handle->ft, node);
  456. }
  457. result2 = toku_verify_ftnode_internal(
  458. ft_handle, rootmsn, parentmsn_with_messages, messages_exist_above, node, height, lesser_pivot, greatereq_pivot,
  459. verbose, keep_going_on_failure, true);
  460. if (result == 0) {
  461. result = result2;
  462. if (result != 0 && (!keep_going_on_failure || result != TOKUDB_NEEDS_REPAIR)) goto done;
  463. }
  464. // Verify that the subtrees have the right properties.
  465. if (recurse && node->height > 0) {
  466. for (int i = 0; i < node->n_children; i++) {
  467. FTNODE child_node;
  468. toku_get_node_for_verify(BP_BLOCKNUM(node, i), ft_handle, &child_node);
  469. DBT x, y;
  470. int r = toku_verify_ftnode(ft_handle, rootmsn,
  471. (toku_bnc_n_entries(BNC(node, i)) > 0
  472. ? this_msn
  473. : parentmsn_with_messages),
  474. messages_exist_above || toku_bnc_n_entries(BNC(node, i)) > 0,
  475. child_node, node->height-1,
  476. (i==0) ? lesser_pivot : node->pivotkeys.fill_pivot(i - 1, &x),
  477. (i==node->n_children-1) ? greatereq_pivot : node->pivotkeys.fill_pivot(i, &y),
  478. progress_callback, progress_extra,
  479. recurse, verbose, keep_going_on_failure);
  480. if (r) {
  481. result = r;
  482. if (!keep_going_on_failure || result != TOKUDB_NEEDS_REPAIR) goto done;
  483. }
  484. }
  485. }
  486. done:
  487. toku_unpin_ftnode(ft_handle->ft, node);
  488. if (result == 0 && progress_callback)
  489. result = progress_callback(progress_extra, 0.0);
  490. return result;
  491. }
  492. int
  493. toku_verify_ft_with_progress (FT_HANDLE ft_handle, int (*progress_callback)(void *extra, float progress), void *progress_extra, int verbose, int keep_on_going) {
  494. assert(ft_handle->ft);
  495. FTNODE root_node = NULL;
  496. {
  497. uint32_t root_hash;
  498. CACHEKEY root_key;
  499. toku_calculate_root_offset_pointer(ft_handle->ft, &root_key, &root_hash);
  500. toku_get_node_for_verify(root_key, ft_handle, &root_node);
  501. }
  502. int r = toku_verify_ftnode(ft_handle, ft_handle->ft->h->max_msn_in_ft, ft_handle->ft->h->max_msn_in_ft, false, root_node, -1, NULL, NULL, progress_callback, progress_extra, 1, verbose, keep_on_going);
  503. if (r == 0) {
  504. toku_ft_lock(ft_handle->ft);
  505. ft_handle->ft->h->time_of_last_verification = time(NULL);
  506. ft_handle->ft->h->dirty = 1;
  507. toku_ft_unlock(ft_handle->ft);
  508. }
  509. return r;
  510. }
  511. int
  512. toku_verify_ft (FT_HANDLE ft_handle) {
  513. return toku_verify_ft_with_progress(ft_handle, NULL, NULL, 0, 0);
  514. }