Commit 913e2faa authored by Zardosht Kasheff's avatar Zardosht Kasheff Committed by Yoni Fogel

[t:3518], fix bug with getting hpk value

git-svn-id: file:///svn/mysql/tokudb-engine/tokudb-engine@34493 c7de825b-a66e-492c-adef-691d508d4ae1
parent 0c8a7e63
......@@ -2878,29 +2878,6 @@ DBT *ha_tokudb::pack_key(
DBUG_RETURN(key);
}
//
// Reads the last element of dictionary of index keynr, and places
// the data into table->record[1].
//
int ha_tokudb::read_last(uint keynr) {
TOKUDB_DBUG_ENTER("ha_tokudb::read_last");
int do_commit = 0;
if (transaction == NULL) {
int r = db_env->txn_begin(db_env, 0, &transaction, 0);
assert(r == 0);
do_commit = 1;
}
int error = index_init(keynr, 0);
if (error == 0)
error = index_last(table->record[1]);
index_end();
if (do_commit) {
commit_txn(transaction, 0);
transaction = NULL;
}
TOKUDB_DBUG_RETURN(error);
}
//
// get max used hidden primary key value
//
......@@ -2908,13 +2885,42 @@ void ha_tokudb::init_hidden_prim_key_info() {
TOKUDB_DBUG_ENTER("ha_tokudb::init_prim_key_info");
pthread_mutex_lock(&share->mutex);
if (!(share->status & STATUS_PRIMARY_KEY_INIT)) {
(void) extra(HA_EXTRA_KEYREAD);
int error = read_last(primary_key);
(void) extra(HA_EXTRA_NO_KEYREAD);
int error = 0;
THD* thd = ha_thd();
DB_TXN* txn = NULL;
DBC* c = NULL;
tokudb_trx_data *trx = NULL;
trx = (tokudb_trx_data *) thd_data_get(ha_thd(), tokudb_hton->slot);
bool do_commit = false;
if (thd_sql_command(thd) == SQLCOM_CREATE_TABLE && trx && trx->sub_sp_level) {
txn = trx->sub_sp_level;
}
else {
do_commit = true;
error = db_env->txn_begin(db_env, 0, &txn, 0);
assert(error == 0);
}
error = share->key_file[primary_key]->cursor(
share->key_file[primary_key],
txn,
&c,
0
);
assert(error == 0);
DBT key,val;
bzero(&key, sizeof(key));
bzero(&val, sizeof(val));
error = c->c_get(c, &key, &val, DB_LAST);
if (error == 0) {
share->auto_ident = hpk_char_to_num(current_ident);
assert(key.size == TOKUDB_HIDDEN_PRIMARY_KEY_LENGTH);
share->auto_ident = hpk_char_to_num((uchar *)key.data);
}
error = c->c_close(c);
assert(error == 0);
if (do_commit) {
commit_txn(txn, 0);
}
share->status |= STATUS_PRIMARY_KEY_INIT;
}
pthread_mutex_unlock(&share->mutex);
......
......@@ -636,7 +636,6 @@ public:
private:
int read_full_row(uchar * buf);
int __close(int mutex_is_locked);
int read_last(uint keynr);
int get_next(uchar* buf, int direction);
int read_data_from_range_query_buff(uchar* buf, bool need_val);
void invalidate_bulk_fetch();
......
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