From e20063f57da3bc721ea82eca61843f961dcfd736 Mon Sep 17 00:00:00 2001 From: Nathaniel Bauernfeind Date: Tue, 30 Apr 2024 10:21:46 -0600 Subject: [PATCH 1/3] Move Script Cache Clearing to Dagger --- .../io/deephaven/server/console/NoConsoleSessionModule.java | 3 +++ .../server/console/groovy/GroovyConsoleSessionModule.java | 3 +++ .../server/console/python/PythonConsoleSessionModule.java | 3 +++ .../java/io/deephaven/server/runner/DeephavenApiServer.java | 3 --- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/io/deephaven/server/console/NoConsoleSessionModule.java b/server/src/main/java/io/deephaven/server/console/NoConsoleSessionModule.java index 7b4146938d3..d78e160dedc 100644 --- a/server/src/main/java/io/deephaven/server/console/NoConsoleSessionModule.java +++ b/server/src/main/java/io/deephaven/server/console/NoConsoleSessionModule.java @@ -10,6 +10,7 @@ import io.deephaven.engine.updategraph.OperationInitializer; import io.deephaven.engine.updategraph.UpdateGraph; import io.deephaven.engine.updategraph.impl.PeriodicUpdateGraph; +import io.deephaven.engine.util.AbstractScriptSession; import io.deephaven.engine.util.NoLanguageDeephavenSession; import io.deephaven.engine.util.ScriptSession; import io.deephaven.server.console.groovy.InitScriptsModule; @@ -29,6 +30,8 @@ ScriptSession bindScriptSession(NoLanguageDeephavenSession noLanguageSession) { NoLanguageDeephavenSession bindNoLanguageSession( @Named(PeriodicUpdateGraph.DEFAULT_UPDATE_GRAPH_NAME) final UpdateGraph updateGraph, final OperationInitializer operationInitializer) { + // create the script cache (or clear previous sessions) + AbstractScriptSession.createScriptCache(); return new NoLanguageDeephavenSession(updateGraph, operationInitializer); } } diff --git a/server/src/main/java/io/deephaven/server/console/groovy/GroovyConsoleSessionModule.java b/server/src/main/java/io/deephaven/server/console/groovy/GroovyConsoleSessionModule.java index 0adcd9400c2..6e0f8cdd177 100644 --- a/server/src/main/java/io/deephaven/server/console/groovy/GroovyConsoleSessionModule.java +++ b/server/src/main/java/io/deephaven/server/console/groovy/GroovyConsoleSessionModule.java @@ -10,6 +10,7 @@ import io.deephaven.engine.updategraph.OperationInitializer; import io.deephaven.engine.updategraph.UpdateGraph; import io.deephaven.engine.updategraph.impl.PeriodicUpdateGraph; +import io.deephaven.engine.util.AbstractScriptSession; import io.deephaven.engine.util.GroovyDeephavenSession; import io.deephaven.engine.util.GroovyDeephavenSession.RunScripts; import io.deephaven.engine.util.ScriptSession; @@ -36,6 +37,8 @@ GroovyDeephavenSession bindGroovySession( final ScriptSession.Listener listener, final RunScripts runScripts) { try { + // create the script cache (or clear previous sessions) + AbstractScriptSession.createScriptCache(); return GroovyDeephavenSession.of(updateGraph, operationInitializer, lookup, listener, runScripts); } catch (final IOException e) { throw new UncheckedIOException(e); diff --git a/server/src/main/java/io/deephaven/server/console/python/PythonConsoleSessionModule.java b/server/src/main/java/io/deephaven/server/console/python/PythonConsoleSessionModule.java index adbd69aa0d6..270e8693ecf 100644 --- a/server/src/main/java/io/deephaven/server/console/python/PythonConsoleSessionModule.java +++ b/server/src/main/java/io/deephaven/server/console/python/PythonConsoleSessionModule.java @@ -10,6 +10,7 @@ import io.deephaven.engine.updategraph.OperationInitializer; import io.deephaven.engine.updategraph.UpdateGraph; import io.deephaven.engine.updategraph.impl.PeriodicUpdateGraph; +import io.deephaven.engine.util.AbstractScriptSession; import io.deephaven.engine.util.PythonEvaluatorJpy; import io.deephaven.engine.util.ScriptSession; import io.deephaven.integrations.python.PythonDeephavenSession; @@ -38,6 +39,8 @@ PythonDeephavenSession bindPythonSession( final ScriptSession.Listener listener, final PythonEvaluatorJpy pythonEvaluator) { try { + // create the script cache (or clear previous sessions) + AbstractScriptSession.createScriptCache(); return new PythonDeephavenSession( updateGraph, operationInitializer, threadInitializationFactory, lookup, listener, true, pythonEvaluator); diff --git a/server/src/main/java/io/deephaven/server/runner/DeephavenApiServer.java b/server/src/main/java/io/deephaven/server/runner/DeephavenApiServer.java index 6ef6c30a478..06d874c8a91 100644 --- a/server/src/main/java/io/deephaven/server/runner/DeephavenApiServer.java +++ b/server/src/main/java/io/deephaven/server/runner/DeephavenApiServer.java @@ -177,9 +177,6 @@ public DeephavenApiServer run() throws IOException, ClassNotFoundException, Time log.info().append("Configuring logging...").endl(); logInit.run(); - log.info().append("Creating/Clearing Script Cache...").endl(); - AbstractScriptSession.createScriptCache(); - for (BusinessCalendar calendar : calendars.get()) { Calendars.addCalendar(calendar); } From b652074a8e40336ccfbe254ea677002852a8a141 Mon Sep 17 00:00:00 2001 From: Nathaniel Bauernfeind Date: Tue, 30 Apr 2024 15:10:57 -0600 Subject: [PATCH 2/3] QueryCompiler: Ensure Directory Before Creating Temp Directory --- .../io/deephaven/engine/context/QueryCompilerImpl.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/engine/table/src/main/java/io/deephaven/engine/context/QueryCompilerImpl.java b/engine/table/src/main/java/io/deephaven/engine/context/QueryCompilerImpl.java index 535b8acc573..4b4d0ded072 100644 --- a/engine/table/src/main/java/io/deephaven/engine/context/QueryCompilerImpl.java +++ b/engine/table/src/main/java/io/deephaven/engine/context/QueryCompilerImpl.java @@ -814,13 +814,13 @@ private void maybeCreateClasses( final String tempDirAsString; try { rootPathAsString = getClassDestination().getAbsolutePath(); - final Path tempPath = - Files.createTempDirectory(Paths.get(rootPathAsString), "temporaryCompilationDirectory"); - tempDirAsString = tempPath.toFile().getAbsolutePath(); - for (final CompilationRequestAttempt request : requests) { request.ensureDirectories(rootPathAsString); } + + final Path tempPath = + Files.createTempDirectory(Paths.get(rootPathAsString), "temporaryCompilationDirectory"); + tempDirAsString = tempPath.toFile().getAbsolutePath(); } catch (IOException ioe) { Exception err = new UncheckedIOException(ioe); for (final CompilationRequestAttempt request : requests) { From 94d3659e3157f0b46dcb1f88c3a823cd3bbf38bb Mon Sep 17 00:00:00 2001 From: Nathaniel Bauernfeind Date: Tue, 30 Apr 2024 15:35:11 -0600 Subject: [PATCH 3/3] Use Different Initialization Construct --- .../server/console/ConsoleModule.java | 7 +++++++ .../console/NoConsoleSessionModule.java | 6 ++---- .../console/ScriptSessionCacheInit.java | 19 +++++++++++++++++++ .../groovy/GroovyConsoleSessionModule.java | 7 +++---- .../python/PythonConsoleSessionModule.java | 7 +++---- 5 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 server/src/main/java/io/deephaven/server/console/ScriptSessionCacheInit.java diff --git a/server/src/main/java/io/deephaven/server/console/ConsoleModule.java b/server/src/main/java/io/deephaven/server/console/ConsoleModule.java index 3aedc3d1336..2d36fd444af 100644 --- a/server/src/main/java/io/deephaven/server/console/ConsoleModule.java +++ b/server/src/main/java/io/deephaven/server/console/ConsoleModule.java @@ -12,6 +12,7 @@ import io.deephaven.server.session.TicketResolver; import io.grpc.BindableService; +import javax.inject.Singleton; import java.util.Collections; import java.util.Set; @@ -25,6 +26,12 @@ public interface ConsoleModule { @IntoSet TicketResolver bindConsoleTicketResolver(ScopeTicketResolver resolver); + @Provides + @Singleton + static ScriptSessionCacheInit bindScriptSessionCacheInit() { + return new ScriptSessionCacheInit(); + } + @Provides @ElementsIntoSet static Set primeCustomCompletions() { diff --git a/server/src/main/java/io/deephaven/server/console/NoConsoleSessionModule.java b/server/src/main/java/io/deephaven/server/console/NoConsoleSessionModule.java index d78e160dedc..ff097829f79 100644 --- a/server/src/main/java/io/deephaven/server/console/NoConsoleSessionModule.java +++ b/server/src/main/java/io/deephaven/server/console/NoConsoleSessionModule.java @@ -10,7 +10,6 @@ import io.deephaven.engine.updategraph.OperationInitializer; import io.deephaven.engine.updategraph.UpdateGraph; import io.deephaven.engine.updategraph.impl.PeriodicUpdateGraph; -import io.deephaven.engine.util.AbstractScriptSession; import io.deephaven.engine.util.NoLanguageDeephavenSession; import io.deephaven.engine.util.ScriptSession; import io.deephaven.server.console.groovy.InitScriptsModule; @@ -29,9 +28,8 @@ ScriptSession bindScriptSession(NoLanguageDeephavenSession noLanguageSession) { @Provides NoLanguageDeephavenSession bindNoLanguageSession( @Named(PeriodicUpdateGraph.DEFAULT_UPDATE_GRAPH_NAME) final UpdateGraph updateGraph, - final OperationInitializer operationInitializer) { - // create the script cache (or clear previous sessions) - AbstractScriptSession.createScriptCache(); + final OperationInitializer operationInitializer, + final ScriptSessionCacheInit ignored) { return new NoLanguageDeephavenSession(updateGraph, operationInitializer); } } diff --git a/server/src/main/java/io/deephaven/server/console/ScriptSessionCacheInit.java b/server/src/main/java/io/deephaven/server/console/ScriptSessionCacheInit.java new file mode 100644 index 00000000000..ddaf3966174 --- /dev/null +++ b/server/src/main/java/io/deephaven/server/console/ScriptSessionCacheInit.java @@ -0,0 +1,19 @@ +// +// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending +// +package io.deephaven.server.console; + +import io.deephaven.engine.util.AbstractScriptSession; + +import javax.inject.Inject; +import javax.inject.Singleton; + +@Singleton +public class ScriptSessionCacheInit { + + @Inject + public ScriptSessionCacheInit() { + // create the script cache (or clear previous sessions) + AbstractScriptSession.createScriptCache(); + } +} diff --git a/server/src/main/java/io/deephaven/server/console/groovy/GroovyConsoleSessionModule.java b/server/src/main/java/io/deephaven/server/console/groovy/GroovyConsoleSessionModule.java index 6e0f8cdd177..3a42c7deaf4 100644 --- a/server/src/main/java/io/deephaven/server/console/groovy/GroovyConsoleSessionModule.java +++ b/server/src/main/java/io/deephaven/server/console/groovy/GroovyConsoleSessionModule.java @@ -10,11 +10,11 @@ import io.deephaven.engine.updategraph.OperationInitializer; import io.deephaven.engine.updategraph.UpdateGraph; import io.deephaven.engine.updategraph.impl.PeriodicUpdateGraph; -import io.deephaven.engine.util.AbstractScriptSession; import io.deephaven.engine.util.GroovyDeephavenSession; import io.deephaven.engine.util.GroovyDeephavenSession.RunScripts; import io.deephaven.engine.util.ScriptSession; import io.deephaven.plugin.type.ObjectTypeLookup; +import io.deephaven.server.console.ScriptSessionCacheInit; import javax.inject.Named; import java.io.IOException; @@ -35,10 +35,9 @@ GroovyDeephavenSession bindGroovySession( final OperationInitializer operationInitializer, final ObjectTypeLookup lookup, final ScriptSession.Listener listener, - final RunScripts runScripts) { + final RunScripts runScripts, + final ScriptSessionCacheInit ignored) { try { - // create the script cache (or clear previous sessions) - AbstractScriptSession.createScriptCache(); return GroovyDeephavenSession.of(updateGraph, operationInitializer, lookup, listener, runScripts); } catch (final IOException e) { throw new UncheckedIOException(e); diff --git a/server/src/main/java/io/deephaven/server/console/python/PythonConsoleSessionModule.java b/server/src/main/java/io/deephaven/server/console/python/PythonConsoleSessionModule.java index 270e8693ecf..8c2609339c9 100644 --- a/server/src/main/java/io/deephaven/server/console/python/PythonConsoleSessionModule.java +++ b/server/src/main/java/io/deephaven/server/console/python/PythonConsoleSessionModule.java @@ -10,11 +10,11 @@ import io.deephaven.engine.updategraph.OperationInitializer; import io.deephaven.engine.updategraph.UpdateGraph; import io.deephaven.engine.updategraph.impl.PeriodicUpdateGraph; -import io.deephaven.engine.util.AbstractScriptSession; import io.deephaven.engine.util.PythonEvaluatorJpy; import io.deephaven.engine.util.ScriptSession; import io.deephaven.integrations.python.PythonDeephavenSession; import io.deephaven.plugin.type.ObjectTypeLookup; +import io.deephaven.server.console.ScriptSessionCacheInit; import io.deephaven.util.thread.ThreadInitializationFactory; import javax.inject.Named; @@ -37,10 +37,9 @@ PythonDeephavenSession bindPythonSession( final OperationInitializer operationInitializer, final ObjectTypeLookup lookup, final ScriptSession.Listener listener, - final PythonEvaluatorJpy pythonEvaluator) { + final PythonEvaluatorJpy pythonEvaluator, + final ScriptSessionCacheInit ignored) { try { - // create the script cache (or clear previous sessions) - AbstractScriptSession.createScriptCache(); return new PythonDeephavenSession( updateGraph, operationInitializer, threadInitializationFactory, lookup, listener, true, pythonEvaluator);