From 9b223bea87ad95080e66307102bc6660b7fc1ba8 Mon Sep 17 00:00:00 2001 From: Dora Korpar Date: Thu, 30 May 2019 17:02:00 -0700 Subject: [PATCH] improvement: S3C 1139 implement batch delete for sproxyd client --- lib/storage/data/DataWrapper.js | 31 +++++++++++++++------- lib/storage/data/MultipleBackendGateway.js | 8 ++++++ 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/lib/storage/data/DataWrapper.js b/lib/storage/data/DataWrapper.js index 633ea3455..97433562b 100644 --- a/lib/storage/data/DataWrapper.js +++ b/lib/storage/data/DataWrapper.js @@ -167,32 +167,45 @@ class DataWrapper { }); } - // It would be preferable to have an sproxyd batch delete route to - // replace this - batchDelete(locations, requestMethod, newObjDataStoreName, log) { + batchDelete(locations, requestMethod, newObjDataStoreName, log, cb) { // TODO: The method of persistence of sproxy delete key will // be finalized; refer Issue #312 for the discussion. In the // meantime, we at least log the location of the data we are // about to delete before attempting its deletion. if (this._shouldSkipDelete(locations, requestMethod, newObjDataStoreName)) { - return; + return process.nextTick(cb); } log.trace('initiating batch delete', { keys: locations, implName: this.implName, method: 'batchDelete', }); - async.eachLimit(locations, 5, (loc, next) => { + const keys = []; + const shouldBatchDelete = locations.every(l => { + if (typeof l === 'string') { + keys.push(l); + return true; + } + if (l.dataStoreName === 'sproxyd') { + keys.push(l.key); + return true; + } + return false; + }); + if (shouldBatchDelete) { + return this.client.batchDelete('sproxyd', keys, log, cb); + } + return async.eachLimit(locations, 5, (loc, next) => { process.nextTick(() => this.delete(loc, log, next)); }, err => { if (err) { - log.error('batch delete failed', { error: err }); - } else { - log.trace('batch delete successfully completed'); + log.end().error('batch delete failed', { error: err }); + return cb(err); } - log.end(); + log.end().trace('batch delete successfully completed'); + return cb(); }); } diff --git a/lib/storage/data/MultipleBackendGateway.js b/lib/storage/data/MultipleBackendGateway.js index 7ef548e3b..a3609c254 100644 --- a/lib/storage/data/MultipleBackendGateway.js +++ b/lib/storage/data/MultipleBackendGateway.js @@ -123,6 +123,14 @@ class MultipleBackendGateway { return client.delete(objectGetInfo, reqUids, callback); } + batchDelete(dataStoreName, keys, log, callback) { + const client = this.clients[dataStoreName]; + if (client.batchDelete) { + return client.batchDelete(keys, log.getSerializedUids(), callback); + } + return callback(errors.NotImplemented); + } + healthcheck(flightCheckOnStartUp, log, callback) { const multBackendResp = {}; const awsArray = [];