-
Notifications
You must be signed in to change notification settings - Fork 190
Fix memory overflow caused by cache behavior #2015
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
navneet1v
merged 1 commit into
opensearch-project:main
from
kotwanikunal:cache-overflow-fix
Sep 4, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/org/opensearch/knn/common/featureflags/KNNFeatureFlags.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| */ | ||
|
|
||
| package org.opensearch.knn.common.featureflags; | ||
|
|
||
| import com.google.common.annotations.VisibleForTesting; | ||
| import com.google.common.collect.ImmutableList; | ||
| import lombok.experimental.UtilityClass; | ||
| import org.opensearch.common.Booleans; | ||
| import org.opensearch.common.settings.Setting; | ||
| import org.opensearch.knn.index.KNNSettings; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static org.opensearch.common.settings.Setting.Property.Dynamic; | ||
| import static org.opensearch.common.settings.Setting.Property.NodeScope; | ||
|
|
||
| /** | ||
| * Class to manage KNN feature flags | ||
| */ | ||
| @UtilityClass | ||
| public class KNNFeatureFlags { | ||
|
|
||
| // Feature flags | ||
| private static final String KNN_FORCE_EVICT_CACHE_ENABLED = "knn.feature.cache.force_evict.enabled"; | ||
|
|
||
| @VisibleForTesting | ||
| public static final Setting<Boolean> KNN_FORCE_EVICT_CACHE_ENABLED_SETTING = Setting.boolSetting( | ||
| KNN_FORCE_EVICT_CACHE_ENABLED, | ||
| false, | ||
| NodeScope, | ||
| Dynamic | ||
| ); | ||
|
|
||
| public static List<Setting<?>> getFeatureFlags() { | ||
| return ImmutableList.of(KNN_FORCE_EVICT_CACHE_ENABLED_SETTING); | ||
| } | ||
|
|
||
| /** | ||
| * Checks if force evict for cache is enabled by executing a check against cluster settings | ||
| * @return true if force evict setting is set to true | ||
| */ | ||
| public static boolean isForceEvictCacheEnabled() { | ||
|
kotwanikunal marked this conversation as resolved.
|
||
| return Booleans.parseBoolean(KNNSettings.state().getSettingValue(KNN_FORCE_EVICT_CACHE_ENABLED).toString(), false); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/test/java/org/opensearch/knn/common/featureflags/KNNFeatureFlagsTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.knn.common.featureflags; | ||
|
|
||
| import org.mockito.Mock; | ||
| import org.opensearch.common.settings.ClusterSettings; | ||
| import org.opensearch.knn.KNNTestCase; | ||
| import org.opensearch.knn.index.KNNSettings; | ||
|
|
||
| import static org.mockito.Mockito.when; | ||
| import static org.opensearch.knn.common.featureflags.KNNFeatureFlags.KNN_FORCE_EVICT_CACHE_ENABLED_SETTING; | ||
| import static org.opensearch.knn.common.featureflags.KNNFeatureFlags.isForceEvictCacheEnabled; | ||
|
|
||
| public class KNNFeatureFlagsTests extends KNNTestCase { | ||
|
|
||
| @Mock | ||
| ClusterSettings clusterSettings; | ||
|
|
||
| public void setUp() throws Exception { | ||
| super.setUp(); | ||
| when(clusterService.getClusterSettings()).thenReturn(clusterSettings); | ||
| KNNSettings.state().setClusterService(clusterService); | ||
| } | ||
|
|
||
| public void testIsForceEvictCacheEnabled() throws Exception { | ||
| when(clusterSettings.get(KNN_FORCE_EVICT_CACHE_ENABLED_SETTING)).thenReturn(false); | ||
| assertFalse(isForceEvictCacheEnabled()); | ||
| when(clusterSettings.get(KNN_FORCE_EVICT_CACHE_ENABLED_SETTING)).thenReturn(true); | ||
| assertTrue(isForceEvictCacheEnabled()); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.