|
24 | 24 | import org.elasticsearch.index.engine.EngineConfig; |
25 | 25 | import org.elasticsearch.index.mapper.MapperMetrics; |
26 | 26 | import org.elasticsearch.index.mapper.MapperRegistry; |
| 27 | +import org.elasticsearch.index.mapper.SeqNoFieldMapper; |
27 | 28 | import org.elasticsearch.index.translog.Translog; |
28 | 29 | import org.elasticsearch.plugins.MapperPlugin; |
29 | 30 | import org.elasticsearch.test.ESTestCase; |
@@ -1081,12 +1082,75 @@ public void testDisableSequenceNumbersSetting() { |
1081 | 1082 | IndexVersion indexVersion = IndexVersionUtils.randomVersionBetween(IndexVersions.DISABLE_SEQUENCE_NUMBERS, IndexVersion.current()); |
1082 | 1083 |
|
1083 | 1084 | var disabled = randomBoolean(); |
1084 | | - Settings settings = Settings.builder().put(IndexSettings.DISABLE_SEQUENCE_NUMBERS.getKey(), disabled).build(); |
| 1085 | + Settings settings = Settings.builder() |
| 1086 | + .put(IndexSettings.DISABLE_SEQUENCE_NUMBERS.getKey(), disabled) |
| 1087 | + .put(IndexSettings.SEQ_NO_INDEX_OPTIONS_SETTING.getKey(), SeqNoFieldMapper.SeqNoIndexOptions.DOC_VALUES_ONLY) |
| 1088 | + .build(); |
1085 | 1089 | IndexMetadata indexMetadata = newIndexMeta("some-index", settings, indexVersion); |
1086 | 1090 | IndexSettings indexSettings = new IndexSettings(indexMetadata, Settings.EMPTY); |
1087 | 1091 | assertThat(indexSettings.sequenceNumbersDisabled(), is(equalTo(disabled))); |
1088 | 1092 | } |
1089 | 1093 |
|
| 1094 | + public void testDisableSequenceNumbersRequiresDocValuesOnly() { |
| 1095 | + assumeTrue("Test should only run with feature flag", IndexSettings.DISABLE_SEQUENCE_NUMBERS_FEATURE_FLAG); |
| 1096 | + final var indexVersion = IndexVersionUtils.randomVersionBetween(IndexVersions.DISABLE_SEQUENCE_NUMBERS, IndexVersion.current()); |
| 1097 | + |
| 1098 | + var builder = Settings.builder().put(IndexSettings.DISABLE_SEQUENCE_NUMBERS.getKey(), true); |
| 1099 | + if (randomBoolean()) { |
| 1100 | + builder.put( |
| 1101 | + IndexSettings.SEQ_NO_INDEX_OPTIONS_SETTING.getKey(), |
| 1102 | + SeqNoFieldMapper.SeqNoIndexOptions.POINTS_AND_DOC_VALUES |
| 1103 | + ); |
| 1104 | + } |
| 1105 | + var indexMetadata = newIndexMeta("some-index", builder.build(), indexVersion); |
| 1106 | + var e = assertThrows( |
| 1107 | + IllegalArgumentException.class, |
| 1108 | + () -> new IndexSettings(indexMetadata, Settings.EMPTY) |
| 1109 | + ); |
| 1110 | + assertThat( |
| 1111 | + e.getMessage(), |
| 1112 | + Matchers.containsString( |
| 1113 | + String.format( |
| 1114 | + Locale.ROOT, |
| 1115 | + "The setting [%s] is only permitted when [%s] is set to [%s]. Current value: [%s].", |
| 1116 | + IndexSettings.DISABLE_SEQUENCE_NUMBERS.getKey(), |
| 1117 | + IndexSettings.SEQ_NO_INDEX_OPTIONS_SETTING.getKey(), |
| 1118 | + SeqNoFieldMapper.SeqNoIndexOptions.DOC_VALUES_ONLY, |
| 1119 | + SeqNoFieldMapper.SeqNoIndexOptions.POINTS_AND_DOC_VALUES |
| 1120 | + ) |
| 1121 | + ) |
| 1122 | + ); |
| 1123 | + } |
| 1124 | + |
| 1125 | + public void testDisableSequenceNumbersRequiresDocValuesOnlyForNonStandardModes() { |
| 1126 | + assumeTrue("Test should only run with feature flag", IndexSettings.DISABLE_SEQUENCE_NUMBERS_FEATURE_FLAG); |
| 1127 | + IndexVersion indexVersion = IndexVersionUtils.randomVersionBetween(IndexVersions.DISABLE_SEQUENCE_NUMBERS, IndexVersion.current()); |
| 1128 | + |
| 1129 | + IndexMode mode = randomFrom(IndexMode.TIME_SERIES, IndexMode.LOGSDB); |
| 1130 | + Settings.Builder builder = Settings.builder() |
| 1131 | + .put(IndexSettings.MODE.getKey(), mode.getName()) |
| 1132 | + .put(IndexSettings.SEQ_NO_INDEX_OPTIONS_SETTING.getKey(), SeqNoFieldMapper.SeqNoIndexOptions.POINTS_AND_DOC_VALUES) |
| 1133 | + .put(IndexSettings.DISABLE_SEQUENCE_NUMBERS.getKey(), true); |
| 1134 | + if (mode == IndexMode.TIME_SERIES) { |
| 1135 | + builder.put(IndexMetadata.INDEX_ROUTING_PATH.getKey(), "foo"); |
| 1136 | + } |
| 1137 | + IndexMetadata indexMetadata = newIndexMeta("some-index", builder.build(), indexVersion); |
| 1138 | + IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> new IndexSettings(indexMetadata, Settings.EMPTY)); |
| 1139 | + assertThat( |
| 1140 | + e.getMessage(), |
| 1141 | + Matchers.containsString( |
| 1142 | + String.format( |
| 1143 | + Locale.ROOT, |
| 1144 | + "The setting [%s] is only permitted when [%s] is set to [%s]. Current value: [%s].", |
| 1145 | + IndexSettings.DISABLE_SEQUENCE_NUMBERS.getKey(), |
| 1146 | + IndexSettings.SEQ_NO_INDEX_OPTIONS_SETTING.getKey(), |
| 1147 | + SeqNoFieldMapper.SeqNoIndexOptions.DOC_VALUES_ONLY, |
| 1148 | + SeqNoFieldMapper.SeqNoIndexOptions.POINTS_AND_DOC_VALUES |
| 1149 | + ) |
| 1150 | + ) |
| 1151 | + ); |
| 1152 | + } |
| 1153 | + |
1090 | 1154 | public void testDisableSequenceNumbersValidationWithInvalidVersion() { |
1091 | 1155 | assumeTrue("Test should only run with feature flag", IndexSettings.DISABLE_SEQUENCE_NUMBERS_FEATURE_FLAG); |
1092 | 1156 | IndexVersion badVersion = IndexVersionUtils.getPreviousVersion(IndexVersions.DISABLE_SEQUENCE_NUMBERS); |
|
0 commit comments