From d4c0d536cbf7fb777d8f5a772e4996e5a5c0b609 Mon Sep 17 00:00:00 2001 From: ulysses-you Date: Wed, 15 Nov 2023 15:30:26 +0800 Subject: [PATCH] Fix validation runtime hanle leak --- .../backendsapi/velox/ValidatorApiImpl.scala | 10 ++++++++-- .../glutenproject/vectorized/NativePlanEvaluator.java | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/backends-velox/src/main/scala/io/glutenproject/backendsapi/velox/ValidatorApiImpl.scala b/backends-velox/src/main/scala/io/glutenproject/backendsapi/velox/ValidatorApiImpl.scala index 6d606cf52310..4d64a790c8d1 100644 --- a/backends-velox/src/main/scala/io/glutenproject/backendsapi/velox/ValidatorApiImpl.scala +++ b/backends-velox/src/main/scala/io/glutenproject/backendsapi/velox/ValidatorApiImpl.scala @@ -17,6 +17,7 @@ package io.glutenproject.backendsapi.velox import io.glutenproject.backendsapi.ValidatorApi +import io.glutenproject.exec.Runtimes import io.glutenproject.substrait.plan.PlanNode import io.glutenproject.validate.NativePlanValidationInfo import io.glutenproject.vectorized.NativePlanEvaluator @@ -31,8 +32,13 @@ class ValidatorApiImpl extends ValidatorApi { doExprValidate(Map(), substraitExprName, expr) override def doNativeValidateWithFailureReason(plan: PlanNode): NativePlanValidationInfo = { - val validator = NativePlanEvaluator.createForValidation() - validator.doNativeValidateWithFailureReason(plan.toProtobuf.toByteArray) + val tmpRuntime = Runtimes.tmpInstance() + try { + val validator = NativePlanEvaluator.createForValidation(tmpRuntime) + validator.doNativeValidateWithFailureReason(plan.toProtobuf.toByteArray) + } finally { + tmpRuntime.release() + } } override def doSparkPlanValidate(plan: SparkPlan): Boolean = true diff --git a/gluten-data/src/main/java/io/glutenproject/vectorized/NativePlanEvaluator.java b/gluten-data/src/main/java/io/glutenproject/vectorized/NativePlanEvaluator.java index 468fc72ecf00..af4f5cf3a090 100644 --- a/gluten-data/src/main/java/io/glutenproject/vectorized/NativePlanEvaluator.java +++ b/gluten-data/src/main/java/io/glutenproject/vectorized/NativePlanEvaluator.java @@ -45,9 +45,9 @@ public static NativePlanEvaluator create() { return new NativePlanEvaluator(Runtimes.contextInstance()); } - public static NativePlanEvaluator createForValidation() { + public static NativePlanEvaluator createForValidation(Runtime runtime) { // Driver side doesn't have context instance of Runtime - return new NativePlanEvaluator(Runtimes.tmpInstance()); + return new NativePlanEvaluator(runtime); } public NativePlanValidationInfo doNativeValidateWithFailureReason(byte[] subPlan) {