Skip to content

Move calls to FeatureFlag.enabled to class-load time #125885

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

Merged
merged 2 commits into from
Apr 10, 2025
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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,11 @@ public void testSearchIdleStats() throws InterruptedException {
}

public void testSearchIdleBoolQueryMatchOneIndex() throws InterruptedException {
checkSearchIdleBoolQueryMatchOneIndex(IndexSettings.DOC_VALUES_SKIPPER.isEnabled());
checkSearchIdleBoolQueryMatchOneIndex(IndexSettings.DOC_VALUES_SKIPPER);
}

public void testSearchIdleBoolQueryMatchOneIndexWithDocValuesSkipper() throws InterruptedException {
assumeTrue("doc values skipper feature should be enabled", IndexSettings.DOC_VALUES_SKIPPER.isEnabled());
assumeTrue("doc values skipper feature should be enabled", IndexSettings.DOC_VALUES_SKIPPER);
checkSearchIdleBoolQueryMatchOneIndex(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@

public final class DataStream implements SimpleDiffable<DataStream>, ToXContentObject, IndexAbstraction {

public static final FeatureFlag FAILURE_STORE_FEATURE_FLAG = new FeatureFlag("failure_store");
public static final boolean FAILURE_STORE_FEATURE_FLAG = new FeatureFlag("failure_store").isEnabled();
public static final TransportVersion ADDED_FAILURE_STORE_TRANSPORT_VERSION = TransportVersions.V_8_12_0;
public static final TransportVersion ADDED_AUTO_SHARDING_EVENT_VERSION = TransportVersions.V_8_14_0;
public static final TransportVersion ADD_DATA_STREAM_OPTIONS_VERSION = TransportVersions.V_8_16_0;

public static boolean isFailureStoreFeatureFlagEnabled() {
return FAILURE_STORE_FEATURE_FLAG.isEnabled();
return FAILURE_STORE_FEATURE_FLAG;
}

public static final String BACKING_INDEX_PREFIX = ".ds-";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public final class IndexScopedSettings extends AbstractScopedSettings {
)
);

if (IndexSettings.DOC_VALUES_SKIPPER.isEnabled()) {
if (IndexSettings.DOC_VALUES_SKIPPER) {
settings.add(IndexSettings.USE_DOC_VALUES_SKIPPER);
}
BUILT_IN_INDEX_SETTINGS = Collections.unmodifiableSet(settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ public boolean isES87TSDBCodecEnabled() {
Property.Final
);

public static final FeatureFlag DOC_VALUES_SKIPPER = new FeatureFlag("doc_values_skipper");
public static final boolean DOC_VALUES_SKIPPER = new FeatureFlag("doc_values_skipper").isEnabled();
public static final Setting<Boolean> USE_DOC_VALUES_SKIPPER = Setting.boolSetting(
"index.mapping.use_doc_values_skipper",
false,
Expand Down Expand Up @@ -1095,7 +1095,7 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti
recoverySourceEnabled = RecoverySettings.INDICES_RECOVERY_SOURCE_ENABLED_SETTING.get(nodeSettings);
recoverySourceSyntheticEnabled = DiscoveryNode.isStateless(nodeSettings) == false
&& scopedSettings.get(RECOVERY_USE_SYNTHETIC_SOURCE_SETTING);
useDocValuesSkipper = DOC_VALUES_SKIPPER.isEnabled() && scopedSettings.get(USE_DOC_VALUES_SKIPPER);
useDocValuesSkipper = DOC_VALUES_SKIPPER && scopedSettings.get(USE_DOC_VALUES_SKIPPER);
if (recoverySourceSyntheticEnabled) {
if (DiscoveryNode.isStateless(settings)) {
throw new IllegalArgumentException("synthetic recovery source is only allowed in stateful");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
public class CodecService implements CodecProvider {

public static final FeatureFlag ZSTD_STORED_FIELDS_FEATURE_FLAG = new FeatureFlag("zstd_stored_fields");
public static final boolean ZSTD_STORED_FIELDS_FEATURE_FLAG = new FeatureFlag("zstd_stored_fields").isEnabled();

private final Map<String, Codec> codecs;

Expand All @@ -47,7 +47,7 @@ public CodecService(@Nullable MapperService mapperService, BigArrays bigArrays)
final var codecs = new HashMap<String, Codec>();

Codec legacyBestSpeedCodec = new LegacyPerFieldMapperCodec(Lucene101Codec.Mode.BEST_SPEED, mapperService, bigArrays);
if (ZSTD_STORED_FIELDS_FEATURE_FLAG.isEnabled()) {
if (ZSTD_STORED_FIELDS_FEATURE_FLAG) {
codecs.put(DEFAULT_CODEC, new PerFieldMapperCodec(Zstd814StoredFieldsFormat.Mode.BEST_SPEED, mapperService, bigArrays));
} else {
codecs.put(DEFAULT_CODEC, legacyBestSpeedCodec);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
public class ObjectMapper extends Mapper {
private static final Logger logger = LogManager.getLogger(ObjectMapper.class);
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(ObjectMapper.class);
public static final FeatureFlag SUB_OBJECTS_AUTO_FEATURE_FLAG = new FeatureFlag("sub_objects_auto");
public static final boolean SUB_OBJECTS_AUTO_FEATURE_FLAG = new FeatureFlag("sub_objects_auto").isEnabled();
static final NodeFeature SUBOBJECTS_FALSE_MAPPING_UPDATE_FIX = new NodeFeature("mapper.subobjects_false_mapping_update_fix");

public static final String CONTENT_TYPE = "object";
Expand Down Expand Up @@ -80,7 +80,7 @@ public static Subobjects from(Object node) {
if (value.equalsIgnoreCase("false")) {
return DISABLED;
}
if (SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled() && value.equalsIgnoreCase("auto")) {
if (SUB_OBJECTS_AUTO_FEATURE_FLAG && value.equalsIgnoreCase("auto")) {
return AUTO;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void testDefaultCodecLogsdb() {
}

public void testDefaultCodec() {
assumeTrue("Only when zstd_stored_fields feature flag is enabled", CodecService.ZSTD_STORED_FIELDS_FEATURE_FLAG.isEnabled());
assumeTrue("Only when zstd_stored_fields feature flag is enabled", CodecService.ZSTD_STORED_FIELDS_FEATURE_FLAG);

var indexService = createIndex("index1");
var storedFieldsFormat = (Zstd814StoredFieldsFormat) indexService.getShard(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@
public class CodecTests extends ESTestCase {

public void testResolveDefaultCodecs() throws Exception {
assumeTrue("Only when zstd_stored_fields feature flag is enabled", CodecService.ZSTD_STORED_FIELDS_FEATURE_FLAG.isEnabled());
assumeTrue("Only when zstd_stored_fields feature flag is enabled", CodecService.ZSTD_STORED_FIELDS_FEATURE_FLAG);
CodecService codecService = createCodecService();
assertThat(codecService.codec("default"), instanceOf(PerFieldMapperCodec.class));
assertThat(codecService.codec("default"), instanceOf(Elasticsearch900Lucene101Codec.class));
}

public void testDefault() throws Exception {
assumeTrue("Only when zstd_stored_fields feature flag is enabled", CodecService.ZSTD_STORED_FIELDS_FEATURE_FLAG.isEnabled());
assumeTrue("Only when zstd_stored_fields feature flag is enabled", CodecService.ZSTD_STORED_FIELDS_FEATURE_FLAG);
Codec codec = createCodecService().codec("default");
assertEquals(
"Zstd814StoredFieldsFormat(compressionMode=ZSTD(level=1), chunkSize=14336, maxDocsPerChunk=128, blockShift=10)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void testPostingsFormat() throws IOException {
MapperService mapperService = createMapperService(fieldMapping(this::minimalMapping));
CodecService codecService = new CodecService(mapperService, BigArrays.NON_RECYCLING_INSTANCE);
Codec codec = codecService.codec("default");
if (CodecService.ZSTD_STORED_FIELDS_FEATURE_FLAG.isEnabled()) {
if (CodecService.ZSTD_STORED_FIELDS_FEATURE_FLAG) {
assertThat(codec, instanceOf(PerFieldMapperCodec.class));
assertThat(((PerFieldMapperCodec) codec).getPostingsFormatForField("field"), instanceOf(latestLuceneCPClass));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,7 @@ public void testMalformedDynamicMapping_v7() throws IOException {
}

public void testSubobjectsAutoFlatPaths() throws IOException {
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG);
MapperService mapperService = createDynamicTemplateAutoSubobjects();
ParsedDocument doc = mapperService.documentMapper().parse(source(b -> {
b.field("foo.metric.count", 10);
Expand All @@ -1418,7 +1418,7 @@ public void testSubobjectsAutoFlatPaths() throws IOException {
}

public void testSubobjectsAutoStructuredPaths() throws IOException {
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG);
MapperService mapperService = createDynamicTemplateAutoSubobjects();
ParsedDocument doc = mapperService.documentMapper().parse(source(b -> {
b.startObject("foo");
Expand All @@ -1441,7 +1441,7 @@ public void testSubobjectsAutoStructuredPaths() throws IOException {
}

public void testSubobjectsAutoArrayOfObjects() throws IOException {
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG);
MapperService mapperService = createDynamicTemplateAutoSubobjects();
ParsedDocument doc = mapperService.documentMapper().parse(source(b -> {
b.startObject("foo");
Expand Down Expand Up @@ -1475,7 +1475,7 @@ public void testSubobjectsAutoArrayOfObjects() throws IOException {
}

public void testSubobjectAutoDynamicNested() throws IOException {
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG);
DocumentMapper mapper = createDocumentMapper(topMapping(b -> {
b.startArray("dynamic_templates");
{
Expand Down Expand Up @@ -1514,7 +1514,7 @@ public void testSubobjectAutoDynamicNested() throws IOException {
}

public void testRootSubobjectAutoDynamicNested() throws IOException {
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG);
DocumentMapper mapper = createDocumentMapper(topMapping(b -> {
b.startArray("dynamic_templates");
{
Expand Down Expand Up @@ -1548,7 +1548,7 @@ public void testRootSubobjectAutoDynamicNested() throws IOException {
}

public void testDynamicSubobjectsAutoDynamicFalse() throws Exception {
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG);
// verify that we read the dynamic value properly from the parent mapper. DocumentParser#dynamicOrDefault splits the field
// name where dots are found, but it does that only for the parent prefix e.g. metrics.service and not for the leaf suffix time.max
DocumentMapper mapper = createDocumentMapper(topMapping(b -> {
Expand Down Expand Up @@ -1612,7 +1612,7 @@ public void testDynamicSubobjectsAutoDynamicFalse() throws Exception {
}

public void testSubobjectsAutoWithInnerNestedFromDynamicTemplate() throws IOException {
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG);
DocumentMapper mapper = createDocumentMapper(topMapping(b -> {
b.startArray("dynamic_templates");
{
Expand Down Expand Up @@ -2080,7 +2080,7 @@ public void testSubobjectsFalseFlattened() throws IOException {
}

public void testSubobjectsAutoFlattened() throws IOException {
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG);
String mapping = """
{
"_doc": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public void testMergeEnabledForIndexTemplates() throws IOException {
assertEquals(ObjectMapper.Subobjects.ENABLED, objectMapper.subobjects());
assertTrue(objectMapper.sourceKeepMode().isEmpty());

if (ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled()) {
if (ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG) {
// Setting 'enabled' to true is allowed, and updates the mapping.
update = Strings.toString(
XContentFactory.jsonBuilder()
Expand Down Expand Up @@ -539,7 +539,7 @@ public void testSubobjectsCannotBeUpdatedOnRoot() throws IOException {
}

public void testSubobjectsAuto() throws Exception {
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG);
MapperService mapperService = createMapperService(mapping(b -> {
b.startObject("metrics.service");
{
Expand Down Expand Up @@ -569,7 +569,7 @@ public void testSubobjectsAuto() throws Exception {
}

public void testSubobjectsAutoWithInnerObject() throws IOException {
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG);
MapperService mapperService = createMapperService(mapping(b -> {
b.startObject("metrics.service");
{
Expand Down Expand Up @@ -603,7 +603,7 @@ public void testSubobjectsAutoWithInnerObject() throws IOException {
}

public void testSubobjectsAutoWithInnerNested() throws IOException {
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG);
MapperService mapperService = createMapperService(mapping(b -> {
b.startObject("metrics.service");
{
Expand All @@ -625,7 +625,7 @@ public void testSubobjectsAutoWithInnerNested() throws IOException {
}

public void testSubobjectsAutoRoot() throws Exception {
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG);
MapperService mapperService = createMapperService(mappingWithSubobjects(b -> {
b.startObject("metrics.service.time");
b.field("type", "long");
Expand All @@ -646,7 +646,7 @@ public void testSubobjectsAutoRoot() throws Exception {
}

public void testSubobjectsAutoRootWithInnerObject() throws IOException {
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG);
MapperService mapperService = createMapperService(mappingWithSubobjects(b -> {
b.startObject("metrics.service.time");
{
Expand All @@ -667,7 +667,7 @@ public void testSubobjectsAutoRootWithInnerObject() throws IOException {
}

public void testSubobjectsAutoRootWithInnerNested() throws IOException {
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG.isEnabled());
assumeTrue("only test when feature flag for subobjects auto is enabled", ObjectMapper.SUB_OBJECTS_AUTO_FEATURE_FLAG);
MapperService mapperService = createMapperService(mappingWithSubobjects(b -> {
b.startObject("metrics.service");
b.field("type", "nested");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1992,7 +1992,7 @@ public void testKnnVectorsFormat() throws IOException {
CodecService codecService = new CodecService(mapperService, BigArrays.NON_RECYCLING_INSTANCE);
Codec codec = codecService.codec("default");
KnnVectorsFormat knnVectorsFormat;
if (CodecService.ZSTD_STORED_FIELDS_FEATURE_FLAG.isEnabled()) {
if (CodecService.ZSTD_STORED_FIELDS_FEATURE_FLAG) {
assertThat(codec, instanceOf(PerFieldMapperCodec.class));
knnVectorsFormat = ((PerFieldMapperCodec) codec).getKnnVectorsFormatForField("field");
} else {
Expand Down Expand Up @@ -2030,7 +2030,7 @@ public void testKnnQuantizedFlatVectorsFormat() throws IOException {
CodecService codecService = new CodecService(mapperService, BigArrays.NON_RECYCLING_INSTANCE);
Codec codec = codecService.codec("default");
KnnVectorsFormat knnVectorsFormat;
if (CodecService.ZSTD_STORED_FIELDS_FEATURE_FLAG.isEnabled()) {
if (CodecService.ZSTD_STORED_FIELDS_FEATURE_FLAG) {
assertThat(codec, instanceOf(PerFieldMapperCodec.class));
knnVectorsFormat = ((PerFieldMapperCodec) codec).getKnnVectorsFormatForField("field");
} else {
Expand Down Expand Up @@ -2081,7 +2081,7 @@ public void testKnnQuantizedHNSWVectorsFormat() throws IOException {
CodecService codecService = new CodecService(mapperService, BigArrays.NON_RECYCLING_INSTANCE);
Codec codec = codecService.codec("default");
KnnVectorsFormat knnVectorsFormat;
if (CodecService.ZSTD_STORED_FIELDS_FEATURE_FLAG.isEnabled()) {
if (CodecService.ZSTD_STORED_FIELDS_FEATURE_FLAG) {
assertThat(codec, instanceOf(PerFieldMapperCodec.class));
knnVectorsFormat = ((PerFieldMapperCodec) codec).getKnnVectorsFormatForField("field");
} else {
Expand Down Expand Up @@ -2127,7 +2127,7 @@ public void testKnnBBQHNSWVectorsFormat() throws IOException {
CodecService codecService = new CodecService(mapperService, BigArrays.NON_RECYCLING_INSTANCE);
Codec codec = codecService.codec("default");
KnnVectorsFormat knnVectorsFormat;
if (CodecService.ZSTD_STORED_FIELDS_FEATURE_FLAG.isEnabled()) {
if (CodecService.ZSTD_STORED_FIELDS_FEATURE_FLAG) {
assertThat(codec, instanceOf(PerFieldMapperCodec.class));
knnVectorsFormat = ((PerFieldMapperCodec) codec).getKnnVectorsFormatForField("field");
} else {
Expand Down Expand Up @@ -2185,7 +2185,7 @@ public void testKnnHalfByteQuantizedHNSWVectorsFormat() throws IOException {
CodecService codecService = new CodecService(mapperService, BigArrays.NON_RECYCLING_INSTANCE);
Codec codec = codecService.codec("default");
KnnVectorsFormat knnVectorsFormat;
if (CodecService.ZSTD_STORED_FIELDS_FEATURE_FLAG.isEnabled()) {
if (CodecService.ZSTD_STORED_FIELDS_FEATURE_FLAG) {
assertThat(codec, instanceOf(PerFieldMapperCodec.class));
knnVectorsFormat = ((PerFieldMapperCodec) codec).getKnnVectorsFormatForField("field");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ private void fail(Expression exp, String message, Object... args) {

@Override
public PlanFactory visitInlinestatsCommand(EsqlBaseParser.InlinestatsCommandContext ctx) {
if (false == EsqlPlugin.INLINESTATS_FEATURE_FLAG.isEnabled()) {
if (false == EsqlPlugin.INLINESTATS_FEATURE_FLAG) {
throw new ParsingException(source(ctx), "INLINESTATS command currently requires a snapshot build");
}
List<Alias> aggFields = visitAggFields(ctx.stats);
Expand Down
Loading