提交 cb73a5c1 编写于 作者: S slzhou

fix: check udf python plugin load/open failure

上级 6dae414e
...@@ -345,7 +345,7 @@ int32_t udfdLoadSharedLib(char *libPath, uv_lib_t *pLib, const char *funcName[], ...@@ -345,7 +345,7 @@ int32_t udfdLoadSharedLib(char *libPath, uv_lib_t *pLib, const char *funcName[],
return 0; return 0;
} }
void udfdInitializePythonPlugin(SUdfScriptPlugin *plugin) { int32_t udfdInitializePythonPlugin(SUdfScriptPlugin *plugin) {
plugin->scriptType = TSDB_FUNC_SCRIPT_PYTHON; plugin->scriptType = TSDB_FUNC_SCRIPT_PYTHON;
// todo: windows support // todo: windows support
sprintf(plugin->libPath, "%s", "libtaospyudf.so"); sprintf(plugin->libPath, "%s", "libtaospyudf.so");
...@@ -360,8 +360,9 @@ void udfdInitializePythonPlugin(SUdfScriptPlugin *plugin) { ...@@ -360,8 +360,9 @@ void udfdInitializePythonPlugin(SUdfScriptPlugin *plugin) {
int32_t err = udfdLoadSharedLib(plugin->libPath, &plugin->lib, funcName, funcs, UDFD_MAX_PLUGIN_FUNCS); int32_t err = udfdLoadSharedLib(plugin->libPath, &plugin->lib, funcName, funcs, UDFD_MAX_PLUGIN_FUNCS);
if (err != 0) { if (err != 0) {
fnError("can not load python plugin. lib path %s", plugin->libPath); fnError("can not load python plugin. lib path %s", plugin->libPath);
return; return err;
} }
if (plugin->openFunc) { if (plugin->openFunc) {
int16_t lenPythonPath = strlen(tsUdfdLdLibPath) + strlen(tsTempDir) + 1 + 1; // tsTempDir:tsUdfdLdLibPath int16_t lenPythonPath = strlen(tsUdfdLdLibPath) + strlen(tsTempDir) + 1 + 1; // tsTempDir:tsUdfdLdLibPath
char *pythonPath = taosMemoryMalloc(lenPythonPath); char *pythonPath = taosMemoryMalloc(lenPythonPath);
...@@ -371,11 +372,17 @@ void udfdInitializePythonPlugin(SUdfScriptPlugin *plugin) { ...@@ -371,11 +372,17 @@ void udfdInitializePythonPlugin(SUdfScriptPlugin *plugin) {
snprintf(pythonPath, lenPythonPath, "%s:%s", tsTempDir, tsUdfdLdLibPath); snprintf(pythonPath, lenPythonPath, "%s:%s", tsTempDir, tsUdfdLdLibPath);
#endif #endif
SScriptUdfEnvItem items[] = {{"PYTHONPATH", pythonPath}, {"LOGDIR", tsLogDir}}; SScriptUdfEnvItem items[] = {{"PYTHONPATH", pythonPath}, {"LOGDIR", tsLogDir}};
plugin->openFunc(items, 1); err = plugin->openFunc(items, 1);
taosMemoryFree(pythonPath); taosMemoryFree(pythonPath);
} }
if (err != 0) {
fnError("udf script python plugin open func failed. error: %d", err);
uv_dlclose(&plugin->lib);
return err;
}
plugin->libLoaded = true; plugin->libLoaded = true;
return;
return 0;
} }
void udfdDeinitCPlugin(SUdfScriptPlugin *plugin) { void udfdDeinitCPlugin(SUdfScriptPlugin *plugin) {
...@@ -420,9 +427,14 @@ int32_t udfdInitScriptPlugin(int8_t scriptType) { ...@@ -420,9 +427,14 @@ int32_t udfdInitScriptPlugin(int8_t scriptType) {
case TSDB_FUNC_SCRIPT_BIN_LIB: case TSDB_FUNC_SCRIPT_BIN_LIB:
udfdInitializeCPlugin(plugin); udfdInitializeCPlugin(plugin);
break; break;
case TSDB_FUNC_SCRIPT_PYTHON: case TSDB_FUNC_SCRIPT_PYTHON: {
udfdInitializePythonPlugin(plugin); int32_t err = udfdInitializePythonPlugin(plugin);
if (err != 0) {
taosMemoryFree(plugin);
return err;
}
break; break;
}
default: default:
fnError("udf script type %d not supported", scriptType); fnError("udf script type %d not supported", scriptType);
taosMemoryFree(plugin); taosMemoryFree(plugin);
...@@ -518,7 +530,7 @@ int32_t udfdInitUdf(char *udfName, SUdf *udf) { ...@@ -518,7 +530,7 @@ int32_t udfdInitUdf(char *udfName, SUdf *udf) {
uv_mutex_lock(&global.scriptPluginsMutex); uv_mutex_lock(&global.scriptPluginsMutex);
SUdfScriptPlugin *scriptPlugin = global.scriptPlugins[udf->scriptType]; SUdfScriptPlugin *scriptPlugin = global.scriptPlugins[udf->scriptType];
if (scriptPlugin == NULL) { if (scriptPlugin == NULL || scriptPlugin->libLoaded == false) {
err = udfdInitScriptPlugin(udf->scriptType); err = udfdInitScriptPlugin(udf->scriptType);
if (err != 0) { if (err != 0) {
uv_mutex_unlock(&global.scriptPluginsMutex); uv_mutex_unlock(&global.scriptPluginsMutex);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册