Commit 6e14e934 authored by Yoni Fogel's avatar Yoni Fogel

Addresses #1963, #1866 refs[t:1963] refs[t:1866] Minor optimizations to...

Addresses #1963, #1866 refs[t:1963] refs[t:1866] Minor optimizations to maybe_get_and_pin_clean, associate with shortcut query

git-svn-id: file:///svn/toku/tokudb@14169 c7de825b-a66e-492c-adef-691d508d4ae1
parent 316b9c96
......@@ -3946,15 +3946,17 @@ brt_cursor_shortcut (BRT_CURSOR cursor, int direction, u_int32_t limit, BRT_GET_
#if TOKU_MULTIPLE_MAIN_THREADS
static int
brt_cursor_maybe_get_and_pin_leaf(BRT_CURSOR brtcursor, BRTNODE* leafp) {
int r = toku_cachetable_maybe_get_and_pin(brtcursor->brt->cf,
brtcursor->leaf_info.blocknumber,
brtcursor->leaf_info.fullhash,
&brtcursor->leaf_info.node);
void *leafv;
int r = toku_cachetable_maybe_get_and_pin_clean(brtcursor->brt->cf,
brtcursor->leaf_info.blocknumber,
brtcursor->leaf_info.fullhash,
&leafv);
assert(r==0);
if (r == 0) {
BRTNODE leaf = brtcursor->leaf_info.node;
assert(leaf->height == 0); // verify that returned node is leaf...
assert(leaf->u.l.buffer == toku_omt_cursor_get_omt(brtcursor->omtcursor)); // ... and has right omt
*leafp = leaf;
brtcursor->leaf_info.node = leafv;
assert(brtcursor->leaf_info.node->height == 0); // verify that returned node is leaf...
assert(brtcursor->leaf_info.node->u.l.buffer == toku_omt_cursor_get_omt(brtcursor->omtcursor)); // ... and has right omt
*leafp = brtcursor->leaf_info.node;
}
return r;
}
......
......@@ -1148,7 +1148,7 @@ int toku_cachetable_maybe_get_and_pin (CACHEFILE cachefile, CACHEKEY key, u_int3
for (p=ct->table[fullhash&(ct->table_size-1)]; p; p=p->hash_chain) {
count++;
if (p->key.b==key.b && p->cachefile==cachefile) {
if (p->state == CTPAIR_IDLE && //If not idle, will require a stall and/or will be clean once it is idle
if (p->state == CTPAIR_IDLE && //If not idle, will require a stall and/or will be clean once it is idle, or might be GONE once not idle
!p->checkpoint_pending && //If checkpoint pending, we would need to first write it, which would make it clean
p->dirty &&
rwlock_try_prefer_read_lock(&p->rwlock, ct->mutex) == 0 //Grab read lock. If any stall would be necessary that means it would be clean AFTER the stall, so don't even try to stall
......@@ -1166,6 +1166,9 @@ int toku_cachetable_maybe_get_and_pin (CACHEFILE cachefile, CACHEKEY key, u_int3
return r;
}
//Used by shortcut query path.
//Same as toku_cachetable_maybe_get_and_pin except that we don't care if the node is clean or dirty (return the node regardless).
//All other conditions remain the same.
int toku_cachetable_maybe_get_and_pin_clean (CACHEFILE cachefile, CACHEKEY key, u_int32_t fullhash, void**value) {
CACHETABLE ct = cachefile->cachetable;
PAIR p;
......@@ -1174,20 +1177,19 @@ int toku_cachetable_maybe_get_and_pin_clean (CACHEFILE cachefile, CACHEKEY key,
cachetable_lock(ct);
for (p=ct->table[fullhash&(ct->table_size-1)]; p; p=p->hash_chain) {
count++;
if (p->key.b==key.b && p->cachefile==cachefile && p->state == CTPAIR_IDLE) {
if (p->checkpoint_pending) {
goto finish;
}
*value = p->value;
rwlock_read_lock(&p->rwlock, ct->mutex);
lru_touch(ct,p);
r = 0;
//printf("%s:%d cachetable_maybe_get_and_pin(%lld)--> %p\n", __FILE__, __LINE__, key, *value);
if (p->key.b==key.b && p->cachefile==cachefile) {
if (p->state == CTPAIR_IDLE && //If not idle, will require a stall and/or might be GONE once not idle
!p->checkpoint_pending && //If checkpoint pending, we would need to first write it, which would make it clean (if the pin would be used for writes. If would be used for read-only we could return it, but that would increase complexity)
rwlock_try_prefer_read_lock(&p->rwlock, ct->mutex) == 0 //Grab read lock only if no stall required
) {
*value = p->value;
lru_touch(ct,p);
r = 0;
//printf("%s:%d cachetable_maybe_get_and_pin_clean(%lld)--> %p\n", __FILE__, __LINE__, key, *value);
}
break;
}
}
finish:
note_hash_count(count);
cachetable_unlock(ct);
return r;
......
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