Commit 6f169168 authored by Zardosht Kasheff's avatar Zardosht Kasheff Committed by Yoni Fogel

[t:4541], merge new fix to main

git-svn-id: file:///svn/toku/tokudb@41583 c7de825b-a66e-492c-adef-691d508d4ae1
parent 0d32c57b
......@@ -203,6 +203,7 @@ static void print_defines (void) {
//printf("#define DB_PRELOCKED_FILE_READ 0x00200000\n"); // private tokudb. No longer supported in #4472
printf("#define DB_IS_HOT_INDEX 0x00100000\n"); // private tokudb
printf("#define DBC_DISABLE_PREFETCHING 0x20000000\n"); // private tokudb
printf("#define DB_UPDATE_CMP_DESCRIPTOR 0x40000000\n"); // private tokudb
{
//dbt flags
......@@ -424,7 +425,6 @@ static void print_db_struct (void) {
"DESCRIPTOR descriptor /* saved row/dictionary descriptor for aiding in comparisons */",
"DESCRIPTOR cmp_descriptor /* saved row/dictionary descriptor for aiding in comparisons */",
"int (*change_descriptor) (DB*, DB_TXN*, const DBT* descriptor, u_int32_t) /* change row/dictionary descriptor for a db. Available only while db is open */",
"int (*update_cmp_descriptor) (DB*) /* Update cmp descriptor. Available only while db is open */",
"int (*getf_set)(DB*, DB_TXN*, u_int32_t, DBT*, YDB_CALLBACK_FUNCTION, void*) /* same as DBC->c_getf_set without a persistent cursor) */",
"int (*optimize)(DB*) /* Run garbage collecion and promote all transactions older than oldest. Amortized (happens during flattening) */",
"int (*hot_optimize)(DB*, int (*progress_callback)(void *progress_extra, float progress), void *progress_extra)",
......
......@@ -156,6 +156,7 @@ typedef enum {
#define DB_PRELOCKED_WRITE 0x00400000
#define DB_IS_HOT_INDEX 0x00100000
#define DBC_DISABLE_PREFETCHING 0x20000000
#define DB_UPDATE_CMP_DESCRIPTOR 0x40000000
#define DB_DBT_APPMALLOC 1
#define DB_DBT_DUPOK 2
#define DB_DBT_MALLOC 8
......@@ -305,7 +306,6 @@ struct __toku_db {
DESCRIPTOR descriptor /* saved row/dictionary descriptor for aiding in comparisons */;
DESCRIPTOR cmp_descriptor /* saved row/dictionary descriptor for aiding in comparisons */;
int (*change_descriptor) (DB*, DB_TXN*, const DBT* descriptor, u_int32_t) /* change row/dictionary descriptor for a db. Available only while db is open */;
int (*update_cmp_descriptor) (DB*) /* Update cmp descriptor. Available only while db is open */;
int (*getf_set)(DB*, DB_TXN*, u_int32_t, DBT*, YDB_CALLBACK_FUNCTION, void*) /* same as DBC->c_getf_set without a persistent cursor) */;
int (*optimize)(DB*) /* Run garbage collecion and promote all transactions older than oldest. Amortized (happens during flattening) */;
int (*hot_optimize)(DB*, int (*progress_callback)(void *progress_extra, float progress), void *progress_extra);
......
......@@ -3504,8 +3504,8 @@ cleanup:
return r;
}
void
toku_brt_update_cmp_descriptor(BRT t) {
static void
brt_update_cmp_descriptor(BRT t) {
t->h->cmp_descriptor.dbt.size = t->h->descriptor.dbt.size;
t->h->cmp_descriptor.dbt.data = toku_xmemdup(
t->h->descriptor.dbt.data,
......@@ -3520,7 +3520,8 @@ toku_brt_change_descriptor(
const DBT* old_descriptor,
const DBT* new_descriptor,
BOOL do_log,
TOKUTXN txn
TOKUTXN txn,
BOOL update_cmp_descriptor
)
{
int r = 0;
......@@ -3543,27 +3544,33 @@ toku_brt_change_descriptor(
if (r != 0) { goto cleanup; }
if (do_log) {
TOKULOGGER logger = toku_txn_logger(txn);
TXNID xid = toku_txn_get_txnid(txn);
r = toku_log_change_fdescriptor(
logger, NULL, 0,
toku_cachefile_filenum(t->cf),
xid,
old_desc_bs,
new_desc_bs
);
if (r != 0) { goto cleanup; }
TOKULOGGER logger = toku_txn_logger(txn);
TXNID xid = toku_txn_get_txnid(txn);
r = toku_log_change_fdescriptor(
logger, NULL, 0,
toku_cachefile_filenum(t->cf),
xid,
old_desc_bs,
new_desc_bs,
update_cmp_descriptor
);
if (r != 0) { goto cleanup; }
}
// write new_descriptor to header
new_d.dbt = *new_descriptor;
fd = toku_cachefile_get_and_pin_fd (t->cf);
r = toku_update_descriptor(t->h, &new_d, fd);
if (r == 0) // very infrequent operation, worth precise threadsafe count
STATUS_VALUE(BRT_DESCRIPTOR_SET)++;
// very infrequent operation, worth precise threadsafe count
if (r == 0) {
STATUS_VALUE(BRT_DESCRIPTOR_SET)++;
}
toku_cachefile_unpin_fd(t->cf);
if (r!=0) goto cleanup;
if (update_cmp_descriptor) {
brt_update_cmp_descriptor(t);
}
cleanup:
return r;
}
......
......@@ -32,8 +32,7 @@ C_BEGIN
typedef int(*BRT_GET_CALLBACK_FUNCTION)(ITEMLEN keylen, bytevec key, ITEMLEN vallen, bytevec val, void *extra, bool lock_only);
int toku_open_brt (const char *fname, int is_create, BRT *, int nodesize, int basementnodesize, CACHETABLE, TOKUTXN, int(*)(DB *,const DBT*,const DBT*), DB*) __attribute__ ((warn_unused_result));
void toku_brt_update_cmp_descriptor(BRT t);
int toku_brt_change_descriptor(BRT t, const DBT* old_descriptor, const DBT* new_descriptor, BOOL do_log, TOKUTXN txn);
int toku_brt_change_descriptor(BRT t, const DBT* old_descriptor, const DBT* new_descriptor, BOOL do_log, TOKUTXN txn, BOOL update_cmp_descriptor);
int toku_update_descriptor(struct brt_header * h, DESCRIPTOR d, int fd);
// Note: See the locking discussion in brt.c for toku_brt_change_descriptor and toku_update_descriptor.
......
......@@ -210,6 +210,7 @@ const struct logtype logtypes[] = {
{"TXNID", "xid", 0},
{"BYTESTRING", "old_descriptor", 0},
{"BYTESTRING", "new_descriptor", 0},
{"BOOL", "update_cmp_descriptor", 0},
NULLFIELD}},
{0,0,FA{NULLFIELD}}
};
......
......@@ -869,7 +869,8 @@ static int toku_recover_change_fdescriptor (struct logtype_change_fdescriptor *l
&old_descriptor,
&new_descriptor,
FALSE,
txn
txn,
l->update_cmp_descriptor
);
assert(r==0);
}
......
......@@ -30,7 +30,7 @@ change_descriptor(DB_ENV* env, DB* db) {
DBT descriptor;
dbt_init(&descriptor, descriptor_contents, sizeof(descriptor_contents));
IN_TXN_COMMIT(env, NULL, txn_desc, 0, {
CHK(db->change_descriptor(db, txn_desc, &descriptor, 0));
CHK(db->change_descriptor(db, txn_desc, &descriptor, DB_UPDATE_CMP_DESCRIPTOR));
});
#endif
}
......@@ -52,12 +52,10 @@ do_x1_shutdown (BOOL do_commit, BOOL do_abort) {
r = db_create(&dba, env, 0); CKERR(r);
r = dba->open(dba, NULL, namea, NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
change_descriptor(env, dba);
dba->update_cmp_descriptor(dba);
r = db_create(&dbb, env, 0); CKERR(r);
r = dbb->open(dbb, NULL, nameb, NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
DB_TXN *txn;
change_descriptor(env, dbb);
dbb->update_cmp_descriptor(dbb);
r = env->txn_begin(env, NULL, &txn, 0); CKERR(r);
{
DBT a={.data="a", .size=2};
......
......@@ -116,8 +116,7 @@ int test_main(int argc, char * const argv[]) {
DBT desc;
dbt_init(&desc, "foo", sizeof("foo"));
IN_TXN_COMMIT(env, NULL, txn, 0,
CHK(db->change_descriptor(db, txn, &desc, 0)));
CHK(db->update_cmp_descriptor(db));
CHK(db->change_descriptor(db, txn, &desc, DB_UPDATE_CMP_DESCRIPTOR)));
pthread_t thd;
CHK(toku_pthread_create(&thd, NULL, startA, NULL));
......
......@@ -157,10 +157,8 @@ static void run_test(void) {
CHK(db->open(db, txn_create, "foo.db", NULL, DB_BTREE, DB_CREATE, 0666));
assert(db->descriptor->dbt.size == 0);
assert(db->cmp_descriptor->dbt.size == 0);
CHK(db->change_descriptor(db, txn_create, &orig_desc, 0));
CHK(db->change_descriptor(db, txn_create, &orig_desc, DB_UPDATE_CMP_DESCRIPTOR));
assert_desc_four(db);
assert(db->cmp_descriptor->dbt.size == 0);
CHK(db->update_cmp_descriptor(db));
assert_cmp_desc_valid(db);
r = env->create_loader(env, txn_create, &loader, db, 1, &db, NULL, NULL, 0);
CKERR(r);
......
......@@ -499,12 +499,6 @@ toku_db_rename(DB * db, const char *fname, const char *dbname, const char *newna
return r;
}
static int
toku_db_update_cmp_descriptor(DB *db) {
toku_brt_update_cmp_descriptor(db->i->brt);
return 0;
}
//
// This function is the only way to set a descriptor of a DB.
//
......@@ -516,6 +510,7 @@ toku_db_change_descriptor(DB *db, DB_TXN* txn, const DBT* descriptor, u_int32_t
TOKUTXN ttxn = txn ? db_txn_struct_i(txn)->tokutxn : NULL;
DBT old_descriptor;
BOOL is_db_hot_index = ((flags & DB_IS_HOT_INDEX) != 0);
BOOL update_cmp_descriptor = ((flags & DB_UPDATE_CMP_DESCRIPTOR) != 0);
toku_init_dbt(&old_descriptor);
if (!db_opened(db) || !txn || !descriptor || (descriptor->size>0 && !descriptor->data)){
......@@ -533,7 +528,14 @@ toku_db_change_descriptor(DB *db, DB_TXN* txn, const DBT* descriptor, u_int32_t
old_descriptor.size = db->descriptor->dbt.size;
old_descriptor.data = toku_memdup(db->descriptor->dbt.data, db->descriptor->dbt.size);
r = toku_brt_change_descriptor(db->i->brt, &old_descriptor, descriptor, TRUE, ttxn);
r = toku_brt_change_descriptor(
db->i->brt,
&old_descriptor,
descriptor,
TRUE,
ttxn,
update_cmp_descriptor
);
cleanup:
if (old_descriptor.data) toku_free(old_descriptor.data);
return r;
......@@ -1077,7 +1079,6 @@ toku_db_create(DB ** db, DB_ENV * env, u_int32_t flags) {
#undef SDB
// methods that take the ydb lock in some capacity,
// but not from beginning to end
result->update_cmp_descriptor = toku_db_update_cmp_descriptor;
result->del = autotxn_db_del;
result->put = autotxn_db_put;
result->update = autotxn_db_update;
......
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