Skip to content

Upload segment to remote store post refresh#3403

Merged
Bukhtawar merged 2 commits intoopensearch-project:feature/durability-enhancementsfrom
sachinpkale:feature/durability-enhancements
May 22, 2022
Merged

Upload segment to remote store post refresh#3403
Bukhtawar merged 2 commits intoopensearch-project:feature/durability-enhancementsfrom
sachinpkale:feature/durability-enhancements

Conversation

@sachinpkale
Copy link
Copy Markdown
Member

@sachinpkale sachinpkale commented May 19, 2022

Signed-off-by: Sachin Kale kalsac@amazon.com

Description

  • This change adds implementation to afterRefresh method of RemoteStoreRefreshListener.
  • After each refresh, newly created segment files are uploaded to remote segment store.
  • To avoid reading remote directory every time, we keep a set of remote files in memory.
  • It also deletes files from remote store that are no longer present in the local filesystem.

Issues Resolved

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Sachin Kale <kalsac@amazon.com>
@sachinpkale sachinpkale requested review from a team and reta as code owners May 19, 2022 10:17
@opensearch-ci-bot
Copy link
Copy Markdown
Collaborator

✅   Gradle Check success e4997bb
Log 5476

Reports 5476

import java.nio.file.NoSuchFileException;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

avoid * based imports

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Removed.

Comment on lines +55 to +82
if (didRefresh) {
Set<String> localFiles = Arrays.stream(storeDirectory.listAll()).collect(Collectors.toSet());
localFiles.stream().filter(file -> !filesUploadedToRemoteStore.contains(file)).forEach(file -> {
try {
remoteDirectory.copyFrom(storeDirectory, file, file, IOContext.DEFAULT);
filesUploadedToRemoteStore.add(file);
} catch (NoSuchFileException e) {
logger.info("The file {} does not exist anymore. It can happen in case of temp files", file);
} catch (IOException e) {
// ToDO: Handle transient and permanent un-availability of the remote store (GitHub #3397)
logger.warn("Exception while uploading file {} to the remote segment store", file);
}
});

Set<String> remoteFilesToBeDeleted = new HashSet<>();
// ToDo: Instead of deleting files in sync, mark them and delete in async/periodic flow (GitHub #3142)
filesUploadedToRemoteStore.stream().filter(file -> !localFiles.contains(file)).forEach(file -> {
try {
remoteDirectory.deleteFile(file);
remoteFilesToBeDeleted.add(file);
} catch (IOException e) {
// ToDO: Handle transient and permanent un-availability of the remote store (GitHub #3397)
logger.warn("Exception while deleting file {} from the remote segment store", file);
}
});

remoteFilesToBeDeleted.forEach(filesUploadedToRemoteStore::remove);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  1. Do we need to ensure this happens within a lock
  2. let log exception as well
  3. Can we do batch deletions outside of upload flow without blocking subsequent uploads?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Do we need to ensure this happens within a lock

ReferenceManager.doMaybeRefresh() acquires lock before notifying refresh listeners

let log exception as well

Will add exception. Most probably it will change based on the exception handling.

Can we do batch deletions outside of upload flow without blocking subsequent uploads?

Yes, that is the plan. Added as ToDo before the delete block. #3142

@sachinpkale sachinpkale force-pushed the feature/durability-enhancements branch from c51f5c2 to a9d9da7 Compare May 19, 2022 12:19
Signed-off-by: Sachin Kale <kalsac@amazon.com>
@sachinpkale sachinpkale force-pushed the feature/durability-enhancements branch from a9d9da7 to deb3975 Compare May 19, 2022 12:27
@opensearch-ci-bot
Copy link
Copy Markdown
Collaborator

❌   Gradle Check failure a9d9da761e0f7932af72fe27d98c4cc7be55e65e
Log 5478

Reports 5478

@opensearch-ci-bot
Copy link
Copy Markdown
Collaborator

✅   Gradle Check success deb3975
Log 5479

Reports 5479

remoteDirectory.copyFrom(storeDirectory, file, file, IOContext.DEFAULT);
filesUploadedToRemoteStore.add(file);
} catch (NoSuchFileException e) {
logger.info(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could a possible segment merge with a concurrency bug manifest in files to be removed?

@Bukhtawar Bukhtawar merged commit b1c36fa into opensearch-project:feature/durability-enhancements May 22, 2022
sachinpkale added a commit to sachinpkale/OpenSearch that referenced this pull request May 27, 2022
Signed-off-by: Sachin Kale <kalsac@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants