Commit 9c96fde1 authored by Sergei Golubchik's avatar Sergei Golubchik

post-review fixes

include/atomic/generic-msvc.h:
  prevent possible compiler warnings
include/lf.h:
  comments, better definition for LF_HASH_OVERHEAD
include/maria.h:
  define MARIA_CANNOT_ROLLBACK here
include/my_pthread.h:
  avoid possible name clash
include/waiting_threads.h:
  comments, const, move WT_RESOURCE to waiting_threads.c
mysql-test/suite/maria/r/maria_notembedded.result:
  new test
mysql-test/suite/maria/t/maria_notembedded.test:
  new test - 5-way deadlock
mysys/lf_hash.c:
  better definition for LF_HASH_OVERHEAD
mysys/my_static.c:
  comment
mysys/my_thr_init.c:
  casts
mysys/waiting_threads.c:
  comments, asserts, etc
server-tools/instance-manager/parse.cc:
  fix my_init_dynamic_array() to follow new calling conventions
sql/mysqld.cc:
  call wt_init after set_proper_floating_point_mode
sql/sql_class.h:
  comment
storage/maria/ha_maria.cc:
  move MARIA_CANNOT_ROLLBACK to a common header
storage/maria/ma_commit.c:
  comment
storage/maria/ma_write.c:
  comments, check for HA_ERR_FOUND_DUPP_KEY
storage/maria/trnman.c:
  comments, assert
storage/maria/trnman.h:
  comments
storage/maria/unittest/trnman-t.c:
  be paranoid
unittest/mysys/lf-t.c:
  comments
unittest/mysys/waiting_threads-t.c:
  comments, safety, memory leak
