1 /* Copyright (c) 2003-2006 MySQL AB 2 Use is subject to license terms 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 as published by 6 the Free Software Foundation; version 2 of the License. 7 8 This program is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License 14 along with this program; if not, write to the Free Software 15 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ 16 17 #ifndef TRIX_H 18 #define TRIX_H 19 20 #include <SimulatedBlock.hpp> 21 #include <trigger_definitions.h> 22 #include <DataBuffer.hpp> 23 #include <SimpleProperties.hpp> 24 #include <signaldata/DictTabInfo.hpp> 25 #include <signaldata/CreateTrig.hpp> 26 #include <signaldata/BuildIndx.hpp> 27 28 // Error codes 29 #define INTERNAL_ERROR_ILLEGAL_CALL 4344 30 #define INTERNAL_ERROR_TRIX_BUSY 4345 31 32 /** 33 * TRIX - This block manages triggers and index (in coop with DICT) 34 */ 35 class Trix : public SimulatedBlock 36 { 37 public: 38 Trix(Block_context&); 39 virtual ~Trix(); 40 41 public: 42 // Subscription data, when communicating with SUMA 43 44 enum RequestType { 45 TABLE_REORG = 0, 46 INDEX_BUILD = 1 47 }; 48 typedef DataBuffer<11> AttrOrderBuffer; 49 50 private: 51 // Private attributes 52 53 BLOCK_DEFINES(Trix); 54 55 // Declared but not defined 56 //DBtrix(const Trix &obj); 57 //void operator = (const Trix &); 58 59 // Block state 60 enum BlockState { 61 NOT_STARTED, 62 STARTED, 63 NODE_FAILURE, 64 IDLE, 65 BUSY 66 }; 67 68 BlockState c_blockState; 69 70 // Node data needed when communicating with remote TRIX:es 71 struct NodeRecord { 72 bool alive; 73 BlockReference trixRef; 74 union { 75 Uint32 nextPool; 76 Uint32 nextList; 77 }; 78 Uint32 prevList; 79 }; 80 81 typedef Ptr<NodeRecord> NodeRecPtr; 82 83 /** 84 * The pool of node records 85 */ 86 ArrayPool<NodeRecord> c_theNodeRecPool; 87 88 /** 89 * The list of other NDB nodes 90 */ 91 DLList<NodeRecord> c_theNodes; 92 93 Uint32 c_masterNodeId; 94 BlockReference c_masterTrixRef; 95 Uint16 c_noNodesFailed; 96 Uint16 c_noActiveNodes; 97 98 AttrOrderBuffer::DataBufferPool c_theAttrOrderBufferPool; 99 100 struct SubscriptionRecord { SubscriptionRecordTrix::SubscriptionRecord101 SubscriptionRecord(AttrOrderBuffer::DataBufferPool & aop): 102 attributeOrder(aop) 103 {} 104 RequestType requestType; 105 BlockReference userReference; // For user 106 Uint32 connectionPtr; // For user 107 Uint32 subscriptionId; // For Suma 108 Uint32 subscriptionKey; // For Suma 109 Uint32 prepareId; // For DbUtil 110 Uint32 indexType; 111 Uint32 sourceTableId; 112 Uint32 targetTableId; 113 AttrOrderBuffer attributeOrder; 114 Uint32 noOfIndexColumns; 115 Uint32 noOfKeyColumns; 116 Uint32 parallelism; 117 BuildIndxRef::ErrorCode errorCode; 118 bool subscriptionCreated; 119 bool pendingSubSyncContinueConf; 120 Uint32 expectedConf; // Count in n UTIL_EXECUTE_CONF + 1 SUB_SYNC_CONF 121 union { 122 Uint32 nextPool; 123 Uint32 nextList; 124 }; 125 Uint32 prevList; 126 }; 127 128 typedef Ptr<SubscriptionRecord> SubscriptionRecPtr; 129 130 /** 131 * The pool of node records 132 */ 133 ArrayPool<SubscriptionRecord> c_theSubscriptionRecPool; 134 135 /** 136 * The list of other subscriptions 137 */ 138 DLList<SubscriptionRecord> c_theSubscriptions; 139 140 // System start 141 void execREAD_CONFIG_REQ(Signal* signal); 142 void execSTTOR(Signal* signal); 143 void execNDB_STTOR(Signal* signal); 144 145 // Node management 146 void execREAD_NODESCONF(Signal* signal); 147 void execREAD_NODESREF(Signal* signal); 148 void execNODE_FAILREP(Signal* signal); 149 void execINCL_NODEREQ(Signal* signal); 150 // Debugging 151 void execDUMP_STATE_ORD(Signal* signal); 152 153 // Build index 154 void execBUILDINDXREQ(Signal* signal); 155 void execBUILDINDXCONF(Signal* signal); 156 void execBUILDINDXREF(Signal* signal); 157 158 void execUTIL_PREPARE_CONF(Signal* signal); 159 void execUTIL_PREPARE_REF(Signal* signal); 160 void execUTIL_EXECUTE_CONF(Signal* signal); 161 void execUTIL_EXECUTE_REF(Signal* signal); 162 void execUTIL_RELEASE_CONF(Signal* signal); 163 void execUTIL_RELEASE_REF(Signal* signal); 164 165 // Suma signals 166 void execSUB_CREATE_CONF(Signal* signal); 167 void execSUB_CREATE_REF(Signal* signal); 168 void execSUB_REMOVE_CONF(Signal* signal); 169 void execSUB_REMOVE_REF(Signal* signal); 170 void execSUB_SYNC_CONF(Signal* signal); 171 void execSUB_SYNC_REF(Signal* signal); 172 void execSUB_SYNC_CONTINUE_REQ(Signal* signal); 173 void execSUB_TABLE_DATA(Signal* signal); 174 175 // Utility functions 176 void setupSubscription(Signal* signal, SubscriptionRecPtr subRecPtr); 177 void startTableScan(Signal* signal, SubscriptionRecPtr subRecPtr); 178 void prepareInsertTransactions(Signal* signal, SubscriptionRecPtr subRecPtr); 179 void executeInsertTransaction(Signal* signal, SubscriptionRecPtr subRecPtr, 180 SegmentedSectionPtr headerPtr, 181 SegmentedSectionPtr dataPtr); 182 void buildComplete(Signal* signal, SubscriptionRecPtr subRecPtr); 183 void buildFailed(Signal* signal, 184 SubscriptionRecPtr subRecPtr, 185 BuildIndxRef::ErrorCode); 186 void checkParallelism(Signal* signal, SubscriptionRecord* subRec); 187 }; 188 189 #endif 190