Migrate lock to be redis-cluster compatible

This commit is contained in:
James Allen 2017-05-15 10:34:24 +01:00
parent 238638b906
commit fb6e028182
7 changed files with 17 additions and 6 deletions

View file

@ -1,6 +1,6 @@
Settings = require "settings-sharelatex"
redis = require("redis-sharelatex")
rclient = redis.createClient(Settings.redis.web)
rclient = redis.createClient(Settings.redis.lock)
os = require "os"
crypto = require "crypto"
logger = require "logger-sharelatex"

View file

@ -6,6 +6,8 @@ LockManager = require "./LockManager"
MongoAWS = require "./MongoAWS"
Metrics = require "metrics-sharelatex"
ProjectIterator = require "./ProjectIterator"
Settings = require "settings-sharelatex"
keys = Settings.redis.lock.key_schema
# Sharejs operations are stored in a 'pack' object
#
@ -319,7 +321,7 @@ module.exports = PackManager =
insertPacksIntoIndexWithLock: (project_id, doc_id, newPacks, callback) ->
LockManager.runWithLock(
"HistoryIndexLock:#{doc_id}",
keys.historyIndexLock({doc_id}),
(releaseLock) ->
PackManager._insertPacksIntoIndex project_id, doc_id, newPacks, releaseLock
callback
@ -438,7 +440,7 @@ module.exports = PackManager =
markPackAsFinalisedWithLock: (project_id, doc_id, pack_id, callback) ->
LockManager.runWithLock(
"HistoryLock:#{doc_id}",
keys.historyLock({doc_id}),
(releaseLock) ->
PackManager._markPackAsFinalised project_id, doc_id, pack_id, releaseLock
callback

View file

@ -9,6 +9,7 @@ logger = require "logger-sharelatex"
async = require "async"
_ = require "underscore"
Settings = require "settings-sharelatex"
keys = Settings.redis.lock.key_schema
module.exports = UpdatesManager =
compressAndSaveRawUpdates: (project_id, doc_id, rawUpdates, temporary, callback = (error) ->) ->
@ -126,7 +127,7 @@ module.exports = UpdatesManager =
UpdatesManager._prepareDocForUpdates project_id, doc_id, (error) ->
return callback(error) if error?
LockManager.runWithLock(
"HistoryLock:#{doc_id}",
keys.historyLock({doc_id}),
(releaseLock) ->
UpdatesManager.processUncompressedUpdates project_id, doc_id, temporary, releaseLock
callback

View file

@ -18,10 +18,13 @@ module.exports =
user: "sharelatex"
pass: "password"
redis:
web:
lock:
host: "localhost"
port: 6379
pass: ""
key_schema:
historyLock: ({doc_id}) -> "HistoryLock:#{doc_id}"
historyIndexLock: ({project_id}) -> "HistoryIndexLock:#{project_id}"
history:
port:"6379"
host:"localhost"

View file

@ -9,7 +9,7 @@ describe "LockManager", ->
beforeEach ->
@Settings =
redis:
web:{}
lock:{}
@LockManager = SandboxedModule.require modulePath, requires:
"redis-sharelatex":
createClient: () => @rclient =

View file

@ -21,6 +21,8 @@ describe "PackManager", ->
"./MongoAWS": {}
"logger-sharelatex": { log: sinon.stub(), error: sinon.stub() }
'metrics-sharelatex': {inc: ()->}
"settings-sharelatex":
redis: lock: key_schema: {}
@callback = sinon.stub()
@doc_id = ObjectId().toString()
@project_id = ObjectId().toString()

View file

@ -17,6 +17,9 @@ describe "UpdatesManager", ->
"./UpdateTrimmer": @UpdateTrimmer = {}
"./DocArchiveManager": @DocArchiveManager = {}
"logger-sharelatex": { log: sinon.stub(), error: sinon.stub() }
"settings-sharelatex":
redis: lock: key_schema:
historyLock: ({doc_id}) -> "HistoryLock:#{doc_id}"
@doc_id = "doc-id-123"
@project_id = "project-id-123"
@callback = sinon.stub()