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

[k-NN] Add Clear Cache API #740

Merged

Conversation

naveentatikonda
Copy link
Member

@naveentatikonda naveentatikonda commented Jan 24, 2023

Description

Add API to flush given k-NN indices out of cache memory.

Issues Resolved

#333

Check List

  • New functionality includes testing.
    • All tests pass
    • New functionality has javadoc added
  • Commits are signed as per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@naveentatikonda naveentatikonda added Features Introduces a new unit of functionality that satisfies a requirement backport 2.x labels Jan 24, 2023
@naveentatikonda naveentatikonda self-assigned this Jan 24, 2023
@naveentatikonda naveentatikonda requested a review from a team January 24, 2023 01:44
@codecov-commenter
Copy link

codecov-commenter commented Jan 24, 2023

Codecov Report

Merging #740 (7d10109) into main (74b87e8) will decrease coverage by 0.06%.
The diff coverage is 85.71%.

@@             Coverage Diff              @@
##               main     #740      +/-   ##
============================================
- Coverage     85.03%   84.97%   -0.06%     
- Complexity     1144     1167      +23     
============================================
  Files           154      159       +5     
  Lines          4692     4760      +68     
  Branches        425      427       +2     
============================================
+ Hits           3990     4045      +55     
- Misses          509      522      +13     
  Partials        193      193              
Files Changed Coverage Δ
...n/java/org/opensearch/knn/common/KNNConstants.java 93.75% <ø> (ø)
...search/knn/plugin/transport/ClearCacheRequest.java 50.00% <50.00%> (ø)
...earch/knn/plugin/transport/ClearCacheResponse.java 50.00% <50.00%> (ø)
...nsearch/knn/plugin/transport/ClearCacheAction.java 75.00% <75.00%> (ø)
...n/java/org/opensearch/knn/index/KNNIndexShard.java 90.32% <80.00%> (-3.56%) ⬇️
...nn/plugin/transport/ClearCacheTransportAction.java 86.66% <86.66%> (ø)
...rch/knn/index/memory/NativeMemoryCacheManager.java 95.48% <100.00%> (+0.28%) ⬆️
...main/java/org/opensearch/knn/plugin/KNNPlugin.java 100.00% <100.00%> (ø)
...nsearch/knn/plugin/rest/RestClearCacheHandler.java 100.00% <100.00%> (ø)

... and 3 files with indirect coverage changes

Copy link
Collaborator

@navneet1v navneet1v left a comment

Choose a reason for hiding this comment

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

@naveentatikonda Here are some of my thoughts:

  1. Why do we believe doing a flush operation using rest handler is the best way to remove the cache? Can this be done periodically is customer wants?
  2. What will happen to the search request which are currently running on that index and using that cached graphs?
  3. Can any user of OpenSearch call this API to clear the cache or there are any restrictions around the usage of the API?

I would recommend creating an issue for this so that different approaches can be discussed around what should be the best approach here.

@naveentatikonda
Copy link
Member Author

Can I get some suggestions on API name something like "Clear k-NN Indices from Memory" or "Evict k-NN Indices from Memory" if we don't want to use the name "Clear Cache API"

Also, for the API endpoint should we use /_plugins/_knn/memory/<warmup | clear>/indices. like @jmazanec15 suggested in design discussion?

Will make the refactoring changes once the API name and endpoint are finalized.

@jmazanec15
Copy link
Member

I think I like this approach (similar to ml-commons for models: https://opensearch.org/docs/latest/ml-commons-plugin/api/#load-model):

POST /_plugins/_knn/{index_names}/_clear // remove indices from memory - if no indices provided, clear everything

POST /_plugins/_knn/{index_names}/_warmup // warmup/load indices into the cache - if no indices provided, warmup everything

I think this centers the APIs around the index/indices resource. With this, I think we could move to deprecating current warmup path:

GET /_plugins/_knn/warmup/{index_names}?pretty

Would be interested to hear what the rest of the team thinks @navneet1v @vamshin @martin-gaievski

@martin-gaievski
Copy link
Member

I think I like this approach (similar to ml-commons for models: https://opensearch.org/docs/latest/ml-commons-plugin/api/#load-model):

POST /_plugins/_knn/{index_names}/_clear // remove indices from memory - if no indices provided, clear everything

POST /_plugins/_knn/{index_names}/_warmup // warmup/load indices into the cache - if no indices provided, warmup everything

I think this centers the APIs around the index/indices resource. With this, I think we could move to deprecating current warmup path:

GET /_plugins/_knn/warmup/{index_names}?pretty

Would be interested to hear what the rest of the team thinks @navneet1v @vamshin @martin-gaievski

sounds good to me, both API suggestions and putting existing API to deprecation

@vamshin vamshin changed the title Add Clear Cache API [k-NN] Add Clear Cache API Jul 27, 2023
@naveentatikonda naveentatikonda force-pushed the add_clear_cache_api branch 2 times, most recently from 4f167d0 to 01bb6c1 Compare August 9, 2023 23:27
CHANGELOG.md Outdated Show resolved Hide resolved
src/main/java/org/opensearch/knn/index/KNNIndexShard.java Outdated Show resolved Hide resolved
src/main/java/org/opensearch/knn/index/KNNIndexShard.java Outdated Show resolved Hide resolved
public static final ClearCacheAction INSTANCE = new ClearCacheAction();
public static final String NAME = "cluster:admin/clear_cache_action";

private ClearCacheAction() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

shouldn't this be public?

Copy link
Member Author

Choose a reason for hiding this comment

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

no, it is private. We will be only using it in this class to create the INSTANCE object.

@navneet1v
Copy link
Collaborator

@naveentatikonda can you fix the build issues happening for the mac and ubnutu.

Signed-off-by: Naveen Tatikonda <[email protected]>
Signed-off-by: Naveen Tatikonda <[email protected]>
Signed-off-by: Naveen Tatikonda <[email protected]>
Signed-off-by: Naveen Tatikonda <[email protected]>
Signed-off-by: Naveen Tatikonda <[email protected]>
* @param indexName name of OpenSearch index
* @return NativeMemoryAllocation associated with given index
*/
public Optional<NativeMemoryAllocation> getIndexMemoryAllocation(String indexName) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: I think our convention is to have params in public methods as final. not a critical though, just for future PRs

@navneet1v
Copy link
Collaborator

I think I like this approach (similar to ml-commons for models: https://opensearch.org/docs/latest/ml-commons-plugin/api/#load-model):

POST /_plugins/_knn/{index_names}/_clear // remove indices from memory - if no indices provided, clear everything

POST /_plugins/_knn/{index_names}/_warmup // warmup/load indices into the cache - if no indices provided, warmup everything

I think this centers the APIs around the index/indices resource. With this, I think we could move to deprecating current warmup path:

GET /_plugins/_knn/warmup/{index_names}?pretty

Would be interested to hear what the rest of the team thinks @navneet1v @vamshin @martin-gaievski

I think we can move towards more index based rest endpoints. But I think deprecation of the endpoints and adding new endpoints is out of scope of this PR.

@naveentatikonda naveentatikonda merged commit 12f4a51 into opensearch-project:main Aug 23, 2023
opensearch-trigger-bot bot pushed a commit that referenced this pull request Aug 23, 2023
* Add Clear Cache API

Signed-off-by: Naveen Tatikonda <[email protected]>

* Add Unit and Integration tests

Signed-off-by: Naveen Tatikonda <[email protected]>

* Add BWC Tests

Signed-off-by: Naveen Tatikonda <[email protected]>

* Add CHANGELOG

Signed-off-by: Naveen Tatikonda <[email protected]>

* Address Review Comments

Signed-off-by: Naveen Tatikonda <[email protected]>

---------

Signed-off-by: Naveen Tatikonda <[email protected]>
(cherry picked from commit 12f4a51)
@jmazanec15 jmazanec15 mentioned this pull request Nov 28, 2023
1 task
naveentatikonda added a commit that referenced this pull request Apr 12, 2024
* Add Clear Cache API

Signed-off-by: Naveen Tatikonda <[email protected]>

* Add Unit and Integration tests

Signed-off-by: Naveen Tatikonda <[email protected]>

* Add BWC Tests

Signed-off-by: Naveen Tatikonda <[email protected]>

* Add CHANGELOG

Signed-off-by: Naveen Tatikonda <[email protected]>

* Address Review Comments

Signed-off-by: Naveen Tatikonda <[email protected]>

---------

Signed-off-by: Naveen Tatikonda <[email protected]>
(cherry picked from commit 12f4a51)
naveentatikonda added a commit that referenced this pull request Apr 12, 2024
* Add Clear Cache API

Signed-off-by: Naveen Tatikonda <[email protected]>

* Add Unit and Integration tests

Signed-off-by: Naveen Tatikonda <[email protected]>

* Add BWC Tests

Signed-off-by: Naveen Tatikonda <[email protected]>

* Add CHANGELOG

Signed-off-by: Naveen Tatikonda <[email protected]>

* Address Review Comments

Signed-off-by: Naveen Tatikonda <[email protected]>

---------

Signed-off-by: Naveen Tatikonda <[email protected]>
(cherry picked from commit 12f4a51)
Signed-off-by: Naveen Tatikonda <[email protected]>
naveentatikonda added a commit that referenced this pull request Apr 13, 2024
* [k-NN] Add Clear Cache API (#740)

* Add Clear Cache API

Signed-off-by: Naveen Tatikonda <[email protected]>

* Add Unit and Integration tests

Signed-off-by: Naveen Tatikonda <[email protected]>

* Add BWC Tests

Signed-off-by: Naveen Tatikonda <[email protected]>

* Add CHANGELOG

Signed-off-by: Naveen Tatikonda <[email protected]>

* Address Review Comments

Signed-off-by: Naveen Tatikonda <[email protected]>

---------

Signed-off-by: Naveen Tatikonda <[email protected]>
(cherry picked from commit 12f4a51)
Signed-off-by: Naveen Tatikonda <[email protected]>

* Fix Failing Clear Cache API Test (#1336)

Signed-off-by: Naveen Tatikonda <[email protected]>

---------

Signed-off-by: Naveen Tatikonda <[email protected]>
Co-authored-by: Naveen Tatikonda <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Features Introduces a new unit of functionality that satisfies a requirement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants