Types.h

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/common/Types.h#24 $
00003 // Fennel is a library of data storage and processing components.
00004 // Copyright (C) 2005-2009 The Eigenbase Project
00005 // Copyright (C) 2003-2009 SQLstream, Inc.
00006 // Copyright (C) 2005-2009 LucidEra, Inc.
00007 // Portions Copyright (C) 1999-2009 John V. Sichi
00008 //
00009 // This program is free software; you can redistribute it and/or modify it
00010 // under the terms of the GNU General Public License as published by the Free
00011 // Software Foundation; either version 2 of the License, or (at your option)
00012 // any later version approved by The Eigenbase Project.
00013 //
00014 // This program is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with this program; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 */
00023 
00024 #ifndef Fennel_Types_Included
00025 #define Fennel_Types_Included
00026 
00027 #include "fennel/common/SharedTypes.h"
00028 
00029 #include <set>
00030 
00031 // TODO jvs 25-Feb-2009:  update these for win64.  I had to use
00032 // the unsized ints to avoid compilation errors from mersenne_twister
00033 // in BernoulliRng.cpp.
00034 #ifdef __MSVC__
00035 typedef __int8 int8_t;
00036 typedef __int16 int16_t;
00037 typedef __int32 int32_t;
00038 typedef __int64 int64_t;
00039 typedef unsigned __int8  uint8_t;
00040 typedef unsigned __int16 uint16_t;
00041 typedef unsigned __int32 uint32_t;
00042 typedef unsigned __int64 uint64_t;
00043 
00044 #define snprintf _snprintf
00045 #define strcasecmp strcmpi
00046 
00047 #endif
00048 
00049 FENNEL_BEGIN_NAMESPACE
00050 
00051 // use these symbols when you want to indicate that a variable points to
00052 // a raw buffer of byte data
00053 typedef uint8_t FixedBuffer;      // e.g. FixedBuffer buf[10];
00054 typedef uint8_t *PBuffer;
00055 typedef uint8_t const *PConstBuffer;
00056 
00057 // a single UCS-2 character
00058 typedef uint16_t Ucs2Char;
00059 // a buffer of UCS-2 characters (with no byte order mark)
00060 typedef Ucs2Char *Ucs2Buffer;
00061 typedef Ucs2Char const *Ucs2ConstBuffer;
00062 
00063 // use FileSize for all file sizes and offsets
00064 typedef uint64_t FileSize;
00065 
00066 // use TupleStorageByteLength for all tuple buffer length indicators
00067 typedef uint TupleStorageByteLength;
00068 
00069 // version number of a VersionedSegment
00070 typedef uint64_t SegVersionNum;
00071 
00072 // magic number used for verifying page type
00073 typedef uint64_t MagicNumber;
00074 
00075 template <class Node>
00076 class SegNodeLock;
00077 
00081 struct FENNEL_COMMON_EXPORT IntrusiveListNode
00082 {
00083     IntrusiveListNode *pNext;
00084 
00085 #ifdef DEBUG
00086     IntrusiveListNode()
00087     {
00088         pNext = NULL;
00089     }
00090 #endif
00091 };
00092 
00093 // When using unsigned types, it's often necessary to detect wrap-around
00094 // (e.g. when decrementing in a for loop) or to have a special value other
00095 // than 0.  The literal -1 cannot be used for this purpose, because the
00096 // compiler knows that an unsigned number can't possibly be negative.
00097 // Instead, use MAXU, defined here.
00098 
00099 class FENNEL_COMMON_EXPORT MaxU {
00100 public:
00101     MaxU()
00102     {
00103     }
00104 
00105     operator uint8_t() const
00106     {
00107         return 0xFF;
00108     }
00109 
00110     operator uint16_t() const
00111     {
00112         return 0xFFFF;
00113     }
00114 
00115     operator uint32_t() const
00116     {
00117         return 0xFFFFFFFF;
00118     }
00119 
00120     operator uint64_t() const
00121     {
00122         return 0xFFFFFFFFFFFFFFFFLL;
00123     }
00124 };
00125 
00126 static const MaxU MAXU;
00127 
00128 // however, you can't compare some unsigned types against MAXU,
00129 // so use isMAXU(u) instead
00130 template <class tU>
00131 inline bool isMAXU(tU u)
00132 {
00133     return (u == tU(0xFFFFFFFFFFFFFFFFLL));
00134 }
00135 
00136 enum { ETERNITY = 0xFFFFFFFF };
00137 
00141 enum LockMode
00142 {
00146     LOCKMODE_S,
00147 
00151     LOCKMODE_X,
00152 
00156     LOCKMODE_S_NOWAIT,
00157 
00161     LOCKMODE_X_NOWAIT
00162 
00163 // NOTE:  enumeration order is significant
00164 };
00165 
00170 enum CheckpointType
00171 {
00175     CHECKPOINT_DISCARD,
00176 
00180     CHECKPOINT_FLUSH_AND_UNMAP,
00181 
00185     CHECKPOINT_FLUSH_ALL,
00186 
00190     CHECKPOINT_FLUSH_FUZZY
00191 
00192 // NOTE:  enumeration order is significant
00193 };
00194 
00199 enum DuplicateSeek
00200 {
00204     DUP_SEEK_ANY,
00205 
00209     DUP_SEEK_BEGIN,
00210 
00214     DUP_SEEK_END
00215 };
00216 
00221 typedef char const * const ParamName;
00222 
00227 typedef char const * const ParamVal;
00228 
00229 // PageOwnerId is a 64-bit integer identifying the owner of a page allocated
00230 // from a segment.  Only the low 62 bits should be used (with the exception
00231 // of ANON_PAGE_OWNER_ID), as the high order bit may be used to flag special
00232 // settings, and if that high order bit is used and set, we need to be able
00233 // to distinguish an ownerId with that bit set from ANON_PAGE_OWNER_ID.  So,
00234 // that's why we also need to reserve the second highest bit.
00235 DEFINE_OPAQUE_INTEGER(PageOwnerId,uint64_t);
00236 
00237 #define VALID_PAGE_OWNER_ID(pageOwnerId) \
00238     (!(opaqueToInt(pageOwnerId) & 0xC000000000000000LL))
00239 
00240 // DeviceID is an integer identifying a device.
00241 DEFINE_OPAQUE_INTEGER(DeviceId,uint);
00242 
00243 // SegmentId is an integer identifying a segment.
00244 DEFINE_OPAQUE_INTEGER(SegmentId,uint);
00245 
00246 // BlockId is a 64-bit identifier for a physical block on disk.
00247 DEFINE_OPAQUE_INTEGER(BlockId,uint64_t);
00248 
00249 // PageId is a 64-bit identifier for a logical page within the scope of a
00250 // particular segment.
00251 DEFINE_OPAQUE_INTEGER(PageId,uint64_t);
00252 
00253 // SegByteId is the logical 64-bit address of a byte within the scope of a
00254 // particular segment.
00255 DEFINE_OPAQUE_INTEGER(SegByteId,uint64_t);
00256 
00257 // TxnId is the 64-bit identifier for a transaction.  Only the low 63 bits
00258 // should be used, as the high order bit may be used to flag special settings.
00259 DEFINE_OPAQUE_INTEGER(TxnId,uint64_t);
00260 
00261 // TxnId is an integer identifier for a txn-relative savepoint.
00262 DEFINE_OPAQUE_INTEGER(SavepointId,uint);
00263 
00264 // LogicalTxnClassId is a magic number identifying the type of
00265 // a logged LogicalTxnParticipant.
00266 DEFINE_OPAQUE_INTEGER(LogicalTxnClassId,uint64_t);
00267 
00268 // DynamicParamId is an identifier for a dynamic parameter within the
00269 // scope of an ExecStreamGraph.
00270 DEFINE_OPAQUE_INTEGER(DynamicParamId,uint);
00271 
00272 // LogicalActionType enumerates the possible actions in a LogicalTxn in a
00273 // participant-defined manner.  Each participant class defines its own
00274 // enumeration of positive integers, but the same integer may be used by
00275 // different participant classes.  Negative integers are used for
00276 // system-defined actions.
00277 typedef int LogicalActionType;
00278 
00279 // Set of pageIds
00280 typedef std::set<PageId> PageSet;
00281 typedef PageSet::const_iterator PageSetConstIter;
00282 
00286 static const PageId NULL_PAGE_ID = PageId(0xFFFFFFFFFFFFFFFFLL);
00287 
00291 static const PageId FIRST_LINEAR_PAGE_ID = PageId(0);
00292 
00296 static const BlockId NULL_BLOCK_ID = BlockId(0xFFFFFFFFFFFFFFFFLL);
00297 
00302 static const PageOwnerId ANON_PAGE_OWNER_ID = PageOwnerId(0xFFFFFFFFFFFFFFFFLL);
00303 
00307 static const SavepointId NULL_SVPT_ID = SavepointId(MAXU);
00308 
00313 static const TxnId IMPLICIT_TXN_ID = TxnId(0);
00314 
00318 static const TxnId FIRST_TXN_ID = TxnId(1);
00319 
00323 static const TxnId NULL_TXN_ID = TxnId(0xFFFFFFFFFFFFFFFFLL);
00324 
00325 // The types below are called "Num" rather than "Id" because they are
00326 // used to represent either a count or an offset.  We use plain
00327 // typedef rather than DEFINE_OPAQUE_INTEGER because a lot of arithmetic
00328 // is done on these.
00329 
00333 typedef uint64_t RecordNum;
00334 
00338 typedef uint ExtentNum;
00339 
00343 typedef uint BlockNum;
00344 
00348 enum SeekPosition
00349 {
00350     SEEK_STREAM_BEGIN,
00351     SEEK_STREAM_END
00352 };
00353 
00354 FENNEL_END_NAMESPACE
00355 
00356 #endif
00357 
00358 // End Types.h

Generated on Mon Jun 22 04:00:18 2009 for Fennel by  doxygen 1.5.1