~ubuntu-branches/ubuntu/trusty/mysql-5.6/trusty

« back to all changes in this revision

Viewing changes to storage/ndb/src/kernel/vm/pc.hpp

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-02-12 11:54:27 UTC
  • Revision ID: package-import@ubuntu.com-20140212115427-oq6tfsqxl1wuwehi
Tags: upstream-5.6.15
ImportĀ upstreamĀ versionĀ 5.6.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Copyright (C) 2003-2006, 2008 MySQL AB, 2008, 2009 Sun Microsystems, Inc.
 
3
    All rights reserved. Use is subject to license terms.
 
4
 
 
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.
 
8
 
 
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.
 
13
 
 
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
 
17
*/
 
18
 
 
19
#ifndef PC_H
 
20
#define PC_H
 
21
 
 
22
 
 
23
#include "Emulator.hpp"
 
24
#include <NdbOut.hpp>
 
25
#include <ndb_limits.h>
 
26
 
 
27
#ifdef NO_EMULATED_JAM
 
28
 
 
29
#define jam()
 
30
#define jamLine(line)
 
31
#define jamEntry()
 
32
#define jamEntryLine(line)
 
33
#define jamBlock(block)
 
34
#define jamBlockLine(block, line)
 
35
#define jamEntryBlock(block)
 
36
#define jamEntryBlockLine(block, line)
 
37
#define jamNoBlock()
 
38
#define jamNoBlockLine(line)
 
39
#define thrjamEntry(buf)
 
40
#define thrjamEntryLine(buf, line)
 
41
#define thrjam(buf)
 
42
#define thrjamLine(buf, line)
 
43
 
 
44
#else
 
45
 
 
46
#define thrjamEntryBlockLine(jamBufferArg, blockNo, line) \
 
47
  do { \
 
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; \
 
54
  } while (0)
 
55
 
 
56
#define thrjamLine(jamBufferArg, line) \
 
57
  do { \
 
58
    EmulatedJamBuffer* jamBuffer = jamBufferArg; \
 
59
    Uint32 jamIndex = jamBuffer->theEmulatedJamIndex; \
 
60
    jamBuffer->theEmulatedJam[jamIndex++] = (line); \
 
61
    jamBuffer->theEmulatedJamIndex = jamIndex & JAM_MASK; \
 
62
  } while(0)
 
63
 
 
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__)
 
73
 
 
74
#define jamNoBlockLine(line) \
 
75
    thrjamLine((EmulatedJamBuffer *)NdbThread_GetTlsKey(NDB_THREAD_TLS_JAM), \
 
76
               (line))
 
77
#define jamNoBlock() jamNoBlockLine(__LINE__)
 
78
 
 
79
#define thrjamEntryLine(buf, line) thrjamEntryBlockLine(buf, number(), line)
 
80
 
 
81
#define thrjam(buf) thrjamLine(buf, __LINE__)
 
82
#define thrjamEntry(buf) thrjamEntryLine(buf, __LINE__)
 
83
 
 
84
#endif
 
85
 
 
86
#ifndef NDB_OPT
 
87
#define ptrCheck(ptr, limit, rec) if (ptr.i < (limit)) ptr.p = &rec[ptr.i]; else ptr.p = NULL
 
88
 
 
89
/**
 
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)
 
92
 *
 
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
 
96
 */
 
97
#define ptrCheckGuardErr(ptr, limit, rec, error) {\
 
98
  UintR TxxzLimit; \
 
99
  TxxzLimit = (limit); \
 
100
  UintR TxxxPtr; \
 
101
  TxxxPtr = ptr.i; \
 
102
  ptr.p = &rec[TxxxPtr]; \
 
103
  if (TxxxPtr < (TxxzLimit)) { \
 
104
    ; \
 
105
  } else { \
 
106
    progError(__LINE__, error, __FILE__); \
 
107
  }}
 
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__)
 
114
#else
 
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)
 
121
#endif
 
122
 
 
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)
 
127
 
 
128
// -------- ERROR INSERT MACROS -------
 
129
#ifdef ERROR_INSERT
 
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
 
138
#else
 
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)
 
146
#endif
 
147
 
 
148
#define DECLARE_DUMP0(BLOCK, CODE, DESC) if (arg == CODE)
 
149
 
 
150
/* ------------------------------------------------------------------------- */
 
151
/*       COMMONLY USED CONSTANTS.                                            */
 
152
/* ------------------------------------------------------------------------- */
 
153
#define ZFALSE 0
 
154
#define ZTRUE 1
 
155
#define ZSET 1
 
156
#define ZOK 0
 
157
#define ZNOT_OK 1
 
158
#define ZCLOSE_FILE 2
 
159
#define ZNIL 0xffff
 
160
#define Z8NIL 255
 
161
 
 
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
 
165
// need large value.
 
166
/* ------------------------------------------------------------------------- */
 
167
#define NO_OF_FRAG_PER_NODE 1
 
168
#define MAX_FRAG_PER_NODE 8
 
169
 
 
170
/**
 
171
* DIH allocates fragments in chunk for fast find of fragment record.
 
172
* These parameters define chunk size and log of chunk size.
 
173
*/
 
174
#define NO_OF_FRAGS_PER_CHUNK 4
 
175
#define LOG_NO_OF_FRAGS_PER_CHUNK 2
 
176
 
 
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
 
182
 
 
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)))
 
193
 
 
194
#ifdef NO_CHECKPOINT
 
195
#define NO_LCP
 
196
#define NO_GCP
 
197
#endif
 
198
 
 
199
/**
 
200
 * Ndb kernel blocks assertion handling
 
201
 *
 
202
 * Two type of assertions:
 
203
 * - ndbassert  - Only used when compiling VM_TRACE
 
204
 * - ndbrequire - Always checked
 
205
 *
 
206
 * If a ndbassert/ndbrequire fails, the system will 
 
207
 * shutdown and generate an error log
 
208
 *
 
209
 *
 
210
 * NOTE these may only be used within blocks
 
211
 */
 
212
#if defined VM_TRACE
 
213
#define ndbassert(check) \
 
214
  if(likely(check)){ \
 
215
  } else {     \
 
216
    progError(__LINE__, NDBD_EXIT_NDBASSERT, __FILE__); \
 
217
  }
 
218
#else
 
219
#define ndbassert(check) do { } while(0)
 
220
#endif
 
221
 
 
222
#define ndbrequireErr(check, error) \
 
223
  if(likely(check)){ \
 
224
  } else {     \
 
225
    progError(__LINE__, error, __FILE__); \
 
226
  }
 
227
 
 
228
#define ndbrequire(check) \
 
229
  ndbrequireErr(check, NDBD_EXIT_NDBREQUIRE)
 
230
 
 
231
#define CRASH_INSERTION(errorType) \
 
232
  if (!ERROR_INSERTED((errorType))) { \
 
233
  } else { \
 
234
    progError(__LINE__, NDBD_EXIT_ERROR_INSERT, __FILE__); \
 
235
  }
 
236
 
 
237
#define CRASH_INSERTION2(errorNum, condition) \
 
238
  if (!(ERROR_INSERTED(errorNum) && condition)) { \
 
239
  } else { \
 
240
    progError(__LINE__, NDBD_EXIT_ERROR_INSERT, __FILE__); \
 
241
  }
 
242
 
 
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));
 
247
 
 
248
#endif