Commit e24c4917 authored by Zardosht Kasheff's avatar Zardosht Kasheff Committed by Yoni Fogel

[t:1979], merge to main line

git-svn-id: file:///svn/mysql/tokudb-engine/src@15772 c7de825b-a66e-492c-adef-691d508d4ae1
parent d82692c7
This diff is collapsed.
......@@ -97,6 +97,7 @@ typedef ulonglong HA_METADATA_KEY;
#define hatoku_capabilities 1
#define hatoku_max_ai 2 //maximum auto increment value found so far
#define hatoku_ai_create_value 3
#define hatoku_key_name 4
typedef struct st_filter_key_part_info {
uint offset;
......@@ -258,14 +259,19 @@ private:
int handle_cursor_error(int error, int err_to_return, uint keynr);
DBT *get_pos(DBT * to, uchar * pos);
int open_secondary_table(DB** ptr, KEY* key_info, const char* name, int mode, u_int32_t* key_type);
int open_main_dictionary(const char* name, int mode, DB_TXN* txn);
int open_secondary_dictionary(DB** ptr, KEY* key_info, const char* name, int mode, u_int32_t* key_type, DB_TXN* txn);
int open_status_dictionary(DB** ptr, const char* name, DB_TXN* txn);
int acquire_table_lock (DB_TXN* trans, TABLE_LOCK_TYPE lt);
int estimate_num_rows(DB* db, u_int64_t* num_rows);
bool has_auto_increment_flag(uint* index);
int write_to_status(DB* db, HA_METADATA_KEY curr_key_data, void* data, uint size );
int write_metadata(DB* db, void* key, uint key_size, void* data, uint data_size );
int write_to_status(DB* db, HA_METADATA_KEY curr_key_data, void* data, uint size, DB_TXN* txn );
int write_metadata(DB* db, void* key, uint key_size, void* data, uint data_size, DB_TXN* txn );
int remove_metadata(DB* db, void* key_data, uint key_size, DB_TXN* transaction);
int update_max_auto_inc(DB* db, ulonglong val);
int write_auto_inc_create(DB* db, ulonglong val);
int remove_key_name_from_status(DB* status_block, char* key_name, DB_TXN* txn);
int write_key_name_to_status(DB* status_block, char* key_name, DB_TXN* txn);
int write_auto_inc_create(DB* db, ulonglong val, DB_TXN* txn);
void init_auto_increment();
int initialize_share(
const char* name,
......@@ -276,7 +282,12 @@ private:
int prelock_range ( const key_range *start_key, const key_range *end_key);
int create_txn(THD* thd, tokudb_trx_data* trx);
bool may_table_be_empty();
int delete_or_rename_table (const char* from_name, const char* to_name, bool is_delete);
int delete_or_rename_dictionary( const char* from_name, const char* to_name, char* index_name, bool is_key, DB_TXN* txn, bool is_delete);
int truncate_dictionary( uint keynr, DB_TXN* txn );
int create_secondary_dictionary(const char* name, TABLE* form, KEY* key_info, DB_TXN* txn);
int create_main_dictionary(const char* name, TABLE* form, DB_TXN* txn);
void trace_create_table_info(const char *name, TABLE * form);
public:
......
......@@ -114,11 +114,6 @@ static void reset_stmt_progress (tokudb_stmt_progress* val) {
static int get_name_length(const char *name) {
int n = 0;
const char *newname = name;
if (tokudb_data_dir) {
n += strlen(tokudb_data_dir) + 1;
if (strncmp("./", name, 2) == 0)
newname = name + 2;
}
n += strlen(newname);
n += strlen(ha_tokudb_ext);
return n;
......@@ -130,25 +125,37 @@ static int get_name_length(const char *name) {
static int get_max_dict_name_path_length(const char *tablename) {
int n = 0;
n += get_name_length(tablename);
n += 1; //for the '/'
n += 1; //for the '-'
n += MAX_DICT_NAME_LEN;
n += strlen(ha_tokudb_ext);
return n;
}
static void make_name(char *newname, const char *tablename, const char *dictname) {
const char *newtablename = tablename;
char *nn = newname;
if (tokudb_data_dir) {
nn += sprintf(nn, "%s/", tokudb_data_dir);
if (strncmp("./", tablename, 2) == 0)
newtablename = tablename + 2;
assert(tablename);
assert(dictname);
nn += sprintf(nn, "%s", newtablename);
nn += sprintf(nn, "-%s", dictname);
}
static inline void commit_txn(DB_TXN* txn, u_int32_t flags) {
int r;
r = txn->commit(txn, flags);
if (r != 0) {
sql_print_error("tried committing transaction 0x%x and got error code %d", txn, r);
}
nn += sprintf(nn, "%s%s", newtablename, ha_tokudb_ext);
if (dictname)
nn += sprintf(nn, "/%s%s", dictname, ha_tokudb_ext);
assert(r == 0);
}
static inline void abort_txn(DB_TXN* txn) {
int r;
r = txn->abort(txn);
if (r != 0) {
sql_print_error("tried aborting transaction 0x%x and got error code %d", txn, r);
}
assert(r == 0);
}
#endif
......@@ -31,7 +31,7 @@ extern "C" {
#undef HAVE_DTRACE
#undef _DTRACE_VERSION
#define TOKU_METADB_NAME ".\\tokudb_meta.tokudb"
#define TOKU_METADB_NAME "tokudb_meta"
static inline void *thd_data_get(THD *thd, int slot) {
return thd->ha_data[slot].ha_ptr;
......@@ -300,12 +300,17 @@ static int tokudb_init_func(void *p) {
r= metadata_db->open(metadata_db, 0, TOKU_METADB_NAME, NULL, DB_BTREE, DB_THREAD|DB_AUTO_COMMIT, 0);
if (r) {
sql_print_error("No metadata table exists, so creating it");
if (r != ENOENT) {
sql_print_error("Got error %d when trying to open metadata_db", r);
goto error;
}
sql_print_warning("No metadata table exists, so creating it");
r= metadata_db->open(metadata_db, NULL, TOKU_METADB_NAME, NULL, DB_BTREE, DB_THREAD | DB_CREATE, my_umask);
if (r) {
goto error;
}
metadata_db->close(metadata_db,0);
r = metadata_db->close(metadata_db,0);
assert(r == 0);
r = db_create(&metadata_db, db_env, 0);
if (r) {
DBUG_PRINT("info", ("failed to create metadata db %d\n", r));
......@@ -435,13 +440,14 @@ static int tokudb_commit(handlerton * hton, THD * thd, bool all) {
u_int32_t syncflag = THDVAR(thd, commit_sync) ? 0 : DB_TXN_NOSYNC;
tokudb_trx_data *trx = (tokudb_trx_data *) thd_data_get(thd, hton->slot);
DB_TXN **txn = all ? &trx->all : &trx->stmt;
int error = 0;
if (*txn) {
if (tokudb_debug & TOKUDB_DEBUG_TXN)
if (tokudb_debug & TOKUDB_DEBUG_TXN) {
TOKUDB_TRACE("commit:%d:%p\n", all, *txn);
error = (*txn)->commit(*txn, syncflag);
if (*txn == trx->sp_level)
}
commit_txn(*txn, syncflag);
if (*txn == trx->sp_level) {
trx->sp_level = 0;
}
*txn = 0;
}
else if (tokudb_debug & TOKUDB_DEBUG_TXN) {
......@@ -451,7 +457,7 @@ static int tokudb_commit(handlerton * hton, THD * thd, bool all) {
trx->iso_level = hatoku_iso_not_set;
}
reset_stmt_progress(&trx->stmt_progress);
TOKUDB_DBUG_RETURN(error);
TOKUDB_DBUG_RETURN(0);
}
static int tokudb_rollback(handlerton * hton, THD * thd, bool all) {
......@@ -459,14 +465,15 @@ static int tokudb_rollback(handlerton * hton, THD * thd, bool all) {
DBUG_PRINT("trans", ("aborting transaction %s", all ? "all" : "stmt"));
tokudb_trx_data *trx = (tokudb_trx_data *) thd_data_get(thd, hton->slot);
DB_TXN **txn = all ? &trx->all : &trx->stmt;
int error = 0;
if (*txn) {
if (tokudb_debug & TOKUDB_DEBUG_TXN)
if (tokudb_debug & TOKUDB_DEBUG_TXN) {
TOKUDB_TRACE("rollback:%p\n", *txn);
error = (*txn)->abort(*txn);
if (*txn == trx->sp_level)
trx->sp_level = 0;
*txn = 0;
}
abort_txn(*txn);
if (*txn == trx->sp_level) {
trx->sp_level = 0;
}
*txn = 0;
}
else {
if (tokudb_debug & TOKUDB_DEBUG_TXN) {
......@@ -477,7 +484,7 @@ static int tokudb_rollback(handlerton * hton, THD * thd, bool all) {
trx->iso_level = hatoku_iso_not_set;
}
reset_stmt_progress(&trx->stmt_progress);
TOKUDB_DBUG_RETURN(error);
TOKUDB_DBUG_RETURN(0);
}
#if 0
......@@ -570,8 +577,6 @@ static bool tokudb_show_data_size(THD * thd, stat_print_fn * stat_print, bool ex
if (!error) {
char* name = (char *)curr_key.data;
char* newname = NULL;
char name_buff[FN_REFLEN];
char* fn_ret = NULL;
u_int64_t curr_num_bytes = 0;
DB_BTREE_STAT64 dict_stats;
......@@ -585,12 +590,11 @@ static bool tokudb_show_data_size(THD * thd, stat_print_fn * stat_print, bool ex
}
make_name(newname, name, "main");
fn_ret = fn_format(name_buff, newname, "", 0, MY_UNPACK_FILENAME|MY_SAFE_PATH);
error = db_create(&curr_db, db_env, 0);
if (error) { goto cleanup; }
error = curr_db->open(curr_db, 0, name_buff, NULL, DB_BTREE, DB_THREAD, 0);
error = curr_db->open(curr_db, 0, newname, NULL, DB_BTREE, DB_THREAD, 0);
if (error == ENOENT) { error = 0; continue; }
if (error) { goto cleanup; }
......@@ -678,7 +682,7 @@ cleanup:
tmp_table_cursor->c_close(tmp_table_cursor);
}
if (txn) {
txn->commit(txn, 0);
commit_txn(txn, 0);
}
if (error) {
sql_print_error("got an error %d in show_data_size\n", error);
......@@ -763,8 +767,8 @@ static bool tokudb_show_engine_status(THD * thd, stat_print_fn * stat_print) {
STATPRINT("logger lock", lockstat);
STATPRINT("logger lock counter", buf);
lockstat = (engstat.cachetable_lock_ctr & 0x01) ? "Locked" : "Unlocked";
lockctr = engstat.cachetable_lock_ctr >> 1; // lsb indicates if locked
//lockstat = (engstat.cachetable_lock_ctr & 0x01) ? "Locked" : "Unlocked";
//lockctr = engstat.cachetable_lock_ctr >> 1; // lsb indicates if locked
sprintf(buf, "%" PRIu32, lockctr);
STATPRINT("cachetable lock", lockstat);
STATPRINT("cachetable lock counter", buf);
......
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