diff options
author | unknown <serg@serg.mylan> | 2005-01-16 13:16:23 +0100 |
---|---|---|
committer | unknown <serg@serg.mylan> | 2005-01-16 13:16:23 +0100 |
commit | 88bd301d36dd00735f6380d37a93594cc8539fe1 (patch) | |
tree | 58ca68b7179b2df96e7b2f14a1da686cc9d2b959 /sql/ha_berkeley.cc | |
parent | 83e58bc0eaa2856e54b08c84417192b07db68a86 (diff) | |
download | mariadb-git-88bd301d36dd00735f6380d37a93594cc8539fe1.tar.gz |
XA (not completely polished out yet)
include/my_pthread.h:
cleanup. don't use gcc extensions
innobase/include/trx0sys.ic:
Jan's fix for innobase_xa_prepare
innobase/read/read0read.c:
Jan's fix for innobase_xa_prepare
innobase/trx/trx0trx.c:
Jan's fix for innobase_xa_prepare
mysql-test/include/varchar.inc:
test fix
mysql-test/r/ctype_ucs.result:
new log event - all binlog positions are changed :(
mysql-test/r/drop_temp_table.result:
new log event - all binlog positions are changed :(
mysql-test/r/insert_select.result:
new log event - all binlog positions are changed :(
mysql-test/r/mix_innodb_myisam_binlog.result:
new log event - all binlog positions are changed :(
mysql-test/r/myisam.result:
test fix
mysql-test/r/rpl000015.result:
new log event - all binlog positions are changed :(
mysql-test/r/rpl_change_master.result:
new log event - all binlog positions are changed :(
mysql-test/r/rpl_charset.result:
new log event - all binlog positions are changed :(
mysql-test/r/rpl_error_ignored_table.result:
new log event - all binlog positions are changed :(
mysql-test/r/rpl_flush_log_loop.result:
new log event - all binlog positions are changed :(
mysql-test/r/rpl_flush_tables.result:
new log event - all binlog positions are changed :(
mysql-test/r/rpl_loaddata.result:
new log event - all binlog positions are changed :(
mysql-test/r/rpl_loaddata_rule_m.result:
new log event - all binlog positions are changed :(
mysql-test/r/rpl_loaddata_rule_s.result:
new log event - all binlog positions are changed :(
mysql-test/r/rpl_log.result:
new log event - all binlog positions are changed :(
mysql-test/r/rpl_log_pos.result:
new log event - all binlog positions are changed :(
mysql-test/r/rpl_max_relay_size.result:
new log event - all binlog positions are changed :(
mysql-test/r/rpl_relayrotate.result:
new log event - all binlog positions are changed :(
mysql-test/r/rpl_replicate_do.result:
new log event - all binlog positions are changed :(
mysql-test/r/rpl_reset_slave.result:
new log event - all binlog positions are changed :(
mysql-test/r/rpl_rotate_logs.result:
new log event - all binlog positions are changed :(
mysql-test/r/rpl_server_id1.result:
new log event - all binlog positions are changed :(
mysql-test/r/rpl_server_id2.result:
new log event - all binlog positions are changed :(
mysql-test/r/rpl_temporary.result:
new log event - all binlog positions are changed :(
mysql-test/r/rpl_timezone.result:
new log event - all binlog positions are changed :(
mysql-test/r/rpl_until.result:
new log event - all binlog positions are changed :(
mysql-test/r/rpl_user_variables.result:
new log event - all binlog positions are changed :(
mysql-test/r/user_var.result:
new log event - all binlog positions are changed :(
mysql-test/t/ctype_ucs.test:
new log event - all binlog positions are changed :(
mysql-test/t/mix_innodb_myisam_binlog.test:
new log event - all binlog positions are changed :(
mysql-test/t/mysqlbinlog.test:
new log event - all binlog positions are changed :(
mysql-test/t/mysqlbinlog2.test:
new log event - all binlog positions are changed :(
mysql-test/t/rpl_charset.test:
new log event - all binlog positions are changed :(
mysql-test/t/rpl_error_ignored_table.test:
new log event - all binlog positions are changed :(
mysql-test/t/rpl_loaddata_rule_m.test:
new log event - all binlog positions are changed :(
mysql-test/t/rpl_loaddata_rule_s.test:
new log event - all binlog positions are changed :(
mysql-test/t/rpl_log.test:
new log event - all binlog positions are changed :(
mysql-test/t/rpl_log_pos.test:
new log event - all binlog positions are changed :(
mysql-test/t/rpl_user_variables.test:
new log event - all binlog positions are changed :(
mysql-test/t/user_var.test:
new log event - all binlog positions are changed :(
mysys/hash.c:
typo fixed
sql/ha_berkeley.cc:
handlerton framework
sql/ha_berkeley.h:
handlerton framework
sql/ha_innodb.cc:
handlerton framework
sql/ha_innodb.h:
handlerton framework
sql/handler.cc:
new transaction handling, handlerton framework, two-phase commit, XA support
sql/handler.h:
new transaction handling, handlerton framework, two-phase commit, XA support
sql/lex.h:
XA commands
sql/log.cc:
new transaction handling, handlerton framework, two-phase commit,
XA support, tc-logging, TC_LOG_MMAP class
sql/log_event.cc:
Xid_log_event
sql/log_event.h:
Xid_log_event, LOG_EVENT_BINLOG_CLOSED_F flag
sql/mysql_priv.h:
wrapper for query_id++
sql/mysqld.cc:
new command-line options --log-tc, --log-tc-size, --tc-heuristic-recover,
new status variables Tc_log_page_size, Tc_log_max_pages_used, Tc_log_page_waits.
init/stop tc logging
sql/set_var.h:
warning fixed
sql/share/errmsg.txt:
XA error messages
sql/sp_head.cc:
s/query_id++/next_query_id()/
sql/sql_base.cc:
typo fixed. new transaction handling.
sql/sql_class.cc:
cleanup of THD.transaction
sql/sql_class.h:
TC_LOG classes, new status variables, new savepoint handling, XA support
sql/sql_insert.cc:
comments
sql/sql_lex.cc:
s/found_colon/found_semicolon/
sql/sql_lex.h:
SQLCOM_XA_xxx, XA related changes in Lex
sql/sql_parse.cc:
cleanup, XA commands, new savepoint handling
sql/sql_repl.cc:
two functions moved to log.cc
sql/sql_repl.h:
two functions moved to log.cc
sql/sql_trigger.cc:
s/lex.name_and_length/lex.ident/
sql/sql_yacc.yy:
XA commands, cleanup
Diffstat (limited to 'sql/ha_berkeley.cc')
-rw-r--r-- | sql/ha_berkeley.cc | 134 |
1 files changed, 87 insertions, 47 deletions
diff --git a/sql/ha_berkeley.cc b/sql/ha_berkeley.cc index 6cb83624eff..160adf13e40 100644 --- a/sql/ha_berkeley.cc +++ b/sql/ha_berkeley.cc @@ -102,11 +102,32 @@ static int write_status(DB *status_block, char *buff, uint length); static void update_status(BDB_SHARE *share, TABLE *table); static void berkeley_noticecall(DB_ENV *db_env, db_notices notice); - +static int berkeley_close_connection(THD *thd); +static int berkeley_commit(THD *thd, bool all); +static int berkeley_rollback(THD *thd, bool all); + +static handlerton berkeley_hton = { + 0, /* slot */ + 0, /* savepoint size */ + berkeley_close_connection, + NULL, /* savepoint_set */ + NULL, /* savepoint_rollback */ + NULL, /* savepoint_release */ + berkeley_commit, + berkeley_rollback, + NULL, /* prepare */ + NULL, /* recover */ +}; + +typedef struct st_berkeley_trx_data { + DB_TXN *all; + DB_TXN *stmt; + uint bdb_lock_count; +} berkeley_trx_data; /* General functions */ -bool berkeley_init(void) +handlerton *berkeley_init(void) { DBUG_ENTER("berkeley_init"); @@ -135,7 +156,7 @@ bool berkeley_init(void) berkeley_log_file_size= max(berkeley_log_file_size, 10*1024*1024L); if (db_env_create(&db_env,0)) - DBUG_RETURN(1); /* purecov: inspected */ + DBUG_RETURN(0); db_env->set_errcall(db_env,berkeley_print_error); db_env->set_errpfx(db_env,"bdb"); db_env->set_noticecall(db_env, berkeley_noticecall); @@ -163,14 +184,15 @@ bool berkeley_init(void) DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | DB_CREATE | DB_THREAD, 0666)) { - db_env->close(db_env,0); /* purecov: inspected */ - db_env=0; /* purecov: inspected */ + db_env->close(db_env,0); + db_env=0; + DBUG_RETURN(0); } (void) hash_init(&bdb_open_tables,system_charset_info,32,0,0, (hash_get_key) bdb_get_key,0,0); pthread_mutex_init(&bdb_mutex,MY_MUTEX_INIT_FAST); - DBUG_RETURN(db_env == 0); + DBUG_RETURN(&berkeley_hton); } @@ -188,6 +210,11 @@ bool berkeley_end(void) DBUG_RETURN(error != 0); } +static int berkeley_close_connection(THD *thd) +{ + my_free((gptr)thd->ha_data[berkeley_hton.slot], MYF(0)); +} + bool berkeley_flush_logs() { int error; @@ -206,26 +233,33 @@ bool berkeley_flush_logs() DBUG_RETURN(result); } - -int berkeley_commit(THD *thd, void *trans) +static int berkeley_commit(THD *thd, bool all) { DBUG_ENTER("berkeley_commit"); - DBUG_PRINT("trans",("ending transaction %s", - trans == thd->transaction.stmt.bdb_tid ? "stmt" : "all")); - int error=txn_commit((DB_TXN*) trans,0); + DBUG_PRINT("trans",("ending transaction %s", all ? "all" : "stmt")); + berkeley_trx_data *trx=(berkeley_trx_data *)thd->ha_data[berkeley_hton.slot]; + int error=txn_commit(all ? trx->all : trx->stmt,0); #ifndef DBUG_OFF if (error) - DBUG_PRINT("error",("error: %d",error)); /* purecov: inspected */ + DBUG_PRINT("error",("error: %d",error)); #endif + if (all) + trx->all=0; + else + trx->stmt=0; DBUG_RETURN(error); } -int berkeley_rollback(THD *thd, void *trans) +static int berkeley_rollback(THD *thd, bool all) { DBUG_ENTER("berkeley_rollback"); - DBUG_PRINT("trans",("aborting transaction %s", - trans == thd->transaction.stmt.bdb_tid ? "stmt" : "all")); - int error=txn_abort((DB_TXN*) trans); + DBUG_PRINT("trans",("aborting transaction %s", all ? "all" : "stmt")); + berkeley_trx_data *trx=(berkeley_trx_data *)thd->ha_data[berkeley_hton.slot]; + int error=txn_abort(all ? trx->all : trx->stmt); + if (all) + trx->all=0; + else + trx->stmt=0; DBUG_RETURN(error); } @@ -1818,52 +1852,56 @@ int ha_berkeley::reset(void) int ha_berkeley::external_lock(THD *thd, int lock_type) { int error=0; + berkeley_trx_data *trx=(berkeley_trx_data *)thd->ha_data[berkeley_hton.slot]; DBUG_ENTER("ha_berkeley::external_lock"); + if (!trx) + { + thd->ha_data[berkeley_hton.slot]= trx= (berkeley_trx_data *) + my_malloc(sizeof(*trx), MYF(MY_ZEROFILL)); + if (!trx) + DBUG_RETURN(1); + } if (lock_type != F_UNLCK) { - if (!thd->transaction.bdb_lock_count++) + if (!trx->bdb_lock_count++) { - DBUG_ASSERT(thd->transaction.stmt.bdb_tid == 0); + DBUG_ASSERT(trx->stmt == 0); transaction=0; // Safety /* First table lock, start transaction */ if ((thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN | - OPTION_TABLE_LOCK)) && - !thd->transaction.all.bdb_tid) + OPTION_TABLE_LOCK)) && !trx->all) { /* We have to start a master transaction */ DBUG_PRINT("trans",("starting transaction all: options: 0x%lx", (ulong) thd->options)); - if ((error=txn_begin(db_env, 0, - (DB_TXN**) &thd->transaction.all.bdb_tid, - 0))) + if ((error=txn_begin(db_env, 0, &trx->all, 0))) { - thd->transaction.bdb_lock_count--; // We didn't get the lock /* purecov: inspected */ - DBUG_RETURN(error); /* purecov: inspected */ + trx->bdb_lock_count--; // We didn't get the lock + DBUG_RETURN(error); } + trans_register_ha(thd, TRUE, &berkeley_hton); if (thd->in_lock_tables) DBUG_RETURN(0); // Don't create stmt trans } DBUG_PRINT("trans",("starting transaction stmt")); - if ((error=txn_begin(db_env, - (DB_TXN*) thd->transaction.all.bdb_tid, - (DB_TXN**) &thd->transaction.stmt.bdb_tid, - 0))) + if ((error=txn_begin(db_env, trx->all, &trx->stmt, 0))) { /* We leave the possible master transaction open */ - thd->transaction.bdb_lock_count--; // We didn't get the lock /* purecov: inspected */ - DBUG_RETURN(error); /* purecov: inspected */ + trx->bdb_lock_count--; // We didn't get the lock + DBUG_RETURN(error); } + trans_register_ha(thd, FALSE, &berkeley_hton); } - transaction= (DB_TXN*) thd->transaction.stmt.bdb_tid; + transaction= trx->stmt; } else { lock.type=TL_UNLOCK; // Unlocked thread_safe_add(share->rows, changed_rows, &share->mutex); changed_rows=0; - if (!--thd->transaction.bdb_lock_count) + if (!--trx->bdb_lock_count) { - if (thd->transaction.stmt.bdb_tid) + if (trx->stmt) { /* F_UNLOCK is done without a transaction commit / rollback. @@ -1871,9 +1909,8 @@ int ha_berkeley::external_lock(THD *thd, int lock_type) We must in this case commit the work to keep the row locks */ DBUG_PRINT("trans",("commiting non-updating transaction")); - error=txn_commit((DB_TXN*) thd->transaction.stmt.bdb_tid,0); - thd->transaction.stmt.bdb_tid=0; - transaction=0; + error= txn_commit(trx->stmt,0); + trx->stmt= transaction= 0; } } } @@ -1891,14 +1928,19 @@ int ha_berkeley::start_stmt(THD *thd) { int error=0; DBUG_ENTER("ha_berkeley::start_stmt"); - if (!thd->transaction.stmt.bdb_tid) + berkeley_trx_data *trx=(berkeley_trx_data *)thd->ha_data[berkeley_hton.slot]; + /* + note that trx->stmt may have been already initialized as start_stmt() + is called for *each table* not for each storage engine, + and there could be many bdb tables referenced in the query + */ + if (!trx->stmt) { DBUG_PRINT("trans",("starting transaction stmt")); - error=txn_begin(db_env, (DB_TXN*) thd->transaction.all.bdb_tid, - (DB_TXN**) &thd->transaction.stmt.bdb_tid, - 0); + error=txn_begin(db_env, trx->all, &trx->stmt, 0); + trans_register_ha(thd, FALSE, &berkeley_hton); } - transaction= (DB_TXN*) thd->transaction.stmt.bdb_tid; + transaction= trx->stmt; DBUG_RETURN(error); } @@ -2234,6 +2276,7 @@ int ha_berkeley::analyze(THD* thd, HA_CHECK_OPT* check_opt) uint i; DB_BTREE_STAT *stat=0; DB_TXN_STAT *txn_stat_ptr= 0; + berkeley_trx_data *trx=(berkeley_trx_data *)thd->ha_data[berkeley_hton.slot]; /* Original bdb documentation says: @@ -2249,11 +2292,8 @@ int ha_berkeley::analyze(THD* thd, HA_CHECK_OPT* check_opt) { DB_TXN_ACTIVE *atxn_stmt= 0, *atxn_all= 0; - DB_TXN *txn_all= (DB_TXN*) thd->transaction.all.bdb_tid; - u_int32_t all_id= txn_all->id(txn_all); - - DB_TXN *txn_stmt= (DB_TXN*) thd->transaction.stmt.bdb_tid; - u_int32_t stmt_id= txn_stmt->id(txn_stmt); + u_int32_t all_id= trx->all->id(trx->all); + u_int32_t stmt_id= trx->stmt->id(trx->stmt); DB_TXN_ACTIVE *cur= txn_stat_ptr->st_txnarray; DB_TXN_ACTIVE *end= cur + txn_stat_ptr->st_nactive; |