fix udf dynamic memory leak of 4.0 branch
This commit is contained in:
		| @ -187,7 +187,7 @@ int ObPL::init(common::ObMySQLProxy &sql_proxy) | |||||||
|   return ret; |   return ret; | ||||||
| } | } | ||||||
|  |  | ||||||
| ObPLCtx::~ObPLCtx() | void ObPLCtx::reset_obj() | ||||||
| { | { | ||||||
|   int tmp_ret = OB_SUCCESS; |   int tmp_ret = OB_SUCCESS; | ||||||
|   for (int64_t i = 0; i < objects_.count(); ++i) { |   for (int64_t i = 0; i < objects_.count(); ++i) { | ||||||
| @ -198,6 +198,11 @@ ObPLCtx::~ObPLCtx() | |||||||
|   objects_.reset(); |   objects_.reset(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | ObPLCtx::~ObPLCtx() | ||||||
|  | { | ||||||
|  |   reset_obj(); | ||||||
|  | } | ||||||
|  |  | ||||||
| void ObPL::destory() | void ObPL::destory() | ||||||
| { | { | ||||||
|   codegen_lock_.destroy(); |   codegen_lock_.destroy(); | ||||||
| @ -281,6 +286,7 @@ int ObPL::execute_proc(ObPLExecCtx &ctx, | |||||||
|         ctx.exec_ctx_->get_sql_ctx()->schema_guard_ = &schema_guard; |         ctx.exec_ctx_->get_sql_ctx()->schema_guard_ = &schema_guard; | ||||||
|         try { |         try { | ||||||
|           if (OB_FAIL(pl.execute(*ctx.exec_ctx_, |           if (OB_FAIL(pl.execute(*ctx.exec_ctx_, | ||||||
|  |                                  ctx.exec_ctx_->get_allocator(), | ||||||
|                                  package_id, |                                  package_id, | ||||||
|                                  proc_id, |                                  proc_id, | ||||||
|                                  path_array, |                                  path_array, | ||||||
| @ -1148,6 +1154,7 @@ int ObPLContext::set_subprogram_var_from_local( | |||||||
|  |  | ||||||
| // for common execute routine. | // for common execute routine. | ||||||
| int ObPL::execute(ObExecContext &ctx, | int ObPL::execute(ObExecContext &ctx, | ||||||
|  |                   ObIAllocator &allocator, | ||||||
|                   ObPLPackageGuard &package_guard, |                   ObPLPackageGuard &package_guard, | ||||||
|                   ObPLFunction &routine, |                   ObPLFunction &routine, | ||||||
|                   ParamStore *params, |                   ParamStore *params, | ||||||
| @ -1166,7 +1173,7 @@ int ObPL::execute(ObExecContext &ctx, | |||||||
|   ObObj local_result(ObMaxType); |   ObObj local_result(ObMaxType); | ||||||
|   int local_status = OB_SUCCESS; |   int local_status = OB_SUCCESS; | ||||||
|  |  | ||||||
|   ObPLExecState pl(ctx.get_allocator(), |   ObPLExecState pl(allocator, | ||||||
|                    ctx, |                    ctx, | ||||||
|                    package_guard, |                    package_guard, | ||||||
|                    routine, |                    routine, | ||||||
| @ -1279,6 +1286,7 @@ int ObPL::execute(ObExecContext &ctx, const ObStmtNodeTree *block) | |||||||
|       try { |       try { | ||||||
|         // execute it. |         // execute it. | ||||||
|         OZ (execute(ctx, |         OZ (execute(ctx, | ||||||
|  |                     ctx.get_allocator(), | ||||||
|                     *(ctx.get_package_guard()), |                     *(ctx.get_package_guard()), | ||||||
|                     *routine, |                     *routine, | ||||||
|                     NULL, // params |                     NULL, // params | ||||||
| @ -1362,6 +1370,7 @@ int ObPL::execute(ObExecContext &ctx, | |||||||
|       try { |       try { | ||||||
|         // execute it... |         // execute it... | ||||||
|         OZ (execute(ctx, |         OZ (execute(ctx, | ||||||
|  |                     ctx.get_allocator(), | ||||||
|                     *(ctx.get_package_guard()), |                     *(ctx.get_package_guard()), | ||||||
|                     *routine, |                     *routine, | ||||||
|                     ¶ms, |                     ¶ms, | ||||||
| @ -1391,6 +1400,7 @@ int ObPL::execute(ObExecContext &ctx, | |||||||
|  |  | ||||||
| // for normal routine | // for normal routine | ||||||
| int ObPL::execute(ObExecContext &ctx, | int ObPL::execute(ObExecContext &ctx, | ||||||
|  |                   ObIAllocator &allocator, | ||||||
|                   uint64_t package_id, |                   uint64_t package_id, | ||||||
|                   uint64_t routine_id, |                   uint64_t routine_id, | ||||||
|                   const ObIArray<int64_t> &subprogram_path, |                   const ObIArray<int64_t> &subprogram_path, | ||||||
| @ -1509,6 +1519,7 @@ int ObPL::execute(ObExecContext &ctx, | |||||||
|     try { |     try { | ||||||
|       // execute it ... |       // execute it ... | ||||||
|       OZ (execute(ctx, |       OZ (execute(ctx, | ||||||
|  |                   allocator, | ||||||
|                   *(ctx.get_package_guard()), |                   *(ctx.get_package_guard()), | ||||||
|                   *routine, |                   *routine, | ||||||
|                   ¶ms, |                   ¶ms, | ||||||
|  | |||||||
| @ -612,6 +612,7 @@ public: | |||||||
|   int add(ObObj &obj) { |   int add(ObObj &obj) { | ||||||
|     return objects_.push_back(obj); |     return objects_.push_back(obj); | ||||||
|   } |   } | ||||||
|  |   void reset_obj(); | ||||||
|   common::ObIArray<ObObj>& get_objects() { return objects_; } |   common::ObIArray<ObObj>& get_objects() { return objects_; } | ||||||
| private: | private: | ||||||
|   // 用于收集在PL执行过程中使用到的Allocator, |   // 用于收集在PL执行过程中使用到的Allocator, | ||||||
| @ -1012,6 +1013,7 @@ public: | |||||||
|  |  | ||||||
|   // for normal routine or package routine |   // for normal routine or package routine | ||||||
|   int execute(sql::ObExecContext &ctx, |   int execute(sql::ObExecContext &ctx, | ||||||
|  |               ObIAllocator &allocator, | ||||||
|               uint64_t package_id, |               uint64_t package_id, | ||||||
|               uint64_t routine_id, |               uint64_t routine_id, | ||||||
|               const ObIArray<int64_t> &subprogram_path, |               const ObIArray<int64_t> &subprogram_path, | ||||||
| @ -1056,6 +1058,7 @@ private: | |||||||
|  |  | ||||||
|   // for inner common execute |   // for inner common execute | ||||||
|   int execute(sql::ObExecContext &ctx, |   int execute(sql::ObExecContext &ctx, | ||||||
|  |               ObIAllocator &allocator, | ||||||
|               ObPLPackageGuard &package_guard, |               ObPLPackageGuard &package_guard, | ||||||
|               ObPLFunction &routine, |               ObPLFunction &routine, | ||||||
|               ParamStore *params, |               ParamStore *params, | ||||||
|  | |||||||
| @ -255,6 +255,7 @@ int ObPLPackage::execute_init_routine(ObIAllocator &allocator, ObExecContext &ex | |||||||
|       int status; |       int status; | ||||||
|       ObSEArray<int64_t, 2> subp_path; |       ObSEArray<int64_t, 2> subp_path; | ||||||
|       OZ (pl_engine->execute(exec_ctx, |       OZ (pl_engine->execute(exec_ctx, | ||||||
|  |                              exec_ctx.get_allocator(), | ||||||
|                              init_routine->get_package_id(), |                              init_routine->get_package_id(), | ||||||
|                              init_routine->get_routine_id(), |                              init_routine->get_routine_id(), | ||||||
|                              subp_path, |                              subp_path, | ||||||
|  | |||||||
| @ -145,6 +145,7 @@ int ObCallProcedureExecutor::execute(ObExecContext &ctx, ObCallProcedureStmt &st | |||||||
|       int64_t pkg_id = stmt.is_udt_routine() |       int64_t pkg_id = stmt.is_udt_routine() | ||||||
|                ? share::schema::ObUDTObjectType::mask_object_id(package_id) : package_id; |                ? share::schema::ObUDTObjectType::mask_object_id(package_id) : package_id; | ||||||
|       if (OB_FAIL(ctx.get_pl_engine()->execute(ctx, |       if (OB_FAIL(ctx.get_pl_engine()->execute(ctx, | ||||||
|  |                                                ctx.get_allocator(), | ||||||
|                                                pkg_id, |                                                pkg_id, | ||||||
|                                                routine_id, |                                                routine_id, | ||||||
|                                                path, |                                                path, | ||||||
|  | |||||||
| @ -403,7 +403,7 @@ int TriggerHandle::calc_trigger_routine( | |||||||
|   trigger_id = ObTriggerInfo::get_trigger_spec_package_id(trigger_id); |   trigger_id = ObTriggerInfo::get_trigger_spec_package_id(trigger_id); | ||||||
|   OV (OB_NOT_NULL(exec_ctx.get_pl_engine())); |   OV (OB_NOT_NULL(exec_ctx.get_pl_engine())); | ||||||
|   OZ (exec_ctx.get_pl_engine()->execute( |   OZ (exec_ctx.get_pl_engine()->execute( | ||||||
|     exec_ctx, trigger_id, routine_id, path, params, nocopy_params, result), |     exec_ctx, exec_ctx.get_allocator(), trigger_id, routine_id, path, params, nocopy_params, result), | ||||||
|       trigger_id, routine_id, params); |       trigger_id, routine_id, params); | ||||||
|   return ret; |   return ret; | ||||||
| } | } | ||||||
|  | |||||||
| @ -407,6 +407,7 @@ int ObExprUDF::build_udf_ctx(int64_t udf_ctx_id, | |||||||
| int ObExprUDF::eval_udf(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &res) | int ObExprUDF::eval_udf(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &res) | ||||||
| { | { | ||||||
|   int ret = OB_SUCCESS; |   int ret = OB_SUCCESS; | ||||||
|  |   ObObj tmp_result; | ||||||
|   ObObj result; |   ObObj result; | ||||||
|   pl::ObPL *pl_engine = nullptr; |   pl::ObPL *pl_engine = nullptr; | ||||||
|   ParamStore *udf_params = nullptr; |   ParamStore *udf_params = nullptr; | ||||||
| @ -479,17 +480,20 @@ int ObExprUDF::eval_udf(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &res) | |||||||
|       CK (0 < udf_params->count()); |       CK (0 < udf_params->count()); | ||||||
|       OZ (ns.init_complex_obj(alloc, pl_type, udf_params->at(0), false, false)); |       OZ (ns.init_complex_obj(alloc, pl_type, udf_params->at(0), false, false)); | ||||||
|     } |     } | ||||||
|  |     ObEvalCtx::TempAllocGuard tmp_alloc_g(ctx); | ||||||
|     try { |     try { | ||||||
|       int64_t package_id = info->is_udt_udf_ ? |       int64_t package_id = info->is_udt_udf_ ? | ||||||
|            share::schema::ObUDTObjectType::mask_object_id(info->udf_package_id_) |            share::schema::ObUDTObjectType::mask_object_id(info->udf_package_id_) | ||||||
|            : info->udf_package_id_; |            : info->udf_package_id_; | ||||||
|       OZ(pl_engine->execute(ctx.exec_ctx_, |       OZ(pl_engine->execute(ctx.exec_ctx_, | ||||||
|  |                             info->is_called_in_sql_ ? tmp_alloc_g.get_allocator() | ||||||
|  |                                                     : alloc, | ||||||
|                             package_id, |                             package_id, | ||||||
|                             info->udf_id_, |                             info->udf_id_, | ||||||
|                             info->subprogram_path_, |                             info->subprogram_path_, | ||||||
|                             *udf_params, |                             *udf_params, | ||||||
|                             info->nocopy_params_, |                             info->nocopy_params_, | ||||||
|                             result, |                             tmp_result, | ||||||
|                             nullptr, |                             nullptr, | ||||||
|                             false, |                             false, | ||||||
|                             true, |                             true, | ||||||
| @ -499,12 +503,22 @@ int ObExprUDF::eval_udf(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &res) | |||||||
|                             info->udf_id_, |                             info->udf_id_, | ||||||
|                             info->udf_package_id_, |                             info->udf_package_id_, | ||||||
|                             info->is_udt_udf_, |                             info->is_udt_udf_, | ||||||
|                             result, |                             tmp_result, | ||||||
|                             package_id); |                             package_id); | ||||||
|     } catch(...) { |     } catch(...) { | ||||||
| //      OZ(after_calc_result(schema_guard, sql_ctx, ctx.exec_ctx_)); | //      OZ(after_calc_result(schema_guard, sql_ctx, ctx.exec_ctx_)); | ||||||
|       throw; |       throw; | ||||||
|     } |     } | ||||||
|  |     if (OB_SUCC(ret)) { | ||||||
|  |       if (tmp_result.is_pl_extend()) { | ||||||
|  |         OZ (pl::ObUserDefinedType::deep_copy_obj(alloc, tmp_result, result, true)); | ||||||
|  |       } else { | ||||||
|  |         OZ (deep_copy_obj(alloc, tmp_result, result)); | ||||||
|  |       } | ||||||
|  |       if (info->is_called_in_sql_) { | ||||||
|  |         OX (ctx.exec_ctx_.get_pl_ctx()->reset_obj()); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|     if (OB_SUCC(ret) && info->is_udt_cons_) { |     if (OB_SUCC(ret) && info->is_udt_cons_) { | ||||||
|       pl::ObPLComposite *obj_self = reinterpret_cast<pl::ObPLRecord *>(udf_params->at(0).get_ext()); |       pl::ObPLComposite *obj_self = reinterpret_cast<pl::ObPLRecord *>(udf_params->at(0).get_ext()); | ||||||
|       CK (OB_NOT_NULL(obj_self)); |       CK (OB_NOT_NULL(obj_self)); | ||||||
|  | |||||||
| @ -110,6 +110,7 @@ int ObPlAggUdfFunction::call_pl_engine_exectue_udf(ParamStore& udf_params, | |||||||
|     LOG_WARN("udf parameter number is not equal to params desc count", |     LOG_WARN("udf parameter number is not equal to params desc count", | ||||||
|                                  K(ret), K(udf_params.count()), K(routine_info->get_param_count())); |                                  K(ret), K(udf_params.count()), K(routine_info->get_param_count())); | ||||||
|   } else if (OB_FAIL(pl_engine->execute(*exec_ctx_, |   } else if (OB_FAIL(pl_engine->execute(*exec_ctx_, | ||||||
|  |                                         exec_ctx_->get_allocator(), | ||||||
|                                         -1, |                                         -1, | ||||||
|                                         routine_info->get_routine_id(), |                                         routine_info->get_routine_id(), | ||||||
|                                         empty_subprogram_path, |                                         empty_subprogram_path, | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 obdev
					obdev