~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.cc

  • Committer: Jay Pipes
  • Date: 2009-03-17 05:47:13 UTC
  • mto: This revision was merged to the branch mainline in revision 941.
  • Revision ID: jpipes@serialcoder-20090317054713-4t3t3e9lvzi2epq5
Pulls remainder of XID and xid_cache implementation into xid.cc and xid.h from drizzled/session.cc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2420
2420
    session->transaction_rollback_request= all;
2421
2421
  }
2422
2422
}
2423
 
/***************************************************************************
2424
 
  Handling of XA id cacheing
2425
 
***************************************************************************/
2426
 
 
2427
 
pthread_mutex_t LOCK_xid_cache;
2428
 
HASH xid_cache;
2429
 
 
2430
 
extern "C" unsigned char *xid_get_hash_key(const unsigned char *, size_t *, bool);
2431
 
extern "C" void xid_free_hash(void *);
2432
 
 
2433
 
unsigned char *xid_get_hash_key(const unsigned char *ptr, size_t *length,
2434
 
                        bool )
2435
 
{
2436
 
  *length=((XID_STATE*)ptr)->xid.key_length();
2437
 
  return ((XID_STATE*)ptr)->xid.key();
2438
 
}
2439
 
 
2440
 
void xid_free_hash(void *ptr)
2441
 
{
2442
 
  if (!((XID_STATE*)ptr)->in_session)
2443
 
    free((unsigned char*)ptr);
2444
 
}
2445
 
 
2446
 
bool xid_cache_init()
2447
 
{
2448
 
  pthread_mutex_init(&LOCK_xid_cache, MY_MUTEX_INIT_FAST);
2449
 
  return hash_init(&xid_cache, &my_charset_bin, 100, 0, 0,
2450
 
                   xid_get_hash_key, xid_free_hash, 0) != 0;
2451
 
}
2452
 
 
2453
 
void xid_cache_free()
2454
 
{
2455
 
  if (hash_inited(&xid_cache))
2456
 
  {
2457
 
    hash_free(&xid_cache);
2458
 
    pthread_mutex_destroy(&LOCK_xid_cache);
2459
 
  }
2460
 
}
2461
 
 
2462
 
XID_STATE *xid_cache_search(XID *xid)
2463
 
{
2464
 
  pthread_mutex_lock(&LOCK_xid_cache);
2465
 
  XID_STATE *res=(XID_STATE *)hash_search(&xid_cache, xid->key(), xid->key_length());
2466
 
  pthread_mutex_unlock(&LOCK_xid_cache);
2467
 
  return res;
2468
 
}
2469
 
 
2470
 
 
2471
 
bool xid_cache_insert(XID *xid, enum xa_states xa_state)
2472
 
{
2473
 
  XID_STATE *xs;
2474
 
  bool res;
2475
 
  pthread_mutex_lock(&LOCK_xid_cache);
2476
 
  if (hash_search(&xid_cache, xid->key(), xid->key_length()))
2477
 
    res=0;
2478
 
  else if (!(xs=(XID_STATE *)malloc(sizeof(*xs))))
2479
 
    res=1;
2480
 
  else
2481
 
  {
2482
 
    xs->xa_state=xa_state;
2483
 
    xs->xid.set(xid);
2484
 
    xs->in_session=0;
2485
 
    res=my_hash_insert(&xid_cache, (unsigned char*)xs);
2486
 
  }
2487
 
  pthread_mutex_unlock(&LOCK_xid_cache);
2488
 
  return res;
2489
 
}
2490
 
 
2491
 
bool xid_cache_insert(XID_STATE *xid_state)
2492
 
{
2493
 
  pthread_mutex_lock(&LOCK_xid_cache);
2494
 
  assert(hash_search(&xid_cache, xid_state->xid.key(),
2495
 
                          xid_state->xid.key_length())==0);
2496
 
  bool res=my_hash_insert(&xid_cache, (unsigned char*)xid_state);
2497
 
  pthread_mutex_unlock(&LOCK_xid_cache);
2498
 
  return res;
2499
 
}
2500
 
 
2501
 
void xid_cache_delete(XID_STATE *xid_state)
2502
 
{
2503
 
  pthread_mutex_lock(&LOCK_xid_cache);
2504
 
  hash_delete(&xid_cache, (unsigned char *)xid_state);
2505
 
  pthread_mutex_unlock(&LOCK_xid_cache);
2506
 
}
2507
2423
 
2508
2424
void Session::disconnect(uint32_t errcode, bool should_lock)
2509
2425
{