Fixed locking in JobQueueAggregatorRedis
authorAaron Schulz <aschulz@wikimedia.org>
Sun, 29 Dec 2013 21:44:33 +0000 (13:44 -0800)
committerAaron Schulz <aschulz@wikimedia.org>
Sun, 29 Dec 2013 22:57:19 +0000 (14:57 -0800)
* The old code would still bump the lock TTL on failure,
  so if processes kept trying to acquire it and the one
  that had it crashed, nothing would ever do anything.

Change-Id: If3fe7b75364204f399fb4caf8bd39204ab51b353

includes/job/aggregator/JobQueueAggregatorRedis.php

index 057a587..c654933 100644 (file)
@@ -104,10 +104,12 @@ class JobQueueAggregatorRedis extends JobQueueAggregator {
                                }
                        } else { // cache miss
                                // Avoid duplicated effort
+                               $rand = wfRandomString( 32 );
                                $conn->multi( Redis::MULTI );
-                               $conn->setnx( $this->getReadyQueueKey() . ":lock", 1 );
-                               $conn->expire( $this->getReadyQueueKey() . ":lock", 3600 );
+                               $conn->setex( "{$rand}:lock", 3600, 1 );
+                               $conn->renamenx( "{$rand}:lock", $this->getReadyQueueKey() . ":lock" );
                                if ( $conn->exec() !== array( true, true ) ) { // lock
+                                       $conn->delete( "{$rand}:lock" );
                                        return array(); // already in progress
                                }