From 482388e40f825ba22bc5c33b2888ed2a78752877 Mon Sep 17 00:00:00 2001 From: Nate Bauernfeind Date: Tue, 30 Apr 2024 16:36:15 -0600 Subject: [PATCH] Move Script Cache Clearing to Dagger (#5436) Also ensure directories before creating temp compilation directory in QueryCompilerImpl. --- .../engine/context/QueryCompilerImpl.java | 8 ++++---- .../server/console/ConsoleModule.java | 7 +++++++ .../console/NoConsoleSessionModule.java | 3 ++- .../console/ScriptSessionCacheInit.java | 19 +++++++++++++++++++ .../groovy/GroovyConsoleSessionModule.java | 4 +++- .../python/PythonConsoleSessionModule.java | 4 +++- .../server/runner/DeephavenApiServer.java | 3 --- 7 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 server/src/main/java/io/deephaven/server/console/ScriptSessionCacheInit.java 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) { 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 7b4146938d3..ff097829f79 100644 --- a/server/src/main/java/io/deephaven/server/console/NoConsoleSessionModule.java +++ b/server/src/main/java/io/deephaven/server/console/NoConsoleSessionModule.java @@ -28,7 +28,8 @@ ScriptSession bindScriptSession(NoLanguageDeephavenSession noLanguageSession) { @Provides NoLanguageDeephavenSession bindNoLanguageSession( @Named(PeriodicUpdateGraph.DEFAULT_UPDATE_GRAPH_NAME) final UpdateGraph updateGraph, - final OperationInitializer operationInitializer) { + 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 0adcd9400c2..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 @@ -14,6 +14,7 @@ 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; @@ -34,7 +35,8 @@ GroovyDeephavenSession bindGroovySession( final OperationInitializer operationInitializer, final ObjectTypeLookup lookup, final ScriptSession.Listener listener, - final RunScripts runScripts) { + final RunScripts runScripts, + final ScriptSessionCacheInit ignored) { try { return GroovyDeephavenSession.of(updateGraph, operationInitializer, lookup, listener, runScripts); } catch (final IOException 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..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 @@ -14,6 +14,7 @@ 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; @@ -36,7 +37,8 @@ PythonDeephavenSession bindPythonSession( final OperationInitializer operationInitializer, final ObjectTypeLookup lookup, final ScriptSession.Listener listener, - final PythonEvaluatorJpy pythonEvaluator) { + final PythonEvaluatorJpy pythonEvaluator, + final ScriptSessionCacheInit ignored) { try { return new PythonDeephavenSession( updateGraph, operationInitializer, threadInitializationFactory, lookup, listener, 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); }