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

Restrict the range of JVMs that need security policy flags set #42

Merged
merged 6 commits into from
Sep 16, 2024
Merged
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ githubRelease.doFirst {
}

tasks.withType(Test).configureEach { task ->
if (JavaVersion.current().compareTo(JavaVersion.VERSION_17) > 0) {
if (JavaVersion.current().compareTo(JavaVersion.VERSION_17) > 0 && JavaVersion.current().compareTo(JavaVersion.VERSION_21) < 0) {
def policyFile = file("${projectDir}/src/main/plugin-metadata/plugin-security.policy").absolutePath
task.jvmArgs += [
"--add-opens", "java.base/java.lang=ALL-UNNAMED",
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/o19s/es/ltr/query/RankerQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public boolean isCacheable(LeafReaderContext ctx) {
// XXX: this is not thread safe and may run into extremely weird issues
// if the searcher uses the parallel collector
// Hopefully elastic never runs
MutableSupplier<LtrRanker.FeatureVector> vectorSupplier = new Suppliers.FeatureVectorSupplier();
MutableSupplier<LtrRanker.FeatureVector> vectorSupplier = new Suppliers.MutableSupplier<>();
FVLtrRankerWrapper ltrRankerWrapper = new FVLtrRankerWrapper(ranker, vectorSupplier);
LtrRewriteContext context = new LtrRewriteContext(ranker, vectorSupplier);
for (Query q : queries) {
Expand Down
28 changes: 4 additions & 24 deletions src/main/java/com/o19s/es/ltr/utils/Suppliers.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@

package com.o19s.es.ltr.utils;

import com.o19s.es.ltr.ranker.LtrRanker;
import org.opensearch.core.Assertions;

import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;

public final class Suppliers {
Expand Down Expand Up @@ -66,33 +64,15 @@ public E get() {
* A mutable supplier
*/
public static class MutableSupplier<T> implements Supplier<T> {
T obj;
private final AtomicReference<T> ref = new AtomicReference<>();

@Override
public T get() {
return obj;
return ref.get();
}

public void set(T obj) {
this.obj = obj;
}
}

/**
* Simple wrapper to make sure we run on the same thread
*/
public static class FeatureVectorSupplier extends MutableSupplier<LtrRanker.FeatureVector> {
private final long threadId = Assertions.ENABLED ? Thread.currentThread().getId() : 0;

public LtrRanker.FeatureVector get() {
assert threadId == Thread.currentThread().getId();
return super.get();
}

@Override
public void set(LtrRanker.FeatureVector obj) {
assert threadId == Thread.currentThread().getId();
super.set(obj);
this.ref.set(obj);
}
}
}
Loading