Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.elasticsearch.action.support.DefaultShardOperationFailedException;
import org.elasticsearch.action.support.WriteRequest;
import org.elasticsearch.action.support.broadcast.BroadcastResponse;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.common.Randomness;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference;
Expand All @@ -38,6 +39,7 @@
import org.elasticsearch.index.engine.EngineTestCase;
import org.elasticsearch.index.engine.VersionConflictEngineException;
import org.elasticsearch.index.mapper.SourceFieldMapper;
import org.elasticsearch.index.seqno.SequenceNumbers;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.test.ESIntegTestCase;
Expand Down Expand Up @@ -1099,6 +1101,67 @@ private GetResponse multiGetDocument(String index, String docId, String field, @
return multiGetResponse.getResponses()[0].getResponse();
}

public void testGetWithSequenceNumbersDisabled() {
assumeTrue("Test should only run with feature flag", IndexSettings.DISABLE_SEQUENCE_NUMBERS_FEATURE_FLAG);
String index = "test-seq-no-disabled";
assertAcked(
prepareCreate(index).setSettings(
Settings.builder()
.put(IndexSettings.DISABLE_SEQUENCE_NUMBERS.getKey(), true)
.put("index.refresh_interval", -1)
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
)
);

prepareIndex(index).setId("1").setSource("field", "value1").get();
prepareIndex(index).setId("2").setSource("field", "value2").get();
prepareIndex(index).setId("3").setSource("field", "value3").get();

assertSeqNoDisabledGet(client().prepareGet(index, "1").get());
assertSeqNoDisabledGet(client().prepareGet(index, "2").get());

MultiGetResponse mgetResponse = client().prepareMultiGet().add(index, "1").add(index, "2").add(index, "3").get();
assertThat(mgetResponse.getResponses().length, equalTo(3));
for (MultiGetItemResponse item : mgetResponse.getResponses()) {
assertSeqNoDisabledGet(item.getResponse());
}

refresh(index);

assertSeqNoDisabledGet(client().prepareGet(index, "1").get());
assertSeqNoDisabledGet(client().prepareGet(index, "2").setRealtime(false).get());

mgetResponse = client().prepareMultiGet().add(index, "1").add(index, "2").add(index, "3").get();
for (MultiGetItemResponse item : mgetResponse.getResponses()) {
assertSeqNoDisabledGet(item.getResponse());
}

prepareIndex(index).setId("4").setSource("field", "value4").get();
assertSeqNoDisabledGet(client().prepareGet(index, "4").get());

flush(index);

assertSeqNoDisabledGet(client().prepareGet(index, "1").get());
assertSeqNoDisabledGet(client().prepareGet(index, "3").setRealtime(false).get());
assertSeqNoDisabledGet(client().prepareGet(index, "4").get());

mgetResponse = client().prepareMultiGet().add(index, "1").add(index, "2").add(index, "3").add(index, "4").get();
assertThat(mgetResponse.getResponses().length, equalTo(4));
for (MultiGetItemResponse item : mgetResponse.getResponses()) {
assertSeqNoDisabledGet(item.getResponse());
}

prepareIndex(index).setId("1").setSource("field", "value1_updated").get();
assertSeqNoDisabledGet(client().prepareGet(index, "1").get());
}

private static void assertSeqNoDisabledGet(GetResponse response) {
assertTrue(response.isExists());
assertThat(response.getSeqNo(), equalTo(SequenceNumbers.UNASSIGNED_SEQ_NO));
assertThat(response.getPrimaryTerm(), equalTo(SequenceNumbers.UNASSIGNED_PRIMARY_TERM));
}

private GetResponse getDocument(String index, String docId, String field, @Nullable String routing) {
return getDocument(index, docId, r -> {
r.setStoredFields(field);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -912,12 +912,13 @@ public NoOpResult(long term, long seqNo) {
}

protected final GetResult getFromSearcher(Get get, Engine.Searcher searcher, boolean uncachedLookup) throws EngineException {
final boolean loadSeqNo = engineConfig.getIndexSettings().sequenceNumbersDisabled() == false;
final DocIdAndVersion docIdAndVersion;
try {
if (uncachedLookup) {
docIdAndVersion = VersionsAndSeqNoResolver.loadDocIdAndVersionUncached(searcher.getIndexReader(), get.uid(), true);
docIdAndVersion = VersionsAndSeqNoResolver.loadDocIdAndVersionUncached(searcher.getIndexReader(), get.uid(), loadSeqNo);
} else {
docIdAndVersion = VersionsAndSeqNoResolver.timeSeriesLoadDocIdAndVersion(searcher.getIndexReader(), get.uid(), true);
docIdAndVersion = VersionsAndSeqNoResolver.timeSeriesLoadDocIdAndVersion(searcher.getIndexReader(), get.uid(), loadSeqNo);
}
} catch (Exception e) {
Releasables.closeWhileHandlingException(searcher);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7767,6 +7767,39 @@ private static void assertCommitGenerations(List<IndexCommit> commits, List<Long
);
}

public void testGetWithSequenceNumbersDisabled() throws IOException {
assumeTrue("Test should only run with feature flag", IndexSettings.DISABLE_SEQUENCE_NUMBERS_FEATURE_FLAG);
Settings settings = Settings.builder()
.put(defaultSettings.getSettings())
.put(IndexSettings.DISABLE_SEQUENCE_NUMBERS.getKey(), true)
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you can you add SEQ_NO_INDEX_OPTIONS_SETTING to docs values only already that's great.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add it to #143583.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, the bot got there first!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No pb :)

.build();
IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("test", settings);
assertTrue(indexSettings.sequenceNumbersDisabled());
try (
Store store = createStore();
InternalEngine engine = createEngine(config(indexSettings, store, createTempDir(), NoMergePolicy.INSTANCE, null))
) {
ParsedDocument doc = testParsedDocument("1", null, testDocumentWithTextField(), B_1, null);
engine.index(indexForDoc(doc));
engine.refresh("test");

MapperService mapperService = createMapperService();
try (
Engine.GetResult get = engine.get(
new Engine.Get(true, false, doc.id()),
mapperService.mappingLookup(),
mapperService.documentParser(),
randomSearcherWrapper()
)
) {
assertTrue(get.exists());
assertThat(get.docIdAndVersion().seqNo, equalTo(UNASSIGNED_SEQ_NO));
assertThat(get.docIdAndVersion().primaryTerm, equalTo(UNASSIGNED_PRIMARY_TERM));
}
}
}

private static void releaseCommitRef(Map<IndexCommit, Engine.IndexCommitRef> commits, long generation) {
var releasable = commits.keySet().stream().filter(c -> c.getGeneration() == generation).findFirst();
assertThat(releasable, isPresent());
Expand Down