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

« back to all changes in this revision

Viewing changes to storage/ndb/src/kernel/blocks/dbtup/Dbtup.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 DBTUP_H
 
17
#define DBTUP_H
 
18
 
 
19
#include <pc.hpp>
 
20
#include <SimulatedBlock.hpp>
 
21
#include <ndb_limits.h>
 
22
#include <trigger_definitions.h>
 
23
#include <AttributeHeader.hpp>
 
24
#include <Bitmask.hpp>
 
25
#include <signaldata/TupKey.hpp>
 
26
#include <signaldata/CreateTrig.hpp>
 
27
#include <signaldata/DropTrig.hpp>
 
28
#include <signaldata/TrigAttrInfo.hpp>
 
29
#include <signaldata/BuildIndx.hpp>
 
30
#include "Undo_buffer.hpp"
 
31
#include "tuppage.hpp"
 
32
#include <../pgman.hpp>
 
33
#include <../tsman.hpp>
 
34
 
 
35
// jams
 
36
#undef jam
 
37
#undef jamEntry
 
38
#ifdef DBTUP_BUFFER_CPP
 
39
#define jam()           jamLine(10000 + __LINE__)
 
40
#define jamEntry()      jamEntryLine(10000 + __LINE__)
 
41
#endif
 
42
#ifdef DBTUP_ROUTINES_CPP
 
43
#define jam()           jamLine(15000 + __LINE__)
 
44
#define jamEntry()      jamEntryLine(15000 + __LINE__)
 
45
#endif
 
46
#ifdef DBTUP_COMMIT_CPP
 
47
#define jam()           jamLine(20000 + __LINE__)
 
48
#define jamEntry()      jamEntryLine(20000 + __LINE__)
 
49
#endif
 
50
#ifdef DBTUP_FIXALLOC_CPP
 
51
#define jam()           jamLine(25000 + __LINE__)
 
52
#define jamEntry()      jamEntryLine(25000 + __LINE__)
 
53
#endif
 
54
#ifdef DBTUP_TRIGGER_CPP
 
55
#define jam()           jamLine(30000 + __LINE__)
 
56
#define jamEntry()      jamEntryLine(30000 + __LINE__)
 
57
#endif
 
58
#ifdef DBTUP_ABORT_CPP
 
59
#define jam()           jamLine(35000 + __LINE__)
 
60
#define jamEntry()      jamEntryLine(35000 + __LINE__)
 
61
#endif
 
62
#ifdef DBTUP_PAGE_MAP_CPP
 
63
#define jam()           jamLine(40000 + __LINE__)
 
64
#define jamEntry()      jamEntryLine(40000 + __LINE__)
 
65
#endif
 
66
#ifdef DBTUP_PAG_MAN_CPP
 
67
#define jam()           jamLine(45000 + __LINE__)
 
68
#define jamEntry()      jamEntryLine(45000 + __LINE__)
 
69
#endif
 
70
#ifdef DBTUP_STORE_PROC_DEF_CPP
 
71
#define jam()           jamLine(50000 + __LINE__)
 
72
#define jamEntry()      jamEntryLine(50000 + __LINE__)
 
73
#endif
 
74
#ifdef DBTUP_META_CPP
 
75
#define jam()           jamLine(55000 + __LINE__)
 
76
#define jamEntry()      jamEntryLine(55000 + __LINE__)
 
77
#endif
 
78
#ifdef DBTUP_TAB_DES_MAN_CPP
 
79
#define jam()           jamLine(60000 + __LINE__)
 
80
#define jamEntry()      jamEntryLine(60000 + __LINE__)
 
81
#endif
 
82
#ifdef DBTUP_GEN_CPP
 
83
#define jam()           jamLine(65000 + __LINE__)
 
84
#define jamEntry()      jamEntryLine(65000 + __LINE__)
 
85
#endif
 
86
#ifdef DBTUP_INDEX_CPP
 
87
#define jam()           jamLine(70000 + __LINE__)
 
88
#define jamEntry()      jamEntryLine(70000 + __LINE__)
 
89
#endif
 
90
#ifdef DBTUP_DEBUG_CPP
 
91
#define jam()           jamLine(75000 + __LINE__)
 
92
#define jamEntry()      jamEntryLine(75000 + __LINE__)
 
93
#endif
 
94
#ifdef DBTUP_VAR_ALLOC_CPP
 
95
#define jam()           jamLine(80000 + __LINE__)
 
96
#define jamEntry()      jamEntryLine(80000 + __LINE__)
 
97
#endif
 
98
#ifdef DBTUP_SCAN_CPP
 
99
#define jam()           jamLine(85000 + __LINE__)
 
100
#define jamEntry()      jamEntryLine(85000 + __LINE__)
 
101
#endif
 
102
#ifdef DBTUP_DISK_ALLOC_CPP
 
103
#define jam()           jamLine(90000 + __LINE__)
 
104
#define jamEntry()      jamEntryLine(90000 + __LINE__)
 
105
#endif
 
106
#ifndef jam
 
107
#define jam()           jamLine(__LINE__)
 
108
#define jamEntry()      jamEntryLine(__LINE__)
 
109
#endif
 
110
 
 
111
#ifdef VM_TRACE
 
112
inline const char* dbgmask(const Bitmask<MAXNROFATTRIBUTESINWORDS>& bm) {
 
113
  static int i=0; static char buf[5][200];
 
114
  bm.getText(buf[i%5]); return buf[i++%5]; }
 
115
inline const char* dbgmask(const Uint32 bm[2]) {
 
116
  static int i=0; static char buf[5][200];
 
117
  sprintf(buf[i%5],"%08x%08x",bm[1],bm[0]); return buf[i++%5]; }
 
118
#endif
 
119
 
 
120
#define ZWORDS_ON_PAGE 8192          /* NUMBER OF WORDS ON A PAGE.      */
 
121
#define ZATTRBUF_SIZE 32             /* SIZE OF ATTRIBUTE RECORD BUFFER */
 
122
#define ZMIN_PAGE_LIMIT_TUPKEYREQ 5
 
123
#define ZTUP_VERSION_BITS 15
 
124
#define ZTUP_VERSION_MASK ((1 << ZTUP_VERSION_BITS) - 1)
 
125
#define MAX_FREE_LIST 4
 
126
 
 
127
inline Uint32* ALIGN_WORD(void * ptr)
 
128
{
 
129
  return (Uint32*)(((UintPtr(ptr) + 3) >> 2) << 2);
 
130
}
 
131
 
 
132
inline const Uint32* ALIGN_WORD(const void* ptr)
 
133
{
 
134
  return (Uint32*)(((UintPtr(ptr) + 3) >> 2) << 2);
 
135
}
 
136
 
 
137
#ifdef DBTUP_C
 
138
//------------------------------------------------------------------
 
139
// Jam Handling:
 
140
//
 
141
// When DBTUP reports lines through jam in the trace files it has to
 
142
// be interpreted. 4024 means as an example line 24 in DbtupCommit.cpp
 
143
// Thus 4000 is added to the line number beacuse it is located in the
 
144
// file DbtupCommit.cpp. The following is the exhaustive list of the
 
145
// added value in the various files. ndbrequire, ptrCheckGuard still
 
146
// only reports the line number in the file it currently is located in.
 
147
// 
 
148
// DbtupExecQuery.cpp         0
 
149
// DbtupBuffer.cpp         10000
 
150
// DbtupRoutines.cpp       15000
 
151
// DbtupCommit.cpp         20000
 
152
// DbtupFixAlloc.cpp       25000
 
153
// DbtupTrigger.cpp        30000
 
154
// DbtupAbort.cpp          35000
 
155
// DbtupPageMap.cpp        40000
 
156
// DbtupPagMan.cpp         45000
 
157
// DbtupStoredProcDef.cpp  50000
 
158
// DbtupMeta.cpp           55000
 
159
// DbtupTabDesMan.cpp      60000
 
160
// DbtupGen.cpp            65000
 
161
// DbtupIndex.cpp          70000
 
162
// DbtupDebug.cpp          75000
 
163
// DbtupVarAlloc.cpp       80000
 
164
// DbtupScan.cpp           85000
 
165
// DbtupDiskAlloc.cpp      90000
 
166
//------------------------------------------------------------------
 
167
 
 
168
/*
 
169
2.2 LOCAL SYMBOLS
 
170
-----------------
 
171
*/
 
172
/* ---------------------------------------------------------------- */
 
173
/*       S I Z E              O F               R E C O R D S       */
 
174
/* ---------------------------------------------------------------- */
 
175
#define ZNO_OF_ATTRBUFREC 10000             /* SIZE   OF ATTRIBUTE INFO FILE   */
 
176
#define ZNO_OF_CONCURRENT_OPEN_OP 40        /* NUMBER OF CONCURRENT OPENS      */
 
177
#define ZNO_OF_CONCURRENT_WRITE_OP 80       /* NUMBER OF CONCURRENT DISK WRITES*/
 
178
#define ZNO_OF_FRAGOPREC 20                 /* NUMBER OF CONCURRENT ADD FRAG.  */
 
179
#define TOT_PAGE_RECORD_SPACE 262144        /* SIZE OF PAGE RECORD FILE.       */
 
180
#define ZNO_OF_PAGE TOT_PAGE_RECORD_SPACE/ZWORDS_ON_PAGE   
 
181
#define ZNO_OF_PAGE_RANGE_REC 128           /* SIZE OF PAGE RANGE FILE         */
 
182
// Trigger constants
 
183
#define ZDEFAULT_MAX_NO_TRIGGERS_PER_TABLE 16
 
184
 
 
185
/* ---------------------------------------------------------------- */
 
186
/* A ATTRIBUTE MAY BE NULL, DYNAMIC OR NORMAL. A NORMAL ATTRIBUTE   */
 
187
/* IS A ATTRIBUTE THAT IS NOT NULL OR DYNAMIC. A NULL ATTRIBUTE     */
 
188
/* MAY HAVE NO VALUE. A DYNAMIC ATTRIBUTE IS A NULL ATTRIBUTE THAT  */
 
189
/* DOES NOT HAVE TO BE A MEMBER OF EVERY TUPLE I A CERTAIN TABLE.   */
 
190
/* ---------------------------------------------------------------- */
 
191
/**
 
192
 * #defines moved into include/kernel/Interpreter.hpp
 
193
 */
 
194
#define ZINSERT_DELETE 0
 
195
#define ZUPDATE_ALL 8
 
196
/* ---------------------------------------------------------------- */
 
197
/* THE MINIMUM SIZE OF AN 'EMPTY' TUPLE HEADER IN R-WORDS           */
 
198
/* ---------------------------------------------------------------- */
 
199
          /* THE TUPLE HEADER FIELD 'SIZE OF NULL ATTR. FIELD' SPECIFYES    */
 
200
          /* THE SIZE OF THE TUPLE HEADER FIELD 'NULL ATTR. FIELD'.         */
 
201
          /* THE TUPLE HEADER FIELD 'TYPE' SPECIFYES THE TYPE OF THE TUPLE  */
 
202
          /* HEADER.                                                        */
 
203
                               /* TUPLE ATTRIBUTE INDEX CLUSTERS, ATTRIBUTE */
 
204
                               /* CLUSTERS AND A DYNAMIC ATTRIBUTE HEADER.  */
 
205
                               /* IT MAY ALSO CONTAIN SHORT ATTRIBUTES AND  */
 
206
                               /* POINTERS TO LONG ATTRIBUTE HEADERS.       */
 
207
                               /* TUPLE ATTRIBUTE INDEX CLUSTERS, ATTRIBUTE */
 
208
                               /* CLUSTERS AND A DYNAMIC ATTRIBUTE HEADER.  */
 
209
 
 
210
          /* DATA STRUCTURE TYPES */
 
211
          /* WHEN ATTRIBUTE INFO IS SENT WITH A ATTRINFO-SIGNAL THE         */
 
212
          /* VARIABLE TYPE IS SPECIFYED. THIS MUST BE DONE TO BE ABLE TO    */
 
213
          /* NOW HOW MUCH DATA OF A ATTRIBUTE TO READ FROM ATTRINFO.        */
 
214
 
 
215
          /* WHEN A REQUEST CAN NOT BE EXECUTED BECAUSE OF A ERROR THE      */
 
216
          /* ERROR MUST BE IDENTIFYED BY MEANS OF A ERROR CODE AND SENT TO  */
 
217
          /* THE REQUESTER.                                                 */
 
218
#define ZGET_OPREC_ERROR 804            // TUP_SEIZEREF
 
219
 
 
220
#define ZEXIST_FRAG_ERROR 816           // Add fragment
 
221
#define ZFULL_FRAGRECORD_ERROR 817      // Add fragment
 
222
#define ZNO_FREE_PAGE_RANGE_ERROR 818   // Add fragment
 
223
#define ZNOFREE_FRAGOP_ERROR 830        // Add fragment
 
224
#define ZTOO_LARGE_TUPLE_ERROR 851      // Add fragment
 
225
#define ZNO_FREE_TAB_ENTRY_ERROR 852    // Add fragment
 
226
#define ZNO_PAGES_ALLOCATED_ERROR 881   // Add fragment
 
227
 
 
228
#define ZGET_REALPID_ERROR 809
 
229
#define ZNOT_IMPLEMENTED_ERROR 812
 
230
#define ZSEIZE_ATTRINBUFREC_ERROR 805
 
231
#define ZTOO_MUCH_ATTRINFO_ERROR 823
 
232
#define ZMEM_NOTABDESCR_ERROR 826
 
233
#define ZMEM_NOMEM_ERROR 827
 
234
#define ZAI_INCONSISTENCY_ERROR 829
 
235
#define ZNO_ILLEGAL_NULL_ATTR 839
 
236
#define ZNOT_NULL_ATTR 840
 
237
#define ZNO_INSTRUCTION_ERROR 871
 
238
#define ZOUTSIDE_OF_PROGRAM_ERROR 876
 
239
#define ZSTORED_PROC_ID_ERROR 877
 
240
#define ZREGISTER_INIT_ERROR 878
 
241
#define ZATTRIBUTE_ID_ERROR 879
 
242
#define ZTRY_TO_READ_TOO_MUCH_ERROR 880
 
243
#define ZTOTAL_LEN_ERROR 882
 
244
#define ZATTR_INTERPRETER_ERROR 883
 
245
#define ZSTACK_OVERFLOW_ERROR 884
 
246
#define ZSTACK_UNDERFLOW_ERROR 885
 
247
#define ZTOO_MANY_INSTRUCTIONS_ERROR 886
 
248
#define ZTRY_TO_UPDATE_ERROR 888
 
249
#define ZCALL_ERROR 890
 
250
#define ZTEMPORARY_RESOURCE_FAILURE 891
 
251
#define ZUNSUPPORTED_BRANCH 892
 
252
 
 
253
#define ZSTORED_SEIZE_ATTRINBUFREC_ERROR 873 // Part of Scan
 
254
#define ZSTORED_TOO_MUCH_ATTRINFO_ERROR 874
 
255
 
 
256
#define ZREAD_ONLY_CONSTRAINT_VIOLATION 893
 
257
#define ZVAR_SIZED_NOT_SUPPORTED 894
 
258
#define ZINCONSISTENT_NULL_ATTRIBUTE_COUNT 895
 
259
#define ZTUPLE_CORRUPTED_ERROR 896
 
260
#define ZTRY_UPDATE_PRIMARY_KEY 897
 
261
#define ZMUST_BE_ABORTED_ERROR 898
 
262
#define ZTUPLE_DELETED_ERROR 626
 
263
#define ZINSERT_ERROR 630
 
264
 
 
265
#define ZINVALID_CHAR_FORMAT 744
 
266
#define ZROWID_ALLOCATED 899
 
267
 
 
268
          /* SOME WORD POSITIONS OF FIELDS IN SOME HEADERS */
 
269
 
 
270
#define ZFREE_COMMON 1                    /* PAGE STATE, PAGE IN COMMON AREA                   */
 
271
#define ZEMPTY_MM 2                       /* PAGE STATE, PAGE IN EMPTY LIST                    */
 
272
#define ZTH_MM_FREE 3                     /* PAGE STATE, TUPLE HEADER PAGE WITH FREE AREA      */
 
273
#define ZTH_MM_FULL 4                     /* PAGE STATE, TUPLE HEADER PAGE WHICH IS FULL       */
 
274
 
 
275
#define ZTD_HEADER 0                      /* HEADER POSITION                   */
 
276
#define ZTD_DATASIZE 1                    /* SIZE OF THE DATA IN THIS CHUNK    */
 
277
#define ZTD_SIZE 2                        /* TOTAL SIZE OF TABLE DESCRIPTOR    */
 
278
 
 
279
          /* TRAILER POSITIONS FROM END OF TABLE DESCRIPTOR RECORD               */
 
280
#define ZTD_TR_SIZE 1                     /* SIZE DESCRIPTOR POS FROM END+1    */
 
281
#define ZTD_TR_TYPE 2
 
282
#define ZTD_TRAILER_SIZE 2                /* TOTAL SIZE OF TABLE TRAILER       */
 
283
#define ZAD_SIZE 2                        /* TOTAL SIZE OF ATTR DESCRIPTOR     */
 
284
#define ZAD_LOG_SIZE 1                    /* TWO LOG OF TOTAL SIZE OF ATTR DESCRIPTOR     */
 
285
 
 
286
          /* CONSTANTS USED TO HANDLE TABLE DESCRIPTOR AS A FREELIST             */
 
287
#define ZTD_FL_HEADER 0                   /* HEADER POSITION                   */
 
288
#define ZTD_FL_SIZE 1                     /* TOTAL SIZE OF THIS FREELIST ENTRY */
 
289
#define ZTD_FL_PREV 2                     /* PREVIOUS RECORD IN FREELIST       */
 
290
#define ZTD_FL_NEXT 3                     /* NEXT RECORD IN FREELIST           */
 
291
#define ZTD_FREE_SIZE 16                  /* SIZE NEEDED TO HOLD ONE FL ENTRY  */
 
292
 
 
293
          /* CONSTANTS USED IN LSB OF TABLE DESCRIPTOR HEADER DESCRIBING USAGE   */
 
294
#define ZTD_TYPE_FREE 0                   /* RECORD LINKED INTO FREELIST       */
 
295
#define ZTD_TYPE_NORMAL 1                 /* RECORD USED AS TABLE DESCRIPTOR   */
 
296
          /* ATTRIBUTE OPERATION CONSTANTS */
 
297
#define ZLEAF 1
 
298
#define ZNON_LEAF 2
 
299
 
 
300
          /* ATTRINBUFREC VARIABLE POSITIONS. */
 
301
#define ZBUF_PREV 29                      /* POSITION OF 'PREV'-VARIABLE (USED BY INTERPRETED EXEC) */
 
302
#define ZBUF_DATA_LEN 30                  /* POSITION OF 'DATA LENGTH'-VARIABLE. */
 
303
#define ZBUF_NEXT 31                      /* POSITION OF 'NEXT'-VARIABLE.        */
 
304
#define ZSAVE_BUF_NEXT 28
 
305
#define ZSAVE_BUF_DATA_LEN 27
 
306
 
 
307
          /* RETURN POINTS. */
 
308
          /* RESTART PHASES */
 
309
#define ZSTARTPHASE1 1
 
310
#define ZSTARTPHASE2 2
 
311
#define ZSTARTPHASE3 3
 
312
#define ZSTARTPHASE4 4
 
313
#define ZSTARTPHASE6 6
 
314
 
 
315
#define ZADDFRAG 0
 
316
 
 
317
//------------------------------------------------------------
 
