diff --git a/libraries/object-persistor/src/GcsPersistor.js b/libraries/object-persistor/src/GcsPersistor.js index 1bf6c05a15..cf96ee776d 100644 --- a/libraries/object-persistor/src/GcsPersistor.js +++ b/libraries/object-persistor/src/GcsPersistor.js @@ -1,11 +1,12 @@ const fs = require('fs') const { pipeline } = require('stream/promises') const { PassThrough } = require('stream') -const { Storage } = require('@google-cloud/storage') +const { Storage, IdempotencyStrategy } = require('@google-cloud/storage') const { WriteError, ReadError, NotFoundError } = require('./Errors') const asyncPool = require('tiny-async-pool') const AbstractPersistor = require('./AbstractPersistor') const PersistorHelper = require('./PersistorHelper') +const Logger = require('@overleaf/logger') module.exports = class GcsPersistor extends AbstractPersistor { constructor(settings) { @@ -20,7 +21,22 @@ module.exports = class GcsPersistor extends AbstractPersistor { storageOptions.projectId = this.settings.endpoint.projectId storageOptions.apiEndpoint = this.settings.endpoint.apiEndpoint } - storageOptions.retryOptions = this.settings.retryOptions + storageOptions.retryOptions = { ...this.settings.retryOptions } + if (storageOptions.retryOptions) { + if (storageOptions.retryOptions.idempotencyStrategy) { + const value = + IdempotencyStrategy[this.settings.retryOptions.idempotencyStrategy] + if (value === undefined) { + throw new Error( + 'Unrecognised value for retryOptions.idempotencyStrategy' + ) + } + Logger.info( + `Setting retryOptions.idempotencyStrategy to ${storageOptions.retryOptions.idempotencyStrategy} (${value})` + ) + storageOptions.retryOptions.idempotencyStrategy = value + } + } this.storage = new Storage(storageOptions) } diff --git a/services/history-v1/config/custom-environment-variables.json b/services/history-v1/config/custom-environment-variables.json index ff9cac16e1..d32e85a4e4 100644 --- a/services/history-v1/config/custom-environment-variables.json +++ b/services/history-v1/config/custom-environment-variables.json @@ -21,7 +21,8 @@ "projectId": "GCS_PROJECT_ID" }, "retryOptions": { - "maxRetries": "GCS_MAX_RETRIES" + "maxRetries": "GCS_MAX_RETRIES", + "idempotencyStrategy": "GCS_IDEMPOTENCY_STRATEGY" } }, "fallback": {