~drizzle-trunk/drizzle/development

520.4.31 by Monty Taylor
Removed server_id from common_includes.
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2008 Sun Microsystems
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; version 2 of the License.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
19
20
#ifndef DRIZZLED_XID_H
21
#define DRIZZLED_XID_H
22
1273.1.4 by Jay Pipes
This patch significantly reworks the way that
23
#include <cstring>
24
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
25
namespace drizzled
26
{
27
520.4.31 by Monty Taylor
Removed server_id from common_includes.
28
extern uint32_t server_id;
29
30
/**
31
  class XID _may_ be binary compatible with the XID structure as
32
  in the X/Open CAE Specification, Distributed Transaction Processing:
33
  The XA Specification, X/Open Company Ltd., 1991.
34
  http://www.opengroup.org/bookstore/catalog/c193.htm
35
36
*/
37
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
38
typedef uint64_t my_xid;
520.4.31 by Monty Taylor
Removed server_id from common_includes.
39
40
#define DRIZZLE_XIDDATASIZE 128
41
#define DRIZZLE_XID_PREFIX "MySQLXid"
42
#define DRIZZLE_XID_PREFIX_LEN 8 // must be a multiple of 8
43
#define DRIZZLE_XID_OFFSET (DRIZZLE_XID_PREFIX_LEN+sizeof(server_id))
44
#define DRIZZLE_XID_GTRID_LEN (DRIZZLE_XID_OFFSET+sizeof(my_xid))
45
46
class XID {
47
48
public:
49
50
  long formatID;
51
  long gtrid_length;
52
  long bqual_length;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
53
  char data[DRIZZLE_XIDDATASIZE];  // not \0-terminated !
520.4.31 by Monty Taylor
Removed server_id from common_includes.
54
1273.1.4 by Jay Pipes
This patch significantly reworks the way that
55
  XID() :
56
    formatID(-1), /* -1 == null */
57
    gtrid_length(0),
58
    bqual_length(0)
59
  {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
60
    memset(data, 0, DRIZZLE_XIDDATASIZE);
1273.1.4 by Jay Pipes
This patch significantly reworks the way that
61
  }
520.4.31 by Monty Taylor
Removed server_id from common_includes.
62
  bool eq(XID *xid);
63
  bool eq(long g, long b, const char *d);
64
  void set(XID *xid);
65
  void set(long f, const char *g, long gl, const char *b, long bl);
66
  void set(uint64_t xid);
67
  void set(long g, long b, const char *d);
68
  bool is_null();
69
  void null();
70
  my_xid quick_get_my_xid();
71
  my_xid get_my_xid();
72
  uint32_t length();
73
  unsigned char *key();
74
  uint32_t key_length();
75
};
76
77
/**
78
  struct st_drizzle_xid is binary compatible with the XID structure as
79
  in the X/Open CAE Specification, Distributed Transaction Processing:
80
  The XA Specification, X/Open Company Ltd., 1991.
81
  http://www.opengroup.org/bookstore/catalog/c193.htm
82
83
*/
1836.2.1 by tdavies
File: /drizzled/xid.h. Changed struct name of 'st_drizzle_xid' to 'drizzle_xid', changed it to a C++ class and added constructor initialization list
84
85
class drizzle_xid {
86
public:
520.4.31 by Monty Taylor
Removed server_id from common_includes.
87
  long formatID;
88
  long gtrid_length;
89
  long bqual_length;
90
  char data[DRIZZLE_XIDDATASIZE];  /* Not \0-terminated */
1836.2.1 by tdavies
File: /drizzled/xid.h. Changed struct name of 'st_drizzle_xid' to 'drizzle_xid', changed it to a C++ class and added constructor initialization list
91
92
  drizzle_xid() :
93
    formatID(0),
94
    gtrid_length(0),
95
    bqual_length(0)
96
  {
1836.2.2 by tdavies
File: /drizzled/xid.h. Changed struct name of 'st_drizzle_xid' to 'drizzle_xid', changed it to a C++ class and added constructor initialization list
97
    memset(data, 0, DRIZZLE_XIDDATASIZE);
1836.2.1 by tdavies
File: /drizzled/xid.h. Changed struct name of 'st_drizzle_xid' to 'drizzle_xid', changed it to a C++ class and added constructor initialization list
98
  }
520.4.31 by Monty Taylor
Removed server_id from common_includes.
99
};
1836.2.1 by tdavies
File: /drizzled/xid.h. Changed struct name of 'st_drizzle_xid' to 'drizzle_xid', changed it to a C++ class and added constructor initialization list
100
typedef class drizzle_xid DRIZZLE_XID;
520.4.31 by Monty Taylor
Removed server_id from common_includes.
101
934.2.15 by Jay Pipes
Pulls remainder of XID and xid_cache implementation into xid.cc and xid.h from drizzled/session.cc.
102
enum xa_states {XA_NOTR=0, XA_ACTIVE, XA_IDLE, XA_PREPARED};
103
extern const char *xa_state_names[];
520.4.31 by Monty Taylor
Removed server_id from common_includes.
104
1130.1.4 by Monty Taylor
Moved StorageEngine into plugin namespace.
105
/* for recover() plugin::StorageEngine call */
520.4.31 by Monty Taylor
Removed server_id from common_includes.
106
#define MIN_XID_LIST_SIZE  128
107
#define MAX_XID_LIST_SIZE  (1024*128)
108
1273.1.4 by Jay Pipes
This patch significantly reworks the way that
109
class XID_STATE 
110
{
111
public:
112
  XID_STATE() :
113
    xid(),
114
    xa_state(XA_NOTR),
115
    in_session(false)
116
  {}
934.2.15 by Jay Pipes
Pulls remainder of XID and xid_cache implementation into xid.cc and xid.h from drizzled/session.cc.
117
  /* For now, this is only used to catch duplicated external xids */
118
  XID  xid;                           // transaction identifier
119
  enum xa_states xa_state;            // used by external XA only
120
  bool in_session;
1273.1.4 by Jay Pipes
This patch significantly reworks the way that
121
};
934.2.15 by Jay Pipes
Pulls remainder of XID and xid_cache implementation into xid.cc and xid.h from drizzled/session.cc.
122
123
bool xid_cache_init(void);
124
void xid_cache_free(void);
125
XID_STATE *xid_cache_search(XID *xid);
126
bool xid_cache_insert(XID *xid, enum xa_states xa_state);
127
bool xid_cache_insert(XID_STATE *xid_state);
128
void xid_cache_delete(XID_STATE *xid_state);
129
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
130
} /* namespace drizzled */
131
520.4.31 by Monty Taylor
Removed server_id from common_includes.
132
#endif /* DRIZZLED_XID_H */