318
// TUP_CONTINUEB codes
 
319
//------------------------------------------------------------
 
320
#define ZINITIALISE_RECORDS 6
 
321
#define ZREL_FRAG 7
 
322
#define ZREPORT_MEMORY_USAGE 8
 
323
#define ZBUILD_INDEX 9
 
324
#define ZTUP_SCAN 10
 
325
#define ZFREE_EXTENT 11
 
326
#define ZUNMAP_PAGES 12
 
327
#define ZFREE_VAR_PAGES 13
 
328
 
 
329
#define ZSCAN_PROCEDURE 0
 
330
#define ZCOPY_PROCEDURE 2
 
331
#define ZSTORED_PROCEDURE_DELETE 3
 
332
#define ZSTORED_PROCEDURE_FREE 0xffff
 
333
#define ZMIN_PAGE_LIMIT_TUP_COMMITREQ 2
 
334
 
 
335
#define ZSKIP_TUX_TRIGGERS 0x1 // flag for TUP_ABORTREQ
 
336
 
 
337
#endif
 
338
 
 
339
class Dbtup: public SimulatedBlock {
 
340
friend class Suma;
 
341
public:
 
342
struct KeyReqStruct;
 
343
friend struct KeyReqStruct; // CC
 
344
typedef bool (Dbtup::* ReadFunction)(Uint32*,
 
345
                                     KeyReqStruct*,
 
346
                                     AttributeHeader*,
 
347
                                     Uint32);
 
348
typedef bool (Dbtup::* UpdateFunction)(Uint32*,
 
349
                                       KeyReqStruct*,
 
350
                                       Uint32);
 
351
private:
 
352
  
 
353
  typedef Tup_fixsize_page Fix_page;
 
354
  typedef Tup_varsize_page Var_page;
 
355
 
 
356
public:
 
357
  class Dblqh *c_lqh;
 
358
  Tsman* c_tsman;
 
359
  Lgman* c_lgman;
 
360
  Page_cache_client m_pgman;
 
361
 
 
362
// State values
 
363
enum ChangeMaskState {
 
364
  DELETE_CHANGES = 0,
 
365
  SET_ALL_MASK = 1,
 
366
  USE_SAVED_CHANGE_MASK = 2,
 
367
  RECALCULATE_CHANGE_MASK = 3
 
368
};
 
369
 
 
370
enum TransState {
 
371
  TRANS_IDLE = 0,
 
372
  TRANS_STARTED = 1,
 
373
  TRANS_WAIT_STORED_PROCEDURE_ATTR_INFO = 2,
 
374
  TRANS_ERROR_WAIT_STORED_PROCREQ = 3,
 
375
  TRANS_ERROR_WAIT_TUPKEYREQ = 4,
 
376
  TRANS_TOO_MUCH_AI = 5,
 
377
  TRANS_DISCONNECTED = 6
 
378
};
 
379
 
 
380
enum TupleState {
 
381
  TUPLE_PREPARED = 1,
 
382
  TUPLE_ALREADY_ABORTED = 2,
 
383
  TUPLE_TO_BE_COMMITTED = 3
 
384
};
 
385
  
 
386
enum State {
 
387
  NOT_INITIALIZED = 0,
 
388
  IDLE = 17,
 
389
  ACTIVE = 18,
 
390
  SYSTEM_RESTART = 19,
 
391
  DEFINED = 34,
 
392
  NOT_DEFINED = 37,
 
393
  NORMAL_PAGE = 40,
 
394
  DEFINING = 65,
 
395
  DROPPING = 68
 
396
};
 
397
 
 
398
// Records
 
399
/* ************** ATTRIBUTE INFO BUFFER RECORD ****************** */
 
400
/* THIS RECORD IS USED AS A BUFFER FOR INCOMING AND OUTGOING DATA */
 
401
/* ************************************************************** */
 
402
struct Attrbufrec {
 
403
  Uint32 attrbuf[ZATTRBUF_SIZE];
 
404
}; /* p2c: size = 128 bytes */
 
405
 
 
406
typedef Ptr<Attrbufrec> AttrbufrecPtr;
 
407
 
 
408
 
 
409
 
 
410
struct Fragoperrec {
 
411
  Uint64 minRows;
 
412
  Uint64 maxRows;
 
413
  Uint32 nextFragoprec;
 
414
  Uint32 lqhPtrFrag;
 
415
  Uint32 fragidFrag;
 
416
  Uint32 tableidFrag;
 
417
  Uint32 fragPointer;
 
418
  Uint32 attributeCount;
 
419
  Uint32 charsetIndex;
 
420
  Uint32 m_null_bits[2];
 
421
  Uint32 m_fix_attributes_size[2]; // In words
 
422
  Uint32 m_var_attributes_size[2]; // In bytes
 
423
  BlockReference lqhBlockrefFrag;
 
424
  bool inUse;
 
425
  bool definingFragment;
 
426
};
 
427
typedef Ptr<Fragoperrec> FragoperrecPtr;
 
428
 
 
429
 
 
430
  typedef Tup_page Page;
 
431
  typedef Ptr<Page> PagePtr;
 
432
 
 
433
  // Scan position
 
434
  struct ScanPos {
 
435
    enum Get {
 
436
      Get_undef = 0,
 
437
      Get_next_page,
 
438
      Get_page,
 
439
      Get_next_page_mm,
 
440
      Get_page_mm,
 
441
      Get_next_page_dd,
 
442
      Get_page_dd,
 
443
      Get_next_tuple,
 
444
      Get_tuple,
 
445
      Get_next_tuple_fs,
 
446
      Get_tuple_fs
 
447
    };
 
448
    Get m_get;                  // entry point in scanNext
 
449
    Local_key m_key;            // scan position pointer MM or DD
 
450
    Page* m_page;               // scanned MM or DD (cache) page
 
451
    Local_key m_key_mm;         // MM local key returned
 
452
    Uint32 m_realpid_mm;        // MM real page id
 
453
    Uint32 m_extent_info_ptr_i;
 
454
  };
 
455
 
 
456
  // Scan Lock
 
457
  struct ScanLock {
 
458
    Uint32 m_accLockOp;
 
459
    union {
 
460
      Uint32 nextPool;
 
461
      Uint32 nextList;
 
462
    };
 
463
    Uint32 prevList;
 
464
  };
 
465
  typedef Ptr<ScanLock> ScanLockPtr;
 
466
  ArrayPool<ScanLock> c_scanLockPool;
 
467
 
 
468
  // Tup scan, similar to Tux scan.  Later some of this could
 
469
  // be moved to common superclass.
 
470
  struct ScanOp {
 
471
    ScanOp() :
 
472
      m_state(Undef),
 
473
      m_bits(0),
 
474
      m_userPtr(RNIL),
 
475
      m_userRef(RNIL),
 
476
      m_tableId(RNIL),
 
477
      m_fragId(~(Uint32)0),
 
478
      m_fragPtrI(RNIL),
 
479
      m_transId1(0),
 
480
      m_transId2(0),
 
481
      m_savePointId(0),
 
482
      m_accLockOp(RNIL)
 
483
    {}
 
484
 
 
485
    enum State {
 
486
      Undef = 0,
 
487
      First = 1,                // before first entry
 
488
      Current = 2,              // at current before locking
 
489
      Blocked = 3,              // at current waiting for ACC lock
 
490
      Locked = 4,               // at current and locked or no lock needed
 
491
      Next = 5,                 // looking for next extry
 
492
      Last = 6,                 // after last entry
 
493
      Aborting = 7,             // lock wait at scan close
 
494
      Invalid = 9               // cannot return REF to LQH currently
 
495
    };
 
496
    Uint16 m_state;
 
497
 
 
498
    enum Bits {
 
499
      SCAN_DD        = 0x01,        // scan disk pages
 
500
      SCAN_VS        = 0x02,        // page format is var size
 
501
      SCAN_LCP       = 0x04,        // LCP mem page scan
 
502
      SCAN_LOCK_SH   = 0x10,        // lock mode shared
 
503
      SCAN_LOCK_EX   = 0x20,        // lock mode exclusive
 
504
      SCAN_LOCK_WAIT = 0x40,        // lock wait
 
505
      // any lock mode
 
506
      SCAN_LOCK      = SCAN_LOCK_SH | SCAN_LOCK_EX,
 
507
      SCAN_NR        = 0x80        // Node recovery scan
 
508
    };
 
509
    Uint16 m_bits;
 
510
    
 
511
    Uint32 m_userPtr;           // scanptr.i in LQH
 
512
    Uint32 m_userRef;
 
513
    Uint32 m_tableId;
 
514
    Uint32 m_fragId;
 
515
    Uint32 m_fragPtrI;
 
516
    Uint32 m_transId1;
 
517
    Uint32 m_transId2;
 
518
    union {
 
519
      Uint32 m_savePointId;
 
520
      Uint32 m_scanGCI;
 
521
    };
 
522
    Uint32 m_endPage;
 
523
    // lock waited for or obtained and not yet passed to LQH
 
524
    Uint32 m_accLockOp;
 
525
 
 
526
    ScanPos m_scanPos;
 
527
 
 
528
    DLFifoList<ScanLock>::Head m_accLockOps;
 
529
 
 
530
    union {
 
531
    Uint32 nextPool;
 
532
    Uint32 nextList;
 
533
    };
 
534
    Uint32 prevList;
 
535
  };
 
536
  typedef Ptr<ScanOp> ScanOpPtr;
 
537
  ArrayPool<ScanOp> c_scanOpPool;
 
538
 
 
539
  void scanReply(Signal*, ScanOpPtr scanPtr);
 
540
  void scanFirst(Signal*, ScanOpPtr scanPtr);
 
541
  bool scanNext(Signal*, ScanOpPtr scanPtr);
 
542
  void scanCont(Signal*, ScanOpPtr scanPtr);
 
543
  void disk_page_tup_scan_callback(Signal*, Uint32 scanPtrI, Uint32 page_i);
 
544
  void scanClose(Signal*, ScanOpPtr scanPtr);
 
545
  void addAccLockOp(ScanOp& scan, Uint32 accLockOp);
 
546
  void removeAccLockOp(ScanOp& scan, Uint32 accLockOp);
 
547
  void releaseScanOp(ScanOpPtr& scanPtr);
 
548
 
 
549
  // for md5 of key (could maybe reuse existing temp buffer)
 
550
  Uint64 c_dataBuffer[ZWORDS_ON_PAGE/2 + 1];
 
551
 
 
552
  struct Page_request 
 
553
  {
 
554
    Local_key m_key;
 
555
    Uint32 m_frag_ptr_i;
 
556
    Uint32 m_extent_info_ptr;
 
557
    Uint16 m_estimated_free_space; // in bytes/records
 
558
    Uint16 m_list_index;           // in Disk_alloc_info.m_page_requests
 
559
    Uint16 m_ref_count;            // Waiters for page
 
560
    Uint16 m_uncommitted_used_space;
 
561
    Uint32 nextList;
 
562
    Uint32 prevList;
 
563
    Uint32 m_magic;
 
564
  }; // 32 bytes
 
565
  
 
566
  typedef RecordPool<Page_request, WOPool> Page_request_pool;
 
567
  typedef DLFifoListImpl<Page_request_pool, Page_request> Page_request_list;
 
568
  typedef LocalDLFifoListImpl<Page_request_pool, Page_request> Local_page_request_list;
 
569
 
 
570
  STATIC_CONST( EXTENT_SEARCH_MATRIX_COLS = 4 ); // Guarantee size
 
571
  STATIC_CONST( EXTENT_SEARCH_MATRIX_ROWS = 5 ); // Total size
 
572
  STATIC_CONST( EXTENT_SEARCH_MATRIX_SIZE = 20 );
 
573
  
 
574
  struct Extent_list_t
 
575
  {
 
576
    Uint32 nextList;
 
577
  };
 
578
 
 
579
  struct Extent_info : public Extent_list_t
 
580
  {
 
581
    Uint32 m_magic;
 
582
    Uint32 m_first_page_no;
 
583
    Local_key m_key;
 
584
    Uint32 m_free_space;
 
585
    Uint32 m_free_matrix_pos;
 
586
    Uint16 m_free_page_count[EXTENT_SEARCH_MATRIX_COLS];
 
587
    union {
 
588
      Uint32 nextList;
 
589
      Uint32 nextPool;
 
590
    };
 
591
    Uint32 prevList;
 
592
    Uint32 nextHash, prevHash;
 
593
 
 
594
    Uint32 hashValue() const {
 
595
      return (m_key.m_file_no << 16) ^ m_key.m_page_idx;
 
596
    }
 
597
 
 
598
    Extent_info() {}
 
599
    bool equal(const Extent_info & rec) const {
 
600
      return m_key.m_file_no == rec.m_key.m_file_no &&
 
601
        m_key.m_page_idx == rec.m_key.m_page_idx;
 
602
    }
 
603
  }; // 40 bytes
 
604
 
 
605
  typedef RecordPool<Extent_info, RWPool> Extent_info_pool;
 
606
  typedef DLListImpl<Extent_info_pool, Extent_info> Extent_info_list;
 
607
  typedef LocalDLListImpl<Extent_info_pool, Extent_info> Local_extent_info_list;
 
608
  typedef DLHashTableImpl<Extent_info_pool, Extent_info> Extent_info_hash;
 
609
  typedef SLListImpl<Extent_info_pool, Extent_info, Extent_list_t> Fragment_extent_list;
 
610
  typedef LocalSLListImpl<Extent_info_pool, Extent_info, Extent_list_t> Local_fragment_extent_list;
 
611
  struct Tablerec;
 
612
  struct Disk_alloc_info 
 
613
  {
 
614
    Disk_alloc_info() {}
 
615
    Disk_alloc_info(const Tablerec* tabPtrP, 
 
616
                    Uint32 extent_size_in_pages);
 
617
    Uint32 m_extent_size;
 
618
    
 
619
    /**
 
620
     * Disk allocation
 
621
     *
 
622
     * 1) Allocate space on pages that already are dirty
 
623
     *    (4 free lists for different requests)
 
624
     * 2) Allocate space on pages waiting to maped that will be dirty
 
625
     *    (4 free lists for different requests)
 
626
     * 3) Check if "current" extent can accommodate request
 
627
     *    If so, allocate page from there
 
628
     *    Else put "current" into free matrix
 
629
     * 4) Search free matrix for extent with greatest amount of free space
 
630
     *    while still accommodating current request
 
631
     *    (20 free lists for different requests)
 
632
     */
 
633
    
 
634
    /**
 
635
     * Free list of pages in different size
 
636
     *   that are dirty
 
637
     */
 
638
    DLList<Page>::Head m_dirty_pages[MAX_FREE_LIST];   // In real page id's
 
639
 
 
640
    /**
 
641
     * Requests (for update) that have sufficient space left after request
 
642
     *   these are currently being "mapped"
 
643
     */
 
644
    Page_request_list::Head m_page_requests[MAX_FREE_LIST];
 
645
 
 
646
    DLList<Page>::Head m_unmap_pages;
 
647
 
 
648
    /**
 
649
     * Current extent
 
650
     */
 
651
    Uint32 m_curr_extent_info_ptr_i;
 
652
    
 
653
    /**
 
654
     * 
 
655
     */
 
656
    STATIC_CONST( SZ = EXTENT_SEARCH_MATRIX_SIZE );
 
657
    Extent_info_list::Head m_free_extents[SZ];
 
658
    Uint32 m_total_extent_free_space_thresholds[EXTENT_SEARCH_MATRIX_ROWS];
 
659
    Uint32 m_page_free_bits_map[EXTENT_SEARCH_MATRIX_COLS];
 
660
 
 
661
    Uint32 find_extent(Uint32 sz) const;
 
662
    Uint32 calc_extent_pos(const Extent_info*) const;
 
663
 
 
664
    /**
 
665
     * Compute minimum free space on page given bits
 
666
     */
 
667
    Uint32 calc_page_free_space(Uint32 bits) const {
 
668
      return m_page_free_bits_map[bits];
 
669
    }
 
670
  
 
671
    /**
 
672
     * Compute page free bits, given free space
 
673
     */
 
674
    Uint32 calc_page_free_bits(Uint32 free) const {
 
675
      for(Uint32 i = 0; i<EXTENT_SEARCH_MATRIX_COLS-1; i++)
 
676
        if(free >= m_page_free_bits_map[i])
 
677
          return i;
 
678
      return EXTENT_SEARCH_MATRIX_COLS - 1;
 
679
    }
 
680
 
 
681
    Fragment_extent_list::Head m_extent_list;
 
682
  };
 
683
  
 
684
  void dump_disk_alloc(Disk_alloc_info&);
 
685
 
 
686
struct Fragrecord {
 
687
  Uint32 nextStartRange;
 
688
  Uint32 currentPageRange;
 
689
  Uint32 rootPageRange;
 
690
  Uint32 noOfPages;
 
691
  Uint32 noOfVarPages;
 
692
  Uint32 noOfPagesToGrow;
 
693
 
 
694
  DLList<Page>::Head emptyPrimPage; // allocated pages (not init)
 
695
  DLFifoList<Page>::Head thFreeFirst;   // pages with atleast 1 free record
 
696
  SLList<Page>::Head m_empty_pages; // Empty pages not in logical/physical map
 
697
  
 
698
  Uint32 m_lcp_scan_op;
 
699
  Uint32 m_lcp_keep_list;
 
700
 
 
701
  State fragStatus;
 
702
  Uint32 fragTableId;
 
703
  Uint32 fragmentId;
 
704
  Uint32 nextfreefrag;
 
705
  DLList<Page>::Head free_var_page_array[MAX_FREE_LIST];
 
706
  
 
707
  DLList<ScanOp>::Head m_scanList;
 
708
 
 
709
  enum { UC_LCP = 1, UC_CREATE = 2, UC_SET_LCP = 3 };
 
710
  Uint32 m_restore_lcp_id;
 
711
  Uint32 m_undo_complete;
 
712
  Uint32 m_tablespace_id;
 
713
  Uint32 m_logfile_group_id;
 
714
  Disk_alloc_info m_disk_alloc_info;
 
715
  Uint32 m_var_page_chunks;
 
716
};
 
717
typedef Ptr<Fragrecord> FragrecordPtr;
 
718
 
 
719
 
 
720
struct Operationrec {
 
721
  /*
 
722
   * To handle Attrinfo signals and buffer them up we need to
 
723
   * a simple list with first and last and we also need to keep track
 
724
   * of how much we received for security check.
 
725
   * Will most likely disappear with introduction of long signals.
 
726
   * These variables are used before TUPKEYREQ is received and not
 
727
   * thereafter and is disposed with after calling copyAttrinfo
 
728
   * which is called before putting the operation into its lists.
 
729
   * Thus we can use union declarations for these variables.
 
730
   */
 
731
 
 
732
  /*
 
733
   * Used by scans to find the Attrinfo buffers.
 
734
   * This is only until returning from copyAttrinfo and
 
735
   * can thus reuse the same memory as needed by the
 
736
   * active operation list variables.
 
737
   */
 
738
 
 
739
  /*
 
740
   * Doubly linked list with anchor on tuple.
 
741
   * This is to handle multiple updates on the same tuple
 
742
   * by the same transaction.
 
743
   */
 
744
  union {
 
745
    Uint32 prevActiveOp;
 
746
    Uint32 storedProcedureId; //Used until copyAttrinfo
 
747
  };
 
748
  union {
 
749
    Uint32 nextActiveOp;
 
750
    Uint32 currentAttrinbufLen; //Used until copyAttrinfo
 
751
  };
 
752
 
 
753
  Operationrec() {}
 
754
  bool is_first_operation() const { return prevActiveOp == RNIL;}
 
755
  bool is_last_operation() const { return nextActiveOp == RNIL;}
 
756
 
 
757
  Uint32 m_undo_buffer_space; // In words
 
758
  union {
 
759
    Uint32 firstAttrinbufrec; //Used until copyAttrinfo
 
760
  };
 
761
  Uint32 m_any_value;
 
762
  union {
 
763
    Uint32 lastAttrinbufrec; //Used until copyAttrinfo
 
764
    Uint32 nextPool;
 
765
  };
 
766
  Uint32 attrinbufLen; //only used during STORED_PROCDEF phase
 
767
  Uint32 storedProcPtr; //only used during STORED_PROCDEF phase
 
768
  
 
769
  /*
 
770
   * From fragment i-value we can find fragment and table record
 
771
   */
 
772
  Uint32 fragmentPtr;
 
773
 
 
774
  /*
 
775
   * We need references to both the original tuple and the copy tuple.
 
776
   * We keep the page's real i-value and its index and from there we
 
777
   * can find out about the fragment page id and the page offset.
 
778
   */
 
779
  Local_key m_tuple_location;
 
780
  Local_key m_copy_tuple_location;
 
781
 
 
782
  /*
 
783
   * We keep the record linked to the operation record in LQH.
 
784
   * This is needed due to writing of REDO log must be performed
 
785
   * in correct order, which is the same order as the writes
 
786
   * occurred. LQH can receive the records in different order.
 
787
   */
 
788
  Uint32 userpointer;
 
789
 
 
790
  /*
 
791
   * When responding to queries in the same transaction they will see
 
792
   * a result from the save point id the query was started. Again
 
793
   * functionality for multi-updates of the same record in one
 
794
   * transaction.
 
795
   */
 
796
  union {
 
797
    Uint32 savepointId;
 
798
    Uint32 m_commit_disk_callback_page;
 
799
  };
 
800
 
 
801
  /*
 
802
   * We use 64 bits to save change mask for the most common cases.
 
803
   */
 
804
  Uint32 saved_change_mask[2];
 
805
 
 
806
  /*
 
807
   * State variables on connection.
 
808
   * State variable on tuple after multi-updates
 
809
   * Is operation undo logged or not
 
810
   * Is operation in fragment list
 
811
   * Is operation in multi-update list
 
812
   * Operation type (READ, UPDATE, etc)
 
813
   * Is record primary replica
 
814
   * Is delete or insert performed
 
815
   */
 
816
  struct OpBitFields {
 
817
    unsigned int trans_state : 3;
 
818
    unsigned int tuple_state : 2;
 
819
    unsigned int in_active_list : 1;
 
820
 
 
821
    unsigned int op_type : 3;
 
822
    unsigned int delete_insert_flag : 1;
 
823
    unsigned int primary_replica : 1;
 
824
    unsigned int change_mask_state : 2;
 
825
    unsigned int m_disk_preallocated : 1;
 
826
    unsigned int m_load_diskpage_on_commit : 1;
 
827
    unsigned int m_wait_log_buffer : 1;
 
828
  };
 
829
  union {
 
830
    OpBitFields op_struct;
 
831
    Uint16 op_bit_fields;
 
832
  };
 
833
 
 
834
  /*
 
835
   * TUX needs to know the tuple version of the tuple since it
 
836
   * keeps an entry for both the committed and all versions in
 
837
   * a transaction currently. So each update will create a new
 
838
   * version even if in the same transaction.
 
839
   */
 
840
  Uint16 tupVersion;
 
841
};
 
842
typedef Ptr<Operationrec> OperationrecPtr;
 
843
 
 
844
          /* ****************************** PAGE RANGE RECORD ************************** */
 
845
          /* PAGE RANGES AND BASE PAGE ID. EACH RANGE HAS A  CORRESPONDING BASE PAGE ID  */
 
846
          /* THAT IS USED TO  CALCULATE REAL PAGE ID FROM A FRAGMENT PAGE ID AND A TABLE */
 
847
          /* REFERENCE.                                                                  */
 
848
          /* THE PAGE RANGES ARE ORGANISED IN A B-TREE FASHION WHERE THE VARIABLE TYPE   */
 
849
          /* SPECIFIES IF A LEAF NODE HAS BEEN REACHED. IF A LEAF NODE HAS BEEN REACHED  */
 
850
          /* THEN BASE_PAGE_ID IS THE BASE_PAGE_ID OF THE SET OF PAGES THAT WAS          */
 
851
          /* ALLOCATED IN THAT RANGE. OTHERWISE BASE_PAGE_ID IS THE POINTER TO THE NEXT  */
 
852
          /* PAGE_RANGE RECORD.                                                          */
 
853
          /* *************************************************************************** */
 
854
struct PageRange {
 
855
  Uint32 startRange[4];                                  /* START OF RANGE                                   */
 
856
  Uint32 endRange[4];                                    /* END OF THIS RANGE                                */
 
857
  Uint32 basePageId[4];                                  /* BASE PAGE ID.                                    */
 
858
/*----               VARIABLE BASE_PAGE_ID2 (4) 8 DS NEEDED WHEN SUPPORTING 40 BIT PAGE ID           -------*/
 
859
  Uint8 type[4];                                        /* TYPE OF BASE PAGE ID                             */
 
860
  Uint32 nextFree;                                       /* NEXT FREE PAGE RANGE RECORD                      */
 
861
  Uint32 parentPtr;                                      /* THE PARENT TO THE PAGE RANGE REC IN THE B-TREE   */
 
862
  Uint8 currentIndexPos;
 
863
};
 
864
typedef Ptr<PageRange> PageRangePtr;
 
865
 
 
866
 
 
867
  /* ************* TRIGGER DATA ************* */
 
868
  /* THIS RECORD FORMS LISTS OF ACTIVE       */
 
869
  /* TRIGGERS FOR EACH TABLE.                 */
 
870
  /* THE RECORDS ARE MANAGED BY A TRIGGER     */
 
871
  /* POOL wHERE A TRIGGER RECORD IS SEIZED    */
 
872
  /* WHEN A TRIGGER IS ACTIVATED AND RELEASED */
 
873
  /* WHEN THE TRIGGER IS DEACTIVATED.         */
 
874
  /* **************************************** */
 
875
struct TupTriggerData {
 
876
  TupTriggerData() {}
 
877
  
 
878
  /**
 
879
   * Trigger id, used by DICT/TRIX to identify the trigger
 
880
   *
 
881
   * trigger Ids are unique per block for SUBSCRIPTION triggers.
 
882
   * This is so that BACKUP can use TUP triggers directly and delete them
 
883
   * properly.
 
884
   */
 
885
  Uint32 triggerId;
 
886
 
 
887
  /**
 
888
   * Index id is needed for ordered index.
 
889
   */
 
890
  Uint32 indexId;
 
891
 
 
892
  /**
 
893
   * Trigger type etc, defines what the trigger is used for
 
894
   */
 
895
  TriggerType::Value triggerType;
 
896
  TriggerActionTime::Value triggerActionTime;
 
897
  TriggerEvent::Value triggerEvent;
 
898
  /**
 
899
   * Receiver block
 
900
   */
 
901
  Uint32 m_receiverBlock;
 
902
  
 
903
  /**
 
904
   * Monitor all replicas, i.e. trigger will fire on all nodes where tuples
 
905
   * are stored
 
906
   */
 
907
  bool monitorReplicas;
 
908
 
 
909
  /**
 
910
   * Monitor all attributes, the trigger monitors all changes to attributes 
 
911
   * in the table
 
912
   */
 
913
  bool monitorAllAttributes;
 
914
 
 
915
  /**
 
916
   * Send only changed attributes at trigger firing time.
 
917
   */
 
918
  bool sendOnlyChangedAttributes;
 
919
 
 
920
  /**
 
921
   * Send also before values at trigger firing time.
 
922
   */
 
923
  bool sendBeforeValues;
 
924
 
 
925
  /**
 
926
   * Attribute mask, defines what attributes are to be monitored
 
927
   * Can be seen as a compact representation of SQL column name list
 
928
   */
 
929
  Bitmask<MAXNROFATTRIBUTESINWORDS> attributeMask;
 
930
  
 
931
  /**
 
932
   * Next ptr (used in pool/list)
 
933
   */
 
934
  union {
 
935
    Uint32 nextPool;
 
936
    Uint32 nextList;
 
937
  };
 
938
  
 
939
  /**
 
940
   * Prev pointer (used in list)
 
941
   */
 
942
  Uint32 prevList;
 
943
 
 
944
  inline void print(NdbOut & s) const { s << "[TriggerData = " << triggerId << "]"; };
 
945
};
 
946
 
 
947
typedef Ptr<TupTriggerData> TriggerPtr;
 
948
  
 
949
/**
 
950
 * Pool of trigger data record
 
951
 */
 
952
ArrayPool<TupTriggerData> c_triggerPool;
 
953
 
 
954
  /* ************ TABLE RECORD ************ */
 
955
  /* THIS RECORD FORMS A LIST OF TABLE      */
 
956
  /* REFERENCE INFORMATION. ONE RECORD      */
 
957
  /* PER TABLE REFERENCE.                   */
 
958
  /* ************************************** */
 
959
  STATIC_CONST( MM = 0 );
 
960
  STATIC_CONST( DD = 1 );
 
961
  
 
962
  struct Tablerec {
 
963
    Tablerec(ArrayPool<TupTriggerData> & triggerPool) : 
 
964
      afterInsertTriggers(triggerPool),
 
965
      afterDeleteTriggers(triggerPool),
 
966
      afterUpdateTriggers(triggerPool),
 
967
      subscriptionInsertTriggers(triggerPool),
 
968
      subscriptionDeleteTriggers(triggerPool),
 
969
      subscriptionUpdateTriggers(triggerPool),
 
970
      constraintUpdateTriggers(triggerPool),
 
971
      tuxCustomTriggers(triggerPool)
 
972
      {}
 
973
    
 
974
    Bitmask<MAXNROFATTRIBUTESINWORDS> notNullAttributeMask;
 
975
    Bitmask<MAXNROFATTRIBUTESINWORDS> blobAttributeMask;
 
976
    
 
977
    ReadFunction* readFunctionArray;
 
978
    UpdateFunction* updateFunctionArray;
 
979
    CHARSET_INFO** charsetArray;
 
980
    
 
981
    Uint32 readKeyArray;
 
982
    Uint32 tabDescriptor;
 
983
    Uint32 m_real_order_descriptor;
 
984
    
 
985
    enum Bits
 
986
    {
 
987
      TR_Checksum = 0x1, // Need to be 1
 
988
      TR_RowGCI   = 0x2,
 
989
      TR_ForceVarPart = 0x4
 
990
    };
 
991
    Uint16 m_bits;
 
992
    Uint16 total_rec_size; // Max total size for entire tuple in words
 
993
    
 
994
    /**
 
995
     * Aggregates
 
996
     */
 
997
    Uint16 m_no_of_attributes;
 
998
    Uint16 m_no_of_disk_attributes;
 
999
    Uint16 noOfKeyAttr;
 
1000
    Uint16 noOfCharsets;
 
1001
 
 
1002
    bool need_expand() const { 
 
1003
      return m_no_of_attributes > m_attributes[MM].m_no_of_fixsize;
 
1004
    }
 
1005
 
 
1006
    bool need_expand(bool disk) const { 
 
1007
      return m_attributes[MM].m_no_of_varsize > 0 ||
 
1008
        (disk && m_no_of_disk_attributes > 0);
 
1009
    }
 
1010
    
 
1011
    bool need_shrink() const {
 
1012
      return 
 
1013
        m_attributes[MM].m_no_of_varsize > 0 ||
 
1014
        m_attributes[DD].m_no_of_varsize > 0;
 
1015
    }
 
1016
    
 
1017
    bool need_shrink(bool disk) const {
 
1018
      return 
 
1019
        m_attributes[MM].m_no_of_varsize > 0 ||
 
1020
        (disk && m_attributes[DD].m_no_of_varsize > 0);
 
1021
    }
 
1022
 
 
1023
    /**
 
1024
     * Descriptors for MM and DD part
 
1025
     */
 
1026
    struct Tuple_offsets {
 
1027
      Uint8 m_null_words;
 
1028
      Uint8 m_null_offset;
 
1029
      Uint16 m_disk_ref_offset; // In words relative m_data
 
1030
      Uint16 m_fix_header_size; // For fix size tuples= total rec size(part)
 
1031
      Uint16 m_max_var_offset;  // In bytes relative m_var_data.m_data_ptr
 
1032
    } m_offsets[2];
 
1033
    
 
1034
    Uint32 get_check_offset(Uint32 mm) const {
 
1035
      return m_offsets[mm].m_fix_header_size;
 
1036
    }
 
1037
 
 
1038
    struct {
 
1039
      Uint16 m_no_of_fixsize;
 
1040
      Uint16 m_no_of_varsize;
 
1041
    } m_attributes[2];
 
1042
    
 
1043
    // Lists of trigger data for active triggers
 
1044
    DLList<TupTriggerData> afterInsertTriggers;
 
1045
    DLList<TupTriggerData> afterDeleteTriggers;
 
1046
    DLList<TupTriggerData> afterUpdateTriggers;
 
1047
    DLList<TupTriggerData> subscriptionInsertTriggers;
 
1048
    DLList<TupTriggerData> subscriptionDeleteTriggers;
 
1049
    DLList<TupTriggerData> subscriptionUpdateTriggers;
 
1050
    DLList<TupTriggerData> constraintUpdateTriggers;
 
1051
    
 
1052
    // List of ordered indexes
 
1053
    DLList<TupTriggerData> tuxCustomTriggers;
 
1054
    
 
1055
    Uint32 fragid[MAX_FRAG_PER_NODE];
 
1056
    Uint32 fragrec[MAX_FRAG_PER_NODE];
 
1057
 
 
1058
    struct {
 
1059
      Uint32 tabUserPtr;
 
1060
      Uint32 tabUserRef;
 
1061
      Uint32 m_lcpno;
 
1062
      Uint32 m_fragPtrI;
 
1063
    } m_dropTable;
 
1064
    State tableStatus;
 
1065
  };  
 
1066
 
 
1067
  struct Disk_undo 
 
1068
  {
 
1069
    enum 
 
1070
    {
 
1071
      UNDO_ALLOC = File_formats::Undofile::UNDO_TUP_ALLOC
 
1072
      ,UNDO_UPDATE = File_formats::Undofile::UNDO_TUP_UPDATE
 
1073
      ,UNDO_FREE = File_formats::Undofile::UNDO_TUP_FREE
 
1074
      ,UNDO_CREATE = File_formats::Undofile::UNDO_TUP_CREATE
 
1075
      ,UNDO_DROP = File_formats::Undofile::UNDO_TUP_DROP
 
1076
      ,UNDO_ALLOC_EXTENT = File_formats::Undofile::UNDO_TUP_ALLOC_EXTENT
 
1077
      ,UNDO_FREE_EXTENT = File_formats::Undofile::UNDO_TUP_FREE_EXTENT
 
1078
    };
 
1079
    
 
1080
    struct Alloc 
 
1081
    {
 
1082
      Uint32 m_file_no_page_idx; // 16 bit file_no, 16 bit page_idx
 
1083
      Uint32 m_page_no;
 
1084
      Uint32 m_type_length; // 16 bit type, 16 bit length
 
1085
    };
 
1086
    
 
1087
    struct Update
 
1088
    {
 
1089
      Uint32 m_file_no_page_idx; // 16 bit file_no, 16 bit page_idx
 
1090
      Uint32 m_page_no;
 
1091
      Uint32 m_gci;
 
1092
      Uint32 m_data[1];
 
1093
      Uint32 m_type_length; // 16 bit type, 16 bit length
 
1094
    };
 
1095
    
 
1096
    struct Free
 
1097
    {
 
1098
      Uint32 m_file_no_page_idx; // 16 bit file_no, 16 bit page_idx
 
1099
      Uint32 m_page_no;
 
1100
      Uint32 m_gci;
 
1101
      Uint32 m_data[1];
 
1102
      Uint32 m_type_length; // 16 bit type, 16 bit length
 
1103
    };
 
1104
    
 
1105
    struct Create
 
1106
    {
 
1107
      Uint32 m_table;
 
1108
      Uint32 m_type_length; // 16 bit type, 16 bit length
 
1109
    };
 
1110
 
 
1111
    struct Drop
 
1112
    {
 
1113
      Uint32 m_table;
 
1114
      Uint32 m_type_length; // 16 bit type, 16 bit length
 
1115
    };
 
1116
 
 
1117
    struct AllocExtent
 
1118
    {
 
1119
      Uint32 m_table;
 
1120
      Uint32 m_fragment;
 
1121
      Uint32 m_page_no;
 
1122
      Uint32 m_file_no;
 
1123
      Uint32 m_type_length;
 
1124
    };
 
1125
 
 
1126
    struct FreeExtent
 
1127
    {
 
1128
      Uint32 m_table;
 
1129
      Uint32 m_fragment;
 
1130
      Uint32 m_page_no;
 
1131
      Uint32 m_file_no;
 
1132
      Uint32 m_type_length;
 
1133
    };
 
1134
  };
 
1135
  
 
1136
  Extent_info_pool c_extent_pool;
 
1137
  Extent_info_hash c_extent_hash;
 
1138
  Page_request_pool c_page_request_pool;
 
1139
 
 
1140
  typedef Ptr<Tablerec> TablerecPtr;
 
1141
 
 
1142
  struct storedProc {
 
1143
    Uint32 storedLinkFirst;
 
1144
    Uint32 storedLinkLast;
 
1145
    Uint32 storedCounter;
 
1146
    Uint32 nextPool;
 
1147
    Uint16 storedCode;
 
1148
    Uint16 storedProcLength;
 
1149
};
 
1150
 
 
1151
typedef Ptr<storedProc> StoredProcPtr;
 
1152
 
 
1153
ArrayPool<storedProc> c_storedProcPool;
 
1154
 
 
1155
/* **************************** TABLE_DESCRIPTOR RECORD ******************************** */
 
1156
/* THIS VARIABLE IS USED TO STORE TABLE DESCRIPTIONS. A TABLE DESCRIPTION IS STORED AS A */
 
1157
/* CONTIGUOS ARRAY IN THIS VARIABLE. WHEN A NEW TABLE IS ADDED A CHUNK IS ALLOCATED IN   */
 
1158
/* THIS RECORD. WHEN ATTRIBUTES ARE ADDED TO THE TABLE, A NEW CHUNK OF PROPER SIZE IS    */
 
1159
/* ALLOCATED AND ALL DATA IS COPIED TO THIS NEW CHUNK AND THEN THE OLD CHUNK IS PUT IN   */
 
1160
/* THE FREE LIST. EACH TABLE IS DESCRIBED BY A NUMBER OF TABLE DESCRIPTIVE ATTRIBUTES    */
 
1161
/* AND A NUMBER OF ATTRIBUTE DESCRIPTORS AS SHOWN IN FIGURE BELOW                        */
 
1162
/*                                                                                       */
 
1163
/* WHEN ALLOCATING A TABLE DESCRIPTOR THE SIZE IS ALWAYS A MULTIPLE OF 16 WORDS.         */
 
1164
/*                                                                                       */
 
1165
/*               ----------------------------------------------                          */
 
1166
/*               |    TRAILER USED FOR ALLOC/DEALLOC          |                          */
 
1167
/*               ----------------------------------------------                          */
 
1168
/*               |    TABLE DESCRIPTIVE ATTRIBUTES            |                          */
 
1169
/*               ----------------------------------------------                          */
 
1170
/*               |    ATTRIBUTE DESCRIPTION 1                 |                          */
 
1171
/*               ----------------------------------------------                          */
 
1172
/*               |    ATTRIBUTE DESCRIPTION 2                 |                          */
 
1173
/*               ----------------------------------------------                          */
 
1174
/*               |                                            |                          */
 
1175
/*               |                                            |                          */
 
1176
/*               |                                            |                          */
 
1177
/*               ----------------------------------------------                          */
 
1178
/*               |    ATTRIBUTE DESCRIPTION N                 |                          */
 
1179
/*               ----------------------------------------------                          */
 
1180
/*                                                                                       */
 
1181
/* THE TABLE DESCRIPTIVE ATTRIBUTES CONTAINS THE FOLLOWING ATTRIBUTES:                   */
 
1182
/*                                                                                       */
 
1183
/*               ----------------------------------------------                          */
 
1184
/*               |    HEADER (TYPE OF INFO)                   |                          */
 
1185
/*               ----------------------------------------------                          */
 
1186
/*               |    SIZE OF WHOLE CHUNK (INCL. TRAILER)     |                          */
 
1187
/*               ----------------------------------------------                          */
 
1188
/*               |    TABLE IDENTITY                          |                          */
 
1189
/*               ----------------------------------------------                          */
 
1190
/*               |    FRAGMENT IDENTITY                       |                          */
 
1191
/*               ----------------------------------------------                          */
 
1192
/*               |    NUMBER OF ATTRIBUTES                    |                          */
 
1193
/*               ----------------------------------------------                          */
 
1194
/*               |    SIZE OF FIXED ATTRIBUTES                |                          */
 
1195
/*               ----------------------------------------------                          */
 
1196
/*               |    NUMBER OF NULL FIELDS                   |                          */
 
1197
/*               ----------------------------------------------                          */
 
1198
/*               |    NOT USED                                |                          */
 
1199
/*               ----------------------------------------------                          */
 
1200
/*                                                                                       */
 
1201
/* THESE ATTRIBUTES ARE ALL ONE R-VARIABLE IN THE RECORD.                                */
 
1202
/* NORMALLY ONLY ONE TABLE DESCRIPTOR IS USED. DURING SCHEMA CHANGES THERE COULD         */
 
1203
/* HOWEVER EXIST MORE THAN ONE TABLE DESCRIPTION SINCE THE SCHEMA CHANGE OF VARIOUS      */
 
1204
/* FRAGMENTS ARE NOT SYNCHRONISED. THIS MEANS THAT ALTHOUGH THE SCHEMA HAS CHANGED       */
 
1205
/* IN ALL FRAGMENTS, BUT THE FRAGMENTS HAVE NOT REMOVED THE ATTRIBUTES IN THE SAME       */
 
1206
/* TIME-FRAME. THEREBY SOME ATTRIBUTE INFORMATION MIGHT DIFFER BETWEEN FRAGMENTS.        */
 
1207
/* EXAMPLES OF ATTRIBUTES THAT MIGHT DIFFER ARE SIZE OF FIXED ATTRIBUTES, NUMBER OF      */
 
1208
/* ATTRIBUTES, FIELD START WORD, START BIT.                                              */
 
1209
/*                                                                                       */
 
1210
/* AN ATTRIBUTE DESCRIPTION CONTAINS THE FOLLOWING ATTRIBUTES:                           */
 
1211
/*                                                                                       */
 
1212
/*               ----------------------------------------------                          */
 
1213
/*               |    Field Type, 4 bits (LSB Bits)           |                          */
 
1214
/*               ----------------------------------------------                          */
 
1215
/*               |    Attribute Size, 4 bits                  |                          */
 
1216
/*               ----------------------------------------------                          */
 
1217
/*               |    NULL indicator 1 bit                    |                          */
 
1218
/*               ----------------------------------------------                          */
 
1219
/*               |    Indicator if TUP stores attr. 1 bit     |                          */
 
1220
/*               ----------------------------------------------                          */
 
1221
/*               |    Not used 6 bits                         |                          */
 
1222
/*               ----------------------------------------------                          */
 
1223
/*               |    No. of elements in fixed array 16 bits  |                          */
 
1224
/*               ----------------------------------------------                          */
 
1225
/*               ----------------------------------------------                          */
 
1226
/*               |    Field Start Word, 21 bits (LSB Bits)    |                          */
 
1227
/*               ----------------------------------------------                          */
 
1228
/*               |    NULL Bit, 11 bits                       |                          */
 
1229
/*               ----------------------------------------------                          */
 
1230
/*                                                                                       */
 
1231
/* THE ATTRIBUTE SIZE CAN BE 1,2,4,8,16,32,64 AND 128 BITS.                              */
 
1232
/*                                                                                       */
 
1233
/* THE UNUSED PARTS OF THE RECORDS ARE PUT IN A LINKED LIST OF FREE PARTS. EACH OF       */
 
1234
/* THOSE FREE PARTS HAVE THREE RECORDS ASSIGNED AS SHOWN IN THIS STRUCTURE               */
 
1235
/* ALL FREE PARTS ARE SET INTO A CHUNK LIST WHERE EACH CHUNK IS AT LEAST 16 WORDS        */
 
1236
/*                                                                                       */
 
1237
/*               ----------------------------------------------                          */
 
1238
/*               |    HEADER = RNIL                           |                          */
 
1239
/*               ----------------------------------------------                          */
 
1240
/*               |    SIZE OF FREE AREA                       |                          */
 
1241
/*               ----------------------------------------------                          */
 
1242
/*               |    POINTER TO PREVIOUS FREE AREA           |                          */
 
1243
/*               ----------------------------------------------                          */
 
1244
/*               |    POINTER TO NEXT FREE AREA               |                          */
 
1245
/*               ----------------------------------------------                          */
 
1246
/*                                                                                       */
 
1247
/* IF THE POINTER TO THE NEXT AREA IS RNIL THEN THIS IS THE LAST FREE AREA.              */
 
1248
/*                                                                                       */
 
1249
/*****************************************************************************************/
 
1250
struct TableDescriptor {
 
1251
  Uint32 tabDescr;
 
1252
};
 
1253
typedef Ptr<TableDescriptor> TableDescriptorPtr;
 
1254
 
 
1255
struct HostBuffer {
 
1256
  bool  inPackedList;
 
1257
  Uint32 packetLenTA;
 
1258
  Uint32 noOfPacketsTA;
 
1259
  Uint32 packetBufferTA[30];
 
1260
};
 
1261
typedef Ptr<HostBuffer> HostBufferPtr;
 
1262
 
 
1263
  /*
 
1264
   * Build index operation record.
 
1265
   */
 
1266
  struct BuildIndexRec {
 
1267
    // request cannot use signal class due to extra members
 
1268
    Uint32 m_request[BuildIndxReq::SignalLength];
 
1269
    Uint8  m_build_vs;          // varsize pages
 
1270
    Uint32 m_indexId;           // the index
 
1271
    Uint32 m_fragNo;            // fragment number under Tablerec
 
1272
    Uint32 m_pageId;            // logical fragment page id
 
1273
    Uint32 m_tupleNo;           // tuple number on page
 
1274
    Uint32 m_buildRef;          // Where to send tuples
 
1275
    BuildIndxRef::ErrorCode m_errorCode;
 
1276
    union {
 
1277
      Uint32 nextPool;
 
1278
      Uint32 nextList;
 
1279
    };
 
1280
    Uint32 prevList;
 
1281
  };
 
1282
  typedef Ptr<BuildIndexRec> BuildIndexPtr;
 
1283
  ArrayPool<BuildIndexRec> c_buildIndexPool;
 
1284
  DLList<BuildIndexRec> c_buildIndexList;
 
1285
  Uint32 c_noOfBuildIndexRec;
 
1286
 
 
1287
  /**
 
1288
   * Reference to variable part when a tuple is chained
 
1289
   */
 
1290
  struct Var_part_ref 
 
1291
  {
 
1292
#ifdef NDB_32BIT_VAR_REF
 
1293
    /*
 
1294
      In versions prior to ndb 6.1.6, 6.2.1 and mysql 5.1.17
 
1295
      Running this code limits DataMemory to 16G, also online
 
1296
      upgrade not possible between versions
 
1297
     */
 
1298
    Uint32 m_ref;
 
1299
    STATIC_CONST( SZ32 = 1 );
 
1300
 
 
1301
    void copyout(Local_key* dst) const {
 
1302
      dst->m_page_no = m_ref >> MAX_TUPLES_BITS;
 
1303
      dst->m_page_idx = m_ref & MAX_TUPLES_PER_PAGE;
 
1304
    }
 
1305
 
 
1306
    void assign(const Local_key* src) {
 
1307
      m_ref = (src->m_page_no << MAX_TUPLES_BITS) | src->m_page_idx;
 
1308
    }
 
1309
#else
 
1310
    Uint32 m_page_no;
 
1311
    Uint32 m_page_idx;
 
1312
    STATIC_CONST( SZ32 = 2 );
 
1313
 
 
1314
    void copyout(Local_key* dst) const {
 
1315
      dst->m_page_no = m_page_no;
 
1316
      dst->m_page_idx = m_page_idx;
 
1317
    }
 
1318
 
 
1319
    void assign(const Local_key* src) {
 
1320
      m_page_no = src->m_page_no;
 
1321
      m_page_idx = src->m_page_idx;
 
1322
    }
 
1323
#endif    
 
1324
  };
 
1325
  
 
1326
  struct Disk_part_ref
 
1327
  {
 
1328
    STATIC_CONST( SZ32 = 2 );
 
1329
  };
 
1330
 
 
1331
  struct Tuple_header
 
1332
  {
 
1333
    union {
 
1334
      /**
 
1335
       * List of prepared operations for this tuple.
 
1336
       * Points to most recent/last operation, ie. to walk the list must follow
 
1337
       * regOperPtr->prevActiveOp links.
 
1338
       */
 
1339
      Uint32 m_operation_ptr_i;  // OperationPtrI
 
1340
      Uint32 m_base_record_ref;  // For disk tuple, ref to MM tuple
 
1341
    };
 
1342
    Uint32 m_header_bits;      // Header word
 
1343
    union {
 
1344
      Uint32 m_checksum;
 
1345
      Uint32 m_data[1];
 
1346
      Uint32 m_null_bits[1];
 
1347
    };
 
1348
 
 
1349
    STATIC_CONST( HeaderSize = 2 );
 
1350
    
 
1351
    /**
 
1352
     * header bits
 
1353
     */
 
1354
    STATIC_CONST( TUP_VERSION_MASK = 0xFFFF );
 
1355
    STATIC_CONST( CHAINED_ROW = 0x00010000 ); // Is var part on different page
 
1356
    STATIC_CONST( DISK_PART   = 0x00020000 ); // Is there a disk part
 
1357
    STATIC_CONST( DISK_ALLOC  = 0x00040000 ); // Is disk part allocated
 
1358
    STATIC_CONST( DISK_INLINE = 0x00080000 ); // Is disk inline
 
1359
    STATIC_CONST( ALLOC       = 0x00100000 ); // Is record allocated now
 
1360
    STATIC_CONST( MM_SHRINK   = 0x00200000 ); // Has MM part shrunk
 
1361
    STATIC_CONST( MM_GROWN    = 0x00400000 ); // Has MM part grown
 
1362
    STATIC_CONST( FREED       = 0x00800000 ); // Is freed
 
1363
    STATIC_CONST( LCP_SKIP    = 0x01000000 ); // Should not be returned in LCP
 
1364
    STATIC_CONST( LCP_KEEP    = 0x02000000 ); // Should be returned in LCP
 
1365
    STATIC_CONST( FREE        = 0x02800000 ); // Is free
 
1366
    
 
1367
    Tuple_header() {}
 
1368
    Uint32 get_tuple_version() const { 
 
1369
      return m_header_bits & TUP_VERSION_MASK;
 
1370
    }
 
1371
    void set_tuple_version(Uint32 version) { 
 
1372
      m_header_bits= 
 
1373
        (m_header_bits & ~(Uint32)TUP_VERSION_MASK) | 
 
1374
        (version & TUP_VERSION_MASK);
 
1375
    }
 
1376
 
 
1377
    Uint32* get_null_bits(const Tablerec* tabPtrP) {
 
1378
      return m_null_bits+tabPtrP->m_offsets[MM].m_null_offset;
 
1379
    }
 
1380
 
 
1381
    Uint32* get_null_bits(const Tablerec* tabPtrP, Uint32 mm) {
 
1382
      return m_null_bits+tabPtrP->m_offsets[mm].m_null_offset;
 
1383
    }
 
1384
    
 
1385
    Var_part_ref* get_var_part_ref_ptr(const Tablerec* tabPtrP) {
 
1386
      return (Var_part_ref*)(get_disk_ref_ptr(tabPtrP) + Disk_part_ref::SZ32);
 
1387
    }
 
1388
 
 
1389
    const Var_part_ref* get_var_part_ref_ptr(const Tablerec* tabPtrP) const {
 
1390
      return (Var_part_ref*)(get_disk_ref_ptr(tabPtrP) + Disk_part_ref::SZ32);
 
1391
    }
 
1392
    
 
1393
    Uint32* get_end_of_fix_part_ptr(const Tablerec* tabPtrP) {
 
1394
      return m_data + tabPtrP->m_offsets[MM].m_fix_header_size - 
 
1395
        Tuple_header::HeaderSize;
 
1396
    }
 
1397
    
 
1398
    const Uint32* get_end_of_fix_part_ptr(const Tablerec* tabPtrP) const {
 
1399
      return m_data + tabPtrP->m_offsets[MM].m_fix_header_size - 
 
1400
        Tuple_header::HeaderSize;
 
1401
    }
 
1402
    
 
1403
    Uint32* get_disk_ref_ptr(const Tablerec* tabPtrP) {
 
1404
      return m_data + tabPtrP->m_offsets[MM].m_disk_ref_offset;
 
1405
    }
 
1406
 
 
1407
    const Uint32* get_disk_ref_ptr(const Tablerec* tabPtrP) const {
 
1408
      return m_data + tabPtrP->m_offsets[MM].m_disk_ref_offset;
 
1409
    }
 
1410
 
 
1411
    Uint32 *get_mm_gci(const Tablerec* tabPtrP){
 
1412
      assert(tabPtrP->m_bits & Tablerec::TR_RowGCI);
 
1413
      return m_data + (tabPtrP->m_bits & Tablerec::TR_Checksum);
 
1414
    }
 
1415
 
 
1416
    Uint32 *get_dd_gci(const Tablerec* tabPtrP, Uint32 mm){
 
1417
      assert(tabPtrP->m_bits & Tablerec::TR_RowGCI);
 
1418
      return m_data;
 
1419
    }
 
1420
  };
 
1421
  
 
1422
struct KeyReqStruct {
 
1423
/**
 
1424
 * These variables are used as temporary storage during execution of the
 
1425
 * TUPKEYREQ signal.
 
1426
 * The first set of variables defines a number of variables needed for
 
1427
 * the fix part of the tuple.
 
1428
 *
 
1429
 * The second part defines a number of commonly used meta data variables.
 
1430
 *
 
1431
 * The third set of variables defines a set of variables needed for the
 
1432
 * variable part.
 
1433
 *
 
1434
 * The fourth part is variables needed only for updates and inserts.
 
1435
 *
 
1436
 * The fifth part is a long array of real lengths which is is put last
 
1437
 * for cache memory reasons. This is part of the variable part and
 
1438
 * contains the real allocated lengths whereas the tuple contains
 
1439
 * the length of attribute stored.
 
1440
 */
 
1441
  Tuple_header *m_tuple_ptr;
 
1442
 
 
1443
  Uint32 check_offset[2];
 
1444
 
 
1445
  TableDescriptor *attr_descr;
 
1446
  Uint32          max_read;
 
1447
  Uint32          out_buf_index;
 
1448
  Uint32          in_buf_index;
 
1449
  Uint32          in_buf_len;
 
1450
  Uint32          attr_descriptor;
 
1451
  bool            xfrm_flag;
 
1452
 
 
1453
  struct Var_data {
 
1454
    char *m_data_ptr;
 
1455
    Uint16 *m_offset_array_ptr;
 
1456
    Uint16 m_var_len_offset;
 
1457
    Uint16 m_max_var_offset;
 
1458
  } m_var_data[2];
 
1459
 
 
1460
  Tuple_header *m_disk_ptr;
 
1461
  PagePtr m_page_ptr;
 
1462
  PagePtr m_varpart_page_ptr;    // could be same as m_page_ptr_p
 
1463
  PagePtr m_disk_page_ptr;       //
 
1464
  Local_key m_row_id;
 
1465
  
 
1466
  bool            dirty_op;
 
1467
  bool            interpreted_exec;
 
1468
  bool            last_row;
 
1469
  bool            m_use_rowid;
 
1470
 
 
1471
  Signal*         signal;
 
1472
  Uint32 no_fired_triggers;
 
1473
  Uint32 frag_page_id;
 
1474
  Uint32 hash_value;
 
1475
  Uint32 gci;
 
1476
  Uint32 log_size;
 
1477
  Uint32 read_length;
 
1478
  Uint32 attrinfo_len;
 
1479
  Uint32 tc_operation_ptr;
 
1480
  Uint32 trans_id1;
 
1481
  Uint32 trans_id2;
 
1482
  Uint32 TC_index;
 
1483
  // next 2 apply only to attrids >= 64 (zero otherwise)
 
1484
  Uint32 max_attr_id_updated;
 
1485
  Uint32 no_changed_attrs;
 
1486
  BlockReference TC_ref;
 
1487
  BlockReference rec_blockref;
 
1488
  bool change_mask_calculated;
 
1489
  /*
 
1490
   * A bit mask where a bit set means that the update or insert
 
1491
   * was updating this record.
 
1492
   */
 
1493
  Bitmask<MAXNROFATTRIBUTESINWORDS> changeMask;
 
1494
  Uint16 var_pos_array[2*MAX_ATTRIBUTES_IN_TABLE + 1];
 
1495
  OperationrecPtr prevOpPtr;
 
1496
};
 
1497
 
 
1498
  friend class Undo_buffer;
 
1499
  Undo_buffer c_undo_buffer;
 
1500
  
 
1501
/*
 
1502
 No longer used:
 
1503
 Implemented by shift instructions in subroutines instead
 
1504
 
 
1505
struct TupHeadInfo {
 
1506
  struct BitPart {
 
1507
    unsigned int disk_indicator : 1;
 
1508
    unsigned int var_part_loc_ind : 1;
 
1509
    unsigned int initialised : 1;
 
1510
    unsigned int not_used_yet : 5;
 
1511
    unsigned int no_var_sized : 8;
 
1512
    unsigned int tuple_version : 16;
 
1513
  };
 
1514
  union {
 
1515
    Uint32 all;
 
1516
    BitPart bit_part;
 
1517
  };
 
1518
};
 
1519
*/
 
1520
 
 
1521
// updateAttributes module
 
1522
  Uint32          terrorCode;
 
1523
 
 
1524
public:
 
1525
  Dbtup(Block_context&, Pgman*);
 
1526
  virtual ~Dbtup();
 
1527
 
 
1528
  /*
 
1529
   * TUX uses logical tuple address when talking to ACC and LQH.
 
1530
   */
 
1531
  void tuxGetTupAddr(Uint32 fragPtrI, Uint32 pageId, Uint32 pageOffset, Uint32& tupAddr);
 
1532
 
 
1533
  /*
 
1534
   * TUX index in TUP has single Uint32 array attribute which stores an
 
1535
   * index node.  TUX reads and writes the node directly via pointer.
 
1536
   */
 
1537
  int tuxAllocNode(Signal* signal, Uint32 fragPtrI, Uint32& pageId, Uint32& pageOffset, Uint32*& node);
 
1538
  void tuxFreeNode(Signal* signal, Uint32 fragPtrI, Uint32 pageId, Uint32 pageOffset, Uint32* node);
 
1539
  void tuxGetNode(Uint32 fragPtrI, Uint32 pageId, Uint32 pageOffset, Uint32*& node);
 
1540
 
 
1541
  /*
 
1542
   * TUX reads primary table attributes for index keys.  Tuple is
 
1543
   * specified by location of original tuple and version number.  Input
 
1544
   * is attribute ids in AttributeHeader format.  Output is attribute
 
1545
   * data with headers.  Uses readAttributes with xfrm option set.
 
1546
   * Returns number of words or negative (-terrorCode) on error.
 
1547
   */
 
1548
  int tuxReadAttrs(Uint32 fragPtrI, Uint32 pageId, Uint32 pageOffset, Uint32 tupVersion, const Uint32* attrIds, Uint32 numAttrs, Uint32* dataOut);
 
1549
 
 
1550
  /*
 
1551
   * TUX reads primary key without headers into an array of words.  Used
 
1552
   * for md5 summing and when returning keyinfo.  Returns number of
 
1553
   * words or negative (-terrorCode) on error.
 
1554
   */
 
1555
  int tuxReadPk(Uint32 fragPtrI, Uint32 pageId, Uint32 pageOffset, Uint32* dataOut, bool xfrmFlag);
 
1556
 
 
1557
  /*
 
1558
   * ACC reads primary key without headers into an array of words.  At
 
1559
   * this point in ACC deconstruction, ACC still uses logical references
 
1560
   * to fragment and tuple.
 
1561
   */
 
1562
  int accReadPk(Uint32 tableId, Uint32 fragId, Uint32 fragPageId, Uint32 pageIndex, Uint32* dataOut, bool xfrmFlag);
 
1563
 
 
1564
  /*
 
1565
   * TUX checks if tuple is visible to scan.
 
1566
   */
 
1567
  bool tuxQueryTh(Uint32 fragPtrI, Uint32 pageId, Uint32 pageIndex, Uint32 tupVersion, Uint32 transId1, Uint32 transId2, bool dirty, Uint32 savepointId);
 
1568
 
 
1569
  int load_diskpage(Signal*, Uint32 opRec, Uint32 fragPtrI, 
 
1570
                    Uint32 local_key, Uint32 flags);
 
1571
 
 
1572
  int load_diskpage_scan(Signal*, Uint32 opRec, Uint32 fragPtrI, 
 
1573
                         Uint32 local_key, Uint32 flags);
 
1574
 
 
1575
  int alloc_page(Tablerec*, Fragrecord*, PagePtr*,Uint32 page_no);
 
1576
  
 
1577
  void start_restore_lcp(Uint32 tableId, Uint32 fragmentId);
 
1578
  void complete_restore_lcp(Uint32 tableId, Uint32 fragmentId);
 
1579
 
 
1580
  int nr_read_pk(Uint32 fragPtr, const Local_key*, Uint32* dataOut, bool&copy);
 
1581
  int nr_update_gci(Uint32 fragPtr, const Local_key*, Uint32 gci);
 
1582
  int nr_delete(Signal*, Uint32, Uint32 fragPtr, const Local_key*, Uint32 gci);
 
1583
 
 
1584
  void nr_delete_page_callback(Signal*, Uint32 op, Uint32 page);
 
1585
  void nr_delete_log_buffer_callback(Signal*, Uint32 op, Uint32 page);
 
1586
 
 
1587
  bool get_frag_info(Uint32 tableId, Uint32 fragId, Uint32* maxPage);
 
1588
private:
 
1589
  BLOCK_DEFINES(Dbtup);
 
1590
 
 
1591
  // Transit signals
 
1592
  void execDEBUG_SIG(Signal* signal);
 
1593
  void execCONTINUEB(Signal* signal);
 
1594
 
 
1595
  // Received signals
 
1596
  void execLCP_FRAG_ORD(Signal*signal);
 
1597
  void execDUMP_STATE_ORD(Signal* signal);
 
1598
  void execSEND_PACKED(Signal* signal);
 
1599
  void execSTTOR(Signal* signal);
 
1600
  void execTUP_LCPREQ(Signal* signal);
 
1601
  void execEND_LCPREQ(Signal* signal);
 
1602
  void execSTART_RECREQ(Signal* signal);
 
1603
  void execMEMCHECKREQ(Signal* signal);
 
1604
  void execTUPSEIZEREQ(Signal* signal);
 
1605
  void execTUPRELEASEREQ(Signal* signal);
 
1606
  void execSTORED_PROCREQ(Signal* signal);
 
1607
  void execTUPFRAGREQ(Signal* signal);
 
1608
  void execTUP_ADD_ATTRREQ(Signal* signal);
 
1609
  void execTUP_COMMITREQ(Signal* signal);
 
1610
  void execTUP_ABORTREQ(Signal* signal);
 
1611
  void execNDB_STTOR(Signal* signal);
 
1612
  void execREAD_CONFIG_REQ(Signal* signal);
 
1613
  void execDROP_TAB_REQ(Signal* signal);
 
1614
  void execALTER_TAB_REQ(Signal* signal);
 
1615
  void execTUP_DEALLOCREQ(Signal* signal);
 
1616
  void execTUP_WRITELOG_REQ(Signal* signal);
 
1617
 
 
1618
  // Ordered index related
 
1619
  void execBUILDINDXREQ(Signal* signal);
 
1620
  void buildIndex(Signal* signal, Uint32 buildPtrI);
 
1621
  void buildIndexReply(Signal* signal, const BuildIndexRec* buildRec);
 
1622
 
 
1623
  // Tup scan
 
1624
  void execACC_SCANREQ(Signal* signal);
 
1625
  void execNEXT_SCANREQ(Signal* signal);
 
1626
  void execACC_CHECK_SCAN(Signal* signal);
 
1627
  void execACCKEYCONF(Signal* signal);
 
1628
  void execACCKEYREF(Signal* signal);
 
1629
  void execACC_ABORTCONF(Signal* signal);
 
1630
 
 
1631
 
 
1632
  // Drop table
 
1633
  void execFSREMOVEREF(Signal*);
 
1634
  void execFSREMOVECONF(Signal*);
 
1635
  
 
1636
//------------------------------------------------------------------
 
1637
//------------------------------------------------------------------
 
1638
// Methods to handle execution of TUPKEYREQ + ATTRINFO.
 
1639
//
 
1640
// Module Execution Manager
 
1641
//
 
1642
// The TUPKEYREQ signal is central to this block. This signal is used
 
1643
// by everybody that needs to read data residing in DBTUP. The data is
 
1644
// read using an interpreter approach.
 
1645
//
 
1646
// Operations only needing to read execute a simplified version of the
 
1647
// interpreter where the only instruction is read Attribute to send.
 
1648
// Operations only needing to update the record (insert or update)
 
1649
// execute a simplified version of the interpreter where the only
 
1650
// instruction is write Attribute.
 
1651
//
 
1652
// Currently TUPKEYREQ is used in the following situations.
 
1653
// 1) Normal transaction execution. Can be any of the types described
 
1654
//    below.
 
1655
// 2) Execution of fragment redo log during system restart.
 
1656
//    In this situation there will only be normal updates, inserts
 
1657
//    and deletes performed.
 
1658
// 3) A special type of normal transaction execution is to write the
 
1659
//    records arriving from the primary replica in the node restart
 
1660
//    processing. This will always be normal write operations which
 
1661
//    are translated to inserts or updates before arriving to TUP.
 
1662
// 4) Scan processing. The scan processing will use normal reads or
 
1663
//    interpreted reads in their execution. There will be one TUPKEYREQ
 
1664
//    signal for each record processed.
 
1665
// 5) Copy fragment processing. This is a special type of scan used in the
 
1666
//    primary replica at system restart. It reads the entire reads and
 
1667
//    converts those to writes to the starting node. In this special case
 
1668
//    LQH acts as an API node and receives also the ATTRINFO sent in the
 
1669
//    TRANSID_AI signals.
 
1670
//
 
1671
// Signal Diagram:
 
1672
//
 
1673
// In Signals:
 
1674
// -----------
 
1675
//
 
1676
// Logically there is one request TUPKEYREQ which requests to read/write data
 
1677
// of one tuple in the database. Since the definition of what to read and write
 
1678
// can be bigger than the maximum signal size we segment the signal. The definition
 
1679
// of what to read/write/interpreted program is sent before the TUPKEYREQ signal.
 
1680
//
 
1681
// ---> ATTRINFO
 
1682
// ...
 
1683
// ---> ATTRINFO
 
1684
// ---> TUPKEYREQ
 
1685
// The number of ATTRINFO signals can be anything between 0 and upwards.
 
1686
// The total size of the ATTRINFO is not allowed to be more than 16384 words.
 
1687
// There is always one and only one TUPKEYREQ.
 
1688
//
 
1689
// Response Signals (successful case):
 
1690
//
 
1691
// Simple/Dirty Read Operation
 
1692
// ---------------------------
 
1693
//
 
1694
// <---- TRANSID_AI (to API)
 
1695
// ...
 
1696
// <---- TRANSID_AI (to API)
 
1697
// <---- READCONF   (to API)
 
1698
// <---- TUPKEYCONF (to LQH)
 
1699
// There is always exactly one READCONF25 sent last. The number of
 
1700
// TRANSID_AI is dependent on how much that was read. The maximum size
 
1701
// of the ATTRINFO sent back is 16384 words. The signals are sent
 
1702
// directly to the application with an address provided by the
 
1703
// TUPKEYREQ signal.
 
1704
// A positive response signal is also sent to LQH.
 
1705
//
 
1706
// Normal Read Operation
 
1707
// ---------------------
 
1708
//
 
1709
// <---- TRANSID_AI (to API)
 
1710
// ...
 
1711
// <---- TRANSID_AI (to API)
 
1712
// <---- TUPKEYCONF (to LQH)
 
1713
// The number of TRANSID_AI is dependent on how much that was read.
 
1714
// The maximum size of the ATTRINFO sent back is 16384 words. The
 
1715
// signals are sent directly to the application with an address
 
1716
// provided by the TUPKEYREQ signal.
 
1717
// A positive response signal is also sent to LQH.
 
1718
//
 
1719
// Normal update/insert/delete operation
 
1720
// -------------------------------------
 
1721
//
 
1722
// <---- TUPKEYCONF
 
1723
// After successful updating of the tuple LQH is informed of this.
 
1724
//
 
1725
// Delete with read
 
1726
// ----------------
 
1727
//
 
1728
// Will behave as a normal read although it also prepares the
 
1729
// deletion of the tuple.
 
1730
//
 
1731
// Interpreted Update
 
1732
// ------------------
 
1733
//
 
1734
// <---- TRANSID_AI (to API)
 
1735
// ...
 
1736
// <---- TRANSID_AI (to API)
 
1737
// <---- TUP_ATTRINFO (to LQH)
 
1738
// ...
 
1739
// <---- TUP_ATTRINFO (to LQH)
 
1740
// <---- TUPKEYCONF (to LQH)
 
1741
//
 
1742
// The interpreted Update contains five sections:
 
1743
// The first section performs read Attribute operations
 
1744
// that send results back to the API.
 
1745
//
 
1746
// The second section executes the interpreted program
 
1747
// where data from attributes can be updated and it
 
1748
// can also read attribute values into the registers.
 
1749
//
 
1750
// The third section performs unconditional updates of
 
1751
// attributes.
 
1752
//
 
1753
// The fourth section can read the attributes to be sent to the
 
1754
// API after updating the record.
 
1755
//
 
1756
// The fifth section contains subroutines used by the interpreter
 
1757
// in the second section.
 
1758
//
 
1759
// All types of interpreted programs contains the same five sections.
 
1760
// The only difference is that only interpreted updates can update
 
1761
// attributes. Interpreted inserts are not allowed.
 
1762
//
 
1763
// Interpreted Updates have to send back the information about the
 
1764
// attributes they have updated. This information will be shipped to
 
1765
// the log and also to any other replicas. Thus interpreted updates
 
1766
// are only performed in the primary replica. The fragment redo log
 
1767
// in LQH will contain information so that normal update/inserts/deletes
 
1768
// can be performed using TUPKEYREQ.
 
1769
//
 
1770
// Interpreted Read
 
1771
// ----------------
 
1772
//
 
1773
// From a signalling point of view the Interpreted Read behaves as
 
1774
// as a Normal Read. The interpreted Read is often used by Scan's.
 
1775
//
 
1776
// Interpreted Delete
 
1777
// ------------------
 
1778
//
 
1779
// <---- TUPKEYCONF
 
1780
// After successful prepartion to delete the tuple LQH is informed
 
1781
// of this.
 
1782
//
 
1783
// Interpreted Delete with Read
 
1784
// ----------------------------
 
1785
//
 
1786
// From a signalling point of view an interpreted delete with read
 
1787
// behaves as a normal read.
 
1788
//
 
1789
// Continuation after successful case:
 
1790
//
 
1791
// After a read of any kind the operation record is ready to be used
 
1792
// again by a new operation.
 
1793
//
 
1794
// Any updates, inserts or deletes waits for either of two messages.
 
1795
// A commit specifying that the operation is to be performed for real
 
1796
// or an abort specifying that the operation is to be rolled back and
 
1797
// the record to be restored in its original format.
 
1798
// 
 
1799
// This is handled by the module Transaction Manager.
 
1800
//
 
1801
// Response Signals (unsuccessful case):
 
1802
//
 
1803
// <---- TUPKEYREF (to LQH)
 
1804
// A signal is sent back to LQH informing about the unsuccessful
 
1805
// operation. In this case TUP waits for an abort signal to arrive
 
1806
// before the operation record is ready for the next operation.
 
1807
// This is handled by the Transaction Manager.
 
1808
//------------------------------------------------------------------
 
1809
//------------------------------------------------------------------
 
1810
 
 
1811
// *****************************************************************
 
1812
// Signal Reception methods.
 
1813
// *****************************************************************
 
1814
//------------------------------------------------------------------
 
1815
//------------------------------------------------------------------
 
1816
  void execTUPKEYREQ(Signal* signal);
 
1817
  void disk_page_load_callback(Signal*, Uint32 op, Uint32 page);
 
1818
  void disk_page_load_scan_callback(Signal*, Uint32 op, Uint32 page);
 
1819
 
 
1820
//------------------------------------------------------------------
 
1821
//------------------------------------------------------------------
 
1822
  void execATTRINFO(Signal* signal);
 
1823
public:
 
1824
  void receive_attrinfo(Signal*, Uint32 op, const Uint32* data, Uint32 len);
 
1825
private:
 
1826
 
 
1827
// Trigger signals
 
1828
//------------------------------------------------------------------
 
1829
//------------------------------------------------------------------
 
1830
  void execCREATE_TRIG_REQ(Signal* signal);
 
1831
 
 
1832
//------------------------------------------------------------------
 
1833
//------------------------------------------------------------------
 
1834
  void execDROP_TRIG_REQ(Signal* signal);
 
1835
 
 
1836
// *****************************************************************
 
1837
// Support methods for ATTRINFO.
 
1838
// *****************************************************************
 
1839
//------------------------------------------------------------------
 
1840
//------------------------------------------------------------------
 
1841
  void handleATTRINFOforTUPKEYREQ(Signal* signal,
 
1842
                                  const Uint32* data,
 
1843
                                  Uint32 length,
 
1844
                                  Operationrec * regOperPtr);
 
1845
 
 
1846
// *****************************************************************
 
1847
// Setting up the environment for reads, inserts, updates and deletes.
 
1848
// *****************************************************************
 
1849
//------------------------------------------------------------------
 
1850
//------------------------------------------------------------------
 
1851
  int handleReadReq(Signal* signal,
 
1852
                    Operationrec* regOperPtr,
 
1853
                    Tablerec* regTabPtr,
 
1854
                    KeyReqStruct* req_struct);
 
1855
 
 
1856
//------------------------------------------------------------------
 
1857
//------------------------------------------------------------------
 
1858
  int handleUpdateReq(Signal* signal,
 
1859
                      Operationrec* regOperPtr,
 
1860
                      Fragrecord* regFragPtr,
 
1861
                      Tablerec* regTabPtr,
 
1862
                      KeyReqStruct* req_struct,
 
1863
                      bool disk);
 
1864
 
 
1865
//------------------------------------------------------------------
 
1866
//------------------------------------------------------------------
 
1867
  int handleInsertReq(Signal* signal,
 
1868
                      Ptr<Operationrec> regOperPtr,
 
1869
                      Ptr<Fragrecord>,
 
1870
                      Tablerec* regTabPtr,
 
1871
                      KeyReqStruct* req_struct);
 
1872
 
 
1873
//------------------------------------------------------------------
 
1874
//------------------------------------------------------------------
 
1875
  int handleDeleteReq(Signal* signal,
 
1876
                      Operationrec* regOperPtr,
 
1877
                      Fragrecord* regFragPtr,
 
1878
                      Tablerec* regTabPtr,
 
1879
                      KeyReqStruct* req_struct,
 
1880
                      bool disk);
 
1881
 
 
1882
//------------------------------------------------------------------
 
1883
//------------------------------------------------------------------
 
1884
  int  updateStartLab(Signal* signal,
 
1885
                      Operationrec* regOperPtr,
 
1886
                      Fragrecord* regFragPtr,
 
1887
                      Tablerec* regTabPtr,
 
1888
                      KeyReqStruct* req_struct);
 
1889
 
 
1890
// *****************************************************************
 
1891
// Interpreter Handling methods.
 
1892
// *****************************************************************
 
1893
 
 
1894
//------------------------------------------------------------------
 
1895
//------------------------------------------------------------------
 
1896
  int interpreterStartLab(Signal* signal,
 
1897
                          KeyReqStruct *req_struct);
 
1898
 
 
1899
//------------------------------------------------------------------
 
1900
//------------------------------------------------------------------
 
1901
  int interpreterNextLab(Signal* signal,
 
1902
                         KeyReqStruct *req_struct,
 
1903
                         Uint32* logMemory,
 
1904
                         Uint32* mainProgram,
 
1905
                         Uint32 TmainProgLen,
 
1906
                         Uint32* subroutineProg,
 
1907
                         Uint32 TsubroutineLen,
 
1908
                         Uint32 * tmpArea,
 
1909
                         Uint32 tmpAreaSz);
 
1910
 
 
1911
// *****************************************************************
 
1912
// Signal Sending methods.
 
1913
// *****************************************************************
 
1914
//------------------------------------------------------------------
 
1915
//------------------------------------------------------------------
 
1916
  void sendReadAttrinfo(Signal* signal,
 
1917
                        KeyReqStruct *req_struct,
 
1918
                        Uint32 TnoOfData,
 
1919
                        const Operationrec * regOperPtr);
 
1920
 
 
1921
//------------------------------------------------------------------
 
1922
//------------------------------------------------------------------
 
1923
  void sendLogAttrinfo(Signal* signal,
 
1924
                       Uint32 TlogSize,
 
1925
                       Operationrec * regOperPtr);
 
1926
 
 
1927
//------------------------------------------------------------------
 
1928
//------------------------------------------------------------------
 
1929
  void sendTUPKEYCONF(Signal* signal,
 
1930
                      KeyReqStruct *req_struct,
 
1931
                      Operationrec * regOperPtr); 
 
1932
 
 
1933
//------------------------------------------------------------------
 
1934
//------------------------------------------------------------------
 
1935
// *****************************************************************
 
1936
// The methods that perform the actual read and update of attributes
 
1937
// in the tuple.
 
1938
// *****************************************************************
 
1939
//------------------------------------------------------------------
 
1940
//------------------------------------------------------------------
 
1941
  int readAttributes(KeyReqStruct* req_struct,
 
1942
                     const Uint32*  inBuffer,
 
1943
                     Uint32   inBufLen,
 
1944
                     Uint32*  outBuffer,
 
1945
                     Uint32   TmaxRead,
 
1946
                     bool     xfrmFlag);
 
1947
 
 
1948
//------------------------------------------------------------------
 
1949
//------------------------------------------------------------------
 
1950
  int updateAttributes(KeyReqStruct *req_struct,
 
1951
                       Uint32*     inBuffer,
 
1952
                       Uint32      inBufLen);
 
1953
 
 
1954
//------------------------------------------------------------------
 
1955
//------------------------------------------------------------------
 
1956
  bool readFixedSizeTHOneWordNotNULL(Uint32* outBuffer,
 
1957
                                     KeyReqStruct *req_struct,
 
1958
                                     AttributeHeader* ahOut,
 
1959
                                     Uint32  attrDes2);
 
1960
 
 
1961
//------------------------------------------------------------------
 
1962
//------------------------------------------------------------------
 
1963
  bool updateFixedSizeTHOneWordNotNULL(Uint32* inBuffer,
 
1964
                                       KeyReqStruct *req_struct,
 
1965
                                       Uint32  attrDes2);
 
1966
 
 
1967
//------------------------------------------------------------------
 
1968
//------------------------------------------------------------------
 
1969
  bool readFixedSizeTHTwoWordNotNULL(Uint32* outBuffer,
 
1970
                                     KeyReqStruct *req_struct,
 
1971
                                     AttributeHeader* ahOut,
 
1972
                                     Uint32  attrDes2);
 
1973
 
 
1974
//------------------------------------------------------------------
 
1975
//------------------------------------------------------------------
 
1976
  bool updateFixedSizeTHTwoWordNotNULL(Uint32* inBuffer,
 
1977
                                       KeyReqStruct *req_struct,
 
1978
                                       Uint32  attrDes2);
 
1979
 
 
1980
//------------------------------------------------------------------
 
1981
//------------------------------------------------------------------
 
1982
  bool readFixedSizeTHManyWordNotNULL(Uint32* outBuffer,
 
1983
                                      KeyReqStruct *req_struct,
 
1984
                                      AttributeHeader* ahOut,
 
1985
                                      Uint32  attrDes2);
 
1986
 
 
1987
//------------------------------------------------------------------
 
1988
//------------------------------------------------------------------
 
1989
  bool updateFixedSizeTHManyWordNotNULL(Uint32* inBuffer,
 
1990
                                        KeyReqStruct *req_struct,
 
1991
                                        Uint32  attrDes2);
 
1992
 
 
1993
//------------------------------------------------------------------
 
1994
//------------------------------------------------------------------
 
1995
  bool readFixedSizeTHOneWordNULLable(Uint32* outBuffer,
 
1996
                                      KeyReqStruct *req_struct,
 
1997
                                      AttributeHeader* ahOut,
 
1998
                                      Uint32  attrDes2);
 
1999
 
 
2000
//------------------------------------------------------------------
 
2001
//------------------------------------------------------------------
 
2002
  bool updateFixedSizeTHOneWordNULLable(Uint32* inBuffer,
 
2003
                                        KeyReqStruct *req_struct,
 
2004
                                        Uint32  attrDes2);
 
2005
 
 
2006
//------------------------------------------------------------------
 
2007
//------------------------------------------------------------------
 
2008
  bool readFixedSizeTHTwoWordNULLable(Uint32* outBuffer,
 
2009
                                      KeyReqStruct *req_struct,
 
2010
                                      AttributeHeader* ahOut,
 
2011
                                      Uint32  attrDes2);
 
2012
 
 
2013
//------------------------------------------------------------------
 
2014
//------------------------------------------------------------------
 
2015
  bool updateFixedSizeTHTwoWordNULLable(Uint32* inBuffer,
 
2016
                                        KeyReqStruct *req_struct,
 
2017
                                        Uint32  attrDes2);
 
2018
 
 
2019
//------------------------------------------------------------------
 
2020
//------------------------------------------------------------------
 
2021
  bool readFixedSizeTHManyWordNULLable(Uint32* outBuffer,
 
2022
                                       KeyReqStruct *req_struct,
 
2023
                                       AttributeHeader* ahOut,
 
2024
                                       Uint32  attrDes2);
 
2025
 
 
2026
//------------------------------------------------------------------
 
2027
//------------------------------------------------------------------
 
2028
  bool readFixedSizeTHZeroWordNULLable(Uint32* outBuffer,
 
2029
                                       KeyReqStruct *req_struct,
 
2030
                                       AttributeHeader* ahOut,
 
2031
                                       Uint32  attrDes2);
 
2032
//------------------------------------------------------------------
 
2033
//------------------------------------------------------------------
 
2034
  bool updateFixedSizeTHManyWordNULLable(Uint32* inBuffer,
 
2035
                                         KeyReqStruct *req_struct,
 
2036
                                         Uint32  attrDes2);
 
2037
 
 
2038
//------------------------------------------------------------------
 
2039
//------------------------------------------------------------------
 
2040
  bool readVarSizeNotNULL(Uint32* outBuffer,
 
2041
                          KeyReqStruct *req_struct,
 
2042
                          AttributeHeader* ahOut,
 
2043
                          Uint32  attrDes2);
 
2044
 
 
2045
//------------------------------------------------------------------
 
2046
//------------------------------------------------------------------
 
2047
  bool updateVarSizeNotNULL(Uint32* inBuffer,
 
2048
                            KeyReqStruct *req_struct,
 
2049
                            Uint32  attrDes2);
 
2050
 
 
2051
//------------------------------------------------------------------
 
2052
//------------------------------------------------------------------
 
2053
  bool readVarSizeNULLable(Uint32* outBuffer,
 
2054
                           KeyReqStruct *req_struct,
 
2055
                           AttributeHeader* ahOut,
 
2056
                           Uint32  attrDes2);
 
2057
 
 
2058
//------------------------------------------------------------------
 
2059
//------------------------------------------------------------------
 
2060
  bool updateVarSizeNULLable(Uint32* inBuffer,
 
2061
                             KeyReqStruct *req_struct,
 
2062
                             Uint32  attrDes2);
 
2063
 
 
2064
//------------------------------------------------------------------
 
2065
//------------------------------------------------------------------
 
2066
  bool readDynFixedSize(Uint32* outBuffer,
 
2067
                        KeyReqStruct *req_struct,
 
2068
                        AttributeHeader* ahOut,
 
2069
                        Uint32  attrDes2);
 
2070
 
 
2071
//------------------------------------------------------------------
 
2072
//------------------------------------------------------------------
 
2073
  bool updateDynFixedSize(Uint32* inBuffer,
 
2074
                          KeyReqStruct *req_struct,
 
2075
                          Uint32  attrDes2);
 
2076
 
 
2077
//------------------------------------------------------------------
 
2078
//------------------------------------------------------------------
 
2079
  bool readDynVarSize(Uint32* outBuffer,
 
2080
                      KeyReqStruct *req_struct,
 
2081
                      AttributeHeader* ahOut,
 
2082
                      Uint32  attrDes2);
 
2083
 
 
2084
//------------------------------------------------------------------
 
2085
//------------------------------------------------------------------
 
2086
  bool updateDynVarSize(Uint32* inBuffer,
 
2087
                        KeyReqStruct *req_struct,
 
2088
                        Uint32  attrDes2);
 
2089
 
 
2090
  bool readCharNotNULL(Uint32* outBuffer,
 
2091
                       KeyReqStruct *req_struct,
 
2092
                       AttributeHeader* ahOut,
 
2093
                       Uint32  attrDes2);
 
2094
 
 
2095
  bool readCharNULLable(Uint32* outBuffer,
 
2096
                        KeyReqStruct *req_struct,
 
2097
                        AttributeHeader* ahOut,
 
2098
                        Uint32  attrDes2);
 
2099
 
 
2100
  bool readBitsNULLable(Uint32* outBuffer, KeyReqStruct *req_struct, AttributeHeader*, Uint32);
 
2101
  bool updateBitsNULLable(Uint32* inBuffer, KeyReqStruct *req_struct, Uint32);
 
2102
  bool readBitsNotNULL(Uint32* outBuffer, KeyReqStruct *req_struct, AttributeHeader*, Uint32);
 
2103
  bool updateBitsNotNULL(Uint32* inBuffer, KeyReqStruct *req_struct, Uint32);
 
2104
 
 
2105
  bool updateFixedNULLable(Uint32* inBuffer, KeyReqStruct *req_struct, Uint32);
 
2106
  bool updateFixedNotNull(Uint32* inBuffer, KeyReqStruct *req_struct, Uint32);
 
2107
 
 
2108
  bool updateVarNULLable(Uint32* inBuffer, KeyReqStruct *req_struct, Uint32);
 
2109
  bool updateVarNotNull(Uint32* inBuffer, KeyReqStruct *req_struct, Uint32);
 
2110
 
 
2111
 
 
2112
  bool readDiskFixedSizeNotNULL(Uint32* outBuffer,
 
2113
                                KeyReqStruct *req_struct,
 
2114
                                AttributeHeader* ahOut,
 
2115
                                Uint32  attrDes2);
 
2116
  
 
2117
  bool readDiskFixedSizeNULLable(Uint32* outBuffer,
 
2118
                                 KeyReqStruct *req_struct,
 
2119
                                 AttributeHeader* ahOut,
 
2120
                                 Uint32  attrDes2);
 
2121
  bool readDiskVarSizeNULLable(Uint32* outBuffer, KeyReqStruct *req_struct, AttributeHeader*, Uint32);
 
2122
  bool readDiskVarSizeNotNULL(Uint32* outBuffer, KeyReqStruct *req_struct, AttributeHeader*, Uint32);
 
2123
 
 
2124
  bool updateDiskFixedSizeNULLable(Uint32*, KeyReqStruct*, Uint32);
 
2125
  bool updateDiskFixedSizeNotNULL(Uint32*, KeyReqStruct*, Uint32);
 
2126
 
 
2127
  bool updateDiskVarSizeNULLable(Uint32*, KeyReqStruct *, Uint32);
 
2128
  bool updateDiskVarSizeNotNULL(Uint32*, KeyReqStruct *, Uint32);
 
2129
  
 
2130
  bool readDiskBitsNULLable(Uint32*, KeyReqStruct*, AttributeHeader*, Uint32);
 
2131
  bool readDiskBitsNotNULL(Uint32*, KeyReqStruct*, AttributeHeader*, Uint32);
 
2132
  bool updateDiskBitsNULLable(Uint32*, KeyReqStruct*, Uint32);
 
2133
  bool updateDiskBitsNotNULL(Uint32*, KeyReqStruct*, Uint32);
 
2134
 
 
2135
 
 
2136
//------------------------------------------------------------------
 
2137
//------------------------------------------------------------------
 
2138
  bool nullFlagCheck(KeyReqStruct *req_struct, Uint32  attrDes2);
 
2139
  bool disk_nullFlagCheck(KeyReqStruct *req_struct, Uint32  attrDes2);
 
2140
  Uint32 read_pseudo(Uint32 attrId,
 
2141
                     KeyReqStruct *req_struct,
 
2142
                     Uint32* outBuffer);
 
2143
 
 
2144
//------------------------------------------------------------------
 
2145
//------------------------------------------------------------------
 
2146
  void setUpQueryRoutines(Tablerec* regTabPtr);
 
2147
 
 
2148
// *****************************************************************
 
2149
// Service methods.
 
2150
// *****************************************************************
 
2151
  TransState get_trans_state(Operationrec * const);
 
2152
  void set_trans_state(Operationrec * const, TransState);
 
2153
  TupleState get_tuple_state(Operationrec * const);
 
2154
  void set_tuple_state(Operationrec * const, TupleState);
 
2155
  Uint32 get_frag_page_id(Uint32 real_page_id);
 
2156
  Uint32 get_fix_page_offset(Uint32 page_index, Uint32 tuple_size);
 
2157
 
 
2158
  Uint32 decr_tup_version(Uint32 tuple_version);
 
2159
  void set_change_mask_state(Operationrec * const, ChangeMaskState);
 
2160
  ChangeMaskState get_change_mask_state(Operationrec * const);
 
2161
  void update_change_mask_info(KeyReqStruct * const, Operationrec * const);
 
2162
  void set_change_mask_info(KeyReqStruct * const, Operationrec * const);
 
2163
 
 
2164
//------------------------------------------------------------------
 
2165
//------------------------------------------------------------------
 
2166
  void copyAttrinfo(Operationrec * regOperPtr, Uint32*  inBuffer);
 
2167
 
 
2168
//------------------------------------------------------------------
 
2169
//------------------------------------------------------------------
 
2170
  void initOpConnection(Operationrec* regOperPtr);
 
2171
 
 
2172
//------------------------------------------------------------------
 
2173
//------------------------------------------------------------------
 
2174
  void initOperationrec(Signal* signal);
 
2175
 
 
2176
//------------------------------------------------------------------
 
2177
//------------------------------------------------------------------
 
2178
  int initStoredOperationrec(Operationrec* regOperPtr,
 
2179
                             KeyReqStruct* req_struct,
 
2180
                             Uint32 storedId);
 
2181
 
 
2182
//------------------------------------------------------------------
 
2183
//------------------------------------------------------------------
 
2184
  bool insertActiveOpList(OperationrecPtr, KeyReqStruct* req_struct);
 
2185
 
 
2186
//------------------------------------------------------------------
 
2187
//------------------------------------------------------------------
 
2188
 
 
2189
//------------------------------------------------------------------
 
2190
//------------------------------------------------------------------
 
2191
  void bufferTRANSID_AI(Signal* signal, BlockReference aRef, Uint32 Tlen);
 
2192
 
 
2193
//------------------------------------------------------------------
 
2194
// Trigger handling routines
 
2195
//------------------------------------------------------------------
 
2196
  DLList<TupTriggerData>*
 
2197
  findTriggerList(Tablerec* table,
 
2198
                  TriggerType::Value ttype,
 
2199
                  TriggerActionTime::Value ttime,
 
2200
                  TriggerEvent::Value tevent);
 
2201
 
 
2202
  bool createTrigger(Tablerec* table, const CreateTrigReq* req);
 
2203
 
 
2204
  Uint32 dropTrigger(Tablerec* table,
 
2205
                     const DropTrigReq* req,
 
2206
                     BlockNumber sender);
 
2207
 
 
2208
  void
 
2209
  checkImmediateTriggersAfterInsert(KeyReqStruct *req_struct,
 
2210
                                    Operationrec* regOperPtr, 
 
2211
                                    Tablerec* tablePtr,
 
2212
                                    bool disk);
 
2213
 
 
2214
  void
 
2215
  checkImmediateTriggersAfterUpdate(KeyReqStruct *req_struct,
 
2216
                                    Operationrec* regOperPtr, 
 
2217
                                    Tablerec* tablePtr,
 
2218
                                    bool disk);
 
2219
 
 
2220
  void
 
2221
  checkImmediateTriggersAfterDelete(KeyReqStruct *req_struct,
 
2222
                                    Operationrec* regOperPtr, 
 
2223
                                    Tablerec* tablePtr,
 
2224
                                    bool disk);
 
2225
 
 
2226
#if 0
 
2227
  void checkDeferredTriggers(Signal* signal, 
 
2228
                             Operationrec* regOperPtr,
 
2229
                             Tablerec* regTablePtr);
 
2230
#endif
 
2231
  void checkDetachedTriggers(KeyReqStruct *req_struct,
 
2232
                             Operationrec* regOperPtr,
 
2233
                             Tablerec* regTablePtr,
 
2234
                             bool disk);
 
2235
 
 
2236
  void fireImmediateTriggers(KeyReqStruct *req_struct,
 
2237
                             DLList<TupTriggerData>& triggerList, 
 
2238
                             Operationrec* regOperPtr,
 
2239
                             bool disk);
 
2240
 
 
2241
  void fireDeferredTriggers(KeyReqStruct *req_struct,
 
2242
                            DLList<TupTriggerData>& triggerList,
 
2243
                            Operationrec* regOperPtr);
 
2244
 
 
2245
  void fireDetachedTriggers(KeyReqStruct *req_struct,
 
2246
                            DLList<TupTriggerData>& triggerList,
 
2247
                            Operationrec* regOperPtr,
 
2248
                            bool disk);
 
2249
 
 
2250
  void executeTriggers(KeyReqStruct *req_struct,
 
2251
                       DLList<TupTriggerData>& triggerList,
 
2252
                       Operationrec* regOperPtr,
 
2253
                       bool disk);
 
2254
 
 
2255
  void executeTrigger(KeyReqStruct *req_struct,
 
2256
                      TupTriggerData* trigPtr, 
 
2257
                      Operationrec* regOperPtr,
 
2258
                      bool disk);
 
2259
 
 
2260
  bool readTriggerInfo(TupTriggerData* trigPtr,
 
2261
                       Operationrec* regOperPtr,
 
2262
                       KeyReqStruct * req_struct,
 
2263
                       Fragrecord* regFragPtr,
 
2264
                       Uint32* keyBuffer,
 
2265
                       Uint32& noPrimKey,
 
2266
                       Uint32* afterBuffer,
 
2267
                       Uint32& noAfterWords,
 
2268
                       Uint32* beforeBuffer,
 
2269
                       Uint32& noBeforeWords,
 
2270
                       bool disk);
 
2271
  
 
2272
  void sendTrigAttrInfo(Signal*        signal, 
 
2273
                        Uint32*        data, 
 
2274
                        Uint32         dataLen,
 
2275
                        bool           executeDirect,
 
2276
                        BlockReference receiverReference);
 
2277
 
 
2278
  Uint32 setAttrIds(Bitmask<MAXNROFATTRIBUTESINWORDS>& attributeMask, 
 
2279
                    Uint32 noOfAttributes, 
 
2280
                    Uint32* inBuffer);
 
2281
 
 
2282
  void sendFireTrigOrd(Signal* signal, 
 
2283
                       KeyReqStruct *req_struct,
 
2284
                       Operationrec * regOperPtr,
 
2285
                       TupTriggerData* trigPtr,
 
2286
                       Uint32 fragmentId,
 
2287
                       Uint32 noPrimKeySignals, 
 
2288
                       Uint32 noBeforeSignals, 
 
2289
                       Uint32 noAfterSignals);
 
2290
 
 
2291
  bool primaryKey(Tablerec* const, Uint32);
 
2292
 
 
2293
  // these set terrorCode and return non-zero on error
 
2294
 
 
2295
  int executeTuxInsertTriggers(Signal* signal, 
 
2296
                               Operationrec* regOperPtr,
 
2297
                               Fragrecord* regFragPtr,
 
2298
                               Tablerec* regTabPtr);
 
2299
 
 
2300
  int executeTuxUpdateTriggers(Signal* signal, 
 
2301
                               Operationrec* regOperPtr,
 
2302
                               Fragrecord* regFragPtr,
 
2303
                               Tablerec* regTabPtr);
 
2304
 
 
2305
  int executeTuxDeleteTriggers(Signal* signal, 
 
2306
                               Operationrec* regOperPtr,
 
2307
                               Fragrecord* regFragPtr,
 
2308
                               Tablerec* regTabPtr);
 
2309
 
 
2310
  int addTuxEntries(Signal* signal,
 
2311
                    Operationrec* regOperPtr,
 
2312
                    Tablerec* regTabPtr);
 
2313
 
 
2314
  // these crash the node on error
 
2315
 
 
2316
  void executeTuxCommitTriggers(Signal* signal, 
 
2317
                                Operationrec* regOperPtr,
 
2318
                                Fragrecord* regFragPtr,
 
2319
                                Tablerec* regTabPtr);
 
2320
 
 
2321
  void executeTuxAbortTriggers(Signal* signal, 
 
2322
                               Operationrec* regOperPtr,
 
2323
                               Fragrecord* regFragPtr,
 
2324
                               Tablerec* regTabPtr);
 
2325
 
 
2326
  void removeTuxEntries(Signal* signal,
 
2327
                        Tablerec* regTabPtr);
 
2328
 
 
2329
// *****************************************************************
 
2330
// Error Handling routines.
 
2331
// *****************************************************************
 
2332
//------------------------------------------------------------------
 
2333
//------------------------------------------------------------------
 
2334
  int TUPKEY_abort(Signal* signal, int error_type);
 
2335
 
 
2336
//------------------------------------------------------------------
 
2337
//------------------------------------------------------------------
 
2338
  void tupkeyErrorLab(Signal* signal);
 
2339
  void do_tup_abortreq(Signal*, Uint32 flags);
 
2340
 
 
2341
//------------------------------------------------------------------
 
2342
//------------------------------------------------------------------
 
2343
// Methods to handle execution of TUP_COMMITREQ + TUP_ABORTREQ.
 
2344
//
 
2345
// Module Transaction Manager
 
2346
//
 
2347
// The Transaction Manager module is responsible for the commit
 
2348
// and abort of operations started by the Execution Manager.
 
2349
//
 
2350
// Commit Operation:
 
2351
// ----------------
 
2352
//
 
2353
// Failures in commit processing is not allowed since that would
 
2354
// leave the database in an unreliable state. Thus the only way
 
2355
// to handle failures in commit processing is to crash the node.
 
2356
//
 
2357
// TUP_COMMITREQ can only be received in the wait state after a
 
2358
// successful TUPKEYREQ which was not a read operation.
 
2359
// 
 
2360
// Commit of Delete:
 
2361
// -----------------
 
2362
//
 
2363
// This will actually perform the deletion of the record unless
 
2364
// other operations also are connected to the record. In this case
 
2365
// we will set the delete state on the record that becomes the ownerd
 
2366
// of the record.
 
2367
//
 
2368
// Commit of Update:
 
2369
// ----------------
 
2370
//
 
2371
// We will release the copy record where the original record was kept.
 
2372
// Also here we will take special care if more operations are updating
 
2373
// the record simultaneously.
 
2374
//
 
2375
// Commit of Insert:
 
2376
// -----------------
 
2377
//
 
2378
// Will simply reset the state of the operation record.
 
2379
//
 
2380
// Signal Diagram:
 
2381
// --->  TUP_COMMITREQ (from LQH)
 
2382
// <---- TUP_COMMITCONF (to LQH)
 
2383
//
 
2384
//
 
2385
// Abort Operation:
 
2386
// ----------------
 
2387
//
 
2388
// Signal Diagram:
 
2389
// --->  TUP_ABORTREQ (from LQH)
 
2390
// <---- TUP_ABORTCONF (to LQH)
 
2391
//
 
2392
// Failures in abort processing is not allowed since that would
 
2393
// leave the database in an unreliable state. Thus the only way
 
2394
// to handle failures in abort processing is to crash the node.
 
2395
//
 
2396
// Abort messages can arrive at any time. It can arrive even before
 
2397
// anything at all have arrived of the operation. It can arrive after
 
2398
// receiving a number of ATTRINFO but before TUPKEYREQ has been received.
 
2399
// It must arrive after that we sent TUPKEYREF in response to TUPKEYREQ
 
2400
// and finally it can arrive after successfully performing the TUPKEYREQ
 
2401
// in all cases including the read case.
 
2402
//------------------------------------------------------------------
 
2403
//------------------------------------------------------------------
 
2404
 
 
2405
#if 0 
 
2406
  void checkPages(Fragrecord* regFragPtr);
 
2407
#endif
 
2408
  Uint32 convert_byte_to_word_size(Uint32 byte_size)
 
2409
  {
 
2410
    return ((byte_size + 3) >> 2);
 
2411
  }
 
2412
  Uint32 convert_bit_to_word_size(Uint32 bit_size)
 
2413
  {
 
2414
    return ((bit_size + 31) >> 5);
 
2415
  }
 
2416
 
 
2417
  void prepare_initial_insert(KeyReqStruct*, Operationrec*, Tablerec*);
 
2418
  void fix_disk_insert_no_mem_insert(KeyReqStruct*, Operationrec*, Tablerec*);
 
2419
  void setup_fixed_part(KeyReqStruct* req_struct,
 
2420
                        Operationrec* regOperPtr,
 
2421
                        Tablerec* regTabPtr);
 
2422
  
 
2423
  void send_TUPKEYREF(Signal* signal,
 
2424
                      Operationrec* regOperPtr);
 
2425
  void early_tupkey_error(Signal* signal);
 
2426
 
 
2427
  void printoutTuplePage(Uint32 fragid, Uint32 pageid, Uint32 printLimit);
 
2428
 
 
2429
  bool checkUpdateOfPrimaryKey(KeyReqStruct *req_struct,
 
2430
                               Uint32* updateBuffer,
 
2431
                               Tablerec* regTabPtr);
 
2432
 
 
2433
  void setNullBits(Uint32*, Tablerec* regTabPtr);
 
2434
  bool checkNullAttributes(KeyReqStruct * const, Tablerec* const);
 
2435
  bool find_savepoint(OperationrecPtr& loopOpPtr, Uint32 savepointId);
 
2436
  bool setup_read(KeyReqStruct* req_struct,
 
2437
                  Operationrec* regOperPtr,
 
2438
                  Fragrecord* regFragPtr,
 
2439
                  Tablerec* regTabPtr,
 
2440
                  bool disk);
 
2441
  
 
2442
  Uint32 calculateChecksum(Tuple_header*, Tablerec* regTabPtr);
 
2443
  void setChecksum(Tuple_header*, Tablerec* regTabPtr);
 
2444
 
 
2445
  void complexTrigger(Signal* signal,
 
2446
                      KeyReqStruct *req_struct,
 
2447
                      Operationrec* regOperPtr,
 
2448
                      Fragrecord* regFragPtr,
 
2449
                      Tablerec* regTabPtr);
 
2450
 
 
2451
  void setTupleStatesSetOpType(Operationrec* regOperPtr,
 
2452
                               KeyReqStruct *req_struct,
 
2453
                               Page* pagePtr,
 
2454
                               Uint32& opType,
 
2455
                               OperationrecPtr& firstOpPtr);
 
2456
 
 
2457
  void findBeforeValueOperation(OperationrecPtr& befOpPtr,
 
2458
                                OperationrecPtr firstOpPtr);
 
2459
 
 
2460
  void calculateChangeMask(Page* PagePtr,
 
2461
                           Tablerec* regTabPtr,
 
2462
                           KeyReqStruct * req_struct);
 
2463
 
 
2464
  void updateGcpId(KeyReqStruct *req_struct,
 
2465
                   Operationrec* regOperPtr,
 
2466
                   Fragrecord* regFragPtr,
 
2467
                   Tablerec* regTabPtr);
 
2468
 
 
2469
  void setTupleStateOnPreviousOps(Uint32 prevOpIndex);
 
2470
  void copyMem(Signal* signal, Uint32 sourceIndex, Uint32 destIndex);
 
2471
 
 
2472
  void freeAllAttrBuffers(Operationrec*  const regOperPtr);
 
2473
  void freeAttrinbufrec(Uint32 anAttrBufRec);
 
2474
  void removeActiveOpList(Operationrec*  const regOperPtr, Tuple_header*);
 
2475
 
 
2476
  void updatePackedList(Signal* signal, Uint16 ahostIndex);
 
2477
 
 
2478
  void setUpDescriptorReferences(Uint32 descriptorReference,
 
2479
                                 Tablerec* regTabPtr,
 
2480
                                 const Uint32* offset);
 
2481
  void setUpKeyArray(Tablerec* regTabPtr);
 
2482
  bool addfragtotab(Tablerec* regTabPtr, Uint32 fragId, Uint32 fragIndex);
 
2483
  void deleteFragTab(Tablerec* regTabPtr, Uint32 fragId);
 
2484
  void abortAddFragOp(Signal* signal);
 
2485
  void releaseTabDescr(Tablerec* regTabPtr);
 
2486
  void getFragmentrec(FragrecordPtr& regFragPtr, Uint32 fragId, Tablerec* regTabPtr);
 
2487
 
 
2488
  void initialiseRecordsLab(Signal* signal, Uint32 switchData, Uint32, Uint32);
 
2489
  void initializeAttrbufrec();
 
2490
  void initializeCheckpointInfoRec();
 
2491
  void initializeDiskBufferSegmentRecord();
 
2492
  void initializeFragoperrec();
 
2493
  void initializeFragrecord();
 
2494
  void initializeHostBuffer();
 
2495
  void initializeLocalLogInfo();
 
2496
  void initializeOperationrec();
 
2497
  void initializePendingFileOpenInfoRecord();
 
2498
  void initializeRestartInfoRec();
 
2499
  void initializeTablerec();
 
2500
  void initializeTabDescr();
 
2501
  void initializeUndoPage();
 
2502
 
 
2503
  void initTab(Tablerec* regTabPtr);
 
2504
 
 
2505
  void startphase3Lab(Signal* signal, Uint32 config1, Uint32 config2);
 
2506
 
 
2507
  void fragrefuseLab(Signal* signal, FragoperrecPtr fragOperPtr);
 
2508
  void fragrefuse1Lab(Signal* signal, FragoperrecPtr fragOperPtr);
 
2509
  void fragrefuse2Lab(Signal* signal, FragoperrecPtr fragOperPtr, FragrecordPtr regFragPtr);
 
2510
  void fragrefuse3Lab(Signal* signal,
 
2511
                      FragoperrecPtr fragOperPtr,
 
2512
                      FragrecordPtr regFragPtr,
 
2513
                      Tablerec* regTabPtr,
 
2514
                      Uint32 fragId);
 
2515
  void fragrefuse4Lab(Signal* signal,
 
2516
                      FragoperrecPtr fragOperPtr,
 
2517
                      FragrecordPtr regFragPtr,
 
2518
                      Tablerec* regTabPtr,
 
2519
                      Uint32 fragId);
 
2520
  void addattrrefuseLab(Signal* signal,
 
2521
                        FragrecordPtr regFragPtr,
 
2522
                        FragoperrecPtr fragOperPtr,
 
2523
                        Tablerec* regTabPtr,
 
2524
                        Uint32 fragId);
 
2525
 
 
2526
 
 
2527
  void releaseFragment(Signal* signal, Uint32 tableId, Uint32);
 
2528
  void drop_fragment_free_var_pages(Signal*);
 
2529
  void drop_fragment_free_extent(Signal*, TablerecPtr, FragrecordPtr, Uint32);
 
2530
  void drop_fragment_free_extent_log_buffer_callback(Signal*, Uint32, Uint32);
 
2531
  void drop_fragment_unmap_pages(Signal*, TablerecPtr, FragrecordPtr, Uint32);
 
2532
  void drop_fragment_unmap_page_callback(Signal* signal, Uint32, Uint32);
 
2533
  void drop_fragment_fsremove(Signal*, TablerecPtr, FragrecordPtr);
 
2534
  void drop_fragment_fsremove_done(Signal*, TablerecPtr, FragrecordPtr);
 
2535
 
 
2536
  // Initialisation
 
2537
  void initData();
 
2538
  void initRecords();
 
2539
 
 
2540
  void deleteScanProcedure(Signal* signal, Operationrec* regOperPtr);
 
2541
  void copyProcedure(Signal* signal,
 
2542
                     TablerecPtr regTabPtr,
 
2543
                     Operationrec* regOperPtr);
 
2544
  void scanProcedure(Signal* signal,
 
2545
                     Operationrec* regOperPtr,
 
2546
                     Uint32 lenAttrInfo);
 
2547
  void storedSeizeAttrinbufrecErrorLab(Signal* signal,
 
2548
                                       Operationrec* regOperPtr,
 
2549
                                       Uint32 errorCode);
 
2550
  bool storedProcedureAttrInfo(Signal* signal,
 
2551
                               Operationrec* regOperPtr,
 
2552
                               const Uint32* data,
 
2553
                               Uint32 length,
 
2554
                               bool copyProc);
 
2555
 
 
2556
//-----------------------------------------------------------------------------
 
2557
// Table Descriptor Memory Manager
 
2558
//-----------------------------------------------------------------------------
 
2559
 
 
2560
// Public methods
 
2561
  Uint32 getTabDescrOffsets(const Tablerec* regTabPtr, Uint32* offset);
 
2562
  Uint32 allocTabDescr(const Tablerec* regTabPtr, Uint32* offset);
 
2563
  void freeTabDescr(Uint32 retRef, Uint32 retNo, bool normal = true);
 
2564
  Uint32 getTabDescrWord(Uint32 index);
 
2565
  void setTabDescrWord(Uint32 index, Uint32 word);
 
2566
 
 
2567
// Private methods
 
2568
  Uint32 sizeOfReadFunction();
 
2569
  void   removeTdArea(Uint32 tabDesRef, Uint32 list);
 
2570
  void   insertTdArea(Uint32 tabDesRef, Uint32 list);
 
2571
  void   itdaMergeTabDescr(Uint32& retRef, Uint32& retNo, bool normal);
 
2572
#ifdef VM_TRACE
 
2573
  void verifytabdes();
 
2574
#endif
 
2575
 
 
2576
  void seizeOpRec(OperationrecPtr& regOperPtr);
 
2577
  void seizeFragrecord(FragrecordPtr& regFragPtr);
 
2578
  void seizeFragoperrec(FragoperrecPtr& fragOperPtr);
 
2579
  void releaseFragoperrec(FragoperrecPtr fragOperPtr);
 
2580
  void releaseFragrec(FragrecordPtr);
 
2581
//----------------------------------------------------------------------------
 
2582
// Page Memory Manager
 
2583
//----------------------------------------------------------------------------
 
2584
  
 
2585
// Public methods
 
2586
  void allocConsPages(Uint32 noOfPagesToAllocate,
 
2587
                      Uint32& noOfPagesAllocated,
 
2588
                      Uint32& allocPageRef);
 
2589
  void returnCommonArea(Uint32 retPageRef, Uint32 retNo);
 
2590
  void initializePage();
 
2591
 
 
2592
// Private methods
 
2593
  void removeCommonArea(Uint32 remPageRef, Uint32 list);
 
2594
  void insertCommonArea(Uint32 insPageRef, Uint32 list);
 
2595
  void findFreeLeftNeighbours(Uint32& allocPageRef, Uint32& noPagesAllocated, Uint32 noPagesToAllocate);
 
2596
  void findFreeRightNeighbours(Uint32& allocPageRef, Uint32& noPagesAllocated, Uint32 noPagesToAllocate);
 
2597
  Uint32 nextHigherTwoLog(Uint32 input);
 
2598
 
 
2599
// Private data
 
2600
  Uint32 cfreepageList[16];
 
2601
 
 
2602
//------------------------------------------------------------------------------------------------------
 
2603
// Page Mapper, convert logical page id's to physical page id's
 
2604
// The page mapper also handles the pages allocated to the fragment.
 
2605
//------------------------------------------------------------------------------------------------------
 
2606
//
 
2607
// Public methods
 
2608
  Uint32 getRealpid(Fragrecord* regFragPtr, Uint32 logicalPageId);
 
2609
  Uint32 getNoOfPages(Fragrecord* regFragPtr);
 
2610
  void initPageRangeSize(Uint32 size);
 
2611
  bool insertPageRangeTab(Fragrecord* regFragPtr,
 
2612
                          Uint32 startPageId,
 
2613
                          Uint32 noPages);
 
2614
  void releaseFragPages(Fragrecord* regFragPtr);
 
2615
  void initFragRange(Fragrecord* regFragPtr);
 
2616
  void initializePageRange();
 
2617
  Uint32 getEmptyPage(Fragrecord* regFragPtr);
 
2618
  Uint32 allocFragPages(Fragrecord* regFragPtr, Uint32 noOfPagesAllocated);
 
2619
  Uint32 get_empty_var_page(Fragrecord* frag_ptr);
 
2620
  
 
2621
// Private methods
 
2622
  Uint32 leafPageRangeFull(Fragrecord* regFragPtr, PageRangePtr currPageRangePtr);
 
2623
  void releasePagerange(PageRangePtr regPRPtr);
 
2624
  void seizePagerange(PageRangePtr& regPageRangePtr);
 
2625
  void errorHandler(Uint32 errorCode);
 
2626
  void allocMoreFragPages(Fragrecord* regFragPtr);
 
2627
 
 
2628
// Private data
 
2629
  Uint32 cfirstfreerange;
 
2630
  PageRange *pageRange;
 
2631
  Uint32 c_noOfFreePageRanges;
 
2632
  Uint32 cnoOfPageRangeRec;
 
2633
 
 
2634
//---------------------------------------------------------------
 
2635
// Variable Allocator
 
2636
// Allocates and deallocates tuples of fixed size on a fragment.
 
2637
//---------------------------------------------------------------
 
2638
//
 
2639
// Public methods
 
2640
 
 
2641
  void init_list_sizes(void);
 
2642
 
 
2643
// Private methods
 
2644
 
 
2645
  Uint32 get_alloc_page(Fragrecord* const, Uint32);
 
2646
  void update_free_page_list(Fragrecord* const, Ptr<Page>);
 
2647
 
 
2648
#if 0  
 
2649
  Uint32 calc_free_list(const Tablerec* regTabPtr, Uint32 sz) const {
 
2650
    return regTabPtr->m_disk_alloc_info.calc_page_free_bits(sz);
 
2651
  }
 
2652
#endif
 
2653
 
 
2654
  Uint32 calculate_free_list_impl(Uint32) const ;
 
2655
  void remove_free_page(Fragrecord*, Var_page*, Uint32);
 
2656
  void insert_free_page(Fragrecord*, Var_page*, Uint32);
 
2657
 
 
2658
//---------------------------------------------------------------
 
2659
// Fixed Allocator
 
2660
// Allocates and deallocates tuples of fixed size on a fragment.
 
2661
//---------------------------------------------------------------
 
2662
//
 
2663
// Public methods
 
2664
  Uint32* alloc_var_rec(Fragrecord*, Tablerec*, Uint32, Local_key*, Uint32*);
 
2665
  void free_var_rec(Fragrecord*, Tablerec*, Local_key*, Ptr<Page>);
 
2666
  Uint32* alloc_var_part(Fragrecord*, Tablerec*, Uint32, Local_key*);
 
2667
  int realloc_var_part(Fragrecord*, Tablerec*, 
 
2668
                       PagePtr, Var_part_ref*, Uint32, Uint32);
 
2669
  
 
2670
  void validate_page(Tablerec*, Var_page* page);
 
2671
  
 
2672
  Uint32* alloc_fix_rec(Fragrecord*const, Tablerec*const, Local_key*,
 
2673
                        Uint32*);
 
2674
  void free_fix_rec(Fragrecord*, Tablerec*, Local_key*, Fix_page*);
 
2675
  
 
2676
  Uint32* alloc_fix_rowid(Fragrecord*, Tablerec*, Local_key*, Uint32 *);
 
2677
  Uint32* alloc_var_rowid(Fragrecord*, Tablerec*, Uint32, Local_key*, Uint32*);
 
2678
// Private methods
 
2679
  void convertThPage(Fix_page* regPagePtr,
 
2680
                     Tablerec*,
 
2681
                     Uint32 mm);
 
2682
 
 
2683
  /**
 
2684
   * Return offset
 
2685
   */
 
2686
  Uint32 alloc_tuple_from_page(Fragrecord* regFragPtr,
 
2687
                               Fix_page* regPagePtr);
 
2688
  
 
2689
//---------------------------------------------------------------
 
2690
// Temporary variables used for storing commonly used variables
 
2691
// in certain modules
 
2692
//---------------------------------------------------------------
 
2693
 
 
2694
  Uint32 c_lcp_scan_op;
 
2695
  FragrecordPtr   fragptr;
 
2696
  OperationrecPtr operPtr;
 
2697
  TablerecPtr     tabptr;
 
2698
 
 
2699
// readAttributes and updateAttributes module
 
2700
//------------------------------------------------------------------------------------------------------
 
2701
// Common stored variables. Variables that have a valid value always.
 
2702
//------------------------------------------------------------------------------------------------------
 
2703
  Attrbufrec *attrbufrec;
 
2704
  Uint32 cfirstfreeAttrbufrec;
 
2705
  Uint32 cnoOfAttrbufrec;
 
2706
  Uint32 cnoFreeAttrbufrec;
 
2707
 
 
2708
  Fragoperrec *fragoperrec;
 
2709
  Uint32 cfirstfreeFragopr;
 
2710
  Uint32 cnoOfFragoprec;
 
2711
 
 
2712
  Fragrecord *fragrecord;
 
2713
  Uint32 cfirstfreefrag;
 
2714
  Uint32 cnoOfFragrec;
 
2715
 
 
2716
  HostBuffer *hostBuffer;
 
2717
 
 
2718
  ArrayPool<Operationrec> c_operation_pool;
 
2719
 
 
2720
  ArrayPool<Page> c_page_pool;
 
2721
  Uint32 cnoOfAllocatedPages;
 
2722
  Uint32 m_max_allocate_pages;
 
2723
 
 
2724
  /* read ahead in pages during disk order scan */
 
2725
  Uint32 m_max_page_read_ahead;
 
2726
  
 
2727
  Tablerec *tablerec;
 
2728
  Uint32 cnoOfTablerec;
 
2729
 
 
2730
  TableDescriptor *tableDescriptor;
 
2731
  Uint32 cnoOfTabDescrRec;
 
2732
  
 
2733
  Uint32 cdata[32];
 
2734
  Uint32 cdataPages[16];
 
2735
  Uint32 cpackedListIndex;
 
2736
  Uint32 cpackedList[MAX_NODES];
 
2737
  Uint32 cfreeTdList[16];
 
2738
  Uint32 clastBitMask;
 
2739
  Uint32 clblPageCounter;
 
2740
  Uint32 clblPagesPerTick;
 
2741
  Uint32 clblPagesPerTickAfterSr;
 
2742
  BlockReference clqhBlockref;
 
2743
  Uint32 clqhUserpointer;
 
2744
  Uint32 cminusOne;
 
2745
  BlockReference cndbcntrRef;
 
2746
  BlockReference cownref;
 
2747
  Uint32 cownNodeId;
 
2748
  Uint32 czero;
 
2749
 
 
2750
 // A little bit bigger to cover overwrites in copy algorithms (16384 real size).
 
2751
#define ZATTR_BUFFER_SIZE 16384
 
2752
  Uint32 clogMemBuffer[ZATTR_BUFFER_SIZE + 16];
 
2753
  Uint32 coutBuffer[ZATTR_BUFFER_SIZE + 16];
 
2754
  Uint32 cinBuffer[ZATTR_BUFFER_SIZE + 16];
 
2755
  Uint32 ctemp_page[ZWORDS_ON_PAGE];
 
2756
  Uint32 ctemp_var_record[ZWORDS_ON_PAGE];
 
2757
  Uint32 totNoOfPagesAllocated;
 
2758
 
 
2759
  // Trigger variables
 
2760
  Uint32 c_maxTriggersPerTable;
 
2761
  Uint32 c_memusage_report_frequency;
 
2762
 
 
2763
  Uint32 c_errorInsert4000TableId;
 
2764
  Uint32 c_min_list_size[MAX_FREE_LIST + 1];
 
2765
  Uint32 c_max_list_size[MAX_FREE_LIST + 1];
 
2766
 
 
2767
  void initGlobalTemporaryVars();
 
2768
  void reportMemoryUsage(Signal* signal, int incDec);
 
2769
 
 
2770
  
 
2771
#ifdef VM_TRACE
 
2772
  struct Th {
 
2773
    Uint32 data[1];
 
2774
  };
 
2775
  friend class NdbOut& operator<<(NdbOut&, const Operationrec&);
 
2776
  friend class NdbOut& operator<<(NdbOut&, const Th&);
 
2777
#endif
 
2778
 
 
2779
  void expand_tuple(KeyReqStruct*, Uint32 sizes[4], Tuple_header*org, 
 
2780
                    const Tablerec*, bool disk);
 
2781
  void shrink_tuple(KeyReqStruct*, Uint32 sizes[2], const Tablerec*,
 
2782
                    bool disk);
 
2783
  
 
2784
  Uint32* get_ptr(Var_part_ref);
 
2785
  Uint32* get_ptr(PagePtr*, Var_part_ref);
 
2786
  Uint32* get_ptr(PagePtr*, const Local_key*, const Tablerec*);
 
2787
  Uint32* get_dd_ptr(PagePtr*, const Local_key*, const Tablerec*);
 
2788
 
 
2789
  /**
 
2790
   * prealloc space from disk
 
2791
   *   key.m_file_no  contains file no
 
2792
   *   key.m_page_no  contains disk page
 
2793
   *   key.m_page_idx contains byte preallocated
 
2794
   */
 
2795
  int disk_page_prealloc(Signal*, Ptr<Fragrecord>, Local_key*, Uint32);
 
2796
  void disk_page_prealloc_dirty_page(Disk_alloc_info&, 
 
2797
                                     Ptr<Page>, Uint32, Uint32);
 
2798
  void disk_page_prealloc_transit_page(Disk_alloc_info&,
 
2799
                                       Ptr<Page_request>, Uint32, Uint32);
 
2800
  
 
2801
  void disk_page_abort_prealloc(Signal*, Fragrecord*,Local_key*, Uint32);
 
2802
  void disk_page_abort_prealloc_callback(Signal*, Uint32, Uint32);
 
2803
  void disk_page_abort_prealloc_callback_1(Signal*, Fragrecord*,
 
2804
                                           PagePtr, Uint32);
 
2805
  
 
2806
  void disk_page_prealloc_callback(Signal*, Uint32, Uint32);
 
2807
  void disk_page_prealloc_initial_callback(Signal*, Uint32, Uint32);
 
2808
  void disk_page_prealloc_callback_common(Signal*, 
 
2809
                                          Ptr<Page_request>, 
 
2810
                                          Ptr<Fragrecord>,
 
2811
                                          Ptr<Page>);
 
2812
  
 
2813
  void disk_page_alloc(Signal*, 
 
2814
                       Tablerec*, Fragrecord*, Local_key*, PagePtr, Uint32);
 
2815
  void disk_page_free(Signal*, 
 
2816
                      Tablerec*, Fragrecord*, Local_key*, PagePtr, Uint32);
 
2817
  
 
2818
  void disk_page_commit_callback(Signal*, Uint32 opPtrI, Uint32 page_id);  
 
2819
  
 
2820
  void disk_page_log_buffer_callback(Signal*, Uint32 opPtrI, Uint32); 
 
2821
 
 
2822
  void disk_page_alloc_extent_log_buffer_callback(Signal*, Uint32, Uint32);
 
2823
  void disk_page_free_extent_log_buffer_callback(Signal*, Uint32, Uint32);
 
2824
  
 
2825
  Uint64 disk_page_undo_alloc(Page*, const Local_key*,
 
2826
                              Uint32 sz, Uint32 gci, Uint32 logfile_group_id);
 
2827
 
 
2828
  Uint64 disk_page_undo_update(Page*, const Local_key*,
 
2829
                               const Uint32*, Uint32,
 
2830
                               Uint32 gci, Uint32 logfile_group_id);
 
2831
  
 
2832
  Uint64 disk_page_undo_free(Page*, const Local_key*,
 
2833
                             const Uint32*, Uint32 sz,
 
2834
                             Uint32 gci, Uint32 logfile_group_id);
 
2835
 
 
2836
  void undo_createtable_callback(Signal* signal, Uint32 opPtrI, Uint32 unused);
 
2837
  void undo_createtable_logsync_callback(Signal* signal, Uint32, Uint32);
 
2838
 
 
2839
  void drop_table_log_buffer_callback(Signal*, Uint32, Uint32);
 
2840
  void drop_table_logsync_callback(Signal*, Uint32, Uint32);
 
2841
 
 
2842
  void disk_page_set_dirty(Ptr<Page>);
 
2843
  void restart_setup_page(Disk_alloc_info&, Ptr<Page>);
 
2844
  void update_extent_pos(Disk_alloc_info&, Ptr<Extent_info>);
 
2845
  
 
2846
  /**
 
2847
   * Disk restart code
 
2848
   */
 
2849
public:
 
2850
  int disk_page_load_hook(Uint32 page_id);
 
2851
  
 
2852
  void disk_page_unmap_callback(Uint32 when, Uint32 page, Uint32 dirty_count);
 
2853
  
 
2854
  int disk_restart_alloc_extent(Uint32 tableId, Uint32 fragId, 
 
2855
                                const Local_key* key, Uint32 pages);
 
2856
  void disk_restart_page_bits(Uint32 tableId, Uint32 fragId,
 
2857
                              const Local_key*, Uint32 bits);
 
2858
  void disk_restart_undo(Signal* signal, Uint64 lsn,
 
2859
                         Uint32 type, const Uint32 * ptr, Uint32 len);
 
2860
 
 
2861
  struct Apply_undo 
 
2862
  {
 
2863
    Uint32 m_type, m_len;
 
2864
    const Uint32* m_ptr;
 
2865
    Uint64 m_lsn;
 
2866
    Ptr<Tablerec> m_table_ptr;
 
2867
    Ptr<Fragrecord> m_fragment_ptr;
 
2868
    Ptr<Page> m_page_ptr;
 
2869
    Ptr<Extent_info> m_extent_ptr;
 
2870
    Local_key m_key;
 
2871
  };
 
2872
 
 
2873
  void disk_restart_lcp_id(Uint32 table, Uint32 frag, Uint32 lcpId);
 
2874
  
 
2875
private:
 
2876
  void disk_restart_undo_next(Signal*);
 
2877
  void disk_restart_undo_lcp(Uint32, Uint32, Uint32 flag, Uint32 lcpId);
 
2878
  void disk_restart_undo_callback(Signal* signal, Uint32, Uint32);
 
2879
  void disk_restart_undo_alloc(Apply_undo*);
 
2880
  void disk_restart_undo_update(Apply_undo*);
 
2881
  void disk_restart_undo_free(Apply_undo*);
 
2882
  void disk_restart_undo_page_bits(Signal*, Apply_undo*);
 
2883
 
 
2884
#ifdef VM_TRACE
 
2885
  void verify_page_lists(Disk_alloc_info&);
 
2886
#else
 
2887
  void verify_page_lists(Disk_alloc_info&) {}
 
2888
#endif
 
2889
  
 
2890
  void findFirstOp(OperationrecPtr&);
 
2891
  void commit_operation(Signal*, Uint32, Tuple_header*, PagePtr,
 
2892
                        Operationrec*, Fragrecord*, Tablerec*);
 
2893
  
 
2894
  void dealloc_tuple(Signal* signal, Uint32, Page*, Tuple_header*, 
 
2895
                     Operationrec*, Fragrecord*, Tablerec*);
 
2896
  
 
2897
  int handle_size_change_after_update(KeyReqStruct* req_struct,
 
2898
                                      Tuple_header* org,
 
2899
                                      Operationrec*,
 
2900
                                      Fragrecord* regFragPtr,
 
2901
                                      Tablerec* regTabPtr,
 
2902
                                      Uint32 sizes[4]);
 
2903
 
 
2904
  /**
 
2905
   * Setup all pointer on keyreqstruct to prepare for read
 
2906
   *   req_struct->m_tuple_ptr is set to tuple to read
 
2907
   */
 
2908
  void prepare_read(KeyReqStruct*, Tablerec* const, bool disk);
 
2909
};
 
