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/*======
5This file is part of PerconaFT.
6
7
8Copyright (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#pragma once
40
41#include <ft/txn/txn_state.h>
42#include <toku_pthread.h>
43
44// the indexer_commit_keys is an ordered set of keys described by a DBT in the keys array.
45// the array is a resizable array with max size "max_keys" and current size "current_keys".
46// the ordered set is used by the hotindex undo function to collect the commit keys.
47struct indexer_commit_keys {
48 int max_keys; // max number of keys
49 int current_keys; // number of valid keys
50 DBT *keys; // the variable length keys array
51};
52
53// a ule and all of its provisional txn info
54// used by the undo-do algorithm to gather up ule provisional info in
55// a cursor callback that provides exclusive access to the source DB
56// with respect to txn commit and abort
57struct ule_prov_info {
58 // these are pointers to the allocated leafentry and ule needed to calculate
59 // provisional info. we only borrow them - whoever created the provisional info
60 // is responsible for cleaning up the leafentry and ule when done.
61 LEAFENTRY le;
62 ULEHANDLE ule;
63 void* key;
64 uint32_t keylen;
65 // provisional txn info for the ule
66 uint32_t num_provisional;
67 uint32_t num_committed;
68 TXNID *prov_ids;
69 TOKUTXN *prov_txns;
70 TOKUTXN_STATE *prov_states;
71};
72
73struct __toku_indexer_internal {
74 DB_ENV *env;
75 DB_TXN *txn;
76 toku_mutex_t indexer_lock;
77 toku_mutex_t indexer_estimate_lock;
78 DBT position_estimate;
79 DB *src_db;
80 int N;
81 DB **dest_dbs; /* [N] */
82 uint32_t indexer_flags;
83 void (*error_callback)(DB *db, int i, int err, DBT *key, DBT *val, void *error_extra);
84 void *error_extra;
85 int (*poll_func)(void *poll_extra, float progress);
86 void *poll_extra;
87 uint64_t estimated_rows; // current estimate of table size
88 uint64_t loop_mod; // how often to call poll_func
89 LE_CURSOR lec;
90 FILENUM *fnums; /* [N] */
91 FILENUMS filenums;
92
93 // undo state
94 struct indexer_commit_keys commit_keys; // set of keys to commit
95 DBT_ARRAY *hot_keys;
96 DBT_ARRAY *hot_vals;
97
98 // test functions
99 int (*undo_do)(DB_INDEXER *indexer, DB *hotdb, DBT* key, ULEHANDLE ule);
100 TOKUTXN_STATE (*test_xid_state)(DB_INDEXER *indexer, TXNID xid);
101 void (*test_lock_key)(DB_INDEXER *indexer, TXNID xid, DB *hotdb, DBT *key);
102 int (*test_delete_provisional)(DB_INDEXER *indexer, DB *hotdb, DBT *hotkey, XIDS xids);
103 int (*test_delete_committed)(DB_INDEXER *indexer, DB *hotdb, DBT *hotkey, XIDS xids);
104 int (*test_insert_provisional)(DB_INDEXER *indexer, DB *hotdb, DBT *hotkey, DBT *hotval, XIDS xids);
105 int (*test_insert_committed)(DB_INDEXER *indexer, DB *hotdb, DBT *hotkey, DBT *hotval, XIDS xids);
106 int (*test_commit_any)(DB_INDEXER *indexer, DB *db, DBT *key, XIDS xids);
107
108 // test flags
109 int test_only_flags;
110};
111
112void indexer_undo_do_init(DB_INDEXER *indexer);
113
114void indexer_undo_do_destroy(DB_INDEXER *indexer);
115
116int indexer_undo_do(DB_INDEXER *indexer, DB *hotdb, struct ule_prov_info *prov_info, DBT_ARRAY *hot_keys, DBT_ARRAY *hot_vals);
117