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) {
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 ||
entry.value.replicationInfo.status !== 'COMPLETED') {
if (results[entry.value.dataStoreName]) {
results[entry.value.dataStoreName] +=
entry.value['content-length'];
results[entry.value.dataStoreName] += size;
} else {
results[entry.value.dataStoreName] =
entry.value['content-length'];
results[entry.value.dataStoreName] = size;
}
} else {
if (!results[entry.value.dataStoreName]) {
@ -1475,13 +1482,16 @@ class MongoClientInterface {
entry.value.replicationInfo.backends.forEach(rep => {
if (rep.status === 'COMPLETED') {
if (results[rep.site]) {
results[rep.site] += entry.value['content-length'];
results[rep.site] += size;
} 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(
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 targetData;
if (res._id.indexOf('\0') !== -1) {

View File

@ -128,8 +128,11 @@ describe('MongoClientInterface::_processEntryData', () => {
},
},
{
data: {
'us-east-1': 42,
},
error: null,
},
],
[
'should not add content-length to total if replication ' +
@ -156,8 +159,11 @@ describe('MongoClientInterface::_processEntryData', () => {
},
},
{
data: {
'us-east-1': 0,
},
error: null,
},
],
[
'should add content-length to total if replication status != ' +
@ -184,8 +190,11 @@ describe('MongoClientInterface::_processEntryData', () => {
},
},
{
data: {
'us-east-1': 42,
},
error: null,
},
],
[
'should add content-length to total if replication ' +
@ -212,8 +221,11 @@ describe('MongoClientInterface::_processEntryData', () => {
},
},
{
data: {
'us-east-1': 42,
},
error: null,
},
],
[
'should add content-length to total for each COMPLETED backends ' +
@ -253,11 +265,14 @@ describe('MongoClientInterface::_processEntryData', () => {
},
},
{
data: {
'us-east-1': 0,
'completed-1': 42,
'completed-2': 42,
'completed-3': 42,
},
error: null,
},
],
[
'should add content-length to total for each COMPLETED backends ' +
@ -297,10 +312,54 @@ describe('MongoClientInterface::_processEntryData', () => {
},
},
{
data: {
'us-east-1': 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'),
},
],
];
tests.forEach(([msg, isTransient, params, expected]) => it(msg, () => {