From 4104ca48894d0b064939ff285e101a435448c027 Mon Sep 17 00:00:00 2001 From: James Allen Date: Wed, 3 May 2017 16:27:32 +0100 Subject: [PATCH] Add in separate redis config for the lock and fix a few web -> realtime --- services/document-updater/app.coffee | 4 -- .../app/coffee/DispatchManager.coffee | 2 +- .../app/coffee/LockManager.coffee | 6 +-- .../config/settings.defaults.coffee | 41 +++++++++++++++---- .../coffee/helpers/DocUpdaterClient.coffee | 7 ++-- .../DispatchManagerTests.coffee | 2 +- 6 files changed, 40 insertions(+), 22 deletions(-) diff --git a/services/document-updater/app.coffee b/services/document-updater/app.coffee index eb0ea771aa..d036beda55 100644 --- a/services/document-updater/app.coffee +++ b/services/document-updater/app.coffee @@ -11,10 +11,6 @@ DispatchManager = require('./app/js/DispatchManager') Errors = require "./app/js/Errors" HttpController = require "./app/js/HttpController" -redis = require("redis-sharelatex") -rclient = redis.createClient(Settings.redis.web) - - Path = require "path" Metrics = require "metrics-sharelatex" Metrics.initialize("doc-updater") diff --git a/services/document-updater/app/coffee/DispatchManager.coffee b/services/document-updater/app/coffee/DispatchManager.coffee index 28397185dc..b7e50291b0 100644 --- a/services/document-updater/app/coffee/DispatchManager.coffee +++ b/services/document-updater/app/coffee/DispatchManager.coffee @@ -8,7 +8,7 @@ Metrics = require('./Metrics') module.exports = DispatchManager = createDispatcher: () -> - client = redis.createClient(Settings.redis.web) + client = redis.createClient(Settings.redis.realtime) worker = { client: client _waitForUpdateThenDispatchWorker: (callback = (error) ->) -> diff --git a/services/document-updater/app/coffee/LockManager.coffee b/services/document-updater/app/coffee/LockManager.coffee index 289075bca9..d237b51feb 100644 --- a/services/document-updater/app/coffee/LockManager.coffee +++ b/services/document-updater/app/coffee/LockManager.coffee @@ -1,7 +1,8 @@ metrics = require('./Metrics') Settings = require('settings-sharelatex') redis = require("redis-sharelatex") -rclient = redis.createClient(Settings.redis.web) +rclient = redis.createClient(Settings.redis.lock) +keys = Settings.redis.lock.key_schema logger = require "logger-sharelatex" os = require "os" crypto = require "crypto" @@ -11,9 +12,6 @@ PID = process.pid RND = crypto.randomBytes(4).toString('hex') COUNT = 0 -keys = - blockingKey: ({doc_id}) -> "Blocking:#{doc_id}" - module.exports = LockManager = LOCK_TEST_INTERVAL: 50 # 50ms between each test of the lock MAX_LOCK_WAIT_TIME: 10000 # 10s maximum time to spend trying to get the lock diff --git a/services/document-updater/config/settings.defaults.coffee b/services/document-updater/config/settings.defaults.coffee index ae5ff0522b..b06b9d8bf9 100755 --- a/services/document-updater/config/settings.defaults.coffee +++ b/services/document-updater/config/settings.defaults.coffee @@ -22,6 +22,12 @@ module.exports = password:"" key_schema: pendingUpdates: ({doc_id}) -> "PendingUpdates:#{doc_id}" + # cluster: [{ + # port: "7000" + # host: "localhost" + # }] + # key_schema: + # pendingUpdates: ({doc_id}) -> "PendingUpdates:{#{doc_id}}" documentupdater: port: "6379" host: "localhost" @@ -35,15 +41,6 @@ module.exports = projectKey: ({doc_id}) -> "ProjectId:#{doc_id}" docsInProject: ({project_id}) -> "DocsIn:#{project_id}" ranges: ({doc_id}) -> "Ranges:#{doc_id}" - history: - port:"6379" - host:"localhost" - password:"" - key_schema: - uncompressedHistoryOps: ({doc_id}) -> "UncompressedHistoryOps:#{doc_id}" - docsWithHistoryOps: ({project_id}) -> "DocsWithHistoryOps:#{project_id}" - - # cluster: [{ # port: "7000" # host: "localhost" @@ -57,6 +54,32 @@ module.exports = # projectKey: ({doc_id}) -> "ProjectId:{#{doc_id}}" # docsInProject: ({project_id}) -> "DocsIn:{#{project_id}}" # ranges: ({doc_id}) -> "Ranges:{#{doc_id}}" + history: + port:"6379" + host:"localhost" + password:"" + key_schema: + uncompressedHistoryOps: ({doc_id}) -> "UncompressedHistoryOps:#{doc_id}" + docsWithHistoryOps: ({project_id}) -> "DocsWithHistoryOps:#{project_id}" + # cluster: [{ + # port: "7000" + # host: "localhost" + # }] + # key_schema: + # uncompressedHistoryOps: ({doc_id}) -> "UncompressedHistoryOps:{#{doc_id}}" + # docsWithHistoryOps: ({project_id}) -> "DocsWithHistoryOps:{#{project_id}}" + lock: + port:"6379" + host:"localhost" + password:"" + key_schema: + blockingKey: ({doc_id}) -> "Blocking:#{doc_id}" + # cluster: [{ + # port: "7000" + # host: "localhost" + # }] + # key_schema: + # blockingKey: ({doc_id}) -> "Blocking:{#{doc_id}}" max_doc_length: 2 * 1024 * 1024 # 2mb diff --git a/services/document-updater/test/acceptance/coffee/helpers/DocUpdaterClient.coffee b/services/document-updater/test/acceptance/coffee/helpers/DocUpdaterClient.coffee index 7755b656f1..4b57e0659f 100644 --- a/services/document-updater/test/acceptance/coffee/helpers/DocUpdaterClient.coffee +++ b/services/document-updater/test/acceptance/coffee/helpers/DocUpdaterClient.coffee @@ -1,9 +1,10 @@ Settings = require('settings-sharelatex') -rclient = require("redis-sharelatex").createClient(Settings.redis.web) +rclient = require("redis-sharelatex").createClient(Settings.redis.realtime) +keys = Settings.redis.realtime.key_schema request = require("request").defaults(jar: false) async = require "async" -rclient_sub = require("redis-sharelatex").createClient(Settings.redis.web) +rclient_sub = require("redis-sharelatex").createClient(Settings.redis.realtime) rclient_sub.subscribe "applied-ops" rclient_sub.setMaxListeners(0) @@ -17,7 +18,7 @@ module.exports = DocUpdaterClient = rclient_sub.on "message", callback sendUpdate: (project_id, doc_id, update, callback = (error) ->) -> - rclient.rpush "PendingUpdates:#{doc_id}", JSON.stringify(update), (error)-> + rclient.rpush keys.pendingUpdates({doc_id}), JSON.stringify(update), (error)-> return callback(error) if error? doc_key = "#{project_id}:#{doc_id}" rclient.sadd "DocsWithPendingUpdates", doc_key, (error) -> diff --git a/services/document-updater/test/unit/coffee/DispatchManager/DispatchManagerTests.coffee b/services/document-updater/test/unit/coffee/DispatchManager/DispatchManagerTests.coffee index eddb1eaddb..a82a40af04 100644 --- a/services/document-updater/test/unit/coffee/DispatchManager/DispatchManagerTests.coffee +++ b/services/document-updater/test/unit/coffee/DispatchManager/DispatchManagerTests.coffee @@ -11,7 +11,7 @@ describe "DispatchManager", -> "logger-sharelatex": @logger = { log: sinon.stub() } "settings-sharelatex": @settings = redis: - web: {} + realtime: {} "redis-sharelatex": @redis = {} @callback = sinon.stub()