summaryrefslogtreecommitdiff
path: root/ndb/src/kernel/vm/pc.hpp
diff options
context:
space:
mode:
authorunknown <magnus@neptunus.(none)>2004-04-14 10:53:21 +0200
committerunknown <magnus@neptunus.(none)>2004-04-14 10:53:21 +0200
commit6386c55cee50bad6a9979d1fab28e03bb8612ca7 (patch)
tree3fbbacf704304b69228474b9f03549ccd585a017 /ndb/src/kernel/vm/pc.hpp
parent0ba6cb48d84f1ff951d09871a96be6cdef3f2c3c (diff)
downloadmariadb-git-6386c55cee50bad6a9979d1fab28e03bb8612ca7.tar.gz
Initial revision of NDB Cluster files
BitKeeper/etc/logging_ok: Logging to logging@openlogging.org accepted
Diffstat (limited to 'ndb/src/kernel/vm/pc.hpp')
-rw-r--r--ndb/src/kernel/vm/pc.hpp248
1 files changed, 248 insertions, 0 deletions
diff --git a/ndb/src/kernel/vm/pc.hpp b/ndb/src/kernel/vm/pc.hpp
new file mode 100644
index 00000000000..873a986bc35
--- /dev/null
+++ b/ndb/src/kernel/vm/pc.hpp
@@ -0,0 +1,248 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef PC_H
+#define PC_H
+
+
+#include "Emulator.hpp"
+#include <NdbOut.hpp>
+#include <ndb_limits.h>
+
+#ifdef USE_EMULATED_JAM
+
+#ifdef NDB_WIN32
+
+#define jam() { \
+ Uint32 tEmulatedJamIndex = theEmulatedJamIndex; \
+ *(Uint32*)(theEmulatedJam + tEmulatedJamIndex) = __LINE__; \
+ theEmulatedJamIndex = (tEmulatedJamIndex + 4) & JAM_MASK; }
+#define jamLine(line) { \
+ Uint32 tEmulatedJamIndex = theEmulatedJamIndex; \
+ *(Uint32*)(theEmulatedJam + tEmulatedJamIndex) = line; \
+ theEmulatedJamIndex = (tEmulatedJamIndex + 4) & JAM_MASK; }
+#define jamEntry() { \
+ theEmulatedJamBlockNumber = number(); \
+ Uint32 tEmulatedJamIndex = theEmulatedJamIndex; \
+ *(Uint32*)(theEmulatedJam + tEmulatedJamIndex) = \
+ ((theEmulatedJamBlockNumber << 20) | __LINE__); \
+ theEmulatedJamIndex = (tEmulatedJamIndex + 4) & JAM_MASK; }
+#define jamEntryLine(line) { \
+ theEmulatedJamBlockNumber = number(); \
+ Uint32 tEmulatedJamIndex = theEmulatedJamIndex; \
+ *(Uint32*)(theEmulatedJam + tEmulatedJamIndex) = \
+ ((theEmulatedJamBlockNumber << 20) | line); \
+ theEmulatedJamIndex = (tEmulatedJamIndex + 4) & JAM_MASK; }
+
+#else
+
+#define jam() { \
+ Uint32 tEmulatedJamIndex = theEmulatedJamIndex; \
+ *(Uint32*)((UintPtr)theEmulatedJam + (Uint32)tEmulatedJamIndex) = __LINE__; \
+ theEmulatedJamIndex = (tEmulatedJamIndex + 4) & JAM_MASK; }
+#define jamLine(line) { \
+ Uint32 tEmulatedJamIndex = theEmulatedJamIndex; \
+ *(Uint32*)((UintPtr)theEmulatedJam + (Uint32)tEmulatedJamIndex) = line; \
+ theEmulatedJamIndex = (tEmulatedJamIndex + 4) & JAM_MASK; }
+#define jamEntry() { \
+ theEmulatedJamBlockNumber = number(); \
+ Uint32 tEmulatedJamIndex = theEmulatedJamIndex; \
+ *(Uint32*)((UintPtr)theEmulatedJam + (Uint32)tEmulatedJamIndex) = \
+ ((theEmulatedJamBlockNumber << 20) | __LINE__); \
+ theEmulatedJamIndex = (tEmulatedJamIndex + 4) & JAM_MASK; }
+#define jamEntryLine(line) { \
+ theEmulatedJamBlockNumber = number(); \
+ Uint32 tEmulatedJamIndex = theEmulatedJamIndex; \
+ *(Uint32*)((UintPtr)theEmulatedJam + (Uint32)tEmulatedJamIndex) = \
+ ((theEmulatedJamBlockNumber << 20) | line); \
+ theEmulatedJamIndex = (tEmulatedJamIndex + 4) & JAM_MASK; }
+
+#endif
+
+#else
+#define jam()
+#define jamLine(line)
+#define jamEntry()
+#define jamEntryLine(line)
+#endif
+#ifndef NDB_OPT
+#define ptrCheck(ptr, limit, rec) if (ptr.i < (limit)) ptr.p = &rec[ptr.i]; else ptr.p = NULL
+
+/**
+ * Sets the p-value of a ptr-struct to be a pointer to record no i
+ * (where i is the i-value of the ptr-struct)
+ *
+ * @param ptr ptr-struct with a set i-value (the p-value in this gets set)
+ * @param limit max no of records in rec
+ * @param rec pointer to first record in an array of records
+ */
+#define ptrCheckGuard(ptr, limit, rec) {\
+ UintR TxxzLimit; \
+ TxxzLimit = (limit); \
+ UintR TxxxPtr; \
+ TxxxPtr = ptr.i; \
+ ptr.p = &rec[TxxxPtr]; \
+ if (TxxxPtr < (TxxzLimit)) { \
+ ; \
+ } else { \
+ progError(__LINE__, ERR_POINTER_NOTINRANGE, __FILE__); \
+ }}
+
+#define ptrAss(ptr, rec) ptr.p = &rec[ptr.i]
+#define ptrNull(ptr) ptr.p = NULL
+#define ptrGuard(ptr) if (ptr.p == NULL) \
+ progError(__LINE__, ERR_POINTER_NOTINRANGE, __FILE__)
+#define arrGuard(ind, size) if ((ind) >= (size)) \
+ progError(__LINE__, ERR_INDEX_NOTINRANGE, __FILE__)
+#else
+#define ptrCheck(ptr, limit, rec) ptr.p = &rec[ptr.i]
+#define ptrCheckGuard(ptr, limit, rec) ptr.p = &rec[ptr.i]
+#define ptrAss(ptr, rec) ptr.p = &rec[ptr.i]
+#define ptrNull(ptr) ptr.p = NULL
+#define ptrGuard(ptr)
+#define arrGuard(ind, size)
+#endif
+
+// ------- EVENT STATES OF A NODE -----------------------------
+#define ZADD 0 /* New application added */
+#define ZREMOVE 1 /* An application has been removed */
+#define ZSTART 2 /* An application is ready to start */
+#define ZRUN 3 /* An application has started to run */
+
+// -------- ERROR INSERT MACROS -------
+#ifdef ERROR_INSERT
+#define ERROR_INSERT_VARIABLE UintR cerrorInsert
+#define ERROR_INSERTED(x) (cerrorInsert == (x))
+#define SET_ERROR_INSERT_VALUE(x) cerrorInsert = x
+#define CLEAR_ERROR_INSERT_VALUE cerrorInsert = 0
+#else
+#define ERROR_INSERT_VARIABLE typedef void * cerrorInsert // Will generate compiler error if used
+#define ERROR_INSERTED(x) false
+#define SET_ERROR_INSERT_VALUE(x)
+#define CLEAR_ERROR_INSERT_VALUE
+#endif
+
+/* ------------------------------------------------------------------------- */
+/* COMMONLY USED CONSTANTS. */
+/* ------------------------------------------------------------------------- */
+#define ZFALSE 0
+#define ZTRUE 1
+#define ZSET 1
+#define ZOK 0
+#define ZNOT_OK 1
+#define ZCLOSE_FILE 2
+#define ZNIL 0xffff
+#define Z8NIL 255
+
+/* ------------------------------------------------------------------------- */
+// Number of fragments stored per node. Should be settable on a table basis
+// in future version since small tables want small value and large tables
+// need large value.
+/* ------------------------------------------------------------------------- */
+#define NO_OF_FRAG_PER_NODE 8
+
+/* ---------------------------------------------------------------- */
+// To avoid synching too big chunks at a time we synch after writing
+// a certain number of data/UNDO pages. (e.g. 2 MBytes).
+/* ---------------------------------------------------------------- */
+#define MAX_PAGES_WITHOUT_SYNCH 64
+#define MAX_REDO_PAGES_WITHOUT_SYNCH 32
+
+/* ------------------------------------------------------------------ */
+// We have these constants to ensure that we can easily change the
+// parallelism of node recovery and the amount of scan
+// operations needed for node recoovery.
+/* ------------------------------------------------------------------ */
+#define MAX_NO_WORDS_OUTSTANDING_COPY_FRAGMENT 6000
+#define MAGIC_CONSTANT 56
+#define NODE_RECOVERY_SCAN_OP_RECORDS \
+ (4 + ((4*MAX_NO_WORDS_OUTSTANDING_COPY_FRAGMENT)/ \
+ ((MAGIC_CONSTANT + 2) * 5)))
+
+#ifdef NO_CHECKPOINT
+#define NO_LCP
+#define NO_GCP
+#endif
+
+/**
+ * Ndb kernel blocks assertion handling
+ *
+ * Two type of assertions:
+ * - ndbassert - Only used when compiling VM_TRACE
+ * - ndbrequire - Always checked
+ *
+ * If a ndbassert/ndbrequire fails, the system will
+ * shutdown and generate an error log
+ *
+ *
+ * NOTE these may only be used within blocks
+ */
+#if defined VM_TRACE || defined NDB_DEBUG
+#define ndbassert(check) \
+ if((check)){ \
+ } else { \
+ progError(__LINE__, ERR_NDBREQUIRE, __FILE__); \
+ }
+
+#define ndbrequire(check) \
+ if((check)){ \
+ } else { \
+ progError(__LINE__, ERR_NDBREQUIRE, __FILE__); \
+ }
+#else
+#define ndbassert(check)
+
+#define ndbrequire(check) \
+ if((check)){ \
+ } else { \
+ progError(__LINE__, ERR_NDBREQUIRE, __FILE__); \
+ }
+#endif
+
+#define CRASH_INSERTION(errorType) \
+ if (!ERROR_INSERTED((errorType))) { \
+ } else { \
+ progError(__LINE__, ERR_ERROR_INSERT, __FILE__); \
+ }
+
+#define CRASH_INSERTION2(errorNum, condition) \
+ if (!(ERROR_INSERTED(errorNum) && condition)) { \
+ } else { \
+ progError(__LINE__, ERR_ERROR_INSERT, __FILE__); \
+ }
+
+#define MEMCOPY_PAGE(to, from, page_size_in_bytes) \
+ memcpy((void*)(to), (void*)(from), (size_t)(page_size_in_bytes));
+#define MEMCOPY_NO_WORDS(to, from, no_of_words) \
+ memcpy((to), (void*)(from), (size_t)(no_of_words << 2));
+
+template <class T>
+struct Ptr {
+ T * p;
+ Uint32 i;
+ inline bool isNull() const { return i == RNIL; }
+ inline void setNull() { i = RNIL; }
+};
+
+template <class T>
+struct ConstPtr {
+ const T * p;
+ Uint32 i;
+ inline bool isNull() const { return i == RNIL; }
+ inline void setNull() { i = RNIL; }
+};
+
+#endif