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) { ...@@ -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_PRELOCKED_FILE_READ 0x00200000\n"); // private tokudb. No longer supported in #4472
printf("#define DB_IS_HOT_INDEX 0x00100000\n"); // private tokudb printf("#define DB_IS_HOT_INDEX 0x00100000\n"); // private tokudb
printf("#define DBC_DISABLE_PREFETCHING 0x20000000\n"); // private tokudb printf("#define DBC_DISABLE_PREFETCHING 0x20000000\n"); // private tokudb
printf("#define DB_UPDATE_CMP_DESCRIPTOR 0x40000000\n"); // private tokudb
{ {
//dbt flags //dbt flags
...@@ -424,7 +425,6 @@ static void print_db_struct (void) { ...@@ -424,7 +425,6 @@ static void print_db_struct (void) {
"DESCRIPTOR descriptor /* saved row/dictionary descriptor for aiding in comparisons */", "DESCRIPTOR descriptor /* saved row/dictionary descriptor for aiding in comparisons */",
"DESCRIPTOR cmp_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 (*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 (*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 (*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)", "int (*hot_optimize)(DB*, int (*progress_callback)(void *progress_extra, float progress), void *progress_extra)",
......
...@@ -156,6 +156,7 @@ typedef enum { ...@@ -156,6 +156,7 @@ typedef enum {
#define DB_PRELOCKED_WRITE 0x00400000 #define DB_PRELOCKED_WRITE 0x00400000
#define DB_IS_HOT_INDEX 0x00100000 #define DB_IS_HOT_INDEX 0x00100000
#define DBC_DISABLE_PREFETCHING 0x20000000 #define DBC_DISABLE_PREFETCHING 0x20000000
#define DB_UPDATE_CMP_DESCRIPTOR 0x40000000
#define DB_DBT_APPMALLOC 1 #define DB_DBT_APPMALLOC 1
#define DB_DBT_DUPOK 2 #define DB_DBT_DUPOK 2
#define DB_DBT_MALLOC 8 #define DB_DBT_MALLOC 8
...@@ -305,7 +306,6 @@ struct __toku_db { ...@@ -305,7 +306,6 @@ struct __toku_db {
DESCRIPTOR descriptor /* saved row/dictionary descriptor for aiding in comparisons */; DESCRIPTOR descriptor /* saved row/dictionary descriptor for aiding in comparisons */;
DESCRIPTOR cmp_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 (*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 (*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 (*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); int (*hot_optimize)(DB*, int (*progress_callback)(void *progress_extra, float progress), void *progress_extra);
......
...@@ -3504,8 +3504,8 @@ cleanup: ...@@ -3504,8 +3504,8 @@ cleanup:
return r; return r;
} }
void static void
toku_brt_update_cmp_descriptor(BRT t) { brt_update_cmp_descriptor(BRT t) {
t->h->cmp_descriptor.dbt.size = t->h->descriptor.dbt.size; t->h->cmp_descriptor.dbt.size = t->h->descriptor.dbt.size;
t->h->cmp_descriptor.dbt.data = toku_xmemdup( t->h->cmp_descriptor.dbt.data = toku_xmemdup(
t->h->descriptor.dbt.data, t->h->descriptor.dbt.data,
...@@ -3520,7 +3520,8 @@ toku_brt_change_descriptor( ...@@ -3520,7 +3520,8 @@ toku_brt_change_descriptor(
const DBT* old_descriptor, const DBT* old_descriptor,
const DBT* new_descriptor, const DBT* new_descriptor,
BOOL do_log, BOOL do_log,
TOKUTXN txn TOKUTXN txn,
BOOL update_cmp_descriptor
) )
{ {
int r = 0; int r = 0;
...@@ -3543,27 +3544,33 @@ toku_brt_change_descriptor( ...@@ -3543,27 +3544,33 @@ toku_brt_change_descriptor(
if (r != 0) { goto cleanup; } if (r != 0) { goto cleanup; }
if (do_log) { if (do_log) {
TOKULOGGER logger = toku_txn_logger(txn); TOKULOGGER logger = toku_txn_logger(txn);
TXNID xid = toku_txn_get_txnid(txn); TXNID xid = toku_txn_get_txnid(txn);
r = toku_log_change_fdescriptor( r = toku_log_change_fdescriptor(
logger, NULL, 0, logger, NULL, 0,
toku_cachefile_filenum(t->cf), toku_cachefile_filenum(t->cf),
xid, xid,
old_desc_bs, old_desc_bs,
new_desc_bs new_desc_bs,
); update_cmp_descriptor
if (r != 0) { goto cleanup; } );
if (r != 0) { goto cleanup; }
} }
// write new_descriptor to header // write new_descriptor to header
new_d.dbt = *new_descriptor; new_d.dbt = *new_descriptor;
fd = toku_cachefile_get_and_pin_fd (t->cf); fd = toku_cachefile_get_and_pin_fd (t->cf);
r = toku_update_descriptor(t->h, &new_d, fd); r = toku_update_descriptor(t->h, &new_d, fd);
if (r == 0) // very infrequent operation, worth precise threadsafe count // very infrequent operation, worth precise threadsafe count
STATUS_VALUE(BRT_DESCRIPTOR_SET)++; if (r == 0) {
STATUS_VALUE(BRT_DESCRIPTOR_SET)++;
}
toku_cachefile_unpin_fd(t->cf); toku_cachefile_unpin_fd(t->cf);
if (r!=0) goto cleanup; if (r!=0) goto cleanup;
if (update_cmp_descriptor) {
brt_update_cmp_descriptor(t);
}
cleanup: cleanup:
return r; return r;
} }
......
...@@ -32,8 +32,7 @@ C_BEGIN ...@@ -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); 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)); 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, BOOL update_cmp_descriptor);
int toku_brt_change_descriptor(BRT t, const DBT* old_descriptor, const DBT* new_descriptor, BOOL do_log, TOKUTXN txn);
int toku_update_descriptor(struct brt_header * h, DESCRIPTOR d, int fd); 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. // 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[] = { ...@@ -210,6 +210,7 @@ const struct logtype logtypes[] = {
{"TXNID", "xid", 0}, {"TXNID", "xid", 0},
{"BYTESTRING", "old_descriptor", 0}, {"BYTESTRING", "old_descriptor", 0},
{"BYTESTRING", "new_descriptor", 0}, {"BYTESTRING", "new_descriptor", 0},
{"BOOL", "update_cmp_descriptor", 0},
NULLFIELD}}, NULLFIELD}},
{0,0,FA{NULLFIELD}} {0,0,FA{NULLFIELD}}
}; };
......
...@@ -869,7 +869,8 @@ static int toku_recover_change_fdescriptor (struct logtype_change_fdescriptor *l ...@@ -869,7 +869,8 @@ static int toku_recover_change_fdescriptor (struct logtype_change_fdescriptor *l
&old_descriptor, &old_descriptor,
&new_descriptor, &new_descriptor,
FALSE, FALSE,
txn txn,
l->update_cmp_descriptor
); );
assert(r==0); assert(r==0);
} }
......
...@@ -30,7 +30,7 @@ change_descriptor(DB_ENV* env, DB* db) { ...@@ -30,7 +30,7 @@ change_descriptor(DB_ENV* env, DB* db) {
DBT descriptor; DBT descriptor;
dbt_init(&descriptor, descriptor_contents, sizeof(descriptor_contents)); dbt_init(&descriptor, descriptor_contents, sizeof(descriptor_contents));
IN_TXN_COMMIT(env, NULL, txn_desc, 0, { 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 #endif
} }
...@@ -52,12 +52,10 @@ do_x1_shutdown (BOOL do_commit, BOOL do_abort) { ...@@ -52,12 +52,10 @@ do_x1_shutdown (BOOL do_commit, BOOL do_abort) {
r = db_create(&dba, env, 0); CKERR(r); 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); r = dba->open(dba, NULL, namea, NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
change_descriptor(env, dba); change_descriptor(env, dba);
dba->update_cmp_descriptor(dba);
r = db_create(&dbb, env, 0); CKERR(r); 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); r = dbb->open(dbb, NULL, nameb, NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
DB_TXN *txn; DB_TXN *txn;
change_descriptor(env, dbb); change_descriptor(env, dbb);
dbb->update_cmp_descriptor(dbb);
r = env->txn_begin(env, NULL, &txn, 0); CKERR(r); r = env->txn_begin(env, NULL, &txn, 0); CKERR(r);
{ {
DBT a={.data="a", .size=2}; DBT a={.data="a", .size=2};
......
...@@ -116,8 +116,7 @@ int test_main(int argc, char * const argv[]) { ...@@ -116,8 +116,7 @@ int test_main(int argc, char * const argv[]) {
DBT desc; DBT desc;
dbt_init(&desc, "foo", sizeof("foo")); dbt_init(&desc, "foo", sizeof("foo"));
IN_TXN_COMMIT(env, NULL, txn, 0, IN_TXN_COMMIT(env, NULL, txn, 0,
CHK(db->change_descriptor(db, txn, &desc, 0))); CHK(db->change_descriptor(db, txn, &desc, DB_UPDATE_CMP_DESCRIPTOR)));
CHK(db->update_cmp_descriptor(db));
pthread_t thd; pthread_t thd;
CHK(toku_pthread_create(&thd, NULL, startA, NULL)); CHK(toku_pthread_create(&thd, NULL, startA, NULL));
......
...@@ -157,10 +157,8 @@ static void run_test(void) { ...@@ -157,10 +157,8 @@ static void run_test(void) {
CHK(db->open(db, txn_create, "foo.db", NULL, DB_BTREE, DB_CREATE, 0666)); CHK(db->open(db, txn_create, "foo.db", NULL, DB_BTREE, DB_CREATE, 0666));
assert(db->descriptor->dbt.size == 0); assert(db->descriptor->dbt.size == 0);
assert(db->cmp_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_desc_four(db);
assert(db->cmp_descriptor->dbt.size == 0);
CHK(db->update_cmp_descriptor(db));
assert_cmp_desc_valid(db); assert_cmp_desc_valid(db);
r = env->create_loader(env, txn_create, &loader, db, 1, &db, NULL, NULL, 0); r = env->create_loader(env, txn_create, &loader, db, 1, &db, NULL, NULL, 0);
CKERR(r); CKERR(r);
......
...@@ -499,12 +499,6 @@ toku_db_rename(DB * db, const char *fname, const char *dbname, const char *newna ...@@ -499,12 +499,6 @@ toku_db_rename(DB * db, const char *fname, const char *dbname, const char *newna
return r; 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. // 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 ...@@ -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; TOKUTXN ttxn = txn ? db_txn_struct_i(txn)->tokutxn : NULL;
DBT old_descriptor; DBT old_descriptor;
BOOL is_db_hot_index = ((flags & DB_IS_HOT_INDEX) != 0); 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); toku_init_dbt(&old_descriptor);
if (!db_opened(db) || !txn || !descriptor || (descriptor->size>0 && !descriptor->data)){ 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 ...@@ -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.size = db->descriptor->dbt.size;
old_descriptor.data = toku_memdup(db->descriptor->dbt.data, 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: cleanup:
if (old_descriptor.data) toku_free(old_descriptor.data); if (old_descriptor.data) toku_free(old_descriptor.data);
return r; return r;
...@@ -1077,7 +1079,6 @@ toku_db_create(DB ** db, DB_ENV * env, u_int32_t flags) { ...@@ -1077,7 +1079,6 @@ toku_db_create(DB ** db, DB_ENV * env, u_int32_t flags) {
#undef SDB #undef SDB
// methods that take the ydb lock in some capacity, // methods that take the ydb lock in some capacity,
// but not from beginning to end // but not from beginning to end
result->update_cmp_descriptor = toku_db_update_cmp_descriptor;
result->del = autotxn_db_del; result->del = autotxn_db_del;
result->put = autotxn_db_put; result->put = autotxn_db_put;
result->update = autotxn_db_update; 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