Skip to content

Commit 34380f9

Browse files
vnickolovMats-SXknutwalker
committed
Use resource monitor instead of statement
Co-authored-by: Mats Rydberg <[email protected]> Co-authored-by: Paul Horn <[email protected]>
1 parent 1440674 commit 34380f9

File tree

6 files changed

+32
-3
lines changed

6 files changed

+32
-3
lines changed

compatibility/4.4/neo4j-kernel-adapter/src/main/java/org/neo4j/gds/compat/_44/Neo4jProxyImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,13 @@ public String metricsManagerClass() {
873873
return "com.neo4j.metrics.global.MetricsManager";
874874
}
875875

876+
@Override
877+
public void registerCloseableResource(KernelTransaction transaction, AutoCloseable autoCloseable) {
878+
try (var statement = transaction.acquireStatement()) {
879+
statement.registerCloseableResource(autoCloseable);
880+
}
881+
}
882+
876883
@Override
877884
public <T> T nodeLabelTokenSet(
878885
NodeCursor nodeCursor,

compatibility/5-common/neo4j-kernel-adapter/src/main/java/org/neo4j/gds/compat/_5x/CommonNeo4jProxyImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.neo4j.gds.compat.PropertyReference;
3737
import org.neo4j.gds.compat.StoreScan;
3838
import org.neo4j.gds.compat.TestLog;
39+
import org.neo4j.kernel.api.KernelTransaction;
3940

4041
import java.nio.file.Path;
4142
import java.util.List;
@@ -514,4 +515,9 @@ public GlobalProcedureRegistry globalProcedureRegistry(org.neo4j.kernel.api.proc
514515
public String metricsManagerClass() {
515516
return "com.neo4j.metrics.global.MetricsManager";
516517
}
518+
519+
@Override
520+
public void registerCloseableResource(KernelTransaction transaction, AutoCloseable autoCloseable) {
521+
throw new IllegalStateException("Compat layer for 5.x must be run on Java 17");
522+
}
517523
}

compatibility/5-common/neo4j-kernel-adapter/src/main/java17/org/neo4j/gds/compat/_5x/CommonNeo4jProxyImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,4 +749,9 @@ public TransactionalContext newQueryContext(
749749
public String metricsManagerClass() {
750750
return "com.neo4j.metrics.global.MetricsManager";
751751
}
752+
753+
@Override
754+
public void registerCloseableResource(KernelTransaction transaction, AutoCloseable autoCloseable) {
755+
transaction.resourceMonitor().registerCloseableResource(autoCloseable);
756+
}
752757
}

compatibility/api/neo4j-kernel-adapter/src/main/java/org/neo4j/gds/compat/Neo4jProxyApi.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,11 @@ TransactionalContext newQueryContext(
324324

325325
String metricsManagerClass();
326326

327+
void registerCloseableResource(
328+
org.neo4j.kernel.api.KernelTransaction transaction,
329+
AutoCloseable autoCloseable
330+
);
331+
327332
<T> T nodeLabelTokenSet(
328333
NodeCursor nodeCursor,
329334
Function<int[], T> intsConstructor,

compatibility/common/neo4j-kernel-adapter/src/main/java/org/neo4j/gds/compat/Neo4jProxy.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,13 @@ public static String neo4jArrowServerAddressHeader() {
486486
return IMPL.neo4jArrowServerAddressHeader();
487487
}
488488

489+
public static void registerCloseableResource(
490+
org.neo4j.kernel.api.KernelTransaction transaction,
491+
AutoCloseable autoCloseable
492+
) {
493+
IMPL.registerCloseableResource(transaction, autoCloseable);
494+
}
495+
489496
private Neo4jProxy() {
490497
throw new UnsupportedOperationException("No instances");
491498
}

procedures/integration/src/main/java/org/neo4j/gds/procedures/integration/CatalogFacadeProvider.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.neo4j.gds.applications.graphstorecatalog.WriteNodePropertiesApplication;
4646
import org.neo4j.gds.applications.graphstorecatalog.WriteRelationshipPropertiesApplication;
4747
import org.neo4j.gds.applications.graphstorecatalog.WriteRelationshipsApplication;
48+
import org.neo4j.gds.compat.Neo4jProxy;
4849
import org.neo4j.gds.core.loading.GraphStoreCatalogService;
4950
import org.neo4j.gds.core.write.ExporterContext;
5051
import org.neo4j.gds.logging.Log;
@@ -218,9 +219,7 @@ CatalogFacade createCatalogFacade(Context context) {
218219
var streamCloser = new Consumer<AutoCloseable>() {
219220
@Override
220221
public void accept(AutoCloseable autoCloseable) {
221-
try (var statement = kernelTransaction.acquireStatement()) {
222-
statement.registerCloseableResource(autoCloseable);
223-
}
222+
Neo4jProxy.registerCloseableResource(kernelTransaction, autoCloseable);
224223
}
225224
};
226225
var terminationFlag = terminationFlagService.createTerminationFlag(kernelTransaction);

0 commit comments

Comments
 (0)