parent e01f6c89
/* Copyright (C) 2006 MySQL AB
/* Copyright (C) 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -55,7 +55,7 @@ LONG _InterlockedExchangeAdd (LONG volatile *Addend, LONG Value);
#define IL_EXCHG_ADD32(X,Y) InterlockedExchangeAdd((volatile LONG *)(X),(Y))
#define IL_COMP_EXCHG32(X,Y,Z) InterlockedCompareExchange((volatile LONG *)(X),(Y),(Z))
#define IL_COMP_EXCHGptr InterlockedCompareExchangePointer
#define IL_EXCHG32 InterlockedExchange
#define IL_EXCHG32(X,Y) InterlockedExchange((volatile LONG *)(X),(Y))
#define IL_EXCHGptr InterlockedExchangePointer
#define make_atomic_add_body(S) \
v= IL_EXCHG_ADD ## S (a, v)
......
/* Copyright (C) 2007 MySQL AB
/* Copyright (C) 2007-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -187,8 +187,8 @@ typedef struct st_lf_allocator {
uchar * volatile top;
uint element_size;
uint32 volatile mallocs;
void (*constructor)(uchar *);
void (*destructor)(uchar *);
void (*constructor)(uchar *); /* called, when an object is malloc()'ed */
void (*destructor)(uchar *); /* called, when an object is free()'d */
} LF_ALLOCATOR;
void lf_alloc_init(LF_ALLOCATOR *allocator, uint size, uint free_ptr_offset);
......@@ -219,7 +219,7 @@ lock_wrap(lf_alloc_new, void *,
#define LF_HASH_UNIQUE 1
/* lf_hash overhead per element (that is, sizeof(LF_SLIST) */
#define LF_HASH_OVERHEAD (sizeof(int*)*4)
extern const int LF_HASH_OVERHEAD;
typedef struct {
LF_DYNARRAY array; /* hash itself */
......
/* Copyright (C) 2006 MySQL AB
/* Copyright (C) 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -33,6 +33,8 @@ extern "C" {
#include <myisamchk.h>
#include <mysql/plugin.h>
#define MARIA_CANNOT_ROLLBACK
/*
Limit max keys according to HA_MAX_POSSIBLE_KEY; See myisamchk.h for details
*/
......
/* Copyright (C) 2000 MySQL AB
/* Copyright (C) 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -430,19 +430,19 @@ int my_pthread_mutex_trylock(pthread_mutex_t *mutex);
/* adapt for two different flavors of struct timespec */
#ifdef HAVE_TIMESPEC_TS_SEC
#define TV_sec ts_sec
#define TV_nsec ts_nsec
#define MY_tv_sec ts_sec
#define MY_tv_nsec ts_nsec
#else
#define TV_sec tv_sec
#define TV_nsec tv_nsec
#define MY_tv_sec tv_sec
#define MY_tv_nsec tv_nsec
#endif /* HAVE_TIMESPEC_TS_SEC */
#ifndef set_timespec_time_nsec
#define set_timespec_time_nsec(ABSTIME,TIME,NSEC) do { \
ulonglong nsec= (NSEC); \
ulonglong now= (TIME) + (nsec/100); \
(ABSTIME).TV_sec= (now / ULL(10000000)); \
(ABSTIME).TV_nsec= (now % ULL(10000000) * 100 + (nsec % 100)); \
(ABSTIME).MY_tv_sec= (now / ULL(10000000)); \
(ABSTIME).MY_tv_nsec= (now % ULL(10000000) * 100 + (nsec % 100)); \
} while(0)
#endif /* !set_timespec_time_nsec */
......
/* Copyright (C) 2008 MySQL AB
/* Copyright (C) 2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -24,16 +24,18 @@
C_MODE_START
typedef struct st_wt_resource_id WT_RESOURCE_ID;
typedef struct st_wt_resource WT_RESOURCE;
typedef struct st_wt_resource_type {
int (*compare)(void *a, void *b);
const void *(*make_key)(WT_RESOURCE_ID *id, uint *len);
my_bool (*compare)(const void *a, const void *b);
const void *(*make_key)(const WT_RESOURCE_ID *id, uint *len); /* not used */
} WT_RESOURCE_TYPE;
struct st_wt_resource_id {
ulonglong value;
WT_RESOURCE_TYPE *type;
const WT_RESOURCE_TYPE *type;
};
/* the below differs from sizeof(WT_RESOURCE_ID) by the amount of padding */
#define sizeof_WT_RESOURCE_ID (sizeof(ulonglong)+sizeof(void*))
#define WT_WAIT_STATS 24
......@@ -43,93 +45,17 @@ extern uint32 wt_wait_stats[WT_WAIT_STATS+1];
extern uint32 wt_cycle_stats[2][WT_CYCLE_STATS+1];
extern uint32 wt_success_stats;
/*
'lock' protects 'owners', 'state', and 'waiter_count'
'id' is read-only
a resource is picked up from a hash in a lock-free manner
it's returned pinned, so it cannot be freed at once
but it may be freed right after the pin is removed
to free a resource it should be
1. have no owners
2. have no waiters
two ways to access a resource:
1. find it in a hash
- it's returned pinned.
a) take a lock in exclusive mode
b) check the state, it should be ACTIVE
c) unpin
2. by a direct reference
- could only used if a resource cannot be freed
e.g. accessing a resource by thd->waiting_for is safe,
a resource cannot be freed as there's a thread waiting for it
*/
typedef struct st_wt_resource {
WT_RESOURCE_ID id;
uint waiter_count;
enum { ACTIVE, FREE } state;
#ifndef DBUG_OFF
pthread_mutex_t *mutex;
#endif
/*
before the 'lock' all elements are mutable, after (and including) -
immutable in the sense that lf_hash_insert() won't memcpy() over them.
See wt_init().
*/
#ifdef WT_RWLOCKS_USE_MUTEXES
/*
we need a special rwlock-like 'lock' to allow readers bypass
waiting writers, otherwise readers can deadlock. For example:
A waits on resource x, owned by B, B waits on resource y, owned
by A, we have a cycle (A->x->B->y->A)
Both A and B start deadlock detection:
A locks x B locks y
A goes deeper B goes deeper
A locks y B locks x
with mutexes it would deadlock. With rwlocks it won't, as long
as both A and B are taking read locks (and they do).
But other threads may take write locks. Assume there's
C who wants to start waiting on x, and D who wants to start
waiting on y.
A read-locks x B read-locks y
A goes deeper B goes deeper
=> C write-locks x (to add a new edge) D write-locks y
.. C is blocked D is blocked
A read-locks y B read-locks x
Now, if a read lock can bypass a pending wrote lock request, we're fine.
If it can not, we have a deadlock.
writer starvation is technically possible, but unlikely, because
the contention is expected to be low.
*/
struct {
pthread_cond_t cond;
pthread_mutex_t mutex;
uint readers: 16;
uint pending_writers: 15;
uint write_locked: 1;
} lock;
#else
rw_lock_t lock;
#endif
pthread_cond_t cond;
DYNAMIC_ARRAY owners;
} WT_RESOURCE;
typedef struct st_wt_thd {
/*
XXX
there's no protection (mutex) against concurrent access of
the dynarray below. it is assumed that a caller will have it
automatically (not to protect this array but to protect its
own - caller's - data structures, and we'll get it for free.
If not, we'll need to add a mutex
there's no protection (mutex) against concurrent access of the
dynarray below. it is assumed that a caller will have it anyway
(not to protect this array but to protect its own - caller's -
data structures), and we'll get it for free. A caller needs to
ensure that a blocker won't release a resource before a blocked
thread starts waiting, which is usually done with a mutex.
If the above assumption is wrong, we'll need to add a mutex here.
*/
DYNAMIC_ARRAY my_resources;
/*
......@@ -141,8 +67,10 @@ typedef struct st_wt_thd {
LF_PINS *pins;
/* pointers to values */
ulong *timeout_short, *deadlock_search_depth_short;
ulong *timeout_long, *deadlock_search_depth_long;
const ulong *timeout_short;
const ulong *deadlock_search_depth_short;
const ulong *timeout_long;
const ulong *deadlock_search_depth_long;
/*
weight relates to the desirability of a transaction being killed if it's
......@@ -169,13 +97,13 @@ typedef struct st_wt_thd {
*/
ulong volatile weight;
/*
'killed' is indirectly protected by waiting_for->lock -
a killed thread needs to clear its 'waiting_for', and thus needs a lock.
'killed' is indirectly protected by waiting_for->lock because
a killed thread needs to clear its 'waiting_for' and thus needs a lock.
That is a thread needs an exclusive lock to read 'killed' reliably.
But other threads may change 'killed' from 0 to 1, a shared
lock is enough for that.
*/
my_bool volatile killed;
my_bool killed;
#ifndef DBUG_OFF
const char *name;
#endif
......@@ -189,13 +117,13 @@ typedef struct st_wt_thd {
void wt_init(void);
void wt_end(void);
void wt_thd_lazy_init(WT_THD *, ulong *, ulong *, ulong *, ulong *);
void wt_thd_lazy_init(WT_THD *, const ulong *, const ulong *, const ulong *, const ulong *);
void wt_thd_destroy(WT_THD *);
int wt_thd_will_wait_for(WT_THD *, WT_THD *, WT_RESOURCE_ID *);
int wt_thd_will_wait_for(WT_THD *, WT_THD *, const WT_RESOURCE_ID *);
int wt_thd_cond_timedwait(WT_THD *, pthread_mutex_t *);
void wt_thd_release(WT_THD *, WT_RESOURCE_ID *);
void wt_thd_release(WT_THD *, const WT_RESOURCE_ID *);
#define wt_thd_release_all(THD) wt_thd_release((THD), 0)
int wt_resource_id_memcmp(void *, void *);
int wt_resource_id_memcmp(const void *, const void *);
C_MODE_END
......
......@@ -30,9 +30,24 @@ insert t1 values (2);
lock table t1 write concurrent;
insert t1 values (3);
insert t1 values (2);
lock table t1 write concurrent;
insert t1 values (4);
insert t1 values (3);
lock table t1 write concurrent;
insert t1 values (5);
insert t1 values (4);
lock table t1 write concurrent;
insert t1 values (6);
insert t1 values (5);
insert t1 values (6);
ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
unlock tables;
ERROR 23000: Duplicate entry '2' for key 'a'
unlock tables;
ERROR 23000: Duplicate entry '3' for key 'a'
unlock tables;
ERROR 23000: Duplicate entry '4' for key 'a'
unlock tables;
ERROR 23000: Duplicate entry '5' for key 'a'
unlock tables;
drop table t1;
......@@ -33,27 +33,64 @@ drop table t1;
#
create table t1 (a int unique) transactional=1;
insert t1 values (1);
lock table t1 write concurrent;
insert t1 values (2);
connect(con_d,localhost,root,,);
connect(con_a,localhost,root,,);
lock table t1 write concurrent;
insert t1 values (3);
send insert t1 values (2);
connect(con_b,localhost,root,,);
lock table t1 write concurrent;
insert t1 values (4);
send insert t1 values (3);
connect(con_c,localhost,root,,);
lock table t1 write concurrent;
insert t1 values (5);
send insert t1 values (4);
connect(con_d,localhost,root,,);
lock table t1 write concurrent;
insert t1 values (6);
send insert t1 values (5);
connection default;
let $wait_condition=select count(*) = 1 from information_schema.processlist where state="waiting for a resource";
let $wait_condition=select count(*) = 4 from information_schema.processlist where state="waiting for a resource";
--source include/wait_condition.inc
--error ER_LOCK_DEADLOCK
insert t1 values (3);
insert t1 values (6);
unlock tables;
connection con_a;
--error ER_DUP_ENTRY
reap;
unlock tables;
disconnect con_a;
connection con_b;
--error ER_DUP_ENTRY
reap;
unlock tables;
disconnect con_b;
connection con_c;
--error ER_DUP_ENTRY
reap;
unlock tables;
disconnect con_c;
connection con_d;
--error ER_DUP_ENTRY
reap;
unlock tables;
disconnect con_d;
connection default;
drop table t1;
--disable_result_log
--disable_query_log
eval set session storage_engine=$default_engine;
......
/* QQ: TODO multi-pinbox */
/* Copyright (C) 2006 MySQL AB
/* Copyright (C) 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -330,7 +330,7 @@ static void _lf_pinbox_real_free(LF_PINS *pins)
{
int npins, alloca_size;
void *list, **addr;
uchar *first, *last= NULL;
void *first, *last= NULL;
LF_PINBOX *pinbox= pins->pinbox;
LINT_INIT(first);
......
/* Copyright (C) 2006 MySQL AB
/* Copyright (C) 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -42,6 +42,8 @@ typedef struct {
*/
} LF_SLIST;
const int LF_HASH_OVERHEAD= sizeof(LF_SLIST);
/*
a structure to pass the context (pointers two the three successive elements
in a list) from lfind to linsert/ldelete
......@@ -315,7 +317,6 @@ void lf_hash_init(LF_HASH *hash, uint element_size, uint flags,
uint key_offset, uint key_length, hash_get_key get_key,
CHARSET_INFO *charset)
{
compile_time_assert(sizeof(LF_SLIST) == LF_HASH_OVERHEAD);
lf_alloc_init(&hash->alloc, sizeof(LF_SLIST)+element_size,
offsetof(LF_SLIST, key));
lf_dynarray_init(&hash->array, sizeof(LF_SLIST *));
......
/* Copyright (C) 2000 MySQL AB
/* Copyright (C) 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -101,6 +101,7 @@ static const char *proc_info_dummy(void *a __attribute__((unused)),
return 0;
}
/* this is to be able to call set_thd_proc_info from the C code */
const char *(*proc_info_hook)(void *, const char *, const char *, const char *,
const unsigned int)= proc_info_dummy;
......
/* Copyright (C) 2000 MySQL AB
/* Copyright (C) 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -332,7 +332,8 @@ my_bool my_thread_init(void)
0);
pthread_cond_init(&tmp->suspend, NULL);
tmp->stack_ends_here= &tmp + STACK_DIRECTION * my_thread_stack_size;
tmp->stack_ends_here= (char*)&tmp +
STACK_DIRECTION * (long)my_thread_stack_size;
pthread_mutex_lock(&THR_LOCK_threads);
tmp->id= ++thread_id;
......
This diff is collapsed.
......@@ -78,7 +78,7 @@ Named_value_arr::Named_value_arr() :
bool Named_value_arr::init()
{
if (my_init_dynamic_array(&arr, sizeof(Named_value), 0, 32))
if (my_init_dynamic_array(&arr, sizeof(Named_value), 32, 32))
return TRUE;
initialized= TRUE;
......
/* Copyright (C) 2000-2003 MySQL AB
/* Copyright (C) 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -3718,8 +3718,6 @@ static int init_server_components()
if (table_cache_init() | table_def_init() | hostname_cache_init())
unireg_abort(1);
wt_init();
query_cache_result_size_limit(query_cache_limit);
query_cache_set_min_res_unit(query_cache_min_res_unit);
query_cache_init();
......@@ -3731,6 +3729,7 @@ static int init_server_components()
#ifdef HAVE_REPLICATION
init_slave_list();
#endif
wt_init();
/* Setup logs */
......@@ -7471,7 +7470,7 @@ static void usage(void)
default_collation_name= (char*) default_charset_info->name;
print_version();
puts("\
Copyright (C) 2000 MySQL AB, by Monty and others\n\
Copyright (C) 2000-2008 MySQL AB, Monty and others, 2008-2009 Sun Microsystems, Inc.\n\
This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n\
and you are welcome to modify and redistribute it under the GPL license\n\n\
Starts the MySQL database server\n");
......
/* Copyright (C) 2000-2006 MySQL AB
/* Copyright (C) 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -1123,6 +1123,8 @@ bool THD::store_globals()
*/
mysys_var->id= thread_id;
real_id= pthread_self(); // For debugging
mysys_var->stack_ends_here= thread_stack + // for consistency, see libevent_thread_proc
STACK_DIRECTION * (long)my_thread_stack_size;
/*
We have to call thr_lock_info_init() again here as THD may have been
......
/* Copyright (C) 2000-2006 MySQL AB
/* Copyright (C) 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -1417,7 +1417,7 @@ class THD :public Statement,
THD_TRANS stmt; // Trans for current statement
bool on; // see ha_enable_transaction()
XID_STATE xid_state;
WT_THD wt;
WT_THD wt; ///< for deadlock detection
Rows_log_event *m_pending_rows_event;
/*
......
/* Copyright (C) 2006,2004 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
/* Copyright (C) 2004-2008 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
Copyright (C) 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -40,9 +41,11 @@ C_MODE_END
Note that in future versions, only *transactional* Maria tables can
rollback, so this flag should be up or down conditionally.
*/
#define MARIA_CANNOT_ROLLBACK HA_NO_TRANSACTIONS
#ifdef MARIA_CANNOT_ROLLBACK
#define CANNOT_ROLLBACK_FLAG HA_NO_TRANSACTIONS
#define trans_register_ha(A, B, C) do { /* nothing */ } while(0)
#else
#define CANNOT_ROLLBACK_FLAG 0
#endif
#define THD_TRN (*(TRN **)thd_ha_data(thd, maria_hton))
......@@ -716,7 +719,7 @@ handler(hton, table_arg), file(0),
int_table_flags(HA_NULL_IN_KEY | HA_CAN_FULLTEXT | HA_CAN_SQL_HANDLER |
HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE |
HA_DUPLICATE_POS | HA_CAN_INDEX_BLOBS | HA_AUTO_PART_KEY |
HA_FILE_BASED | HA_CAN_GEOMETRY | MARIA_CANNOT_ROLLBACK |
HA_FILE_BASED | HA_CAN_GEOMETRY | CANNOT_ROLLBACK_FLAG |
HA_CAN_BIT_FIELD | HA_CAN_RTREEKEYS |
HA_HAS_RECORDS | HA_STATS_RECORDS_IS_EXACT),
can_enable_indexes(1), bulk_insert_single_undo(BULK_INSERT_NONE)
......
/* Copyright (C) 2007 MySQL AB
/* Copyright (C) 2007-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -17,7 +17,7 @@
#include "trnman.h"
/**
@brief writes a COMMIT record to log and commits transaction in memory
writes a COMMIT record to log and commits transaction in memory
@param trn transaction
......@@ -82,7 +82,7 @@ int ma_commit(TRN *trn)
/**
@brief Writes a COMMIT record for a transaciton associated with a file
Writes a COMMIT record for a transaciton associated with a file
@param info Maria handler
......@@ -98,13 +98,17 @@ int maria_commit(MARIA_HA *info)
/**
@brief Starts a transaction on a file handle
Starts a transaction on a file handle
@param info Maria handler
@return Operation status
@retval 0 ok
@retval # Error code.
@note this can be used only in single-threaded programs (tests),
because we create a transaction (trnman_new_trn) with WT_THD=0.
XXX it needs to be fixed when we'll start using maria_begin from SQL.
*/
int maria_begin(MARIA_HA *info)
......
/* Copyright (C) 2006 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
/* Copyright (C) 2004-2008 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
Copyright (C) 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -39,8 +40,8 @@ static uchar *_ma_find_last_pos(MARIA_HA *info, MARIA_KEY *int_key,
uchar *page, uchar **after_key);
static my_bool _ma_ck_write_tree(register MARIA_HA *info, MARIA_KEY *key);
static my_bool _ma_ck_write_btree(register MARIA_HA *info, MARIA_KEY *key);
static int _ma_ck_write_btree_with_log(MARIA_HA *info, MARIA_KEY *key,
my_off_t *root, uint32 comp_flag);
static int _ma_ck_write_btree_with_log(MARIA_HA *, MARIA_KEY *, my_off_t *,
uint32);
static my_bool _ma_log_split(MARIA_HA *info, my_off_t page, const uchar *buff,
uint org_length, uint new_length,
const uchar *key_pos,
......@@ -181,9 +182,8 @@ int maria_write(MARIA_HA *info, uchar *record)
else
{
while (keyinfo->ck_insert(info,
(*keyinfo->make_key)(info, &int_key, i,
buff, record, filepos,
info->trn->trid)))
(*keyinfo->make_key)(info, &int_key, i, buff, record,
filepos, info->trn->trid)))
{
TRN *blocker;
DBUG_PRINT("error",("Got error: %d on write",my_errno));
......@@ -193,10 +193,12 @@ int maria_write(MARIA_HA *info, uchar *record)
below doesn't work for them.
Also, filter out non-thread maria use, and table modified in
the same transaction.
At last, filter out non-dup-unique errors.
*/
if (!local_lock_tree)
goto err;
if (info->dup_key_trid == info->trn->trid)
if (info->dup_key_trid == info->trn->trid ||
my_errno != HA_ERR_FOUND_DUPP_KEY)
{
rw_unlock(&keyinfo->root_lock);
goto err;
......@@ -257,6 +259,9 @@ int maria_write(MARIA_HA *info, uchar *record)
}
}
rw_wrlock(&keyinfo->root_lock);
#ifndef MARIA_CANNOT_ROLLBACK
keyinfo->version++;
#endif
}
}
......@@ -671,12 +676,14 @@ static int w_search(register MARIA_HA *info, uint32 comp_flag, MARIA_KEY *key,
When the index will support true versioning - with multiple
identical values in the UNIQUE index, invisible to each other -
the following should be changed to "continue inserting keys, at the
end (of the row or statement) wait". Until it's done we cannot properly
support deadlock timeouts.
end (of the row or statement) wait". We need to wait on *all*
unique conflicts at once, not one-at-a-time, because we need to
know all blockers in advance, otherwise we'll have incomplete wait-for
graph.
*/
/*
transaction that has inserted the conflicting key is in progress.
wait for it to be committed or aborted.
transaction that has inserted the conflicting key may be in progress.
the caller will wait for it to be committed or aborted.
*/
info->dup_key_trid= _ma_trid_from_key(&tmp_key);
info->dup_key_pos= dup_key_pos;
......
/* Copyright (C) 2006 MySQL AB
/* Copyright (C) 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -42,7 +42,7 @@ static TrID global_trid_generator;
The default value is used when transaction manager not initialize;
Probably called from maria_chk
*/
static TrID trid_min_read_from= ~(TrID) 0;
static TrID trid_min_read_from= MAX_TRID;
/* the mutex for everything above */
static pthread_mutex_t LOCK_trn_list;
......@@ -59,6 +59,7 @@ static TRN **short_trid_to_active_trn;
/* locks for short_trid_to_active_trn and pool */
static my_atomic_rwlock_t LOCK_short_trid_to_trn, LOCK_pool;
static my_bool default_trnman_end_trans_hook(TRN *, my_bool, my_bool);
static void trnman_free_trn(TRN *);
my_bool (*trnman_end_trans_hook)(TRN *, my_bool, my_bool)=
default_trnman_end_trans_hook;
......@@ -88,6 +89,7 @@ void trnman_reset_locked_tables(TRN *trn, uint locked_tables)
trn->locked_tables= locked_tables;
}
/** Wake up threads waiting for this transaction */
static void wt_thd_release_self(TRN *trn)
{
if (trn->wt)
......@@ -149,12 +151,12 @@ int trnman_init(TrID initial_trid)
*/
active_list_max.trid= active_list_min.trid= 0;
active_list_max.min_read_from= ~(TrID) 0;
active_list_max.min_read_from= MAX_TRID;
active_list_max.next= active_list_min.prev= 0;
active_list_max.prev= &active_list_min;
active_list_min.next= &active_list_max;
committed_list_max.commit_trid= ~(TrID) 0;
committed_list_max.commit_trid= MAX_TRID;
committed_list_max.next= committed_list_min.prev= 0;
committed_list_max.prev= &committed_list_min;
committed_list_min.next= &committed_list_max;
......@@ -198,6 +200,7 @@ void trnman_destroy()
{
TRN *trn= pool;
pool= pool->next;
DBUG_ASSERT(trn->wt == NULL);
pthread_mutex_destroy(&trn->state_lock);
my_free((void *)trn, MYF(0));
}
......@@ -251,10 +254,12 @@ static uint get_short_trid(TRN *trn)
return res;
}
/*
DESCRIPTION
start a new transaction, allocate and initialize transaction object
mutex and cond will be used for lock waits
/**
Allocates and initialzies a new TRN object
@note the 'wt' parameter can only be 0 in a single-threaded code (or,
generally, where threads cannot block each other), otherwise the
first call to the deadlock detector will sigsegv.
*/
TRN *trnman_new_trn(WT_THD *wt)
......@@ -338,7 +343,8 @@ TRN *trnman_new_trn(WT_THD *wt)
trn->min_read_from= trn->trid + 1;
}
trn->commit_trid= ~(TrID)0;
/* no other transaction can read changes done by this one */
trn->commit_trid= MAX_TRID;
trn->rec_lsn= trn->undo_lsn= trn->first_undo_lsn= 0;
trn->used_tables= 0;
......@@ -394,6 +400,7 @@ my_bool trnman_end_trn(TRN *trn, my_bool commit)
/* if a rollback, all UNDO records should have been executed */
DBUG_ASSERT(commit || trn->undo_lsn == 0);
DBUG_ASSERT(trn != &dummy_transaction_object);
DBUG_PRINT("info", ("pthread_mutex_lock LOCK_trn_list"));
pthread_mutex_lock(&LOCK_trn_list);
......@@ -429,6 +436,7 @@ my_bool trnman_end_trn(TRN *trn, my_bool commit)
}
pthread_mutex_lock(&trn->state_lock);
if (commit)
trn->commit_trid= global_trid_generator;
wt_thd_release_self(trn);
pthread_mutex_unlock(&trn->state_lock);
......@@ -502,7 +510,7 @@ my_bool trnman_end_trn(TRN *trn, my_bool commit)
running. It may even be called automatically on checkpoints if no
transactions are running.
*/
void trnman_free_trn(TRN *trn)
static void trnman_free_trn(TRN *trn)
{
/*
union is to solve strict aliasing issue.
......@@ -580,6 +588,16 @@ int trnman_can_read_from(TRN *trn, TrID trid)
return can;
}
/**
Finds a TRN by its TrID
@param trn current trn. Needed for pinning pointers (see lf_pin)
@param trid trid to search for
@return found trn or 0
@note that trn is returned with its state locked!
*/
TRN *trnman_trid_to_trn(TRN *trn, TrID trid)
{
TRN **found;
......@@ -604,7 +622,7 @@ TRN *trnman_trid_to_trn(TRN *trn, TrID trid)
lf_hash_search_unpin(trn->pins);
/* Gotcha! */
return *found; /* note that TRN is returned locked !!! */
return *found;
}
/* TODO: the stubs below are waiting for savepoints to be implemented */
......
/* Copyright (C) 2006 MySQL AB
/* Copyright (C) 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -22,7 +22,7 @@ C_MODE_START
#include "trnman_public.h"
#include "ma_loghandler_lsn.h"
/*
/**
trid - 6 uchar transaction identifier. Assigned when a transaction
is created. Transaction can always be identified by its trid,
even after transaction has ended.
......@@ -33,7 +33,7 @@ C_MODE_START
when short_id is 0, TRN is not initialized, for all practical purposes
it could be considered unused.
when commit_trid is ~(TrID)0 the transaction is running, otherwise it's
when commit_trid is MAX_TRID the transaction is running, otherwise it's
committed.
state_lock mutex protects the state of a TRN, that is whether a TRN
......@@ -46,7 +46,7 @@ struct st_ma_transaction
LF_PINS *pins;
WT_THD *wt;
pthread_mutex_t state_lock;
void *used_tables; /* Tables used by transaction */
void *used_tables; /**< Tables used by transaction */
TRN *next, *prev;
TrID trid, min_read_from, commit_trid;
LSN rec_lsn, undo_lsn;
......@@ -56,6 +56,7 @@ struct st_ma_transaction
};
#define TRANSACTION_LOGGED_LONG_ID ULL(0x8000000000000000)
#define MAX_TRID (~(TrID)0)
extern WT_RESOURCE_TYPE ma_rc_dup_unique;
......
/* Copyright (C) 2006 MySQL AB
/* Copyright (C) 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -44,7 +44,6 @@ my_bool trnman_end_trn(TRN *trn, my_bool commit);
#define trnman_commit_trn(T) trnman_end_trn(T, TRUE)
#define trnman_abort_trn(T) trnman_end_trn(T, FALSE)
#define trnman_rollback_trn(T) trnman_end_trn(T, FALSE)
void trnman_free_trn(TRN *trn);
int trnman_can_read_from(TRN *trn, TrID trid);
TRN *trnman_trid_to_trn(TRN *trn, TrID trid);
void trnman_new_statement(TRN *trn);
......
/* Copyright (C) 2006 MySQL AB
/* Copyright (C) 2006-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -40,7 +40,8 @@ pthread_handler_t test_trnman(void *arg)
TRN *trn[MAX_ITER];
int m= (*(int *)arg);
my_thread_init();
if (my_thread_init())
BAIL_OUT("my_thread_init failed!");
for (x= ((int)(intptr)(&m)); m > 0; )
{
......
/* Copyright (C) 2006 MySQL AB
/* Copyright (C) 2008-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -13,6 +13,12 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/**
@file
Unit tests for lock-free algorithms of mysys
*/
#include "thr_template.c"
#include <lf.h>
......@@ -47,6 +53,10 @@ pthread_handler_t test_lf_pinbox(void *arg)
return 0;
}
/*
thread local data area, allocated using lf_alloc.
union is required to enforce the minimum required element size (sizeof(ptr))
*/
typedef union {
int32 data;
void *not_used;
......
/* Copyright (C) 2006 MySQL AB
/* Copyright (C) 2006-2008 MySQL AB, 2008 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......
/* Copyright (C) 2006 MySQL AB
/* Copyright (C) 2006-2008 MySQL AB, 2008 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......
/* Copyright (C) 2006 MySQL AB
/* Copyright (C) 2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -16,7 +16,6 @@
#include "thr_template.c"
#include <waiting_threads.h>
#include <m_string.h>
#include <locale.h>
struct test_wt_thd {
WT_THD thd;
......@@ -31,6 +30,7 @@ ulong wt_timeout_long=10000, wt_deadlock_search_depth_long=15;
#define reset(ARRAY) bzero(ARRAY, sizeof(ARRAY))
/* see explanation of the kill strategies in waiting_threads.h */
enum { LATEST, RANDOM, YOUNGEST, LOCKS } kill_strategy;
WT_RESOURCE_TYPE restype={ wt_resource_id_memcmp, 0};
......@@ -68,13 +68,14 @@ pthread_handler_t test_wt(void *arg)
res= 0;
/* prepare for waiting for a random number of random threads */
for (j= n= (rnd() % THREADS)/10; !res && j >= 0; j--)
{
retry:
i= rnd() % (THREADS-1);
if (i >= id) i++;
i= rnd() % (THREADS-1); /* pick a random thread */
if (i >= id) i++; /* with a number from 0 to THREADS-1 excluding ours */
for (k=n; k >=j; k--)
for (k=n; k >=j; k--) /* the one we didn't pick before */
if (blockers[k] == i)
goto retry;
blockers[j]= i;
......@@ -121,7 +122,7 @@ pthread_handler_t test_wt(void *arg)
#define DEL "(deleted)"
char *x=malloc(strlen(thds[id].thd.name)+sizeof(DEL)+1);
strxmov(x, thds[id].thd.name, DEL, 0);
thds[id].thd.name=x; /* it's a memory leak, go on, shoot me */
thds[id].thd.name=x;
}
#endif
......@@ -165,8 +166,8 @@ void do_one_test()
void do_tests()
{
plan(12);
compile_time_assert(THREADS >= 3);
plan(14);
compile_time_assert(THREADS >= 4);
DBUG_PRINT("wt", ("================= initialization ==================="));
......@@ -206,22 +207,22 @@ void do_tests()
pthread_mutex_lock(&lock);
bad= wt_thd_cond_timedwait(& thds[0].thd, &lock);
pthread_mutex_unlock(&lock);
ok(bad == ETIMEDOUT, "timeout test returned %d", bad);
ok(bad == WT_TIMEOUT, "timeout test returned %d", bad);
ok_wait(0,1,0);
ok_wait(1,2,1);
ok_deadlock(2,0,2);
pthread_mutex_lock(&lock);
wt_thd_cond_timedwait(& thds[0].thd, &lock);
wt_thd_cond_timedwait(& thds[1].thd, &lock);
ok(wt_thd_cond_timedwait(& thds[0].thd, &lock) == WT_TIMEOUT, "as always");
ok(wt_thd_cond_timedwait(& thds[1].thd, &lock) == WT_TIMEOUT, "as always");
wt_thd_release_all(& thds[0].thd);
wt_thd_release_all(& thds[1].thd);
wt_thd_release_all(& thds[2].thd);
wt_thd_release_all(& thds[3].thd);
pthread_mutex_unlock(&lock);
for (cnt=0; cnt < 3; cnt++)
for (cnt=0; cnt < 4; cnt++)
{
wt_thd_destroy(& thds[cnt].thd);
wt_thd_lazy_init(& thds[cnt].thd,
......@@ -261,6 +262,7 @@ void do_tests()
wt_thd_release_all(& thds[cnt].thd);
wt_thd_destroy(& thds[cnt].thd);
pthread_mutex_destroy(& thds[cnt].lock);
free(thds[cnt].thd.name);
}
pthread_mutex_unlock(&lock);
wt_end();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment