Merge pull request #500 from sharelatex/ja-rename-lock

Rename lock to avoid potential conflict with doc updater
This commit is contained in:
James Allen 2017-05-11 15:29:36 +01:00 committed by GitHub
commit cb51b1ada1
4 changed files with 9 additions and 9 deletions

View file

@ -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)->

View file

@ -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', ()->

View file

@ -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()

View file

@ -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", ->