Commit 438ffcae authored by antirez's avatar antirez
Browse files

Threaded core commands: key unlocking WIP 2.

parent f302c75f
...@@ -171,7 +171,7 @@ void unblockClient(client *c) { ...@@ -171,7 +171,7 @@ void unblockClient(client *c) {
/* Re-execute the command if it was not executed at all since the /* Re-execute the command if it was not executed at all since the
* client was blocked because of key locks. */ * client was blocked because of key locks. */
if (btype == BLOCKED_LOCK) processCommand(c); if (btype == BLOCKED_LOCK) processCommandAndResetClient(c);
} }
/* This function gets called when a blocked client timed out in order to /* This function gets called when a blocked client timed out in order to
......
...@@ -1858,11 +1858,15 @@ void unlockKey(client *c, robj *key, uint64_t owner_id) { ...@@ -1858,11 +1858,15 @@ void unlockKey(client *c, robj *key, uint64_t owner_id) {
listNode *ln = listSearchKey(lk->owners,&lkc); listNode *ln = listSearchKey(lk->owners,&lkc);
if (ln == NULL) return; if (ln == NULL) return;
/* Unlock the key, and if this key dropped to a locked count of /* Remove the lock for thsi owner, and if this key dropped to a locked
* zero, we need to resume the clients in the waiting list. */ * count of zero, we need to resume the clients in the waiting list. */
listDelNode(lk->owners,ln); listDelNode(lk->owners,ln);
if (listLength(lk->owners) != 0) return; if (listLength(lk->owners) != 0) return;
/* There are no longer owners for this lock: unlock the key
* before resuming the clients. */
dictDelete(c->db->locked_keys,key);
listIter li; listIter li;
listRewind(lk->waiting,&li); listRewind(lk->waiting,&li);
while((ln = listNext(&li))) { while((ln = listNext(&li))) {
...@@ -1872,7 +1876,6 @@ void unlockKey(client *c, robj *key, uint64_t owner_id) { ...@@ -1872,7 +1876,6 @@ void unlockKey(client *c, robj *key, uint64_t owner_id) {
blocked->flags & CLIENT_BLOCKED && blocked->flags & CLIENT_BLOCKED &&
blocked->btype == BLOCKED_LOCK) blocked->btype == BLOCKED_LOCK)
{ {
printf("UNBLOCK %llu\n", blocked->id);
/* XXX: Check if the client is yet locked in some other key /* XXX: Check if the client is yet locked in some other key
* before unblocking it? Right now we just unblock it, and * before unblocking it? Right now we just unblock it, and
* it will get blocked again if there are yet keys that are * it will get blocked again if there are yet keys that are
...@@ -1882,10 +1885,7 @@ void unlockKey(client *c, robj *key, uint64_t owner_id) { ...@@ -1882,10 +1885,7 @@ void unlockKey(client *c, robj *key, uint64_t owner_id) {
listDelNode(lk->waiting,ln); listDelNode(lk->waiting,ln);
} }
/* At this point the key is no longer locked by any owner, nor /* Frre the lock state. */
* it has any client in the waiting list. Remove it from the
* dictionary. */
dictDelete(c->db->locked_keys,key);
listRelease(lk->owners); listRelease(lk->owners);
listRelease(lk->waiting); listRelease(lk->waiting);
zfree(lk); zfree(lk);
......
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