Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Remote Translog] Add support for downloading files from remote translog #5649

Merged
merged 12 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address PR comments
Signed-off-by: Sachin Kale <kalsac@amazon.com>
  • Loading branch information
Sachin Kale committed Jan 4, 2023
commit 075d5009637d9015a88168e12492fe2a9acabcf4
Original file line number Diff line number Diff line change
Expand Up @@ -460,19 +460,9 @@ private void recoverFromRemoteStore(IndexShard indexShard, Repository repository
indexShard.syncSegmentsFromRemoteSegmentStore(true);

if (repository != null) {
FileTransferTracker fileTransferTracker = new FileTransferTracker(shardId);
assert repository instanceof BlobStoreRepository : "repository should be instance of BlobStoreRepository";
BlobStoreRepository blobStoreRepository = (BlobStoreRepository) repository;
TranslogTransferManager translogTransferManager = new TranslogTransferManager(
new BlobStoreTransferService(
blobStoreRepository.blobStore(),
indexShard.getThreadPool().executor(ThreadPool.Names.TRANSLOG_TRANSFER)
),
blobStoreRepository.basePath().add(shardId.getIndex().getUUID()).add(String.valueOf(shardId.id())),
fileTransferTracker,
fileTransferTracker::exclusionFilter
);
RemoteFsTranslog.download(translogTransferManager, indexShard.shardPath().resolveTranslog());
syncTranslogFilesFromRemoteTranslog(indexShard, repository);
} else {
bootstrap(indexShard, store);
}

assert indexShard.shardRouting.primary() : "only primary shards can recover from store";
Expand All @@ -489,6 +479,22 @@ private void recoverFromRemoteStore(IndexShard indexShard, Repository repository
}
}

private void syncTranslogFilesFromRemoteTranslog(IndexShard indexShard, Repository repository) throws IOException {
FileTransferTracker fileTransferTracker = new FileTransferTracker(shardId);
assert repository instanceof BlobStoreRepository : "repository should be instance of BlobStoreRepository";
BlobStoreRepository blobStoreRepository = (BlobStoreRepository) repository;
TranslogTransferManager translogTransferManager = new TranslogTransferManager(
new BlobStoreTransferService(
blobStoreRepository.blobStore(),
indexShard.getThreadPool().executor(ThreadPool.Names.TRANSLOG_TRANSFER)
),
blobStoreRepository.basePath().add(shardId.getIndex().getUUID()).add(String.valueOf(shardId.id())),
fileTransferTracker,
fileTransferTracker::exclusionFilter
);
RemoteFsTranslog.download(translogTransferManager, indexShard.shardPath().resolveTranslog());
}

/**
* Recovers the state of the shard from the store.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,32 +134,29 @@ public boolean transferSnapshot(TransferSnapshot transferSnapshot, TranslogTrans

public boolean downloadTranslog(String primaryTerm, String generation, Path location, boolean latest) throws IOException {
logger.info("Downloading translog files with: Primry Term = {}, Generation = {}, Location = {}", primaryTerm, generation, location);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: typo

String checkpointFilename = "translog-" + generation + ".ckp";
String ckpFileName = "translog-" + generation + ".ckp";
if (latest) {
checkpointFilename = "translog.ckp";
}
if (Files.exists(location.resolve(checkpointFilename)) == false) {
try (
InputStream checkpointFileInputStream = transferService.downloadBlob(
remoteBaseTransferPath.add(primaryTerm),
"translog-" + generation + ".ckp"
)
) {
Files.copy(checkpointFileInputStream, location.resolve(checkpointFilename));
}
String ckpWithoutGenerationFileName = "translog.ckp";
downloadToFS(ckpFileName, ckpWithoutGenerationFileName, location, primaryTerm);
}
// Download Checkpoint file from remote and store on FS
downloadToFS(ckpFileName, location, primaryTerm);
// Download translog file from remote and store on FS
String translogFilename = "translog-" + generation + ".tlog";
if (Files.exists(location.resolve(translogFilename)) == false) {
try (
InputStream translogFileInputStream = transferService.downloadBlob(
remoteBaseTransferPath.add(primaryTerm),
"translog-" + generation + ".tlog"
)
) {
Files.copy(translogFileInputStream, location.resolve(translogFilename));
downloadToFS(translogFilename, location, primaryTerm);
return true;
}

private void downloadToFS(String fileName, Path location, String primaryTerm) throws IOException {
downloadToFS(fileName, fileName, location, primaryTerm);
}

private void downloadToFS(String remoteFileName, String localFileName, Path location, String primaryTerm) throws IOException {
if (Files.exists(location.resolve(localFileName)) == false) {
try (InputStream inputStream = transferService.downloadBlob(remoteBaseTransferPath.add(primaryTerm), remoteFileName)) {
Files.copy(inputStream, location.resolve(localFileName));
}
}
return true;
}

public TranslogTransferMetadata readMetadata() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,17 @@ public void testReadLocationDownload() throws IOException {
Files.delete(file);
}

translog = create(translogDir, repository, translogUUID);
// Creating RemoteFsTranslog with the same location
Translog newTranslog = create(translogDir, repository, translogUUID);
i = 0;
for (Translog.Operation op : ops) {
assertEquals(op, translog.readOperation(locs.get(i++)));
assertEquals(op, newTranslog.readOperation(locs.get(i++)));
}
try {
newTranslog.close();
} catch (Exception e) {
// Ignoring this exception for now. Once the download flow populates FileTracker,
// we can remove this try-catch block
}
}

Expand Down