2910
 
 
2911
#if 0
 
2912
inline
 
2913
Uint32
 
2914
Dbtup::get_frag_page_id(Uint32 real_page_id)
 
2915
{
 
2916
  PagePtr real_page_ptr;
 
2917
  real_page_ptr.i= real_page_id;
 
2918
  ptrCheckGuard(real_page_ptr, cnoOfPage, cpage);
 
2919
  return real_page_ptr.p->frag_page_id;
 
2920
}
 
2921
#endif
 
2922
 
 
2923
inline
 
2924
Dbtup::TransState
 
2925
Dbtup::get_trans_state(Operationrec * regOperPtr)
 
2926
{
 
2927
  return (Dbtup::TransState)regOperPtr->op_struct.trans_state;
 
2928
}
 
2929
 
 
2930
inline
 
2931
void
 
2932
Dbtup::set_trans_state(Operationrec* regOperPtr,
 
2933
                       Dbtup::TransState trans_state)
 
2934
{
 
2935
  regOperPtr->op_struct.trans_state= (Uint32)trans_state;
 
2936
}
 
2937
 
 
2938
inline
 
2939
Dbtup::TupleState
 
2940
Dbtup::get_tuple_state(Operationrec * regOperPtr)
 
2941
{
 
2942
  return (Dbtup::TupleState)regOperPtr->op_struct.tuple_state;
 
2943
}
 
