MCPcopy
hub / github.com/scality/cloudserver / batchDelete

Function batchDelete

lib/routes/routeBackbeat.js:1385–1481  ·  view source on GitHub ↗
(request, response, userInfo, log, callback)

Source from the content-addressed store, hash-verified

1383}
1384
1385function batchDelete(request, response, userInfo, log, callback) {
1386 return _getRequestPayload(request, (err, payload) => {
1387 if (err) {
1388 return callback(err);
1389 }
1390 let parsedPayload;
1391 try {
1392 parsedPayload = JSON.parse(payload);
1393 } catch {
1394 // FIXME: add error type MalformedJSON
1395 return callback(errors.MalformedPOSTRequest);
1396 }
1397 if (!parsedPayload || !Array.isArray(parsedPayload.Locations)) {
1398 return callback(errors.MalformedPOSTRequest);
1399 }
1400 const locations = parsedPayload.Locations;
1401 if (_shouldConditionallyDelete(request, locations)) {
1402 return _performConditionalDelete(request, response, locations, log, callback);
1403 }
1404 log.trace('batch delete locations', { locations });
1405 return async.eachLimit(
1406 locations,
1407 5,
1408 (loc, next) => {
1409 const _loc = Object.assign({}, loc);
1410 if (_loc.dataStoreVersionId !== undefined) {
1411 // required by cloud backends
1412 _loc.deleteVersion = true;
1413 }
1414 dataWrapper.data.delete(_loc, log, err => {
1415 if (err?.is?.ObjNotFound) {
1416 log.info('batch delete: data location do not exist', {
1417 method: 'batchDelete',
1418 location: loc,
1419 });
1420 return next();
1421 }
1422 return next(err);
1423 });
1424 },
1425 err => {
1426 if (err) {
1427 log.error('batch delete failed', {
1428 method: 'batchDelete',
1429 locations,
1430 error: err,
1431 });
1432 return callback(err);
1433 }
1434 log.debug('batch delete successful', { locations });
1435
1436 // Update inflight metrics for the data which has just been freed
1437 const bucket = request.bucketName;
1438 const contentLength = locations.reduce((length, loc) => length + loc.size, 0);
1439
1440 // TODO: `bucket` should probably always be passed, to be confirmed in CLDSRV-643
1441 // For now be leniant and skip inflight updates if it is not specified, to avoid any
1442 // impact esp. on CRR

Callers

nothing calls this directly

Calls 10

_getRequestPayloadFunction · 0.85
_respondFunction · 0.85
traceMethod · 0.80
infoMethod · 0.80
errorMethod · 0.80
debugMethod · 0.80
isQuotaEnabledMethod · 0.80
warnMethod · 0.80

Tested by

no test coverage detected