diff --git a/.gitignore b/.gitignore index ff27b531395b..8261893fd0bf 100644 --- a/.gitignore +++ b/.gitignore @@ -51,7 +51,6 @@ pysim/ tests/script/api/batchprepare taosadapter taosadapter-debug -tools/taos-tools/* tools/taosws-rs/* tools/taosadapter/* tools/upx* @@ -60,7 +59,6 @@ tools/upx* html/ /.vs /CMakeFiles/3.10.2 -/CMakeCache.txt /Makefile /*.cmake /src/cq/test/CMakeFiles/cqtest.dir/*.cmake @@ -133,7 +131,6 @@ tools/THANKS tools/NEWS tools/COPYING tools/BUGS -tools/taos-tools tools/taosws-rs tags .clangd diff --git a/Jenkinsfile2 b/Jenkinsfile2 index 3135b7b683a1..5a2d6cbb3ed9 100644 --- a/Jenkinsfile2 +++ b/Jenkinsfile2 @@ -371,6 +371,7 @@ def pre_test_build_win() { pip3 install taospy==2.7.21 pip3 install taos-ws-py==0.3.8 xcopy /e/y/i/f %WIN_INTERNAL_ROOT%\\debug\\build\\lib\\taos.dll C:\\Windows\\System32 + xcopy /e/y/i/f %WIN_INTERNAL_ROOT%\\debug\\build\\lib\\taosnative.dll C:\\Windows\\System32 ''' return 1 } @@ -389,7 +390,9 @@ def run_win_test() { bat ''' echo "windows test ..." xcopy /e/y/i/f %WIN_INTERNAL_ROOT%\\debug\\build\\lib\\taos.dll C:\\Windows\\System32 + xcopy /e/y/i/f %WIN_INTERNAL_ROOT%\\debug\\build\\lib\\taosnative.dll C:\\Windows\\System32 ls -l C:\\Windows\\System32\\taos.dll + ls -l C:\\Windows\\System32\\taosnative.dll time /t cd %WIN_SYSTEM_TEST_ROOT% echo "testing ..." diff --git a/cmake/cmake.define b/cmake/cmake.define index 72c9e84f78df..10eb14c6736f 100644 --- a/cmake/cmake.define +++ b/cmake/cmake.define @@ -97,14 +97,10 @@ ELSE() SET(TD_TAOS_TOOLS TRUE) ENDIF() -SET(TAOS_LIB taos) +SET(TAOS_LIB taos) SET(TAOS_LIB_STATIC taos_static) - -IF(${TD_WINDOWS}) - SET(TAOS_LIB_PLATFORM_SPEC taos_static) -ELSE() - SET(TAOS_LIB_PLATFORM_SPEC taos) -ENDIF() +SET(TAOS_NATIVE_LIB taosnative) +SET(TAOS_NATIVE_LIB_STATIC taosnative_static) # build TSZ by default IF("${TSZ_ENABLED}" MATCHES "false") diff --git a/cmake/taosws_CMakeLists.txt.in b/cmake/taosws_CMakeLists.txt.in index b013d4591198..30273a769299 100644 --- a/cmake/taosws_CMakeLists.txt.in +++ b/cmake/taosws_CMakeLists.txt.in @@ -2,7 +2,7 @@ # taosws-rs ExternalProject_Add(taosws-rs GIT_REPOSITORY https://github.com/taosdata/taos-connector-rust.git - GIT_TAG main + GIT_TAG feat/new-libtaos-with-ws SOURCE_DIR "${TD_SOURCE_DIR}/tools/taosws-rs" BINARY_DIR "" #BUILD_IN_SOURCE TRUE diff --git a/docs/en/14-reference/05-connector/10-cpp.md b/docs/en/14-reference/05-connector/10-cpp.md index edccd8ebd431..ac9a7284df63 100644 --- a/docs/en/14-reference/05-connector/10-cpp.md +++ b/docs/en/14-reference/05-connector/10-cpp.md @@ -682,7 +682,7 @@ The basic API is used to establish database connections and provide a runtime en - **Interface Description**: Cleans up the runtime environment, should be called before the application exits. - `int taos_options(TSDB_OPTION option, const void * arg, ...)` - - **Interface Description**: Sets client options, currently supports locale (`TSDB_OPTION_LOCALE`), character set (`TSDB_OPTION_CHARSET`), timezone (`TSDB_OPTION_TIMEZONE`), and configuration file path (`TSDB_OPTION_CONFIGDIR`). Locale, character set, and timezone default to the current settings of the operating system. + - **Interface Description**: Sets client options, currently supports locale (`TSDB_OPTION_LOCALE`), character set (`TSDB_OPTION_CHARSET`), timezone (`TSDB_OPTION_TIMEZONE`), configuration file path (`TSDB_OPTION_CONFIGDIR`), and driver type (`TSDB_OPTION_DRIVER`). Locale, character set, and timezone default to the current settings of the operating system. The driver type can be either the native interface(`native`) or the WebSocket interface(`websocket`), with the default being `websocket`. - **Parameter Description**: - `option`: [Input] Setting item type. - `arg`: [Input] Setting item value. diff --git a/docs/en/14-reference/09-error-code.md b/docs/en/14-reference/09-error-code.md index 7dbd58bb1d1c..882822884b0e 100644 --- a/docs/en/14-reference/09-error-code.md +++ b/docs/en/14-reference/09-error-code.md @@ -41,6 +41,8 @@ This document details the server error codes that may be encountered when using | 0x80000107 | Ref ID is removed | The referenced ref resource has been released | Preserve the scene and logs, report issue on github | | 0x80000108 | Invalid Ref ID | Invalid ref ID | Preserve the scene and logs, report issue on github | | 0x8000010A | Ref is not there | ref information does not exist | Preserve the scene and logs, report issue on github | +| 0x8000010B | Driver was not loaded | libtaosnative.so or libtaosws.so was not found in the system path | Reinstall the client driver | +| 0x8000010C | Function was not loaded from the driver | some function defined in libtaos.so are not implemented in libtaosnative.so or libtaosws.so | Reinstall the client driver | | 0x80000110 | Unexpected generic error | System internal error | Preserve the scene and logs, report issue on github | | 0x80000111 | Action in progress | Operation in progress | 1. Wait for the operation to complete 2. Cancel the operation if necessary 3. If it exceeds a reasonable time and still not completed, preserve the scene and logs, or contact customer support | | 0x80000112 | Out of range | Configuration parameter exceeds allowed value range | Change the parameter | diff --git a/docs/zh/14-reference/05-connector/10-cpp.mdx b/docs/zh/14-reference/05-connector/10-cpp.mdx index 3f36fb9e91a1..14a309afca52 100644 --- a/docs/zh/14-reference/05-connector/10-cpp.mdx +++ b/docs/zh/14-reference/05-connector/10-cpp.mdx @@ -680,7 +680,7 @@ TDengine 客户端驱动的版本号与 TDengine 服务端的版本号是一一 - **接口说明**:清理运行环境,应用退出前应调用。 - `int taos_options(TSDB_OPTION option, const void * arg, ...)` - - **接口说明**:设置客户端选项,支持区域设置(`TSDB_OPTION_LOCALE`)、字符集设置(`TSDB_OPTION_CHARSET`)、时区设置(`TSDB_OPTION_TIMEZONE`)、配置文件路径设置(`TSDB_OPTION_CONFIGDIR`)。区域设置、字符集、时区默认为操作系统当前设置。 + - **接口说明**:设置客户端选项,支持区域设置(`TSDB_OPTION_LOCALE`)、字符集设置(`TSDB_OPTION_CHARSET`)、时区设置(`TSDB_OPTION_TIMEZONE`)、配置文件路径设置(`TSDB_OPTION_CONFIGDIR`)、驱动类型设置(`TSDB_OPTION_DRIVER`)。区域设置、字符集、时区默认为操作系统当前设置。驱动类型可选内部原生接口(`native`)和 WebSocket 接口(`websocket`),默认为 `websocket`。 - **参数说明**: - `option`:[入参] 设置项类型。 - `arg`:[入参] 设置项值。 diff --git a/docs/zh/14-reference/09-error-code.md b/docs/zh/14-reference/09-error-code.md index 353ce16ed428..b48647555751 100644 --- a/docs/zh/14-reference/09-error-code.md +++ b/docs/zh/14-reference/09-error-code.md @@ -44,6 +44,8 @@ description: TDengine 服务端的错误码列表和详细说明 | 0x80000107 | Ref ID is removed | 引用的 ref 资源已经释放 | 保留现场和日志,github 上报 issue | | 0x80000108 | Invalid Ref ID | 无效 ref ID | 保留现场和日志,github 上报 issue | | 0x8000010A | Ref is not there | ref 信息不存在 | 保留现场和日志,github 上报 issue | +| 0x8000010B | Driver was not loaded | 未在系统路径中找到 libtaosnative.so 或 libtaosws.so | 重新安装客户端驱动 | +| 0x8000010C | Function was not loaded from the driver | 在 libtaos.so 中定义的一些函数在 libtaosnative.so 或 libtaosws.so 中未实现 | 保留现场和日志,github 上报 issue | | 0x80000110 | Unexpected generic error | 系统内部错误 | 保留现场和日志,github 上报 issue | | 0x80000111 | Action in progress | 操作进行中 | 1.等待操作完成 2.根据需要取消操作 3.当超出合理时间仍然未完成可保留现场和日志,或联系客户支持 | | 0x80000112 | Out of range | 配置参数超出允许值范围 | 更改参数 | diff --git a/examples/c/CMakeLists.txt b/examples/c/CMakeLists.txt index e3c992f53fb1..94297272f795 100644 --- a/examples/c/CMakeLists.txt +++ b/examples/c/CMakeLists.txt @@ -42,27 +42,27 @@ IF(TD_LINUX) ) target_link_libraries(tmq - ${TAOS_LIB} + ${TAOS_NATIVE_LIB} ) target_link_libraries(stream_demo - ${TAOS_LIB} + ${TAOS_NATIVE_LIB} ) target_link_libraries(schemaless - ${TAOS_LIB} + ${TAOS_NATIVE_LIB} ) target_link_libraries(prepare - ${TAOS_LIB} + ${TAOS_NATIVE_LIB} ) target_link_libraries(demo - ${TAOS_LIB} + ${TAOS_NATIVE_LIB} ) target_link_libraries(asyncdemo - ${TAOS_LIB} + ${TAOS_NATIVE_LIB} ) SET_TARGET_PROPERTIES(tmq PROPERTIES OUTPUT_NAME tmq) diff --git a/include/client/taos.h b/include/client/taos.h index 433779f81142..324f4632835f 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -61,6 +61,7 @@ typedef enum { TSDB_OPTION_CONFIGDIR, TSDB_OPTION_SHELL_ACTIVITY_TIMER, TSDB_OPTION_USE_ADAPTER, + TSDB_OPTION_DRIVER, TSDB_MAX_OPTIONS } TSDB_OPTION; @@ -154,11 +155,14 @@ typedef enum { TAOS_NOTIFY_USER_DROPPED = 2, } TAOS_NOTIFY_TYPE; +/* -- implemented in the native interface, for internal component only, the API may change -- */ #define RET_MSG_LENGTH 1024 typedef struct setConfRet { SET_CONF_RET_CODE retCode; char retMsg[RET_MSG_LENGTH]; } setConfRet; +DLL_EXPORT setConfRet taos_set_config(const char *config); // implemented in the native interface +/* -- end -- */ typedef struct TAOS_VGROUP_HASH_INFO { int32_t vgId; @@ -181,14 +185,13 @@ typedef struct TAOS_STMT_OPTIONS { bool singleTableBindOnce; } TAOS_STMT_OPTIONS; -DLL_EXPORT void taos_cleanup(void); -DLL_EXPORT int taos_options(TSDB_OPTION option, const void *arg, ...); -DLL_EXPORT int taos_options_connection(TAOS *taos, TSDB_OPTION_CONNECTION option, const void *arg, ...); -DLL_EXPORT setConfRet taos_set_config(const char *config); -DLL_EXPORT int taos_init(void); -DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port); -DLL_EXPORT TAOS *taos_connect_auth(const char *ip, const char *user, const char *auth, const char *db, uint16_t port); -DLL_EXPORT void taos_close(TAOS *taos); +DLL_EXPORT int taos_init(void); +DLL_EXPORT void taos_cleanup(void); +DLL_EXPORT int taos_options(TSDB_OPTION option, const void *arg, ...); +DLL_EXPORT int taos_options_connection(TAOS *taos, TSDB_OPTION_CONNECTION option, const void *arg, ...); +DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port); +DLL_EXPORT TAOS *taos_connect_auth(const char *ip, const char *user, const char *auth, const char *db, uint16_t port); +DLL_EXPORT void taos_close(TAOS *taos); DLL_EXPORT const char *taos_data_type(int type); @@ -219,6 +222,7 @@ DLL_EXPORT char *taos_stmt_errstr(TAOS_STMT *stmt); DLL_EXPORT int taos_stmt_affected_rows(TAOS_STMT *stmt); DLL_EXPORT int taos_stmt_affected_rows_once(TAOS_STMT *stmt); +/* -- implemented in the native interface, for internal component only, the API may change -- */ typedef void TAOS_STMT2; typedef struct TAOS_STMT2_OPTION { @@ -256,6 +260,7 @@ DLL_EXPORT int taos_stmt2_get_fields(TAOS_STMT2 *stmt, int *count, TAOS_FIELD_AL DLL_EXPORT void taos_stmt2_free_fields(TAOS_STMT2 *stmt, TAOS_FIELD_ALL *fields); DLL_EXPORT TAOS_RES *taos_stmt2_result(TAOS_STMT2 *stmt); DLL_EXPORT char *taos_stmt2_error(TAOS_STMT2 *stmt); +/* -- end -- */ DLL_EXPORT TAOS_RES *taos_query(TAOS *taos, const char *sql); DLL_EXPORT TAOS_RES *taos_query_with_reqid(TAOS *taos, const char *sql, int64_t reqId); @@ -311,9 +316,11 @@ DLL_EXPORT void taos_set_hb_quit(int8_t quitByKill); DLL_EXPORT int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t fp, void *param, int type); +/* -- implemented in the native interface, for internal component only, the API may change -- */ typedef void (*__taos_async_whitelist_fn_t)(void *param, int code, TAOS *taos, int numOfWhiteLists, uint64_t *pWhiteLists); DLL_EXPORT void taos_fetch_whitelist_a(TAOS *taos, __taos_async_whitelist_fn_t fp, void *param); +/* ---- end ---- */ typedef enum { TAOS_CONN_MODE_BI = 0, @@ -412,7 +419,7 @@ DLL_EXPORT int32_t tmq_get_vgroup_id(TAOS_RES *res); DLL_EXPORT int64_t tmq_get_vgroup_offset(TAOS_RES *res); DLL_EXPORT const char *tmq_err2str(int32_t code); -/* ------------------------------ TAOSX INTERFACE -----------------------------------*/ +/* -- implemented in the native interface, for internal component(TAOSX) only, the API may change -- */ typedef struct tmq_raw_data { void *raw; uint32_t raw_len; @@ -433,8 +440,9 @@ DLL_EXPORT void tmq_free_raw(tmq_raw_data raw); // Returning null means error. Returned result need to be freed by tmq_free_json_meta DLL_EXPORT char *tmq_get_json_meta(TAOS_RES *res); DLL_EXPORT void tmq_free_json_meta(char *jsonMeta); -/* ---------------------------- TAOSX END -------------------------------- */ +/* ---- end ---- */ +/* -- implemented in the native interface, for internal component only, the API may change -- */ typedef enum { TSDB_SRV_STATUS_UNAVAILABLE = 0, TSDB_SRV_STATUS_NETWORK_OK = 1, @@ -444,7 +452,10 @@ typedef enum { } TSDB_SERVER_STATUS; DLL_EXPORT TSDB_SERVER_STATUS taos_check_server_status(const char *fqdn, int port, char *details, int maxlen); +DLL_EXPORT void taos_write_crashinfo(int signum, void *sigInfo, void *context); DLL_EXPORT char *getBuildInfo(); +/* ---- end ---- */ + #ifdef __cplusplus } #endif diff --git a/include/os/os.h b/include/os/os.h index a9c5ce5679c4..e9ee8066f93e 100644 --- a/include/os/os.h +++ b/include/os/os.h @@ -50,6 +50,7 @@ extern "C" { #include #if defined(DARWIN) +#include #else #include #include diff --git a/include/os/osDir.h b/include/os/osDir.h index 99d3ebccdef9..6cdd4ff0ad79 100644 --- a/include/os/osDir.h +++ b/include/os/osDir.h @@ -98,7 +98,9 @@ bool taosDirEntryIsDir(TdDirEntryPtr pDirEntry); char *taosGetDirEntryName(TdDirEntryPtr pDirEntry); int32_t taosCloseDir(TdDirPtr *ppDir); -int taosGetDirSize(const char *path, int64_t *size); +int32_t taosAppPath(char *path, int32_t maxLen); +int32_t taosGetDirSize(const char *path, int64_t *size); + #ifdef __cplusplus } #endif diff --git a/include/os/osSystem.h b/include/os/osSystem.h index 06f23eec0fba..694bbf408591 100644 --- a/include/os/osSystem.h +++ b/include/os/osSystem.h @@ -46,10 +46,12 @@ int32_t taosEOFCmd(TdCmdPtr pCmd); void taosCloseCmd(TdCmdPtr *ppCmd); -void *taosLoadDll(const char *filename); +void *taosLoadDll(const char *fileName); void taosCloseDll(void *handle); +void *taosLoadDllFunc(void *handle, const char *funcName); + int32_t taosSetConsoleEcho(bool on); int32_t taosSetTerminalMode(); diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 29e95251e999..e934b722a703 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -112,6 +112,8 @@ int32_t taosGetErrSize(); #define TSDB_CODE_REF_INVALID_ID TAOS_DEF_ERROR_CODE(0, 0x0108) // internal #define TSDB_CODE_REF_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0109) // internal #define TSDB_CODE_REF_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x010A) // internal +#define TSDB_CODE_DLL_NOT_LOAD TAOS_DEF_ERROR_CODE(0, 0x010B) +#define TSDB_CODE_DLL_FUNC_NOT_LOAD TAOS_DEF_ERROR_CODE(0, 0x010C) #define TSDB_CODE_APP_ERROR TAOS_DEF_ERROR_CODE(0, 0x0110) // #define TSDB_CODE_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0111) // internal diff --git a/include/util/tlog.h b/include/util/tlog.h index 07b11bb16e20..021e224770bb 100644 --- a/include/util/tlog.h +++ b/include/util/tlog.h @@ -118,7 +118,7 @@ bool taosAssertRelease(bool condition); #endif #endif -void taosLogCrashInfo(char *nodeType, char *pMsg, int64_t msgLen, int signum, void *sigInfo); +void taosLogCrashInfo(const char *nodeType, char *pMsg, int64_t msgLen, int signum, void *sigInfo); void taosReadCrashInfo(char *filepath, char **pMsg, int64_t *pMsgLen, TdFilePtr *pFd); void taosReleaseCrashLogFile(TdFilePtr pFile, bool truncateFile); diff --git a/packaging/check_package.sh b/packaging/check_package.sh index 5c3a2f926731..2179b64f3b93 100644 --- a/packaging/check_package.sh +++ b/packaging/check_package.sh @@ -152,10 +152,14 @@ function check_lib_path() { # check all links check_link ${lib_link_dir}/libtaos.so check_link ${lib_link_dir}/libtaos.so.1 + check_link ${lib_link_dir}/libtaosnative.so + check_link ${lib_link_dir}/libtaosnative.so.1 if [[ -d ${lib64_link_dir} ]]; then check_link ${lib64_link_dir}/libtaos.so check_link ${lib64_link_dir}/libtaos.so.1 + check_link ${lib64_link_dir}/libtaosnative.so + check_link ${lib64_link_dir}/libtaosnative.so.1 fi echo -e "Check lib path:\033[32mOK\033[0m!" } diff --git a/packaging/deb/DEBIAN/preinst b/packaging/deb/DEBIAN/preinst index 904a946e2092..b223dbf3d81e 100644 --- a/packaging/deb/DEBIAN/preinst +++ b/packaging/deb/DEBIAN/preinst @@ -80,4 +80,5 @@ fi # there can not libtaos.so*, otherwise ln -s error ${csudo}rm -f ${install_main_dir}/driver/libtaos.* || : +${csudo}rm -f ${install_main_dir}/driver/libtaosnative.* || : [ -f ${install_main_dir}/driver/libtaosws.so ] && ${csudo}rm -f ${install_main_dir}/driver/libtaosws.so || : diff --git a/packaging/deb/DEBIAN/prerm b/packaging/deb/DEBIAN/prerm index 31561c568228..9f52fe730c86 100644 --- a/packaging/deb/DEBIAN/prerm +++ b/packaging/deb/DEBIAN/prerm @@ -44,6 +44,8 @@ else ${csudo}rm -f ${inc_link_dir}/taosws.h || : ${csudo}rm -f ${lib_link_dir}/libtaos.* || : ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib_link_dir}/libtaosnative.* || : + ${csudo}rm -f ${lib64_link_dir}/libtaosnative.* || : ${csudo}rm -f ${lib_link_dir}/libtaosws.so || : ${csudo}rm -f ${lib64_link_dir}/libtaosws.so || : diff --git a/packaging/deb/makedeb.sh b/packaging/deb/makedeb.sh index 93f523a13fb9..145199e87fc5 100755 --- a/packaging/deb/makedeb.sh +++ b/packaging/deb/makedeb.sh @@ -31,6 +31,7 @@ mkdir -p ${pkg_dir} cd ${pkg_dir} libfile="libtaos.so.${tdengine_ver}" +nativelibfile="libtaosnative.so.${tdengine_ver}" wslibfile="libtaosws.so" # create install dir @@ -120,11 +121,12 @@ fi cp ${compile_dir}/build/bin/taos ${pkg_dir}${install_home_path}/bin cp ${compile_dir}/build/lib/${libfile} ${pkg_dir}${install_home_path}/driver +cp ${compile_dir}/build/lib/${nativelibfile} ${pkg_dir}${install_home_path}/driver [ -f ${compile_dir}/build/lib/${wslibfile} ] && cp ${compile_dir}/build/lib/${wslibfile} ${pkg_dir}${install_home_path}/driver ||: cp ${compile_dir}/../include/client/taos.h ${pkg_dir}${install_home_path}/include cp ${compile_dir}/../include/common/taosdef.h ${pkg_dir}${install_home_path}/include cp ${compile_dir}/../include/util/taoserror.h ${pkg_dir}${install_home_path}/include -cp ${compile_dir}/../include/util/tdef.h ${pkg_dir}${install_home_path}/include +cp ${compile_dir}/../include/util/tdef.h ${pkg_dir}${install_home_path}/include cp ${compile_dir}/../include/libs/function/taosudf.h ${pkg_dir}${install_home_path}/include [ -f ${compile_dir}/build/include/taosws.h ] && cp ${compile_dir}/build/include/taosws.h ${pkg_dir}${install_home_path}/include ||: cp -r ${top_dir}/examples/* ${pkg_dir}${install_home_path}/examples diff --git a/packaging/rpm/tdengine.spec b/packaging/rpm/tdengine.spec index bfa91b6af79e..097ba39a3a4c 100644 --- a/packaging/rpm/tdengine.spec +++ b/packaging/rpm/tdengine.spec @@ -44,6 +44,7 @@ echo version: %{_version} echo buildroot: %{buildroot} libfile="libtaos.so.%{_version}" +nativelibfile="libtaosnative.so.%{_version}" wslibfile="libtaosws.so" # create install path, and cp file @@ -112,11 +113,12 @@ if [ -f %{_compiledir}/build/bin/taosadapter ]; then cp %{_compiledir}/build/bin/taosadapter %{buildroot}%{homepath}/bin fi cp %{_compiledir}/build/lib/${libfile} %{buildroot}%{homepath}/driver +cp %{_compiledir}/build/lib/${nativelibfile} %{buildroot}%{homepath}/driver [ -f %{_compiledir}/build/lib/${wslibfile} ] && cp %{_compiledir}/build/lib/${wslibfile} %{buildroot}%{homepath}/driver ||: cp %{_compiledir}/../include/client/taos.h %{buildroot}%{homepath}/include cp %{_compiledir}/../include/common/taosdef.h %{buildroot}%{homepath}/include cp %{_compiledir}/../include/util/taoserror.h %{buildroot}%{homepath}/include -cp %{_compiledir}/../include/util/tdef.h %{buildroot}%{homepath}/include +cp %{_compiledir}/../include/util/tdef.h %{buildroot}%{homepath}/include cp %{_compiledir}/../include/libs/function/taosudf.h %{buildroot}%{homepath}/include [ -f %{_compiledir}/build/include/taosws.h ] && cp %{_compiledir}/build/include/taosws.h %{buildroot}%{homepath}/include ||: #cp -r %{_compiledir}/../src/connector/python %{buildroot}%{homepath}/connector @@ -246,6 +248,8 @@ if [ $1 -eq 0 ];then ${csudo}rm -f ${inc_link_dir}/taosudf.h || : ${csudo}rm -f ${inc_link_dir}/taows.h || : ${csudo}rm -f ${lib_link_dir}/libtaos.so || : + ${csudo}rm -f ${lib_link_dir}/libtaosnative.so || : + ${csudo}rm -f ${lib64_link_dir}/libtaosnative.so || : ${csudo}rm -f ${lib_link_dir}/libtaosws.so || : ${csudo}rm -f ${lib64_link_dir}/libtaosws.so || : diff --git a/packaging/tools/install.sh b/packaging/tools/install.sh index a6fd69d16fb2..970582c2d919 100755 --- a/packaging/tools/install.sh +++ b/packaging/tools/install.sh @@ -268,17 +268,23 @@ function install_lib() { # Remove links ${csudo}rm -f ${lib_link_dir}/libtaos.* || : ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib_link_dir}/libtaosnative.* || : + ${csudo}rm -f ${lib64_link_dir}/libtaosnative.* || : #${csudo}rm -rf ${v15_java_app_dir} || : ${csudo}cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo}chmod 777 ${install_main_dir}/driver/* ${csudo}ln -sf ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 ${csudo}ln -sf ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so + ${csudo}ln -sf ${install_main_dir}/driver/libtaosnative.* ${lib_link_dir}/libtaosnative.so.1 + ${csudo}ln -sf ${lib_link_dir}/libtaosnative.so.1 ${lib_link_dir}/libtaosnative.so [ -f ${install_main_dir}/driver/libtaosws.so ] && ${csudo}ln -sf ${install_main_dir}/driver/libtaosws.so ${lib_link_dir}/libtaosws.so || : if [[ -d ${lib64_link_dir} && ! -e ${lib64_link_dir}/libtaos.so ]]; then ${csudo}ln -sf ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : ${csudo}ln -sf ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : + ${csudo}ln -sf ${install_main_dir}/driver/libtaosnative.* ${lib64_link_dir}/libtaosnative.so.1 || : + ${csudo}ln -sf ${lib64_link_dir}/libtaosnative.so.1 ${lib64_link_dir}/libtaosnative.so || : [ -f ${install_main_dir}/libtaosws.so ] && ${csudo}ln -sf ${install_main_dir}/libtaosws.so ${lib64_link_dir}/libtaosws.so || : fi diff --git a/packaging/tools/install_client.sh b/packaging/tools/install_client.sh index 9ba952914624..3fe654f094a1 100755 --- a/packaging/tools/install_client.sh +++ b/packaging/tools/install_client.sh @@ -128,6 +128,7 @@ function install_bin() { function clean_lib() { sudo rm -f /usr/lib/libtaos.* || : + sudo rm -f /usr/lib/libtaosnative.* || : [ -f /usr/lib/libtaosws.so ] && sudo rm -f /usr/lib/libtaosws.so || : [ -f /usr/lib64/libtaosws.so ] && sudo rm -f /usr/lib64/libtaosws.so || : sudo rm -rf ${lib_dir} || : @@ -137,6 +138,8 @@ function install_lib() { # Remove links ${csudo}rm -f ${lib_link_dir}/libtaos.* || : ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib_link_dir}/libtaosnative.* || : + ${csudo}rm -f ${lib64_link_dir}/libtaosnative.* || : [ -f ${lib_link_dir}/libtaosws.so ] && ${csudo}rm -f ${lib_link_dir}/libtaosws.so || : [ -f ${lib64_link_dir}/libtaosws.so ] && ${csudo}rm -f ${lib64_link_dir}/libtaosws.so || : @@ -148,18 +151,24 @@ function install_lib() { if [ "$osType" != "Darwin" ]; then ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 ${csudo}ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so + ${csudo}ln -s ${install_main_dir}/driver/libtaosnative.* ${lib_link_dir}/libtaosnative.so.1 + ${csudo}ln -s ${lib_link_dir}/libtaosnative.so.1 ${lib_link_dir}/libtaosnative.so [ -f ${install_main_dir}/driver/libtaosws.so ] && ${csudo}ln -sf ${install_main_dir}/driver/libtaosws.so ${lib_link_dir}/libtaosws.so ||: if [ -d "${lib64_link_dir}" ]; then ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 || : ${csudo}ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || : + ${csudo}ln -s ${install_main_dir}/driver/libtaosnative.* ${lib64_link_dir}/libtaosnative.so.1 || : + ${csudo}ln -s ${lib64_link_dir}/libtaosnative.so.1 ${lib64_link_dir}/libtaosnative.so || : [ -f ${install_main_dir}/driver/libtaosws.so ] && ${csudo}ln -sf ${install_main_dir}/driver/libtaosws.so ${lib64_link_dir}/libtaosws.so || : fi else ${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.1.dylib ${csudo}ln -s ${lib_link_dir}/libtaos.1.dylib ${lib_link_dir}/libtaos.dylib + ${csudo}ln -s ${install_main_dir}/driver/libtaosnative.* ${lib_link_dir}/libtaosnative.1.dylib + ${csudo}ln -s ${lib_link_dir}/libtaosnative.1.dylib ${lib_link_dir}/libtaosnative.dylib [ -f ${install_main_dir}/driver/libtaosws.dylib ] && ${csudo}ln -sf ${install_main_dir}/driver/libtaosws.dylib ${lib_link_dir}/libtaosws.dylib ||: fi @@ -172,7 +181,7 @@ function install_lib() { } function install_header() { - ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/tdef.h ${inc_link_dir}/taoserror.h ${inc_link_dir}/taosudf.h || : + ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosws.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/tdef.h ${inc_link_dir}/taoserror.h ${inc_link_dir}/taosudf.h || : ${csudo}cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/* ${csudo}ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h ${csudo}ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h diff --git a/packaging/tools/make_install.bat b/packaging/tools/make_install.bat index 04d342ea06f5..976354ad6158 100644 --- a/packaging/tools/make_install.bat +++ b/packaging/tools/make_install.bat @@ -66,6 +66,9 @@ copy %source_dir%\\include\\libs\\function\\taosudf.h %target_dir%\\include > nu copy %binary_dir%\\build\\lib\\taos.lib %target_dir%\\driver > nul copy %binary_dir%\\build\\lib\\taos_static.lib %target_dir%\\driver > nul copy %binary_dir%\\build\\lib\\taos.dll %target_dir%\\driver > nul +copy %binary_dir%\\build\\lib\\taosnative.lib %target_dir%\\driver > nul +copy %binary_dir%\\build\\lib\\taosnative_static.lib %target_dir%\\driver > nul +copy %binary_dir%\\build\\lib\\taosnative.dll %target_dir%\\driver > nul copy %binary_dir%\\build\\bin\\taos.exe %target_dir% > nul if exist %binary_dir%\\build\\bin\\taosBenchmark.exe ( copy %binary_dir%\\build\\bin\\taosBenchmark.exe %target_dir% > nul @@ -149,12 +152,14 @@ call :check_svc taoskeeper if exist c:\\windows\\sysnative ( echo x86 copy /y C:\\TDengine\\driver\\taos.dll %windir%\\sysnative > nul + copy /y C:\\TDengine\\driver\\taosnative.dll %windir%\\sysnative > nul if exist C:\\TDengine\\driver\\taosws.dll ( copy /y C:\\TDengine\\driver\\taosws.dll %windir%\\sysnative > nul ) ) else ( echo x64 copy /y C:\\TDengine\\driver\\taos.dll C:\\Windows\\System32 > nul + copy /y C:\\TDengine\\driver\\taosnative.dll C:\\Windows\\System32 > nul if exist C:\\TDengine\\driver\\taosws.dll ( copy /y C:\\TDengine\\driver\\taosws.dll C:\\Windows\\System32 > nul ) diff --git a/packaging/tools/make_install.sh b/packaging/tools/make_install.sh index bb61392f8006..889f22473b07 100755 --- a/packaging/tools/make_install.sh +++ b/packaging/tools/make_install.sh @@ -313,9 +313,11 @@ function install_avro() { function install_lib() { # Remove links ${csudo}rm -f ${lib_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib_link_dir}/libtaosnative.* || : [ -f ${lib_link_dir}/libtaosws.so ] && ${csudo}rm -f ${lib_link_dir}/libtaosws.so || : if [ "$osType" != "Darwin" ]; then ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : + ${csudo}rm -f ${lib64_link_dir}/libtaosnative.* || : [ -f ${lib64_link_dir}/libtaosws.so ] && ${csudo}rm -f ${lib64_link_dir}/libtaosws.so || : fi @@ -324,6 +326,10 @@ function install_lib() { ${install_main_dir}/driver && ${csudo}chmod 777 ${install_main_dir}/driver/libtaos.so.${verNumber} + ${csudo}cp ${binary_dir}/build/lib/libtaosnative.so.${verNumber} \ + ${install_main_dir}/driver && + ${csudo}chmod 777 ${install_main_dir}/driver/libtaosnative.so.${verNumber} + ${csudo}ln -sf ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 > /dev/null 2>&1 ${csudo}ln -sf ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so > /dev/null 2>&1 if [ -d "${lib64_link_dir}" ]; then @@ -331,6 +337,13 @@ function install_lib() { ${csudo}ln -sf ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so > /dev/null 2>&1 fi + ${csudo}ln -sf ${install_main_dir}/driver/libtaosnative.* ${lib_link_dir}/libtaosnative.so.1 > /dev/null 2>&1 + ${csudo}ln -sf ${lib_link_dir}/libtaosnative.so.1 ${lib_link_dir}/libtaosnative.so > /dev/null 2>&1 + if [ -d "${lib64_link_dir}" ]; then + ${csudo}ln -sf ${install_main_dir}/driver/libtaosnative.* ${lib64_link_dir}/libtaosnative.so.1 > /dev/null 2>&1 + ${csudo}ln -sf ${lib64_link_dir}/libtaosnative.so.1 ${lib64_link_dir}/libtaosnative.so > /dev/null 2>&1 + fi + if [ -f ${binary_dir}/build/lib/libtaosws.so ]; then ${csudo}cp ${binary_dir}/build/lib/libtaosws.so \ ${install_main_dir}/driver && @@ -342,11 +355,19 @@ function install_lib() { ${csudo}cp -Rf ${binary_dir}/build/lib/libtaos.${verNumber}.dylib \ ${install_main_dir}/driver && ${csudo}chmod 777 ${install_main_dir}/driver/* + ${csudo}cp -Rf ${binary_dir}/build/lib/libtaosnative.${verNumber}.dylib \ + ${install_main_dir}/driver && ${csudo}chmod 777 ${install_main_dir}/driver/* + ${csudo}ln -sf ${install_main_dir}/driver/libtaos.${verNumber}.dylib \ ${lib_link_dir}/libtaos.1.dylib > /dev/null 2>&1 || : + ${csudo}ln -sf ${install_main_dir}/driver/libtaosnative.${verNumber}.dylib \ + ${lib_link_dir}/libtaosnative.1.dylib > /dev/null 2>&1 || : + ${csudo}ln -sf ${lib_link_dir}/libtaos.1.dylib ${lib_link_dir}/libtaos.dylib > /dev/null 2>&1 || : + ${csudo}ln -sf ${lib_link_dir}/libtaosnative.1.dylib ${lib_link_dir}/libtaosnative.dylib > /dev/null 2>&1 || : + if [ -f ${binary_dir}/build/lib/libtaosws.dylib ]; then ${csudo}cp ${binary_dir}/build/lib/libtaosws.dylib \ ${install_main_dir}/driver && diff --git a/packaging/tools/makeclient.sh b/packaging/tools/makeclient.sh index 87f4f57fd3c1..2c2f6205b505 100755 --- a/packaging/tools/makeclient.sh +++ b/packaging/tools/makeclient.sh @@ -79,10 +79,12 @@ if [ "$osType" != "Darwin" ]; then ${script_dir}/get_client.sh" fi lib_files="${build_dir}/lib/libtaos.so.${version}" + nativelib_files="${build_dir}/lib/libtaosnative.so.${version}" wslib_files="${build_dir}/lib/libtaosws.so" else bin_files="${build_dir}/bin/${clientName} ${script_dir}/remove_client.sh" lib_files="${build_dir}/lib/libtaos.${version}.dylib" + nativelib_files="${build_dir}/lib/libtaosnative.${version}.dylib" wslib_files="${build_dir}/lib/libtaosws.dylib" fi @@ -224,6 +226,7 @@ fi # Copy driver mkdir -p ${install_dir}/driver cp ${lib_files} ${install_dir}/driver +cp ${nativelib_files} ${install_dir}/driver # Copy connector connector_dir="${code_dir}/connector" diff --git a/packaging/tools/makepkg.sh b/packaging/tools/makepkg.sh index fb461835b474..cdc8e9b2db75 100755 --- a/packaging/tools/makepkg.sh +++ b/packaging/tools/makepkg.sh @@ -108,9 +108,11 @@ fi if [ "$osType" == "Darwin" ]; then lib_files="${build_dir}/lib/libtaos.${version}.dylib" + nativelib_files="${build_dir}/lib/libtaosnative.${version}.dylib" wslib_files="${build_dir}/lib/libtaosws.dylib" else lib_files="${build_dir}/lib/libtaos.so.${version}" + nativelib_files="${build_dir}/lib/libtaosnative.so.${version}" wslib_files="${build_dir}/lib/libtaosws.so" fi header_files="${code_dir}/include/client/taos.h ${code_dir}/include/common/taosdef.h ${code_dir}/include/util/taoserror.h ${code_dir}/include/util/tdef.h ${code_dir}/include/libs/function/taosudf.h" @@ -332,7 +334,7 @@ if [[ $dbName == "taos" ]]; then fi # Copy driver -mkdir -p ${install_dir}/driver && cp ${lib_files} ${install_dir}/driver && echo "${versionComp}" >${install_dir}/driver/vercomp.txt +mkdir -p ${install_dir}/driver && cp ${lib_files} ${install_dir}/driver && cp ${nativelib_files} ${install_dir}/driver && echo "${versionComp}" >${install_dir}/driver/vercomp.txt [ -f ${wslib_files} ] && cp ${wslib_files} ${install_dir}/driver || : # Copy connector && taosx diff --git a/packaging/tools/post.sh b/packaging/tools/post.sh index 6b4c96e8c44b..09b60cb4493a 100755 --- a/packaging/tools/post.sh +++ b/packaging/tools/post.sh @@ -205,18 +205,24 @@ function install_lib() { log_print "start install lib from ${lib_dir} to ${lib_link_dir}" ${csudo}rm -f ${lib_link_dir}/libtaos* || : ${csudo}rm -f ${lib64_link_dir}/libtaos* || : + ${csudo}rm -f ${lib_link_dir}/libtaosnative* || : + ${csudo}rm -f ${lib64_link_dir}/libtaosnative* || : [ -f ${lib_link_dir}/libtaosws.${lib_file_ext} ] && ${csudo}rm -f ${lib_link_dir}/libtaosws.${lib_file_ext} || : [ -f ${lib64_link_dir}/libtaosws.${lib_file_ext} ] && ${csudo}rm -f ${lib64_link_dir}/libtaosws.${lib_file_ext} || : ${csudo}ln -s ${lib_dir}/libtaos.* ${lib_link_dir}/libtaos.${lib_file_ext_1} 2>>${install_log_path} || return 1 ${csudo}ln -s ${lib_link_dir}/libtaos.${lib_file_ext_1} ${lib_link_dir}/libtaos.${lib_file_ext} 2>>${install_log_path} || return 1 + ${csudo}ln -s ${lib_dir}/libtaosnative.* ${lib_link_dir}/libtaosnative.${lib_file_ext_1} 2>>${install_log_path} || return 1 + ${csudo}ln -s ${lib_link_dir}/libtaosnative.${lib_file_ext_1} ${lib_link_dir}/libtaosnative.${lib_file_ext} 2>>${install_log_path} || return 1 [ -f ${lib_dir}/libtaosws.${lib_file_ext} ] && ${csudo}ln -sf ${lib_dir}/libtaosws.${lib_file_ext} ${lib_link_dir}/libtaosws.${lib_file_ext} ||: if [[ -d ${lib64_link_dir} && ! -e ${lib64_link_dir}/libtaos.${lib_file_ext} ]]; then ${csudo}ln -s ${lib_dir}/libtaos.* ${lib64_link_dir}/libtaos.${lib_file_ext_1} 2>>${install_log_path} || return 1 ${csudo}ln -s ${lib64_link_dir}/libtaos.${lib_file_ext_1} ${lib64_link_dir}/libtaos.${lib_file_ext} 2>>${install_log_path} || return 1 + ${csudo}ln -s ${lib_dir}/libtaosnative.* ${lib64_link_dir}/libtaosnative.${lib_file_ext_1} 2>>${install_log_path} || return 1 + ${csudo}ln -s ${lib64_link_dir}/libtaosnative.${lib_file_ext_1} ${lib64_link_dir}/libtaosnative.${lib_file_ext} 2>>${install_log_path} || return 1 [ -f ${lib_dir}/libtaosws.${lib_file_ext} ] && ${csudo}ln -sf ${lib_dir}/libtaosws.${lib_file_ext} ${lib64_link_dir}/libtaosws.${lib_file_ext} 2>>${install_log_path} fi diff --git a/packaging/tools/preun.sh b/packaging/tools/preun.sh index d975841e8382..757db8ee62c6 100755 --- a/packaging/tools/preun.sh +++ b/packaging/tools/preun.sh @@ -167,8 +167,10 @@ ${csudo}rm -f ${inc_link_dir}/tdef.h || : ${csudo}rm -f ${inc_link_dir}/taosudf.h || : ${csudo}rm -f ${inc_link_dir}/taosws.h || : ${csudo}rm -f ${lib_link_dir}/libtaos.* || : +${csudo}rm -f ${lib_link_dir}/libtaosnative.* || : ${csudo}rm -f ${lib_link_dir}/libtaosws.so || : ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : +${csudo}rm -f ${lib64_link_dir}/libtaosnative.* || : ${csudo}rm -f ${lib64_link_dir}/libtaosws.so || : ${csudo}rm -f ${log_link_dir} || : diff --git a/packaging/tools/remove.sh b/packaging/tools/remove.sh index 43c2de4ba495..0d9aab0f9922 100755 --- a/packaging/tools/remove.sh +++ b/packaging/tools/remove.sh @@ -176,9 +176,11 @@ remove_bin() { function clean_lib() { # Remove link ${csudo}rm -f ${lib_link_dir}/libtaos.* || : + [ -f ${lib_link_dir}/libtaosnative.* ] && ${csudo}rm -f ${lib_link_dir}/libtaosnative.* || : [ -f ${lib_link_dir}/libtaosws.* ] && ${csudo}rm -f ${lib_link_dir}/libtaosws.* || : ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : + [ -f ${lib64_link_dir}/libtaosnative.* ] && ${csudo}rm -f ${lib64_link_dir}/libtaosnative.* || : [ -f ${lib64_link_dir}/libtaosws.* ] && ${csudo}rm -f ${lib64_link_dir}/libtaosws.* || : #${csudo}rm -rf ${v15_java_app_dir} || : } diff --git a/packaging/tools/remove_client.sh b/packaging/tools/remove_client.sh index 1d2965f66bf2..f625d674a474 100755 --- a/packaging/tools/remove_client.sh +++ b/packaging/tools/remove_client.sh @@ -68,9 +68,11 @@ function clean_lib() { # Remove link ${csudo}rm -f ${lib_link_dir}/libtaos.* || : [ -f ${lib_link_dir}/libtaosws.* ] && ${csudo}rm -f ${lib_link_dir}/libtaosws.* || : + [ -f ${lib_link_dir}/libtaosnative.* ] && ${csudo}rm -f ${lib_link_dir}/libtaosnative.* || : ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : [ -f ${lib64_link_dir}/libtaosws.* ] && ${csudo}rm -f ${lib64_link_dir}/libtaosws.* || : + [ -f ${lib64_link_dir}/libtaosnative.* ] && ${csudo}rm -f ${lib64_link_dir}/libtaosnative.* || : #${csudo}rm -rf ${v15_java_app_dir} || : } diff --git a/source/client/CMakeLists.txt b/source/client/CMakeLists.txt index 2113aa7921f8..5008c7f94761 100644 --- a/source/client/CMakeLists.txt +++ b/source/client/CMakeLists.txt @@ -5,24 +5,24 @@ if(TD_ENTERPRISE) endif() if(TD_WINDOWS) - add_library(${TAOS_LIB} SHARED ${CLIENT_SRC} ${CMAKE_CURRENT_SOURCE_DIR}/src/taos.rc.in) + add_library(${TAOS_NATIVE_LIB} SHARED ${CLIENT_SRC} ${CMAKE_CURRENT_SOURCE_DIR}/src/taosnative.rc.in) else() - add_library(${TAOS_LIB} SHARED ${CLIENT_SRC}) + add_library(${TAOS_NATIVE_LIB} SHARED ${CLIENT_SRC}) endif() if(${TD_DARWIN}) - target_compile_options(${TAOS_LIB} PRIVATE -Wno-error=deprecated-non-prototype) + target_compile_options(${TAOS_NATIVE_LIB} PRIVATE -Wno-error=deprecated-non-prototype) endif() INCLUDE_DIRECTORIES(jni) target_include_directories( - ${TAOS_LIB} + ${TAOS_NATIVE_LIB} PUBLIC "${TD_SOURCE_DIR}/include/client" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) target_link_libraries( - ${TAOS_LIB} + ${TAOS_NATIVE_LIB} INTERFACE api PRIVATE os util common transport monitor nodes parser command planner catalog scheduler function qcom geometry ) @@ -36,32 +36,32 @@ else() endif() set_target_properties( - ${TAOS_LIB} + ${TAOS_NATIVE_LIB} PROPERTIES CLEAN_DIRECT_OUTPUT 1 ) set_target_properties( - ${TAOS_LIB} + ${TAOS_NATIVE_LIB} PROPERTIES VERSION ${TD_VER_NUMBER} SOVERSION 1 ) -add_library(${TAOS_LIB_STATIC} STATIC ${CLIENT_SRC}) +add_library(${TAOS_NATIVE_LIB_STATIC} STATIC ${CLIENT_SRC}) if(${TD_DARWIN}) - target_compile_options(${TAOS_LIB_STATIC} PRIVATE -Wno-error=deprecated-non-prototype) + target_compile_options(${TAOS_NATIVE_LIB_STATIC} PRIVATE -Wno-error=deprecated-non-prototype) endif() target_include_directories( - ${TAOS_LIB_STATIC} + ${TAOS_NATIVE_LIB_STATIC} PUBLIC "${TD_SOURCE_DIR}/include/client" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) target_link_libraries( - ${TAOS_LIB_STATIC} + ${TAOS_NATIVE_LIB_STATIC} INTERFACE api PRIVATE os util common transport monitor nodes parser command planner catalog scheduler function qcom geometry ) @@ -69,3 +69,5 @@ target_link_libraries( if(${BUILD_TEST}) ADD_SUBDIRECTORY(test) endif(${BUILD_TEST}) + +ADD_SUBDIRECTORY(wrapper) diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 266bd4a61854..be0f770f5884 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -918,7 +918,7 @@ void tscStopCrashReport() { } } -void tscWriteCrashInfo(int signum, void *sigInfo, void *context) { +void taos_write_crashinfo(int signum, void *sigInfo, void *context) { writeCrashLogToFile(signum, sigInfo, CUS_PROMPT, lastClusterId, appInfo.startTime); } diff --git a/source/client/src/taos.rc.in b/source/client/src/taos.rc.in index 84a2a7a5b5d8..c062a32304e5 100644 --- a/source/client/src/taos.rc.in +++ b/source/client/src/taos.rc.in @@ -15,10 +15,10 @@ BEGIN BEGIN BLOCK "040904b0" BEGIN - VALUE "FileDescription", "Native C Driver for TDengine" + VALUE "FileDescription", "C Driver for TDengine" VALUE "FileVersion", "${TD_VER_NUMBER}" VALUE "InternalName", "taos.dll(${TD_VER_CPUTYPE})" - VALUE "LegalCopyright", "Copyright (C) 2020 TAOS Data" + VALUE "LegalCopyright", "Copyright (C) 2025 TAOS Data" VALUE "OriginalFilename", "" VALUE "ProductName", "taos.dll(${TD_VER_CPUTYPE})" VALUE "ProductVersion", "${TD_VER_NUMBER}" diff --git a/source/client/src/taosnative.rc.in b/source/client/src/taosnative.rc.in new file mode 100644 index 000000000000..1cd080b492fc --- /dev/null +++ b/source/client/src/taosnative.rc.in @@ -0,0 +1,31 @@ +1 VERSIONINFO + FILEVERSION ${TD_VER_NUMBER} + PRODUCTVERSION ${TD_VER_NUMBER} + FILEFLAGSMASK 0x17L +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x0L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "FileDescription", "Internal C Driver for TDengine" + VALUE "FileVersion", "${TD_VER_NUMBER}" + VALUE "InternalName", "taosnative.dll(${TD_VER_CPUTYPE})" + VALUE "LegalCopyright", "Copyright (C) 2025 TAOS Data" + VALUE "OriginalFilename", "" + VALUE "ProductName", "taosnative.dll(${TD_VER_CPUTYPE})" + VALUE "ProductVersion", "${TD_VER_NUMBER}" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END \ No newline at end of file diff --git a/source/client/test/CMakeLists.txt b/source/client/test/CMakeLists.txt index 9e1a04879ef5..cee5dc08f936 100644 --- a/source/client/test/CMakeLists.txt +++ b/source/client/test/CMakeLists.txt @@ -8,49 +8,49 @@ AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) ADD_EXECUTABLE(clientTest clientTests.cpp) TARGET_LINK_LIBRARIES( clientTest - os util common transport parser catalog scheduler gtest ${TAOS_LIB_STATIC} qcom executor function + os util common transport parser catalog scheduler gtest ${TAOS_NATIVE_LIB_STATIC} qcom executor function ) ADD_EXECUTABLE(connectOptionsTest connectOptionsTest.cpp) TARGET_LINK_LIBRARIES( connectOptionsTest - os util common transport parser catalog scheduler gtest ${TAOS_LIB_STATIC} qcom executor function + os util common transport parser catalog scheduler gtest ${TAOS_NATIVE_LIB_STATIC} qcom executor function ) ADD_EXECUTABLE(tmqTest tmqTest.cpp) TARGET_LINK_LIBRARIES( tmqTest - PUBLIC os util common transport parser catalog scheduler function gtest ${TAOS_LIB_STATIC} qcom + PUBLIC os util common transport parser catalog scheduler function gtest ${TAOS_NATIVE_LIB_STATIC} qcom ) ADD_EXECUTABLE(smlTest smlTest.cpp) TARGET_LINK_LIBRARIES( smlTest - PUBLIC os util common transport parser catalog scheduler function gtest ${TAOS_LIB_STATIC} qcom geometry + PUBLIC os util common transport parser catalog scheduler function gtest ${TAOS_NATIVE_LIB_STATIC} qcom geometry ) #ADD_EXECUTABLE(clientMonitorTest clientMonitorTests.cpp) #TARGET_LINK_LIBRARIES( # clientMonitorTest -# PUBLIC os util common transport monitor parser catalog scheduler function gtest ${TAOS_LIB_STATIC} qcom executor +# PUBLIC os util common transport monitor parser catalog scheduler function gtest ${TAOS_NATIVE_LIB_STATIC} qcom executor #) ADD_EXECUTABLE(userOperTest ../../../tests/script/api/passwdTest.c) TARGET_LINK_LIBRARIES( userOperTest - PUBLIC ${TAOS_LIB} + PUBLIC ${TAOS_NATIVE_LIB} ) ADD_EXECUTABLE(stmt2Test stmt2Test.cpp) TARGET_LINK_LIBRARIES( stmt2Test - os util common transport parser catalog scheduler gtest ${TAOS_LIB_STATIC} qcom executor function + os util common transport parser catalog scheduler gtest ${TAOS_NATIVE_LIB_STATIC} qcom executor function ) ADD_EXECUTABLE(stmtTest stmtTest.cpp) TARGET_LINK_LIBRARIES( stmtTest - os util common transport parser catalog scheduler gtest ${TAOS_LIB_STATIC} qcom executor function + os util common transport parser catalog scheduler gtest ${TAOS_NATIVE_LIB_STATIC} qcom executor function ) TARGET_INCLUDE_DIRECTORIES( diff --git a/source/client/wrapper/CMakeLists.txt b/source/client/wrapper/CMakeLists.txt new file mode 100644 index 000000000000..a92cace21aae --- /dev/null +++ b/source/client/wrapper/CMakeLists.txt @@ -0,0 +1,57 @@ +aux_source_directory(src WRAPPER_SRC) + +if(TD_WINDOWS) + add_library(${TAOS_LIB} SHARED ${WRAPPER_SRC} ${CMAKE_CURRENT_SOURCE_DIR}/../src/taos.rc.in) +else() + add_library(${TAOS_LIB} SHARED ${WRAPPER_SRC}) +endif() + +if(${TD_DARWIN}) + target_compile_options(${TAOS_LIB} PRIVATE -Wno-error=deprecated-non-prototype) +endif() + +target_include_directories( + ${TAOS_LIB} + PUBLIC "${TD_SOURCE_DIR}/include/client" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) + +target_link_libraries( + ${TAOS_LIB} + PUBLIC os util +) + +set_target_properties( + ${TAOS_LIB} + PROPERTIES + CLEAN_DIRECT_OUTPUT + 1 +) + +set_target_properties( + ${TAOS_LIB} + PROPERTIES + VERSION ${TD_VER_NUMBER} + SOVERSION 1 +) + +add_library(${TAOS_LIB_STATIC} STATIC ${WRAPPER_SRC}) + +if(${TD_DARWIN}) + target_compile_options(${TAOS_LIB_STATIC} PRIVATE -Wno-error=deprecated-non-prototype) +endif() + +target_include_directories( + ${TAOS_LIB_STATIC} + PUBLIC "${TD_SOURCE_DIR}/include/client" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) + +target_link_libraries( + ${TAOS_LIB_STATIC} + PUBLIC os util +) + +# if(${BUILD_TEST}) +# ADD_SUBDIRECTORY(test) +# endif(${BUILD_TEST}) diff --git a/source/client/wrapper/inc/wrapper.h b/source/client/wrapper/inc/wrapper.h new file mode 100644 index 000000000000..3505e297fca1 --- /dev/null +++ b/source/client/wrapper/inc/wrapper.h @@ -0,0 +1,231 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_WRAPPER_H +#define TDENGINE_WRAPPER_H + +#include "os.h" +#include "taos.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + DRIVER_NATIVE = 0, + DRIVER_WEBSOCKET = 1, + DRIVER_MAX = 2, +} EDriverType; + +extern EDriverType tsDriverType; +extern void *tsDriver; + +extern int32_t taosDriverInit(EDriverType driverType); +extern void taosDriverCleanup(); + +extern setConfRet (*fp_taos_set_config)(const char *config); + +extern int (*fp_taos_init)(void); +extern void (*fp_taos_cleanup)(void); +extern int (*fp_taos_options)(TSDB_OPTION option, const void *arg, ...); +extern int (*fp_taos_options_connection)(TAOS *taos, TSDB_OPTION_CONNECTION option, const void *arg, ...); +extern TAOS *(*fp_taos_connect)(const char *ip, const char *user, const char *pass, const char *db, uint16_t port); +extern TAOS *(*fp_taos_connect_auth)(const char *ip, const char *user, const char *auth, const char *db, uint16_t port); +extern void (*fp_taos_close)(TAOS *taos); + +extern const char *(*fp_taos_data_type)(int type); + +extern TAOS_STMT *(*fp_taos_stmt_init)(TAOS *taos); +extern TAOS_STMT *(*fp_taos_stmt_init_with_reqid)(TAOS *taos, int64_t reqid); +extern TAOS_STMT *(*fp_taos_stmt_init_with_options)(TAOS *taos, TAOS_STMT_OPTIONS *options); +extern int (*fp_taos_stmt_prepare)(TAOS_STMT *stmt, const char *sql, unsigned long length); +extern int (*fp_taos_stmt_set_tbname_tags)(TAOS_STMT *stmt, const char *name, TAOS_MULTI_BIND *tags); +extern int (*fp_taos_stmt_set_tbname)(TAOS_STMT *stmt, const char *name); +extern int (*fp_taos_stmt_set_tags)(TAOS_STMT *stmt, TAOS_MULTI_BIND *tags); +extern int (*fp_taos_stmt_set_sub_tbname)(TAOS_STMT *stmt, const char *name); +extern int (*fp_taos_stmt_get_tag_fields)(TAOS_STMT *stmt, int *fieldNum, TAOS_FIELD_E **fields); +extern int (*fp_taos_stmt_get_col_fields)(TAOS_STMT *stmt, int *fieldNum, TAOS_FIELD_E **fields); +extern void (*fp_taos_stmt_reclaim_fields)(TAOS_STMT *stmt, TAOS_FIELD_E *fields); + +extern int (*fp_taos_stmt_is_insert)(TAOS_STMT *stmt, int *insert); +extern int (*fp_taos_stmt_num_params)(TAOS_STMT *stmt, int *nums); +extern int (*fp_taos_stmt_get_param)(TAOS_STMT *stmt, int idx, int *type, int *bytes); +extern int (*fp_taos_stmt_bind_param)(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind); +extern int (*fp_taos_stmt_bind_param_batch)(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind); +extern int (*fp_taos_stmt_bind_single_param_batch)(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, int colIdx); +extern int (*fp_taos_stmt_add_batch)(TAOS_STMT *stmt); +extern int (*fp_taos_stmt_execute)(TAOS_STMT *stmt); +extern TAOS_RES *(*fp_taos_stmt_use_result)(TAOS_STMT *stmt); +extern int (*fp_taos_stmt_close)(TAOS_STMT *stmt); +extern char *(*fp_taos_stmt_errstr)(TAOS_STMT *stmt); +extern int (*fp_taos_stmt_affected_rows)(TAOS_STMT *stmt); +extern int (*fp_taos_stmt_affected_rows_once)(TAOS_STMT *stmt); + +extern TAOS_STMT2 *(*fp_taos_stmt2_init)(TAOS *taos, TAOS_STMT2_OPTION *option); +extern int (*fp_taos_stmt2_prepare)(TAOS_STMT2 *stmt, const char *sql, unsigned long length); +extern int (*fp_taos_stmt2_bind_param)(TAOS_STMT2 *stmt, TAOS_STMT2_BINDV *bindv, int32_t col_idx); +extern int (*fp_taos_stmt2_bind_param_a)(TAOS_STMT2 *stmt, TAOS_STMT2_BINDV *bindv, int32_t col_idx, + __taos_async_fn_t fp, void *param); +extern int (*fp_taos_stmt2_exec)(TAOS_STMT2 *stmt, int *affected_rows); +extern int (*fp_taos_stmt2_close)(TAOS_STMT2 *stmt); +extern int (*fp_taos_stmt2_is_insert)(TAOS_STMT2 *stmt, int *insert); +extern int (*fp_taos_stmt2_get_fields)(TAOS_STMT2 *stmt, int *count, TAOS_FIELD_ALL **fields); +extern void (*fp_taos_stmt2_free_fields)(TAOS_STMT2 *stmt, TAOS_FIELD_ALL *fields); +extern TAOS_RES *(*fp_taos_stmt2_result)(TAOS_STMT2 *stmt); +extern char *(*fp_taos_stmt2_error)(TAOS_STMT2 *stmt); + +extern TAOS_RES *(*fp_taos_query)(TAOS *taos, const char *sql); +extern TAOS_RES *(*fp_taos_query_with_reqid)(TAOS *taos, const char *sql, int64_t reqId); + +extern TAOS_ROW (*fp_taos_fetch_row)(TAOS_RES *res); +extern int (*fp_taos_result_precision)(TAOS_RES *res); // get the time precision of result +extern void (*fp_taos_free_result)(TAOS_RES *res); +extern void (*fp_taos_kill_query)(TAOS *taos); +extern int (*fp_taos_field_count)(TAOS_RES *res); +extern int (*fp_taos_num_fields)(TAOS_RES *res); +extern int (*fp_taos_affected_rows)(TAOS_RES *res); +extern int64_t (*fp_taos_affected_rows64)(TAOS_RES *res); + +extern TAOS_FIELD *(*fp_taos_fetch_fields)(TAOS_RES *res); +extern int (*fp_taos_select_db)(TAOS *taos, const char *db); +extern int (*fp_taos_print_row)(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields); +extern int (*fp_taos_print_row_with_size)(char *str, uint32_t size, TAOS_ROW row, TAOS_FIELD *fields, int num_fields); +extern void (*fp_taos_stop_query)(TAOS_RES *res); +extern bool (*fp_taos_is_null)(TAOS_RES *res, int32_t row, int32_t col); +extern int (*fp_taos_is_null_by_column)(TAOS_RES *res, int columnIndex, bool result[], int *rows); +extern bool (*fp_taos_is_update_query)(TAOS_RES *res); +extern int (*fp_taos_fetch_block)(TAOS_RES *res, TAOS_ROW *rows); +extern int (*fp_taos_fetch_block_s)(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows); +extern int (*fp_taos_fetch_raw_block)(TAOS_RES *res, int *numOfRows, void **pData); +extern int *(*fp_taos_get_column_data_offset)(TAOS_RES *res, int columnIndex); +extern int (*fp_taos_validate_sql)(TAOS *taos, const char *sql); +extern void (*fp_taos_reset_current_db)(TAOS *taos); + +extern int *(*fp_taos_fetch_lengths)(TAOS_RES *res); +extern TAOS_ROW *(*fp_taos_result_block)(TAOS_RES *res); + +extern const char *(*fp_taos_get_server_info)(TAOS *taos); +extern const char *(*fp_taos_get_client_info)(); +extern int (*fp_taos_get_current_db)(TAOS *taos, char *database, int len, int *required); + +extern const char *(*fp_taos_errstr)(TAOS_RES *res); +extern int (*fp_taos_errno)(TAOS_RES *res); + +extern void (*fp_taos_query_a)(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param); +extern void (*fp_taos_query_a_with_reqid)(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param, + int64_t reqid); +extern void (*fp_taos_fetch_rows_a)(TAOS_RES *res, __taos_async_fn_t fp, void *param); +extern void (*fp_taos_fetch_raw_block_a)(TAOS_RES *res, __taos_async_fn_t fp, void *param); +extern const void *(*fp_taos_get_raw_block)(TAOS_RES *res); + +extern int (*fp_taos_get_db_route_info)(TAOS *taos, const char *db, TAOS_DB_ROUTE_INFO *dbInfo); +extern int (*fp_taos_get_table_vgId)(TAOS *taos, const char *db, const char *table, int *vgId); +extern int (*fp_taos_get_tables_vgId)(TAOS *taos, const char *db, const char *table[], int tableNum, int *vgId); + +extern int (*fp_taos_load_table_info)(TAOS *taos, const char *tableNameList); + +extern void (*fp_taos_set_hb_quit)(int8_t quitByKill); + +extern int (*fp_taos_set_notify_cb)(TAOS *taos, __taos_notify_fn_t fp, void *param, int type); + +extern void (*fp_taos_fetch_whitelist_a)(TAOS *taos, __taos_async_whitelist_fn_t fp, void *param); + +extern int (*fp_taos_set_conn_mode)(TAOS *taos, int mode, int value); + +extern TAOS_RES *(*fp_taos_schemaless_insert)(TAOS *taos, char *lines[], int numLines, int protocol, int precision); +extern TAOS_RES *(*fp_taos_schemaless_insert_with_reqid)(TAOS *taos, char *lines[], int numLines, int protocol, + int precision, int64_t reqid); +extern TAOS_RES *(*fp_taos_schemaless_insert_raw)(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol, + int precision); +extern TAOS_RES *(*fp_taos_schemaless_insert_raw_with_reqid)(TAOS *taos, char *lines, int len, int32_t *totalRows, + int protocol, int precision, int64_t reqid); +extern TAOS_RES *(*fp_taos_schemaless_insert_ttl)(TAOS *taos, char *lines[], int numLines, int protocol, int precision, + int32_t ttl); +extern TAOS_RES *(*fp_taos_schemaless_insert_ttl_with_reqid)(TAOS *taos, char *lines[], int numLines, int protocol, + int precision, int32_t ttl, int64_t reqid); +extern TAOS_RES *(*fp_taos_schemaless_insert_raw_ttl)(TAOS *taos, char *lines, int len, int32_t *totalRows, + int protocol, int precision, int32_t ttl); +extern TAOS_RES *(*fp_taos_schemaless_insert_raw_ttl_with_reqid)(TAOS *taos, char *lines, int len, int32_t *totalRows, + int protocol, int precision, int32_t ttl, + int64_t reqid); +extern TAOS_RES *(*fp_taos_schemaless_insert_raw_ttl_with_reqid_tbname_key)(TAOS *taos, char *lines, int len, + int32_t *totalRows, int protocol, + int precision, int32_t ttl, int64_t reqid, + char *tbnameKey); +extern TAOS_RES *(*fp_taos_schemaless_insert_ttl_with_reqid_tbname_key)(TAOS *taos, char *lines[], int numLines, + int protocol, int precision, int32_t ttl, + int64_t reqid, char *tbnameKey); + +extern tmq_conf_t *(*fp_tmq_conf_new)(); +extern tmq_conf_res_t (*fp_tmq_conf_set)(tmq_conf_t *conf, const char *key, const char *value); +extern void (*fp_tmq_conf_destroy)(tmq_conf_t *conf); +extern void (*fp_tmq_conf_set_auto_commit_cb)(tmq_conf_t *conf, tmq_commit_cb *cb, void *param); + +extern tmq_list_t *(*fp_tmq_list_new)(); +extern int32_t (*fp_tmq_list_append)(tmq_list_t *, const char *); +extern void (*fp_tmq_list_destroy)(tmq_list_t *); +extern int32_t (*fp_tmq_list_get_size)(const tmq_list_t *); +extern char **(*fp_tmq_list_to_c_array)(const tmq_list_t *); + +extern tmq_t *(*fp_tmq_consumer_new)(tmq_conf_t *conf, char *errstr, int32_t errstrLen); +extern int32_t (*fp_tmq_subscribe)(tmq_t *tmq, const tmq_list_t *topic_list); +extern int32_t (*fp_tmq_unsubscribe)(tmq_t *tmq); +extern int32_t (*fp_tmq_subscription)(tmq_t *tmq, tmq_list_t **topics); +extern TAOS_RES *(*fp_tmq_consumer_poll)(tmq_t *tmq, int64_t timeout); +extern int32_t (*fp_tmq_consumer_close)(tmq_t *tmq); +extern int32_t (*fp_tmq_commit_sync)(tmq_t *tmq, const TAOS_RES *msg); +extern void (*fp_tmq_commit_async)(tmq_t *tmq, const TAOS_RES *msg, tmq_commit_cb *cb, void *param); +extern int32_t (*fp_tmq_commit_offset_sync)(tmq_t *tmq, const char *pTopicName, int32_t vgId, int64_t offset); +extern void (*fp_tmq_commit_offset_async)(tmq_t *tmq, const char *pTopicName, int32_t vgId, int64_t offset, + tmq_commit_cb *cb, void *param); +extern int32_t (*fp_tmq_get_topic_assignment)(tmq_t *tmq, const char *pTopicName, tmq_topic_assignment **assignment, + int32_t *numOfAssignment); +extern void (*fp_tmq_free_assignment)(tmq_topic_assignment *pAssignment); +extern int32_t (*fp_tmq_offset_seek)(tmq_t *tmq, const char *pTopicName, int32_t vgId, int64_t offset); +extern int64_t (*fp_tmq_position)(tmq_t *tmq, const char *pTopicName, int32_t vgId); +extern int64_t (*fp_tmq_committed)(tmq_t *tmq, const char *pTopicName, int32_t vgId); + +extern TAOS *(*fp_tmq_get_connect)(tmq_t *tmq); +extern const char *(*fp_tmq_get_table_name)(TAOS_RES *res); +extern tmq_res_t (*fp_tmq_get_res_type)(TAOS_RES *res); +extern const char *(*fp_tmq_get_topic_name)(TAOS_RES *res); +extern const char *(*fp_tmq_get_db_name)(TAOS_RES *res); +extern int32_t (*fp_tmq_get_vgroup_id)(TAOS_RES *res); +extern int64_t (*fp_tmq_get_vgroup_offset)(TAOS_RES *res); +extern const char *(*fp_tmq_err2str)(int32_t code); + +extern int32_t (*fp_tmq_get_raw)(TAOS_RES *res, tmq_raw_data *raw); +extern int32_t (*fp_tmq_write_raw)(TAOS *taos, tmq_raw_data raw); +extern int (*fp_taos_write_raw_block)(TAOS *taos, int numOfRows, char *pData, const char *tbname); +extern int (*fp_taos_write_raw_block_with_reqid)(TAOS *taos, int numOfRows, char *pData, const char *tbname, + int64_t reqid); +extern int (*fp_taos_write_raw_block_with_fields)(TAOS *taos, int rows, char *pData, const char *tbname, + TAOS_FIELD *fields, int numFields); +extern int (*fp_taos_write_raw_block_with_fields_with_reqid)(TAOS *taos, int rows, char *pData, const char *tbname, + TAOS_FIELD *fields, int numFields, int64_t reqid); +extern void (*fp_tmq_free_raw)(tmq_raw_data raw); + +extern char *(*fp_tmq_get_json_meta)(TAOS_RES *res); +extern void (*fp_tmq_free_json_meta)(char *jsonMeta); + +extern TSDB_SERVER_STATUS (*fp_taos_check_server_status)(const char *fqdn, int port, char *details, int maxlen); +extern void (*fp_taos_write_crashinfo)(int signum, void *sigInfo, void *context); +extern char *(*fp_getBuildInfo)(); + +#ifdef __cplusplus +} +#endif + +#endif // TDENGINE_CLIENT_WRAPPER_H diff --git a/source/client/wrapper/src/wrapperDriver.c b/source/client/wrapper/src/wrapperDriver.c new file mode 100644 index 000000000000..5a0449254a0a --- /dev/null +++ b/source/client/wrapper/src/wrapperDriver.c @@ -0,0 +1,270 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "wrapper.h" + +#ifdef WINDOWS +#define DRIVER_NATIVE_NAME "taosnative.dll" +#define DRIVER_WSBSOCKET_NAME "taosws.dll" +#elif defined(DARWIN) +#define DRIVER_NATIVE_NAME "libtaosnative.dylib" +#define DRIVER_WSBSOCKET_NAME "libtaosws.dylib" +#else +#define DRIVER_NATIVE_NAME "libtaosnative.so" +#define DRIVER_WSBSOCKET_NAME "libtaosws.so" +#endif + +#define LOAD_FUNC(fptr, fname) \ + funcName = fname; \ + fptr = taosLoadDllFunc(tsDriver, funcName); \ + if (fptr == NULL) goto _OVER; + +#ifdef WEBSOCKET +EDriverType tsDriverType = DRIVER_NATIVE; // todo simon +#else +EDriverType tsDriverType = DRIVER_NATIVE; +#endif + +void *tsDriver = NULL; + +static int32_t tossGetDevelopPath(char *driverPath, const char *driverName) { + char appPath[PATH_MAX] = {0}; + int32_t ret = taosAppPath(appPath, PATH_MAX); + if (ret == 0) { + snprintf(driverPath, PATH_MAX, "%s%s..%slib%s%s", appPath, TD_DIRSEP, TD_DIRSEP, TD_DIRSEP, driverName); + ret = taosRealPath(driverPath, NULL, PATH_MAX); + } + + return ret; +} + +static int32_t taosGetInstallPath(char *driverPath, const char *driverName) { + tstrncpy(driverPath, driverName, PATH_MAX); + return 0; +} + +int32_t taosDriverInit(EDriverType driverType) { + int32_t code = -1; + char driverPath[PATH_MAX + 32] = {0}; + const char *driverName = NULL; + const char *funcName = NULL; + + if (driverType == DRIVER_NATIVE) { + driverName = DRIVER_NATIVE_NAME; + } else { + driverName = DRIVER_WSBSOCKET_NAME; + } + + if (tsDriver == NULL && tossGetDevelopPath(driverPath, driverName) == 0) { + tsDriver = taosLoadDll(driverPath); + } + + if (tsDriver == NULL && taosGetInstallPath(driverPath, driverName) == 0) { + tsDriver = taosLoadDll(driverPath); + } + + if (tsDriver == NULL) { + printf("failed to load %s since %s [0x%X]\r\n", driverName, terrstr(), terrno); + return code; + } + + // printf("load driver from %s\r\n", driverPath); + LOAD_FUNC(fp_taos_set_config, "taos_set_config"); + + LOAD_FUNC(fp_taos_init, "taos_init"); + LOAD_FUNC(fp_taos_cleanup, "taos_cleanup"); + LOAD_FUNC(fp_taos_options, "taos_options"); + LOAD_FUNC(fp_taos_options_connection, "taos_options_connection"); + LOAD_FUNC(fp_taos_connect, "taos_connect"); + LOAD_FUNC(fp_taos_connect_auth, "taos_connect_auth"); + LOAD_FUNC(fp_taos_close, "taos_close"); + + LOAD_FUNC(fp_taos_data_type, "taos_data_type"); + + LOAD_FUNC(fp_taos_stmt_init, "taos_stmt_init"); + LOAD_FUNC(fp_taos_stmt_init_with_reqid, "taos_stmt_init_with_reqid"); + LOAD_FUNC(fp_taos_stmt_init_with_options, "taos_stmt_init_with_options"); + LOAD_FUNC(fp_taos_stmt_prepare, "taos_stmt_prepare"); + LOAD_FUNC(fp_taos_stmt_set_tbname_tags, "taos_stmt_set_tbname_tags"); + LOAD_FUNC(fp_taos_stmt_set_tbname, "taos_stmt_set_tbname"); + LOAD_FUNC(fp_taos_stmt_set_tags, "taos_stmt_set_tags"); + LOAD_FUNC(fp_taos_stmt_set_sub_tbname, "taos_stmt_set_sub_tbname"); + LOAD_FUNC(fp_taos_stmt_get_tag_fields, "taos_stmt_get_tag_fields"); + LOAD_FUNC(fp_taos_stmt_get_col_fields, "taos_stmt_get_col_fields"); + LOAD_FUNC(fp_taos_stmt_reclaim_fields, "taos_stmt_reclaim_fields"); + + LOAD_FUNC(fp_taos_stmt_is_insert, "taos_stmt_is_insert"); + LOAD_FUNC(fp_taos_stmt_num_params, "taos_stmt_num_params"); + LOAD_FUNC(fp_taos_stmt_get_param, "taos_stmt_get_param"); + LOAD_FUNC(fp_taos_stmt_bind_param, "taos_stmt_bind_param"); + LOAD_FUNC(fp_taos_stmt_bind_param_batch, "taos_stmt_bind_param_batch"); + LOAD_FUNC(fp_taos_stmt_bind_single_param_batch, "taos_stmt_bind_single_param_batch"); + LOAD_FUNC(fp_taos_stmt_add_batch, "taos_stmt_add_batch"); + LOAD_FUNC(fp_taos_stmt_execute, "taos_stmt_execute"); + LOAD_FUNC(fp_taos_stmt_use_result, "taos_stmt_use_result"); + LOAD_FUNC(fp_taos_stmt_close, "taos_stmt_close"); + LOAD_FUNC(fp_taos_stmt_errstr, "taos_stmt_errstr"); + LOAD_FUNC(fp_taos_stmt_affected_rows, "taos_stmt_affected_rows"); + LOAD_FUNC(fp_taos_stmt_affected_rows_once, "taos_stmt_affected_rows_once"); + + LOAD_FUNC(fp_taos_stmt2_init, "taos_stmt2_init"); + LOAD_FUNC(fp_taos_stmt2_prepare, "taos_stmt2_prepare"); + LOAD_FUNC(fp_taos_stmt2_bind_param, "taos_stmt2_bind_param"); + LOAD_FUNC(fp_taos_stmt2_bind_param_a, "taos_stmt2_bind_param_a"); + LOAD_FUNC(fp_taos_stmt2_exec, "taos_stmt2_exec"); + LOAD_FUNC(fp_taos_stmt2_close, "taos_stmt2_close"); + LOAD_FUNC(fp_taos_stmt2_is_insert, "taos_stmt2_is_insert"); + LOAD_FUNC(fp_taos_stmt2_get_fields, "taos_stmt2_get_fields"); + LOAD_FUNC(fp_taos_stmt2_free_fields, "taos_stmt2_free_fields"); + LOAD_FUNC(fp_taos_stmt2_result, "taos_stmt2_result"); + LOAD_FUNC(fp_taos_stmt2_error, "taos_stmt2_error"); + + LOAD_FUNC(fp_taos_query, "taos_query"); + LOAD_FUNC(fp_taos_query_with_reqid, "taos_query_with_reqid"); + + LOAD_FUNC(fp_taos_fetch_row, "taos_fetch_row"); + LOAD_FUNC(fp_taos_result_precision, "taos_result_precision"); + LOAD_FUNC(fp_taos_free_result, "taos_free_result"); + LOAD_FUNC(fp_taos_kill_query, "taos_kill_query"); + LOAD_FUNC(fp_taos_field_count, "taos_field_count"); + LOAD_FUNC(fp_taos_num_fields, "taos_num_fields"); + LOAD_FUNC(fp_taos_affected_rows, "taos_affected_rows"); + LOAD_FUNC(fp_taos_affected_rows64, "taos_affected_rows64"); + + LOAD_FUNC(fp_taos_fetch_fields, "taos_fetch_fields"); + LOAD_FUNC(fp_taos_select_db, "taos_select_db"); + LOAD_FUNC(fp_taos_print_row, "taos_print_row"); + LOAD_FUNC(fp_taos_print_row_with_size, "taos_print_row_with_size"); + LOAD_FUNC(fp_taos_stop_query, "taos_stop_query"); + LOAD_FUNC(fp_taos_is_null, "taos_is_null"); + LOAD_FUNC(fp_taos_is_null_by_column, "taos_is_null_by_column"); + LOAD_FUNC(fp_taos_is_update_query, "taos_is_update_query"); + LOAD_FUNC(fp_taos_fetch_block, "taos_fetch_block"); + LOAD_FUNC(fp_taos_fetch_block_s, "taos_fetch_block_s"); + LOAD_FUNC(fp_taos_fetch_raw_block, "taos_fetch_raw_block"); + LOAD_FUNC(fp_taos_get_column_data_offset, "taos_get_column_data_offset"); + LOAD_FUNC(fp_taos_validate_sql, "taos_validate_sql"); + LOAD_FUNC(fp_taos_reset_current_db, "taos_reset_current_db"); + + LOAD_FUNC(fp_taos_fetch_lengths, "taos_fetch_lengths"); + LOAD_FUNC(fp_taos_result_block, "taos_result_block"); + + LOAD_FUNC(fp_taos_get_server_info, "taos_get_server_info"); + LOAD_FUNC(fp_taos_get_client_info, "taos_get_client_info"); + LOAD_FUNC(fp_taos_get_current_db, "taos_get_current_db"); + + LOAD_FUNC(fp_taos_errstr, "taos_errstr"); + LOAD_FUNC(fp_taos_errno, "taos_errno"); + + LOAD_FUNC(fp_taos_query_a, "taos_query_a"); + LOAD_FUNC(fp_taos_query_a_with_reqid, "taos_query_a_with_reqid"); + LOAD_FUNC(fp_taos_fetch_rows_a, "taos_fetch_rows_a"); + LOAD_FUNC(fp_taos_fetch_raw_block_a, "taos_fetch_raw_block_a"); + LOAD_FUNC(fp_taos_get_raw_block, "taos_get_raw_block"); + + LOAD_FUNC(fp_taos_get_db_route_info, "taos_get_db_route_info"); + LOAD_FUNC(fp_taos_get_table_vgId, "taos_get_table_vgId"); + LOAD_FUNC(fp_taos_get_tables_vgId, "taos_get_tables_vgId"); + + LOAD_FUNC(fp_taos_load_table_info, "taos_load_table_info"); + + LOAD_FUNC(fp_taos_set_hb_quit, "taos_set_hb_quit"); + + LOAD_FUNC(fp_taos_set_notify_cb, "taos_set_notify_cb"); + + LOAD_FUNC(fp_taos_fetch_whitelist_a, "taos_fetch_whitelist_a"); + + LOAD_FUNC(fp_taos_set_conn_mode, "taos_set_conn_mode"); + + LOAD_FUNC(fp_taos_schemaless_insert, "taos_schemaless_insert"); + LOAD_FUNC(fp_taos_schemaless_insert_with_reqid, "taos_schemaless_insert_with_reqid"); + LOAD_FUNC(fp_taos_schemaless_insert_raw, "taos_schemaless_insert_raw"); + LOAD_FUNC(fp_taos_schemaless_insert_raw_with_reqid, "taos_schemaless_insert_raw_with_reqid"); + LOAD_FUNC(fp_taos_schemaless_insert_ttl, "taos_schemaless_insert_ttl"); + LOAD_FUNC(fp_taos_schemaless_insert_ttl_with_reqid, "taos_schemaless_insert_ttl_with_reqid"); + LOAD_FUNC(fp_taos_schemaless_insert_raw_ttl, "taos_schemaless_insert_raw_ttl"); + LOAD_FUNC(fp_taos_schemaless_insert_raw_ttl_with_reqid, "taos_schemaless_insert_raw_ttl_with_reqid"); + LOAD_FUNC(fp_taos_schemaless_insert_raw_ttl_with_reqid_tbname_key, + "taos_schemaless_insert_raw_ttl_with_reqid_tbname_key"); + LOAD_FUNC(fp_taos_schemaless_insert_ttl_with_reqid_tbname_key, "taos_schemaless_insert_ttl_with_reqid_tbname_key"); + + LOAD_FUNC(fp_tmq_conf_new, "tmq_conf_new"); + LOAD_FUNC(fp_tmq_conf_set, "tmq_conf_set"); + LOAD_FUNC(fp_tmq_conf_destroy, "tmq_conf_destroy"); + LOAD_FUNC(fp_tmq_conf_set_auto_commit_cb, "tmq_conf_set_auto_commit_cb"); + + LOAD_FUNC(fp_tmq_list_new, "tmq_list_new"); + LOAD_FUNC(fp_tmq_list_append, "tmq_list_append"); + LOAD_FUNC(fp_tmq_list_destroy, "tmq_list_destroy"); + LOAD_FUNC(fp_tmq_list_get_size, "tmq_list_get_size"); + LOAD_FUNC(fp_tmq_list_to_c_array, "tmq_list_to_c_array"); + + LOAD_FUNC(fp_tmq_consumer_new, "tmq_consumer_new"); + LOAD_FUNC(fp_tmq_subscribe, "tmq_subscribe"); + LOAD_FUNC(fp_tmq_unsubscribe, "tmq_unsubscribe"); + LOAD_FUNC(fp_tmq_subscription, "tmq_subscription"); + LOAD_FUNC(fp_tmq_consumer_poll, "tmq_consumer_poll"); + LOAD_FUNC(fp_tmq_consumer_close, "tmq_consumer_close"); + LOAD_FUNC(fp_tmq_commit_sync, "tmq_commit_sync"); + LOAD_FUNC(fp_tmq_commit_async, "tmq_commit_async"); + LOAD_FUNC(fp_tmq_commit_offset_sync, "tmq_commit_offset_sync"); + LOAD_FUNC(fp_tmq_commit_offset_async, "tmq_commit_offset_async"); + LOAD_FUNC(fp_tmq_get_topic_assignment, "tmq_get_topic_assignment"); + LOAD_FUNC(fp_tmq_free_assignment, "tmq_free_assignment"); + LOAD_FUNC(fp_tmq_offset_seek, "tmq_offset_seek"); + LOAD_FUNC(fp_tmq_position, "tmq_position"); + LOAD_FUNC(fp_tmq_committed, "tmq_committed"); + + LOAD_FUNC(fp_tmq_get_connect, "tmq_get_connect"); + LOAD_FUNC(fp_tmq_get_table_name, "tmq_get_table_name"); + LOAD_FUNC(fp_tmq_get_res_type, "tmq_get_res_type"); + LOAD_FUNC(fp_tmq_get_topic_name, "tmq_get_topic_name"); + LOAD_FUNC(fp_tmq_get_db_name, "tmq_get_db_name"); + LOAD_FUNC(fp_tmq_get_vgroup_id, "tmq_get_vgroup_id"); + LOAD_FUNC(fp_tmq_get_vgroup_offset, "tmq_get_vgroup_offset"); + LOAD_FUNC(fp_tmq_err2str, "tmq_err2str"); + + LOAD_FUNC(fp_tmq_get_raw, "tmq_get_raw"); + LOAD_FUNC(fp_tmq_write_raw, "tmq_write_raw"); + LOAD_FUNC(fp_taos_write_raw_block, "taos_write_raw_block"); + LOAD_FUNC(fp_taos_write_raw_block_with_reqid, "taos_write_raw_block_with_reqid"); + LOAD_FUNC(fp_taos_write_raw_block_with_fields, "taos_write_raw_block_with_fields"); + LOAD_FUNC(fp_taos_write_raw_block_with_fields_with_reqid, "taos_write_raw_block_with_fields_with_reqid"); + LOAD_FUNC(fp_tmq_free_raw, "tmq_free_raw"); + + LOAD_FUNC(fp_tmq_get_json_meta, "tmq_get_json_meta"); + LOAD_FUNC(fp_tmq_free_json_meta, "tmq_free_json_meta"); + + LOAD_FUNC(fp_taos_check_server_status, "taos_check_server_status"); + LOAD_FUNC(fp_taos_write_crashinfo, "taos_write_crashinfo"); + LOAD_FUNC(fp_getBuildInfo, "getBuildInfo"); + + code = 0; + +_OVER: + if (code != 0) { + printf("failed to load function %s from %s since %s [0x%X]\r\n", funcName, driverPath, terrstr(), terrno); + taosDriverCleanup(); + } + + return code; +} + +void taosDriverCleanup() { + if (tsDriver != NULL) { + taosCloseDll(tsDriver); + tsDriver = NULL; + } +} diff --git a/source/client/wrapper/src/wrapperFunc.c b/source/client/wrapper/src/wrapperFunc.c new file mode 100644 index 000000000000..f0f5cc0a1946 --- /dev/null +++ b/source/client/wrapper/src/wrapperFunc.c @@ -0,0 +1,865 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "version.h" +#include "wrapper.h" + +static TdThreadOnce tsDriverOnce = PTHREAD_ONCE_INIT; +volatile int32_t tsDriverOnceRet = 0; + +#define ERR_VOID(code) \ + terrno = code; \ + return; + +#define ERR_PTR(code) \ + terrno = code; \ + return NULL; + +#define ERR_INT(code) \ + terrno = code; \ + return -1; + +#define ERR_BOOL(code) \ + terrno = code; \ + return false; + +#define ERR_CONFRET(code) \ + terrno = code; \ + setConfRet ret = {.retCode = -1}; \ + return ret; + +#define CHECK_VOID(fp) \ + if (tsDriver == NULL) { \ + ERR_VOID(TSDB_CODE_DLL_NOT_LOAD) \ + } \ + if (fp == NULL) { \ + ERR_VOID(TSDB_CODE_DLL_NOT_LOAD) \ + } + +#define CHECK_PTR(fp) \ + if (tsDriver == NULL) { \ + ERR_PTR(TSDB_CODE_DLL_NOT_LOAD) \ + } \ + if (fp == NULL) { \ + ERR_PTR(TSDB_CODE_DLL_NOT_LOAD) \ + } + +#define CHECK_INT(fp) \ + if (tsDriver == NULL) { \ + ERR_INT(TSDB_CODE_DLL_NOT_LOAD) \ + } \ + if (fp == NULL) { \ + ERR_INT(TSDB_CODE_DLL_NOT_LOAD) \ + } + +#define CHECK_BOOL(fp) \ + if (tsDriver == NULL) { \ + ERR_BOOL(TSDB_CODE_DLL_NOT_LOAD) \ + } \ + if (fp == NULL) { \ + ERR_BOOL(TSDB_CODE_DLL_NOT_LOAD) \ + } + +#define CHECK_CONFRET(fp) \ + if (tsDriver == NULL) { \ + ERR_CONFRET(TSDB_CODE_DLL_NOT_LOAD) \ + } \ + if (fp == NULL) { \ + ERR_CONFRET(TSDB_CODE_DLL_NOT_LOAD) \ + } + +setConfRet taos_set_config(const char *config) { + if (taos_init() != 0) { + ERR_CONFRET(TSDB_CODE_DLL_NOT_LOAD) + } + + CHECK_CONFRET(fp_taos_set_config); + return (*fp_taos_set_config)(config); +} + +static void taos_init_wrapper(void) { + tsDriverOnceRet = taosDriverInit(tsDriverType); + if (tsDriverOnceRet != 0) return; + + if (fp_taos_init == NULL) { + terrno = TSDB_CODE_DLL_FUNC_NOT_LOAD; + tsDriverOnceRet = -1; + } else { + tsDriverOnceRet = (*fp_taos_init)(); + } +} + +int taos_init(void) { + (void)taosThreadOnce(&tsDriverOnce, taos_init_wrapper); + return tsDriverOnceRet; +} + +void taos_cleanup(void) { + CHECK_VOID(fp_taos_cleanup); + (*fp_taos_cleanup)(); +} + +int taos_options(TSDB_OPTION option, const void *arg, ...) { + if (option == TSDB_OPTION_DRIVER) { + if (tsDriver == NULL) { + if (strcasecmp((const char *)arg, "native") == 0) { + tsDriverType = DRIVER_NATIVE; + return 0; + } + if (strcasecmp((const char *)arg, "websocket") == 0) { + tsDriverType = DRIVER_WEBSOCKET; + return 0; + } + } + terrno = TSDB_CODE_REPEAT_INIT; + return -1; + } + + if (taos_init() != 0) { + terrno = TSDB_CODE_DLL_NOT_LOAD; + return -1; + } + + CHECK_INT(fp_taos_options); + return (*fp_taos_options)(option, arg); +} + +int taos_options_connection(TAOS *taos, TSDB_OPTION_CONNECTION option, const void *arg, ...) { + CHECK_INT(fp_taos_options_connection); + return (*fp_taos_options_connection)(taos, option, (const char *)arg); +} + +TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port) { + if (taos_init() != 0) { + terrno = TSDB_CODE_DLL_NOT_LOAD; + return NULL; + } + + CHECK_PTR(fp_taos_connect); + return (*fp_taos_connect)(ip, user, pass, db, port); +} + +TAOS *taos_connect_auth(const char *ip, const char *user, const char *auth, const char *db, uint16_t port) { + if (taos_init() != 0) { + terrno = TSDB_CODE_DLL_NOT_LOAD; + return NULL; + } + + CHECK_PTR(fp_taos_connect_auth); + return (*fp_taos_connect_auth)(ip, user, auth, db, port); +} + +void taos_close(TAOS *taos) { + CHECK_VOID(fp_taos_close); + (*fp_taos_close)(taos); +} + +const char *taos_data_type(int type) { + CHECK_PTR(fp_taos_data_type); + return (*fp_taos_data_type)(type); +} + +TAOS_STMT *taos_stmt_init(TAOS *taos) { + CHECK_PTR(fp_taos_stmt_init); + return (*fp_taos_stmt_init)(taos); +} + +TAOS_STMT *taos_stmt_init_with_reqid(TAOS *taos, int64_t reqid) { + CHECK_PTR(fp_taos_stmt_init_with_reqid); + return (*fp_taos_stmt_init_with_reqid)(taos, reqid); +} + +TAOS_STMT *taos_stmt_init_with_options(TAOS *taos, TAOS_STMT_OPTIONS *options) { + CHECK_PTR(fp_taos_stmt_init_with_options); + return (*fp_taos_stmt_init_with_options)(taos, options); +} + +int taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length) { + CHECK_INT(fp_taos_stmt_prepare); + return (*fp_taos_stmt_prepare)(stmt, sql, length); +} + +int taos_stmt_set_tbname_tags(TAOS_STMT *stmt, const char *name, TAOS_MULTI_BIND *tags) { + CHECK_INT(fp_taos_stmt_set_tbname_tags); + return (*fp_taos_stmt_set_tbname_tags)(stmt, name, tags); +} + +int taos_stmt_set_tbname(TAOS_STMT *stmt, const char *name) { + CHECK_INT(fp_taos_stmt_set_tbname); + return (*fp_taos_stmt_set_tbname)(stmt, name); +} + +int taos_stmt_set_tags(TAOS_STMT *stmt, TAOS_MULTI_BIND *tags) { + CHECK_INT(fp_taos_stmt_set_tags); + return (*fp_taos_stmt_set_tags)(stmt, tags); +} + +int taos_stmt_set_sub_tbname(TAOS_STMT *stmt, const char *name) { + CHECK_INT(fp_taos_stmt_set_sub_tbname); + return (*fp_taos_stmt_set_sub_tbname)(stmt, name); +} + +int taos_stmt_get_tag_fields(TAOS_STMT *stmt, int *fieldNum, TAOS_FIELD_E **fields) { + CHECK_INT(fp_taos_stmt_get_tag_fields); + return (*fp_taos_stmt_get_tag_fields)(stmt, fieldNum, fields); +} + +int taos_stmt_get_col_fields(TAOS_STMT *stmt, int *fieldNum, TAOS_FIELD_E **fields) { + CHECK_INT(fp_taos_stmt_get_col_fields); + return (*fp_taos_stmt_get_col_fields)(stmt, fieldNum, fields); +} + +void taos_stmt_reclaim_fields(TAOS_STMT *stmt, TAOS_FIELD_E *fields) { + CHECK_VOID(fp_taos_stmt_reclaim_fields); + (*fp_taos_stmt_reclaim_fields)(stmt, fields); +} + +int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert) { + CHECK_INT(fp_taos_stmt_is_insert); + return (*fp_taos_stmt_is_insert)(stmt, insert); +} + +int taos_stmt_num_params(TAOS_STMT *stmt, int *nums) { + CHECK_INT(fp_taos_stmt_num_params); + return (*fp_taos_stmt_num_params)(stmt, nums); +} + +int taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes) { + CHECK_INT(fp_taos_stmt_get_param); + return (*fp_taos_stmt_get_param)(stmt, idx, type, bytes); +} + +int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind) { + CHECK_INT(fp_taos_stmt_bind_param); + return (*fp_taos_stmt_bind_param)(stmt, bind); +} + +int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind) { + CHECK_INT(fp_taos_stmt_bind_param_batch); + return (*fp_taos_stmt_bind_param_batch)(stmt, bind); +} + +int taos_stmt_bind_single_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, int colIdx) { + CHECK_INT(fp_taos_stmt_bind_single_param_batch); + return (*fp_taos_stmt_bind_single_param_batch)(stmt, bind, colIdx); +} + +int taos_stmt_add_batch(TAOS_STMT *stmt) { + CHECK_INT(fp_taos_stmt_add_batch); + return (*fp_taos_stmt_add_batch)(stmt); +} + +int taos_stmt_execute(TAOS_STMT *stmt) { + CHECK_INT(fp_taos_stmt_execute); + return (*fp_taos_stmt_execute)(stmt); +} + +TAOS_RES *taos_stmt_use_result(TAOS_STMT *stmt) { + CHECK_PTR(fp_taos_stmt_use_result); + return (*fp_taos_stmt_use_result)(stmt); +} + +int taos_stmt_close(TAOS_STMT *stmt) { + CHECK_INT(fp_taos_stmt_close); + return (*fp_taos_stmt_close)(stmt); +} + +char *taos_stmt_errstr(TAOS_STMT *stmt) { + CHECK_PTR(fp_taos_stmt_errstr); + return (*fp_taos_stmt_errstr)(stmt); +} + +int taos_stmt_affected_rows(TAOS_STMT *stmt) { + CHECK_INT(fp_taos_stmt_affected_rows); + return (*fp_taos_stmt_affected_rows)(stmt); +} + +int taos_stmt_affected_rows_once(TAOS_STMT *stmt) { + CHECK_INT(fp_taos_stmt_affected_rows_once); + return (*fp_taos_stmt_affected_rows_once)(stmt); +} + +TAOS_STMT2 *taos_stmt2_init(TAOS *taos, TAOS_STMT2_OPTION *option) { + CHECK_PTR(fp_taos_stmt2_init); + return (*fp_taos_stmt2_init)(taos, option); +} + +int taos_stmt2_prepare(TAOS_STMT2 *stmt, const char *sql, unsigned long length) { + CHECK_INT(fp_taos_stmt2_prepare); + return (*fp_taos_stmt2_prepare)(stmt, sql, length); +} + +int taos_stmt2_bind_param(TAOS_STMT2 *stmt, TAOS_STMT2_BINDV *bindv, int32_t col_idx) { + CHECK_INT(fp_taos_stmt2_bind_param); + return (*fp_taos_stmt2_bind_param)(stmt, bindv, col_idx); +} + +int taos_stmt2_bind_param_a(TAOS_STMT2 *stmt, TAOS_STMT2_BINDV *bindv, int32_t col_idx, __taos_async_fn_t fp, + void *param) { + CHECK_INT(fp_taos_stmt2_bind_param_a); + return (*fp_taos_stmt2_bind_param_a)(stmt, bindv, col_idx, fp, param); +} + +int taos_stmt2_exec(TAOS_STMT2 *stmt, int *affected_rows) { + CHECK_INT(fp_taos_stmt2_exec); + return (*fp_taos_stmt2_exec)(stmt, affected_rows); +} + +int taos_stmt2_close(TAOS_STMT2 *stmt) { + CHECK_INT(fp_taos_stmt2_close); + return (*fp_taos_stmt2_close)(stmt); +} + +int taos_stmt2_is_insert(TAOS_STMT2 *stmt, int *insert) { + CHECK_INT(fp_taos_stmt2_is_insert); + return (*fp_taos_stmt2_is_insert)(stmt, insert); +} + +int taos_stmt2_get_fields(TAOS_STMT2 *stmt, int *count, TAOS_FIELD_ALL **fields) { + CHECK_INT(fp_taos_stmt2_get_fields); + return (*fp_taos_stmt2_get_fields)(stmt, count, fields); +} + +void taos_stmt2_free_fields(TAOS_STMT2 *stmt, TAOS_FIELD_ALL *fields) { + CHECK_VOID(fp_taos_stmt2_free_fields); + (*fp_taos_stmt2_free_fields)(stmt, fields); +} + +TAOS_RES *taos_stmt2_result(TAOS_STMT2 *stmt) { + CHECK_PTR(fp_taos_stmt2_result); + return (*fp_taos_stmt2_result)(stmt); +} + +char *taos_stmt2_error(TAOS_STMT2 *stmt) { + CHECK_PTR(fp_taos_stmt2_error); + return (*fp_taos_stmt2_error)(stmt); +} + +TAOS_RES *taos_query(TAOS *taos, const char *sql) { + CHECK_PTR(fp_taos_query); + return (*fp_taos_query)(taos, sql); +} + +TAOS_RES *taos_query_with_reqid(TAOS *taos, const char *sql, int64_t reqId) { + CHECK_PTR(fp_taos_query_with_reqid); + return (*fp_taos_query_with_reqid)(taos, sql, reqId); +} + +TAOS_ROW taos_fetch_row(TAOS_RES *res) { + CHECK_PTR(fp_taos_fetch_row); + return (*fp_taos_fetch_row)(res); +} + +int taos_result_precision(TAOS_RES *res) { + CHECK_INT(fp_taos_result_precision); + return (*fp_taos_result_precision)(res); +} + +void taos_free_result(TAOS_RES *res) { + CHECK_VOID(fp_taos_free_result); + return (*fp_taos_free_result)(res); +} + +void taos_kill_query(TAOS *taos) { + CHECK_VOID(fp_taos_kill_query); + return (*fp_taos_kill_query)(taos); +} + +int taos_field_count(TAOS_RES *res) { + CHECK_INT(fp_taos_field_count); + return (*fp_taos_field_count)(res); +} + +int taos_num_fields(TAOS_RES *res) { + CHECK_INT(fp_taos_num_fields); + return (*fp_taos_num_fields)(res); +} + +int taos_affected_rows(TAOS_RES *res) { + CHECK_INT(fp_taos_affected_rows); + return (*fp_taos_affected_rows)(res); +} + +int64_t taos_affected_rows64(TAOS_RES *res) { + CHECK_INT(fp_taos_affected_rows64); + return (*fp_taos_affected_rows64)(res); +} + +TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) { + CHECK_PTR(fp_taos_fetch_fields); + return (*fp_taos_fetch_fields)(res); +} + +int taos_select_db(TAOS *taos, const char *db) { + CHECK_INT(fp_taos_select_db); + return (*fp_taos_select_db)(taos, db); +} + +int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields) { + CHECK_INT(fp_taos_print_row); + return (*fp_taos_print_row)(str, row, fields, num_fields); +} + +int taos_print_row_with_size(char *str, uint32_t size, TAOS_ROW row, TAOS_FIELD *fields, int num_fields) { + CHECK_INT(fp_taos_print_row_with_size); + return (*fp_taos_print_row_with_size)(str, size, row, fields, num_fields); +} + +void taos_stop_query(TAOS_RES *res) { + CHECK_VOID(fp_taos_stop_query); + (*fp_taos_stop_query)(res); +} + +bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col) { + CHECK_BOOL(fp_taos_is_null); + return (*fp_taos_is_null)(res, row, col); +} + +int taos_is_null_by_column(TAOS_RES *res, int columnIndex, bool result[], int *rows) { + CHECK_INT(fp_taos_is_null_by_column); + return (*fp_taos_is_null_by_column)(res, columnIndex, result, rows); +} + +bool taos_is_update_query(TAOS_RES *res) { + CHECK_BOOL(fp_taos_is_update_query); + return (*fp_taos_is_update_query)(res); +} + +int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) { + CHECK_INT(fp_taos_fetch_block); + return (*fp_taos_fetch_block)(res, rows); +} + +int taos_fetch_block_s(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows) { + CHECK_INT(fp_taos_fetch_block_s); + return (*fp_taos_fetch_block_s)(res, numOfRows, rows); +} + +int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData) { + CHECK_INT(fp_taos_fetch_raw_block); + return (*fp_taos_fetch_raw_block)(res, numOfRows, pData); +} + +int *taos_get_column_data_offset(TAOS_RES *res, int columnIndex) { + CHECK_PTR(fp_taos_get_column_data_offset); + return (*fp_taos_get_column_data_offset)(res, columnIndex); +} + +int taos_validate_sql(TAOS *taos, const char *sql) { + CHECK_INT(fp_taos_validate_sql); + return (*fp_taos_validate_sql)(taos, sql); +} + +void taos_reset_current_db(TAOS *taos) { + CHECK_VOID(fp_taos_reset_current_db); + (*fp_taos_reset_current_db)(taos); +} + +int *taos_fetch_lengths(TAOS_RES *res) { + CHECK_PTR(fp_taos_fetch_lengths); + return (*fp_taos_fetch_lengths)(res); +} + +TAOS_ROW *taos_result_block(TAOS_RES *res) { + CHECK_PTR(fp_taos_result_block); + return (*fp_taos_result_block)(res); +} + +const char *taos_get_server_info(TAOS *taos) { + CHECK_PTR(fp_taos_get_server_info); + return (*fp_taos_get_server_info)(taos); +} + +const char *taos_get_client_info() { + if (fp_taos_get_client_info == NULL) { + return td_version; + } else { + return (*fp_taos_get_client_info)(); + } +} + +int taos_get_current_db(TAOS *taos, char *database, int len, int *required) { + CHECK_INT(fp_taos_get_current_db); + return (*fp_taos_get_current_db)(taos, database, len, required); +} + +const char *taos_errstr(TAOS_RES *res) { + if (fp_taos_errstr == NULL) { + return tstrerror(terrno); + } + return (*fp_taos_errstr)(res); +} + +int taos_errno(TAOS_RES *res) { + if (fp_taos_errno == NULL) { + return terrno; + } + return (*fp_taos_errno)(res); +} + +void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param) { + CHECK_VOID(fp_taos_query_a); + (*fp_taos_query_a)(taos, sql, fp, param); +} + +void taos_query_a_with_reqid(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param, int64_t reqid) { + CHECK_VOID(fp_taos_query_a_with_reqid); + (*fp_taos_query_a_with_reqid)(taos, sql, fp, param, reqid); +} + +void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) { + CHECK_VOID(fp_taos_fetch_rows_a); + (*fp_taos_fetch_rows_a)(res, fp, param); +} + +void taos_fetch_raw_block_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) { + CHECK_VOID(fp_taos_fetch_raw_block_a); + (*fp_taos_fetch_raw_block_a)(res, fp, param); +} + +const void *taos_get_raw_block(TAOS_RES *res) { + CHECK_PTR(fp_taos_get_raw_block); + return (*fp_taos_get_raw_block)(res); +} + +int taos_get_db_route_info(TAOS *taos, const char *db, TAOS_DB_ROUTE_INFO *dbInfo) { + CHECK_INT(fp_taos_get_db_route_info); + return (*fp_taos_get_db_route_info)(taos, db, dbInfo); +} + +int taos_get_table_vgId(TAOS *taos, const char *db, const char *table, int *vgId) { + CHECK_INT(fp_taos_get_table_vgId); + return (*fp_taos_get_table_vgId)(taos, db, table, vgId); +} + +int taos_get_tables_vgId(TAOS *taos, const char *db, const char *table[], int tableNum, int *vgId) { + CHECK_INT(fp_taos_get_tables_vgId); + return (*fp_taos_get_tables_vgId)(taos, db, table, tableNum, vgId); +} + +int taos_load_table_info(TAOS *taos, const char *tableNameList) { + CHECK_INT(fp_taos_load_table_info); + return (*fp_taos_load_table_info)(taos, tableNameList); +} + +void taos_set_hb_quit(int8_t quitByKill) { + if (taos_init() != 0) { + return; + } + + CHECK_VOID(fp_taos_set_hb_quit); + return (*fp_taos_set_hb_quit)(quitByKill); +} + +int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t fp, void *param, int type) { + CHECK_INT(fp_taos_set_notify_cb); + return (*fp_taos_set_notify_cb)(taos, fp, param, type); +} + +void taos_fetch_whitelist_a(TAOS *taos, __taos_async_whitelist_fn_t fp, void *param) { + CHECK_VOID(fp_taos_fetch_whitelist_a); + return (*fp_taos_fetch_whitelist_a)(taos, fp, param); +} + +int taos_set_conn_mode(TAOS *taos, int mode, int value) { + CHECK_INT(fp_taos_set_conn_mode); + return (*fp_taos_set_conn_mode)(taos, mode, value); +} + +TAOS_RES *taos_schemaless_insert(TAOS *taos, char *lines[], int numLines, int protocol, int precision) { + CHECK_PTR(fp_taos_schemaless_insert); + return (*fp_taos_schemaless_insert)(taos, lines, numLines, protocol, precision); +} + +TAOS_RES *taos_schemaless_insert_with_reqid(TAOS *taos, char *lines[], int numLines, int protocol, int precision, + int64_t reqid) { + CHECK_PTR(fp_taos_schemaless_insert_with_reqid); + return (*fp_taos_schemaless_insert_with_reqid)(taos, lines, numLines, protocol, precision, reqid); +} + +TAOS_RES *taos_schemaless_insert_raw(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol, + int precision) { + CHECK_PTR(fp_taos_schemaless_insert_raw); + return (*fp_taos_schemaless_insert_raw)(taos, lines, len, totalRows, protocol, precision); +} + +TAOS_RES *taos_schemaless_insert_raw_with_reqid(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol, + int precision, int64_t reqid) { + CHECK_PTR(fp_taos_schemaless_insert_raw_with_reqid); + return (*fp_taos_schemaless_insert_raw_with_reqid)(taos, lines, len, totalRows, protocol, precision, reqid); +} + +TAOS_RES *taos_schemaless_insert_ttl(TAOS *taos, char *lines[], int numLines, int protocol, int precision, + int32_t ttl) { + CHECK_PTR(fp_taos_schemaless_insert_ttl); + return (*fp_taos_schemaless_insert_ttl)(taos, lines, numLines, protocol, precision, ttl); +} + +TAOS_RES *taos_schemaless_insert_ttl_with_reqid(TAOS *taos, char *lines[], int numLines, int protocol, int precision, + int32_t ttl, int64_t reqid) { + CHECK_PTR(fp_taos_schemaless_insert_ttl_with_reqid); + return (*fp_taos_schemaless_insert_ttl_with_reqid)(taos, lines, numLines, protocol, precision, ttl, reqid); +} + +TAOS_RES *taos_schemaless_insert_raw_ttl(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol, + int precision, int32_t ttl) { + CHECK_PTR(fp_taos_schemaless_insert_raw_ttl); + return (*fp_taos_schemaless_insert_raw_ttl)(taos, lines, len, totalRows, protocol, precision, ttl); +} + +TAOS_RES *taos_schemaless_insert_raw_ttl_with_reqid(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol, + int precision, int32_t ttl, int64_t reqid) { + CHECK_PTR(fp_taos_schemaless_insert_raw_ttl_with_reqid); + return (*fp_taos_schemaless_insert_raw_ttl_with_reqid)(taos, lines, len, totalRows, protocol, precision, ttl, reqid); +} + +TAOS_RES *taos_schemaless_insert_raw_ttl_with_reqid_tbname_key(TAOS *taos, char *lines, int len, int32_t *totalRows, + int protocol, int precision, int32_t ttl, int64_t reqid, + char *tbnameKey) { + CHECK_PTR(fp_taos_schemaless_insert_raw_ttl_with_reqid_tbname_key); + return (*fp_taos_schemaless_insert_raw_ttl_with_reqid_tbname_key)(taos, lines, len, totalRows, protocol, precision, + ttl, reqid, tbnameKey); +} + +TAOS_RES *taos_schemaless_insert_ttl_with_reqid_tbname_key(TAOS *taos, char *lines[], int numLines, int protocol, + int precision, int32_t ttl, int64_t reqid, char *tbnameKey) { + CHECK_PTR(fp_taos_schemaless_insert_ttl_with_reqid_tbname_key); + return (*fp_taos_schemaless_insert_ttl_with_reqid_tbname_key)(taos, lines, numLines, protocol, precision, ttl, reqid, + tbnameKey); +} + +tmq_conf_t *tmq_conf_new() { + CHECK_PTR(fp_tmq_conf_new); + return (*fp_tmq_conf_new)(); +} + +tmq_conf_res_t tmq_conf_set(tmq_conf_t *conf, const char *key, const char *value) { + CHECK_INT(fp_tmq_conf_set); + return (*fp_tmq_conf_set)(conf, key, value); +} + +void tmq_conf_destroy(tmq_conf_t *conf) { + CHECK_VOID(fp_tmq_conf_destroy); + (*fp_tmq_conf_destroy)(conf); +} + +void tmq_conf_set_auto_commit_cb(tmq_conf_t *conf, tmq_commit_cb *cb, void *param) { + CHECK_VOID(fp_tmq_conf_set_auto_commit_cb); + (*fp_tmq_conf_set_auto_commit_cb)(conf, cb, param); +} + +tmq_list_t *tmq_list_new() { + CHECK_PTR(fp_tmq_list_new); + return (*fp_tmq_list_new)(); +} + +int32_t tmq_list_append(tmq_list_t *tlist, const char *val) { + CHECK_INT(fp_tmq_list_append); + return (*fp_tmq_list_append)(tlist, val); +} + +void tmq_list_destroy(tmq_list_t *tlist) { + CHECK_VOID(fp_tmq_list_destroy); + (*fp_tmq_list_destroy)(tlist); +} + +int32_t tmq_list_get_size(const tmq_list_t *tlist) { + CHECK_INT(fp_tmq_list_get_size); + return (*fp_tmq_list_get_size)(tlist); +} + +char **tmq_list_to_c_array(const tmq_list_t *tlist) { + CHECK_PTR(fp_tmq_list_to_c_array); + return (*fp_tmq_list_to_c_array)(tlist); +} + +tmq_t *tmq_consumer_new(tmq_conf_t *conf, char *errstr, int32_t errstrLen) { + CHECK_PTR(fp_tmq_consumer_new); + return (*fp_tmq_consumer_new)(conf, errstr, errstrLen); +} + +int32_t tmq_subscribe(tmq_t *tmq, const tmq_list_t *topic_list) { + CHECK_INT(fp_tmq_subscribe); + return (*fp_tmq_subscribe)(tmq, topic_list); +} + +int32_t tmq_unsubscribe(tmq_t *tmq) { + CHECK_INT(fp_tmq_unsubscribe); + return (*fp_tmq_unsubscribe)(tmq); +} + +int32_t tmq_subscription(tmq_t *tmq, tmq_list_t **topics) { + CHECK_INT(fp_tmq_subscription); + return (*fp_tmq_subscription)(tmq, topics); +} + +TAOS_RES *tmq_consumer_poll(tmq_t *tmq, int64_t timeout) { + CHECK_PTR(fp_tmq_consumer_poll); + return (*fp_tmq_consumer_poll)(tmq, timeout); +} + +int32_t tmq_consumer_close(tmq_t *tmq) { + CHECK_INT(fp_tmq_consumer_close); + return (*fp_tmq_consumer_close)(tmq); +} + +int32_t tmq_commit_sync(tmq_t *tmq, const TAOS_RES *msg) { + CHECK_INT(fp_tmq_commit_sync); + return (*fp_tmq_commit_sync)(tmq, msg); +} + +void tmq_commit_async(tmq_t *tmq, const TAOS_RES *msg, tmq_commit_cb *cb, void *param) { + CHECK_VOID(fp_tmq_commit_async); + (*fp_tmq_commit_async)(tmq, msg, cb, param); +} + +int32_t tmq_commit_offset_sync(tmq_t *tmq, const char *pTopicName, int32_t vgId, int64_t offset) { + CHECK_INT(fp_tmq_commit_offset_sync); + return (*fp_tmq_commit_offset_sync)(tmq, pTopicName, vgId, offset); +} + +void tmq_commit_offset_async(tmq_t *tmq, const char *pTopicName, int32_t vgId, int64_t offset, tmq_commit_cb *cb, + void *param) { + CHECK_VOID(fp_tmq_commit_offset_async); + (*fp_tmq_commit_offset_async)(tmq, pTopicName, vgId, offset, cb, param); +} + +int32_t tmq_get_topic_assignment(tmq_t *tmq, const char *pTopicName, tmq_topic_assignment **assignment, + int32_t *numOfAssignment) { + CHECK_INT(fp_tmq_get_topic_assignment); + return (*fp_tmq_get_topic_assignment)(tmq, pTopicName, assignment, numOfAssignment); +} + +void tmq_free_assignment(tmq_topic_assignment *pAssignment) { + CHECK_VOID(fp_tmq_free_assignment); + (*fp_tmq_free_assignment)(pAssignment); +} + +int32_t tmq_offset_seek(tmq_t *tmq, const char *pTopicName, int32_t vgId, int64_t offset) { + CHECK_INT(fp_tmq_offset_seek); + return (*fp_tmq_offset_seek)(tmq, pTopicName, vgId, offset); +} + +int64_t tmq_position(tmq_t *tmq, const char *pTopicName, int32_t vgId) { + CHECK_INT(fp_tmq_position); + return (*fp_tmq_position)(tmq, pTopicName, vgId); +} + +int64_t tmq_committed(tmq_t *tmq, const char *pTopicName, int32_t vgId) { + CHECK_INT(fp_tmq_committed); + return (*fp_tmq_committed)(tmq, pTopicName, vgId); +} + +TAOS *tmq_get_connect(tmq_t *tmq) { + CHECK_PTR(fp_tmq_get_connect); + return (*fp_tmq_get_connect)(tmq); +} + +const char *tmq_get_table_name(TAOS_RES *res) { + CHECK_PTR(fp_tmq_get_table_name); + return (*fp_tmq_get_table_name)(res); +} + +tmq_res_t tmq_get_res_type(TAOS_RES *res) { + CHECK_INT(fp_tmq_get_res_type); + return (*fp_tmq_get_res_type)(res); +} + +const char *tmq_get_topic_name(TAOS_RES *res) { + CHECK_PTR(fp_tmq_get_topic_name); + return (*fp_tmq_get_topic_name)(res); +} + +const char *tmq_get_db_name(TAOS_RES *res) { + CHECK_PTR(fp_tmq_get_db_name); + return (*fp_tmq_get_db_name)(res); +} + +int32_t tmq_get_vgroup_id(TAOS_RES *res) { + CHECK_INT(fp_tmq_get_vgroup_id); + return (*fp_tmq_get_vgroup_id)(res); +} + +int64_t tmq_get_vgroup_offset(TAOS_RES *res) { + CHECK_INT(fp_tmq_get_vgroup_offset); + return (*fp_tmq_get_vgroup_offset)(res); +} + +const char *tmq_err2str(int32_t code) { + CHECK_PTR(fp_tmq_err2str); + return (*fp_tmq_err2str)(code); +} + +int32_t tmq_get_raw(TAOS_RES *res, tmq_raw_data *raw) { + CHECK_INT(fp_tmq_get_raw); + return (*fp_tmq_get_raw)(res, raw); +} + +int32_t tmq_write_raw(TAOS *taos, tmq_raw_data raw) { + CHECK_INT(fp_tmq_write_raw); + return (*fp_tmq_write_raw)(taos, raw); +} + +int taos_write_raw_block(TAOS *taos, int numOfRows, char *pData, const char *tbname) { + CHECK_INT(fp_taos_write_raw_block); + return (*fp_taos_write_raw_block)(taos, numOfRows, pData, tbname); +} + +int taos_write_raw_block_with_reqid(TAOS *taos, int numOfRows, char *pData, const char *tbname, int64_t reqid) { + CHECK_INT(fp_taos_write_raw_block_with_reqid); + return (*fp_taos_write_raw_block_with_reqid)(taos, numOfRows, pData, tbname, reqid); +} + +int taos_write_raw_block_with_fields(TAOS *taos, int rows, char *pData, const char *tbname, TAOS_FIELD *fields, + int numFields) { + CHECK_INT(fp_taos_write_raw_block_with_fields); + return (*fp_taos_write_raw_block_with_fields)(taos, rows, pData, tbname, fields, numFields); +} + +int taos_write_raw_block_with_fields_with_reqid(TAOS *taos, int rows, char *pData, const char *tbname, + TAOS_FIELD *fields, int numFields, int64_t reqid) { + CHECK_INT(fp_taos_write_raw_block_with_fields_with_reqid); + return (*fp_taos_write_raw_block_with_fields_with_reqid)(taos, rows, pData, tbname, fields, numFields, reqid); +} + +void tmq_free_raw(tmq_raw_data raw) { + CHECK_VOID(fp_tmq_free_raw); + (*fp_tmq_free_raw)(raw); +} + +char *tmq_get_json_meta(TAOS_RES *res) { + CHECK_PTR(fp_tmq_get_json_meta); + return (*fp_tmq_get_json_meta)(res); +} + +void tmq_free_json_meta(char *jsonMeta) { + CHECK_VOID(fp_tmq_free_json_meta); + return (*fp_tmq_free_json_meta)(jsonMeta); +} + +TSDB_SERVER_STATUS taos_check_server_status(const char *fqdn, int port, char *details, int maxlen) { + CHECK_INT(fp_taos_check_server_status); + return (*fp_taos_check_server_status)(fqdn, port, details, maxlen); +} + +void taos_write_crashinfo(int signum, void *sigInfo, void *context) { + CHECK_VOID(fp_taos_write_crashinfo); + (*fp_taos_write_crashinfo)(signum, sigInfo, context); +} + +char *getBuildInfo() { + CHECK_PTR(fp_getBuildInfo); + return (*fp_getBuildInfo)(); +} diff --git a/source/client/wrapper/src/wrapperVariable.c b/source/client/wrapper/src/wrapperVariable.c new file mode 100644 index 000000000000..a1eab91ba740 --- /dev/null +++ b/source/client/wrapper/src/wrapperVariable.c @@ -0,0 +1,204 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY = NULL; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "wrapper.h" + +setConfRet (*fp_taos_set_config)(const char *config) = NULL; + +int (*fp_taos_init)(void) = NULL; +void (*fp_taos_cleanup)(void) = NULL; +int (*fp_taos_options)(TSDB_OPTION option, const void *arg, ...) = NULL; +int (*fp_taos_options_connection)(TAOS *taos, TSDB_OPTION_CONNECTION option, const void *arg, ...) = NULL; +TAOS *(*fp_taos_connect)(const char *ip, const char *user, const char *pass, const char *db, uint16_t port) = NULL; +TAOS *(*fp_taos_connect_auth)(const char *ip, const char *user, const char *auth, const char *db, uint16_t port) = NULL; +void (*fp_taos_close)(TAOS *taos) = NULL; + +const char *(*fp_taos_data_type)(int type) = NULL; + +TAOS_STMT *(*fp_taos_stmt_init)(TAOS *taos) = NULL; +TAOS_STMT *(*fp_taos_stmt_init_with_reqid)(TAOS *taos, int64_t reqid) = NULL; +TAOS_STMT *(*fp_taos_stmt_init_with_options)(TAOS *taos, TAOS_STMT_OPTIONS *options) = NULL; +int (*fp_taos_stmt_prepare)(TAOS_STMT *stmt, const char *sql, unsigned long length) = NULL; +int (*fp_taos_stmt_set_tbname_tags)(TAOS_STMT *stmt, const char *name, TAOS_MULTI_BIND *tags) = NULL; +int (*fp_taos_stmt_set_tbname)(TAOS_STMT *stmt, const char *name) = NULL; +int (*fp_taos_stmt_set_tags)(TAOS_STMT *stmt, TAOS_MULTI_BIND *tags) = NULL; +int (*fp_taos_stmt_set_sub_tbname)(TAOS_STMT *stmt, const char *name) = NULL; +int (*fp_taos_stmt_get_tag_fields)(TAOS_STMT *stmt, int *fieldNum, TAOS_FIELD_E **fields) = NULL; +int (*fp_taos_stmt_get_col_fields)(TAOS_STMT *stmt, int *fieldNum, TAOS_FIELD_E **fields) = NULL; +void (*fp_taos_stmt_reclaim_fields)(TAOS_STMT *stmt, TAOS_FIELD_E *fields) = NULL; + +int (*fp_taos_stmt_is_insert)(TAOS_STMT *stmt, int *insert) = NULL; +int (*fp_taos_stmt_num_params)(TAOS_STMT *stmt, int *nums) = NULL; +int (*fp_taos_stmt_get_param)(TAOS_STMT *stmt, int idx, int *type, int *bytes) = NULL; +int (*fp_taos_stmt_bind_param)(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind) = NULL; +int (*fp_taos_stmt_bind_param_batch)(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind) = NULL; +int (*fp_taos_stmt_bind_single_param_batch)(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, int colIdx) = NULL; +int (*fp_taos_stmt_add_batch)(TAOS_STMT *stmt) = NULL; +int (*fp_taos_stmt_execute)(TAOS_STMT *stmt) = NULL; +TAOS_RES *(*fp_taos_stmt_use_result)(TAOS_STMT *stmt) = NULL; +int (*fp_taos_stmt_close)(TAOS_STMT *stmt) = NULL; +char *(*fp_taos_stmt_errstr)(TAOS_STMT *stmt) = NULL; +int (*fp_taos_stmt_affected_rows)(TAOS_STMT *stmt) = NULL; +int (*fp_taos_stmt_affected_rows_once)(TAOS_STMT *stmt) = NULL; + +TAOS_STMT2 *(*fp_taos_stmt2_init)(TAOS *taos, TAOS_STMT2_OPTION *option) = NULL; +int (*fp_taos_stmt2_prepare)(TAOS_STMT2 *stmt, const char *sql, unsigned long length) = NULL; +int (*fp_taos_stmt2_bind_param)(TAOS_STMT2 *stmt, TAOS_STMT2_BINDV *bindv, int32_t col_idx) = NULL; +int (*fp_taos_stmt2_bind_param_a)(TAOS_STMT2 *stmt, TAOS_STMT2_BINDV *bindv, int32_t col_idx, __taos_async_fn_t fp, + void *param) = NULL; +int (*fp_taos_stmt2_exec)(TAOS_STMT2 *stmt, int *affected_rows) = NULL; +int (*fp_taos_stmt2_close)(TAOS_STMT2 *stmt) = NULL; +int (*fp_taos_stmt2_is_insert)(TAOS_STMT2 *stmt, int *insert) = NULL; +int (*fp_taos_stmt2_get_fields)(TAOS_STMT2 *stmt, int *count, TAOS_FIELD_ALL **fields) = NULL; +void (*fp_taos_stmt2_free_fields)(TAOS_STMT2 *stmt, TAOS_FIELD_ALL *fields) = NULL; +TAOS_RES *(*fp_taos_stmt2_result)(TAOS_STMT2 *stmt) = NULL; +char *(*fp_taos_stmt2_error)(TAOS_STMT2 *stmt) = NULL; + +TAOS_RES *(*fp_taos_query)(TAOS *taos, const char *sql) = NULL; +TAOS_RES *(*fp_taos_query_with_reqid)(TAOS *taos, const char *sql, int64_t reqId) = NULL; + +TAOS_ROW (*fp_taos_fetch_row)(TAOS_RES *res) = NULL; +int (*fp_taos_result_precision)(TAOS_RES *res) = NULL; // get the time precision of result +void (*fp_taos_free_result)(TAOS_RES *res) = NULL; +void (*fp_taos_kill_query)(TAOS *taos) = NULL; +int (*fp_taos_field_count)(TAOS_RES *res) = NULL; +int (*fp_taos_num_fields)(TAOS_RES *res) = NULL; +int (*fp_taos_affected_rows)(TAOS_RES *res) = NULL; +int64_t (*fp_taos_affected_rows64)(TAOS_RES *res) = NULL; + +TAOS_FIELD *(*fp_taos_fetch_fields)(TAOS_RES *res) = NULL; +int (*fp_taos_select_db)(TAOS *taos, const char *db) = NULL; +int (*fp_taos_print_row)(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields) = NULL; +int (*fp_taos_print_row_with_size)(char *str, uint32_t size, TAOS_ROW row, TAOS_FIELD *fields, int num_fields) = NULL; +void (*fp_taos_stop_query)(TAOS_RES *res) = NULL; +bool (*fp_taos_is_null)(TAOS_RES *res, int32_t row, int32_t col) = NULL; +int (*fp_taos_is_null_by_column)(TAOS_RES *res, int columnIndex, bool result[], int *rows) = NULL; +bool (*fp_taos_is_update_query)(TAOS_RES *res) = NULL; +int (*fp_taos_fetch_block)(TAOS_RES *res, TAOS_ROW *rows) = NULL; +int (*fp_taos_fetch_block_s)(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows) = NULL; +int (*fp_taos_fetch_raw_block)(TAOS_RES *res, int *numOfRows, void **pData) = NULL; +int *(*fp_taos_get_column_data_offset)(TAOS_RES *res, int columnIndex) = NULL; +int (*fp_taos_validate_sql)(TAOS *taos, const char *sql) = NULL; +void (*fp_taos_reset_current_db)(TAOS *taos) = NULL; + +int *(*fp_taos_fetch_lengths)(TAOS_RES *res) = NULL; +TAOS_ROW *(*fp_taos_result_block)(TAOS_RES *res) = NULL; + +const char *(*fp_taos_get_server_info)(TAOS *taos) = NULL; +const char *(*fp_taos_get_client_info)() = NULL; +int (*fp_taos_get_current_db)(TAOS *taos, char *database, int len, int *required) = NULL; + +const char *(*fp_taos_errstr)(TAOS_RES *res) = NULL; +int (*fp_taos_errno)(TAOS_RES *res) = NULL; + +void (*fp_taos_query_a)(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param) = NULL; +void (*fp_taos_query_a_with_reqid)(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param, + int64_t reqid) = NULL; +void (*fp_taos_fetch_rows_a)(TAOS_RES *res, __taos_async_fn_t fp, void *param) = NULL; +void (*fp_taos_fetch_raw_block_a)(TAOS_RES *res, __taos_async_fn_t fp, void *param) = NULL; +const void *(*fp_taos_get_raw_block)(TAOS_RES *res) = NULL; + +int (*fp_taos_get_db_route_info)(TAOS *taos, const char *db, TAOS_DB_ROUTE_INFO *dbInfo) = NULL; +int (*fp_taos_get_table_vgId)(TAOS *taos, const char *db, const char *table, int *vgId) = NULL; +int (*fp_taos_get_tables_vgId)(TAOS *taos, const char *db, const char *table[], int tableNum, int *vgId) = NULL; + +int (*fp_taos_load_table_info)(TAOS *taos, const char *tableNameList) = NULL; + +void (*fp_taos_set_hb_quit)(int8_t quitByKill) = NULL; + +int (*fp_taos_set_notify_cb)(TAOS *taos, __taos_notify_fn_t fp, void *param, int type) = NULL; + +void (*fp_taos_fetch_whitelist_a)(TAOS *taos, __taos_async_whitelist_fn_t fp, void *param) = NULL; + +int (*fp_taos_set_conn_mode)(TAOS *taos, int mode, int value) = NULL; + +TAOS_RES *(*fp_taos_schemaless_insert)(TAOS *taos, char *lines[], int numLines, int protocol, int precision) = NULL; +TAOS_RES *(*fp_taos_schemaless_insert_with_reqid)(TAOS *taos, char *lines[], int numLines, int protocol, int precision, + int64_t reqid) = NULL; +TAOS_RES *(*fp_taos_schemaless_insert_raw)(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol, + int precision) = NULL; +TAOS_RES *(*fp_taos_schemaless_insert_raw_with_reqid)(TAOS *taos, char *lines, int len, int32_t *totalRows, + int protocol, int precision, int64_t reqid) = NULL; +TAOS_RES *(*fp_taos_schemaless_insert_ttl)(TAOS *taos, char *lines[], int numLines, int protocol, int precision, + int32_t ttl) = NULL; +TAOS_RES *(*fp_taos_schemaless_insert_ttl_with_reqid)(TAOS *taos, char *lines[], int numLines, int protocol, + int precision, int32_t ttl, int64_t reqid) = NULL; +TAOS_RES *(*fp_taos_schemaless_insert_raw_ttl)(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol, + int precision, int32_t ttl) = NULL; +TAOS_RES *(*fp_taos_schemaless_insert_raw_ttl_with_reqid)(TAOS *taos, char *lines, int len, int32_t *totalRows, + int protocol, int precision, int32_t ttl, + int64_t reqid) = NULL; +TAOS_RES *(*fp_taos_schemaless_insert_raw_ttl_with_reqid_tbname_key)(TAOS *taos, char *lines, int len, + int32_t *totalRows, int protocol, int precision, + int32_t ttl, int64_t reqid, + char *tbnameKey) = NULL; +TAOS_RES *(*fp_taos_schemaless_insert_ttl_with_reqid_tbname_key)(TAOS *taos, char *lines[], int numLines, int protocol, + int precision, int32_t ttl, int64_t reqid, + char *tbnameKey) = NULL; + +tmq_conf_t *(*fp_tmq_conf_new)() = NULL; +tmq_conf_res_t (*fp_tmq_conf_set)(tmq_conf_t *conf, const char *key, const char *value) = NULL; +void (*fp_tmq_conf_destroy)(tmq_conf_t *conf) = NULL; +void (*fp_tmq_conf_set_auto_commit_cb)(tmq_conf_t *conf, tmq_commit_cb *cb, void *param) = NULL; + +tmq_list_t *(*fp_tmq_list_new)() = NULL; +int32_t (*fp_tmq_list_append)(tmq_list_t *, const char *) = NULL; +void (*fp_tmq_list_destroy)(tmq_list_t *) = NULL; +int32_t (*fp_tmq_list_get_size)(const tmq_list_t *) = NULL; +char **(*fp_tmq_list_to_c_array)(const tmq_list_t *) = NULL; + +tmq_t *(*fp_tmq_consumer_new)(tmq_conf_t *conf, char *errstr, int32_t errstrLen) = NULL; +int32_t (*fp_tmq_subscribe)(tmq_t *tmq, const tmq_list_t *topic_list) = NULL; +int32_t (*fp_tmq_unsubscribe)(tmq_t *tmq) = NULL; +int32_t (*fp_tmq_subscription)(tmq_t *tmq, tmq_list_t **topics) = NULL; +TAOS_RES *(*fp_tmq_consumer_poll)(tmq_t *tmq, int64_t timeout) = NULL; +int32_t (*fp_tmq_consumer_close)(tmq_t *tmq) = NULL; +int32_t (*fp_tmq_commit_sync)(tmq_t *tmq, const TAOS_RES *msg) = NULL; +void (*fp_tmq_commit_async)(tmq_t *tmq, const TAOS_RES *msg, tmq_commit_cb *cb, void *param) = NULL; +int32_t (*fp_tmq_commit_offset_sync)(tmq_t *tmq, const char *pTopicName, int32_t vgId, int64_t offset) = NULL; +void (*fp_tmq_commit_offset_async)(tmq_t *tmq, const char *pTopicName, int32_t vgId, int64_t offset, tmq_commit_cb *cb, + void *param) = NULL; +int32_t (*fp_tmq_get_topic_assignment)(tmq_t *tmq, const char *pTopicName, tmq_topic_assignment **assignment, + int32_t *numOfAssignment) = NULL; +void (*fp_tmq_free_assignment)(tmq_topic_assignment *pAssignment) = NULL; +int32_t (*fp_tmq_offset_seek)(tmq_t *tmq, const char *pTopicName, int32_t vgId, int64_t offset) = NULL; +int64_t (*fp_tmq_position)(tmq_t *tmq, const char *pTopicName, int32_t vgId) = NULL; +int64_t (*fp_tmq_committed)(tmq_t *tmq, const char *pTopicName, int32_t vgId) = NULL; + +TAOS *(*fp_tmq_get_connect)(tmq_t *tmq) = NULL; +const char *(*fp_tmq_get_table_name)(TAOS_RES *res) = NULL; +tmq_res_t (*fp_tmq_get_res_type)(TAOS_RES *res) = NULL; +const char *(*fp_tmq_get_topic_name)(TAOS_RES *res) = NULL; +const char *(*fp_tmq_get_db_name)(TAOS_RES *res) = NULL; +int32_t (*fp_tmq_get_vgroup_id)(TAOS_RES *res) = NULL; +int64_t (*fp_tmq_get_vgroup_offset)(TAOS_RES *res) = NULL; +const char *(*fp_tmq_err2str)(int32_t code) = NULL; + +int32_t (*fp_tmq_get_raw)(TAOS_RES *res, tmq_raw_data *raw) = NULL; +int32_t (*fp_tmq_write_raw)(TAOS *taos, tmq_raw_data raw) = NULL; +int (*fp_taos_write_raw_block)(TAOS *taos, int numOfRows, char *pData, const char *tbname) = NULL; +int (*fp_taos_write_raw_block_with_reqid)(TAOS *taos, int numOfRows, char *pData, const char *tbname, + int64_t reqid) = NULL; +int (*fp_taos_write_raw_block_with_fields)(TAOS *taos, int rows, char *pData, const char *tbname, TAOS_FIELD *fields, + int numFields) = NULL; +int (*fp_taos_write_raw_block_with_fields_with_reqid)(TAOS *taos, int rows, char *pData, const char *tbname, + TAOS_FIELD *fields, int numFields, int64_t reqid) = NULL; +void (*fp_tmq_free_raw)(tmq_raw_data raw) = NULL; +char *(*fp_tmq_get_json_meta)(TAOS_RES *res) = NULL; +void (*fp_tmq_free_json_meta)(char *jsonMeta) = NULL; + +TSDB_SERVER_STATUS (*fp_taos_check_server_status)(const char *fqdn, int port, char *details, int maxlen) = NULL; +void (*fp_taos_write_crashinfo)(int signum, void *sigInfo, void *context) = NULL; +char *(*fp_getBuildInfo)() = NULL; diff --git a/source/dnode/mgmt/node_util/CMakeLists.txt b/source/dnode/mgmt/node_util/CMakeLists.txt index 320da4506560..ad8282f87fc7 100644 --- a/source/dnode/mgmt/node_util/CMakeLists.txt +++ b/source/dnode/mgmt/node_util/CMakeLists.txt @@ -6,5 +6,5 @@ target_include_directories( PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) target_link_libraries( - node_util cjson mnode vnode qnode snode wal sync ${TAOS_LIB_STATIC} tfs monitor monitorfw + node_util cjson mnode vnode qnode snode wal sync ${TAOS_NATIVE_LIB_STATIC} tfs monitor monitorfw ) \ No newline at end of file diff --git a/source/libs/catalog/test/CMakeLists.txt b/source/libs/catalog/test/CMakeLists.txt index f23a6beaee91..f3b82fd62456 100644 --- a/source/libs/catalog/test/CMakeLists.txt +++ b/source/libs/catalog/test/CMakeLists.txt @@ -9,7 +9,7 @@ IF(NOT TD_DARWIN) ADD_EXECUTABLE(catalogTest ${SOURCE_LIST}) TARGET_LINK_LIBRARIES( catalogTest - PUBLIC os util common nodes catalog transport gtest qcom ${TAOS_LIB_STATIC} + PUBLIC os util common nodes catalog transport gtest qcom ${TAOS_NATIVE_LIB_STATIC} ) TARGET_INCLUDE_DIRECTORIES( @@ -19,7 +19,7 @@ IF(NOT TD_DARWIN) ) add_test( - NAME catalogTest - COMMAND catalogTest + NAME catalogTest + COMMAND catalogTest ) ENDIF() diff --git a/source/libs/executor/test/CMakeLists.txt b/source/libs/executor/test/CMakeLists.txt index 4136640847f2..ab64dd85d41f 100644 --- a/source/libs/executor/test/CMakeLists.txt +++ b/source/libs/executor/test/CMakeLists.txt @@ -9,7 +9,7 @@ MESSAGE(STATUS "build parser unit test") # ADD_EXECUTABLE(executorTest ${SOURCE_LIST}) # TARGET_LINK_LIBRARIES( # executorTest -# PRIVATE os util common transport gtest ${TAOS_LIB_STATIC} qcom executor function planner scalar nodes vnode +# PRIVATE os util common transport gtest ${TAOS_NATIVE_LIB_STATIC} qcom executor function planner scalar nodes vnode # ) # # TARGET_INCLUDE_DIRECTORIES( diff --git a/source/libs/scheduler/test/CMakeLists.txt b/source/libs/scheduler/test/CMakeLists.txt index d9572e8decd1..ac06d1e16729 100644 --- a/source/libs/scheduler/test/CMakeLists.txt +++ b/source/libs/scheduler/test/CMakeLists.txt @@ -8,15 +8,15 @@ IF(NOT TD_DARWIN) ADD_EXECUTABLE(schedulerTest ${SOURCE_LIST}) - IF (TD_GRANT) + IF(TD_GRANT) TARGET_LINK_LIBRARIES( schedulerTest - PUBLIC os util common catalog transport gtest qcom ${TAOS_LIB_STATIC} planner scheduler grant + PUBLIC os util common catalog transport gtest qcom ${TAOS_NATIVE_LIB_STATIC} planner scheduler grant ) - ELSE () + ELSE() TARGET_LINK_LIBRARIES( schedulerTest - PUBLIC os util common catalog transport gtest qcom ${TAOS_LIB_STATIC} planner scheduler + PUBLIC os util common catalog transport gtest qcom ${TAOS_NATIVE_LIB_STATIC} planner scheduler ) ENDIF() @@ -28,6 +28,5 @@ IF(NOT TD_DARWIN) add_test( NAME schedulerTest COMMAND schedulerTest - ) - + ) ENDIF() \ No newline at end of file diff --git a/source/os/CMakeLists.txt b/source/os/CMakeLists.txt index 6b33e68377db..9fafe0ac89a6 100644 --- a/source/os/CMakeLists.txt +++ b/source/os/CMakeLists.txt @@ -16,21 +16,26 @@ target_include_directories( PUBLIC "${TD_SOURCE_DIR}/contrib/msvcregex" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) + # iconv if(TD_WINDOWS) find_path(IconvApiIncludes iconv.h "${TD_SOURCE_DIR}/contrib/iconv") else() find_path(IconvApiIncludes iconv.h PATHS) endif(TD_WINDOWS) + if(NOT IconvApiIncludes) - add_definitions(-DDISALLOW_NCHAR_WITHOUT_ICONV) -endif () + add_definitions(-DDISALLOW_NCHAR_WITHOUT_ICONV) +endif() + if(USE_TD_MEMORY) - add_definitions(-DUSE_TD_MEMORY) -endif () + add_definitions(-DUSE_TD_MEMORY) +endif() + if(BUILD_WITH_RAND_ERR) - add_definitions(-DBUILD_WITH_RAND_ERR) -endif () + add_definitions(-DBUILD_WITH_RAND_ERR) +endif() + if(BUILD_ADDR2LINE) if(NOT TD_WINDOWS) target_include_directories( @@ -41,31 +46,35 @@ if(BUILD_ADDR2LINE) os PUBLIC addr2line dl z ) endif() + add_definitions(-DUSE_ADDR2LINE) -endif () +endif() + if(CHECK_STR2INT_ERROR) add_definitions(-DTD_CHECK_STR_TO_INT_ERROR) endif() + target_link_libraries( os PUBLIC pthread PUBLIC zlibstatic ) + if(TD_WINDOWS) target_link_libraries( os PUBLIC ws2_32 iconv msvcregex wcwidth winmm crashdump dbghelp version KtmW32 ) elseif(TD_DARWIN_64) find_library(CORE_FOUNDATION_FRAMEWORK CoreFoundation) - target_link_libraries(os PUBLIC ${CORE_FOUNDATION_FRAMEWORK}) + target_link_libraries(os PUBLIC ${CORE_FOUNDATION_FRAMEWORK}) find_library(SYSTEM_CONFIGURATION_FRAMEWORK SystemConfiguration) - target_link_libraries(os PUBLIC ${SYSTEM_CONFIGURATION_FRAMEWORK}) + target_link_libraries(os PUBLIC ${SYSTEM_CONFIGURATION_FRAMEWORK}) target_link_libraries( os PUBLIC dl m iconv ) elseif(TD_ALPINE) target_link_libraries( - os PUBLIC dl m rt unwind + os PUBLIC dl m rt unwind ) else() target_link_libraries( @@ -73,9 +82,9 @@ else() ) endif() -IF (JEMALLOC_ENABLED) +IF(JEMALLOC_ENABLED) target_link_libraries(os PUBLIC -L${CMAKE_BINARY_DIR}/build/lib -ljemalloc) -ENDIF () +ENDIF() #if(NOT ${TD_WINDOWS}) # find_library(tz libtz.a "${TD_SOURCE_DIR}/contrib/tz") @@ -85,3 +94,4 @@ ENDIF () if(${BUILD_TEST}) add_subdirectory(test) endif(${BUILD_TEST}) + diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index 410f9da623be..03ed07fc8895 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -58,7 +58,7 @@ int32_t wordexp(char *words, wordexp_t *pwordexp, int32_t flags) { void wordfree(wordexp_t *pwordexp) {} #elif defined(DARWIN) - +#include #include #include #include @@ -77,6 +77,7 @@ typedef struct TdDir { #else +#include #include #include #include @@ -361,7 +362,7 @@ int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) { int32_t taosRealPath(char *dirname, char *realPath, int32_t maxlen) { OS_PARAM_CHECK(dirname); - char tmp[PATH_MAX] = {0}; + char tmp[PATH_MAX + 1] = {0}; #ifdef WINDOWS if (_fullpath(tmp, dirname, maxlen) != NULL) { #else @@ -584,6 +585,24 @@ void taosGetCwd(char *buf, int32_t len) { #endif } +int32_t taosAppPath(char *path, int32_t maxLen) { + int32_t ret = 0; + +#ifdef WINDOWS + ret = GetModuleFileName(NULL, path, maxLen - 1); +#elif defined(DARWIN) + ret = _NSGetExecutablePath(path, &maxLen) ; +#else + ret = readlink("/proc/self/exe", path, maxLen - 1); +#endif + + if (ret >= 0) { + ret = (taosDirName(path) == NULL) ? -1 : 0; + } + + return ret; +} + int32_t taosGetDirSize(const char *path, int64_t *size) { int32_t code = 0; char fullPath[PATH_MAX + 100] = {0}; @@ -620,3 +639,54 @@ int32_t taosGetDirSize(const char *path, int64_t *size) { TAOS_UNUSED(taosCloseDir(&pDir)); return code; } + + +void* taosLoadDll(const char* fileName) { +#if defined(WINDOWS) + void* handle = LoadLibraryA(fileName); +#else + void* handle = dlopen(fileName, RTLD_LAZY); +#endif + + if (handle == NULL) { + if (errno != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + } else { + terrno = TSDB_CODE_DLL_NOT_LOAD; + } + } + + return handle; +} + +void taosCloseDll(void* handle) { + if (handle == NULL) return; + +#if defined(WINDOWS) + FreeLibrary((HMODULE)handle); +#else + if (dlclose(handle) != 0 && errno != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + } +#endif +} + +void* taosLoadDllFunc(void* handle, const char* funcName) { + if (handle == NULL) return NULL; + +#if defined(WINDOWS) + void *fptr = GetProcAddress((HMODULE)handle, funcName); +#else + void *fptr = dlsym(handle, funcName); +#endif + + if (handle == NULL) { + if (errno != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + } else { + terrno = TSDB_CODE_DLL_FUNC_NOT_LOAD; + } + } + + return fptr; +} diff --git a/source/os/src/osSystem.c b/source/os/src/osSystem.c index fefada214218..eb483647631b 100644 --- a/source/os/src/osSystem.c +++ b/source/os/src/osSystem.c @@ -75,7 +75,6 @@ void stratWindowsService(MainWindows mainWindows) { StartServiceCtrlDispatcher(ServiceTable); } -#elif defined(_TD_DARWIN_64) #else #include #include @@ -88,38 +87,6 @@ struct termios oldtio; typedef struct FILE TdCmd; -#ifdef BUILD_NO_CALL -void* taosLoadDll(const char* filename) { -#if defined(WINDOWS) - return NULL; -#elif defined(_TD_DARWIN_64) - return NULL; -#else - void* handle = dlopen(filename, RTLD_LAZY); - if (!handle) { - // printf("load dll:%s failed, error:%s", filename, dlerror()); - return NULL; - } - - // printf("dll %s loaded", filename); - - return handle; -#endif -} - -void taosCloseDll(void* handle) { -#if defined(WINDOWS) - return; -#elif defined(_TD_DARWIN_64) - return; -#else - if (handle) { - dlclose(handle); - } -#endif -} -#endif - int32_t taosSetConsoleEcho(bool on) { #if defined(WINDOWS) HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE); diff --git a/source/util/src/terror.c b/source/util/src/terror.c index cbc7f4d1be2a..91b5780ed046 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -76,7 +76,8 @@ TAOS_DEFINE_ERROR(TSDB_CODE_REF_ID_REMOVED, "Ref ID is removed") TAOS_DEFINE_ERROR(TSDB_CODE_REF_INVALID_ID, "Invalid Ref ID") TAOS_DEFINE_ERROR(TSDB_CODE_REF_ALREADY_EXIST, "Ref is already there") TAOS_DEFINE_ERROR(TSDB_CODE_REF_NOT_EXIST, "Ref is not there") - +TAOS_DEFINE_ERROR(TSDB_CODE_DLL_NOT_LOAD, "Driver was not loaded") +TAOS_DEFINE_ERROR(TSDB_CODE_DLL_FUNC_NOT_LOAD, "Function was not loaded from the driver") TAOS_DEFINE_ERROR(TSDB_CODE_APP_ERROR, "Unexpected generic error") TAOS_DEFINE_ERROR(TSDB_CODE_ACTION_IN_PROGRESS, "Action in progress") TAOS_DEFINE_ERROR(TSDB_CODE_OUT_OF_RANGE, "Out of range") diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index 2460c7c650ec..1af6703109c5 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -1230,7 +1230,7 @@ bool taosAssertDebug(bool condition, const char *file, int32_t line, bool core, return true; } -void taosLogCrashInfo(char *nodeType, char *pMsg, int64_t msgLen, int signum, void *sigInfo) { +void taosLogCrashInfo(const char *nodeType, char *pMsg, int64_t msgLen, int signum, void *sigInfo) { const char *flags = "UTL FATAL "; ELogLevel level = DEBUG_FATAL; int32_t dflag = 255; @@ -1357,7 +1357,10 @@ static void checkWriteCrashLogToFileInNewThead() { } taosLogCrashInfo(gCrashBasicInfo.nodeType, pMsg, msgLen, gCrashBasicInfo.signum, gCrashBasicInfo.sigInfo); setCrashWriterStatus(CRASH_LOG_WRITER_INIT); - tsem_post(&gCrashBasicInfo.sem); + int32_t code = tsem_post(&gCrashBasicInfo.sem); + if (code != 0 ) { + uError("failed to post sem for crashBasicInfo, code:%d", code); + } } } @@ -1386,7 +1389,10 @@ void writeCrashLogToFile(int signum, void *sigInfo, char *nodeType, int64_t clus gCrashBasicInfo.nodeType = nodeType; gCrashBasicInfo.signum = signum; gCrashBasicInfo.sigInfo = sigInfo; - tsem_wait(&gCrashBasicInfo.sem); + int32_t code = tsem_wait(&gCrashBasicInfo.sem); + if (code != 0 ) { + uError("failed to wait sem for crashBasicInfo, code:%d", code); + } } } diff --git a/source/util/test/errorCodeTable.ini b/source/util/test/errorCodeTable.ini index f66948504d4e..c135b677bff0 100644 --- a/source/util/test/errorCodeTable.ini +++ b/source/util/test/errorCodeTable.ini @@ -17,6 +17,8 @@ TSDB_CODE_REF_ID_REMOVED = 0x80000107 TSDB_CODE_REF_INVALID_ID = 0x80000108 TSDB_CODE_REF_ALREADY_EXIST = 0x80000109 TSDB_CODE_REF_NOT_EXIST = 0x8000010A +TSDB_CODE_DLL_NOT_LOAD = 0x8000010B +TSDB_CODE_DLL_FUNC_NOT_LOAD = 0x8000010C TSDB_CODE_APP_ERROR = 0x80000110 TSDB_CODE_ACTION_IN_PROGRESS = 0x80000111 TSDB_CODE_OUT_OF_RANGE = 0x80000112 diff --git a/tests/army/cmdline/taosCli.py b/tests/army/cmdline/taosCli.py index ba52ba97bee8..fe39546527ff 100644 --- a/tests/army/cmdline/taosCli.py +++ b/tests/army/cmdline/taosCli.py @@ -57,31 +57,29 @@ def checkDescribe(self): def checkResultWithMode(self, db, stb, arg): result = "Query OK, 10 row(s)" mode = arg[0] - rowh = arg[1] - rowv = arg[2] - idx = arg[3] - idxv = arg[4] # use db - if mode != "-R": - rlist = self.taos(f'{mode} -s "show databases;use {db};show databases;" ') - self.checkListString(rlist, "Database changed") + rlist = self.taos(f'{mode} -s "show databases;use {db};show databases;" ') + self.checkListString(rlist, "Database changed") # hori - cmd = f'{mode} -s "select * from {db}.{stb} limit 10' + cmd = f'{mode} -s "select ts,ic from {db}.{stb} limit 10' rlist = self.taos(cmd + '"') - # line count - self.checkSame(len(rlist), rowh) - # last line - self.checkSame(rlist[idx][:len(result)], result) + results = [ + "2022-10-01 00:00:09.000 |", + result + ] + self.checkManyString(rlist, results) # vec rlist = self.taos(cmd + '\G"') - # line count - self.checkSame(len(rlist), rowv) - self.checkSame(rlist[idxv], "*************************** 10.row ***************************") - # last line - self.checkSame(rlist[idx][:len(result)], result) + results = [ + "****** 10.row *******", + "ts: 2022-10-01 00:00:09.000", + result + ] + self.checkManyString(rlist, results) + # -B have some problem need todo self.taos(f'{mode} -B -s "select * from {db}.{stb} where ts < 1"') @@ -96,12 +94,16 @@ def checkBasic(self): # insert json = "cmdline/json/taosCli.json" db, stb, childCount, insertRows = self.insertBenchJson(json) + # set + self.db = db + self.stb = stb + self.insert_rows = insertRows + self.childtable_count = childCount # native restful websock test args = [ - ["", 18, 346, -2, 310], - ["-R", 22, 350, -3, 313], - ["-T 40 -E http://localhost:6041", 21, 349, -3, 312] + ["-Z native"], + ["-T 40 -E http://localhost:6041"] ] for arg in args: self.checkResultWithMode(db, stb, arg) @@ -133,8 +135,7 @@ def checkDumpInOutMode(self, source, arg, db, insertRows): def checkDumpInOut(self): args = [ - ["", 18], - ["-R ", 22], + ["", 18], ["-E http://localhost:6041", 21] ] @@ -150,10 +151,18 @@ def checkVersion(self): rlist2 = self.taos("--version") self.checkSame(rlist1, rlist2) - self.checkSame(len(rlist1), 5) + if len(rlist1) < 4: + tdLog.exit(f"version lines less than 4. {rlist1}") if len(rlist1[2]) < 42: tdLog.exit("git commit id length is invalid: " + rlist1[2]) + + keys = [ + "version:", + "git:", + "build:" + ] + self.checkManyString(rlist1, keys) def checkHelp(self): @@ -182,9 +191,9 @@ def checkCommand(self): # invalid input check args = [ - [lname, "failed to create log at"], + #[lname, "failed to create log at"], ['-uroot -w 40 -ptaosdata -c /root/taos/ -s"show databases"', queryOK], - ['-o "./current/log/files/" -s"show databases;"', queryOK], + ['-o "./current/log/files/" -h localhost -uroot -ptaosdata -s"show databases;"', queryOK], ['-a ""', "Invalid auth"], ['-s "quit;"', "Welcome to the TDengine Command Line Interface"], ['-a "abc"', "[0x80000357]"], @@ -195,7 +204,7 @@ def checkCommand(self): ['-p"abc" -s "show dnodes;"', "[0x80000357]"], ['-d "abc" -s "show dnodes;"', "[0x80000388]"], ['-N 0 -s "show dnodes;"', "Invalid pktNum"], - ['-N 10 -s "show dnodes;"', queryOK], + ['-N 10 -h 127.0.0.1 -s "show dnodes;"', queryOK], ['-w 0 -s "show dnodes;"', "Invalid displayWidth"], ['-w 10 -s "show dnodes;"', queryOK], ['-W 10 -s "show dnodes;"', None], @@ -209,10 +218,116 @@ def checkCommand(self): ['-uroot -p < cmdline/data/pwd.txt -s "show dnodes;"', queryOK], ] - for arg in args: - rlist = self.taos(arg[0]) - if arg[1] != None: - self.checkListString(rlist, arg[1]) + modes = ["-Z 0","-Z 1"] + for mode in modes: + for arg in args: + rlist = self.taos(mode + " " + arg[0]) + if arg[1] != None: + self.checkListString(rlist, arg[1]) + + + # expect cmd > json > evn + def checkPriority(self): + # + # cmd & env + # + + # env 6043 - invalid + os.environ['TDENGINE_CLOUD_DSN'] = "http://127.0.0.1:6043" + # cmd 6041 - valid + cmd = f"-X http://127.0.0.1:6041 -s 'select ts from test.meters'" + rlist = self.taos(cmd, checkRun = True) + results = [ + "WebSocket Client Version", + "2022-10-01 00:01:39.000", + "Query OK, 200 row(s) in set" + ] + self.checkManyString(rlist, results) + + # + # env + # + + # cloud + os.environ['TDENGINE_CLOUD_DSN'] = "http://127.0.0.1:6041" + cmd = f"-s 'select ts from test.meters'" + rlist = self.taos(cmd, checkRun = True) + self.checkManyString(rlist, results) + # local + os.environ['TDENGINE_CLOUD_DSN'] = "" + os.environ['TDENGINE_DSN'] = "http://127.0.0.1:6041" + cmd = f"-s 'select ts from test.meters'" + rlist = self.taos(cmd, checkRun = True) + self.checkManyString(rlist, results) + # local & cloud -> cloud first + os.environ['TDENGINE_CLOUD_DSN'] = "http://127.0.0.1:6041" # valid + os.environ['TDENGINE_DSN'] = "http://127.0.0.1:6042" # invalid + cmd = f"-s 'select ts from test.meters'" + rlist = self.taos(cmd, checkRun = True) + self.checkManyString(rlist, results) + + + # + # cmd + # + + os.environ['TDENGINE_CLOUD_DSN'] = "" + os.environ['TDENGINE_DSN'] = "" + cmd = f"-X http://127.0.0.1:6041 -s 'select ts from test.meters'" + rlist = self.taos(cmd, checkRun = True) + self.checkManyString(rlist, results) + + + def checkExceptCmd(self): + # exe + taos = frame.etool.taosFile() + # option + options = [ + "-Z native -X http://127.0.0.1:6041", + "-Z 100", + "-Z abcdefg", + "-X", + "-X ", + "-X 127.0.0.1:6041", + "-X https://gw.cloud.taosdata.com?token617ffdf...", + "-Z 1 -X https://gw.cloud.taosdata.com?token=617ffdf...", + "-X http://127.0.0.1:6042" + ] + + # do check + for option in options: + self.checkExcept(taos + " -s 'show dnodes;' " + option) + + def checkModeVersion(self): + # results + results = [ + "WebSocket Client Version", + "2022-10-01 00:01:39.000", + "Query OK, 100 row(s) in set" + ] + + # default + cmd = f"-s 'select ts from test.d0'" + rlist = self.taos(cmd, checkRun = True) + self.checkManyString(rlist, results) + # websocket + cmd = f"-Z 1 -s 'select ts from test.d0'" + rlist = self.taos(cmd, checkRun = True) + self.checkManyString(rlist, results) + + # native + cmd = f"-Z 0 -s 'select ts from test.d0'" + results[0] = "Native Client Version" + rlist = self.taos(cmd, checkRun = True) + self.checkManyString(rlist, results) + + def checkConnMode(self): + # priority + self.checkPriority() + # except + self.checkExceptCmd() + # mode version + self.checkModeVersion() # run def run(self): @@ -236,6 +351,9 @@ def run(self): # check data in/out self.checkDumpInOut() + # check conn mode + self.checkConnMode() + tdLog.success(f"{__file__} successfully executed") diff --git a/tests/army/frame/caseBase.py b/tests/army/frame/caseBase.py index 4427ddcea59d..5e1ebc7039f8 100644 --- a/tests/army/frame/caseBase.py +++ b/tests/army/frame/caseBase.py @@ -35,6 +35,12 @@ class TBase: # init def init(self, conn, logSql, replicaVar=1, db="db", stb="stb", checkColName="ic"): + + # init + self.childtable_count = 0 + self.insert_rows = 0 + self.timestamp_step = 0 + # save param self.replicaVar = int(replicaVar) tdSql.init(conn.cursor(), True) @@ -51,12 +57,12 @@ def init(self, conn, logSql, replicaVar=1, db="db", stb="stb", checkColName="ic" self.stb = stb # sql - self.sqlSum = f"select sum({checkColName}) from {self.stb}" - self.sqlMax = f"select max({checkColName}) from {self.stb}" - self.sqlMin = f"select min({checkColName}) from {self.stb}" - self.sqlAvg = f"select avg({checkColName}) from {self.stb}" - self.sqlFirst = f"select first(ts) from {self.stb}" - self.sqlLast = f"select last(ts) from {self.stb}" + self.sqlSum = f"select sum({checkColName}) from {db}.{self.stb}" + self.sqlMax = f"select max({checkColName}) from {db}.{self.stb}" + self.sqlMin = f"select min({checkColName}) from {db}.{self.stb}" + self.sqlAvg = f"select avg({checkColName}) from {db}.{self.stb}" + self.sqlFirst = f"select first(ts) from {db}.{self.stb}" + self.sqlLast = f"select last(ts) from {db}.{self.stb}" # stop def stop(self): @@ -137,15 +143,15 @@ def balanceVGroupLeaderOn(self, vgId): # basic def checkInsertCorrect(self, difCnt = 0): # check count - sql = f"select count(*) from {self.stb}" + sql = f"select count(*) from {self.db}.{self.stb}" tdSql.checkAgg(sql, self.childtable_count * self.insert_rows) # check child table count - sql = f" select count(*) from (select count(*) as cnt , tbname from {self.stb} group by tbname) where cnt = {self.insert_rows} " + sql = f" select count(*) from (select count(*) as cnt , tbname from {self.db}.{self.stb} group by tbname) where cnt = {self.insert_rows} " tdSql.checkAgg(sql, self.childtable_count) # check step - sql = f"select count(*) from (select diff(ts) as dif from {self.stb} partition by tbname order by ts desc) where dif != {self.timestamp_step}" + sql = f"select count(*) from (select diff(ts) as dif from {self.db}.{self.stb} partition by tbname order by ts desc) where dif != {self.timestamp_step}" tdSql.checkAgg(sql, difCnt) # save agg result @@ -169,27 +175,27 @@ def checkAggCorrect(self): # self check def checkConsistency(self, col): # top with max - sql = f"select max({col}) from {self.stb}" + sql = f"select max({col}) from {self.db}.{self.stb}" expect = tdSql.getFirstValue(sql) - sql = f"select top({col}, 5) from {self.stb}" + sql = f"select top({col}, 5) from {self.db}.{self.stb}" tdSql.checkFirstValue(sql, expect) #bottom with min - sql = f"select min({col}) from {self.stb}" + sql = f"select min({col}) from {self.db}.{self.stb}" expect = tdSql.getFirstValue(sql) - sql = f"select bottom({col}, 5) from {self.stb}" + sql = f"select bottom({col}, 5) from {self.db}.{self.stb}" tdSql.checkFirstValue(sql, expect) # order by asc limit 1 with first - sql = f"select last({col}) from {self.stb}" + sql = f"select last({col}) from {self.db}.{self.stb}" expect = tdSql.getFirstValue(sql) - sql = f"select {col} from {self.stb} order by _c0 desc limit 1" + sql = f"select {col} from {self.db}.{self.stb} order by _c0 desc limit 1" tdSql.checkFirstValue(sql, expect) # order by desc limit 1 with last - sql = f"select first({col}) from {self.stb}" + sql = f"select first({col}) from {self.db}.{self.db}." expect = tdSql.getFirstValue(sql) - sql = f"select {col} from {self.stb} order by _c0 asc limit 1" + sql = f"select {col} from {self.db}.{self.db}. order by _c0 asc limit 1" tdSql.checkFirstValue(sql, expect) @@ -240,6 +246,17 @@ def checkSame(self, real, expect, show = True): else: tdLog.exit(f"check same failed. real={real} expect={expect}.") + # check except + def checkExcept(self, command): + try: + code = frame.eos.exe(command, show = True) + if code == 0: + tdLog.exit(f"Failed, not report error cmd:{command}") + else: + tdLog.info(f"Passed, report error code={code} is expect, cmd:{command}") + except: + tdLog.info(f"Passed, catch expect report error for command {command}") + # # get db information # @@ -289,7 +306,8 @@ def taos(self, command, show = True, checkRun = False): def taosdump(self, command, show = True, checkRun = True, retFail = True): return frame.etool.runBinFile("taosdump", command, show, checkRun, retFail) - + def benchmark(self, command, show = True, checkRun = True, retFail = True): + return frame.etool.runBinFile("taosBenchmark", command, show, checkRun, retFail) # # util # @@ -332,15 +350,22 @@ def checkListNotEmpty(self, lists, tips=""): # check list have str - def checkListString(self, vlist, s): - for i in range(len(vlist)): - if vlist[i].find(s) != -1: + def checkListString(self, rlist, s): + if s is None: + return + for i in range(len(rlist)): + if rlist[i].find(s) != -1: # found - tdLog.info(f'found "{s}" on index {i} , line={vlist[i]}') + tdLog.info(f'found "{s}" on index {i} , line={rlist[i]}') return # not found - tdLog.exit(f'faild, not found "{s}" on list:{vlist}') + tdLog.exit(f'faild, not found "{s}" on list:{rlist}') + + # check many string + def checkManyString(self, rlist, manys): + for s in manys: + self.checkListString(rlist, s) # # str util @@ -439,4 +464,21 @@ def tmqBenchJson(self, jsonFile, options="", checkStep=False): # print(rlist) - return rlist \ No newline at end of file + return rlist + + + # cmd + def benchmarkCmd(self, options, childCnt, insertRows, timeStep, results): + # set + self.childtable_count = childCnt + self.insert_rows = insertRows + self.timestamp_step = timeStep + + # run + cmd = f"{options} -t {childCnt} -n {insertRows} -S {timeStep} -y" + rlist = self.benchmark(cmd) + for result in results: + self.checkListString(rlist, result) + + # check correct + self.checkInsertCorrect() \ No newline at end of file diff --git a/tests/army/frame/etool.py b/tests/army/frame/etool.py index 4ad3efb036b4..041a43d4df4e 100644 --- a/tests/army/frame/etool.py +++ b/tests/army/frame/etool.py @@ -23,6 +23,14 @@ import frame.eos from frame.log import * + +# taos +def taosFile(): + bmFile = frame.epath.binFile("taos") + if frame.eos.isWin(): + bmFile += ".exe" + return bmFile + # taosdump def taosDumpFile(): bmFile = frame.epath.binFile("taosdump") diff --git a/tests/army/test.py b/tests/army/test.py index 6ac0948b7bae..a66743b40a8d 100644 --- a/tests/army/test.py +++ b/tests/army/test.py @@ -37,6 +37,9 @@ import taosrest import taosws +from taos.cinterface import * +taos.taos_options(6, "native") + def checkRunTimeError(): import win32gui timeCount = 0 @@ -258,8 +261,9 @@ def runOnPreviousCluster(host, config, fileName): # # do exeCmd command # + taosAdapter = True # default is websocket , so must start taosAdapter if not execCmd == "": - if taosAdapter or taosAdapter or restful or websocket: + if taosAdapter or restful or websocket: tAdapter.init(deployPath) else: tdDnodes.init(deployPath) diff --git a/tests/army/tools/benchmark/basic/commandline-sml-rest.py b/tests/army/tools/benchmark/basic/commandline-sml-rest.py deleted file mode 100644 index 3f5bcd80404d..000000000000 --- a/tests/army/tools/benchmark/basic/commandline-sml-rest.py +++ /dev/null @@ -1,75 +0,0 @@ -################################################################### -# Copyright (c) 2016 by TAOS Technologies, Inc. -# All rights reserved. -# -# This file is proprietary and confidential to TAOS Technologies. -# No part of this file may be reproduced, stored, transmitted, -# disclosed or used in any form or by any means other than as -# expressly provided by the written permission from Jianhui Tao -# -################################################################### - -# -*- coding: utf-8 -*- -import os - -import frame -import frame.etool -from frame.log import * -from frame.cases import * -from frame.sql import * -from frame.caseBase import * -from frame import * - - - -class TDTestCase(TBase): - def caseDescription(self): - """ - [TD-22334] taosBenchmark sml rest test cases - """ - - - def run(self): - binPath = etool.benchMarkFile() - - cmd = "%s -I sml-rest -t 1 -n 1 -y" % binPath - tdLog.info("%s" % cmd) - os.system("%s" % cmd) - tdSql.query("select count(*) from test.meters") - tdSql.checkData(0, 0, 1) - - cmd = "%s -I sml-rest-line -t 1 -n 1 -y" % binPath - tdLog.info("%s" % cmd) - os.system("%s" % cmd) - tdSql.query("select count(*) from test.meters") - tdSql.checkData(0, 0, 1) - - cmd = "%s -I sml-rest-telnet -t 1 -n 1 -y" % binPath - tdLog.info("%s" % cmd) - os.system("%s" % cmd) - tdSql.query("select count(*) from test.meters") - tdSql.checkData(0, 0, 1) - - cmd = "%s -I sml-rest-json -t 1 -n 1 -y" % binPath - tdLog.info("%s" % cmd) - os.system("%s" % cmd) - tdSql.query("select count(*) from test.meters") - tdSql.checkData(0, 0, 1) - - cmd = "%s -I sml-rest-taosjson -t 1 -n 1 -y" % binPath - tdLog.info("%s" % cmd) - os.system("%s" % cmd) - tdSql.query("select count(*) from test.meters") - tdSql.checkData(0, 0, 1) - - cmd = "%s -N -I sml-rest -y" % binPath - tdLog.info("%s" % cmd) - assert os.system("%s" % cmd) != 0 - - def stop(self): - tdSql.close() - tdLog.success("%s successfully executed" % __file__) - - -tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/army/tools/benchmark/basic/commandline-sml.py b/tests/army/tools/benchmark/basic/commandline-sml.py index 7c3dc39f7b74..4533dedbbd72 100644 --- a/tests/army/tools/benchmark/basic/commandline-sml.py +++ b/tests/army/tools/benchmark/basic/commandline-sml.py @@ -67,6 +67,16 @@ def run(self): tdSql.query("select count(*) from test.meters") tdSql.checkData(0, 0, 10*10000) + # add normal table + cmd = "%s -N -I sml -t 2 -n 10000 -y" % binPath + tdLog.info("%s" % cmd) + os.system("%s" % cmd) + + tdSql.query("select count(*) from test.d0") + tdSql.checkData(0, 0, 1*10000) + tdSql.query("select count(*) from test.d1") + tdSql.checkData(0, 0, 1*10000) + def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) diff --git a/tests/army/tools/benchmark/basic/commandline.py b/tests/army/tools/benchmark/basic/commandline.py index 94b812aed0ab..3330056d51f6 100644 --- a/tests/army/tools/benchmark/basic/commandline.py +++ b/tests/army/tools/benchmark/basic/commandline.py @@ -184,7 +184,7 @@ def run(self): tdSql.query("select last(ts) from test.meters") tdSql.checkData(0, 0, "2017-07-14 10:40:00.034") - cmd = "%s -N -I taosc -t 11 -n 11 -y -x -E" % binPath + cmd = "%s -N -I taosc -t 11 -n 11 -y -x -E -c abcde" % binPath tdLog.info("%s" % cmd) os.system("%s" % cmd) tdSql.execute("use test") @@ -195,7 +195,7 @@ def run(self): tdSql.query("select count(*) from `d10`") tdSql.checkData(0, 0, 11) - cmd = "%s -N -I rest -t 11 -n 11 -y -x" % binPath + cmd = "%s -N -I rest -t 11 -n 11 -y -x -c /etc/taos" % binPath tdLog.info("%s" % cmd) os.system("%s" % cmd) tdSql.execute("use test") @@ -315,21 +315,6 @@ def run(self): tdSql.query("describe test.meters") tdSql.checkData(1, 1, "NCHAR") - # 2.x is binary and 3.x is varchar - # cmd = "%s -n 1 -t 1 -y -b binary" %binPath - # tdLog.info("%s" % cmd) - # os.system("%s" % cmd) - # tdSql.execute("reset query cache") - # tdSql.query("describe test.meters") - # tdSql.checkData(1, 1, "BINARY") - - # cmd = "%s -n 1 -t 1 -y -b binary\(7\)" %binPath - # tdLog.info("%s" % cmd) - # os.system("%s" % cmd) - # tdSql.execute("reset query cache") - # tdSql.query("describe test.meters") - # tdSql.checkData(1, 1, "BINARY") - cmd = "%s -n 1 -t 1 -y -A json" % binPath tdLog.info("%s" % cmd) os.system("%s" % cmd) diff --git a/tests/army/tools/benchmark/basic/connMode.py b/tests/army/tools/benchmark/basic/connMode.py new file mode 100644 index 000000000000..0f3a99a3863d --- /dev/null +++ b/tests/army/tools/benchmark/basic/connMode.py @@ -0,0 +1,158 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- +# import os, signal +import os +from time import sleep +import frame +import frame.etool +from frame.log import * +from frame.cases import * +from frame.sql import * +from frame.caseBase import * +from frame import * + + +class TDTestCase(TBase): + def caseDescription(self): + """ + taosBenchmark public->connMode test cases + """ + + # expect cmd > evn > json + def checkPriority(self): + + # + # cmd & json + # + + # cmd first 6041 - valid + options = "-X http://127.0.0.1:6041" + # json 6042 - invalid + json = "tools/benchmark/basic/json/connModePriorityErrDsn.json" + self.insertBenchJson(json, options, True) + + # + # env > json + # + + # env 6041 - valid + os.environ['TDENGINE_CLOUD_DSN'] = "http://127.0.0.1:6041" + # json 6042 - invalid + json = "tools/benchmark/basic/json/connModePriorityErrDsn.json" + self.insertBenchJson(json, "", True) + + + # + # cmd & json & evn + # + + # cmd 6041 - valid + options = "-X http://127.0.0.1:6041" + # env 6043 - invalid + os.environ['TDENGINE_CLOUD_DSN'] = "http://127.0.0.1:6043" + # json 6042 - invalid + json = "tools/benchmark/basic/json/connModePriorityErrDsn.json" + self.insertBenchJson(json, options, True) + + # clear env + os.environ['TDENGINE_CLOUD_DSN'] = "" + + def checkCommandLine(self): + # modes + modes = ["", "-Z 1 -B 1", "-Z websocket", "-Z 0", "-Z native -B 2"] + # result + Rows = "insert rows: 9990" + results1 = [ + ["Connect mode is : WebSocket", Rows], + ["Connect mode is : WebSocket", Rows], + ["Connect mode is : WebSocket", Rows], + ["Connect mode is : Native", Rows], + ["Connect mode is : Native", Rows], + ] + # iface todo add sml + iface = ["taosc", "stmt", "stmt2"] + + # do check + for face in iface: + for i in range(len(modes)): + self.benchmarkCmd(f"{modes[i]} -I {face}", 10, 999, 1000, results1[i]) + + + def checkExceptCmd(self): + # exe + bench = frame.etool.benchMarkFile() + # option + options = [ + "-Z native -X http://127.0.0.1:6041", + "-Z 100", + "-Z abcdefg", + "-X", + "-X 127.0.0.1:6041", + "-X https://gw.cloud.taosdata.com?token617ffdf...", + "-Z 1 -X https://gw.cloud.taosdata.com?token=617ffdf...", + "-X http://127.0.0.1:6042" + ] + + # do check + for option in options: + self.checkExcept(bench + " -y " + option) + + def checkHostPort(self): + # + # ommand + # + self.benchmarkCmd("-h 127.0.0.1", 5, 100, 10, ["insert rows: 500"]) + self.benchmarkCmd("-h 127.0.0.1 -P 6041 -uroot -ptaosdata", 5, 100, 10, ["insert rows: 500"]) + self.benchmarkCmd("-Z 0 -h 127.0.0.1 -P 6030 -uroot -ptaosdata", 5, 100, 10, ["insert rows: 500"]) + + # + # command & json + # + + # 6041 is default + options = "-h 127.0.0.1 -P 6041 -uroot -ptaosdata" + json = "tools/benchmark/basic/json/connModePriorityErrHost.json" + self.insertBenchJson(json, options, True) + + # cmd port first json port + options = "-Z native -P 6030" + json = "tools/benchmark/basic/json/connModePriority.json" + self.insertBenchJson(json, options, True) + options = "-Z websocket -P 6041" + json = "tools/benchmark/basic/json/connModePriority.json" + self.insertBenchJson(json, options, True) + + def run(self): + # init + self.db = "test" + self.stb = "meters" + + # command line test + self.checkCommandLine() + + # except + self.checkExceptCmd() + + # cmd > json > env + self.checkPriority() + + # host and port + self.checkHostPort() + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/army/tools/benchmark/basic/json/TD-31490.json b/tests/army/tools/benchmark/basic/json/TD-31490.json index a4c674fa50e0..469be9ba5444 100644 --- a/tests/army/tools/benchmark/basic/json/TD-31490.json +++ b/tests/army/tools/benchmark/basic/json/TD-31490.json @@ -22,7 +22,7 @@ "wal_retention_period": 0, "buffer": 256, "stt_trigger": 1, - "vgroups ": 1 + "vgroups": 1 }, "super_tables": [ { diff --git a/tests/army/tools/benchmark/basic/json/TS-5002.json b/tests/army/tools/benchmark/basic/json/TS-5002.json index 024f9f0f9e2d..3e39085ca9a1 100644 --- a/tests/army/tools/benchmark/basic/json/TS-5002.json +++ b/tests/army/tools/benchmark/basic/json/TS-5002.json @@ -24,7 +24,7 @@ "cachemodel": "'both'", "cachesize": 100, "stt_trigger": 1, - "vgroups ": 3 + "vgroups": 3 }, "super_tables": [ { diff --git a/tests/army/tools/benchmark/basic/json/connModePriority.json b/tests/army/tools/benchmark/basic/json/connModePriority.json new file mode 100644 index 000000000000..aec4e5ac9cc2 --- /dev/null +++ b/tests/army/tools/benchmark/basic/json/connModePriority.json @@ -0,0 +1,65 @@ +{ + "filetype": "insert", + "dsn": "http://127.0.0.1:6041", + "cfgdir": "/etc/taos", + "host": "127.0.0.1", + "port": 6030, + "user": "root", + "password": "taosdata", + "num_of_records_per_req": 3000, + "thread_count": 2, + "confirm_parameter_prompt": "no", + "databases": [ + { + "dbinfo": { + "name": "test", + "drop": "yes", + "precision": "ms", + "vgroups": 1 + }, + "super_tables": [ + { + "name": "meters", + "child_table_exists": "no", + "childtable_count": 2, + "insert_rows": 1000, + "childtable_prefix": "d", + "insert_mode": "taosc", + "interlace_rows": 0, + "timestamp_step": 1000, + "start_timestamp":1700000000000, + "columns": [ + { "type": "bool", "name": "bc"}, + { "type": "float", "name": "fc", "max": 1, "min": 0 }, + { "type": "double", "name": "dc", "max": 10, "min": 0 }, + { "type": "tinyint", "name": "ti", "max": 100, "min": -100 }, + { "type": "smallint", "name": "si", "max": 100, "min": -50 }, + { "type": "int", "name": "ic", "max": 1000, "min": -1000 }, + { "type": "bigint", "name": "bi", "max": 100, "min": -1000 }, + { "type": "utinyint", "name": "uti", "max": 100, "min": 0 }, + { "type": "usmallint", "name": "usi", "max": 100, "min": 0 }, + { "type": "uint", "name": "ui", "max": 1000, "min": 0 }, + { "type": "ubigint", "name": "ubi", "max": 10000, "min": 0 }, + { "type": "binary", "name": "bin", "len": 4}, + { "type": "nchar", "name": "nch", "len": 8} + ], + "tags": [ + { "type": "bool", "name": "tbc"}, + { "type": "float", "name": "tfc", "max": 1, "min": 0 }, + { "type": "double", "name": "tdc", "max": 10, "min": 0 }, + { "type": "tinyint", "name": "tti", "max": 100, "min": -100 }, + { "type": "smallint", "name": "tsi", "max": 100, "min": -50 }, + { "type": "int", "name": "tic", "max": 1000, "min": -1000 }, + { "type": "bigint", "name": "tbi", "max": 100, "min": -1000 }, + { "type": "utinyint", "name": "tuti", "max": 100, "min": 0 }, + { "type": "usmallint", "name": "tusi", "max": 100, "min": 0 }, + { "type": "uint", "name": "tui", "max": 1000, "min": 0 }, + { "type": "ubigint", "name": "tubi", "max": 10000, "min": 0 }, + { "type": "binary", "name": "tbin", "len": 4}, + { "type": "nchar", "name": "tnch", "len": 8} + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/army/tools/benchmark/basic/json/connModePriorityErrDsn.json b/tests/army/tools/benchmark/basic/json/connModePriorityErrDsn.json new file mode 100644 index 000000000000..633d657861b3 --- /dev/null +++ b/tests/army/tools/benchmark/basic/json/connModePriorityErrDsn.json @@ -0,0 +1,60 @@ +{ + "filetype": "insert", + "dsn": "http://127.0.0.1:6042", + "num_of_records_per_req": 3000, + "thread_count": 2, + "confirm_parameter_prompt": "no", + "databases": [ + { + "dbinfo": { + "name": "test", + "drop": "yes", + "precision": "ms", + "vgroups": 1 + }, + "super_tables": [ + { + "name": "meters", + "child_table_exists": "no", + "childtable_count": 2, + "insert_rows": 1000, + "childtable_prefix": "d", + "insert_mode": "taosc", + "interlace_rows": 0, + "timestamp_step": 1000, + "start_timestamp":1700000000000, + "columns": [ + { "type": "bool", "name": "bc"}, + { "type": "float", "name": "fc", "max": 1, "min": 0 }, + { "type": "double", "name": "dc", "max": 10, "min": 0 }, + { "type": "tinyint", "name": "ti", "max": 100, "min": -100 }, + { "type": "smallint", "name": "si", "max": 100, "min": -50 }, + { "type": "int", "name": "ic", "max": 1000, "min": -1000 }, + { "type": "bigint", "name": "bi", "max": 100, "min": -1000 }, + { "type": "utinyint", "name": "uti", "max": 100, "min": 0 }, + { "type": "usmallint", "name": "usi", "max": 100, "min": 0 }, + { "type": "uint", "name": "ui", "max": 1000, "min": 0 }, + { "type": "ubigint", "name": "ubi", "max": 10000, "min": 0 }, + { "type": "binary", "name": "bin", "len": 4}, + { "type": "nchar", "name": "nch", "len": 8} + ], + "tags": [ + { "type": "bool", "name": "tbc"}, + { "type": "float", "name": "tfc", "max": 1, "min": 0 }, + { "type": "double", "name": "tdc", "max": 10, "min": 0 }, + { "type": "tinyint", "name": "tti", "max": 100, "min": -100 }, + { "type": "smallint", "name": "tsi", "max": 100, "min": -50 }, + { "type": "int", "name": "tic", "max": 1000, "min": -1000 }, + { "type": "bigint", "name": "tbi", "max": 100, "min": -1000 }, + { "type": "utinyint", "name": "tuti", "max": 100, "min": 0 }, + { "type": "usmallint", "name": "tusi", "max": 100, "min": 0 }, + { "type": "uint", "name": "tui", "max": 1000, "min": 0 }, + { "type": "ubigint", "name": "tubi", "max": 10000, "min": 0 }, + { "type": "binary", "name": "tbin", "len": 4}, + { "type": "nchar", "name": "tnch", "len": 8} + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/army/tools/benchmark/basic/json/connModePriorityErrHost.json b/tests/army/tools/benchmark/basic/json/connModePriorityErrHost.json new file mode 100644 index 000000000000..f32acbeb1f5b --- /dev/null +++ b/tests/army/tools/benchmark/basic/json/connModePriorityErrHost.json @@ -0,0 +1,64 @@ +{ + "filetype": "insert", + "cfgdir": "/etc/taos", + "host": "127.0.0.2", + "port": 6032, + "user": "root-error", + "password": "taosdata-error", + "num_of_records_per_req": 3000, + "thread_count": 2, + "confirm_parameter_prompt": "no", + "databases": [ + { + "dbinfo": { + "name": "test", + "drop": "yes", + "precision": "ms", + "vgroups": 1 + }, + "super_tables": [ + { + "name": "meters", + "child_table_exists": "no", + "childtable_count": 2, + "insert_rows": 1000, + "childtable_prefix": "d", + "insert_mode": "taosc", + "interlace_rows": 0, + "timestamp_step": 1000, + "start_timestamp":1700000000000, + "columns": [ + { "type": "bool", "name": "bc"}, + { "type": "float", "name": "fc", "max": 1, "min": 0 }, + { "type": "double", "name": "dc", "max": 10, "min": 0 }, + { "type": "tinyint", "name": "ti", "max": 100, "min": -100 }, + { "type": "smallint", "name": "si", "max": 100, "min": -50 }, + { "type": "int", "name": "ic", "max": 1000, "min": -1000 }, + { "type": "bigint", "name": "bi", "max": 100, "min": -1000 }, + { "type": "utinyint", "name": "uti", "max": 100, "min": 0 }, + { "type": "usmallint", "name": "usi", "max": 100, "min": 0 }, + { "type": "uint", "name": "ui", "max": 1000, "min": 0 }, + { "type": "ubigint", "name": "ubi", "max": 10000, "min": 0 }, + { "type": "binary", "name": "bin", "len": 4}, + { "type": "nchar", "name": "nch", "len": 8} + ], + "tags": [ + { "type": "bool", "name": "tbc"}, + { "type": "float", "name": "tfc", "max": 1, "min": 0 }, + { "type": "double", "name": "tdc", "max": 10, "min": 0 }, + { "type": "tinyint", "name": "tti", "max": 100, "min": -100 }, + { "type": "smallint", "name": "tsi", "max": 100, "min": -50 }, + { "type": "int", "name": "tic", "max": 1000, "min": -1000 }, + { "type": "bigint", "name": "tbi", "max": 100, "min": -1000 }, + { "type": "utinyint", "name": "tuti", "max": 100, "min": 0 }, + { "type": "usmallint", "name": "tusi", "max": 100, "min": 0 }, + { "type": "uint", "name": "tui", "max": 1000, "min": 0 }, + { "type": "ubigint", "name": "tubi", "max": 10000, "min": 0 }, + { "type": "binary", "name": "tbin", "len": 4}, + { "type": "nchar", "name": "tnch", "len": 8} + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/army/tools/benchmark/basic/json/queryInsertrestdata.json b/tests/army/tools/benchmark/basic/json/queryInsertrestdata.json deleted file mode 100644 index 67144977665c..000000000000 --- a/tests/army/tools/benchmark/basic/json/queryInsertrestdata.json +++ /dev/null @@ -1,73 +0,0 @@ -{ - "filetype": "insert", - "cfgdir": "/etc/taos", - "host": "127.0.0.1", - "port": 6030, - "user": "root", - "password": "taosdata", - "thread_count": 4, - "thread_count_create_tbl": 4, - "result_file": "./insert_res.txt", - "confirm_parameter_prompt": "no", - "insert_interval": 0, - "interlace_rows": 0, - "num_of_records_per_req": 3000, - "max_sql_len": 1024000, - "databases": [{ - "dbinfo": { - "name": "db", - "drop": "yes", - "precision": "ms" - }, - "super_tables": [{ - "name": "stb0", - "child_table_exists":"no", - "childtable_count": 2, - "childtable_prefix": "stb00_", - "auto_create_table": "no", - "batch_create_tbl_num": 10, - "data_source": "rand", - "insert_mode": "taosc", - "insert_rows": 10, - "childtable_limit": 0, - "childtable_offset": 0, - "interlace_rows": 0, - "insert_interval": 0, - "max_sql_len": 1024000, - "disorder_ratio": 0, - "disorder_range": 1000, - "timestamp_step": 1, - "start_timestamp": "2020-11-01 00:00:00.000", - "sample_format": "csv", - "sample_file": "./sample.csv", - "tags_file": "", - "columns": [{"type": "BINARY", "len": 1, "count":1}, {"type": "BINARY", "len": 3, "count":1}, {"type": "INT"}, {"type": "DOUBLE", "count":1}], - "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":5}] - }, - { - "name": "stb1", - "child_table_exists":"no", - "childtable_count": 2, - "childtable_prefix": "stb01_", - "auto_create_table": "no", - "batch_create_tbl_num": 10, - "data_source": "rand", - "insert_mode": "taosc", - "insert_rows": 5, - "childtable_limit": 0, - "childtable_offset": 0, - "interlace_rows": 0 , - "insert_interval": 0, - "max_sql_len": 1024000, - "disorder_ratio": 0, - "disorder_range": 1000, - "timestamp_step": 1, - "start_timestamp": "2020-11-01 00:00:00.000", - "sample_format": "csv", - "sample_file": "./sample.csv", - "tags_file": "", - "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":6}, {"type": "BINARY", "len": 1, "count":3}, {"type": "BINARY", "len": 2, "count":6}], - "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":5}] - }] - }] -} diff --git a/tests/army/tools/benchmark/basic/json/queryModeSpecMixRest.json b/tests/army/tools/benchmark/basic/json/queryModeSpecMixRest.json deleted file mode 100644 index 5d962f135494..000000000000 --- a/tests/army/tools/benchmark/basic/json/queryModeSpecMixRest.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "filetype": "query", - "cfgdir": "/etc/taos", - "host": "127.0.0.1", - "port": 6030, - "user": "root", - "password": "taosdata", - "confirm_parameter_prompt": "no", - "databases": "test", - "query_times": 100, - "query_mode": "rest", - "specified_table_query": { - "concurrent": 3, - "mixed_query": "yes", - "sqls": [ - { - "sql": "select last_row(*) from meters" - }, - { - "sql": "select count(*) from d0", - "result": "./query_res1.txt" - }, - { - "sql": "select count(*) from meters" - } - ] - } -} diff --git a/tests/army/tools/benchmark/basic/json/queryModeSpecRest.json b/tests/army/tools/benchmark/basic/json/queryModeSpecRest.json deleted file mode 100644 index 5b00ee647924..000000000000 --- a/tests/army/tools/benchmark/basic/json/queryModeSpecRest.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "filetype": "query", - "cfgdir": "/etc/taos", - "host": "127.0.0.1", - "port": 6030, - "user": "root", - "password": "taosdata", - "confirm_parameter_prompt": "no", - "databases": "test", - "query_times": 100, - "query_mode": "rest", - "specified_table_query": { - "concurrent": 3, - "sqls": [ - { - "sql": "select last_row(*) from meters" - }, - { - "sql": "select count(*) from d0", - "result": "./query_res1.txt" - }, - { - "sql": "select count(*) from meters" - } - ] - } -} diff --git a/tests/army/tools/benchmark/basic/json/queryModeSuperRest.json b/tests/army/tools/benchmark/basic/json/queryModeSuperRest.json deleted file mode 100644 index 4ae43062a6af..000000000000 --- a/tests/army/tools/benchmark/basic/json/queryModeSuperRest.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "filetype": "query", - "cfgdir": "/etc/taos", - "host": "127.0.0.1", - "port": 6030, - "user": "root", - "password": "taosdata", - "confirm_parameter_prompt": "no", - "continue_if_fail": "yes", - "databases": "test", - "query_times": 100, - "query_mode": "rest", - "super_table_query": { - "stblname": "meters", - "concurrent": 3, - "query_interval": 0, - "sqls": [ - { - "sql": "select last_row(ts) from xxxx", - "result": "./query_res2.txt" - } - ] - } -} diff --git a/tests/army/tools/benchmark/basic/json/queryRestful.json b/tests/army/tools/benchmark/basic/json/queryRestful.json deleted file mode 100644 index 6cb83bc2e1f4..000000000000 --- a/tests/army/tools/benchmark/basic/json/queryRestful.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "filetype": "query", - "cfgdir": "/etc/taos", - "host": "127.0.0.1", - "port": 6030, - "user": "root", - "password": "taosdata", - "confirm_parameter_prompt": "no", - "databases": "db", - "query_times": 2, - "query_mode": "rest", - "specified_table_query": { - "query_interval": 1, - "threads": 3, - "sqls": [ - { - "sql": "select last_row(*) from db.stb0 ", - "result": "./query_res0.txt" - }, - { - "sql": "select count(*) from db.stb00_1", - "result": "./query_res1.txt" - } - ] - } - } - diff --git a/tests/army/tools/benchmark/basic/json/queryRestful1.json b/tests/army/tools/benchmark/basic/json/queryRestful1.json deleted file mode 100644 index 54d2589ce9d9..000000000000 --- a/tests/army/tools/benchmark/basic/json/queryRestful1.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "filetype": "query", - "cfgdir": "/etc/taos", - "host": "127.0.0.1", - "port": 6030, - "user": "root", - "password": "taosdata", - "confirm_parameter_prompt": "no", - "databases": "db", - "query_times": 2, - "query_mode": "rest", - "super_table_query": { - "stblname": "stb1", - "query_interval": 1, - "threads": 3, - "sqls": [ - { - "sql": "select last_row(ts) from xxxx", - "result": "./query_res2.txt" - } - ] - } - } - diff --git a/tests/army/tools/benchmark/basic/queryMain.py b/tests/army/tools/benchmark/basic/queryMain.py index bd6fa9ca31e4..b30cc5d65d8d 100644 --- a/tests/army/tools/benchmark/basic/queryMain.py +++ b/tests/army/tools/benchmark/basic/queryMain.py @@ -203,10 +203,6 @@ def threeQueryMode(self, benchmark, tbCnt, tbRow): for arg in args: self.checkAfterRun(benchmark, arg[0] + ".json", arg[1], tbCnt) - # rest - for arg in args: - self.checkAfterRun(benchmark, arg[0] + "Rest.json", arg[1], tbCnt) - def expectFailed(self, command): ret = os.system(command) if ret == 0: diff --git a/tests/army/tools/benchmark/basic/query_json.py b/tests/army/tools/benchmark/basic/query_json.py index 6f71a508aff8..5e59b1392fd7 100644 --- a/tests/army/tools/benchmark/basic/query_json.py +++ b/tests/army/tools/benchmark/basic/query_json.py @@ -32,7 +32,7 @@ def caseDescription(self): def run(self): binPath = etool.benchMarkFile() os.system( - "rm -f rest_query_specified-0 rest_query_super-0 taosc_query_specified-0 taosc_query_super-0" + "rm -f taosc_query_specified-0 taosc_query_super-0" ) tdSql.execute("drop database if exists db") tdSql.execute("create database if not exists db") @@ -58,46 +58,6 @@ def run(self): queryTaosc = line.strip().split()[0] assert queryTaosc == "1", "result is %s != expect: 1" % queryTaosc - # split two - cmd = "%s -f ./tools/benchmark/basic/json/rest_query.json" % binPath - tdLog.info("%s" % cmd) - os.system("%s" % cmd) - cmd = "%s -f ./tools/benchmark/basic/json/rest_query1.json" % binPath - tdLog.info("%s" % cmd) - os.system("%s" % cmd) - - times = 0 - with open("rest_query_super-0", "r+") as f1: - for line in f1.readlines(): - contents = line.strip() - if contents.find("data") != -1: - pattern = re.compile("{.*}") - contents = pattern.search(contents).group() - contentsDict = ast.literal_eval(contents) - queryResultRest = contentsDict["data"][0][0] - assert queryResultRest == 1, ( - "result is %s != expect: 1" % queryResultRest - ) - times += 1 - - assert times == 3, "result is %s != expect: 3" % times - - times = 0 - with open("rest_query_specified-0", "r+") as f1: - for line in f1.readlines(): - contents = line.strip() - if contents.find("data") != -1: - pattern = re.compile("{.*}") - contents = pattern.search(contents).group() - contentsDict = ast.literal_eval(contents) - queryResultRest = contentsDict["data"][0][0] - assert queryResultRest == 3, ( - "result is %s != expect: 3" % queryResultRest - ) - times += 1 - - assert times == 1, "result is %s != expect: 1" % times - def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) diff --git a/tests/army/tools/benchmark/basic/taosdemoTestQueryWithJson-mixed-query.py b/tests/army/tools/benchmark/basic/taosdemoTestQueryWithJson-mixed-query.py index 14bf201e975f..a3f1a149676f 100644 --- a/tests/army/tools/benchmark/basic/taosdemoTestQueryWithJson-mixed-query.py +++ b/tests/army/tools/benchmark/basic/taosdemoTestQueryWithJson-mixed-query.py @@ -37,22 +37,6 @@ def assertfileDataTaosc(self, filename, expectResult): queryResultTaosc = line.strip().split()[0] self.assertCheck(filename, queryResultTaosc, expectResult) - # 获取restful接口查询的结果文件中的关键内容,目前的关键内容找到第一个key就跳出循,所以就只有一个数据。后续再修改多个结果文件。 - def getfileDataRestful(self, filename): - self.filename = filename - with open("%s" % filename, "r+") as f1: - for line in f1.readlines(): - contents = line.strip() - if contents.find("data") != -1: - pattern = re.compile("{.*}") - contents = pattern.search(contents).group() - contentsDict = ast.literal_eval(contents) # 字符串转换为字典 - queryResultRest = contentsDict["data"][0][0] - break - else: - queryResultRest = "" - return queryResultRest - # 获取taosc接口查询次数 def queryTimesTaosc(self, filename): self.filename = filename @@ -60,13 +44,6 @@ def queryTimesTaosc(self, filename): times = int(subprocess.getstatusoutput(command)[1]) return times - # 获取restful接口查询次数 - def queryTimesRestful(self, filename): - self.filename = filename - command = 'cat %s |grep "200 OK" |wc -l' % filename - times = int(subprocess.getstatusoutput(command)[1]) - return times - # 定义断言结果是否正确。不正确返回错误结果,正确即通过。 def assertCheck(self, filename, queryResult, expectResult): self.filename = filename @@ -106,26 +83,6 @@ def run(self): os.system("rm -rf ./query_res*") os.system("rm -rf ./all_query*") - # use restful api to query - os.system("%s -f ./tools/benchmark/basic/json/queryInsertrestdata.json" % binPath) - os.system("%s -f ./tools/benchmark/basic/json/queryRestful.json" % binPath) - os.system("%s -f ./tools/benchmark/basic/json/queryRestful1.json" % binPath) - os.system("cat query_res2.txt* > all_query_res2_rest.txt") - - # correct Times testcases - - queryTimes2Restful = self.queryTimesRestful("all_query_res2_rest.txt") - self.assertCheck("all_query_res2_rest.txt", queryTimes2Restful, 4) - - # correct data testcase - - data2 = self.getfileDataRestful("all_query_res2_rest.txt") - print(data2) - if data2 != "2020-11-01 00:00:00.004" and data2 != "2020-10-31T16:00:00.004Z": - tdLog.exit( - "data2 is not 2020-11-01 00:00:00.004 and 2020-10-31T16:00:00.004Z" - ) - # query times less than or equal to 100 assert ( os.system("%s -f ./tools/benchmark/basic/json/queryInsertdata.json" % binPath) == 0 diff --git a/tests/army/tools/benchmark/basic/taosdemoTestQueryWithJson.py b/tests/army/tools/benchmark/basic/taosdemoTestQueryWithJson.py index 3e55a5df7074..c529381c18c2 100644 --- a/tests/army/tools/benchmark/basic/taosdemoTestQueryWithJson.py +++ b/tests/army/tools/benchmark/basic/taosdemoTestQueryWithJson.py @@ -115,41 +115,6 @@ def run(self): os.system("rm -rf ./query_res*") os.system("rm -rf ./all_query*") - # use restful api to query - os.system("%s -f ./tools/benchmark/basic/json/queryInsertrestdata.json" % binPath) - os.system("%s -f ./tools/benchmark/basic/json/queryRestful.json" % binPath) - os.system("%s -f ./tools/benchmark/basic/json/queryRestful1.json" % binPath) - os.system("cat query_res0.txt* > all_query_res0_rest.txt") - os.system("cat query_res1.txt* > all_query_res1_rest.txt") - os.system("cat query_res2.txt* > all_query_res2_rest.txt") - - # correct Times testcases - queryTimes0Restful = self.queryTimesRestful("all_query_res0_rest.txt") - self.assertCheck("all_query_res0_rest.txt", queryTimes0Restful, 6) - - queryTimes1Restful = self.queryTimesRestful("all_query_res1_rest.txt") - self.assertCheck("all_query_res1_rest.txt", queryTimes1Restful, 6) - - queryTimes2Restful = self.queryTimesRestful("all_query_res2_rest.txt") - self.assertCheck("all_query_res2_rest.txt", queryTimes2Restful, 4) - - # correct data testcase - data0 = self.getfileDataRestful("all_query_res0_rest.txt") - if data0 != "2020-11-01 00:00:00.009" and data0 != "2020-10-31T16:00:00.009Z": - tdLog.exit( - "data0 is not 2020-11-01 00:00:00.009 and 2020-10-31T16:00:00.009Z" - ) - - data1 = self.getfileDataRestful("all_query_res1_rest.txt") - self.assertCheck("all_query_res1_rest.txt", data1, 10) - - data2 = self.getfileDataRestful("all_query_res2_rest.txt") - print(data2) - if data2 != "2020-11-01 00:00:00.004" and data2 != "2020-10-31T16:00:00.004Z": - tdLog.exit( - "data2 is not 2020-11-01 00:00:00.004 and 2020-10-31T16:00:00.004Z" - ) - # query times less than or equal to 100 assert ( os.system("%s -f ./tools/benchmark/basic/json/queryInsertdata.json" % binPath) == 0 @@ -170,10 +135,6 @@ def run(self): exceptcode = os.system("%s -f ./tools/benchmark/basic/json/queryQps1.json" % binPath) assert exceptcode == 0 - # 2021.02.09 need modify taosBenchmakr code - # use illegal or out of range parameters query json file - os.system("%s -f ./tools/benchmark/basic/json/queryInsertdata.json" % binPath) - # delete useless files os.system("rm -rf ./insert_res.txt") os.system("rm -rf ./tools/benchmark/basic/*.py.sql") diff --git a/tests/army/tools/taosdump/native/json/insertFullType.json b/tests/army/tools/taosdump/native/json/insertFullType.json index a121670c371e..5bdecef72b44 100644 --- a/tests/army/tools/taosdump/native/json/insertFullType.json +++ b/tests/army/tools/taosdump/native/json/insertFullType.json @@ -41,7 +41,9 @@ { "type": "ubigint", "name": "ubi", "max": 10000, "min": 0 }, { "type": "binary", "name": "bin", "len": 4}, { "type": "nchar", "name": "nch", "len": 8}, - { "type": "varchar", "name": "vac", "len": 8} + { "type": "varbinary", "name": "vab", "len": 8}, + { "type": "varchar", "name": "vac", "len": 8}, + { "type": "geometry", "name": "geo", "len": 32} ], "tags":[ { "type": "bool", "name": "tbc"}, @@ -57,7 +59,9 @@ { "type": "ubigint", "name": "tubi", "max": 10000, "min": 0 }, { "type": "binary", "name": "tbin", "len": 4}, { "type": "nchar", "name": "tnch", "len": 8}, - { "type": "varchar", "name": "tvac", "len": 8} + { "type": "varbinary", "name": "tvab", "len": 8}, + { "type": "varchar", "name": "tvac", "len": 8}, + { "type": "geometry", "name": "tgeo", "len": 32} ] } ] diff --git a/tests/army/tools/taosdump/native/json/insertOther.json b/tests/army/tools/taosdump/native/json/insertOther.json deleted file mode 100644 index bd6bb12beca6..000000000000 --- a/tests/army/tools/taosdump/native/json/insertOther.json +++ /dev/null @@ -1,70 +0,0 @@ -{ - "filetype":"insert", - "cfgdir":"/etc/taos", - "host":"127.0.0.1", - "port":6030, - "user":"root", - "password":"taosdata", - "thread_count":1, - "create_table_thread_count":1, - "confirm_parameter_prompt":"no", - "prepare_rand":100, - "num_of_records_per_req":100, - "databases": [ - { - "dbinfo":{ - "name":"testother", - "drop":"yes" - }, - "super_tables":[ - { - "name":"meters", - "child_table_exists":"no", - "childtable_prefix":"d", - "data_source":"rand", - "insert_mode":"taosc", - "childtable_count": 2, - "insert_rows":100, - "timestamp_step":1000, - "start_timestamp":"2022-10-01 00:00:00.000", - "columns":[ - { "type": "bool", "name": "bc"}, - { "type": "float", "name": "fc", "max": 1, "min": 0 }, - { "type": "double", "name": "dc", "max": 10, "min": 0 }, - { "type": "tinyint", "name": "ti", "max": 100, "min": -100 }, - { "type": "smallint", "name": "si", "max": 100, "min": -50 }, - { "type": "int", "name": "ic", "max": 1000, "min": -1000 }, - { "type": "bigint", "name": "bi", "max": 100, "min": -1000 }, - { "type": "utinyint", "name": "uti", "max": 100, "min": 0 }, - { "type": "usmallint", "name": "usi", "max": 100, "min": 0 }, - { "type": "uint", "name": "ui", "max": 1000, "min": 0 }, - { "type": "ubigint", "name": "ubi", "max": 10000, "min": 0 }, - { "type": "binary", "name": "bin", "len": 4}, - { "type": "nchar", "name": "nch", "len": 8}, - { "type": "varbinary", "name": "vab", "len": 8}, - { "type": "varchar", "name": "vac", "len": 8}, - { "type": "geometry", "name": "geo", "len": 32} - ], - "tags":[ - { "type": "bool", "name": "tbc"}, - { "type": "float", "name": "tfc", "max": 1, "min": 0 }, - { "type": "double", "name": "tdc", "max": 10, "min": 0 }, - { "type": "tinyint", "name": "tti", "max": 100, "min": -100 }, - { "type": "smallint", "name": "tsi", "max": 100, "min": -50 }, - { "type": "int", "name": "tic", "max": 1000, "min": -1000 }, - { "type": "bigint", "name": "tbi", "max": 100, "min": -1000 }, - { "type": "utinyint", "name": "tuti", "max": 100, "min": 0 }, - { "type": "usmallint", "name": "tusi", "max": 100, "min": 0 }, - { "type": "uint", "name": "tui", "max": 1000, "min": 0 }, - { "type": "ubigint", "name": "tubi", "max": 10000, "min": 0 }, - { "type": "binary", "name": "tbin", "len": 4}, - { "type": "nchar", "name": "tnch", "len": 8}, - { "type": "varbinary", "name": "tvab", "len": 8}, - { "type": "varchar", "name": "tvac", "len": 8}, - { "type": "geometry", "name": "tgeo", "len": 32} - ] - } - ] - } - ] -} diff --git a/tests/army/tools/taosdump/native/taosdumpCommandline.py b/tests/army/tools/taosdump/native/taosdumpCommandline.py index c43ea0e9e732..c67d140cb0c2 100644 --- a/tests/army/tools/taosdump/native/taosdumpCommandline.py +++ b/tests/army/tools/taosdump/native/taosdumpCommandline.py @@ -95,11 +95,11 @@ def insertData(self, json): # normal table sqls = [ f"create table {db}.ntb(st timestamp, c1 int, c2 binary(32))", - f"insert into {db}.ntb values(now, 1, 'abc1')", - f"insert into {db}.ntb values(now, 2, 'abc2')", - f"insert into {db}.ntb values(now, 3, 'abc3')", - f"insert into {db}.ntb values(now, 4, 'abc4')", - f"insert into {db}.ntb values(now, 5, 'abc5')", + f"insert into {db}.ntb values('2025-01-01 10:00:01', 1, 'abc1')", + f"insert into {db}.ntb values('2025-01-01 10:00:02', 2, 'abc2')", + f"insert into {db}.ntb values('2025-01-01 10:00:03', 3, 'abc3')", + f"insert into {db}.ntb values('2025-01-01 10:00:04', 4, 'abc4')", + f"insert into {db}.ntb values('2025-01-01 10:00:05', 5, 'abc5')", ] for sql in sqls: tdSql.execute(sql) @@ -158,9 +158,10 @@ def dumpInOutMode(self, mode, db, json, tmpdir): def basicCommandLine(self, tmpdir): #command and check result checkItems = [ - [f"-h 127.0.0.1 -P 6030 -uroot -ptaosdata -A -N -o {tmpdir}", ["OK: Database test dumped"]], + [f"-h 127.0.0.1 -P 6041 -uroot -ptaosdata -A -N -o {tmpdir}", ["OK: Database test dumped"]], [f"-r result -a -e test d0 -o {tmpdir}", ["OK: table: d0 dumped", "OK: 100 row(s) dumped out!"]], [f"-n -D test -o {tmpdir}", ["OK: Database test dumped", "OK: 205 row(s) dumped out!"]], + [f"-Z 0 -P 6030 -n -D test -o {tmpdir}", ["OK: Database test dumped", "OK: 205 row(s) dumped out!"]], [f"-L -D test -o {tmpdir}", ["OK: Database test dumped", "OK: 205 row(s) dumped out!"]], [f"-s -D test -o {tmpdir}", ["dumping out schema: 1 from meters.d0", "OK: Database test dumped", "OK: 0 row(s) dumped out!"]], [f"-N -d deflate -S '2022-10-01 00:00:50.000' test meters -o {tmpdir}",["OK: table: meters dumped", "OK: 100 row(s) dumped out!"]], @@ -172,7 +173,18 @@ def basicCommandLine(self, tmpdir): [f"--help", ["Report bugs to"]], [f"-?", ["Report bugs to"]], [f"-V", ["version:"]], - [f"--usage", ["taosdump [OPTION...] -o outpath"]] + [f"--usage", ["taosdump [OPTION...] -o outpath"]], + # conn mode -Z + [f"-Z 0 -E '2022-10-01 00:00:60.000' test -o {tmpdir}", [ + "Connect mode is : Native", + "OK: Database test dumped", + "OK: 122 row(s) dumped out!"] + ], + [f"-Z 1 -E '2022-10-01 00:00:60.000' test -o {tmpdir}", [ + "Connect mode is : WebSocket", + "OK: Database test dumped", + "OK: 122 row(s) dumped out!"] + ], ] # executes @@ -181,22 +193,8 @@ def basicCommandLine(self, tmpdir): command = item[0] results = item[1] rlist = self.taosdump(command) - for result in results: - self.checkListString(rlist, result) - # clear tmp - - - # check except - def checkExcept(self, command): - try: - code = frame.eos.exe(command, show = True) - if code == 0: - tdLog.exit(f"Failed, not report error cmd:{command}") - else: - tdLog.info(f"Passed, report error code={code} is expect, cmd:{command}") - except: - tdLog.info(f"Passed, catch expect report error for command {command}") - + self.checkManyString(rlist, results) + # clear tmp # except commandline def exceptCommandLine(self, taosdump, db, stb, tmpdir): @@ -214,6 +212,73 @@ def exceptCommandLine(self, taosdump, db, stb, tmpdir): self.checkExcept(taosdump + f" -t 2 -k 2 -z 1 -C https://not-exist.com:80/cloud -D test -o {tmpdir}") self.checkExcept(taosdump + f" -P 65536") + # conn mode + options = [ + f"-Z native -X http://127.0.0.1:6041 -D {db} -o {tmpdir}", + f"-Z 100 -D {db} -o {tmpdir}", + f"-Z abcdefg -D {db} -o {tmpdir}", + f"-X -D {db} -o {tmpdir}", + f"-X 127.0.0.1:6041 -D {db} -o {tmpdir}", + f"-X https://gw.cloud.taosdata.com?token617ffdf... -D {db} -o {tmpdir}", + f"-Z 1 -X https://gw.cloud.taosdata.com?token=617ffdf... -D {db} -o {tmpdir}", + f"-X http://127.0.0.1:6042 -D {db} -o {tmpdir}" + ] + + # do check + for option in options: + self.checkExcept(taosdump + " " + option) + + + # expect cmd > json > evn + def checkPriority(self, db, stb, childCount, insertRows, tmpdir): + # + # cmd & env + # + + # env 6043 - invalid + os.environ['TDENGINE_CLOUD_DSN'] = "http://127.0.0.1:6043" + # cmd 6041 - valid + cmd = f"-X http://127.0.0.1:6041 -D {db} -o {tmpdir}" + self.clearPath(tmpdir) + rlist = self.taosdump(cmd) + results = [ + "Connect mode is : WebSocket", + "OK: Database test dumped", + "OK: 205 row(s) dumped out!" + ] + self.checkManyString(rlist, results) + + # + # env + # + + os.environ['TDENGINE_CLOUD_DSN'] = "http://127.0.0.1:6041" + # cmd 6041 - valid + self.clearPath(tmpdir) + cmd = f"-D {db} -o {tmpdir}" + rlist = self.taosdump(cmd) + self.checkManyString(rlist, results) + + # + # cmd + # + + os.environ['TDENGINE_CLOUD_DSN'] = "" + # cmd 6041 - valid + self.clearPath(tmpdir) + cmd = f"-X http://127.0.0.1:6041 -D {db} -o {tmpdir}" + rlist = self.taosdump(cmd) + self.checkManyString(rlist, results) + + # clear env + os.environ['TDENGINE_CLOUD_DSN'] = "" + + + # conn mode + def checkConnMode(self, db, stb, childCount, insertRows, tmpdir): + # priority + self.checkPriority(db, stb, childCount, insertRows, tmpdir) + # run def run(self): @@ -225,11 +290,11 @@ def run(self): db, stb, childCount, insertRows = self.insertData(json) # dumpInOut - modes = ["", "-R" , "--cloud=http://localhost:6041"] + modes = ["-Z native", "-Z websocket", "--dsn=http://localhost:6041"] for mode in modes: self.dumpInOutMode(mode, db , json, tmpdir) - tdLog.info("1. native rest ws dumpIn Out .......................... [Passed]") + tdLog.info("1. native rest ws dumpIn Out ........................... [Passed]") # basic commandline self.basicCommandLine(tmpdir) @@ -240,14 +305,13 @@ def run(self): tdLog.info("3. except command line ................................. [Passed]") # - # varbinary and geometry for native + # check connMode # - json = "./tools/taosdump/native/json/insertOther.json" - # insert - db, stb, childCount, insertRows = self.insertData(json) - # dump in/out - self.dumpInOutMode("", db , json, tmpdir) - tdLog.info("4. native varbinary geometry ........................... [Passed]") + self.checkConnMode(db, stb, childCount, insertRows, tmpdir) + tdLog.info("4. check conn mode ..................................... [Passed]") + + + def stop(self): diff --git a/tests/develop-test/test.py b/tests/develop-test/test.py index 3525fd6332fa..b291e58e3d74 100644 --- a/tests/develop-test/test.py +++ b/tests/develop-test/test.py @@ -38,6 +38,8 @@ import taos import taosrest +from taos.cinterface import * +taos.taos_options(6, "native") def checkRunTimeError(): import win32gui diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index 1bfd86df4dd9..b644824148f2 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -83,11 +83,12 @@ # benchmark 66 cases ,,y,army,./pytest.sh python3 ./test.py -f tools/benchmark/basic/commandline.py ,,y,army,./pytest.sh python3 ./test.py -f tools/benchmark/basic/commandline-partial-col-numpy.py -,,y,army,./pytest.sh python3 ./test.py -f tools/benchmark/basic/commandline-sml-rest.py -R ,,y,army,./pytest.sh python3 ./test.py -f tools/benchmark/basic/commandline-single-table.py ,,y,army,./pytest.sh python3 ./test.py -f tools/benchmark/basic/commandline-supplement-insert.py ,,y,army,./pytest.sh python3 ./test.py -f tools/benchmark/basic/commandline-vgroups.py +,,y,army,./pytest.sh python3 ./test.py -f tools/benchmark/basic/connMode.py -B + ,,y,army,./pytest.sh python3 ./test.py -f tools/benchmark/basic/custom_col_tag.py ,,y,army,./pytest.sh python3 ./test.py -f tools/benchmark/basic/default_json.py diff --git a/tests/parallel_test/run_case.sh b/tests/parallel_test/run_case.sh index b72a7cacca4f..6cbeecd65ec5 100755 --- a/tests/parallel_test/run_case.sh +++ b/tests/parallel_test/run_case.sh @@ -50,6 +50,8 @@ if [ $ent -eq 0 ]; then export LD_LIBRARY_PATH=/home/TDengine/debug/build/lib ln -s /home/TDengine/debug/build/lib/libtaos.so /usr/lib/libtaos.so 2>/dev/null ln -s /home/TDengine/debug/build/lib/libtaos.so /usr/lib/libtaos.so.1 2>/dev/null + ln -s /home/TDengine/debug/build/lib/libtaosnative.so /usr/lib/libtaosnative.so 2>/dev/null + ln -s /home/TDengine/debug/build/lib/libtaosnative.so /usr/lib/libtaosnative.so.1 2>/dev/null ln -s /home/TDengine/include/client/taos.h /usr/include/taos.h 2>/dev/null ln -s /home/TDengine/include/common/taosdef.h /usr/include/taosdef.h 2>/dev/null ln -s /home/TDengine/include/util/taoserror.h /usr/include/taoserror.h 2>/dev/null @@ -60,6 +62,8 @@ else export LD_LIBRARY_PATH=/home/TDinternal/debug/build/lib ln -s /home/TDinternal/debug/build/lib/libtaos.so /usr/lib/libtaos.so 2>/dev/null ln -s /home/TDinternal/debug/build/lib/libtaos.so /usr/lib/libtaos.so.1 2>/dev/null + ln -s /home/TDinternal/debug/build/lib/libtaosnative.so /usr/lib/libtaosnative.so 2>/dev/null + ln -s /home/TDinternal/debug/build/lib/libtaosnative.so /usr/lib/libtaosnative.so.1 2>/dev/null ln -s /home/TDinternal/community/include/client/taos.h /usr/include/taos.h 2>/dev/null ln -s /home/TDinternal/community/include/common/taosdef.h /usr/include/taosdef.h 2>/dev/null ln -s /home/TDinternal/community/include/util/taoserror.h /usr/include/taoserror.h 2>/dev/null @@ -75,6 +79,8 @@ ulimit -c unlimited md5sum /usr/lib/libtaos.so.1 md5sum /home/TDinternal/debug/build/lib/libtaos.so +md5sum /usr/lib/libtaosnative.so.1 +md5sum /home/TDinternal/debug/build/lib/libtaosnative.so #get python connector and update: taospy and taos-ws-py to latest pip3 install taospy==2.7.21 @@ -84,6 +90,8 @@ RET=$? echo "cmd exit code: $RET" md5sum /usr/lib/libtaos.so.1 md5sum /home/TDinternal/debug/build/lib/libtaos.so +md5sum /usr/lib/libtaosnative.so.1 +md5sum /home/TDinternal/debug/build/lib/libtaosnative.so if [ $RET -ne 0 ]; then diff --git a/tests/pytest/auto_run_regular.sh b/tests/pytest/auto_run_regular.sh index 27e801326989..c5f275cd6803 100755 --- a/tests/pytest/auto_run_regular.sh +++ b/tests/pytest/auto_run_regular.sh @@ -5,6 +5,8 @@ export PATH=$PATH:/home/TDengine/debug/build/bin export LD_LIBRARY_PATH=/home/TDengine/debug/build/lib ln -s /home/TDengine/debug/build/lib/libtaos.so /usr/lib/libtaos.so 2>/dev/null ln -s /home/TDengine/debug/build/lib/libtaos.so /usr/lib/libtaos.so.1 2>/dev/null +ln -s /home/TDengine/debug/build/lib/libtaosnative.so /usr/lib/libtaosnative.so 2>/dev/null +ln -s /home/TDengine/debug/build/lib/libtaosnative.so /usr/lib/libtaosnative.so.1 2>/dev/null ln -s /home/TDengine/include/client/taos.h /usr/include/taos.h 2>/dev/null # run crash_gen auto script diff --git a/tests/pytest/auto_run_valgrind.sh b/tests/pytest/auto_run_valgrind.sh index c7154e867c97..4b5e9ee91c44 100755 --- a/tests/pytest/auto_run_valgrind.sh +++ b/tests/pytest/auto_run_valgrind.sh @@ -5,6 +5,8 @@ export PATH=$PATH:/home/TDengine/debug/build/bin export LD_LIBRARY_PATH=/home/TDengine/debug/build/lib ln -s /home/TDengine/debug/build/lib/libtaos.so /usr/lib/libtaos.so 2>/dev/null ln -s /home/TDengine/debug/build/lib/libtaos.so /usr/lib/libtaos.so.1 2>/dev/null +ln -s /home/TDengine/debug/build/lib/libtaosnative.so /usr/lib/libtaosnative.so 2>/dev/null +ln -s /home/TDengine/debug/build/lib/libtaosnative.so /usr/lib/libtaosnative.so.1 2>/dev/null ln -s /home/TDengine/include/client/taos.h /usr/include/taos.h 2>/dev/null # run crash_gen auto script diff --git a/tests/pytest/auto_run_valgrind_cluster.sh b/tests/pytest/auto_run_valgrind_cluster.sh index 62bc22e923a2..4706bbd6d058 100755 --- a/tests/pytest/auto_run_valgrind_cluster.sh +++ b/tests/pytest/auto_run_valgrind_cluster.sh @@ -5,6 +5,8 @@ export PATH=$PATH:/home/TDengine/debug/build/bin export LD_LIBRARY_PATH=/home/TDengine/debug/build/lib ln -s /home/TDengine/debug/build/lib/libtaos.so /usr/lib/libtaos.so 2>/dev/null ln -s /home/TDengine/debug/build/lib/libtaos.so /usr/lib/libtaos.so.1 2>/dev/null +ln -s /home/TDengine/debug/build/lib/libtaosnative.so /usr/lib/libtaosnative.so 2>/dev/null +ln -s /home/TDengine/debug/build/lib/libtaosnative.so /usr/lib/libtaosnative.so.1 2>/dev/null ln -s /home/TDengine/include/client/taos.h /usr/include/taos.h 2>/dev/null # run crash_gen auto script diff --git a/tests/pytest/dockerCluster/Dockerfile b/tests/pytest/dockerCluster/Dockerfile index 437dbc65e643..ecb068541f11 100644 --- a/tests/pytest/dockerCluster/Dockerfile +++ b/tests/pytest/dockerCluster/Dockerfile @@ -33,6 +33,7 @@ COPY --from=builder /root/bin/taosdump /usr/bin COPY --from=builder /root/bin/taos /usr/bin COPY --from=builder /root/cfg/taos.cfg /etc/taos/ COPY --from=builder /root/lib/libtaos.so.* /usr/lib/libtaos.so.1 +COPY --from=builder /root/lib/libtaosnative.so.* /usr/lib/libtaosnative.so.1 ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/lib" ENV LC_CTYPE=en_US.UTF-8 diff --git a/tests/system-test/test.py b/tests/system-test/test.py index cd0e60160caf..57854e5717b7 100644 --- a/tests/system-test/test.py +++ b/tests/system-test/test.py @@ -40,6 +40,9 @@ import taosrest import taosws +from taos.cinterface import * +taos.taos_options(6, "native") + def checkRunTimeError(): import win32gui timeCount = 0 @@ -252,8 +255,9 @@ def runOnPreviousCluster(host, config, fileName): # # do exeCmd command # + taosAdapter = True # default is websocket , so must start taosAdapter if not execCmd == "": - if restful or websocket: + if taosAdapter or restful or websocket: tAdapter.init(deployPath) else: tdDnodes.init(deployPath) @@ -292,7 +296,7 @@ def runOnPreviousCluster(host, config, fileName): if valgrind: time.sleep(2) - if restful or websocket: + if taosAdapter or restful or websocket: toBeKilled = "taosadapter" # killCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}' | xargs kill -TERM > /dev/null 2>&1" % toBeKilled @@ -388,7 +392,7 @@ def runOnPreviousCluster(host, config, fileName): tdDnodes.deploy(1,updateCfgDict) tdDnodes.start(1) tdCases.logSql(logSql) - if restful or websocket: + if taosAdapter or restful or websocket: tAdapter.deploy(adapter_cfg_dict) tAdapter.start() @@ -428,7 +432,7 @@ def runOnPreviousCluster(host, config, fileName): tdDnodes.starttaosd(dnode.index) tdCases.logSql(logSql) - if restful or websocket: + if taosAdapter or restful or websocket: tAdapter.deploy(adapter_cfg_dict) tAdapter.start() @@ -550,7 +554,7 @@ def runOnPreviousCluster(host, config, fileName): except: pass - if restful or websocket: + if taosAdapter or restful or websocket: tAdapter.init(deployPath, masterIp) tAdapter.stop(force_kill=True) @@ -560,7 +564,7 @@ def runOnPreviousCluster(host, config, fileName): tdDnodes.start(1) tdCases.logSql(logSql) - if restful or websocket: + if taosAdapter or restful or websocket: tAdapter.deploy(adapter_cfg_dict) tAdapter.start() @@ -615,7 +619,7 @@ def runOnPreviousCluster(host, config, fileName): tdDnodes.starttaosd(dnode.index) tdCases.logSql(logSql) - if restful or websocket: + if taosAdapter or restful or websocket: tAdapter.deploy(adapter_cfg_dict) tAdapter.start() diff --git a/tests/taosc_test/CMakeLists.txt b/tests/taosc_test/CMakeLists.txt index f622d1ccdefb..7cd01175b88b 100644 --- a/tests/taosc_test/CMakeLists.txt +++ b/tests/taosc_test/CMakeLists.txt @@ -16,7 +16,7 @@ aux_source_directory(src OS_SRC) # taoscTest add_executable(taoscTest "taoscTest.cpp") -target_link_libraries(taoscTest PUBLIC ${TAOS_LIB} os util common gtest_main) +target_link_libraries(taoscTest PUBLIC ${TAOS_NATIVE_LIB} os util common gtest_main) target_include_directories( taoscTest PUBLIC "${TD_SOURCE_DIR}/include/os" diff --git a/tools/inc/pub.h b/tools/inc/pub.h new file mode 100644 index 000000000000..7e96c7a324fa --- /dev/null +++ b/tools/inc/pub.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the MIT license as published by the Free Software + * Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef PUB_H_ +#define PUB_H_ + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef WINDOWS +#define strcasecmp _stricmp +#define strncasecmp _strnicmp +#endif + +// +// -------------- define ------------------ +// + +// connect mode string +#define STR_NATIVE "Native" +#define STR_WEBSOCKET "WebSocket" + +#define DRIVER_OPT "driver" +#define DRIVER_DESC "Connect driver , value can be \"Native\" or \"WebSocket\"" + +#define DSN_DESC "The dsn to connect the cloud service." +#define OLD_DSN_DESC "same with -X options" + +#define DSN_NATIVE_CONFLICT "DSN option not support in native connection mode.\n" + +// connect mode type define +#define CONN_MODE_INVALID -1 +#define CONN_MODE_NATIVE 0 +#define CONN_MODE_WEBSOCKET 1 + +// define error show module +#define INIT_PHASE "init" +#define TIP_ENGINE_ERR "Call engine failed." + +// default port +#define DEFAULT_PORT_WS_LOCAL 6041 +#define DEFAULT_PORT_WS_CLOUD 443 +#define DEFAULT_PORT_NATIVE 6030 + + +// +// -------------- api ------------------ +// + +// get comn mode, if invalid argp then exit app +int8_t getConnMode(char *arg); + +char* strToLowerCopy(const char *str); +int32_t parseDsn(char* dsn, char **host, char **port, char **user, char **pwd, char* error); + +#endif // PUB_H_ \ No newline at end of file diff --git a/tools/shell/CMakeLists.txt b/tools/shell/CMakeLists.txt index 2301f3380326..1b7e006e825e 100644 --- a/tools/shell/CMakeLists.txt +++ b/tools/shell/CMakeLists.txt @@ -1,6 +1,6 @@ aux_source_directory(src SHELL_SRC) -add_executable(shell ${SHELL_SRC}) +add_executable(shell ${SHELL_SRC} ../src/pub.c) IF(TD_LINUX_64 AND JEMALLOC_ENABLED) ADD_DEFINITIONS(-DTD_JEMALLOC_ENABLED -I${CMAKE_BINARY_DIR}/build/include -L${CMAKE_BINARY_DIR}/build/lib -Wl,-rpath,${CMAKE_BINARY_DIR}/build/lib -ljemalloc) @@ -10,22 +10,6 @@ ELSE() SET(LINK_JEMALLOC "") ENDIF() -IF(TD_LINUX AND TD_WEBSOCKET) - ADD_DEFINITIONS(-DWEBSOCKET -I${CMAKE_BINARY_DIR}/build/include -ltaosws) - SET(LINK_WEBSOCKET "-L${CMAKE_BINARY_DIR}/build/lib -ltaosws") - ADD_DEPENDENCIES(shell taosws-rs) -ELSEIF(TD_DARWIN AND TD_WEBSOCKET) - ADD_DEFINITIONS(-DWEBSOCKET -I${CMAKE_BINARY_DIR}/build/include) - SET(LINK_WEBSOCKET "${CMAKE_BINARY_DIR}/build/lib/libtaosws.dylib") - ADD_DEPENDENCIES(shell taosws-rs) -ELSEIF(TD_WINDOWS AND TD_WEBSOCKET) - ADD_DEFINITIONS(-DWEBSOCKET -I${CMAKE_BINARY_DIR}/build/include) - SET(LINK_WEBSOCKET "${CMAKE_BINARY_DIR}/build/lib/taosws.lib") - ADD_DEPENDENCIES(shell taosws-rs) -ELSE() - SET(LINK_WEBSOCKET "") -ENDIF() - IF(TD_LINUX AND TD_ALPINE) SET(LINK_ARGP "/usr/lib/libargp.a") ELSE() @@ -33,9 +17,9 @@ ELSE() ENDIF() if(TD_WINDOWS) - target_link_libraries(shell PUBLIC ${TAOS_LIB_STATIC} ${LINK_WEBSOCKET}) + target_link_libraries(shell PUBLIC ${TAOS_LIB}) else() - target_link_libraries(shell PUBLIC ${TAOS_LIB} ${LINK_WEBSOCKET} ${LINK_JEMALLOC} ${LINK_ARGP}) + target_link_libraries(shell PUBLIC ${TAOS_LIB} ${LINK_JEMALLOC} ${LINK_ARGP}) endif() target_link_libraries( @@ -57,13 +41,11 @@ SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME taos) IF(TD_LINUX) # include include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc) + # shell_ut library - add_library(shell_ut STATIC ${SHELL_SRC}) + add_library(shell_ut STATIC ${SHELL_SRC} ../src/pub.c) - IF(TD_WEBSOCKET) - ADD_DEPENDENCIES(shell_ut taosws-rs) - ENDIF() - target_link_libraries(shell_ut PUBLIC ${TAOS_LIB} ${LINK_WEBSOCKET} ${LINK_JEMALLOC} ${LINK_ARGP}) + target_link_libraries(shell_ut PUBLIC ${TAOS_LIB} ${LINK_JEMALLOC} ${LINK_ARGP}) target_link_libraries(shell_ut PRIVATE os common transport geometry util) # util depends @@ -76,5 +58,18 @@ IF(TD_LINUX) # unit test IF(${BUILD_TEST}) ADD_SUBDIRECTORY(test) - ENDIF(${BUILD_TEST}) + ENDIF(${BUILD_TEST}) ENDIF() + +# +# collect --version information +# +MESSAGE("collect --version show info:") +# version +IF (DEFINED TD_VER_NUMBER) + ADD_DEFINITIONS(-DTD_VER_NUMBER="${TD_VER_NUMBER}") + MESSAGE(STATUS "taos version:${TD_VER_NUMBER}") +ELSE () + # abort build + MESSAGE(FATAL_ERROR "build taos not found TD_VER_NUMBER define.") +ENDIF () \ No newline at end of file diff --git a/tools/shell/inc/shellAuto.h b/tools/shell/inc/shellAuto.h index 7583932ff512..836898cdf16d 100644 --- a/tools/shell/inc/shellAuto.h +++ b/tools/shell/inc/shellAuto.h @@ -31,7 +31,7 @@ void pressTabKey(SShellCmd* cmd); void pressOtherKey(char c); // init shell auto function , shell start call once -bool shellAutoInit(); +void shellAutoInit(); // set conn void shellSetConn(TAOS* conn, bool runOnce); @@ -51,9 +51,8 @@ void showAD(bool end); // show all commands help void showHelp(); - // -// for unit test +// for unit test // bool fieldOptionsArea(char* p); bool isCreateFieldsArea(char* p); diff --git a/tools/shell/inc/shellInt.h b/tools/shell/inc/shellInt.h index 9e14cd32f0c8..98d496b63ef6 100644 --- a/tools/shell/inc/shellInt.h +++ b/tools/shell/inc/shellInt.h @@ -17,23 +17,22 @@ #define _TD_SHELL_INT_H_ #include "os.h" -#include "taos.h" #include "taosdef.h" #include "taoserror.h" +#include "taos.h" +#include "tcommon.h" #include "tconfig.h" #include "tglobal.h" #include "trpc.h" #include "ttypes.h" #include "tutil.h" +#include "tversion.h" +#include "version.h" +#include "../../inc/pub.h" -#ifdef WEBSOCKET -#include "taosws.h" - -#define SHELL_WS_TIMEOUT 30 -#define SHELL_WS_DSN_BUFF 256 -#define SHELL_WS_DSN_MASK 10 -#endif - +#define SHELL_WS_TIMEOUT 30 +#define SHELL_WS_DSN_BUFF 256 +#define SHELL_WS_DSN_MASK 10 #define SHELL_MAX_HISTORY_SIZE 1000 #define SHELL_MAX_COMMAND_SIZE 1048586 #define SHELL_HISTORY_FILE ".taos_history" @@ -48,7 +47,9 @@ #define SHELL_FLOAT_WIDTH 20 #define SHELL_DOUBLE_WIDTH 25 -#define ERROR_CODE_DETAIL "\r\n\r\nTo view possible causes and suggested actions for error codes, see \r\n\"Error Code Reference\" in the TDengine online documentation.\r\n" +#define ERROR_CODE_DETAIL \ + "\r\n\r\nTo view possible causes and suggested actions for error codes, see \r\n\"Error Code Reference\" in the " \ + "TDengine online documentation.\r\n" typedef struct { char* hist[SHELL_MAX_HISTORY_SIZE]; char file[TSDB_FILENAME_LEN]; @@ -79,20 +80,17 @@ typedef struct { int32_t pktNum; int32_t displayWidth; int32_t abort; -#ifdef WEBSOCKET - bool restful; - bool cloud; - bool local; char* dsn; int32_t timeout; -#endif + int8_t connMode; + bool port_inputted; } SShellArgs; typedef struct { - const char *clientVersion; - char cusName[32]; - char promptHeader[32]; - char promptContinue[32]; + const char* clientVersion; + char cusName[32]; + char promptHeader[32]; + char promptContinue[32]; const char* osname; int32_t promptSize; char programVersion[256]; @@ -106,10 +104,6 @@ typedef struct { TdThread pid; tsem_t cancelSem; bool exit; -#ifdef WEBSOCKET - WS_TAOS* ws_conn; - bool stop_query; -#endif } SShellObj; typedef struct { @@ -134,6 +128,7 @@ int32_t shellCalcColWidth(TAOS_FIELD *field, int32_t precision); void shellPrintHeader(TAOS_FIELD *fields, int32_t *width, int32_t num_fields); void shellPrintField(const char *val, TAOS_FIELD *field, int32_t width, int32_t length, int32_t precision); void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, int32_t length, int32_t precision); + // shellUtil.c int32_t shellCheckIntSize(); void shellPrintVersion(); @@ -142,21 +137,13 @@ void shellGenerateAuth(); void shellDumpConfig(); void shellCheckServerStatus(); bool shellRegexMatch(const char* s, const char* reg, int32_t cflags); +int32_t getDsnEnv(); void shellExit(); // shellNettest.c void shellTestNetWork(); -#ifdef WEBSOCKET -void shellCheckConnectMode(); -// shellWebsocket.c -int shell_conn_ws_server(bool first); -int32_t shell_run_websocket(); -void shellRunSingleCommandWebsocketImp(char *command); -#endif - // shellMain.c extern SShellObj shell; -extern void tscWriteCrashInfo(int signum, void *sigInfo, void *context); #endif /*_TD_SHELL_INT_H_*/ diff --git a/tools/shell/inc/shellTire.h b/tools/shell/inc/shellTire.h index 472f604a2c24..247f6dfa27b7 100644 --- a/tools/shell/inc/shellTire.h +++ b/tools/shell/inc/shellTire.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef __TRIE__ -#define __TRIE__ +#ifndef _TD_TRIE_H_ +#define _TD_TRIE_H_ // // The prefix search tree is a efficient storage words and search words tree, it support 95 visible ascii code character diff --git a/tools/shell/src/shellArguments.c b/tools/shell/src/shellArguments.c index 93381b4f51c5..c1c0e7c503d9 100644 --- a/tools/shell/src/shellArguments.c +++ b/tools/shell/src/shellArguments.c @@ -13,13 +13,8 @@ * along with this program. If not, see . */ -#ifdef _TD_DARWIN_64 -#include -#endif - -#include "cus_name.h" #include "shellInt.h" -#include "version.h" +#include "../../inc/pub.h" #define TAOS_CONSOLE_PROMPT_CONTINUE " -> " @@ -43,17 +38,19 @@ #define SHELL_PKT_LEN "Packet length used for net test, default is 1024 bytes." #define SHELL_PKT_NUM "Packet numbers used for net test, default is 100." #define SHELL_BI_MODE "Set BI mode" +#define SHELL_VERSION "Print program version." +#define SHELL_DSN "Use dsn to connect to the cloud server or to a remote server which provides WebSocket connection." +#define SHELL_TIMEOUT "Set the timeout for WebSocket query in seconds, default is 30." #define SHELL_LOG_OUTPUT \ "Specify log output. Options:\n\r\t\t\t stdout, stderr, /dev/null, , /, " \ "\n\r\t\t\t * If OUTPUT contains an absolute directory, logs will be stored in that directory " \ "instead of logDir.\n\r\t\t\t * If OUTPUT contains a relative directory, logs will be stored in the directory " \ "combined with logDir and the relative directory." -#define SHELL_VERSION "Print program version." #ifdef WEBSOCKET -#define SHELL_DSN "Use dsn to connect to the cloud server or to a remote server which provides WebSocket connection." -#define SHELL_REST "Use RESTful mode when connecting." -#define SHELL_TIMEOUT "Set the timeout for websocket query in seconds, default is 30." +#define SHELL_DRIVER_DEFAULT "0." // todo simon -> 1 +#else +#define SHELL_DRIVER_DEFAULT "0." #endif static int32_t shellParseSingleOpt(int32_t key, char *arg); @@ -82,13 +79,13 @@ void shellPrintHelp() { printf("%s%s%s%s\r\n", indent, "-s,", indent, SHELL_CMD); printf("%s%s%s%s\r\n", indent, "-t,", indent, SHELL_STARTUP); printf("%s%s%s%s\r\n", indent, "-u,", indent, SHELL_USER); -#ifdef WEBSOCKET - printf("%s%s%s%s\r\n", indent, "-E,", indent, SHELL_DSN); - printf("%s%s%s%s\r\n", indent, "-R,", indent, SHELL_REST); + printf("%s%s%s%s\r\n", indent, "-E,", indent, OLD_DSN_DESC); printf("%s%s%s%s\r\n", indent, "-T,", indent, SHELL_TIMEOUT); -#endif printf("%s%s%s%s\r\n", indent, "-w,", indent, SHELL_WIDTH); printf("%s%s%s%s\r\n", indent, "-V,", indent, SHELL_VERSION); + printf("%s%s%s%s\r\n", indent, "-X,", indent, DSN_DESC); + printf("%s%s%s%s\r\n", indent, "-Z,", indent, DRIVER_DESC); + #ifdef CUS_EMAIL printf("\r\n\r\nReport bugs to %s.\r\n", CUS_EMAIL); #else @@ -129,16 +126,13 @@ static struct argp_option shellOptions[] = { {"display-width", 'w', "WIDTH", 0, SHELL_WIDTH}, {"netrole", 'n', "NETROLE", 0, SHELL_NET_ROLE}, {"pktlen", 'l', "PKTLEN", 0, SHELL_PKT_LEN}, -#ifdef WEBSOCKET - {"dsn", 'E', "DSN", 0, SHELL_DSN}, - {"restful", 'R', 0, 0, SHELL_REST}, + {"cloud-dsn", 'E', "DSN", 0, OLD_DSN_DESC}, {"timeout", 'T', "SECONDS", 0, SHELL_TIMEOUT}, -#endif {"pktnum", 'N', "PKTNUM", 0, SHELL_PKT_NUM}, {"bimode", 'B', 0, 0, SHELL_BI_MODE}, -#if defined(LINUX) {"log-output", 'o', "OUTPUT", 0, SHELL_LOG_OUTPUT}, -#endif + {"dsn", 'X', "DSN", 0, DSN_DESC}, + {DRIVER_OPT, 'Z', "DRIVER", 0, DRIVER_DESC}, {0}, }; @@ -146,9 +140,10 @@ static error_t shellParseOpt(int32_t key, char *arg, struct argp_state *state) { static struct argp shellArgp = {shellOptions, shellParseOpt, "", ""}; -static void shellParseArgsUseArgp(int argc, char *argv[]) { +static int32_t shellParseArgsUseArgp(int argc, char *argv[]) { argp_program_version = shell.info.programVersion; - argp_parse(&shellArgp, argc, argv, 0, 0, &shell.args); + error_t err = argp_parse(&shellArgp, argc, argv, 0, 0, &shell.args); + return (err != 0); } #endif @@ -163,16 +158,14 @@ static int32_t shellParseSingleOpt(int32_t key, char *arg) { switch (key) { case 'h': pArgs->host = arg; -#ifdef WEBSOCKET - pArgs->cloud = false; -#endif break; case 'P': pArgs->port = atoi(arg); -#ifdef WEBSOCKET - pArgs->cloud = false; -#endif - if (pArgs->port == 0) pArgs->port = -1; + if (pArgs->port == 0) { + pArgs->port = -1; + } else { + pArgs->port_inputted = true; + } break; case 'u': pArgs->user = arg; @@ -189,9 +182,6 @@ static int32_t shellParseSingleOpt(int32_t key, char *arg) { pArgs->is_bi_mode = true; break; case 'c': -#ifdef WEBSOCKET - pArgs->cloud = false; -#endif pArgs->cfgdir = arg; break; case 'C': @@ -229,33 +219,35 @@ static int32_t shellParseSingleOpt(int32_t key, char *arg) { break; #if defined(LINUX) case 'o': + printf(" -o need todo optins.\n"); + // need todo pass tsLogOutput to engine + /* if (strlen(arg) >= PATH_MAX) { - printf("failed to set log output since length overflow, max length is %d\n", PATH_MAX); + printf("failed to set log output since length overflow, max length is %d\r\n", PATH_MAX); return TSDB_CODE_INVALID_CFG; } tsLogOutput = taosMemoryMalloc(PATH_MAX); if (!tsLogOutput) { - printf("failed to set log output: '%s' since %s\n", arg, tstrerror(terrno)); + printf("failed to set log output: '%s' since %s\r\n", arg, tstrerror(terrno)); return terrno; } if (taosExpandDir(arg, tsLogOutput, PATH_MAX) != 0) { - printf("failed to expand log output: '%s' since %s\n", arg, tstrerror(terrno)); + printf("failed to expand log output: '%s' since %s\r\n", arg, tstrerror(terrno)); return terrno; } + */ break; #endif -#ifdef WEBSOCKET - case 'R': - pArgs->restful = true; - break; case 'E': + case 'X': pArgs->dsn = arg; - pArgs->cloud = true; break; case 'T': pArgs->timeout = atoi(arg); break; -#endif + case 'Z': + pArgs->connMode = getConnMode(arg); + break; case 'V': pArgs->is_version = true; break; @@ -270,15 +262,16 @@ static int32_t shellParseSingleOpt(int32_t key, char *arg) { } return 0; } + #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) || defined(_TD_DARWIN_64) int32_t shellParseArgsWithoutArgp(int argc, char *argv[]) { SShellArgs *pArgs = &shell.args; + int32_t ret = 0; for (int i = 1; i < argc; i++) { if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "--usage") == 0 || strcmp(argv[i], "-?") == 0 || strcmp(argv[i], "/?") == 0) { - shellParseSingleOpt('?', NULL); - return 0; + return shellParseSingleOpt('?', NULL); } char *key = argv[i]; @@ -292,14 +285,9 @@ int32_t shellParseArgsWithoutArgp(int argc, char *argv[]) { return -1; } - if (key[1] == 'h' || key[1] == 'P' || key[1] == 'u' - || key[1] == 'a' || key[1] == 'c' || key[1] == 's' - || key[1] == 'f' || key[1] == 'd' || key[1] == 'w' - || key[1] == 'n' || key[1] == 'l' || key[1] == 'N' -#ifdef WEBSOCKET - || key[1] == 'E' || key[1] == 'T' -#endif - ) { + if (key[1] == 'h' || key[1] == 'P' || key[1] == 'u' || key[1] == 'a' || key[1] == 'c' || key[1] == 's' || + key[1] == 'f' || key[1] == 'd' || key[1] == 'w' || key[1] == 'n' || key[1] == 'l' || key[1] == 'N' || + key[1] == 'E' || key[1] == 'T' || key[1] == 'X' || key[1] == 'Z') { if (i + 1 >= argc) { fprintf(stderr, "option %s requires an argument\r\n", key); return -1; @@ -309,21 +297,19 @@ int32_t shellParseArgsWithoutArgp(int argc, char *argv[]) { fprintf(stderr, "option %s requires an argument\r\n", key); return -1; } - shellParseSingleOpt(key[1], val); + ret = shellParseSingleOpt(key[1], val); i++; - } else if (key[1] == 'p' || key[1] == 'A' || key[1] == 'C' - || key[1] == 'r' || key[1] == 'k' - || key[1] == 't' || key[1] == 'V' - || key[1] == '?' || key[1] == 1 -#ifdef WEBSOCKET - ||key[1] == 'R' -#endif - ) { - shellParseSingleOpt(key[1], NULL); + } else if (key[1] == 'p' || key[1] == 'A' || key[1] == 'C' || key[1] == 'r' || key[1] == 'k' || key[1] == 't' || + key[1] == 'V' || key[1] == '?' || key[1] == 1 || key[1] == 'R'|| key[1] == 'B') { + ret = shellParseSingleOpt(key[1], NULL); } else { fprintf(stderr, "invalid option %s\r\n", key); return -1; } + + if (ret != 0) { + return ret; + } } return 0; @@ -348,6 +334,7 @@ static void shellInitArgs(int argc, char *argv[]) { tstrncpy(shell.args.password, (char *)(argv[i] + 2), sizeof(shell.args.password)); strcpy(argv[i], "-p"); } + printf("\r\n"); } } if (strlen(shell.args.password) == 0) { @@ -359,6 +346,9 @@ static void shellInitArgs(int argc, char *argv[]) { pArgs->pktLen = SHELL_DEF_PKG_LEN; pArgs->pktNum = SHELL_DEF_PKG_NUM; pArgs->displayWidth = SHELL_DEFAULT_MAX_BINARY_DISPLAY_WIDTH; + pArgs->timeout = SHELL_WS_TIMEOUT; + + shell.exit = false; } static int32_t shellCheckArgs() { @@ -442,7 +432,7 @@ static int32_t shellCheckArgs() { int32_t shellParseArgs(int32_t argc, char *argv[]) { shellInitArgs(argc, argv); shell.info.clientVersion = - "Welcome to the %s Command Line Interface, Client Version:%s\r\n" + "Welcome to the %s Command Line Interface, %s Client Version:%s \r\n" "Copyright (c) 2025 by %s, all rights reserved.\r\n\r\n"; #ifdef CUS_NAME strcpy(shell.info.cusName, CUS_NAME); @@ -480,8 +470,7 @@ int32_t shellParseArgs(int32_t argc, char *argv[]) { #else shell.info.osname = "Linux"; snprintf(shell.history.file, TSDB_FILENAME_LEN, "%s/%s", getenv("HOME"), SHELL_HISTORY_FILE); - shellParseArgsUseArgp(argc, argv); - // if (shellParseArgsWithoutArgp(argc, argv) != 0) return -1; + if (shellParseArgsUseArgp(argc, argv) != 0) return -1; if (shell.args.abort) { return -1; } @@ -489,3 +478,35 @@ int32_t shellParseArgs(int32_t argc, char *argv[]) { return shellCheckArgs(); } + +int32_t getDsnEnv() { + if (shell.args.connMode == CONN_MODE_NATIVE) { + if (shell.args.dsn != NULL) { + fprintf(stderr, DSN_NATIVE_CONFLICT); + return -1; + } + } else { + if (shell.args.dsn != NULL) { + return 0; + } else { + // read cloud + shell.args.dsn = getenv("TDENGINE_CLOUD_DSN"); + if (shell.args.dsn && strlen(shell.args.dsn) > 4) { + fprintf(stderr, "Use the environment variable TDENGINE_CLOUD_DSN:%s as the input for the DSN option.\r\n", + shell.args.dsn); + return 0; + } + + // read local + shell.args.dsn = getenv("TDENGINE_DSN"); + if (shell.args.dsn && strlen(shell.args.dsn) > 4) { + fprintf(stderr, "Use the environment variable TDENGINE_DSN:%s as the input for the DSN option.\r\n", + shell.args.dsn); + return 0; + } + shell.args.dsn = NULL; + } + } + + return 0; +} diff --git a/tools/shell/src/shellAuto.c b/tools/shell/src/shellAuto.c index f8ea42917ccf..41ed4177167e 100644 --- a/tools/shell/src/shellAuto.c +++ b/tools/shell/src/shellAuto.c @@ -787,7 +787,7 @@ void GenerateVarType(int type, char** p, int count) { // // init shell auto function , shell start call once -bool shellAutoInit() { +void shellAutoInit() { // command int32_t count = SHELL_COMMAND_COUNT(); for (int32_t i = 0; i < count; i++) { @@ -816,8 +816,6 @@ bool shellAutoInit() { GenerateVarType(WT_VAR_LANGUAGE, udf_language, sizeof(udf_language) / sizeof(char*)); GenerateVarType(WT_VAR_GLOBALKEYS, global_keys, sizeof(global_keys) / sizeof(char*)); GenerateVarType(WT_VAR_FIELD_OPTIONS, field_options, sizeof(field_options) / sizeof(char*)); - - return true; } // set conn diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index a3e542a768d5..a3dd87f5f40a 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -124,15 +124,7 @@ int32_t shellRunSingleCommand(char *command) { shellSourceFile(c_ptr); return 0; } -#ifdef WEBSOCKET - if (shell.args.restful || shell.args.cloud) { - shellRunSingleCommandWebsocketImp(command); - } else { -#endif - shellRunSingleCommandImp(command); -#ifdef WEBSOCKET - } -#endif + shellRunSingleCommandImp(command); return 0; } @@ -287,7 +279,6 @@ void shellRunSingleCommandImp(char *command) { if (error_no == 0) { printf("Query OK, %" PRId64 " row(s) in set (%.6fs)\r\n", numOfRows, (et - st) / 1E6); } else { - terrno = error_no; printf("Query interrupted (%s), %" PRId64 " row(s) in set (%.6fs)\r\n", taos_errstr(NULL), numOfRows, (et - st) / 1E6); } @@ -1094,7 +1085,7 @@ void shellCleanupHistory() { void shellPrintError(TAOS_RES *tres, int64_t st) { int64_t et = taosGetTimestampUs(); - fprintf(stderr, "\r\nDB error: %s[0x%08X] (%.6fs)\r\n", taos_errstr(tres), taos_errno(tres), (et - st) / 1E6); + fprintf(stderr, "\r\nDB error: %s [0x%08X] (%.6fs)\r\n", taos_errstr(tres), taos_errno(tres), (et - st) / 1E6); taos_free_result(tres); } @@ -1246,18 +1237,11 @@ void *shellCancelHandler(void *arg) { continue; } -#ifdef WEBSOCKET - if (shell.args.restful || shell.args.cloud) { - shell.stop_query = true; - } else { -#endif - if (shell.conn) { - shellCmdkilled = true; - taos_kill_query(shell.conn); - } -#ifdef WEBSOCKET + if (shell.conn) { + shellCmdkilled = true; + taos_kill_query(shell.conn); } -#endif + #ifdef WINDOWS printf("\n%s", shell.info.promptHeader); #endif @@ -1302,34 +1286,84 @@ void *shellThreadLoop(void *arg) { } #pragma GCC diagnostic pop +TAOS* createConnect(SShellArgs *pArgs) { + char show[256] = "\0"; + char * host = NULL; + uint16_t port = 0; + char * user = NULL; + char * pwd = NULL; + int32_t code = 0; + char * dsnc = NULL; + + // set mode + if (pArgs->connMode != CONN_MODE_NATIVE && pArgs->dsn) { + dsnc = strToLowerCopy(pArgs->dsn); + if (dsnc == NULL) { + return NULL; + } + + char *cport = NULL; + char error[512] = "\0"; + code = parseDsn(dsnc, &host, &cport, &user, &pwd, error); + if (code) { + printf("%s dsn=%s\n", error, dsnc); + free(dsnc); + return NULL; + } + + // default ws port + if (cport == NULL) { + if (user) + port = DEFAULT_PORT_WS_CLOUD; + else + port = DEFAULT_PORT_WS_LOCAL; + } else { + port = atoi(cport); + } + + // websocket + memcpy(show, pArgs->dsn, 20); + memcpy(show + 20, "...", 3); + memcpy(show + 23, pArgs->dsn + strlen(pArgs->dsn) - 10, 10); + + } else { + + host = (char *)pArgs->host; + user = (char *)pArgs->user; + pwd = pArgs->password; + + if (pArgs->port_inputted) { + port = pArgs->port; + } else { + port = pArgs->connMode == CONN_MODE_NATIVE ? DEFAULT_PORT_NATIVE : DEFAULT_PORT_WS_LOCAL; + } + + sprintf(show, "host:%s port:%d ", host, port); + } + + // connect main + if (pArgs->auth) { + return taos_connect_auth(host, user, pArgs->auth, pArgs->database, port); + } else { + return taos_connect(host, user, pwd, pArgs->database, port); + } +} + int32_t shellExecute() { - printf(shell.info.clientVersion, shell.info.cusName, taos_get_client_info(), shell.info.cusName); + printf(shell.info.clientVersion, shell.info.cusName, + shell.args.connMode == CONN_MODE_NATIVE ? STR_NATIVE : STR_WEBSOCKET, + TD_VER_NUMBER, shell.info.cusName); fflush(stdout); SShellArgs *pArgs = &shell.args; -#ifdef WEBSOCKET - if (shell.args.restful || shell.args.cloud) { - if (shell_conn_ws_server(1)) { - printf("failed to connect to server, reason: %s[0x%08X]\n%s", ws_errstr(NULL), ws_errno(NULL), ERROR_CODE_DETAIL); - fflush(stdout); - return -1; - } - } else { -#endif - if (shell.args.auth == NULL) { - shell.conn = taos_connect(pArgs->host, pArgs->user, pArgs->password, pArgs->database, pArgs->port); - } else { - shell.conn = taos_connect_auth(pArgs->host, pArgs->user, pArgs->auth, pArgs->database, pArgs->port); - } + shell.conn = createConnect(pArgs); - if (shell.conn == NULL) { - printf("failed to connect to server, reason: %s[0x%08X]\n%s", taos_errstr(NULL), taos_errno(NULL), ERROR_CODE_DETAIL); - fflush(stdout); - return -1; - } -#ifdef WEBSOCKET + if (shell.conn == NULL) { + printf("failed to connect to server, reason: %s [0x%08X]\n%s", taos_errstr(NULL), taos_errno(NULL), + ERROR_CODE_DETAIL); + fflush(stdout); + return -1; } -#endif bool runOnce = pArgs->commands != NULL || pArgs->file[0] != 0; shellSetConn(shell.conn, runOnce); @@ -1338,9 +1372,7 @@ int32_t shellExecute() { if (shell.args.is_bi_mode) { // need set bi mode printf("Set BI mode is true.\n"); -#ifndef WEBSOCKET taos_set_conn_mode(shell.conn, TAOS_CONN_MODE_BI, 1); -#endif } if (runOnce) { @@ -1354,15 +1386,8 @@ int32_t shellExecute() { if (pArgs->file[0] != 0) { shellSourceFile(pArgs->file); } -#ifdef WEBSOCKET - if (shell.args.restful || shell.args.cloud) { - ws_close(shell.ws_conn); - } else { -#endif - taos_close(shell.conn); -#ifdef WEBSOCKET - } -#endif + + taos_close(shell.conn); shellWriteHistory(); shellCleanupHistory(); @@ -1381,28 +1406,20 @@ int32_t shellExecute() { taosSetSignal(SIGHUP, shellQueryInterruptHandler); taosSetSignal(SIGINT, shellQueryInterruptHandler); -#ifdef WEBSOCKET - if (!shell.args.restful && !shell.args.cloud) { -#endif - char buf[512] = {0}; - int32_t verType = shellGetGrantInfo(buf); + char buf[512] = {0}; + int32_t verType = shellGetGrantInfo(buf); #ifndef WINDOWS - printfIntroduction(verType); + printfIntroduction(verType); #else -#ifndef WEBSOCKET if (verType == TSDB_VERSION_OSS) { showAD(false); } #endif -#endif - // printf version - if (verType == TSDB_VERSION_ENTERPRISE || verType == TSDB_VERSION_CLOUD) { - printf("%s\n", buf); - } - -#ifdef WEBSOCKET + // printf version + if (verType == TSDB_VERSION_ENTERPRISE || verType == TSDB_VERSION_CLOUD) { + printf("%s\n", buf); } -#endif + while (1) { taosThreadCreate(&shell.pid, NULL, shellThreadLoop, NULL); taosThreadJoin(shell.pid, NULL); @@ -1412,12 +1429,10 @@ int32_t shellExecute() { break; } } -#ifndef WEBSOCKET - // commnuity + if (verType == TSDB_VERSION_OSS) { showAD(true); } -#endif taosThreadJoin(spid, NULL); diff --git a/tools/shell/src/shellMain.c b/tools/shell/src/shellMain.c index 1f6f8fe3dfa0..99aaf326e597 100644 --- a/tools/shell/src/shellMain.c +++ b/tools/shell/src/shellMain.c @@ -14,8 +14,8 @@ */ #define __USE_XOPEN -#include "shellInt.h" #include "shellAuto.h" +#include "shellInt.h" extern SShellObj shell; @@ -24,15 +24,14 @@ void shellCrashHandler(int signum, void *sigInfo, void *context) { taosIgnSignal(SIGHUP); taosIgnSignal(SIGINT); taosIgnSignal(SIGBREAK); - -#if !defined(WINDOWS) - taosIgnSignal(SIGBUS); -#endif taosIgnSignal(SIGABRT); taosIgnSignal(SIGFPE); taosIgnSignal(SIGSEGV); +#if !defined(WINDOWS) + taosIgnSignal(SIGBUS); +#endif - tscWriteCrashInfo(signum, sigInfo, context); + taos_write_crashinfo(signum, sigInfo, context); #ifdef _TD_DARWIN_64 exit(signum); @@ -41,14 +40,33 @@ void shellCrashHandler(int signum, void *sigInfo, void *context) { #endif } -int main(int argc, char *argv[]) { - shell.exit = false; -#ifdef WEBSOCKET - shell.args.timeout = SHELL_WS_TIMEOUT; - shell.args.cloud = true; - shell.args.local = false; -#endif +// init arguments +void initArgument(SShellArgs *pArgs) { + pArgs->host = NULL; + pArgs->port = 0; + pArgs->user = NULL; + pArgs->database = NULL; + + // conn mode + pArgs->dsn = NULL; + pArgs->connMode = CONN_MODE_INVALID; + + pArgs->port_inputted = false; +} +// set conn mode +int32_t setConnMode(int8_t connMode) { + // set conn mode + char * strMode = connMode == CONN_MODE_NATIVE ? STR_NATIVE : STR_WEBSOCKET; + int32_t code = taos_options(TSDB_OPTION_DRIVER, strMode); + if (code != TSDB_CODE_SUCCESS) { + fprintf(stderr, "failed to load driver since %s [0x%08X]\r\n", taos_errstr(NULL), taos_errno(NULL)); + return -1; + } + return 0; +} + +int main(int argc, char *argv[]) { #if !defined(WINDOWS) taosSetSignal(SIGBUS, shellCrashHandler); #endif @@ -56,6 +74,8 @@ int main(int argc, char *argv[]) { taosSetSignal(SIGFPE, shellCrashHandler); taosSetSignal(SIGSEGV, shellCrashHandler); + initArgument(&shell.args); + if (shellCheckIntSize() != 0) { return -1; } @@ -78,37 +98,42 @@ int main(int argc, char *argv[]) { shellPrintHelp(); return 0; } -#ifdef WEBSOCKET - shellCheckConnectMode(); -#endif - if (taos_init() != 0) { - return -1; - } - // kill heart-beat thread when quit - taos_set_hb_quit(1); + if (shell.args.netrole != NULL) { + shellTestNetWork(); + return 0; + } if (shell.args.is_dump_config) { shellDumpConfig(); - taos_cleanup(); return 0; } - if (shell.args.is_startup || shell.args.is_check) { - shellCheckServerStatus(); - taos_cleanup(); - return 0; + if (getDsnEnv() != 0) { + return -1; } - if (shell.args.netrole != NULL) { - shellTestNetWork(); + if (setConnMode(shell.args.connMode)) { + return -1; + } + + if (taos_init() != 0) { + fprintf(stderr, "failed to init shell since %s [0x%08X]\r\n", taos_errstr(NULL), taos_errno(NULL)); + return -1; + } + + // kill heart-beat thread when quit + taos_set_hb_quit(1); + + if (shell.args.is_startup || shell.args.is_check) { + shellCheckServerStatus(); taos_cleanup(); return 0; } - // support port feature shellAutoInit(); int32_t ret = shellExecute(); shellAutoExit(); + return ret; } diff --git a/tools/shell/src/shellNettest.c b/tools/shell/src/shellNettest.c index d1ecf503d242..c779a2d89911 100644 --- a/tools/shell/src/shellNettest.c +++ b/tools/shell/src/shellNettest.c @@ -15,7 +15,6 @@ #define _GNU_SOURCE #include "shellInt.h" -#include "tversion.h" static void shellWorkAsClient() { SShellArgs *pArgs = &shell.args; @@ -30,9 +29,9 @@ static void shellWorkAsClient() { rpcInit.numOfThreads = 1; rpcInit.sessions = 16; rpcInit.connType = TAOS_CONN_CLIENT; - rpcInit.idleTime = tsShellActivityTimer * 1000; + rpcInit.idleTime = 3000; rpcInit.user = "_dnd"; - rpcInit.timeToGetConn = tsTimeToGetAvailableConn; + rpcInit.timeToGetConn = 500000; taosVersionStrToInt(td_version, &rpcInit.compatibilityVer); clientRpc = rpcOpen(&rpcInit); @@ -41,17 +40,16 @@ static void shellWorkAsClient() { goto _OVER; } + if (pArgs->port == 0) { + pArgs->port = 6030; + } if (pArgs->host == NULL) { - pArgs->host = tsFirst; + pArgs->host = "localhost"; } char fqdn[TSDB_FQDN_LEN] = {0}; tstrncpy(fqdn, pArgs->host, TSDB_FQDN_LEN); strtok(fqdn, ":"); - if (pArgs->port == 0) { - pArgs->port = tsServerPort; - } - printf("network test client is initialized, the server is %s:%u\r\n", fqdn, pArgs->port); tstrncpy(epSet.eps[0].fqdn, fqdn, TSDB_FQDN_LEN); @@ -112,18 +110,21 @@ static void shellWorkAsServer() { SShellArgs *pArgs = &shell.args; if (pArgs->port == 0) { - pArgs->port = tsServerPort; + pArgs->port = 6030; + } + if (pArgs->host == NULL) { + pArgs->host = "127.0.0.1"; } SRpcInit rpcInit = {0}; - memcpy(rpcInit.localFqdn, tsLocalFqdn, strlen(tsLocalFqdn)); + memcpy(rpcInit.localFqdn, pArgs->host, strlen(pArgs->host)); rpcInit.localPort = pArgs->port; rpcInit.label = "CHK"; rpcInit.numOfThreads = 2; rpcInit.cfp = (RpcCfp)shellProcessMsg; rpcInit.sessions = 10; rpcInit.connType = TAOS_CONN_SERVER; - rpcInit.idleTime = tsShellActivityTimer * 1000; + rpcInit.idleTime = 3000; taosVersionStrToInt(td_version, &rpcInit.compatibilityVer); @@ -131,13 +132,16 @@ static void shellWorkAsServer() { if (serverRpc == NULL) { printf("failed to init net test server since %s\r\n", terrstr()); } else { - printf("network test server is initialized, port:%u\r\n", pArgs->port); + printf("network test server is initialized, %s:%u\r\n", pArgs->host, pArgs->port); taosSetSignal(SIGTERM, shellNettestHandler); while (1) taosMsleep(10); } } void shellTestNetWork() { + (void)osDefaultInit(); + (void)rpcInit(); + if (strcmp(shell.args.netrole, "client") == 0) { shellWorkAsClient(); } diff --git a/tools/shell/src/shellUtil.c b/tools/shell/src/shellUtil.c index a8c1193ab8a0..73150b89d38d 100644 --- a/tools/shell/src/shellUtil.c +++ b/tools/shell/src/shellUtil.c @@ -50,19 +50,19 @@ bool shellRegexMatch(const char *s, const char *reg, int32_t cflags) { int32_t shellCheckIntSize() { if (sizeof(int8_t) != 1) { - printf("int8 size is %d(!= 1)", (int)sizeof(int8_t)); + printf("int8 size is %d(!= 1)\r\n", (int)sizeof(int8_t)); return -1; } if (sizeof(int16_t) != 2) { - printf("int16 size is %d(!= 2)", (int)sizeof(int16_t)); + printf("int16 size is %d(!= 2)\r\n", (int)sizeof(int16_t)); return -1; } if (sizeof(int32_t) != 4) { - printf("int32 size is %d(!= 4)", (int)sizeof(int32_t)); + printf("int32 size is %d(!= 4)\r\n", (int)sizeof(int32_t)); return -1; } if (sizeof(int64_t) != 8) { - printf("int64 size is %d(!= 8)", (int)sizeof(int64_t)); + printf("int64 size is %d(!= 8)\r\n", (int)sizeof(int64_t)); return -1; } return 0; @@ -78,12 +78,15 @@ void shellGenerateAuth() { } void shellDumpConfig() { - SConfig *pCfg = taosGetCfg(); - if (pCfg == NULL) { - printf("read global config failed!\r\n"); - } else { - cfgDumpCfg(pCfg, 1, true); + (void)osDefaultInit(); + + if (taosInitCfg(configDir, NULL, NULL, NULL, NULL, 1) != 0) { + fprintf(stderr, "failed to load cfg since %s [0x%08X]\n", terrstr(), terrno); + return; } + + cfgDumpCfg(taosGetCfg(), 1, true); + fflush(stdout); } @@ -121,48 +124,6 @@ void shellCheckServerStatus() { } } while (1); } -#ifdef WEBSOCKET -char dsn[1024] = "ws://localhost:6041"; -void shellCheckConnectMode() { - if (shell.args.dsn) { - shell.args.cloud = true; - shell.args.restful = false; - return; - } - if (shell.args.cloud) { - shell.args.dsn = getenv("TDENGINE_CLOUD_DSN"); - if (shell.args.dsn && strlen(shell.args.dsn) > 4) { - shell.args.cloud = true; - shell.args.local = false; - shell.args.restful = false; - return; - } - - shell.args.dsn = getenv("TDENGINE_DSN"); - if (shell.args.dsn && strlen(shell.args.dsn) > 4) { - shell.args.cloud = true; - shell.args.local = true; - shell.args.restful = false; - return; - } - } - - if (shell.args.restful) { - if (!shell.args.host) { - shell.args.host = "localhost"; - } - if (!shell.args.port) { - shell.args.port = 6041; - } - shell.args.dsn = dsn; - snprintf(shell.args.dsn, 1024, "ws://%s:%d", - shell.args.host, shell.args.port); - } - shell.args.cloud = false; - return; - -} -#endif void shellExit() { if (shell.conn != NULL) { diff --git a/tools/shell/src/shellWebsocket.c b/tools/shell/src/shellWebsocket.c deleted file mode 100644 index 61074102be41..000000000000 --- a/tools/shell/src/shellWebsocket.c +++ /dev/null @@ -1,396 +0,0 @@ - -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -#ifdef WEBSOCKET -#include -#include - -// save current database name -char curDBName[128] = ""; // TDB_MAX_DBNAME_LEN is 24, put large - -int shell_conn_ws_server(bool first) { - char cuttedDsn[SHELL_WS_DSN_BUFF] = {0}; - int dsnLen = strlen(shell.args.dsn); - snprintf(cuttedDsn, - ((dsnLen-SHELL_WS_DSN_MASK) > SHELL_WS_DSN_BUFF)? - SHELL_WS_DSN_BUFF:(dsnLen-SHELL_WS_DSN_MASK), - "%s", shell.args.dsn); - fprintf(stdout, "trying to connect %s****** ", cuttedDsn); - fflush(stdout); - for (int i = 0; i < shell.args.timeout; i++) { - if(shell.args.is_bi_mode) { - size_t len = strlen(shell.args.dsn); - char * dsn = taosMemoryMalloc(len + 32); - sprintf(dsn, "%s&conn_mode=1", shell.args.dsn); - shell.ws_conn = ws_connect(dsn); - taosMemoryFree(dsn); - } else { - shell.ws_conn = ws_connect(shell.args.dsn); - } - - if (NULL == shell.ws_conn) { - int errNo = ws_errno(NULL); - if (0xE001 == errNo) { - fprintf(stdout, "."); - fflush(stdout); - taosMsleep(1000); // sleep 1 second then try again - continue; - } else { - fprintf(stderr, "\nfailed to connect %s***, reason: %s\n", - cuttedDsn, ws_errstr(NULL)); - return -1; - } - } else { - break; - } - } - if (NULL == shell.ws_conn) { - fprintf(stdout, "\n timeout\n"); - fprintf(stderr, "\nfailed to connect %s***, reason: %s\n", - cuttedDsn, ws_errstr(NULL)); - return -1; - } else { - fprintf(stdout, "\n"); - } - if (first && shell.args.restful) { - fprintf(stdout, "successfully connected to %s\n\n", - shell.args.dsn); - } else if (first && shell.args.cloud) { - if(shell.args.local) { - const char* host = strstr(shell.args.dsn, "@"); - if(host) { - host += 1; - } else { - host = shell.args.dsn; - } - fprintf(stdout, "successfully connected to %s\n", host); - } else { - fprintf(stdout, "successfully connected to service\n"); - } - } - fflush(stdout); - - // switch to current database if have - if(curDBName[0] !=0) { - char command[256]; - sprintf(command, "use %s;", curDBName); - shellRunSingleCommandWebsocketImp(command); - } - - return 0; -} - -static int horizontalPrintWebsocket(WS_RES* wres, double* execute_time) { - const void* data = NULL; - int rows; - ws_fetch_raw_block(wres, &data, &rows); - if (wres) { - *execute_time += (double)(ws_take_timing(wres)/1E6); - } - if (!rows) { - return 0; - } - int num_fields = ws_field_count(wres); - TAOS_FIELD* fields = (TAOS_FIELD*)ws_fetch_fields(wres); - int precision = ws_result_precision(wres); - - int width[TSDB_MAX_COLUMNS]; - for (int col = 0; col < num_fields; col++) { - width[col] = shellCalcColWidth(fields + col, precision); - } - - shellPrintHeader(fields, width, num_fields); - - int numOfRows = 0; - do { - uint8_t ty; - uint32_t len; - for (int i = 0; i < rows; i++) { - for (int j = 0; j < num_fields; j++) { - putchar(' '); - const void *value = ws_get_value_in_block(wres, i, j, &ty, &len); - shellPrintField((const char*)value, fields+j, width[j], len, precision); - putchar(' '); - putchar('|'); - } - putchar('\r'); - putchar('\n'); - } - numOfRows += rows; - ws_fetch_raw_block(wres, &data, &rows); - } while (rows && !shell.stop_query); - return numOfRows; -} - -static int verticalPrintWebsocket(WS_RES* wres, double* pexecute_time) { - int rows = 0; - const void* data = NULL; - ws_fetch_raw_block(wres, &data, &rows); - if (wres) { - *pexecute_time += (double)(ws_take_timing(wres)/1E6); - } - if (!rows) { - return 0; - } - int num_fields = ws_field_count(wres); - TAOS_FIELD* fields = (TAOS_FIELD*)ws_fetch_fields(wres); - int precision = ws_result_precision(wres); - - int maxColNameLen = 0; - for (int col = 0; col < num_fields; col++) { - int len = (int)strlen(fields[col].name); - if (len > maxColNameLen) { - maxColNameLen = len; - } - } - int numOfRows = 0; - do { - uint8_t ty; - uint32_t len; - for (int i = 0; i < rows; i++) { - printf("*************************** %d.row ***************************\n", - numOfRows + 1); - for (int j = 0; j < num_fields; j++) { - TAOS_FIELD* field = fields + j; - int padding = (int)(maxColNameLen - strlen(field->name)); - printf("%*.s%s: ", padding, " ", field->name); - const void *value = ws_get_value_in_block(wres, i, j, &ty, &len); - shellPrintField((const char*)value, field, 0, len, precision); - putchar('\n'); - } - numOfRows++; - } - ws_fetch_raw_block(wres, &data, &rows); - } while (rows && !shell.stop_query); - return numOfRows; -} - -static int dumpWebsocketToFile(const char* fname, WS_RES* wres, - double* pexecute_time) { - char fullname[PATH_MAX] = {0}; - if (taosExpandDir(fname, fullname, PATH_MAX) != 0) { - tstrncpy(fullname, fname, PATH_MAX); - } - - TdFilePtr pFile = taosOpenFile(fullname, - TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM); - if (pFile == NULL) { - fprintf(stderr, "failed to open file: %s\r\n", fullname); - return -1; - } - int rows = 0; - const void* data = NULL; - ws_fetch_raw_block(wres, &data, &rows); - if (wres) { - *pexecute_time += (double)(ws_take_timing(wres)/1E6); - } - if (!rows) { - taosCloseFile(&pFile); - return 0; - } - int numOfRows = 0; - TAOS_FIELD* fields = (TAOS_FIELD*)ws_fetch_fields(wres); - int num_fields = ws_field_count(wres); - int precision = ws_result_precision(wres); - for (int col = 0; col < num_fields; col++) { - if (col > 0) { - taosFprintfFile(pFile, ","); - } - taosFprintfFile(pFile, "%s", fields[col].name); - } - taosFprintfFile(pFile, "\r\n"); - do { - uint8_t ty; - uint32_t len; - numOfRows += rows; - for (int i = 0; i < rows; i++) { - for (int j = 0; j < num_fields; j++) { - if (j > 0) { - taosFprintfFile(pFile, ","); - } - const void *value = ws_get_value_in_block(wres, i, j, &ty, &len); - shellDumpFieldToFile(pFile, (const char*)value, - fields + j, len, precision); - } - taosFprintfFile(pFile, "\r\n"); - } - ws_fetch_raw_block(wres, &data, &rows); - } while (rows && !shell.stop_query); - taosCloseFile(&pFile); - return numOfRows; -} - -static int shellDumpWebsocket(WS_RES *wres, char *fname, - int *error_no, bool vertical, - double* pexecute_time) { - int numOfRows = 0; - if (fname != NULL) { - numOfRows = dumpWebsocketToFile(fname, wres, pexecute_time); - } else if (vertical) { - numOfRows = verticalPrintWebsocket(wres, pexecute_time); - } else { - numOfRows = horizontalPrintWebsocket(wres, pexecute_time); - } - *error_no = ws_errno(wres); - return numOfRows; -} - -char * strendG(const char* pstr); -void shellRunSingleCommandWebsocketImp(char *command) { - int64_t st, et; - char *sptr = NULL; - char *cptr = NULL; - char *fname = NULL; - bool printMode = false; - - if ((sptr = strstr(command, ">>")) != NULL) { - fname = sptr + 2; - while (*fname == ' ') fname++; - *sptr = '\0'; - - cptr = strstr(fname, ";"); - if (cptr != NULL) { - *cptr = '\0'; - } - } - - if ((sptr = strendG(command)) != NULL) { - *sptr = '\0'; - printMode = true; // When output to a file, the switch does not work. - } - - shell.stop_query = false; - WS_RES* res; - - for (int reconnectNum = 0; reconnectNum < 2; reconnectNum++) { - if (!shell.ws_conn && shell_conn_ws_server(0) || shell.stop_query) { - return; - } - st = taosGetTimestampUs(); - - res = ws_query_timeout(shell.ws_conn, command, shell.args.timeout); - int code = ws_errno(res); - if (code != 0 && !shell.stop_query) { - // if it's not a ws connection error - if (TSDB_CODE_WS_DSN_ERROR != (code&TSDB_CODE_WS_DSN_ERROR)) { - et = taosGetTimestampUs(); - fprintf(stderr, "\nDB: error:0x%08X %s (%.6fs)\n", - ws_errno(res), ws_errstr(res), (et - st)/1E6); - ws_free_result(res); - return; - } - if (code == TSDB_CODE_WS_SEND_TIMEOUT - || code == TSDB_CODE_WS_RECV_TIMEOUT) { - fprintf(stderr, "Hint: use -T to increase the timeout in seconds\n"); - } else if (code == TSDB_CODE_WS_INTERNAL_ERRO - || code == TSDB_CODE_WS_CLOSED) { - shell.ws_conn = NULL; - } - ws_free_result(res); - if (reconnectNum == 0) { - continue; - } else { - fprintf(stderr, "The server is disconnected, will try to reconnect\n"); - } - return; - } - break; - } - - double execute_time = 0; - if (res) { - execute_time = ws_take_timing(res)/1E6; - } - - if (shellRegexMatch(command, "^\\s*use\\s+[a-zA-Z0-9_]+\\s*;\\s*$", - REG_EXTENDED | REG_ICASE)) { - - // copy dbname to curDBName - char *p = command; - bool firstStart = false; - bool firstEnd = false; - int i = 0; - while (*p != 0) { - if (*p != ' ') { - // not blank - if (!firstStart) { - firstStart = true; - } else if (firstEnd) { - if(*p == ';' && *p != '\\') { - break; - } - // database name - curDBName[i++] = *p; - if(i + 4 > sizeof(curDBName)) { - // DBName is too long, reset zero and break - i = 0; - break; - } - } - } else { - // blank - if(firstStart == true && firstEnd == false){ - firstEnd = true; - } - if(firstStart && firstEnd && i > 0){ - // blank after database name - break; - } - } - // move next - p++; - } - // append end - curDBName[i] = 0; - - fprintf(stdout, "Database changed to %s.\r\n\r\n", curDBName); - fflush(stdout); - ws_free_result(res); - return; - } - - int numOfRows = 0; - if (ws_is_update_query(res)) { - numOfRows = ws_affected_rows(res); - et = taosGetTimestampUs(); - double total_time = (et - st)/1E3; - double net_time = total_time - (double)execute_time; - printf("Query Ok, %d of %d row(s) in database\n", numOfRows, numOfRows); - printf("Execute: %.2f ms Network: %.2f ms Total: %.2f ms\n", - execute_time, net_time, total_time); - } else { - int error_no = 0; - numOfRows = shellDumpWebsocket(res, fname, &error_no, - printMode, &execute_time); - if (numOfRows < 0) { - ws_free_result(res); - return; - } - et = taosGetTimestampUs(); - double total_time = (et - st) / 1E3; - double net_time = total_time - execute_time; - if (error_no == 0 && !shell.stop_query) { - printf("Query OK, %d row(s) in set\n", numOfRows); - printf("Execute: %.2f ms Network: %.2f ms Total: %.2f ms\n", - execute_time, net_time, total_time); - } else { - printf("Query interrupted, %d row(s) in set (%.6fs)\n", numOfRows, - (et - st)/1E6); - } - } - printf("\n"); - ws_free_result(res); -} -#endif diff --git a/tools/src/pub.c b/tools/src/pub.c new file mode 100644 index 000000000000..0e1cbdd654af --- /dev/null +++ b/tools/src/pub.c @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the MIT license as published by the Free Software + * Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + */ + + #include + #include "../inc/pub.h" + + + char* strToLowerCopy(const char *str) { + if (str == NULL) { + return NULL; + } + size_t len = strlen(str); + char *result = (char*)malloc(len + 1); + if (result == NULL) { + return NULL; + } + for (size_t i = 0; i < len; i++) { + result[i] = tolower((unsigned char)str[i]); + } + result[len] = '\0'; + return result; + } + + int32_t parseDsn(char* dsn, char **host, char **port, char **user, char **pwd, char *error) { + // dsn format: + // local http://127.0.0.1:6041 + // cloud https://gw.cloud.taosdata.com?token=617ffdf... + // https://gw.cloud.taosdata.com:433?token=617ffdf... + + // find "://" + char *p1 = strstr(dsn, "://"); + if (p1 == NULL) { + sprintf(error, "%s", "dsn invalid, not found \"://\" "); + return -1; + } + *host = p1 + 3; // host + char *p = *host; + + // find ":" - option + char *p2 = strstr(p, ":"); + if (p2) { + p = p2 + 1; + *port = p2 + 1; // port + *p2 = 0; + } + + // find "?" + char *p3 = strstr(p, "?"); + if (p3) { + p = p3 + 1; + *user = p3 + 1; + *p3 = 0; + } else { + return 0; + } + + // find "=" + char *p4 = strstr(p, "="); + if (p4) { + *p4 = 0; + *pwd = p4 + 1; + } else { + sprintf(error, "%s", "dsn invalid, found \"?\" but not found \"=\" "); + return -1; + } + + return 0; + } + + // get comn mode, if invalid exit app + int8_t getConnMode(char *arg) { + // compare + if (strcasecmp(arg, STR_NATIVE) == 0 || strcasecmp(arg, "0") == 0) { + return CONN_MODE_NATIVE; + } else if (strcasecmp(arg, STR_WEBSOCKET) == 0 || strcasecmp(arg, "1") == 0) { + return CONN_MODE_WEBSOCKET; + } else { + fprintf(stderr, "invalid input %s for option -Z, only support: %s or %s\r\n", arg, STR_NATIVE, STR_WEBSOCKET); + exit(-1); + } + } + \ No newline at end of file diff --git a/tools/taos-tools/inc/bench.h b/tools/taos-tools/inc/bench.h index 97c82ac2fa8b..6b35d4e8e752 100644 --- a/tools/taos-tools/inc/bench.h +++ b/tools/taos-tools/inc/bench.h @@ -16,6 +16,8 @@ #ifndef INC_BENCH_H_ #define INC_BENCH_H_ +#include "pub.h" + #define _GNU_SOURCE #define CURL_STATICLIB #define ALLOW_FORBID_FUNC @@ -71,10 +73,7 @@ #include #include #include - -#ifdef WEBSOCKET -#include -#endif +#include "../../inc/pub.h" #ifdef WINDOWS #define _CRT_RAND_S @@ -254,19 +253,11 @@ typedef unsigned __int32 uint32_t; "when keep trying be enabled." #define BENCH_NODROP "Do not drop database." -#ifdef WEBSOCKET -#define BENCH_DSN "The dsn to connect the cloud service." -#define BENCH_TIMEOUT \ - "The timeout wait on websocket query in seconds, default is 10." -#endif - #define IS_VAR_DATA_TYPE(t) \ (((t) == TSDB_DATA_TYPE_VARCHAR) || ((t) == TSDB_DATA_TYPE_VARBINARY) || ((t) == TSDB_DATA_TYPE_NCHAR) || \ ((t) == TSDB_DATA_TYPE_JSON) || ((t) == TSDB_DATA_TYPE_GEOMETRY)) - - enum TEST_MODE { INSERT_TEST, // 0 QUERY_TEST, // 1 @@ -278,11 +269,9 @@ enum enumSYNC_MODE { SYNC_MODE, ASYNC_MODE, MODE_BUT }; enum enum_TAOS_INTERFACE { TAOSC_IFACE, - REST_IFACE, STMT_IFACE, STMT2_IFACE, SML_IFACE, - SML_REST_IFACE, INTERFACE_BUT }; @@ -743,7 +732,6 @@ typedef struct SArguments_S { uint64_t insert_interval; bool demo_mode; bool aggr_func; - struct sockaddr_in serv_addr; uint64_t totalChildTables; uint64_t actualChildTables; uint64_t autoCreatedChildTables; @@ -757,18 +745,16 @@ typedef struct SArguments_S { #endif bool terminate; bool in_prompt; -#ifdef WEBSOCKET - int32_t timeout; + + // websocket char* dsn; - bool websocket; -#endif + bool supplementInsert; int64_t startTimestamp; int32_t partialColNum; int32_t keep_trying; uint32_t trying_interval; int iface; - int rest_server_ver_major; bool check_sql; int suit; // see define SUIT_ int16_t inputted_vgroups; @@ -779,6 +765,7 @@ typedef struct SArguments_S { char csvPath[MAX_FILE_NAME_LEN]; bool bind_vgroup; + int8_t connMode; // see define CONN_MODE_ } SArguments; typedef struct SBenchConn { @@ -786,10 +773,6 @@ typedef struct SBenchConn { TAOS* ctaos; // check taos TAOS_STMT* stmt; TAOS_STMT2* stmt2; -#ifdef WEBSOCKET - WS_TAOS* taos_ws; - WS_STMT* stmt_ws; -#endif } SBenchConn; #define MAX_BATCOLS 256 @@ -919,18 +902,10 @@ void tmfclose(FILE *fp); int64_t fetchResult(TAOS_RES *res, char *filePath); void prompt(bool NonStopMode); void ERROR_EXIT(const char *msg); -int getServerVersionRest(int16_t rest_port); -int postProceSql(char *sqlstr, char* dbName, int precision, int iface, - int protocol, uint16_t rest_port, bool tcp, - int sockfd, char* filePath); int queryDbExecCall(SBenchConn *conn, char *command); -int queryDbExecRest(char *command, char* dbName, int precision, - int iface, int protocol, bool tcp, int sockfd); SBenchConn* initBenchConn(); void closeBenchConn(SBenchConn* conn); int regexMatch(const char *s, const char *reg, int cflags); -int convertHostToServAddr(char *host, uint16_t port, - struct sockaddr_in *serv_addr); int getAllChildNameOfSuperTable(TAOS *taos, char *dbName, char *stbName, char ** childTblNameOfSuperTbl, int64_t childTblCountOfSuperTbl); @@ -976,9 +951,6 @@ int insertTestProcess(); void postFreeResource(); int queryTestProcess(); int subscribeTestProcess(); -int convertServAddr(int iface, bool tcp, int protocol); -int createSockFd(); -void destroySockFd(int sockfd); void printVersion(); int32_t benchParseSingleOpt(int32_t key, char* arg); @@ -1012,6 +984,9 @@ int tmpGeometry(char *tmp, int iface, Field *field, int64_t k); int tmpInt32ImplTag(Field *field, int i, int k); char* genQMark( int32_t QCnt); +// get colNames , first is tbname +char *genColNames(BArray *cols); + // stmt2 TAOS_STMT2_BINDV* createBindV(int32_t count, int32_t tagCnt, int32_t colCnt); // clear bindv table count tables tag and column @@ -1020,9 +995,6 @@ void clearBindV(TAOS_STMT2_BINDV *bindv); void freeBindV(TAOS_STMT2_BINDV *bindv); void showBindV(TAOS_STMT2_BINDV *bindv, BArray *tags, BArray *cols); -// IFace is rest return True -bool isRest(int32_t iface); - // get group index about dbname.tbname int32_t calcGroupIndex(char* dbName, char* tbName, int32_t groupCnt); @@ -1038,5 +1010,7 @@ void *queryKiller(void *arg); int killSlowQuery(); // fetch super table child name from server int fetchChildTableName(char *dbName, char *stbName); +// call engine error +void engineError(char * module, char * fun, int32_t code); #endif // INC_BENCH_H_ diff --git a/tools/taos-tools/inc/benchData.h b/tools/taos-tools/inc/benchData.h index 0ccbf7df225a..804ae0c7937c 100644 --- a/tools/taos-tools/inc/benchData.h +++ b/tools/taos-tools/inc/benchData.h @@ -29,8 +29,8 @@ int generateRandData(SSuperTable *stbInfo, char *sampleDataBuf, int lenOfOneRow, BArray * fields, int64_t loop, bool tag, BArray *childCols); // prepare -int prepareStmt (TAOS_STMT *stmt, SSuperTable *stbInfo, char* tagData, uint64_t tableSeq); -int prepareStmt2(TAOS_STMT2 *stmt2, SSuperTable *stbInfo, char* tagData, uint64_t tableSeq); +int prepareStmt (TAOS_STMT *stmt, SSuperTable *stbInfo, char* tagData, uint64_t tableSeq, char *db); +int prepareStmt2(TAOS_STMT2 *stmt2, SSuperTable *stbInfo, char* tagData, uint64_t tableSeq, char *db); uint32_t bindParamBatch(threadInfo *pThreadInfo, uint32_t batch, int64_t startTime, int64_t pos, diff --git a/tools/taos-tools/inc/benchLog.h b/tools/taos-tools/inc/benchLog.h index 426112bcd868..44d41af15360 100644 --- a/tools/taos-tools/inc/benchLog.h +++ b/tools/taos-tools/inc/benchLog.h @@ -36,7 +36,6 @@ void unlockLog(int8_t idx); // exit log void exitLog(); - #define debugPrint(fmt, ...) \ do { \ if (g_arguments->debug_print) { \ diff --git a/tools/taos-tools/inc/dump.h b/tools/taos-tools/inc/dump.h index b21dca4343ec..6a92d477c65a 100644 --- a/tools/taos-tools/inc/dump.h +++ b/tools/taos-tools/inc/dump.h @@ -39,10 +39,7 @@ #include #include #include - -#ifdef WEBSOCKET -#include -#endif +#include "../../inc/pub.h" // @@ -377,22 +374,18 @@ typedef struct arguments { bool performance_print; bool dotReplace; int dumpDbCount; -#ifdef WEBSOCKET - bool restful; - bool cloud; - int ws_timeout; + + int8_t connMode; + bool port_inputted; char *dsn; - char *cloudToken; - int cloudPort; - char cloudHost[MAX_HOSTNAME_LEN]; -#endif // put rename db string char * renameBuf; SRenameDB * renameHead; // retry for call engine api int32_t retryCount; - int32_t retrySleepMs; + int32_t retrySleepMs; + } SArguments; bool isSystemDatabase(char *dbName); @@ -479,6 +472,7 @@ int64_t dumpANormalTableNotBelong( void* openQuery(void** taos_v , const char * sql); void closeQuery(void* res); int32_t readRow(void *res, int32_t idx, int32_t col, uint32_t *len, char **data); +void engineError(char * module, char * fun, int32_t code); extern struct arguments g_args; diff --git a/tools/taos-tools/inc/dumpUtil.h b/tools/taos-tools/inc/dumpUtil.h index 484237177e85..b4c05e8d51d8 100644 --- a/tools/taos-tools/inc/dumpUtil.h +++ b/tools/taos-tools/inc/dumpUtil.h @@ -66,18 +66,4 @@ TAOS *taosConnect(const char *dbName); TAOS_RES *taosQuery(TAOS *taos, const char *sql, int32_t *code); -// -// --------------- websocket ------------------ -// -#ifdef WEBSOCKET -// ws connect -WS_TAOS *wsConnect(); -// ws query -WS_RES *wsQuery(WS_TAOS **ws_taos, const char *sql, int32_t *code); -// ws fetch -int32_t wsFetchBlock(WS_RES *rs, const void **pData, int32_t *numOfRows); - -#endif - - #endif // INC_DUMPUTIL_H_ \ No newline at end of file diff --git a/tools/taos-tools/inc/wsdump.h b/tools/taos-tools/inc/wsdump.h deleted file mode 100644 index 5b65b8c17c76..000000000000 --- a/tools/taos-tools/inc/wsdump.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef INC_WSDUMP_H_ -#define INC_WSDUMP_H_ - -// -// --------------- websocket ------------------ -// - -#ifdef WEBSOCKET - -#include -#include -#include - -int cleanIfQueryFailedWS(const char *funcname, int lineno, char *command, WS_RES *res); -int getTableRecordInfoWS(char *dbName, char *table, TableRecordInfo *pTableRecordInfo); -int getDbCountWS(WS_RES *ws_res); -int64_t getNtbCountOfStbWS(char *dbName, const char *stbName); -int getTableDesFromStbWS(WS_TAOS **taos_v, const char *dbName, const TableDes *stbTableDes, const char *table, - TableDes **ppTableDes); -int getTableDesWS(WS_TAOS **taos_v, const char *dbName, const char *table, TableDes *tableDes, const bool colOnly); -int64_t queryDbForDumpOutCountWS(char *command, WS_TAOS **taos_v, const char *dbName, const char *tbName, - const int precision); -TAOS_RES *queryDbForDumpOutOffsetWS(WS_TAOS **taos_v, char *command); -int64_t dumpTableDataAvroWS(char *dataFilename, int64_t index, const char *tbName, const bool belongStb, - const char *dbName, const int precision, int colCount, TableDes *tableDes, - int64_t start_time, int64_t end_time); -int64_t fillTbNameArrWS(WS_TAOS **taos_v, char *command, char **tbNameArr, const char *stable, const int64_t preCount); -int readNextTableDesWS(void *ws_res, TableDes *tbDes, int *idx, int *cnt); -void dumpExtraInfoVarWS(void **taos_v, FILE *fp); -int queryDbImplWS(WS_TAOS *taos_v, char *command); -void dumpNormalTablesOfStbWS(threadInfo *pThreadInfo, FILE *fp, char *dumpFilename); -int64_t dumpStbAndChildTbOfDbWS(WS_TAOS **taos_v, SDbInfo *dbInfo, FILE *fpDbs); -int64_t dumpNTablesOfDbWS(WS_TAOS **taos_v, SDbInfo *dbInfo); -int fillDbInfoWS(void **taos_v); -bool jointCloudDsn(); -bool splitCloudDsn(); -int64_t dumpTableDataWS(const int64_t index, FILE *fp, const char *tbName, const char *dbName, const int precision, - TableDes *tableDes, const int64_t start_time, const int64_t end_time); -int32_t readRowWS(void *res, int32_t idx, int32_t col, uint32_t *len, char **data); -#endif - -#endif // INC_WSDUMP_H_ \ No newline at end of file diff --git a/tools/taos-tools/src/CMakeLists.txt b/tools/taos-tools/src/CMakeLists.txt index 1f0899db5c73..20e2ad0750bd 100644 --- a/tools/taos-tools/src/CMakeLists.txt +++ b/tools/taos-tools/src/CMakeLists.txt @@ -86,6 +86,7 @@ LINK_DIRECTORIES(/usr/lib /usr/lib64) INCLUDE_DIRECTORIES(/usr/local/taos/include) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_LIST_DIR}/../deps/avro/lang/c/src) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_LIST_DIR}/../deps/toolscJson/src) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_LIST_DIR}/../../inc) INCLUDE_DIRECTORIES(${TD_SOURCE_DIR}/contrib/pthread) INCLUDE_DIRECTORIES(${TD_SOURCE_DIR}/contrib/msvcregex) @@ -116,38 +117,18 @@ IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin SET_PROPERTY(TARGET snappy PROPERTY IMPORTED_LOCATION "${CMAKE_BINARY_DIR}/build/lib/libsnappy.a") - ADD_EXECUTABLE(taosdump taosdump.c dumpUtil.c wsdump.c toolstime.c toolsSys.c toolsDir.c toolsString.c) + ADD_EXECUTABLE(taosdump taosdump.c ../../src/pub.c dumpUtil.c toolstime.c toolsSys.c toolsDir.c toolsString.c) ADD_DEPENDENCIES(deps-snappy apache-avro) ADD_DEPENDENCIES(taosdump deps-jansson) ADD_DEPENDENCIES(taosdump deps-snappy) - ADD_EXECUTABLE(taosBenchmark benchMain.c benchLog.c benchTmq.c benchQuery.c benchCsv.c benchJsonOpt.c benchInsert.c benchInsertMix.c benchDataMix.c wrapDb.c benchData.c benchCommandOpt.c benchUtil.c benchUtilDs.c benchSys.c toolstime.c toolsSys.c toolsString.c) + ADD_EXECUTABLE(taosBenchmark benchMain.c benchLog.c benchTmq.c benchQuery.c benchCsv.c benchJsonOpt.c benchInsert.c benchInsertMix.c benchDataMix.c wrapDb.c benchData.c benchCommandOpt.c benchUtil.c ../../src/pub.c benchUtilDs.c benchSys.c toolstime.c toolsSys.c toolsString.c) ELSE () INCLUDE_DIRECTORIES(/usr/local/include) ADD_DEFINITIONS(-DDARWIN) LINK_DIRECTORIES(/usr/local/lib) SET(OS_ID "Darwin") - ADD_EXECUTABLE(taosBenchmark benchMain.c benchLog.c benchTmq.c benchQuery.c benchCsv.c benchJsonOpt.c benchInsert.c benchInsertMix.c benchDataMix.c wrapDb.c benchData.c benchCommandOpt.c benchUtil.c benchUtilDs.c benchSys.c toolstime.c toolsSys.c toolsString.c) - ENDIF () - - # websocket - IF (${WEBSOCKET}) - ADD_DEFINITIONS(-DWEBSOCKET) - INCLUDE_DIRECTORIES(/usr/local/include/) - SET(WEBSOCKET_LINK_FLAGS "-ltaosws") - - IF (${CMAKE_PROJECT_NAME} STREQUAL "taos-tools") - MESSAGE("libtaosws.so need to be installed first") - ELSE () - ADD_DEPENDENCIES(taosBenchmark taosws-rs) - IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - ADD_DEPENDENCIES(taosdump taosws-rs) - ELSE () - MESSAGE("TODO: taosdump for macOS is WIP") - ENDIF () - ENDIF () - ELSE () - SET(WEBSOCKET_LINK_FLAGS "") + ADD_EXECUTABLE(taosBenchmark benchMain.c benchLog.c benchTmq.c benchQuery.c benchCsv.c benchJsonOpt.c benchInsert.c benchInsertMix.c benchDataMix.c wrapDb.c benchData.c benchCommandOpt.c benchUtil.c ../../src/pub.c benchUtilDs.c benchSys.c toolstime.c toolsSys.c toolsString.c) ENDIF () IF (${TOOLS_COVER} MATCHES "true") @@ -191,7 +172,7 @@ IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin ENDIF() ELSE () MESSAGE("Compiler is: ${CMAKE_C_COMPILER_ID}, version: ${CMAKE_C_COMPILER_VERSION}") - SET(CMAKE_C_FLAGS "-std=c99 -std=gnu11 -O0 -g3 -DDEBUG ${WEBSOCKET_LINK_FLAGS}") + SET(CMAKE_C_FLAGS "-std=c99 -std=gnu11 -O0 -g3 -DDEBUG ") ENDIF () IF (${OS_ID} MATCHES "alpine") @@ -202,8 +183,8 @@ IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin FIND_LIBRARY(LIBZ_LIBRARY z) MESSAGE(${ARGP_LIBRARY}) - TARGET_LINK_LIBRARIES(taosBenchmark taos pthread m toolscJson $<$:${LIBZ_LIBRARY}> $<$:${ARGP_LIBRARY}> ${WEBSOCKET_LINK_FLAGS}) - TARGET_LINK_LIBRARIES(taosdump taos avro jansson atomic pthread m argp $<$:${LIBZ_LIBRARY}> $<$:${ARGP_LIBRARY}> ${WEBSOCKET_LINK_FLAGS}) + TARGET_LINK_LIBRARIES(taosBenchmark taos pthread m toolscJson $<$:${LIBZ_LIBRARY}> $<$:${ARGP_LIBRARY}> ) + TARGET_LINK_LIBRARIES(taosdump taos avro jansson atomic pthread m argp $<$:${LIBZ_LIBRARY}> $<$:${ARGP_LIBRARY}> ) ELSEIF(${OS_ID} MATCHES "Darwin") ADD_LIBRARY(argp STATIC IMPORTED) IF (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64") @@ -213,11 +194,11 @@ IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin SET_PROPERTY(TARGET argp PROPERTY IMPORTED_LOCATION "/usr/local/lib/libargp.a") INCLUDE_DIRECTORIES(/usr/local/include/) ENDIF () - TARGET_LINK_LIBRARIES(taosBenchmark taos pthread m toolscJson argp ${WEBSOCKET_LINK_FLAGS}) + TARGET_LINK_LIBRARIES(taosBenchmark taos pthread m toolscJson argp ) ElSE () MESSAGE("${Yellow} DEBUG mode use shared avro library to link for debug ${ColourReset}") - TARGET_LINK_LIBRARIES(taosdump taos avro jansson atomic pthread m ${WEBSOCKET_LINK_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}) - TARGET_LINK_LIBRARIES(taosBenchmark taos pthread m toolscJson ${WEBSOCKET_LINK_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}) + TARGET_LINK_LIBRARIES(taosdump taos avro jansson atomic pthread m ${GCC_COVERAGE_LINK_FLAGS}) + TARGET_LINK_LIBRARIES(taosBenchmark taos pthread m toolscJson ${GCC_COVERAGE_LINK_FLAGS}) ENDIF() ELSE () @@ -238,15 +219,6 @@ IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin ENDIF () IF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - # ADD_LIBRARY(jansson STATIC IMPORTED) - #SET_PROPERTY(TARGET jansson PROPERTY IMPORTED_LOCATION "/opt/homebrew/opt/jansson/lib/libjansson.a") - - # ADD_LIBRARY(snappy STATIC IMPORTED) - # SET_PROPERTY(TARGET snappy PROPERTY IMPORTED_LOCATION "/opt/homebrew/opt/snappy/lib/libsnappy.a") - - # ADD_LIBRARY(avro STATIC IMPORTED) - # SET_PROPERTY(TARGET avro PROPERTY IMPORTED_LOCATION "/opt/homebrew/opt/avro-c/lib/libavro.a") - # TARGET_LINK_LIBRARIES(taosdump taos avro jansson snappy lzma z pthread) ADD_LIBRARY(argp STATIC IMPORTED) IF (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64") SET_PROPERTY(TARGET argp PROPERTY IMPORTED_LOCATION "/opt/homebrew/opt/argp-standalone/lib/libargp.a") @@ -256,7 +228,7 @@ IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin INCLUDE_DIRECTORIES(/usr/local/include/) ENDIF () - TARGET_LINK_LIBRARIES(taosBenchmark taos pthread m toolscJson argp ${WEBSOCKET_LINK_FLAGS}) + TARGET_LINK_LIBRARIES(taosBenchmark taos pthread m toolscJson argp ) ELSE () EXECUTE_PROCESS ( COMMAND sh -c "awk -F= '/^ID=/{print $2}' /etc/os-release |tr -d '\n' | tr -d '\"'" @@ -307,11 +279,11 @@ IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin FIND_LIBRARY(LIBZ_LIBRARY z) MESSAGE(${LIBZ_LIBRARY}) - TARGET_LINK_LIBRARIES(taosdump taos avro jansson snappy stdc++ lzma atomic pthread $<$:${LIBZ_LIBRARY}> $<$:${ARGP_LIBRARY}> ${WEBSOCKET_LINK_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}) - TARGET_LINK_LIBRARIES(taosBenchmark taos pthread m toolscJson $<$:${LIBZ_LIBRARY}> $<$:${ARGP_LIBRARY}> ${WEBSOCKET_LINK_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}) + TARGET_LINK_LIBRARIES(taosdump taos avro jansson snappy stdc++ lzma atomic pthread $<$:${LIBZ_LIBRARY}> $<$:${ARGP_LIBRARY}> ${GCC_COVERAGE_LINK_FLAGS}) + TARGET_LINK_LIBRARIES(taosBenchmark taos pthread m toolscJson $<$:${LIBZ_LIBRARY}> $<$:${ARGP_LIBRARY}> ${GCC_COVERAGE_LINK_FLAGS}) ELSE() - TARGET_LINK_LIBRARIES(taosdump taos avro jansson snappy stdc++ lzma libz-static atomic pthread ${WEBSOCKET_LINK_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}) - TARGET_LINK_LIBRARIES(taosBenchmark taos pthread m toolscJson ${WEBSOCKET_LINK_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}) + TARGET_LINK_LIBRARIES(taosdump taos avro jansson snappy stdc++ lzma libz-static atomic pthread ${GCC_COVERAGE_LINK_FLAGS}) + TARGET_LINK_LIBRARIES(taosBenchmark taos pthread m toolscJson ${GCC_COVERAGE_LINK_FLAGS}) ENDIF() ENDIF () @@ -321,9 +293,9 @@ ELSE () SET(CMAKE_C_STANDARD 11) SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /utf-8") SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /utf-8") - ADD_EXECUTABLE(taosBenchmark benchMain.c benchLog.c benchTmq.c benchQuery.c benchCsv.c benchJsonOpt.c benchInsert.c benchInsertMix.c benchDataMix.c wrapDb.c benchData.c benchCommandOpt.c benchUtil.c benchUtilDs.c benchSys.c toolstime.c toolsString.c toolsSys.c toolsString.c) + ADD_EXECUTABLE(taosBenchmark benchMain.c benchLog.c benchTmq.c benchQuery.c benchCsv.c benchJsonOpt.c benchInsert.c benchInsertMix.c benchDataMix.c wrapDb.c benchData.c benchCommandOpt.c benchUtil.c ../../src/pub.c benchUtilDs.c benchSys.c toolstime.c toolsString.c toolsSys.c toolsString.c) - ADD_EXECUTABLE(taosdump taosdump.c dumpUtil.c wsdump.c toolsSys.c toolstime.c toolsDir.c toolsString.c) + ADD_EXECUTABLE(taosdump taosdump.c ../../src/pub.c dumpUtil.c toolsSys.c toolstime.c toolsDir.c toolsString.c) ADD_DEPENDENCIES(apache-avro tools-zlib) ADD_DEPENDENCIES(apache-avro deps-jansson) ADD_DEPENDENCIES(apache-avro deps-snappy) @@ -332,19 +304,6 @@ ELSE () ADD_DEPENDENCIES(taosdump deps-libargp) ADD_DEPENDENCIES(taosdump apache-avro) - IF (${WEBSOCKET}) - INCLUDE_DIRECTORIES(/usr/local/include/) - SET(WEBSOCKET_LINK_FLAGS "taosws.lib") - IF (${CMAKE_PROJECT_NAME} STREQUAL "taos-tools") - MESSAGE("taosws.lib need to be installed first") - ELSE () - ADD_DEPENDENCIES(taosBenchmark taosws-rs) - ADD_DEPENDENCIES(taosdump taosws-rs) - ENDIF () - ELSE () - SET(WEBSOCKET_LINK_FLAGS "") - ENDIF () - target_include_directories( taosdump PUBLIC "${TD_SOURCE_DIR}/contrib/pthread" @@ -352,14 +311,10 @@ ELSE () ) IF (${TOOLS_BUILD_TYPE} MATCHES "Debug") - TARGET_LINK_LIBRARIES(taosdump taos avro jansson snappy pthread libargp.lib zlib ${WEBSOCKET_LINK_FLAGS}) + TARGET_LINK_LIBRARIES(taosdump taos avro jansson snappy pthread libargp.lib zlib ) ELSE () - #SET(CMAKE_C_FLAGS "/w /D_WIN32 /DWIN32 /Zi /D NDEBUG /MTd") - # SET(CMAKE_C_FLAGS "/permissive- /GS /GL /Gy /Zc:wchar_t /Zi /Gm- /O2 /Zc:inline /fp:precise /D \"RELEASE\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_UNICODE\" /D \"UNICODE\" /errorReport:prompt /Zc:forScope /Gd /Oi /MTd /FC /EHsc /nologo /diagnostics:column") - # SET(CMAKE_CXX_FLAGS "/permissive- /GS /GL /Gy /Zc:wchar_t /Zi /Gm- /O2 /sdl /Zc:inline /fp:precise /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_UNICODE\" /D \"UNICODE\" /errorReport:prompt /Zc:forScope /Gd /Oi /MTd /FC /EHsc /nologo /diagnostics:column") - #TARGET_LINK_LIBRARIES(taosdump taos avro jansson snappy pthread libargp.lib zlibstatic ${WEBSOCKET_LINK_FLAGS} msvcrt.lib ucrtd.lib) - TARGET_LINK_LIBRARIES(taosdump taos avro jansson snappy pthread libargp.lib zlibstatic ${WEBSOCKET_LINK_FLAGS}) + TARGET_LINK_LIBRARIES(taosdump taos avro jansson snappy pthread libargp.lib zlibstatic ) ENDIF () - TARGET_LINK_LIBRARIES(taosBenchmark taos msvcregex pthread toolscJson ${WEBSOCKET_LINK_FLAGS}) + TARGET_LINK_LIBRARIES(taosBenchmark taos msvcregex pthread toolscJson ) ENDIF () diff --git a/tools/taos-tools/src/benchCommandOpt.c b/tools/taos-tools/src/benchCommandOpt.c index 9bc57bff01e3..1b1f4320177a 100644 --- a/tools/taos-tools/src/benchCommandOpt.c +++ b/tools/taos-tools/src/benchCommandOpt.c @@ -210,13 +210,11 @@ void initArgument() { g_arguments->test_mode = INSERT_TEST; g_arguments->demo_mode = true; g_arguments->host = NULL; - g_arguments->host_auto = true; - g_arguments->port = DEFAULT_PORT; + g_arguments->port = 0; g_arguments->port_inputted = false; - g_arguments->port_auto = true; g_arguments->telnet_tcp_port = TELNET_TCP_PORT; - g_arguments->user = TSDB_DEFAULT_USER; - g_arguments->password = TSDB_DEFAULT_PASS; + g_arguments->user = NULL; + g_arguments->password = NULL; g_arguments->answer_yes = 0; g_arguments->debug_print = 0; g_arguments->binwidth = DEFAULT_BINWIDTH; @@ -233,9 +231,6 @@ void initArgument() { g_arguments->chinese = false; g_arguments->aggr_func = 0; g_arguments->terminate = false; -#ifdef WEBSOCKET - g_arguments->timeout = 10; -#endif g_arguments->supplementInsert = false; g_arguments->startTimestamp = DEFAULT_START_TIME; @@ -244,10 +239,10 @@ void initArgument() { g_arguments->keep_trying = 0; g_arguments->trying_interval = 0; g_arguments->iface = TAOSC_IFACE; - g_arguments->rest_server_ver_major = -1; g_arguments->inputted_vgroups = -1; g_arguments->mistMode = false; + g_arguments->connMode = CONN_MODE_INVALID; initDatabase(); initStable(); @@ -257,29 +252,6 @@ void initArgument() { void modifyArgument() { SDataBase * database = benchArrayGet(g_arguments->databases, 0); SSuperTable *superTable = benchArrayGet(database->superTbls, 0); -#ifdef WEBSOCKET - if (!g_arguments->websocket) { -#endif - if (strlen(g_configDir) - && g_arguments->host_auto - && g_arguments->port_auto) { -#ifdef LINUX - wordexp_t full_path; - if (wordexp(g_configDir, &full_path, 0) != 0) { - errorPrint("Invalid path %s\n", g_configDir); - exit(EXIT_FAILURE); - } - taos_options(TSDB_OPTION_CONFIGDIR, full_path.we_wordv[0]); - wordfree(&full_path); -#else - taos_options(TSDB_OPTION_CONFIGDIR, g_configDir); -#endif - g_arguments->host = DEFAULT_HOST; - g_arguments->port = 0; - } -#ifdef WEBSOCKET - } -#endif superTable->startTimestamp = g_arguments->startTimestamp; @@ -332,10 +304,7 @@ void modifyArgument() { static void *queryStableAggrFunc(void *sarg) { threadInfo *pThreadInfo = (threadInfo *)sarg; - TAOS *taos = NULL; - if (REST_IFACE != g_arguments->iface) { - taos = pThreadInfo->conn->taos; - } + TAOS *taos = taos = pThreadInfo->conn->taos; #ifdef LINUX prctl(PR_SET_NAME, "queryStableAggrFunc"); #endif @@ -391,24 +360,18 @@ static void *queryStableAggrFunc(void *sarg) { } double t = (double)toolsGetTimestampUs(); int32_t code = -1; - if (REST_IFACE == g_arguments->iface) { - code = postProceSql(command, NULL, 0, REST_IFACE, - 0, g_arguments->port, 0, - pThreadInfo->sockfd, NULL); - } else { - TAOS_RES *res = taos_query(taos, command); - code = taos_errno(res); - if (code != 0) { - printErrCmdCodeStr(command, code, res); - free(command); - return NULL; - } - int count = 0; - while (taos_fetch_row(res) != NULL) { - count++; - } - taos_free_result(res); + TAOS_RES *res = taos_query(taos, command); + code = taos_errno(res); + if (code != 0) { + printErrCmdCodeStr(command, code, res); + free(command); + return NULL; + } + int count = 0; + while (taos_fetch_row(res) != NULL) { + count++; } + taos_free_result(res); t = toolsGetTimestampUs() - t; if (fp) { fprintf(fp, "| Speed: %12.2f(per s) | Latency: %.4f(ms) |\n", @@ -469,23 +432,17 @@ static void *queryNtableAggrFunc(void *sarg) { (uint64_t) DEFAULT_START_TIME); double t = (double)toolsGetTimestampUs(); int32_t code = -1; - if (REST_IFACE == g_arguments->iface) { - code = postProceSql(command, NULL, 0, REST_IFACE, - 0, g_arguments->port, 0, - pThreadInfo->sockfd, NULL); - } else { - TAOS_RES *res = taos_query(taos, command); - code = taos_errno(res); - if (code != 0) { - printErrCmdCodeStr(command, code, res); - free(command); - return NULL; - } - while (taos_fetch_row(res) != NULL) { - count++; - } - taos_free_result(res); + TAOS_RES *res = taos_query(taos, command); + code = taos_errno(res); + if (code != 0) { + printErrCmdCodeStr(command, code, res); + free(command); + return NULL; + } + while (taos_fetch_row(res) != NULL) { + count++; } + taos_free_result(res); t = toolsGetTimestampUs() - t; totalT += t; @@ -524,19 +481,11 @@ void queryAggrFunc() { return; } - if (REST_IFACE != g_arguments->iface) { - pThreadInfo->conn = initBenchConn(); - if (pThreadInfo->conn == NULL) { - errorPrint("%s() failed to init connection\n", __func__); - free(pThreadInfo); - return; - } - } else { - pThreadInfo->sockfd = createSockFd(); - if (pThreadInfo->sockfd < 0) { - free(pThreadInfo); - return; - } + pThreadInfo->conn = initBenchConn(); + if (pThreadInfo->conn == NULL) { + errorPrint("%s() failed to init connection\n", __func__); + free(pThreadInfo); + return; } if (stbInfo->use_metric) { pthread_create(&read_id, NULL, queryStableAggrFunc, pThreadInfo); @@ -544,12 +493,7 @@ void queryAggrFunc() { pthread_create(&read_id, NULL, queryNtableAggrFunc, pThreadInfo); } pthread_join(read_id, NULL); - if (REST_IFACE != g_arguments->iface) { - closeBenchConn(pThreadInfo->conn); - } else { - if (pThreadInfo->sockfd) { - destroySockFd(pThreadInfo->sockfd); - } - } + + closeBenchConn(pThreadInfo->conn); free(pThreadInfo); } diff --git a/tools/taos-tools/src/benchData.c b/tools/taos-tools/src/benchData.c index 9b58ad06ca45..2e7f0505506e 100644 --- a/tools/taos-tools/src/benchData.c +++ b/tools/taos-tools/src/benchData.c @@ -229,12 +229,13 @@ void rand_string(char *str, int size, bool chinese) { } // generate prepare sql -char* genPrepareSql(SSuperTable *stbInfo, char* tagData, uint64_t tableSeq) { +char* genPrepareSql(SSuperTable *stbInfo, char* tagData, uint64_t tableSeq, char *db) { int len = 0; char *prepare = benchCalloc(1, TSDB_MAX_ALLOWED_SQL_LEN, true); int n; char *tagQ = NULL; char *colQ = genQMark(stbInfo->cols->size); + char *colNames = NULL; bool tagQFree = false; if(tagData == NULL) { @@ -252,19 +253,28 @@ char* genPrepareSql(SSuperTable *stbInfo, char* tagData, uint64_t tableSeq) { } n = snprintf(prepare + len, TSDB_MAX_ALLOWED_SQL_LEN - len, - "INSERT INTO ? USING `%s` TAGS (%s) %s VALUES(?,%s)", - stbInfo->stbName, tagQ, ttl, colQ); + "INSERT INTO ? USING `%s`.`%s` TAGS (%s) %s VALUES(?,%s)", + db, stbInfo->stbName, tagQ, ttl, colQ); } else { - n = snprintf(prepare + len, TSDB_MAX_ALLOWED_SQL_LEN - len, - "INSERT INTO ? VALUES(?,%s)", colQ); + if (g_arguments->connMode == CONN_MODE_NATIVE) { + // native + n = snprintf(prepare + len, TSDB_MAX_ALLOWED_SQL_LEN - len, + "INSERT INTO ? VALUES(?,%s)", colQ); + } else { + // websocket + colNames = genColNames(stbInfo->cols); + n = snprintf(prepare + len, TSDB_MAX_ALLOWED_SQL_LEN - len, + "INSERT INTO `%s`.`%s`(%s) VALUES(?,?,%s)", db, stbInfo->stbName, colNames, colQ); + } } len += n; - // free from genQMark - if(tagQFree) { + // free + if (tagQFree) { tmfree(tagQ); } tmfree(colQ); + tmfree(colNames); // check valid if (g_arguments->prepared_rand < g_arguments->reqPerReq) { @@ -281,8 +291,8 @@ char* genPrepareSql(SSuperTable *stbInfo, char* tagData, uint64_t tableSeq) { return prepare; } -int prepareStmt(TAOS_STMT *stmt, SSuperTable *stbInfo, char* tagData, uint64_t tableSeq) { - char *prepare = genPrepareSql(stbInfo, tagData, tableSeq); +int prepareStmt(TAOS_STMT *stmt, SSuperTable *stbInfo, char* tagData, uint64_t tableSeq, char *db) { + char *prepare = genPrepareSql(stbInfo, tagData, tableSeq, db); if (taos_stmt_prepare(stmt, prepare, strlen(prepare))) { errorPrint("taos_stmt_prepare(%s) failed. errstr=%s\n", prepare, taos_stmt_errstr(stmt)); tmfree(prepare); @@ -292,8 +302,8 @@ int prepareStmt(TAOS_STMT *stmt, SSuperTable *stbInfo, char* tagData, uint64_t t return 0; } -int prepareStmt2(TAOS_STMT2 *stmt2, SSuperTable *stbInfo, char* tagData, uint64_t tableSeq) { - char *prepare = genPrepareSql(stbInfo, tagData, tableSeq); +int prepareStmt2(TAOS_STMT2 *stmt2, SSuperTable *stbInfo, char* tagData, uint64_t tableSeq, char *db) { + char *prepare = genPrepareSql(stbInfo, tagData, tableSeq, db); if (taos_stmt2_prepare(stmt2, prepare, strlen(prepare))) { errorPrint("taos_stmt2_prepare(%s) failed. errstr=%s\n", prepare, taos_stmt2_error(stmt2)); tmfree(prepare); @@ -469,11 +479,11 @@ uint32_t accumulateRowLen(BArray *fields, int iface) { return len; } len += 1; - if (iface == SML_REST_IFACE || iface == SML_IFACE) { + if (iface == SML_IFACE) { len += SML_LINE_SQL_SYNTAX_OFFSET + strlen(field->name); } } - if (iface == SML_IFACE || iface == SML_REST_IFACE) { + if (iface == SML_IFACE) { len += 2 * TSDB_TABLE_NAME_LEN * 2 + SML_LINE_SQL_SYNTAX_OFFSET; } len += TIMESTAMP_BUFF_LEN; @@ -1802,7 +1812,6 @@ int generateRandData(SSuperTable *stbInfo, char *sampleDataBuf, int iface = stbInfo->iface; switch (iface) { case TAOSC_IFACE: - case REST_IFACE: return generateRandDataSQL(stbInfo, sampleDataBuf, bufLen, lenOfOneRow, fields, loop, tag); case STMT_IFACE: @@ -1817,7 +1826,6 @@ int generateRandData(SSuperTable *stbInfo, char *sampleDataBuf, bufLen, lenOfOneRow, fields, loop, tag); } case SML_IFACE: - case SML_REST_IFACE: return generateRandDataSml(stbInfo, sampleDataBuf, bufLen, lenOfOneRow, fields, loop, tag); default: @@ -1843,8 +1851,7 @@ int prepareSampleData(SDataBase* database, SSuperTable* stbInfo) { stbInfo->lenOfCols = accumulateRowLen(stbInfo->cols, stbInfo->iface); stbInfo->lenOfTags = accumulateRowLen(stbInfo->tags, stbInfo->iface); if (stbInfo->partialColNum != 0 - && ((stbInfo->iface == TAOSC_IFACE - || stbInfo->iface == REST_IFACE))) { + && stbInfo->iface == TAOSC_IFACE) { // check valid if(stbInfo->partialColFrom >= stbInfo->cols->size) { stbInfo->partialColFrom = 0; @@ -2003,12 +2010,6 @@ int prepareSampleData(SDataBase* database, SSuperTable* stbInfo) { } } - if (0 != convertServAddr( - stbInfo->iface, - stbInfo->tcpTransfer, - stbInfo->lineProtocol)) { - return -1; - } return 0; } diff --git a/tools/taos-tools/src/benchInsert.c b/tools/taos-tools/src/benchInsert.c index 885a6e529f8e..500fe9446a54 100644 --- a/tools/taos-tools/src/benchInsert.c +++ b/tools/taos-tools/src/benchInsert.c @@ -39,32 +39,6 @@ TAOS_STMT2* initStmt2(TAOS* taos, bool single); tmfree(infos); \ } while (0) \ -static int getSuperTableFromServerRest( - SDataBase* database, SSuperTable* stbInfo, char *command) { - - // TODO(zero): it will create super table based on this error code. - return TSDB_CODE_NOT_FOUND; - // TODO(me): finish full implementation -#if 0 - int sockfd = createSockFd(); - if (sockfd < 0) { - return -1; - } - - int code = postProceSql(command, - database->dbName, - database->precision, - REST_IFACE, - 0, - g_arguments->port, - false, - sockfd, - NULL); - - destroySockFd(sockfd); -#endif // 0 -} - static int getSuperTableFromServerTaosc( SDataBase *database, SSuperTable *stbInfo, char *command) { TAOS_RES *res; @@ -161,90 +135,41 @@ static int getSuperTableFromServerTaosc( static int getSuperTableFromServer(SDataBase* database, SSuperTable* stbInfo) { -#ifdef WEBSOCKET - if (g_arguments->websocket) { - return 0; - } -#endif - int ret = 0; char command[SHORT_1K_SQL_BUFF_LEN] = "\0"; snprintf(command, SHORT_1K_SQL_BUFF_LEN, "DESCRIBE `%s`.`%s`", database->dbName, stbInfo->stbName); - if (REST_IFACE == stbInfo->iface) { - ret = getSuperTableFromServerRest(database, stbInfo, command); - } else { - ret = getSuperTableFromServerTaosc(database, stbInfo, command); - } - - return ret; + return getSuperTableFromServerTaosc(database, stbInfo, command); } static int queryDbExec(SDataBase *database, SSuperTable *stbInfo, char *command) { int ret = 0; - if (isRest(stbInfo->iface)) { - if (0 != convertServAddr(stbInfo->iface, false, 1)) { - errorPrint("%s", "Failed to convert server address\n"); - return -1; - } - int sockfd = createSockFd(); - if (sockfd < 0) { - ret = -1; - } else { - ret = queryDbExecRest(command, - database->dbName, - database->precision, - stbInfo->iface, - stbInfo->lineProtocol, - stbInfo->tcpTransfer, - sockfd); - destroySockFd(sockfd); - } + SBenchConn* conn = initBenchConn(); + if (NULL == conn) { + ret = -1; } else { - SBenchConn* conn = initBenchConn(); - if (NULL == conn) { - ret = -1; - } else { + ret = queryDbExecCall(conn, command); + int32_t trying = g_arguments->keep_trying; + while (ret && trying) { + infoPrint("will sleep %"PRIu32" milliseconds then re-execute command: %s\n", + g_arguments->trying_interval, command); + toolsMsleep(g_arguments->trying_interval); ret = queryDbExecCall(conn, command); - int32_t trying = g_arguments->keep_trying; - while (ret && trying) { - infoPrint("will sleep %"PRIu32" milliseconds then re-execute command: %s\n", - g_arguments->trying_interval, command); - toolsMsleep(g_arguments->trying_interval); - ret = queryDbExecCall(conn, command); - if (trying != -1) { - trying--; - } - } - if (0 != ret) { - ret = -1; + if (trying != -1) { + trying--; } - closeBenchConn(conn); } + if (0 != ret) { + ret = -1; + } + closeBenchConn(conn); } return ret; } -#ifdef WEBSOCKET -static void dropSuperTable(SDataBase* database, SSuperTable* stbInfo) { - char command[SHORT_1K_SQL_BUFF_LEN] = "\0"; - snprintf(command, sizeof(command), - g_arguments->escape_character - ? "DROP TABLE IF EXISTS `%s`.`%s`" - : "DROP TABLE IF EXISTS %s.%s", - database->dbName, - stbInfo->stbName); - - infoPrint("drop stable: <%s>\n", command); - queryDbExec(database, stbInfo, command); - - return; -} -#endif // WEBSOCKET - int getCompressStr(Field* col, char* buf) { int pos = 0; if(strlen(col->encode) > 0) { @@ -521,80 +446,6 @@ int32_t getVgroupsNative(SBenchConn *conn, SDataBase *database) { return vgroups; } -#ifdef WEBSOCKET -int32_t getVgroupsWS(SBenchConn *conn, SDataBase *database) { - int vgroups = 0; - char sql[128] = "\0"; - snprintf(sql, sizeof(sql), - g_arguments->escape_character - ? "SHOW `%s`.VGROUPS" - : "SHOW %s.VGROUPS", - database->dbName); - - // query - WS_RES *res = ws_query_timeout(conn->taos_ws, sql, g_arguments->timeout); - int32_t code = ws_errno(res); - if (code != 0) { - // failed - errorPrint("Failed ws_query_timeout <%s>, code: 0x%08x, reason: %s\n", - sql, code, ws_errstr(res)); - ws_free_result(res); - return 0; - } - - // fetch - WS_ROW row; - database->vgArray = benchArrayInit(8, sizeof(SVGroup)); - while ( (row = ws_fetch_row(res)) && !g_arguments->terminate) { - SVGroup *vg = benchCalloc(1, sizeof(SVGroup), true); - vg->vgId = *(int32_t *)row[0]; - benchArrayPush(database->vgArray, vg); - vgroups++; - debugPrint(" ws fetch vgroups vgid=%d cnt=%d \n", vg->vgId, vgroups); - } - ws_free_result(res); - database->vgroups = vgroups; - - // return count - return vgroups; -} - -/* -int32_t getTableVgidWS(SBenchConn *conn, char *db, char *tb, int32_t *vgId) { - char sql[128] = "\0"; - snprintf(sql, sizeof(sql), - "select vgroup_id from information_schema.ins_tables where db_name='%s' and table_name='%s';", - db, tb); - // query - WS_RES *res = ws_query_timeout(conn->taos_ws, sql, g_arguments->timeout); - int32_t code = ws_errno(res); - if (code != 0) { - // failed - errorPrint("Failed ws_query_timeout <%s>, code: 0x%08x, reason: %s\n", - sql, code, ws_errstr(res)); - ws_free_result(res); - return code; - } - - // fetch - WS_ROW row; - while ( (row = ws_fetch_row(res)) && !g_arguments->terminate) { - *vgId = *(int32_t *)row[0]; - debugPrint(" getTableVgidWS table:%s vgid=%d\n", tb, *vgId); - break; - } - ws_free_result(res); - - if(*vgId == 0) { - return -1; - } else { - return 0; - } -} -*/ - -#endif - int32_t toolsGetDefaultVGroups() { int32_t cores = toolsGetNumberOfCores(); if (cores < 3 ) { @@ -701,70 +552,6 @@ int geneDbCreateCmd(SDataBase *database, char *command, int remainVnodes) { return dataLen; } -int createDatabaseRest(SDataBase* database) { - int32_t code = 0; - char command[SHORT_1K_SQL_BUFF_LEN] = "\0"; - - int sockfd = createSockFd(); - if (sockfd < 0) { - return -1; - } - - // drop exist database - snprintf(command, SHORT_1K_SQL_BUFF_LEN, - g_arguments->escape_character - ? "DROP DATABASE IF EXISTS `%s`;" - : "DROP DATABASE IF EXISTS %s;", - database->dbName); - code = postProceSql(command, - database->dbName, - database->precision, - REST_IFACE, - 0, - g_arguments->port, - false, - sockfd, - NULL); - if (code != 0) { - errorPrint("Failed to drop database %s\n", database->dbName); - } - - // create database - int remainVnodes = INT_MAX; - geneDbCreateCmd(database, command, remainVnodes); - code = postProceSql(command, - database->dbName, - database->precision, - REST_IFACE, - 0, - g_arguments->port, - false, - sockfd, - NULL); - int32_t trying = g_arguments->keep_trying; - while (code && trying) { - infoPrint("will sleep %"PRIu32" milliseconds then " - "re-create database %s\n", - g_arguments->trying_interval, database->dbName); - toolsMsleep(g_arguments->trying_interval); - code = postProceSql(command, - database->dbName, - database->precision, - REST_IFACE, - 0, - g_arguments->port, - false, - sockfd, - NULL); - if (trying != -1) { - trying--; - } - } - - destroySockFd(sockfd); - return code; -} - int32_t getRemainVnodes(SBenchConn *conn) { int remainVnodes = 0; char command[SHORT_1K_SQL_BUFF_LEN] = "SHOW DNODES"; @@ -786,7 +573,7 @@ int32_t getRemainVnodes(SBenchConn *conn) { return remainVnodes; } -int createDatabaseTaosc(SDataBase* database) { +int createDatabase(SDataBase* database) { char command[SHORT_1K_SQL_BUFF_LEN] = "\0"; // conn SBenchConn* conn = initBenchConn(); @@ -817,22 +604,17 @@ int createDatabaseTaosc(SDataBase* database) { "DROP DATABASE IF EXISTS %s;", database->dbName); if (0 != queryDbExecCall(conn, command)) { -#ifdef WEBSOCKET - if (g_arguments->websocket) { + if (g_arguments->dsn) { + // websocket warnPrint("%s", "TDengine cloud normal users have no privilege " "to drop database! DROP DATABASE failure is ignored!\n"); - } else { -#endif - closeBenchConn(conn); - return -1; -#ifdef WEBSOCKET } -#endif + closeBenchConn(conn); + return -1; } // get remain vgroups int remainVnodes = INT_MAX; -#ifndef WEBSOCKET if (g_arguments->bind_vgroup) { remainVnodes = getRemainVnodes(conn); if (0 >= remainVnodes) { @@ -841,7 +623,6 @@ int createDatabaseTaosc(SDataBase* database) { return -1; } } -#endif // generate and execute create database sql geneDbCreateCmd(database, command, remainVnodes); @@ -859,21 +640,15 @@ int createDatabaseTaosc(SDataBase* database) { } if (code) { -#ifdef WEBSOCKET - if (g_arguments->websocket) { + if (g_arguments->dsn) { warnPrint("%s", "TDengine cloud normal users have no privilege " "to create database! CREATE DATABASE " "failure is ignored!\n"); - } else { -#endif + } - closeBenchConn(conn); - errorPrint("\ncreate database %s failed!\n\n", - database->dbName); - return -1; -#ifdef WEBSOCKET - } -#endif + closeBenchConn(conn); + errorPrint("\ncreate database %s failed!\n\n", database->dbName); + return -1; } infoPrint("command to create database: <%s>\n", command); @@ -881,15 +656,7 @@ int createDatabaseTaosc(SDataBase* database) { // malloc and get vgroup if (g_arguments->bind_vgroup) { int32_t vgroups; -#ifdef WEBSOCKET - if (g_arguments->websocket) { - vgroups = getVgroupsWS(conn, database); - } else { -#endif - vgroups = getVgroupsNative(conn, database); -#ifdef WEBSOCKET - } -#endif + vgroups = getVgroupsNative(conn, database); if (vgroups <= 0) { closeBenchConn(conn); errorPrint("Database %s's vgroups is %d\n", @@ -902,28 +669,6 @@ int createDatabaseTaosc(SDataBase* database) { return 0; } -int createDatabase(SDataBase* database) { - int ret = 0; - if (REST_IFACE == g_arguments->iface || SML_REST_IFACE == g_arguments->iface) { - ret = createDatabaseRest(database); - } else { - ret = createDatabaseTaosc(database); - } -#if 0 -#ifdef LINUX - infoPrint("%s() LN%d, ret: %d\n", __func__, __LINE__, ret); - sleep(10); - infoPrint("%s() LN%d, ret: %d\n", __func__, __LINE__, ret); -#elif defined(DARWIN) - sleep(2); -#else - Sleep(2); -#endif -#endif - - return ret; -} - static int generateChildTblName(int len, char *buffer, SDataBase *database, SSuperTable *stbInfo, uint64_t tableSeq, char* tagData, int i, char *ttl) { @@ -1072,26 +817,16 @@ static void *createTable(void *sarg) { int ret = 0; debugPrint("thread[%d] creating table: %s\n", pThreadInfo->threadID, pThreadInfo->buffer); - if (REST_IFACE == stbInfo->iface) { - ret = queryDbExecRest(pThreadInfo->buffer, - database->dbName, - database->precision, - stbInfo->iface, - stbInfo->lineProtocol, - stbInfo->tcpTransfer, - pThreadInfo->sockfd); - } else { + ret = queryDbExecCall(pThreadInfo->conn, pThreadInfo->buffer); + int32_t trying = g_arguments->keep_trying; + while (ret && trying) { + infoPrint("will sleep %"PRIu32" milliseconds then re-create " + "table %s\n", + g_arguments->trying_interval, pThreadInfo->buffer); + toolsMsleep(g_arguments->trying_interval); ret = queryDbExecCall(pThreadInfo->conn, pThreadInfo->buffer); - int32_t trying = g_arguments->keep_trying; - while (ret && trying) { - infoPrint("will sleep %"PRIu32" milliseconds then re-create " - "table %s\n", - g_arguments->trying_interval, pThreadInfo->buffer); - toolsMsleep(g_arguments->trying_interval); - ret = queryDbExecCall(pThreadInfo->conn, pThreadInfo->buffer); - if (trying != -1) { - trying--; - } + if (trying != -1) { + trying--; } } @@ -1123,17 +858,7 @@ static void *createTable(void *sarg) { int ret = 0; debugPrint("thread[%d] creating table: %s\n", pThreadInfo->threadID, pThreadInfo->buffer); - if (REST_IFACE == stbInfo->iface) { - ret = queryDbExecRest(pThreadInfo->buffer, - database->dbName, - database->precision, - stbInfo->iface, - stbInfo->lineProtocol, - stbInfo->tcpTransfer, - pThreadInfo->sockfd); - } else { - ret = queryDbExecCall(pThreadInfo->conn, pThreadInfo->buffer); - } + ret = queryDbExecCall(pThreadInfo->conn, pThreadInfo->buffer); if (0 != ret) { g_fail = true; goto create_table_end; @@ -1188,17 +913,9 @@ static int startMultiThreadCreateChildTable(SDataBase* database, SSuperTable* st pThreadInfo->threadID = i; pThreadInfo->stbInfo = stbInfo; pThreadInfo->dbInfo = database; - if (REST_IFACE == stbInfo->iface) { - int sockfd = createSockFd(); - if (sockfd < 0) { - FREE_PIDS_INFOS_RETURN_MINUS_1(); - } - pThreadInfo->sockfd = sockfd; - } else { - pThreadInfo->conn = initBenchConn(); - if (NULL == pThreadInfo->conn) { - goto over; - } + pThreadInfo->conn = initBenchConn(); + if (NULL == pThreadInfo->conn) { + goto over; } pThreadInfo->start_table_from = tableFrom; pThreadInfo->ntables = i < mod ? div + 1 : div; @@ -1221,7 +938,7 @@ static int startMultiThreadCreateChildTable(SDataBase* database, SSuperTable* st threadInfo *pThreadInfo = infos + i; g_arguments->actualChildTables += pThreadInfo->tables_created; - if ((REST_IFACE != stbInfo->iface) && pThreadInfo->conn) { + if (pThreadInfo->conn) { closeBenchConn(pThreadInfo->conn); } } @@ -1254,8 +971,7 @@ static int createChildTables() { for (int j = 0; (j < database->superTbls->size && !g_arguments->terminate); j++) { SSuperTable * stbInfo = benchArrayGet(database->superTbls, j); - if (stbInfo->autoTblCreating || stbInfo->iface == SML_IFACE - || stbInfo->iface == SML_REST_IFACE) { + if (stbInfo->autoTblCreating || stbInfo->iface == SML_IFACE) { g_arguments->autoCreatedChildTables += stbInfo->childTblCount; continue; @@ -1441,37 +1157,6 @@ int32_t execInsert(threadInfo *pThreadInfo, uint32_t k, int64_t *delay3) { } } break; - - case REST_IFACE: - debugPrint("buffer: %s\n", pThreadInfo->buffer); - code = postProceSql(pThreadInfo->buffer, - database->dbName, - database->precision, - stbInfo->iface, - stbInfo->lineProtocol, - g_arguments->port, - stbInfo->tcpTransfer, - pThreadInfo->sockfd, - pThreadInfo->filePath); - while (code && trying && !g_arguments->terminate) { - infoPrint("will sleep %"PRIu32" milliseconds then re-insert\n", - trying_interval); - toolsMsleep(trying_interval); - code = postProceSql(pThreadInfo->buffer, - database->dbName, - database->precision, - stbInfo->iface, - stbInfo->lineProtocol, - g_arguments->port, - stbInfo->tcpTransfer, - pThreadInfo->sockfd, - pThreadInfo->filePath); - if (trying != -1) { - trying--; - } - } - break; - case STMT_IFACE: // add batch if(!stbInfo->autoTblCreating) { @@ -1552,54 +1237,6 @@ int32_t execInsert(threadInfo *pThreadInfo, uint32_t k, int64_t *delay3) { } taos_free_result(res); break; - - case SML_REST_IFACE: { - if (TSDB_SML_JSON_PROTOCOL == protocol - || SML_JSON_TAOS_FORMAT == protocol) { - code = postProceSql(pThreadInfo->lines[0], database->dbName, - database->precision, stbInfo->iface, - protocol, g_arguments->port, - stbInfo->tcpTransfer, - pThreadInfo->sockfd, pThreadInfo->filePath); - } else { - int len = 0; - for (int i = 0; i < k; i++) { - if (strlen(pThreadInfo->lines[i]) != 0) { - int n; - if (TSDB_SML_TELNET_PROTOCOL == protocol - && stbInfo->tcpTransfer) { - n = snprintf(pThreadInfo->buffer + len, - TSDB_MAX_ALLOWED_SQL_LEN - len, - "put %s\n", pThreadInfo->lines[i]); - } else { - n = snprintf(pThreadInfo->buffer + len, - TSDB_MAX_ALLOWED_SQL_LEN - len, - "%s\n", - pThreadInfo->lines[i]); - } - if (n < 0 || n >= TSDB_MAX_ALLOWED_SQL_LEN - len) { - errorPrint("%s() LN%d snprintf overflow on %d\n", - __func__, __LINE__, i); - break; - } else { - len += n; - } - } else { - break; - } - } - if (g_arguments->terminate) { - break; - } - code = postProceSql(pThreadInfo->buffer, database->dbName, - database->precision, - stbInfo->iface, protocol, - g_arguments->port, - stbInfo->tcpTransfer, - pThreadInfo->sockfd, pThreadInfo->filePath); - } - break; - } } return code; } @@ -1622,29 +1259,20 @@ static int smartContinueIfFail(threadInfo *pThreadInfo, stbInfo->stbName, tagData + i * stbInfo->lenOfTags, ttl); debugPrint("creating table: %s\n", buffer); - int ret; - if (REST_IFACE == stbInfo->iface) { - ret = queryDbExecRest(buffer, - database->dbName, - database->precision, - stbInfo->iface, - stbInfo->lineProtocol, - stbInfo->tcpTransfer, - pThreadInfo->sockfd); - } else { + + int32_t ret = queryDbExecCall(pThreadInfo->conn, buffer); + int32_t trying = g_arguments->keep_trying; + while (ret && trying) { + infoPrint("will sleep %"PRIu32" milliseconds then " + "re-create table %s\n", + g_arguments->trying_interval, buffer); + toolsMsleep(g_arguments->trying_interval); ret = queryDbExecCall(pThreadInfo->conn, buffer); - int32_t trying = g_arguments->keep_trying; - while (ret && trying) { - infoPrint("will sleep %"PRIu32" milliseconds then " - "re-create table %s\n", - g_arguments->trying_interval, buffer); - toolsMsleep(g_arguments->trying_interval); - ret = queryDbExecCall(pThreadInfo->conn, buffer); - if (trying != -1) { - trying--; - } + if (trying != -1) { + trying--; } } + tmfree(buffer); return ret; @@ -1791,7 +1419,7 @@ int32_t reConnectStmt2(threadInfo * pThreadInfo, int32_t w) { } // prepare - code = prepareStmt2(pThreadInfo->conn->stmt2, pThreadInfo->stbInfo, NULL, w); + code = prepareStmt2(pThreadInfo->conn->stmt2, pThreadInfo->stbInfo, NULL, w, pThreadInfo->dbInfo->dbName); if (code != 0) { return code; } @@ -1932,14 +1560,14 @@ static void *syncWriteInterlace(void *sarg) { // not auto create table call once if(stbInfo->iface == STMT_IFACE && !oldInitStmt) { debugPrint("call prepareStmt for stable:%s\n", stbInfo->stbName); - if (prepareStmt(pThreadInfo->conn->stmt, stbInfo, tagData, w)) { + if (prepareStmt(pThreadInfo->conn->stmt, stbInfo, tagData, w, database->dbName)) { g_fail = true; goto free_of_interlace; } } else if (stbInfo->iface == STMT2_IFACE) { // only prepare once - if (prepareStmt2(pThreadInfo->conn->stmt2, stbInfo, NULL, w)) { + if (prepareStmt2(pThreadInfo->conn->stmt2, stbInfo, NULL, w, database->dbName)) { g_fail = true; goto free_of_interlace; } @@ -1980,7 +1608,6 @@ static void *syncWriteInterlace(void *sarg) { snprintf(ttl, SMALL_BUFF_LEN, "TTL %d", stbInfo->ttl); } switch (stbInfo->iface) { - case REST_IFACE: case TAOSC_IFACE: { char escapedTbName[TSDB_TABLE_NAME_LEN+2] = "\0"; if (g_arguments->escape_character) { @@ -2123,7 +1750,7 @@ static void *syncWriteInterlace(void *sarg) { // old must call prepareStmt for each table if (oldInitStmt) { debugPrint("call prepareStmt for stable:%s\n", stbInfo->stbName); - if (prepareStmt(pThreadInfo->conn->stmt, stbInfo, tagData, w)) { + if (prepareStmt(pThreadInfo->conn->stmt, stbInfo, tagData, w, database->dbName)) { g_fail = true; goto free_of_interlace; } @@ -2208,7 +1835,6 @@ static void *syncWriteInterlace(void *sarg) { break; } - case SML_REST_IFACE: case SML_IFACE: { int protocol = stbInfo->lineProtocol; for (int64_t j = 0; j < interlaceRows; j++) { @@ -2341,15 +1967,11 @@ static void *syncWriteInterlace(void *sarg) { int protocol = stbInfo->lineProtocol; switch (stbInfo->iface) { case TAOSC_IFACE: - case REST_IFACE: debugPrint("pThreadInfo->buffer: %s\n", pThreadInfo->buffer); free_ds(&pThreadInfo->buffer); pThreadInfo->buffer = new_ds(0); break; - case SML_REST_IFACE: - memset(pThreadInfo->buffer, 0, - g_arguments->reqPerReq * (pThreadInfo->max_sql_len + 1)); case SML_IFACE: if (TSDB_SML_JSON_PROTOCOL == protocol || SML_JSON_TAOS_FORMAT == protocol) { @@ -2893,7 +2515,7 @@ void *syncWriteProgressive(void *sarg) { char* tagData = NULL; bool stmt = (stbInfo->iface == STMT_IFACE || stbInfo->iface == STMT2_IFACE) && stbInfo->autoTblCreating; bool smart = SMART_IF_FAILED == stbInfo->continueIfFail; - bool acreate = (stbInfo->iface == TAOSC_IFACE || stbInfo->iface == REST_IFACE) && stbInfo->autoTblCreating; + bool acreate = stbInfo->iface == TAOSC_IFACE && stbInfo->autoTblCreating; int w = 0; if (stmt || smart || acreate) { csvFile = openTagCsv(stbInfo); @@ -2903,13 +2525,13 @@ void *syncWriteProgressive(void *sarg) { bool oldInitStmt = stbInfo->autoTblCreating || database->superTbls->size > 1; // stmt. not auto table create call on stmt if (stbInfo->iface == STMT_IFACE && !oldInitStmt) { - if (prepareStmt(pThreadInfo->conn->stmt, stbInfo, tagData, w)) { + if (prepareStmt(pThreadInfo->conn->stmt, stbInfo, tagData, w, database->dbName)) { g_fail = true; goto free_of_progressive; } } else if (stbInfo->iface == STMT2_IFACE && !stbInfo->autoTblCreating) { - if (prepareStmt2(pThreadInfo->conn->stmt2, stbInfo, tagData, w)) { + if (prepareStmt2(pThreadInfo->conn->stmt2, stbInfo, tagData, w, database->dbName)) { g_fail = true; goto free_of_progressive; } @@ -2957,13 +2579,13 @@ void *syncWriteProgressive(void *sarg) { // old init stmt must call for each table if (stbInfo->iface == STMT_IFACE && oldInitStmt) { - if (prepareStmt(pThreadInfo->conn->stmt, stbInfo, tagData, w)) { + if (prepareStmt(pThreadInfo->conn->stmt, stbInfo, tagData, w, database->dbName)) { g_fail = true; goto free_of_progressive; } } else if (stbInfo->iface == STMT2_IFACE && stbInfo->autoTblCreating) { - if (prepareStmt2(pThreadInfo->conn->stmt2, stbInfo, tagData, w)) { + if (prepareStmt2(pThreadInfo->conn->stmt2, stbInfo, tagData, w, database->dbName)) { g_fail = true; goto free_of_progressive; } @@ -2988,7 +2610,6 @@ void *syncWriteProgressive(void *sarg) { int32_t generated = 0; switch (stbInfo->iface) { case TAOSC_IFACE: - case REST_IFACE: generated = prepareProgressDataSql( pThreadInfo, childTbl, @@ -3010,7 +2631,6 @@ void *syncWriteProgressive(void *sarg) { &delay3, &startTs, &endTs, w); break; } - case SML_REST_IFACE: case SML_IFACE: generated = prepareProgressDataSml( pThreadInfo, @@ -3116,14 +2736,9 @@ void *syncWriteProgressive(void *sarg) { } int protocol = stbInfo->lineProtocol; switch (stbInfo->iface) { - case REST_IFACE: case TAOSC_IFACE: memset(pThreadInfo->buffer, 0, pThreadInfo->max_sql_len); break; - case SML_REST_IFACE: - memset(pThreadInfo->buffer, 0, - g_arguments->reqPerReq * - (pThreadInfo->max_sql_len + 1)); case SML_IFACE: if (TSDB_SML_JSON_PROTOCOL == protocol) { memset(pThreadInfo->lines[0], 0, @@ -3660,8 +3275,7 @@ static int64_t fillChildTblName(SDataBase *database, SSuperTable *stbInfo) { snprintf(childName, TSDB_TABLE_NAME_LEN, "%s", stbInfo->stbName); stbInfo->childTblArray[0]->name = strdup(childName); - } else if ((stbInfo->iface != SML_IFACE - && stbInfo->iface != SML_REST_IFACE) + } else if ((stbInfo->iface != SML_IFACE) && stbInfo->childTblExists) { ntables = fillChildTblNameImp(database, stbInfo); } else { @@ -3888,20 +3502,6 @@ int32_t initInsertThread(SDataBase* database, SSuperTable* stbInfo, int32_t nthr // init conn pThreadInfo->delayList = benchArrayInit(1, sizeof(int64_t)); switch (stbInfo->iface) { - // rest - case REST_IFACE: { - if (stbInfo->interlaceRows > 0) { - pThreadInfo->buffer = new_ds(0); - } else { - pThreadInfo->buffer = benchCalloc(1, TSDB_MAX_ALLOWED_SQL_LEN, true); - } - int sockfd = createSockFd(); - if (sockfd < 0) { - goto END; - } - pThreadInfo->sockfd = sockfd; - break; - } // stmt & stmt2 init case STMT_IFACE: case STMT2_IFACE: { @@ -3968,14 +3568,6 @@ int32_t initInsertThread(SDataBase* database, SSuperTable* stbInfo, int32_t nthr break; } - // sml rest - case SML_REST_IFACE: { - int sockfd = createSockFd(); - if (sockfd < 0) { - goto END; - } - pThreadInfo->sockfd = sockfd; - } // sml case SML_IFACE: { if (stbInfo->iface == SML_IFACE) { @@ -3990,9 +3582,6 @@ int32_t initInsertThread(SDataBase* database, SSuperTable* stbInfo, int32_t nthr } } pThreadInfo->max_sql_len = stbInfo->lenOfCols + stbInfo->lenOfTags; - if (stbInfo->iface == SML_REST_IFACE) { - pThreadInfo->buffer = benchCalloc(1, g_arguments->reqPerReq * (1 + pThreadInfo->max_sql_len), true); - } int protocol = stbInfo->lineProtocol; if (TSDB_SML_JSON_PROTOCOL != protocol && SML_JSON_TAOS_FORMAT != protocol) { pThreadInfo->sml_tags = (char **)benchCalloc(pThreadInfo->ntables, sizeof(char *), true); @@ -4205,22 +3794,6 @@ int32_t exitInsertThread(SDataBase* database, SSuperTable* stbInfo, int32_t nthr // close conn int protocol = stbInfo->lineProtocol; switch (stbInfo->iface) { - case REST_IFACE: - if (g_arguments->terminate) - toolsMsleep(100); - destroySockFd(pThreadInfo->sockfd); - if (stbInfo->interlaceRows > 0) { - free_ds(&pThreadInfo->buffer); - } else { - tmfree(pThreadInfo->buffer); - pThreadInfo->buffer = NULL; - } - break; - case SML_REST_IFACE: - if (g_arguments->terminate) - toolsMsleep(100); - tmfree(pThreadInfo->buffer); - // on-purpose no break here case SML_IFACE: if (TSDB_SML_JSON_PROTOCOL != protocol && SML_JSON_TAOS_FORMAT != protocol) { @@ -4355,7 +3928,7 @@ int32_t exitInsertThread(SDataBase* database, SSuperTable* stbInfo, int32_t nthr } static int startMultiThreadInsertData(SDataBase* database, SSuperTable* stbInfo) { - if ((stbInfo->iface == SML_IFACE || stbInfo->iface == SML_REST_IFACE) + if ((stbInfo->iface == SML_IFACE) && !stbInfo->use_metric) { errorPrint("%s", "schemaless cannot work without stable\n"); return -1; @@ -4622,26 +4195,9 @@ int insertTestProcess() { //loop create database for (int i = 0; i < g_arguments->databases->size; i++) { - if (isRest(g_arguments->iface)) { - if (0 != convertServAddr(g_arguments->iface, - false, - 1)) { - return -1; - } - } SDataBase * database = benchArrayGet(g_arguments->databases, i); if (database->drop && !(g_arguments->supplementInsert)) { - if (database->superTbls && database->superTbls->size > 0) { - SSuperTable * stbInfo = benchArrayGet(database->superTbls, 0); - if (stbInfo && isRest(stbInfo->iface)) { - if (0 != convertServAddr(stbInfo->iface, - stbInfo->tcpTransfer, - stbInfo->lineProtocol)) { - return -1; - } - } - } if (createDatabase(database)) { errorPrint("failed to create database (%s)\n", database->dbName); @@ -4652,16 +4208,7 @@ int insertTestProcess() { // database already exist, get vgroups from server SBenchConn* conn = initBenchConn(); if (conn) { - int32_t vgroups; -#ifdef WEBSOCKET - if (g_arguments->websocket) { - vgroups = getVgroupsWS(conn, database); - } else { -#endif - vgroups = getVgroupsNative(conn, database); -#ifdef WEBSOCKET - } -#endif + int32_t vgroups = getVgroupsNative(conn, database); if (vgroups <=0) { closeBenchConn(conn); errorPrint("Database %s's vgroups is zero , db exist case.\n", database->dbName); @@ -4680,13 +4227,7 @@ int insertTestProcess() { for (int j = 0; j < database->superTbls->size; j++) { SSuperTable * stbInfo = benchArrayGet(database->superTbls, j); if (stbInfo->iface != SML_IFACE - && stbInfo->iface != SML_REST_IFACE && !stbInfo->childTblExists) { -#ifdef WEBSOCKET - if (g_arguments->websocket && !g_arguments->supplementInsert) { - dropSuperTable(database, stbInfo); - } -#endif int code = getSuperTableFromServer(database, stbInfo); if (code == TSDB_CODE_FAILED) { return -1; diff --git a/tools/taos-tools/src/benchJsonOpt.c b/tools/taos-tools/src/benchJsonOpt.c index 4791385741bf..2cc6c9850dbe 100644 --- a/tools/taos-tools/src/benchJsonOpt.c +++ b/tools/taos-tools/src/benchJsonOpt.c @@ -820,16 +820,12 @@ void parseStringToIntArray(char *str, BArray *arr) { // get interface name uint16_t getInterface(char *name) { uint16_t iface = TAOSC_IFACE; - if (0 == strcasecmp(name, "rest")) { - iface = REST_IFACE; - } else if (0 == strcasecmp(name, "stmt")) { + if (0 == strcasecmp(name, "stmt")) { iface = STMT_IFACE; } else if (0 == strcasecmp(name, "stmt2")) { iface = STMT2_IFACE; } else if (0 == strcasecmp(name, "sml")) { iface = SML_IFACE; - } else if (0 == strcasecmp(name, "sml-rest")) { - iface = SML_REST_IFACE; } return iface; @@ -969,30 +965,7 @@ static int getStableInfo(tools_cJSON *dbinfos, int index) { g_arguments->reqPerReq, SML_MAX_BATCH); return -1; } - } else if (isRest(superTable->iface)) { - if (g_arguments->reqPerReq > SML_MAX_BATCH) { - errorPrint("reqPerReq (%u) larger than maximum (%d)\n", - g_arguments->reqPerReq, SML_MAX_BATCH); - return -1; - } - if (0 != convertServAddr(REST_IFACE, - false, - 1)) { - errorPrint("%s", "Failed to convert server address\n"); - return -1; - } - encodeAuthBase64(); - g_arguments->rest_server_ver_major = - getServerVersionRest(g_arguments->port + TSDB_PORT_HTTP); } -#ifdef WEBSOCKET - if (g_arguments->websocket) { - infoPrint("Since WebSocket interface is enabled, " - "the interface %s is changed to use WebSocket.\n", - stbIface->valuestring); - superTable->iface = TAOSC_IFACE; - } -#endif } @@ -1523,45 +1496,69 @@ static int getMetaFromCommonJsonFile(tools_cJSON *json) { tools_cJSON *cfgdir = tools_cJSON_GetObjectItem(json, "cfgdir"); if (cfgdir && (cfgdir->type == tools_cJSON_String) && (cfgdir->valuestring != NULL)) { - tstrncpy(g_configDir, cfgdir->valuestring, MAX_FILE_NAME_LEN); + if (!g_arguments->cfg_inputted) { + tstrncpy(g_configDir, cfgdir->valuestring, MAX_FILE_NAME_LEN); + debugPrint("configDir from cfg: %s\n", g_configDir); + } else { + warnPrint("configDir set by command line, so ignore cfg. cmd: %s\n", g_configDir); + } } + // dsn + tools_cJSON *dsn = tools_cJSON_GetObjectItem(json, "dsn"); + if (tools_cJSON_IsString(dsn) && strlen(dsn->valuestring) > 0) { + if (g_arguments->dsn == NULL) { + g_arguments->dsn = dsn->valuestring; + infoPrint("read dsn from json. dsn=%s\n", g_arguments->dsn); + } + } + + // host tools_cJSON *host = tools_cJSON_GetObjectItem(json, "host"); if (host && host->type == tools_cJSON_String && host->valuestring != NULL) { - if(g_arguments->host && strlen(g_arguments->host) > 0) { - warnPrint("command line already pass host is %s, json config host(%s) had been ignored.\n", g_arguments->host, host->valuestring); - } else { + if(g_arguments->host == NULL) { g_arguments->host = host->valuestring; + infoPrint("read host from json: %s .\n", g_arguments->host); } } + // port tools_cJSON *port = tools_cJSON_GetObjectItem(json, "port"); if (port && port->type == tools_cJSON_Number) { - if(g_arguments->port != DEFAULT_PORT) { - warnPrint("command line already pass port is %d, json config port(%d) had been ignored.\n", g_arguments->port, (uint16_t)port->valueint); + if (g_arguments->port_inputted) { + // command line input port first + warnPrint("command port: %d, json port ignored.\n", g_arguments->port); } else { - g_arguments->port = (uint16_t)port->valueint; - if(g_arguments->port != DEFAULT_PORT) { - infoPrint("json file config special port %d .\n", g_arguments->port); - g_arguments->port_inputted = true; + // default port set auto port + if (port->valueint != DEFAULT_PORT) { + g_arguments->port = (uint16_t)port->valueint; + infoPrint("read port form json: %d .\n", g_arguments->port); + g_arguments->port_inputted = true; } } } + // user tools_cJSON *user = tools_cJSON_GetObjectItem(json, "user"); if (user && user->type == tools_cJSON_String && user->valuestring != NULL) { - g_arguments->user = user->valuestring; + if (g_arguments->user == NULL) { + g_arguments->user = user->valuestring; + infoPrint("read user from json: %s .\n", g_arguments->user); + } } + // pass tools_cJSON *password = tools_cJSON_GetObjectItem(json, "password"); if (password && password->type == tools_cJSON_String && password->valuestring != NULL) { - g_arguments->password = password->valuestring; + if(g_arguments->password == NULL) { + g_arguments->password = password->valuestring; + infoPrint("read password from json: %s .\n", "******"); + } } - tools_cJSON *answerPrompt = - tools_cJSON_GetObjectItem(json, - "confirm_parameter_prompt"); // yes, no, + // yes, no + tools_cJSON *answerPrompt = tools_cJSON_GetObjectItem(json, "confirm_parameter_prompt"); if (answerPrompt && answerPrompt->type == tools_cJSON_String && answerPrompt->valuestring != NULL) { if (0 == strcasecmp(answerPrompt->valuestring, "no")) { @@ -1614,15 +1611,6 @@ static int getMetaFromCommonJsonFile(tools_cJSON *json) { static int getMetaFromInsertJsonFile(tools_cJSON *json) { int32_t code = -1; -#ifdef WEBSOCKET - tools_cJSON *dsn = tools_cJSON_GetObjectItem(json, "dsn"); - if (tools_cJSON_IsString(dsn)) { - g_arguments->dsn = dsn->valuestring; - g_arguments->websocket = true; - infoPrint("set websocket true from json->dsn=%s\n", g_arguments->dsn); - } -#endif - // check after inserted tools_cJSON *checkSql = tools_cJSON_GetObjectItem(json, "check_sql"); if (tools_cJSON_IsString(checkSql)) { @@ -1677,24 +1665,6 @@ static int getMetaFromInsertJsonFile(tools_cJSON *json) { g_arguments->table_threads = (uint32_t)table_theads->valueint; } -#ifdef WEBSOCKET - if (!g_arguments->websocket) { -#endif -#ifdef LINUX - if (strlen(g_configDir)) { - wordexp_t full_path; - if (wordexp(g_configDir, &full_path, 0) != 0) { - errorPrint("Invalid path %s\n", g_configDir); - exit(EXIT_FAILURE); - } - taos_options(TSDB_OPTION_CONFIGDIR, full_path.we_wordv[0]); - wordfree(&full_path); - } -#endif -#ifdef WEBSOCKET - } -#endif - tools_cJSON *numRecPerReq = tools_cJSON_GetObjectItem(json, "num_of_records_per_req"); if (numRecPerReq && numRecPerReq->type == tools_cJSON_Number) { @@ -2204,9 +2174,7 @@ static int getMetaFromQueryJsonFile(tools_cJSON *json) { tools_cJSON *queryMode = tools_cJSON_GetObjectItem(json, "query_mode"); if (tools_cJSON_IsString(queryMode)) { - if (0 == strcasecmp(queryMode->valuestring, "rest")) { - g_queryInfo.iface = REST_IFACE; - } else if (0 == strcasecmp(queryMode->valuestring, "taosc")) { + if (0 == strcasecmp(queryMode->valuestring, "taosc")) { g_queryInfo.iface = TAOSC_IFACE; } else { errorPrint("Invalid query_mode value: %s\n", @@ -2256,24 +2224,6 @@ static int getMetaFromQueryJsonFile(tools_cJSON *json) { static int getMetaFromTmqJsonFile(tools_cJSON *json) { int32_t code = -1; - - tools_cJSON *cfgdir = tools_cJSON_GetObjectItem(json, "cfgdir"); - if (tools_cJSON_IsString(cfgdir)) { - tstrncpy(g_configDir, cfgdir->valuestring, MAX_FILE_NAME_LEN); - } - -#ifdef LINUX - if (strlen(g_configDir)) { - wordexp_t full_path; - if (wordexp(g_configDir, &full_path, 0) != 0) { - errorPrint("Invalid path %s\n", g_configDir); - exit(EXIT_FAILURE); - } - taos_options(TSDB_OPTION_CONFIGDIR, full_path.we_wordv[0]); - wordfree(&full_path); - } -#endif - tools_cJSON *resultfile = tools_cJSON_GetObjectItem(json, "result_file"); if (resultfile && resultfile->type == tools_cJSON_String && resultfile->valuestring != NULL) { diff --git a/tools/taos-tools/src/benchMain.c b/tools/taos-tools/src/benchMain.c index 86ad795d0508..739d2792b71e 100644 --- a/tools/taos-tools/src/benchMain.c +++ b/tools/taos-tools/src/benchMain.c @@ -21,6 +21,7 @@ STmqMetaInfo g_tmqInfo; bool g_fail = false; uint64_t g_memoryUsage = 0; tools_cJSON* root; +extern char g_configDir[MAX_PATH_LEN]; #define CLIENT_INFO_LEN 20 static char g_client_info[CLIENT_INFO_LEN] = {0}; @@ -59,18 +60,42 @@ void checkArgumentValid() { g_arguments->host = DEFAULT_HOST; } - if (isRest(g_arguments->iface)) { - if (0 != convertServAddr(g_arguments->iface, - false, - 1)) { - errorPrint("%s", "Failed to convert server address\n"); - return; - } - encodeAuthBase64(); - g_arguments->rest_server_ver_major = - getServerVersionRest(g_arguments->port); +} + +// apply cfg +int32_t applyConfigDir(char * cfgDir){ + // set engine config dir + int32_t code; +#ifdef LINUX + wordexp_t full_path; + if (wordexp(cfgDir, &full_path, 0) != 0) { + errorPrint("Invalid path %s\n", cfgDir); + exit(EXIT_FAILURE); + } + code = taos_options(TSDB_OPTION_CONFIGDIR, full_path.we_wordv[0]); + wordfree(&full_path); +#else + code = taos_options(TSDB_OPTION_CONFIGDIR, cfgDir); +#endif + // show error + if (code) { + engineError("applyConfigDir", "taos_options(TSDB_OPTION_CONFIGDIR, ...)", code); + } + + return code; + } + +int32_t setConnMode(int8_t connMode, char *dsn) { + // set conn mode + char * strMode = connMode == CONN_MODE_NATIVE ? STR_NATIVE : STR_WEBSOCKET; + int32_t code = taos_options(TSDB_OPTION_DRIVER, strMode); + if (code != TSDB_CODE_SUCCESS) { + engineError(INIT_PHASE, "taos_options", code); + return -1; } + infoPrint("Connect mode is : %s\n\n", strMode); + return 0; } int main(int argc, char* argv[]) { @@ -81,46 +106,36 @@ int main(int argc, char* argv[]) { initArgument(); srand(time(NULL)%1000000); + // majorVersion snprintf(g_client_info, CLIENT_INFO_LEN, "%s", taos_get_client_info()); g_majorVersionOfClient = atoi(g_client_info); debugPrint("Client info: %s, major version: %d\n", g_client_info, g_majorVersionOfClient); -#ifdef LINUX - if (sem_init(&g_arguments->cancelSem, 0, 0) != 0) { - errorPrint("%s", "failed to create cancel semaphore\n"); - exit(EXIT_FAILURE); - } - pthread_t spid = {0}; - pthread_create(&spid, NULL, benchCancelHandler, NULL); - - benchSetSignal(SIGINT, benchQueryInterruptHandler); - -#endif + // read command line if (benchParseArgs(argc, argv)) { exitLog(); return -1; } -#ifdef WEBSOCKET - if (g_arguments->debug_print) { - ws_enable_log("info"); + + // check valid + if(g_arguments->connMode == CONN_MODE_NATIVE && g_arguments->dsn) { + errorPrint("%s", DSN_NATIVE_CONFLICT); + exitLog(); + return -1; } - if (g_arguments->dsn != NULL) { - g_arguments->websocket = true; - infoPrint("set websocket true from dsn not empty. dsn=%s\n", g_arguments->dsn); - } else { + // read evn + if (g_arguments->dsn == NULL) { char * dsn = getenv("TDENGINE_CLOUD_DSN"); - if (dsn != NULL && strlen(dsn) > 3) { + if (dsn != NULL && strlen(dsn) > 0) { g_arguments->dsn = dsn; - g_arguments->websocket = true; - infoPrint("set websocket true from getenv TDENGINE_CLOUD_DSN=%s\n", g_arguments->dsn); - } else { - g_arguments->dsn = false; - } + infoPrint("Get dsn from getenv TDENGINE_CLOUD_DSN=%s\n", g_arguments->dsn); + } } -#endif + + // read json config if (g_arguments->metaFile) { g_arguments->totalChildTables = 0; if (readJsonConfig(g_arguments->metaFile)) { @@ -132,6 +147,7 @@ int main(int argc, char* argv[]) { modifyArgument(); } + // open result file if(g_arguments->output_file[0] == 0) { infoPrint("%s","result_file is empty, ignore output."); g_arguments->fpOfInsertResult = NULL; @@ -143,9 +159,40 @@ int main(int argc, char* argv[]) { } } + // check argument infoPrint("client version: %s\n", taos_get_client_info()); checkArgumentValid(); + // conn mode + if (setConnMode(g_arguments->connMode, g_arguments->dsn) != 0) { + exitLog(); + return -1; + } + + // check condition for set config dir + if (strlen(g_configDir) + && g_arguments->host_auto + && g_arguments->port_auto) { + // apply + if(applyConfigDir(g_configDir) != TSDB_CODE_SUCCESS) { + exitLog(); + return -1; + } + infoPrint("Set engine cfgdir successfully, dir:%s\n", g_configDir); + } + + // cancel thread +#ifdef LINUX + if (sem_init(&g_arguments->cancelSem, 0, 0) != 0) { + errorPrint("%s", "failed to create cancel semaphore\n"); + exit(EXIT_FAILURE); + } + pthread_t spid = {0}; + pthread_create(&spid, NULL, benchCancelHandler, NULL); + benchSetSignal(SIGINT, benchQueryInterruptHandler); +#endif + + // running if (g_arguments->test_mode == INSERT_TEST) { if (insertTestProcess()) { errorPrint("%s", "insert test process failed\n"); @@ -171,6 +218,8 @@ int main(int argc, char* argv[]) { if ((ret == 0) && g_arguments->aggr_func) { queryAggrFunc(); } + + // free and exit postFreeResource(); #ifdef LINUX diff --git a/tools/taos-tools/src/benchQuery.c b/tools/taos-tools/src/benchQuery.c index 0de71d8b18ae..3ba4eb1a9fef 100644 --- a/tools/taos-tools/src/benchQuery.c +++ b/tools/taos-tools/src/benchQuery.c @@ -23,42 +23,31 @@ int selectAndGetResult(qThreadInfo *pThreadInfo, char *command, bool record) { } // execute sql - uint32_t threadID = pThreadInfo->threadID; char dbName[TSDB_DB_NAME_LEN] = {0}; tstrncpy(dbName, g_queryInfo.dbName, TSDB_DB_NAME_LEN); - if (g_queryInfo.iface == REST_IFACE) { - int retCode = postProceSql(command, g_queryInfo.dbName, 0, REST_IFACE, - 0, g_arguments->port, false, - pThreadInfo->sockfd, pThreadInfo->filePath); - if (0 != retCode) { - errorPrint("====restful return fail, threadID[%u]\n", threadID); - ret = -1; - } + // query + TAOS *taos = pThreadInfo->conn->taos; + int64_t rows = 0; + TAOS_RES *res = taos_query(taos, command); + int code = taos_errno(res); + if (res == NULL || code) { + // failed query + errorPrint("failed to execute sql:%s, " + "code: 0x%08x, reason:%s\n", + command, code, taos_errstr(res)); + ret = -1; } else { - // query - TAOS *taos = pThreadInfo->conn->taos; - int64_t rows = 0; - TAOS_RES *res = taos_query(taos, command); - int code = taos_errno(res); - if (res == NULL || code) { - // failed query - errorPrint("failed to execute sql:%s, " - "code: 0x%08x, reason:%s\n", - command, code, taos_errstr(res)); - ret = -1; - } else { - // succ query - if (record) - rows = fetchResult(res, pThreadInfo->filePath); - } + // succ query + if (record) + rows = fetchResult(res, pThreadInfo->filePath); + } - // free result - if (res) { - taos_free_result(res); - } - debugPrint("query sql:%s rows:%"PRId64"\n", command, rows); + // free result + if (res) { + taos_free_result(res); } + debugPrint("query sql:%s rows:%"PRId64"\n", command, rows); // record count if (ret ==0) { @@ -867,10 +856,6 @@ void totalQuery(int64_t spends) { int queryTestProcess() { prompt(0); - if (REST_IFACE == g_queryInfo.iface) { - encodeAuthBase64(); - } - // kill sql for executing seconds over "kill_slow_query_threshold" if (g_queryInfo.iface == TAOSC_IFACE && g_queryInfo.killQueryThreshold) { int32_t ret = killSlowQuery(); @@ -879,16 +864,6 @@ int queryTestProcess() { } } - // covert addr - if (g_queryInfo.iface == REST_IFACE) { - if (convertHostToServAddr(g_arguments->host, - g_arguments->port + TSDB_PORT_HTTP, - &(g_arguments->serv_addr)) != 0) { - errorPrint("%s", "convert host to server address\n"); - return -1; - } - } - // fetch child name if super table if ((g_queryInfo.superQueryInfo.sqlCount > 0) && (g_queryInfo.superQueryInfo.threadCnt > 0)) { diff --git a/tools/taos-tools/src/benchSys.c b/tools/taos-tools/src/benchSys.c index d7e44c045f70..b808b2d8df30 100644 --- a/tools/taos-tools/src/benchSys.c +++ b/tools/taos-tools/src/benchSys.c @@ -73,12 +73,10 @@ void benchPrintHelp() { printf("%s%s%s%s\r\n", indent, "-x,", indent, BENCH_AGGR); printf("%s%s%s%s\r\n", indent, "-y,", indent, BENCH_YES); printf("%s%s%s%s\r\n", indent, "-z,", indent, BENCH_TRYING_INTERVAL); -#ifdef WEBSOCKET - printf("%s%s%s%s\r\n", indent, "-W,", indent, BENCH_DSN); - printf("%s%s%s%s\r\n", indent, "-D,", indent, BENCH_TIMEOUT); -#endif printf("%s%s%s%s\r\n", indent, "-v,", indent, BENCH_VGROUPS); printf("%s%s%s%s\r\n", indent, "-V,", indent, BENCH_VERSION); + printf("%s%s%s%s\r\n", indent, "-X,", indent, DSN_DESC); + printf("%s%s%s%s\r\n", indent, "-Z,", indent, DRIVER_DESC); printf("\r\n\r\nReport bugs to %s.\r\n", CUS_EMAIL); } @@ -120,11 +118,10 @@ int32_t benchParseArgsNoArgp(int argc, char* argv[]) { || key[1] == 'R' || key[1] == 'O' || key[1] == 'a' || key[1] == 'F' || key[1] == 'k' || key[1] == 'z' -#ifdef WEBSOCKET - || key[1] == 'D' || key[1] == 'W' -#endif - || key[1] == 'v' + || key[1] == 'W' || key[1] == 'v' + || key[1] == 'X' || key[1] == 'Z' ) { + // check input value if (i + 1 >= argc) { errorPrint("option %s requires an argument\r\n", key); return -1; @@ -191,15 +188,14 @@ static struct argp_option bench_options[] = { {"debug", 'g', 0, 0, BENCH_DEBUG}, {"performance", 'G', 0, 0, BENCH_PERFORMANCE}, {"prepared_rand", 'F', "NUMBER", 0, BENCH_PREPARE}, -#ifdef WEBSOCKET - {"cloud_dsn", 'W', "DSN", 0, BENCH_DSN}, - {"timeout", 'D', "NUMBER", 0, BENCH_TIMEOUT}, -#endif + {"cloud_dsn", 'W', "DSN", 0, OLD_DSN_DESC}, {"keep-trying", 'k', "NUMBER", 0, BENCH_KEEPTRYING}, {"trying-interval", 'z', "NUMBER", 0, BENCH_TRYING_INTERVAL}, {"vgroups", 'v', "NUMBER", 0, BENCH_VGROUPS}, {"version", 'V', 0, 0, BENCH_VERSION}, {"nodrop", 'Q', 0, 0, BENCH_NODROP}, + {"dsn", 'X', "DSN", 0, DSN_DESC}, + {DRIVER_OPT, 'Z', "DRIVER", 0, DRIVER_DESC}, {0} }; @@ -251,11 +247,7 @@ int32_t benchParseSingleOpt(int32_t key, char* arg) { errorPrint( "Invalid -P: %s, will auto set to default(6030)\n", arg); - if (REST_IFACE == g_arguments->iface) { - g_arguments->port = DEFAULT_REST_PORT; - } else { - g_arguments->port = DEFAULT_PORT; - } + g_arguments->port = DEFAULT_PORT; } else { g_arguments->port_auto = false; } @@ -269,11 +261,6 @@ int32_t benchParseSingleOpt(int32_t key, char* arg) { stbInfo->iface = STMT_IFACE; } else if (0 == strcasecmp(arg, "stmt2")) { stbInfo->iface = STMT2_IFACE; - } else if (0 == strcasecmp(arg, "rest")) { - stbInfo->iface = REST_IFACE; - if (false == g_arguments->port_inputted) { - g_arguments->port = DEFAULT_REST_PORT; - } } else if (0 == strcasecmp(arg, "sml") || 0 == strcasecmp(arg, "sml-line")) { stbInfo->iface = SML_IFACE; @@ -287,19 +274,6 @@ int32_t benchParseSingleOpt(int32_t key, char* arg) { } else if (0 == strcasecmp(arg, "sml-taosjson")) { stbInfo->iface = SML_IFACE; stbInfo->lineProtocol = SML_JSON_TAOS_FORMAT; - } else if (0 == strcasecmp(arg, "sml-rest") - || (0 == strcasecmp(arg, "sml-rest-line"))) { - stbInfo->iface = SML_REST_IFACE; - stbInfo->lineProtocol = TSDB_SML_LINE_PROTOCOL; - } else if (0 == strcasecmp(arg, "sml-rest-telnet")) { - stbInfo->iface = SML_REST_IFACE; - stbInfo->lineProtocol = TSDB_SML_TELNET_PROTOCOL; - } else if (0 == strcasecmp(arg, "sml-rest-json")) { - stbInfo->iface = SML_REST_IFACE; - stbInfo->lineProtocol = TSDB_SML_JSON_PROTOCOL; - } else if (0 == strcasecmp(arg, "sml-rest-taosjson")) { - stbInfo->iface = SML_REST_IFACE; - stbInfo->lineProtocol = SML_JSON_TAOS_FORMAT; } else { errorPrint( "Invalid -I: %s, will auto set to default (taosc)\n", @@ -625,19 +599,11 @@ int32_t benchParseSingleOpt(int32_t key, char* arg) { g_arguments->performance_print = true; break; -#ifdef WEBSOCKET case 'W': + case 'X': g_arguments->dsn = arg; break; - case 'D': - if (!toolsIsStringNumber(arg)) { - errorPrintReqArg2(CUS_PROMPT"Benchmark", "D"); - } - - g_arguments->timeout = atoi(arg); - break; -#endif case 'v': if (!toolsIsStringNumber(arg)) { errorPrintReqArg2(CUS_PROMPT"Benchmark", "v"); @@ -651,6 +617,9 @@ int32_t benchParseSingleOpt(int32_t key, char* arg) { case 'V': printVersion(); exit(0); + case 'Z': + g_arguments->connMode = getConnMode(arg); + break; default: return ARGP_ERR_UNKNOWN; } diff --git a/tools/taos-tools/src/benchUtil.c b/tools/taos-tools/src/benchUtil.c index 8dcca30f8c1c..d5f614de7ca9 100644 --- a/tools/taos-tools/src/benchUtil.c +++ b/tools/taos-tools/src/benchUtil.c @@ -10,6 +10,7 @@ * FITNESS FOR A PARTICULAR PURPOSE. */ +#include #include #include "benchLog.h" @@ -45,8 +46,8 @@ FORCE_INLINE void tmfree(void *buf) { } } -FORCE_INLINE bool isRest(int32_t iface) { - return REST_IFACE == iface || SML_REST_IFACE == iface; +void engineError(char * module, char * fun, int32_t code) { + errorPrint("%s API:%s error code:0x%08X %s\n", TIP_ENGINE_ERR, fun, code, module); } void ERROR_EXIT(const char *msg) { @@ -161,50 +162,6 @@ int getAllChildNameOfSuperTable(TAOS *taos, char *dbName, char *stbName, return 0; } -int convertHostToServAddr(char *host, uint16_t port, - struct sockaddr_in *serv_addr) { - if (!host) { - errorPrint("%s", "convertHostToServAddr host is null."); - return -1; - } - debugPrint("convertHostToServAddr(host: %s, port: %d)\n", host, - port); -#ifdef WINDOWS - WSADATA wsaData; - int ret = WSAStartup(MAKEWORD(2, 2), &wsaData); - if (ret) { - return ret; - } -#endif - struct hostent *server = gethostbyname(host); - if ((server == NULL) || (server->h_addr == NULL)) { - errorPrint("%s", "no such host"); - return -1; - } - memset(serv_addr, 0, sizeof(struct sockaddr_in)); - serv_addr->sin_family = AF_INET; - serv_addr->sin_port = htons(port); - -#ifdef WINDOWS - struct addrinfo hints = {0}; - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_STREAM; - - struct addrinfo *pai = NULL; - - if (!getaddrinfo(server->h_name, NULL, &hints, &pai)) { - serv_addr->sin_addr.s_addr = - ((struct sockaddr_in *) pai->ai_addr)->sin_addr.s_addr; - freeaddrinfo(pai); - } - WSACleanup(); -#else - serv_addr->sin_addr.s_addr = inet_addr(host); - memcpy(&(serv_addr->sin_addr.s_addr), server->h_addr, server->h_length); -#endif - return 0; -} - void prompt(bool nonStopMode) { if (!g_arguments->answer_yes) { g_arguments->in_prompt = true; @@ -295,48 +252,85 @@ int regexMatch(const char *s, const char *reg, int cflags) { return 0; } - - - SBenchConn* initBenchConnImpl() { SBenchConn* conn = benchCalloc(1, sizeof(SBenchConn), true); -#ifdef WEBSOCKET - if (g_arguments->websocket) { - conn->taos_ws = ws_connect(g_arguments->dsn); - char maskedDsn[256] = "\0"; - memcpy(maskedDsn, g_arguments->dsn, 20); - memcpy(maskedDsn+20, "...", 3); - memcpy(maskedDsn+23, - g_arguments->dsn + strlen(g_arguments->dsn)-10, 10); - if (conn->taos_ws == NULL) { - errorPrint("failed to connect %s, reason: %s\n", - maskedDsn, ws_errstr(NULL)); + char show[256] = "\0"; + char * host = NULL; + uint16_t port = 0; + char * user = NULL; + char * pwd = NULL; + int32_t code = 0; + char * dsnc = NULL; + + // set mode + if (g_arguments->connMode != CONN_MODE_NATIVE && g_arguments->dsn) { + dsnc = strToLowerCopy(g_arguments->dsn); + if (dsnc == NULL) { tmfree(conn); return NULL; } - succPrint("%s conneced\n", maskedDsn); - } else { -#endif - conn->taos = taos_connect(g_arguments->host, - g_arguments->user, g_arguments->password, - NULL, g_arguments->port); - if (conn->taos == NULL) { - errorPrint("failed to connect native %s:%d, " - "code: 0x%08x, reason: %s\n", - g_arguments->host, g_arguments->port, - taos_errno(NULL), taos_errstr(NULL)); + char *cport = NULL; + char error[512] = "\0"; + code = parseDsn(dsnc, &host, &cport, &user, &pwd, error); + if (code) { + errorPrint("%s dsn=%s\n", error, dsnc); tmfree(conn); + tmfree(dsnc); return NULL; } - conn->ctaos = taos_connect(g_arguments->host, - g_arguments->user, - g_arguments->password, - NULL, g_arguments->port); -#ifdef WEBSOCKET + // default ws port + if (cport == NULL) { + if (user) + port = DEFAULT_PORT_WS_CLOUD; + else + port = DEFAULT_PORT_WS_LOCAL; + } else { + port = atoi(cport); + } + + // websocket + memcpy(show, g_arguments->dsn, 20); + memcpy(show + 20, "...", 3); + memcpy(show + 23, g_arguments->dsn + strlen(g_arguments->dsn) - 10, 10); + + } else { + + host = g_arguments->host; + user = g_arguments->user; + pwd = g_arguments->password; + + if (g_arguments->port_inputted) { + port = g_arguments->port; + } else { + port = g_arguments->connMode == CONN_MODE_NATIVE ? DEFAULT_PORT_NATIVE : DEFAULT_PORT_WS_LOCAL; + } + + sprintf(show, "host:%s port:%d ", host, port); + } + + // connect main + conn->taos = taos_connect(host, user, pwd, NULL, port); + if (conn->taos == NULL) { + errorPrint("failed to connect %s:%d, " + "code: 0x%08x, reason: %s\n", + g_arguments->host, g_arguments->port, + taos_errno(NULL), taos_errstr(NULL)); + tmfree(conn); + if (dsnc) { + tmfree(dsnc); + } + return NULL; + } + succPrint("%s connect successfully.\n", show); + + // check write correct connect + conn->ctaos = taos_connect(host, user, pwd, NULL, port); + + if (dsnc) { + tmfree(dsnc); } -#endif return conn; } @@ -350,7 +344,7 @@ SBenchConn* initBenchConn() { break; } - infoPrint("sleep %dms and try to connect... %d \n", g_arguments->trying_interval, keep_trying); + infoPrint("sleep %dms and try to connect... %d/%d \n", g_arguments->trying_interval, keep_trying, g_arguments->keep_trying); if(g_arguments->trying_interval > 0) { toolsMsleep(g_arguments->trying_interval); } @@ -362,63 +356,28 @@ SBenchConn* initBenchConn() { void closeBenchConn(SBenchConn* conn) { if(conn == NULL) return ; -#ifdef WEBSOCKET - if (g_arguments->websocket) { - ws_close(conn->taos_ws); - } else { -#endif - if(conn->taos) { - taos_close(conn->taos); - conn->taos = NULL; - } - if (conn->ctaos) { - taos_close(conn->ctaos); - conn->ctaos = NULL; - } -#ifdef WEBSOCKET + + if(conn->taos) { + taos_close(conn->taos); + conn->taos = NULL; } -#endif - tmfree(conn); -} -int32_t queryDbExecRest(char *command, char* dbName, int precision, - int iface, int protocol, bool tcp, int sockfd) { - int32_t code = postProceSql(command, - dbName, - precision, - iface, - protocol, - g_arguments->port, - tcp, - sockfd, - NULL); - return code; + if (conn->ctaos) { + taos_close(conn->ctaos); + conn->ctaos = NULL; + } + tmfree(conn); } int32_t queryDbExecCall(SBenchConn *conn, char *command) { int32_t code = 0; -#ifdef WEBSOCKET - if (g_arguments->websocket) { - WS_RES* res = ws_query_timeout(conn->taos_ws, - command, g_arguments->timeout); - code = ws_errno(res); - if (code != 0) { - errorPrint("Failed to execute <%s>, code: 0x%08x, reason: %s\n", - command, code, ws_errstr(res)); - } - ws_free_result(res); + TAOS_RES *res = taos_query(conn->taos, command); + code = taos_errno(res); + if (code) { + printErrCmdCodeStr(command, code, res); } else { -#endif - TAOS_RES *res = taos_query(conn->taos, command); - code = taos_errno(res); - if (code) { - printErrCmdCodeStr(command, code, res); - } else { - taos_free_result(res); - } -#ifdef WEBSOCKET + taos_free_result(res); } -#endif return code; } @@ -458,374 +417,6 @@ void encodeAuthBase64() { g_arguments->base64_buf[encoded_len - 1 - l] = '='; } -int postProceSqlImpl(char *sqlstr, char* dbName, int precision, int iface, - int protocol, uint16_t rest_port, bool tcp, int sockfd, - char* filePath, - char *responseBuf, int64_t response_length) { - int32_t code = -1; - char * req_fmt = - "POST %s HTTP/1.1\r\nHost: %s:%d\r\nAccept: */*\r\nAuthorization: " - "Basic %s\r\nContent-Length: %d\r\nContent-Type: " - "application/x-www-form-urlencoded\r\n\r\n%s"; - char url[URL_BUFF_LEN] = {0}; - if (iface == REST_IFACE) { - snprintf(url, URL_BUFF_LEN, "/rest/sql/%s", dbName); - } else if (iface == SML_REST_IFACE - && protocol == TSDB_SML_LINE_PROTOCOL) { - snprintf(url, URL_BUFF_LEN, - "/influxdb/v1/write?db=%s&precision=%s", dbName, - precision == TSDB_TIME_PRECISION_MILLI - ? "ms" - : precision == TSDB_TIME_PRECISION_NANO - ? "ns" - : "u"); - } else if (iface == SML_REST_IFACE - && protocol == TSDB_SML_TELNET_PROTOCOL) { - snprintf(url, URL_BUFF_LEN, "/opentsdb/v1/put/telnet/%s", dbName); - } else if (iface == SML_REST_IFACE - && (protocol == TSDB_SML_JSON_PROTOCOL - || protocol == SML_JSON_TAOS_FORMAT)) { - snprintf(url, URL_BUFF_LEN, "/opentsdb/v1/put/json/%s", dbName); - } - - int bytes, sent, received, req_str_len, resp_len; - char * request_buf = NULL; - int req_buf_len = (int)strlen(sqlstr) + REQ_EXTRA_BUF_LEN; - - if (g_arguments->terminate) { - goto free_of_postImpl; - } - request_buf = benchCalloc(1, req_buf_len, false); - - int r; - if (protocol == TSDB_SML_TELNET_PROTOCOL && tcp) { - r = snprintf(request_buf, req_buf_len, "%s", sqlstr); - } else { - r = snprintf(request_buf, req_buf_len, req_fmt, url, g_arguments->host, - rest_port, g_arguments->base64_buf, strlen(sqlstr), - sqlstr); - } - if (r >= req_buf_len) { - free(request_buf); - ERROR_EXIT("too long request"); - } - - req_str_len = (int)strlen(request_buf); - debugPrint("request buffer: %s\n", request_buf); - sent = 0; - do { - bytes = send(sockfd, request_buf + sent, - req_str_len - sent, 0); - if (bytes < 0) { - errorPrint("%s", "writing no message to socket\n"); - goto free_of_postImpl; - } - if (bytes == 0) break; - sent += bytes; - } while ((sent < req_str_len) && !g_arguments->terminate); - - if (protocol == TSDB_SML_TELNET_PROTOCOL - && iface == SML_REST_IFACE && tcp) { - code = 0; - goto free_of_postImpl; - } - - resp_len = response_length - 1; - received = 0; - - bool chunked = false; - - if (g_arguments->terminate) { - goto free_of_postImpl; - } - do { - bytes = recv(sockfd, responseBuf + received, - resp_len - received, 0); - if (bytes <= 0) { - errorPrint("%s", "reading no response from socket\n"); - goto free_of_postImpl; - } - responseBuf[resp_len] = 0; - debugPrint("response buffer: %s bytes=%d\n", responseBuf, bytes); - if (NULL != strstr(responseBuf, resEncodingChunk)) { - chunked = true; - } - int64_t index = strlen(responseBuf) - 1; - while (responseBuf[index] == '\n' || responseBuf[index] == '\r') { - if (index == 0) { - break; - } - index--; - } - debugPrint("index: %" PRId64 "\n", index); - if (chunked && responseBuf[index] == '0') { - code = 0; - break; - } - if (!chunked && responseBuf[index] == '}') { - code = 0; - break; - } - - received += bytes; - - if (g_arguments->test_mode == INSERT_TEST) { - if (strlen(responseBuf)) { - if (((NULL != strstr(responseBuf, resEncodingChunk)) && - (NULL != strstr(responseBuf, resHttp))) || - ((NULL != strstr(responseBuf, resHttpOk)) || - (NULL != strstr(responseBuf, influxHttpOk)) || - (NULL != strstr(responseBuf, opentsdbHttpOk)))) { - break; - } - } - } - } while ((received < resp_len) && !g_arguments->terminate); - - if (received == resp_len) { - errorPrint("%s", "storing complete response from socket\n"); - goto free_of_postImpl; - } - - if (NULL == strstr(responseBuf, resHttpOk) && - NULL == strstr(responseBuf, influxHttpOk) && - NULL == strstr(responseBuf, succMessage) && - NULL == strstr(responseBuf, opentsdbHttpOk)) { - errorPrint("Response:\n%s\n", responseBuf); - goto free_of_postImpl; - } - - code = 0; -free_of_postImpl: - if (filePath && strlen(filePath) > 0 && !g_arguments->terminate) { - appendResultBufToFile(responseBuf, filePath); - } - tmfree(request_buf); - return code; -} - -static int getServerVersionRestImpl(int16_t rest_port, int sockfd) { - int server_ver = -1; - char command[SHORT_1K_SQL_BUFF_LEN] = "\0"; - snprintf(command, SHORT_1K_SQL_BUFF_LEN, "SELECT SERVER_VERSION()"); - char *responseBuf = benchCalloc(1, RESP_BUF_LEN, false); - int code = postProceSqlImpl(command, - NULL, - 0, - REST_IFACE, - 0, - rest_port, - false, - sockfd, - NULL, responseBuf, RESP_BUF_LEN); - if (code != 0) { - errorPrint("Failed to execute command: %s\n", command); - goto free_of_getversion; - } - debugPrint("response buffer: %s\n", responseBuf); - if (NULL != strstr(responseBuf, resHttpOk)) { - char* start = strstr(responseBuf, "{"); - if (start == NULL) { - errorPrint("Invalid response format: %s\n", responseBuf); - goto free_of_getversion; - } - tools_cJSON* resObj = tools_cJSON_Parse(start); - if (resObj == NULL) { - errorPrint("Cannot parse response into json: %s\n", start); - } - tools_cJSON* dataObj = tools_cJSON_GetObjectItem(resObj, "data"); - if (!tools_cJSON_IsArray(dataObj)) { - char* pstr = tools_cJSON_Print(resObj); - errorPrint("Invalid or miss 'data' key in json: %s\n", pstr ? pstr : "null"); - tmfree(pstr); - tools_cJSON_Delete(resObj); - goto free_of_getversion; - } - tools_cJSON *versionObj = tools_cJSON_GetArrayItem(dataObj, 0); - tools_cJSON *versionStrObj = tools_cJSON_GetArrayItem(versionObj, 0); - server_ver = atoi(versionStrObj->valuestring); - char* pstr = tools_cJSON_Print(versionStrObj); - debugPrint("versionStrObj: %s, version: %s, server_ver: %d\n", - pstr ? pstr : "null", - versionStrObj->valuestring, server_ver); - tmfree(pstr); - tools_cJSON_Delete(resObj); - } -free_of_getversion: - free(responseBuf); - return server_ver; -} - -int getServerVersionRest(int16_t rest_port) { - int sockfd = createSockFd(); - if (sockfd < 0) { - return -1; - } - - int server_version = getServerVersionRestImpl(rest_port, sockfd); - - destroySockFd(sockfd); - return server_version; -} - -static int getCodeFromResp(char *responseBuf) { - int code = -1; - char* start = strstr(responseBuf, "{"); - if (start == NULL) { - errorPrint("Invalid response format: %s\n", responseBuf); - return -1; - } - tools_cJSON* resObj = tools_cJSON_Parse(start); - if (resObj == NULL) { - errorPrint("Cannot parse response into json: %s\n", start); - return -1; - } - tools_cJSON* codeObj = tools_cJSON_GetObjectItem(resObj, "code"); - if (!tools_cJSON_IsNumber(codeObj)) { - char* pstr = tools_cJSON_Print(resObj); - errorPrint("Invalid or miss 'code' key in json: %s\n", pstr ? pstr : "null"); - tmfree(pstr); - tools_cJSON_Delete(resObj); - return -1; - } - - code = codeObj->valueint; - - if (codeObj->valueint != 0) { - tools_cJSON* desc = tools_cJSON_GetObjectItem(resObj, "desc"); - if (!tools_cJSON_IsString(desc)) { - char* pstr = tools_cJSON_Print(resObj); - errorPrint("Invalid or miss 'desc' key in json: %s\n", pstr ? pstr : "null"); - tmfree(pstr); - return -1; - } - errorPrint("response, code: %d, reason: %s\n", - (int)codeObj->valueint, desc->valuestring); - } - - tools_cJSON_Delete(resObj); - return code; -} - -int postProceSql(char *sqlstr, char* dbName, int precision, int iface, - int protocol, uint16_t rest_port, - bool tcp, int sockfd, char* filePath) { - uint64_t response_length; - if (g_arguments->test_mode == INSERT_TEST) { - response_length = RESP_BUF_LEN; - } else { - response_length = g_queryInfo.response_buffer; - } - - char *responseBuf = benchCalloc(1, response_length, false); - int code = postProceSqlImpl(sqlstr, dbName, precision, iface, protocol, - rest_port, - tcp, sockfd, filePath, responseBuf, - response_length); - // compatibility 2.6 - if (-1 == g_arguments->rest_server_ver_major) { - // confirm version is 2.x according to "succ" - if (NULL != strstr(responseBuf, succMessage) && iface == REST_IFACE) { - g_arguments->rest_server_ver_major = 2; - } - } - - if (NULL != strstr(responseBuf, resHttpOk) && iface == REST_IFACE) { - // if taosd is not starting , rest_server_ver_major can't be got by 'select server_version()' , so is -1 - if (-1 == g_arguments->rest_server_ver_major || 3 <= g_arguments->rest_server_ver_major) { - code = getCodeFromResp(responseBuf); - } else { - code = 0; - } - goto free_of_post; - } - - if (2 == g_arguments->rest_server_ver_major) { - if (NULL != strstr(responseBuf, succMessage) && iface == REST_IFACE) { - code = getCodeFromResp(responseBuf); - } else { - code = 0; - } - goto free_of_post; - } - - if (NULL != strstr(responseBuf, influxHttpOk) && - protocol == TSDB_SML_LINE_PROTOCOL && iface == SML_REST_IFACE) { - code = 0; - goto free_of_post; - } - - if (NULL != strstr(responseBuf, opentsdbHttpOk) - && (protocol == TSDB_SML_TELNET_PROTOCOL - || protocol == TSDB_SML_JSON_PROTOCOL - || protocol == SML_JSON_TAOS_FORMAT) - && iface == SML_REST_IFACE) { - code = 0; - goto free_of_post; - } - - if (g_arguments->test_mode == INSERT_TEST) { - debugPrint("Response: \n%s\n", responseBuf); - char* start = strstr(responseBuf, "{"); - if ((start == NULL) - && (TSDB_SML_TELNET_PROTOCOL != protocol) - && (TSDB_SML_JSON_PROTOCOL != protocol) - && (SML_JSON_TAOS_FORMAT != protocol) - ) { - errorPrint("Invalid response format: %s\n", responseBuf); - goto free_of_post; - } - tools_cJSON* resObj = tools_cJSON_Parse(start); - if ((resObj == NULL) - && (TSDB_SML_TELNET_PROTOCOL != protocol) - && (TSDB_SML_JSON_PROTOCOL != protocol) - && (SML_JSON_TAOS_FORMAT != protocol) - ) { - errorPrint("Cannot parse response into json: %s\n", start); - } - tools_cJSON* codeObj = tools_cJSON_GetObjectItem(resObj, "code"); - if ((!tools_cJSON_IsNumber(codeObj)) - && (TSDB_SML_TELNET_PROTOCOL != protocol) - && (TSDB_SML_JSON_PROTOCOL != protocol) - && (SML_JSON_TAOS_FORMAT != protocol) - ) { - char* pstr = tools_cJSON_Print(resObj); - errorPrint("Invalid or miss 'code' key in json: %s\n", pstr ? pstr : "null"); - tmfree(pstr); - tools_cJSON_Delete(resObj); - goto free_of_post; - } - - if ((SML_REST_IFACE == iface) && codeObj - && (200 == codeObj->valueint)) { - code = 0; - tools_cJSON_Delete(resObj); - goto free_of_post; - } - - if ((iface == SML_REST_IFACE) - && (protocol == TSDB_SML_LINE_PROTOCOL) - && codeObj - && (codeObj->valueint != 0) && (codeObj->valueint != 200)) { - tools_cJSON* desc = tools_cJSON_GetObjectItem(resObj, "desc"); - if (!tools_cJSON_IsString(desc)) { - char* pstr = tools_cJSON_Print(resObj); - errorPrint("Invalid or miss 'desc' key in json: %s\n", pstr ? pstr : "null"); - tmfree(pstr); - } else { - errorPrint("insert mode response, code: %d, reason: %s\n", - (int)codeObj->valueint, desc->valuestring); - } - } else { - code = 0; - } - tools_cJSON_Delete(resObj); - } -free_of_post: - free(responseBuf); - return code; -} - // fetch result fo file or nothing int64_t fetchResult(TAOS_RES *res, char * filePath) { TAOS_ROW row = NULL; @@ -1219,111 +810,6 @@ void benchSetSignal(int32_t signum, ToolsSignalHandler sigfp) { } #endif -int convertServAddr(int iface, bool tcp, int protocol) { - if (tcp - && iface == SML_REST_IFACE - && protocol == TSDB_SML_TELNET_PROTOCOL) { - // telnet_tcp_port - if (convertHostToServAddr(g_arguments->host, - g_arguments->telnet_tcp_port, - &(g_arguments->serv_addr))) { - errorPrint("%s\n", "convert host to server address"); - return -1; - } - infoPrint("convertServAddr host=%s telnet_tcp_port:%d to serv_addr=%p iface=%d \n", - g_arguments->host, g_arguments->telnet_tcp_port, &g_arguments->serv_addr, iface); - } else { - int port = g_arguments->port_inputted ? g_arguments->port:DEFAULT_REST_PORT; - if (convertHostToServAddr(g_arguments->host, - port, - &(g_arguments->serv_addr))) { - errorPrint("%s\n", "convert host to server address"); - return -1; - } - infoPrint("convertServAddr host=%s port:%d to serv_addr=%p iface=%d \n", - g_arguments->host, port, &g_arguments->serv_addr, iface); - } - return 0; -} - -static void errorPrintSocketMsg(char *msg, int result) { -#ifdef WINDOWS - errorPrint("%s: %d\n", msg, WSAGetLastError()); -#else - errorPrint("%s: %d\n", msg, result); -#endif -} - -int createSockFd() { -#ifdef WINDOWS - WSADATA wsaData; - WSAStartup(MAKEWORD(2, 2), &wsaData); - SOCKET sockfd; -#else - int sockfd; -#endif - sockfd = socket(AF_INET, SOCK_STREAM, 0); - if (sockfd < 0) { - errorPrintSocketMsg("Could not create socket : ", sockfd); - return -1; - } - - int retConn = connect( - sockfd, (struct sockaddr *)&(g_arguments->serv_addr), - sizeof(struct sockaddr)); - infoPrint("createSockFd call connect serv_addr=%p retConn=%d\n", &g_arguments->serv_addr, retConn); - if (retConn < 0) { - errorPrint("%s\n", "failed to connect"); -#ifdef WINDOWS - closesocket(sockfd); - WSACleanup(); -#else - close(sockfd); -#endif - return -1; - } - return sockfd; -} - -static void closeSockFd(int sockfd) { -#ifdef WINDOWS - closesocket(sockfd); - WSACleanup(); -#else - close(sockfd); -#endif -} - -void destroySockFd(int sockfd) { - // check valid - if (sockfd < 0) { - return; - } - - // shutdown the connection since no more data will be sent - int result; - result = shutdown(sockfd, SHUT_WR); - if (SOCKET_ERROR == result) { - errorPrintSocketMsg("Socket shutdown failed with error: ", result); - closeSockFd(sockfd); - return; - } - // Receive until the peer closes the connection - do { - int recvbuflen = LARGE_BUFF_LEN; - char recvbuf[LARGE_BUFF_LEN]; - result = recv(sockfd, recvbuf, recvbuflen, 0); - if ( result > 0 ) { - debugPrint("Socket bytes received: %d\n", result); - } else if (result == 0) { - infoPrint("Connection closed with result %d\n", result); - } else { - errorPrintSocketMsg("Socket recv failed with error: ", result); - } - } while (result > 0); - - closeSockFd(sockfd); -} FORCE_INLINE void printErrCmdCodeStr(char *cmd, int32_t code, TAOS_RES *res) { char buff[512]; @@ -1334,7 +820,7 @@ FORCE_INLINE void printErrCmdCodeStr(char *cmd, int32_t code, TAOS_RES *res) { strcat(buff, "..."); msg = buff; } - errorPrint("failed to run error code: 0x%08x, reason: %s command %s\n", + errorPrint("%s error code: 0x%08x, reason: %s command %s\n", TIP_ENGINE_ERR, code, taos_errstr(res), msg); taos_free_result(res); } @@ -1372,6 +858,19 @@ char* genQMark( int32_t QCnt) { return buf; } +// get colNames , first is tbname +char *genColNames(BArray *cols) { + // reserve tbname,ts and "," space + char * buf = benchCalloc(TSDB_TABLE_NAME_LEN + 1, cols->size + 1, false); + strcpy(buf, "tbname,ts"); + for (int32_t i = 0; i < cols->size; i++) { + Field * col = benchArrayGet(cols, i); + strcat(buf, ","); + strcat(buf, col->name); + } + return buf; +} + // // STMT2 // @@ -1583,17 +1082,9 @@ uint32_t MurmurHash3_32(const char *key, uint32_t len) { // init conn int32_t initQueryConn(qThreadInfo * pThreadInfo, int iface) { // create conn - if (iface == REST_IFACE) { - int sockfd = createSockFd(); - if (sockfd < 0) { - return -1; - } - pThreadInfo->sockfd = sockfd; - } else { - pThreadInfo->conn = initBenchConn(); - if (pThreadInfo->conn == NULL) { - return -1; - } + pThreadInfo->conn = initBenchConn(); + if (pThreadInfo->conn == NULL) { + return -1; } return 0; @@ -1601,17 +1092,8 @@ int32_t initQueryConn(qThreadInfo * pThreadInfo, int iface) { // close conn void closeQueryConn(qThreadInfo * pThreadInfo, int iface) { - if (iface == REST_IFACE) { -#ifdef WINDOWS - closesocket(pThreadInfo->sockfd); - WSACleanup(); -#else - close(pThreadInfo->sockfd); -#endif - } else { - closeBenchConn(pThreadInfo->conn); - pThreadInfo->conn = NULL; - } + closeBenchConn(pThreadInfo->conn); + pThreadInfo->conn = NULL; } diff --git a/tools/taos-tools/src/dumpUtil.c b/tools/taos-tools/src/dumpUtil.c index 0b684de43f66..8535a2f0a738 100644 --- a/tools/taos-tools/src/dumpUtil.c +++ b/tools/taos-tools/src/dumpUtil.c @@ -15,6 +15,7 @@ #include +#include "pub.h" #include "dump.h" #include "dumpUtil.h" @@ -74,19 +75,6 @@ bool canRetry(int32_t code, int8_t type) { } } -#ifdef WEBSOCKET - int32_t wsCode = code & 0xFFFF; - // range1 - if (wsCode >= WEBSOCKET_CODE_BEGIN1 && wsCode <= WEBSOCKET_CODE_END1) { - return true; - } - // range2 - if (wsCode >= WEBSOCKET_CODE_BEGIN2 && wsCode <= WEBSOCKET_CODE_END2) { - return true; - } - -#endif - return false; } @@ -97,21 +85,81 @@ bool canRetry(int32_t code, int8_t type) { // connect TAOS *taosConnect(const char *dbName) { + // + // collect params + // + char show[256] = "\0"; + char * host = NULL; + uint16_t port = 0; + char * user = NULL; + char * pwd = NULL; + int32_t code = 0; + char * dsnc = NULL; + + // set mode + if (g_args.dsn) { + dsnc = strToLowerCopy(g_args.dsn); + if (dsnc == NULL) { + return NULL; + } + + char *cport = NULL; + char error[512] = ""; + code = parseDsn(dsnc, &host, &cport, &user, &pwd, error); + if (code) { + errorPrint("%s dsn=%s\n", error, dsnc); + free(dsnc); + return NULL; + } + + // default ws port + if (cport == NULL) { + if (user) + port = DEFAULT_PORT_WS_CLOUD; + else + port = DEFAULT_PORT_WS_LOCAL; + } else { + port = atoi(cport); + } + + // websocket + memcpy(show, g_args.dsn, 20); + memcpy(show + 20, "...", 3); + memcpy(show + 23, g_args.dsn + strlen(g_args.dsn) - 10, 10); + + } else { + + host = g_args.host; + user = g_args.user; + pwd = g_args.password; + + if (g_args.port_inputted) { + port = g_args.port; + } else { + port = g_args.connMode == CONN_MODE_NATIVE ? DEFAULT_PORT_NATIVE : DEFAULT_PORT_WS_LOCAL; + } + + sprintf(show, "host:%s port:%d ", host, port); + } + + // + // connect + // int32_t i = 0; + TAOS *taos = NULL; while (1) { - TAOS *taos = taos_connect(g_args.host, g_args.user, g_args.password, dbName, g_args.port); + taos = taos_connect(host, user, pwd, dbName, port); if (taos) { // successful if (i > 0) { - okPrint("Retry %d to connect %s:%d successfully!\n", i, g_args.host, g_args.port); + okPrint("Retry %d to connect %s:%d successfully!\n", i, host, port); } - return taos; + break; } // fail - errorPrint("Failed to connect to server %s, code: 0x%08x, reason: %s! \n", g_args.host, taos_errno(NULL), + errorPrint("Failed to connect to server %s, code: 0x%08x, reason: %s! \n", host, taos_errno(NULL), taos_errstr(NULL)); - if (++i > g_args.retryCount) { break; } @@ -120,7 +168,11 @@ TAOS *taosConnect(const char *dbName) { infoPrint("Retry to connect for %d after sleep %dms ...\n", i, g_args.retrySleepMs); toolsMsleep(g_args.retrySleepMs); } - return NULL; + + if (dsnc) { + free(dsnc); + } + return taos; } // query @@ -160,132 +212,6 @@ TAOS_RES *taosQuery(TAOS *taos, const char *sql, int32_t *code) { return NULL; } - -// -// --------------- websocket ------------------ -// - -#ifdef WEBSOCKET -// ws connect -WS_TAOS *wsConnect() { - int32_t i = 0; - while (1) { - WS_TAOS *ws_taos = ws_connect(g_args.dsn); - if (ws_taos) { - // successful - if (i > 0) { - okPrint("Retry %d to connect %s:%d successfully!\n", i, g_args.host, g_args.port); - } - return ws_taos; - } - - // fail - char maskedDsn[256] = "\0"; - memcpy(maskedDsn, g_args.dsn, 20); - memcpy(maskedDsn + 20, "...", 3); - memcpy(maskedDsn + 23, g_args.dsn + strlen(g_args.dsn) - 10, 10); - errorPrint("Failed to ws_connect to server %s, code: 0x%08x, reason: %s!\n", maskedDsn, ws_errno(NULL), - ws_errstr(NULL)); - - if (++i > g_args.retryCount) { - break; - } - - // retry agian - infoPrint("Retry to ws_connect for %d after sleep %dms ...\n", i, g_args.retrySleepMs); - toolsMsleep(g_args.retrySleepMs); - } - return NULL; -} - -// ws query -WS_RES *wsQuery(WS_TAOS **taos_v, const char *sql, int32_t *code) { - int32_t i = 0; - WS_RES *ws_res = NULL; - while (1) { - ws_res = ws_query_timeout(*taos_v, sql, g_args.ws_timeout); - *code = ws_errno(ws_res); - if (*code == 0) { - if (i > 0) { - okPrint("Retry %d to execute taosQuery %s successfully!\n", i, sql); - } - // successful - return ws_res; - } - - // fail - errorPrint("Failed to execute taosQuery, code: 0x%08x, reason: %s, sql=%s \n", *code, ws_errstr(ws_res), sql); - - // can retry - if(!canRetry(*code, RETRY_TYPE_QUERY)) { - infoPrint("%s", "error code not in retry range , give up retry.\n"); - return ws_res; - } - - if (++i > g_args.retryCount) { - break; - } - - // retry agian - infoPrint("Retry to execute taosQuery for %d after sleep %dms ...\n", i, g_args.retrySleepMs); - toolsMsleep(g_args.retrySleepMs); - } - - // need reconnect - infoPrint("query switch new connect to try , sql=%s \n", sql); - WS_TAOS * new_conn = wsConnect(); - if(new_conn == NULL) { - // return old - return ws_res; - } - - // use new conn to query - ws_res = ws_query_timeout(new_conn, sql, g_args.ws_timeout); - *code = ws_errno(ws_res); - if (*code == 0) { - // set new connect to old - ws_close(*taos_v); - *taos_v = new_conn; - okPrint("execute taosQuery with new connection successfully! sql=%s\n", sql); - // successful - return ws_res; - } - - // fail - errorPrint("execute taosQuery with new connection failed, code: 0x%08x, reason: %s \n", *code, ws_errstr(ws_res)); - ws_close(new_conn); - return ws_res; -} - -// fetch -int32_t wsFetchBlock(WS_RES *rs, const void **pData, int32_t *numOfRows) { - int32_t i = 0; - int32_t ws_code = TSDB_CODE_FAILED; - while (1) { - ws_code = ws_fetch_raw_block(rs, pData, numOfRows); - if (ws_code == TSDB_CODE_SUCCESS) { - // successful - if (i > 0) { - okPrint("Retry %d to fetch block successfully!\n", i); - } - return ws_code; - } - - if(!canRetry(ws_code, RETRY_TYPE_FETCH)) { - infoPrint("give up retry fetch because error code need not retry. err code=%d\n", ws_code); - break; - } - - if (++i > g_args.retryCount) { - break; - } - - // retry agian - infoPrint("Retry to ws fetch raw block for %d after sleep %dms ...\n", i, g_args.retrySleepMs); - toolsMsleep(g_args.retrySleepMs); - } - - return ws_code; -} - -#endif \ No newline at end of file +void engineError(char * module, char * fun, int32_t code) { + errorPrint("%s %s fun=%s error code:0x%08X \n", TIP_ENGINE_ERR, module, fun, code); +} \ No newline at end of file diff --git a/tools/taos-tools/src/taosdump.c b/tools/taos-tools/src/taosdump.c index 35fae99c6aff..f11d188816a0 100644 --- a/tools/taos-tools/src/taosdump.c +++ b/tools/taos-tools/src/taosdump.c @@ -11,12 +11,10 @@ #define _GNU_SOURCE +#include "pub.h" #include "cus_name.h" // include/util/ #include "dump.h" #include "dumpUtil.h" -#ifdef WEBSOCKET -#include "wsdump.h" -#endif static char **g_tsDumpInDebugFiles = NULL; static char g_dumpInCharset[64] = {0}; @@ -152,18 +150,17 @@ static struct argp_option options[] = { {"inspect", 'I', 0, 0, "inspect avro file content and print on screen", 10}, {"no-escape", 'n', 0, 0, "No escape char '`'. Default is using it.", 10}, -#ifdef WEBSOCKET - {"restful", 'R', 0, 0, "Use RESTful interface to connect server", 11}, - {"cloud", 'C', "CLOUD_DSN", 0, - "specify a DSN to access the cloud service", 11}, + {"cloud", 'C', "CLOUD_DSN", 0, OLD_DSN_DESC, 11}, {"timeout", 't', "SECONDS", 0, "The timeout seconds for " "websocket to interact."}, -#endif {"debug", 'g', 0, 0, "Print debug info.", 15}, {"dot-replace", 'Q', 0, 0, "Repalce dot character with underline character in the table name.", 10}, - {"rename", 'W', "RENAME-LIST", 0, "Rename database name with new name during importing data. RENAME-LIST: \"db1=newDB1|db2=newDB2\" means rename db1 to newDB1 and rename db2 to newDB2", 10}, + {"rename", 'W', "RENAME-LIST", 0, "Rename database name with new name during importing data. \ + RENAME-LIST: \"db1=newDB1|db2=newDB2\" means rename db1 to newDB1 and rename db2 to newDB2", 10}, {"retry-count", 'k', "VALUE", 0, "Set the number of retry attempts for connection or query failures", 11}, {"retry-sleep-ms", 'z', "VALUE", 0, "retry interval sleep time, unit ms", 11}, + {"dsn", 'X', "DSN", 0, DSN_DESC, 11}, + {DRIVER_OPT, 'Z', "DRIVER", 0, DRIVER_DESC}, {0} }; @@ -221,15 +218,9 @@ struct arguments g_args = { false, // dotRepalce 0, // dumpDbCount -#ifdef WEBSOCKET - false, // restful - false, // cloud - 10, // ws_timeout + CONN_MODE_INVALID, // connMode NULL, // dsn - NULL, // cloudToken - 0, // cloudPort - {0}, // cloudHost -#endif // WEBSOCKET + false, // port_inputted NULL, // renameBuf NULL, // renameHead @@ -584,6 +575,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { exit(EXIT_FAILURE); } g_args.port = (uint16_t)port; + g_args.port_inputted = true; break; case 'o': @@ -700,29 +692,19 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { g_args.thread_num = atoi((const char *)arg); break; -#ifdef WEBSOCKET - case 'R': - g_args.restful = true; - break; - case 'C': + case 'X': if (arg) { - g_args.dsn = arg; + if (arg[0]!= 0) { + g_args.dsn = arg; + } + } else { errorPrint("%s", "\n\t-C need a valid cloud DSN following!\n"); exit(EXIT_FAILURE); } break; - case 't': - if (arg) { - g_args.ws_timeout = atoi(arg); - } else { - fprintf(stderr, "Invalid -t option\n"); - } - break; -#endif // WEBSOCKET - case OPT_ABORT: g_args.abort = 1; break; @@ -745,6 +727,10 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { g_args.retrySleepMs = atoi((const char *)arg); printf(" set argument retry interval sleep = %d ms\n", g_args.retrySleepMs); break; + case 'Z': + g_args.connMode = getConnMode(arg); + break; + default: return ARGP_ERR_UNKNOWN; } @@ -1083,7 +1069,7 @@ static int getTableRecordInfoImplNative( return -1; } -static int getTableRecordInfoNative( +static int getTableRecordInfo( char *dbName, char *table, TableRecordInfo *pTableRecordInfo) { if (0 == getTableRecordInfoImplNative( @@ -1098,22 +1084,6 @@ static int getTableRecordInfoNative( return -1; } -static int getTableRecordInfo( - char *dbName, - char *table, TableRecordInfo *pTableRecordInfo) { - int ret; -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - ret = getTableRecordInfoWS(dbName, table, pTableRecordInfo); - } else { -#endif - ret = getTableRecordInfoNative(dbName, table, pTableRecordInfo); -#ifdef WEBSOCKET - } -#endif - return ret; -} - bool isSystemDatabase(char *dbName) { if (g_majorVersionOfClient == 3) { if ((strcmp(dbName, "information_schema") == 0) @@ -1215,46 +1185,20 @@ static int getDumpDbCount() { int32_t code = -1; -#ifdef WEBSOCKET - WS_TAOS *ws_taos = NULL; - WS_RES *ws_res; - /* Connect to server */ - if (g_args.cloud || g_args.restful) { - if (NULL == (ws_taos = wsConnect())) { - free(command); - return 0; - } - - int32_t ws_code = -1; - ws_res = wsQuery(&ws_taos, command, &ws_code); - if (0 != ws_code) { - cleanIfQueryFailedWS(__func__, __LINE__, command, ws_res); - ws_close(ws_taos); - return 0; - } - - count = getDbCountWS(ws_res); - ws_free_result(ws_res); - ws_close(ws_taos); - } else { -#endif // WEBSOCKET - if (NULL == (taos = taosConnect(NULL))) { - free(command); - return 0; - } - res = taosQuery(taos, command, &code); - if (0 != code) { - cleanIfQueryFailed(__func__, __LINE__, command, res); - taos_close(taos); - return 0; - } - - count = getDbCountNative(res); - taos_free_result(res); + if (NULL == (taos = taosConnect(NULL))) { + free(command); + return 0; + } + res = taosQuery(taos, command, &code); + if (0 != code) { + cleanIfQueryFailed(__func__, __LINE__, command, res); taos_close(taos); -#ifdef WEBSOCKET + return 0; } -#endif + + count = getDbCountNative(res); + taos_free_result(res); + taos_close(taos); free(command); return count; @@ -2044,18 +1988,8 @@ char *queryCreateTableSql(void** taos_v, const char *dbName, char *tbName) { // read uint32_t len = 0; char* data = 0; - int32_t ret; -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - ret = readRowWS(res, 0, 1, &len, &data); - } else { -#endif - ret = readRow(res, 0, 1, &len, &data); -#ifdef WEBSOCKET - } -#endif - + int32_t ret = readRow(res, 0, 1, &len, &data); if (ret != 0) { closeQuery(res); return NULL; @@ -2507,20 +2441,10 @@ static int dumpStableClasuse( const char *stbName, TableDes **pStbTableDes, FILE *fp) { - int colCount = -1; + TableDes *tableDes = *pStbTableDes; -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - colCount = getTableDesWS( - taos_v, dbInfo->name, - stbName, tableDes, true); - } else { -#endif - colCount = getTableDesNative(*taos_v, dbInfo->name, + int32_t colCount = getTableDesNative(*taos_v, dbInfo->name, stbName, tableDes, true); -#ifdef WEBSOCKET - } -#endif if (colCount < 0) { errorPrint("%s() LN%d, failed to get stable[%s] schema\n", @@ -3481,7 +3405,6 @@ int64_t queryDbForDumpOutCount( const char *dbName, const char *tbName, const int precision) { - int64_t count = -1; char *command = calloc(1, TSDB_MAX_ALLOWED_SQL_LEN); if (NULL == command) { errorPrint("%s() LN%d, memory allocation failed\n", __func__, __LINE__); @@ -3500,17 +3423,8 @@ int64_t queryDbForDumpOutCount( dbName, g_escapeChar, tbName, g_escapeChar, startTime, endTime); -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - count = queryDbForDumpOutCountWS( - command, taos_v, dbName, tbName, precision); - } else { -#endif - count = queryDbForDumpOutCountNative( + int64_t count = queryDbForDumpOutCountNative( command, *taos_v, dbName, tbName, precision); -#ifdef WEBSOCKET - } -#endif return count; } @@ -3564,16 +3478,7 @@ void *queryDbForDumpOutOffset( start_time, end_time, limit, offset); } - void *res = NULL; -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - res = queryDbForDumpOutOffsetWS(taos_v, command); - } else { -#endif - res = queryDbForDumpOutOffsetNative(*taos_v, command); -#ifdef WEBSOCKET - } -#endif + void *res = queryDbForDumpOutOffsetNative(*taos_v, command); return res; } @@ -4698,17 +4603,8 @@ static int64_t dumpInAvroTbTagsImpl( if ((0 == strlen(tableDes->name)) || (0 != strcmp(tableDes->name, stbName))) { -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - getTableDesWS(taos_v, namespace, - stbName, tableDes, false); - } else { -#endif - getTableDesNative(*taos_v, namespace, + getTableDesNative(*taos_v, namespace, stbName, tableDes, false); -#ifdef WEBSOCKET - } -#endif } avro_value_get_by_name(&value, "tbname", &field_value, NULL); @@ -4832,34 +4728,16 @@ static int64_t dumpInAvroTbTagsImpl( curr_sqlstr_len += sprintf(sqlstr + curr_sqlstr_len-1, ")"); debugPrint("%s() LN%d, sqlstr=\n%s\n", __func__, __LINE__, sqlstr); freeTbNameIfLooseMode(stbName); -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - int32_t ws_code = -1; - WS_RES *ws_res = wsQuery(taos_v, sqlstr, &ws_code); - if (ws_code != 0) { - warnPrint("%s() LN%d ws_query() failed! reason: %s\n", - __func__, __LINE__, ws_errstr(ws_res)); - failed++; - } else { - success++; - } - ws_free_result(ws_res); - ws_res = NULL; + int32_t code = -1; + TAOS_RES *res = taosQuery(*taos_v, sqlstr, &code); + if (code != 0) { + warnPrint("%s() LN%d taosQuery() failed! sqlstr: %s, reason: %s\n", + __func__, __LINE__, sqlstr, taos_errstr(res)); + failed++; } else { -#endif - int32_t code = -1; - TAOS_RES *res = taosQuery(*taos_v, sqlstr, &code); - if (code != 0) { - warnPrint("%s() LN%d taosQuery() failed! sqlstr: %s, reason: %s\n", - __func__, __LINE__, sqlstr, taos_errstr(res)); - failed++; - } else { - success++; - } - taos_free_result(res); -#ifdef WEBSOCKET + success++; } -#endif + taos_free_result(res); } avro_value_decref(&value); @@ -4911,40 +4789,20 @@ static int64_t dumpInAvroNtbImpl( buf = newBuf; } -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - int32_t ws_code = -1; - WS_RES *ws_res = wsQuery(taos_v, buf, &ws_code); - if (0 != ws_code) { - errorPrint("%s() LN%d," - " Failed to execute ws_query(%s)." - " ws_taos: %p, code: 0x%08x, reason: %s\n", - __func__, __LINE__, buf, - *taos_v, ws_code, ws_errstr(ws_res)); - failed++; - } else { - success++; - } - ws_free_result(ws_res); - ws_res = NULL; + int32_t code = -1; + TAOS_RES *res = taosQuery(*taos_v, buf, &code); + if (0 != code) { + errorPrint("%s() LN%d," + " Failed to execute taosQuery(%s)." + " taos: %p, code: 0x%08x, reason: %s\n", + __func__, __LINE__, buf, + *taos_v, code, taos_errstr(res)); + failed++; } else { -#endif - int32_t code = -1; - TAOS_RES *res = taosQuery(*taos_v, buf, &code); - if (0 != code) { - errorPrint("%s() LN%d," - " Failed to execute taosQuery(%s)." - " taos: %p, code: 0x%08x, reason: %s\n", - __func__, __LINE__, buf, - *taos_v, code, taos_errstr(res)); - failed++; - } else { - success++; - } - taos_free_result(res); -#ifdef WEBSOCKET + success++; } -#endif + taos_free_result(res); + // free if (newBuf) { free(newBuf); @@ -5598,43 +5456,19 @@ static int64_t dumpInAvroDataImpl( RecordSchema *recordSchema, char *fileName) { TAOS_STMT *stmt = NULL; -#ifdef WEBSOCKET - WS_STMT *ws_stmt = NULL; - if (g_args.cloud || g_args.restful) { - ws_stmt = ws_stmt_init(*taos_v); - int32_t ws_code = ws_errno(ws_stmt); - if (ws_code) { - errorPrint("%s() LN%d, stmt init failed! ws_taos: %p," - " code: 0x%08x, reason: %s\n", - __func__, __LINE__, *taos_v, ws_code, ws_errstr(ws_stmt)); - return -1; - } - } else { -#endif - stmt = taos_stmt_init(*taos_v); - if (NULL == stmt) { - errorPrint("%s() LN%d, stmt init failed! taos: %p, code: 0x%08x, " - "reason: %s\n", - __func__, __LINE__, *taos_v, - taos_errno(NULL), taos_errstr(NULL)); - return -1; - } -#ifdef WEBSOCKET + stmt = taos_stmt_init(*taos_v); + if (NULL == stmt) { + errorPrint("%s() LN%d, stmt init failed! taos: %p, code: 0x%08x, " + "reason: %s\n", + __func__, __LINE__, *taos_v, + taos_errno(NULL), taos_errstr(NULL)); + return -1; } -#endif TableDes *tableDes = (TableDes *)calloc(1, sizeof(TableDes) + sizeof(ColDes) * TSDB_MAX_COLUMNS); if (NULL == tableDes) { errorPrint("%s() LN%d, memory allocation failed!\n", __func__, __LINE__); -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - ws_stmt_close(ws_stmt); - } else { -#endif - taos_stmt_close(stmt); -#ifdef WEBSOCKET - } -#endif + taos_stmt_close(stmt); return -1; } @@ -5642,15 +5476,7 @@ static int64_t dumpInAvroDataImpl( if (NULL == stmtBuffer) { errorPrint("%s() LN%d, memory allocation failed!\n", __func__, __LINE__); free(tableDes); -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - ws_stmt_close(ws_stmt); - } else { -#endif - taos_stmt_close(stmt); -#ifdef WEBSOCKET - } -#endif + taos_stmt_close(stmt); return -1; } @@ -5668,33 +5494,15 @@ static int64_t dumpInAvroDataImpl( __func__, __LINE__, stmtBuffer); int code; -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - if (0 != (code = ws_stmt_prepare(ws_stmt, stmtBuffer, strlen(stmtBuffer)))) { - errorPrint("%s() LN%d, failed to execute ws_stmt_prepare()." - " ws_taos: %p, code: 0x%08x, reason: %s\n", - __func__, __LINE__, - *taos_v, code, ws_errstr(ws_stmt)); - - free(stmtBuffer); - free(tableDes); - ws_stmt_close(ws_stmt); - return -1; - } - } else { -#endif - if (0 != (code = taos_stmt_prepare(stmt, stmtBuffer, 0))) { - errorPrint("Failed to execute taos_stmt_prepare(). reason: %s\n", - taos_stmt_errstr(stmt)); + if (0 != (code = taos_stmt_prepare(stmt, stmtBuffer, 0))) { + errorPrint("Failed to execute taos_stmt_prepare(). reason: %s\n", + taos_stmt_errstr(stmt)); - free(stmtBuffer); - free(tableDes); - taos_stmt_close(stmt); - return -1; - } -#ifdef WEBSOCKET + free(stmtBuffer); + free(tableDes); + taos_stmt_close(stmt); + return -1; } -#endif avro_value_iface_t *value_class = avro_generic_class_from_schema(schema); avro_value_t value; @@ -5706,15 +5514,7 @@ static int64_t dumpInAvroDataImpl( errorPrint("%s() LN%d, memory allocation failed!\n", __func__, __LINE__); free(stmtBuffer); free(tableDes); -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - ws_stmt_close(ws_stmt); - } else { -#endif - taos_stmt_close(stmt); -#ifdef WEBSOCKET - } -#endif + taos_stmt_close(stmt); return -1; } @@ -5762,73 +5562,30 @@ static int64_t dumpInAvroDataImpl( free(stmtBuffer); free(tableDes); tfree(tbName); - #ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - ws_stmt_close(ws_stmt); - } else { - #endif - taos_stmt_close(stmt); - #ifdef WEBSOCKET - } - #endif + taos_stmt_close(stmt); return -1; } - #ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - snprintf(escapedTbName, escapedTbNameLen, "%s.%s%s%s", - namespace, g_escapeChar, tbName, g_escapeChar); + snprintf(escapedTbName, escapedTbNameLen, "%s%s%s", + g_escapeChar, tbName, g_escapeChar); - debugPrint("%s() LN%d escaped table: %s\n", - __func__, __LINE__, escapedTbName); + debugPrint("%s() LN%d escaped table: %s\n", + __func__, __LINE__, escapedTbName); - debugPrint("%s() LN%d, stmt: %p, will call ws_stmt_set_tbname(%s)\n", - __func__, __LINE__, ws_stmt, escapedTbName); - if (0 != (code = ws_stmt_set_tbname(ws_stmt, escapedTbName))) { - errorPrint("%s() LN%d, failed to execute ws_stmt_set_tbname(%s)." - " ws_taos: %p, code: 0x%08x, reason: %s\n", - __func__, __LINE__, - escapedTbName, *taos_v, code, ws_errstr(ws_stmt)); - free(escapedTbName); - freeTbNameIfLooseMode(tbName); - continue; - } - debugPrint("%s() LN%d, stmt: %p, ws_stmt_set_tbname(%s) done\n", - __func__, __LINE__, ws_stmt, escapedTbName); - } else { - #endif - snprintf(escapedTbName, escapedTbNameLen, "%s%s%s", - g_escapeChar, tbName, g_escapeChar); - - debugPrint("%s() LN%d escaped table: %s\n", - __func__, __LINE__, escapedTbName); - - if (0 != taos_stmt_set_tbname(stmt, escapedTbName)) { - errorPrint("Failed to execute taos_stmt_set_tbname(%s)." - "reason: %s\n", - escapedTbName, taos_stmt_errstr(stmt)); - free(escapedTbName); - free(tbName); - tbName = NULL; - continue; - } - #ifdef WEBSOCKET + if (0 != taos_stmt_set_tbname(stmt, escapedTbName)) { + errorPrint("Failed to execute taos_stmt_set_tbname(%s)." + "reason: %s\n", + escapedTbName, taos_stmt_errstr(stmt)); + free(escapedTbName); + free(tbName); + tbName = NULL; + continue; } - #endif free(escapedTbName); if ((0 == strlen(tableDes->name)) || (0 != strcmp(tableDes->name, tbName))) { - #ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - getTableDesWS(taos_v, namespace, - tbName, tableDes, true); - } else { - #endif - getTableDesNative(*taos_v, namespace, + getTableDesNative(*taos_v, namespace, tbName, tableDes, true); - #ifdef WEBSOCKET - } - #endif } } // tbName @@ -6045,117 +5802,55 @@ static int64_t dumpInAvroDataImpl( bind->num = 1; } debugPrint2("%s", "\n"); -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - if (0 != (code = ws_stmt_bind_param_batch(ws_stmt, - (const WS_MULTI_BIND *)bindArray, onlyCol))) { - errorPrint("%s() LN%d ws_stmt_bind_param_batch() failed!" - " ws_taos: %p, code: 0x%08x, reason: %s\n", - __func__, __LINE__, *taos_v, code, ws_errstr(ws_stmt)); - countFailureAndFree(bindArray, onlyCol, &failed, tbName); - continue; - } + if (0 != (code = taos_stmt_bind_param_batch(stmt, + (TAOS_MULTI_BIND *)bindArray))) { + errorPrint("%s() LN%d stmt_bind_param_batch() failed! " + "reason: %s\n", + __func__, __LINE__, taos_stmt_errstr(stmt)); + countFailureAndFree(bindArray, onlyCol, &failed, tbName); + continue; + } - if (0 != (code = ws_stmt_add_batch(ws_stmt))) { - errorPrint("%s() LN%d stmt_bind_param() failed!" - " ws_taos: %p, code: 0x%08x, reason: %s\n", - __func__, __LINE__, *taos_v, code, ws_errstr(ws_stmt)); - countFailureAndFree(bindArray, onlyCol, &failed, tbName); - continue; - } + if (0 != (code = taos_stmt_add_batch(stmt))) { + errorPrint("%s() LN%d stmt_bind_param() failed! reason: %s\n", + __func__, __LINE__, taos_stmt_errstr(stmt)); + countFailureAndFree(bindArray, onlyCol, &failed, tbName); + continue; + } - if ( 0 == (count % g_args.data_batch) ) { - // batch to exec - int32_t affected_rows; - if (0 != (code = ws_stmt_execute(ws_stmt, &affected_rows))) { - errorPrint("%s() LN%d ws_stmt_execute() failed!" - " ws_taos: %p, code: 0x%08x, reason: %s, " - "timestamp: %"PRId64" count=%"PRId64"\n", - __func__, __LINE__, *taos_v, code, - ws_errstr(ws_stmt), ts_debug, count); - countFailureAndFree(bindArray, onlyCol, &failed, tbName); - continue; + // batch execute + if ( 0 == (count % g_args.data_batch) ) { + if( 0 != (code = taos_stmt_execute(stmt)) ){ + if (code == TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE) { + countTSOutOfRange++; } else { - success += g_args.data_batch; - debugPrint("ok call ws_stmt_execute count=%"PRId64" success=%"PRId64" failed=%"PRId64"\n", - count, success, failed); + errorPrint("%s() LN%d taos_stmt_execute() failed! " + "code: 0x%08x, reason: %s, timestamp: %"PRId64"\n", + __func__, __LINE__, + code, taos_stmt_errstr(stmt), ts_debug); } - } - } else { -#endif - if (0 != (code = taos_stmt_bind_param_batch(stmt, - (TAOS_MULTI_BIND *)bindArray))) { - errorPrint("%s() LN%d stmt_bind_param_batch() failed! " - "reason: %s\n", - __func__, __LINE__, taos_stmt_errstr(stmt)); - countFailureAndFree(bindArray, onlyCol, &failed, tbName); - continue; - } - - if (0 != (code = taos_stmt_add_batch(stmt))) { - errorPrint("%s() LN%d stmt_bind_param() failed! reason: %s\n", - __func__, __LINE__, taos_stmt_errstr(stmt)); countFailureAndFree(bindArray, onlyCol, &failed, tbName); continue; + } else { + success += g_args.data_batch; + debugPrint("ok call taos_stmt_execute count=%"PRId64" success=%"PRId64" failed=%"PRId64"\n", + count, success, failed); } - - // batch execute - if ( 0 == (count % g_args.data_batch) ) { - if( 0 != (code = taos_stmt_execute(stmt)) ){ - if (code == TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE) { - countTSOutOfRange++; - } else { - errorPrint("%s() LN%d taos_stmt_execute() failed! " - "code: 0x%08x, reason: %s, timestamp: %"PRId64"\n", - __func__, __LINE__, - code, taos_stmt_errstr(stmt), ts_debug); - } - countFailureAndFree(bindArray, onlyCol, &failed, tbName); - continue; - } else { - success += g_args.data_batch; - debugPrint("ok call taos_stmt_execute count=%"PRId64" success=%"PRId64" failed=%"PRId64"\n", - count, success, failed); - } - } -#ifdef WEBSOCKET } -#endif freeBindArray(bindArray, onlyCol); } // last batch execute -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - if ( 0 != (count % g_args.data_batch) ) { - int32_t affected_rows; - if (0 != (code = ws_stmt_execute(ws_stmt, &affected_rows))) { - errorPrint( - "%s() LN%d ws_stmt_execute() failed!" - " ws_taos: %p, code: 0x%08x, reason: %s \n", - __func__, __LINE__, *taos_v, code, ws_errstr(ws_stmt)); - failed++; - } else { - success += count % g_args.data_batch; - debugPrint("ok call last ws_stmt_execute count=%"PRId64" success=%"PRId64" failed=%"PRId64"\n", - count, success, failed); - } - } - } else { -#endif - if (0 != (count % g_args.data_batch)) { - if (0 != (code = taos_stmt_execute(stmt))) { - errorPrint("error last execute taos_stmt_execute. errstr=%s\n", taos_stmt_errstr(stmt)); - failed++; - } else { - success += count % g_args.data_batch; - debugPrint("ok call last ws_stmt_execute count=%"PRId64" success=%"PRId64" failed=%"PRId64"\n", - count, success, failed); - } + if (0 != (count % g_args.data_batch)) { + if (0 != (code = taos_stmt_execute(stmt))) { + errorPrint("error last execute taos_stmt_execute. errstr=%s\n", taos_stmt_errstr(stmt)); + failed++; + } else { + success += count % g_args.data_batch; + debugPrint("ok call last ws_stmt_execute count=%"PRId64" success=%"PRId64" failed=%"PRId64"\n", + count, success, failed); } -#ifdef WEBSOCKET } -#endif free(tbName); avro_value_decref(&value); @@ -6163,15 +5858,7 @@ static int64_t dumpInAvroDataImpl( tfree(bindArray); tfree(stmtBuffer); freeTbDes(tableDes, true); -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - ws_stmt_close(ws_stmt); - } else { -#endif - taos_stmt_close(stmt); -#ifdef WEBSOCKET - } -#endif + taos_stmt_close(stmt); if (failed) { if (countTSOutOfRange) { errorPrint("Total %"PRId64" record(s) ts out of range!\n", @@ -6267,15 +5954,7 @@ static RecordSchema *getSchemaAndReaderFromFile( } static void closeTaosConnWrapper(void *taos) { -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - ws_close(taos); - } else { -#endif - taos_close(taos); -#ifdef WEBSOCKET - } -#endif + taos_close(taos); } static int64_t dumpInOneAvroFile( @@ -6311,22 +5990,10 @@ static int64_t dumpInOneAvroFile( TAOS *taos = NULL; void **taos_v = NULL; -#ifdef WEBSOCKET - WS_TAOS *ws_taos = NULL; - if (g_args.cloud || g_args.restful) { - if (NULL == (ws_taos = wsConnect())) { - return -1; - } - taos_v = &ws_taos; - } else { -#endif - if (NULL == (taos = taosConnect(namespace))) { - return -1; - } - taos_v = &taos; -#ifdef WEBSOCKET + if (NULL == (taos = taosConnect(namespace))) { + return -1; } -#endif + taos_v = &taos; int64_t retExec = 0; switch (avroType) { @@ -7029,27 +6696,15 @@ static int64_t dumpTableDataAvro( return -1; } - int64_t rows; - int64_t start_time = getStartTime(precision); int64_t end_time = getEndTime(precision); if ((-1 == start_time) || (-1 == end_time)) { return -1; } -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - rows = dumpTableDataAvroWS(dataFilename, index, tbName, + int64_t rows = dumpTableDataAvroNative(dataFilename, index, tbName, belongStb, dbInfo->name, precision, colCount, tableDes, start_time, end_time); - } else { -#endif - rows = dumpTableDataAvroNative(dataFilename, index, tbName, - belongStb, dbInfo->name, precision, colCount, tableDes, - start_time, end_time); -#ifdef WEBSOCKET - } -#endif return rows; } @@ -7094,18 +6749,9 @@ static int64_t dumpTableData( return -1; } - int64_t rows; -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - rows = dumpTableDataWS(index, fp, tbName, dbInfo->name, - precision, tableDes, start_time, end_time); - } else { -#endif - rows = dumpTableDataNative(index, fp, tbName, dbInfo->name, + + int64_t rows = dumpTableDataNative(index, fp, tbName, dbInfo->name, precision, tableDes, start_time, end_time); -#ifdef WEBSOCKET - } -#endif return rows; } @@ -7139,17 +6785,8 @@ int64_t dumpNormalTable( __func__, __LINE__); return -1; } -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - numColsAndTags = getTableDesWS(taos_v, - dbInfo->name, tbName, tableDes, !belongStb); - } else { -#endif - numColsAndTags = getTableDesNative(*taos_v, + numColsAndTags = getTableDesNative(*taos_v, dbInfo->name, tbName, tableDes, !belongStb); -#ifdef WEBSOCKET - } -#endif if (numColsAndTags < 0) { errorPrint("%s() LN%d, failed to get table[%s] schema\n", @@ -7170,18 +6807,8 @@ int64_t dumpNormalTable( errorPrint("%s() LN%d, memory allocation failed!\n", __func__, __LINE__); return -1; } -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - numColsAndTags = getTableDesWS( - taos_v, + numColsAndTags = getTableDesNative(*taos_v, dbInfo->name, tbName, tableDes, !belongStb); - } else { -#endif - numColsAndTags = getTableDesNative(*taos_v, - dbInfo->name, tbName, tableDes, !belongStb); -#ifdef WEBSOCKET - } -#endif if (numColsAndTags < 0) { errorPrint("%s() LN%d, failed to get table[%s] schema\n", @@ -7243,22 +6870,9 @@ int64_t dumpNormalTable( __func__, __LINE__); return -1; } -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - numColsAndTags = getTableDesFromStbWS( - taos_v, - dbInfo->name, - stbDes, - tbName, &tableDes); - - } else { -#endif - numColsAndTags = getTableDesFromStbNative( + numColsAndTags = getTableDesFromStbNative( *taos_v, dbInfo->name, stbDes, tbName, &tableDes); -#ifdef WEBSOCKET - } -#endif if (numColsAndTags < 0) { errorPrint("%s() LN%d columns/tags count is %d\n", __func__, __LINE__, numColsAndTags); @@ -7417,34 +7031,10 @@ static int createMTableAvroHeadImp( return -1; } - int colCount = 0; - colCount = colCount; // reduce compile warning -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - colCount = getTableDesFromStbWS( - (WS_TAOS*)taos_v, - dbName, + getTableDesFromStbNative(*taos_v, dbName, stbTableDes, tbName, &subTableDes); - } else { -#endif // WEBSOCKET - colCount = getTableDesFromStbNative(*taos_v, dbName, - stbTableDes, - tbName, - &subTableDes); -#ifdef WEBSOCKET - } - - if (colCount < 0) { - errorPrint("%s() LN%d, columns count is %d\n", - __func__, __LINE__, colCount); - if (subTableDes) { - freeTbDes(subTableDes, true); - } - return -1; - } -#endif for (int tag = 0; tag < subTableDes->tags; tag++) { debugPrint("%s() LN%d, sub table %s no. %d tags is %s, " @@ -7786,15 +7376,7 @@ static int createMTableAvroHeadSpecified( return -1; } -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - getTableDesWS(taos_v, dbName, stable, stbTableDes, false); - } else { -#endif - getTableDesNative(*taos_v, dbName, stable, stbTableDes, false); -#ifdef WEBSOCKET - } -#endif + getTableDesNative(*taos_v, dbName, stable, stbTableDes, false); char *jsonTagsSchema = NULL; if (0 != convertTbTagsDesToJsonWrap( @@ -7926,19 +7508,8 @@ static int64_t fillTbNameArr( debugPrint("%s() LN%d, run command <%s>.\n", __func__, __LINE__, command2); - int64_t ntbCount; - -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - ntbCount = fillTbNameArrWS( - taos_v, command2, tbNameArr, stable, preCount); - } else { -#endif - ntbCount = fillTbNameArrNative( + int64_t ntbCount = fillTbNameArrNative( *taos_v, command2, tbNameArr, stable, preCount); -#ifdef WEBSOCKET - } -#endif infoPrint("The number of tables of %s be filled is %"PRId64"!\n", stable, ntbCount); @@ -8314,46 +7885,21 @@ static int writeTagsToAvro( // open query with native or websocket void* openQuery(void** taos_v, const char * sql) { -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - int32_t ws_code = -1; - WS_RES *ws_res = wsQuery(taos_v, sql, &ws_code); - if (ws_code != 0) { - errorPrint("exe sql:%s failed. error code =%d\n", sql, ws_code); - return NULL; - } - return ws_res; - } else { -#endif - int32_t code = -1; - TAOS_RES* res = taosQuery(*taos_v, sql, &code); - if (code != 0) { - taos_free_result(res); - errorPrint("open query: %s execute failed. errcode=%d\n", sql, code); - return NULL; - } - return res; -#ifdef WEBSOCKET + int32_t code = -1; + TAOS_RES* res = taosQuery(*taos_v, sql, &code); + if (code != 0) { + taos_free_result(res); + errorPrint("open query: %s execute failed. errcode=%d\n", sql, code); + return NULL; } -#endif + return res; } // close query and free result void closeQuery(void* res) { -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - if(res) { - ws_free_result(res); - } - return ; - } else { -#endif - if(res) { - taos_free_result(res); - } -#ifdef WEBSOCKET - } -#endif + if(res) { + taos_free_result(res); + } } // read next table tags to tbDes @@ -8478,11 +8024,6 @@ static int dumpStableMeta( return -1; } -#ifdef WEBSOCKET - int idx = 0; - int cnt = 0; -#endif - // loop read tables des int size = sizeof(TableDes) + sizeof(ColDes) * stbDes->tags; TableDes *tbDes = calloc(1, size); @@ -8493,16 +8034,7 @@ static int dumpStableMeta( memset(tbDes->name, 0, sizeof(tbDes->name)); // reset zero tbDes->tags = stbDes->tags; // stable tags same with child table memcpy(tbDes->cols, &stbDes->cols[stbDes->columns], sizeof(ColDes)* stbDes->tags); // copy tag info - int ret; -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - ret = readNextTableDesWS(tagsRes, tbDes, &idx, &cnt); - } else { -#endif - ret = readNextTableDesNative(tagsRes, tbDes); -#ifdef WEBSOCKET - } -#endif + int32_t ret = readNextTableDesNative(tagsRes, tbDes); if(ret < 0){ // read error @@ -8655,6 +8187,8 @@ static void printArgs(FILE *file) { fprintf(file, "loose_mode: %s\n", g_args.loose_mode?"true":"false"); fprintf(file, "isDumpIn: %s\n", g_args.isDumpIn?"true":"false"); fprintf(file, "arg_list_len: %d\n", g_args.arg_list_len); + +/* TODO #ifdef WEBSOCKET if (g_args.cloud) { fprintf(file, "cloud: %s\n", g_args.cloud?"true":"false"); @@ -8671,6 +8205,7 @@ static void printArgs(FILE *file) { } } #endif // WEBSOCKET +*/ fflush(file); } @@ -8871,17 +8406,8 @@ static int dumpExtraInfoHead(void *taos, FILE *fp) { return -1; } -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - snprintf(buffer, BUFFER_LEN, "#!server_ver: %s\n", - ws_get_server_info(taos)); - } else { -#endif - snprintf(buffer, BUFFER_LEN, "#!server_ver: %s\n", + snprintf(buffer, BUFFER_LEN, "#!server_ver: %s\n", taos_get_server_info(taos)); -#ifdef WEBSOCKET - } -#endif char *firstline = strchr(buffer, '\n'); @@ -8965,15 +8491,7 @@ static int dumpExtraInfo(void **taos_v, FILE *fp) { return ret; } -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - dumpExtraInfoVarWS(taos_v, fp); - } else { -#endif - dumpExtraInfoVar(*taos_v, fp); -#ifdef WEBSOCKET - } -#endif + dumpExtraInfoVar(*taos_v, fp); ret = ferror(fp); @@ -9166,15 +8684,7 @@ static int64_t dumpInOneDebugFile( } debugPrint("%s() LN%d, cmd: %s\n", __func__, __LINE__, cmd); -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - ret = queryDbImplWS(taos_v, newSql?newSql:cmd); - } else { -#endif - ret = queryDbImplNative(*taos_v, newSql?newSql:cmd); -#ifdef WEBSOCKET - } -#endif + ret = queryDbImplNative(*taos_v, newSql?newSql:cmd); // free if (newSql) { free(newSql); @@ -9306,23 +8816,11 @@ static int dumpInDebugWorkThreads(const char *dbPath) { " from %"PRId64"\n", t, pThreadInfo->count, pThreadInfo->from); -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - if (NULL == (pThreadInfo->taos = wsConnect())) { - free(infos); - free(pids); - return -1; - } - } else { -#endif // WEBSOCKET - if (NULL == (pThreadInfo->taos = taosConnect(NULL))) { - free(infos); - free(pids); - return -1; - } -#ifdef WEBSOCKET + if (NULL == (pThreadInfo->taos = taosConnect(NULL))) { + free(infos); + free(pids); + return -1; } -#endif // WEBSOCKET if (pthread_create(pids + t, NULL, dumpInDebugWorkThreadFp, (void*)pThreadInfo) != 0) { @@ -9345,15 +8843,7 @@ static int dumpInDebugWorkThreads(const char *dbPath) { } for (int32_t t = 0; t < threads; ++t) { -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - ws_close(infos[t].taos); - } else { -#endif - taos_close(infos[t].taos); -#ifdef WEBSOCKET - } -#endif // WEBSOCKET + taos_close(infos[t].taos); } for (int32_t t = 0; t < threads; ++t) { @@ -9372,22 +8862,10 @@ static int dumpInDebugWorkThreads(const char *dbPath) { static int dumpInDbs(const char *dbPath) { void **taos_v = NULL; TAOS *taos = NULL; -#ifdef WEBSOCKET - WS_TAOS *ws_taos = NULL; - if (g_args.cloud || g_args.restful) { - if (NULL == (ws_taos = wsConnect())) { - return -1; - } - taos_v = &ws_taos; - } else { -#endif - if (NULL == (taos = taosConnect(NULL))) { - return -1; - } - taos_v = &taos; -#ifdef WEBSOCKET + if (NULL == (taos = taosConnect(NULL))) { + return -1; } -#endif + taos_v = &taos; char dbsSql[MAX_PATH_LEN]; snprintf(dbsSql, MAX_PATH_LEN, "%s/%s", dbPath, "dbs.sql"); @@ -9629,15 +9107,7 @@ static void *dumpTablesOfStbThread(void *arg) { } } -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - dumpNormalTablesOfStbWS(pThreadInfo, fp, dumpFilename); - } else { -#endif - dumpTablesOfStbNative(pThreadInfo, fp, dumpFilename); -#ifdef WEBSOCKET - } -#endif + dumpTablesOfStbNative(pThreadInfo, fp, dumpFilename); if (fp) { fclose(fp); fp = NULL; @@ -9666,28 +9136,11 @@ int dumpSTableData(SDbInfo* dbInfo, TableDes* stbDes, char** tbNameArr, int64_t threadInfo *pThreadInfo; for (int32_t i = 0; i < threads; i++) { pThreadInfo = infos + i; -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - if (NULL == (pThreadInfo->taos = wsConnect())) { - errorPrint("%s() LN%d, Failed to connect to server, " - "reason: %s\n", - __func__, - __LINE__, - ws_errstr(NULL)); - free(pids); - free(infos); - return -1; - } - } else { -#endif // WEBSOCKET - if (NULL == (pThreadInfo->taos = taosConnect(dbInfo->name))) { - free(pids); - free(infos); - return -1; - } -#ifdef WEBSOCKET + if (NULL == (pThreadInfo->taos = taosConnect(dbInfo->name))) { + free(pids); + free(infos); + return -1; } -#endif pThreadInfo->threadIndex = i; pThreadInfo->count = (i < mod) ? batch+1 : batch; @@ -9728,15 +9181,7 @@ int dumpSTableData(SDbInfo* dbInfo, TableDes* stbDes, char** tbNameArr, int64_t stbDes->name, tbCount); for (int32_t i = 0; i < threads; i++) { pThreadInfo = infos + i; -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - ws_close(pThreadInfo->taos); - } else { -#endif // WEBSOCKET - taos_close(pThreadInfo->taos); -#ifdef WEBSOCKET - } -#endif + taos_close(pThreadInfo->taos); } free(pids); @@ -9777,18 +9222,8 @@ static int64_t dumpStable( } // obtain stable des data - int colCount = 0; -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - colCount = getTableDesWS(taos_v, dbInfo->name, - stbName, stbDes, true); - } else { -#endif - colCount = getTableDesNative(*taos_v, dbInfo->name, + int32_t colCount = getTableDesNative(*taos_v, dbInfo->name, stbName, stbDes, true); -#ifdef WEBSOCKET - } -#endif if (colCount < 0) { errorPrint("%s() LN%d, failed to get stable[%s] schema\n", __func__, __LINE__, stbName); @@ -9800,16 +9235,7 @@ static int64_t dumpStable( stbName, stbDes->columns, stbDes->tags); // get stable child count - int64_t tbCount = 0; -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - tbCount = getNtbCountOfStbWS(dbInfo->name, stbName); - } else { -#endif - tbCount = getTbCountOfStbNative(dbInfo->name, stbName); -#ifdef WEBSOCKET - } -#endif + int64_t tbCount = getTbCountOfStbNative(dbInfo->name, stbName); if(tbCount < 0 ) { errorPrint("get stable %s failed.", stbName); freeTbDes(stbDes, true); @@ -10139,21 +9565,10 @@ static int64_t dumpWholeDatabase(void **taos_v, SDbInfo *dbInfo, FILE *fp) { atomic_add_fetch_64( &g_resultStatistics.totalDatabasesOfDumpOut, 1); -#ifdef WEBSOCKET - if (g_args.cloud || g_args.restful) { - ret = dumpStbAndChildTbOfDbWS(taos_v, dbInfo, fpDbs); - if (ret >= 0) { - ret = dumpNTablesOfDbWS(taos_v, dbInfo); - } - } else { -#endif - ret = dumpStbAndChildTbOfDbNative(taos_v, dbInfo, fpDbs); - if (ret >= 0) { - ret = dumpNTablesOfDbNative(taos_v, dbInfo); - } -#ifdef WEBSOCKET + ret = dumpStbAndChildTbOfDbNative(taos_v, dbInfo, fpDbs); + if (ret >= 0) { + ret = dumpNTablesOfDbNative(taos_v, dbInfo); } -#endif if (AVRO_CODEC_UNKNOWN != g_args.avro_codec) { fclose(fpDbs); } @@ -10638,41 +10053,19 @@ static int dumpOut() { /* Connect to server and dump extra info*/ void **taos_v = NULL; -#ifdef WEBSOCKET - WS_TAOS *ws_taos = NULL; - - if (g_args.cloud || g_args.restful) { - if (NULL == (ws_taos = wsConnect())) { - ret = -1; - goto _exit_failure; - } - - taos_v = &ws_taos; - ret = dumpExtraInfo(taos_v, fp); - - if (ret < 0) { - goto _exit_failure; - } - - dbCount = fillDbInfoWS(taos_v); - } else { -#endif - if (NULL == (taos = taosConnect(NULL))) { - ret = -1; - goto _exit_failure; - } - - taos_v = &taos; - ret = dumpExtraInfo(taos_v, fp); + if (NULL == (taos = taosConnect(NULL))) { + ret = -1; + goto _exit_failure; + } - if (ret < 0) { - goto _exit_failure; - } + taos_v = &taos; + ret = dumpExtraInfo(taos_v, fp); - dbCount = fillDbInfoNative(taos); -#ifdef WEBSOCKET + if (ret < 0) { + goto _exit_failure; } -#endif + + dbCount = fillDbInfoNative(taos); if (dbCount <= 0) { errorPrint("%d database(s) valid to dump\n", dbCount); @@ -10824,33 +10217,6 @@ static int dumpOut() { static int dumpEntry() { int ret = 0; -#ifdef WEBSOCKET - if ( g_args.debug_print) { - ws_enable_log("trace"); - printf("ws_enable_log(\"trace\");\n"); - } else { - ws_enable_log("error"); - printf("ws_enable_log(\"error\");\n"); - } - - if (NULL == g_args.dsn) { - g_args.dsn = getenv("TDENGINE_CLOUD_DSN"); - if (NULL == g_args.dsn) { - g_args.cloud = false; - } else { - g_args.cloud = true; - } - } else { - g_args.cloud = true; - } - - if (g_args.cloud) { - splitCloudDsn(); - } else if (g_args.restful) { - jointCloudDsn(); - } -#endif // WEBSOCKET - if (checkParam() < 0) { exit(EXIT_FAILURE); } @@ -11484,6 +10850,20 @@ static int inspectAvroFiles(int argc, char *argv[]) { return ret; } +int32_t setConnMode(int8_t connMode) { + // set conn mode + char * strMode = connMode == CONN_MODE_NATIVE ? STR_NATIVE : STR_WEBSOCKET; + int32_t code = taos_options(TSDB_OPTION_DRIVER, strMode); + if (code != TSDB_CODE_SUCCESS) { + engineError(INIT_PHASE, "taos_options", code); + return -1; + } + + infoPrint("\nConnect mode is : %s\n\n", strMode); + return 0; +} + + int main(int argc, char *argv[]) { g_uniqueID = getUniqueIDFromEpoch(); @@ -11495,12 +10875,13 @@ int main(int argc, char *argv[]) { parse_args(argc, argv, &g_args); } + // command line argp_parse(&argp, argc, argv, 0, 0, &g_args); - if (g_args.abort) { abort(); } + // client info snprintf(g_client_info, MIDDLE_BUFF_LEN, "%s", taos_get_client_info()); g_majorVersionOfClient = atoi(g_client_info); debugPrint("Client info: %s, major version: %d\n", @@ -11516,6 +10897,31 @@ int main(int argc, char *argv[]) { } } + // env dsn + if ( NULL == g_args.dsn) { + char *dsn = getenv("TDENGINE_CLOUD_DSN"); + if(dsn && dsn[0] != 0) { + if (g_args.connMode != CONN_MODE_NATIVE) { + g_args.dsn = dsn; + infoPrint("read dsn from evn dsn=%s\n", dsn); + } else { + warnPrint("command line pass native mode , ignore evn dsn:%s\n", dsn); + } + } + } else { + // check conflict + if (g_args.connMode == CONN_MODE_NATIVE) { + errorPrint("%s", DSN_NATIVE_CONFLICT); + return -1; + } + } + + // conn mode + if (setConnMode(g_args.connMode) != 0) { + return -1; + } + + // running if (g_args.inspect) { ret = inspectAvroFiles(argc, argv); } else { diff --git a/tools/taos-tools/src/wsdump.c b/tools/taos-tools/src/wsdump.c deleted file mode 100644 index 3ed0c461b984..000000000000 --- a/tools/taos-tools/src/wsdump.c +++ /dev/null @@ -1,1939 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the MIT license as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - */ - -#define _GNU_SOURCE - -#ifdef WEBSOCKET - -#include "dump.h" -#include "dumpUtil.h" - -int cleanIfQueryFailedWS(const char *funcname, int lineno, char *command, WS_RES *res) { - errorPrint("%s() LN%d, failed to run command <%s>. code: 0x%08x, reason: %s\n", funcname, lineno, command, - ws_errno(res), ws_errstr(res)); - ws_free_result(res); - free(command); - return -1; -} - -int getTableRecordInfoImplWS(char *dbName, char *table, TableRecordInfo *pTableRecordInfo, bool tryStable) { - WS_TAOS *ws_taos = NULL; - WS_RES *ws_res; - int32_t ws_code = -1; - - if (NULL == (ws_taos = wsConnect())) { - return -1; - } - memset(pTableRecordInfo, 0, sizeof(TableRecordInfo)); - - char *command = calloc(1, TSDB_MAX_ALLOWED_SQL_LEN); - if (NULL == command) { - errorPrint("%s() LN%d, memory allocation failed\n", __func__, __LINE__); - return -1; - } - - snprintf(command, TSDB_MAX_ALLOWED_SQL_LEN, g_args.db_escape_char ? "USE `%s`" : "USE %s", dbName); - ws_res = wsQuery(&ws_taos, command, &ws_code); - if (ws_code != 0) { - errorPrint("Invalid database %s, reason: %s\n", dbName, ws_errstr(ws_res)); - ws_free_result(ws_res); - ws_res = NULL; - free(command); - return 0; - } - ws_free_result(ws_res); - - if (3 == g_majorVersionOfClient) { - if (tryStable) { - snprintf(command, TSDB_MAX_ALLOWED_SQL_LEN, - "SELECT STABLE_NAME FROM information_schema.ins_stables " - "WHERE db_name='%s' AND stable_name='%s'", - dbName, table); - } else { - snprintf(command, TSDB_MAX_ALLOWED_SQL_LEN, - "SELECT TABLE_NAME,STABLE_NAME FROM " - "information_schema.ins_tables " - "WHERE db_name='%s' AND table_name='%s'", - dbName, table); - } - } else { - if (tryStable) { - snprintf(command, TSDB_MAX_ALLOWED_SQL_LEN, "SHOW STABLES LIKE \'%s\'", table); - } else { - snprintf(command, TSDB_MAX_ALLOWED_SQL_LEN, "SHOW TABLES LIKE \'%s\'", table); - } - } - - ws_res = wsQuery(&ws_taos, command, &ws_code); - - if (ws_code != 0) { - cleanIfQueryFailedWS(__func__, __LINE__, command, ws_res); - ws_close(ws_taos); - return -1; - } - - bool isSet = false; - - while (true) { - int rows = 0; - const void *data = NULL; - ws_code = ws_fetch_raw_block(ws_res, &data, &rows); - if (ws_code) { - errorPrint("%s() LN%d, ws_fetch_raw_block() error. reason: %s!\n", __func__, __LINE__, ws_errstr(ws_res)); - ws_free_result(ws_res); - ws_res = NULL; - ws_close(ws_taos); - ws_taos = NULL; - free(command); - return 0; - } - - if (0 == rows) { - break; - } - - uint8_t type; - uint32_t length; - char buffer[TSDB_TABLE_NAME_LEN] = {0}; - - for (int row = 0; row < rows; row++) { - const void *value0 = ws_get_value_in_block(ws_res, row, TSDB_SHOW_DB_NAME_INDEX, &type, &length); - if (NULL == value0) { - errorPrint( - "%s() LN%d, row: %d, col: %d, " - "ws_get_value_in_block() error!\n", - __func__, __LINE__, row, TSDB_SHOW_DB_NAME_INDEX); - continue; - } - - memset(buffer, 0, TSDB_TABLE_NAME_LEN); - memcpy(buffer, value0, length); - - if (0 == strcmp(buffer, table)) { - if (tryStable) { - pTableRecordInfo->isStb = true; - tstrncpy(pTableRecordInfo->tableRecord.stable, buffer, min(TSDB_TABLE_NAME_LEN, length + 1)); - isSet = true; - } else { - pTableRecordInfo->isStb = false; - tstrncpy(pTableRecordInfo->tableRecord.name, buffer, min(TSDB_TABLE_NAME_LEN, length + 1)); - const void *value1 = NULL; - if (3 == g_majorVersionOfClient) { - value1 = ws_get_value_in_block(ws_res, row, 1, &type, &length); - } else { - value1 = ws_get_value_in_block(ws_res, row, TSDB_SHOW_TABLES_METRIC_INDEX, &type, &length); - } - if (length) { - if (NULL == value1) { - errorPrint( - "%s() LN%d, row: %d, col: %d, " - "ws_get_value_in_block() error!\n", - __func__, __LINE__, row, TSDB_SHOW_TABLES_METRIC_INDEX); - break; - } - - pTableRecordInfo->belongStb = true; - memset(buffer, 0, TSDB_TABLE_NAME_LEN); - memcpy(buffer, value1, length); - tstrncpy(pTableRecordInfo->tableRecord.stable, buffer, min(TSDB_TABLE_NAME_LEN, length + 1)); - } else { - pTableRecordInfo->belongStb = false; - } - isSet = true; - break; - } - } - } - - if (isSet) { - break; - } - } - - ws_free_result(ws_res); - ws_res = NULL; - ws_close(ws_taos); - ws_taos = NULL; - - free(command); - - if (isSet) { - return 0; - } - return -1; -} - -int getTableRecordInfoWS(char *dbName, char *table, TableRecordInfo *pTableRecordInfo) { - if (0 == getTableRecordInfoImplWS(dbName, table, pTableRecordInfo, false)) { - return 0; - } else if (0 == getTableRecordInfoImplWS(dbName, table, pTableRecordInfo, true)) { - return 0; - } - - errorPrint("Invalid table/stable %s\n", table); - return -1; -} - -int getDbCountWS(WS_RES *ws_res) { - int count = 0; - int32_t code; - - while (true) { - int rows = 0; - const void *data = NULL; - code = ws_fetch_raw_block(ws_res, &data, &rows); - if (code) { - errorPrint("%s() LN%d, ws_fetch_raw_block() error. reason: %s!\n", __func__, __LINE__, ws_errstr(ws_res)); - return 0; - } - - if (0 == rows) { - break; - } - - uint8_t type; - uint32_t length; - char buffer[VALUE_BUF_LEN] = {0}; - - for (int row = 0; row < rows; row++) { - const void *value = ws_get_value_in_block(ws_res, row, TSDB_SHOW_DB_NAME_INDEX, &type, &length); - if (NULL == value) { - errorPrint( - "%s() LN%d, row: %d, " - "ws_get_value_in_block() error!\n", - __func__, __LINE__, row); - continue; - } - - memset(buffer, 0, VALUE_BUF_LEN); - memcpy(buffer, value, length); - debugPrint("%s() LN%d, dbname: %s\n", __func__, __LINE__, buffer); - - if (isSystemDatabase(buffer)) { - if (!g_args.allow_sys) { - continue; - } - } else if (g_args.databases) { // input multi dbs - if (inDatabasesSeq(buffer) != 0) { - continue; - } - } else if (!g_args.all_databases) { // only input one db - if (strcmp(g_args.arg_list[0], buffer)) { - continue; - } - } - count++; - } - } - - return count; -} - -int64_t getNtbCountOfStbWS(char *dbName, const char *stbName) { - WS_TAOS *ws_taos; - if (NULL == (ws_taos = wsConnect())) { - return -1; - } - - int64_t count = 0; - char *command = calloc(1, TSDB_MAX_ALLOWED_SQL_LEN); - if (NULL == command) { - errorPrint("%s() LN%d, memory allocation failed\n", __func__, __LINE__); - return -1; - } - if (3 == g_majorVersionOfClient) { - snprintf(command, TSDB_MAX_ALLOWED_SQL_LEN, - g_args.db_escape_char ? "SELECT COUNT(*) FROM (SELECT DISTINCT(TBNAME) " - "FROM `%s`.%s%s%s)" - : "SELECT COUNT(*) FROM (SELECT DISTINCT(TBNAME) " - "FROM %s.%s%s%s)", - dbName, g_escapeChar, stbName, g_escapeChar); - } else { - snprintf( - command, TSDB_MAX_ALLOWED_SQL_LEN, - g_args.db_escape_char ? "SELECT COUNT(TBNAME) FROM `%s`.%s%s%s" : "SELECT COUNT(TBNAME) FROM %s.%s%s%s", - dbName, g_escapeChar, stbName, g_escapeChar); - } - debugPrint("get stable child count %s", command); - - int32_t ws_code = -1; - WS_RES *ws_res = wsQuery(&ws_taos, command, &ws_code); - if (ws_code) { - return cleanIfQueryFailedWS(__func__, __LINE__, command, ws_res); - } - tfree(command); - - while (true) { - int rows = 0; - const void *data = NULL; - ws_code = ws_fetch_raw_block(ws_res, &data, &rows); - if (0 == rows) { - debugPrint( - "%s() LN%d, No more data from ws_fetch_raw_block(), " - "ws_taos: %p, code: 0x%08x, reason:%s\n", - __func__, __LINE__, ws_taos, ws_errno(ws_res), ws_errstr(ws_res)); - break; - } - - uint8_t type; - uint32_t len; - - for (int row = 0; row < rows; row++) { - const void *value = ws_get_value_in_block(ws_res, row, TSDB_SHOW_TABLES_NAME_INDEX, &type, &len); - if (0 == len) { - errorPrint( - "%s() LN%d, row: %d, col: %d, " - "ws_get_value_in_block() error!\n", - __func__, __LINE__, TSDB_DESCRIBE_METRIC_FIELD_INDEX, row); - continue; - } - count = *(int64_t *)value; - } - break; - } - debugPrint("%s() LN%d, COUNT(TBNAME): %" PRId64 "\n", __func__, __LINE__, count); - - ws_free_result(ws_res); - ws_close(ws_taos); - return count; -} - -int getTableTagValueWSV3(WS_TAOS **taos_v, const char *dbName, const char *table, TableDes **ppTableDes) { - TableDes *tableDes = *ppTableDes; - char *command = calloc(1, TSDB_MAX_ALLOWED_SQL_LEN); - if (NULL == command) { - errorPrint("%s() LN%d, memory allocation failed\n", __func__, __LINE__); - return -1; - } - - snprintf(command, TSDB_MAX_ALLOWED_SQL_LEN, - "SELECT tag_name,tag_value FROM information_schema.ins_tags " - "WHERE db_name = '%s' AND table_name = '%s'", - dbName, table); - - int32_t ws_code = -1; - WS_RES *ws_res = wsQuery(taos_v, command, &ws_code); - if (ws_code) { - return cleanIfQueryFailedWS(__func__, __LINE__, command, ws_res); - } - - while (true) { - int rows = 0; - const void *data = NULL; - ws_code = ws_fetch_raw_block(ws_res, &data, &rows); - - if (ws_code) { - errorPrint( - "%s() LN%d, ws_fetch_raw_block() error, " - "code: 0x%08x, command: %s, reason: %s\n", - __func__, __LINE__, ws_code, command, ws_errstr(ws_res)); - } - if (0 == rows) { - debugPrint( - "%s() LN%d, No more data from fetch to run " - "command <%s>, " - "ws_taos: %p, code: 0x%08x, reason:%s\n", - __func__, __LINE__, command, taos_v, ws_errno(ws_res), ws_errstr(ws_res)); - break; - } - - uint8_t type; - uint32_t len; - int index = tableDes->columns; - - for (int row = 0; row < rows; row++) { - const void *value1 = ws_get_value_in_block(ws_res, row, 1, &type, &len); - - debugPrint("%s() LN%d, len=%d\n", __func__, __LINE__, len); - - if (NULL == value1) { - strcpy(tableDes->cols[index].value, "NULL"); - strcpy(tableDes->cols[index].note, "NUL"); - } else if (0 != processFieldsValueV3(index, tableDes, value1, len)) { - errorPrint("%s() LN%d, processFieldsValueV3 tag_value: %p\n", __func__, __LINE__, value1); - ws_free_result(ws_res); - free(command); - return -1; - } - index++; - } - } - - ws_free_result(ws_res); - free(command); - - return (tableDes->columns + tableDes->tags); -} - -int getTableTagValueWSV2(WS_TAOS **taos_v, const char *dbName, const char *table, TableDes **ppTableDes) { - TableDes *tableDes = *ppTableDes; - char *command = calloc(1, TSDB_MAX_ALLOWED_SQL_LEN); - if (NULL == command) { - errorPrint("%s() LN%d, memory allocation failed\n", __func__, __LINE__); - return -1; - } - char *sqlstr = command; - - sqlstr += snprintf(sqlstr, TSDB_MAX_ALLOWED_SQL_LEN, "SELECT %s%s%s", g_escapeChar, - tableDes->cols[tableDes->columns].field, g_escapeChar); - for (int i = tableDes->columns + 1; i < (tableDes->columns + tableDes->tags); i++) { - sqlstr += sprintf(sqlstr, ",%s%s%s ", g_escapeChar, tableDes->cols[i].field, g_escapeChar); - } - sqlstr += sprintf(sqlstr, g_args.db_escape_char ? " FROM `%s`.%s%s%s LIMIT 1" : " FROM %s.%s%s%s LIMIT 1", dbName, - g_escapeChar, table, g_escapeChar); - - int32_t ws_code = -1; - int32_t retryCount = 0; - WS_RES *ws_res = NULL; - - RETRY_QUERY: - ws_res = wsQuery(taos_v, command, &ws_code); - if (ws_code) { - return cleanIfQueryFailedWS(__func__, __LINE__, command, ws_res); - } - - while (true) { - int rows = 0; - const void *data = NULL; - ws_code = wsFetchBlock(ws_res, &data, &rows); - - if (ws_code) { - // output error - errorPrint( - "%s() LN%d, getTableTagValueWSV2-> wsFetchBlock() error, " - "code: 0x%08x, sqlstr: %s, reason: %s\n", - __func__, __LINE__, ws_code, sqlstr, ws_errstr(ws_res)); - - // check can retry - if(canRetry(ws_code, RETRY_TYPE_FETCH) && ++retryCount <= g_args.retryCount) { - infoPrint("wsFetchBlock failed, goto wsQuery to retry %d\n", retryCount); - ws_free_result(ws_res); - ws_res = NULL; - toolsMsleep(g_args.retrySleepMs); - goto RETRY_QUERY; - } - - // error break while - break; - } - if (0 == rows) { - debugPrint( - "%s() LN%d, No more data from fetch to run " - "command <%s>, " - "ws_taos: %p, code: 0x%08x, reason:%s\n", - __func__, __LINE__, sqlstr, *taos_v, ws_errno(ws_res), ws_errstr(ws_res)); - break; - } - - uint8_t type; - uint32_t len; - for (int row = 0; row < rows; row++) { - for (int j = tableDes->columns; j < (tableDes->columns + tableDes->tags); j++) { - const void *value = ws_get_value_in_block(ws_res, row, j - tableDes->columns, &type, &len); - - debugPrint("%s() LN%d, len=%d\n", __func__, __LINE__, len); - - if (NULL == value) { - strcpy(tableDes->cols[j].value, "NULL"); - strcpy(tableDes->cols[j].note, "NUL"); - } else if (0 != processFieldsValueV2(j, tableDes, value, len)) { - errorPrint("%s() LN%d, processFieldsValueV2 value0: %p\n", __func__, __LINE__, value); - ws_free_result(ws_res); - free(command); - return -1; - } - } - } - } - - ws_free_result(ws_res); - free(command); - - return (tableDes->columns + tableDes->tags); -} - -int getTableTagValueWS(void **taos_v, const char *dbName, const char *table, TableDes **ppTableDes) { - int ret = -1; - if (3 == g_majorVersionOfClient) { - // if child-table have tag, V3 using select tag_value - // from information_schema.ins_tag where table to get tagValue - ret = getTableTagValueWSV2(taos_v, dbName, table, ppTableDes); - if (ret < 0) { - ret = getTableTagValueWSV3(taos_v, dbName, table, ppTableDes); - } - } else if (2 == g_majorVersionOfClient) { - // if child-table have tag, - // using select tagName from table to get tagValue - ret = getTableTagValueWSV2(taos_v, dbName, table, ppTableDes); - } else { - errorPrint("%s() LN%d, major version %d is not supported\n", __func__, __LINE__, g_majorVersionOfClient); - } - - return ret; -} - -int getTableDesFromStbWS(WS_TAOS **taos_v, const char *dbName, const TableDes *stbTableDes, const char *table, - TableDes **ppTableDes) { - constructTableDesFromStb(stbTableDes, table, ppTableDes); - return getTableTagValueWS(taos_v, dbName, table, ppTableDes); -} - -int getTableDesWS(WS_TAOS **taos_v, const char *dbName, const char *table, TableDes *tableDes, const bool colOnly) { - int colCount = 0; - char *command = calloc(1, TSDB_MAX_ALLOWED_SQL_LEN); - if (NULL == command) { - errorPrint("%s() LN%d, memory allocation failed\n", __func__, __LINE__); - return -1; - } - - snprintf(command, TSDB_MAX_ALLOWED_SQL_LEN, g_args.db_escape_char ? "DESCRIBE `%s`.%s%s%s" : "DESCRIBE %s.%s%s%s", - dbName, g_escapeChar, table, g_escapeChar); - - int32_t ws_code = -1; - WS_RES *ws_res = wsQuery(taos_v, command, &ws_code); - if (ws_code) { - return cleanIfQueryFailedWS(__func__, __LINE__, command, ws_res); - } else { - debugPrint("%s() LN%d, run command <%s> success, ws_taos: %p\n", __func__, __LINE__, command, *taos_v); - } - - tstrncpy(tableDes->name, table, TSDB_TABLE_NAME_LEN); - while (true) { - int rows = 0; - const void *data = NULL; - ws_code = ws_fetch_raw_block(ws_res, &data, &rows); - if (0 == rows) { - debugPrint( - "%s() LN%d, No more data from ws_fetch_raw_block(), " - "ws_taos: %p, code: 0x%08x, reason:%s\n", - __func__, __LINE__, *taos_v, ws_errno(ws_res), ws_errstr(ws_res)); - break; - } - - uint8_t type; - uint32_t len; - char buffer[VALUE_BUF_LEN] = {0}; - const void *value = NULL; - - for (int row = 0; row < rows; row++) { - value = ws_get_value_in_block(ws_res, row, TSDB_DESCRIBE_METRIC_FIELD_INDEX, &type, &len); - if (NULL == value) { - errorPrint( - "%s() LN%d, row: %d, col: %d, " - "ws_get_value_in_block() error!\n", - __func__, __LINE__, TSDB_DESCRIBE_METRIC_FIELD_INDEX, row); - continue; - } - memset(buffer, 0, VALUE_BUF_LEN); - memcpy(buffer, value, len); - strncpy(tableDes->cols[colCount].field, buffer, len); - - value = ws_get_value_in_block(ws_res, row, TSDB_DESCRIBE_METRIC_TYPE_INDEX, &type, &len); - if (NULL == value) { - errorPrint( - "%s() LN%d, row: %d, col: %d, " - "ws_get_value_in_block() error!\n", - __func__, __LINE__, TSDB_DESCRIBE_METRIC_TYPE_INDEX, row); - continue; - } - memset(buffer, 0, VALUE_BUF_LEN); - memcpy(buffer, value, len); - tableDes->cols[colCount].type = typeStrToType(buffer); - - value = ws_get_value_in_block(ws_res, row, TSDB_DESCRIBE_METRIC_LENGTH_INDEX, &type, &len); - if (NULL == value) { - errorPrint("row: %d, col: %d, ws_get_value_in_block() error!\n", TSDB_DESCRIBE_METRIC_LENGTH_INDEX, - row); - continue; - } - tableDes->cols[colCount].length = *((int *)value); - - value = ws_get_value_in_block(ws_res, row, TSDB_DESCRIBE_METRIC_NOTE_INDEX, &type, &len); - if (NULL == value) { - errorPrint("row: %d, col: %d, ws_get_value_in_block() error!\n", TSDB_DESCRIBE_METRIC_NOTE_INDEX, row); - continue; - } - memset(buffer, 0, VALUE_BUF_LEN); - memcpy(buffer, value, len); - - debugPrint("%s() LN%d, buffer: %s\n", __func__, __LINE__, buffer); - - strncpy(tableDes->cols[colCount].note, buffer, len); - if (strcmp(tableDes->cols[colCount].note, "TAG") != 0) { - tableDes->columns++; - } else { - tableDes->tags++; - } - colCount++; - } - } - - ws_free_result(ws_res); - ws_res = NULL; - free(command); - - if (colOnly) { - return colCount; - } - - return getTableTagValueWS(taos_v, dbName, table, &tableDes); -} - -int64_t queryDbForDumpOutCountWS(char *command, WS_TAOS **taos_v, const char *dbName, const char *tbName, - const int precision) { - int64_t count = -1; - int32_t ws_code = -1; - WS_RES *ws_res = wsQuery(taos_v, command, &ws_code); - if (ws_code != 0) { - return cleanIfQueryFailedWS(__func__, __LINE__, command, ws_res); - } - - while (true) { - int rows = 0; - const void *data = NULL; - ws_code = ws_fetch_raw_block(ws_res, &data, &rows); - if (0 == rows) { - debugPrint( - "%s() LN%d, No more data from ws_fetch_raw_block(), " - "ws_taos: %p, code: 0x%08x, reason:%s\n", - __func__, __LINE__, *taos_v, ws_errno(ws_res), ws_errstr(ws_res)); - break; - } - - uint8_t type; - uint32_t len; - - for (int row = 0; row < rows; row++) { - const void *value0 = ws_get_value_in_block(ws_res, row, TSDB_SHOW_TABLES_NAME_INDEX, &type, &len); - if (NULL == value0) { - if (0 == ws_errno(ws_res)) { - count = 0; - debugPrint("%s fetch row, count: %" PRId64 "\n", command, count); - } else { - count = -1; - errorPrint( - "failed run %s to fetch row, ws_taos: %p, " - "code: 0x%08x, reason: %s\n", - command, *taos_v, ws_errno(ws_res), ws_errstr(ws_res)); - } - } else { - count = *(int64_t *)value0; - debugPrint("%s fetch row, count: %" PRId64 "\n", command, count); - break; - } - } - } - - ws_free_result(ws_res); - free(command); - return count; -} - -TAOS_RES *queryDbForDumpOutOffsetWS(WS_TAOS **taos_v, char *command) { - int32_t ws_code = -1; - WS_RES *ws_res = wsQuery(taos_v, command, &ws_code); - if (ws_code) { - cleanIfQueryFailedWS(__func__, __LINE__, command, ws_res); - return NULL; - } - free(command); - return ws_res; -} - -int64_t writeResultToAvroWS(const char *avroFilename, const char *dbName, const char *tbName, char *jsonSchema, - WS_TAOS **taos_v, int precision, int64_t start_time, int64_t end_time) { - int64_t queryCount = queryDbForDumpOutCount(taos_v, dbName, tbName, precision); - if (queryCount <= 0) { - return 0; - } - - avro_schema_t schema; - RecordSchema *recordSchema; - avro_file_writer_t db; - - avro_value_iface_t *wface = prepareAvroWface(avroFilename, jsonSchema, &schema, &recordSchema, &db); - - int64_t success = 0; - int64_t failed = 0; - - bool printDot = true; - - int currentPercent = 0; - int percentComplete = 0; - - int64_t limit = g_args.data_batch; - int64_t offset = 0; - - do { - if (queryCount > limit) { - if (limit < (queryCount - offset)) { - limit = queryCount - offset; - } - } else { - limit = queryCount; - } - - WS_RES *ws_res = NULL; - int numFields = 0; - void *ws_fields = NULL; - int32_t countInBatch = 0; - int32_t retryCount = 0; - -RETRY_QUERY: - countInBatch = 0; - ws_res = queryDbForDumpOutOffset(taos_v, dbName, tbName, precision, start_time, end_time, limit, offset); - if (NULL == ws_res) { - break; - } - - numFields = ws_field_count(ws_res); - if (3 == g_majorVersionOfClient) { - const struct WS_FIELD *ws_fields_v3 = ws_fetch_fields(ws_res); - ws_fields = (void *)ws_fields_v3; - } else { - const struct WS_FIELD_V2 *ws_fields_v2 = ws_fetch_fields_v2(ws_res); - ws_fields = (void *)ws_fields_v2; - } - - while (true) { - int rows = 0; - const void *data = NULL; - int32_t ws_code = wsFetchBlock(ws_res, &data, &rows); - - if (ws_code) { - errorPrint( - "%s() LN%d, writeResultToAvroWS->wsFetchBlock() error, ws_taos: %p, " - "code: 0x%08x, reason: %s\n", - __func__, __LINE__, *taos_v, ws_code, ws_errstr(ws_res)); - - // check can retry - if(canRetry(ws_code, RETRY_TYPE_FETCH) && ++retryCount <= g_args.retryCount) { - infoPrint("wsFetchBlock failed, goto wsQuery to retry %d limit=%"PRId64" offset=%"PRId64" queryCount=%"PRId64" \n", - retryCount, limit, offset, queryCount); - // need close old res - ws_free_result(ws_res); - ws_res = NULL; - toolsMsleep(g_args.retrySleepMs); - goto RETRY_QUERY; - } - - // break - break; - } - - if (0 == rows) { - debugPrint( - "%s() LN%d, No more data from wsFetchBlock(), " - "ws_taos: %p, code: 0x%08x, reason:%s\n", - __func__, __LINE__, *taos_v, ws_errno(ws_res), ws_errstr(ws_res)); - break; - } - - for (int row = 0; row < rows; row++) { - avro_value_t record; - avro_generic_value_new(wface, &record); - - avro_value_t avro_value, branch; - - if (!g_args.loose_mode) { - if (0 != avro_value_get_by_name(&record, "tbname", &avro_value, NULL)) { - errorPrint( - "%s() LN%d, avro_value_get_by_name(tbname) " - "failed\n", - __func__, __LINE__); - break; - } - avro_value_set_branch(&avro_value, 1, &branch); - avro_value_set_string(&branch, tbName); - } - - for (int32_t f = 0; f < numFields; f++) { - uint8_t type; - uint32_t len; - - const void *value = ws_get_value_in_block(ws_res, row, f, &type, &len); - - if (3 == g_majorVersionOfClient) { - struct WS_FIELD *ws_fields_3 = (struct WS_FIELD *)ws_fields; - processValueToAvro(f, record, avro_value, branch, ws_fields_3[f].name, ws_fields_3[f].type, - ws_fields_3[f].bytes, value, len); - } else { - struct WS_FIELD_V2 *ws_fields_2 = (struct WS_FIELD_V2 *)ws_fields; - processValueToAvro(f, record, avro_value, branch, ws_fields_2[f].name, ws_fields_2[f].type, - ws_fields_2[f].bytes, value, len); - } - } - - if (0 != avro_file_writer_append_value(db, &record)) { - errorPrint( - "%s() LN%d, " - "Unable to write record to file. Message: %s\n", - __func__, __LINE__, avro_strerror()); - failed--; - } else { - success++; - } - - countInBatch++; - avro_value_decref(&record); - } - } - - if (countInBatch != limit) { - errorPrint("%s() LN%d, actual dump out: %d, batch %" PRId64 "\n", __func__, __LINE__, countInBatch, limit); - } - ws_free_result(ws_res); - ws_res = NULL; - printDotOrX(offset, &printDot); - offset += limit; - - currentPercent = ((offset) * 100 / queryCount); - if (currentPercent > percentComplete) { - // infoPrint("%d%% of %s\n", currentPercent, tbName); - percentComplete = currentPercent; - } - } while (offset < queryCount); - - if (percentComplete < 100) { - errorPrint("%d%% of %s\n", percentComplete, tbName); - } - - avro_value_iface_decref(wface); - freeRecordSchema(recordSchema); - avro_file_writer_close(db); - avro_schema_decref(schema); - - return success; -} - -int64_t writeResultDebugWS(WS_RES *ws_res, FILE *fp, const char *dbName, const char *tbName) { - int64_t totalRows = 0; - - int32_t sql_buf_len = g_args.max_sql_len; - char *tmpBuffer = (char *)calloc(1, sql_buf_len + 128); - if (NULL == tmpBuffer) { - errorPrint("%s() LN%d, memory allocation failed!\n", __func__, __LINE__); - return 0; - } - - char *pstr = tmpBuffer; - - int64_t lastRowsPrint = 5000000; - int count = 0; - - int fieldCount = ws_field_count(ws_res); - ASSERT(fieldCount > 0); - - void *ws_fields = NULL; - if (3 == g_majorVersionOfClient) { - const struct WS_FIELD *ws_fields_v3 = ws_fetch_fields(ws_res); - ws_fields = (void *)ws_fields_v3; - } else { - const struct WS_FIELD_V2 *ws_fields_v2 = ws_fetch_fields_v2(ws_res); - ws_fields = (void *)ws_fields_v2; - } - - int32_t total_sqlstr_len = 0; - - while (true) { - int rows = 0; - const void *data = NULL; - int32_t ws_code = ws_fetch_raw_block(ws_res, &data, &rows); - - if (ws_code) { - errorPrint( - "%s() LN%d, ws_fetch_raw_block() error!" - " code: 0x%08x, reason: %s\n", - __func__, __LINE__, ws_code, ws_errstr(ws_res)); - break; - } - if (0 == rows) { - debugPrint( - "%s() LN%d, No more data from ws_fetch_raw_block(), " - "code: 0x%08x, reason:%s\n", - __func__, __LINE__, ws_errno(ws_res), ws_errstr(ws_res)); - break; - } - - for (int row = 0; row < rows; row++) { - int32_t curr_sqlstr_len = 0; - - if (count == 0) { - total_sqlstr_len = 0; - curr_sqlstr_len += sprintf(pstr + curr_sqlstr_len, "INSERT INTO %s.%s VALUES (", dbName, tbName); - } else { - curr_sqlstr_len += sprintf(pstr + curr_sqlstr_len, "("); - } - - for (int f = 0; f < fieldCount; f++) { - if (f != 0) { - curr_sqlstr_len += sprintf(pstr + curr_sqlstr_len, ", "); - } - uint8_t type; - uint32_t len; - - const void *value = ws_get_value_in_block(ws_res, row, f, &type, &len); - if (NULL == value) { - errorPrint("row: %d, ws_get_value_in_block() error!\n", row); - continue; - } - - if (3 == g_majorVersionOfClient) { - struct WS_FIELD *ws_fields_3 = (struct WS_FIELD *)ws_fields; - curr_sqlstr_len += processResultValue(pstr, curr_sqlstr_len, ws_fields_3[f].type, value, len); - } else { - struct WS_FIELD_V2 *ws_fields_2 = (struct WS_FIELD_V2 *)ws_fields; - curr_sqlstr_len += processResultValue(pstr, curr_sqlstr_len, ws_fields_2[f].type, value, len); - } - } - curr_sqlstr_len += sprintf(pstr + curr_sqlstr_len, ")"); - - totalRows++; - count++; - fprintf(fp, "%s", tmpBuffer); - - if (totalRows >= lastRowsPrint) { - infoPrint(" %" PRId64 " rows already be dump-out from %s.%s\n", totalRows, dbName, tbName); - lastRowsPrint += 5000000; - } - - total_sqlstr_len += curr_sqlstr_len; - - if ((count >= g_args.data_batch) || (sql_buf_len - total_sqlstr_len < TSDB_MAX_BYTES_PER_ROW)) { - fprintf(fp, ";\n"); - count = 0; - } - } - } - - debugPrint("total_sqlstr_len: %d\n", total_sqlstr_len); - - fprintf(fp, "\n"); - free(tmpBuffer); - - return totalRows; -} - -WS_RES *queryDbForDumpOutWS(WS_TAOS **taos_v, const char *dbName, const char *tbName, const int precision, - const int64_t start_time, const int64_t end_time) { - char *command = calloc(1, TSDB_MAX_ALLOWED_SQL_LEN); - if (NULL == command) { - errorPrint("%s() LN%d, memory allocation failed\n", __func__, __LINE__); - return NULL; - } - - snprintf(command, TSDB_MAX_ALLOWED_SQL_LEN, - g_args.db_escape_char ? "SELECT * FROM `%s`.%s%s%s WHERE _c0 >= %" PRId64 - " " - "AND _c0 <= %" PRId64 " ORDER BY _c0 ASC;" - : "SELECT * FROM %s.%s%s%s WHERE _c0 >= %" PRId64 - " " - "AND _c0 <= %" PRId64 " ORDER BY _c0 ASC;", - dbName, g_escapeChar, tbName, g_escapeChar, start_time, end_time); - - int32_t ws_code = -1; - WS_RES *ws_res = wsQuery(taos_v, command, &ws_code); - if (ws_code != 0) { - cleanIfQueryFailedWS(__func__, __LINE__, command, ws_res); - return NULL; - } - - free(command); - return ws_res; -} - -int64_t dumpTableDataAvroWS(char *dataFilename, int64_t index, const char *tbName, const bool belongStb, - const char *dbName, const int precision, int colCount, TableDes *tableDes, - int64_t start_time, int64_t end_time) { - WS_TAOS *ws_taos; - if (NULL == (ws_taos = wsConnect())) { - return -1; - } - - char *jsonSchema = NULL; - if (0 != convertTbDesToJsonWrap(dbName, tbName, tableDes, colCount, &jsonSchema)) { - errorPrint("%s() LN%d, convertTbDesToJsonWrap failed\n", __func__, __LINE__); - ws_close(ws_taos); - return -1; - } - - int64_t totalRows = - writeResultToAvroWS(dataFilename, dbName, tbName, jsonSchema, &ws_taos, precision, start_time, end_time); - - ws_close(ws_taos); - ws_taos = NULL; - tfree(jsonSchema); - - return totalRows; -} - -int64_t fillTbNameArrWS(WS_TAOS **taos_v, char *command, char **tbNameArr, const char *stable, const int64_t preCount) { - int32_t ws_code = -1; - WS_RES *ws_res = wsQuery(taos_v, command, &ws_code); - if (ws_code) { - return cleanIfQueryFailedWS(__func__, __LINE__, command, ws_res); - } - - int currentPercent = 0; - int percentComplete = 0; - - int64_t ntbCount = 0; - while (true) { - int rows = 0; - const void *data = NULL; - ws_code = ws_fetch_raw_block(ws_res, &data, &rows); - - if (0 == rows) { - debugPrint( - "%s() LN%d, No more data from ws_fetch_raw_block(), " - "ws_taos: %p, code: 0x%08x, reason:%s\n", - __func__, __LINE__, *taos_v, ws_errno(ws_res), ws_errstr(ws_res)); - break; - } - - uint8_t type; - uint32_t len; - - for (int row = 0; row < rows; row++) { - const void *value0 = ws_get_value_in_block(ws_res, row, TSDB_SHOW_TABLES_NAME_INDEX, &type, &len); - if (NULL == value0) { - errorPrint( - "%s() LN%d, ws_get_value_in_blocK() return NULL." - " code: 0x%08x, reason: %s!\n", - __func__, __LINE__, ws_errno(ws_res), ws_errstr(ws_res)); - continue; - } else { - debugPrint("%s() LN%d, ws_get_value_in_blocK() return %s. len: %d\n", __func__, __LINE__, - (char *)value0, len); - } - - tbNameArr[ntbCount] = calloc(len + 1, 1); - strncpy(tbNameArr[ntbCount], (char *)value0, len); - - debugPrint("%s() LN%d, sub table name: %s %" PRId64 " of stable: %s\n", __func__, __LINE__, - tbNameArr[ntbCount], ntbCount, stable); - ++ntbCount; - - currentPercent = (ntbCount * 100 / preCount); - - if (currentPercent > percentComplete) { - infoPrint("connection %p fetched %d%% of %s' tbname\n", *taos_v, currentPercent, stable); - percentComplete = currentPercent; - } - } - } - - if ((preCount > 0) && (percentComplete < 100)) { - errorPrint("%d%% - total %" PRId64 " sub-table's names of stable: %s fetched\n", percentComplete, ntbCount, - stable); - } else { - okPrint("total %" PRId64 " sub-table's name of stable: %s fetched\n", ntbCount, stable); - } - - ws_free_result(ws_res); - free(command); - return ntbCount; -} - -int readNextTableDesWS(void* ws_res, TableDes* tbDes, int *idx, int *cnt) { - // tbname, tagName , tagValue - int index = 0; - uint8_t type = 0; - uint32_t len = 0; - while( index < tbDes->tags) { - // get block - if(*idx >= *cnt || *cnt == 0) { - const void *data = NULL; - int ws_code = ws_fetch_raw_block(ws_res, &data, cnt); - if (ws_code !=0 ) { - // read to end - errorPrint("read next ws_fetch_raw_block failed, err code=%d idx=%d index=%d\n", ws_code, *idx, index); - return -1; - } - - if(*cnt == 0) { - infoPrint("read schema over. tag columns %d.\n", tbDes->tags); - break; - } - *idx = 0; - } - - // read first column tbname - const void *val = ws_get_value_in_block(ws_res, *idx, 0, &type, &len); - if(val == NULL) { - errorPrint("read tbname failed, idx=%d cnt=%d \n", *idx, *cnt); - return -1; - } - - // tbname changed check - if(tbDes->name[0] == 0) { - // first set tbName - strncpy(tbDes->name, val, len); - } else { - // compare tbname change - if(!(strncmp(tbDes->name, val, len) == 0 - && tbDes->name[len] == 0)) { - // tbname cnanged, break - break; - } - } - - // read third column tagvalue - val = ws_get_value_in_block(ws_res, *idx, 2, &type, &len); - // copy tagvalue - if (NULL == val) { - strcpy(tbDes->cols[index].value, "NULL"); - strcpy(tbDes->cols[index].note , "NUL"); - } else if (0 != processFieldsValueV3(index, tbDes, val, len)) { - errorPrint("%s() LN%d, call processFieldsValueV3 tag_value: %p\n", - __func__, __LINE__, val); - return -1; - } - - // move next row - *idx = *idx + 1; - // counter ++ - index++; - } - - // check tags count corrent - if(*cnt && index != tbDes->tags) { - errorPrint("child table %s read tags(%d) not equal stable tags (%d).\n", - tbDes->name, index, tbDes->tags); - return -1; - } - - return index; -} - -// read specail line, col -int32_t readRowWS(void *res, int32_t idx, int32_t col, uint32_t *len, char **data) { - int32_t i = 0; - while (i <= idx) { - // fetch block - const void *block = NULL; - int32_t cnt = 0; - int ws_code = ws_fetch_raw_block(res, &block, &cnt); - if (ws_code != 0) { - errorPrint("readRow->ws_fetch_raw_block failed, err code=%d i=%d\n", ws_code, i); - return -1; - } - - // cnt check - if (cnt == 0) { - infoPrint("ws_fetch_raw_block read cnt zero. i=%d.\n", i); - return -1; - } - - // check idx - if (i + cnt <= idx) { - // move next block - i += cnt; - continue; - } - - // set - uint8_t type = 0; - const void *val = ws_get_value_in_block(res, idx, col, &type, len); - if (val == NULL) { - errorPrint("readRow ws_get_value_in_block failed, cnt=%d idx=%d col=%d \n", cnt, idx, col); - return -1; - } - *data = (char *)val; - break; - } - - return 0; -} - -void dumpExtraInfoVarWS(void **taos_v, FILE *fp) { - char buffer[BUFFER_LEN]; - char *command = calloc(1, TSDB_MAX_ALLOWED_SQL_LEN); - if (NULL == command) { - errorPrint("%s() LN%d, memory allocation failed\n", __func__, __LINE__); - return; - } - strcpy(command, "SHOW VARIABLES"); - - int32_t ws_code = -1; - WS_RES *ws_res = wsQuery(taos_v, command, &ws_code); - - if (0 != ws_code) { - warnPrint( - "%s() LN%d, failed to run command %s, " - "code: 0x%08x, reason: %s. Will use default settings\n", - __func__, __LINE__, command, ws_code, ws_errstr(ws_res)); - fprintf(g_fpOfResult, - "# SHOW VARIABLES failed, " - "code: 0x%08x, reason:%s\n", - ws_errno(ws_res), ws_errstr(ws_res)); - snprintf(buffer, BUFFER_LEN, "#!charset: %s\n", "UTF-8"); - size_t len = fwrite(buffer, 1, strlen(buffer), fp); - if (len != strlen(buffer)) { - errorPrint( - "%s() LN%d, write to file. " - "try to write %zu, actual len %zu, " - "Errno is %d. Reason is %s.\n", - __func__, __LINE__, strlen(buffer), len, errno, strerror(errno)); - } - ws_free_result(ws_res); - ws_res = NULL; - free(command); - return; - } - - while (true) { - int rows = 0; - const void *data = NULL; - ws_code = ws_fetch_raw_block(ws_res, &data, &rows); - - if (0 == rows) { - debugPrint( - "%s() LN%d, No more data from ws_fetch_raw_block(), " - "ws_taos: %p, code: 0x%08x, reason:%s\n", - __func__, __LINE__, *taos_v, ws_errno(ws_res), ws_errstr(ws_res)); - break; - } - - uint8_t type; - uint32_t len; - char tmp[BUFFER_LEN - 12] = {0}; - - for (int row = 0; row < rows; row++) { - const void *value0 = ws_get_value_in_block(ws_res, row, 0, &type, &len); - memset(tmp, 0, BUFFER_LEN - 12); - memcpy(tmp, value0, len); - - verbosePrint("%s() LN%d, value0: %s\n", __func__, __LINE__, tmp); - if (0 == strcmp(tmp, "charset")) { - const void *value1 = ws_get_value_in_block(ws_res, row, 1, &type, &len); - memset(tmp, 0, BUFFER_LEN - 12); - memcpy(tmp, value1, min(BUFFER_LEN - 13, len)); - snprintf(buffer, BUFFER_LEN, "#!charset: %s\n", tmp); - debugPrint("%s() LN%d buffer: %s\n", __func__, __LINE__, buffer); - size_t w_len = fwrite(buffer, 1, strlen(buffer), fp); - if (w_len != strlen(buffer)) { - errorPrint( - "%s() LN%d, write to file. " - "try to write %zu, actual len %zu, " - "Errno is %d. Reason is %s.\n", - __func__, __LINE__, strlen(buffer), w_len, errno, strerror(errno)); - } - } - } - } - - ws_free_result(ws_res); - ws_res = NULL; - free(command); -} - -int queryDbImplWS(WS_TAOS **taos_v, char *command) { - int ret = 0; - WS_RES *ws_res = NULL; - int32_t ws_code = -1; - - ws_res = wsQuery(taos_v, command, &ws_code); - - if (ws_code) { - errorPrint( - "Failed to run <%s>, ws_taos: %p, " - "code: 0x%08x, reason: %s\n", - command, *taos_v, ws_code, ws_errstr(ws_res)); - ret = -1; - ; - } - - ws_free_result(ws_res); - ws_res = NULL; - return ret; -} - -void dumpNormalTablesOfStbWS(threadInfo *pThreadInfo, FILE *fp, char *dumpFilename) { - for (int64_t i = pThreadInfo->from; i < (pThreadInfo->from + pThreadInfo->count); i++) { - char *tbName = pThreadInfo->tbNameArr[i]; - debugPrint("%s() LN%d, [%d] sub table %" PRId64 ": name: %s\n", __func__, __LINE__, pThreadInfo->threadIndex, i, - tbName); - - int64_t count; - if (g_args.avro) { - count = dumpNormalTable(i, &pThreadInfo->taos, pThreadInfo->dbInfo, true, pThreadInfo->stbName, - pThreadInfo->stbDes, tbName, pThreadInfo->precision, dumpFilename, NULL); - } else { - count = dumpNormalTable(i, &pThreadInfo->taos, pThreadInfo->dbInfo, true, pThreadInfo->stbName, - pThreadInfo->stbDes, tbName, pThreadInfo->precision, NULL, fp); - } - - // show progress - atomic_add_fetch_64(&g_tableDone, 1); - infoPrint("%s.%s %" PRId64 "/%" PRId64 " %s dump data ok.\n", g_dbName, g_stbName, g_tableDone, g_tableCount, - tbName); - if (count < 0) { - break; - } else { - atomic_add_fetch_64(&g_totalDumpOutRows, count); - } - } - - return; -} - -int64_t dumpStbAndChildTbOfDbWS(WS_TAOS **taos_v, SDbInfo *dbInfo, FILE *fpDbs) { - int64_t ret = 0; - - // - // obtain need dump all stable name - // - char *command = calloc(1, TSDB_MAX_ALLOWED_SQL_LEN); - if (NULL == command) { - errorPrint("%s() LN%d, memory allocation failed\n", __func__, __LINE__); - return -1; - } - - snprintf(command, TSDB_MAX_ALLOWED_SQL_LEN, g_args.db_escape_char ? "USE `%s`" : "USE %s", dbInfo->name); - WS_RES *ws_res; - int32_t ws_code = -1; - - ws_res = wsQuery(taos_v, command, &ws_code); - if (ws_code != 0) { - errorPrint("Invalid database %s, reason: %s\n", dbInfo->name, ws_errstr(ws_res)); - ws_free_result(ws_res); - free(command); - return -1; - } - - if (3 == g_majorVersionOfClient) { - snprintf(command, TSDB_MAX_ALLOWED_SQL_LEN, - "SELECT STABLE_NAME FROM information_schema.ins_stables " - "WHERE db_name='%s'", - dbInfo->name); - } else { - snprintf(command, TSDB_MAX_ALLOWED_SQL_LEN, "SHOW STABLES"); - } - - ws_res = wsQuery(taos_v, command, &ws_code); - - if (ws_code) { - return cleanIfQueryFailedWS(__func__, __LINE__, command, ws_res); - } - - // link - SNode* head = NULL; - SNode* end = NULL; - - while (true) { - int rows = 0; - const void *data = NULL; - ws_code = ws_fetch_raw_block(ws_res, &data, &rows); - - if (0 == rows) { - debugPrint( - "%s() LN%d, No more data from ws_fetch_raw_block(), " - "ws_taos: %p, code: 0x%08x, reason:%s\n", - __func__, __LINE__, *taos_v, ws_errno(ws_res), ws_errstr(ws_res)); - break; - } - - uint8_t type; - uint32_t len; - - for (int row = 0; row < rows; row++) { - const void *value0 = ws_get_value_in_block(ws_res, row, TSDB_SHOW_DB_NAME_INDEX, &type, &len); - if (NULL == value0) { - errorPrint("row: %d, ws_get_value_in_block() error!\n", row); - continue; - } - - // put to linked list - if (head == NULL) { - head = end = mallocNode(value0, len); - if(head == NULL) { - errorPrint("row: %d, mallocNode head error!\n", row); - continue; - } - } else { - end->next = mallocNode(value0, len); - if(end->next == NULL) { - errorPrint("row: %d, mallocNode next error!\n", row); - continue; - } - end = end->next; - } - // check - debugPrint("%s() LN%d, stable: %s\n", __func__, __LINE__, end->name); - } - } - - free(command); - - // check except - if (head == NULL) { - infoPrint("%s() LN%d, stable count is zero.\n", __func__, __LINE__ ); - return 0; - } - - // - // dump stable data - // - SNode * next = head; - while (next) { - ret = dumpStbAndChildTb(taos_v, dbInfo, next->name, fpDbs); - if (ret < 0) { - errorPrint("%s() LN%d, stable: %s dump out failed\n", __func__, __LINE__, next->name); - break; - } - // move next - next = next->next; - } - - // free nodes - freeNodes(head); - return ret; -} - -int64_t dumpNTablesOfDbWS(WS_TAOS **taos_v, SDbInfo *dbInfo) { - int64_t ret = 0; - if (0 == dbInfo->ntables) { - errorPrint("%s() LN%d, database: %s has 0 tables\n", __func__, __LINE__, dbInfo->name); - return 0; - } - - char *command = calloc(1, TSDB_MAX_ALLOWED_SQL_LEN); - if (NULL == command) { - errorPrint("%s() LN%d, memory allocation failed\n", __func__, __LINE__); - return -1; - } - - WS_RES *ws_res; - int32_t ws_code = -1; - - if (3 == g_majorVersionOfClient) { - snprintf(command, TSDB_MAX_ALLOWED_SQL_LEN, - "SELECT TABLE_NAME,STABLE_NAME FROM " - "information_schema.ins_tables WHERE db_name='%s'", - dbInfo->name); - } else { - snprintf(command, TSDB_MAX_ALLOWED_SQL_LEN, g_args.db_escape_char ? "USE `%s`" : "USE %s", dbInfo->name); - ws_res = wsQuery(taos_v, command, &ws_code); - if (ws_code) { - errorPrint("invalid database %s, code: 0x%08x, reason: %s\n", dbInfo->name, ws_code, ws_errstr(ws_res)); - ws_free_result(ws_res); - ws_res = NULL; - ws_close(taos_v); - taos_v = NULL; - free(command); - return 0; - } - ws_free_result(ws_res); - snprintf(command, TSDB_MAX_ALLOWED_SQL_LEN, "SHOW TABLES"); - } - - ws_res = wsQuery(taos_v, command, &ws_code); - if (ws_code) { - errorPrint("Failed to show %s\'s tables, code: 0x%08x, reason: %s!\n", dbInfo->name, ws_code, - ws_errstr(ws_res)); - ws_free_result(ws_res); - ws_res = NULL; - ws_close(taos_v); - taos_v = NULL; - free(command); - return 0; - } - - // link - SNode* head = NULL; - SNode* end = NULL; - - int64_t count = 0; - while (true) { - int rows = 0; - const void *data = NULL; - ws_code = ws_fetch_raw_block(ws_res, &data, &rows); - - if (0 == rows) { - debugPrint( - "%s() LN%d, No more data from ws_fetch_raw_block(), " - "ws_taos: %p, code: 0x%08x, reason:%s\n", - __func__, __LINE__, *taos_v, ws_errno(ws_res), ws_errstr(ws_res)); - break; - } - - uint8_t type; - uint32_t len0, len1; - - for (int row = 0; row < rows; row++) { - const void *value1 = NULL; - if (3 == g_majorVersionOfClient) { - value1 = ws_get_value_in_block(ws_res, row, 1, &type, &len1); - } else { - value1 = ws_get_value_in_block(ws_res, row, TSDB_SHOW_TABLES_METRIC_INDEX, &type, &len1); - } - - if (len1) { - if (g_args.debug_print || g_args.verbose_print) { - char buffer[VALUE_BUF_LEN]; - memset(buffer, 0, VALUE_BUF_LEN); - memcpy(buffer, value1, len1); - debugPrint("%s() LN%d, get table belong %s\n", __func__, __LINE__, buffer); - } - continue; - } else { - const void *value0 = ws_get_value_in_block(ws_res, row, 0, &type, &len0); - if ((NULL == value0) || (0 == len0)) { - errorPrint("%s() LN%d, value0: %p, type: %d, len0: %d\n", __func__, __LINE__, value0, type, len0); - continue; - } - - // put to linked list - if (head == NULL) { - head = end = mallocNode(value0, len0); - if (head == NULL) { - errorPrint("row: %d, mallocNode head error!\n", row); - continue; - } - } else { - end->next = mallocNode(value0, len0); - if (end->next == NULL) { - errorPrint("row: %d, mallocNode next error!\n", row); - continue; - } - end = end->next; - } - - debugPrint("%s() LN%d count: %" PRId64 - ", table name: %s, " - "length: %d\n", - __func__, __LINE__, count, end->name, len0); - } - count++; - } - } - - ws_free_result(ws_res); - free(command); - - // check except - if (head == NULL) { - infoPrint("%s() LN%d, normal table count is zero.\n", __func__, __LINE__ ); - return 0; - } - - // - // dump stable data - // - SNode * next = head; - while (next) { - ret = dumpANormalTableNotBelong(count, taos_v, dbInfo, next->name); - if (0 == ret) { - infoPrint("Dumping normal table: %s\n", next->name); - } else { - errorPrint("%s() LN%d, dump normal table: %s\n", __func__, __LINE__, next->name); - break; - } - - // move next - next = next->next; - } - - // free nodes - freeNodes(head); - - return ret; -} - -bool fillDBInfoWithFieldsWS(const int index, const char *name, const int row, const int f, WS_RES *res) { - uint8_t type; - uint32_t len; - char tmp[VALUE_BUF_LEN] = {0}; - - const void *value = ws_get_value_in_block(res, row, f, &type, &len); - if (0 == strcmp(name, "name")) { - if (NULL == value) { - errorPrint( - "%s() LN%d, row: %d, field: %d, " - "ws_get_value_in_block() error!\n", - __func__, __LINE__, row, f); - return false; - } else { - memset(tmp, 0, VALUE_BUF_LEN); - memcpy(tmp, value, len); - strncpy(g_dbInfos[index]->name, tmp, len); - } - } else if (0 == strcmp(name, "vgroups")) { - if (TSDB_DATA_TYPE_INT == type) { - g_dbInfos[index]->vgroups = *((int32_t *)value); - } else if (TSDB_DATA_TYPE_SMALLINT == type) { - g_dbInfos[index]->vgroups = *((int16_t *)value); - } else { - errorPrint("%s() LN%d, unexpected type: %d\n", __func__, __LINE__, type); - return false; - } - } else if (0 == strcmp(name, "ntables")) { - if (TSDB_DATA_TYPE_INT == type) { - g_dbInfos[index]->ntables = *((int32_t *)value); - } else if (TSDB_DATA_TYPE_BIGINT == type) { - g_dbInfos[index]->ntables = *((int64_t *)value); - } else { - errorPrint("%s() LN%d, unexpected type: %d\n", __func__, __LINE__, type); - return false; - } - } else if (0 == strcmp(name, "replica")) { - if (TSDB_DATA_TYPE_TINYINT == type) { - g_dbInfos[index]->replica = *((int8_t *)value); - } else if (TSDB_DATA_TYPE_SMALLINT == type) { - g_dbInfos[index]->replica = *((int16_t *)value); - } else { - errorPrint("%s() LN%d, unexpected type: %d\n", __func__, __LINE__, type); - return false; - } - } else if (0 == strcmp(name, "strict")) { - tstrncpy(g_dbInfos[index]->strict, (char *)value, min(STRICT_LEN, len + 1)); - debugPrint("%s() LN%d: field: %d, strict: %s, length:%d\n", __func__, __LINE__, f, g_dbInfos[index]->strict, - len); - } else if (0 == strcmp(name, "quorum")) { - g_dbInfos[index]->quorum = *((int16_t *)value); - } else if (0 == strcmp(name, "days")) { - g_dbInfos[index]->days = *((int16_t *)value); - } else if ((0 == strcmp(name, "keep")) || (0 == strcmp(name, "keep0,keep1,keep2"))) { - tstrncpy(g_dbInfos[index]->keeplist, value, min(KEEPLIST_LEN, len + 1)); - debugPrint("%s() LN%d: field: %d, keep: %s, length:%d\n", __func__, __LINE__, f, g_dbInfos[index]->keeplist, - len); - } else if (0 == strcmp(name, "duration")) { - tstrncpy(g_dbInfos[index]->duration, value, min(DURATION_LEN, len + 1)); - debugPrint("%s() LN%d: field: %d, tmp: %s, duration: %s, length:%d\n", __func__, __LINE__, f, tmp, - g_dbInfos[index]->duration, len); - } else if ((0 == strcmp(name, "cache")) || (0 == strcmp(name, "cache(MB)"))) { - g_dbInfos[index]->cache = *((int32_t *)value); - } else if (0 == strcmp(name, "blocks")) { - g_dbInfos[index]->blocks = *((int32_t *)value); - } else if (0 == strcmp(name, "minrows")) { - if (TSDB_DATA_TYPE_INT == type) { - g_dbInfos[index]->minrows = *((int32_t *)value); - } else { - errorPrint("%s() LN%d, unexpected type: %d\n", __func__, __LINE__, type); - return false; - } - } else if (0 == strcmp(name, "maxrows")) { - if (TSDB_DATA_TYPE_INT == type) { - g_dbInfos[index]->maxrows = *((int32_t *)value); - } else { - errorPrint("%s() LN%d, unexpected type: %d\n", __func__, __LINE__, type); - return false; - } - } else if (0 == strcmp(name, "wallevel")) { - g_dbInfos[index]->wallevel = *((int8_t *)value); - } else if (0 == strcmp(name, "wal")) { - if (TSDB_DATA_TYPE_TINYINT == type) { - g_dbInfos[index]->wal = *((int8_t *)value); - } else { - errorPrint("%s() LN%d, unexpected type: %d\n", __func__, __LINE__, type); - return false; - } - } else if (0 == strcmp(name, "fsync")) { - if (TSDB_DATA_TYPE_INT == type) { - g_dbInfos[index]->fsync = *((int32_t *)value); - } else { - errorPrint("%s() LN%d, unexpected type: %d\n", __func__, __LINE__, type); - return false; - } - } else if (0 == strcmp(name, "comp")) { - if (TSDB_DATA_TYPE_TINYINT == type) { - g_dbInfos[index]->comp = (int8_t)(*((int8_t *)value)); - } else { - errorPrint("%s() LN%d, unexpected type: %d\n", __func__, __LINE__, type); - return false; - } - } else if (0 == strcmp(name, "cachelast")) { - if (TSDB_DATA_TYPE_TINYINT == type) { - g_dbInfos[index]->cachelast = (int8_t)(*((int8_t *)value)); - } else { - errorPrint("%s() LN%d, unexpected type: %d\n", __func__, __LINE__, type); - return false; - } - } else if (0 == strcmp(name, "cache_model")) { - if (TSDB_DATA_TYPE_TINYINT == type) { - g_dbInfos[index]->cache_model = (int8_t)(*((int8_t *)value)); - } else { - errorPrint("%s() LN%d, unexpected type: %d\n", __func__, __LINE__, type); - return false; - } - } else if (0 == strcmp(name, "single_stable_model")) { - if (TSDB_DATA_TYPE_BOOL == type) { - g_dbInfos[index]->single_stable_model = (bool)(*((bool *)value)); - } else { - errorPrint("%s() LN%d, unexpected type: %d\n", __func__, __LINE__, type); - return false; - } - } else if (0 == strcmp(name, "precision")) { - tstrncpy(g_dbInfos[index]->precision, (char *)value, min(DB_PRECISION_LEN, len + 1)); - } else if (0 == strcmp(name, "update")) { - g_dbInfos[index]->update = *((int8_t *)value); - } - - return true; -} - -int fillDbExtraInfoV3WS(void **taos_v, const char *dbName, const int dbIndex) { - int ret = 0; - char *command = calloc(1, TSDB_MAX_ALLOWED_SQL_LEN); - if (NULL == command) { - errorPrint("%s() LN%d, memory allocation failed\n", __func__, __LINE__); - return -1; - } - snprintf(command, TSDB_MAX_ALLOWED_SQL_LEN, - "SELECT COUNT(table_name) FROM " - "information_schema.ins_tables WHERE db_name='%s'", - dbName); - - infoPrint("Getting table(s) count of db (%s) ...\n", dbName); - - int32_t ws_code = -1; - WS_RES *ws_res = wsQuery(taos_v, command, &ws_code); - if (ws_code) { - return cleanIfQueryFailedWS(__func__, __LINE__, command, ws_res); - } else { - while (true) { - int rows = 0; - const void *data = NULL; - ws_code = ws_fetch_raw_block(ws_res, &data, &rows); - - if (0 == rows) { - debugPrint( - "%s() LN%d, No more data from ws_fetch_raw_block(), " - "ws_taos: %p, code: 0x%08x, reason:%s\n", - __func__, __LINE__, *taos_v, ws_errno(ws_res), ws_errstr(ws_res)); - break; - } - - uint8_t type; - uint32_t len; - for (int row = 0; row < rows; row++) { - const void *value0 = ws_get_value_in_block(ws_res, row, TSDB_SHOW_DB_NAME_INDEX, &type, &len); - if (NULL == value0) { - errorPrint("row: %d, ws_get_value_in_block() error!\n", row); - continue; - } - - if (TSDB_DATA_TYPE_BIGINT == type) { - g_dbInfos[dbIndex]->ntables = *(int64_t *)value0; - } else { - errorPrint("%s() LN%d, type: %d, not converted\n", __func__, __LINE__, type); - } - } - } - } - - ws_free_result(ws_res); - free(command); - return ret; -} - -int fillDbInfoWS(void **taos_v) { - int ret = 0; - int dbIndex = 0; - - char *command = calloc(1, TSDB_MAX_ALLOWED_SQL_LEN); - if (NULL == command) { - errorPrint("%s() LN%d, memory allocation failed\n", __func__, __LINE__); - return -1; - } - - if (3 == g_majorVersionOfClient) { - snprintf(command, TSDB_MAX_ALLOWED_SQL_LEN, "SELECT * FROM information_schema.ins_databases"); - } else { - snprintf(command, TSDB_MAX_ALLOWED_SQL_LEN, "SHOW DATABASES"); - } - - int32_t ws_code = -1; - WS_RES *ws_res = wsQuery(taos_v, command, &ws_code); - if (ws_code != 0) { - return cleanIfQueryFailedWS(__func__, __LINE__, command, ws_res); - } - - int fieldCount = ws_field_count(ws_res); - void *ws_fields = NULL; - if (3 == g_majorVersionOfClient) { - const struct WS_FIELD *ws_fields_v3 = ws_fetch_fields(ws_res); - ws_fields = (void *)ws_fields_v3; - } else { - const struct WS_FIELD_V2 *ws_fields_v2 = ws_fetch_fields_v2(ws_res); - ws_fields = (void *)ws_fields_v2; - } - - while (true) { - int rows = 0; - const void *data = NULL; - ws_code = ws_fetch_raw_block(ws_res, &data, &rows); - - if (0 == rows) { - debugPrint( - "%s() LN%d, No more data from ws_fetch_raw_block(), " - "ws_taos: %p, code: 0x%08x, reason:%s\n", - __func__, __LINE__, *taos_v, ws_errno(ws_res), ws_errstr(ws_res)); - break; - } - - uint8_t type; - uint32_t len; - char buffer[VALUE_BUF_LEN] = {0}; - - for (int row = 0; row < rows; row++) { - const void *value0 = ws_get_value_in_block(ws_res, row, TSDB_SHOW_DB_NAME_INDEX, &type, &len); - if (NULL == value0) { - errorPrint("row: %d, ws_get_value_in_block() error!\n", row); - continue; - } - memset(buffer, 0, VALUE_BUF_LEN); - memcpy(buffer, value0, len); - debugPrint("%s() LN%d, dbname: %s\n", __func__, __LINE__, buffer); - - if (isSystemDatabase(buffer)) { - if (!g_args.allow_sys) { - continue; - } - } else if (g_args.databases) { - if (inDatabasesSeq(buffer) != 0) { - continue; - } - } else if (!g_args.all_databases) { - if (strcmp(g_args.arg_list[0], buffer)) { - continue; - } - } - - g_dbInfos[dbIndex] = (SDbInfo *)calloc(1, sizeof(SDbInfo)); - if (NULL == g_dbInfos[dbIndex]) { - errorPrint("%s() LN%d, failed to allocate %" PRIu64 " memory\n", __func__, __LINE__, - (uint64_t)sizeof(SDbInfo)); - ret = -1; - break; - } - - okPrint("Database: %s exists\n", buffer); - if (3 == g_majorVersionOfClient) { - struct WS_FIELD *fields = (struct WS_FIELD *)ws_fields; - for (int f = 0; f < fieldCount; f++) { - if (false == fillDBInfoWithFieldsWS(dbIndex, fields[f].name, row, f, ws_res)) { - ret = -1; - break; - } - } - } else { - struct WS_FIELD_V2 *fields = (struct WS_FIELD_V2 *)ws_fields; - for (int f = 0; f < fieldCount; f++) { - if (false == fillDBInfoWithFieldsWS(dbIndex, fields[f].name, row, f, ws_res)) { - ret = -1; - break; - } - } - } - - if (3 == g_majorVersionOfClient) { - fillDbExtraInfoV3WS(taos_v, g_dbInfos[dbIndex]->name, dbIndex); - } - - dbIndex++; - - if (g_args.databases) { - if (dbIndex > g_args.dumpDbCount) break; - } else if (!g_args.all_databases) { - if (dbIndex >= 1) break; - } - } - } - - ws_free_result(ws_res); - ws_res = NULL; - free(command); - - if (0 != ret) { - return ret; - } - - return dbIndex; -} - -bool jointCloudDsn() { - if ((NULL != g_args.host) && strlen(g_args.host)) { - if (0 == g_args.port) { - snprintf(g_args.cloudHost, MAX_HOSTNAME_LEN, "ws://%s:6041", g_args.host); - } else { - snprintf(g_args.cloudHost, MAX_HOSTNAME_LEN, "ws://%s:%d", g_args.host, g_args.port); - } - } else { - if (0 == g_args.port) { - snprintf(g_args.cloudHost, MAX_HOSTNAME_LEN, "ws://localhost:6041"); - } else { - snprintf(g_args.cloudHost, MAX_HOSTNAME_LEN, "ws://localhost:%d", g_args.port); - } - } - - g_args.dsn = g_args.cloudHost; - debugPrint("%s() LN%d, dsn: %s\n", __func__, __LINE__, g_args.dsn); - return true; -} - -bool splitCloudDsn() { - if (g_args.dsn) { - char *token = strstr(g_args.dsn, "?token="); - if (NULL == token) { - return false; - } else { - g_args.cloudToken = token + strlen("?token="); - } - - char *http = NULL, *https = NULL; - http = strstr(g_args.dsn, "http://"); - if (NULL == http) { - https = strstr(g_args.dsn, "https://"); - if (NULL == https) { - tstrncpy(g_args.cloudHost, g_args.dsn, MAX_HOSTNAME_LEN); - } else { - tstrncpy(g_args.cloudHost, https + strlen("https://"), MAX_HOSTNAME_LEN); - } - } else { - tstrncpy(g_args.cloudHost, http + strlen("http://"), MAX_HOSTNAME_LEN); - } - - char *colon = strstr(g_args.cloudHost, ":"); - if (colon) { - g_args.cloudHost[strlen(g_args.cloudHost) - strlen(colon)] = '\0'; - g_args.cloudPort = atoi(colon + 1); - } - - return true; - } - - return false; -} - -int64_t dumpTableDataWS(const int64_t index, FILE *fp, const char *tbName, const char *dbName, const int precision, - TableDes *tableDes, const int64_t start_time, const int64_t end_time) { - WS_TAOS *ws_taos; - if (NULL == (ws_taos = wsConnect())) { - return -1; - } - - WS_RES *ws_res = queryDbForDumpOutWS(&ws_taos, dbName, tbName, precision, start_time, end_time); - - int64_t totalRows = -1; - if (ws_res) { - totalRows = writeResultDebugWS(ws_res, fp, dbName, tbName); - } - - ws_free_result(ws_res); - ws_res = NULL; - ws_close(ws_taos); - - return totalRows; -} - -#endif // WEBSOCKET diff --git a/tools/taos-tools/test/CMakeLists.txt b/tools/taos-tools/test/CMakeLists.txt index 1586dae65dde..182cb166dd3f 100644 --- a/tools/taos-tools/test/CMakeLists.txt +++ b/tools/taos-tools/test/CMakeLists.txt @@ -15,8 +15,9 @@ IF(TD_LINUX) ) target_include_directories( - benchmarkTest - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../inc" + benchmarkTest PRIVATE + "${CMAKE_CURRENT_SOURCE_DIR}/../inc" + "${CMAKE_CURRENT_SOURCE_DIR}/../deps/toolscJson/inc/" ) add_test( diff --git a/tools/taos-tools/test/benchmarkTest.cpp b/tools/taos-tools/test/benchmarkTest.cpp index 5ea296e4cb98..8310e616c98c 100644 --- a/tools/taos-tools/test/benchmarkTest.cpp +++ b/tools/taos-tools/test/benchmarkTest.cpp @@ -16,11 +16,50 @@ #include #include -TEST(jsonTest, taosBenchmarkTest) { - printf("hello world taosBenchmark unit test for C \n"); + +// lower +char* strToLowerCopy(const char *str) { + if (str == NULL) { + return NULL; + } + size_t len = strlen(str); + char *result = (char*)malloc(len + 1); + if (result == NULL) { + return NULL; + } + for (size_t i = 0; i < len; i++) { + result[i] = tolower((unsigned char)str[i]); + } + result[len] = '\0'; + return result; +} + +// pase dsn +int32_t parseDsn(char* dsn, char **host, char **port, char **user, char **pwd); + +TEST(jsonTest, strToLowerCopy) { + // strToLowerCopy + const char* arr[][2] = { + {"ABC","abc"}, + {"Http://Localhost:6041","htttp://localhost:6041"}, + {"DEF","def"} + }; + + int rows = sizeof(arr) / sizeof(arr[0]); + for (int i = 0; i < rows; i++) { + char *p1 = (char *)arr[i][0]; + char *p2 = strToLowerCopy(p1); + int32_t cmp = strcmp(p1, p2); + ASSERT_EQ(cmp, 0); + } + + // null + char * p = strToLowerCopy(NULL); + ASSERT_EQ(p, nullptr); } int main(int argc, char **argv) { + printf("Hello world taosBenchmark unit test for C \n"); testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } \ No newline at end of file diff --git a/utils/test/c/CMakeLists.txt b/utils/test/c/CMakeLists.txt index f9e2938f566b..a5fc2269682d 100644 --- a/utils/test/c/CMakeLists.txt +++ b/utils/test/c/CMakeLists.txt @@ -1,4 +1,5 @@ add_executable(tmq_demo tmqDemo.c) +add_dependencies(tmq_demo ${TAOS_NATIVE_LIB}) add_executable(tmq_sim tmqSim.c) add_executable(create_table createTable.c) add_executable(tmq_taosx_ci tmq_taosx_ci.c) @@ -26,7 +27,7 @@ endif(${TD_LINUX}) target_link_libraries( tmq_offset - PUBLIC ${TAOS_LIB} + PUBLIC ${TAOS_NATIVE_LIB} PUBLIC util PUBLIC common PUBLIC os @@ -34,7 +35,7 @@ target_link_libraries( target_link_libraries( tmq_multi_thread_test - PUBLIC ${TAOS_LIB} + PUBLIC ${TAOS_NATIVE_LIB} PUBLIC util PUBLIC common PUBLIC os @@ -42,7 +43,7 @@ target_link_libraries( target_link_libraries( create_table - PUBLIC ${TAOS_LIB} + PUBLIC ${TAOS_NATIVE_LIB} PUBLIC util PUBLIC common PUBLIC os @@ -50,7 +51,7 @@ target_link_libraries( target_link_libraries( tmq_demo - PUBLIC ${TAOS_LIB} + PUBLIC ${TAOS_NATIVE_LIB} PUBLIC util PUBLIC common PUBLIC os @@ -58,7 +59,7 @@ target_link_libraries( target_link_libraries( tmq_sim - PUBLIC ${TAOS_LIB_PLATFORM_SPEC} + PUBLIC ${TAOS_NATIVE_LIB} PUBLIC util PUBLIC common PUBLIC os @@ -66,7 +67,7 @@ target_link_libraries( target_link_libraries( tmq_ts5466 - PUBLIC ${TAOS_LIB} + PUBLIC ${TAOS_NATIVE_LIB} PUBLIC util PUBLIC common PUBLIC os @@ -74,7 +75,7 @@ target_link_libraries( target_link_libraries( tmq_td32187 - PUBLIC ${TAOS_LIB} + PUBLIC ${TAOS_NATIVE_LIB} PUBLIC util PUBLIC common PUBLIC os @@ -105,7 +106,7 @@ target_link_libraries( ) target_link_libraries( tmq_td32526 - PUBLIC ${TAOS_LIB} + PUBLIC ${TAOS_NATIVE_LIB} PUBLIC util PUBLIC common PUBLIC os @@ -121,7 +122,7 @@ target_link_libraries( target_link_libraries( tmq_taosx_ci - PUBLIC ${TAOS_LIB} + PUBLIC ${TAOS_NATIVE_LIB} PUBLIC util PUBLIC common PUBLIC os @@ -129,7 +130,7 @@ target_link_libraries( target_link_libraries( tmq_offset_test - PUBLIC ${TAOS_LIB} + PUBLIC ${TAOS_NATIVE_LIB} PUBLIC util PUBLIC common PUBLIC os @@ -137,7 +138,7 @@ target_link_libraries( target_link_libraries( replay_test - PUBLIC ${TAOS_LIB} + PUBLIC ${TAOS_NATIVE_LIB} PUBLIC util PUBLIC common PUBLIC os @@ -145,7 +146,7 @@ target_link_libraries( target_link_libraries( write_raw_block_test - PUBLIC ${TAOS_LIB} + PUBLIC ${TAOS_NATIVE_LIB} PUBLIC util PUBLIC common PUBLIC os @@ -153,7 +154,7 @@ target_link_libraries( target_link_libraries( tmq_write_raw_test - PUBLIC ${TAOS_LIB} + PUBLIC ${TAOS_NATIVE_LIB} PUBLIC util PUBLIC common PUBLIC os @@ -161,7 +162,7 @@ target_link_libraries( target_link_libraries( sml_test - PUBLIC ${TAOS_LIB} + PUBLIC ${TAOS_NATIVE_LIB} PUBLIC util PUBLIC common PUBLIC os @@ -170,7 +171,7 @@ target_link_libraries( target_link_libraries( get_db_name_test - PUBLIC ${TAOS_LIB} + PUBLIC ${TAOS_NATIVE_LIB} PUBLIC util PUBLIC common PUBLIC os @@ -178,7 +179,7 @@ target_link_libraries( target_link_libraries( varbinary_test - PUBLIC ${TAOS_LIB} + PUBLIC ${TAOS_NATIVE_LIB} PUBLIC util PUBLIC common PUBLIC os @@ -195,9 +196,9 @@ target_link_libraries( if(${TD_LINUX}) target_link_libraries( tsz_test - PUBLIC ${TAOS_LIB} + PUBLIC ${TAOS_NATIVE_LIB} PUBLIC util PUBLIC common PUBLIC os ) -endif(${TD_LINUX}) \ No newline at end of file +endif(${TD_LINUX}) diff --git a/utils/tsim/CMakeLists.txt b/utils/tsim/CMakeLists.txt index b725ed919a64..d450e378bece 100644 --- a/utils/tsim/CMakeLists.txt +++ b/utils/tsim/CMakeLists.txt @@ -10,7 +10,7 @@ TARGET_INCLUDE_DIRECTORIES( ) TARGET_LINK_LIBRARIES( tsim_static - PUBLIC ${TAOS_LIB} + PUBLIC ${TAOS_NATIVE_LIB} PUBLIC util PUBLIC common PUBLIC os diff --git a/utils/tsim/src/simEntry.c b/utils/tsim/src/simEntry.c index dd11c21af050..2ebad8d19103 100644 --- a/utils/tsim/src/simEntry.c +++ b/utils/tsim/src/simEntry.c @@ -43,6 +43,8 @@ int32_t simEntry(int32_t argc, char **argv) { } } + taos_options(TSDB_OPTION_DRIVER, "native"); + simInfo("simulator is running ..."); simSystemInit();