2944
 
 
2945
inline
 
2946
void
 
2947
Dbtup::set_tuple_state(Operationrec* regOperPtr,
 
2948
                       Dbtup::TupleState tuple_state)
 
2949
{
 
2950
  regOperPtr->op_struct.tuple_state= (Uint32)tuple_state;
 
2951
}
 
2952
 
 
2953
 
 
2954
inline
 
2955
Uint32
 
2956
Dbtup::decr_tup_version(Uint32 tup_version)
 
2957
{
 
2958
  return (tup_version - 1) & ZTUP_VERSION_MASK;
 
2959
}
 
2960
 
 
2961
inline
 
2962
Dbtup::ChangeMaskState
 
2963
Dbtup::get_change_mask_state(Operationrec * regOperPtr)
 
2964
{
 
2965
  return (Dbtup::ChangeMaskState)regOperPtr->op_struct.change_mask_state;
 
2966
}
 
2967
 
 
2968
inline
 
2969
void
 
2970
Dbtup::set_change_mask_state(Operationrec * regOperPtr,
 
2971
                             ChangeMaskState new_state)
 
2972
{
 
2973
  regOperPtr->op_struct.change_mask_state= (Uint32)new_state;
 
2974
}
 
2975
 
 
2976
inline
 
2977
void
 
