1 /* 2 Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License, version 2.0, 6 as published by the Free Software Foundation. 7 8 This program is also distributed with certain software (including 9 but not limited to OpenSSL) that is licensed under separate terms, 10 as designated in a particular file or component or in included license 11 documentation. The authors of MySQL hereby grant you an additional 12 permission to link the program and your derivative works with the 13 separately licensed software that they have included with MySQL. 14 15 This program is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU General Public License, version 2.0, for more details. 19 20 You should have received a copy of the GNU General Public License 21 along with this program; if not, write to the Free Software 22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 */ 24 25 #ifndef UTIL_TRANSACTIONS_HPP 26 #define UTIL_TRANSACTIONS_HPP 27 28 #include <NDBT.hpp> 29 30 typedef int (ReadCallBackFn)(NDBT_ResultRow*); 31 32 class UtilTransactions { 33 public: 34 Uint64 m_util_latest_gci; get_high_latest_gci()35 Uint32 get_high_latest_gci() 36 { 37 return Uint32(Uint64(m_util_latest_gci >> 32)); 38 } get_low_latest_gci()39 Uint32 get_low_latest_gci() 40 { 41 return Uint32(Uint64(m_util_latest_gci & 0xFFFFFFFF)); 42 } 43 UtilTransactions(const NdbDictionary::Table&, 44 const NdbDictionary::Index* idx = 0); 45 UtilTransactions(Ndb* ndb, 46 const char * tableName, const char * indexName = 0); 47 48 int closeTransaction(Ndb*); 49 50 int clearTable(Ndb*, 51 NdbScanOperation::ScanFlag, 52 int records = 0, 53 int parallelism = 0); 54 55 int clearTable(Ndb*, 56 int records = 0, 57 int parallelism = 0); 58 59 // Delete all records from the table using a scan 60 int clearTable1(Ndb*, 61 int records = 0, 62 int parallelism = 0); 63 // Delete all records from the table using a scan 64 // Using batching 65 int clearTable2(Ndb*, 66 int records = 0, 67 int parallelism = 0); 68 69 int clearTable3(Ndb*, 70 int records = 0, 71 int parallelism = 0); 72 73 int selectCount(Ndb*, 74 int parallelism = 0, 75 int* count_rows = NULL, 76 NdbOperation::LockMode lm = NdbOperation::LM_CommittedRead); 77 78 int scanReadRecords(Ndb*, 79 int parallelism, 80 NdbOperation::LockMode lm, 81 int records, 82 int noAttribs, 83 int* attrib_list, 84 ReadCallBackFn* fn = NULL); 85 int verifyIndex(Ndb*, 86 const char* indexName, 87 int parallelism = 0, 88 bool transactional = false); 89 90 int copyTableData(Ndb*, 91 const char* destName); 92 93 /** 94 * Compare this table with other_table 95 * 96 * return 0 - on equality 97 * -1 - on error 98 * >0 - otherwise 99 */ 100 int compare(Ndb*, const char * other_table, int flags); 101 102 private: 103 static int takeOverAndDeleteRecord(Ndb*, 104 NdbOperation*); 105 106 int addRowToDelete(Ndb* pNdb, 107 NdbConnection* pDelTrans, 108 NdbOperation* pOrgOp); 109 110 111 int addRowToInsert(Ndb* pNdb, 112 NdbConnection* pInsTrans, 113 NDBT_ResultRow & row, 114 const char* insertTabName); 115 116 117 int verifyUniqueIndex(Ndb*, 118 const NdbDictionary::Index *, 119 int parallelism = 0, 120 bool transactional = false); 121 122 int scanAndCompareUniqueIndex(Ndb* pNdb, 123 const NdbDictionary::Index *, 124 int parallelism, 125 bool transactional); 126 127 int readRowFromTableAndIndex(Ndb* pNdb, 128 NdbConnection* pTrans, 129 const NdbDictionary::Index *, 130 NDBT_ResultRow& row ); 131 132 int verifyOrderedIndex(Ndb*, 133 const NdbDictionary::Index *, 134 int parallelism = 0, 135 bool transactional = false); 136 137 138 int get_values(NdbOperation* op, NDBT_ResultRow& dst); 139 int equal(const NdbDictionary::Table*, NdbOperation*, const NDBT_ResultRow&); 140 int equal(const NdbDictionary::Index*, NdbOperation*, const NDBT_ResultRow&); 141 142 protected: 143 int m_defaultClearMethod; 144 const NdbDictionary::Table& tab; 145 const NdbDictionary::Index* idx; 146 NdbConnection* pTrans; 147 148 NdbOperation* getOperation(NdbConnection*, 149 NdbOperation::OperationType); 150 NdbScanOperation* getScanOperation(NdbConnection*); 151 }; 152 153 #endif 154