diff --git a/services/track-changes/app/coffee/LockManager.coffee b/services/track-changes/app/coffee/LockManager.coffee index 7e7468d1c2..18a764035c 100644 --- a/services/track-changes/app/coffee/LockManager.coffee +++ b/services/track-changes/app/coffee/LockManager.coffee @@ -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" diff --git a/services/track-changes/app/coffee/PackManager.coffee b/services/track-changes/app/coffee/PackManager.coffee index d8069da518..d33978229d 100644 --- a/services/track-changes/app/coffee/PackManager.coffee +++ b/services/track-changes/app/coffee/PackManager.coffee @@ -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 diff --git a/services/track-changes/app/coffee/UpdatesManager.coffee b/services/track-changes/app/coffee/UpdatesManager.coffee index 48423a39ec..af001f7959 100644 --- a/services/track-changes/app/coffee/UpdatesManager.coffee +++ b/services/track-changes/app/coffee/UpdatesManager.coffee @@ -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 diff --git a/services/track-changes/config/settings.defaults.coffee b/services/track-changes/config/settings.defaults.coffee index 084ce7de62..907d3c0033 100755 --- a/services/track-changes/config/settings.defaults.coffee +++ b/services/track-changes/config/settings.defaults.coffee @@ -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" diff --git a/services/track-changes/test/unit/coffee/LockManager/LockManagerTests.coffee b/services/track-changes/test/unit/coffee/LockManager/LockManagerTests.coffee index fd141ef426..ad4df198a9 100644 --- a/services/track-changes/test/unit/coffee/LockManager/LockManagerTests.coffee +++ b/services/track-changes/test/unit/coffee/LockManager/LockManagerTests.coffee @@ -9,7 +9,7 @@ describe "LockManager", -> beforeEach -> @Settings = redis: - web:{} + lock:{} @LockManager = SandboxedModule.require modulePath, requires: "redis-sharelatex": createClient: () => @rclient = diff --git a/services/track-changes/test/unit/coffee/PackManager/PackManagerTests.coffee b/services/track-changes/test/unit/coffee/PackManager/PackManagerTests.coffee index 29c9cf6d3d..bedc65683e 100644 --- a/services/track-changes/test/unit/coffee/PackManager/PackManagerTests.coffee +++ b/services/track-changes/test/unit/coffee/PackManager/PackManagerTests.coffee @@ -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() diff --git a/services/track-changes/test/unit/coffee/UpdatesManager/UpdatesManagerTests.coffee b/services/track-changes/test/unit/coffee/UpdatesManager/UpdatesManagerTests.coffee index c422fffec0..88f1c7998a 100644 --- a/services/track-changes/test/unit/coffee/UpdatesManager/UpdatesManagerTests.coffee +++ b/services/track-changes/test/unit/coffee/UpdatesManager/UpdatesManagerTests.coffee @@ -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()