This is an automated email from the ASF dual-hosted git repository.

rongr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new 9698b3e4dd [hotfix]groovy class cache leak (#9716)
9698b3e4dd is described below

commit 9698b3e4ddedec0a78aeca44f5cafd9148f44fad
Author: Rong Rong <[email protected]>
AuthorDate: Thu Nov 3 14:24:17 2022 -0700

    [hotfix]groovy class cache leak (#9716)
    
    * groovy class cache needs to be clean up;
    * downside is template cache reuse is not possible. but luckily we don't 
reuse template that often.
    
    Co-authored-by: Rong Rong <[email protected]>
    Co-authored-by: Xiaotian (Jackie) Jiang 
<[email protected]>
---
 .../main/java/org/apache/pinot/spi/utils/GroovyTemplateUtils.java | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git 
a/pinot-spi/src/main/java/org/apache/pinot/spi/utils/GroovyTemplateUtils.java 
b/pinot-spi/src/main/java/org/apache/pinot/spi/utils/GroovyTemplateUtils.java
index 52f00b0ca6..26b5da90cb 100644
--- 
a/pinot-spi/src/main/java/org/apache/pinot/spi/utils/GroovyTemplateUtils.java
+++ 
b/pinot-spi/src/main/java/org/apache/pinot/spi/utils/GroovyTemplateUtils.java
@@ -18,6 +18,7 @@
  */
 package org.apache.pinot.spi.utils;
 
+import groovy.lang.GroovyShell;
 import groovy.text.SimpleTemplateEngine;
 import java.io.IOException;
 import java.time.Instant;
@@ -33,7 +34,8 @@ public class GroovyTemplateUtils {
   private GroovyTemplateUtils() {
   }
 
-  private static final SimpleTemplateEngine GROOVY_TEMPLATE_ENGINE = new 
SimpleTemplateEngine();
+  private static final GroovyShell GROOVY_SHELL = new GroovyShell();
+  private static final SimpleTemplateEngine GROOVY_TEMPLATE_ENGINE = new 
SimpleTemplateEngine(GROOVY_SHELL);
   private static final DateTimeFormatter DATE_FORMAT =
       DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneOffset.UTC);
 
@@ -41,7 +43,9 @@ public class GroovyTemplateUtils {
       throws IOException, ClassNotFoundException {
     Map<String, Object> contextMap = getDefaultContextMap();
     contextMap.putAll(newContext);
-    return 
GROOVY_TEMPLATE_ENGINE.createTemplate(template).make(contextMap).toString();
+    String templateRendered = 
GROOVY_TEMPLATE_ENGINE.createTemplate(template).make(contextMap).toString();
+    GROOVY_SHELL.resetLoadedClasses();
+    return templateRendered;
   }
 
   /**


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to