Drizzled Public API Documentation

xid.h
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #pragma once
00021 
00022 #include <cstring>
00023 
00024 namespace drizzled {
00025 
00026 extern uint32_t server_id;
00027 
00036 typedef uint64_t my_xid;
00037 
00038 #define DRIZZLE_XIDDATASIZE 128
00039 #define DRIZZLE_XID_PREFIX "DrizzleXid"
00040 #define DRIZZLE_XID_PREFIX_LEN 8 // must be a multiple of 8
00041 #define DRIZZLE_XID_OFFSET (DRIZZLE_XID_PREFIX_LEN+sizeof(server_id))
00042 #define DRIZZLE_XID_GTRID_LEN (DRIZZLE_XID_OFFSET+sizeof(my_xid))
00043 
00044 class XID
00045 {
00046 public:
00047   long formatID;
00048   long gtrid_length;
00049   long bqual_length;
00050   char data[DRIZZLE_XIDDATASIZE];  // not \0-terminated !
00051 
00052   XID() :
00053     formatID(-1), /* -1 == null */
00054     gtrid_length(0),
00055     bqual_length(0)
00056   {
00057     memset(data, 0, DRIZZLE_XIDDATASIZE);
00058   }
00059   void set(uint64_t xid);
00060   void set(long g, long b, const char *d);
00061   bool is_null() const;
00062   void set_null();
00063   my_xid quick_get_my_xid();
00064   my_xid get_my_xid();
00065   uint32_t length() const;
00066 };
00067 
00076 class DrizzleXid
00077 {
00078 public:
00079   long formatID;
00080   long gtrid_length;
00081   long bqual_length;
00082   char data[DRIZZLE_XIDDATASIZE];  /* Not \0-terminated */
00083 
00084   DrizzleXid() :
00085     formatID(0),
00086     gtrid_length(0),
00087     bqual_length(0)
00088   {
00089     memset(data, 0, DRIZZLE_XIDDATASIZE);
00090   }
00091 };
00092 
00093 enum xa_states {XA_NOTR=0, XA_ACTIVE, XA_IDLE, XA_PREPARED};
00094 extern const char *xa_state_names[];
00095 
00096 /* for recover() plugin::StorageEngine call */
00097 #define MIN_XID_LIST_SIZE  128
00098 #define MAX_XID_LIST_SIZE  (1024*128)
00099 
00100 class XID_STATE
00101 {
00102 public:
00103   XID_STATE() :
00104     xa_state(XA_NOTR),
00105     in_session(false)
00106   {}
00107   /* For now, this is only used to catch duplicated external xids */
00108   XID  xid;                           // transaction identifier
00109   xa_states xa_state;            // used by external XA only
00110   bool in_session;
00111 };
00112 
00113 } /* namespace drizzled */
00114