2978
Dbtup::update_change_mask_info(KeyReqStruct * req_struct,
 
2979
                               Operationrec * regOperPtr)
 
2980
{
 
2981
  if (req_struct->max_attr_id_updated == 0) {
 
2982
    if (get_change_mask_state(regOperPtr) == USE_SAVED_CHANGE_MASK) {
 
2983
      // add new changes
 
2984
      regOperPtr->saved_change_mask[0] |= req_struct->changeMask.getWord(0);
 
2985
      regOperPtr->saved_change_mask[1] |= req_struct->changeMask.getWord(1);
 
2986
    }
 
2987
  } else {
 
2988
    if (req_struct->no_changed_attrs < 16) {
 
2989
      set_change_mask_state(regOperPtr, RECALCULATE_CHANGE_MASK);
 
2990
    } else {
 
2991
      set_change_mask_state(regOperPtr, SET_ALL_MASK);
 
2992
    }
 
2993
  }
 
2994
}
 
2995
 
 
2996
inline
 
2997
Uint32*
 
2998
Dbtup::get_ptr(Var_part_ref ref)
 
2999
{
 
3000
  Ptr<Page> tmp;
 
3001
  return get_ptr(&tmp, ref);
 
3002
}
 
3003
 
 
3004
inline
 
3005
Uint32*
 
