~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/ndb/src/kernel/blocks/dblqh/Dblqh.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

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