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   bool eq(XID *xid);
00060   bool eq(long g, long b, const char *d);
00061   void set(XID *xid);
00062   void set(long f, const char *g, long gl, const char *b, long bl);
00063   void set(uint64_t xid);
00064   void set(long g, long b, const char *d);
00065   bool is_null();
00066   void null();
00067   my_xid quick_get_my_xid();
00068   my_xid get_my_xid();
00069   uint32_t length() const;
00070   const unsigned char* key() const;
00071   uint32_t key_length() const;
00072 };
00073 
00082 class DrizzleXid
00083 {
00084 public:
00085   long formatID;
00086   long gtrid_length;
00087   long bqual_length;
00088   char data[DRIZZLE_XIDDATASIZE];  /* Not \0-terminated */
00089 
00090   DrizzleXid() :
00091     formatID(0),
00092     gtrid_length(0),
00093     bqual_length(0)
00094   {
00095     memset(data, 0, DRIZZLE_XIDDATASIZE);
00096   }
00097 };
00098 
00099 enum xa_states {XA_NOTR=0, XA_ACTIVE, XA_IDLE, XA_PREPARED};
00100 extern const char *xa_state_names[];
00101 
00102 /* for recover() plugin::StorageEngine call */
00103 #define MIN_XID_LIST_SIZE  128
00104 #define MAX_XID_LIST_SIZE  (1024*128)
00105 
00106 class XID_STATE
00107 {
00108 public:
00109   XID_STATE() :
00110     xa_state(XA_NOTR),
00111     in_session(false)
00112   {}
00113   /* For now, this is only used to catch duplicated external xids */
00114   XID  xid;                           // transaction identifier
00115   xa_states xa_state;            // used by external XA only
00116   bool in_session;
00117 };
00118 
00119 } /* namespace drizzled */
00120