3006
Dbtup::get_ptr(Ptr<Page>* pagePtr, Var_part_ref ref)
 
3007
{
 
3008
  PagePtr tmp;
 
3009
  Local_key key;
 
3010
  ref.copyout(&key);
 
3011
  tmp.i = key.m_page_no;
 
3012
  
 
3013
  c_page_pool.getPtr(tmp);
 
3014
  memcpy(pagePtr, &tmp, sizeof(tmp));
 
3015
  return ((Var_page*)tmp.p)->get_ptr(key.m_page_idx);
 
3016
}
 
3017
 
 
3018
inline
 
3019
Uint32*
 
3020
Dbtup::get_ptr(PagePtr* pagePtr, 
 
3021
               const Local_key* key, const Tablerec* regTabPtr)
 
3022
{
 
3023
  PagePtr tmp;
 
3024
  tmp.i= key->m_page_no;
 
3025
  c_page_pool.getPtr(tmp);
 
3026
  memcpy(pagePtr, &tmp, sizeof(tmp));
 
3027
 
 
3028
  return ((Fix_page*)tmp.p)->
 
3029
    get_ptr(key->m_page_idx, regTabPtr->m_offsets[MM].m_fix_header_size);
 
3030
}
 
3031
 
 
3032
inline
 
3033
Uint32*
 
