Add a "flush: false" option to the doc delete endpoint

This will delete the document from Redis without flushing to web,
docstore or history. To be used when something is broken.
This commit is contained in:
Eric Mc Sween 2020-03-07 08:11:18 -05:00
parent dec18e0773
commit c09bc0e868
4 changed files with 41 additions and 16 deletions

View file

@ -54,7 +54,7 @@ app.post '/project/:project_id/get_and_flush_if_old', HttpCont
app.post '/project/:project_id/clearState', HttpController.clearProjectState app.post '/project/:project_id/clearState', HttpController.clearProjectState
app.post '/project/:project_id/doc/:doc_id', HttpController.setDoc app.post '/project/:project_id/doc/:doc_id', HttpController.setDoc
app.post '/project/:project_id/doc/:doc_id/flush', HttpController.flushDocIfLoaded app.post '/project/:project_id/doc/:doc_id/flush', HttpController.flushDocIfLoaded
app.delete '/project/:project_id/doc/:doc_id', HttpController.flushAndDeleteDoc app.delete '/project/:project_id/doc/:doc_id', HttpController.deleteDoc
app.delete '/project/:project_id', HttpController.deleteProject app.delete '/project/:project_id', HttpController.deleteProject
app.delete '/project', HttpController.deleteMultipleProjects app.delete '/project', HttpController.deleteMultipleProjects
app.post '/project/:project_id', HttpController.updateProject app.post '/project/:project_id', HttpController.updateProject

View file

@ -222,6 +222,10 @@ module.exports = DocumentManager =
UpdateManager = require "./UpdateManager" UpdateManager = require "./UpdateManager"
UpdateManager.lockUpdatesAndDo DocumentManager.flushAndDeleteDoc, project_id, doc_id, callback UpdateManager.lockUpdatesAndDo DocumentManager.flushAndDeleteDoc, project_id, doc_id, callback
deleteDocWithLock: (project_id, doc_id, callback) ->
UpdateManager = require "./UpdateManager"
UpdateManager.lockUpdatesAndDo RedisManager.removeDocFromMemory, project_id, doc_id, callback
acceptChangesWithLock: (project_id, doc_id, change_ids, callback = (error) ->) -> acceptChangesWithLock: (project_id, doc_id, change_ids, callback = (error) ->) ->
UpdateManager = require "./UpdateManager" UpdateManager = require "./UpdateManager"
UpdateManager.lockUpdatesAndDo DocumentManager.acceptChanges, project_id, doc_id, change_ids, callback UpdateManager.lockUpdatesAndDo DocumentManager.acceptChanges, project_id, doc_id, change_ids, callback

View file

@ -103,20 +103,28 @@ module.exports = HttpController =
logger.log project_id: project_id, doc_id: doc_id, "flushed doc via http" logger.log project_id: project_id, doc_id: doc_id, "flushed doc via http"
res.send 204 # No Content res.send 204 # No Content
flushAndDeleteDoc: (req, res, next = (error) ->) -> deleteDoc: (req, res, next = (error) ->) ->
doc_id = req.params.doc_id doc_id = req.params.doc_id
project_id = req.params.project_id project_id = req.params.project_id
logger.log project_id: project_id, doc_id: doc_id, "deleting doc via http" flush = req.body.flush ? true
logger.log project_id: project_id, doc_id: doc_id, flush: flush, "deleting doc via http"
timer = new Metrics.Timer("http.deleteDoc") timer = new Metrics.Timer("http.deleteDoc")
DocumentManager.flushAndDeleteDocWithLock project_id, doc_id, (error) -> if flush
timer.done() DocumentManager.flushAndDeleteDocWithLock project_id, doc_id, (error) ->
# There is no harm in flushing project history if the previous call timer.done()
# failed and sometimes it is required # There is no harm in flushing project history if the previous call
HistoryManager.flushProjectChangesAsync project_id # failed and sometimes it is required
HistoryManager.flushProjectChangesAsync project_id
return next(error) if error? return next(error) if error?
logger.log project_id: project_id, doc_id: doc_id, "deleted doc via http" logger.log project_id: project_id, doc_id: doc_id, "deleted doc via http"
res.send 204 # No Content res.send 204 # No Content
else
DocumentManager.deleteDocWithLock project_id, doc_id, (error) ->
timer.done()
return next(error) if error?
logger.log project_id: project_id, doc_id: doc_id, "deleted doc via http"
res.send 204 # No Content
flushProject: (req, res, next = (error) ->) -> flushProject: (req, res, next = (error) ->) ->
project_id = req.params.project_id project_id = req.params.project_id

View file

@ -264,18 +264,19 @@ describe "HttpController", ->
@next @next
.calledWith(new Error("oops")) .calledWith(new Error("oops"))
.should.equal true .should.equal true
describe "flushAndDeleteDoc", -> describe "deleteDoc", ->
beforeEach -> beforeEach ->
@req = @req =
params: params:
project_id: @project_id project_id: @project_id
doc_id: @doc_id doc_id: @doc_id
body: {}
describe "successfully", -> describe "successfully", ->
beforeEach -> beforeEach ->
@DocumentManager.flushAndDeleteDocWithLock = sinon.stub().callsArgWith(2) @DocumentManager.flushAndDeleteDocWithLock = sinon.stub().callsArgWith(2)
@HttpController.flushAndDeleteDoc(@req, @res, @next) @HttpController.deleteDoc(@req, @res, @next)
it "should flush and delete the doc", -> it "should flush and delete the doc", ->
@DocumentManager.flushAndDeleteDocWithLock @DocumentManager.flushAndDeleteDocWithLock
@ -294,16 +295,28 @@ describe "HttpController", ->
it "should log the request", -> it "should log the request", ->
@logger.log @logger.log
.calledWith(doc_id: @doc_id, project_id: @project_id, "deleting doc via http") .calledWith(doc_id: @doc_id, project_id: @project_id, flush: true, "deleting doc via http")
.should.equal true .should.equal true
it "should time the request", -> it "should time the request", ->
@Metrics.Timer::done.called.should.equal true @Metrics.Timer::done.called.should.equal true
describe "without flush", ->
beforeEach ->
@req.body.flush = false
@DocumentManager.deleteDocWithLock = sinon.stub().yields()
@HttpController.deleteDoc(@req, @res, @next)
it "should delete the doc", ->
@DocumentManager.deleteDocWithLock.calledWith(@project_id, @doc_id).should.equal true
it "should return a successful No Content response", ->
@res.send.calledWith(204).should.equal true
describe "when an errors occurs", -> describe "when an errors occurs", ->
beforeEach -> beforeEach ->
@DocumentManager.flushAndDeleteDocWithLock = sinon.stub().callsArgWith(2, new Error("oops")) @DocumentManager.flushAndDeleteDocWithLock = sinon.stub().callsArgWith(2, new Error("oops"))
@HttpController.flushAndDeleteDoc(@req, @res, @next) @HttpController.deleteDoc(@req, @res, @next)
it "should flush project history", -> it "should flush project history", ->
@HistoryManager.flushProjectChangesAsync @HistoryManager.flushProjectChangesAsync