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