Skip to content

Commit

Permalink
Address review comment
Browse files Browse the repository at this point in the history
Signed-off-by: Suraj Singh <[email protected]>
  • Loading branch information
dreamer-89 committed Jul 7, 2023
1 parent 0ef1de0 commit 1328c59
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions server/src/main/java/org/opensearch/index/store/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -821,17 +821,14 @@ public void cleanupAndPreserveLatestCommitPoint(String reason, SegmentInfos info
*
* @throws IllegalStateException if the latest snapshot in this store differs from the given one after the cleanup.
*/
public void cleanupAndPreserveLatestCommitPoint(
String reason,
SegmentInfos infos,
SegmentInfos lastCommittedSegmentInfos
) throws IOException {
public void cleanupAndPreserveLatestCommitPoint(String reason, SegmentInfos infos, SegmentInfos lastCommittedSegmentInfos)
throws IOException {
assert indexSettings.isSegRepEnabled();
// fetch a snapshot from the latest on disk Segments_N file. This can be behind
// the passed in local in memory snapshot, so we want to ensure files it references are not removed.
metadataLock.writeLock().lock();
try (Lock writeLock = directory.obtainLock(IndexWriter.WRITE_LOCK_NAME)) {
cleanupFiles(reason, lastCommittedSegmentInfos.files(true), infos.files(true));
cleanupFiles(List.of(directory.listAll()), reason, lastCommittedSegmentInfos.files(true), infos.files(true));
} finally {
metadataLock.writeLock().unlock();
}
Expand All @@ -843,31 +840,34 @@ public void cleanupAndPreserveLatestCommitPoint(
* Performs cleanup of un-referenced files intended to be used after reader close action
*
* @param reason Reason for cleanup
* @param filesToConsider Files to consider for clean up
* @param filesToCleanUp Files to consider for clean up
* @throws IOException Exception from cleanup operation
*/
public void cleanupUnReferencedFiles(String reason, Collection<String> filesToConsider) throws IOException {
public void cleanupUnReferencedFiles(String reason, Collection<String> filesToCleanUp) throws IOException {
assert indexSettings.isSegRepEnabled();
metadataLock.writeLock().lock();
try (Lock writeLock = directory.obtainLock(IndexWriter.WRITE_LOCK_NAME)) {
cleanupFiles(reason, null, filesToConsider);
cleanupFiles(filesToCleanUp, reason, null, null);
} finally {
metadataLock.writeLock().unlock();
}
}

private void cleanupFiles(
Collection<String> filesToCleanUp,
String reason,
Collection<String> localSnapshot,
@Nullable Collection<String> additionalFiles
) throws IOException {
assert metadataLock.isWriteLockedByCurrentThread();
for (String existingFile : directory.listAll()) {
for (String existingFile : filesToCleanUp) {
if (Store.isAutogenerated(existingFile)
|| localSnapshot != null && localSnapshot.contains(existingFile)
|| (additionalFiles != null && additionalFiles.contains(existingFile))
// also ensure we are not deleting a file referenced by an active reader.
|| replicaFileTracker != null && replicaFileTracker.canDelete(existingFile) == false) {
|| replicaFileTracker != null && replicaFileTracker.canDelete(existingFile) == false
// Prevent temporary replication files as it should be cleaned up MultiFileWriter
|| existingFile.startsWith(REPLICATION_PREFIX)) {
// don't delete snapshot file, or the checksums file (note, this is extra protection since the Store won't delete
// checksum)
continue;
Expand Down

0 comments on commit 1328c59

Please sign in to comment.