Skip to content

Commit

Permalink
Restrict the range of JVMs that need security policy flags set (#42)
Browse files Browse the repository at this point in the history
Signed-off-by: Scott Stults <[email protected]>
Signed-off-by: jzonthemtn <[email protected]>
Co-authored-by: Jeff Zemerick <[email protected]>
  • Loading branch information
sstults and jzonthemtn authored Sep 16, 2024
1 parent 980e3c6 commit e34d607
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 26 deletions.
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);
}
}
}

0 comments on commit e34d607

Please sign in to comment.