-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into csaLatencies
Signed-off-by: Harsh Garg <gkharsh@amazon.com>
- Loading branch information
Showing
202 changed files
with
11,308 additions
and
1,229 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -30,3 +30,4 @@ BWC_VERSION: | |
- "2.12.0" | ||
- "2.12.1" | ||
- "2.13.0" | ||
- "2.14.0" |
This file contains 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 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 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 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 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 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 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 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 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
70 changes: 70 additions & 0 deletions
70
modules/cache-common/src/main/java/org/opensearch/cache/common/policy/TookTimePolicy.java
This file contains 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,70 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
/* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.cache.common.policy; | ||
|
||
import org.opensearch.common.cache.policy.CachedQueryResult; | ||
import org.opensearch.common.unit.TimeValue; | ||
|
||
import java.util.function.Function; | ||
import java.util.function.Predicate; | ||
|
||
/** | ||
* A cache tier policy which accepts queries whose took time is greater than some threshold. | ||
* The threshold should be set to approximately the time it takes to get a result from the cache tier. | ||
* The policy accepts values of type V and decodes them into CachedQueryResult.PolicyValues, which has the data needed | ||
* to decide whether to admit the value. | ||
* @param <V> The type of data consumed by test(). | ||
*/ | ||
public class TookTimePolicy<V> implements Predicate<V> { | ||
/** | ||
* The minimum took time to allow a query. Set to TimeValue.ZERO to let all data through. | ||
*/ | ||
private final TimeValue threshold; | ||
|
||
/** | ||
* Function which extracts the relevant PolicyValues from a serialized CachedQueryResult | ||
*/ | ||
private final Function<V, CachedQueryResult.PolicyValues> cachedResultParser; | ||
|
||
/** | ||
* Constructs a took time policy. | ||
* @param threshold the threshold | ||
* @param cachedResultParser the function providing policy values | ||
*/ | ||
public TookTimePolicy(TimeValue threshold, Function<V, CachedQueryResult.PolicyValues> cachedResultParser) { | ||
if (threshold.compareTo(TimeValue.ZERO) < 0) { | ||
throw new IllegalArgumentException("Threshold for TookTimePolicy must be >= 0ms but was " + threshold.getStringRep()); | ||
} | ||
this.threshold = threshold; | ||
this.cachedResultParser = cachedResultParser; | ||
} | ||
|
||
/** | ||
* Check whether to admit data. | ||
* @param data the input argument | ||
* @return whether to admit the data | ||
*/ | ||
public boolean test(V data) { | ||
long tookTimeNanos; | ||
try { | ||
tookTimeNanos = cachedResultParser.apply(data).getTookTimeNanos(); | ||
} catch (Exception e) { | ||
// If we can't read a CachedQueryResult.PolicyValues from the BytesReference, reject the data | ||
return false; | ||
} | ||
|
||
TimeValue tookTime = TimeValue.timeValueNanos(tookTimeNanos); | ||
return tookTime.compareTo(threshold) >= 0; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
modules/cache-common/src/main/java/org/opensearch/cache/common/policy/package-info.java
This file contains 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,10 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
/** A package for policies controlling what can enter caches. */ | ||
package org.opensearch.cache.common.policy; |
Oops, something went wrong.