Skip to content

Commit

Permalink
Add sample test
Browse files Browse the repository at this point in the history
Signed-off-by: Sachin Kale <[email protected]>
  • Loading branch information
Sachin Kale committed Oct 3, 2023
1 parent 7dc6683 commit 098efca
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import org.opensearch.test.BackgroundIndexer;
import org.opensearch.test.InternalTestCluster;
import org.opensearch.test.OpenSearchIntegTestCase;
import org.opensearch.test.junit.annotations.TestIssueLogging;
import org.opensearch.test.transport.MockTransportService;
import org.opensearch.transport.TransportService;
import org.junit.Before;
Expand Down Expand Up @@ -126,6 +127,26 @@ private static String indexOrAlias() {
return randomBoolean() ? INDEX_NAME : "alias";
}

@TestIssueLogging(value = "_root:TRACE", issueUrl = "issue debug")
public void testSimpleIndexingFlow() {
String primaryNode = internalCluster().startDataOnlyNode();
createIndex(INDEX_NAME, Settings.builder()
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
.put(IndexMetadata.SETTING_REPLICATION_TYPE, ReplicationType.SEGMENT)
.build());
ensureYellowAndNoInitializingShards(INDEX_NAME);
ensureGreen(INDEX_NAME);

int numDocs = randomIntBetween(10, 20);
for (int i = 0; i < numDocs; i++) {
String id = Integer.toString(i);
client(primaryNode).prepareIndex(INDEX_NAME).setId(id).setSource("text", "sometext").get();
}

client(primaryNode).admin().indices().prepareFlush(INDEX_NAME).setForce(true).execute().actionGet();
}

public void testPrimaryStopped_ReplicaPromoted() throws Exception {
final String primary = internalCluster().startDataOnlyNode();
createIndex(INDEX_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1856,8 +1856,8 @@ public void flush(boolean force, boolean waitIfOngoing) throws EngineException {
|| force
|| shouldPeriodicallyFlush
|| getProcessedLocalCheckpoint() > Long.parseLong(
lastCommittedSegmentInfos.userData.get(SequenceNumbers.LOCAL_CHECKPOINT_KEY)
)) {
lastCommittedSegmentInfos.userData.get(SequenceNumbers.LOCAL_CHECKPOINT_KEY)
)) {
translogManager.ensureCanFlush();
try {
translogManager.rollTranslogGeneration();
Expand Down Expand Up @@ -1887,6 +1887,18 @@ public void flush(boolean force, boolean waitIfOngoing) throws EngineException {
latestCommit.close();
}

try (GatedCloseable<IndexCommit> latestCommit2 = acquireLastIndexCommit(false)) {
SegmentInfos directoryInfos = store.readLastCommittedSegmentsInfo();
if (latestCommit2.get().getGeneration() == directoryInfos.getGeneration()) {
logger.info("--> Same generations");
}
assert latestCommit2.get().getGeneration() == directoryInfos.getGeneration() : "Different generations";
} catch (Throwable t) {
if (t instanceof AssertionError) {
throw (AssertionError) t;
}
}

translogManager.trimUnreferencedReaders();
} catch (AlreadyClosedException e) {
failOnTragicEvent(e);
Expand All @@ -1909,6 +1921,7 @@ public void flush(boolean force, boolean waitIfOngoing) throws EngineException {
if (engineConfig.isEnableGcDeletes()) {
pruneDeletedTombstones();
}

}

private void refreshLastCommittedSegmentInfos() {
Expand Down

0 comments on commit 098efca

Please sign in to comment.