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.

199 lines
8.0 KiB

  1. /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
  2. // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
  3. #ifndef TOKU_CHECKPOINT_H
  4. #define TOKU_CHECKPOINT_H
  5. /*
  6. COPYING CONDITIONS NOTICE:
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of version 2 of the GNU General Public License as
  9. published by the Free Software Foundation, and provided that the
  10. following conditions are met:
  11. * Redistributions of source code must retain this COPYING
  12. CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
  13. DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
  14. PATENT MARKING NOTICE (below), and the PATENT RIGHTS
  15. GRANT (below).
  16. * Redistributions in binary form must reproduce this COPYING
  17. CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
  18. DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
  19. PATENT MARKING NOTICE (below), and the PATENT RIGHTS
  20. GRANT (below) in the documentation and/or other materials
  21. provided with the distribution.
  22. You should have received a copy of the GNU General Public License
  23. along with this program; if not, write to the Free Software
  24. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  25. 02110-1301, USA.
  26. COPYRIGHT NOTICE:
  27. TokuDB, Tokutek Fractal Tree Indexing Library.
  28. Copyright (C) 2007-2013 Tokutek, Inc.
  29. DISCLAIMER:
  30. This program is distributed in the hope that it will be useful, but
  31. WITHOUT ANY WARRANTY; without even the implied warranty of
  32. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  33. General Public License for more details.
  34. UNIVERSITY PATENT NOTICE:
  35. The technology is licensed by the Massachusetts Institute of
  36. Technology, Rutgers State University of New Jersey, and the Research
  37. Foundation of State University of New York at Stony Brook under
  38. United States of America Serial No. 11/760379 and to the patents
  39. and/or patent applications resulting from it.
  40. PATENT MARKING NOTICE:
  41. This software is covered by US Patent No. 8,185,551.
  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) 2009-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. #ident "$Id$"
  74. #include "cachetable.h"
  75. #include <stdint.h>
  76. void toku_set_checkpoint_period(CACHETABLE ct, uint32_t new_period);
  77. //Effect: Change [end checkpoint (n) - begin checkpoint (n+1)] delay to
  78. // new_period seconds. 0 means disable.
  79. uint32_t toku_get_checkpoint_period_unlocked(CACHETABLE ct);
  80. /******
  81. *
  82. * NOTE: checkpoint_safe_lock is highest level lock
  83. * multi_operation_lock is next level lock
  84. * ydb_big_lock is next level lock
  85. *
  86. * Locks must always be taken in this sequence (highest level first).
  87. *
  88. */
  89. /******
  90. * Client code must hold the checkpoint_safe lock during the following operations:
  91. * - delete a dictionary via DB->remove
  92. * - delete a dictionary via DB_TXN->abort(txn) (where txn created a dictionary)
  93. * - rename a dictionary //TODO: Handlerton rename needs to take this
  94. * //TODO: Handlerton rename needs to be recoded for transaction recovery
  95. *****/
  96. void toku_checkpoint_safe_client_lock(void);
  97. void toku_checkpoint_safe_client_unlock(void);
  98. /******
  99. * These functions are called from the ydb level.
  100. * Client code must hold the multi_operation lock during the following operations:
  101. * - insertion into multiple indexes
  102. * - replace into (simultaneous delete/insert on a single key)
  103. *****/
  104. void toku_multi_operation_client_lock(void);
  105. void toku_low_priority_multi_operation_client_lock(void);
  106. void toku_multi_operation_client_unlock(void);
  107. void toku_low_priority_multi_operation_client_unlock(void);
  108. // Initialize the checkpoint mechanism, must be called before any client operations.
  109. // Must pass in function pointers to take/release ydb lock.
  110. void toku_checkpoint_init(void);
  111. void toku_checkpoint_destroy(void);
  112. typedef enum {SCHEDULED_CHECKPOINT = 0, // "normal" checkpoint taken on checkpoint thread
  113. CLIENT_CHECKPOINT = 1, // induced by client, such as FLUSH LOGS or SAVEPOINT
  114. INDEXER_CHECKPOINT = 2,
  115. STARTUP_CHECKPOINT = 3,
  116. UPGRADE_CHECKPOINT = 4,
  117. RECOVERY_CHECKPOINT = 5,
  118. SHUTDOWN_CHECKPOINT = 6} checkpoint_caller_t;
  119. // Take a checkpoint of all currently open dictionaries
  120. // Callbacks are called during checkpoint procedure while checkpoint_safe lock is still held.
  121. // Callbacks are primarily intended for use in testing.
  122. // caller_id identifies why the checkpoint is being taken.
  123. int toku_checkpoint(CHECKPOINTER cp, TOKULOGGER logger,
  124. void (*callback_f)(void*), void * extra,
  125. void (*callback2_f)(void*), void * extra2,
  126. checkpoint_caller_t caller_id);
  127. /******
  128. * These functions are called from the ydb level.
  129. * They return status information and have no side effects.
  130. * Some status information may be incorrect because no locks are taken to collect status.
  131. * (If checkpoint is in progress, it may overwrite status info while it is being read.)
  132. *****/
  133. typedef enum {
  134. CP_PERIOD,
  135. CP_FOOTPRINT,
  136. CP_TIME_LAST_CHECKPOINT_BEGIN,
  137. CP_TIME_LAST_CHECKPOINT_BEGIN_COMPLETE,
  138. CP_TIME_LAST_CHECKPOINT_END,
  139. CP_LAST_LSN,
  140. CP_CHECKPOINT_COUNT,
  141. CP_CHECKPOINT_COUNT_FAIL,
  142. CP_WAITERS_NOW, // how many threads are currently waiting for the checkpoint_safe lock to perform a checkpoint
  143. CP_WAITERS_MAX, // max threads ever simultaneously waiting for the checkpoint_safe lock to perform a checkpoint
  144. CP_CLIENT_WAIT_ON_MO, // how many times a client thread waited to take the multi_operation lock, not for checkpoint
  145. CP_CLIENT_WAIT_ON_CS, // how many times a client thread waited for the checkpoint_safe lock, not for checkpoint
  146. CP_STATUS_NUM_ROWS // number of rows in this status array
  147. } cp_status_entry;
  148. typedef struct {
  149. bool initialized;
  150. TOKU_ENGINE_STATUS_ROW_S status[CP_STATUS_NUM_ROWS];
  151. } CHECKPOINT_STATUS_S, *CHECKPOINT_STATUS;
  152. void toku_checkpoint_get_status(CACHETABLE ct, CHECKPOINT_STATUS stat);
  153. #endif