Skip to content

Commit

Permalink
Change visibility of Engine.getLastCommittedSegmentInfos() to public
Browse files Browse the repository at this point in the history
  • Loading branch information
stu-elastic committed Jul 27, 2023
1 parent 710fa2f commit d5074c6
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 101 deletions.
13 changes: 1 addition & 12 deletions server/src/main/java/org/elasticsearch/index/engine/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import static org.elasticsearch.core.Strings.format;
import static org.elasticsearch.index.seqno.SequenceNumbers.UNASSIGNED_PRIMARY_TERM;
Expand Down Expand Up @@ -148,16 +146,7 @@ public final EngineConfig config() {
return engineConfig;
}

protected abstract SegmentInfos getLastCommittedSegmentInfos();

/**
* Get the a lazily loaded file size for all segments in the last commit
*/
public List<SegmentFileSize> getLastCommittedSegmentFileSizes() {
return StreamSupport.stream(getLastCommittedSegmentInfos().spliterator(), false)
.map(SegmentFileSize::new)
.collect(Collectors.toList());
}
public abstract SegmentInfos getLastCommittedSegmentInfos();

public MergeStats getMergeStats() {
return new MergeStats();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2478,7 +2478,7 @@ protected boolean maybeFailEngine(String source, Exception e) {
}

@Override
protected SegmentInfos getLastCommittedSegmentInfos() {
public SegmentInfos getLastCommittedSegmentInfos() {
return lastCommittedSegmentInfos;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ protected ReferenceManager<ElasticsearchDirectoryReader> getReferenceManager(Sea
}

@Override
protected SegmentInfos getLastCommittedSegmentInfos() {
public SegmentInfos getLastCommittedSegmentInfos() {
return lastCommittedSegmentInfos;
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -510,58 +510,6 @@ public void testSegments() throws Exception {
assertThat(segments.get(1).committed, equalTo(committed));
}
}

public void testSegmentFileSizes() throws Exception {
final AtomicLong globalCheckpoint = new AtomicLong(SequenceNumbers.NO_OPS_PERFORMED);
try (
Store store = createStore();
InternalEngine engine = createEngine(
config(defaultSettings, store, createTempDir(), NoMergePolicy.INSTANCE, null, null, globalCheckpoint::get)
)
) {
assertThat(engine.segments(), empty());
int numDocsSeg1 = 100;
for (int i = 0; i < numDocsSeg1; i++) {
String id = Integer.toString(i);
ParsedDocument doc = testParsedDocument(id, null, testDocument(), B_1, null);
engine.index(indexForDoc(doc));
}
List<SegmentFileSize> fileSizes = engine.getLastCommittedSegmentFileSizes();
assertThat(fileSizes, empty());
List<Segment> segments = engine.segments();
assertThat(segments, empty());

engine.flush();
segments = engine.segments();
fileSizes = engine.getLastCommittedSegmentFileSizes();
assertThat(fileSizes, hasSize(1));
assertThat(fileSizes.get(0).sizeInBytes(), greaterThan(0L));
assertThat(segments, hasSize(1));
assertThat(segments.get(0).getNumDocs(), equalTo(numDocsSeg1));
assertThat(segments.get(0).getDeletedDocs(), equalTo(0));
assertTrue(segments.get(0).committed);
int numDocsSeg2 = 20;
for (int i = 0; i < numDocsSeg2; i++) {
engine.index(indexForDoc(testParsedDocument(UUIDs.randomBase64UUID(), null, testDocument(), B_1, null)));
}

engine.flush();
segments = engine.segments();
fileSizes = engine.getLastCommittedSegmentFileSizes();
assertThat(fileSizes, hasSize(2));
assertThat(segments, hasSize(2));
assertThat(segments.get(0).getNumDocs(), equalTo(numDocsSeg1));
assertThat(segments.get(0).getDeletedDocs(), equalTo(0));
assertTrue(segments.get(0).committed);
assertThat(fileSizes.get(0).sizeInBytes(), greaterThan(0L));

assertThat(segments.get(1).getNumDocs(), equalTo(numDocsSeg2));
assertThat(segments.get(1).getDeletedDocs(), equalTo(0));
assertTrue(segments.get(1).committed);
assertThat(fileSizes.get(1).sizeInBytes(), greaterThan(0L));
}
}

public void testCommitStats() throws IOException {
final AtomicLong maxSeqNo = new AtomicLong(SequenceNumbers.NO_OPS_PERFORMED);
final AtomicLong localCheckpoint = new AtomicLong(SequenceNumbers.NO_OPS_PERFORMED);
Expand Down

0 comments on commit d5074c6

Please sign in to comment.