Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
Merge pull request #132 from braydonf/master
Browse files Browse the repository at this point in the history
Fix case where first shard isn't known yet
  • Loading branch information
pgerbes1 committed Oct 6, 2017
2 parents c5923b0 + 09f5abd commit 0b133a0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/models/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ Frame.methods.lock = function(callback) {
Frame.statics.validShardSizes = function(shards) {
if (shards.length > 1) {
shards.sort((a, b) => parseInt(a.index) - parseInt(b.index));
if (shards[0].index !== 0) {
return true;
}
let shardSize = shards[0].size;
let lastShardIndex = shards.length - 1;
for (let i = 0; i < shards.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"merge": "^1.2.0",
"mime-db": "^1.24.0",
"moment": "^2.17.1",
"mongoose": "^4.6.7",
"mongoose": "=4.11.14",
"mongoose-int32": "^0.1.0",
"mongoose-types": "^1.0.3",
"ms": "^0.7.1",
Expand Down
47 changes: 44 additions & 3 deletions test/frame.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ describe('Storage/models/Frame', function() {
it('return true (small single shard)', function() {
const shards = [
{
index: 0,
size: 1024
}
];
Expand Down Expand Up @@ -224,30 +225,48 @@ describe('Storage/models/Frame', function() {
it('return true (several 2MiB shards)', function() {
const shards = [
{
index: 0,
size: 2097152
},
{
index: 1,
size: 2097152
},
{
index: 2,
size: 2097152
}
];
expect(Frame.validShardSizes(shards)).to.equal(true);
});

it('return true', function() {
const shards = [
{
index: 10,
size: 1024
},
{
index: 11,
size: 2097152,
parity: true
}
];
expect(Frame.validShardSizes(shards)).to.equal(true);
});

it('return true on unsorted shards', function() {
const shards = [
{
index: 1,
index: 0,
size: 2097152
},
{
index: 3,
index: 2,
size: 100
},
{
index: 2,
index: 1,
size: 2097152
}
];
Expand All @@ -257,15 +276,19 @@ describe('Storage/models/Frame', function() {
it('return true (several 2MiB shards with small last shard)', function() {
const shards = [
{
index: 0,
size: 2097152
},
{
index: 1,
size: 2097152
},
{
index: 2,
size: 2097152
},
{
index: 3,
size: 1024
}
];
Expand All @@ -275,22 +298,28 @@ describe('Storage/models/Frame', function() {
it('return true (2MiB, small last shard, w/ parity shards)', function() {
const shards = [
{
index: 0,
size: 2097152
},
{
index: 1,
size: 2097152
},
{
index: 2,
size: 2097152
},
{
index: 3,
size: 1024
},
{
index: 4,
size: 2097152,
parity: true
},
{
index: 5,
size: 2097152,
parity: true
}
Expand All @@ -301,15 +330,19 @@ describe('Storage/models/Frame', function() {
it('return false (5KiB shards)', function() {
const shards = [
{
index: 0,
size: 5120
},
{
index: 1,
size: 5120
},
{
index: 2,
size: 5120
},
{
index: 3,
size: 5120
}
];
Expand All @@ -319,12 +352,15 @@ describe('Storage/models/Frame', function() {
it('return false (various size shards)', function() {
const shards = [
{
index: 0,
size: 5120
},
{
index: 1,
size: 3072
},
{
index: 2,
size: 4096
}
];
Expand All @@ -334,19 +370,24 @@ describe('Storage/models/Frame', function() {
it('return false (various size parity shards)', function() {
const shards = [
{
index: 0,
size: 5120
},
{
index: 1,
size: 5120
},
{
index: 2,
size: 3072
},
{
index: 3,
size: 23552,
parity: true
},
{
index: 4,
size: 2048,
parity: true
}
Expand Down

0 comments on commit 0b133a0

Please sign in to comment.