Skip to content

Commit

Permalink
Add criteria based IndexWriter changes behind a setting
Browse files Browse the repository at this point in the history
  • Loading branch information
RS146BIJAY committed Oct 21, 2024
1 parent 134283c commit 908b5ca
Show file tree
Hide file tree
Showing 9 changed files with 269 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ public Iterator<Setting<?>> settings() {
);

public static final String SETTING_REMOTE_STORE_ENABLED = "index.remote_store.enabled";
public static final String SETTING_CONTEXT_AWARE_ENABLED = "index.context_aware.enabled";

public static final String SETTING_REMOTE_SEGMENT_STORE_REPOSITORY = "index.remote_store.segment.repository";

Expand Down Expand Up @@ -384,6 +385,13 @@ public Iterator<Setting<?>> settings() {
Property.Dynamic
);

public static final Setting<Boolean> INDEX_CONTEXT_AWARE_ENABLED_SETTING = Setting.boolSetting(
SETTING_CONTEXT_AWARE_ENABLED,
false,
Property.IndexScope,
Property.Dynamic
);

/**
* Used to specify remote store repository to use for this index.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ public final class IndexScopedSettings extends AbstractScopedSettings {
IndexSettings.INDEX_CONTEXT_CREATED_VERSION,
IndexSettings.INDEX_CONTEXT_CURRENT_VERSION,

IndexMetadata.INDEX_CONTEXT_AWARE_ENABLED_SETTING,

// validate that built-in similarities don't get redefined
Setting.groupSetting("index.similarity.", (s) -> {
Map<String, Settings> groups = s.getAsGroups();
Expand Down
11 changes: 11 additions & 0 deletions server/src/main/java/org/opensearch/index/IndexSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,7 @@ public static IndexMergePolicy fromString(String text) {
private final int numberOfShards;
private final ReplicationType replicationType;
private volatile boolean isRemoteStoreEnabled;
private volatile boolean isContextAwareEnabled;
private final boolean isStoreLocalityPartial;
private volatile TimeValue remoteTranslogUploadBufferInterval;
private volatile String remoteStoreTranslogRepository;
Expand Down Expand Up @@ -994,6 +995,7 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti
numberOfShards = settings.getAsInt(IndexMetadata.SETTING_NUMBER_OF_SHARDS, null);
replicationType = IndexMetadata.INDEX_REPLICATION_TYPE_SETTING.get(settings);
isRemoteStoreEnabled = settings.getAsBoolean(IndexMetadata.SETTING_REMOTE_STORE_ENABLED, false);
isContextAwareEnabled = settings.getAsBoolean(IndexMetadata.SETTING_CONTEXT_AWARE_ENABLED, false);
isStoreLocalityPartial = settings.get(
IndexModule.INDEX_STORE_LOCALITY_SETTING.getKey(),
IndexModule.DataLocalityType.FULL.toString()
Expand Down Expand Up @@ -1192,6 +1194,7 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti
);
scopedSettings.addSettingsUpdateConsumer(ALLOW_DERIVED_FIELDS, this::setAllowDerivedField);
scopedSettings.addSettingsUpdateConsumer(IndexMetadata.INDEX_REMOTE_STORE_ENABLED_SETTING, this::setRemoteStoreEnabled);
scopedSettings.addSettingsUpdateConsumer(IndexMetadata.INDEX_CONTEXT_AWARE_ENABLED_SETTING, this::setContextAwareEnabled);
scopedSettings.addSettingsUpdateConsumer(
IndexMetadata.INDEX_REMOTE_SEGMENT_STORE_REPOSITORY_SETTING,
this::setRemoteStoreRepository
Expand Down Expand Up @@ -1347,6 +1350,10 @@ public boolean isRemoteStoreEnabled() {
return isRemoteStoreEnabled;
}

public boolean isContextAwareEnabled() {
return isContextAwareEnabled;
}

public boolean isAssignedOnRemoteNode() {
return assignedOnRemoteNode;
}
Expand Down Expand Up @@ -2027,6 +2034,10 @@ public void setRemoteStoreEnabled(boolean isRemoteStoreEnabled) {
this.isRemoteStoreEnabled = isRemoteStoreEnabled;
}

public void setContextAwareEnabled(boolean contextAwareEnabled) {
isContextAwareEnabled = contextAwareEnabled;
}

public void setRemoteStoreRepository(String remoteStoreRepository) {
this.remoteStoreRepository = remoteStoreRepository;
}
Expand Down
12 changes: 12 additions & 0 deletions server/src/main/java/org/opensearch/index/engine/EngineConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ private static void doValidateCodecSettings(final String codec) {
private final TranslogConfig translogConfig;

private final TranslogFactory translogFactory;
private final boolean isContextAwareEnabled;

/**
* Creates a new {@link org.opensearch.index.engine.EngineConfig}
Expand Down Expand Up @@ -296,6 +297,7 @@ private EngineConfig(Builder builder) {
this.startedPrimarySupplier = builder.startedPrimarySupplier;
this.translogFactory = builder.translogFactory;
this.leafSorter = builder.leafSorter;
this.isContextAwareEnabled = builder.isContextAwareEnabled;
}

/**
Expand Down Expand Up @@ -355,6 +357,10 @@ public Engine.Warmer getWarmer() {
return warmer;
}

public boolean isContextAwareEnabled() {
return isContextAwareEnabled;
}

/**
* Returns the {@link org.opensearch.index.store.Store} instance that provides access to the
* {@link org.apache.lucene.store.Directory} used for the engines {@link org.apache.lucene.index.IndexWriter} to write it's index files
Expand Down Expand Up @@ -590,6 +596,7 @@ public static class Builder {
private BooleanSupplier startedPrimarySupplier;
private TranslogFactory translogFactory = new InternalTranslogFactory();
Comparator<LeafReader> leafSorter;
private boolean isContextAwareEnabled;

public Builder shardId(ShardId shardId) {
this.shardId = shardId;
Expand Down Expand Up @@ -726,6 +733,11 @@ public Builder leafSorter(Comparator<LeafReader> leafSorter) {
return this;
}

public Builder isContextAwareEnabled(boolean isContextAwareEnabled) {
this.isContextAwareEnabled = isContextAwareEnabled;
return this;
}

public EngineConfig build() {
return new EngineConfig(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ public EngineConfig newEngineConfig(
boolean isReadOnlyReplica,
BooleanSupplier startedPrimarySupplier,
TranslogFactory translogFactory,
Comparator<LeafReader> leafSorter
Comparator<LeafReader> leafSorter,
boolean isContextAwareEnabled
) {
CodecService codecServiceToUse = codecService;
if (codecService == null && this.codecServiceFactory != null) {
Expand Down Expand Up @@ -188,6 +189,7 @@ public EngineConfig newEngineConfig(
.startedPrimarySupplier(startedPrimarySupplier)
.translogFactory(translogFactory)
.leafSorter(leafSorter)
.isContextAwareEnabled(isContextAwareEnabled)
.build();
}

Expand Down
Loading

0 comments on commit 908b5ca

Please sign in to comment.