Fix part size calculation if all parts are of the same size
Relates to #13574
This commit is contained in:
parent
97db3d5ef6
commit
5915309939
|
@ -163,7 +163,7 @@ public class BlobStoreIndexShardSnapshot implements ToXContent, FromXContentBuil
|
|||
return partBytes;
|
||||
}
|
||||
// Last part size is deducted from the length and the number of parts
|
||||
return length() % partBytes;
|
||||
return length() - (partBytes * (numberOfParts-1));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -83,7 +83,7 @@ public class FileInfoTests extends ESTestCase {
|
|||
String name = "foobar";
|
||||
String physicalName = "_foobar";
|
||||
String failure = null;
|
||||
long length = Math.max(0,Math.abs(randomLong()));
|
||||
long length = Math.max(0, Math.abs(randomLong()));
|
||||
// random corruption
|
||||
switch (randomIntBetween(0, 3)) {
|
||||
case 0:
|
||||
|
@ -137,4 +137,31 @@ public class FileInfoTests extends ESTestCase {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetPartSize() {
|
||||
BlobStoreIndexShardSnapshot.FileInfo info = new BlobStoreIndexShardSnapshot.FileInfo("foo", new StoreFileMetaData("foo", 36), new ByteSizeValue(6));
|
||||
int numBytes = 0;
|
||||
for (int i = 0; i < info.numberOfParts(); i++) {
|
||||
numBytes += info.partBytes(i);
|
||||
}
|
||||
assertEquals(numBytes, 36);
|
||||
|
||||
info = new BlobStoreIndexShardSnapshot.FileInfo("foo", new StoreFileMetaData("foo", 35), new ByteSizeValue(6));
|
||||
numBytes = 0;
|
||||
for (int i = 0; i < info.numberOfParts(); i++) {
|
||||
numBytes += info.partBytes(i);
|
||||
}
|
||||
assertEquals(numBytes, 35);
|
||||
final int numIters = randomIntBetween(10, 100);
|
||||
for (int j = 0; j < numIters; j++) {
|
||||
StoreFileMetaData metaData = new StoreFileMetaData("foo", randomIntBetween(0, 1000));
|
||||
info = new BlobStoreIndexShardSnapshot.FileInfo("foo", metaData, new ByteSizeValue(randomIntBetween(1, 1000)));
|
||||
numBytes = 0;
|
||||
for (int i = 0; i < info.numberOfParts(); i++) {
|
||||
numBytes += info.partBytes(i);
|
||||
}
|
||||
assertEquals(numBytes, metaData.length());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue