MCPcopy Index your code
hub / github.com/scality/cloudserver / locationStorageCheck

Function locationStorageCheck

lib/api/apiUtils/object/locationStorageCheck.js:22–46  ·  view source on GitHub ↗

* locationStorageCheck - will ensure there is enough space left for object on * PUT operations, or will update metric on DELETE * NOTE: storage limit may not be exactly enforced in the case of concurrent * requests when near limit * @param {string} location - name of location to check quota * @

(location, updateSize, log, cb)

Source from the content-addressed store, hash-verified

20 * @return {undefined}
21 */
22function locationStorageCheck(location, updateSize, log, cb) {
23 const lc = config.locationConstraints;
24 const sizeLimitGB = lc[location] ? lc[location].sizeLimitGB : undefined;
25 if (updateSize === 0 || sizeLimitGB === undefined || sizeLimitGB === null) {
26 return cb();
27 }
28 // no need to list location metric, since it should be decreased
29 if (updateSize < 0) {
30 return pushLocationMetric(location, updateSize, log, cb);
31 }
32 return getLocationMetric(location, log, (err, bytesStored) => {
33 if (err) {
34 log.error(`Error listing metrics from Utapi: ${err.message}`);
35 return cb(err);
36 }
37 const newStorageSize = parseInt(bytesStored, 10) + updateSize;
38 const sizeLimitBytes = _gbToBytes(sizeLimitGB);
39 if (sizeLimitBytes < newStorageSize) {
40 return cb(errorInstances.AccessDenied.customizeDescription(
41 `The assigned storage space limit for location ${location} ` +
42 'will be exceeded'));
43 }
44 return pushLocationMetric(location, updateSize, log, cb);
45 });
46}
47
48module.exports = locationStorageCheck;

Callers

nothing calls this directly

Calls 4

pushLocationMetricFunction · 0.85
getLocationMetricFunction · 0.85
_gbToBytesFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected