mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #41 from sharelatex/revert-38-bg-load-doc-safely-in-lock
Revert "fail safely if doc cannot be loaded"
This commit is contained in:
commit
0e0f4c34f0
5 changed files with 6 additions and 67 deletions
|
@ -28,13 +28,6 @@ module.exports = DocumentManager =
|
||||||
else
|
else
|
||||||
callback null, lines, version, ranges, true
|
callback null, lines, version, ranges, true
|
||||||
|
|
||||||
ensureDocIsLoaded: (project_id, doc_id, callback = (error) ->) ->
|
|
||||||
RedisManager.checkDocInMemory project_id, doc_id, (error) ->
|
|
||||||
if error?
|
|
||||||
DocumentManager.getDoc project_id, doc_id, callback
|
|
||||||
else
|
|
||||||
callback()
|
|
||||||
|
|
||||||
getDocAndRecentOps: (project_id, doc_id, fromVersion, _callback = (error, lines, version, recentOps, ranges) ->) ->
|
getDocAndRecentOps: (project_id, doc_id, fromVersion, _callback = (error, lines, version, recentOps, ranges) ->) ->
|
||||||
timer = new Metrics.Timer("docManager.getDocAndRecentOps")
|
timer = new Metrics.Timer("docManager.getDocAndRecentOps")
|
||||||
callback = (args...) ->
|
callback = (args...) ->
|
||||||
|
|
|
@ -30,12 +30,6 @@ historyKeys = Settings.redis.history.key_schema
|
||||||
module.exports = RedisManager =
|
module.exports = RedisManager =
|
||||||
rclient: rclient
|
rclient: rclient
|
||||||
|
|
||||||
checkDocInMemory: (project_id, doc_id, callback) ->
|
|
||||||
rclient.exists keys.docLines(doc_id:doc_id), (error, result) ->
|
|
||||||
return callback(error) if error?
|
|
||||||
return callback new Error("doc not in memory") if result isnt 1
|
|
||||||
callback()
|
|
||||||
|
|
||||||
putDocInMemory : (project_id, doc_id, docLines, version, ranges, _callback)->
|
putDocInMemory : (project_id, doc_id, docLines, version, ranges, _callback)->
|
||||||
timer = new metrics.Timer("redis.put-doc")
|
timer = new metrics.Timer("redis.put-doc")
|
||||||
callback = (error) ->
|
callback = (error) ->
|
||||||
|
|
|
@ -14,12 +14,8 @@ RangesManager = require "./RangesManager"
|
||||||
module.exports = UpdateManager =
|
module.exports = UpdateManager =
|
||||||
processOutstandingUpdates: (project_id, doc_id, callback = (error) ->) ->
|
processOutstandingUpdates: (project_id, doc_id, callback = (error) ->) ->
|
||||||
timer = new Metrics.Timer("updateManager.processOutstandingUpdates")
|
timer = new Metrics.Timer("updateManager.processOutstandingUpdates")
|
||||||
DocumentManager.ensureDocIsLoaded project_id, doc_id, (error) ->
|
|
||||||
# an error at this point is safe, because we haven't consumed any ops yet
|
|
||||||
return callback(error) if error?
|
|
||||||
UpdateManager.fetchAndApplyUpdates project_id, doc_id, (error) ->
|
UpdateManager.fetchAndApplyUpdates project_id, doc_id, (error) ->
|
||||||
timer.done()
|
timer.done()
|
||||||
# now we have taken ops off the queue so errors here will cause data loss
|
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
callback()
|
callback()
|
||||||
|
|
||||||
|
|
|
@ -189,47 +189,6 @@ describe "DocumentManager", ->
|
||||||
it "should time the execution", ->
|
it "should time the execution", ->
|
||||||
@Metrics.Timer::done.called.should.equal true
|
@Metrics.Timer::done.called.should.equal true
|
||||||
|
|
||||||
|
|
||||||
describe "ensureDocIsLoaded", ->
|
|
||||||
describe "when the doc exists in Redis", ->
|
|
||||||
beforeEach ->
|
|
||||||
@RedisManager.checkDocInMemory = sinon.stub().callsArgWith(2)
|
|
||||||
@DocumentManager.ensureDocIsLoaded @project_id, @doc_id, @callback
|
|
||||||
|
|
||||||
it "should check the doc in Redis", ->
|
|
||||||
@RedisManager.checkDocInMemory
|
|
||||||
.calledWith(@project_id, @doc_id)
|
|
||||||
.should.equal true
|
|
||||||
|
|
||||||
it "should call the callback", ->
|
|
||||||
@callback.called.should.equal true
|
|
||||||
|
|
||||||
describe "when the doc does not exist in Redis", ->
|
|
||||||
beforeEach ->
|
|
||||||
@RedisManager.getDoc = sinon.stub().callsArgWith(2, null, null, null, null, null)
|
|
||||||
@PersistenceManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges)
|
|
||||||
@RedisManager.putDocInMemory = sinon.stub().yields()
|
|
||||||
@RedisManager.checkDocInMemory = sinon.stub().callsArgWith(2, new Error("doc is not loaded"))
|
|
||||||
@DocumentManager.ensureDocIsLoaded @project_id, @doc_id, @callback
|
|
||||||
|
|
||||||
it "should try to get the doc from Redis", ->
|
|
||||||
@RedisManager.getDoc
|
|
||||||
.calledWith(@project_id, @doc_id)
|
|
||||||
.should.equal true
|
|
||||||
|
|
||||||
it "should get the doc from the PersistenceManager", ->
|
|
||||||
@PersistenceManager.getDoc
|
|
||||||
.calledWith(@project_id, @doc_id)
|
|
||||||
.should.equal true
|
|
||||||
|
|
||||||
it "should set the doc in Redis", ->
|
|
||||||
@RedisManager.putDocInMemory
|
|
||||||
.calledWith(@project_id, @doc_id, @lines, @version, @ranges)
|
|
||||||
.should.equal true
|
|
||||||
|
|
||||||
it "should call the callback", ->
|
|
||||||
@callback.calledWith(null).should.equal true
|
|
||||||
|
|
||||||
describe "setDoc", ->
|
describe "setDoc", ->
|
||||||
describe "with plain tex lines", ->
|
describe "with plain tex lines", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
|
|
@ -25,7 +25,6 @@ describe "UpdateManager", ->
|
||||||
|
|
||||||
describe "processOutstandingUpdates", ->
|
describe "processOutstandingUpdates", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@DocumentManager.ensureDocIsLoaded = sinon.stub().callsArg(2)
|
|
||||||
@UpdateManager.fetchAndApplyUpdates = sinon.stub().callsArg(2)
|
@UpdateManager.fetchAndApplyUpdates = sinon.stub().callsArg(2)
|
||||||
@UpdateManager.processOutstandingUpdates @project_id, @doc_id, @callback
|
@UpdateManager.processOutstandingUpdates @project_id, @doc_id, @callback
|
||||||
|
|
||||||
|
@ -43,7 +42,6 @@ describe "UpdateManager", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@LockManager.tryLock = sinon.stub().callsArgWith(1, null, true, @lockValue = "mock-lock-value")
|
@LockManager.tryLock = sinon.stub().callsArgWith(1, null, true, @lockValue = "mock-lock-value")
|
||||||
@LockManager.releaseLock = sinon.stub().callsArg(2)
|
@LockManager.releaseLock = sinon.stub().callsArg(2)
|
||||||
@RedisManager.checkDocInMemory = sinon.stub().callsArg(2)
|
|
||||||
@UpdateManager.continueProcessingUpdatesWithLock = sinon.stub().callsArg(2)
|
@UpdateManager.continueProcessingUpdatesWithLock = sinon.stub().callsArg(2)
|
||||||
@UpdateManager.processOutstandingUpdates = sinon.stub().callsArg(2)
|
@UpdateManager.processOutstandingUpdates = sinon.stub().callsArg(2)
|
||||||
|
|
||||||
|
@ -93,7 +91,6 @@ describe "UpdateManager", ->
|
||||||
it "should not process the updates", ->
|
it "should not process the updates", ->
|
||||||
@UpdateManager.processOutstandingUpdates.called.should.equal false
|
@UpdateManager.processOutstandingUpdates.called.should.equal false
|
||||||
|
|
||||||
|
|
||||||
describe "continueProcessingUpdatesWithLock", ->
|
describe "continueProcessingUpdatesWithLock", ->
|
||||||
describe "when there are outstanding updates", ->
|
describe "when there are outstanding updates", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
|
Loading…
Reference in a new issue