-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[Segment Replication] Update getSegmentInfosSnapshot() logic to return SegmentInfos with highest generation number #4288
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7546,6 +7546,61 @@ public void testGetSegmentInfosSnapshot() throws IOException { | |
engine.close(); | ||
} | ||
|
||
// This method simulates behaviour of on-disk SegmentInfos having higher segment generation number compared to | ||
// actual in-memory SegmentInfos and verified that engine.getSegmentInfosSnapshot returns on-disk SegmentInfos | ||
public void testGetSegmentInfosWithHighestGenOnDisk() throws IOException { | ||
IOUtils.close(store, engine); | ||
Store store = spy(createStore()); | ||
InternalEngine engine = createEngine(store, createTempDir()); | ||
final int numDocs = randomIntBetween(10, 100); | ||
for (int docId = 0; docId < numDocs; docId++) { | ||
index(engine, docId); | ||
if (randomBoolean()) { | ||
engine.refresh("test"); | ||
} | ||
} | ||
engine.flush(true, true); | ||
|
||
SegmentInfos sisDisk = store.readLastCommittedSegmentsInfo(); | ||
// Increment generation number of on-disk SegmentInfos | ||
sisDisk.setNextWriteGeneration(sisDisk.getGeneration() + 1); | ||
|
||
when(store.getLastCommitGeneration()).thenReturn(sisDisk.getGeneration()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than mocking here, you should be able to invoke SegmentInfos.commit and create a new _N file with a higher generation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for sharing this, I wasn't aware of this method. I tried |
||
when(store.readLastCommittedSegmentsInfo()).thenReturn(sisDisk); | ||
|
||
GatedCloseable<SegmentInfos> segmentInfosSnapshot = engine.getSegmentInfosSnapshot(); | ||
assertEquals(segmentInfosSnapshot.get(), sisDisk); | ||
assertEquals(segmentInfosSnapshot.get().getGeneration(), sisDisk.getGeneration()); | ||
segmentInfosSnapshot.close(); | ||
store.close(); | ||
engine.close(); | ||
} | ||
|
||
// This method verifies that when on-disk segment generation is not higher compared to memory copy, then | ||
// engine.getSegmentInfosSnapsho returns in-memory SegmentInfos | ||
public void testGetSegmentInfosWithHighestGenInMemory() throws IOException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -> This test case will have both in-memory and on-disk segmentInfos on same segment generation number but not lower on on-disk as it is mentioned (or purpose of this test case). In this test case we are not incrementing or decrementing segment generation of either on-disk on in-memory, so both will be same. So we are not testing the case here that we actually want to. -> Is this test really necessary? Will there be a scenario ever with on-disk segmentInfos having lower segment generation number than in-memory ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
IOUtils.close(store, engine); | ||
Store store = spy(createStore()); | ||
InternalEngine engine = createEngine(store, createTempDir()); | ||
final int numDocs = randomIntBetween(10, 100); | ||
for (int docId = 0; docId < numDocs; docId++) { | ||
index(engine, docId); | ||
if (randomBoolean()) { | ||
engine.refresh("test"); | ||
} | ||
} | ||
engine.flush(true, true); | ||
|
||
SegmentInfos sisInMemory = engine.getLatestSegmentInfos(); | ||
|
||
GatedCloseable<SegmentInfos> segmentInfosSnapshot = engine.getSegmentInfosSnapshot(); | ||
assertEquals(segmentInfosSnapshot.get(), sisInMemory); | ||
assertEquals(segmentInfosSnapshot.get().getGeneration(), sisInMemory.getGeneration()); | ||
segmentInfosSnapshot.close(); | ||
store.close(); | ||
engine.close(); | ||
} | ||
|
||
public void testGetProcessedLocalCheckpoint() throws IOException { | ||
final long expectedLocalCheckpoint = 1L; | ||
IOUtils.close(store, engine); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need this method on the store? can we call
directly from InternalEngine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created new method for consistency purpose as to keep disk(store) related calls on Store