1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
4
* Copyright (C) 2008 Sun Microsystems
6
6
* This program is free software; you can redistribute it and/or modify
7
7
* it under the terms of the GNU General Public License as published by
17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
#include <drizzled/my_hash.h>
23
24
#include <drizzled/xid.h>
24
#include <drizzled/charset.h>
25
#include "drizzled/charset.h"
26
#include "drizzled/global_charset_info.h"
27
#include "drizzled/charset_info.h"
29
#include <boost/thread/mutex.hpp>
34
bool XID::eq(XID *xid)
36
return eq(xid->gtrid_length, xid->bqual_length, xid->data);
39
bool XID::eq(long g, long b, const char *d)
41
return g == gtrid_length && b == bqual_length && !memcmp(d, data, g+b);
44
void XID::set(XID *xid)
46
memcpy(this, xid, xid->length());
49
void XID::set(long f, const char *g, long gl, const char *b, long bl)
52
memcpy(data, g, gtrid_length= gl);
53
memcpy(data+gl, b, bqual_length= bl);
28
56
void XID::set(uint64_t xid)
31
60
set(DRIZZLE_XID_PREFIX_LEN, 0, DRIZZLE_XID_PREFIX);
32
memcpy(data + DRIZZLE_XID_PREFIX_LEN, &server_id, sizeof(server_id));
34
memcpy(data + DRIZZLE_XID_OFFSET, &tmp, sizeof(tmp));
35
gtrid_length= DRIZZLE_XID_GTRID_LEN;
61
memcpy(data+DRIZZLE_XID_PREFIX_LEN, &server_id, sizeof(server_id));
63
memcpy(data+DRIZZLE_XID_OFFSET, &tmp, sizeof(tmp));
64
gtrid_length=DRIZZLE_XID_GTRID_LEN;
38
67
void XID::set(long g, long b, const char *d)
68
97
quick_get_my_xid() : 0;
71
uint32_t XID::length() const
100
uint32_t XID::length()
73
102
return sizeof(formatID)+sizeof(gtrid_length)+sizeof(bqual_length)+
74
103
gtrid_length+bqual_length;
106
unsigned char *XID::key()
108
return (unsigned char *)>rid_length;
111
uint32_t XID::key_length()
113
return sizeof(gtrid_length)+sizeof(bqual_length)+gtrid_length+bqual_length;
116
/***************************************************************************
117
Handling of XA id cacheing
118
***************************************************************************/
119
boost::mutex LOCK_xid_cache;
122
unsigned char *xid_get_hash_key(const unsigned char *, size_t *, bool);
123
void xid_free_hash(void *);
125
unsigned char *xid_get_hash_key(const unsigned char *ptr, size_t *length,
128
*length=((XID_STATE*)ptr)->xid.key_length();
129
return ((XID_STATE*)ptr)->xid.key();
132
void xid_free_hash(void *ptr)
134
XID_STATE *state= (XID_STATE *)ptr;
135
if (state->in_session == false)
139
bool xid_cache_init()
141
return hash_init(&xid_cache, &my_charset_bin, 100, 0, 0,
142
xid_get_hash_key, xid_free_hash, 0) != 0;
145
void xid_cache_free()
147
if (hash_inited(&xid_cache))
149
hash_free(&xid_cache);
153
XID_STATE *xid_cache_search(XID *xid)
155
LOCK_xid_cache.lock();
156
XID_STATE *res=(XID_STATE *)hash_search(&xid_cache, xid->key(), xid->key_length());
157
LOCK_xid_cache.unlock();
161
bool xid_cache_insert(XID *xid, enum xa_states xa_state)
165
LOCK_xid_cache.lock();
166
if (hash_search(&xid_cache, xid->key(), xid->key_length()))
170
else if ((xs = new XID_STATE) == NULL)
176
xs->xa_state=xa_state;
179
res= my_hash_insert(&xid_cache, (unsigned char*)xs);
181
LOCK_xid_cache.unlock();
185
bool xid_cache_insert(XID_STATE *xid_state)
187
LOCK_xid_cache.lock();
188
bool res=my_hash_insert(&xid_cache, (unsigned char*)xid_state);
189
LOCK_xid_cache.unlock();
193
void xid_cache_delete(XID_STATE *xid_state)
195
LOCK_xid_cache.lock();
196
hash_delete(&xid_cache, (unsigned char *)xid_state);
197
LOCK_xid_cache.unlock();
77
200
} /* namespace drizzled */