Skip to content

Commit

Permalink
[squash] review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderchan-scality committed Apr 4, 2018
1 parent 7215ce7 commit 5d6c28f
Showing 1 changed file with 41 additions and 24 deletions.
65 changes: 41 additions & 24 deletions lib/storage/metadata/mongoclient/MongoClientInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -862,16 +862,27 @@ class MongoClientInterface {
versions: 0,
buckets: 0,
bucketList: [],
dataManaged: {},
/* eslint-disable quote-props*/
dataManaged: {
total: { curr: 0, prev: 0 },
'by-location': {},
},
/* eslint-enable quote-props*/
};

const consolidateData = dataManaged => {
Object.keys(dataManaged).forEach(loc => {
if (!res.dataManaged[loc]) {
res.dataManaged[loc] = Object.assign({}, dataManaged[loc]);
const locations = dataManaged.locations;
res.dataManaged.total.curr = dataManaged.total.curr;
res.dataManaged.total.prev = dataManaged.total.prev;
Object.keys(locations).forEach(site => {
if (!res.dataManaged['by-location'][site]) {
res.dataManaged['by-location'][site] =
Object.assign({}, locations[site]);
} else {
res.dataManaged[loc].curr += dataManaged[loc].curr;
res.dataManaged[loc].prev += dataManaged[loc].prev;
res.dataManaged['by-location'][site].curr +=
locations[site].curr;
res.dataManaged['by-location'][site].prev +=
locations[site].prev;
}
});
};
Expand Down Expand Up @@ -927,25 +938,24 @@ class MongoClientInterface {
}

getDataManaged(c, query, cb) {
const dataManaged = {};
const dataManaged = {
total: 0,
locations: {},
};
c.find(query).toArray((err, entries) => {
if (err) {
return cb(err);
}
entries.forEach(entry => {
const { backends } = entry.value.replicationInfo;
const objMD = entry.value;
if (!dataManaged.total) {
dataManaged.total = objMD['content-length'];
} else {
dataManaged.total += objMD['content-length'];
}
dataManaged.total += objMD['content-length'];
backends.forEach(location => {
const { site } = location;
if (!dataManaged[site]) {
dataManaged[site] = objMD['content-length'];
if (!dataManaged.locations[site]) {
dataManaged.locations[site] = objMD['content-length'];
} else {
dataManaged[site] += objMD['content-length'];
dataManaged.locations[site] += objMD['content-length'];
}
});
});
Expand Down Expand Up @@ -1003,21 +1013,28 @@ class MongoClientInterface {
if (err) {
return callback(err);
}
const dataManaged = {};
const mstData = res.master.dataManaged;
const verData = res.archived.dataManaged;
const dataManaged = {
total: { curr: 0, prev: 0 },
locations: {},
};
const mstData = res.master.dataManaged.locations;
const verData = res.archived.dataManaged.locations;

// add total
dataManaged.total.curr = res.master.dataManaged.total;
dataManaged.total.prev = res.archived.dataManaged.total;

Object.keys(mstData).forEach(loc => {
if (!dataManaged[loc]) {
dataManaged[loc] = { prev: 0, curr: 0 };
if (!dataManaged.locations[loc]) {
dataManaged.locations[loc] = { prev: 0, curr: 0 };
}
dataManaged[loc].curr = mstData[loc];
dataManaged.locations[loc].curr = mstData[loc];
});
Object.keys(verData).forEach(loc => {
if (!dataManaged[loc]) {
dataManaged[loc] = { prev: 0, curr: 0 };
if (!dataManaged.locations[loc]) {
dataManaged.locations[loc] = { prev: 0, curr: 0 };
}
dataManaged[loc].prev = verData[loc];
dataManaged.locations[loc].prev = verData[loc];
});

return callback(null, {
Expand Down

0 comments on commit 5d6c28f

Please sign in to comment.