Skip to content

Commit

Permalink
[hotfix]groovy class cache leak (#9716)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Nov 3, 2022
1 parent 229c55e commit 9698b3e
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,15 +34,18 @@ 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);

public static String renderTemplate(String template, Map<String, Object> newContext)
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;
}

/**
Expand Down

0 comments on commit 9698b3e

Please sign in to comment.