1 /*
2 Copyright (c) 2003, 2021, Oracle and/or its affiliates.
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 DBTUP_H
26 #define DBTUP_H
27
28 #include <pc.hpp>
29 #include <SimulatedBlock.hpp>
30 #include <ndb_limits.h>
31 #include <trigger_definitions.h>
32 #include <AttributeHeader.hpp>
33 #include <Bitmask.hpp>
34 #include <signaldata/TupKey.hpp>
35 #include <signaldata/CreateTrig.hpp>
36 #include <signaldata/CreateTrigImpl.hpp>
37 #include <signaldata/DropTrig.hpp>
38 #include <signaldata/DropTrigImpl.hpp>
39 #include <signaldata/TrigAttrInfo.hpp>
40 #include <signaldata/BuildIndxImpl.hpp>
41 #include <signaldata/AlterTab.hpp>
42 #include <AttributeDescriptor.hpp>
43 #include "AttributeOffset.hpp"
44 #include "Undo_buffer.hpp"
45 #include "tuppage.hpp"
46 #include <DynArr256.hpp>
47 #include "../pgman.hpp"
48 #include "../tsman.hpp"
49
50 #define JAM_FILE_ID 414
51
52
53
54 #ifdef VM_TRACE
dbgmask(const Bitmask<MAXNROFATTRIBUTESINWORDS> & bm)55 inline const char* dbgmask(const Bitmask<MAXNROFATTRIBUTESINWORDS>& bm) {
56 static int i=0; static char buf[5][200];
57 bm.getText(buf[i%5]); return buf[i++%5]; }
dbgmask(const Uint32 bm[2])58 inline const char* dbgmask(const Uint32 bm[2]) {
59 static int i=0; static char buf[5][200];
60 sprintf(buf[i%5],"%08x%08x",bm[1],bm[0]); return buf[i++%5]; }
61 #endif
62
63 #define ZWORDS_ON_PAGE 8192 /* NUMBER OF WORDS ON A PAGE. */
64 #define ZMIN_PAGE_LIMIT_TUPKEYREQ 5
65 #define ZTUP_VERSION_BITS 15
66 #define ZTUP_VERSION_MASK ((1 << ZTUP_VERSION_BITS) - 1)
67 #define MAX_FREE_LIST 4
68
ALIGN_WORD(void * ptr)69 inline Uint32* ALIGN_WORD(void * ptr)
70 {
71 return (Uint32*)(((UintPtr(ptr) + 3) >> 2) << 2);
72 }
73
ALIGN_WORD(const void * ptr)74 inline const Uint32* ALIGN_WORD(const void* ptr)
75 {
76 return (Uint32*)(((UintPtr(ptr) + 3) >> 2) << 2);
77 }
78
79 #ifdef DBTUP_C
80
81 /*
82 2.2 LOCAL SYMBOLS
83 -----------------
84 */
85 /* ---------------------------------------------------------------- */
86 /* S I Z E O F R E C O R D S */
87 /* ---------------------------------------------------------------- */
88 #define ZNO_OF_CONCURRENT_OPEN_OP 40 /* NUMBER OF CONCURRENT OPENS */
89 #define ZNO_OF_CONCURRENT_WRITE_OP 80 /* NUMBER OF CONCURRENT DISK WRITES*/
90 #define ZNO_OF_FRAGOPREC 20 /* NUMBER OF CONCURRENT ADD FRAG. */
91 #define TOT_PAGE_RECORD_SPACE 262144 /* SIZE OF PAGE RECORD FILE. */
92 #define ZNO_OF_PAGE TOT_PAGE_RECORD_SPACE/ZWORDS_ON_PAGE
93 #define ZNO_OF_PAGE_RANGE_REC 128 /* SIZE OF PAGE RANGE FILE */
94 // Trigger constants
95 #define ZDEFAULT_MAX_NO_TRIGGERS_PER_TABLE 16
96
97 /* ---------------------------------------------------------------- */
98 /* A ATTRIBUTE MAY BE NULL, DYNAMIC OR NORMAL. A NORMAL ATTRIBUTE */
99 /* IS A ATTRIBUTE THAT IS NOT NULL OR DYNAMIC. A NULL ATTRIBUTE */
100 /* MAY HAVE NO VALUE. A DYNAMIC ATTRIBUTE IS A NULL ATTRIBUTE THAT */
101 /* DOES NOT HAVE TO BE A MEMBER OF EVERY TUPLE I A CERTAIN TABLE. */
102 /* ---------------------------------------------------------------- */
103 /**
104 * #defines moved into include/kernel/Interpreter.hpp
105 */
106 #define ZINSERT_DELETE 0
107 #define ZUPDATE_ALL 8
108 /* ---------------------------------------------------------------- */
109 /* THE MINIMUM SIZE OF AN 'EMPTY' TUPLE HEADER IN R-WORDS */
110 /* ---------------------------------------------------------------- */
111 /* THE TUPLE HEADER FIELD 'SIZE OF NULL ATTR. FIELD' SPECIFYES */
112 /* THE SIZE OF THE TUPLE HEADER FIELD 'NULL ATTR. FIELD'. */
113 /* THE TUPLE HEADER FIELD 'TYPE' SPECIFYES THE TYPE OF THE TUPLE */
114 /* HEADER. */
115 /* TUPLE ATTRIBUTE INDEX CLUSTERS, ATTRIBUTE */
116 /* CLUSTERS AND A DYNAMIC ATTRIBUTE HEADER. */
117 /* IT MAY ALSO CONTAIN SHORT ATTRIBUTES AND */
118 /* POINTERS TO LONG ATTRIBUTE HEADERS. */
119 /* TUPLE ATTRIBUTE INDEX CLUSTERS, ATTRIBUTE */
120 /* CLUSTERS AND A DYNAMIC ATTRIBUTE HEADER. */
121
122 /* DATA STRUCTURE TYPES */
123 /* WHEN ATTRIBUTE INFO IS SENT WITH A ATTRINFO-SIGNAL THE */
124 /* VARIABLE TYPE IS SPECIFYED. THIS MUST BE DONE TO BE ABLE TO */
125 /* NOW HOW MUCH DATA OF A ATTRIBUTE TO READ FROM ATTRINFO. */
126
127 /* WHEN A REQUEST CAN NOT BE EXECUTED BECAUSE OF A ERROR THE */
128 /* ERROR MUST BE IDENTIFYED BY MEANS OF A ERROR CODE AND SENT TO */
129 /* THE REQUESTER. */
130 #define ZGET_OPREC_ERROR 804 // TUP_SEIZEREF
131
132 #define ZEXIST_FRAG_ERROR 816 // Add fragment
133 #define ZFULL_FRAGRECORD_ERROR 817 // Add fragment
134 #define ZNO_FREE_PAGE_RANGE_ERROR 818 // Add fragment
135 #define ZNOFREE_FRAGOP_ERROR 830 // Add fragment
136 #define ZTOO_LARGE_TUPLE_ERROR 851 // Add fragment
137 #define ZNO_FREE_TAB_ENTRY_ERROR 852 // Add fragment
138 #define ZNO_PAGES_ALLOCATED_ERROR 881 // Add fragment
139
140 #define ZGET_REALPID_ERROR 809
141 #define ZNOT_IMPLEMENTED_ERROR 812
142 #define ZSEIZE_ATTRINBUFREC_ERROR 805
143 #define ZTOO_MUCH_ATTRINFO_ERROR 823
144 #define ZMEM_NOTABDESCR_ERROR 826
145 #define ZMEM_NOMEM_ERROR 827
146 #define ZAI_INCONSISTENCY_ERROR 829
147 #define ZNO_ILLEGAL_NULL_ATTR 839
148 #define ZNOT_NULL_ATTR 840
149 #define ZBAD_DEFAULT_VALUE_LEN 850
150 #define ZNO_INSTRUCTION_ERROR 871
151 #define ZOUTSIDE_OF_PROGRAM_ERROR 876
152 #define ZSTORED_PROC_ID_ERROR 877
153 #define ZREGISTER_INIT_ERROR 878
154 #define ZATTRIBUTE_ID_ERROR 879
155 #define ZTRY_TO_READ_TOO_MUCH_ERROR 880
156 #define ZTOTAL_LEN_ERROR 882
157 #define ZATTR_INTERPRETER_ERROR 883
158 #define ZSTACK_OVERFLOW_ERROR 884
159 #define ZSTACK_UNDERFLOW_ERROR 885
160 #define ZTOO_MANY_INSTRUCTIONS_ERROR 886
161 #define ZTRY_TO_UPDATE_ERROR 888
162 #define ZCALL_ERROR 890
163 #define ZTEMPORARY_RESOURCE_FAILURE 891
164 #define ZUNSUPPORTED_BRANCH 892
165
166 #define ZSTORED_SEIZE_ATTRINBUFREC_ERROR 873 // Part of Scan
167 #define ZSTORED_TOO_MUCH_ATTRINFO_ERROR 874
168
169 #define ZREAD_ONLY_CONSTRAINT_VIOLATION 893
170 #define ZVAR_SIZED_NOT_SUPPORTED 894
171 #define ZINCONSISTENT_NULL_ATTRIBUTE_COUNT 895
172 #define ZTUPLE_CORRUPTED_ERROR 896
173 #define ZTRY_UPDATE_PRIMARY_KEY 897
174 #define ZMUST_BE_ABORTED_ERROR 898
175 #define ZTUPLE_DELETED_ERROR 626
176 #define ZINSERT_ERROR 630
177 #define ZOP_AFTER_REFRESH_ERROR 920
178
179 #define ZINVALID_CHAR_FORMAT 744
180 #define ZROWID_ALLOCATED 899
181 #define ZINVALID_ALTER_TAB 741
182
183 #define ZTOO_MANY_BITS_ERROR 791
184
185 /* SOME WORD POSITIONS OF FIELDS IN SOME HEADERS */
186
187 #define ZTH_MM_FREE 3 /* PAGE STATE, TUPLE HEADER PAGE WITH FREE AREA */
188 #define ZTH_MM_FULL 4 /* PAGE STATE, TUPLE HEADER PAGE WHICH IS FULL */
189
190 #define ZTD_HEADER 0 /* HEADER POSITION */
191 #define ZTD_DATASIZE 1 /* SIZE OF THE DATA IN THIS CHUNK */
192 #define ZTD_SIZE 2 /* TOTAL SIZE OF TABLE DESCRIPTOR */
193
194 /* TRAILER POSITIONS FROM END OF TABLE DESCRIPTOR RECORD */
195 #define ZTD_TR_SIZE 1 /* SIZE DESCRIPTOR POS FROM END+1 */
196 #define ZTD_TR_TYPE 2
197 #define ZTD_TRAILER_SIZE 2 /* TOTAL SIZE OF TABLE TRAILER */
198 #define ZAD_SIZE 2 /* TOTAL SIZE OF ATTR DESCRIPTOR */
199 #define ZAD_LOG_SIZE 1 /* TWO LOG OF TOTAL SIZE OF ATTR DESCRIPTOR */
200
201 /* CONSTANTS USED TO HANDLE TABLE DESCRIPTOR AS A FREELIST */
202 #define ZTD_FL_HEADER 0 /* HEADER POSITION */
203 #define ZTD_FL_SIZE 1 /* TOTAL SIZE OF THIS FREELIST ENTRY */
204 #define ZTD_FL_PREV 2 /* PREVIOUS RECORD IN FREELIST */
205 #define ZTD_FL_NEXT 3 /* NEXT RECORD IN FREELIST */
206 #define ZTD_FREE_SIZE 16 /* SIZE NEEDED TO HOLD ONE FL ENTRY */
207
208 /* CONSTANTS USED IN LSB OF TABLE DESCRIPTOR HEADER DESCRIBING USAGE */
209 #define ZTD_TYPE_FREE 0 /* RECORD LINKED INTO FREELIST */
210 #define ZTD_TYPE_NORMAL 1 /* RECORD USED AS TABLE DESCRIPTOR */
211 /* ATTRIBUTE OPERATION CONSTANTS */
212 #define ZLEAF 1
213 #define ZNON_LEAF 2
214
215 /* RETURN POINTS. */
216 /* RESTART PHASES */
217 #define ZSTARTPHASE1 1
218 #define ZSTARTPHASE2 2
219 #define ZSTARTPHASE3 3
220 #define ZSTARTPHASE4 4
221 #define ZSTARTPHASE6 6
222
223 #define ZADDFRAG 0
224
225 //------------------------------------------------------------
226 // TUP_CONTINUEB codes
227 //------------------------------------------------------------
228 #define ZINITIALISE_RECORDS 6
229 #define ZREL_FRAG 7
230 #define ZREPORT_MEMORY_USAGE 8
231 #define ZBUILD_INDEX 9
232 #define ZTUP_SCAN 10
233 #define ZFREE_EXTENT 11
234 #define ZUNMAP_PAGES 12
235 #define ZFREE_VAR_PAGES 13
236 #define ZFREE_PAGES 14
237 #define ZREBUILD_FREE_PAGE_LIST 15
238 #define ZDISK_RESTART_UNDO 16
239
240 #define ZSCAN_PROCEDURE 0
241 #define ZCOPY_PROCEDURE 2
242 #define ZSTORED_PROCEDURE_DELETE 3
243 #define ZSTORED_PROCEDURE_FREE 0xffff
244 #define ZMIN_PAGE_LIMIT_TUP_COMMITREQ 2
245
246 #define ZSKIP_TUX_TRIGGERS 0x1 // flag for TUP_ABORTREQ
247 #define ZABORT_DEALLOC 0x2 // flag for TUP_ABORTREQ
248
249 #endif
250
251 class Dbtup: public SimulatedBlock {
252 friend class DbtupProxy;
253 friend class Suma;
254 public:
255 struct KeyReqStruct;
256 friend struct KeyReqStruct; // CC
257 typedef bool (Dbtup::* ReadFunction)(Uint8*,
258 KeyReqStruct*,
259 AttributeHeader*,
260 Uint32);
261 typedef bool (Dbtup::* UpdateFunction)(Uint32*,
262 KeyReqStruct*,
263 Uint32);
264 private:
265
266 typedef Tup_fixsize_page Fix_page;
267 typedef Tup_varsize_page Var_page;
268
269 public:
270 class Dblqh *c_lqh;
271 class Backup *c_backup;
272 Tsman* c_tsman;
273 Lgman* c_lgman;
274 Pgman* c_pgman;
275
276 enum CallbackIndex {
277 // lgman
278 UNDO_CREATETABLE_LOGSYNC_CALLBACK = 1,
279 DROP_TABLE_LOGSYNC_CALLBACK = 2,
280 UNDO_CREATETABLE_CALLBACK = 3,
281 DROP_TABLE_LOG_BUFFER_CALLBACK = 4,
282 DROP_FRAGMENT_FREE_EXTENT_LOG_BUFFER_CALLBACK = 5,
283 NR_DELETE_LOG_BUFFER_CALLBACK = 6,
284 DISK_PAGE_LOG_BUFFER_CALLBACK = 7,
285 COUNT_CALLBACKS = 8
286 };
287 CallbackEntry m_callbackEntry[COUNT_CALLBACKS];
288 CallbackTable m_callbackTable;
289
290 enum TransState {
291 TRANS_IDLE = 0,
292 TRANS_STARTED = 1,
293 TRANS_NOT_USED_STATE = 2, // No longer used.
294 TRANS_ERROR_WAIT_STORED_PROCREQ = 3,
295 TRANS_ERROR_WAIT_TUPKEYREQ = 4,
296 TRANS_TOO_MUCH_AI = 5,
297 TRANS_DISCONNECTED = 6
298 };
299
300 enum TupleState {
301 TUPLE_PREPARED = 1,
302 TUPLE_ALREADY_ABORTED = 2,
303 TUPLE_TO_BE_COMMITTED = 3
304 };
305
306 enum State {
307 NOT_INITIALIZED = 0,
308 IDLE = 17,
309 ACTIVE = 18,
310 SYSTEM_RESTART = 19,
311 DEFINED = 34,
312 NOT_DEFINED = 37,
313 NORMAL_PAGE = 40,
314 DEFINING = 65,
315 DROPPING = 68
316 };
317
318
319 struct Fragoperrec {
320 Uint64 minRows;
321 Uint64 maxRows;
322 Uint32 nextFragoprec;
323 Uint32 lqhPtrFrag;
324 Uint32 fragidFrag;
325 Uint32 tableidFrag;
326 Uint32 fragPointer;
327 Uint32 attributeCount;
328 Uint32 charsetIndex;
329 Uint32 m_null_bits[2];
330 Uint32 m_extra_row_gci_bits;
331 Uint32 m_extra_row_author_bits;
332 union {
333 BlockReference lqhBlockrefFrag;
334 Uint32 m_senderRef;
335 };
336 Uint32 m_senderData;
337 bool inUse;
338 bool definingFragment;
339 };
340 typedef Ptr<Fragoperrec> FragoperrecPtr;
341
342 /* Operation record used during alter table. */
343 struct AlterTabOperation {
AlterTabOperationDbtup::AlterTabOperation344 AlterTabOperation() { memset(this, 0, sizeof(AlterTabOperation)); };
345 Uint32 nextAlterTabOp;
346 Uint32 newNoOfAttrs;
347 Uint32 newNoOfCharsets;
348 Uint32 newNoOfKeyAttrs;
349 Uint32 noOfDynNullBits;
350 Uint32 noOfDynVar;
351 Uint32 noOfDynFix;
352 Uint32 noOfDynamic;
353 Uint32 tabDesOffset[7];
354 Uint32 tableDescriptor;
355 Uint32 dynTabDesOffset[3];
356 Uint32 dynTableDescriptor;
357 };
358 typedef Ptr<AlterTabOperation> AlterTabOperationPtr;
359
360 typedef Tup_page Page;
361 typedef Ptr<Page> PagePtr;
362
363 // Scan position
364 struct ScanPos {
365 enum Get {
366 Get_undef = 0,
367 Get_next_page,
368 Get_page,
369 Get_next_page_mm,
370 Get_page_mm,
371 Get_next_page_dd,
372 Get_page_dd,
373 Get_next_tuple,
374 Get_tuple
375 };
376 Get m_get; // entry point in scanNext
377 Local_key m_key; // scan position pointer MM or DD
378 Page* m_page; // scanned MM or DD (cache) page
379 Local_key m_key_mm; // MM local key returned
380 Uint32 m_realpid_mm; // MM real page id
381 Uint32 m_extent_info_ptr_i;
ScanPosDbtup::ScanPos382 ScanPos() {
383 /*
384 * Position is Null until scanFirst(). In particular in LCP scan
385 * it is Null between LCP_FRAG_ORD and ACC_SCANREQ.
386 */
387 m_key.setNull();
388 }
389 };
390
391 // Scan Lock
392 struct ScanLock {
ScanLockDbtup::ScanLock393 ScanLock() {}
394 Uint32 m_accLockOp;
395 union {
396 Uint32 nextPool;
397 Uint32 nextList;
398 };
399 Uint32 prevList;
400 };
401 typedef Ptr<ScanLock> ScanLockPtr;
402 ArrayPool<ScanLock> c_scanLockPool;
403
404 // Tup scan, similar to Tux scan. Later some of this could
405 // be moved to common superclass.
406 struct ScanOp {
ScanOpDbtup::ScanOp407 ScanOp() :
408 m_state(Undef),
409 m_bits(0),
410 m_userPtr(RNIL),
411 m_userRef(RNIL),
412 m_tableId(RNIL),
413 m_fragId(~(Uint32)0),
414 m_fragPtrI(RNIL),
415 m_transId1(0),
416 m_transId2(0),
417 m_savePointId(0),
418 m_accLockOp(RNIL)
419 {}
420
421 enum State {
422 Undef = 0,
423 First = 1, // before first entry
424 Current = 2, // at current before locking
425 Blocked = 3, // at current waiting for ACC lock
426 Locked = 4, // at current and locked or no lock needed
427 Next = 5, // looking for next extry
428 Last = 6, // after last entry
429 Aborting = 7, // lock wait at scan close
430 Invalid = 9 // cannot return REF to LQH currently
431 };
432 Uint16 m_state;
433
434 enum Bits {
435 SCAN_DD = 0x01, // scan disk pages
436 SCAN_VS = 0x02, // page format is var size
437 SCAN_LCP = 0x04, // LCP mem page scan
438 SCAN_LOCK_SH = 0x10, // lock mode shared
439 SCAN_LOCK_EX = 0x20, // lock mode exclusive
440 SCAN_LOCK_WAIT = 0x40, // lock wait
441 // any lock mode
442 SCAN_LOCK = SCAN_LOCK_SH | SCAN_LOCK_EX,
443 SCAN_NR = 0x80 // Node recovery scan
444 };
445 Uint16 m_bits;
446
447 Uint32 m_userPtr; // scanptr.i in LQH
448 Uint32 m_userRef;
449 Uint32 m_tableId;
450 Uint32 m_fragId;
451 Uint32 m_fragPtrI;
452 Uint32 m_transId1;
453 Uint32 m_transId2;
454 union {
455 Uint32 m_savePointId;
456 Uint32 m_scanGCI;
457 };
458 Uint32 m_endPage;
459 // lock waited for or obtained and not yet passed to LQH
460 Uint32 m_accLockOp;
461
462 ScanPos m_scanPos;
463
464 DLFifoList<ScanLock>::Head m_accLockOps;
465
466 union {
467 Uint32 nextPool;
468 Uint32 nextList;
469 };
470 Uint32 prevList;
471 };
472 typedef Ptr<ScanOp> ScanOpPtr;
473 ArrayPool<ScanOp> c_scanOpPool;
474
475 void scanReply(Signal*, ScanOpPtr scanPtr);
476 void scanFirst(Signal*, ScanOpPtr scanPtr);
477 bool scanNext(Signal*, ScanOpPtr scanPtr);
478 void scanCont(Signal*, ScanOpPtr scanPtr);
479 void disk_page_tup_scan_callback(Signal*, Uint32 scanPtrI, Uint32 page_i);
480 void scanClose(Signal*, ScanOpPtr scanPtr);
481 void addAccLockOp(ScanOp& scan, Uint32 accLockOp);
482 void removeAccLockOp(ScanOp& scan, Uint32 accLockOp);
483 void releaseScanOp(ScanOpPtr& scanPtr);
484
485 // for md5 of key (could maybe reuse existing temp buffer)
486 Uint64 c_dataBuffer[ZWORDS_ON_PAGE/2 + 1];
487
488 // Crash the node when a tuple got corrupted
489 bool c_crashOnCorruptedTuple;
490
491 struct Page_request
492 {
Page_requestDbtup::Page_request493 Page_request() {}
494 Local_key m_key;
495 Uint32 m_frag_ptr_i;
496 Uint32 m_extent_info_ptr;
497 Uint16 m_original_estimated_free_space; // in bytes/records
498 Uint16 m_list_index; // in Disk_alloc_info.m_page_requests
499 Uint16 m_ref_count; // Waiters for page
500 Uint16 m_uncommitted_used_space;
501 Uint32 nextList;
502 Uint32 prevList;
503 Uint32 m_magic;
504 }; // 32 bytes
505
506 typedef RecordPool<Page_request, WOPool> Page_request_pool;
507 typedef DLFifoListImpl<Page_request_pool, Page_request> Page_request_list;
508 typedef LocalDLFifoListImpl<Page_request_pool, Page_request> Local_page_request_list;
509
510 STATIC_CONST( EXTENT_SEARCH_MATRIX_COLS = 4 ); // Guarantee size
511 STATIC_CONST( EXTENT_SEARCH_MATRIX_ROWS = 5 ); // Total size
512 STATIC_CONST( EXTENT_SEARCH_MATRIX_SIZE = 20 );
513
514 struct Extent_list_t
515 {
516 Uint32 nextList;
517 };
518
519 struct Extent_info : public Extent_list_t
520 {
521 Uint32 m_magic;
522 Uint32 m_first_page_no;
523 Uint32 m_empty_page_no;
524 Local_key m_key;
525 Uint32 m_free_space;
526 Uint32 m_free_matrix_pos;
527 Uint16 m_free_page_count[EXTENT_SEARCH_MATRIX_COLS];
528 union {
529 Uint32 nextList;
530 Uint32 nextPool;
531 };
532 Uint32 prevList;
533 Uint32 nextHash, prevHash;
534
hashValueDbtup::Extent_info535 Uint32 hashValue() const {
536 return (m_key.m_file_no << 16) ^ m_key.m_page_idx;
537 }
538
Extent_infoDbtup::Extent_info539 Extent_info() {}
equalDbtup::Extent_info540 bool equal(const Extent_info & rec) const {
541 return m_key.m_file_no == rec.m_key.m_file_no &&
542 m_key.m_page_idx == rec.m_key.m_page_idx;
543 }
544 }; // 40 bytes
545
546 typedef RecordPool<Extent_info, RWPool> Extent_info_pool;
547 typedef DLListImpl<Extent_info_pool, Extent_info> Extent_info_list;
548 typedef LocalDLListImpl<Extent_info_pool, Extent_info> Local_extent_info_list;
549 typedef DLHashTableImpl<Extent_info_pool, Extent_info> Extent_info_hash;
550 typedef SLListImpl<Extent_info_pool, Extent_info, Extent_list_t> Fragment_extent_list;
551 typedef LocalSLListImpl<Extent_info_pool, Extent_info, Extent_list_t> Local_fragment_extent_list;
552 struct Tablerec;
553 struct Disk_alloc_info
554 {
Disk_alloc_infoDbtup::Disk_alloc_info555 Disk_alloc_info() {}
556 Disk_alloc_info(const Tablerec* tabPtrP,
557 Uint32 extent_size_in_pages);
558 Uint32 m_extent_size;
559
560 /**
561 * Disk allocation
562 *
563 * 1) Allocate space on pages that already are dirty
564 * (4 free lists for different requests)
565 * 2) Allocate space on pages waiting to maped that will be dirty
566 * (4 free lists for different requests)
567 * 3) Check if "current" extent can accommodate request
568 * If so, allocate page from there
569 * Else put "current" into free matrix
570 * 4) Search free matrix for extent with greatest amount of free space
571 * while still accommodating current request
572 * (20 free lists for different requests)
573 */
574
575 /**
576 * Free list of pages in different size
577 * that are dirty
578 */
579 DLList<Page>::Head m_dirty_pages[MAX_FREE_LIST]; // In real page id's
580
581 /**
582 * Requests (for update) that have sufficient space left after request
583 * these are currently being "mapped"
584 */
585 Page_request_list::Head m_page_requests[MAX_FREE_LIST];
586
587 DLList<Page>::Head m_unmap_pages;
588
589 /**
590 * Current extent
591 */
592 Uint32 m_curr_extent_info_ptr_i;
593
594 /**
595 *
596 */
597 STATIC_CONST( SZ = EXTENT_SEARCH_MATRIX_SIZE );
598 Extent_info_list::Head m_free_extents[SZ];
599 Uint32 m_total_extent_free_space_thresholds[EXTENT_SEARCH_MATRIX_ROWS];
600 Uint32 m_page_free_bits_map[EXTENT_SEARCH_MATRIX_COLS];
601
602 Uint32 find_extent(Uint32 sz) const;
603 Uint32 calc_extent_pos(const Extent_info*) const;
604
605 /**
606 * Compute minimum free space on page given bits
607 */
calc_page_free_spaceDbtup::Disk_alloc_info608 Uint32 calc_page_free_space(Uint32 bits) const {
609 return m_page_free_bits_map[bits];
610 }
611
612 /**
613 * Compute page free bits, given free space
614 */
calc_page_free_bitsDbtup::Disk_alloc_info615 Uint32 calc_page_free_bits(Uint32 free) const {
616 for(Uint32 i = 0; i<EXTENT_SEARCH_MATRIX_COLS-1; i++)
617 if(free >= m_page_free_bits_map[i])
618 return i;
619 return EXTENT_SEARCH_MATRIX_COLS - 1;
620 }
621
622 Fragment_extent_list::Head m_extent_list;
623 };
624
625 void dump_disk_alloc(Disk_alloc_info&);
626
627 STATIC_CONST( FREE_PAGE_BIT = 0x80000000 );
628 STATIC_CONST( FREE_PAGE_RNIL = RNIL + 1 );
629
630 struct Fragrecord {
631 // Number of allocated pages for fixed-sized data.
632 Uint32 noOfPages;
633 // Number of allocated pages for var-sized data.
634 Uint32 noOfVarPages;
635 // No of allocated but unused words for var-sized fields.
636 Uint64 m_varWordsFree;
637
638 /**
639 * m_max_page_cnt contains the next page number to use when allocating
640 * a new page and all pages with lower page numbers are filled with
641 * rows. At fragment creation it is 0 since no pages are yet allocated.
642 * With 1 page allocated it is set to 1. The actual max page number with
643 * 1 page is however 0 since we start with page numbers from 0.
644 */
645 Uint32 m_max_page_cnt;
646 Uint32 m_free_page_id_list;
647 DynArr256::Head m_page_map;
648 DLFifoList<Page>::Head thFreeFirst; // pages with atleast 1 free record
649
650 Uint32 m_lcp_scan_op;
651 Local_key m_lcp_keep_list_head;
652 Local_key m_lcp_keep_list_tail;
653
654 enum FragState
655 { FS_FREE
656 ,FS_ONLINE // Ordinary fragment
657 ,FS_REORG_NEW // A new (not yet "online" fragment)
658 ,FS_REORG_COMMIT // An ordinary fragment which has been split
659 ,FS_REORG_COMMIT_NEW // An new fragment which is online
660 ,FS_REORG_COMPLETE // An ordinary fragment which has been split
661 ,FS_REORG_COMPLETE_NEW // An new fragment which is online
662 } fragStatus;
663 Uint32 fragTableId;
664 Uint32 fragmentId;
665 Uint32 nextfreefrag;
666 // +1 is as "full" pages are stored last
667 DLList<Page>::Head free_var_page_array[MAX_FREE_LIST+1];
668
669 DLList<ScanOp>::Head m_scanList;
670
671 enum { UC_LCP = 1, UC_CREATE = 2, UC_SET_LCP = 3 };
672 Uint32 m_restore_lcp_id;
673 Uint32 m_undo_complete;
674 Uint32 m_tablespace_id;
675 Uint32 m_logfile_group_id;
676 Disk_alloc_info m_disk_alloc_info;
677 // Number of fixed-seize tuple parts (which equals the tuple count).
678 Uint64 m_fixedElemCount;
679 /**
680 Number of variable-size tuple parts, i.e. the number of tuples that has
681 one or more non-NULL varchar/varbinary or blob fields. (The first few bytes
682 of a blob is stored like that, the rest in a blob table.)
683 */
684 Uint64 m_varElemCount;
685
686 // Consistency check.
verifyVarSpaceDbtup::Fragrecord687 bool verifyVarSpace() const
688 {
689 return (m_varWordsFree < Uint64(1)<<60) && //Underflow.
690 m_varWordsFree * sizeof(Uint32) <=
691 noOfVarPages * File_formats::NDB_PAGE_SIZE;
692 }
693 };
694 typedef Ptr<Fragrecord> FragrecordPtr;
695
696 struct Operationrec {
697 /*
698 * Doubly linked list with anchor on tuple.
699 * This is to handle multiple updates on the same tuple
700 * by the same transaction.
701 */
702 Uint32 prevActiveOp;
703 Uint32 nextActiveOp;
704
OperationrecDbtup::Operationrec705 Operationrec() {}
is_first_operationDbtup::Operationrec706 bool is_first_operation() const { return prevActiveOp == RNIL;}
is_last_operationDbtup::Operationrec707 bool is_last_operation() const { return nextActiveOp == RNIL;}
708
709 Uint32 m_undo_buffer_space; // In words
710
711 Uint32 m_any_value;
712 Uint32 nextPool;
713
714 /*
715 * From fragment i-value we can find fragment and table record
716 */
717 Uint32 fragmentPtr;
718
719 /*
720 * We need references to both the original tuple and the copy tuple.
721 * We keep the page's real i-value and its index and from there we
722 * can find out about the fragment page id and the page offset.
723 */
724 Local_key m_tuple_location;
725 Local_key m_copy_tuple_location;
726
727 /*
728 * We keep the record linked to the operation record in LQH.
729 * This is needed due to writing of REDO log must be performed
730 * in correct order, which is the same order as the writes
731 * occurred. LQH can receive the records in different order.
732 */
733 Uint32 userpointer;
734
735 /*
736 * When responding to queries in the same transaction they will see
737 * a result from the save point id the query was started. Again
738 * functionality for multi-updates of the same record in one
739 * transaction.
740 */
741 union {
742 Uint32 savepointId;
743 Uint32 m_commit_disk_callback_page;
744 };
745
746 Uint32 op_type;
747 Uint32 trans_state;
748 Uint32 tuple_state;
749
750 /*
751 * State variables on connection.
752 * State variable on tuple after multi-updates
753 * Is operation undo logged or not
754 * Is operation in fragment list
755 * Is operation in multi-update list
756 * Operation type (READ, UPDATE, etc)
757 * Is record primary replica
758 * Is delete or insert performed
759 */
760 struct OpBitFields {
761 /*
762 * TUX needs to know the tuple version of the tuple since it
763 * keeps an entry for both the committed and all versions in
764 * a transaction currently. So each update will create a new
765 * version even if in the same transaction.
766 */
767 unsigned int tupVersion : 16;
768
769 unsigned int m_reorg : 2;
770 unsigned int in_active_list : 1;
771 unsigned int delete_insert_flag : 1;
772 unsigned int primary_replica : 1;
773 unsigned int m_disk_preallocated : 1;
774 unsigned int m_load_diskpage_on_commit : 1;
775 unsigned int m_wait_log_buffer : 1;
776 unsigned int m_gci_written : 1;
777 /* If the op has no logical effect, it should not be logged
778 * or sent as an event. Example op is OPTIMIZE table,
779 * which uses ZUPDATE to move varpart values physically.
780 */
781 unsigned int m_physical_only_op : 1;
782 /* No foreign keys should be checked for this operation.
783 * No fk triggers will be fired.
784 */
785 unsigned int m_disable_fk_checks : 1;
786 };
787 union OpStruct {
788 OpBitFields bit_field;
789 Uint32 op_bit_fields;
790 };
791 OpStruct op_struct;
792
793 /*
794 * When refreshing a row, there are four scenarios
795 * The actual scenario is encoded in the 'copy tuple location'
796 * to enable special handling at commit time
797 */
798 enum RefreshScenario
799 {
800 RF_SINGLE_NOT_EXIST = 1, /* Refresh op first in trans, no row */
801 RF_SINGLE_EXIST = 2, /* Refresh op first in trans, row exists */
802 RF_MULTI_NOT_EXIST = 3, /* Refresh op !first in trans, row deleted */
803 RF_MULTI_EXIST = 4 /* Refresh op !first in trans, row exists */
804 };
805 };
806 typedef Ptr<Operationrec> OperationrecPtr;
807
808 /* ************* TRIGGER DATA ************* */
809 /* THIS RECORD FORMS LISTS OF ACTIVE */
810 /* TRIGGERS FOR EACH TABLE. */
811 /* THE RECORDS ARE MANAGED BY A TRIGGER */
812 /* POOL wHERE A TRIGGER RECORD IS SEIZED */
813 /* WHEN A TRIGGER IS ACTIVATED AND RELEASED */
814 /* WHEN THE TRIGGER IS DEACTIVATED. */
815 /* **************************************** */
816 struct TupTriggerData {
TupTriggerDataDbtup::TupTriggerData817 TupTriggerData() {}
818
819 /**
820 * Trigger id, used by DICT/TRIX to identify the trigger
821 *
822 * trigger Ids are unique per block for SUBSCRIPTION triggers.
823 * This is so that BACKUP can use TUP triggers directly and delete them
824 * properly.
825 */
826 Uint32 triggerId;
827
828 /**
829 * In 6.3 there is one trigger per operation
830 */
831 Uint32 oldTriggerIds[3]; // INS/UPD/DEL
832
833 /**
834 * Index id is needed for ordered index.
835 */
836 Uint32 indexId;
837
838 /**
839 * Trigger type etc, defines what the trigger is used for
840 */
841 TriggerType::Value triggerType;
842 TriggerActionTime::Value triggerActionTime;
843 TriggerEvent::Value triggerEvent;
844 /**
845 * Receiver block reference
846 */
847 Uint32 m_receiverRef;
848
849 /**
850 * Monitor all replicas, i.e. trigger will fire on all nodes where tuples
851 * are stored
852 */
853 bool monitorReplicas;
854
855 /**
856 * Monitor all attributes, the trigger monitors all changes to attributes
857 * in the table
858 */
859 bool monitorAllAttributes;
860
861 /**
862 * Send only changed attributes at trigger firing time.
863 */
864 bool sendOnlyChangedAttributes;
865
866 /**
867 * Send also before values at trigger firing time.
868 */
869 bool sendBeforeValues;
870
871 /**
872 * Attribute mask, defines what attributes are to be monitored
873 * Can be seen as a compact representation of SQL column name list
874 */
875 Bitmask<MAXNROFATTRIBUTESINWORDS> attributeMask;
876
877 /**
878 * Next ptr (used in pool/list)
879 */
880 union {
881 Uint32 nextPool;
882 Uint32 nextList;
883 };
884
885 /**
886 * Prev pointer (used in list)
887 */
888 Uint32 prevList;
889
printDbtup::TupTriggerData890 inline void print(NdbOut & s) const { s << "[TriggerData = " << triggerId << "]"; };
891 };
892
893 typedef Ptr<TupTriggerData> TriggerPtr;
894
895 /**
896 * Pool of trigger data record
897 */
898 ArrayPool<TupTriggerData> c_triggerPool;
899
900 /* ************ TABLE RECORD ************ */
901 /* THIS RECORD FORMS A LIST OF TABLE */
902 /* REFERENCE INFORMATION. ONE RECORD */
903 /* PER TABLE REFERENCE. */
904 /* ************************************** */
905 STATIC_CONST( MM = 0 );
906 STATIC_CONST( DD = 1 );
907 STATIC_CONST( DYN_BM_LEN_BITS = 8 );
908 STATIC_CONST( DYN_BM_LEN_MASK = ((1 << DYN_BM_LEN_BITS) - 1));
909
910 /* Array length in the data structures like
911 dynTabDescriptor, dynVarSizeMask, dynFixSizeMask, etc.
912 1 for dynamic main memory data,
913 2 for dynamic main memory and dynamic disk data.
914 */
915 STATIC_CONST( NO_DYNAMICS = 2 );
916
917 struct Tablerec {
TablerecDbtup::Tablerec918 Tablerec(ArrayPool<TupTriggerData> & triggerPool) :
919 afterInsertTriggers(triggerPool),
920 afterDeleteTriggers(triggerPool),
921 afterUpdateTriggers(triggerPool),
922 subscriptionInsertTriggers(triggerPool),
923 subscriptionDeleteTriggers(triggerPool),
924 subscriptionUpdateTriggers(triggerPool),
925 constraintUpdateTriggers(triggerPool),
926 deferredInsertTriggers(triggerPool),
927 deferredUpdateTriggers(triggerPool),
928 deferredDeleteTriggers(triggerPool),
929 tuxCustomTriggers(triggerPool)
930 {}
931
932 Bitmask<MAXNROFATTRIBUTESINWORDS> notNullAttributeMask;
933 Bitmask<MAXNROFATTRIBUTESINWORDS> blobAttributeMask;
934
935 /*
936 Extra table descriptor for dynamic attributes, or RNIL if none.
937 The size of this depends on actual column definitions, so it is allocated
938 _after_ seeing all columns, hence must be separate from the readKeyArray
939 et al descriptor, which is allocated before seeing columns.
940 */
941 Uint32 dynTabDescriptor[2];
942
943 /* Mask of variable-sized dynamic attributes. */
944 Uint32* dynVarSizeMask[2];
945 /*
946 Mask of fixed-sized dynamic attributes. There is one bit set for each
947 32-bit word occupied by fixed-size attributes, so fixed-size dynamic
948 attributes >32bit have multiple bits here.
949 */
950 Uint32* dynFixSizeMask[2];
951
952 ReadFunction* readFunctionArray;
953 UpdateFunction* updateFunctionArray;
954 CHARSET_INFO** charsetArray;
955
956 Uint32 readKeyArray;
957 /*
958 Offset into Dbtup::tableDescriptor of the start of the descriptor
959 words for each attribute.
960 For attribute i, the AttributeDescriptor word is stored at index
961 Tablerec::tabDescriptor+i*ZAD_SIZE, and the AttributeOffset word at
962 index Tablerec::tabDescriptor+i*ZAD_SIZE+1.
963 */
964 Uint32 tabDescriptor;
965 /*
966 Offset into Dbtup::tableDescriptor of memory used as an array of Uint16.
967
968 The values stored are offsets from Tablerec::tabDescriptor first for all
969 fixed-sized static attributes, then static varsized attributes, then
970 dynamic fixed-size, then dynamic varsized, and finally disk-stored fixed
971 size:
972 [mm_fix mm_var mm_dynfix mm_dynvar dd_fix]
973 This is used to find the AttributeDescriptor and AttributeOffset words
974 for an attribute. For example, the offset for the second dynamic
975 fixed-size attribute is at index <num fixed> + <num varsize> + 1.
976 */
977 Uint32 m_real_order_descriptor;
978
979 enum Bits
980 {
981 TR_Checksum = 0x1, // Need to be 1
982 TR_RowGCI = 0x2,
983 TR_ForceVarPart = 0x4,
984 TR_DiskPart = 0x8,
985 TR_ExtraRowGCIBits = 0x10,
986 TR_ExtraRowAuthorBits = 0x20
987 };
988 Uint16 m_bits;
989 Uint16 total_rec_size; // Max total size for entire tuple in words
990
991 /**
992 * Aggregates
993 */
994 Uint16 m_no_of_attributes;
995 Uint16 m_no_of_disk_attributes;
996 Uint16 noOfKeyAttr;
997 Uint16 noOfCharsets;
998 Uint16 m_dyn_null_bits[2];
999 Uint16 m_no_of_extra_columns; // "Hidden" columns
1000
need_expandDbtup::Tablerec1001 bool need_expand() const {
1002 return m_no_of_attributes > m_attributes[MM].m_no_of_fixsize;
1003 }
1004
need_expandDbtup::Tablerec1005 bool need_expand(bool disk) const {
1006 return m_attributes[MM].m_no_of_varsize > 0 ||
1007 m_attributes[MM].m_no_of_dynamic > 0 ||
1008 (disk && m_no_of_disk_attributes > 0);
1009 }
1010
need_shrinkDbtup::Tablerec1011 bool need_shrink() const {
1012 return
1013 m_attributes[MM].m_no_of_varsize > 0 ||
1014 m_attributes[MM].m_no_of_dynamic > 0 ||
1015 m_attributes[DD].m_no_of_varsize > 0;
1016 }
1017
need_shrinkDbtup::Tablerec1018 bool need_shrink(bool disk) const {
1019 return
1020 m_attributes[MM].m_no_of_varsize > 0 ||
1021 m_attributes[MM].m_no_of_dynamic > 0 ||
1022 (disk && m_attributes[DD].m_no_of_varsize > 0);
1023 }
1024
getExtraAttrIdDbtup::Tablerec1025 template <Uint32 bit> Uint32 getExtraAttrId() const {
1026 if (bit == TR_ExtraRowGCIBits)
1027 return 0;
1028 Uint32 no = 0;
1029 if (m_bits & TR_ExtraRowGCIBits)
1030 no++;
1031 assert(bit == TR_ExtraRowAuthorBits);
1032 //if (bit == TR_ExtraRowAuthorBits)
1033 return no;
1034 }
1035
1036 /**
1037 * Descriptors for MM and DD part
1038 */
1039 struct Tuple_offsets {
1040 Uint8 m_null_words;
1041 Uint8 m_null_offset;
1042 Uint16 m_disk_ref_offset; // In words relative m_data
1043 Uint16 m_fix_header_size; // For fix size tuples= total rec size(part)
1044 Uint16 m_max_var_offset; // In bytes relative m_var_data.m_data_ptr
1045 Uint16 m_max_dyn_offset; // In bytes relative m_var_data.m_dyn_data_ptr
1046 Uint16 m_dyn_null_words; // 32-bit words in dynattr bitmap
1047 } m_offsets[2];
1048
get_check_offsetDbtup::Tablerec1049 Uint32 get_check_offset(Uint32 mm) const {
1050 return m_offsets[mm].m_fix_header_size;
1051 }
1052
1053 struct {
1054 Uint16 m_no_of_fixsize;
1055 Uint16 m_no_of_varsize;
1056 Uint16 m_no_of_dynamic; // Total no. of dynamic attrs
1057 Uint16 m_no_of_dyn_fix; // No. of fixsize dynamic
1058 Uint16 m_no_of_dyn_var; // No. of varsize dynamic
1059 /*
1060 Note that due to bit types, we may have
1061 m_no_of_dynamic > m_no_of_dyn_fix + m_no_of_dyn_var
1062 */
1063 } m_attributes[2];
1064
1065 // Lists of trigger data for active triggers
1066 DLList<TupTriggerData> afterInsertTriggers;
1067 DLList<TupTriggerData> afterDeleteTriggers;
1068 DLList<TupTriggerData> afterUpdateTriggers;
1069 DLList<TupTriggerData> subscriptionInsertTriggers;
1070 DLList<TupTriggerData> subscriptionDeleteTriggers;
1071 DLList<TupTriggerData> subscriptionUpdateTriggers;
1072 DLList<TupTriggerData> constraintUpdateTriggers;
1073 DLList<TupTriggerData> deferredInsertTriggers;
1074 DLList<TupTriggerData> deferredUpdateTriggers;
1075 DLList<TupTriggerData> deferredDeleteTriggers;
1076
1077 // List of ordered indexes
1078 DLList<TupTriggerData> tuxCustomTriggers;
1079
1080 Uint32 fragid[MAX_FRAG_PER_LQH];
1081 Uint32 fragrec[MAX_FRAG_PER_LQH];
1082
1083 union {
1084 struct {
1085 Uint32 tabUserPtr;
1086 Uint32 tabUserRef;
1087 Uint32 m_lcpno;
1088 Uint32 m_fragPtrI;
1089 } m_dropTable;
1090 struct {
1091 Uint32 m_fragOpPtrI;
1092 Uint32 defValSectionI;
1093 Local_key defValLocation;
1094 } m_createTable;
1095 struct {
1096 Uint32 m_gci_hi;
1097 } m_reorg_suma_filter;
1098 };
1099
1100 State tableStatus;
1101 Local_key m_default_value_location;
1102 };
1103
1104 /*
1105 It is more space efficient to store dynamic fixed-size attributes
1106 of more than about 16 words as variable-sized internally.
1107 */
1108 STATIC_CONST(InternalMaxDynFix= 16);
1109
1110 struct Disk_undo
1111 {
1112 enum
1113 {
1114 UNDO_ALLOC = File_formats::Undofile::UNDO_TUP_ALLOC
1115 ,UNDO_UPDATE = File_formats::Undofile::UNDO_TUP_UPDATE
1116 ,UNDO_FREE = File_formats::Undofile::UNDO_TUP_FREE
1117 ,UNDO_CREATE = File_formats::Undofile::UNDO_TUP_CREATE
1118 ,UNDO_DROP = File_formats::Undofile::UNDO_TUP_DROP
1119 ,UNDO_ALLOC_EXTENT = File_formats::Undofile::UNDO_TUP_ALLOC_EXTENT
1120 ,UNDO_FREE_EXTENT = File_formats::Undofile::UNDO_TUP_FREE_EXTENT
1121 };
1122
1123 struct Alloc
1124 {
1125 Uint32 m_file_no_page_idx; // 16 bit file_no, 16 bit page_idx
1126 Uint32 m_page_no;
1127 Uint32 m_type_length; // 16 bit type, 16 bit length
1128 };
1129
1130 struct Update
1131 {
1132 Uint32 m_file_no_page_idx; // 16 bit file_no, 16 bit page_idx
1133 Uint32 m_page_no;
1134 Uint32 m_gci;
1135 Uint32 m_data[1];
1136 Uint32 m_type_length; // 16 bit type, 16 bit length
1137 };
1138
1139 struct Free
1140 {
1141 Uint32 m_file_no_page_idx; // 16 bit file_no, 16 bit page_idx
1142 Uint32 m_page_no;
1143 Uint32 m_gci;
1144 Uint32 m_data[1];
1145 Uint32 m_type_length; // 16 bit type, 16 bit length
1146 };
1147
1148 struct Create
1149 {
1150 Uint32 m_table;
1151 Uint32 m_type_length; // 16 bit type, 16 bit length
1152 };
1153
1154 struct Drop
1155 {
1156 Uint32 m_table;
1157 Uint32 m_type_length; // 16 bit type, 16 bit length
1158 };
1159
1160 struct AllocExtent
1161 {
1162 Uint32 m_table;
1163 Uint32 m_fragment;
1164 Uint32 m_page_no;
1165 Uint32 m_file_no;
1166 Uint32 m_type_length;
1167 };
1168
1169 struct FreeExtent
1170 {
1171 Uint32 m_table;
1172 Uint32 m_fragment;
1173 Uint32 m_page_no;
1174 Uint32 m_file_no;
1175 Uint32 m_type_length;
1176 };
1177 };
1178
1179 Extent_info_pool c_extent_pool;
1180 Extent_info_hash c_extent_hash;
1181 Page_request_pool c_page_request_pool;
1182
1183 typedef Ptr<Tablerec> TablerecPtr;
1184
1185 struct storedProc {
1186 Uint32 storedProcIVal;
1187 Uint32 nextPool;
1188 Uint16 storedCode;
1189 };
1190
1191 typedef Ptr<storedProc> StoredProcPtr;
1192
1193 ArrayPool<storedProc> c_storedProcPool;
1194 RSS_AP_SNAPSHOT(c_storedProcPool);
1195 Uint32 c_storedProcCountNonAPI;
1196 void storedProcCountNonAPI(BlockReference apiBlockref, int add_del);
1197
1198 /* **************************** TABLE_DESCRIPTOR RECORD ******************************** */
1199 /* THIS VARIABLE IS USED TO STORE TABLE DESCRIPTIONS. A TABLE DESCRIPTION IS STORED AS A */
1200 /* CONTIGUOS ARRAY IN THIS VARIABLE. WHEN A NEW TABLE IS ADDED A CHUNK IS ALLOCATED IN */
1201 /* THIS RECORD. WHEN ATTRIBUTES ARE ADDED TO THE TABLE, A NEW CHUNK OF PROPER SIZE IS */
1202 /* ALLOCATED AND ALL DATA IS COPIED TO THIS NEW CHUNK AND THEN THE OLD CHUNK IS PUT IN */
1203 /* THE FREE LIST. EACH TABLE IS DESCRIBED BY A NUMBER OF TABLE DESCRIPTIVE ATTRIBUTES */
1204 /* AND A NUMBER OF ATTRIBUTE DESCRIPTORS AS SHOWN IN FIGURE BELOW */
1205 /* */
1206 /* WHEN ALLOCATING A TABLE DESCRIPTOR THE SIZE IS ALWAYS A MULTIPLE OF 16 WORDS. */
1207 /* */
1208 /* ---------------------------------------------- */
1209 /* | TRAILER USED FOR ALLOC/DEALLOC | */
1210 /* ---------------------------------------------- */
1211 /* | TABLE DESCRIPTIVE ATTRIBUTES | */
1212 /* ---------------------------------------------- */
1213 /* | ATTRIBUTE DESCRIPTION 1 | */
1214 /* ---------------------------------------------- */
1215 /* | ATTRIBUTE DESCRIPTION 2 | */
1216 /* ---------------------------------------------- */
1217 /* | | */
1218 /* | | */
1219 /* | | */
1220 /* ---------------------------------------------- */
1221 /* | ATTRIBUTE DESCRIPTION N | */
1222 /* ---------------------------------------------- */
1223 /* */
1224 /* THE TABLE DESCRIPTIVE ATTRIBUTES CONTAINS THE FOLLOWING ATTRIBUTES: */
1225 /* */
1226 /* ---------------------------------------------- */
1227 /* | HEADER (TYPE OF INFO) | */
1228 /* ---------------------------------------------- */
1229 /* | SIZE OF WHOLE CHUNK (INCL. TRAILER) | */
1230 /* ---------------------------------------------- */
1231 /* | TABLE IDENTITY | */
1232 /* ---------------------------------------------- */
1233 /* | FRAGMENT IDENTITY | */
1234 /* ---------------------------------------------- */
1235 /* | NUMBER OF ATTRIBUTES | */
1236 /* ---------------------------------------------- */
1237 /* | SIZE OF FIXED ATTRIBUTES | */
1238 /* ---------------------------------------------- */
1239 /* | NUMBER OF NULL FIELDS | */
1240 /* ---------------------------------------------- */
1241 /* | NOT USED | */
1242 /* ---------------------------------------------- */
1243 /* */
1244 /* THESE ATTRIBUTES ARE ALL ONE R-VARIABLE IN THE RECORD. */
1245 /* NORMALLY ONLY ONE TABLE DESCRIPTOR IS USED. DURING SCHEMA CHANGES THERE COULD */
1246 /* HOWEVER EXIST MORE THAN ONE TABLE DESCRIPTION SINCE THE SCHEMA CHANGE OF VARIOUS */
1247 /* FRAGMENTS ARE NOT SYNCHRONISED. THIS MEANS THAT ALTHOUGH THE SCHEMA HAS CHANGED */
1248 /* IN ALL FRAGMENTS, BUT THE FRAGMENTS HAVE NOT REMOVED THE ATTRIBUTES IN THE SAME */
1249 /* TIME-FRAME. THEREBY SOME ATTRIBUTE INFORMATION MIGHT DIFFER BETWEEN FRAGMENTS. */
1250 /* EXAMPLES OF ATTRIBUTES THAT MIGHT DIFFER ARE SIZE OF FIXED ATTRIBUTES, NUMBER OF */
1251 /* ATTRIBUTES, FIELD START WORD, START BIT. */
1252 /* */
1253 /* AN ATTRIBUTE DESCRIPTION CONTAINS THE FOLLOWING ATTRIBUTES: */
1254 /* */
1255 /* ---------------------------------------------- */
1256 /* | Field Type, 4 bits (LSB Bits) | */
1257 /* ---------------------------------------------- */
1258 /* | Attribute Size, 4 bits | */
1259 /* ---------------------------------------------- */
1260 /* | NULL indicator 1 bit | */
1261 /* ---------------------------------------------- */
1262 /* | Indicator if TUP stores attr. 1 bit | */
1263 /* ---------------------------------------------- */
1264 /* | Not used 6 bits | */
1265 /* ---------------------------------------------- */
1266 /* | No. of elements in fixed array 16 bits | */
1267 /* ---------------------------------------------- */
1268 /* ---------------------------------------------- */
1269 /* | Field Start Word, 21 bits (LSB Bits) | */
1270 /* ---------------------------------------------- */
1271 /* | NULL Bit, 11 bits | */
1272 /* ---------------------------------------------- */
1273 /* */
1274 /* THE ATTRIBUTE SIZE CAN BE 1,2,4,8,16,32,64 AND 128 BITS. */
1275 /* */
1276 /* THE UNUSED PARTS OF THE RECORDS ARE PUT IN A LINKED LIST OF FREE PARTS. EACH OF */
1277 /* THOSE FREE PARTS HAVE THREE RECORDS ASSIGNED AS SHOWN IN THIS STRUCTURE */
1278 /* ALL FREE PARTS ARE SET INTO A CHUNK LIST WHERE EACH CHUNK IS AT LEAST 16 WORDS */
1279 /* */
1280 /* ---------------------------------------------- */
1281 /* | HEADER = RNIL | */
1282 /* ---------------------------------------------- */
1283 /* | SIZE OF FREE AREA | */
1284 /* ---------------------------------------------- */
1285 /* | POINTER TO PREVIOUS FREE AREA | */
1286 /* ---------------------------------------------- */
1287 /* | POINTER TO NEXT FREE AREA | */
1288 /* ---------------------------------------------- */
1289 /* */
1290 /* IF THE POINTER TO THE NEXT AREA IS RNIL THEN THIS IS THE LAST FREE AREA. */
1291 /* */
1292 /*****************************************************************************************/
1293 struct TableDescriptor {
1294 Uint32 tabDescr;
1295 };
1296 typedef Ptr<TableDescriptor> TableDescriptorPtr;
1297
1298 struct HostBuffer {
1299 bool inPackedList;
1300 Uint32 packetLenTA;
1301 Uint32 noOfPacketsTA;
1302 Uint32 packetBufferTA[30];
1303 };
1304 typedef Ptr<HostBuffer> HostBufferPtr;
1305
1306 /*
1307 * Build index operation record.
1308 */
1309 struct BuildIndexRec {
BuildIndexRecDbtup::BuildIndexRec1310 BuildIndexRec() {}
1311
1312 BuildIndxImplReq m_request;
1313 Uint8 m_build_vs; // varsize pages
1314 Uint32 m_indexId; // the index
1315 Uint32 m_fragNo; // fragment number under Tablerec
1316 Uint32 m_pageId; // logical fragment page id
1317 Uint32 m_tupleNo; // tuple number on page
1318 Uint32 m_buildRef; // Where to send tuples
1319 Uint32 m_outstanding; // If mt-build...
1320 BuildIndxImplRef::ErrorCode m_errorCode;
1321 union {
1322 Uint32 nextPool;
1323 Uint32 nextList;
1324 };
1325 Uint32 prevList;
1326 };
1327 typedef Ptr<BuildIndexRec> BuildIndexPtr;
1328 ArrayPool<BuildIndexRec> c_buildIndexPool;
1329 DLList<BuildIndexRec> c_buildIndexList;
1330 Uint32 c_noOfBuildIndexRec;
1331
1332 int mt_scan_init(Uint32 tableId, Uint32 fragId, Local_key * pos, Uint32 * fragPtrI);
1333 int mt_scan_next(Uint32 tableId, Uint32 fragPtrI, Local_key* pos, bool moveNext);
1334
1335 /**
1336 * Reference to variable part when a tuple is chained
1337 */
1338 struct Var_part_ref
1339 {
1340 #ifdef NDB_32BIT_VAR_REF
1341 /*
1342 In versions prior to ndb 6.1.6, 6.2.1 and mysql 5.1.17
1343 Running this code limits DataMemory to 16G, also online
1344 upgrade not possible between versions
1345 */
1346 Uint32 m_ref;
1347 STATIC_CONST( SZ32 = 1 );
1348
copyoutDbtup::Var_part_ref1349 void copyout(Local_key* dst) const {
1350 dst->m_page_no = Local_key::ref2page_id(m_ref);
1351 dst->m_page_idx = Local_key::ref2page_idx(m_ref);
1352 }
1353
assignDbtup::Var_part_ref1354 void assign(const Local_key* src) {
1355 m_ref = Local_key::ref(src->m_page_no, src->m_page_idx);
1356 }
1357 #else
1358 Uint32 m_page_no;
1359 Uint32 m_page_idx;
1360 STATIC_CONST( SZ32 = 2 );
1361
1362 void copyout(Local_key* dst) const {
1363 dst->m_page_no = m_page_no;
1364 dst->m_page_idx = m_page_idx;
1365 }
1366
1367 void assign(const Local_key* src) {
1368 m_page_no = src->m_page_no;
1369 m_page_idx = src->m_page_idx;
1370 }
1371 #endif
1372 };
1373
1374 struct Disk_part_ref
1375 {
1376 STATIC_CONST( SZ32 = 2 );
1377 };
1378
1379 struct Tuple_header
1380 {
1381 union {
1382 /**
1383 * List of prepared operations for this tuple.
1384 * Points to most recent/last operation, ie. to walk the list must follow
1385 * regOperPtr->prevActiveOp links.
1386 */
1387 Uint32 m_operation_ptr_i; // OperationPtrI
1388 Uint32 m_base_record_ref; // For disk tuple, ref to MM tuple
1389 };
1390 Uint32 m_header_bits; // Header word
1391 union {
1392 Uint32 m_checksum;
1393 Uint32 m_data[1];
1394 Uint32 m_null_bits[1];
1395 };
1396
1397 STATIC_CONST( HeaderSize = 2 );
1398
1399 /*
1400 Header bits.
1401
1402 MM_GROWN: When a tuple is updated to a bigger size, the original varpart
1403 of the tuple is immediately re-allocated to a location with sufficient
1404 size for the new data (but containing only the original smaller-sized
1405 data). This is so that commit can be sure to find room for the extra
1406 data. In the case of abort, the varpart must then be shrunk. For a
1407 MM_GROWN tuple, the original size is stored in the last word of the
1408 varpart until commit.
1409 */
1410 STATIC_CONST( TUP_VERSION_MASK = 0xFFFF );
1411 STATIC_CONST( COPY_TUPLE = 0x00010000 ); // Is this a copy tuple
1412 STATIC_CONST( DISK_PART = 0x00020000 ); // Is there a disk part
1413 STATIC_CONST( DISK_ALLOC = 0x00040000 ); // Is disk part allocated
1414 STATIC_CONST( DISK_INLINE = 0x00080000 ); // Is disk inline
1415 STATIC_CONST( ALLOC = 0x00100000 ); // Is record allocated now
1416 STATIC_CONST( MM_SHRINK = 0x00200000 ); // Has MM part shrunk
1417 STATIC_CONST( MM_GROWN = 0x00400000 ); // Has MM part grown
1418 STATIC_CONST( FREED = 0x00800000 ); // Is freed
1419 STATIC_CONST( FREE = 0x00800000 ); // alias
1420 STATIC_CONST( LCP_SKIP = 0x01000000 ); // Should not be returned in LCP
1421 STATIC_CONST( VAR_PART = 0x04000000 ); // Is there a varpart
1422 STATIC_CONST( REORG_MOVE = 0x08000000 );
1423
Tuple_headerDbtup::Tuple_header1424 Tuple_header() {}
get_tuple_versionDbtup::Tuple_header1425 Uint32 get_tuple_version() const {
1426 return m_header_bits & TUP_VERSION_MASK;
1427 }
set_tuple_versionDbtup::Tuple_header1428 void set_tuple_version(Uint32 version) {
1429 m_header_bits=
1430 (m_header_bits & ~(Uint32)TUP_VERSION_MASK) |
1431 (version & TUP_VERSION_MASK);
1432 }
1433
get_null_bitsDbtup::Tuple_header1434 Uint32* get_null_bits(const Tablerec* tabPtrP) {
1435 return m_null_bits+tabPtrP->m_offsets[MM].m_null_offset;
1436 }
1437
get_null_bitsDbtup::Tuple_header1438 Uint32* get_null_bits(const Tablerec* tabPtrP, Uint32 mm) {
1439 return m_null_bits+tabPtrP->m_offsets[mm].m_null_offset;
1440 }
1441
get_var_part_ref_ptrDbtup::Tuple_header1442 Var_part_ref* get_var_part_ref_ptr(const Tablerec* tabPtrP) {
1443 return (Var_part_ref*)(get_disk_ref_ptr(tabPtrP) + Disk_part_ref::SZ32);
1444 }
1445
get_var_part_ref_ptrDbtup::Tuple_header1446 const Var_part_ref* get_var_part_ref_ptr(const Tablerec* tabPtrP) const {
1447 return (Var_part_ref*)(get_disk_ref_ptr(tabPtrP) + Disk_part_ref::SZ32);
1448 }
1449
get_end_of_fix_part_ptrDbtup::Tuple_header1450 Uint32* get_end_of_fix_part_ptr(const Tablerec* tabPtrP) {
1451 return m_data + tabPtrP->m_offsets[MM].m_fix_header_size -
1452 Tuple_header::HeaderSize;
1453 }
1454
get_end_of_fix_part_ptrDbtup::Tuple_header1455 const Uint32* get_end_of_fix_part_ptr(const Tablerec* tabPtrP) const {
1456 return m_data + tabPtrP->m_offsets[MM].m_fix_header_size -
1457 Tuple_header::HeaderSize;
1458 }
1459
get_disk_ref_ptrDbtup::Tuple_header1460 Uint32* get_disk_ref_ptr(const Tablerec* tabPtrP) {
1461 return m_data + tabPtrP->m_offsets[MM].m_disk_ref_offset;
1462 }
1463
get_disk_ref_ptrDbtup::Tuple_header1464 const Uint32* get_disk_ref_ptr(const Tablerec* tabPtrP) const {
1465 return m_data + tabPtrP->m_offsets[MM].m_disk_ref_offset;
1466 }
1467
get_mm_gciDbtup::Tuple_header1468 Uint32 *get_mm_gci(const Tablerec* tabPtrP){
1469 assert(tabPtrP->m_bits & Tablerec::TR_RowGCI);
1470 return m_data + (tabPtrP->m_bits & Tablerec::TR_Checksum);
1471 }
1472
get_dd_gciDbtup::Tuple_header1473 Uint32 *get_dd_gci(const Tablerec* tabPtrP, Uint32 mm){
1474 assert(tabPtrP->m_bits & Tablerec::TR_RowGCI);
1475 return m_data;
1476 }
1477 };
1478
1479 /**
1480 * Format of varpart after insert/update
1481 */
1482 struct Varpart_copy
1483 {
1484 Uint32 m_len;
1485 Uint32 m_data[1]; // Only used for easy offset handling
1486
1487 STATIC_CONST( SZ32 = 1 );
1488 };
1489
1490 enum When
1491 {
1492 KRS_PREPARE = 0,
1493 KRS_COMMIT = 1,
1494 KRS_PRE_COMMIT_BASE = 2,
1495 KRS_UK_PRE_COMMIT0 = KRS_PRE_COMMIT_BASE + TriggerPreCommitPass::UK_PASS_0,
1496 KRS_UK_PRE_COMMIT1 = KRS_PRE_COMMIT_BASE + TriggerPreCommitPass::UK_PASS_1,
1497 KRS_FK_PRE_COMMIT = KRS_PRE_COMMIT_BASE + TriggerPreCommitPass::FK_PASS_0
1498 };
1499
1500 struct KeyReqStruct {
1501
KeyReqStructDbtup::KeyReqStruct1502 KeyReqStruct(EmulatedJamBuffer * _jamBuffer, When when = KRS_PREPARE) {
1503 #if defined VM_TRACE || defined ERROR_INSERT
1504 memset(this, 0xf3, sizeof(* this));
1505 #endif
1506 jamBuffer = _jamBuffer;
1507 m_when = when;
1508 m_deferred_constraints = true;
1509 m_disable_fk_checks = false;
1510 }
KeyReqStructDbtup::KeyReqStruct1511 KeyReqStruct(Dbtup* tup, When when = KRS_PREPARE) {
1512 #if defined VM_TRACE || defined ERROR_INSERT
1513 memset(this, 0xf3, sizeof(* this));
1514 #endif
1515 jamBuffer = tup->jamBuffer();
1516 m_when = when;
1517 m_deferred_constraints = true;
1518 m_disable_fk_checks = false;
1519 }
1520
1521 /**
1522 * These variables are used as temporary storage during execution of the
1523 * TUPKEYREQ signal.
1524 *
1525 * The first set of variables defines a number of variables needed for
1526 * the fix part of the tuple.
1527 *
1528 * The second part defines a number of commonly used meta data variables.
1529 *
1530 * The third part is variables needed only for updates and inserts.
1531 *
1532 * The fourth set of variables defines a set of variables needed for the
1533 * variable part.
1534 *
1535 * The fifth part is a long array of real lengths which is is put last
1536 * for cache memory reasons. This is part of the variable part and
1537 * contains the real allocated lengths whereas the tuple contains
1538 * the length of attribute stored.
1539 */
1540
1541 Tablerec* tablePtrP;
1542 Fragrecord* fragPtrP;
1543 Operationrec * operPtrP;
1544 EmulatedJamBuffer * jamBuffer;
1545 Tuple_header *m_tuple_ptr;
1546
1547 Uint32 check_offset[2];
1548
1549 TableDescriptor *attr_descr;
1550 Uint32 max_read;
1551 Uint32 out_buf_index;
1552 Uint32 out_buf_bits;
1553 Uint32 in_buf_index;
1554 union {
1555 Uint32 in_buf_len;
1556 Uint32 m_lcp_varpart_len;
1557 };
1558 union {
1559 Uint32 attr_descriptor;
1560 Uint32 errorCode; // Used in DbtupRoutines read/update functions
1561 };
1562 bool xfrm_flag;
1563
1564 /* Flag: is tuple in expanded or in shrunken/stored format? */
1565 bool is_expanded;
1566 bool m_is_lcp;
1567 enum When m_when;
1568
1569 Tuple_header *m_disk_ptr;
1570 PagePtr m_page_ptr;
1571 PagePtr m_varpart_page_ptr; // could be same as m_page_ptr_p
1572 PagePtr m_disk_page_ptr; //
1573 Local_key m_row_id;
1574 Uint32 optimize_options;
1575
1576 bool dirty_op;
1577 bool interpreted_exec;
1578 bool last_row;
1579 bool m_use_rowid;
1580 Uint8 m_reorg;
1581 Uint8 m_prio_a_flag;
1582 bool m_deferred_constraints;
1583 bool m_disable_fk_checks;
1584
1585 Signal* signal;
1586 Uint32 num_fired_triggers;
1587 Uint32 no_exec_instructions;
1588 Uint32 frag_page_id;
1589 Uint32 hash_value;
1590 Uint32 gci_hi;
1591 Uint32 gci_lo;
1592 Uint32 log_size;
1593 Uint32 read_length;
1594 Uint32 attrinfo_len;
1595 Uint32 tc_operation_ptr;
1596 Uint32 trans_id1;
1597 Uint32 trans_id2;
1598 Uint32 TC_index;
1599 // next 2 apply only to attrids >= 64 (zero otherwise)
1600 BlockReference TC_ref;
1601 BlockReference rec_blockref;
1602
1603 struct Var_data {
1604 /*
1605 These are the pointers and offsets to the variable-sized part of the row
1606 (static part, alwways stored even if NULL). They are used both for
1607 expanded and shrunken form, with different values to allow using the
1608 same read/update code for both forms.
1609 */
1610 char *m_data_ptr;
1611 Uint16 *m_offset_array_ptr;
1612 Uint16 m_var_len_offset;
1613 Uint16 m_max_var_offset;
1614 Uint16 m_max_dyn_offset;
1615
1616 /* These are the pointers and offsets to the dynamic part of the row. */
1617
1618 /* Pointer to the start of the bitmap for the dynamic part of the row. */
1619 char *m_dyn_data_ptr;
1620 /* Number of 32-bit words in dynamic part (stored/shrunken format). */
1621 Uint32 m_dyn_part_len;
1622 /*
1623 Pointer to array with one element for each dynamic attribute (both
1624 variable and fixed size). Each value is the offset from the end of the
1625 bitmap to the start of the data for that attribute.
1626 */
1627 Uint16 *m_dyn_offset_arr_ptr;
1628 /*
1629 Offset from m_dyn_offset_array_ptr of array with one element for each
1630 dynamic attribute. Each value is the offset to the end of data for that
1631 attribute, so the difference to m_dyn_offset_array_ptr elements provides
1632 the data lengths.
1633 */
1634 Uint16 m_dyn_len_offset;
1635 } m_var_data[2];
1636
1637 /*
1638 * A bit mask where a bit set means that the update or insert
1639 * was updating this record.
1640 */
1641 Bitmask<MAXNROFATTRIBUTESINWORDS> changeMask;
1642 Uint16 var_pos_array[2*MAX_ATTRIBUTES_IN_TABLE + 1];
1643 OperationrecPtr prevOpPtr;
1644 };
1645
1646 friend struct Undo_buffer;
1647 Undo_buffer c_undo_buffer;
1648
1649 /*
1650 No longer used:
1651 Implemented by shift instructions in subroutines instead
1652
1653 struct TupHeadInfo {
1654 struct BitPart {
1655 unsigned int disk_indicator : 1;
1656 unsigned int var_part_loc_ind : 1;
1657 unsigned int initialised : 1;
1658 unsigned int not_used_yet : 5;
1659 unsigned int no_var_sized : 8;
1660 unsigned int tuple_version : 16;
1661 };
1662 union {
1663 Uint32 all;
1664 BitPart bit_part;
1665 };
1666 };
1667 */
1668
1669 struct ChangeMask
1670 {
1671 Uint32 m_cols;
1672 Uint32 m_mask[1];
1673
end_of_maskDbtup::ChangeMask1674 const Uint32 * end_of_mask() const { return end_of_mask(m_cols); }
end_of_maskDbtup::ChangeMask1675 const Uint32 * end_of_mask(Uint32 cols) const {
1676 return m_mask + ((cols + 31) >> 5);
1677 }
1678
end_of_maskDbtup::ChangeMask1679 Uint32 * end_of_mask() { return end_of_mask(m_cols); }
end_of_maskDbtup::ChangeMask1680 Uint32 * end_of_mask(Uint32 cols) {
1681 return m_mask + ((cols + 31) >> 5);
1682 }
1683 };
1684
1685 // updateAttributes module
1686 Uint32 terrorCode;
1687
1688 public:
1689 Dbtup(Block_context&, Uint32 instanceNumber = 0);
1690 virtual ~Dbtup();
1691
1692 /*
1693 * TUX uses logical tuple address when talking to ACC and LQH.
1694 */
1695 void tuxGetTupAddr(Uint32 fragPtrI, Uint32 pageId, Uint32 pageOffset,
1696 Uint32& lkey1, Uint32& lkey2);
1697
1698 /*
1699 * TUX index in TUP has single Uint32 array attribute which stores an
1700 * index node. TUX reads and writes the node directly via pointer.
1701 */
1702 int tuxAllocNode(EmulatedJamBuffer*, Uint32 fragPtrI, Uint32& pageId, Uint32& pageOffset, Uint32*& node);
1703 void tuxFreeNode(Uint32 fragPtrI, Uint32 pageId, Uint32 pageOffset, Uint32* node);
1704 void tuxGetNode(Uint32 fragPtrI, Uint32 pageId, Uint32 pageOffset, Uint32*& node);
1705
1706 /*
1707 * TUX reads primary table attributes for index keys. Tuple is
1708 * specified by location of original tuple and version number. Input
1709 * is attribute ids in AttributeHeader format. Output is attribute
1710 * data with headers. Uses readAttributes with xfrm option set.
1711 * After wl4163, xfrm is not set.
1712 * Returns number of words or negative (-terrorCode) on error.
1713 */
1714 int tuxReadAttrs(EmulatedJamBuffer*,
1715 Uint32 fragPtrI, Uint32 pageId, Uint32 pageOffset, Uint32 tupVersion,
1716 const Uint32* attrIds, Uint32 numAttrs, Uint32* dataOut, bool xfrmFlag);
1717
1718 /*
1719 * TUX reads primary key without headers into an array of words. Used
1720 * for md5 summing and when returning keyinfo. Returns number of
1721 * words or negative (-terrorCode) on error.
1722 */
1723 int tuxReadPk(Uint32 fragPtrI, Uint32 pageId, Uint32 pageOffset, Uint32* dataOut, bool xfrmFlag);
1724
1725 /*
1726 * ACC reads primary key without headers into an array of words. At
1727 * this point in ACC deconstruction, ACC still uses logical references
1728 * to fragment and tuple.
1729 */
1730 int accReadPk(Uint32 tableId, Uint32 fragId, Uint32 fragPageId, Uint32 pageIndex, Uint32* dataOut, bool xfrmFlag);
1731
1732 /*
1733 * TUX checks if tuple is visible to scan.
1734 */
1735 bool tuxQueryTh(Uint32 fragPtrI, Uint32 pageId, Uint32 pageIndex, Uint32 tupVersion, Uint32 transId1, Uint32 transId2, bool dirty, Uint32 savepointId);
1736
1737 int load_diskpage(Signal*, Uint32 opRec, Uint32 fragPtrI,
1738 Uint32 lkey1, Uint32 lkey2, Uint32 flags);
1739
1740 int load_diskpage_scan(Signal*, Uint32 opRec, Uint32 fragPtrI,
1741 Uint32 lkey1, Uint32 lkey2, Uint32 flags);
1742
1743 void start_restore_lcp(Uint32 tableId, Uint32 fragmentId);
1744 void complete_restore_lcp(Signal*, Uint32 ref, Uint32 data,
1745 Uint32 tableId, Uint32 fragmentId);
1746 Uint32 get_max_lcp_record_size(Uint32 tableId);
1747
1748 int nr_read_pk(Uint32 fragPtr, const Local_key*, Uint32* dataOut, bool©);
1749 int nr_update_gci(Uint32 fragPtr, const Local_key*, Uint32 gci);
1750 int nr_delete(Signal*, Uint32, Uint32 fragPtr, const Local_key*, Uint32 gci);
1751
1752 void nr_delete_page_callback(Signal*, Uint32 op, Uint32 page);
1753 void nr_delete_log_buffer_callback(Signal*, Uint32 op, Uint32 page);
1754
1755 bool get_frag_info(Uint32 tableId, Uint32 fragId, Uint32* maxPage);
1756
1757 void execSTORED_PROCREQ(Signal* signal);
1758
1759
1760 // Statistics about fragment memory usage.
1761 struct FragStats
1762 {
1763 // Size of fixed-size part of record.
1764 Uint32 fixedRecordBytes;
1765 // Page size (32k, see File_formats::NDB_PAGE_SIZE).
1766 Uint32 pageSizeBytes;
1767 // Number of fixed-size parts that fits in each page.
1768 Uint32 fixedSlotsPerPage;
1769 // Number of pages allocated for storing fixed-size parts.
1770 Uint64 fixedMemoryAllocPages;
1771 // Number of pages allocated for storing var-size parts.
1772 Uint64 varMemoryAllocPages;
1773 /**
1774 Number of bytes for storing var-size parts that are allocated but not yet
1775 used.
1776 */
1777 Uint64 varMemoryFreeBytes;
1778 // Number of fixed-size elements (i.e. number of rows.)
1779 Uint64 fixedElemCount;
1780 /**
1781 Number of var-size elements. There will be one for each row that has at
1782 least one non-null var-size field (varchar/varbinary/blob).
1783 */
1784 Uint64 varElemCount;
1785 // Size of the page map (DynArr256) that maps from logical to physical pages.
1786 Uint64 logToPhysMapAllocBytes;
1787 };
1788
1789 const FragStats get_frag_stats(Uint32 fragId) const;
1790
1791 private:
1792 BLOCK_DEFINES(Dbtup);
1793
1794 // Transit signals
1795 void execDEBUG_SIG(Signal* signal);
1796 void execCONTINUEB(Signal* signal);
1797
1798 // Received signals
1799 void execLCP_FRAG_ORD(Signal*signal);
1800 void execDUMP_STATE_ORD(Signal* signal);
1801 void execSEND_PACKED(Signal* signal);
1802 void execSTTOR(Signal* signal);
1803 void execTUP_LCPREQ(Signal* signal);
1804 void execEND_LCPREQ(Signal* signal);
1805 void execSTART_RECREQ(Signal* signal);
1806 void execMEMCHECKREQ(Signal* signal);
1807 void execTUPSEIZEREQ(Signal* signal);
1808 void execTUPRELEASEREQ(Signal* signal);
1809
1810 void execCREATE_TAB_REQ(Signal*);
1811 void execTUP_ADD_ATTRREQ(Signal* signal);
1812 void execTUPFRAGREQ(Signal* signal);
1813 void execTUP_COMMITREQ(Signal* signal);
1814 void execTUP_ABORTREQ(Signal* signal);
1815 void execNDB_STTOR(Signal* signal);
1816 void execREAD_CONFIG_REQ(Signal* signal);
1817 void execDROP_TAB_REQ(Signal* signal);
1818 void execALTER_TAB_REQ(Signal* signal);
1819 void execTUP_DEALLOCREQ(Signal* signal);
1820 void execTUP_WRITELOG_REQ(Signal* signal);
1821 void execNODE_FAILREP(Signal* signal);
1822 void execNODE_STATE_REP(Signal*);
1823
1824 void execDROP_FRAG_REQ(Signal*);
1825
1826 // Ordered index related
1827 void execBUILD_INDX_IMPL_REQ(Signal* signal);
1828 void execBUILD_INDX_IMPL_REF(Signal* signal);
1829 void execBUILD_INDX_IMPL_CONF(Signal* signal);
1830 void buildIndex(Signal* signal, Uint32 buildPtrI);
1831 void buildIndexReply(Signal* signal, const BuildIndexRec* buildRec);
1832 void buildIndexOffline(Signal* signal, Uint32 buildPtrI);
1833 void buildIndexOffline_table_readonly(Signal* signal, Uint32 buildPtrI);
1834 void execALTER_TAB_CONF(Signal*);
1835
1836 // Tup scan
1837 void execACC_SCANREQ(Signal* signal);
1838 void execNEXT_SCANREQ(Signal* signal);
1839 void execACC_CHECK_SCAN(Signal* signal);
1840 void execACCKEYCONF(Signal* signal);
1841 void execACCKEYREF(Signal* signal);
1842 void execACC_ABORTCONF(Signal* signal);
1843
1844
1845 // Drop table
1846 void execFSREMOVEREF(Signal*);
1847 void execFSREMOVECONF(Signal*);
1848
1849 void execDBINFO_SCANREQ(Signal*);
1850 void execSUB_GCP_COMPLETE_REP(Signal*);
1851
1852 //------------------------------------------------------------------
1853 //------------------------------------------------------------------
1854 // Methods to handle execution of TUPKEYREQ + ATTRINFO.
1855 //
1856 // Module Execution Manager
1857 //
1858 // The TUPKEYREQ signal is central to this block. This signal is used
1859 // by everybody that needs to read data residing in DBTUP. The data is
1860 // read using an interpreter approach.
1861 //
1862 // Operations only needing to read execute a simplified version of the
1863 // interpreter where the only instruction is read Attribute to send.
1864 // Operations only needing to update the record (insert or update)
1865 // execute a simplified version of the interpreter where the only
1866 // instruction is write Attribute.
1867 //
1868 // Currently TUPKEYREQ is used in the following situations.
1869 // 1) Normal transaction execution. Can be any of the types described
1870 // below.
1871 // 2) Execution of fragment redo log during system restart.
1872 // In this situation there will only be normal updates, inserts
1873 // and deletes performed.
1874 // 3) A special type of normal transaction execution is to write the
1875 // records arriving from the primary replica in the node restart
1876 // processing. This will always be normal write operations which
1877 // are translated to inserts or updates before arriving to TUP.
1878 // 4) Scan processing. The scan processing will use normal reads or
1879 // interpreted reads in their execution. There will be one TUPKEYREQ
1880 // signal for each record processed.
1881 // 5) Copy fragment processing. This is a special type of scan used in the
1882 // primary replica at system restart. It reads the entire reads and
1883 // converts those to writes to the starting node. In this special case
1884 // LQH acts as an API node and receives also the ATTRINFO sent in the
1885 // TRANSID_AI signals.
1886 //
1887 // Signal Diagram:
1888 //
1889 // In Signals:
1890 // -----------
1891 //
1892 // ---> TUPKEYREQ
1893 // A single TUPKEYREQ is received. The TUPKEYREQ can contain an I-value
1894 // for a long section containing AttrInfo words. Delete requests usually
1895 // contain no AttrInfo, and requests referencing a stored procedure (e.g.
1896 // scan originated requests) do not contain AttrInfo.
1897 //
1898 // The total size of the ATTRINFO is not allowed to be more than 16384 words.
1899 // There is always one and only one TUPKEYREQ.
1900 //
1901 // Response Signals (successful case):
1902 //
1903 // Simple/Dirty Read Operation
1904 // ---------------------------
1905 //
1906 // <---- TRANSID_AI (to API)
1907 // ...
1908 // <---- TRANSID_AI (to API)
1909 // <---- READCONF (to API)
1910 // <---- TUPKEYCONF (to LQH)
1911 // There is always exactly one READCONF25 sent last. The number of
1912 // TRANSID_AI is dependent on how much that was read. The maximum size
1913 // of the ATTRINFO sent back is 16384 words. The signals are sent
1914 // directly to the application with an address provided by the
1915 // TUPKEYREQ signal.
1916 // A positive response signal is also sent to LQH.
1917 //
1918 // Normal Read Operation
1919 // ---------------------
1920 //
1921 // <---- TRANSID_AI (to API)
1922 // ...
1923 // <---- TRANSID_AI (to API)
1924 // <---- TUPKEYCONF (to LQH)
1925 // The number of TRANSID_AI is dependent on how much that was read.
1926 // The maximum size of the ATTRINFO sent back is 16384 words. The
1927 // signals are sent directly to the application with an address
1928 // provided by the TUPKEYREQ signal.
1929 // A positive response signal is also sent to LQH.
1930 //
1931 // Normal update/insert/delete operation
1932 // -------------------------------------
1933 //
1934 // <---- TUPKEYCONF
1935 // After successful updating of the tuple LQH is informed of this.
1936 //
1937 // Delete with read
1938 // ----------------
1939 //
1940 // Will behave as a normal read although it also prepares the
1941 // deletion of the tuple.
1942 //
1943 // Interpreted Update
1944 // ------------------
1945 //
1946 // <---- TRANSID_AI (to API)
1947 // ...
1948 // <---- TRANSID_AI (to API)
1949 // <---- TUP_ATTRINFO (to LQH)
1950 // ...
1951 // <---- TUP_ATTRINFO (to LQH)
1952 // <---- TUPKEYCONF (to LQH)
1953 //
1954 // The interpreted Update contains five sections:
1955 // The first section performs read Attribute operations
1956 // that send results back to the API.
1957 //
1958 // The second section executes the interpreted program
1959 // where data from attributes can be updated and it
1960 // can also read attribute values into the registers.
1961 //
1962 // The third section performs unconditional updates of
1963 // attributes.
1964 //
1965 // The fourth section can read the attributes to be sent to the
1966 // API after updating the record.
1967 //
1968 // The fifth section contains subroutines used by the interpreter
1969 // in the second section.
1970 //
1971 // All types of interpreted programs contains the same five sections.
1972 // The only difference is that only interpreted updates can update
1973 // attributes. Interpreted inserts are not allowed.
1974 //
1975 // Interpreted Updates have to send back the information about the
1976 // attributes they have updated. This information will be shipped to
1977 // the log and also to any other replicas. Thus interpreted updates
1978 // are only performed in the primary replica. The fragment redo log
1979 // in LQH will contain information so that normal update/inserts/deletes
1980 // can be performed using TUPKEYREQ.
1981 //
1982 // Interpreted Read
1983 // ----------------
1984 //
1985 // From a signalling point of view the Interpreted Read behaves as
1986 // as a Normal Read. The interpreted Read is often used by Scan's.
1987 //
1988 // Interpreted Delete
1989 // ------------------
1990 //
1991 // <---- TUPKEYCONF
1992 // After successful prepartion to delete the tuple LQH is informed
1993 // of this.
1994 //
1995 // Interpreted Delete with Read
1996 // ----------------------------
1997 //
1998 // From a signalling point of view an interpreted delete with read
1999 // behaves as a normal read.
2000 //
2001 // Continuation after successful case:
2002 //
2003 // After a read of any kind the operation record is ready to be used
2004 // again by a new operation.
2005 //
2006 // Any updates, inserts or deletes waits for either of two messages.
2007 // A commit specifying that the operation is to be performed for real
2008 // or an abort specifying that the operation is to be rolled back and
2009 // the record to be restored in its original format.
2010 //
2011 // This is handled by the module Transaction Manager.
2012 //
2013 // Response Signals (unsuccessful case):
2014 //
2015 // <---- TUPKEYREF (to LQH)
2016 // A signal is sent back to LQH informing about the unsuccessful
2017 // operation. In this case TUP waits for an abort signal to arrive
2018 // before the operation record is ready for the next operation.
2019 // This is handled by the Transaction Manager.
2020 //------------------------------------------------------------------
2021 //------------------------------------------------------------------
2022
2023 // *****************************************************************
2024 // Signal Reception methods.
2025 // *****************************************************************
2026 //------------------------------------------------------------------
2027 //------------------------------------------------------------------
2028 public:
2029 bool execTUPKEYREQ(Signal* signal);
2030 /**
2031 * Prepare for execTUPKEYREQ by prefetching row and preparing
2032 * some variables as part of row address calculation.
2033 */
2034 void prepareTUPKEYREQ(Uint32 page_id,
2035 Uint32 page_idx,
2036 Uint32 frag_id);
2037 private:
2038 void disk_page_load_callback(Signal*, Uint32 op, Uint32 page);
2039 void disk_page_load_scan_callback(Signal*, Uint32 op, Uint32 page);
2040
2041 private:
2042
2043 // Trigger signals
2044 //------------------------------------------------------------------
2045 //------------------------------------------------------------------
2046 void execCREATE_TRIG_IMPL_REQ(Signal* signal);
2047
2048 //------------------------------------------------------------------
2049 //------------------------------------------------------------------
2050 void execDROP_TRIG_IMPL_REQ(Signal* signal);
2051
2052 /**
2053 * Deferred triggers execute when execFIRE_TRIG_REQ
2054 * is called
2055 */
2056 void execFIRE_TRIG_REQ(Signal* signal);
2057
2058 // *****************************************************************
2059 // Setting up the environment for reads, inserts, updates and deletes.
2060 // *****************************************************************
2061 //------------------------------------------------------------------
2062 //------------------------------------------------------------------
2063 int handleReadReq(Signal* signal,
2064 Operationrec* regOperPtr,
2065 Tablerec* regTabPtr,
2066 KeyReqStruct* req_struct);
2067
2068 //------------------------------------------------------------------
2069 //------------------------------------------------------------------
2070 int handleUpdateReq(Signal* signal,
2071 Operationrec* regOperPtr,
2072 Fragrecord* regFragPtr,
2073 Tablerec* regTabPtr,
2074 KeyReqStruct* req_struct,
2075 bool disk);
2076
2077 //------------------------------------------------------------------
2078 //------------------------------------------------------------------
2079 int handleInsertReq(Signal* signal,
2080 Ptr<Operationrec> regOperPtr,
2081 Ptr<Fragrecord>,
2082 Tablerec* regTabPtr,
2083 KeyReqStruct* req_struct,
2084 Local_key ** accminupdateptr);
2085
2086 //------------------------------------------------------------------
2087 //------------------------------------------------------------------
2088 int handleDeleteReq(Signal* signal,
2089 Operationrec* regOperPtr,
2090 Fragrecord* regFragPtr,
2091 Tablerec* regTabPtr,
2092 KeyReqStruct* req_struct,
2093 bool disk);
2094
2095 int handleRefreshReq(Signal* signal,
2096 Ptr<Operationrec>,
2097 Ptr<Fragrecord>,
2098 Tablerec*,
2099 KeyReqStruct*,
2100 bool disk);
2101
2102 //------------------------------------------------------------------
2103 //------------------------------------------------------------------
2104 int updateStartLab(Signal* signal,
2105 Operationrec* regOperPtr,
2106 Fragrecord* regFragPtr,
2107 Tablerec* regTabPtr,
2108 KeyReqStruct* req_struct);
2109
2110 // *****************************************************************
2111 // Interpreter Handling methods.
2112 // *****************************************************************
2113
2114 //------------------------------------------------------------------
2115 //------------------------------------------------------------------
2116 int interpreterStartLab(Signal* signal,
2117 KeyReqStruct *req_struct);
2118
2119 //------------------------------------------------------------------
2120 //------------------------------------------------------------------
2121 Uint32 brancher(Uint32, Uint32);
2122 int interpreterNextLab(Signal* signal,
2123 KeyReqStruct *req_struct,
2124 Uint32* logMemory,
2125 Uint32* mainProgram,
2126 Uint32 TmainProgLen,
2127 Uint32* subroutineProg,
2128 Uint32 TsubroutineLen,
2129 Uint32 * tmpArea,
2130 Uint32 tmpAreaSz);
2131
2132 const Uint32 * lookupInterpreterParameter(Uint32 paramNo,
2133 const Uint32 * subptr,
2134 Uint32 sublen) const;
2135
2136 // *****************************************************************
2137 // Signal Sending methods.
2138 // *****************************************************************
2139 //------------------------------------------------------------------
2140 //------------------------------------------------------------------
2141 void sendReadAttrinfo(Signal* signal,
2142 KeyReqStruct *req_struct,
2143 Uint32 TnoOfData);
2144
2145 //------------------------------------------------------------------
2146 //------------------------------------------------------------------
2147 int sendLogAttrinfo(Signal* signal,
2148 KeyReqStruct *req_struct,
2149 Uint32 TlogSize,
2150 Operationrec * regOperPtr);
2151
2152 //------------------------------------------------------------------
2153 //------------------------------------------------------------------
2154 void returnTUPKEYCONF(Signal* signal,
2155 KeyReqStruct *req_struct,
2156 Operationrec * regOperPtr,
2157 TransState trans_state);
2158
2159 //------------------------------------------------------------------
2160 //------------------------------------------------------------------
2161 // *****************************************************************
2162 // The methods that perform the actual read and update of attributes
2163 // in the tuple.
2164 // *****************************************************************
2165 //------------------------------------------------------------------
2166 //------------------------------------------------------------------
2167 int readAttributes(KeyReqStruct* req_struct,
2168 const Uint32* inBuffer,
2169 Uint32 inBufLen,
2170 Uint32* outBuffer,
2171 Uint32 TmaxRead,
2172 bool xfrmFlag);
2173
2174 //------------------------------------------------------------------
2175 //------------------------------------------------------------------
2176 int updateAttributes(KeyReqStruct *req_struct,
2177 Uint32* inBuffer,
2178 Uint32 inBufLen);
2179
2180 //------------------------------------------------------------------
2181 //------------------------------------------------------------------
2182 bool readFixedSizeTHOneWordNotNULL(Uint8* outBuffer,
2183 KeyReqStruct *req_struct,
2184 AttributeHeader* ahOut,
2185 Uint32 attrDes2);
2186
2187 //------------------------------------------------------------------
2188 //------------------------------------------------------------------
2189 bool updateFixedSizeTHOneWordNotNULL(Uint32* inBuffer,
2190 KeyReqStruct *req_struct,
2191 Uint32 attrDes2);
2192
2193 //------------------------------------------------------------------
2194 //------------------------------------------------------------------
2195 bool readFixedSizeTHTwoWordNotNULL(Uint8* outBuffer,
2196 KeyReqStruct *req_struct,
2197 AttributeHeader* ahOut,
2198 Uint32 attrDes2);
2199
2200 //------------------------------------------------------------------
2201 //------------------------------------------------------------------
2202 bool updateFixedSizeTHTwoWordNotNULL(Uint32* inBuffer,
2203 KeyReqStruct *req_struct,
2204 Uint32 attrDes2);
2205
2206 //------------------------------------------------------------------
2207 //------------------------------------------------------------------
2208 bool readFixedSizeTHManyWordNotNULL(Uint8* outBuffer,
2209 KeyReqStruct *req_struct,
2210 AttributeHeader* ahOut,
2211 Uint32 attrDes2);
2212
2213 //------------------------------------------------------------------
2214 //------------------------------------------------------------------
2215 bool fixsize_updater(Uint32* inBuffer,
2216 KeyReqStruct *req_struct,
2217 Uint32 attrDes2,
2218 Uint32 *dst_ptr,
2219 Uint32 updateOffset,
2220 Uint32 checkOffset);
2221 bool updateFixedSizeTHManyWordNotNULL(Uint32* inBuffer,
2222 KeyReqStruct *req_struct,
2223 Uint32 attrDes2);
2224
2225 //------------------------------------------------------------------
2226 //------------------------------------------------------------------
2227 bool readFixedSizeTHOneWordNULLable(Uint8* outBuffer,
2228 KeyReqStruct *req_struct,
2229 AttributeHeader* ahOut,
2230 Uint32 attrDes2);
2231
2232 //------------------------------------------------------------------
2233 //------------------------------------------------------------------
2234 bool updateFixedSizeTHOneWordNULLable(Uint32* inBuffer,
2235 KeyReqStruct *req_struct,
2236 Uint32 attrDes2);
2237
2238 //------------------------------------------------------------------
2239 //------------------------------------------------------------------
2240 bool readFixedSizeTHTwoWordNULLable(Uint8* outBuffer,
2241 KeyReqStruct *req_struct,
2242 AttributeHeader* ahOut,
2243 Uint32 attrDes2);
2244
2245 //------------------------------------------------------------------
2246 //------------------------------------------------------------------
2247 bool updateFixedSizeTHTwoWordNULLable(Uint32* inBuffer,
2248 KeyReqStruct *req_struct,
2249 Uint32 attrDes2);
2250
2251 //------------------------------------------------------------------
2252 //------------------------------------------------------------------
2253 bool readFixedSizeTHManyWordNULLable(Uint8* outBuffer,
2254 KeyReqStruct *req_struct,
2255 AttributeHeader* ahOut,
2256 Uint32 attrDes2);
2257
2258 //------------------------------------------------------------------
2259 //------------------------------------------------------------------
2260 bool readFixedSizeTHZeroWordNULLable(Uint8* outBuffer,
2261 KeyReqStruct *req_struct,
2262 AttributeHeader* ahOut,
2263 Uint32 attrDes2);
2264 //------------------------------------------------------------------
2265 //------------------------------------------------------------------
2266 bool updateFixedSizeTHManyWordNULLable(Uint32* inBuffer,
2267 KeyReqStruct *req_struct,
2268 Uint32 attrDes2);
2269
2270 //------------------------------------------------------------------
2271 //------------------------------------------------------------------
2272 bool varsize_reader(Uint8* out_buffer,
2273 KeyReqStruct *req_struct,
2274 AttributeHeader* ah_out,
2275 Uint32 attr_des2,
2276 const void* src_ptr,
2277 Uint32 vsize_in_bytes);
2278
2279 bool xfrm_reader(Uint8* out_buffer,
2280 KeyReqStruct *req_struct,
2281 AttributeHeader* ah_out,
2282 Uint32 attr_des2,
2283 const void* src_ptr,
2284 Uint32 srcBytes);
2285
2286 bool bits_reader(Uint8* out_buffer,
2287 KeyReqStruct *req_struct,
2288 AttributeHeader* ah_out,
2289 const Uint32* bm_ptr, Uint32 bm_len,
2290 Uint32 bitPos, Uint32 bitCnt);
2291
2292 bool varsize_updater(Uint32* in_buffer,
2293 KeyReqStruct *req_struct,
2294 char *var_data_start,
2295 Uint32 var_attr_pos,
2296 Uint16 *len_offset_ptr,
2297 Uint32 check_offset);
2298 //------------------------------------------------------------------
2299 //------------------------------------------------------------------
2300 bool readVarSizeNotNULL(Uint8* outBuffer,
2301 KeyReqStruct *req_struct,
2302 AttributeHeader* ahOut,
2303 Uint32 attrDes2);
2304
2305 //------------------------------------------------------------------
2306 //------------------------------------------------------------------
2307 bool updateVarSizeNotNULL(Uint32* inBuffer,
2308 KeyReqStruct *req_struct,
2309 Uint32 attrDes2);
2310
2311 //------------------------------------------------------------------
2312 //------------------------------------------------------------------
2313 bool readVarSizeNULLable(Uint8* outBuffer,
2314 KeyReqStruct *req_struct,
2315 AttributeHeader* ahOut,
2316 Uint32 attrDes2);
2317
2318 //------------------------------------------------------------------
2319 //------------------------------------------------------------------
2320 bool updateVarSizeNULLable(Uint32* inBuffer,
2321 KeyReqStruct *req_struct,
2322 Uint32 attrDes2);
2323
2324 //------------------------------------------------------------------
2325 //------------------------------------------------------------------
2326 bool readDynFixedSizeNotNULL(Uint8* outBuffer,
2327 KeyReqStruct *req_struct,
2328 AttributeHeader* ahOut,
2329 Uint32 attrDes2);
2330 bool readDynFixedSizeNULLable(Uint8* outBuffer,
2331 KeyReqStruct *req_struct,
2332 AttributeHeader* ahOut,
2333 Uint32 attrDes2);
2334 bool readDynFixedSizeExpandedNotNULL(Uint8* outBuffer,
2335 KeyReqStruct *req_struct,
2336 AttributeHeader* ahOut,
2337 Uint32 attrDes2);
2338 bool readDynFixedSizeShrunkenNotNULL(Uint8* outBuffer,
2339 KeyReqStruct *req_struct,
2340 AttributeHeader* ahOut,
2341 Uint32 attrDes2);
2342 bool readDynFixedSizeExpandedNULLable(Uint8* outBuffer,
2343 KeyReqStruct *req_struct,
2344 AttributeHeader* ahOut,
2345 Uint32 attrDes2);
2346 bool readDynFixedSizeShrunkenNULLable(Uint8* outBuffer,
2347 KeyReqStruct *req_struct,
2348 AttributeHeader* ahOut,
2349 Uint32 attrDes2);
2350
2351 //------------------------------------------------------------------
2352 //------------------------------------------------------------------
2353 bool updateDynFixedSizeNotNULL(Uint32* inBuffer,
2354 KeyReqStruct *req_struct,
2355 Uint32 attrDes2);
2356 bool updateDynFixedSizeNULLable(Uint32* inBuffer,
2357 KeyReqStruct *req_struct,
2358 Uint32 attrDes2);
2359
2360 //------------------------------------------------------------------
2361 //------------------------------------------------------------------
2362 bool readDynBigFixedSizeNotNULL(Uint8* outBuffer,
2363 KeyReqStruct *req_struct,
2364 AttributeHeader* ahOut,
2365 Uint32 attrDes2);
2366 bool readDynBigFixedSizeNULLable(Uint8* outBuffer,
2367 KeyReqStruct *req_struct,
2368 AttributeHeader* ahOut,
2369 Uint32 attrDes2);
2370 bool readDynBigFixedSizeExpandedNotNULL(Uint8* outBuffer,
2371 KeyReqStruct *req_struct,
2372 AttributeHeader* ahOut,
2373 Uint32 attrDes2);
2374 bool readDynBigFixedSizeShrunkenNotNULL(Uint8* outBuffer,
2375 KeyReqStruct *req_struct,
2376 AttributeHeader* ahOut,
2377 Uint32 attrDes2);
2378 bool readDynBigFixedSizeExpandedNULLable(Uint8* outBuffer,
2379 KeyReqStruct *req_struct,
2380 AttributeHeader* ahOut,
2381 Uint32 attrDes2);
2382 bool readDynBigFixedSizeShrunkenNULLable(Uint8* outBuffer,
2383 KeyReqStruct *req_struct,
2384 AttributeHeader* ahOut,
2385 Uint32 attrDes2);
2386
2387 //------------------------------------------------------------------
2388 //------------------------------------------------------------------
2389 bool updateDynBigFixedSizeNotNULL(Uint32* inBuffer,
2390 KeyReqStruct *req_struct,
2391 Uint32 attrDes2);
2392 bool updateDynBigFixedSizeNULLable(Uint32* inBuffer,
2393 KeyReqStruct *req_struct,
2394 Uint32 attrDes2);
2395
2396 //------------------------------------------------------------------
2397 //------------------------------------------------------------------
2398 bool readDynBitsNotNULL(Uint8* outBuffer,
2399 KeyReqStruct *req_struct,
2400 AttributeHeader* ahOut,
2401 Uint32 attrDes2);
2402 bool readDynBitsNULLable(Uint8* outBuffer,
2403 KeyReqStruct *req_struct,
2404 AttributeHeader* ahOut,
2405 Uint32 attrDes2);
2406 bool readDynBitsExpandedNotNULL(Uint8* outBuffer,
2407 KeyReqStruct *req_struct,
2408 AttributeHeader* ahOut,
2409 Uint32 attrDes2);
2410 bool readDynBitsShrunkenNotNULL(Uint8* outBuffer,
2411 KeyReqStruct *req_struct,
2412 AttributeHeader* ahOut,
2413 Uint32 attrDes2);
2414 bool readDynBitsExpandedNULLable(Uint8* outBuffer,
2415 KeyReqStruct *req_struct,
2416 AttributeHeader* ahOut,
2417 Uint32 attrDes2);
2418 bool readDynBitsShrunkenNULLable(Uint8* outBuffer,
2419 KeyReqStruct *req_struct,
2420 AttributeHeader* ahOut,
2421 Uint32 attrDes2);
2422
2423 //------------------------------------------------------------------
2424 //------------------------------------------------------------------
2425 bool updateDynBitsNotNULL(Uint32* inBuffer,
2426 KeyReqStruct *req_struct,
2427 Uint32 attrDes2);
2428 bool updateDynBitsNULLable(Uint32* inBuffer,
2429 KeyReqStruct *req_struct,
2430 Uint32 attrDes2);
2431
2432 //------------------------------------------------------------------
2433 //------------------------------------------------------------------
2434 bool readDynVarSizeNotNULL(Uint8* outBuffer,
2435 KeyReqStruct *req_struct,
2436 AttributeHeader* ahOut,
2437 Uint32 attrDes2);
2438 bool readDynVarSizeNULLable(Uint8* outBuffer,
2439 KeyReqStruct *req_struct,
2440 AttributeHeader* ahOut,
2441 Uint32 attrDes2);
2442 bool readDynVarSizeExpandedNotNULL(Uint8* outBuffer,
2443 KeyReqStruct *req_struct,
2444 AttributeHeader* ahOut,
2445 Uint32 attrDes2);
2446 bool readDynVarSizeShrunkenNotNULL(Uint8* outBuffer,
2447 KeyReqStruct *req_struct,
2448 AttributeHeader* ahOut,
2449 Uint32 attrDes2);
2450 bool readDynVarSizeExpandedNULLable(Uint8* outBuffer,
2451 KeyReqStruct *req_struct,
2452 AttributeHeader* ahOut,
2453 Uint32 attrDes2);
2454 bool readDynVarSizeShrunkenNULLable(Uint8* outBuffer,
2455 KeyReqStruct *req_struct,
2456 AttributeHeader* ahOut,
2457 Uint32 attrDes2);
2458
2459 //------------------------------------------------------------------
2460 //------------------------------------------------------------------
2461 bool updateDynVarSizeNotNULL(Uint32* inBuffer,
2462 KeyReqStruct *req_struct,
2463 Uint32 attrDes2);
2464 bool updateDynVarSizeNULLable(Uint32* inBuffer,
2465 KeyReqStruct *req_struct,
2466 Uint32 attrDes2);
2467
2468 bool readCharNotNULL(Uint8* outBuffer,
2469 KeyReqStruct *req_struct,
2470 AttributeHeader* ahOut,
2471 Uint32 attrDes2);
2472
2473 bool readCharNULLable(Uint8* outBuffer,
2474 KeyReqStruct *req_struct,
2475 AttributeHeader* ahOut,
2476 Uint32 attrDes2);
2477
2478 bool readBitsNULLable(Uint8* outBuffer, KeyReqStruct *req_struct, AttributeHeader*, Uint32);
2479 bool updateBitsNULLable(Uint32* inBuffer, KeyReqStruct *req_struct, Uint32);
2480 bool readBitsNotNULL(Uint8* outBuffer, KeyReqStruct *req_struct, AttributeHeader*, Uint32);
2481 bool updateBitsNotNULL(Uint32* inBuffer, KeyReqStruct *req_struct, Uint32);
2482
2483 bool updateFixedNULLable(Uint32* inBuffer, KeyReqStruct *req_struct, Uint32);
2484 bool updateFixedNotNull(Uint32* inBuffer, KeyReqStruct *req_struct, Uint32);
2485
2486 bool updateVarNULLable(Uint32* inBuffer, KeyReqStruct *req_struct, Uint32);
2487 bool updateVarNotNull(Uint32* inBuffer, KeyReqStruct *req_struct, Uint32);
2488
2489
2490 bool readDiskFixedSizeNotNULL(Uint8* outBuffer,
2491 KeyReqStruct *req_struct,
2492 AttributeHeader* ahOut,
2493 Uint32 attrDes2);
2494
2495 bool readDiskFixedSizeNULLable(Uint8* outBuffer,
2496 KeyReqStruct *req_struct,
2497 AttributeHeader* ahOut,
2498 Uint32 attrDes2);
2499
2500 bool readDiskVarAsFixedSizeNotNULL(Uint8* outBuffer,
2501 KeyReqStruct *req_struct,
2502 AttributeHeader* ahOut,
2503 Uint32 attrDes2);
2504
2505 bool readDiskVarAsFixedSizeNULLable(Uint8* outBuffer,
2506 KeyReqStruct *req_struct,
2507 AttributeHeader* ahOut,
2508 Uint32 attrDes2);
2509 bool readDiskVarSizeNULLable(Uint8*, KeyReqStruct*, AttributeHeader*,Uint32);
2510 bool readDiskVarSizeNotNULL(Uint8*, KeyReqStruct*, AttributeHeader*, Uint32);
2511
2512 bool updateDiskFixedSizeNULLable(Uint32*, KeyReqStruct*, Uint32);
2513 bool updateDiskFixedSizeNotNULL(Uint32*, KeyReqStruct*, Uint32);
2514
2515 bool updateDiskVarAsFixedSizeNULLable(Uint32*, KeyReqStruct*, Uint32);
2516 bool updateDiskVarAsFixedSizeNotNULL(Uint32*, KeyReqStruct*, Uint32);
2517
2518 bool updateDiskVarSizeNULLable(Uint32*, KeyReqStruct *, Uint32);
2519 bool updateDiskVarSizeNotNULL(Uint32*, KeyReqStruct *, Uint32);
2520
2521 bool readDiskBitsNULLable(Uint8*, KeyReqStruct*, AttributeHeader*, Uint32);
2522 bool readDiskBitsNotNULL(Uint8*, KeyReqStruct*, AttributeHeader*, Uint32);
2523 bool updateDiskBitsNULLable(Uint32*, KeyReqStruct*, Uint32);
2524 bool updateDiskBitsNotNULL(Uint32*, KeyReqStruct*, Uint32);
2525
2526
2527 /* Alter table methods. */
2528 void handleAlterTablePrepare(Signal *, const AlterTabReq *, const Tablerec *);
2529 void handleAlterTableCommit(Signal *, const AlterTabReq *, Tablerec *);
2530 void handleAlterTableComplete(Signal *, const AlterTabReq *, Tablerec *);
2531 void handleAlterTableAbort(Signal *, const AlterTabReq *, const Tablerec *);
2532 void sendAlterTabRef(Signal *signal, Uint32 errorCode);
2533 void sendAlterTabConf(Signal *, Uint32 clientData=RNIL);
2534
2535 void handleCharsetPos(Uint32 csNumber, CHARSET_INFO** charsetArray,
2536 Uint32 noOfCharsets,
2537 Uint32 & charsetIndex, Uint32 & attrDes2);
2538 Uint32 computeTableMetaData(Tablerec *regTabPtr);
2539
2540 //------------------------------------------------------------------
2541 //------------------------------------------------------------------
2542 bool nullFlagCheck(KeyReqStruct *req_struct, Uint32 attrDes2);
2543 bool disk_nullFlagCheck(KeyReqStruct *req_struct, Uint32 attrDes2);
2544 int read_pseudo(const Uint32 *, Uint32, KeyReqStruct*, Uint32*);
2545 Uint32 read_packed(const Uint32 *, Uint32, KeyReqStruct*, Uint32*);
2546 Uint32 update_packed(KeyReqStruct*, const Uint32* src);
2547
2548 Uint32 read_lcp(const Uint32 *, Uint32, KeyReqStruct*, Uint32*);
2549 void update_lcp(KeyReqStruct *req_struct, const Uint32* src, Uint32 len);
2550
2551 void flush_read_buffer(KeyReqStruct *, const Uint32* outBuf,
2552 Uint32 resultRef, Uint32 resultData, Uint32 routeRef);
2553 public:
2554 /**
2555 * Used by Restore...
2556 */
2557 Uint32 read_lcp_keys(Uint32, const Uint32 * src, Uint32 len, Uint32 *dst);
2558 private:
2559
2560 //------------------------------------------------------------------
2561 //------------------------------------------------------------------
2562 void setUpQueryRoutines(Tablerec* regTabPtr);
2563
2564 // *****************************************************************
2565 // Service methods.
2566 // *****************************************************************
2567 TransState get_trans_state(Operationrec * const);
2568 void set_trans_state(Operationrec * const, TransState);
2569 TupleState get_tuple_state(Operationrec * const);
2570 void set_tuple_state(Operationrec * const, TupleState);
2571 Uint32 get_frag_page_id(Uint32 real_page_id);
2572 Uint32 get_fix_page_offset(Uint32 page_index, Uint32 tuple_size);
2573
2574 Uint32 decr_tup_version(Uint32 tuple_version);
2575 void update_change_mask_info(const Tablerec*, ChangeMask* dst, const Uint32*src);
2576 void set_change_mask_info(const Tablerec*, ChangeMask* dst);
2577 void clear_change_mask_info(const Tablerec*, ChangeMask* dst);
2578 void copy_change_mask_info(const Tablerec*, ChangeMask* dst, const ChangeMask * src);
2579 void set_commit_change_mask_info(const Tablerec*,
2580 KeyReqStruct*,
2581 const Operationrec*);
2582
2583 //------------------------------------------------------------------
2584 //------------------------------------------------------------------
2585 void copyAttrinfo(Operationrec * regOperPtr, Uint32* inBuffer,
2586 Uint32 expectedLen, Uint32 attrInfoIVal);
2587
2588 //------------------------------------------------------------------
2589 //------------------------------------------------------------------
2590 void initOpConnection(Operationrec* regOperPtr);
2591
2592 //------------------------------------------------------------------
2593 //------------------------------------------------------------------
2594 void initOperationrec(Signal* signal);
2595
2596 //------------------------------------------------------------------
2597 //------------------------------------------------------------------
2598 int getStoredProcAttrInfo(Uint32 storedId,
2599 KeyReqStruct* req_struct,
2600 Uint32& attrInfoIVal);
2601
2602 //------------------------------------------------------------------
2603 //------------------------------------------------------------------
2604 bool insertActiveOpList(OperationrecPtr, KeyReqStruct* req_struct);
2605
2606 //------------------------------------------------------------------
2607 //------------------------------------------------------------------
2608
2609 int store_default_record(const TablerecPtr& regTabPtr);
2610 bool receive_defvalue(Signal* signal, const TablerecPtr& regTabPtr);
2611 //------------------------------------------------------------------
2612 //------------------------------------------------------------------
2613 void bufferTRANSID_AI(Signal* signal, BlockReference aRef, Uint32 Tlen);
2614
2615 //------------------------------------------------------------------
2616 // Trigger handling routines
2617 //------------------------------------------------------------------
2618 DLList<TupTriggerData>*
2619 findTriggerList(Tablerec* table,
2620 TriggerType::Value ttype,
2621 TriggerActionTime::Value ttime,
2622 TriggerEvent::Value tevent);
2623
2624 bool createTrigger(Tablerec*, const CreateTrigImplReq*, const AttributeMask&);
2625
2626 Uint32 dropTrigger(Tablerec* table,
2627 const DropTrigImplReq* req,
2628 BlockNumber sender);
2629
2630 Uint32 getOldTriggerId(const TupTriggerData*, Uint32 op);
2631
2632 void
2633 checkImmediateTriggersAfterInsert(KeyReqStruct *req_struct,
2634 Operationrec* regOperPtr,
2635 Tablerec* tablePtr,
2636 bool disk);
2637
2638 void
2639 checkImmediateTriggersAfterUpdate(KeyReqStruct *req_struct,
2640 Operationrec* regOperPtr,
2641 Tablerec* tablePtr,
2642 bool disk);
2643
2644 void
2645 checkImmediateTriggersAfterDelete(KeyReqStruct *req_struct,
2646 Operationrec* regOperPtr,
2647 Tablerec* tablePtr,
2648 bool disk);
2649
2650 void checkDeferredTriggers(KeyReqStruct *req_struct,
2651 Operationrec* regOperPtr,
2652 Tablerec* regTablePtr,
2653 bool disk);
2654
2655 void checkDetachedTriggers(KeyReqStruct *req_struct,
2656 Operationrec* regOperPtr,
2657 Tablerec* regTablePtr,
2658 bool disk,
2659 Uint32 diskPagePtrI);
2660
2661 void fireImmediateTriggers(KeyReqStruct *req_struct,
2662 DLList<TupTriggerData>& triggerList,
2663 Operationrec* regOperPtr,
2664 bool disk);
2665
2666 void checkDeferredTriggersDuringPrepare(KeyReqStruct *req_struct,
2667 DLList<TupTriggerData>& triggerList,
2668 Operationrec* const regOperPtr,
2669 bool disk);
2670 void fireDeferredTriggers(KeyReqStruct *req_struct,
2671 DLList<TupTriggerData>& triggerList,
2672 Operationrec* const regOperPtr,
2673 bool disk);
2674
2675 void fireDeferredConstraints(KeyReqStruct *req_struct,
2676 DLList<TupTriggerData>& triggerList,
2677 Operationrec* const regOperPtr,
2678 bool disk);
2679
2680 void fireDetachedTriggers(KeyReqStruct *req_struct,
2681 DLList<TupTriggerData>& triggerList,
2682 Operationrec* regOperPtr,
2683 bool disk,
2684 Uint32 diskPagePtrI);
2685
2686 void executeTrigger(KeyReqStruct *req_struct,
2687 TupTriggerData* trigPtr,
2688 Operationrec* regOperPtr,
2689 bool disk);
2690
2691 bool check_fire_trigger(const Fragrecord*,
2692 const TupTriggerData*,
2693 const KeyReqStruct*,
2694 const Operationrec*) const;
2695
2696 bool check_fire_reorg(const KeyReqStruct *, Fragrecord::FragState) const;
2697 bool check_fire_suma(const KeyReqStruct *,
2698 const Operationrec*,
2699 const Fragrecord*) const;
2700
2701 bool readTriggerInfo(TupTriggerData* trigPtr,
2702 Operationrec* regOperPtr,
2703 KeyReqStruct * req_struct,
2704 Fragrecord* regFragPtr,
2705 Uint32* keyBuffer,
2706 Uint32& noPrimKey,
2707 Uint32* afterBuffer,
2708 Uint32& noAfterWords,
2709 Uint32* beforeBuffer,
2710 Uint32& noBeforeWords,
2711 bool disk);
2712
2713 void sendTrigAttrInfo(Signal* signal,
2714 Uint32* data,
2715 Uint32 dataLen,
2716 bool executeDirect,
2717 BlockReference receiverReference);
2718
2719 Uint32 setAttrIds(Bitmask<MAXNROFATTRIBUTESINWORDS>& attributeMask,
2720 Uint32 noOfAttributes,
2721 Uint32* inBuffer);
2722
2723 bool primaryKey(Tablerec* const, Uint32);
2724
2725 // these set terrorCode and return non-zero on error
2726
2727 int executeTuxInsertTriggers(Signal* signal,
2728 Operationrec* regOperPtr,
2729 Fragrecord* regFragPtr,
2730 Tablerec* regTabPtr);
2731
2732 int executeTuxUpdateTriggers(Signal* signal,
2733 Operationrec* regOperPtr,
2734 Fragrecord* regFragPtr,
2735 Tablerec* regTabPtr);
2736
2737 int executeTuxDeleteTriggers(Signal* signal,
2738 Operationrec* regOperPtr,
2739 Fragrecord* regFragPtr,
2740 Tablerec* regTabPtr);
2741
2742 int addTuxEntries(Signal* signal,
2743 Operationrec* regOperPtr,
2744 Tablerec* regTabPtr);
2745
2746 // these crash the node on error
2747
2748 void executeTuxCommitTriggers(Signal* signal,
2749 Operationrec* regOperPtr,
2750 Fragrecord* regFragPtr,
2751 Tablerec* regTabPtr);
2752
2753 void executeTuxAbortTriggers(Signal* signal,
2754 Operationrec* regOperPtr,
2755 Fragrecord* regFragPtr,
2756 Tablerec* regTabPtr);
2757
2758 void removeTuxEntries(Signal* signal,
2759 Tablerec* regTabPtr);
2760
2761 void ndbmtd_buffer_suma_trigger(Signal* signal, Uint32 len,
2762 LinearSectionPtr ptr[]);
2763 void flush_ndbmtd_suma_buffer(Signal*);
2764
2765 struct SumaTriggerBuffer
2766 {
SumaTriggerBufferDbtup::SumaTriggerBuffer2767 SumaTriggerBuffer() { m_out_of_memory = 0;m_pageId = RNIL; m_freeWords = 0;}
2768 Uint32 m_out_of_memory;
2769 Uint32 m_pageId;
2770 Uint32 m_freeWords;
2771 } m_suma_trigger_buffer;
2772
2773 // *****************************************************************
2774 // Error Handling routines.
2775 // *****************************************************************
2776 //------------------------------------------------------------------
2777 //------------------------------------------------------------------
2778 int TUPKEY_abort(KeyReqStruct*, int error_type);
2779
2780 //------------------------------------------------------------------
2781 //------------------------------------------------------------------
2782 void tupkeyErrorLab(KeyReqStruct*);
2783 void do_tup_abortreq(Signal*, Uint32 flags);
2784 void do_tup_abort_operation(Signal*, Tuple_header *,
2785 Operationrec*,
2786 Fragrecord*,
2787 Tablerec*);
2788
2789 //------------------------------------------------------------------
2790 //------------------------------------------------------------------
2791 // Methods to handle execution of TUP_COMMITREQ + TUP_ABORTREQ.
2792 //
2793 // Module Transaction Manager
2794 //
2795 // The Transaction Manager module is responsible for the commit
2796 // and abort of operations started by the Execution Manager.
2797 //
2798 // Commit Operation:
2799 // ----------------
2800 //
2801 // Failures in commit processing is not allowed since that would
2802 // leave the database in an unreliable state. Thus the only way
2803 // to handle failures in commit processing is to crash the node.
2804 //
2805 // TUP_COMMITREQ can only be received in the wait state after a
2806 // successful TUPKEYREQ which was not a read operation.
2807 //
2808 // Commit of Delete:
2809 // -----------------
2810 //
2811 // This will actually perform the deletion of the record unless
2812 // other operations also are connected to the record. In this case
2813 // we will set the delete state on the record that becomes the ownerd
2814 // of the record.
2815 //
2816 // Commit of Update:
2817 // ----------------
2818 //
2819 // We will release the copy record where the original record was kept.
2820 // Also here we will take special care if more operations are updating
2821 // the record simultaneously.
2822 //
2823 // Commit of Insert:
2824 // -----------------
2825 //
2826 // Will simply reset the state of the operation record.
2827 //
2828 // Signal Diagram:
2829 // ---> TUP_COMMITREQ (from LQH)
2830 // <---- TUP_COMMITCONF (to LQH)
2831 //
2832 //
2833 // Abort Operation:
2834 // ----------------
2835 //
2836 // Signal Diagram:
2837 // ---> TUP_ABORTREQ (from LQH)
2838 // <---- TUP_ABORTCONF (to LQH)
2839 //
2840 // Failures in abort processing is not allowed since that would
2841 // leave the database in an unreliable state. Thus the only way
2842 // to handle failures in abort processing is to crash the node.
2843 //
2844 // Abort messages can arrive at any time. It can arrive even before
2845 // anything at all have arrived of the operation. It can arrive after
2846 // receiving a number of ATTRINFO but before TUPKEYREQ has been received.
2847 // It must arrive after that we sent TUPKEYREF in response to TUPKEYREQ
2848 // and finally it can arrive after successfully performing the TUPKEYREQ
2849 // in all cases including the read case.
2850 //------------------------------------------------------------------
2851 //------------------------------------------------------------------
2852
2853 #if 0
2854 void checkPages(Fragrecord* regFragPtr);
2855 #endif
convert_byte_to_word_size(Uint32 byte_size)2856 Uint32 convert_byte_to_word_size(Uint32 byte_size)
2857 {
2858 return ((byte_size + 3) >> 2);
2859 }
convert_bit_to_word_size(Uint32 bit_size)2860 Uint32 convert_bit_to_word_size(Uint32 bit_size)
2861 {
2862 return ((bit_size + 31) >> 5);
2863 }
2864
2865 void prepare_initial_insert(KeyReqStruct*, Operationrec*, Tablerec*);
2866 void fix_disk_insert_no_mem_insert(KeyReqStruct*, Operationrec*, Tablerec*);
2867 void setup_fixed_tuple_ref_opt(KeyReqStruct* req_struct);
2868 void setup_fixed_tuple_ref(KeyReqStruct* req_struct,
2869 Operationrec* regOperPtr,
2870 Tablerec* regTabPtr);
2871 void setup_fixed_part(KeyReqStruct* req_struct,
2872 Operationrec* regOperPtr,
2873 Tablerec* regTabPtr);
2874
2875 void send_TUPKEYREF(const KeyReqStruct* req_struct);
2876 void early_tupkey_error(KeyReqStruct*);
2877
2878 void printoutTuplePage(Uint32 fragid, Uint32 pageid, Uint32 printLimit);
2879
2880 bool checkUpdateOfPrimaryKey(KeyReqStruct *req_struct,
2881 Uint32* updateBuffer,
2882 Tablerec* regTabPtr);
2883
2884 void setNullBits(Uint32*, Tablerec* regTabPtr);
2885 bool checkNullAttributes(KeyReqStruct * const, Tablerec* const);
2886 bool find_savepoint(OperationrecPtr& loopOpPtr, Uint32 savepointId);
2887 bool setup_read(KeyReqStruct* req_struct,
2888 Operationrec* regOperPtr,
2889 Fragrecord* regFragPtr,
2890 Tablerec* regTabPtr,
2891 bool disk);
2892
2893 Uint32 calculateChecksum(Tuple_header*, const Tablerec* regTabPtr);
2894 void setChecksum(Tuple_header*, const Tablerec* regTabPtr);
2895 void setInvalidChecksum(Tuple_header*, const Tablerec* regTabPtr);
2896 void updateChecksum(Tuple_header *,
2897 const Tablerec *,
2898 Uint32 old_header,
2899 Uint32 new_header);
2900 int corruptedTupleDetected(KeyReqStruct*, Tablerec*);
2901
2902 void complexTrigger(Signal* signal,
2903 KeyReqStruct *req_struct,
2904 Operationrec* regOperPtr,
2905 Fragrecord* regFragPtr,
2906 Tablerec* regTabPtr);
2907
2908 void setTupleStatesSetOpType(Operationrec* regOperPtr,
2909 KeyReqStruct *req_struct,
2910 Page* pagePtr,
2911 Uint32& opType,
2912 OperationrecPtr& firstOpPtr);
2913
2914 void findBeforeValueOperation(OperationrecPtr& befOpPtr,
2915 OperationrecPtr firstOpPtr);
2916
2917 void updateGcpId(KeyReqStruct *req_struct,
2918 Operationrec* regOperPtr,
2919 Fragrecord* regFragPtr,
2920 Tablerec* regTabPtr);
2921
2922 void setTupleStateOnPreviousOps(Uint32 prevOpIndex);
2923 void copyMem(Signal* signal, Uint32 sourceIndex, Uint32 destIndex);
2924
2925 void removeActiveOpList(Operationrec* const regOperPtr, Tuple_header*);
2926
2927 void updatePackedList(Signal* signal, Uint16 ahostIndex);
2928
2929 void setUpDescriptorReferences(Uint32 descriptorReference,
2930 Tablerec* regTabPtr,
2931 const Uint32* offset);
2932 void setupDynDescriptorReferences(Uint32 dynDescr,
2933 Tablerec* const regTabPtr,
2934 const Uint32* offset,
2935 Uint32 ind=0);
2936 void setUpKeyArray(Tablerec* regTabPtr);
2937 bool addfragtotab(Tablerec* regTabPtr, Uint32 fragId, Uint32 fragIndex);
2938 void deleteFragTab(Tablerec* regTabPtr, Uint32 fragId);
2939 void abortAddFragOp(Signal* signal);
2940 void releaseTabDescr(Tablerec* regTabPtr);
2941 void getFragmentrec(FragrecordPtr& regFragPtr, Uint32 fragId, Tablerec* regTabPtr);
2942
2943 void initialiseRecordsLab(Signal* signal, Uint32 switchData, Uint32, Uint32);
2944 void initializeCheckpointInfoRec();
2945 void initializeDiskBufferSegmentRecord();
2946 void initializeFragoperrec();
2947 void initializeFragrecord();
2948 void initializeAlterTabOperation();
2949 void initializeHostBuffer();
2950 void initializeLocalLogInfo();
2951 void initializeOperationrec();
2952 void initializePendingFileOpenInfoRecord();
2953 void initializeRestartInfoRec();
2954 void initializeTablerec();
2955 void initializeTabDescr();
2956 void initializeUndoPage();
2957 void initializeDefaultValuesFrag();
2958
2959 void initTab(Tablerec* regTabPtr);
2960
2961 void fragrefuseLab(Signal* signal, FragoperrecPtr fragOperPtr);
2962 void fragrefuse1Lab(Signal* signal, FragoperrecPtr fragOperPtr);
2963 void fragrefuse2Lab(Signal* signal, FragoperrecPtr fragOperPtr, FragrecordPtr regFragPtr);
2964 void fragrefuse3Lab(Signal* signal,
2965 FragoperrecPtr fragOperPtr,
2966 FragrecordPtr regFragPtr,
2967 Tablerec* regTabPtr,
2968 Uint32 fragId);
2969 void fragrefuse4Lab(Signal* signal,
2970 FragoperrecPtr fragOperPtr,
2971 FragrecordPtr regFragPtr,
2972 Tablerec* regTabPtr,
2973 Uint32 fragId);
2974 void addattrrefuseLab(Signal* signal,
2975 FragrecordPtr regFragPtr,
2976 FragoperrecPtr fragOperPtr,
2977 Tablerec* regTabPtr,
2978 Uint32 fragId);
2979
2980 void releaseFragment(Signal*, Uint32, Uint32);
2981 void drop_fragment_free_var_pages(Signal*);
2982 void drop_fragment_free_pages(Signal*);
2983 void drop_fragment_free_extent(Signal*, TablerecPtr, FragrecordPtr, Uint32);
2984 void drop_fragment_free_extent_log_buffer_callback(Signal*, Uint32, Uint32);
2985 void drop_fragment_unmap_pages(Signal*, TablerecPtr, FragrecordPtr, Uint32);
2986 void drop_fragment_unmap_page_callback(Signal* signal, Uint32, Uint32);
2987 void drop_fragment_fsremove(Signal*, TablerecPtr, FragrecordPtr);
2988 void drop_fragment_fsremove_done(Signal*, TablerecPtr, FragrecordPtr);
2989
2990 // Initialisation
2991 void initData();
2992 void initRecords();
2993
2994 // 2 words for optional GCI64 + AUTHOR info
2995 #define EXTRA_COPY_PROC_WORDS 2
2996 #define MAX_COPY_PROC_LEN (MAX_ATTRIBUTES_IN_TABLE + EXTRA_COPY_PROC_WORDS)
2997
2998
2999 void deleteScanProcedure(Signal* signal, Operationrec* regOperPtr);
3000 void allocCopyProcedure();
3001 void freeCopyProcedure();
3002 void prepareCopyProcedure(Uint32 numAttrs, Uint16 tableBits);
3003 void releaseCopyProcedure();
3004 void copyProcedure(Signal* signal,
3005 TablerecPtr regTabPtr,
3006 Operationrec* regOperPtr);
3007 void scanProcedure(Signal* signal,
3008 Operationrec* regOperPtr,
3009 SectionHandle* handle,
3010 bool isCopy);
3011 void storedProcBufferSeizeErrorLab(Signal* signal,
3012 Operationrec* regOperPtr,
3013 Uint32 storedProcPtr,
3014 Uint32 errorCode);
3015
3016 //-----------------------------------------------------------------------------
3017 // Table Descriptor Memory Manager
3018 //-----------------------------------------------------------------------------
3019
3020 // Public methods
3021 Uint32 getTabDescrOffsets(Uint32, Uint32, Uint32, Uint32, Uint32*);
3022 Uint32 getDynTabDescrOffsets(Uint32 MaskSize, Uint32* offset);
3023 Uint32 allocTabDescr(Uint32 allocSize);
3024 void releaseTabDescr(Uint32 desc);
3025
3026 void freeTabDescr(Uint32 retRef, Uint32 retNo, bool normal = true);
3027 Uint32 getTabDescrWord(Uint32 index);
3028 void setTabDescrWord(Uint32 index, Uint32 word);
3029
3030 // Private methods
3031 Uint32 sizeOfReadFunction();
3032 void removeTdArea(Uint32 tabDesRef, Uint32 list);
3033 void insertTdArea(Uint32 tabDesRef, Uint32 list);
3034 void itdaMergeTabDescr(Uint32& retRef, Uint32& retNo, bool normal);
3035 #if defined VM_TRACE || defined ERROR_INSERT
3036 void verifytabdes();
3037 #endif
3038
3039 void seizeOpRec(OperationrecPtr& regOperPtr);
3040 void seizeFragrecord(FragrecordPtr& regFragPtr);
3041 void seizeFragoperrec(FragoperrecPtr& fragOperPtr);
3042 void seizeAlterTabOperation(AlterTabOperationPtr& alterTabOpPtr);
3043 void releaseFragoperrec(FragoperrecPtr fragOperPtr);
3044 void releaseFragrec(FragrecordPtr);
3045 void releaseAlterTabOpRec(AlterTabOperationPtr regAlterTabOpPtr);
3046
3047 //----------------------------------------------------------------------------
3048 // Page Memory Manager
3049 //----------------------------------------------------------------------------
3050
3051 // Public methods
3052 void allocConsPages(EmulatedJamBuffer* jamBuf,
3053 Uint32 noOfPagesToAllocate,
3054 Uint32& noOfPagesAllocated,
3055 Uint32& allocPageRef);
3056 void returnCommonArea(Uint32 retPageRef, Uint32 retNo);
3057 void initializePage();
3058
3059 Uint32 nextHigherTwoLog(Uint32 input);
3060
3061 Uint32 m_pages_allocated;
3062 Uint32 m_pages_allocated_max;
3063
3064 //------------------------------------------------------------------------------------------------------
3065 // Page Mapper, convert logical page id's to physical page id's
3066 // The page mapper also handles the pages allocated to the fragment.
3067 //------------------------------------------------------------------------------------------------------
3068 //
3069 // Public methods
3070 Uint32 getRealpid(Fragrecord* regFragPtr, Uint32 logicalPageId);
3071 Uint32 getRealpidCheck(Fragrecord* regFragPtr, Uint32 logicalPageId);
3072 Uint32 getNoOfPages(Fragrecord* regFragPtr);
3073 Uint32 getEmptyPage(Fragrecord* regFragPtr);
3074 Uint32 allocFragPage(EmulatedJamBuffer* jamBuf, Uint32 * err,
3075 Fragrecord* regFragPtr);
3076 Uint32 allocFragPage(Uint32 * err, Tablerec*, Fragrecord*, Uint32 page_no);
3077 void releaseFragPage(Fragrecord* regFragPtr, Uint32 logicalPageId, PagePtr);
3078 void rebuild_page_free_list(Signal*);
3079 Uint32 get_empty_var_page(Fragrecord* frag_ptr);
3080 void init_page(Fragrecord*, PagePtr, Uint32 page_no);
3081
3082 // Private methods
3083 void errorHandler(Uint32 errorCode);
3084
3085 //---------------------------------------------------------------
3086 // Variable Allocator
3087 // Allocates and deallocates tuples of fixed size on a fragment.
3088 //---------------------------------------------------------------
3089 //
3090 // Public methods
3091
3092 void init_list_sizes(void);
3093
3094 // Private methods
3095
3096 Uint32 get_alloc_page(Fragrecord* const, Uint32);
3097 void update_free_page_list(Fragrecord* const, Ptr<Page>);
3098
3099 #if 0
3100 Uint32 calc_free_list(const Tablerec* regTabPtr, Uint32 sz) const {
3101 return regTabPtr->m_disk_alloc_info.calc_page_free_bits(sz);
3102 }
3103 #endif
3104
3105 Uint32 calculate_free_list_impl(Uint32) const ;
3106 Uint64 calculate_used_var_words(Fragrecord* fragPtr);
3107 void remove_free_page(Fragrecord*, Var_page*, Uint32);
3108 void insert_free_page(Fragrecord*, Var_page*, Uint32);
3109
3110 //---------------------------------------------------------------
3111 // Fixed Allocator
3112 // Allocates and deallocates tuples of fixed size on a fragment.
3113 //---------------------------------------------------------------
3114 //
3115 // Public methods
3116 Uint32* alloc_var_rec(Uint32 * err,
3117 Fragrecord*, Tablerec*, Uint32, Local_key*, Uint32*);
3118 void free_var_rec(Fragrecord*, Tablerec*, Local_key*, Ptr<Page>);
3119 void free_var_part(Fragrecord*, Tablerec*, Local_key*);
3120 Uint32* alloc_var_part(Uint32*err,Fragrecord*, Tablerec*, Uint32, Local_key*);
3121 Uint32 *realloc_var_part(Uint32 * err, Fragrecord*, Tablerec*,
3122 PagePtr, Var_part_ref*, Uint32, Uint32);
3123
3124 void move_var_part(Fragrecord* fragPtr, Tablerec* tabPtr, PagePtr pagePtr,
3125 Var_part_ref* refptr, Uint32 size);
3126
3127 void free_var_part(Fragrecord* fragPtr, PagePtr pagePtr, Uint32 page_idx);
3128
3129 void validate_page(Tablerec*, Var_page* page);
3130
3131 Uint32* alloc_fix_rec(EmulatedJamBuffer* jamBuf, Uint32* err,
3132 Fragrecord*const, Tablerec*const, Local_key*,
3133 Uint32*);
3134 void free_fix_rec(Fragrecord*, Tablerec*, Local_key*, Fix_page*);
3135
3136 Uint32* alloc_fix_rowid(Uint32 * err,
3137 Fragrecord*, Tablerec*, Local_key*, Uint32 *);
3138 Uint32* alloc_var_rowid(Uint32 * err,
3139 Fragrecord*, Tablerec*, Uint32, Local_key*, Uint32*);
3140 // Private methods
3141 void convertThPage(Fix_page* regPagePtr,
3142 Tablerec*,
3143 Uint32 mm);
3144
3145 /**
3146 * Return offset
3147 */
3148 Uint32 alloc_tuple_from_page(Fragrecord* regFragPtr,
3149 Fix_page* regPagePtr);
3150
3151 //---------------------------------------------------------------
3152 // Temporary variables used for storing commonly used variables
3153 // in certain modules
3154 //---------------------------------------------------------------
3155
3156 Uint32 c_lcp_scan_op;
3157
3158 // readAttributes and updateAttributes module
3159 //------------------------------------------------------------------------------------------------------
3160 // Common stored variables. Variables that have a valid value always.
3161 //------------------------------------------------------------------------------------------------------
3162 Fragoperrec *fragoperrec;
3163 Uint32 cfirstfreeFragopr;
3164 Uint32 cnoOfFragoprec;
3165 RSS_OP_COUNTER(cnoOfFreeFragoprec);
3166 RSS_OP_SNAPSHOT(cnoOfFreeFragoprec);
3167
3168 Fragrecord *fragrecord;
3169 Uint32 cfirstfreefrag;
3170 Uint32 cnoOfFragrec;
3171 RSS_OP_COUNTER(cnoOfFreeFragrec);
3172 RSS_OP_SNAPSHOT(cnoOfFreeFragrec);
3173 FragrecordPtr prepare_fragptr;
3174
3175 /*
3176 * DefaultValuesFragment is a normal struct Fragrecord.
3177 * It is TUP block-variable.
3178 * There is only ONE DefaultValuesFragment shared
3179 * among all table fragments stored by this TUP block.
3180 */
3181 FragrecordPtr DefaultValuesFragment;
3182 RSS_OP_SNAPSHOT(defaultValueWordsHi);
3183 RSS_OP_SNAPSHOT(defaultValueWordsLo);
3184
3185 AlterTabOperation *alterTabOperRec;
3186 Uint32 cfirstfreeAlterTabOp;
3187 Uint32 cnoOfAlterTabOps;
3188
3189 HostBuffer *hostBuffer;
3190
3191 NdbMutex c_page_map_pool_mutex;
3192 DynArr256Pool c_page_map_pool;
3193 ArrayPool<Operationrec> c_operation_pool;
3194
3195 ArrayPool<Page> c_page_pool;
3196
3197 /* read ahead in pages during disk order scan */
3198 Uint32 m_max_page_read_ahead;
3199
3200 Tablerec *tablerec;
3201 Uint32 cnoOfTablerec;
3202
3203 TableDescriptor *tableDescriptor;
3204 Uint32 cnoOfTabDescrRec;
3205 RSS_OP_COUNTER(cnoOfFreeTabDescrRec);
3206 RSS_OP_SNAPSHOT(cnoOfFreeTabDescrRec);
3207 TablerecPtr prepare_tabptr;
3208
3209 PagePtr prepare_pageptr;
3210 Uint32 *prepare_tuple_ptr;
3211 #ifdef VM_TRACE
3212 Local_key prepare_orig_local_key;
3213 #endif
3214 Uint32 prepare_page_no;
3215
3216 Uint32 cdata[32];
3217 Uint32 cdataPages[16];
3218 Uint32 cpackedListIndex;
3219 Uint32 cpackedList[MAX_NODES];
3220 Uint32 cerrorPackedDelay;
3221 Uint32 cfreeTdList[16];
3222 Uint32 clastBitMask;
3223 Uint32 clblPageCounter;
3224 Uint32 clblPagesPerTick;
3225 Uint32 clblPagesPerTickAfterSr;
3226 BlockReference clqhBlockref;
3227 Uint32 clqhUserpointer;
3228 Uint32 cminusOne;
3229 BlockReference cndbcntrRef;
3230 BlockReference cownref;
3231 Uint32 cownNodeId;
3232 Uint32 czero;
3233 Uint32 cCopyProcedure;
3234 Uint32 cCopyLastSeg;
3235 Uint32 cCopyOverwrite;
3236 Uint32 cCopyOverwriteLen;
3237
3238 // A little bit bigger to cover overwrites in copy algorithms (16384 real size).
3239 #define ZATTR_BUFFER_SIZE 16384
3240 Uint32 clogMemBuffer[ZATTR_BUFFER_SIZE + 16];
3241 Uint32 coutBuffer[ZATTR_BUFFER_SIZE + 16];
3242 Uint32 cinBuffer[ZATTR_BUFFER_SIZE + 16];
3243 Uint32 ctemp_page[ZWORDS_ON_PAGE];
3244 Uint32 ctemp_var_record[ZWORDS_ON_PAGE];
3245
3246 // Trigger variables
3247 Uint32 c_maxTriggersPerTable;
3248 Uint32 m_minFreePages;
3249 Uint32 m_max_parallel_index_build;
3250
3251 Uint32 c_errorInsert4000TableId;
3252 Uint32 c_min_list_size[MAX_FREE_LIST + 1];
3253 Uint32 c_max_list_size[MAX_FREE_LIST + 1];
3254
3255 void initGlobalTemporaryVars();
3256 void reportMemoryUsage(Signal* signal, int incDec);
3257
3258
3259 #ifdef VM_TRACE
3260 struct Th {
3261 Uint32 data[1];
3262 };
3263 friend class NdbOut& operator<<(NdbOut&, const Operationrec&);
3264 friend class NdbOut& operator<<(NdbOut&, const Th&);
3265 #endif
3266
3267 void expand_tuple(KeyReqStruct*, Uint32 sizes[4], Tuple_header*org,
3268 const Tablerec*, bool disk);
3269 void shrink_tuple(KeyReqStruct*, Uint32 sizes[2], const Tablerec*,
3270 bool disk);
3271
3272 Uint32* get_ptr(Var_part_ref);
3273 Uint32* get_ptr(PagePtr*, Var_part_ref);
3274 Uint32* get_ptr(PagePtr*, const Local_key*, const Tablerec*);
3275 Uint32* get_dd_ptr(PagePtr*, const Local_key*, const Tablerec*);
3276 Uint32* get_default_ptr(const Tablerec*, Uint32&);
3277 Uint32 get_len(Ptr<Page>* pagePtr, Var_part_ref ref);
3278
3279 STATIC_CONST( COPY_TUPLE_HEADER32 = 4 );
3280
alloc_copy_tuple(const Tablerec * tabPtrP,Local_key * ptr)3281 Tuple_header* alloc_copy_tuple(const Tablerec* tabPtrP, Local_key* ptr){
3282 Uint32 * dst = c_undo_buffer.alloc_copy_tuple(ptr,
3283 tabPtrP->total_rec_size);
3284 if (unlikely(dst == 0))
3285 return 0;
3286 #ifdef HAVE_VALGRIND
3287 bzero(dst, tabPtrP->total_rec_size);
3288 #endif
3289 Uint32 count = tabPtrP->m_no_of_attributes;
3290 ChangeMask * mask = (ChangeMask*)(dst + COPY_TUPLE_HEADER32);
3291 mask->m_cols = count;
3292 return (Tuple_header*)(mask->end_of_mask(count));
3293 }
3294
get_copy_tuple_raw(const Local_key * ptr)3295 Uint32 * get_copy_tuple_raw(const Local_key* ptr) {
3296 return c_undo_buffer.get_ptr(ptr);
3297 }
3298
get_copy_tuple(Uint32 * rawptr)3299 Tuple_header * get_copy_tuple(Uint32 * rawptr) {
3300 return (Tuple_header*)
3301 (get_change_mask_ptr(rawptr)->end_of_mask());
3302 }
3303
get_change_mask_ptr(Uint32 * rawptr)3304 ChangeMask * get_change_mask_ptr(Uint32 * rawptr) {
3305 return (ChangeMask*)(rawptr + COPY_TUPLE_HEADER32);
3306 }
3307
get_copy_tuple(const Local_key * ptr)3308 Tuple_header* get_copy_tuple(const Local_key* ptr){
3309 return get_copy_tuple(get_copy_tuple_raw(ptr));
3310 }
3311
get_change_mask_ptr(const Tablerec * tabP,Tuple_header * copytuple)3312 ChangeMask* get_change_mask_ptr(const Tablerec* tabP,Tuple_header* copytuple){
3313 Uint32 * raw = (Uint32*)copytuple;
3314 Uint32 * tmp = raw - (1 + ((tabP->m_no_of_attributes + 31) >> 5));
3315 ChangeMask* mask = (ChangeMask*)tmp;
3316 assert(mask->end_of_mask() == raw);
3317 assert(get_copy_tuple(tmp - COPY_TUPLE_HEADER32) == copytuple);
3318 return mask;
3319 }
3320
3321 /**
3322 * prealloc space from disk
3323 * key.m_file_no contains file no
3324 * key.m_page_no contains disk page
3325 * key.m_page_idx contains byte preallocated
3326 */
3327 int disk_page_prealloc(Signal*, Ptr<Fragrecord>, Local_key*, Uint32);
3328 void disk_page_prealloc_dirty_page(Disk_alloc_info&,
3329 Ptr<Page>, Uint32, Uint32);
3330 void disk_page_prealloc_transit_page(Disk_alloc_info&,
3331 Ptr<Page_request>, Uint32, Uint32);
3332
3333 void disk_page_abort_prealloc(Signal*, Fragrecord*,Local_key*, Uint32);
3334 void disk_page_abort_prealloc_callback(Signal*, Uint32, Uint32);
3335 void disk_page_abort_prealloc_callback_1(Signal*, Fragrecord*,
3336 PagePtr, Uint32);
3337
3338 void disk_page_prealloc_callback(Signal*, Uint32, Uint32);
3339 void disk_page_prealloc_initial_callback(Signal*, Uint32, Uint32);
3340 void disk_page_prealloc_callback_common(Signal*,
3341 Ptr<Page_request>,
3342 Ptr<Fragrecord>,
3343 Ptr<Page>);
3344
3345 void disk_page_alloc(Signal*,
3346 Tablerec*, Fragrecord*, Local_key*, PagePtr, Uint32);
3347 void disk_page_free(Signal*,
3348 Tablerec*, Fragrecord*, Local_key*, PagePtr, Uint32);
3349
3350 void disk_page_commit_callback(Signal*, Uint32 opPtrI, Uint32 page_id);
3351
3352 void disk_page_log_buffer_callback(Signal*, Uint32 opPtrI, Uint32);
3353
3354 void disk_page_alloc_extent_log_buffer_callback(Signal*, Uint32, Uint32);
3355 void disk_page_free_extent_log_buffer_callback(Signal*, Uint32, Uint32);
3356
3357 Uint64 disk_page_undo_alloc(Page*, const Local_key*,
3358 Uint32 sz, Uint32 gci, Uint32 logfile_group_id);
3359
3360 Uint64 disk_page_undo_update(Page*, const Local_key*,
3361 const Uint32*, Uint32,
3362 Uint32 gci, Uint32 logfile_group_id);
3363
3364 Uint64 disk_page_undo_free(Page*, const Local_key*,
3365 const Uint32*, Uint32 sz,
3366 Uint32 gci, Uint32 logfile_group_id);
3367
3368 void undo_createtable_callback(Signal* signal, Uint32 opPtrI, Uint32 unused);
3369 void undo_createtable_logsync_callback(Signal* signal, Uint32, Uint32);
3370
3371 void drop_table_log_buffer_callback(Signal*, Uint32, Uint32);
3372 void drop_table_logsync_callback(Signal*, Uint32, Uint32);
3373
3374 void disk_page_set_dirty(Ptr<Page>);
3375 void restart_setup_page(Disk_alloc_info&, Ptr<Page>, Int32 estimate);
3376 void update_extent_pos(EmulatedJamBuffer* jamBuf, Disk_alloc_info&,
3377 Ptr<Extent_info>, Int32 delta);
3378
3379 void disk_page_move_page_request(Disk_alloc_info& alloc,
3380 Ptr<Extent_info>,
3381 Ptr<Page_request> req,
3382 Uint32 old_idx, Uint32 new_idx);
3383
3384 void disk_page_move_dirty_page(Disk_alloc_info& alloc,
3385 Ptr<Extent_info> extentPtr,
3386 Ptr<Page> pagePtr,
3387 Uint32 old_idx, Uint32 new_idx);
3388
3389 void disk_page_get_allocated(const Tablerec*, const Fragrecord*,
3390 Uint64 res[2]);
3391 /**
3392 * Disk restart code
3393 */
3394 public:
3395 int disk_page_load_hook(Uint32 page_id);
3396
3397 void disk_page_unmap_callback(Uint32 when, Uint32 page, Uint32 dirty_count);
3398
3399 int disk_restart_alloc_extent(EmulatedJamBuffer* jamBuf,
3400 Uint32 tableId, Uint32 fragId,
3401 const Local_key* key, Uint32 pages);
3402 void disk_restart_page_bits(EmulatedJamBuffer* jamBuf,
3403 Uint32 tableId, Uint32 fragId,
3404 const Local_key*, Uint32 bits);
3405 void disk_restart_undo(Signal* signal, Uint64 lsn,
3406 Uint32 type, const Uint32 * ptr, Uint32 len);
3407
3408 struct Apply_undo
3409 {
3410 Uint32 m_type, m_len;
3411 const Uint32* m_ptr;
3412 Uint64 m_lsn;
3413 Ptr<Tablerec> m_table_ptr;
3414 Ptr<Fragrecord> m_fragment_ptr;
3415 Ptr<Page> m_page_ptr;
3416 Ptr<Extent_info> m_extent_ptr;
3417 Local_key m_key;
3418 Apply_undo();
3419 };
3420
3421 void disk_restart_lcp_id(Uint32 table, Uint32 frag, Uint32 lcpId);
3422
3423 private:
3424 // these 2 were file-static before mt-lqh
3425 bool f_undo_done;
3426 Dbtup::Apply_undo f_undo;
3427 Uint32 c_proxy_undo_data[20 + MAX_TUPLE_SIZE_IN_WORDS];
3428
3429 void disk_restart_undo_next(Signal*, Uint32 applied = 0);
3430 void disk_restart_undo_lcp(Uint32, Uint32, Uint32 flag, Uint32 lcpId);
3431 void disk_restart_undo_callback(Signal* signal, Uint32, Uint32);
3432 void disk_restart_undo_alloc(Apply_undo*);
3433 void disk_restart_undo_update(Apply_undo*);
3434 void disk_restart_undo_free(Apply_undo*);
3435 void disk_restart_undo_page_bits(Signal*, Apply_undo*);
3436
3437 #ifdef VM_TRACE
3438 void verify_page_lists(Disk_alloc_info&);
3439 #else
verify_page_lists(Disk_alloc_info &)3440 void verify_page_lists(Disk_alloc_info&) {}
3441 #endif
3442
3443 void findFirstOp(OperationrecPtr&);
3444 bool is_rowid_in_remaining_lcp_set(const Page* page,
3445 const Local_key& key1,
3446 const Dbtup::ScanOp& op) const;
3447 void commit_operation(Signal*,
3448 Uint32,
3449 Uint32,
3450 Tuple_header*,
3451 PagePtr,
3452 Operationrec*,
3453 Fragrecord*,
3454 Tablerec*,
3455 Ptr<GlobalPage> diskPagePtr);
3456
3457 void commit_refresh(Signal*,
3458 Uint32,
3459 Uint32,
3460 Tuple_header*,
3461 PagePtr,
3462 KeyReqStruct*,
3463 Operationrec*,
3464 Fragrecord*,
3465 Tablerec*,
3466 Ptr<GlobalPage> diskPagePtr);
3467
3468 int retrieve_data_page(Signal*,
3469 Page_cache_client::Request,
3470 OperationrecPtr,
3471 Ptr<GlobalPage> &diskPagePtr);
3472 int retrieve_log_page(Signal*, FragrecordPtr, OperationrecPtr);
3473
3474 void dealloc_tuple(Signal* signal,
3475 Uint32,
3476 Uint32,
3477 Page*,
3478 Tuple_header*,
3479 KeyReqStruct*,
3480 Operationrec*,
3481 Fragrecord*,
3482 Tablerec*,
3483 Ptr<GlobalPage> diskPagePtr);
3484
3485 bool store_extra_row_bits(Uint32, const Tablerec*, Tuple_header*, Uint32,
3486 bool);
3487 void read_extra_row_bits(Uint32, const Tablerec*, Tuple_header*, Uint32 *,
3488 bool);
3489
3490 int handle_size_change_after_update(KeyReqStruct* req_struct,
3491 Tuple_header* org,
3492 Operationrec*,
3493 Fragrecord* regFragPtr,
3494 Tablerec* regTabPtr,
3495 Uint32 sizes[4]);
3496 int optimize_var_part(KeyReqStruct* req_struct,
3497 Tuple_header* org,
3498 Operationrec* regOperPtr,
3499 Fragrecord* regFragPtr,
3500 Tablerec* regTabPtr);
3501
3502 /**
3503 * Setup all pointer on keyreqstruct to prepare for read
3504 * req_struct->m_tuple_ptr is set to tuple to read
3505 */
3506 void prepare_read(KeyReqStruct*, Tablerec* const, bool disk);
3507
3508 /* For debugging, dump the contents of a tuple. */
3509 void dump_tuple(const KeyReqStruct* req_struct, const Tablerec* tabPtrP);
3510
3511 #ifdef VM_TRACE
3512 void check_page_map(Fragrecord*);
3513 bool find_page_id_in_list(Fragrecord*, Uint32 pid);
3514 #endif
3515 void handle_lcp_keep(Signal*, FragrecordPtr, ScanOp*);
3516 void handle_lcp_keep_commit(const Local_key*,
3517 KeyReqStruct *,
3518 Operationrec*, Fragrecord*, Tablerec*);
3519
3520 void setup_lcp_read_copy_tuple( KeyReqStruct *,
3521 Operationrec*,
3522 Fragrecord*,
3523 Tablerec*);
3524
isCopyTuple(Uint32 pageid,Uint32 pageidx) const3525 bool isCopyTuple(Uint32 pageid, Uint32 pageidx) const {
3526 return (pageidx & (Uint16(1) << 15)) != 0;
3527 }
3528
setCopyTuple(Uint32 & pageid,Uint16 & pageidx) const3529 void setCopyTuple(Uint32& pageid, Uint16& pageidx) const {
3530 assert(!isCopyTuple(pageid, pageidx));
3531 pageidx |= (Uint16(1) << 15);
3532 assert(isCopyTuple(pageid, pageidx));
3533 }
3534
clearCopyTuple(Uint32 & pageid,Uint16 & pageidx) const3535 void clearCopyTuple(Uint32& pageid, Uint16& pageidx) const {
3536 assert(isCopyTuple(pageid, pageidx));
3537 pageidx &= ~(Uint16(1) << 15);
3538 assert(!isCopyTuple(pageid, pageidx));
3539 }
3540 };
3541
3542 #if 0
3543 inline
3544 Uint32
3545 Dbtup::get_frag_page_id(Uint32 real_page_id)
3546 {
3547 PagePtr real_page_ptr;
3548 real_page_ptr.i= real_page_id;
3549 ptrCheckGuard(real_page_ptr, cnoOfPage, cpage);
3550 return real_page_ptr.p->frag_page_id;
3551 }
3552 #endif
3553
3554 inline
3555 void
setup_fixed_tuple_ref_opt(KeyReqStruct * req_struct)3556 Dbtup::setup_fixed_tuple_ref_opt(KeyReqStruct* req_struct)
3557 {
3558 req_struct->m_page_ptr = prepare_pageptr;
3559 req_struct->m_tuple_ptr = (Tuple_header*)prepare_tuple_ptr;
3560 }
3561
3562 inline
3563 void
setup_fixed_tuple_ref(KeyReqStruct * req_struct,Operationrec * regOperPtr,Tablerec * regTabPtr)3564 Dbtup::setup_fixed_tuple_ref(KeyReqStruct* req_struct,
3565 Operationrec* regOperPtr,
3566 Tablerec* regTabPtr)
3567 {
3568 PagePtr page_ptr;
3569 Uint32* ptr= get_ptr(&page_ptr, ®OperPtr->m_tuple_location, regTabPtr);
3570 req_struct->m_page_ptr = page_ptr;
3571 req_struct->m_tuple_ptr = (Tuple_header*)ptr;
3572 }
3573
3574 inline
3575 Dbtup::TransState
get_trans_state(Operationrec * regOperPtr)3576 Dbtup::get_trans_state(Operationrec * regOperPtr)
3577 {
3578 return (Dbtup::TransState)regOperPtr->trans_state;
3579 }
3580
3581 inline
3582 void
set_trans_state(Operationrec * regOperPtr,Dbtup::TransState trans_state)3583 Dbtup::set_trans_state(Operationrec* regOperPtr,
3584 Dbtup::TransState trans_state)
3585 {
3586 regOperPtr->trans_state= (Uint32)trans_state;
3587 }
3588
3589 inline
3590 Dbtup::TupleState
get_tuple_state(Operationrec * regOperPtr)3591 Dbtup::get_tuple_state(Operationrec * regOperPtr)
3592 {
3593 return (Dbtup::TupleState)regOperPtr->tuple_state;
3594 }
3595
3596 inline
3597 void
set_tuple_state(Operationrec * regOperPtr,Dbtup::TupleState tuple_state)3598 Dbtup::set_tuple_state(Operationrec* regOperPtr,
3599 Dbtup::TupleState tuple_state)
3600 {
3601 regOperPtr->tuple_state= (Uint32)tuple_state;
3602 }
3603
3604
3605 inline
3606 Uint32
decr_tup_version(Uint32 tup_version)3607 Dbtup::decr_tup_version(Uint32 tup_version)
3608 {
3609 return (tup_version - 1) & ZTUP_VERSION_MASK;
3610 }
3611
3612 inline
3613 Uint32*
get_ptr(Var_part_ref ref)3614 Dbtup::get_ptr(Var_part_ref ref)
3615 {
3616 Ptr<Page> tmp;
3617 return get_ptr(&tmp, ref);
3618 }
3619
3620 inline
3621 Uint32*
get_ptr(Ptr<Page> * pagePtr,Var_part_ref ref)3622 Dbtup::get_ptr(Ptr<Page>* pagePtr, Var_part_ref ref)
3623 {
3624 PagePtr tmp;
3625 Local_key key;
3626 ref.copyout(&key);
3627 tmp.i = key.m_page_no;
3628
3629 c_page_pool.getPtr(tmp);
3630 memcpy(pagePtr, &tmp, sizeof(tmp));
3631 return ((Var_page*)tmp.p)->get_ptr(key.m_page_idx);
3632 }
3633
3634 inline
3635 Uint32*
get_ptr(PagePtr * pagePtr,const Local_key * key,const Tablerec * regTabPtr)3636 Dbtup::get_ptr(PagePtr* pagePtr,
3637 const Local_key* key, const Tablerec* regTabPtr)
3638 {
3639 PagePtr tmp;
3640 tmp.i= key->m_page_no;
3641 c_page_pool.getPtr(tmp);
3642 memcpy(pagePtr, &tmp, sizeof(tmp));
3643
3644 return ((Fix_page*)tmp.p)->
3645 get_ptr(key->m_page_idx, regTabPtr->m_offsets[MM].m_fix_header_size);
3646 }
3647
3648 inline
3649 Uint32*
get_default_ptr(const Tablerec * regTabPtr,Uint32 & default_len)3650 Dbtup::get_default_ptr(const Tablerec* regTabPtr, Uint32& default_len)
3651 {
3652 Var_part_ref ref;
3653 ref.assign(®TabPtr->m_default_value_location);
3654 Ptr<Page> page;
3655
3656 Uint32* default_data = get_ptr(&page, ref);
3657 default_len = get_len(&page, ref);
3658
3659 return default_data;
3660 }
3661
3662 inline
3663 Uint32*
get_dd_ptr(PagePtr * pagePtr,const Local_key * key,const Tablerec * regTabPtr)3664 Dbtup::get_dd_ptr(PagePtr* pagePtr,
3665 const Local_key* key, const Tablerec* regTabPtr)
3666 {
3667 PagePtr tmp;
3668 tmp.i= key->m_page_no;
3669 tmp.p= (Page*)m_global_page_pool.getPtr(tmp.i);
3670 memcpy(pagePtr, &tmp, sizeof(tmp));
3671
3672 if(regTabPtr->m_attributes[DD].m_no_of_varsize ||
3673 regTabPtr->m_attributes[DD].m_no_of_dynamic)
3674 return ((Var_page*)tmp.p)->get_ptr(key->m_page_idx);
3675 else
3676 return ((Fix_page*)tmp.p)->
3677 get_ptr(key->m_page_idx, regTabPtr->m_offsets[DD].m_fix_header_size);
3678 }
3679
3680 /*
3681 This function assumes that get_ptr() has been called first to
3682 initialise the pagePtr argument.
3683 */
3684 inline
3685 Uint32
get_len(Ptr<Page> * pagePtr,Var_part_ref ref)3686 Dbtup::get_len(Ptr<Page>* pagePtr, Var_part_ref ref)
3687 {
3688 Uint32 page_idx= ref.m_page_idx;
3689 return ((Var_page*)pagePtr->p)->get_entry_len(page_idx);
3690 }
3691
3692 NdbOut&
3693 operator<<(NdbOut&, const Dbtup::Tablerec&);
3694
3695 inline
find_savepoint(OperationrecPtr & loopOpPtr,Uint32 savepointId)3696 bool Dbtup::find_savepoint(OperationrecPtr& loopOpPtr, Uint32 savepointId)
3697 {
3698 while (true) {
3699 if (savepointId > loopOpPtr.p->savepointId) {
3700 jam();
3701 return true;
3702 }
3703 loopOpPtr.i = loopOpPtr.p->prevActiveOp;
3704 if (loopOpPtr.i == RNIL) {
3705 break;
3706 }
3707 c_operation_pool.getPtr(loopOpPtr);
3708 }
3709 return false;
3710 }
3711
3712 inline
3713 void
update_change_mask_info(const Tablerec * tablePtrP,ChangeMask * dst,const Uint32 * src)3714 Dbtup::update_change_mask_info(const Tablerec* tablePtrP,
3715 ChangeMask* dst,
3716 const Uint32 * src)
3717 {
3718 assert(dst->m_cols == tablePtrP->m_no_of_attributes);
3719 Uint32 * ptr = dst->m_mask;
3720 Uint32 len = (tablePtrP->m_no_of_attributes + 31) >> 5;
3721 for (Uint32 i = 0; i<len; i++)
3722 {
3723 * ptr |= *src;
3724 ptr++;
3725 src++;
3726 }
3727 }
3728
3729 inline
3730 void
set_change_mask_info(const Tablerec * tablePtrP,ChangeMask * dst)3731 Dbtup::set_change_mask_info(const Tablerec* tablePtrP, ChangeMask* dst)
3732 {
3733 assert(dst->m_cols == tablePtrP->m_no_of_attributes);
3734 Uint32 len = (tablePtrP->m_no_of_attributes + 31) >> 5;
3735 BitmaskImpl::set(len, dst->m_mask);
3736 }
3737
3738 inline
3739 void
clear_change_mask_info(const Tablerec * tablePtrP,ChangeMask * dst)3740 Dbtup::clear_change_mask_info(const Tablerec* tablePtrP, ChangeMask* dst)
3741 {
3742 assert(dst->m_cols == tablePtrP->m_no_of_attributes);
3743 Uint32 len = (tablePtrP->m_no_of_attributes + 31) >> 5;
3744 BitmaskImpl::clear(len, dst->m_mask);
3745 }
3746
3747 inline
3748 void
copy_change_mask_info(const Tablerec * tablePtrP,ChangeMask * dst,const ChangeMask * src)3749 Dbtup::copy_change_mask_info(const Tablerec* tablePtrP,
3750 ChangeMask* dst, const ChangeMask* src)
3751 {
3752 Uint32 dst_cols = tablePtrP->m_no_of_attributes;
3753 assert(dst->m_cols == dst_cols);
3754 Uint32 src_cols = src->m_cols;
3755
3756 if (dst_cols == src_cols)
3757 {
3758 memcpy(dst->m_mask, src->m_mask, 4 * ((dst_cols + 31) >> 5));
3759 }
3760 else
3761 {
3762 ndbassert(dst_cols > src_cols); // drop column not supported
3763 memcpy(dst->m_mask, src->m_mask, 4 * ((src_cols + 31) >> 5));
3764 BitmaskImpl::setRange((dst_cols + 31) >> 5, dst->m_mask,
3765 src_cols, (dst_cols - src_cols));
3766 }
3767 }
3768
3769 // Dbtup_client provides proxying similar to Page_cache_client
3770
3771 class Dbtup_client
3772 {
3773 friend class DbtupProxy;
3774 // jam buffer of caller block.
3775 EmulatedJamBuffer* const m_jamBuf;
3776 class DbtupProxy* m_dbtup_proxy; // set if we go via proxy
3777 Dbtup* m_dbtup;
3778 DEBUG_OUT_DEFINES(DBTUP);
3779
3780 public:
3781 Dbtup_client(SimulatedBlock* block, SimulatedBlock* dbtup);
3782
3783 // LGMAN
3784
3785 void disk_restart_undo(Signal* signal, Uint64 lsn,
3786 Uint32 type, const Uint32 * ptr, Uint32 len);
3787
3788 // TSMAN
3789
3790 int disk_restart_alloc_extent(Uint32 tableId, Uint32 fragId,
3791 const Local_key* key, Uint32 pages);
3792
3793 void disk_restart_page_bits(Uint32 tableId, Uint32 fragId,
3794 const Local_key* key, Uint32 bits);
3795 };
3796
3797
3798 #undef JAM_FILE_ID
3799
3800 #endif
3801