Просмотр исходного кода

Rename lock to avoid potential conflict with doc updater

James Allen 9 лет назад
Родитель
Сommit
3bfd92dd9c

+ 6 - 6
services/web/app/coffee/infrastructure/LockManager.coffee

@@ -9,17 +9,17 @@ module.exports = LockManager =
 	MAX_LOCK_WAIT_TIME: 10000 # 10s maximum time to spend trying to get the lock
 	REDIS_LOCK_EXPIRY: 30 # seconds. Time until lock auto expires in redis.
 
-	_blockingKey : (key)-> "Blocking:"+key
+	_blockingKey : (key)-> "lock:web:{#{key}}"
 
 	tryLock : (key, callback = (err, isFree)->)->
 		rclient.set LockManager._blockingKey(key), "locked", "EX", LockManager.REDIS_LOCK_EXPIRY, "NX", (err, gotLock)->
 			return callback(err) if err?
 			if gotLock == "OK"
-				metrics.inc "doc-not-blocking"
+				metrics.inc "lock-not-blocking"
 				callback err, true
 			else
-				metrics.inc "doc-blocking"
-				logger.log key: key, redis_response: gotLock, "doc is locked"
+				metrics.inc "lock-blocking"
+				logger.log key: key, redis_response: gotLock, "lock is locked"
 				callback err, false
 
 	getLock: (key, callback = (error) ->) ->
@@ -42,10 +42,10 @@ module.exports = LockManager =
 			return callback(err) if err?
 			exists = parseInt replys[0]
 			if exists == 1
-				metrics.inc "doc-blocking"
+				metrics.inc "lock-blocking"
 				callback err, false
 			else
-				metrics.inc "doc-not-blocking"
+				metrics.inc "lock-not-blocking"
 				callback err, true
 
 	releaseLock: (key, callback)->

+ 1 - 1
services/web/test/UnitTests/coffee/infrastructure/LockManager/CheckingTheLock.coffee

@@ -4,7 +4,7 @@ path = require('path')
 modulePath = path.join __dirname, '../../../../../app/js/infrastructure/LockManager.js'
 project_id = 1234
 doc_id     = 5678
-blockingKey = "Blocking:#{doc_id}"
+blockingKey = "lock:web:{#{doc_id}}"
 SandboxedModule = require('sandboxed-module')
 
 describe 'LockManager - checking the lock', ()->

+ 1 - 1
services/web/test/UnitTests/coffee/infrastructure/LockManager/ReleasingTheLock.coffee

@@ -21,6 +21,6 @@ describe 'LockManager - releasing the lock', ()->
 
 	it 'should put a all data into memory', (done)->
 		LockManager.releaseLock doc_id, ->
-			deleteStub.calledWith("Blocking:#{doc_id}").should.equal true
+			deleteStub.calledWith("lock:web:{#{doc_id}}").should.equal true
 			done()
 

+ 1 - 1
services/web/test/UnitTests/coffee/infrastructure/LockManager/tryLockTests.coffee

@@ -24,7 +24,7 @@ describe 'LockManager - trying the lock', ->
 			@LockManager.tryLock @doc_id, @callback
 
 		it "should set the lock key with an expiry if it is not set", ->
-			@set.calledWith("Blocking:#{@doc_id}", "locked", "EX", 30, "NX")
+			@set.calledWith("lock:web:{#{@doc_id}}", "locked", "EX", 30, "NX")
 				.should.equal true
 
 		it "should return the callback with true", ->