Skip to content
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

Set additional settings at index level for knn enabled indexes #738

Closed
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
31 changes: 28 additions & 3 deletions src/main/java/org/opensearch/knn/plugin/KNNPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.opensearch.common.ParseField;
import org.opensearch.index.codec.CodecServiceFactory;
import org.opensearch.index.engine.EngineFactory;
import org.opensearch.index.shard.IndexSettingProvider;
import org.opensearch.indices.SystemIndexDescriptor;
import org.opensearch.knn.index.KNNCircuitBreaker;
import org.opensearch.knn.index.KNNClusterUtil;
Expand Down Expand Up @@ -342,12 +343,35 @@ public Collection<SystemIndexDescriptor> getSystemIndexDescriptors(Settings sett
}

/**
* Plugin can provide additional node settings, that includes new settings or overrides for existing one from core.
* Plugin can provide additional index settings, that includes new settings or overrides for existing one from core.
*
* @return settings that are set by plugin
*/
@Override
public Settings additionalSettings() {
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to keep it for cluster level as well for indices that upgrade or were created on an old version of the cluster?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's not required as we apply the setting in the code, it's not persisted. Also if customer used custom index-level overwrites that will apply to 2.6 as well. Customer values should overwrite both cluster defaults and index provided by the plugin.

Copy link
Member

Choose a reason for hiding this comment

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

Right, but assume that a customer did not apply any override. On 2.5, by default, their index with use vex/vec in the setting because we apply the cluster override. However, in 2.6, if no cluster override is provided, the index will not use vex/vec in the setting. So this could be an unexpected degradation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Checked with quick bwc test, indexes from 2.5 do not have index level setting when opened in 2.6, setting is stored along with the index and doesn't apply on index or shard opening as I was initially thinking.

public Collection<IndexSettingProvider> getAdditionalIndexSettingProviders() {
final IndexSettingProvider settingProvider = new IndexSettingProvider() {
@Override
public Settings getAdditionalIndexSettings(
final String indexName,
boolean isDataStreamIndex,
final Settings templateAndRequestSettings
) {
return pluginAdditionalSettings(templateAndRequestSettings);
}
};
return List.of(settingProvider);
}

private Settings pluginAdditionalSettings(final Settings templateAndRequestSettings) {
final var settingsBuilder = Settings.builder();
boolean isKnnIndex = Boolean.parseBoolean(templateAndRequestSettings.get(KNNSettings.KNN_INDEX, Boolean.FALSE.toString()));
if (isKnnIndex) {
additionalMMapFileExtensionsForHybridFs(settingsBuilder);
}
return settingsBuilder.build();
}

private void additionalMMapFileExtensionsForHybridFs(final Settings.Builder settingsBuilder) {
// We add engine specific extensions to the core list for HybridFS store type. We read existing values
// and append ours because in core setting will be replaced by override.
// Values are set as cluster defaults and are used at index creation time. Index specific overrides will take priority over values
Expand All @@ -359,6 +383,7 @@ public Settings additionalSettings() {
IndexModule.INDEX_STORE_HYBRID_MMAP_EXTENSIONS.getDefault(Settings.EMPTY).stream(),
engineSettings.stream()
).collect(Collectors.toList());
return Settings.builder().putList(IndexModule.INDEX_STORE_HYBRID_MMAP_EXTENSIONS.getKey(), combinedSettings).build();

settingsBuilder.putList(IndexModule.INDEX_STORE_HYBRID_MMAP_EXTENSIONS.getKey(), combinedSettings);
}
}
59 changes: 59 additions & 0 deletions src/test/java/org/opensearch/knn/plugin/KNNPluginTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.knn.plugin;

import org.opensearch.common.settings.Settings;
import org.opensearch.index.IndexModule;
import org.opensearch.index.shard.IndexSettingProvider;
import org.opensearch.knn.KNNTestCase;
import org.opensearch.knn.index.util.KNNEngine;

import java.util.Collection;
import java.util.List;

public class KNNPluginTests extends KNNTestCase {

private static final String INDEX_NAME = "test_index";

public void testMMapFileExtensionsForHybridFs() {
final KNNPlugin knnPlugin = new KNNPlugin();

final Collection<IndexSettingProvider> additionalIndexSettingProviders = knnPlugin.getAdditionalIndexSettingProviders();

assertEquals(1, additionalIndexSettingProviders.size());

final IndexSettingProvider indexSettingProvider = additionalIndexSettingProviders.iterator().next();
// settings for knn enabled index
final Settings knnIndexSettings = indexSettingProvider.getAdditionalIndexSettings(INDEX_NAME, false, getKnnDefaultIndexSettings());
final List<String> mmapFileExtensionsForHybridFsKnnIndex = knnIndexSettings.getAsList(
IndexModule.INDEX_STORE_HYBRID_MMAP_EXTENSIONS.getKey()
);

assertNotNull(mmapFileExtensionsForHybridFsKnnIndex);
assertFalse(mmapFileExtensionsForHybridFsKnnIndex.isEmpty());

for (KNNEngine engine : KNNEngine.values()) {
assertTrue(mmapFileExtensionsForHybridFsKnnIndex.containsAll(engine.mmapFileExtensions()));
}

// settings for index without knn
final Settings nonKnnIndexSettings = indexSettingProvider.getAdditionalIndexSettings(INDEX_NAME, false, getNonKnnIndexSettings());
final List<String> mmapFileExtensionsForHybridFsNonKnnIndex = nonKnnIndexSettings.getAsList(
IndexModule.INDEX_STORE_HYBRID_MMAP_EXTENSIONS.getKey()
);

assertNotNull(mmapFileExtensionsForHybridFsNonKnnIndex);
assertTrue(mmapFileExtensionsForHybridFsNonKnnIndex.isEmpty());
}

private Settings getKnnDefaultIndexSettings() {
return Settings.builder().put("number_of_shards", 1).put("number_of_replicas", 0).put("index.knn", true).build();
}

private Settings getNonKnnIndexSettings() {
return Settings.builder().put("number_of_shards", 1).put("number_of_replicas", 0).build();
}
}