String filePath = file.getAbsolutePath();
String relPath = filePath.substring(baseDir.length(), filePath.length());
byte[] buf = new byte[BUFFER_SIZE];
int bytesRead = fileStream.read(buf, 0, BUFFER_SIZE);
long bytesReadTotal = 0;
BytesArray content = new BytesArray(buf, 0, bytesRead);
BlobRecoveryStartTransferRequest startTransferRequest =
new BlobRecoveryStartTransferRequest(request.recoveryId(), relPath, content,
fileSize
);
if (bytesRead > 0) {
bytesReadTotal += bytesRead;
logger.trace("[{}][{}] send BlobRecoveryStartTransferRequest to {} for file {} with size {}",
request.shardId().index().name(), request.shardId().id(),
request.targetNode().getName(),
relPath,
fileSize
);
transportService.submitRequest(
request.targetNode(),
BlobRecoveryTarget.Actions.START_TRANSFER,
startTransferRequest,
TransportRequestOptions.options(),
EmptyTransportResponseHandler.INSTANCE_SAME
).txGet();
boolean isLast = false;
boolean sentChunks = false;
while ((bytesRead = fileStream.read(buf, 0, BUFFER_SIZE)) > 0) {
sentChunks = true;
bytesReadTotal += bytesRead;
if (shard.state() == IndexShardState.CLOSED) { // check if the shard got closed on us
throw new IndexShardClosedException(shard.shardId());
}
if (bytesReadTotal == fileSize) {
isLast = true;
}
content = new BytesArray(buf, 0, bytesRead);
transportService.submitRequest(request.targetNode(),
BlobRecoveryTarget.Actions.TRANSFER_CHUNK,
new BlobRecoveryChunkRequest(request.recoveryId(),
startTransferRequest.transferId(), content, isLast),