Aaron Schulz has uploaded a new change for review.
https://gerrit.wikimedia.org/r/59800
Change subject: Factored JobQueueRedis::redisEval() into
RedisConnRef::luaEval().
......................................................................
Factored JobQueueRedis::redisEval() into RedisConnRef::luaEval().
Change-Id: I1b4bb4f4bb5e25fc3f358c9e2b16e4672584c68b
---
M includes/clientpool/RedisConnectionPool.php
M includes/job/JobQueueRedis.php
2 files changed, 38 insertions(+), 33 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/00/59800/1
diff --git a/includes/clientpool/RedisConnectionPool.php
b/includes/clientpool/RedisConnectionPool.php
index 7a29154..728029b 100644
--- a/includes/clientpool/RedisConnectionPool.php
+++ b/includes/clientpool/RedisConnectionPool.php
@@ -302,6 +302,38 @@
return call_user_func_array( array( $this->conn, $name ),
$arguments );
}
+ /**
+ * @param string $script
+ * @param array $params
+ * @param integer $numKeys
+ * @return mixed
+ * @throws RedisException
+ */
+ protected function luaEval( $script, array $params, $numKeys ) {
+ $sha1 = sha1( $script ); // 40 char hex
+ $conn = $this->conn; // convenience
+
+ // Try to run the server-side cached copy of the script
+ $conn->clearLastError();
+ $res = $conn->evalSha( $sha1, $params, $numKeys );
+ // If the script is not in cache, use eval() to retry and cache
it
+ if ( $conn->getLastError() && $conn->script( 'exists', $sha1 )
=== array( 0 ) ) {
+ $conn->clearLastError();
+ $res = $conn->eval( $script, $params, $numKeys );
+ wfDebugLog( 'redis', "Used eval() for Lua script
$sha1." );
+ }
+
+ if ( $conn->getLastError() ) { // script bug?
+ wfDebugLog( 'redis', "Lua script error: " .
$conn->getLastError() );
+ }
+
+ return $res;
+ }
+
+ /**
+ * @param RedisConnRef $conn
+ * @return bool
+ */
public function isConnIdentical( Redis $conn ) {
return $this->conn === $conn;
}
diff --git a/includes/job/JobQueueRedis.php b/includes/job/JobQueueRedis.php
index d30e20e..3c3f48b 100644
--- a/includes/job/JobQueueRedis.php
+++ b/includes/job/JobQueueRedis.php
@@ -263,7 +263,7 @@
end
return pushed
LUA;
- return $this->redisEval( $conn, $script,
+ return $conn->luaEval( $script,
array_merge(
array(
$this->getQueueKey( 'l-unclaimed' ), #
KEYS[1]
@@ -346,7 +346,7 @@
-- Return the job data
return item
LUA;
- return $this->redisEval( $conn, $script,
+ return $conn->luaEval( $script,
array(
$this->getQueueKey( 'l-unclaimed' ), # KEYS[1]
$this->getQueueKey( 'h-sha1ById' ), # KEYS[2]
@@ -377,7 +377,7 @@
redis.call('hIncrBy',KEYS[5],id,1)
return redis.call('hGet',KEYS[6],id)
LUA;
- return $this->redisEval( $conn, $script,
+ return $conn->luaEval( $script,
array(
$this->getQueueKey( 'l-unclaimed' ), # KEYS[1]
$this->getQueueKey( 'h-sha1ById' ), # KEYS[2]
@@ -413,7 +413,7 @@
-- Delete the job data itself
return redis.call('hDel',KEYS[3],ARGV[1])
LUA;
- $res = $this->redisEval( $conn, $script,
+ $res = $conn->luaEval( $script,
array(
$this->getQueueKey( 'z-claimed'
), # KEYS[1]
$this->getQueueKey(
'h-attempts' ), # KEYS[2]
@@ -567,7 +567,7 @@
end
return #ids
LUA;
- $count += (int)$this->redisEval( $conn, $script,
+ $count += (int)$conn->luaEval( $script,
array(
$this->getQueueKey( 'z-delayed' ), //
KEYS[1]
$this->getQueueKey( 'l-unclaimed' ), //
KEYS[2]
@@ -633,7 +633,7 @@
end
return {released,abandoned,pruned}
LUA;
- $res = $this->redisEval( $conn, $script,
+ $res = $conn->luaEval( $script,
array(
$this->getQueueKey( 'z-claimed' ), #
KEYS[1]
$this->getQueueKey( 'h-attempts' ), #
KEYS[2]
@@ -676,33 +676,6 @@
);
}
return $tasks;
- }
-
- /**
- * @param RedisConnRef $conn
- * @param string $script
- * @param array $params
- * @param integer $numKeys
- * @return mixed
- */
- protected function redisEval( RedisConnRef $conn, $script, array
$params, $numKeys ) {
- $sha1 = sha1( $script ); // 40 char hex
-
- // Try to run the server-side cached copy of the script
- $conn->clearLastError();
- $res = $conn->evalSha( $sha1, $params, $numKeys );
- // If the script is not in cache, use eval() to retry and cache
it
- if ( $conn->getLastError() && $conn->script( 'exists', $sha1 )
=== array( 0 ) ) {
- $conn->clearLastError();
- $res = $conn->eval( $script, $params, $numKeys );
- wfDebugLog( 'JobQueueRedis', "Used eval() for Lua
script $sha1." );
- }
-
- if ( $conn->getLastError() ) { // script bug?
- wfDebugLog( 'JobQueueRedis', "Lua script error: " .
$conn->getLastError() );
- }
-
- return $res;
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/59800
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1b4bb4f4bb5e25fc3f358c9e2b16e4672584c68b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits