1 /*
2    Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License, version 2.0,
6    as published by the Free Software Foundation.
7 
8    This program is also distributed with certain software (including
9    but not limited to OpenSSL) that is licensed under separate terms,
10    as designated in a particular file or component or in included license
11    documentation.  The authors of MySQL hereby grant you an additional
12    permission to link the program and your derivative works with the
13    separately licensed software that they have included with MySQL.
14 
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License, version 2.0, for more details.
19 
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
23 */
24 
25 #ifndef DBLQH_H
26 #define DBLQH_H
27 
28 #include <pc.hpp>
29 #include <ndb_limits.h>
30 #include <SimulatedBlock.hpp>
31 #include <SectionReader.hpp>
32 #include <SLList.hpp>
33 #include <DLList.hpp>
34 #include <DLFifoList.hpp>
35 #include <DLHashTable.hpp>
36 
37 #include <NodeBitmask.hpp>
38 #include <signaldata/LCP.hpp>
39 #include <signaldata/LqhTransConf.hpp>
40 #include <signaldata/CreateTab.hpp>
41 #include <signaldata/LqhFrag.hpp>
42 #include <signaldata/FsOpenReq.hpp>
43 #include <signaldata/DropTab.hpp>
44 
45 // primary key is stored in TUP
46 #include "../dbtup/Dbtup.hpp"
47 
48 class Dbacc;
49 class Dbtup;
50 class Lgman;
51 
52 #ifdef DBLQH_C
53 // Constants
54 /* ------------------------------------------------------------------------- */
55 /*       CONSTANTS USED WHEN MASTER REQUESTS STATE OF COPY FRAGMENTS.        */
56 /* ------------------------------------------------------------------------- */
57 #define ZCOPY_CLOSING 0
58 #define ZCOPY_ONGOING 1
59 #define ZCOPY_ACTIVATION 2
60 /* ------------------------------------------------------------------------- */
61 /*       STATES FOR THE VARIABLE GCP_LOG_PART_STATE                          */
62 /* ------------------------------------------------------------------------- */
63 #define ZIDLE 0
64 #define ZWAIT_DISK 1
65 #define ZON_DISK 2
66 #define ZACTIVE 1
67 /* ------------------------------------------------------------------------- */
68 /*       STATES FOR THE VARIABLE CSR_PHASES_STARTED                          */
69 /* ------------------------------------------------------------------------- */
70 #define ZSR_NO_PHASE_STARTED 0
71 #define ZSR_PHASE1_COMPLETED 1
72 #define ZSR_PHASE2_COMPLETED 2
73 #define ZSR_BOTH_PHASES_STARTED 3
74 /* ------------------------------------------------------------------------- */
75 /*       THE NUMBER OF PAGES IN A MBYTE, THE TWO LOGARITHM OF THIS.          */
76 /*       THE NUMBER OF MBYTES IN A LOG FILE.                                 */
77 /*       THE MAX NUMBER OF PAGES READ/WRITTEN FROM/TO DISK DURING            */
78 /*       A WRITE OR READ.                                                    */
79 /* ------------------------------------------------------------------------- */
80 #define ZNOT_DIRTY 0
81 #define ZDIRTY 1
82 #define ZREAD_AHEAD_SIZE 8
83 /* ------------------------------------------------------------------------- */
84 /*       CONSTANTS OF THE LOG PAGES                                          */
85 /* ------------------------------------------------------------------------- */
86 #define ZPAGE_HEADER_SIZE 32
87 #define ZPAGE_SIZE 8192
88 #define ZPAGES_IN_MBYTE 32
89 #define ZTWOLOG_NO_PAGES_IN_MBYTE 5
90 #define ZTWOLOG_PAGE_SIZE 13
91 #define ZMAX_MM_BUFFER_SIZE 32     // Main memory window during log execution
92 
93 #define ZMAX_PAGES_WRITTEN 8    // Max pages before writing to disk (=> config)
94 #define ZMIN_READ_BUFFER_SIZE 2       // Minimum number of pages to execute log
95 #define ZMIN_LOG_PAGES_OPERATION 10   // Minimum no of pages before stopping
96 
97 #define ZPOS_CHECKSUM 0
98 #define ZPOS_LOG_LAP 1
99 #define ZPOS_MAX_GCI_COMPLETED 2
100 #define ZPOS_MAX_GCI_STARTED 3
101 #define ZNEXT_PAGE 4
102 #define ZPREV_PAGE 5
103 #define ZPOS_VERSION 6
104 #define ZPOS_NO_LOG_FILES 7
105 #define ZCURR_PAGE_INDEX 8
106 #define ZLAST_LOG_PREP_REF 10
107 #define ZPOS_DIRTY 11
108 /* A number of debug items written in the page header of all log files */
109 #define ZPOS_LOG_TIMER 12
110 #define ZPOS_PAGE_I 13
111 #define ZPOS_PLACE_WRITTEN_FROM 14
112 #define ZPOS_PAGE_NO 15
113 #define ZPOS_PAGE_FILE_NO 16
114 #define ZPOS_WORD_WRITTEN 17
115 #define ZPOS_IN_WRITING 18
116 #define ZPOS_PREV_PAGE_NO 19
117 #define ZPOS_IN_FREE_LIST 20
118 
119 /* ------------------------------------------------------------------------- */
120 /*       CONSTANTS FOR THE VARIOUS REPLICA AND NODE TYPES.                   */
121 /* ------------------------------------------------------------------------- */
122 #define ZPRIMARY_NODE 0
123 #define ZBACKUP_NODE 1
124 #define ZSTANDBY_NODE 2
125 #define ZTC_NODE 3
126 #define ZLOG_NODE 3
127 /* ------------------------------------------------------------------------- */
128 /*       VARIOUS CONSTANTS USED AS FLAGS TO THE FILE MANAGER.                */
129 /* ------------------------------------------------------------------------- */
130 #define ZVAR_NO_LOG_PAGE_WORD 1
131 #define ZLIST_OF_PAIRS 0
132 #define ZLIST_OF_PAIRS_SYNCH 16
133 #define ZARRAY_OF_PAGES 1
134 #define ZLIST_OF_MEM_PAGES 2
135 #define ZLIST_OF_MEM_PAGES_SYNCH 18
136 #define ZCLOSE_NO_DELETE 0
137 #define ZCLOSE_DELETE 1
138 #define ZPAGE_ZERO 0
139 /* ------------------------------------------------------------------------- */
140 /*       THE FOLLOWING CONSTANTS ARE USED TO DESCRIBE THE TYPES OF           */
141 /*       LOG RECORDS, THE SIZE OF THE VARIOUS LOG RECORD TYPES AND           */
142 /*       THE POSITIONS WITHIN THOSE LOG RECORDS.                             */
143 /* ------------------------------------------------------------------------- */
144 /* ------------------------------------------------------------------------- */
145 /*       THESE CONSTANTS DESCRIBE THE SIZES OF VARIOUS TYPES OF LOG REORDS.  */
146 /*       NEXT_LOG_SIZE IS ACTUALLY ONE. THE REASON WE SET IT TO 2 IS TO      */
147 /*       SIMPLIFY THE CODE SINCE OTHERWISE HAVE TO USE A SPECIAL VERSION     */
148 /*       OF READ_LOGWORD WHEN READING LOG RECORD TYPE                        */
149 /*       SINCE NEXT MBYTE TYPE COULD BE THE VERY LAST WORD IN THE MBYTE.     */
150 /*       BY SETTING IT TO 2 WE ENSURE IT IS NEVER THE VERY LAST WORD         */
151 /*       IN THE MBYTE.                                                       */
152 /* ------------------------------------------------------------------------- */
153 #define ZFD_HEADER_SIZE 3
154 #define ZFD_MBYTE_SIZE 3
155 #define ZLOG_HEAD_SIZE 8
156 #define ZNEXT_LOG_SIZE 2
157 #define ZABORT_LOG_SIZE 3
158 #define ZCOMMIT_LOG_SIZE 9
159 #define ZCOMPLETED_GCI_LOG_SIZE 2
160 /* ------------------------------------------------------------------------- */
161 /*       THESE CONSTANTS DESCRIBE THE TYPE OF A LOG RECORD.                  */
162 /*       THIS IS THE FIRST WORD OF A LOG RECORD.                             */
163 /* ------------------------------------------------------------------------- */
164 #define ZNEW_PREP_OP_TYPE 0
165 #define ZPREP_OP_TYPE 1
166 #define ZCOMMIT_TYPE 2
167 #define ZABORT_TYPE 3
168 #define ZFD_TYPE 4
169 #define ZFRAG_SPLIT_TYPE 5
170 #define ZNEXT_LOG_RECORD_TYPE 6
171 #define ZNEXT_MBYTE_TYPE 7
172 #define ZCOMPLETED_GCI_TYPE 8
173 #define ZINVALID_COMMIT_TYPE 9
174 /* ------------------------------------------------------------------------- */
175 /*       THE POSITIONS OF LOGGED DATA IN A FILE DESCRIPTOR LOG RECORD HEADER.*/
176 /*       ALSO THE MAXIMUM NUMBER OF FILE DESCRIPTORS IN A LOG RECORD.        */
177 /* ------------------------------------------------------------------------- */
178 #define ZPOS_LOG_TYPE 0
179 #define ZPOS_NO_FD 1
180 #define ZPOS_FILE_NO 2
181 /* ------------------------------------------------------------------------- */
182 /*       THE POSITIONS WITHIN A PREPARE LOG RECORD AND A NEW PREPARE         */
183 /*       LOG RECORD.                                                         */
184 /* ------------------------------------------------------------------------- */
185 #define ZPOS_HASH_VALUE 2
186 #define ZPOS_SCHEMA_VERSION 3
187 #define ZPOS_TRANS_TICKET 4
188 #define ZPOS_OP_TYPE 5
189 #define ZPOS_NO_ATTRINFO 6
190 #define ZPOS_NO_KEYINFO 7
191 /* ------------------------------------------------------------------------- */
192 /*       THE POSITIONS WITHIN A COMMIT LOG RECORD.                           */
193 /* ------------------------------------------------------------------------- */
194 #define ZPOS_COMMIT_TRANSID1 1
195 #define ZPOS_COMMIT_TRANSID2 2
196 #define ZPOS_COMMIT_GCI 3
197 #define ZPOS_COMMIT_TABLE_REF 4
198 #define ZPOS_COMMIT_FRAGID 5
199 #define ZPOS_COMMIT_FILE_NO 6
200 #define ZPOS_COMMIT_START_PAGE_NO 7
201 #define ZPOS_COMMIT_START_PAGE_INDEX 8
202 #define ZPOS_COMMIT_STOP_PAGE_NO 9
203 /* ------------------------------------------------------------------------- */
204 /*       THE POSITIONS WITHIN A ABORT LOG RECORD.                            */
205 /* ------------------------------------------------------------------------- */
206 #define ZPOS_ABORT_TRANSID1 1
207 #define ZPOS_ABORT_TRANSID2 2
208 /* ------------------------------------------------------------------------- */
209 /*       THE POSITION WITHIN A COMPLETED GCI LOG RECORD.                     */
210 /* ------------------------------------------------------------------------- */
211 #define ZPOS_COMPLETED_GCI 1
212 /* ------------------------------------------------------------------------- */
213 /*       THE POSITIONS WITHIN A NEW PREPARE LOG RECORD.                      */
214 /* ------------------------------------------------------------------------- */
215 #define ZPOS_NEW_PREP_FILE_NO 8
216 #define ZPOS_NEW_PREP_PAGE_REF 9
217 
218 #define ZLAST_WRITE_IN_FILE 1
219 #define ZENFORCE_WRITE 2
220 /* ------------------------------------------------------------------------- */
221 /*       CONSTANTS USED AS INPUT TO SUBROUTINE WRITE_LOG_PAGES AMONG OTHERS. */
222 /* ------------------------------------------------------------------------- */
223 #define ZNORMAL 0
224 #define ZINIT 1
225 /* ------------------------------------------------------------------------- */
226 /*       CONSTANTS USED BY CONTINUEB TO DEDUCE WHICH CONTINUE SIGNAL IS TO   */
227 /*       BE EXECUTED AS A RESULT OF THIS CONTINUEB SIGNAL.                   */
228 /* ------------------------------------------------------------------------- */
229 #define ZLOG_LQHKEYREQ 0
230 #define ZPACK_LQHKEYREQ 1
231 #define ZSEND_ATTRINFO 2
232 #define ZSR_GCI_LIMITS 3
233 #define ZSR_LOG_LIMITS 4
234 #define ZSEND_EXEC_CONF 5
235 #define ZEXEC_SR 6
236 #define ZSR_FOURTH_COMP 7
237 #define ZINIT_FOURTH 8
238 #define ZTIME_SUPERVISION 9
239 #define ZSR_PHASE3_START 10
240 #define ZLQH_TRANS_NEXT 11
241 #define ZLQH_RELEASE_AT_NODE_FAILURE 12
242 #define ZSCAN_TC_CONNECT 13
243 #define ZINITIALISE_RECORDS 14
244 #define ZINIT_GCP_REC 15
245 #define ZCHECK_LCP_STOP_BLOCKED 17
246 #define ZSCAN_MARKERS 18
247 #define ZOPERATION_EVENT_REP 19
248 #define ZDROP_TABLE_WAIT_USAGE 20
249 #define ZENABLE_EXPAND_CHECK 21
250 #define ZRETRY_TCKEYREF 22
251 #define ZWAIT_REORG_SUMA_FILTER_ENABLED 23
252 #define ZREBUILD_ORDERED_INDEXES 24
253 #define ZWAIT_READONLY 25
254 
255 /* ------------------------------------------------------------------------- */
256 /*        NODE STATE DURING SYSTEM RESTART, VARIABLES CNODES_SR_STATE        */
257 /*        AND CNODES_EXEC_SR_STATE.                                          */
258 /* ------------------------------------------------------------------------- */
259 #define ZSTART_SR 1
260 #define ZEXEC_SR_COMPLETED 2
261 /* ------------------------------------------------------------------------- */
262 /*       CONSTANTS USED BY NODE STATUS TO DEDUCE THE STATUS OF A NODE.       */
263 /* ------------------------------------------------------------------------- */
264 #define ZNODE_UP 0
265 #define ZNODE_DOWN 1
266 /* ------------------------------------------------------------------------- */
267 /*       START PHASES                                                        */
268 /* ------------------------------------------------------------------------- */
269 #define ZLAST_START_PHASE 255
270 #define ZSTART_PHASE1 1
271 #define ZSTART_PHASE2 2
272 #define ZSTART_PHASE3 3
273 #define ZSTART_PHASE4 4
274 #define ZSTART_PHASE6 6
275 /* ------------------------------------------------------------------------- */
276 /*       CONSTANTS USED BY SCAN AND COPY FRAGMENT PROCEDURES                 */
277 /* ------------------------------------------------------------------------- */
278 #define ZSTORED_PROC_SCAN 0
279 #define ZSTORED_PROC_COPY 2
280 #define ZDELETE_STORED_PROC_ID 3
281 #define ZWRITE_LOCK 1
282 #define ZSCAN_FRAG_CLOSED 2
283 /* ------------------------------------------------------------------------- */
284 /*       ERROR CODES ADDED IN VERSION 0.1 AND 0.2                            */
285 /* ------------------------------------------------------------------------- */
286 #define ZNOT_FOUND 1             // Not an error code, a return value
287 #define ZNO_FREE_LQH_CONNECTION 414
288 #define ZGET_DATAREC_ERROR 418
289 #define ZGET_ATTRINBUF_ERROR 419
290 #define ZNO_FREE_FRAGMENTREC 460 // Insert new fragment error code
291 #define ZTAB_FILE_SIZE 464       // Insert new fragment error code + Start kernel
292 #define ZNO_ADD_FRAGREC 465      // Insert new fragment error code
293 /* ------------------------------------------------------------------------- */
294 /*       ERROR CODES ADDED IN VERSION 0.3                                    */
295 /* ------------------------------------------------------------------------- */
296 #define ZTAIL_PROBLEM_IN_LOG_ERROR 410
297 #define ZGCI_TOO_LOW_ERROR 429        // GCP_SAVEREF error code
298 #define ZTAB_STATE_ERROR 474          // Insert new fragment error code
299 #define ZTOO_NEW_GCI_ERROR 479        // LCP Start error
300 /* ------------------------------------------------------------------------- */
301 /*       ERROR CODES ADDED IN VERSION 0.4                                    */
302 /* ------------------------------------------------------------------------- */
303 
304 #define ZNO_FREE_FRAG_SCAN_REC_ERROR 490 // SCAN_FRAGREF error code
305 #define ZCOPY_NO_FRAGMENT_ERROR 491      // COPY_FRAGREF error code
306 #define ZTAKE_OVER_ERROR 499
307 #define ZCOPY_NODE_ERROR 1204
308 #define ZTOO_MANY_COPY_ACTIVE_ERROR 1208 // COPY_FRAG and COPY_ACTIVEREF code
309 #define ZCOPY_ACTIVE_ERROR 1210          // COPY_ACTIVEREF error code
310 #define ZNO_TC_CONNECT_ERROR 1217        // Simple Read + SCAN
311 #define ZTRANSPORTER_OVERLOADED_ERROR 1218
312 /* ------------------------------------------------------------------------- */
313 /*       ERROR CODES ADDED IN VERSION 1.X                                    */
314 /* ------------------------------------------------------------------------- */
315 //#define ZSCAN_BOOK_ACC_OP_ERROR 1219   // SCAN_FRAGREF error code
316 #define ZFILE_CHANGE_PROBLEM_IN_LOG_ERROR 1220
317 #define ZTEMPORARY_REDO_LOG_FAILURE 1221
318 #define ZNO_FREE_MARKER_RECORDS_ERROR 1222
319 #define ZNODE_SHUTDOWN_IN_PROGESS 1223
320 #define ZTOO_MANY_FRAGMENTS 1224
321 #define ZTABLE_NOT_DEFINED 1225
322 #define ZDROP_TABLE_IN_PROGRESS 1226
323 #define ZINVALID_SCHEMA_VERSION 1227
324 #define ZTABLE_READ_ONLY 1233
325 #define ZREDO_IO_PROBLEM 1234
326 
327 /* ------------------------------------------------------------------------- */
328 /*       ERROR CODES ADDED IN VERSION 2.X                                    */
329 /* ------------------------------------------------------------------------- */
330 #define ZNODE_FAILURE_ERROR 400
331 #define ZBAD_UNLOCK_STATE 416
332 #define ZBAD_OP_REF 417
333 /* ------------------------------------------------------------------------- */
334 /*       ERROR CODES FROM ACC                                                */
335 /* ------------------------------------------------------------------------- */
336 #define ZNO_TUPLE_FOUND 626
337 #define ZTUPLE_ALREADY_EXIST 630
338 /* ------------------------------------------------------------------------- */
339 /*       ERROR CODES FROM TUP                                                */
340 /* ------------------------------------------------------------------------- */
341 #define ZSEARCH_CONDITION_FALSE 899
342 #define ZUSER_ERROR_CODE_LIMIT 6000
343 #endif
344 
345 /**
346  * @class dblqh
347  *
348  * @section secIntro Introduction
349  *
350  * Dblqh is the coordinator of the LDM.  Dblqh is responsible for
351  * performing operations on tuples.  It does this job with help of
352  * Dbacc block (that manages the index structures) and Dbtup
353  * (that manages the tuples).
354  *
355  * Dblqh also keeps track of the participants and acts as a coordinator of
356  * 2-phase commits.  Logical redo logging is also handled by the Dblqh
357  * block.
358  *
359  * @section secModules Modules
360  *
361  * The code is partitioned into the following modules:
362  * - START / RESTART
363  *   - Start phase 1: Load our block reference and our processor id
364  *   - Start phase 2: Initiate all records within the block
365  *                    Connect LQH with ACC and TUP.
366  *   - Start phase 4: Connect LQH with LQH.  Connect every LQH with
367  *                    every LQH in the database system.
368  *	              If initial start, then create the fragment log files.
369  *	              If system restart or node restart,
370  *                    then open the fragment log files and
371  *	              find the end of the log files.
372  * - ADD / DELETE FRAGMENT<br>
373  *     Used by dictionary to create new fragments and delete old fragments.
374  *  - EXECUTION<br>
375  *    handles the reception of lqhkeyreq and all processing
376  *    of operations on behalf of this request.
377  *    This does also involve reception of various types of attrinfo
378  *    and keyinfo.
379  *    It also involves communication with ACC and TUP.
380  *  - LOG<br>
381  *    The log module handles the reading and writing of the log.
382  *    It is also responsible for handling system restart.
383  *    It controls the system restart in TUP and ACC as well.
384  *  - TRANSACTION<br>
385  *    This module handles the commit and the complete phases.
386  *  - MODULE TO HANDLE TC FAILURE<br>
387  *  - SCAN<br>
388  *    This module contains the code that handles a scan of a particular
389  *    fragment.
390  *    It operates under the control of TC and orders ACC to
391  *    perform a scan of all tuples in the fragment.
392  *    TUP performs the necessary search conditions
393  *    to ensure that only valid tuples are returned to the application.
394  *  - NODE RECOVERY<br>
395  *    Used when a node has failed.
396  *    It performs a copy of a fragment to a new replica of the fragment.
397  *    It does also shut down all connections to the failed node.
398  *  - LOCAL CHECKPOINT<br>
399  *    Handles execution and control of LCPs
400  *    It controls the LCPs in TUP and ACC.
401  *    It also interacts with DIH to control which GCPs are recoverable.
402  *  - GLOBAL CHECKPOINT<br>
403  *    Helps DIH in discovering when GCPs are recoverable.
404  *    It handles the request gcp_savereq that requests LQH to
405  *    save a particular GCP to disk and respond when completed.
406  *  - FILE HANDLING<br>
407  *    With submodules:
408  *    - SIGNAL RECEPTION
409  *    - NORMAL OPERATION
410  *    - FILE CHANGE
411  *    - INITIAL START
412  *    - SYSTEM RESTART PHASE ONE
413  *    - SYSTEM RESTART PHASE TWO,
414  *    - SYSTEM RESTART PHASE THREE
415  *    - SYSTEM RESTART PHASE FOUR
416  *  - ERROR
417  *  - TEST
418  *  - LOG
419  */
420 class Dblqh: public SimulatedBlock {
421   friend class DblqhProxy;
422 
423 public:
424   enum LcpCloseState {
425     LCP_IDLE = 0,
426     LCP_RUNNING = 1,       // LCP is running
427     LCP_CLOSE_STARTED = 2, // Completion(closing of files) has started
428     ACC_LCP_CLOSE_COMPLETED = 3,
429     TUP_LCP_CLOSE_COMPLETED = 4
430   };
431 
432   enum ExecUndoLogState {
433     EULS_IDLE = 0,
434     EULS_STARTED = 1,
435     EULS_COMPLETED = 2
436   };
437 
438   struct AddFragRecord {
439     enum AddFragStatus {
440       FREE = 0,
441       ACC_ADDFRAG = 1,
442       WAIT_TUP = 3,
443       WAIT_TUX = 5,
444       WAIT_ADD_ATTR = 6,
445       TUP_ATTR_WAIT = 7,
446       TUX_ATTR_WAIT = 9
447     };
448     AddFragStatus addfragStatus;
449     UintR fragmentPtr;
450     UintR nextAddfragrec;
451     UintR accConnectptr;
452     UintR tupConnectptr;
453     UintR tuxConnectptr;
454 
455     CreateTabReq m_createTabReq;
456     LqhFragReq m_lqhFragReq;
457     LqhAddAttrReq m_addAttrReq;
458     DropFragReq m_dropFragReq;
459     DropTabReq m_dropTabReq;
460 
461     Uint16 addfragErrorCode;
462     Uint16 attrSentToTup;
463     Uint16 attrReceived;
464     Uint16 totalAttrReceived;
465     Uint16 fragCopyCreation;
466     Uint16 defValNextPos;
467     Uint32 defValSectionI;
468   };
469   typedef Ptr<AddFragRecord> AddFragRecordPtr;
470 
471   struct ScanRecord {
ScanRecordDblqh::ScanRecord472     ScanRecord() {}
473     enum ScanState {
474       SCAN_FREE = 0,
475       WAIT_STORED_PROC_COPY = 1,
476       WAIT_STORED_PROC_SCAN = 2,
477       WAIT_NEXT_SCAN_COPY = 3,
478       WAIT_NEXT_SCAN = 4,
479       WAIT_DELETE_STORED_PROC_ID_SCAN = 5,
480       WAIT_DELETE_STORED_PROC_ID_COPY = 6,
481       WAIT_ACC_COPY = 7,
482       WAIT_ACC_SCAN = 8,
483       WAIT_SCAN_NEXTREQ = 10,
484       WAIT_CLOSE_SCAN = 12,
485       WAIT_CLOSE_COPY = 13,
486       WAIT_RELEASE_LOCK = 14,
487       WAIT_TUPKEY_COPY = 15,
488       WAIT_LQHKEY_COPY = 16,
489       IN_QUEUE = 17
490     };
491     enum ScanType {
492       ST_IDLE = 0,
493       SCAN = 1,
494       COPY = 2
495     };
496 
497     /* A single scan of each fragment can have MAX_PARALLEL_OP_PER_SCAN
498      * read operations in progress at one time
499      * We must store ACC ptrs for each read operation.  They are stored
500      * in SegmentedSections linked in the array below.
501      * The main oddity is that the first element of scan_acc_op_ptr is
502      * an ACC ptr, but all others are refs to SectionSegments containing
503      * ACC ptrs.
504      */
505     STATIC_CONST( MaxScanAccSegments= (
506                  (MAX_PARALLEL_OP_PER_SCAN + SectionSegment::DataLength - 1) /
507                  SectionSegment::DataLength) + 1);
508 
509     UintR scan_acc_op_ptr[ MaxScanAccSegments ];
510     Uint32 scan_acc_index;
511     Uint32 scan_acc_segments;
512     UintR scanApiOpPtr;
513     Local_key m_row_id;
514 
515     Uint32 m_max_batch_size_rows;
516     Uint32 m_max_batch_size_bytes;
517 
518     Uint32 m_curr_batch_size_rows;
519     Uint32 m_curr_batch_size_bytes;
520 
521     bool check_scan_batch_completed() const;
522 
523     UintR copyPtr;
524     union {
525       Uint32 nextPool;
526       Uint32 nextList;
527     };
528     Uint32 prevList;
529     Uint32 nextHash;
530     Uint32 prevHash;
equalDblqh::ScanRecord531     bool equal(const ScanRecord & key) const {
532       return scanNumber == key.scanNumber && fragPtrI == key.fragPtrI;
533     }
hashValueDblqh::ScanRecord534     Uint32 hashValue() const {
535       return fragPtrI ^ scanNumber;
536     }
537 
538     UintR scanAccPtr;
539     UintR scanAiLength;
540     UintR scanErrorCounter;
541     UintR scanSchemaVersion;
542     Uint32 scanTcWaiting; // When the request came from TC, 0 is no request
543 
544     /**
545      * This is _always_ main table, even in range scan
546      *   in which case scanTcrec->fragmentptr is different
547      */
548     Uint32 fragPtrI;
549     UintR scanStoredProcId;
550     ScanState scanState;
551     UintR scanTcrec;
552     ScanType scanType;
553     BlockReference scanApiBlockref;
554     NodeId scanNodeId;
555     Uint16 scanReleaseCounter;
556     Uint16 scanNumber;
557 
558     // scan source block ACC TUX TUP
559     BlockReference scanBlockref;
560 
561     Uint8 scanCompletedStatus;
562     Uint8 scanFlag;
563     Uint8 scanLockHold;
564     Uint8 scanLockMode;
565     Uint8 readCommitted;
566     Uint8 rangeScan;
567     Uint8 descending;
568     Uint8 tupScan;
569     Uint8 lcpScan;
570     Uint8 scanKeyinfoFlag;
571     Uint8 m_last_row;
572     Uint8 m_reserved;
573     Uint8 statScan;
574     Uint8 dummy[3]; // align?
575   }; // Size 272 bytes
576   typedef Ptr<ScanRecord> ScanRecordPtr;
577 
578   struct Fragrecord {
FragrecordDblqh::Fragrecord579     Fragrecord() {}
580 
581     enum ExecSrStatus {
582       IDLE = 0,
583       ACTIVE = 2
584     };
585     /**
586      * Possible state transitions are:
587      * - FREE -> DEFINED                 Fragment record is allocated
588      * - DEFINED -> ACTIVE               Add fragment is completed and
589      *                                   fragment is ready to
590      *                                   receive operations.
591      * - DEFINED -> ACTIVE_CREATION      Add fragment is completed and
592      *                                   fragment is ready to
593      *                                   receive operations in parallel
594      *                                   with a copy fragment
595      *                                   which is performed from the
596      *                                   primary replica
597      * - DEFINED -> CRASH_RECOVERING     A fragment is ready to be
598      *                                   recovered from a local
599      *                                   checkpoint on disk
600      * - ACTIVE -> BLOCKED               A local checkpoint is to be
601      *                                   started.  No more operations
602      *                                   are allowed to be started until
603      *                                   the local checkpoint
604      *                                   has been started.
605      * - ACTIVE -> REMOVING              A fragment is removed from the node
606      * - BLOCKED -> ACTIVE               Operations are allowed again in
607      *                                   the fragment.
608      * - CRASH_RECOVERING -> ACTIVE      A fragment has been recovered and
609      *                                   are now ready for
610      *                                   operations again.
611      * - CRASH_RECOVERING -> REMOVING    Fragment recovery failed or
612      *                                   was cancelled.
613      * - ACTIVE_CREATION -> ACTIVE       A fragment is now copied and now
614      *                                   is a normal fragment
615      * - ACTIVE_CREATION -> REMOVING     Copying of the fragment failed
616      * - REMOVING -> FREE                Removing of the fragment is
617      *                                   completed and the fragment
618      *                                   is now free again.
619      */
620     enum FragStatus {
621       FREE = 0,               ///< Fragment record is currently not in use
622       FSACTIVE = 1,           ///< Fragment is defined and usable for operations
623       DEFINED = 2,            ///< Fragment is defined but not yet usable by
624                               ///< operations
625       BLOCKED = 3,            ///< LQH is waiting for all active operations to
626                               ///< complete the current phase so that the
627                               ///< local checkpoint can be started.
628       ACTIVE_CREATION = 4,    ///< Fragment is defined and active but is under
629                               ///< creation by the primary LQH.
630       CRASH_RECOVERING = 5,   ///< Fragment is recovering after a crash by
631                               ///< executing the fragment log and so forth.
632                               ///< Will need further breakdown.
633       REMOVING = 6            ///< The fragment is currently removed.
634                               ///< Operations are not allowed.
635     };
636     enum LogFlag {
637       STATE_TRUE = 0,
638       STATE_FALSE = 1
639     };
640     enum SrStatus {
641       SS_IDLE = 0,
642       SS_STARTED = 1,
643       SS_COMPLETED = 2
644     };
645     enum LcpFlag {
646       LCP_STATE_TRUE = 0,
647       LCP_STATE_FALSE = 1
648     };
649     /**
650      *        Last GCI for executing the fragment log in this phase.
651      */
652     UintR execSrLastGci[4];
653     /**
654      *       Start GCI for executing the fragment log in this phase.
655      */
656     UintR execSrStartGci[4];
657     /**
658      *       Requesting user pointer for executing the fragment log in
659      *       this phase
660      */
661     UintR execSrUserptr[4];
662     /**
663      *       The LCP identifier of the LCP's.
664      *       =0 means that the LCP number has not been stored.
665      *       The LCP identifier is supplied by DIH when starting the LCP.
666      */
667     UintR lcpId[MAX_LCP_STORED];
668     UintR maxGciInLcp;
669     /**
670      *       This variable contains the maximum global checkpoint
671      *       identifier that exists in a certain local checkpoint.
672      *       Maximum 4 local checkpoints is possible in this release.
673      */
674     UintR maxGciCompletedInLcp;
675     UintR srLastGci[4];
676     UintR srStartGci[4];
677     /**
678      *       The fragment pointers in ACC
679      */
680     UintR accFragptr;
681     /**
682      *       The EXEC_SR variables are used to keep track of which fragments
683      *       that are interested in being executed as part of executing the
684      *       fragment loop.
685      *       It is initialised for every phase of executing the
686      *       fragment log (the fragment log can be executed upto four times).
687      *
688      *       Each execution is capable of executing the log records on four
689      *       fragment replicas.
690      */
691     /**
692      *       Requesting block reference for executing the fragment log
693      *       in this phase.
694      */
695     BlockReference execSrBlockref[4];
696     /**
697      *       This variable contains references to active scan and copy
698      *       fragment operations on the fragment.
699      *       A maximum of four concurrently active is allowed.
700      */
701 
702     typedef Bitmask<8> ScanNumberMask; // Max 255 KeyInfo20::ScanNo
703     ScanNumberMask m_scanNumberMask;
704     DLList<ScanRecord>::Head m_activeScans;
705     DLFifoList<ScanRecord>::Head m_queuedScans;
706     DLFifoList<ScanRecord>::Head m_queuedTupScans;
707 
708     Uint16 srLqhLognode[4];
709     /**
710      *       The fragment pointers in TUP and TUX
711      */
712     UintR tupFragptr;
713     UintR tuxFragptr;
714 
715     /**
716      *       This variable keeps track of how many operations that are
717      *       active that have skipped writing the log but not yet committed
718      *       or aborted.  This is used during start of fragment.
719      */
720     UintR activeTcCounter;
721 
722     /**
723      *       This status specifies whether this fragment is actively
724      *       engaged in executing the fragment log.
725      */
726     ExecSrStatus execSrStatus;
727 
728     /**
729      *       The fragment id of this fragment.
730      */
731     UintR fragId;
732 
733     /**
734      *       Status of fragment
735      */
736     FragStatus fragStatus;
737 
738     /**
739      * 0 = undefined i.e fragStatus != ACTIVE_CREATION
740      * 1 = yes
741      * 2 = no
742      */
743     enum ActiveCreat {
744       AC_NORMAL = 0,  // fragStatus != ACTIVE_CREATION
745       AC_IGNORED = 1, // Operation that got ignored during NR
746       AC_NR_COPY = 2  // Operation that got performed during NR
747     };
748     Uint8 m_copy_started_state;
749 
750     /**
751      *       This flag indicates whether logging is currently activated at
752      *       the fragment.
753      *       During a system restart it is temporarily shut off.
754      *       Some fragments have it permanently shut off.
755      */
756     LogFlag logFlag;
757     UintR masterPtr;
758     /**
759      *       This variable contains the maximum global checkpoint identifier
760      *       which was completed when the local checkpoint was started.
761      */
762     /**
763      *       Reference to the next fragment record in a free list of fragment
764      *       records.
765      */
766     union {
767       Uint32 nextPool;
768       Uint32 nextList;
769     };
770     Uint32 prevList;
771 
772     /**
773      *       The newest GCI that has been committed on fragment
774      */
775     UintR newestGci;
776     SrStatus srStatus;
777     UintR srUserptr;
778     /**
779      *       The starting global checkpoint of this fragment.
780      */
781     UintR startGci;
782     /**
783      *       A reference to the table owning this fragment.
784      */
785     UintR tabRef;
786 
787     /**
788      *       This is the queue to put operations that have been blocked
789      *       during start of a local chkp.
790      */
791     UintR firstWaitQueue;
792     UintR lastWaitQueue;
793 
794     /**
795      *       The block reference to ACC on the fragment makes it
796      *       possible to have different ACC blocks for different
797      *       fragments in the future.
798      */
799     BlockReference accBlockref;
800 
801     /**
802      *       Ordered index block.
803      */
804     BlockReference tuxBlockref;
805     /**
806      *       The master block reference as sent in COPY_ACTIVEREQ.
807      */
808     BlockReference masterBlockref;
809     /**
810      *       These variables are used during system restart to recall
811      *       from which node to execute the fragment log and which GCI's
812      *       this node should start and stop from. Also to remember who
813      *       to send the response to when system restart is completed.
814      */
815     BlockReference srBlockref;
816     /**
817      *       The block reference to TUP on the fragment makes it
818      *       possible to have different TUP blocks for different
819      *       fragments in the future.
820      */
821     BlockReference tupBlockref;
822     /**
823      *      This state indicates if the fragment will participate in a
824      *      checkpoint.
825      *      Temporary tables with Fragrecord::logFlag permanently off
826      *      will also have Fragrecord::lcpFlag off.
827      */
828     LcpFlag lcpFlag;
829     /**
830      *       Used to ensure that updates started with old
831      *       configuration do not arrive here after the copy fragment
832      *       has started.
833      *       If they are allowed to arrive after they
834      *       could update a record that has already been replicated to
835      *       the new node.  This type of arrival should be extremely
836      *       rare but we must anyway ensure that no harm is done.
837      */
838     Uint16 copyNode;
839     /**
840      *       This variable ensures that only one copy fragment is
841      *       active at a time on the fragment.
842      */
843     Uint8 copyFragState;
844     /**
845      *       The number of fragment replicas that will execute the log
846      *       records in this round of executing the fragment
847      *       log.  Maximum four is possible.
848      */
849     Uint8 execSrNoReplicas;
850     /**
851      *       This variable contains what type of replica this fragment
852      *       is.  Two types are possible:
853      *       - Primary/Backup replica = 0
854      *       - Stand-by replica = 1
855      *
856      *       It is not possible to distinguish between primary and
857      *       backup on a fragment.
858      *       This can only be done per transaction.
859      *       DIH can change from primary to backup without informing
860      *       the various replicas about this change.
861      */
862     Uint8 fragCopy;
863     /**
864      *       This is the last fragment distribution key that we have
865      *       heard of.
866      */
867     Uint8 fragDistributionKey;
868    /**
869      *       How many local checkpoints does the fragment contain
870      */
871     Uint8 srChkpnr;
872     Uint8 srNoLognodes;
873     /**
874      *       Table type.
875      */
876     Uint8 tableType;
877     /**
878      *       For ordered index fragment, i-value of corresponding
879      *       fragment in primary table.
880      */
881     UintR tableFragptr;
882 
883     /**
884      * Log part
885      */
886     Uint32 m_log_part_ptr_i;
887 
888     /**
889      * Instance key for fast access.
890      */
891     Uint16 lqhInstanceKey;
892   };
893   typedef Ptr<Fragrecord> FragrecordPtr;
894 
895   /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
896   /* $$$$$$$                GLOBAL CHECKPOINT RECORD                  $$$$$$ */
897   /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
898   /**
899    *       This record describes a global checkpoint that is
900    *       completed.  It waits for all log records belonging to this
901    *       global checkpoint to be saved on disk.
902    */
903   struct GcpRecord {
904     /**
905      *       The file number within each log part where the log was
906      *       located when gcp_savereq was received. The last record
907      *       belonging to this global checkpoint is certainly before
908      *       this place in the log. We could come even closer but it
909      *       would cost performance and doesn't seem like a good
910      *       idea. This is simple and it works.
911      */
912     Uint16 gcpFilePtr[4];
913     /**
914      *       The page number within the file for each log part.
915      */
916     Uint16 gcpPageNo[4];
917     /**
918      *       The word number within the last page that was written for
919      *       each log part.
920      */
921     Uint16 gcpWordNo[4];
922     /**
923      *       The identity of this global checkpoint.
924      */
925     UintR gcpId;
926     /**
927      *       The state of this global checkpoint, one for each log part.
928      */
929     Uint8 gcpLogPartState[4];
930     /**
931      *       The sync state of this global checkpoint, one for each
932      *       log part.
933      */
934     Uint8 gcpSyncReady[4];
935     /**
936      *       User pointer of the sender of gcp_savereq (= master DIH).
937      */
938     UintR gcpUserptr;
939     /**
940      *       Block reference of the sender of gcp_savereq
941      *       (= master DIH).
942      */
943     BlockReference gcpBlockref;
944   }; // Size 44 bytes
945   typedef Ptr<GcpRecord> GcpRecordPtr;
946 
947   struct HostRecord {
948     Uint8 inPackedList;
949     Uint8 nodestatus;
950     Uint8 _unused[2];
951     UintR noOfPackedWordsLqh;
952     UintR packedWordsLqh[30];
953     UintR noOfPackedWordsTc;
954     UintR packedWordsTc[29];
955     BlockReference hostLqhBlockRef;
956     BlockReference hostTcBlockRef;
957   };// Size 128 bytes
958   typedef Ptr<HostRecord> HostRecordPtr;
959 
960   /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
961   /* $$$$$$               LOCAL CHECKPOINT SUPPORT RECORD            $$$$$$$ */
962   /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
963   /**
964    *      This record contains the information about an outstanding
965    *      request to TUP or ACC. Used for both local checkpoints and
966    *      system restart.
967    */
968   struct LcpLocRecord {
969     enum LcpLocstate {
970       IDLE = 0,
971       WAIT_TUP_PREPLCP = 1,
972       WAIT_LCPHOLDOP = 2,
973       HOLDOP_READY = 3,
974       ACC_WAIT_STARTED = 4,
975       ACC_STARTED = 5,
976       ACC_COMPLETED = 6,
977       TUP_WAIT_STARTED = 7,
978       TUP_STARTED = 8,
979       TUP_COMPLETED = 9,
980       SR_ACC_STARTED = 10,
981       SR_TUP_STARTED = 11,
982       SR_ACC_COMPLETED = 12,
983       SR_TUP_COMPLETED = 13
984     };
985     LcpLocstate lcpLocstate;
986     Uint32 lcpRef;
987   }; // 28 bytes
988   typedef Ptr<LcpLocRecord> LcpLocRecordPtr;
989 
990   /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
991   /* $$$$$$$              LOCAL CHECKPOINT RECORD                    $$$$$$$ */
992   /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
993   /**
994    *       This record contains the information about a local
995    *       checkpoint that is ongoing. This record is also used as a
996    *       system restart record.
997    */
998   struct LcpRecord {
LcpRecordDblqh::LcpRecord999     LcpRecord() { m_EMPTY_LCP_REQ.clear(); }
1000 
1001     enum LcpState {
1002       LCP_IDLE = 0,
1003       LCP_COMPLETED = 2,
1004       LCP_WAIT_FRAGID = 3,
1005       LCP_WAIT_TUP_PREPLCP = 4,
1006       LCP_WAIT_HOLDOPS = 5,
1007       LCP_START_CHKP = 7,
1008       LCP_BLOCKED_COMP = 8,
1009       LCP_SR_WAIT_FRAGID = 9,
1010       LCP_SR_STARTED = 10,
1011       LCP_SR_COMPLETED = 11
1012     };
1013 
1014     LcpState lcpState;
1015     bool firstFragmentFlag;
1016     bool lastFragmentFlag;
1017 
1018     struct FragOrd {
1019       Uint32 fragPtrI;
1020       LcpFragOrd lcpFragOrd;
1021     };
1022     FragOrd currentFragment;
1023 
1024     bool   lcpQueued;
1025     FragOrd queuedFragment;
1026 
1027     bool   reportEmpty;
1028     NdbNodeBitmask m_EMPTY_LCP_REQ;
1029 
1030     Uint32 m_error;
1031     Uint32 m_outstanding;
1032   }; // Size 76 bytes
1033   typedef Ptr<LcpRecord> LcpRecordPtr;
1034 
1035   struct IOTracker
1036   {
1037     STATIC_CONST( SAMPLE_TIME = 128 );              // millis
1038     STATIC_CONST( SLIDING_WINDOW_LEN = 1024 );      // millis
1039     STATIC_CONST( SLIDING_WINDOW_HISTORY_LEN = 8 );
1040 
1041     void init(Uint32 partNo);
1042     Uint32 m_log_part_no;
1043     Uint32 m_current_time;
1044 
1045     /**
1046      * Keep sliding window of measurement
1047      */
1048     Uint32 m_save_pos; // current pos in array
1049     Uint32 m_save_written_bytes[SLIDING_WINDOW_HISTORY_LEN];
1050     Uint32 m_save_elapsed_millis[SLIDING_WINDOW_HISTORY_LEN];
1051 
1052     /**
1053      * Current sum of sliding window
1054      */
1055     Uint32 m_curr_written_bytes;
1056     Uint32 m_curr_elapsed_millis;
1057 
1058     /**
1059      * Currently outstanding bytes
1060      */
1061     Uint32 m_sum_outstanding_bytes;
1062 
1063     /**
1064      * How many times did we pass lag-threshold
1065      */
1066     Uint32 m_lag_cnt;
1067 
1068     /**
1069      * bytes send during current sample
1070      */
1071     Uint32 m_sample_sent_bytes;
1072 
1073     /**
1074      * bytes completed during current sample
1075      */
1076     Uint32 m_sample_completed_bytes;
1077 
1078     int tick(Uint32 now, Uint32 maxlag, Uint32 maxlag_cnt);
1079     void send_io(Uint32 bytes);
1080     void complete_io(Uint32 bytes);
1081   };
1082 
1083   /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
1084   /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
1085   /*                                                                          */
1086   /*       THE RECORDS THAT START BY LOG_ ARE A PART OF THE LOG MANAGER.      */
1087   /*       THESE RECORDS ARE USED TO HANDLE THE FRAGMENT LOG.                 */
1088   /*                                                                          */
1089   /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
1090   /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
1091   /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
1092   /* $$$$$$$                       LOG RECORD                         $$$$$$$ */
1093   /*                                                                          */
1094   /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
1095   /*       THIS RECORD IS ALIGNED TO BE 256 BYTES.                            */
1096   /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
1097   /**
1098    *       This record describes the current state of a log.
1099    *       A log consists of a number of log files.
1100    *       These log files are described by the log file record.
1101    *
1102    *       There will be 4 sets of log files.
1103    *       Different tables will use different log files dependent
1104    *       on the table id.
1105    *       This  ensures that more than one outstanding request can
1106    *       be sent to the file system.
1107    *       The log file to use is found by performing a very simple hash
1108    *       function.
1109    */
1110   struct LogPartRecord {
1111     enum LogPartState {
1112       IDLE = 0,                       ///< Nothing happens at the moment
1113       ACTIVE = 1,                     ///< An operation is active logging
1114       SR_FIRST_PHASE = 2,             ///< Finding the end of the log and
1115                                       ///< the information about global
1116                                       ///< checkpoints in the log is ongoing.
1117       SR_FIRST_PHASE_COMPLETED = 3,   ///< First phase completed
1118       SR_THIRD_PHASE_STARTED = 4,     ///< Executing fragment log is in 3rd ph
1119       SR_THIRD_PHASE_COMPLETED = 5,
1120       SR_FOURTH_PHASE_STARTED = 6,    ///< Finding the log tail and head
1121                                       ///< is the fourth phase.
1122       SR_FOURTH_PHASE_COMPLETED = 7
1123     };
1124     enum WaitWriteGciLog {
1125       WWGL_TRUE = 0,
1126       WWGL_FALSE = 1
1127     };
1128     enum LogExecState {
1129       LES_IDLE = 0,
1130       LES_SEARCH_STOP = 1,
1131       LES_SEARCH_START = 2,
1132       LES_EXEC_LOG = 3,
1133       LES_EXEC_LOG_NEW_MBYTE = 4,
1134       LES_EXEC_LOG_NEW_FILE = 5,
1135       LES_EXEC_LOGREC_FROM_FILE = 6,
1136       LES_EXEC_LOG_COMPLETED = 7,
1137       LES_WAIT_READ_EXEC_SR_NEW_MBYTE = 8,
1138       LES_WAIT_READ_EXEC_SR = 9,
1139       LES_EXEC_LOG_INVALIDATE = 10
1140     };
1141 
1142     /**
1143      *       Is a CONTINUEB(ZLOG_LQHKEYREQ) signal sent and
1144      *       outstanding. We do not want several instances of this
1145      *       signal out in the air since that would create multiple
1146      *       writers of the list.
1147      */
1148     UintR LogLqhKeyReqSent;
1149     /**
1150      *       Contains the current log file where log records are
1151      *       written.  During system restart it is used to indicate the
1152      *       last log file.
1153      */
1154     UintR currentLogfile;
1155     /**
1156      *       The log file used to execute log records from far behind.
1157      */
1158     UintR execSrExecLogFile;
1159     /**
1160      *       The currently executing prepare record starts in this log
1161      *       page. This variable is used to enable that a log record is
1162      *       executed multiple times in execution of the log.
1163      */
1164     UintR execSrLogPage;
1165     /**
1166      *       This variable keeps track of the lfo record where the
1167      *       pages that were read from disk when an operations log
1168      *       record were not found in the main memory buffer for log
1169      *       pages.
1170      */
1171     UintR execSrLfoRec;
1172     /**
1173      *       The starting page number when reading log from far behind.
1174      */
1175     UintR execSrStartPageNo;
1176     /**
1177      *       The last page number when reading log from far behind.
1178      */
1179     UintR execSrStopPageNo;
1180     /**
1181      *       Contains a reference to the first log file, file number 0.
1182      */
1183     UintR firstLogfile;
1184     /**
1185      *       This variable contains the oldest operation in this log
1186      *       part which have not been committed yet.
1187      */
1188     UintR firstLogTcrec;
1189     /**
1190      *       The first reference to a set of 8 pages. These are used
1191      *       during execution of the log to keep track of which pages
1192      *       are in memory and which are not.
1193      */
1194     UintR firstPageRef;
1195     /**
1196      *       This variable contains the global checkpoint record
1197      *       waiting for disk writes to complete.
1198      */
1199     UintR gcprec;
1200     /**
1201      *       The last reference to a set of 8 pages.  These are used
1202      *       during execution of the log to keep track of which pages
1203      *       are in memory and which are not.
1204      */
1205     UintR lastPageRef;
1206 
1207     struct OperationQueue
1208     {
initDblqh::LogPartRecord::OperationQueue1209       void init() { firstElement = lastElement = RNIL;}
isEmptyDblqh::LogPartRecord::OperationQueue1210       bool isEmpty() const { return firstElement == RNIL; }
1211       Uint32 firstElement;
1212       Uint32 lastElement;
1213     };
1214 
1215     /**
1216      * operations queued waiting on REDO to prepare
1217      */
1218     struct OperationQueue m_log_prepare_queue;
1219 
1220     /**
1221      * operations queued waiting on REDO to commit/abort
1222      */
1223     struct OperationQueue m_log_complete_queue;
1224 
1225     /**
1226      *       This variable contains the newest operation in this log
1227      *       part which have not been committed yet.
1228      */
1229     UintR lastLogTcrec;
1230     /**
1231      *       This variable indicates which was the last mbyte that was
1232      *       written before the system crashed.  Discovered during
1233      *       system restart.
1234      */
1235     UintR lastLogfile;
1236     /**
1237      *       This variable is used to keep track of the state during
1238      *       the third phase of the system restart, i.e. when
1239      *       LogPartRecord::logPartState ==
1240      *       LogPartRecord::SR_THIRD_PHASE_STARTED.
1241      */
1242     LogExecState logExecState;
1243     /**
1244      *       This variable contains the lap number of this log part.
1245      */
1246     UintR logLap;
1247     /**
1248      *       This variable contains the place to stop executing the log
1249      *       in this phase.
1250      */
1251     UintR logLastGci;
1252     /**
1253      *       This variable contains the place to start executing the
1254      *       log in this phase.
1255      */
1256     UintR logStartGci;
1257     /**
1258      *       The latest GCI completed in this log part.
1259      */
1260     UintR logPartNewestCompletedGCI;
1261     /**
1262      *       The current state of this log part.
1263      */
1264     LogPartState logPartState;
1265 
1266     /**
1267      * does current log-part have tail-problem (i.e 410)
1268      */
1269     enum {
1270       P_TAIL_PROBLEM        = 0x1,// 410
1271       P_REDO_IO_PROBLEM     = 0x2,// 1234
1272       P_FILE_CHANGE_PROBLEM = 0x4 // 1220
1273     };
1274     Uint32 m_log_problems;
1275 
1276     /**
1277      *       A timer that is set every time a log page is sent to disk.
1278      *       Ensures that log pages are not kept in main memory for
1279      *       more than a certain time.
1280      */
1281     UintR logPartTimer;
1282     /**
1283      *       The current timer which is set by the periodic signal
1284      *       received by LQH
1285      */
1286     UintR logTimer;
1287     /**
1288      *       Contains the number of the log tail file and the mbyte
1289      *       reference within that file.  This information ensures that
1290      *       the tail is not overwritten when writing new log records.
1291      */
1292     UintR logTailFileNo;
1293     /**
1294      *       The TcConnectionrec used during execution of this log part.
1295      */
1296     UintR logTcConrec;
1297     /**
1298      *       The number of pages that currently resides in the main
1299      *       memory buffer.  It does not refer pages that are currently
1300      *       read from the log files.  Only to pages already read
1301      *       from the log file.
1302      */
1303     UintR mmBufferSize;
1304     /**
1305      *       Contains the current number of log files in this log part.
1306      */
1307     UintR noLogFiles;
1308     /**
1309      *       This variable is used only during execution of a log
1310      *       record.  It keeps track of in which page record a log
1311      *       record was started.  It is used then to deduce which
1312      *       pages that are dirty after that the log records on the
1313      *       page have been executed.
1314      *
1315      *       It is also used to find out where to write the invalidate
1316      *       command when that is needed.
1317      */
1318     UintR prevLogpage;
1319     /**
1320      *       The number of files remaining to gather GCI information
1321      *       for during system restart.  Only used if number of files
1322      *       is larger than 60.
1323      */
1324     UintR srRemainingFiles;
1325     /**
1326      *       The log file where to start executing the log during
1327      *       system restart.
1328      */
1329     UintR startLogfile;
1330     /**
1331      *       The last log file in which to execute the log during system
1332      *       restart.
1333      */
1334     UintR stopLogfile;
1335     /**
1336      *       This variable keeps track of when we want to write a complete
1337      *       gci log record but have been blocked by an ongoing log operation.
1338      */
1339     WaitWriteGciLog waitWriteGciLog;
1340     /**
1341      *       The currently executing prepare record starts in this index
1342      *       in the log page.
1343      */
1344     Uint16 execSrLogPageIndex;
1345     /**
1346      *       Which of the four exec_sr's in the fragment is currently executing
1347      */
1348     Uint16 execSrExecuteIndex;
1349     /**
1350      *       The number of pages executed in the current mbyte.
1351      */
1352     Uint16 execSrPagesExecuted;
1353     /**
1354      *       The number of pages read from disk that have arrived and are
1355      *       currently awaiting execution of the log.
1356      */
1357     Uint16 execSrPagesRead;
1358     /**
1359      *       The number of pages read from disk and currently not arrived
1360      *       to the block.
1361      */
1362     Uint16 execSrPagesReading;
1363     /**
1364      *       This variable refers to the new header file where we will
1365      *       start writing the log after a system restart have been completed.
1366      */
1367     Uint16 headFileNo;
1368     /**
1369      *       This variable refers to the page number within the header file.
1370      */
1371     Uint16 headPageNo;
1372     /**
1373      *       This variable refers to the index within the new header
1374      *       page.
1375      */
1376     Uint16 headPageIndex;
1377     /**
1378      *       This variables indicates which was the last mbyte in the last
1379      *       logfile before a system crash. Discovered during system restart.
1380      */
1381     Uint16 lastMbyte;
1382     /**
1383      *       This variable is used only during execution of a log
1384      *       record. It keeps track of in which file page a log
1385      *       record was started.  It is used if it is needed to write a
1386      *       dirty page to disk during log execution (this happens when
1387      *       commit records are invalidated).
1388      */
1389     Uint16 prevFilepage;
1390     /**
1391      *       This is used to save where we were in the execution of log
1392      *       records when we find a commit record that needs to be
1393      *       executed.
1394      *
1395      *       This variable is also used to remember the index where the
1396      *       log type was in the log record. It is only used in this
1397      *       role when finding a commit record that needs to be
1398      *       invalidated.
1399      */
1400     Uint16 savePageIndex;
1401     Uint16 logTailMbyte;
1402     /**
1403      *       The mbyte within the starting log file where to start
1404      *       executing the log.
1405      */
1406     Uint16 startMbyte;
1407     /**
1408      *       The last mbyte in which to execute the log during system
1409      *       restart.
1410      */
1411     Uint16 stopMbyte;
1412    /**
1413      *       This variable refers to the file where invalidation is
1414      *       occuring during system/node restart.
1415      */
1416     Uint16 invalidateFileNo;
1417     /**
1418      *       This variable refers to the page where invalidation is
1419      *       occuring during system/node restart.
1420      */
1421     Uint16 invalidatePageNo;
1422     /**
1423      *       For MT LQH the log part (0-3).
1424      */
1425     Uint16 logPartNo;
1426 
1427     /**
1428      * IO tracker...
1429      */
1430     struct IOTracker m_io_tracker;
1431   }; // Size 164 Bytes
1432   typedef Ptr<LogPartRecord> LogPartRecordPtr;
1433 
1434   /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
1435   /* $$$$$$$                      LOG FILE RECORD                     $$$$$$$ */
1436   /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
1437   /*       THIS RECORD IS ALIGNED TO BE 288 (256 + 32) BYTES.                 */
1438   /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
1439   /**
1440    *              This record contains information about a log file.
1441    *              A log file contains log records from several tables and
1442    *              fragments of a table. LQH can contain more than
1443    *              one log file to ensure faster log processing.
1444    *
1445    *              The number of pages to write to disk at a time is
1446    *              configurable.
1447    */
1448   struct LogFileRecord {
LogFileRecordDblqh::LogFileRecord1449     LogFileRecord() {}
1450 
1451     enum FileChangeState {
1452       NOT_ONGOING = 0,
1453       BOTH_WRITES_ONGOING = 1,
1454       LAST_WRITE_ONGOING = 2,
1455       FIRST_WRITE_ONGOING = 3,
1456       WRITE_PAGE_ZERO_ONGOING = 4
1457     };
1458     enum LogFileStatus {
1459       LFS_IDLE = 0,                     ///< Log file record not in use
1460       CLOSED = 1,                       ///< Log file closed
1461       OPENING_INIT = 2,
1462       OPEN_SR_FRONTPAGE = 3,            ///< Log file opened as part of system
1463                                         ///< restart.  Open file 0 to find
1464                                         ///< the front page of the log part.
1465       OPEN_SR_LAST_FILE = 4,            ///< Open last log file that was written
1466                                         ///< before the system restart.
1467       OPEN_SR_NEXT_FILE = 5,            ///< Open a log file which is 16 files
1468                                         ///< backwards to find the next
1469                                         ///< information about GCPs.
1470       OPEN_EXEC_SR_START = 6,           ///< Log file opened as part of
1471                                         ///< executing
1472                                         ///< log during system restart.
1473       OPEN_EXEC_SR_NEW_MBYTE = 7,
1474       OPEN_SR_FOURTH_PHASE = 8,
1475       OPEN_SR_FOURTH_NEXT = 9,
1476       OPEN_SR_FOURTH_ZERO = 10,
1477       OPENING_WRITE_LOG = 11,           ///< Log file opened as part of writing
1478                                         ///< log during normal operation.
1479       OPEN_EXEC_LOG = 12,
1480       CLOSING_INIT = 13,
1481       CLOSING_SR = 14,                  ///< Log file closed as part of system
1482                                         ///< restart.  Currently trying to
1483                                         ///< find where to start executing the
1484                                         ///< log
1485       CLOSING_EXEC_SR = 15,             ///< Log file closed as part of
1486                                         ///< executing log during system restart
1487       CLOSING_EXEC_SR_COMPLETED = 16,
1488       CLOSING_WRITE_LOG = 17,           ///< Log file closed as part of writing
1489                                         ///< log during normal operation.
1490       CLOSING_EXEC_LOG = 18,
1491       OPEN_INIT = 19,
1492       OPEN = 20,                         ///< Log file open
1493       OPEN_SR_READ_INVALIDATE_PAGES = 21,
1494       CLOSE_SR_READ_INVALIDATE_PAGES = 22,
1495       OPEN_SR_WRITE_INVALIDATE_PAGES = 23,
1496       CLOSE_SR_WRITE_INVALIDATE_PAGES = 24,
1497       OPEN_SR_READ_INVALIDATE_SEARCH_FILES = 25,
1498       CLOSE_SR_READ_INVALIDATE_SEARCH_FILES = 26,
1499       CLOSE_SR_READ_INVALIDATE_SEARCH_LAST_FILE = 27
1500 #ifndef NO_REDO_OPEN_FILE_CACHE
1501       ,OPEN_EXEC_LOG_CACHED = 28
1502       ,CLOSING_EXEC_LOG_CACHED = 29
1503 #endif
1504     };
1505 
1506     /**
1507      *       When a new mbyte is started in the log we have to find out
1508      *       how far back in the log we still have prepared operations
1509      *       which have been neither committed or aborted.  This variable
1510      *       keeps track of this value for each of the mbytes in this
1511      *       log file.  This is used in writing down these values in the
1512      *       header of each log file.  That information is used during
1513      *       system restart to find the tail of the log.
1514      */
1515     UintR *logLastPrepRef;
1516     /**
1517      *       The max global checkpoint completed before the mbyte in the
1518      *       log file was started.  One variable per mbyte.
1519      */
1520     UintR *logMaxGciCompleted;
1521     /**
1522      *       The max global checkpoint started before the mbyte in the log
1523      *       file was started.  One variable per mbyte.
1524      */
1525     UintR *logMaxGciStarted;
1526     /**
1527      *       This variable contains the file name as needed by the file
1528      *       system when opening the file.
1529      */
1530     UintR fileName[4];
1531     /**
1532      *       This variable has a reference to the log page which is
1533      *       currently in use by the log.
1534      */
1535     UintR currentLogpage;
1536     /**
1537      *       The number of the current mbyte in the log file.
1538      */
1539     UintR currentMbyte;
1540     /**
1541      *       This variable is used when changing files.  It is to find
1542      *       out when both the last write in the previous file and the
1543      *       first write in this file has been completed.  After these
1544      *       writes have completed the variable keeps track of when the
1545      *       write to page zero in file zero is completed.
1546      */
1547     FileChangeState fileChangeState;
1548     /**
1549      *       The number of the file within this log part.
1550      */
1551     UintR fileNo;
1552     /**
1553      *       This variable shows where to read/write the next pages into
1554      *       the log.  Used when writing the log during normal operation
1555      *       and when reading the log during system restart.  It
1556      *       specifies the page position where each page is 8 kbyte.
1557      */
1558     UintR filePosition;
1559     /**
1560      *       This contains the file pointer needed by the file system
1561      *       when reading/writing/closing and synching.
1562      */
1563     UintR fileRef;
1564     /**
1565      *       The head of the pages waiting for shipment to disk.
1566      *       They are filled with log info.
1567      */
1568     UintR firstFilledPage;
1569     /**
1570      *       A list of active read/write operations on the log file.
1571      *       Operations are always put in last and the first should
1572      *       always complete first.
1573      */
1574     UintR firstLfo;
1575     UintR lastLfo;
1576     /**
1577      *       The tail of the pages waiting for shipment to disk.
1578      *       They are filled with log info.
1579      */
1580     UintR lastFilledPage;
1581     /**
1582      *       This variable keeps track of the last written page in the
1583      *       file while writing page zero in file zero when changing log
1584      *       file.
1585      */
1586     UintR lastPageWritten;
1587     /**
1588      *       This variable keeps track of the last written word in the
1589      *       last page written in the file while writing page zero in
1590      *       file zero when changing log file.
1591      */
1592     UintR lastWordWritten;
1593     /**
1594      *       This variable contains the last word written in the last page.
1595      */
1596     LogFileStatus logFileStatus;
1597     /**
1598      *       A reference to page zero in this file.
1599      *       This page is written before the file is closed.
1600      */
1601     UintR logPageZero;
1602     /**
1603      *       This variable contains a reference to the record describing
1604      *       this log part.   One of four records (0,1,2 or 3).
1605      */
1606     UintR logPartRec;
1607     /**
1608      *       Next free log file record or next log file in this log.
1609      */
1610     UintR nextLogFile;
1611     /**
1612      *       The previous log file.
1613      */
1614     UintR prevLogFile;
1615     /**
1616      *       The number of remaining words in this mbyte of the log file.
1617      */
1618     UintR remainingWordsInMbyte;
1619     /**
1620      *       The current file page within the current log file. This is
1621      *       a reference within the file and not a reference to a log
1622      *       page record.  It is used to deduce where log records are
1623      *       written.  Particularly completed gcp records and prepare log
1624      *       records.
1625      */
1626     Uint16 currentFilepage;
1627     /**
1628      *       The number of pages in the list referenced by
1629      *       LOG_PAGE_BUFFER.
1630      */
1631     Uint16 noLogpagesInBuffer;
1632 
1633 #ifndef NO_REDO_OPEN_FILE_CACHE
1634     Uint32 nextList;
1635     Uint32 prevList;
1636 #endif
1637   }; // Size 288 bytes
1638   typedef Ptr<LogFileRecord> LogFileRecordPtr;
1639 
1640   /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
1641   /* $$$$$$$                      LOG OPERATION RECORD                $$$$$$$ */
1642   /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
1643   /**
1644    * This record contains a currently active file operation
1645    * that has started by the log module.
1646    */
1647   struct LogFileOperationRecord {
1648     enum LfoState {
1649       IDLE = 0,                         ///< Operation is not used at the moment
1650       INIT_WRITE_AT_END = 1,            ///< Write in file so that it grows to
1651                                         ///< 16 Mbyte
1652       INIT_FIRST_PAGE = 2,              ///< Initialise the first page in a file
1653       WRITE_GCI_ZERO = 3,
1654       WRITE_INIT_MBYTE = 4,
1655       WRITE_DIRTY = 5,
1656       READ_SR_FRONTPAGE = 6,            ///< Read page zero in file zero during
1657                                         ///< system restart
1658       READ_SR_LAST_FILE = 7,            ///< Read page zero in last file open
1659                                         ///< before system crash
1660       READ_SR_NEXT_FILE = 8,            ///< Read 60 files backwards to find
1661                                         ///< further information GCPs in page
1662                                         ///< zero
1663       READ_SR_LAST_MBYTE = 9,
1664       READ_EXEC_SR = 10,
1665       READ_EXEC_LOG = 11,
1666       READ_SR_FOURTH_PHASE = 12,
1667       READ_SR_FOURTH_ZERO = 13,
1668       FIRST_PAGE_WRITE_IN_LOGFILE = 14,
1669       LAST_WRITE_IN_FILE = 15,
1670       WRITE_PAGE_ZERO = 16,
1671       ACTIVE_WRITE_LOG = 17,             ///< A write operation during
1672                                         ///< writing of log
1673       READ_SR_INVALIDATE_PAGES = 18,
1674       WRITE_SR_INVALIDATE_PAGES = 19,
1675       WRITE_SR_INVALIDATE_PAGES_UPDATE_PAGE0 = 20
1676       ,READ_SR_INVALIDATE_SEARCH_FILES = 21
1677     };
1678     /**
1679      * We have to remember the log pages read.
1680      * Otherwise we cannot build the linked list after the pages have
1681      * arrived to main memory.
1682      */
1683     UintR logPageArray[16];
1684     /**
1685      * A list of the pages that are part of this active operation.
1686      */
1687     UintR firstLfoPage;
1688     /**
1689      * A timer to ensure that records are not lost.
1690      */
1691     UintR lfoTimer;
1692     /**
1693      * The word number of the last written word in the last during
1694      * a file write.
1695      */
1696     UintR lfoWordWritten;
1697     /**
1698      * This variable contains the state of the log file operation.
1699      */
1700     LfoState lfoState;
1701     /**
1702      * The log file that the file operation affects.
1703      */
1704     UintR logFileRec;
1705     /**
1706      * The log file operations on a file are kept in a linked list.
1707      */
1708     UintR nextLfo;
1709     /**
1710      * The page number of the first read/written page during a file
1711      * read/write.
1712      */
1713     Uint16 lfoPageNo;
1714     /**
1715      * The number of pages written or read during an operation to
1716      * the log file.
1717      */
1718     Uint16 noPagesRw;
1719   }; // 92 bytes
1720   typedef Ptr<LogFileOperationRecord> LogFileOperationRecordPtr;
1721 
1722   /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
1723   /* $$$$$$$                      LOG PAGE RECORD                     $$$$$$$ */
1724   /* $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
1725   /**
1726    *    These are the 8 k pages used to store log records before storing
1727    *    them in the file system.
1728    *    Since 64 kbyte is sent to disk at a time it is necessary to have
1729    *    at least 4*64 kbytes of log pages.
1730    *    To handle multiple outstanding requests we need some additional pages.
1731    *    Thus we allocate 1 mbyte to ensure that we do not get problems with
1732    *    insufficient number of pages.
1733    */
1734   struct LogPageRecord {
1735     /**
1736      * This variable contains the pages that are sent to disk.
1737      *
1738      * All pages contain a header of 12 words:
1739      * - WORD 0:  CHECKSUM             Calculated before storing on disk and
1740      *                                 checked when read from disk.
1741      * - WORD 1:  LAP                  How many wraparounds have the log
1742      *                                 experienced since initial start of the
1743      *                                 system.
1744      * - WORD 2:  MAX_GCI_COMPLETED    Which is the maximum gci which have
1745      *                                 completed before this page. This
1746      *                                 gci will not be found in this
1747      *                                 page and hereafter in the log.
1748      * - WORD 3:  MAX_GCI_STARTED      The maximum gci which have started
1749      *                                 before this page.
1750      * - WORD 4:  NEXT_PAGE            Pointer to the next page.
1751      *                                 Only used in main memory
1752      * - WORD 5:  PREVIOUS_PAGE        Pointer to the previous page.
1753      *                                 Currently not used.
1754      * - WORD 6:  VERSION              NDB version that wrote the page.
1755      * - WORD 7:  NO_LOG_FILES         Number of log files in this log part.
1756      * - WORD 8:  CURRENT PAGE INDEX   This keeps track of where we are in the
1757      *                                 page.
1758      *                                 This is only used when pages is in
1759      *                                 memory.
1760      * - WORD 9:  OLD PREPARE FILE NO  This keeps track of the oldest prepare
1761      *                                 operation still alive (not committed
1762      *                                 or aborted) when this mbyte started.
1763      * - WORD 10: OLD PREPARE PAGE REF File page reference within this file
1764      *                                 number.
1765      *                                 Page no + Page index.
1766      *                                 If no prepare was alive then these
1767      *                                 values points this mbyte.
1768      * - WORD 11: DIRTY FLAG            = 0 means not dirty and
1769      *                                  = 1 means the page is dirty.
1770      *                                 Is used when executing log when
1771      *                                 a need to write invalid commit
1772      *                                 records arise.
1773      *
1774      * The remaining 2036 words are used for log information, i.e.
1775      * log records.
1776      *
1777      * A log record on this page has the following layout:
1778      * - WORD 0: LOG RECORD TYPE
1779      *     The following types are supported:
1780      *     - PREPARE OPERATION       An operation not yet committed.
1781      *     - NEW PREPARE OPERATION   A prepared operation already
1782      *                               logged is inserted
1783      *                               into the log again so that the
1784      *                               log tail can be advanced.
1785      *                               This can happen when a transaction is
1786      *                               committed for a long time.
1787      *     - ABORT TRANSACTION       A previously prepared transaction
1788      *                               was aborted.
1789      *     - COMMIT TRANSACTION      A previously prepared transaction
1790      *                               was committed.
1791      *     - INVALID COMMIT          A previous commit record was
1792      *                               invalidated by a
1793      *                               subsequent system restart.
1794      *                               A log record must be invalidated
1795      *                               in a system restart if it belongs
1796      *                               to a global checkpoint id which
1797      *                               is not included in the system
1798      *                               restart.
1799      *                               Otherwise it will be included in
1800      *                               a subsequent system restart since
1801      *                               it will then most likely belong
1802      *                               to a global checkpoint id which
1803      *                               is part of that system
1804      *                               restart.
1805      *                               This is not a correct behaviour
1806      *                               since this operation is lost in a
1807      *                               system restart and should not
1808      *                               reappear at a later system
1809      *                               restart.
1810      *     - COMPLETED GCI           A GCI has now been completed.
1811      *     - FRAGMENT SPLIT          A fragment has been split
1812      *                               (not implemented yet)
1813      *     - FILE DESCRIPTOR         This is always the first log record
1814      *                               in a file.
1815      *                               It is always placed on page 0 after
1816      *                               the header.
1817      *                               It is written when the file is
1818      *                               opened and when the file is closed.
1819      *     - NEXT LOG RECORD         This log record only records where
1820      *                               the next log record starts.
1821      *     - NEXT MBYTE RECORD       This log record specifies that there
1822      *                               are no more log records in this mbyte.
1823      *
1824      *
1825      * A FILE DESCRIPTOR log record continues as follows:
1826      * - WORD 1: NO_LOG_DESCRIPTORS  This defines the number of
1827      *                               descriptors of log files that
1828      *                               will follow hereafter (max 32).
1829      *                               the log descriptor will describe
1830      *                               information about
1831      *                               max_gci_completed,
1832      *                               max_gci_started and log_lap at
1833      *                               every 1 mbyte of the log file
1834      *                               since a log file is 16 mbyte
1835      *                               always, i need 16 entries in the
1836      *                               array with max_gci_completed,
1837      *                               max_gci_started and log_lap. thus
1838      *                               32 entries per log file
1839      *                               descriptor (max 32*48 = 1536,
1840      *                               always fits in page 0).
1841      * - WORD 2: LAST LOG FILE       The number of the log file currently
1842      *                               open.  This is only valid in file 0.
1843      * - WORD 3 - WORD 18:           MAX_GCI_COMPLETED for every 1 mbyte
1844      *                               in this log file.
1845      * - WORD 19 - WORD 34:          MAX_GCI_STARTED for every 1 mbyte
1846      *                               in this log file.
1847      *
1848      * Then it continues for NO_LOG_DESCRIPTORS until all subsequent
1849      * log files (max 32) have been properly described.
1850      *
1851      *
1852      * A PREPARE OPERATION log record continues as follows:
1853      * - WORD 1: LOG RECORD SIZE
1854      * - WORD 2: HASH VALUE
1855      * - WORD 3: SCHEMA VERSION
1856      * - WORD 4: OPERATION TYPE
1857      *            = 0 READ,
1858      *            = 1 UPDATE,
1859      *            = 2 INSERT,
1860      *            = 3 DELETE
1861      * - WORD 5: NUMBER OF WORDS IN ATTRINFO PART
1862      * - WORD 6: KEY LENGTH IN WORDS
1863      * - WORD 7 - (WORD 7 + KEY_LENGTH - 1)                 The tuple key
1864      * - (WORD 7 + KEY_LENGTH) -
1865      *   (WORD 7 + KEY_LENGTH + ATTRINFO_LENGTH - 1)        The attrinfo
1866      *
1867      * A log record can be spread in several pages in some cases.
1868      * The next log record always starts immediately after this log record.
1869      * A log record does however never traverse a 1 mbyte boundary.
1870      * This is used to ensure that we can always come back if something
1871      * strange occurs in the log file.
1872      * To ensure this we also have log records which only records
1873      * the next log record.
1874      *
1875      *
1876      * A COMMIT TRANSACTION log record continues as follows:
1877      * - WORD 1: TRANSACTION ID PART 1
1878      * - WORD 2: TRANSACTION ID PART 2
1879      * - WORD 3: FRAGMENT ID OF THE OPERATION
1880      * - WORD 4: TABLE ID OF THE OPERATION
1881      * - WORD 5: THE FILE NUMBER OF THE PREPARE RECORD
1882      * - WORD 6: THE STARTING PAGE NUMBER OF THE PREPARE RECORD
1883      * - WORD 7: THE STARTING PAGE INDEX OF THE PREPARE RECORD
1884      * - WORD 8: THE STOP PAGE NUMBER OF THE PREPARE RECORD
1885      * - WORD 9: GLOBAL CHECKPOINT OF THE TRANSACTION
1886      *
1887      *
1888      * An ABORT TRANSACTION log record continues as follows:
1889      * - WORD 1: TRANSACTION ID PART 1
1890      * - WORD 2: TRANSACTION ID PART 2
1891      *
1892      *
1893      * A COMPLETED CGI log record continues as follows:
1894      * - WORD 1: THE COMPLETED GCI
1895      *
1896      *
1897      * A NEXT LOG RECORD log record continues as follows:
1898      * - There is no more information needed.
1899      *   The next log record will always refer to the start of the next page.
1900      *
1901      * A NEXT MBYTE RECORD log record continues as follows:
1902      * - There is no more information needed.
1903      *   The next mbyte will always refer to the start of the next mbyte.
1904      */
1905     UintR logPageWord[8192]; // Size 32 kbytes
1906   };
1907   typedef Ptr<LogPageRecord> LogPageRecordPtr;
1908 
1909   struct PageRefRecord {
1910     UintR pageRef[8];
1911     UintR prNext;
1912     UintR prPrev;
1913     Uint16 prFileNo;
1914     Uint16 prPageNo;
1915   }; // size 44 bytes
1916   typedef Ptr<PageRefRecord> PageRefRecordPtr;
1917 
1918   struct Tablerec {
1919     enum TableStatus {
1920       TABLE_DEFINED = 0,
1921       NOT_DEFINED = 1,
1922       ADD_TABLE_ONGOING = 2,
1923       PREP_DROP_TABLE_DONE = 3,
1924       DROP_TABLE_WAIT_USAGE = 4,
1925       DROP_TABLE_WAIT_DONE = 5,
1926       DROP_TABLE_ACC = 6,
1927       DROP_TABLE_TUP = 7,
1928       DROP_TABLE_TUX = 8
1929       ,TABLE_READ_ONLY = 9
1930     };
1931 
1932     UintR fragrec[MAX_FRAG_PER_NODE];
1933     Uint16 fragid[MAX_FRAG_PER_NODE];
1934     /**
1935      * Status of the table
1936      */
1937     TableStatus tableStatus;
1938     /**
1939      * Table type and target table of index.
1940      */
1941     Uint16 tableType;
1942     Uint16 primaryTableId;
1943     Uint32 schemaVersion;
1944     Uint8 m_disk_table;
1945 
1946     Uint32 usageCountR; // readers
1947     Uint32 usageCountW; // writers
1948   }; // Size 100 bytes
1949   typedef Ptr<Tablerec> TablerecPtr;
1950 
1951   struct TcConnectionrec {
1952     enum ListState {
1953       NOT_IN_LIST = 0,
1954       WAIT_QUEUE_LIST = 3
1955     };
1956     enum LogWriteState {
1957       NOT_STARTED = 0,
1958       NOT_WRITTEN = 1,
1959       NOT_WRITTEN_WAIT = 2,
1960       WRITTEN = 3
1961     };
1962     enum AbortState {
1963       ABORT_IDLE = 0,
1964       ABORT_ACTIVE = 1,
1965       NEW_FROM_TC = 2,
1966       REQ_FROM_TC = 3,
1967       ABORT_FROM_TC = 4,
1968       ABORT_FROM_LQH = 5
1969     };
1970     enum TransactionState {
1971       IDLE = 0,
1972 
1973       /* -------------------------------------------------------------------- */
1974       // Transaction in progress states
1975       /* -------------------------------------------------------------------- */
1976       WAIT_ACC = 1,
1977       WAIT_TUPKEYINFO = 2,
1978       WAIT_ATTR = 3,
1979       WAIT_TUP = 4,
1980       STOPPED = 5,
1981       LOG_QUEUED = 6,
1982       PREPARED = 7,
1983       LOG_COMMIT_WRITTEN_WAIT_SIGNAL = 8,
1984       LOG_COMMIT_QUEUED_WAIT_SIGNAL = 9,
1985 
1986       /* -------------------------------------------------------------------- */
1987       // Commit in progress states
1988       /* -------------------------------------------------------------------- */
1989       COMMIT_STOPPED = 10,
1990       LOG_COMMIT_QUEUED = 11,
1991       COMMIT_QUEUED = 12,
1992       COMMITTED = 13,
1993       WAIT_TUP_COMMIT= 35,
1994 
1995       /* -------------------------------------------------------------------- */
1996       // Abort in progress states
1997       /* -------------------------------------------------------------------- */
1998       WAIT_ACC_ABORT = 14,
1999       ABORT_QUEUED = 15,
2000       ABORT_STOPPED = 16,
2001       WAIT_AI_AFTER_ABORT = 17,
2002       LOG_ABORT_QUEUED = 18,
2003       WAIT_TUP_TO_ABORT = 19,
2004 
2005       /* -------------------------------------------------------------------- */
2006       // Scan in progress states
2007       /* -------------------------------------------------------------------- */
2008       WAIT_SCAN_AI = 20,
2009       SCAN_STATE_USED = 21,
2010       SCAN_FIRST_STOPPED = 22,
2011       SCAN_CHECK_STOPPED = 23,
2012       SCAN_STOPPED = 24,
2013       SCAN_RELEASE_STOPPED = 25,
2014       SCAN_CLOSE_STOPPED = 26,
2015       COPY_CLOSE_STOPPED = 27,
2016       COPY_FIRST_STOPPED = 28,
2017       COPY_STOPPED = 29,
2018       SCAN_TUPKEY = 30,
2019       COPY_TUPKEY = 31,
2020 
2021       TC_NOT_CONNECTED = 32,
2022       PREPARED_RECEIVED_COMMIT = 33, // Temporary state in write commit log
2023       LOG_COMMIT_WRITTEN = 34        // Temporary state in write commit log
2024     };
2025     enum ConnectState {
2026       DISCONNECTED = 0,
2027       CONNECTED = 1,
2028       COPY_CONNECTED = 2,
2029       LOG_CONNECTED = 3
2030     };
2031     ConnectState connectState;
2032     UintR copyCountWords;
2033     Uint32 keyInfoIVal;
2034     Uint32 attrInfoIVal;
2035     UintR transid[2];
2036     AbortState abortState;
2037     UintR accConnectrec;
2038     UintR applOprec;
2039     UintR clientConnectrec;
2040     UintR tcTimer;
2041     UintR currReclenAi;
2042     UintR currTupAiLen;
2043     UintR fragmentid;
2044     UintR fragmentptr;
2045     UintR gci_hi;
2046     UintR gci_lo;
2047     UintR hashValue;
2048     /**
2049      * Each operation (TcConnectrec) can be stored in max one out of many
2050      * lists.
2051      * This variable keeps track of which list it is in.
2052      */
2053     ListState listState;
2054 
2055     UintR logStartFileNo;
2056     LogWriteState logWriteState;
2057     UintR nextHashRec;
2058     UintR nextLogTcrec;
2059     UintR nextTcLogQueue;
2060     UintR nextTc;
2061     UintR nextTcConnectrec;
2062     UintR prevHashRec;
2063     UintR prevLogTcrec;
2064     UintR prevTc;
2065     UintR readlenAi;
2066     UintR reqRef;
2067     UintR reqinfo;
2068     UintR schemaVersion;
2069     UintR storedProcId;
2070     UintR simpleTcConnect;
2071     UintR tableref;
2072     UintR tcOprec;
2073     Uint32 tcHashKeyHi;
2074     UintR tcScanInfo;
2075     UintR tcScanRec;
2076     UintR totReclenAi;
2077     UintR totSendlenAi;
2078     UintR tupConnectrec;
2079     UintR savePointId;
2080     TransactionState transactionState;
2081     BlockReference applRef;
2082     BlockReference clientBlockref;
2083 
2084     BlockReference reqBlockref;
2085     BlockReference tcBlockref;
2086     BlockReference tcAccBlockref;
2087     BlockReference tcTuxBlockref;
2088     BlockReference tcTupBlockref;
2089     Uint32 commitAckMarker;
2090     union {
2091       Uint32 m_scan_curr_range_no;
2092       UintR noFiredTriggers;
2093     };
2094     Uint32 m_corrFactorLo; // For result correlation for linked operations.
2095     Uint32 m_corrFactorHi;
2096     Uint64 lqhKeyReqId;
2097     Uint16 errorCode;
2098     Uint16 logStartPageIndex;
2099     Uint16 logStartPageNo;
2100     Uint16 logStopPageNo;
2101     Uint16 nextReplica;
2102     Uint16 primKeyLen;
2103     Uint16 save1;
2104     Uint16 nodeAfterNext[3];
2105 
2106     Uint8 activeCreat;
2107     Uint8 apiVersionNo;
2108     Uint8 dirtyOp;
2109     Uint8 indTakeOver;
2110     Uint8 lastReplicaNo;
2111     Uint8 lockType;
2112     Uint8 nextSeqNoReplica;
2113     Uint8 opSimple;
2114     Uint8 opExec;
2115     Uint8 operation;
2116     Uint8 m_reorg;
2117     Uint8 reclenAiLqhkey;
2118     Uint8 replicaType;
2119     Uint8 seqNoReplica;
2120     Uint8 tcNodeFailrec;
2121     Uint8 m_disk_table;
2122     Uint8 m_use_rowid;
2123     Uint8 m_dealloc;
2124     Uint8 m_fire_trig_pass;
2125     enum op_flags {
2126       OP_ISLONGREQ              = 0x1,
2127       OP_SAVEATTRINFO           = 0x2,
2128       OP_SCANKEYINFOPOSSAVED    = 0x4,
2129       OP_DEFERRED_CONSTRAINTS   = 0x8
2130     };
2131     Uint32 m_flags;
2132     Uint32 m_log_part_ptr_i;
2133     SectionReader::PosInfo scanKeyInfoPos;
2134     Local_key m_row_id;
2135 
2136     struct {
2137       Uint32 m_cnt;
2138       Uint32 m_page_id[2];
2139       Local_key m_disk_ref[2];
2140     } m_nr_delete;
2141   }; /* p2c: size = 280 bytes */
2142 
2143   typedef Ptr<TcConnectionrec> TcConnectionrecPtr;
2144 
2145   struct TcNodeFailRecord {
2146     enum TcFailStatus {
2147       TC_STATE_TRUE = 0,
2148       TC_STATE_FALSE = 1,
2149       TC_STATE_BREAK = 2
2150     };
2151     UintR lastNewTcRef;
2152     UintR newTcRef;
2153     TcFailStatus tcFailStatus;
2154     UintR tcRecNow;
2155     BlockReference lastNewTcBlockref;
2156     BlockReference newTcBlockref;
2157     Uint16 oldNodeId;
2158   }; // Size 28 bytes
2159   typedef Ptr<TcNodeFailRecord> TcNodeFailRecordPtr;
2160 
2161   struct CommitLogRecord {
2162     Uint32 startPageNo;
2163     Uint32 startPageIndex;
2164     Uint32 stopPageNo;
2165     Uint32 fileNo;
2166   };
2167   //for statistic information about redo log initialization
2168   Uint32 totalLogFiles;
2169   Uint32 logFileInitDone;
2170   Uint32 totallogMBytes;
2171   Uint32 logMBytesInitDone;
2172 
2173   Uint32 m_startup_report_frequency;
2174   NDB_TICKS m_next_report_time;
2175 
2176 public:
2177   Dblqh(Block_context& ctx, Uint32 instanceNumber = 0);
2178   virtual ~Dblqh();
2179 
2180   void receive_keyinfo(Signal*, Uint32 * data, Uint32 len);
2181   void receive_attrinfo(Signal*, Uint32 * data, Uint32 len);
2182 
2183 private:
2184   BLOCK_DEFINES(Dblqh);
2185 
2186   void execPACKED_SIGNAL(Signal* signal);
2187   void execDEBUG_SIG(Signal* signal);
2188   void execATTRINFO(Signal* signal);
2189   void execKEYINFO(Signal* signal);
2190   void execLQHKEYREQ(Signal* signal);
2191   void execLQHKEYREF(Signal* signal);
2192   void execCOMMIT(Signal* signal);
2193   void execCOMPLETE(Signal* signal);
2194   void execLQHKEYCONF(Signal* signal);
2195   void execTESTSIG(Signal* signal);
2196   void execLQH_RESTART_OP(Signal* signal);
2197   void execCONTINUEB(Signal* signal);
2198   void execSTART_RECREQ(Signal* signal);
2199   void execSTART_RECCONF(Signal* signal);
2200   void execEXEC_FRAGREQ(Signal* signal);
2201   void execEXEC_FRAGCONF(Signal* signal);
2202   void execEXEC_FRAGREF(Signal* signal);
2203   void execSTART_EXEC_SR(Signal* signal);
2204   void execEXEC_SRREQ(Signal* signal);
2205   void execEXEC_SRCONF(Signal* signal);
2206   void execREAD_PSEUDO_REQ(Signal* signal);
2207   void execSIGNAL_DROPPED_REP(Signal* signal);
2208 
2209   void execDBINFO_SCANREQ(Signal* signal);
2210   void execDUMP_STATE_ORD(Signal* signal);
2211   void execACC_ABORTCONF(Signal* signal);
2212   void execNODE_FAILREP(Signal* signal);
2213   void execCHECK_LCP_STOP(Signal* signal);
2214   void execSEND_PACKED(Signal* signal);
2215   void execTUP_ATTRINFO(Signal* signal);
2216   void execREAD_CONFIG_REQ(Signal* signal);
2217 
2218   void execCREATE_TAB_REQ(Signal* signal);
2219   void execCREATE_TAB_REF(Signal* signal);
2220   void execCREATE_TAB_CONF(Signal* signal);
2221   void execLQHADDATTREQ(Signal* signal);
2222   void execTUP_ADD_ATTCONF(Signal* signal);
2223   void execTUP_ADD_ATTRREF(Signal* signal);
2224 
2225   void execLQHFRAGREQ(Signal* signal);
2226   void execACCFRAGCONF(Signal* signal);
2227   void execACCFRAGREF(Signal* signal);
2228   void execTUPFRAGCONF(Signal* signal);
2229   void execTUPFRAGREF(Signal* signal);
2230 
2231   void execDROP_FRAG_REQ(Signal*);
2232   void execDROP_FRAG_REF(Signal*);
2233   void execDROP_FRAG_CONF(Signal*);
2234 
2235   void execTAB_COMMITREQ(Signal* signal);
2236   void execACCSEIZECONF(Signal* signal);
2237   void execACCSEIZEREF(Signal* signal);
2238   void execREAD_NODESCONF(Signal* signal);
2239   void execREAD_NODESREF(Signal* signal);
2240   void execSTTOR(Signal* signal);
2241   void execNDB_STTOR(Signal* signal);
2242   void execTUPSEIZECONF(Signal* signal);
2243   void execTUPSEIZEREF(Signal* signal);
2244   void execACCKEYCONF(Signal* signal);
2245   void execACCKEYREF(Signal* signal);
2246   void execTUPKEYCONF(Signal* signal);
2247   void execTUPKEYREF(Signal* signal);
2248   void execABORT(Signal* signal);
2249   void execABORTREQ(Signal* signal);
2250   void execCOMMITREQ(Signal* signal);
2251   void execCOMPLETEREQ(Signal* signal);
2252   void execMEMCHECKREQ(Signal* signal);
2253   void execSCAN_FRAGREQ(Signal* signal);
2254   void execSCAN_NEXTREQ(Signal* signal);
2255   void execACC_SCANCONF(Signal* signal);
2256   void execACC_SCANREF(Signal* signal);
2257   void execNEXT_SCANCONF(Signal* signal);
2258   void execNEXT_SCANREF(Signal* signal);
2259   void execACC_TO_REF(Signal* signal);
2260   void execSTORED_PROCCONF(Signal* signal);
2261   void execSTORED_PROCREF(Signal* signal);
2262   void execCOPY_FRAGREQ(Signal* signal);
2263   void execCOPY_FRAGREF(Signal* signal);
2264   void execCOPY_FRAGCONF(Signal* signal);
2265   void execPREPARE_COPY_FRAG_REQ(Signal* signal);
2266   void execUPDATE_FRAG_DIST_KEY_ORD(Signal*);
2267   void execCOPY_ACTIVEREQ(Signal* signal);
2268   void execCOPY_STATEREQ(Signal* signal);
2269   void execLQH_TRANSREQ(Signal* signal);
2270   void execTRANSID_AI(Signal* signal);
2271   void execINCL_NODEREQ(Signal* signal);
2272 
2273   void force_lcp(Signal* signal);
2274   void execLCP_FRAG_ORD(Signal* signal);
2275   void execEMPTY_LCP_REQ(Signal* signal);
2276 
2277   void execSTART_FRAGREQ(Signal* signal);
2278   void execSTART_RECREF(Signal* signal);
2279 
2280   void execGCP_SAVEREQ(Signal* signal);
2281   void execSUB_GCP_COMPLETE_REP(Signal* signal);
2282   void execFSOPENREF(Signal* signal);
2283   void execFSOPENCONF(Signal* signal);
2284   void execFSCLOSECONF(Signal* signal);
2285   void execFSWRITECONF(Signal* signal);
2286   void execFSWRITEREF(Signal* signal);
2287   void execFSREADCONF(Signal* signal);
2288   void execFSREADREF(Signal* signal);
2289   void execFSWRITEREQ(Signal*);
2290   void execTIME_SIGNAL(Signal* signal);
2291   void execFSSYNCCONF(Signal* signal);
2292 
2293   void execALTER_TAB_REQ(Signal* signal);
2294   void execALTER_TAB_CONF(Signal* signal);
2295 
2296   void execCREATE_TRIG_IMPL_CONF(Signal* signal);
2297   void execCREATE_TRIG_IMPL_REF(Signal* signal);
2298   void execCREATE_TRIG_IMPL_REQ(Signal* signal);
2299 
2300   void execDROP_TRIG_IMPL_CONF(Signal* signal);
2301   void execDROP_TRIG_IMPL_REF(Signal* signal);
2302   void execDROP_TRIG_IMPL_REQ(Signal* signal);
2303 
2304   void execPREP_DROP_TAB_REQ(Signal* signal);
2305   void execDROP_TAB_REQ(Signal* signal);
2306   void execDROP_TAB_REF(Signal*);
2307   void execDROP_TAB_CONF(Signal*);
2308   void dropTable_nextStep(Signal*, AddFragRecordPtr);
2309 
2310   void execLQH_ALLOCREQ(Signal* signal);
2311   void execTUP_DEALLOCREQ(Signal* signal);
2312   void execLQH_WRITELOG_REQ(Signal* signal);
2313 
2314   void execTUXFRAGCONF(Signal* signal);
2315   void execTUXFRAGREF(Signal* signal);
2316   void execTUX_ADD_ATTRCONF(Signal* signal);
2317   void execTUX_ADD_ATTRREF(Signal* signal);
2318 
2319   void execBUILD_INDX_IMPL_REF(Signal* signal);
2320   void execBUILD_INDX_IMPL_CONF(Signal* signal);
2321 
2322   void execFIRE_TRIG_REQ(Signal*);
2323 
2324   // Statement blocks
2325 
2326   void init_acc_ptr_list(ScanRecord*);
2327   bool seize_acc_ptr_list(ScanRecord*, Uint32, Uint32);
2328   void release_acc_ptr_list(ScanRecord*);
2329   Uint32 get_acc_ptr_from_scan_record(ScanRecord*, Uint32, bool);
2330   void set_acc_ptr_in_scan_record(ScanRecord*, Uint32, Uint32);
2331   void i_get_acc_ptr(ScanRecord*, Uint32*&, Uint32);
2332 
2333   void removeTable(Uint32 tableId);
2334   void sendLCP_COMPLETE_REP(Signal* signal, Uint32 lcpId);
2335   void sendEMPTY_LCP_CONF(Signal* signal, bool idle);
2336   void sendLCP_FRAGIDREQ(Signal* signal);
2337   void sendLCP_FRAG_REP(Signal * signal, const LcpRecord::FragOrd &,
2338                         const Fragrecord*) const;
2339 
2340   void updatePackedList(Signal* signal, HostRecord * ahostptr, Uint16 hostId);
2341   void LQHKEY_abort(Signal* signal, int errortype);
2342   void LQHKEY_error(Signal* signal, int errortype);
2343   void nextRecordCopy(Signal* signal);
2344   Uint32 calculateHash(Uint32 tableId, const Uint32* src);
2345   void continueAfterCheckLcpStopBlocked(Signal* signal);
2346   void checkLcpStopBlockedLab(Signal* signal);
2347   void sendCommittedTc(Signal* signal, BlockReference atcBlockref);
2348   void sendCompletedTc(Signal* signal, BlockReference atcBlockref);
2349   void sendLqhkeyconfTc(Signal* signal, BlockReference atcBlockref);
2350   void sendCommitLqh(Signal* signal, BlockReference alqhBlockref);
2351   void sendCompleteLqh(Signal* signal, BlockReference alqhBlockref);
2352   void sendPackedSignalLqh(Signal* signal, HostRecord * ahostptr);
2353   void sendPackedSignalTc(Signal* signal, HostRecord * ahostptr);
2354   void cleanUp(Signal* signal);
2355   void sendAttrinfoLoop(Signal* signal);
2356   void sendAttrinfoSignal(Signal* signal);
2357   void sendLqhAttrinfoSignal(Signal* signal);
2358   void sendKeyinfoAcc(Signal* signal, Uint32 pos);
2359   Uint32 initScanrec(const class ScanFragReq *,
2360                      Uint32 aiLen);
2361   void initScanTc(const class ScanFragReq *,
2362                   Uint32 transid1,
2363                   Uint32 transid2,
2364                   Uint32 fragId,
2365                   Uint32 nodeId,
2366                   Uint32 hashHi);
2367   void finishScanrec(Signal* signal);
2368   void releaseScanrec(Signal* signal);
2369   void seizeScanrec(Signal* signal);
2370   Uint32 sendKeyinfo20(Signal* signal, ScanRecord *, TcConnectionrec *);
2371   void sendTCKEYREF(Signal*, Uint32 dst, Uint32 route, Uint32 cnt);
2372   void sendScanFragConf(Signal* signal, Uint32 scanCompleted);
2373   void initCopyrec(Signal* signal);
2374   void initCopyTc(Signal* signal, Operation_t);
2375   void sendCopyActiveConf(Signal* signal,Uint32 tableId);
2376   void checkLcpCompleted(Signal* signal);
2377   void checkLcpHoldop(Signal* signal);
2378   bool checkLcpStarted(Signal* signal);
2379   void checkLcpTupprep(Signal* signal);
2380   void getNextFragForLcp(Signal* signal);
2381   void sendAccContOp(Signal* signal);
2382   void sendStartLcp(Signal* signal);
2383   void setLogTail(Signal* signal, Uint32 keepGci);
2384   Uint32 remainingLogSize(const LogFileRecordPtr &sltCurrLogFilePtr,
2385 			  const LogPartRecordPtr &sltLogPartPtr);
2386   bool checkGcpCompleted(Signal* signal, Uint32 pageWritten, Uint32 wordWritten);
2387   void initFsopenconf(Signal* signal);
2388   void initFsrwconf(Signal* signal, bool write);
2389   void initLfo(Signal* signal);
2390   void initLogfile(Signal* signal, Uint32 fileNo);
2391   void initLogpage(Signal* signal);
2392   void openFileRw(Signal* signal, LogFileRecordPtr olfLogFilePtr, bool writeBuffer = true);
2393   void openLogfileInit(Signal* signal);
2394   void openNextLogfile(Signal* signal);
2395   void releaseLfo(Signal* signal);
2396   void releaseLfoPages(Signal* signal);
2397   void releaseLogpage(Signal* signal);
2398   void seizeLfo(Signal* signal);
2399   void seizeLogfile(Signal* signal);
2400   void seizeLogpage(Signal* signal);
2401   void writeFileDescriptor(Signal* signal);
2402   void writeFileHeaderOpen(Signal* signal, Uint32 type);
2403   void writeInitMbyte(Signal* signal);
2404   void writeSinglePage(Signal* signal, Uint32 pageNo,
2405                        Uint32 wordWritten, Uint32 place,
2406                        bool sync = true);
2407   void buildLinkedLogPageList(Signal* signal);
2408   void changeMbyte(Signal* signal);
2409   Uint32 checkIfExecLog(Signal* signal);
2410   void checkNewMbyte(Signal* signal);
2411   void checkReadExecSr(Signal* signal);
2412   void checkScanTcCompleted(Signal* signal);
2413   void closeFile(Signal* signal, LogFileRecordPtr logFilePtr, Uint32 place);
2414   void completedLogPage(Signal* signal, Uint32 clpType, Uint32 place);
2415 
2416   void commit_reorg(TablerecPtr tablePtr);
2417   void wait_reorg_suma_filter_enabled(Signal*);
2418 
2419   void deleteFragrec(Uint32 fragId);
2420   void deleteTransidHash(Signal* signal);
2421   void findLogfile(Signal* signal,
2422                    Uint32 fileNo,
2423                    LogPartRecordPtr flfLogPartPtr,
2424                    LogFileRecordPtr* parLogFilePtr);
2425   void findPageRef(Signal* signal, CommitLogRecord* commitLogRecord);
2426   int  findTransaction(UintR Transid1, UintR Transid2, UintR TcOprec, UintR hi);
2427   void getFirstInLogQueue(Signal* signal, Ptr<TcConnectionrec>&dst);
2428   bool getFragmentrec(Signal* signal, Uint32 fragId);
2429   void initialiseAddfragrec(Signal* signal);
2430   void initialiseFragrec(Signal* signal);
2431   void initialiseGcprec(Signal* signal);
2432   void initialiseLcpRec(Signal* signal);
2433   void initialiseLfo(Signal* signal);
2434   void initialiseLogFile(Signal* signal);
2435   void initialiseLogPage(Signal* signal);
2436   void initialiseLogPart(Signal* signal);
2437   void initialisePageRef(Signal* signal);
2438   void initialiseScanrec(Signal* signal);
2439   void initialiseTabrec(Signal* signal);
2440   void initialiseTcrec(Signal* signal);
2441   void initialiseTcNodeFailRec(Signal* signal);
2442   void initFragrec(Signal* signal,
2443                    Uint32 tableId,
2444                    Uint32 fragId,
2445                    Uint32 copyType);
2446   void initFragrecSr(Signal* signal);
2447   void initGciInLogFileRec(Signal* signal, Uint32 noFdDesc);
2448   void initLcpSr(Signal* signal,
2449                  Uint32 lcpNo,
2450                  Uint32 lcpId,
2451                  Uint32 tableId,
2452                  Uint32 fragId,
2453                  Uint32 fragPtr);
2454   void initLogpart(Signal* signal);
2455   void initLogPointers(Signal* signal);
2456   void initReqinfoExecSr(Signal* signal);
2457   bool insertFragrec(Signal* signal, Uint32 fragId);
2458   void linkFragQueue(Signal* signal);
2459   void linkWaitLog(Signal*, LogPartRecordPtr, LogPartRecord::OperationQueue &);
2460   void logNextStart(Signal* signal);
2461   void moveToPageRef(Signal* signal);
2462   void readAttrinfo(Signal* signal);
2463   void readCommitLog(Signal* signal, CommitLogRecord* commitLogRecord);
2464   void readExecLog(Signal* signal);
2465   void readExecSrNewMbyte(Signal* signal);
2466   void readExecSr(Signal* signal);
2467   void readKey(Signal* signal);
2468   void readLogData(Signal* signal, Uint32 noOfWords, Uint32& sectionIVal);
2469   void readLogHeader(Signal* signal);
2470   Uint32 readLogword(Signal* signal);
2471   Uint32 readLogwordExec(Signal* signal);
2472   void readSinglePage(Signal* signal, Uint32 pageNo);
2473   void releaseActiveCopy(Signal* signal);
2474   void releaseAddfragrec(Signal* signal);
2475   void releaseFragrec();
2476   void releaseOprec(Signal* signal);
2477   void releasePageRef(Signal* signal);
2478   void releaseMmPages(Signal* signal);
2479   void releasePrPages(Signal* signal);
2480   void releaseTcrec(Signal* signal, TcConnectionrecPtr tcConnectptr);
2481   void releaseTcrecLog(Signal* signal, TcConnectionrecPtr tcConnectptr);
2482   void releaseWaitQueue(Signal* signal);
2483   void removeLogTcrec(Signal* signal);
2484   void removePageRef(Signal* signal);
2485   Uint32 returnExecLog(Signal* signal);
2486   int saveAttrInfoInSection(const Uint32* dataPtr, Uint32 len);
2487   void seizeAddfragrec(Signal* signal);
2488   Uint32 seizeSegment();
2489   Uint32 copyNextRange(Uint32 * dst, TcConnectionrec*);
2490 
2491   void seizeFragmentrec(Signal* signal);
2492   void seizePageRef(Signal* signal);
2493   void seizeTcrec();
2494   void sendAborted(Signal* signal);
2495   void sendLqhTransconf(Signal* signal, LqhTransConf::OperationStatus);
2496   void sendTupkey(Signal* signal);
2497   void startExecSr(Signal* signal);
2498   void startNextExecSr(Signal* signal);
2499   void startTimeSupervision(Signal* signal);
2500   void stepAhead(Signal* signal, Uint32 stepAheadWords);
2501   void systemError(Signal* signal, int line);
2502   void writeAbortLog(Signal* signal);
2503   void writeCommitLog(Signal* signal, LogPartRecordPtr regLogPartPtr);
2504   void writeCompletedGciLog(Signal* signal);
2505   void writeDbgInfoPageHeader(LogPageRecordPtr logPagePtr, Uint32 place,
2506                               Uint32 pageNo, Uint32 wordWritten);
2507   void writeDirty(Signal* signal, Uint32 place);
2508   void writeKey(Signal* signal);
2509   void writeLogHeader(Signal* signal);
2510   void writeLogWord(Signal* signal, Uint32 data);
2511   void writeLogWords(Signal* signal, const Uint32* data, Uint32 len);
2512   void writeNextLog(Signal* signal);
2513   void errorReport(Signal* signal, int place);
2514   void warningReport(Signal* signal, int place);
2515   void invalidateLogAfterLastGCI(Signal *signal);
2516   Uint32 nextLogFilePtr(Uint32 logFilePtrI);
2517   void readFileInInvalidate(Signal *signal, int stepNext);
2518   void writeFileInInvalidate(Signal *signal, int stepPrev);
2519   bool invalidateCloseFile(Signal*, Ptr<LogPartRecord>, Ptr<LogFileRecord>,
2520                            LogFileRecord::LogFileStatus status);
2521   void exitFromInvalidate(Signal* signal);
2522   Uint32 calcPageCheckSum(LogPageRecordPtr logP);
2523   Uint32 handleLongTupKey(Signal* signal, Uint32* dataPtr, Uint32 len);
2524 
2525   void rebuildOrderedIndexes(Signal* signal, Uint32 tableId);
2526 
2527   // Generated statement blocks
2528   void systemErrorLab(Signal* signal, int line);
2529   void initFourth(Signal* signal);
2530   void packLqhkeyreqLab(Signal* signal);
2531   void sendNdbSttorryLab(Signal* signal);
2532   void execSrCompletedLab(Signal* signal);
2533   void execLogRecord(Signal* signal);
2534   void srPhase3Comp(Signal* signal);
2535   void srLogLimits(Signal* signal);
2536   void srGciLimits(Signal* signal);
2537   void srPhase3Start(Signal* signal);
2538   void checkStartCompletedLab(Signal* signal);
2539   void continueAbortLab(Signal* signal);
2540   void abortContinueAfterBlockedLab(Signal* signal);
2541   void abortCommonLab(Signal* signal);
2542   void localCommitLab(Signal* signal);
2543   void abortErrorLab(Signal* signal);
2544   void continueAfterReceivingAllAiLab(Signal* signal);
2545   void abortStateHandlerLab(Signal* signal);
2546   void writeAttrinfoLab(Signal* signal);
2547   void scanAttrinfoLab(Signal* signal, Uint32* dataPtr, Uint32 length);
2548   void abort_scan(Signal* signal, Uint32 scan_ptr_i, Uint32 errcode);
2549   void localAbortStateHandlerLab(Signal* signal);
2550   void logLqhkeyreqLab(Signal* signal);
2551   void logLqhkeyreqLab_problems(Signal* signal);
2552   void update_log_problem(Signal*, LogPartRecordPtr, Uint32 problem, bool);
2553   void lqhAttrinfoLab(Signal* signal, Uint32* dataPtr, Uint32 length);
2554   void rwConcludedAiLab(Signal* signal);
2555   void aiStateErrorCheckLab(Signal* signal, Uint32* dataPtr, Uint32 length);
2556   void takeOverErrorLab(Signal* signal);
2557   void endgettupkeyLab(Signal* signal);
2558   bool checkTransporterOverloaded(Signal* signal,
2559                                   const NodeBitmask& all,
2560                                   const class LqhKeyReq* req);
2561   void noFreeRecordLab(Signal* signal,
2562 		       const class LqhKeyReq * lqhKeyReq,
2563 		       Uint32 errorCode);
2564   void logLqhkeyrefLab(Signal* signal);
2565   void closeCopyLab(Signal* signal);
2566   void commitReplyLab(Signal* signal);
2567   void completeUnusualLab(Signal* signal);
2568   void completeTransNotLastLab(Signal* signal);
2569   void completedLab(Signal* signal);
2570   void copyCompletedLab(Signal* signal);
2571   void completeLcpRoundLab(Signal* signal, Uint32 lcpId);
2572   void continueAfterLogAbortWriteLab(Signal* signal);
2573   void sendAttrinfoLab(Signal* signal);
2574   void sendExecConf(Signal* signal);
2575   void execSr(Signal* signal);
2576   void srFourthComp(Signal* signal);
2577   void timeSup(Signal* signal);
2578   void closeCopyRequestLab(Signal* signal);
2579   void closeScanRequestLab(Signal* signal);
2580   void scanTcConnectLab(Signal* signal, Uint32 startTcCon, Uint32 fragId);
2581   void initGcpRecLab(Signal* signal);
2582   void prepareContinueAfterBlockedLab(Signal* signal);
2583   void commitContinueAfterBlockedLab(Signal* signal);
2584   void continueCopyAfterBlockedLab(Signal* signal);
2585   void continueFirstCopyAfterBlockedLab(Signal* signal);
2586   void continueFirstScanAfterBlockedLab(Signal* signal);
2587   void continueScanAfterBlockedLab(Signal* signal);
2588   void continueScanReleaseAfterBlockedLab(Signal* signal);
2589   void continueCloseScanAfterBlockedLab(Signal* signal);
2590   void continueCloseCopyAfterBlockedLab(Signal* signal);
2591   void sendExecFragRefLab(Signal* signal);
2592   void fragrefLab(Signal* signal, Uint32 errorCode, const LqhFragReq* req);
2593   void abortAddFragOps(Signal* signal);
2594   void rwConcludedLab(Signal* signal);
2595   void sendsttorryLab(Signal* signal);
2596   void initialiseRecordsLab(Signal* signal, Uint32 data, Uint32, Uint32);
2597   void startphase2Lab(Signal* signal, Uint32 config);
2598   void startphase3Lab(Signal* signal);
2599   void startphase4Lab(Signal* signal);
2600   void startphase6Lab(Signal* signal);
2601   void moreconnectionsLab(Signal* signal);
2602   void scanReleaseLocksLab(Signal* signal);
2603   void closeScanLab(Signal* signal);
2604   void nextScanConfLoopLab(Signal* signal);
2605   void scanNextLoopLab(Signal* signal);
2606   void commitReqLab(Signal* signal, Uint32 gci_hi, Uint32 gci_lo);
2607   void completeTransLastLab(Signal* signal);
2608   void tupScanCloseConfLab(Signal* signal);
2609   void tupCopyCloseConfLab(Signal* signal);
2610   void accScanCloseConfLab(Signal* signal);
2611   void accCopyCloseConfLab(Signal* signal);
2612   void nextScanConfScanLab(Signal* signal);
2613   void nextScanConfCopyLab(Signal* signal);
2614   void continueScanNextReqLab(Signal* signal);
2615   bool keyinfoLab(const Uint32 * src, Uint32 len);
2616   void copySendTupkeyReqLab(Signal* signal);
2617   void storedProcConfScanLab(Signal* signal);
2618   void storedProcConfCopyLab(Signal* signal);
2619   void copyStateFinishedLab(Signal* signal);
2620   void lcpCompletedLab(Signal* signal);
2621   void lcpStartedLab(Signal* signal);
2622   void contChkpNextFragLab(Signal* signal);
2623   void startLcpRoundLab(Signal* signal);
2624   void startFragRefLab(Signal* signal);
2625   void srCompletedLab(Signal* signal);
2626   void openFileInitLab(Signal* signal);
2627   void openSrFrontpageLab(Signal* signal);
2628   void openSrLastFileLab(Signal* signal);
2629   void openSrNextFileLab(Signal* signal);
2630   void openExecSrStartLab(Signal* signal);
2631   void openExecSrNewMbyteLab(Signal* signal);
2632   void openSrFourthPhaseLab(Signal* signal);
2633   void openSrFourthZeroSkipInitLab(Signal* signal);
2634   void openSrFourthZeroLab(Signal* signal);
2635   void openExecLogLab(Signal* signal);
2636   void checkInitCompletedLab(Signal* signal);
2637   void closingSrLab(Signal* signal);
2638   void closeExecSrLab(Signal* signal);
2639   void execLogComp(Signal* signal);
2640   void execLogComp_extra_files_closed(Signal* signal);
2641   void closeWriteLogLab(Signal* signal);
2642   void closeExecLogLab(Signal* signal);
2643   void writePageZeroLab(Signal* signal, Uint32 from);
2644   void lastWriteInFileLab(Signal* signal);
2645   void initWriteEndLab(Signal* signal);
2646   void initFirstPageLab(Signal* signal);
2647   void writeGciZeroLab(Signal* signal);
2648   void writeDirtyLab(Signal* signal);
2649   void writeInitMbyteLab(Signal* signal);
2650   void writeLogfileLab(Signal* signal);
2651   void firstPageWriteLab(Signal* signal);
2652   void readSrLastMbyteLab(Signal* signal);
2653   void readSrLastFileLab(Signal* signal);
2654   void readSrNextFileLab(Signal* signal);
2655   void readExecSrLab(Signal* signal);
2656   void readExecLogLab(Signal* signal);
2657   void readSrFourthPhaseLab(Signal* signal);
2658   void readSrFourthZeroLab(Signal* signal);
2659   void copyLqhKeyRefLab(Signal* signal);
2660   void restartOperationsLab(Signal* signal);
2661   void lqhTransNextLab(Signal* signal);
2662   void restartOperationsAfterStopLab(Signal* signal);
2663   void startphase1Lab(Signal* signal, Uint32 config, Uint32 nodeId);
2664   void tupkeyConfLab(Signal* signal);
2665   void copyTupkeyRefLab(Signal* signal);
2666   void copyTupkeyConfLab(Signal* signal);
2667   void scanTupkeyConfLab(Signal* signal);
2668   void scanTupkeyRefLab(Signal* signal);
2669   void accScanConfScanLab(Signal* signal);
2670   void accScanConfCopyLab(Signal* signal);
2671   void scanLockReleasedLab(Signal* signal);
2672   void openSrFourthNextLab(Signal* signal);
2673   void closingInitLab(Signal* signal);
2674   void closeExecSrCompletedLab(Signal* signal);
2675   void readSrFrontpageLab(Signal* signal);
2676 
2677   void sendCreateTabReq(Signal*, AddFragRecordPtr);
2678   void sendAddAttrReq(Signal* signal);
2679   void sendAddFragReq(Signal* signal);
2680   void dropTab_wait_usage(Signal*);
2681   Uint32 get_table_state_error(Ptr<Tablerec> tabPtr) const;
2682   void wait_readonly(Signal*);
2683   int check_tabstate(Signal * signal, const Tablerec * tablePtrP, Uint32 op);
2684 
2685   void remove_commit_marker(TcConnectionrec * const regTcPtr);
2686   // Initialisation
2687   void initData();
2688   void initRecords();
2689 protected:
2690   virtual bool getParam(const char* name, Uint32* count);
2691 
2692 private:
2693 
2694 
2695   bool validate_filter(Signal*);
2696   bool match_and_print(Signal*, Ptr<TcConnectionrec>);
2697 
2698   void define_backup(Signal*);
2699   void execDEFINE_BACKUP_REF(Signal*);
2700   void execDEFINE_BACKUP_CONF(Signal*);
2701   void execBACKUP_FRAGMENT_REF(Signal* signal);
2702   void execBACKUP_FRAGMENT_CONF(Signal* signal);
2703   void execLCP_PREPARE_REF(Signal* signal);
2704   void execLCP_PREPARE_CONF(Signal* signal);
2705   void execEND_LCPREF(Signal* signal);
2706   void execEND_LCPCONF(Signal* signal);
2707   Uint32 m_backup_ptr;
2708 
2709   void send_restore_lcp(Signal * signal);
2710   void execRESTORE_LCP_REF(Signal* signal);
2711   void execRESTORE_LCP_CONF(Signal* signal);
2712 
2713   /**
2714    * For periodic redo log file initialization status reporting
2715    * and explicit redo log file status reporting
2716    */
2717   /* Init at start of redo log file initialization, timers etc... */
2718   void initReportStatus(Signal* signal);
2719   /* Check timers for reporting at certain points */
2720   void checkReportStatus(Signal* signal);
2721   /* Send redo log file initialization status, invoked either periodically, or explicitly */
2722   void reportStatus(Signal* signal);
2723   /* redo log file initialization completed report*/
2724   void logfileInitCompleteReport(Signal* signal);
2725 
2726   void check_send_scan_hb_rep(Signal* signal, ScanRecord*, TcConnectionrec*);
2727 
2728   void unlockError(Signal* signal, Uint32 error);
2729   void handleUserUnlockRequest(Signal* signal);
2730 
2731   Dbtup* c_tup;
2732   Dbacc* c_acc;
2733   Lgman* c_lgman;
2734 
2735   /**
2736    * Read primary key from tup
2737    */
2738   Uint32 readPrimaryKeys(ScanRecord*, TcConnectionrec*, Uint32 * dst);
2739 
2740   /**
2741    * Read primary key from operation
2742    */
2743 public:
2744   Uint32 readPrimaryKeys(Uint32 opPtrI, Uint32 * dst, bool xfrm);
2745 private:
2746 
2747   void acckeyconf_tupkeyreq(Signal*, TcConnectionrec*, Fragrecord*,
2748                             Uint32, Uint32, Uint32);
2749   void acckeyconf_load_diskpage(Signal*,TcConnectionrecPtr,Fragrecord*,
2750                                 Uint32, Uint32);
2751 
2752   void handle_nr_copy(Signal*, Ptr<TcConnectionrec>);
2753   void exec_acckeyreq(Signal*, Ptr<TcConnectionrec>);
2754   int compare_key(const TcConnectionrec*, const Uint32 * ptr, Uint32 len);
2755   void nr_copy_delete_row(Signal*, Ptr<TcConnectionrec>, Local_key*, Uint32);
2756   Uint32 getKeyInfoWordOrZero(const TcConnectionrec* regTcPtr,
2757                               Uint32 offset);
2758 public:
2759   struct Nr_op_info
2760   {
2761     Uint32 m_ptr_i;
2762     Uint32 m_tup_frag_ptr_i;
2763     Uint32 m_gci_hi;
2764     Uint32 m_gci_lo;
2765     Uint32 m_page_id;
2766     Local_key m_disk_ref;
2767   };
2768   void get_nr_op_info(Nr_op_info*, Uint32 page_id = RNIL);
2769   void nr_delete_complete(Signal*, Nr_op_info*);
2770 
2771 public:
2772   void acckeyconf_load_diskpage_callback(Signal*, Uint32, Uint32);
2773 
2774 private:
2775   void next_scanconf_load_diskpage(Signal* signal,
2776 				   ScanRecordPtr scanPtr,
2777 				   Ptr<TcConnectionrec> regTcPtr,
2778 				   Fragrecord* fragPtrP);
2779 
2780   void next_scanconf_tupkeyreq(Signal* signal, ScanRecordPtr,
2781 			       TcConnectionrec * regTcPtr,
2782 			       Fragrecord* fragPtrP,
2783 			       Uint32 disk_page);
2784 
2785 public:
2786   void next_scanconf_load_diskpage_callback(Signal* signal, Uint32, Uint32);
2787 
2788   void tupcommit_conf_callback(Signal* signal, Uint32 tcPtrI);
2789 private:
2790   void tupcommit_conf(Signal* signal, TcConnectionrec *,Fragrecord *);
2791 
2792 // ----------------------------------------------------------------
2793 // These are variables handling the records. For most records one
2794 // pointer to the array of structs, one pointer-struct, a file size
2795 // and a first free record variable. The pointer struct are temporary
2796 // variables that are kept on the class object since there are often a
2797 // great deal of those variables that exist simultaneously and
2798 // thus no perfect solution of handling them is currently available.
2799 // ----------------------------------------------------------------
2800 /* ------------------------------------------------------------------------- */
2801 /*       POSITIONS WITHIN THE ATTRINBUF AND THE MAX SIZE OF DATA WITHIN AN   */
2802 /*       ATTRINBUF.                                                          */
2803 /* ------------------------------------------------------------------------- */
2804 
2805 
2806 #define ZADDFRAGREC_FILE_SIZE 1
2807   AddFragRecord *addFragRecord;
2808   AddFragRecordPtr addfragptr;
2809   UintR cfirstfreeAddfragrec;
2810   UintR caddfragrecFileSize;
2811   Uint32 c_active_add_frag_ptr_i;
2812 
2813 // Configurable
2814   FragrecordPtr fragptr;
2815   ArrayPool<Fragrecord> c_fragment_pool;
2816   RSS_AP_SNAPSHOT(c_fragment_pool);
2817 
2818 #define ZGCPREC_FILE_SIZE 1
2819   GcpRecord *gcpRecord;
2820   GcpRecordPtr gcpPtr;
2821   UintR cgcprecFileSize;
2822 
2823 // MAX_NDB_NODES is the size of this array
2824   HostRecord *hostRecord;
2825   UintR chostFileSize;
2826 
2827 #define ZNO_CONCURRENT_LCP 1
2828   LcpRecord *lcpRecord;
2829   LcpRecordPtr lcpPtr;
2830   UintR cfirstfreeLcpLoc;
2831   UintR clcpFileSize;
2832 
2833 #define ZLOG_PART_FILE_SIZE 4
2834   LogPartRecord *logPartRecord;
2835   LogPartRecordPtr logPartPtr;
2836   UintR clogPartFileSize;
2837   Uint32 clogFileSize; // In MBYTE
2838   Uint32 cmaxLogFilesInPageZero; //
2839 
2840 // Configurable
2841   LogFileRecord *logFileRecord;
2842   LogFileRecordPtr logFilePtr;
2843   UintR cfirstfreeLogFile;
2844   UintR clogFileFileSize;
2845 
2846 #define ZLFO_MIN_FILE_SIZE 256
2847 // RedoBuffer/32K minimum ZLFO_MIN_FILE_SIZE
2848   LogFileOperationRecord *logFileOperationRecord;
2849   LogFileOperationRecordPtr lfoPtr;
2850   UintR cfirstfreeLfo;
2851   UintR clfoFileSize;
2852 
2853   LogPageRecord *logPageRecord;
2854   LogPageRecordPtr logPagePtr;
2855   UintR cfirstfreeLogPage;
2856   UintR clogPageFileSize;
2857   Uint32 clogPageCount;
2858 
2859 #define ZPAGE_REF_FILE_SIZE 20
2860   PageRefRecord *pageRefRecord;
2861   PageRefRecordPtr pageRefPtr;
2862   UintR cfirstfreePageRef;
2863   UintR cpageRefFileSize;
2864 
2865 // Configurable
2866   ArrayPool<ScanRecord> c_scanRecordPool;
2867   ScanRecordPtr scanptr;
2868   Uint32 cscanrecFileSize;
2869   DLList<ScanRecord> m_reserved_scans; // LCP + NR
2870 
2871 // Configurable
2872   Tablerec *tablerec;
2873   TablerecPtr tabptr;
2874   UintR ctabrecFileSize;
2875 
2876 // Configurable
2877   TcConnectionrec *tcConnectionrec;
2878   TcConnectionrecPtr tcConnectptr;
2879   UintR cfirstfreeTcConrec;
2880   UintR ctcConnectrecFileSize;
2881 
2882 // MAX_NDB_NODES is the size of this array
2883   TcNodeFailRecord *tcNodeFailRecord;
2884   TcNodeFailRecordPtr tcNodeFailptr;
2885   UintR ctcNodeFailrecFileSize;
2886 
2887   Uint16 terrorCode;
2888 
2889   Uint32 c_firstInNodeGroup;
2890 
2891 // ------------------------------------------------------------------------
2892 // These variables are used to store block state which do not need arrays
2893 // of struct's.
2894 // ------------------------------------------------------------------------
2895   Uint32 c_lcpId;
2896   Uint32 cnoOfFragsCheckpointed;
2897   Uint32 c_last_force_lcp_time;
2898   Uint32 c_free_mb_force_lcp_limit; // Force lcp when less than this free mb
2899   Uint32 c_free_mb_tail_problem_limit; // Set TAIL_PROBLEM when less than this..
2900 
2901 /* ------------------------------------------------------------------------- */
2902 // cmaxWordsAtNodeRec keeps track of how many words that currently are
2903 // outstanding in a node recovery situation.
2904 // cbookedAccOps keeps track of how many operation records that have been
2905 // booked in ACC for the scan processes.
2906 // cmaxAccOps contains the maximum number of operation records which can be
2907 // allocated for scan purposes in ACC.
2908 /* ------------------------------------------------------------------------- */
2909   UintR cmaxWordsAtNodeRec;
2910   UintR cbookedAccOps;
2911   UintR cmaxAccOps;
2912 /* ------------------------------------------------------------------------- */
2913 /*THIS STATE VARIABLE IS ZTRUE IF AN ADD NODE IS ONGOING. ADD NODE MEANS     */
2914 /*THAT CONNECTIONS ARE SET-UP TO THE NEW NODE.                               */
2915 /* ------------------------------------------------------------------------- */
2916   Uint8 caddNodeState;
2917 /* ------------------------------------------------------------------------- */
2918 /*THIS VARIABLE SPECIFIES WHICH TYPE OF RESTART THAT IS ONGOING              */
2919 /* ------------------------------------------------------------------------- */
2920   Uint16 cstartType;
2921 /* ------------------------------------------------------------------------- */
2922 /*THIS VARIABLE INDICATES WHETHER AN INITIAL RESTART IS ONGOING OR NOT.      */
2923 /* ------------------------------------------------------------------------- */
2924   Uint8 cinitialStartOngoing;
2925 /* ------------------------------------------------------------------------- */
2926 /*THIS VARIABLE KEEPS TRACK OF WHEN TUP AND ACC HAVE COMPLETED EXECUTING     */
2927 /*THEIR UNDO LOG.                                                            */
2928 /* ------------------------------------------------------------------------- */
2929   ExecUndoLogState csrExecUndoLogState;
2930 /* ------------------------------------------------------------------------- */
2931 /*THIS VARIABLE KEEPS TRACK OF WHEN TUP AND ACC HAVE CONFIRMED COMPLETION    */
2932 /*OF A LOCAL CHECKPOINT ROUND.                                               */
2933 /* ------------------------------------------------------------------------- */
2934   LcpCloseState clcpCompletedState;
2935 /* ------------------------------------------------------------------------- */
2936 /*DURING CONNECTION PROCESSES IN SYSTEM RESTART THESE VARIABLES KEEP TRACK   */
2937 /*OF HOW MANY CONNECTIONS AND RELEASES THAT ARE TO BE PERFORMED.             */
2938 /* ------------------------------------------------------------------------- */
2939 /***************************************************************************>*/
2940 /*THESE VARIABLES CONTAIN INFORMATION USED DURING SYSTEM RESTART.            */
2941 /***************************************************************************>*/
2942 /* ------------------------------------------------------------------------- */
2943 /*THIS VARIABLE IS ZTRUE IF THE SIGNAL START_REC_REQ HAVE BEEN RECEIVED.     */
2944 /*RECEPTION OF THIS SIGNAL INDICATES THAT ALL FRAGMENTS THAT THIS NODE       */
2945 /*SHOULD START HAVE BEEN RECEIVED.                                           */
2946 /* ------------------------------------------------------------------------- */
2947   enum {
2948     SRR_INITIAL                = 0
2949     ,SRR_START_REC_REQ_ARRIVED = 1
2950     ,SRR_REDO_COMPLETE         = 2
2951     ,SRR_FIRST_LCP_DONE        = 3
2952   } cstartRecReq;
2953   Uint32 cstartRecReqData;
2954 
2955 /* ------------------------------------------------------------------------- */
2956 /*THIS VARIABLE KEEPS TRACK OF HOW MANY FRAGMENTS THAT PARTICIPATE IN        */
2957 /*EXECUTING THE LOG. IF ZERO WE DON'T NEED TO EXECUTE THE LOG AT ALL.        */
2958 /* ------------------------------------------------------------------------- */
2959   Uint32 cnoFragmentsExecSr;
2960 
2961   /**
2962    * This is no of sent GSN_EXEC_FRAGREQ during this log phase
2963    */
2964   Uint32 cnoOutstandingExecFragReq;
2965 
2966 /* ------------------------------------------------------------------------- */
2967 /*THIS VARIABLE KEEPS TRACK OF WHICH OF THE FIRST TWO RESTART PHASES THAT    */
2968 /*HAVE COMPLETED.                                                            */
2969 /* ------------------------------------------------------------------------- */
2970   Uint8 csrPhaseStarted;
2971 /* ------------------------------------------------------------------------- */
2972 /*NUMBER OF PHASES COMPLETED OF EXECUTING THE FRAGMENT LOG.                  */
2973 /* ------------------------------------------------------------------------- */
2974   Uint8 csrPhasesCompleted;
2975 /* ------------------------------------------------------------------------- */
2976 /*THE BLOCK REFERENCE OF THE MASTER DIH DURING SYSTEM RESTART.               */
2977 /* ------------------------------------------------------------------------- */
2978   BlockReference cmasterDihBlockref;
2979 /* ------------------------------------------------------------------------- */
2980 /*THIS VARIABLE IS THE HEAD OF A LINKED LIST OF FRAGMENTS WAITING TO BE      */
2981 /*RESTORED FROM DISK.                                                        */
2982 /* ------------------------------------------------------------------------- */
2983   DLFifoList<Fragrecord> c_lcp_waiting_fragments;  // StartFragReq'ed
2984   DLFifoList<Fragrecord> c_lcp_restoring_fragments; // Restoring as we speek
2985   DLFifoList<Fragrecord> c_lcp_complete_fragments;  // Restored
2986 
2987 /* ------------------------------------------------------------------------- */
2988 /*USED DURING SYSTEM RESTART, INDICATES THE OLDEST GCI THAT CAN BE RESTARTED */
2989 /*FROM AFTER THIS SYSTEM RESTART. USED TO FIND THE LOG TAIL.                 */
2990 /* ------------------------------------------------------------------------- */
2991   UintR crestartOldestGci;
2992 /* ------------------------------------------------------------------------- */
2993 /*USED DURING SYSTEM RESTART, INDICATES THE NEWEST GCI THAT CAN BE RESTARTED */
2994 /*AFTER THIS SYSTEM RESTART. USED TO FIND THE LOG HEAD.                      */
2995 /* ------------------------------------------------------------------------- */
2996   UintR crestartNewestGci;
2997 /* ------------------------------------------------------------------------- */
2998 /*THE NUMBER OF LOG FILES. SET AS A PARAMETER WHEN NDB IS STARTED.           */
2999 /* ------------------------------------------------------------------------- */
3000   UintR cnoLogFiles;
3001 /* ------------------------------------------------------------------------- */
3002 /*THESE TWO VARIABLES CONTAIN THE NEWEST GCI RECEIVED IN THE BLOCK AND THE   */
3003 /*NEWEST COMPLETED GCI IN THE BLOCK.                                         */
3004 /* ------------------------------------------------------------------------- */
3005   UintR cnewestGci;
3006   UintR cnewestCompletedGci;
3007 /* ------------------------------------------------------------------------- */
3008 /*THIS VARIABLE ONLY PASSES INFORMATION FROM STTOR TO STTORRY = TEMPORARY    */
3009 /* ------------------------------------------------------------------------- */
3010   Uint16 csignalKey;
3011 /* ------------------------------------------------------------------------- */
3012 /*THIS VARIABLE CONTAINS THE CURRENT START PHASE IN THE BLOCK. IS ZNIL IF    */
3013 /*NO SYSTEM RESTART IS ONGOING.                                              */
3014 /* ------------------------------------------------------------------------- */
3015   Uint16 cstartPhase;
3016 /* ------------------------------------------------------------------------- */
3017 /*THIS VARIABLE CONTAIN THE CURRENT GLOBAL CHECKPOINT RECORD. IT'S RNIL IF   */
3018 /*NOT A GCP SAVE IS ONGOING.                                                 */
3019 /* ------------------------------------------------------------------------- */
3020   UintR ccurrentGcprec;
3021 /* ------------------------------------------------------------------------- */
3022 /*THESE VARIABLES ARE USED TO KEEP TRACK OF ALL ACTIVE COPY FRAGMENTS IN LQH.*/
3023 /* ------------------------------------------------------------------------- */
3024   Uint8 cnoActiveCopy;
3025   UintR cactiveCopy[4];
3026 
3027 /* ------------------------------------------------------------------------- */
3028 /*THESE VARIABLES CONTAIN THE BLOCK REFERENCES OF THE OTHER NDB BLOCKS.      */
3029 /*ALSO THE BLOCK REFERENCE OF MY OWN BLOCK = LQH                             */
3030 /* ------------------------------------------------------------------------- */
3031   BlockReference caccBlockref;
3032   BlockReference ctupBlockref;
3033   BlockReference ctuxBlockref;
3034   BlockReference cownref;
3035   Uint32 cTransactionDeadlockDetectionTimeout;
3036   UintR cLqhTimeOutCount;
3037   UintR cLqhTimeOutCheckCount;
3038   UintR cnoOfLogPages;
3039 /* ------------------------------------------------------------------------- */
3040 /*THIS VARIABLE CONTAINS MY OWN PROCESSOR ID.                                */
3041 /* ------------------------------------------------------------------------- */
3042   NodeId cownNodeid;
3043 
3044 /* ------------------------------------------------------------------------- */
3045 /*THESE VARIABLES CONTAIN INFORMATION ABOUT THE OTHER NODES IN THE SYSTEM    */
3046 /*THESE VARIABLES ARE MOSTLY USED AT SYSTEM RESTART AND ADD NODE TO SET-UP   */
3047 /*AND RELEASE CONNECTIONS TO OTHER NODES IN THE CLUSTER.                     */
3048 /* ------------------------------------------------------------------------- */
3049 /* ------------------------------------------------------------------------- */
3050 /*THIS ARRAY CONTAINS THE PROCESSOR ID'S OF THE NODES THAT ARE ALIVE.        */
3051 /*CNO_OF_NODES SPECIFIES HOW MANY NODES THAT ARE CURRENTLY ALIVE.            */
3052 /*CNODE_VERSION SPECIFIES THE NDB VERSION EXECUTING ON THE NODE.             */
3053 /* ------------------------------------------------------------------------- */
3054   UintR cpackedListIndex;
3055   Uint16 cpackedList[MAX_NDB_NODES];
3056   UintR cnodeData[MAX_NDB_NODES];
3057   UintR cnodeStatus[MAX_NDB_NODES];
3058   UintR cnoOfNodes;
3059 
3060   NdbNodeBitmask m_sr_nodes;
3061   NdbNodeBitmask m_sr_exec_sr_req;
3062   NdbNodeBitmask m_sr_exec_sr_conf;
3063 
3064 /* ------------------------------------------------------------------------- */
3065 /* THIS VARIABLE CONTAINS THE DIRECTORY OF A HASH TABLE OF ALL ACTIVE        */
3066 /* OPERATION IN THE BLOCK. IT IS USED TO BE ABLE TO QUICKLY ABORT AN         */
3067 /* OPERATION WHERE THE CONNECTION WAS LOST DUE TO NODE FAILURES. IT IS       */
3068 /* ACTUALLY USED FOR ALL ABORTS COMMANDED BY TC.                             */
3069 /* ------------------------------------------------------------------------- */
3070   UintR preComputedRequestInfoMask;
3071   UintR ctransidHash[1024];
3072 
3073   Uint32 c_diskless;
3074   Uint32 c_o_direct;
3075   Uint32 m_use_om_init;
3076   Uint32 c_error_insert_table_id;
3077 
3078 #ifndef NO_REDO_PAGE_CACHE
3079   /***********************************************************
3080    * MODULE: Redo Page Cache
3081    *
3082    *   When running redo, current codes scan log until finding a commit
3083    *     record (for an operation). The commit record contains a back-pointer
3084    *     to a prepare-record.
3085    *
3086    *   If the prepare record is inside the 512k window that is being read
3087    *     from redo-log, the access is quick.
3088    *
3089    *   But it's not, then the following sequence is performed
3090    *     [file-open]?[page-read][execute-log-record][file-close]?[release-page]
3091    *
3092    *   For big (or long running) transactions this becomes very inefficient
3093    *
3094    *   The RedoPageCache changes this so that the pages that are not released
3095    *     in sequence above, but rather put into a LRU (using RedoBuffer)
3096    */
3097 
3098   /**
3099    * This is a "dummy" struct that is used when
3100    *  putting LogPageRecord-entries into lists/hashes
3101    */
3102   struct RedoCacheLogPageRecord
3103   {
RedoCacheLogPageRecordDblqh::RedoCacheLogPageRecord3104     RedoCacheLogPageRecord() {}
3105     /**
3106      * NOTE: These numbers must match page-header definition
3107      */
3108     Uint32 header0[15];
3109     Uint32 m_page_no;
3110     Uint32 m_file_no;
3111     Uint32 header1[5];
3112     Uint32 m_part_no;
3113     Uint32 nextList;
3114     Uint32 nextHash;
3115     Uint32 prevList;
3116     Uint32 prevHash;
3117     Uint32 rest[8192-27];
3118 
equalDblqh::RedoCacheLogPageRecord3119     inline bool equal(const RedoCacheLogPageRecord & p) const {
3120       return
3121         (p.m_part_no == m_part_no) &&
3122         (p.m_page_no == m_page_no) &&
3123         (p.m_file_no == m_file_no);
3124     }
3125 
hashValueDblqh::RedoCacheLogPageRecord3126     inline Uint32 hashValue() const {
3127       return (m_part_no << 24) + (m_file_no << 16) + m_page_no;
3128     }
3129   };
3130   struct RedoPageCache
3131   {
RedoPageCacheDblqh::RedoPageCache3132     RedoPageCache() : m_hash(m_pool), m_lru(m_pool),
3133                       m_hits(0),m_multi_page(0), m_multi_miss(0) {}
3134     DLHashTable<RedoCacheLogPageRecord> m_hash;
3135     DLCFifoList<RedoCacheLogPageRecord> m_lru;
3136     ArrayPool<RedoCacheLogPageRecord> m_pool;
3137     Uint32 m_hits;
3138     Uint32 m_multi_page;
3139     Uint32 m_multi_miss;
3140   } m_redo_page_cache;
3141 
3142   void evict(RedoPageCache&, Uint32 cnt);
3143   void do_evict(RedoPageCache&, Ptr<RedoCacheLogPageRecord>);
3144   void addCachePages(RedoPageCache&,
3145                      Uint32 partNo,
3146                      Uint32 startPageNo,
3147                      LogFileOperationRecord*);
3148   void release(RedoPageCache&);
3149 #endif
3150 
3151 #ifndef NO_REDO_OPEN_FILE_CACHE
3152   struct RedoOpenFileCache
3153   {
RedoOpenFileCacheDblqh::RedoOpenFileCache3154     RedoOpenFileCache() : m_lru(m_pool), m_hits(0), m_close_cnt(0) {}
3155 
3156     DLCFifoList<LogFileRecord> m_lru;
3157     ArrayPool<LogFileRecord> m_pool;
3158     Uint32 m_hits;
3159     Uint32 m_close_cnt;
3160   } m_redo_open_file_cache;
3161 
3162   void openFileRw_cache(Signal* signal, LogFileRecordPtr olfLogFilePtr);
3163   void closeFile_cache(Signal* signal, LogFileRecordPtr logFilePtr, Uint32);
3164   void release(Signal*, RedoOpenFileCache&);
3165 #endif
3166 
3167 public:
3168   bool is_same_trans(Uint32 opId, Uint32 trid1, Uint32 trid2);
3169   void get_op_info(Uint32 opId, Uint32 *hash, Uint32* gci_hi, Uint32* gci_lo,
3170                    Uint32* transId1, Uint32* transId2);
3171   void accminupdate(Signal*, Uint32 opPtrI, const Local_key*);
3172   void accremoverow(Signal*, Uint32 opPtrI, const Local_key*);
3173 
3174   /**
3175    *
3176    */
3177   struct CommitAckMarker {
CommitAckMarkerDblqh::CommitAckMarker3178     CommitAckMarker() {}
3179     Uint32 transid1;
3180     Uint32 transid2;
3181 
3182     Uint32 apiRef;    // Api block ref
3183     Uint32 apiOprec;  // Connection Object in NDB API
3184     Uint32 tcNodeId;
3185     union { Uint32 nextPool; Uint32 nextHash; };
3186     Uint32 prevHash;
3187     Uint32 reference_count;
3188 
equalDblqh::CommitAckMarker3189     inline bool equal(const CommitAckMarker & p) const {
3190       return ((p.transid1 == transid1) && (p.transid2 == transid2));
3191     }
3192 
hashValueDblqh::CommitAckMarker3193     inline Uint32 hashValue() const {
3194       return transid1;
3195     }
3196   };
3197 
3198   typedef Ptr<CommitAckMarker> CommitAckMarkerPtr;
3199   ArrayPool<CommitAckMarker>   m_commitAckMarkerPool;
3200   DLHashTable<CommitAckMarker> m_commitAckMarkerHash;
3201   typedef DLHashTable<CommitAckMarker>::Iterator CommitAckMarkerIterator;
3202   void execREMOVE_MARKER_ORD(Signal* signal);
3203   void scanMarkers(Signal* signal, Uint32 tcNodeFail, Uint32 bucket, Uint32 i);
3204 
3205   void ndbdFailBlockCleanupCallback(Signal* signal, Uint32 failedNodeID, Uint32 ignoredRc);
3206 
3207   struct MonotonicCounters {
MonotonicCountersDblqh::MonotonicCounters3208     MonotonicCounters() :
3209       operations(0) {}
3210 
3211     Uint64 operations;
3212 
build_event_repDblqh::MonotonicCounters3213     Uint32 build_event_rep(Signal* signal) const
3214     {
3215       /*
3216         Read saved value from CONTINUEB, subtract from
3217         counter and write to EVENT_REP
3218       */
3219       struct { const Uint64* ptr; Uint64 old; } vars[] = {
3220         { &operations, 0 }
3221       };
3222       const size_t num = sizeof(vars)/sizeof(vars[0]);
3223 
3224       signal->theData[0] = NDB_LE_OperationReportCounters;
3225 
3226       // Read old values from signal
3227       for (size_t i = 0; i < num ; i++)
3228       {
3229         vars[i].old =
3230           (signal->theData[1+(2*i)+1] |(Uint64(signal->theData[1+(2*i)])<< 32));
3231       }
3232 
3233       // Write difference back to signal
3234       for (size_t i = 0; i < num ; i++)
3235       {
3236         signal->theData[1 + i] = (Uint32)(*vars[i].ptr - vars[i].old);
3237       }
3238       return 1 + num;
3239     }
3240 
build_continueBDblqh::MonotonicCounters3241     Uint32 build_continueB(Signal* signal) const
3242     {
3243       /* Save current value of counters to CONTINUEB */
3244       const Uint64* vars[] = { &operations };
3245       const size_t num = sizeof(vars)/sizeof(vars[0]);
3246 
3247       for (size_t i = 0; i < num ; i++)
3248       {
3249         signal->theData[1+i*2] = Uint32(*vars[i] >> 32);
3250         signal->theData[1+i*2+1] = Uint32(*vars[i]);
3251       }
3252       return 1 + num * 2;
3253     }
3254 
3255   } c_Counters;
3256 
3257   Uint32 c_max_redo_lag;
3258   Uint32 c_max_redo_lag_counter;
3259   Uint64 cTotalLqhKeyReqCount;
3260   Uint32 c_max_parallel_scans_per_frag;
3261 
getAllowRead() const3262   inline bool getAllowRead() const {
3263     return getNodeState().startLevel < NodeState::SL_STOPPING_3;
3264   }
3265 
3266   DLHashTable<ScanRecord> c_scanTakeOverHash;
3267 
3268   inline bool TRACE_OP_CHECK(const TcConnectionrec* regTcPtr);
3269 #ifdef ERROR_INSERT
3270   void TRACE_OP_DUMP(const TcConnectionrec* regTcPtr, const char * pos);
3271 #endif
3272 
3273 #ifdef ERROR_INSERT
3274   Uint32 c_master_node_id;
3275 #endif
3276 
3277   Uint32 get_node_status(Uint32 nodeId) const;
3278   bool check_ndb_versions() const;
3279 
3280   void suspendFile(Signal* signal, Uint32 filePtrI, Uint32 millis);
3281   void suspendFile(Signal* signal, Ptr<LogFileRecord> logFile, Uint32 millis);
3282 
3283   void send_runredo_event(Signal*, LogPartRecord *, Uint32 currgci);
3284 
3285   void sendFireTrigConfTc(Signal* signal, BlockReference ref, Uint32 Tdata[]);
3286   bool check_fire_trig_pass(Uint32 op, Uint32 pass);
3287 };
3288 
3289 inline
3290 bool
check_scan_batch_completed() const3291 Dblqh::ScanRecord::check_scan_batch_completed() const
3292 {
3293   Uint32 max_rows = m_max_batch_size_rows;
3294   Uint32 max_bytes = m_max_batch_size_bytes;
3295 
3296   return (max_rows > 0 && (m_curr_batch_size_rows >= max_rows))  ||
3297     (max_bytes > 0 && (m_curr_batch_size_bytes >= max_bytes));
3298 }
3299 
3300 inline
3301 void
i_get_acc_ptr(ScanRecord * scanP,Uint32 * & acc_ptr,Uint32 index)3302 Dblqh::i_get_acc_ptr(ScanRecord* scanP, Uint32* &acc_ptr, Uint32 index)
3303 {
3304   /* Return ptr to place where acc ptr for operation with given
3305    * index is stored.
3306    * If index == 0, it's stored in the ScanRecord, otherwise it's
3307    * stored in a segment linked from the ScanRecord.
3308    */
3309   if (index == 0) {
3310     acc_ptr= (Uint32*)&scanP->scan_acc_op_ptr[0];
3311   } else {
3312     jam();
3313 
3314     Uint32 segmentIVal, segment, segmentOffset;
3315     SegmentedSectionPtr segPtr;
3316 
3317     segment= (index + SectionSegment::DataLength -1) /
3318       SectionSegment::DataLength;
3319     segmentOffset= (index - 1) % SectionSegment::DataLength;
3320 
3321     ndbassert( segment < ScanRecord::MaxScanAccSegments );
3322 
3323     segmentIVal= scanP->scan_acc_op_ptr[ segment ];
3324     getSection(segPtr, segmentIVal);
3325 
3326     acc_ptr= &segPtr.p->theData[ segmentOffset ];
3327   }
3328 }
3329 
3330 inline
3331 bool
is_same_trans(Uint32 opId,Uint32 trid1,Uint32 trid2)3332 Dblqh::is_same_trans(Uint32 opId, Uint32 trid1, Uint32 trid2)
3333 {
3334   TcConnectionrecPtr regTcPtr;
3335   regTcPtr.i= opId;
3336   ptrCheckGuard(regTcPtr, ctcConnectrecFileSize, tcConnectionrec);
3337   return ((regTcPtr.p->transid[0] == trid1) &&
3338           (regTcPtr.p->transid[1] == trid2));
3339 }
3340 
3341 inline
3342 void
get_op_info(Uint32 opId,Uint32 * hash,Uint32 * gci_hi,Uint32 * gci_lo,Uint32 * transId1,Uint32 * transId2)3343 Dblqh::get_op_info(Uint32 opId, Uint32 *hash, Uint32* gci_hi, Uint32* gci_lo,
3344                    Uint32* transId1, Uint32* transId2)
3345 {
3346   TcConnectionrecPtr regTcPtr;
3347   regTcPtr.i= opId;
3348   ptrCheckGuard(regTcPtr, ctcConnectrecFileSize, tcConnectionrec);
3349   *hash = regTcPtr.p->hashValue;
3350   *gci_hi = regTcPtr.p->gci_hi;
3351   *gci_lo = regTcPtr.p->gci_lo;
3352   *transId1 = regTcPtr.p->transid[0];
3353   *transId2 = regTcPtr.p->transid[1];
3354 }
3355 
3356 #include "../dbacc/Dbacc.hpp"
3357 
3358 inline
3359 void
accminupdate(Signal * signal,Uint32 opId,const Local_key * key)3360 Dblqh::accminupdate(Signal* signal, Uint32 opId, const Local_key* key)
3361 {
3362   TcConnectionrecPtr regTcPtr;
3363   regTcPtr.i= opId;
3364   ptrCheckGuard(regTcPtr, ctcConnectrecFileSize, tcConnectionrec);
3365   signal->theData[0] = regTcPtr.p->accConnectrec;
3366   signal->theData[1] = key->m_page_no;
3367   signal->theData[2] = key->m_page_idx;
3368   c_acc->execACCMINUPDATE(signal);
3369 
3370   if (ERROR_INSERTED(5714))
3371   {
3372     FragrecordPtr regFragptr;
3373     regFragptr.i = regTcPtr.p->fragmentptr;
3374     c_fragment_pool.getPtr(regFragptr);
3375     if (regFragptr.p->m_copy_started_state == Fragrecord::AC_NR_COPY)
3376       ndbout << " LK: " << *key;
3377   }
3378 
3379   if (ERROR_INSERTED(5712) || ERROR_INSERTED(5713))
3380     ndbout << " LK: " << *key;
3381   regTcPtr.p->m_row_id = *key;
3382 }
3383 
3384 inline
3385 void
accremoverow(Signal * signal,Uint32 opId,const Local_key * key)3386 Dblqh::accremoverow(Signal* signal, Uint32 opId, const Local_key* key)
3387 {
3388   TcConnectionrecPtr regTcPtr;
3389   regTcPtr.i= opId;
3390   ptrCheckGuard(regTcPtr, ctcConnectrecFileSize, tcConnectionrec);
3391   c_acc->removerow(regTcPtr.p->accConnectrec, key);
3392 }
3393 
3394 inline
3395 bool
TRACE_OP_CHECK(const TcConnectionrec * regTcPtr)3396 Dblqh::TRACE_OP_CHECK(const TcConnectionrec* regTcPtr)
3397 {
3398   if (ERROR_INSERTED(5714))
3399   {
3400     FragrecordPtr regFragptr;
3401     regFragptr.i = regTcPtr->fragmentptr;
3402     c_fragment_pool.getPtr(regFragptr);
3403     return regFragptr.p->m_copy_started_state == Fragrecord::AC_NR_COPY;
3404   }
3405 
3406   return (ERROR_INSERTED(5712) &&
3407 	  (regTcPtr->operation == ZINSERT ||
3408 	   regTcPtr->operation == ZDELETE)) ||
3409     ERROR_INSERTED(5713);
3410 }
3411 
3412 #endif
3413