Fix blob size in writeBlob() method

This commit is contained in:
Tanguy Leroux 2015-09-15 16:02:24 +02:00
parent a3abfab865
commit d715dfd16c
3 changed files with 17 additions and 8 deletions

View File

@ -624,13 +624,14 @@ public class BlobStoreIndexShardRepository extends AbstractComponent implements
*/
private void snapshotFile(final BlobStoreIndexShardSnapshot.FileInfo fileInfo) throws IOException {
final String file = fileInfo.physicalName();
final byte[] buffer = new byte[BUFFER_SIZE];
try (IndexInput indexInput = store.openVerifyingInput(file, IOContext.READONCE, fileInfo.metadata())) {
for (int i = 0; i < fileInfo.numberOfParts(); i++) {
final InputStreamIndexInput inputStreamIndexInput = new InputStreamIndexInput(indexInput, fileInfo.partBytes());
final long partBytes = fileInfo.partBytes(i);
final InputStreamIndexInput inputStreamIndexInput = new InputStreamIndexInput(indexInput, partBytes);
InputStream inputStream = snapshotRateLimiter == null ? inputStreamIndexInput : new RateLimitingInputStream(inputStreamIndexInput, snapshotRateLimiter, snapshotThrottleListener);
inputStream = new AbortableInputStream(inputStream, fileInfo.physicalName());
blobContainer.writeBlob(fileInfo.partName(i), inputStream, fileInfo.partBytes());
blobContainer.writeBlob(fileInfo.partName(i), inputStream, partBytes);
}
Store.verify(indexInput);
snapshotStatus.addProcessedFile(fileInfo.length());

View File

@ -150,12 +150,20 @@ public class BlobStoreIndexShardSnapshot implements ToXContent, FromXContentBuil
}
/**
* Return maximum number of bytes in a part
* Returns the size (in bytes) of a given part
*
* @return maximum number of bytes in a part
* @return the size (in bytes) of a given part
*/
public long partBytes() {
return partBytes;
public long partBytes(int part) {
if (numberOfParts == 1) {
return length();
}
// First and last-but-one parts have a size equal to partBytes
if (part < (numberOfParts - 1)) {
return partBytes;
}
// Last part size is deducted from the length and the number of parts
return length() % partBytes;
}
/**

View File

@ -63,7 +63,7 @@ public class FileInfoTests extends ESTestCase {
assertThat(info.physicalName(), equalTo(parsedInfo.physicalName()));
assertThat(info.length(), equalTo(parsedInfo.length()));
assertThat(info.checksum(), equalTo(parsedInfo.checksum()));
assertThat(info.partBytes(), equalTo(parsedInfo.partBytes()));
assertThat(info.partSize(), equalTo(parsedInfo.partSize()));
assertThat(parsedInfo.metadata().hash().length, equalTo(hash.length));
assertThat(parsedInfo.metadata().hash(), equalTo(hash));
assertThat(parsedInfo.metadata().writtenBy(), equalTo(Version.LATEST));