2
Copyright (C) 2003-2006, 2008 MySQL AB, 2008, 2009 Sun Microsystems, Inc.
3
All rights reserved. Use is subject to license terms.
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
#include "Emulator.hpp"
25
#include <ndb_limits.h>
27
#ifdef NO_EMULATED_JAM
32
#define jamEntryLine(line)
33
#define jamBlock(block)
34
#define jamBlockLine(block, line)
35
#define jamEntryBlock(block)
36
#define jamEntryBlockLine(block, line)
38
#define jamNoBlockLine(line)
39
#define thrjamEntry(buf)
40
#define thrjamEntryLine(buf, line)
42
#define thrjamLine(buf, line)
46
#define thrjamEntryBlockLine(jamBufferArg, blockNo, line) \
48
EmulatedJamBuffer* jamBuffer = jamBufferArg; \
49
Uint32 blockNumber = blockNo; \
50
Uint32 jamIndex = jamBuffer->theEmulatedJamIndex; \
51
jamBuffer->theEmulatedJam[jamIndex++] = (blockNumber << 20) | (line); \
52
jamBuffer->theEmulatedJamBlockNumber = blockNumber; \
53
jamBuffer->theEmulatedJamIndex = jamIndex & JAM_MASK; \
56
#define thrjamLine(jamBufferArg, line) \
58
EmulatedJamBuffer* jamBuffer = jamBufferArg; \
59
Uint32 jamIndex = jamBuffer->theEmulatedJamIndex; \
60
jamBuffer->theEmulatedJam[jamIndex++] = (line); \
61
jamBuffer->theEmulatedJamIndex = jamIndex & JAM_MASK; \
64
#define jamBlockLine(block, line) thrjamLine(block->jamBuffer(), line)
65
#define jamBlock(block) jamBlockLine((block), __LINE__)
66
#define jamLine(line) jamBlockLine(this, (line))
67
#define jam() jamLine(__LINE__)
68
#define jamBlockEntryLine(block, line) \
69
thrjamEntryBlockLine(block->jamBuffer(), block->number(), line)
70
#define jamEntryBlock(block) jamEntryBlockLine(block, __LINE__)
71
#define jamEntryLine(line) jamBlockEntryLine(this, (line))
72
#define jamEntry() jamEntryLine(__LINE__)
74
#define jamNoBlockLine(line) \
75
thrjamLine((EmulatedJamBuffer *)NdbThread_GetTlsKey(NDB_THREAD_TLS_JAM), \
77
#define jamNoBlock() jamNoBlockLine(__LINE__)
79
#define thrjamEntryLine(buf, line) thrjamEntryBlockLine(buf, number(), line)
81
#define thrjam(buf) thrjamLine(buf, __LINE__)
82
#define thrjamEntry(buf) thrjamEntryLine(buf, __LINE__)
87
#define ptrCheck(ptr, limit, rec) if (ptr.i < (limit)) ptr.p = &rec[ptr.i]; else ptr.p = NULL
90
* Sets the p-value of a ptr-struct to be a pointer to record no i
91
* (where i is the i-value of the ptr-struct)
93
* @param ptr ptr-struct with a set i-value (the p-value in this gets set)
94
* @param limit max no of records in rec
95
* @param rec pointer to first record in an array of records
97
#define ptrCheckGuardErr(ptr, limit, rec, error) {\
99
TxxzLimit = (limit); \
102
ptr.p = &rec[TxxxPtr]; \
103
if (TxxxPtr < (TxxzLimit)) { \
106
progError(__LINE__, error, __FILE__); \
108
#define ptrAss(ptr, rec) ptr.p = &rec[ptr.i]
109
#define ptrNull(ptr) ptr.p = NULL
110
#define ptrGuardErr(ptr, error) if (ptr.p == NULL) \
111
progError(__LINE__, error, __FILE__)
112
#define arrGuardErr(ind, size, error) if ((ind) >= (size)) \
113
progError(__LINE__, error, __FILE__)
115
#define ptrCheck(ptr, limit, rec) ptr.p = &rec[ptr.i]
116
#define ptrCheckGuardErr(ptr, limit, rec, error) ptr.p = &rec[ptr.i]
117
#define ptrAss(ptr, rec) ptr.p = &rec[ptr.i]
118
#define ptrNull(ptr) ptr.p = NULL
119
#define ptrGuardErr(ptr, error)
120
#define arrGuardErr(ind, size, error)
123
#define ptrCheckGuard(ptr, limit, rec) \
124
ptrCheckGuardErr(ptr, limit, rec, NDBD_EXIT_POINTER_NOTINRANGE)
125
#define ptrGuard(ptr) ptrGuardErr(ptr, NDBD_EXIT_POINTER_NOTINRANGE)
126
#define arrGuard(ind, size) arrGuardErr(ind, size, NDBD_EXIT_INDEX_NOTINRANGE)
128
// -------- ERROR INSERT MACROS -------
130
#define ERROR_INSERT_VARIABLE UintR cerrorInsert, c_error_insert_extra
131
#define ERROR_INSERTED(x) (cerrorInsert == (x))
132
#define ERROR_INSERTED_CLEAR(x) (cerrorInsert == (x) ? (cerrorInsert = 0, true) : false)
133
#define ERROR_INSERT_VALUE cerrorInsert
134
#define ERROR_INSERT_EXTRA c_error_insert_extra
135
#define SET_ERROR_INSERT_VALUE(x) cerrorInsert = x
136
#define SET_ERROR_INSERT_VALUE2(x,y) cerrorInsert = x; c_error_insert_extra = y
137
#define CLEAR_ERROR_INSERT_VALUE cerrorInsert = 0
139
#define ERROR_INSERT_VARIABLE typedef void * cerrorInsert // Will generate compiler error if used
140
#define ERROR_INSERTED(x) false
141
#define ERROR_INSERTED_CLEAR(x) false
142
#define ERROR_INSERT_VALUE 0
143
#define SET_ERROR_INSERT_VALUE(x) do { } while(0)
144
#define SET_ERROR_INSERT_VALUE2(x,y) do { } while(0)
145
#define CLEAR_ERROR_INSERT_VALUE do { } while(0)
148
#define DECLARE_DUMP0(BLOCK, CODE, DESC) if (arg == CODE)
150
/* ------------------------------------------------------------------------- */
151
/* COMMONLY USED CONSTANTS. */
152
/* ------------------------------------------------------------------------- */
158
#define ZCLOSE_FILE 2
162
/* ------------------------------------------------------------------------- */
163
// Number of fragments stored per node. Should be settable on a table basis
164
// in future version since small tables want small value and large tables
166
/* ------------------------------------------------------------------------- */
167
#define NO_OF_FRAG_PER_NODE 1
168
#define MAX_FRAG_PER_NODE 8
171
* DIH allocates fragments in chunk for fast find of fragment record.
172
* These parameters define chunk size and log of chunk size.
174
#define NO_OF_FRAGS_PER_CHUNK 4
175
#define LOG_NO_OF_FRAGS_PER_CHUNK 2
177
/* ---------------------------------------------------------------- */
178
// To avoid synching too big chunks at a time we synch after writing
179
// a certain number of data/UNDO pages. (e.g. 2 MBytes).
180
/* ---------------------------------------------------------------- */
181
#define MAX_REDO_PAGES_WITHOUT_SYNCH 32
183
/* ------------------------------------------------------------------ */
184
// We have these constants to ensure that we can easily change the
185
// parallelism of node recovery and the amount of scan
186
// operations needed for node recoovery.
187
/* ------------------------------------------------------------------ */
188
#define MAX_NO_WORDS_OUTSTANDING_COPY_FRAGMENT 6000
189
#define MAGIC_CONSTANT 56
190
#define NODE_RECOVERY_SCAN_OP_RECORDS \
191
(4 + ((4*MAX_NO_WORDS_OUTSTANDING_COPY_FRAGMENT)/ \
192
((MAGIC_CONSTANT + 2) * 5)))
200
* Ndb kernel blocks assertion handling
202
* Two type of assertions:
203
* - ndbassert - Only used when compiling VM_TRACE
204
* - ndbrequire - Always checked
206
* If a ndbassert/ndbrequire fails, the system will
207
* shutdown and generate an error log
210
* NOTE these may only be used within blocks
213
#define ndbassert(check) \
216
progError(__LINE__, NDBD_EXIT_NDBASSERT, __FILE__); \
219
#define ndbassert(check) do { } while(0)
222
#define ndbrequireErr(check, error) \
225
progError(__LINE__, error, __FILE__); \
228
#define ndbrequire(check) \
229
ndbrequireErr(check, NDBD_EXIT_NDBREQUIRE)
231
#define CRASH_INSERTION(errorType) \
232
if (!ERROR_INSERTED((errorType))) { \
234
progError(__LINE__, NDBD_EXIT_ERROR_INSERT, __FILE__); \
237
#define CRASH_INSERTION2(errorNum, condition) \
238
if (!(ERROR_INSERTED(errorNum) && condition)) { \
240
progError(__LINE__, NDBD_EXIT_ERROR_INSERT, __FILE__); \
243
#define MEMCOPY_PAGE(to, from, page_size_in_bytes) \
244
memcpy((void*)(to), (void*)(from), (size_t)(page_size_in_bytes));
245
#define MEMCOPY_NO_WORDS(to, from, no_of_words) \
246
memcpy((to), (void*)(from), (size_t)((no_of_words) << 2));