mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-23 05:32:48 +00:00
Refactor TCP redis monitoring to be more explicit
This commit is contained in:
parent
8ef03c3d2f
commit
414ab5d6a9
5 changed files with 40 additions and 42 deletions
|
@ -18,7 +18,7 @@ class Client
|
|||
}
|
||||
)
|
||||
|
||||
monitorAndReconnect: () ->
|
||||
monitorTcpAndReconnect: () ->
|
||||
for client in @clients
|
||||
if client.driver == "ioredis"
|
||||
@_monitorCluster(client.rclient)
|
||||
|
@ -28,18 +28,18 @@ class Client
|
|||
# Nodes can come and go as the cluster moves/heals, so each heartbeat
|
||||
# we ask again for the currently known nodes.
|
||||
for node in rclient.nodes("all")
|
||||
do (node) =>
|
||||
timer = setTimeout () =>
|
||||
logger.error {err: new Error("Node timed out, reconnecting"), key: node.options.key}
|
||||
node.stream.destroy()
|
||||
timer = null
|
||||
, @HEARTBEAT_TIMEOUT
|
||||
node.ping (err) ->
|
||||
if !err?
|
||||
clearTimeout timer
|
||||
timer = null
|
||||
@_checkNode(node)
|
||||
, @HEARTBEAT_INTERVAL
|
||||
|
||||
|
||||
_checkNode: (node) ->
|
||||
timer = setTimeout () ->
|
||||
logger.error {err: new Error("Node timed out, reconnecting"), key: node.options.key}
|
||||
# Discussion of application layer monitoring recommends this way of reconnecting at https://github.com/luin/ioredis/issues/275
|
||||
node.stream.destroy()
|
||||
, @HEARTBEAT_TIMEOUT
|
||||
node.ping (err) ->
|
||||
if !err?
|
||||
clearTimeout timer
|
||||
|
||||
class MultiClient
|
||||
constructor: (@clients) ->
|
||||
|
|
|
@ -10,7 +10,7 @@ Errors = require "./Errors"
|
|||
# Make times easy to read
|
||||
minutes = 60 # seconds for Redis expire
|
||||
|
||||
rclient.monitorAndReconnect()
|
||||
rclient.monitorTcpAndReconnect()
|
||||
|
||||
module.exports = RedisManager =
|
||||
putDocInMemory : (project_id, doc_id, docLines, version, _callback)->
|
||||
|
|
|
@ -21,33 +21,31 @@ module.exports =
|
|||
host:"localhost"
|
||||
password:""
|
||||
documentupdater:
|
||||
port:"6379"
|
||||
host:"localhost"
|
||||
password:""
|
||||
key_schema:
|
||||
blockingKey: ({doc_id}) -> "Blocking:#{doc_id}"
|
||||
docLines: ({doc_id}) -> "doclines:#{doc_id}"
|
||||
docOps: ({doc_id}) -> "DocOps:#{doc_id}"
|
||||
docVersion: ({doc_id}) -> "DocVersion:#{doc_id}"
|
||||
projectKey: ({doc_id}) -> "ProjectId:#{doc_id}"
|
||||
pendingUpdates: ({doc_id}) -> "PendingUpdates:#{doc_id}"
|
||||
docsInProject: ({project_id}) -> "DocsIn:#{project_id}"
|
||||
# port:"6379"
|
||||
# host:"localhost"
|
||||
# password:""
|
||||
# key_schema:
|
||||
# blockingKey: ({doc_id}) -> "Blocking:#{doc_id}"
|
||||
# docLines: ({doc_id}) -> "doclines:#{doc_id}"
|
||||
# docOps: ({doc_id}) -> "DocOps:#{doc_id}"
|
||||
# docVersion: ({doc_id}) -> "DocVersion:#{doc_id}"
|
||||
# projectKey: ({doc_id}) -> "ProjectId:#{doc_id}"
|
||||
# docsInProject: ({project_id}) -> "DocsIn:#{project_id}"
|
||||
# To use Redis cluster, configure the backend as follows:
|
||||
# [{
|
||||
# primary: true
|
||||
# cluster: [{
|
||||
# port: "7000"
|
||||
# host: "localhost"
|
||||
# }]
|
||||
# key_schema:
|
||||
# blockingKey: ({doc_id}) -> "Blocking:{#{doc_id}}"
|
||||
# docLines: ({doc_id}) -> "doclines:{#{doc_id}}"
|
||||
# docOps: ({doc_id}) -> "DocOps:{#{doc_id}}"
|
||||
# docVersion: ({doc_id}) -> "DocVersion:{#{doc_id}}"
|
||||
# projectKey: ({doc_id}) -> "ProjectId:{#{doc_id}}"
|
||||
# pendingUpdates: ({doc_id}) -> "PendingUpdates:{#{doc_id}}"
|
||||
# docsInProject: ({project_id}) -> "DocsIn:{#{project_id}}"
|
||||
# }]
|
||||
[{
|
||||
primary: true
|
||||
cluster: [{
|
||||
port: "7000"
|
||||
host: "localhost"
|
||||
}]
|
||||
key_schema:
|
||||
blockingKey: ({doc_id}) -> "Blocking:{#{doc_id}}"
|
||||
docLines: ({doc_id}) -> "doclines:{#{doc_id}}"
|
||||
docOps: ({doc_id}) -> "DocOps:{#{doc_id}}"
|
||||
docVersion: ({doc_id}) -> "DocVersion:{#{doc_id}}"
|
||||
projectKey: ({doc_id}) -> "ProjectId:{#{doc_id}}"
|
||||
docsInProject: ({project_id}) -> "DocsIn:{#{project_id}}"
|
||||
}]
|
||||
|
||||
max_doc_length: 2 * 1024 * 1024 # 2mb
|
||||
|
||||
|
|
|
@ -307,10 +307,10 @@ describe "RedisBackend", ->
|
|||
}, "error in redis backend")
|
||||
.should.equal true
|
||||
|
||||
describe "monitorAndReconnect", ->
|
||||
describe "monitorTcpAndReconnect", ->
|
||||
beforeEach ->
|
||||
@client._monitorCluster = sinon.stub()
|
||||
@client.monitorAndReconnect()
|
||||
@client.monitorTcpAndReconnect()
|
||||
|
||||
it "should monitor the cluster client", ->
|
||||
@client._monitorCluster
|
||||
|
|
|
@ -10,7 +10,7 @@ describe "RedisManager", ->
|
|||
@rclient =
|
||||
auth: () ->
|
||||
exec: sinon.stub()
|
||||
monitorAndReconnect: () ->
|
||||
monitorTcpAndReconnect: () ->
|
||||
@rclient.multi = () => @rclient
|
||||
@RedisManager = SandboxedModule.require modulePath, requires:
|
||||
"./RedisBackend":
|
||||
|
|
Loading…
Reference in a new issue