3034
Dbtup::get_dd_ptr(PagePtr* pagePtr, 
 
3035
                  const Local_key* key, const Tablerec* regTabPtr)
 
3036
{
 
3037
  PagePtr tmp;
 
3038
  tmp.i= key->m_page_no;
 
3039
  tmp.p= (Page*)m_global_page_pool.getPtr(tmp.i);
 
3040
  memcpy(pagePtr, &tmp, sizeof(tmp));
 
3041
  
 
3042
  if(regTabPtr->m_attributes[DD].m_no_of_varsize)
 
3043
    return ((Var_page*)tmp.p)->get_ptr(key->m_page_idx);
 
3044
  else
 
3045
    return ((Fix_page*)tmp.p)->
 
3046
      get_ptr(key->m_page_idx, regTabPtr->m_offsets[DD].m_fix_header_size);
 
3047
}
 
3048
 
 
3049
NdbOut&
 
3050
operator<<(NdbOut&, const Dbtup::Tablerec&);
 
3051
 
 
3052
inline
 
3053
bool Dbtup::find_savepoint(OperationrecPtr& loopOpPtr, Uint32 savepointId)
 
3054
{
 
3055
  while (true) {
 
3056
    if (savepointId > loopOpPtr.p->savepointId) {
 
3057
      jam();
 
3058
      return true;
 
3059
    }
 
3060
    loopOpPtr.i = loopOpPtr.p->prevActiveOp;
 
3061
    if (loopOpPtr.i == RNIL) {
 
3062
      break;
 
3063
    }
 
3064
    c_operation_pool.getPtr(loopOpPtr);
 
3065
  }
 
3066
  return false;
 
3067
}
 
3068
 
 
3069
#endif