Commit 360bea3e authored by Yoni Fogel's avatar Yoni Fogel

[t:2506] [t:2507] Fix locking mechanism for unpin_and_remove

We mistakenly thought that the workqueue lock was the same as the cachetable lock

git-svn-id: file:///svn/toku/tokudb@19188 c7de825b-a66e-492c-adef-691d508d4ae1
parent b93d3411
...@@ -1610,9 +1610,12 @@ int toku_cachefile_prefetch(CACHEFILE cf, CACHEKEY key, u_int32_t fullhash, ...@@ -1610,9 +1610,12 @@ int toku_cachefile_prefetch(CACHEFILE cf, CACHEKEY key, u_int32_t fullhash,
cachetable_lock(ct); cachetable_lock(ct);
// lookup // lookup
PAIR p; PAIR p;
for (p = ct->table[fullhash&(ct->table_size-1)]; p; p = p->hash_chain) for (p = ct->table[fullhash&(ct->table_size-1)]; p; p = p->hash_chain) {
if (p->key.b==key.b && p->cachefile==cf) if (p->key.b==key.b && p->cachefile==cf) {
//Maybe check for pending and do write_pair_for_checkpoint()?
break; break;
}
}
// if not found then create a pair in the READING state and fetch it // if not found then create a pair in the READING state and fetch it
if (p == 0) { if (p == 0) {
...@@ -1890,16 +1893,20 @@ int toku_cachetable_unpin_and_remove (CACHEFILE cachefile, CACHEKEY key) { ...@@ -1890,16 +1893,20 @@ int toku_cachetable_unpin_and_remove (CACHEFILE cachefile, CACHEKEY key) {
//this pair. //this pair.
assert(rwlock_blocked_writers(&p->rwlock)==1); //Only one checkpoint thread. assert(rwlock_blocked_writers(&p->rwlock)==1); //Only one checkpoint thread.
// If anyone is waiting on write lock, let them finish. // If anyone is waiting on write lock, let them finish.
cachetable_unlock(ct);
struct workqueue cq; struct workqueue cq;
workqueue_init(&cq); workqueue_init(&cq);
p->cq = &cq; p->cq = &cq;
WORKITEM wi = 0; WORKITEM wi = 0;
r = workqueue_deq(&cq, &wi, 0); r = workqueue_deq(&cq, &wi, 1);
//Writer is now done. //Writer is now done.
assert(r == 0); assert(r == 0);
PAIR pp = workitem_arg(wi); PAIR pp = workitem_arg(wi);
assert(pp == p); assert(pp == p);
//We are holding the write lock on the pair //We are holding the write lock on the pair
cachetable_lock(ct);
assert(rwlock_writers(&p->rwlock) == 1); assert(rwlock_writers(&p->rwlock) == 1);
assert(rwlock_users(&p->rwlock) == 1); assert(rwlock_users(&p->rwlock) == 1);
cachetable_complete_write_pair(ct, p, TRUE); cachetable_complete_write_pair(ct, p, TRUE);
......
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