Skip to content

Commit

Permalink
Clean up segment collection assertions
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Handalian <[email protected]>
  • Loading branch information
mch2 committed Jan 31, 2024
1 parent d5002a2 commit 8200c98
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.opensearch.common.lucene.index.OpenSearchDirectoryReader;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.common.util.set.Sets;
import org.opensearch.core.common.io.stream.NamedWriteableRegistry;
import org.opensearch.core.index.shard.ShardId;
import org.opensearch.core.xcontent.XContentBuilder;
Expand Down Expand Up @@ -89,6 +90,8 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -1029,7 +1032,7 @@ public void testScrollCreatedOnReplica() throws Exception {

final IndexShard replicaShard = getIndexShard(replica, INDEX_NAME);
SegmentInfos latestSegmentInfos = getLatestSegmentInfos(replicaShard);
Collection<String> snapshottedSegments = latestSegmentInfos.files(false);
final Set<String> snapshottedSegments = new HashSet<>(latestSegmentInfos.files(false));
logger.info("Segments {}", snapshottedSegments);

// index more docs and force merge down to 1 segment
Expand Down Expand Up @@ -1072,16 +1075,12 @@ public void testScrollCreatedOnReplica() throws Exception {
assertEquals(1, scrollHits);

client(replica).prepareClearScroll().addScrollId(searchResponse.getScrollId()).get();
List<String> filesAfterClearScroll = List.of(replicaShard.store().directory().listAll());
final Set<String> filesAfterClearScroll = Arrays.stream(replicaShard.store().directory().listAll()).collect(Collectors.toSet());
// there should be no active readers, snapshots, or on-disk commits containing the snapshotted files, check that they have been
// deleted.
for (String file : snapshottedSegments) {
assertFalse(
"Latest on-disk commit does not contain snapshotted segments",
replicaShard.store().readLastCommittedSegmentsInfo().files(false).contains(file)
);
assertFalse("File " + file + " should no longer be on disk", filesAfterClearScroll.contains(file));
}
Set<String> latestCommitSegments = new HashSet<>(replicaShard.store().readLastCommittedSegmentsInfo().files(false));
assertEquals("Snapshotted files are no longer part of the latest commit", Collections.emptySet(), Sets.intersection(latestCommitSegments, snapshottedSegments));
assertEquals("All snapshotted files should be deleted", Collections.emptySet(), Sets.intersection(filesAfterClearScroll, snapshottedSegments));
}

/**
Expand Down

0 comments on commit 8200c98

Please sign in to comment.