Compare commits

...

1 Commits

Author SHA1 Message Date
Alexander Chan 4b46779651 fix count items helpers 2021-11-02 11:57:39 -07:00
2 changed files with 97 additions and 19 deletions

View File

@ -1458,14 +1458,21 @@ class MongoClientInterface {
*/ */
_processEntryData(entry, isTransient) { _processEntryData(entry, isTransient) {
const results = {}; const results = {};
const size = Number.parseInt(entry.value['content-length'], 10);
if (Number.isNaN(size)) {
return {
data: {},
error: new Error('invalid content length'),
};
}
if (!isTransient || if (!isTransient ||
entry.value.replicationInfo.status !== 'COMPLETED') { entry.value.replicationInfo.status !== 'COMPLETED') {
if (results[entry.value.dataStoreName]) { if (results[entry.value.dataStoreName]) {
results[entry.value.dataStoreName] += results[entry.value.dataStoreName] += size;
entry.value['content-length'];
} else { } else {
results[entry.value.dataStoreName] = results[entry.value.dataStoreName] = size;
entry.value['content-length'];
} }
} else { } else {
if (!results[entry.value.dataStoreName]) { if (!results[entry.value.dataStoreName]) {
@ -1475,13 +1482,16 @@ class MongoClientInterface {
entry.value.replicationInfo.backends.forEach(rep => { entry.value.replicationInfo.backends.forEach(rep => {
if (rep.status === 'COMPLETED') { if (rep.status === 'COMPLETED') {
if (results[rep.site]) { if (results[rep.site]) {
results[rep.site] += entry.value['content-length']; results[rep.site] += size;
} else { } else {
results[rep.site] = entry.value['content-length']; results[rep.site] = size;
} }
} }
}); });
return results; return {
data: results,
error: null,
};
} }
/** /**
@ -1531,7 +1541,16 @@ class MongoClientInterface {
cursor.forEach( cursor.forEach(
res => { res => {
const data = this._processEntryData(res, isTransient); const { data, error } = this._processEntryData(res, isTransient);
if (error instanceof Error) {
log.error('Failed to process entry data', {
method: 'getObjectMDStats',
entry: res,
error,
});
}
let targetCount; let targetCount;
let targetData; let targetData;
if (res._id.indexOf('\0') !== -1) { if (res._id.indexOf('\0') !== -1) {

View File

@ -128,7 +128,10 @@ describe('MongoClientInterface::_processEntryData', () => {
}, },
}, },
{ {
'us-east-1': 42, data: {
'us-east-1': 42,
},
error: null,
}, },
], ],
[ [
@ -156,7 +159,10 @@ describe('MongoClientInterface::_processEntryData', () => {
}, },
}, },
{ {
'us-east-1': 0, data: {
'us-east-1': 0,
},
error: null,
}, },
], ],
[ [
@ -184,7 +190,10 @@ describe('MongoClientInterface::_processEntryData', () => {
}, },
}, },
{ {
'us-east-1': 42, data: {
'us-east-1': 42,
},
error: null,
}, },
], ],
[ [
@ -212,7 +221,10 @@ describe('MongoClientInterface::_processEntryData', () => {
}, },
}, },
{ {
'us-east-1': 42, data: {
'us-east-1': 42,
},
error: null,
}, },
], ],
[ [
@ -253,10 +265,13 @@ describe('MongoClientInterface::_processEntryData', () => {
}, },
}, },
{ {
'us-east-1': 0, data: {
'completed-1': 42, 'us-east-1': 0,
'completed-2': 42, 'completed-1': 42,
'completed-3': 42, 'completed-2': 42,
'completed-3': 42,
},
error: null,
}, },
], ],
[ [
@ -297,9 +312,53 @@ describe('MongoClientInterface::_processEntryData', () => {
}, },
}, },
{ {
'us-east-1': 42, data: {
'completed-1': 42, 'us-east-1': 42,
'completed-2': 42, 'completed-1': 42,
'completed-2': 42,
},
error: null,
},
],
[
'should error if content-lenght is invalid',
true,
{
_id: 'testkey',
value: {
'last-modified': new Date(),
'replicationInfo': {
status: 'PENDING',
backends: [
{
status: 'PENDING',
site: 'not-completed',
},
{
status: 'COMPLETED',
site: 'completed-1',
},
{
status: 'COMPLETED',
site: 'completed-2',
},
],
content: [],
destination: '',
storageClass: '',
role: '',
storageType: '',
dataStoreVersionId: '',
isNFS: null,
},
'dataStoreName': 'us-east-1',
'content-length': 'not-a-number',
'versionId': '0123456789abcdefg',
},
},
{
data: {},
error: new Error('invalid content length'),
}, },
], ],
]; ];