pr_15410.patch 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. --- services/history-v1/api/controllers/projects.js
  2. +++ services/history-v1/api/controllers/projects.js
  3. @@ -194,18 +194,23 @@ async function getProjectBlob(req, res, next) {
  4. const hash = req.swagger.params.hash.value
  5. const blobStore = new BlobStore(projectId)
  6. - let stream
  7. + logger.debug({ projectId, hash }, 'getProjectBlob started')
  8. try {
  9. - stream = await blobStore.getStream(hash)
  10. - } catch (err) {
  11. - if (err instanceof Blob.NotFoundError) {
  12. - return render.notFound(res)
  13. - } else {
  14. - throw err
  15. + let stream
  16. + try {
  17. + stream = await blobStore.getStream(hash)
  18. + } catch (err) {
  19. + if (err instanceof Blob.NotFoundError) {
  20. + return render.notFound(res)
  21. + } else {
  22. + throw err
  23. + }
  24. }
  25. + res.set('Content-Type', 'application/octet-stream')
  26. + await pipeline(stream, res)
  27. + } finally {
  28. + logger.debug({ projectId, hash }, 'getProjectBlob finished')
  29. }
  30. - res.set('Content-Type', 'application/octet-stream')
  31. - await pipeline(stream, res)
  32. }
  33. async function getSnapshotAtVersion(projectId, version) {
  34. --- services/history-v1/storage/lib/blob_store/index.js
  35. +++ services/history-v1/storage/lib/blob_store/index.js
  36. @@ -20,6 +20,7 @@ const projectKey = require('../project_key')
  37. const streams = require('../streams')
  38. const postgresBackend = require('./postgres')
  39. const mongoBackend = require('./mongo')
  40. +const logger = require('@overleaf/logger')
  41. const GLOBAL_BLOBS = new Map()
  42. @@ -34,9 +35,14 @@ function makeProjectKey(projectId, hash) {
  43. async function uploadBlob(projectId, blob, stream) {
  44. const bucket = config.get('blobStore.projectBucket')
  45. const key = makeProjectKey(projectId, blob.getHash())
  46. - await persistor.sendStream(bucket, key, stream, {
  47. - contentType: 'application/octet-stream',
  48. - })
  49. + logger.debug({ projectId, blob }, 'uploadBlob started')
  50. + try {
  51. + await persistor.sendStream(bucket, key, stream, {
  52. + contentType: 'application/octet-stream',
  53. + })
  54. + } finally {
  55. + logger.debug({ projectId, blob }, 'uploadBlob finished')
  56. + }
  57. }
  58. function getBlobLocation(projectId, hash) {
  59. @@ -109,7 +115,12 @@ async function getStringLengthOfFile(byteLength, pathname) {
  60. async function deleteBlobsInBucket(projectId) {
  61. const bucket = config.get('blobStore.projectBucket')
  62. const prefix = `${projectKey.format(projectId)}/`
  63. - await persistor.deleteDirectory(bucket, prefix)
  64. + logger.debug({ projectId }, 'deleteBlobsInBucket started')
  65. + try {
  66. + await persistor.deleteDirectory(bucket, prefix)
  67. + } finally {
  68. + logger.debug({ projectId }, 'deleteBlobsInBucket finished')
  69. + }
  70. }
  71. async function loadGlobalBlobs() {
  72. @@ -202,9 +213,15 @@ class BlobStore {
  73. async getString(hash) {
  74. assert.blobHash(hash, 'bad hash')
  75. - const stream = await this.getStream(hash)
  76. - const buffer = await streams.readStreamToBuffer(stream)
  77. - return buffer.toString()
  78. + const projectId = this.projectId
  79. + logger.debug({ projectId, hash }, 'getString started')
  80. + try {
  81. + const stream = await this.getStream(hash)
  82. + const buffer = await streams.readStreamToBuffer(stream)
  83. + return buffer.toString()
  84. + } finally {
  85. + logger.debug({ projectId, hash }, 'getString finished')
  86. + }
  87. }
  88. /**
  89. --- services/history-v1/storage/lib/history_store.js
  90. +++ services/history-v1/storage/lib/history_store.js
  91. @@ -8,6 +8,7 @@ const path = require('path')
  92. const OError = require('@overleaf/o-error')
  93. const objectPersistor = require('@overleaf/object-persistor')
  94. +const logger = require('@overleaf/logger')
  95. const assert = require('./assert')
  96. const persistor = require('./persistor')
  97. @@ -70,6 +71,7 @@ HistoryStore.prototype.loadRaw = function historyStoreLoadRaw(
  98. const key = getKey(projectId, chunkId)
  99. + logger.debug({ projectId, chunkId }, 'loadRaw started')
  100. return BPromise.resolve()
  101. .then(() => persistor.getObjectStream(BUCKET, key))
  102. .then(streams.gunzipStreamToBuffer)
  103. @@ -80,6 +82,7 @@ HistoryStore.prototype.loadRaw = function historyStoreLoadRaw(
  104. }
  105. throw new HistoryStore.LoadError(projectId, chunkId).withCause(err)
  106. })
  107. + .finally(() => logger.debug({ projectId, chunkId }, 'loadRaw finished'))
  108. }
  109. /**
  110. @@ -102,6 +105,7 @@ HistoryStore.prototype.storeRaw = function historyStoreStoreRaw(
  111. const key = getKey(projectId, chunkId)
  112. const stream = streams.gzipStringToStream(JSON.stringify(rawHistory))
  113. + logger.debug({ projectId, chunkId }, 'storeRaw started')
  114. return BPromise.resolve()
  115. .then(() =>
  116. persistor.sendStream(BUCKET, key, stream, {
  117. @@ -112,6 +116,7 @@ HistoryStore.prototype.storeRaw = function historyStoreStoreRaw(
  118. .catch(err => {
  119. throw new HistoryStore.StoreError(projectId, chunkId).withCause(err)
  120. })
  121. + .finally(() => logger.debug({ projectId, chunkId }, 'storeRaw finished'))
  122. }
  123. /**
  124. @@ -121,12 +126,13 @@ HistoryStore.prototype.storeRaw = function historyStoreStoreRaw(
  125. * @return {Promise}
  126. */
  127. HistoryStore.prototype.deleteChunks = function historyDeleteChunks(chunks) {
  128. + logger.debug({ chunks }, 'deleteChunks started')
  129. return BPromise.all(
  130. chunks.map(chunk => {
  131. const key = getKey(chunk.projectId, chunk.chunkId)
  132. return persistor.deleteObject(BUCKET, key)
  133. })
  134. - )
  135. + ).finally(() => logger.debug({ chunks }, 'deleteChunks finished'))
  136. }
  137. module.exports = new HistoryStore()