Преглед изворни кода

Merge pull request #13362 from overleaf/csh-issue-13004-Always-Retry-during-GCS-delete

Always retry during GCS delete in history-v1 cron

GitOrigin-RevId: 1b64133dd0b9982f18124d9baa6e29bcdf6fa1f3
Christopher Hoskin пре 3 година
родитељ
комит
cc35bf4447

+ 18 - 2
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)
   }

+ 2 - 1
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": {