Переглянути джерело

Add in separate redis config for the lock and fix a few web -> realtime

James Allen 9 роки тому
батько
коміт
4104ca4889

+ 0 - 4
services/document-updater/app.coffee

@@ -11,10 +11,6 @@ DispatchManager = require('./app/js/DispatchManager')
 Errors = require "./app/js/Errors"
 Errors = require "./app/js/Errors"
 HttpController = require "./app/js/HttpController"
 HttpController = require "./app/js/HttpController"
 
 
-redis = require("redis-sharelatex")
-rclient = redis.createClient(Settings.redis.web)
-
-
 Path = require "path"
 Path = require "path"
 Metrics = require "metrics-sharelatex"
 Metrics = require "metrics-sharelatex"
 Metrics.initialize("doc-updater")
 Metrics.initialize("doc-updater")

+ 1 - 1
services/document-updater/app/coffee/DispatchManager.coffee

@@ -8,7 +8,7 @@ Metrics = require('./Metrics')
 
 
 module.exports = DispatchManager =
 module.exports = DispatchManager =
 	createDispatcher: () ->
 	createDispatcher: () ->
-		client = redis.createClient(Settings.redis.web)
+		client = redis.createClient(Settings.redis.realtime)
 		worker = {
 		worker = {
 			client: client
 			client: client
 			_waitForUpdateThenDispatchWorker: (callback = (error) ->) ->
 			_waitForUpdateThenDispatchWorker: (callback = (error) ->) ->

+ 2 - 4
services/document-updater/app/coffee/LockManager.coffee

@@ -1,7 +1,8 @@
 metrics = require('./Metrics')
 metrics = require('./Metrics')
 Settings = require('settings-sharelatex')
 Settings = require('settings-sharelatex')
 redis = require("redis-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"
 logger = require "logger-sharelatex"
 os = require "os"
 os = require "os"
 crypto = require "crypto"
 crypto = require "crypto"
@@ -11,9 +12,6 @@ PID = process.pid
 RND = crypto.randomBytes(4).toString('hex')
 RND = crypto.randomBytes(4).toString('hex')
 COUNT = 0
 COUNT = 0
 
 
-keys =
-	blockingKey: ({doc_id}) -> "Blocking:#{doc_id}"
-
 module.exports = LockManager =
 module.exports = LockManager =
 	LOCK_TEST_INTERVAL: 50 # 50ms between each test of the lock
 	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
 	MAX_LOCK_WAIT_TIME: 10000 # 10s maximum time to spend trying to get the lock

+ 32 - 9
services/document-updater/config/settings.defaults.coffee

@@ -22,6 +22,12 @@ module.exports =
 			password:""
 			password:""
 			key_schema:
 			key_schema:
 				pendingUpdates: ({doc_id}) -> "PendingUpdates:#{doc_id}"
 				pendingUpdates: ({doc_id}) -> "PendingUpdates:#{doc_id}"
+			# cluster: [{
+			# 	port: "7000"
+			# 	host: "localhost"
+			# }]
+			# key_schema:
+			# 	pendingUpdates: ({doc_id}) -> "PendingUpdates:{#{doc_id}}"
 		documentupdater:
 		documentupdater:
 			port: "6379"
 			port: "6379"
 			host: "localhost"
 			host: "localhost"
@@ -35,15 +41,6 @@ module.exports =
 				projectKey: ({doc_id}) -> "ProjectId:#{doc_id}"
 				projectKey: ({doc_id}) -> "ProjectId:#{doc_id}"
 				docsInProject: ({project_id}) -> "DocsIn:#{project_id}"
 				docsInProject: ({project_id}) -> "DocsIn:#{project_id}"
 				ranges: ({doc_id}) -> "Ranges:#{doc_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: [{
 			# cluster: [{
 			# 	port: "7000"
 			# 	port: "7000"
 			# 	host: "localhost"
 			# 	host: "localhost"
@@ -57,6 +54,32 @@ module.exports =
 			# 	projectKey: ({doc_id}) -> "ProjectId:{#{doc_id}}"
 			# 	projectKey: ({doc_id}) -> "ProjectId:{#{doc_id}}"
 			# 	docsInProject: ({project_id}) -> "DocsIn:{#{project_id}}"
 			# 	docsInProject: ({project_id}) -> "DocsIn:{#{project_id}}"
 			# 	ranges: ({doc_id}) -> "Ranges:{#{doc_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
 	max_doc_length: 2 * 1024 * 1024 # 2mb
 
 

+ 4 - 3
services/document-updater/test/acceptance/coffee/helpers/DocUpdaterClient.coffee

@@ -1,9 +1,10 @@
 Settings = require('settings-sharelatex')
 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)
 request = require("request").defaults(jar: false)
 async = require "async"
 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.subscribe "applied-ops"
 rclient_sub.setMaxListeners(0)
 rclient_sub.setMaxListeners(0)
 	
 	
@@ -17,7 +18,7 @@ module.exports = DocUpdaterClient =
 		rclient_sub.on "message", callback
 		rclient_sub.on "message", callback
 
 
 	sendUpdate: (project_id, doc_id, update, callback = (error) ->) ->
 	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?
 			return callback(error) if error?
 			doc_key = "#{project_id}:#{doc_id}"
 			doc_key = "#{project_id}:#{doc_id}"
 			rclient.sadd "DocsWithPendingUpdates", doc_key, (error) ->
 			rclient.sadd "DocsWithPendingUpdates", doc_key, (error) ->

+ 1 - 1
services/document-updater/test/unit/coffee/DispatchManager/DispatchManagerTests.coffee

@@ -11,7 +11,7 @@ describe "DispatchManager", ->
 			"logger-sharelatex": @logger = { log: sinon.stub() }
 			"logger-sharelatex": @logger = { log: sinon.stub() }
 			"settings-sharelatex": @settings =
 			"settings-sharelatex": @settings =
 				redis:
 				redis:
-					web: {}
+					realtime: {}
 			"redis-sharelatex": @redis = {}
 			"redis-sharelatex": @redis = {}
 		@callback = sinon.stub()
 		@callback = sinon.stub()