diff --git a/cmake/taostools_CMakeLists.txt.in b/cmake/taostools_CMakeLists.txt.in
index 1d06995380..d14efcfee3 100644
--- a/cmake/taostools_CMakeLists.txt.in
+++ b/cmake/taostools_CMakeLists.txt.in
@@ -2,7 +2,7 @@
# taos-tools
ExternalProject_Add(taos-tools
GIT_REPOSITORY https://github.com/taosdata/taos-tools.git
- GIT_TAG 41affde
+ GIT_TAG ad1a32b
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taos-tools"
BINARY_DIR ""
#BUILD_IN_SOURCE TRUE
diff --git a/docs/zh/05-get-started/index.md b/docs/zh/05-get-started/index.md
index e144c563b9..ea586ff9ba 100644
--- a/docs/zh/05-get-started/index.md
+++ b/docs/zh/05-get-started/index.md
@@ -41,7 +41,7 @@ TDengine 知识地图中涵盖了 TDengine 的各种知识点,揭示了各概
 |
-加入“物联网大数据技术群” 与大家进行技术交流 |
+加入 TDengine 微信群 了解学习最新物联网技术 |
关注 TDengine 视频号 收看技术直播与教学视频 |
关注 TDengine 公众号 阅读技术文章与行业案例 |
diff --git a/include/common/tcommon.h b/include/common/tcommon.h
index 2a40976a8b..9e928a79ac 100644
--- a/include/common/tcommon.h
+++ b/include/common/tcommon.h
@@ -25,13 +25,6 @@
extern "C" {
#endif
-// TODO remove it
-enum {
- TMQ_CONF__RESET_OFFSET__NONE = -3,
- TMQ_CONF__RESET_OFFSET__EARLIEAST = -2,
- TMQ_CONF__RESET_OFFSET__LATEST = -1,
-};
-
// clang-format off
#define IS_META_MSG(x) ( \
x == TDMT_VND_CREATE_STB \
diff --git a/include/common/tglobal.h b/include/common/tglobal.h
index ac75b84762..13e8454ac3 100644
--- a/include/common/tglobal.h
+++ b/include/common/tglobal.h
@@ -98,7 +98,8 @@ extern char *tsSvrCrashReportUri;
// query buffer management
extern int32_t tsQueryBufferSize; // maximum allowed usage buffer size in MB for each data node during query processing
-extern int64_t tsQueryBufferSizeBytes; // maximum allowed usage buffer size in byte for each data node
+extern int64_t tsQueryBufferSizeBytes; // maximum allowed usage buffer size in byte for each data node
+extern int32_t tsCacheLazyLoadThreshold; // cost threshold for last/last_row loading cache as much as possible
// query client
extern int32_t tsQueryPolicy;
@@ -145,10 +146,10 @@ extern char tsUdfdResFuncs[];
extern char tsUdfdLdLibPath[];
// schemaless
-extern char tsSmlChildTableName[];
-extern char tsSmlTagName[];
-//extern bool tsSmlDataFormat;
-//extern int32_t tsSmlBatchSize;
+extern char tsSmlChildTableName[];
+extern char tsSmlTagName[];
+// extern bool tsSmlDataFormat;
+// extern int32_t tsSmlBatchSize;
// wal
extern int64_t tsWalFsyncDataSizeLimit;
diff --git a/include/common/tmsg.h b/include/common/tmsg.h
index d9d3c7e297..ce441502cb 100644
--- a/include/common/tmsg.h
+++ b/include/common/tmsg.h
@@ -1136,6 +1136,7 @@ typedef struct {
int64_t numOfInsertSuccessReqs;
int64_t numOfBatchInsertReqs;
int64_t numOfBatchInsertSuccessReqs;
+ int32_t numOfCachedTables;
} SVnodeLoad;
typedef struct {
@@ -3185,6 +3186,7 @@ typedef struct {
SArray* blockData;
SArray* blockTbName;
SArray* blockSchema;
+ // the following attributes are extended from SMqDataRsp
int32_t createTableNum;
SArray* createTableLen;
SArray* createTableReq;
diff --git a/include/libs/sync/sync.h b/include/libs/sync/sync.h
index 189484d1a6..08a6be8015 100644
--- a/include/libs/sync/sync.h
+++ b/include/libs/sync/sync.h
@@ -143,10 +143,11 @@ typedef struct SSyncFSM {
void* data;
int32_t (*FpCommitCb)(const struct SSyncFSM* pFsm, SRpcMsg* pMsg, const SFsmCbMeta* pMeta);
+ SyncIndex (*FpAppliedIndexCb)(const struct SSyncFSM* pFsm);
int32_t (*FpPreCommitCb)(const struct SSyncFSM* pFsm, SRpcMsg* pMsg, const SFsmCbMeta* pMeta);
void (*FpRollBackCb)(const struct SSyncFSM* pFsm, SRpcMsg* pMsg, const SFsmCbMeta* pMeta);
- void (*FpRestoreFinishCb)(const struct SSyncFSM* pFsm);
+ void (*FpRestoreFinishCb)(const struct SSyncFSM* pFsm, const SyncIndex commitIdx);
void (*FpReConfigCb)(const struct SSyncFSM* pFsm, SRpcMsg* pMsg, const SReConfigCbMeta* pMeta);
void (*FpLeaderTransferCb)(const struct SSyncFSM* pFsm, SRpcMsg* pMsg, const SFsmCbMeta* pMeta);
bool (*FpApplyQueueEmptyCb)(const struct SSyncFSM* pFsm);
diff --git a/include/util/taoserror.h b/include/util/taoserror.h
index 900a6ce57e..f626f49661 100644
--- a/include/util/taoserror.h
+++ b/include/util/taoserror.h
@@ -542,7 +542,8 @@ int32_t* taosGetErrno();
#define TSDB_CODE_SYN_BATCH_ERROR TAOS_DEF_ERROR_CODE(0, 0x0913)
#define TSDB_CODE_SYN_RESTORING TAOS_DEF_ERROR_CODE(0, 0x0914)
#define TSDB_CODE_SYN_INVALID_SNAPSHOT_MSG TAOS_DEF_ERROR_CODE(0, 0x0915) // internal
-#define TSDB_CODE_SYN_BUFFER_FULL TAOS_DEF_ERROR_CODE(0, 0x0916) //
+#define TSDB_CODE_SYN_BUFFER_FULL TAOS_DEF_ERROR_CODE(0, 0x0916)
+#define TSDB_CODE_SYN_WRITE_STALL TAOS_DEF_ERROR_CODE(0, 0x0917)
#define TSDB_CODE_SYN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x09FF)
// tq
diff --git a/include/util/tlrucache.h b/include/util/tlrucache.h
index 1900934248..c9cf71c2fd 100644
--- a/include/util/tlrucache.h
+++ b/include/util/tlrucache.h
@@ -55,6 +55,8 @@ void *taosLRUCacheValue(SLRUCache *cache, LRUHandle *handle);
size_t taosLRUCacheGetUsage(SLRUCache *cache);
size_t taosLRUCacheGetPinnedUsage(SLRUCache *cache);
+int32_t taosLRUCacheGetElems(SLRUCache *cache);
+
void taosLRUCacheSetCapacity(SLRUCache *cache, size_t capacity);
size_t taosLRUCacheGetCapacity(SLRUCache *cache);
diff --git a/packaging/cfg/taos.cfg b/packaging/cfg/taos.cfg
index 3d3dfc8e73..a98dc5a236 100644
--- a/packaging/cfg/taos.cfg
+++ b/packaging/cfg/taos.cfg
@@ -1,19 +1,19 @@
########################################################
# #
-# TDengine Configuration #
+# Configuration #
# Any questions, please email support@taosdata.com #
# #
########################################################
######### 0. Client only configurations #############
-# The interval for TDengine CLI to send heartbeat to mnode
+# The interval for CLI to send heartbeat to mnode
# shellActivityTimer 3
############### 1. Cluster End point ############################
-# The end point of the first dnode in the cluster to be connected to when this dnode or a TDengine CLI `taos` is started
+# The end point of the first dnode in the cluster to be connected to when this dnode or a CLI `taos` is started
# firstEp hostname:6030
# The end point of the second dnode to be connected to if the firstEp is not available
@@ -40,10 +40,10 @@
# temporary file's directory, if you are using Windows platform please change to Windows path
# tempDir /tmp/
-# Switch for allowing TDengine to collect and report service usage information
+# Switch for allowing to collect and report service usage information
# telemetryReporting 1
-# Switch for allowing TDengine to collect and report crash information
+# Switch for allowing to collect and report crash information
# crashReporting 1
# The maximum number of vnodes supported by this dnode
diff --git a/packaging/debRpmAutoInstall.sh b/packaging/debRpmAutoInstall.sh
index 3579f813e5..2fe18fd7a9 100755
--- a/packaging/debRpmAutoInstall.sh
+++ b/packaging/debRpmAutoInstall.sh
@@ -1,15 +1,15 @@
#!/usr/bin/expect
-set packgeName [lindex $argv 0]
+set packageName [lindex $argv 0]
set packageSuffix [lindex $argv 1]
set timeout 3
if { ${packageSuffix} == "deb" } {
- spawn dpkg -i ${packgeName}
+ spawn dpkg -i ${packageName}
} elseif { ${packageSuffix} == "rpm"} {
- spawn rpm -ivh ${packgeName}
+ spawn rpm -ivh ${packageName}
}
expect "*one:"
send "\r"
expect "*skip:"
send "\r"
-expect eof
\ No newline at end of file
+expect eof
diff --git a/packaging/testpackage.sh b/packaging/testpackage.sh
index 78d5043b0c..9959d290e7 100755
--- a/packaging/testpackage.sh
+++ b/packaging/testpackage.sh
@@ -25,7 +25,7 @@ sourcePath="nas"
cpuType="x64"
lite="true"
packageType="tar"
-subFile="taos.tar.gz"
+subFile="package.tar.gz"
while getopts "m:c:f:l:s:o:t:v:h" opt; do
case $opt in
m)
@@ -79,9 +79,9 @@ GREEN_UNDERLINE='\033[4;32m'
NC='\033[0m'
if [[ ${verMode} = "enterprise" ]];then
- prePackag="TDengine-enterprise-${testFile}"
+ prePackage="TDengine-enterprise-${testFile}"
elif [ ${verMode} = "community" ];then
- prePackag="TDengine-${testFile}"
+ prePackage="TDengine-${testFile}"
fi
if [ ${lite} = "true" ];then
packageLite="-Lite"
@@ -92,10 +92,10 @@ if [[ "$packageType" = "tar" ]] ;then
packageType="tar.gz"
fi
-tdPath="${prePackag}-${version}"
-originTdpPath="${prePackag}-${originversion}"
+tdPath="${prePackage}-${version}"
+originTdpPath="${prePackage}-${originversion}"
-packgeName="${tdPath}-Linux-${cpuType}${packageLite}.${packageType}"
+packageName="${tdPath}-Linux-${cpuType}${packageLite}.${packageType}"
originPackageName="${originTdpPath}-Linux-${cpuType}${packageLite}.${packageType}"
if [ "$testFile" == "server" ] ;then
@@ -105,13 +105,13 @@ elif [ ${testFile} = "client" ];then
elif [ ${testFile} = "tools" ];then
tdPath="taosTools-${version}"
originTdpPath="taosTools-${originversion}"
- packgeName="${tdPath}-Linux-${cpuType}${packageLite}.${packageType}"
+ packageName="${tdPath}-Linux-${cpuType}${packageLite}.${packageType}"
originPackageName="${originTdpPath}-Linux-${cpuType}${packageLite}.${packageType}"
- installCmd="install-taostools.sh"
+ installCmd="install-tools.sh"
fi
-echo "tdPath:${tdPath},originTdpPath:${originTdpPath},packgeName:${packgeName},originPackageName:${originPackageName}"
+echo "tdPath:${tdPath},originTdpPath:${originTdpPath},packageName:${packageName},originPackageName:${originPackageName}"
function cmdInstall {
command=$1
if command -v ${command} ;then
@@ -206,7 +206,7 @@ else
fi
-if [[ ${packgeName} =~ "server" ]] ;then
+if [[ ${packageName} =~ "server" ]] ;then
echoColor BD " pkill -9 taosd "
pkill -9 taosd
fi
@@ -232,25 +232,25 @@ if [ -d ${installPath}/${tdPath} ] ;then
fi
echoColor G "===== download installPackage ====="
-cd ${installPath} && wgetFile ${packgeName} ${version} ${sourcePath}
+cd ${installPath} && wgetFile ${packageName} ${version} ${sourcePath}
cd ${oriInstallPath} && wgetFile ${originPackageName} ${originversion} ${sourcePath}
cd ${installPath}
cp -r ${scriptDir}/debRpmAutoInstall.sh .
-packageSuffix=$(echo ${packgeName} | awk -F '.' '{print $NF}')
+packageSuffix=$(echo ${packageName} | awk -F '.' '{print $NF}')
if [ ! -f debRpmAutoInstall.sh ];then
echo '#!/usr/bin/expect ' > debRpmAutoInstall.sh
- echo 'set packgeName [lindex $argv 0]' >> debRpmAutoInstall.sh
+ echo 'set packageName [lindex $argv 0]' >> debRpmAutoInstall.sh
echo 'set packageSuffix [lindex $argv 1]' >> debRpmAutoInstall.sh
echo 'set timeout 3 ' >> debRpmAutoInstall.sh
echo 'if { ${packageSuffix} == "deb" } {' >> debRpmAutoInstall.sh
- echo ' spawn dpkg -i ${packgeName} ' >> debRpmAutoInstall.sh
+ echo ' spawn dpkg -i ${packageName} ' >> debRpmAutoInstall.sh
echo '} elseif { ${packageSuffix} == "rpm"} {' >> debRpmAutoInstall.sh
- echo ' spawn rpm -ivh ${packgeName}' >> debRpmAutoInstall.sh
+ echo ' spawn rpm -ivh ${packageName}' >> debRpmAutoInstall.sh
echo '}' >> debRpmAutoInstall.sh
echo 'expect "*one:"' >> debRpmAutoInstall.sh
echo 'send "\r"' >> debRpmAutoInstall.sh
@@ -261,25 +261,25 @@ fi
echoColor G "===== instal Package ====="
-if [[ ${packgeName} =~ "deb" ]];then
+if [[ ${packageName} =~ "deb" ]];then
cd ${installPath}
dpkg -r taostools
dpkg -r tdengine
- if [[ ${packgeName} =~ "TDengine" ]];then
- echoColor BD "./debRpmAutoInstall.sh ${packgeName} ${packageSuffix}" && chmod 755 debRpmAutoInstall.sh && ./debRpmAutoInstall.sh ${packgeName} ${packageSuffix}
+ if [[ ${packageName} =~ "TDengine" ]];then
+ echoColor BD "./debRpmAutoInstall.sh ${packageName} ${packageSuffix}" && chmod 755 debRpmAutoInstall.sh && ./debRpmAutoInstall.sh ${packageName} ${packageSuffix}
else
- echoColor BD "dpkg -i ${packgeName}" && dpkg -i ${packgeName}
+ echoColor BD "dpkg -i ${packageName}" && dpkg -i ${packageName}
fi
-elif [[ ${packgeName} =~ "rpm" ]];then
+elif [[ ${packageName} =~ "rpm" ]];then
cd ${installPath}
sudo rpm -e tdengine
sudo rpm -e taostools
- if [[ ${packgeName} =~ "TDengine" ]];then
- echoColor BD "./debRpmAutoInstall.sh ${packgeName} ${packageSuffix}" && chmod 755 debRpmAutoInstall.sh && ./debRpmAutoInstall.sh ${packgeName} ${packageSuffix}
+ if [[ ${packageName} =~ "TDengine" ]];then
+ echoColor BD "./debRpmAutoInstall.sh ${packageName} ${packageSuffix}" && chmod 755 debRpmAutoInstall.sh && ./debRpmAutoInstall.sh ${packageName} ${packageSuffix}
else
- echoColor BD "rpm -ivh ${packgeName}" && rpm -ivh ${packgeName}
+ echoColor BD "rpm -ivh ${packageName}" && rpm -ivh ${packageName}
fi
-elif [[ ${packgeName} =~ "tar" ]];then
+elif [[ ${packageName} =~ "tar" ]];then
echoColor G "===== check installPackage File of tar ====="
cd ${oriInstallPath}
if [ ! -f {originPackageName} ];then
@@ -290,7 +290,7 @@ elif [[ ${packgeName} =~ "tar" ]];then
echoColor BD "tar -xf ${originPackageName}" && tar -xf ${originPackageName}
cd ${installPath}
echoColor YD "unzip the new installation package"
- echoColor BD "tar -xf ${packgeName}" && tar -xf ${packgeName}
+ echoColor BD "tar -xf ${packageName}" && tar -xf ${packageName}
if [ ${testFile} != "tools" ] ;then
cd ${installPath}/${tdPath} && tar xf ${subFile}
@@ -326,15 +326,15 @@ fi
cd ${installPath}
-if [[ ${packgeName} =~ "Lite" ]] || ([[ ${packgeName} =~ "x64" ]] && [[ ${packgeName} =~ "client" ]]) || ([[ ${packgeName} =~ "deb" ]] && [[ ${packgeName} =~ "server" ]]) || ([[ ${packgeName} =~ "rpm" ]] && [[ ${packgeName} =~ "server" ]]) ;then
+if [[ ${packageName} =~ "Lite" ]] || ([[ ${packageName} =~ "x64" ]] && [[ ${packageName} =~ "client" ]]) || ([[ ${packageName} =~ "deb" ]] && [[ ${packageName} =~ "server" ]]) || ([[ ${packageName} =~ "rpm" ]] && [[ ${packageName} =~ "server" ]]) ;then
echoColor G "===== install taos-tools when package is lite or client ====="
cd ${installPath}
if [ ! -f "taosTools-2.1.3-Linux-x64.tar.gz " ];then
wgetFile taosTools-2.1.3-Linux-x64.tar.gz v2.1.3 web
tar xf taosTools-2.1.3-Linux-x64.tar.gz
fi
- cd taosTools-2.1.3 && bash install-taostools.sh
-elif ([[ ${packgeName} =~ "arm64" ]] && [[ ${packgeName} =~ "client" ]]);then
+ cd taosTools-2.1.3 && bash install-tools.sh
+elif ([[ ${packageName} =~ "arm64" ]] && [[ ${packageName} =~ "client" ]]);then
echoColor G "===== install taos-tools arm when package is arm64-client ====="
cd ${installPath}
if [ ! -f "taosTools-2.1.3-Linux-x64.tar.gz " ];then
@@ -342,37 +342,37 @@ elif ([[ ${packgeName} =~ "arm64" ]] && [[ ${packgeName} =~ "client" ]]);then
tar xf taosTools-2.1.3-Linux-arm64.tar.gz
fi
- cd taosTools-2.1.3 && bash install-taostools.sh
+ cd taosTools-2.1.3 && bash install-tools.sh
fi
echoColor G "===== start TDengine ====="
-if [[ ${packgeName} =~ "server" ]] ;then
+if [[ ${packageName} =~ "server" ]] ;then
echoColor BD " rm -rf /var/lib/taos/* && systemctl restart taosd "
rm -rf /var/lib/taos/*
systemctl restart taosd
fi
-rm -rf ${installPath}/${packgeName}
+rm -rf ${installPath}/${packageName}
rm -rf ${installPath}/${tdPath}/
-# if ([[ ${packgeName} =~ "Lite" ]] && [[ ${packgeName} =~ "tar" ]]) || [[ ${packgeName} =~ "client" ]] ;then
+# if ([[ ${packageName} =~ "Lite" ]] && [[ ${packageName} =~ "tar" ]]) || [[ ${packageName} =~ "client" ]] ;then
# echoColor G "===== install taos-tools when package is lite or client ====="
# cd ${installPath}
# wgetFile taosTools-2.1.2-Linux-x64.tar.gz .
# tar xf taosTools-2.1.2-Linux-x64.tar.gz
-# cd taosTools-2.1.2 && bash install-taostools.sh
-# elif [[ ${packgeName} =~ "Lite" ]] && [[ ${packgeName} =~ "deb" ]] ;then
+# cd taosTools-2.1.2 && bash install-tools.sh
+# elif [[ ${packageName} =~ "Lite" ]] && [[ ${packageName} =~ "deb" ]] ;then
# echoColor G "===== install taos-tools when package is lite or client ====="
# cd ${installPath}
# wgetFile taosTools-2.1.2-Linux-x64.tar.gz .
# tar xf taosTools-2.1.2-Linux-x64.tar.gz
-# cd taosTools-2.1.2 && bash install-taostools.sh
-# elif [[ ${packgeName} =~ "Lite" ]] && [[ ${packgeName} =~ "rpm" ]] ;then
+# cd taosTools-2.1.2 && bash install-tools.sh
+# elif [[ ${packageName} =~ "Lite" ]] && [[ ${packageName} =~ "rpm" ]] ;then
# echoColor G "===== install taos-tools when package is lite or client ====="
# cd ${installPath}
# wgetFile taosTools-2.1.2-Linux-x64.tar.gz .
# tar xf taosTools-2.1.2-Linux-x64.tar.gz
-# cd taosTools-2.1.2 && bash install-taostools.sh
+# cd taosTools-2.1.2 && bash install-tools.sh
# fi
diff --git a/packaging/tools/install.sh b/packaging/tools/install.sh
index 2495e177e1..a3f8b53d33 100755
--- a/packaging/tools/install.sh
+++ b/packaging/tools/install.sh
@@ -24,7 +24,7 @@ productName="TDengine"
emailName="taosdata.com"
uninstallScript="rmtaos"
historyFile="taos_history"
-tarName="taos.tar.gz"
+tarName="package.tar.gz"
dataDir="/var/lib/taos"
logDir="/var/log/taos"
configDir="/etc/taos"
@@ -222,24 +222,24 @@ function install_bin() {
${csudo}cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo}chmod 0555 ${install_main_dir}/bin/*
#Make link
- [ -x ${install_main_dir}/bin/${clientName} ] && ${csudo}ln -s ${install_main_dir}/bin/${clientName} ${bin_link_dir}/${clientName} || :
- [ -x ${install_main_dir}/bin/${serverName} ] && ${csudo}ln -s ${install_main_dir}/bin/${serverName} ${bin_link_dir}/${serverName} || :
- [ -x ${install_main_dir}/bin/${udfdName} ] && ${csudo}ln -s ${install_main_dir}/bin/${udfdName} ${bin_link_dir}/${udfdName} || :
- [ -x ${install_main_dir}/bin/${adapterName} ] && ${csudo}ln -s ${install_main_dir}/bin/${adapterName} ${bin_link_dir}/${adapterName} || :
+ [ -x ${install_main_dir}/bin/${clientName} ] && ${csudo}ln -sf ${install_main_dir}/bin/${clientName} ${bin_link_dir}/${clientName} || :
+ [ -x ${install_main_dir}/bin/${serverName} ] && ${csudo}ln -sf ${install_main_dir}/bin/${serverName} ${bin_link_dir}/${serverName} || :
+ [ -x ${install_main_dir}/bin/${udfdName} ] && ${csudo}ln -sf ${install_main_dir}/bin/${udfdName} ${bin_link_dir}/${udfdName} || :
+ [ -x ${install_main_dir}/bin/${adapterName} ] && ${csudo}ln -sf ${install_main_dir}/bin/${adapterName} ${bin_link_dir}/${adapterName} || :
[ -x ${install_main_dir}/bin/${benchmarkName} ] && ${csudo}ln -sf ${install_main_dir}/bin/${benchmarkName} ${bin_link_dir}/${demoName} || :
[ -x ${install_main_dir}/bin/${benchmarkName} ] && ${csudo}ln -sf ${install_main_dir}/bin/${benchmarkName} ${bin_link_dir}/${benchmarkName} || :
- [ -x ${install_main_dir}/bin/${dumpName} ] && ${csudo}ln -s ${install_main_dir}/bin/${dumpName} ${bin_link_dir}/${dumpName} || :
- [ -x ${install_main_dir}/bin/${xname} ] && ${csudo}ln -s ${install_main_dir}/bin/${xname} ${bin_link_dir}/${xname} || :
- [ -x ${install_main_dir}/bin/${explorerName} ] && ${csudo}ln -s ${install_main_dir}/bin/${explorerName} ${bin_link_dir}/${explorerName} || :
- [ -x ${install_main_dir}/bin/TDinsight.sh ] && ${csudo}ln -s ${install_main_dir}/bin/TDinsight.sh ${bin_link_dir}/TDinsight.sh || :
- [ -x ${install_main_dir}/bin/remove.sh ] && ${csudo}ln -s ${install_main_dir}/bin/remove.sh ${bin_link_dir}/${uninstallScript} || :
- [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo}ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || :
+ [ -x ${install_main_dir}/bin/${dumpName} ] && ${csudo}ln -sf ${install_main_dir}/bin/${dumpName} ${bin_link_dir}/${dumpName} || :
+ [ -x ${install_main_dir}/bin/${xname} ] && ${csudo}ln -sf ${install_main_dir}/bin/${xname} ${bin_link_dir}/${xname} || :
+ [ -x ${install_main_dir}/bin/${explorerName} ] && ${csudo}ln -sf ${install_main_dir}/bin/${explorerName} ${bin_link_dir}/${explorerName} || :
+ [ -x ${install_main_dir}/bin/TDinsight.sh ] && ${csudo}ln -sf ${install_main_dir}/bin/TDinsight.sh ${bin_link_dir}/TDinsight.sh || :
+ [ -x ${install_main_dir}/bin/remove.sh ] && ${csudo}ln -sf ${install_main_dir}/bin/remove.sh ${bin_link_dir}/${uninstallScript} || :
+ [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo}ln -sf ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || :
if [ "$verMode" == "cluster" ] && [ "$clientName" != "$clientName2" ]; then
- [ -x ${install_main_dir}/bin/${clientName} ] && ${csudo}ln -s ${install_main_dir}/bin/${clientName} ${bin_link_dir}/${clientName2} || :
- [ -x ${install_main_dir}/bin/${benchmarkName} ] && ${csudo}ln -s ${install_main_dir}/bin/${benchmarkName} ${bin_link_dir}/${benchmarkName2} || :
- [ -x ${install_main_dir}/bin/${dumpName} ] && ${csudo}ln -s ${install_main_dir}/bin/${dumpName} ${bin_link_dir}/${dumpName2} || :
- [ -x ${install_main_dir}/bin/remove.sh ] && ${csudo}ln -s ${install_main_dir}/bin/remove.sh ${bin_link_dir}/${uninstallScript2} || :
+ [ -x ${install_main_dir}/bin/${clientName} ] && ${csudo}ln -sf ${install_main_dir}/bin/${clientName} ${bin_link_dir}/${clientName2} || :
+ [ -x ${install_main_dir}/bin/${benchmarkName} ] && ${csudo}ln -sf ${install_main_dir}/bin/${benchmarkName} ${bin_link_dir}/${benchmarkName2} || :
+ [ -x ${install_main_dir}/bin/${dumpName} ] && ${csudo}ln -sf ${install_main_dir}/bin/${dumpName} ${bin_link_dir}/${dumpName2} || :
+ [ -x ${install_main_dir}/bin/remove.sh ] && ${csudo}ln -sf ${install_main_dir}/bin/remove.sh ${bin_link_dir}/${uninstallScript2} || :
fi
}
@@ -250,14 +250,14 @@ function install_lib() {
#${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 -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 -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
[ -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 -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 -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 || :
[ -f ${install_main_dir}/libtaosws.so ] && ${csudo}ln -sf ${install_main_dir}/libtaosws.so ${lib64_link_dir}/libtaosws.so || :
fi
@@ -347,10 +347,10 @@ function install_header() {
[ -f ${inc_link_dir}/taosws.h ] && ${csudo}rm -f ${inc_link_dir}/taosws.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
- ${csudo}ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h
- ${csudo}ln -s ${install_main_dir}/include/taosudf.h ${inc_link_dir}/taosudf.h
+ ${csudo}ln -sf ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h
+ ${csudo}ln -sf ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h
+ ${csudo}ln -sf ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h
+ ${csudo}ln -sf ${install_main_dir}/include/taosudf.h ${inc_link_dir}/taosudf.h
[ -f ${install_main_dir}/include/taosws.h ] && ${csudo}ln -sf ${install_main_dir}/include/taosws.h ${inc_link_dir}/taosws.h || :
}
@@ -511,7 +511,7 @@ function install_adapter_config() {
fi
[ -f ${cfg_install_dir}/${adapterName}.toml ] &&
- ${csudo}ln -s ${cfg_install_dir}/${adapterName}.toml ${install_main_dir}/cfg/${adapterName}.toml
+ ${csudo}ln -sf ${cfg_install_dir}/${adapterName}.toml ${install_main_dir}/cfg/${adapterName}.toml
[ ! -z $1 ] && return 0 || : # only install client
@@ -527,7 +527,7 @@ function install_config() {
${csudo}cp -f ${script_dir}/cfg/${configFile} ${cfg_install_dir}/${configFile}.new
fi
- ${csudo}ln -s ${cfg_install_dir}/${configFile} ${install_main_dir}/cfg
+ ${csudo}ln -sf ${cfg_install_dir}/${configFile} ${install_main_dir}/cfg
[ ! -z $1 ] && return 0 || : # only install client
@@ -573,13 +573,13 @@ function install_log() {
${csudo}rm -rf ${log_dir} || :
${csudo}mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir}
- ${csudo}ln -s ${log_dir} ${install_main_dir}/log
+ ${csudo}ln -sf ${log_dir} ${install_main_dir}/log
}
function install_data() {
${csudo}mkdir -p ${data_dir}
- ${csudo}ln -s ${data_dir} ${install_main_dir}/data
+ ${csudo}ln -sf ${data_dir} ${install_main_dir}/data
}
function install_connector() {
@@ -862,21 +862,21 @@ function updateProduct() {
openresty_work=false
echo
- echo -e "${GREEN_DARK}To configure ${productName} ${NC}: edit ${cfg_install_dir}/${configFile}"
+ echo -e "${GREEN_DARK}To configure ${productName2} ${NC}: edit ${cfg_install_dir}/${configFile}"
[ -f ${configDir}/taosadapter.toml ] && [ -f ${installDir}/bin/taosadapter ] && \
- echo -e "${GREEN_DARK}To configure Adapter ${NC}: edit ${configDir}/taosadapter.toml"
+ echo -e "${GREEN_DARK}To configure ${clientName2} Adapter ${NC}: edit ${configDir}/taosadapter.toml"
if ((${service_mod} == 0)); then
- echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${csudo}systemctl start ${serverName}${NC}"
+ echo -e "${GREEN_DARK}To start ${productName2} ${NC}: ${csudo}systemctl start ${serverName}${NC}"
[ -f ${service_config_dir}/taosadapter.service ] && [ -f ${installDir}/bin/taosadapter ] && \
- echo -e "${GREEN_DARK}To start Adatper ${NC}: ${csudo}systemctl start taosadapter ${NC}"
+ echo -e "${GREEN_DARK}To start ${clientName2} Adapter ${NC}: ${csudo}systemctl start taosadapter ${NC}"
elif ((${service_mod} == 1)); then
- echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${csudo}service ${serverName} start${NC}"
+ echo -e "${GREEN_DARK}To start ${productName2} ${NC}: ${csudo}service ${serverName} start${NC}"
[ -f ${service_config_dir}/taosadapter.service ] && [ -f ${installDir}/bin/taosadapter ] && \
- echo -e "${GREEN_DARK}To start Adapter ${NC}: ${csudo}service taosadapter start${NC}"
+ echo -e "${GREEN_DARK}To start ${clientName2} Adapter ${NC}: ${csudo}service taosadapter start${NC}"
else
- echo -e "${GREEN_DARK}To start ${productName} ${NC}: ./${serverName}${NC}"
+ echo -e "${GREEN_DARK}To start ${productName2} ${NC}: ./${serverName}${NC}"
[ -f ${installDir}/bin/taosadapter ] && \
- echo -e "${GREEN_DARK}To start ${clientName} Adapter ${NC}: taosadapter &${NC}"
+ echo -e "${GREEN_DARK}To start ${clientName2} Adapter ${NC}: taosadapter &${NC}"
fi
if [ ${openresty_work} = 'true' ]; then
@@ -887,7 +887,7 @@ function updateProduct() {
if ((${prompt_force} == 1)); then
echo ""
- echo -e "${RED}Please run '${serverName} --force-keep-file' at first time for the exist ${productName} $exist_version!${NC}"
+ echo -e "${RED}Please run '${serverName} --force-keep-file' at first time for the exist ${productName2} $exist_version!${NC}"
fi
echo
echo -e "\033[44;32;1m${productName2} is updated successfully!${NC}"
@@ -944,21 +944,21 @@ function installProduct() {
# Ask if to start the service
echo
- echo -e "${GREEN_DARK}To configure ${productName} ${NC}: edit ${cfg_install_dir}/${configFile}"
+ echo -e "${GREEN_DARK}To configure ${productName2} ${NC}: edit ${cfg_install_dir}/${configFile}"
[ -f ${configDir}/taosadapter.toml ] && [ -f ${installDir}/bin/taosadapter ] && \
- echo -e "${GREEN_DARK}To configure Taos Adapter ${NC}: edit ${configDir}/taosadapter.toml"
+ echo -e "${GREEN_DARK}To configure ${clientName2} Adapter ${NC}: edit ${configDir}/taosadapter.toml"
if ((${service_mod} == 0)); then
- echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${csudo}systemctl start ${serverName}${NC}"
+ echo -e "${GREEN_DARK}To start ${productName2} ${NC}: ${csudo}systemctl start ${serverName}${NC}"
[ -f ${service_config_dir}/taosadapter.service ] && [ -f ${installDir}/bin/taosadapter ] && \
- echo -e "${GREEN_DARK}To start Taos Adatper ${NC}: ${csudo}systemctl start taosadapter ${NC}"
+ echo -e "${GREEN_DARK}To start ${clientName2} Adapter ${NC}: ${csudo}systemctl start taosadapter ${NC}"
elif ((${service_mod} == 1)); then
- echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${csudo}service ${serverName} start${NC}"
+ echo -e "${GREEN_DARK}To start ${productName2} ${NC}: ${csudo}service ${serverName} start${NC}"
[ -f ${service_config_dir}/taosadapter.service ] && [ -f ${installDir}/bin/taosadapter ] && \
- echo -e "${GREEN_DARK}To start Taos Adapter ${NC}: ${csudo}service taosadapter start${NC}"
+ echo -e "${GREEN_DARK}To start ${clientName2} Adapter ${NC}: ${csudo}service taosadapter start${NC}"
else
- echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${serverName}${NC}"
+ echo -e "${GREEN_DARK}To start ${productName2} ${NC}: ${serverName}${NC}"
[ -f ${installDir}/bin/taosadapter ] && \
- echo -e "${GREEN_DARK}To start Taos Adapter ${NC}: taosadapter &${NC}"
+ echo -e "${GREEN_DARK}To start ${clientName2} Adapter ${NC}: taosadapter &${NC}"
fi
if [ ! -z "$firstEp" ]; then
@@ -970,24 +970,24 @@ function installProduct() {
tmpPort=""
fi
if [[ "$tmpPort" != "" ]]; then
- echo -e "${GREEN_DARK}To access ${productName} ${NC}: ${clientName} -h $tmpFqdn -P $tmpPort${GREEN_DARK} to login into cluster, then${NC}"
+ echo -e "${GREEN_DARK}To access ${productName2} ${NC}: ${clientName2} -h $tmpFqdn -P $tmpPort${GREEN_DARK} to login into cluster, then${NC}"
else
- echo -e "${GREEN_DARK}To access ${productName} ${NC}: ${clientName} -h $tmpFqdn${GREEN_DARK} to login into cluster, then${NC}"
+ echo -e "${GREEN_DARK}To access ${productName2} ${NC}: ${clientName2} -h $tmpFqdn${GREEN_DARK} to login into cluster, then${NC}"
fi
echo -e "${GREEN_DARK}execute ${NC}: create dnode 'newDnodeFQDN:port'; ${GREEN_DARK}to add this new node${NC}"
echo
elif [ ! -z "$serverFqdn" ]; then
- echo -e "${GREEN_DARK}To access ${productName} ${NC}: ${clientName} -h $serverFqdn${GREEN_DARK} to login into ${productName} server${NC}"
+ echo -e "${GREEN_DARK}To access ${productName2} ${NC}: ${clientName2} -h $serverFqdn${GREEN_DARK} to login into ${productName2} server${NC}"
echo
fi
- echo -e "\033[44;32;1m${productName} is installed successfully!${NC}"
+ echo -e "\033[44;32;1m${productName2} is installed successfully!${NC}"
echo
else # Only install client
install_bin
install_config
echo
- echo -e "\033[44;32;1m${productName} client is installed successfully!${NC}"
+ echo -e "\033[44;32;1m${productName2} client is installed successfully!${NC}"
fi
touch ~/.${historyFile}
diff --git a/packaging/tools/install_client.sh b/packaging/tools/install_client.sh
index 1543c59297..d941fbc0cb 100755
--- a/packaging/tools/install_client.sh
+++ b/packaging/tools/install_client.sh
@@ -17,7 +17,7 @@ serverName="taosd"
clientName="taos"
uninstallScript="rmtaos"
configFile="taos.cfg"
-tarName="taos.tar.gz"
+tarName="package.tar.gz"
osType=Linux
pagMode=full
diff --git a/packaging/tools/make_install.sh b/packaging/tools/make_install.sh
index 5725560bd6..f6fc64d875 100755
--- a/packaging/tools/make_install.sh
+++ b/packaging/tools/make_install.sh
@@ -606,23 +606,23 @@ function update_TDengine() {
echo -e "${GREEN_DARK}To configure ${productName} ${NC}: edit ${configDir}/${configFile}"
[ -f ${configDir}/taosadapter.toml ] && [ -f ${installDir}/bin/taosadapter ] && \
- echo -e "${GREEN_DARK}To configure Taos Adapter ${NC}: edit ${configDir}/taosadapter.toml"
+ echo -e "${GREEN_DARK}To configure Adapter ${NC}: edit ${configDir}/taosadapter.toml"
if ((${service_mod} == 0)); then
echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${csudo}systemctl start ${serverName}${NC}"
[ -f ${service_config_dir}/taosadapter.service ] && [ -f ${installDir}/bin/taosadapter ] && \
- echo -e "${GREEN_DARK}To start Taos Adatper ${NC}: ${csudo}systemctl start taosadapter ${NC}"
+ echo -e "${GREEN_DARK}To start Adapter ${NC}: ${csudo}systemctl start taosadapter ${NC}"
elif ((${service_mod} == 1)); then
echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${csudo}service ${serverName} start${NC}"
[ -f ${service_config_dir}/taosadapter.service ] && [ -f ${installDir}/bin/taosadapter ] && \
- echo -e "${GREEN_DARK}To start Taos Adapter ${NC}: ${csudo}service taosadapter start${NC}"
+ echo -e "${GREEN_DARK}To start Adapter ${NC}: ${csudo}service taosadapter start${NC}"
else
if [ "$osType" != "Darwin" ]; then
echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${serverName}${NC}"
[ -f ${installDir}/bin/taosadapter ] && \
- echo -e "${GREEN_DARK}To start Taos Adapter ${NC}: taosadapter &${NC}"
+ echo -e "${GREEN_DARK}To start Adapter ${NC}: taosadapter &${NC}"
else
echo -e "${GREEN_DARK}To start service ${NC}: launchctl start com.tdengine.taosd${NC}"
- echo -e "${GREEN_DARK}To start Taos Adapter ${NC}: launchctl start com.tdengine.taosadapter${NC}"
+ echo -e "${GREEN_DARK}To start Adapter ${NC}: launchctl start com.tdengine.taosadapter${NC}"
fi
fi
@@ -658,23 +658,23 @@ function install_TDengine() {
echo
echo -e "${GREEN_DARK}To configure ${productName} ${NC}: edit ${configDir}/${configFile}"
[ -f ${configDir}/taosadapter.toml ] && [ -f ${installDir}/bin/taosadapter ] && \
- echo -e "${GREEN_DARK}To configure Taos Adapter ${NC}: edit ${configDir}/taosadapter.toml"
+ echo -e "${GREEN_DARK}To configure Adapter ${NC}: edit ${configDir}/taosadapter.toml"
if ((${service_mod} == 0)); then
echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${csudo}systemctl start ${serverName}${NC}"
[ -f ${service_config_dir}/taosadapter.service ] && [ -f ${installDir}/bin/taosadapter ] && \
- echo -e "${GREEN_DARK}To start Taos Adapter ${NC}: ${csudo}systemctl start taosadapter ${NC}"
+ echo -e "${GREEN_DARK}To start Adapter ${NC}: ${csudo}systemctl start taosadapter ${NC}"
elif ((${service_mod} == 1)); then
echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${csudo}service ${serverName} start${NC}"
[ -f ${service_config_dir}/taosadapter.service ] && [ -f ${installDir}/bin/taosadapter ] && \
- echo -e "${GREEN_DARK}To start Taos Adapter ${NC}: ${csudo}service taosadapter start${NC}"
+ echo -e "${GREEN_DARK}To start Adapter ${NC}: ${csudo}service taosadapter start${NC}"
else
if [ "$osType" != "Darwin" ]; then
echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${serverName}${NC}"
[ -f ${installDir}/bin/taosadapter ] && \
- echo -e "${GREEN_DARK}To start Taos Adapter ${NC}: taosadapter &${NC}"
+ echo -e "${GREEN_DARK}To start Adapter ${NC}: taosadapter &${NC}"
else
echo -e "${GREEN_DARK}To start service ${NC}: launchctl start com.tdengine.taosd${NC}"
- echo -e "${GREEN_DARK}To start Taos Adapter ${NC}: launchctl start com.tdengine.taosadapter${NC}"
+ echo -e "${GREEN_DARK}To start Adapter ${NC}: launchctl start com.tdengine.taosadapter${NC}"
fi
fi
diff --git a/packaging/tools/makeclient.sh b/packaging/tools/makeclient.sh
index 208bfc183c..f46de0f94b 100755
--- a/packaging/tools/makeclient.sh
+++ b/packaging/tools/makeclient.sh
@@ -24,7 +24,7 @@ clientName2="${12}"
productName="TDengine"
clientName="taos"
configFile="taos.cfg"
-tarName="taos.tar.gz"
+tarName="package.tar.gz"
if [ "$osType" != "Darwin" ]; then
script_dir="$(dirname $(readlink -f $0))"
diff --git a/packaging/tools/makepkg.sh b/packaging/tools/makepkg.sh
index 7ad3cf7b0a..d71d5df47c 100755
--- a/packaging/tools/makepkg.sh
+++ b/packaging/tools/makepkg.sh
@@ -28,7 +28,7 @@ productName="TDengine"
serverName="taosd"
clientName="taos"
configFile="taos.cfg"
-tarName="taos.tar.gz"
+tarName="package.tar.gz"
dumpName="taosdump"
benchmarkName="taosBenchmark"
toolsName="taostools"
@@ -171,22 +171,22 @@ if [ -n "${taostools_bin_files}" ]; then
&& cp ${taostools_bin_files} ${taostools_install_dir}/bin \
&& chmod a+x ${taostools_install_dir}/bin/* || :
- if [ -f ${top_dir}/tools/taos-tools/packaging/tools/install-taostools.sh ]; then
- cp ${top_dir}/tools/taos-tools/packaging/tools/install-taostools.sh \
+ if [ -f ${top_dir}/tools/taos-tools/packaging/tools/install-tools.sh ]; then
+ cp ${top_dir}/tools/taos-tools/packaging/tools/install-tools.sh \
${taostools_install_dir}/ > /dev/null \
- && chmod a+x ${taostools_install_dir}/install-taostools.sh \
- || echo -e "failed to copy install-taostools.sh"
+ && chmod a+x ${taostools_install_dir}/install-tools.sh \
+ || echo -e "failed to copy install-tools.sh"
else
- echo -e "install-taostools.sh not found"
+ echo -e "install-tools.sh not found"
fi
- if [ -f ${top_dir}/tools/taos-tools/packaging/tools/uninstall-taostools.sh ]; then
- cp ${top_dir}/tools/taos-tools/packaging/tools/uninstall-taostools.sh \
+ if [ -f ${top_dir}/tools/taos-tools/packaging/tools/uninstall-tools.sh ]; then
+ cp ${top_dir}/tools/taos-tools/packaging/tools/uninstall-tools.sh \
${taostools_install_dir}/ > /dev/null \
- && chmod a+x ${taostools_install_dir}/uninstall-taostools.sh \
- || echo -e "failed to copy uninstall-taostools.sh"
+ && chmod a+x ${taostools_install_dir}/uninstall-tools.sh \
+ || echo -e "failed to copy uninstall-tools.sh"
else
- echo -e "uninstall-taostools.sh not found"
+ echo -e "uninstall-tools.sh not found"
fi
if [ -f ${build_dir}/lib/libavro.so.23.0.0 ]; then
diff --git a/packaging/tools/post.sh b/packaging/tools/post.sh
index 78eb7f7587..9861806677 100755
--- a/packaging/tools/post.sh
+++ b/packaging/tools/post.sh
@@ -530,7 +530,7 @@ function install_service_on_sysvinit() {
function clean_service_on_systemd() {
taosd_service_config="${service_config_dir}/taosd.service"
- # taosd service already is stoped before install in preinst script
+ # taosd service already is stopped before install in preinst script
#if systemctl is-active --quiet taosd; then
# echo "TDengine is running, stopping it..."
# ${csudo}systemctl stop taosd &> /dev/null || echo &> /dev/null
diff --git a/packaging/tools/release_note b/packaging/tools/release_note
index 4578a4523c..81b09ba69c 100644
--- a/packaging/tools/release_note
+++ b/packaging/tools/release_note
@@ -72,7 +72,7 @@ New Features:
taos-1.4.13 (Released on 2018-12-14)
Bugs Fixed:
- - Clients failed to connect to server due to unexpected and invalid packets recieved by the server.
+ - Clients failed to connect to server due to unexpected and invalid packets received by the server.
Features Added:
- Add support to HikariCP in TSDB JDBC driver.
diff --git a/packaging/tools/repair_link.sh b/packaging/tools/repair_link.sh
index 7fd503f270..d71a16023e 100755
--- a/packaging/tools/repair_link.sh
+++ b/packaging/tools/repair_link.sh
@@ -8,7 +8,7 @@ read -p "Please enter link directory such as /var/lib/taos/tsdb: " linkDir
while true; do
if [ ! -d $linkDir ]; then
- read -p "Paht not exists, please enter the correct link path:" linkDir
+ read -p "Path not exists, please enter the correct link path:" linkDir
continue
fi
break
@@ -28,12 +28,12 @@ for linkFile in $(find -L $linkDir -xtype l); do
if [ -z "${dirHash["$dirName"]}" ]; then
read -p "Please enter the directory to replace ${dirName}:" newDir
- read -p "Do you want to replcace all[y/N]?" replcaceAll
- if [[ ( "${replcaceAll}" == "y") || ( "${replcaceAll}" == "Y") ]]; then
+ read -p "Do you want to replace all[y/N]?" replaceAll
+ if [[ ( "${replaceAll}" == "y") || ( "${replaceAll}" == "Y") ]]; then
dirHash["$dirName"]="$newDir"
fi
fi
- # Replcace the file
+ # Replace the file
ln -sf "${newDir}/${baseName}" "${linkFile}"
done
diff --git a/packaging/tools/tdengine.iss b/packaging/tools/tdengine.iss
index 02f412f5d4..8676fa2c51 100644
--- a/packaging/tools/tdengine.iss
+++ b/packaging/tools/tdengine.iss
@@ -21,7 +21,7 @@
[Setup]
VersionInfoVersion={#MyAppVersion}
AppId={{A0F7A93C-79C4-485D-B2B8-F0D03DF42FAB}
-AppName={#MyAppName}
+AppName={#CusName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
@@ -64,8 +64,8 @@ Source: {#MyAppSourceDir}\taosdump.exe; DestDir: "{app}"; DestName: "{#CusPrompt
[run]
-Filename: {sys}\sc.exe; Parameters: "create taosd start= DEMAND binPath= ""C:\\{#CusName}\\taosd.exe --win_service""" ; Flags: runhidden
-Filename: {sys}\sc.exe; Parameters: "create taosadapter start= DEMAND binPath= ""C:\\{#CusName}\\taosadapter.exe""" ; Flags: runhidden
+Filename: {sys}\sc.exe; Parameters: "create taosd start= DEMAND binPath= ""C:\\TDengine\\taosd.exe --win_service""" ; Flags: runhidden
+Filename: {sys}\sc.exe; Parameters: "create taosadapter start= DEMAND binPath= ""C:\\TDengine\\taosadapter.exe""" ; Flags: runhidden
[UninstallRun]
RunOnceId: "stoptaosd"; Filename: {sys}\sc.exe; Parameters: "stop taosd" ; Flags: runhidden
diff --git a/packaging/tools/windows_before_install.txt b/packaging/tools/windows_before_install.txt
index ef783bf10b..91cb35d77e 100644
--- a/packaging/tools/windows_before_install.txt
+++ b/packaging/tools/windows_before_install.txt
@@ -1,4 +1,4 @@
-TDengine is a high-efficient, scalable, high-available distributed time-series database, which makes a lot of optimizations on inserting and querying data, which is far more efficient than normal regular databases. So TDengine can meet the high requirements of IOT and other areas on storing and querying a large amount of data.
+TDengine is an open-source, cloud-native time-series database optimized for Internet of Things (IoT), Connected Cars, and Industrial IoT. With its built-in caching, stream processing, and data subscription capabilities, TDengine offers a simplified solution for time-series data processing.
TDengine will be installed under C:\TDengine, users can modify configuration file C:\TDengine\cfg\taos.cfg, set the log file path or other parameters.
To start/stop TDengine with administrator privileges: sc start/stop taosd
diff --git a/source/client/src/clientRawBlockWrite.c b/source/client/src/clientRawBlockWrite.c
index a12f94cf1d..cfd1005181 100644
--- a/source/client/src/clientRawBlockWrite.c
+++ b/source/client/src/clientRawBlockWrite.c
@@ -194,6 +194,7 @@ static char* processCreateStb(SMqMetaRsp* metaRsp) {
SDecoder coder;
char* string = NULL;
+ uDebug("processCreateStb called");
// decode and process req
void* data = POINTER_SHIFT(metaRsp->metaRsp, sizeof(SMsgHead));
int32_t len = metaRsp->metaRspLen - sizeof(SMsgHead);
@@ -203,7 +204,7 @@ static char* processCreateStb(SMqMetaRsp* metaRsp) {
goto _err;
}
string = buildCreateTableJson(&req.schemaRow, &req.schemaTag, req.name, req.suid, TSDB_SUPER_TABLE);
-
+ uDebug("processCreateStb %s", string);
_err:
tDecoderClear(&coder);
return string;
@@ -213,6 +214,7 @@ static char* processAlterStb(SMqMetaRsp* metaRsp) {
SVCreateStbReq req = {0};
SDecoder coder;
char* string = NULL;
+ uDebug("processAlterStb called");
// decode and process req
void* data = POINTER_SHIFT(metaRsp->metaRsp, sizeof(SMsgHead));
@@ -223,6 +225,7 @@ static char* processAlterStb(SMqMetaRsp* metaRsp) {
goto _err;
}
string = buildAlterSTableJson(req.alterOriData, req.alterOriDataLen);
+ uDebug("processAlterStb %s", string);
_err:
tDecoderClear(&coder);
@@ -346,6 +349,7 @@ static char* processCreateTable(SMqMetaRsp* metaRsp) {
SVCreateTbReq* pCreateReq;
char* string = NULL;
// decode
+ uDebug("processCreateTable called");
void* data = POINTER_SHIFT(metaRsp->metaRsp, sizeof(SMsgHead));
int32_t len = metaRsp->metaRspLen - sizeof(SMsgHead);
tDecoderInit(&decoder, data, len);
@@ -359,9 +363,9 @@ static char* processCreateTable(SMqMetaRsp* metaRsp) {
if (pCreateReq->type == TSDB_CHILD_TABLE) {
string = buildCreateCTableJson(req.pReqs, req.nReqs);
} else if (pCreateReq->type == TSDB_NORMAL_TABLE) {
- string =
- buildCreateTableJson(&pCreateReq->ntb.schemaRow, NULL, pCreateReq->name, pCreateReq->uid, TSDB_NORMAL_TABLE);
+ string = buildCreateTableJson(&pCreateReq->ntb.schemaRow, NULL, pCreateReq->name, pCreateReq->uid, TSDB_NORMAL_TABLE);
}
+ uDebug("processCreateTable :%s", string);
}
_exit:
@@ -377,6 +381,7 @@ _exit:
}
static char* processAutoCreateTable(STaosxRsp* rsp) {
+ uDebug("processAutoCreateTable called");
if (rsp->createTableNum <= 0) {
uError("WriteRaw:processAutoCreateTable rsp->createTableNum <= 0");
goto _exit;
@@ -402,7 +407,7 @@ static char* processAutoCreateTable(STaosxRsp* rsp) {
}
}
string = buildCreateCTableJson(pCreateReq, rsp->createTableNum);
-
+ uDebug("processAutoCreateTable :%s", string);
_exit:
for (int i = 0; i < rsp->createTableNum; i++) {
tDecoderClear(&decoder[i]);
@@ -422,6 +427,7 @@ static char* processAlterTable(SMqMetaRsp* metaRsp) {
char* string = NULL;
cJSON* json = NULL;
+ uDebug("processAlterTable called");
// decode
void* data = POINTER_SHIFT(metaRsp->metaRsp, sizeof(SMsgHead));
int32_t len = metaRsp->metaRspLen - sizeof(SMsgHead);
@@ -527,6 +533,7 @@ static char* processAlterTable(SMqMetaRsp* metaRsp) {
break;
}
string = cJSON_PrintUnformatted(json);
+ uDebug("processAlterTable :%s", string);
_exit:
cJSON_Delete(json);
@@ -539,6 +546,7 @@ static char* processDropSTable(SMqMetaRsp* metaRsp) {
SVDropStbReq req = {0};
char* string = NULL;
cJSON* json = NULL;
+ uDebug("processDropSTable called");
// decode
void* data = POINTER_SHIFT(metaRsp->metaRsp, sizeof(SMsgHead));
@@ -560,7 +568,7 @@ static char* processDropSTable(SMqMetaRsp* metaRsp) {
cJSON_AddItemToObject(json, "tableName", tableName);
string = cJSON_PrintUnformatted(json);
-
+ uDebug("processDropSTable :%s", string);
_exit:
cJSON_Delete(json);
tDecoderClear(&decoder);
@@ -573,6 +581,7 @@ static char* processDeleteTable(SMqMetaRsp* metaRsp) {
cJSON* json = NULL;
char* string = NULL;
+ uDebug("processDeleteTable called");
// decode and process req
void* data = POINTER_SHIFT(metaRsp->metaRsp, sizeof(SMsgHead));
int32_t len = metaRsp->metaRspLen - sizeof(SMsgHead);
@@ -599,7 +608,7 @@ static char* processDeleteTable(SMqMetaRsp* metaRsp) {
cJSON_AddItemToObject(json, "sql", sqlJson);
string = cJSON_PrintUnformatted(json);
-
+ uDebug("processDeleteTable :%s", string);
_exit:
cJSON_Delete(json);
tDecoderClear(&coder);
@@ -612,6 +621,7 @@ static char* processDropTable(SMqMetaRsp* metaRsp) {
char* string = NULL;
cJSON* json = NULL;
+ uDebug("processDropTable called");
// decode
void* data = POINTER_SHIFT(metaRsp->metaRsp, sizeof(SMsgHead));
int32_t len = metaRsp->metaRspLen - sizeof(SMsgHead);
@@ -641,7 +651,7 @@ static char* processDropTable(SMqMetaRsp* metaRsp) {
cJSON_AddItemToObject(json, "tableNameList", tableNameList);
string = cJSON_PrintUnformatted(json);
-
+ uDebug("processDropTable :%s", string);
_exit:
cJSON_Delete(json);
tDecoderClear(&decoder);
@@ -655,6 +665,7 @@ static int32_t taosCreateStb(TAOS* taos, void* meta, int32_t metaLen) {
int32_t code = TSDB_CODE_SUCCESS;
SRequestObj* pRequest = NULL;
+ uDebug("taosCreateStb called");
code = buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest, 0);
if (code != TSDB_CODE_SUCCESS) {
goto end;
@@ -698,6 +709,7 @@ static int32_t taosCreateStb(TAOS* taos, void* meta, int32_t metaLen) {
pReq.source = TD_REQ_FROM_TAOX;
pReq.igExists = true;
+ uDebug("taosCreateStb name:%s suid:%"PRId64" processSuid:%"PRId64, req.name, req.suid, pReq.suid);
STscObj* pTscObj = pRequest->pTscObj;
SName tableName;
tNameExtractFullName(toName(pTscObj->acctId, pRequest->pDb, req.name, &tableName), pReq.name);
@@ -744,6 +756,7 @@ static int32_t taosDropStb(TAOS* taos, void* meta, int32_t metaLen) {
int32_t code = TSDB_CODE_SUCCESS;
SRequestObj* pRequest = NULL;
+ uDebug("taosDropStb called");
code = buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest, 0);
if (code != TSDB_CODE_SUCCESS) {
goto end;
@@ -763,11 +776,37 @@ static int32_t taosDropStb(TAOS* taos, void* meta, int32_t metaLen) {
goto end;
}
+ SCatalog* pCatalog = NULL;
+ code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
+ if (code != TSDB_CODE_SUCCESS) {
+ goto end;
+ }
+ SRequestConnInfo conn = {.pTrans = pRequest->pTscObj->pAppInfo->pTransporter,
+ .requestId = pRequest->requestId,
+ .requestObjRefId = pRequest->self,
+ .mgmtEps = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp)};
+ SName pName = {0};
+ toName(pRequest->pTscObj->acctId, pRequest->pDb, req.name, &pName);
+ STableMeta *pTableMeta = NULL;
+ code = catalogGetTableMeta(pCatalog, &conn, &pName, &pTableMeta);
+ if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST){
+ code = TSDB_CODE_SUCCESS;
+ taosMemoryFreeClear(pTableMeta);
+ goto end;
+ }
+ if (code != TSDB_CODE_SUCCESS) {
+ uError("taosCreateTable:catalogGetTableMeta failed. table name: %s", req.name);
+ goto end;
+ }
+ pReq.suid = pTableMeta->uid;
+ taosMemoryFreeClear(pTableMeta);
+
// build drop stable
pReq.igNotExists = true;
pReq.source = TD_REQ_FROM_TAOX;
- pReq.suid = processSuid(req.suid, pRequest->pDb);
+// pReq.suid = processSuid(req.suid, pRequest->pDb);
+ uDebug("taosDropStb name:%s suid:%"PRId64" new suid:%"PRId64, req.name, req.suid, pReq.suid);
STscObj* pTscObj = pRequest->pTscObj;
SName tableName = {0};
tNameExtractFullName(toName(pTscObj->acctId, pRequest->pDb, req.name, &tableName), pReq.name);
@@ -792,7 +831,7 @@ static int32_t taosDropStb(TAOS* taos, void* meta, int32_t metaLen) {
launchQueryImpl(pRequest, &pQuery, true, NULL);
if (pRequest->code == TSDB_CODE_SUCCESS) {
- SCatalog* pCatalog = NULL;
+// SCatalog* pCatalog = NULL;
catalogGetHandle(pTscObj->pAppInfo->clusterId, &pCatalog);
catalogRemoveTableMeta(pCatalog, &tableName);
}
@@ -825,6 +864,7 @@ static int32_t taosCreateTable(TAOS* taos, void* meta, int32_t metaLen) {
SQuery* pQuery = NULL;
SHashObj* pVgroupHashmap = NULL;
+ uDebug("taosCreateTable called");
code = buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest, 0);
if (code != TSDB_CODE_SUCCESS) {
goto end;
@@ -884,13 +924,16 @@ static int32_t taosCreateTable(TAOS* taos, void* meta, int32_t metaLen) {
if (pCreateReq->type == TSDB_CHILD_TABLE) {
STableMeta* pTableMeta = NULL;
SName sName = {0};
- pCreateReq->ctb.suid = processSuid(pCreateReq->ctb.suid, pRequest->pDb);
+ tb_uid_t oldSuid = pCreateReq->ctb.suid;
+// pCreateReq->ctb.suid = processSuid(pCreateReq->ctb.suid, pRequest->pDb);
toName(pTscObj->acctId, pRequest->pDb, pCreateReq->ctb.stbName, &sName);
code = catalogGetTableMeta(pCatalog, &conn, &sName, &pTableMeta);
if (code != TSDB_CODE_SUCCESS) {
uError("taosCreateTable:catalogGetTableMeta failed. table name: %s", pCreateReq->ctb.stbName);
goto end;
}
+ pCreateReq->ctb.suid = pTableMeta->uid;
+ uDebug("taosCreateTable name:%s sname:%s suid:%"PRId64" new suid:%"PRId64, pCreateReq->name, pCreateReq->ctb.stbName, oldSuid, pCreateReq->ctb.suid);
for (int32_t i = 0; i < taosArrayGetSize(pCreateReq->ctb.tagName); i++) {
char* tName = taosArrayGet(pCreateReq->ctb.tagName, i);
@@ -979,6 +1022,7 @@ static int32_t taosDropTable(TAOS* taos, void* meta, int32_t metaLen) {
SQuery* pQuery = NULL;
SHashObj* pVgroupHashmap = NULL;
+ uDebug("taosDropTable called");
code = buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest, 0);
if (code != TSDB_CODE_SUCCESS) {
goto end;
@@ -1022,7 +1066,7 @@ static int32_t taosDropTable(TAOS* taos, void* meta, int32_t metaLen) {
for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
pDropReq = req.pReqs + iReq;
pDropReq->igNotExists = true;
- pDropReq->suid = processSuid(pDropReq->suid, pRequest->pDb);
+// pDropReq->suid = processSuid(pDropReq->suid, pRequest->pDb);
SVgroupInfo pInfo = {0};
SName pName = {0};
@@ -1032,6 +1076,22 @@ static int32_t taosDropTable(TAOS* taos, void* meta, int32_t metaLen) {
goto end;
}
+ STableMeta *pTableMeta = NULL;
+ code = catalogGetTableMeta(pCatalog, &conn, &pName, &pTableMeta);
+ if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST){
+ code = TSDB_CODE_SUCCESS;
+ taosMemoryFreeClear(pTableMeta);
+ continue;
+ }
+ if (code != TSDB_CODE_SUCCESS) {
+ uError("taosDropTable:catalogGetTableMeta failed. table name: %s", pDropReq->name);
+ goto end;
+ }
+ tb_uid_t oldSuid = pDropReq->suid;
+ pDropReq->suid = pTableMeta->suid;
+ taosMemoryFreeClear(pTableMeta);
+ uDebug("taosDropTable name:%s suid:%"PRId64" new suid:%"PRId64, pDropReq->name, oldSuid, pDropReq->suid);
+
taosArrayPush(pRequest->tableList, &pName);
SVgroupDropTableBatch* pTableBatch = taosHashGet(pVgroupHashmap, &pInfo.vgId, sizeof(pInfo.vgId));
if (pTableBatch == NULL) {
@@ -1046,6 +1106,9 @@ static int32_t taosDropTable(TAOS* taos, void* meta, int32_t metaLen) {
}
}
+ if (taosHashGetSize(pVgroupHashmap) == 0){
+ goto end;
+ }
SArray* pBufArray = serializeVgroupsDropTableBatch(pVgroupHashmap);
if (NULL == pBufArray) {
code = TSDB_CODE_OUT_OF_MEMORY;
@@ -1114,6 +1177,7 @@ static int32_t taosDeleteData(TAOS* taos, void* meta, int32_t metaLen) {
SDecoder coder = {0};
int32_t code = TSDB_CODE_SUCCESS;
+ uDebug("taosDeleteData called");
// decode and process req
void* data = POINTER_SHIFT(meta, sizeof(SMsgHead));
int32_t len = metaLen - sizeof(SMsgHead);
@@ -1151,6 +1215,7 @@ static int32_t taosAlterTable(TAOS* taos, void* meta, int32_t metaLen) {
SArray* pArray = NULL;
SVgDataBlocks* pVgData = NULL;
+ uDebug("taosAlterTable called");
code = buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest, 0);
if (code != TSDB_CODE_SUCCESS) {
@@ -1196,6 +1261,7 @@ static int32_t taosAlterTable(TAOS* taos, void* meta, int32_t metaLen) {
goto end;
}
+ uDebug("taosAlterTable name:%s", req.tbName);
pArray = taosArrayInit(1, sizeof(void*));
if (NULL == pArray) {
code = TSDB_CODE_OUT_OF_MEMORY;
@@ -1261,6 +1327,7 @@ int taos_write_raw_block_with_fields(TAOS* taos, int rows, char* pData, const ch
STableMeta* pTableMeta = NULL;
SQuery* pQuery = NULL;
SHashObj* pVgHash = NULL;
+ uDebug("taos_write_raw_block_with_fields called");
SRequestObj* pRequest = (SRequestObj*)createRequest(*(int64_t*)taos, TSDB_SQL_INSERT, 0);
if (!pRequest) {
@@ -1280,6 +1347,7 @@ int taos_write_raw_block_with_fields(TAOS* taos, int rows, char* pData, const ch
tstrncpy(pName.dbname, pRequest->pDb, sizeof(pName.dbname));
tstrncpy(pName.tname, tbname, sizeof(pName.tname));
+ uDebug("taos_write_raw_block_with_fields name:%s", tbname);
struct SCatalog* pCatalog = NULL;
code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
if (code != TSDB_CODE_SUCCESS) {
@@ -1342,6 +1410,7 @@ int taos_write_raw_block(TAOS* taos, int rows, char* pData, const char* tbname)
SQuery* pQuery = NULL;
SHashObj* pVgHash = NULL;
+ uDebug("taos_write_raw_block called");
SRequestObj* pRequest = (SRequestObj*)createRequest(*(int64_t*)taos, TSDB_SQL_INSERT, 0);
if (!pRequest) {
uError("WriteRaw:createRequest error request is null");
@@ -1360,6 +1429,7 @@ int taos_write_raw_block(TAOS* taos, int rows, char* pData, const char* tbname)
tstrncpy(pName.dbname, pRequest->pDb, sizeof(pName.dbname));
tstrncpy(pName.tname, tbname, sizeof(pName.tname));
+ uDebug("taos_write_raw_block name:%s", tbname);
struct SCatalog* pCatalog = NULL;
code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
if (code != TSDB_CODE_SUCCESS) {
@@ -1423,6 +1493,7 @@ static int32_t tmqWriteRawDataImpl(TAOS* taos, void* data, int32_t dataLen) {
SMqRspObj rspObj = {0};
SDecoder decoder = {0};
STableMeta* pTableMeta = NULL;
+ uDebug("tmqWriteRawDataImpl called");
terrno = TSDB_CODE_SUCCESS;
SRequestObj* pRequest = (SRequestObj*)createRequest(*(int64_t*)taos, TSDB_SQL_INSERT, 0);
@@ -1468,7 +1539,7 @@ static int32_t tmqWriteRawDataImpl(TAOS* taos, void* data, int32_t dataLen) {
goto end;
}
pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
- uDebug("raw data block num:%d\n", rspObj.rsp.blockNum);
+ uDebug("tmqWriteRawDataImpl raw data block num:%d", rspObj.rsp.blockNum);
while (++rspObj.resIter < rspObj.rsp.blockNum) {
SRetrieveTableRsp* pRetrieve = (SRetrieveTableRsp*)taosArrayGetP(rspObj.rsp.blockData, rspObj.resIter);
if (!rspObj.rsp.withSchema) {
@@ -1483,7 +1554,7 @@ static int32_t tmqWriteRawDataImpl(TAOS* taos, void* data, int32_t dataLen) {
goto end;
}
- uDebug("raw data tbname:%s\n", tbName);
+ uDebug("tmqWriteRawDataImpl raw data tbname:%s", tbName);
SName pName = {TSDB_TABLE_NAME_T, pRequest->pTscObj->acctId, {0}, {0}};
strcpy(pName.dbname, pRequest->pDb);
strcpy(pName.tname, tbName);
@@ -1556,6 +1627,7 @@ static int32_t tmqWriteRawMetaDataImpl(TAOS* taos, void* data, int32_t dataLen)
SDecoder decoder = {0};
STableMeta* pTableMeta = NULL;
SVCreateTbReq* pCreateReqDst = NULL;
+ uDebug("tmqWriteRawMetaDataImpl called");
terrno = TSDB_CODE_SUCCESS;
SRequestObj* pRequest = (SRequestObj*)createRequest(*(int64_t*)taos, TSDB_SQL_INSERT, 0);
@@ -1602,7 +1674,7 @@ static int32_t tmqWriteRawMetaDataImpl(TAOS* taos, void* data, int32_t dataLen)
}
pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
- uDebug("raw data block num:%d\n", rspObj.rsp.blockNum);
+ uDebug("tmqWriteRawMetaDataImpl raw data block num:%d", rspObj.rsp.blockNum);
while (++rspObj.resIter < rspObj.rsp.blockNum) {
SRetrieveTableRsp* pRetrieve = (SRetrieveTableRsp*)taosArrayGetP(rspObj.rsp.blockData, rspObj.resIter);
if (!rspObj.rsp.withSchema) {
@@ -1617,7 +1689,7 @@ static int32_t tmqWriteRawMetaDataImpl(TAOS* taos, void* data, int32_t dataLen)
goto end;
}
- uDebug("raw data tbname:%s\n", tbName);
+ uDebug("tmqWriteRawMetaDataImpl raw data tbname:%s\n", tbName);
SName pName = {TSDB_TABLE_NAME_T, pRequest->pTscObj->acctId, {0}, {0}};
strcpy(pName.dbname, pRequest->pDb);
strcpy(pName.tname, tbName);
@@ -1644,7 +1716,7 @@ static int32_t tmqWriteRawMetaDataImpl(TAOS* taos, void* data, int32_t dataLen)
}
if (strcmp(tbName, pCreateReq.name) == 0) {
cloneSVreateTbReq(&pCreateReq, &pCreateReqDst);
- pCreateReqDst->ctb.suid = processSuid(pCreateReqDst->ctb.suid, pRequest->pDb);
+// pCreateReqDst->ctb.suid = processSuid(pCreateReqDst->ctb.suid, pRequest->pDb);
tDecoderClear(&decoderTmp);
break;
}
@@ -1677,6 +1749,7 @@ static int32_t tmqWriteRawMetaDataImpl(TAOS* taos, void* data, int32_t dataLen)
if (pCreateReqDst) {
pTableMeta->vgId = vg.vgId;
pTableMeta->uid = pCreateReqDst->uid;
+ pCreateReqDst->ctb.suid = pTableMeta->suid;
}
void* hData = taosHashGet(pVgHash, &vg.vgId, sizeof(vg.vgId));
if (hData == NULL) {
@@ -1726,6 +1799,7 @@ end:
}
char* tmq_get_json_meta(TAOS_RES* res) {
+ uDebug("tmq_get_json_meta called");
if (!TD_RES_TMQ_META(res) && !TD_RES_TMQ_METADATA(res)) {
return NULL;
}
@@ -1760,6 +1834,7 @@ char* tmq_get_json_meta(TAOS_RES* res) {
void tmq_free_json_meta(char* jsonMeta) { taosMemoryFreeClear(jsonMeta); }
int32_t tmq_get_raw(TAOS_RES* res, tmq_raw_data* raw) {
+ uDebug("tmq_get_raw called");
if (!raw || !res) {
return TSDB_CODE_INVALID_PARA;
}
@@ -1768,6 +1843,7 @@ int32_t tmq_get_raw(TAOS_RES* res, tmq_raw_data* raw) {
raw->raw = pMetaRspObj->metaRsp.metaRsp;
raw->raw_len = pMetaRspObj->metaRsp.metaRspLen;
raw->raw_type = pMetaRspObj->metaRsp.resMsgType;
+ uDebug("tmq_get_raw meta");
} else if (TD_RES_TMQ(res)) {
SMqRspObj* rspObj = ((SMqRspObj*)res);
@@ -1787,6 +1863,7 @@ int32_t tmq_get_raw(TAOS_RES* res, tmq_raw_data* raw) {
raw->raw = buf;
raw->raw_len = len;
raw->raw_type = RES_TYPE__TMQ;
+ uDebug("tmq_get_raw data");
} else if (TD_RES_TMQ_METADATA(res)) {
SMqTaosxRspObj* rspObj = ((SMqTaosxRspObj*)res);
@@ -1806,19 +1883,23 @@ int32_t tmq_get_raw(TAOS_RES* res, tmq_raw_data* raw) {
raw->raw = buf;
raw->raw_len = len;
raw->raw_type = RES_TYPE__TMQ_METADATA;
+ uDebug("tmq_get_raw meta data");
} else {
+ uError("tmq_get_raw error:%d", *(int8_t*)res);
return TSDB_CODE_TMQ_INVALID_MSG;
}
return TSDB_CODE_SUCCESS;
}
void tmq_free_raw(tmq_raw_data raw) {
+ uDebug("tmq_free_raw raw_type:%d", raw.raw_type);
if (raw.raw_type == RES_TYPE__TMQ || raw.raw_type == RES_TYPE__TMQ_METADATA) {
taosMemoryFree(raw.raw);
}
}
int32_t tmq_write_raw(TAOS* taos, tmq_raw_data raw) {
+ uDebug("tmq_write_raw called");
if (!taos) {
return TSDB_CODE_INVALID_PARA;
}
diff --git a/source/client/src/clientTmq.c b/source/client/src/clientTmq.c
index 9f24deff94..45bf69c450 100644
--- a/source/client/src/clientTmq.c
+++ b/source/client/src/clientTmq.c
@@ -20,18 +20,10 @@
#include "tdatablock.h"
#include "tdef.h"
#include "tglobal.h"
-#include "tmsgtype.h"
#include "tqueue.h"
#include "tref.h"
#include "ttimer.h"
-#if 0
-#undef tsem_post
-#define tsem_post(x) \
- tscInfo("call sem post at %s %d", __FUNCTION__, __LINE__); \
- sem_post(x)
-#endif
-
struct SMqMgmt {
int8_t inited;
tmr_h timer;
@@ -106,17 +98,13 @@ struct tmq_t {
tmr_h reportTimer;
tmr_h commitTimer;
- // connection
- STscObj* pTscObj;
-
- // container
- SArray* clientTopics; // SArray
- STaosQueue* mqueue; // queue of rsp
- STaosQall* qall;
- STaosQueue* delayedTask; // delayed task queue for heartbeat and auto commit
-
- // ctl
- tsem_t rspSem;
+ STscObj* pTscObj; // connection
+ SArray* clientTopics; // SArray
+ STaosQueue* mqueue; // queue of rsp
+ STaosQall* qall;
+ STaosQueue* delayedTask; // delayed task queue for heartbeat and auto commit
+ TdThreadMutex lock; // used to protect the operation on each topic, when updating the epsets.
+ tsem_t rspSem;
};
enum {
@@ -138,20 +126,17 @@ enum {
};
typedef struct {
- // statistics
- int64_t pollCnt;
- // offset
+ int64_t pollCnt;
STqOffsetVal committedOffset;
STqOffsetVal currentOffset;
- // connection info
- int32_t vgId;
- int32_t vgStatus;
- int32_t vgSkipCnt;
- SEpSet epSet;
+ int32_t vgId;
+ int32_t vgStatus;
+ int32_t vgSkipCnt;
+ int64_t emptyBlockReceiveTs; // once empty block is received, idle for ignoreCnt then start to poll data
+ SEpSet epSet;
} SMqClientVg;
typedef struct {
- // subscribe info
char topicName[TSDB_TOPIC_FNAME_LEN];
char db[TSDB_DB_FNAME_LEN];
SArray* vgs; // SArray
@@ -163,6 +148,7 @@ typedef struct {
int32_t epoch;
SMqClientVg* vgHandle;
SMqClientTopic* topicHandle;
+ uint64_t reqId;
union {
SMqDataRsp dataRsp;
SMqMetaRsp metaRsp;
@@ -213,12 +199,17 @@ typedef struct {
typedef struct {
SMqCommitCbParamSet* params;
STqOffset* pOffset;
- SMqClientVg* pMqVg;
- /*char topicName[TSDB_TOPIC_FNAME_LEN];*/
- /*int32_t vgId;*/
+ char topicName[TSDB_TOPIC_FNAME_LEN];
+ int32_t vgId;
+ tmq_t* pTmq;
} SMqCommitCbParam;
static int32_t tmqAskEp(tmq_t* tmq, bool async);
+static int32_t makeTopicVgroupKey(char* dst, const char* topicName, int32_t vg);
+static int32_t tmqCommitDone(SMqCommitCbParamSet* pParamSet);
+static int32_t doSendCommitMsg(tmq_t* tmq, SMqClientVg* pVg, const char* pTopicName, SMqCommitCbParamSet* pParamSet,
+ int32_t index, int32_t totalVgroups);
+static void tmqCommitRspCountDown(SMqCommitCbParamSet* pParamSet, int64_t consumerId, const char* pTopic, int32_t vgId);
tmq_conf_t* tmq_conf_new() {
tmq_conf_t* conf = taosMemoryCalloc(1, sizeof(tmq_conf_t));
@@ -230,7 +221,7 @@ tmq_conf_t* tmq_conf_new() {
conf->withTbName = false;
conf->autoCommit = true;
conf->autoCommitInterval = 5000;
- conf->resetOffset = TMQ_CONF__RESET_OFFSET__EARLIEAST;
+ conf->resetOffset = TMQ_OFFSET__RESET_EARLIEAST;
conf->hbBgEnable = true;
return conf;
@@ -238,29 +229,35 @@ tmq_conf_t* tmq_conf_new() {
void tmq_conf_destroy(tmq_conf_t* conf) {
if (conf) {
- if (conf->ip) taosMemoryFree(conf->ip);
- if (conf->user) taosMemoryFree(conf->user);
- if (conf->pass) taosMemoryFree(conf->pass);
+ if (conf->ip) {
+ taosMemoryFree(conf->ip);
+ }
+ if (conf->user) {
+ taosMemoryFree(conf->user);
+ }
+ if (conf->pass) {
+ taosMemoryFree(conf->pass);
+ }
taosMemoryFree(conf);
}
}
tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value) {
- if (strcmp(key, "group.id") == 0) {
+ if (strcasecmp(key, "group.id") == 0) {
tstrncpy(conf->groupId, value, TSDB_CGROUP_LEN);
return TMQ_CONF_OK;
}
- if (strcmp(key, "client.id") == 0) {
+ if (strcasecmp(key, "client.id") == 0) {
tstrncpy(conf->clientId, value, 256);
return TMQ_CONF_OK;
}
- if (strcmp(key, "enable.auto.commit") == 0) {
- if (strcmp(value, "true") == 0) {
+ if (strcasecmp(key, "enable.auto.commit") == 0) {
+ if (strcasecmp(value, "true") == 0) {
conf->autoCommit = true;
return TMQ_CONF_OK;
- } else if (strcmp(value, "false") == 0) {
+ } else if (strcasecmp(value, "false") == 0) {
conf->autoCommit = false;
return TMQ_CONF_OK;
} else {
@@ -268,31 +265,31 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value
}
}
- if (strcmp(key, "auto.commit.interval.ms") == 0) {
+ if (strcasecmp(key, "auto.commit.interval.ms") == 0) {
conf->autoCommitInterval = atoi(value);
return TMQ_CONF_OK;
}
- if (strcmp(key, "auto.offset.reset") == 0) {
- if (strcmp(value, "none") == 0) {
- conf->resetOffset = TMQ_CONF__RESET_OFFSET__NONE;
+ if (strcasecmp(key, "auto.offset.reset") == 0) {
+ if (strcasecmp(value, "none") == 0) {
+ conf->resetOffset = TMQ_OFFSET__RESET_NONE;
return TMQ_CONF_OK;
- } else if (strcmp(value, "earliest") == 0) {
- conf->resetOffset = TMQ_CONF__RESET_OFFSET__EARLIEAST;
+ } else if (strcasecmp(value, "earliest") == 0) {
+ conf->resetOffset = TMQ_OFFSET__RESET_EARLIEAST;
return TMQ_CONF_OK;
- } else if (strcmp(value, "latest") == 0) {
- conf->resetOffset = TMQ_CONF__RESET_OFFSET__LATEST;
+ } else if (strcasecmp(value, "latest") == 0) {
+ conf->resetOffset = TMQ_OFFSET__RESET_LATEST;
return TMQ_CONF_OK;
} else {
return TMQ_CONF_INVALID;
}
}
- if (strcmp(key, "msg.with.table.name") == 0) {
- if (strcmp(value, "true") == 0) {
+ if (strcasecmp(key, "msg.with.table.name") == 0) {
+ if (strcasecmp(value, "true") == 0) {
conf->withTbName = true;
return TMQ_CONF_OK;
- } else if (strcmp(value, "false") == 0) {
+ } else if (strcasecmp(value, "false") == 0) {
conf->withTbName = false;
return TMQ_CONF_OK;
} else {
@@ -300,11 +297,11 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value
}
}
- if (strcmp(key, "experimental.snapshot.enable") == 0) {
- if (strcmp(value, "true") == 0) {
+ if (strcasecmp(key, "experimental.snapshot.enable") == 0) {
+ if (strcasecmp(value, "true") == 0) {
conf->snapEnable = true;
return TMQ_CONF_OK;
- } else if (strcmp(value, "false") == 0) {
+ } else if (strcasecmp(value, "false") == 0) {
conf->snapEnable = false;
return TMQ_CONF_OK;
} else {
@@ -312,42 +309,40 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value
}
}
- if (strcmp(key, "experimental.snapshot.batch.size") == 0) {
+ if (strcasecmp(key, "experimental.snapshot.batch.size") == 0) {
conf->snapBatchSize = atoi(value);
return TMQ_CONF_OK;
}
- if (strcmp(key, "enable.heartbeat.background") == 0) {
- if (strcmp(value, "true") == 0) {
+ if (strcasecmp(key, "enable.heartbeat.background") == 0) {
+ if (strcasecmp(value, "true") == 0) {
conf->hbBgEnable = true;
return TMQ_CONF_OK;
- } else if (strcmp(value, "false") == 0) {
+ } else if (strcasecmp(value, "false") == 0) {
conf->hbBgEnable = false;
return TMQ_CONF_OK;
} else {
return TMQ_CONF_INVALID;
}
- return TMQ_CONF_OK;
}
- if (strcmp(key, "td.connect.ip") == 0) {
+ if (strcasecmp(key, "td.connect.ip") == 0) {
conf->ip = taosStrdup(value);
return TMQ_CONF_OK;
}
- if (strcmp(key, "td.connect.user") == 0) {
+ if (strcasecmp(key, "td.connect.user") == 0) {
conf->user = taosStrdup(value);
return TMQ_CONF_OK;
}
- if (strcmp(key, "td.connect.pass") == 0) {
+ if (strcasecmp(key, "td.connect.pass") == 0) {
conf->pass = taosStrdup(value);
return TMQ_CONF_OK;
}
- if (strcmp(key, "td.connect.port") == 0) {
+ if (strcasecmp(key, "td.connect.port") == 0) {
conf->port = atoi(value);
return TMQ_CONF_OK;
}
- if (strcmp(key, "td.connect.db") == 0) {
- /*conf->db = taosStrdup(value);*/
+ if (strcasecmp(key, "td.connect.db") == 0) {
return TMQ_CONF_OK;
}
@@ -355,7 +350,6 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value
}
tmq_list_t* tmq_list_new() {
- //
return (tmq_list_t*)taosArrayInit(0, sizeof(void*));
}
@@ -385,84 +379,100 @@ char** tmq_list_to_c_array(const tmq_list_t* list) {
return container->pData;
}
-static int32_t tmqMakeTopicVgKey(char* dst, const char* topicName, int32_t vg) {
- return sprintf(dst, "%s:%d", topicName, vg);
-}
+static SMqClientVg* foundClientVg(SArray* pTopicList, const char* pName, int32_t vgId, int32_t* index, int32_t* numOfVgroups) {
+ int32_t numOfTopics = taosArrayGetSize(pTopicList);
+ *index = -1;
+ *numOfVgroups = 0;
-int32_t tmqCommitDone(SMqCommitCbParamSet* pParamSet) {
- tmq_t* tmq = taosAcquireRef(tmqMgmt.rsetId, pParamSet->refId);
- if (tmq == NULL) {
- if (!pParamSet->async) {
- tsem_destroy(&pParamSet->rspSem);
+ for(int32_t i = 0; i < numOfTopics; ++i) {
+ SMqClientTopic* pTopic = taosArrayGet(pTopicList, i);
+ if (strcmp(pTopic->topicName, pName) != 0) {
+ continue;
}
- taosMemoryFree(pParamSet);
- terrno = TSDB_CODE_TMQ_CONSUMER_CLOSED;
- return -1;
- }
- // if no more waiting rsp
- if (pParamSet->async) {
- // call async cb func
- if (pParamSet->automatic && tmq->commitCb) {
- tmq->commitCb(tmq, pParamSet->rspErr, tmq->commitCbUserParam);
- } else if (!pParamSet->automatic && pParamSet->userCb) {
- // sem post
- pParamSet->userCb(tmq, pParamSet->rspErr, pParamSet->userParam);
+ *numOfVgroups = taosArrayGetSize(pTopic->vgs);
+ for (int32_t j = 0; j < (*numOfVgroups); ++j) {
+ SMqClientVg* pClientVg = taosArrayGet(pTopic->vgs, j);
+ if (pClientVg->vgId == vgId) {
+ *index = j;
+ return pClientVg;
+ }
}
- taosMemoryFree(pParamSet);
- } else {
- tsem_post(&pParamSet->rspSem);
}
-#if 0
- taosArrayDestroyP(pParamSet->successfulOffsets, taosMemoryFree);
- taosArrayDestroyP(pParamSet->failedOffsets, taosMemoryFree);
-#endif
- return 0;
+ return NULL;
}
-static void tmqCommitRspCountDown(SMqCommitCbParamSet* pParamSet) {
- int32_t waitingRspNum = atomic_sub_fetch_32(&pParamSet->waitingRspNum, 1);
- if (waitingRspNum == 0) {
- tmqCommitDone(pParamSet);
- }
-}
-
-int32_t tmqCommitCb(void* param, SDataBuf* pBuf, int32_t code) {
+static int32_t tmqCommitCb(void* param, SDataBuf* pBuf, int32_t code) {
SMqCommitCbParam* pParam = (SMqCommitCbParam*)param;
SMqCommitCbParamSet* pParamSet = (SMqCommitCbParamSet*)pParam->params;
- // push into array
-#if 0
- if (code == 0) {
- taosArrayPush(pParamSet->failedOffsets, &pParam->pOffset);
- } else {
- taosArrayPush(pParamSet->successfulOffsets, &pParam->pOffset);
- }
-#endif
- // there may be race condition. fix it
- if (pBuf->pEpSet != NULL && pParam->pMqVg != NULL) {
- SMqClientVg* pMqVg = pParam->pMqVg;
+ if (code != TSDB_CODE_SUCCESS) { // if commit offset failed, let's try again
+ taosThreadMutexLock(&pParam->pTmq->lock);
+ int32_t numOfVgroups, index;
+ SMqClientVg* pVg = foundClientVg(pParam->pTmq->clientTopics, pParam->topicName, pParam->vgId, &index, &numOfVgroups);
- SEp* pEp = GET_ACTIVE_EP(pBuf->pEpSet);
- SEp* pOld = GET_ACTIVE_EP(&(pMqVg->epSet));
- uDebug("subKey:%s update the epset vgId:%d, ep:%s:%d, old ep:%s:%d", pParam->pOffset->subKey, pMqVg->vgId,
- pEp->fqdn, pEp->port, pOld->fqdn, pOld->port);
- pParam->pMqVg->epSet = *pBuf->pEpSet;
+ if (pVg == NULL) {
+ tscDebug("consumer:0x%" PRIx64
+ " subKey:%s vgId:%d commit failed, code:%s has been transferred to other consumer, no need retry ordinal:%d/%d",
+ pParam->pTmq->consumerId, pParam->pOffset->subKey, pParam->vgId, tstrerror(code), index + 1, numOfVgroups);
+ } else { // let's retry the commit
+ int32_t code1 = doSendCommitMsg(pParam->pTmq, pVg, pParam->topicName, pParamSet, index, numOfVgroups);
+ if (code1 != TSDB_CODE_SUCCESS) { // retry failed.
+ tscError("consumer:0x%" PRIx64 " topic:%s vgId:%d offset:%" PRId64
+ " retry failed, ignore this commit. code:%s ordinal:%d/%d",
+ pParam->pTmq->consumerId, pParam->topicName, pVg->vgId, pVg->committedOffset.version,
+ tstrerror(terrno), index + 1, numOfVgroups);
+ }
+ }
+
+ taosThreadMutexUnlock(&pParam->pTmq->lock);
+
+ taosMemoryFree(pParam->pOffset);
+ taosMemoryFree(pBuf->pData);
+ taosMemoryFree(pBuf->pEpSet);
+
+ tmqCommitRspCountDown(pParamSet, pParam->pTmq->consumerId, pParam->topicName, pParam->vgId);
+ return 0;
}
+ // todo replace the pTmq with refId
+ taosThreadMutexLock(&pParam->pTmq->lock);
+ tmq_t* pTmq = pParam->pTmq;
+ int32_t index = 0, numOfVgroups = 0;
+
+ SMqClientVg* pVg = foundClientVg(pTmq->clientTopics, pParam->topicName, pParam->vgId, &index, &numOfVgroups);
+ if (pVg == NULL) {
+ tscDebug("consumer:0x%" PRIx64 " subKey:%s vgId:%d has been transferred to other consumer, ordinal:%d/%d",
+ pParam->pTmq->consumerId, pParam->pOffset->subKey, pParam->vgId, index + 1, numOfVgroups);
+ } else { // update the epset if needed
+ if (pBuf->pEpSet != NULL) {
+ SEp* pEp = GET_ACTIVE_EP(pBuf->pEpSet);
+ SEp* pOld = GET_ACTIVE_EP(&(pVg->epSet));
+
+ tscDebug("consumer:0x%" PRIx64 " subKey:%s update the epset vgId:%d, ep:%s:%d, old ep:%s:%d, ordinal:%d/%d",
+ pTmq->consumerId, pParam->pOffset->subKey, pParam->vgId, pEp->fqdn, pEp->port, pOld->fqdn, pOld->port,
+ index + 1, numOfVgroups);
+
+ pVg->epSet = *pBuf->pEpSet;
+ }
+
+ tscDebug("consumer:0x%" PRIx64 " subKey:%s vgId:%d, commit offset success. ordinal:%d/%d", pTmq->consumerId,
+ pParam->pOffset->subKey, pParam->vgId, index + 1, numOfVgroups);
+ }
+
+ taosThreadMutexUnlock(&pParam->pTmq->lock);
+
taosMemoryFree(pParam->pOffset);
taosMemoryFree(pBuf->pData);
taosMemoryFree(pBuf->pEpSet);
- /*tscDebug("receive offset commit cb of %s on vgId:%d, offset is %" PRId64, pParam->pOffset->subKey, pParam->->vgId,
- * pOffset->version);*/
-
- tmqCommitRspCountDown(pParamSet);
+ tmqCommitRspCountDown(pParamSet, pParam->pTmq->consumerId, pParam->topicName, pParam->vgId);
return 0;
}
-static int32_t tmqSendCommitReq(tmq_t* tmq, SMqClientVg* pVg, SMqClientTopic* pTopic, SMqCommitCbParamSet* pParamSet) {
+static int32_t doSendCommitMsg(tmq_t* tmq, SMqClientVg* pVg, const char* pTopicName, SMqCommitCbParamSet* pParamSet,
+ int32_t index, int32_t totalVgroups) {
STqOffset* pOffset = taosMemoryCalloc(1, sizeof(STqOffset));
if (pOffset == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
@@ -474,7 +484,7 @@ static int32_t tmqSendCommitReq(tmq_t* tmq, SMqClientVg* pVg, SMqClientTopic* pT
int32_t groupLen = strlen(tmq->groupId);
memcpy(pOffset->subKey, tmq->groupId, groupLen);
pOffset->subKey[groupLen] = TMQ_SEPARATOR;
- strcpy(pOffset->subKey + groupLen + 1, pTopic->topicName);
+ strcpy(pOffset->subKey + groupLen + 1, pTopicName);
int32_t len;
int32_t code;
@@ -508,7 +518,10 @@ static int32_t tmqSendCommitReq(tmq_t* tmq, SMqClientVg* pVg, SMqClientTopic* pT
pParam->params = pParamSet;
pParam->pOffset = pOffset;
- pParam->pMqVg = pVg; // there may be an race condition
+ pParam->vgId = pVg->vgId;
+ pParam->pTmq = tmq;
+
+ tstrncpy(pParam->topicName, pTopicName, tListLen(pParam->topicName));
// build send info
SMsgSendInfo* pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
@@ -525,30 +538,28 @@ static int32_t tmqSendCommitReq(tmq_t* tmq, SMqClientVg* pVg, SMqClientTopic* pT
.handle = NULL,
};
- SEp* pEp = &pVg->epSet.eps[pVg->epSet.inUse];
- tscDebug("consumer:0x%" PRIx64 " topic:%s on vgId:%d offset:%" PRId64 " prev:%" PRId64 ", ep:%s:%d", tmq->consumerId,
- pOffset->subKey, pVg->vgId, pOffset->val.version, pVg->committedOffset.version, pEp->fqdn, pEp->port);
-
- // TODO: put into cb, the commit offset should be move to the callback function
- pVg->committedOffset = pVg->currentOffset;
-
pMsgSendInfo->requestId = generateRequestId();
pMsgSendInfo->requestObjRefId = 0;
pMsgSendInfo->param = pParam;
pMsgSendInfo->paramFreeFp = taosMemoryFree;
pMsgSendInfo->fp = tmqCommitCb;
pMsgSendInfo->msgType = TDMT_VND_TMQ_COMMIT_OFFSET;
- // send msg
atomic_add_fetch_32(&pParamSet->waitingRspNum, 1);
atomic_add_fetch_32(&pParamSet->totalRspNum, 1);
+ SEp* pEp = GET_ACTIVE_EP(&pVg->epSet);
+ tscDebug("consumer:0x%" PRIx64 " topic:%s on vgId:%d send offset:%" PRId64 " prev:%" PRId64
+ ", ep:%s:%d, ordinal:%d/%d, req:0x%" PRIx64,
+ tmq->consumerId, pOffset->subKey, pVg->vgId, pOffset->val.version, pVg->committedOffset.version, pEp->fqdn,
+ pEp->port, index + 1, totalVgroups, pMsgSendInfo->requestId);
+
int64_t transporterId = 0;
asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &pVg->epSet, &transporterId, pMsgSendInfo);
return 0;
}
-int32_t tmqCommitMsgImpl(tmq_t* tmq, const TAOS_RES* msg, int8_t async, tmq_commit_cb* userCb, void* userParam) {
+static int32_t tmqCommitMsgImpl(tmq_t* tmq, const TAOS_RES* msg, int8_t async, tmq_commit_cb* userCb, void* userParam) {
char* topic;
int32_t vgId;
if (TD_RES_TMQ(msg)) {
@@ -572,6 +583,7 @@ int32_t tmqCommitMsgImpl(tmq_t* tmq, const TAOS_RES* msg, int8_t async, tmq_comm
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
+
pParamSet->refId = tmq->refId;
pParamSet->epoch = tmq->epoch;
pParamSet->automatic = 0;
@@ -582,15 +594,22 @@ int32_t tmqCommitMsgImpl(tmq_t* tmq, const TAOS_RES* msg, int8_t async, tmq_comm
int32_t code = -1;
+ taosThreadMutexLock(&tmq->lock);
for (int32_t i = 0; i < taosArrayGetSize(tmq->clientTopics); i++) {
SMqClientTopic* pTopic = taosArrayGet(tmq->clientTopics, i);
- if (strcmp(pTopic->topicName, topic) != 0) continue;
- for (int32_t j = 0; j < taosArrayGetSize(pTopic->vgs); j++) {
+ if (strcmp(pTopic->topicName, topic) != 0) {
+ continue;
+ }
+
+ int32_t numOfVgroups = taosArrayGetSize(pTopic->vgs);
+ for (int32_t j = 0; j < numOfVgroups; j++) {
SMqClientVg* pVg = taosArrayGet(pTopic->vgs, j);
- if (pVg->vgId != vgId) continue;
+ if (pVg->vgId != vgId) {
+ continue;
+ }
if (pVg->currentOffset.type > 0 && !tOffsetEqual(&pVg->currentOffset, &pVg->committedOffset)) {
- if (tmqSendCommitReq(tmq, pVg, pTopic, pParamSet) < 0) {
+ if (doSendCommitMsg(tmq, pVg, pTopic->topicName, pParamSet, j, numOfVgroups) < 0) {
tsem_destroy(&pParamSet->rspSem);
taosMemoryFree(pParamSet);
goto FAIL;
@@ -604,10 +623,12 @@ HANDLE_RSP:
if (pParamSet->totalRspNum == 0) {
tsem_destroy(&pParamSet->rspSem);
taosMemoryFree(pParamSet);
+ taosThreadMutexUnlock(&tmq->lock);
return 0;
}
if (!async) {
+ taosThreadMutexUnlock(&tmq->lock);
tsem_wait(&pParamSet->rspSem);
code = pParamSet->rspErr;
tsem_destroy(&pParamSet->rspSem);
@@ -618,9 +639,11 @@ HANDLE_RSP:
}
FAIL:
+ taosThreadMutexUnlock(&tmq->lock);
if (code != 0 && async) {
userCb(tmq, code, userParam);
}
+
return 0;
}
@@ -653,26 +676,41 @@ static int32_t tmqCommitConsumerImpl(tmq_t* tmq, int8_t automatic, int8_t async,
// init as 1 to prevent concurrency issue
pParamSet->waitingRspNum = 1;
+ taosThreadMutexLock(&tmq->lock);
int32_t numOfTopics = taosArrayGetSize(tmq->clientTopics);
tscDebug("consumer:0x%" PRIx64 " start to commit offset for %d topics", tmq->consumerId, numOfTopics);
for (int32_t i = 0; i < numOfTopics; i++) {
SMqClientTopic* pTopic = taosArrayGet(tmq->clientTopics, i);
+ int32_t numOfVgroups = taosArrayGetSize(pTopic->vgs);
- int32_t numOfVgroups = taosArrayGetSize(pTopic->vgs);
+ tscDebug("consumer:0x%" PRIx64 " commit offset for topics:%s, numOfVgs:%d", tmq->consumerId, pTopic->topicName,
+ numOfVgroups);
for (int32_t j = 0; j < numOfVgroups; j++) {
SMqClientVg* pVg = taosArrayGet(pTopic->vgs, j);
+
if (pVg->currentOffset.type > 0 && !tOffsetEqual(&pVg->currentOffset, &pVg->committedOffset)) {
- if (tmqSendCommitReq(tmq, pVg, pTopic, pParamSet) < 0) {
+ code = doSendCommitMsg(tmq, pVg, pTopic->topicName, pParamSet, j, numOfVgroups);
+ if (code != TSDB_CODE_SUCCESS) {
+ tscError("consumer:0x%" PRIx64 " topic:%s vgId:%d offset:%" PRId64 " failed, code:%s ordinal:%d/%d",
+ tmq->consumerId, pTopic->topicName, pVg->vgId, pVg->committedOffset.version, tstrerror(terrno),
+ j + 1, numOfVgroups);
continue;
}
+
+ // update the offset value.
+ pVg->committedOffset = pVg->currentOffset;
} else {
- tscDebug("consumer:0x%" PRIx64 " topic:%s vgId:%d, not commit, current:%" PRId64 ", ordinal:%d/%d",
+ tscDebug("consumer:0x%" PRIx64 " topic:%s vgId:%d, no commit, current:%" PRId64 ", ordinal:%d/%d",
tmq->consumerId, pTopic->topicName, pVg->vgId, pVg->currentOffset.version, j + 1, numOfVgroups);
}
}
}
+ tscDebug("consumer:0x%" PRIx64 " total commit:%d for %d topics", tmq->consumerId, pParamSet->waitingRspNum - 1,
+ numOfTopics);
+ taosThreadMutexUnlock(&tmq->lock);
+
// no request is sent
if (pParamSet->totalRspNum == 0) {
tsem_destroy(&pParamSet->rspSem);
@@ -681,7 +719,7 @@ static int32_t tmqCommitConsumerImpl(tmq_t* tmq, int8_t automatic, int8_t async,
}
// count down since waiting rsp num init as 1
- tmqCommitRspCountDown(pParamSet);
+ tmqCommitRspCountDown(pParamSet, tmq->consumerId, "", 0);
if (!async) {
tsem_wait(&pParamSet->rspSem);
@@ -697,11 +735,11 @@ static int32_t tmqCommitConsumerImpl(tmq_t* tmq, int8_t automatic, int8_t async,
return code;
}
-int32_t tmqCommitInner(tmq_t* tmq, const TAOS_RES* msg, int8_t automatic, int8_t async, tmq_commit_cb* userCb,
- void* userParam) {
- if (msg) {
+static int32_t tmqCommitInner(tmq_t* tmq, const TAOS_RES* msg, int8_t automatic, int8_t async, tmq_commit_cb* userCb,
+ void* userParam) {
+ if (msg) { // user invoked commit
return tmqCommitMsgImpl(tmq, msg, async, userCb, userParam);
- } else {
+ } else { // this for auto commit
return tmqCommitConsumerImpl(tmq, automatic, async, userCb, userParam);
}
}
@@ -944,10 +982,14 @@ void tmqFreeImpl(void* handle) {
tmqClearUnhandleMsg(tmq);
taosCloseQueue(tmq->mqueue);
}
- if (tmq->delayedTask) taosCloseQueue(tmq->delayedTask);
- taosFreeQall(tmq->qall);
+ if (tmq->delayedTask) {
+ taosCloseQueue(tmq->delayedTask);
+ }
+
+ taosFreeQall(tmq->qall);
tsem_destroy(&tmq->rspSem);
+ taosThreadMutexDestroy(&tmq->lock);
int32_t sz = taosArrayGetSize(tmq->clientTopics);
for (int32_t i = 0; i < sz; i++) {
@@ -955,6 +997,7 @@ void tmqFreeImpl(void* handle) {
taosMemoryFreeClear(pTopic->schema.pSchema);
taosArrayDestroy(pTopic->vgs);
}
+
taosArrayDestroy(tmq->clientTopics);
taos_close_internal(tmq->pTscObj);
taosMemoryFree(tmq);
@@ -984,7 +1027,7 @@ tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) {
tmq_t* pTmq = taosMemoryCalloc(1, sizeof(tmq_t));
if (pTmq == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
- tscError("failed to create consumer, consumer group %s, code:%s", conf->groupId, terrstr());
+ tscError("failed to create consumer, groupId:%s, code:%s", conf->groupId, terrstr());
return NULL;
}
@@ -993,15 +1036,16 @@ tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) {
pTmq->clientTopics = taosArrayInit(0, sizeof(SMqClientTopic));
pTmq->mqueue = taosOpenQueue();
- pTmq->qall = taosAllocateQall();
pTmq->delayedTask = taosOpenQueue();
+ pTmq->qall = taosAllocateQall();
+ taosThreadMutexInit(&pTmq->lock, NULL);
if (pTmq->clientTopics == NULL || pTmq->mqueue == NULL || pTmq->qall == NULL || pTmq->delayedTask == NULL ||
conf->groupId[0] == 0) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
- tscError("consumer:0x%" PRIx64 " setup failed since %s, consumer group %s", pTmq->consumerId, terrstr(),
+ tscError("consumer:0x%" PRIx64 " setup failed since %s, groupId:%s", pTmq->consumerId, terrstr(),
pTmq->groupId);
- goto FAIL;
+ goto _failed;
}
// init status
@@ -1031,22 +1075,20 @@ tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) {
if (tsem_init(&pTmq->rspSem, 0, 0) != 0) {
tscError("consumer:0x %" PRIx64 " setup failed since %s, consumer group %s", pTmq->consumerId, terrstr(),
pTmq->groupId);
- goto FAIL;
+ goto _failed;
}
// init connection
pTmq->pTscObj = taos_connect_internal(conf->ip, user, pass, NULL, NULL, conf->port, CONN_TYPE__TMQ);
if (pTmq->pTscObj == NULL) {
- tscError("consumer:0x %" PRIx64 " setup failed since %s, consumer group %s", pTmq->consumerId, terrstr(),
- pTmq->groupId);
+ tscError("consumer:0x%" PRIx64 " setup failed since %s, groupId:%s", pTmq->consumerId, terrstr(), pTmq->groupId);
tsem_destroy(&pTmq->rspSem);
- goto FAIL;
+ goto _failed;
}
pTmq->refId = taosAddRef(tmqMgmt.rsetId, pTmq);
if (pTmq->refId < 0) {
- tmqFreeImpl(pTmq);
- return NULL;
+ goto _failed;
}
if (pTmq->hbBgEnable) {
@@ -1055,16 +1097,17 @@ tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) {
pTmq->hbLiveTimer = taosTmrStart(tmqSendHbReq, 1000, pRefId, tmqMgmt.timer);
}
- tscInfo("consumer:0x%" PRIx64 " is setup, groupId:%s", pTmq->consumerId, pTmq->groupId);
+ char buf[80] = {0};
+ STqOffsetVal offset = {.type = pTmq->resetOffsetCfg};
+ tFormatOffset(buf, tListLen(buf), &offset);
+ tscInfo("consumer:0x%" PRIx64 " is setup, groupId:%s, snapshot:%d, autoCommit:%d, commitInterval:%dms, offset:%s, backgroudHB:%d",
+ pTmq->consumerId, pTmq->groupId, pTmq->useSnapshot, pTmq->autoCommit, pTmq->autoCommitInterval, buf,
+ pTmq->hbBgEnable);
+
return pTmq;
-FAIL:
- if (pTmq->clientTopics) taosArrayDestroy(pTmq->clientTopics);
- if (pTmq->mqueue) taosCloseQueue(pTmq->mqueue);
- if (pTmq->delayedTask) taosCloseQueue(pTmq->delayedTask);
- if (pTmq->qall) taosFreeQall(pTmq->qall);
- taosMemoryFree(pTmq);
-
+_failed:
+ tmqFreeImpl(pTmq);
return NULL;
}
@@ -1193,7 +1236,6 @@ FAIL:
}
void tmq_conf_set_auto_commit_cb(tmq_conf_t* conf, tmq_commit_cb* cb, void* param) {
- //
conf->commitCb = cb;
conf->commitCbUserParam = param;
}
@@ -1220,8 +1262,8 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) {
taosMemoryFree(pParam);
if (code != 0) {
- tscWarn("consumer:0x%"PRIx64" msg from vgId:%d discarded, epoch %d, since %s, reqId:0x%"PRIx64, tmq->consumerId, vgId,
- epoch, tstrerror(code), requestId);
+ tscWarn("consumer:0x%" PRIx64 " msg from vgId:%d discarded, epoch %d, since %s, reqId:0x%" PRIx64, tmq->consumerId,
+ vgId, epoch, tstrerror(code), requestId);
if (pMsg->pData) taosMemoryFree(pMsg->pData);
if (pMsg->pEpSet) taosMemoryFree(pMsg->pEpSet);
@@ -1240,10 +1282,7 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) {
}
pRspWrapper->tmqRspType = TMQ_MSG_TYPE__END_RSP;
- /*pRspWrapper->vgHandle = pVg;*/
- /*pRspWrapper->topicHandle = pTopic;*/
taosWriteQitem(tmq->mqueue, pRspWrapper);
- tsem_post(&tmq->rspSem);
}
goto CREATE_MSG_FAIL;
@@ -1263,8 +1302,8 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) {
}
if (msgEpoch != tmqEpoch) {
- tscWarn("consumer:0x%"PRIx64" mismatch rsp from vgId:%d, epoch %d, current epoch %d, reqId:0x%"PRIx64, tmq->consumerId, vgId,
- msgEpoch, tmqEpoch, requestId);
+ tscWarn("consumer:0x%" PRIx64 " mismatch rsp from vgId:%d, epoch %d, current epoch %d, reqId:0x%" PRIx64,
+ tmq->consumerId, vgId, msgEpoch, tmqEpoch, requestId);
}
// handle meta rsp
@@ -1281,6 +1320,7 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) {
pRspWrapper->tmqRspType = rspType;
pRspWrapper->vgHandle = pVg;
pRspWrapper->topicHandle = pTopic;
+ pRspWrapper->reqId = requestId;
if (rspType == TMQ_MSG_TYPE__POLL_RSP) {
SDecoder decoder;
@@ -1289,9 +1329,10 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) {
tDecoderClear(&decoder);
memcpy(&pRspWrapper->dataRsp, pMsg->pData, sizeof(SMqRspHead));
- tscDebug("consumer:0x%" PRIx64 " recv poll rsp, vgId:%d, req offset:%" PRId64 ", rsp offset:%" PRId64 " type %d, reqId:0x%"PRIx64,
- tmq->consumerId, pVg->vgId, pRspWrapper->dataRsp.reqOffset.version, pRspWrapper->dataRsp.rspOffset.version,
- rspType, requestId);
+ tscDebug("consumer:0x%" PRIx64 " recv poll rsp, vgId:%d, req:%" PRId64 ", rsp:%" PRId64
+ " type %d, reqId:0x%" PRIx64,
+ tmq->consumerId, vgId, pRspWrapper->dataRsp.reqOffset.version, pRspWrapper->dataRsp.rspOffset.version, rspType, requestId);
+
} else if (rspType == TMQ_MSG_TYPE__POLL_META_RSP) {
SDecoder decoder;
tDecoderInit(&decoder, POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), pMsg->len - sizeof(SMqRspHead));
@@ -1304,17 +1345,18 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) {
tDecodeSTaosxRsp(&decoder, &pRspWrapper->taosxRsp);
tDecoderClear(&decoder);
memcpy(&pRspWrapper->taosxRsp, pMsg->pData, sizeof(SMqRspHead));
+ } else { // invalid rspType
+ tscError("consumer:0x%"PRIx64" invalid rsp msg received, type:%d ignored", tmq->consumerId, rspType);
}
taosMemoryFree(pMsg->pData);
taosMemoryFree(pMsg->pEpSet);
-
- tscDebug("consumer:0x%" PRIx64 ", put poll res into mqueue, total in queue:%d, reqId:0x%" PRIx64, tmq->consumerId,
- tmq->mqueue->numOfItems, requestId);
-
taosWriteQitem(tmq->mqueue, pRspWrapper);
- tsem_post(&tmq->rspSem);
+ tscDebug("consumer:0x%" PRIx64 " put poll res into mqueue, type:%d, vgId:%d, total in queue:%d, reqId:0x%" PRIx64,
+ tmq->consumerId, rspType, vgId, tmq->mqueue->numOfItems, requestId);
+
+ tsem_post(&tmq->rspSem);
return 0;
CREATE_MSG_FAIL:
@@ -1326,7 +1368,56 @@ CREATE_MSG_FAIL:
return -1;
}
-bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, const SMqAskEpRsp* pRsp) {
+static void initClientTopicFromRsp(SMqClientTopic* pTopic, SMqSubTopicEp* pTopicEp, SHashObj* pVgOffsetHashMap,
+ tmq_t* tmq) {
+ pTopic->schema = pTopicEp->schema;
+ pTopicEp->schema.nCols = 0;
+ pTopicEp->schema.pSchema = NULL;
+
+ char vgKey[TSDB_TOPIC_FNAME_LEN + 22];
+ int32_t vgNumGet = taosArrayGetSize(pTopicEp->vgs);
+
+ tstrncpy(pTopic->topicName, pTopicEp->topic, TSDB_TOPIC_FNAME_LEN);
+ tstrncpy(pTopic->db, pTopicEp->db, TSDB_DB_FNAME_LEN);
+
+ tscDebug("consumer:0x%" PRIx64 ", update topic:%s, numOfVgs:%d", tmq->consumerId, pTopic->topicName, vgNumGet);
+ pTopic->vgs = taosArrayInit(vgNumGet, sizeof(SMqClientVg));
+
+ for (int32_t j = 0; j < vgNumGet; j++) {
+ SMqSubVgEp* pVgEp = taosArrayGet(pTopicEp->vgs, j);
+
+ makeTopicVgroupKey(vgKey, pTopic->topicName, pVgEp->vgId);
+ STqOffsetVal* pOffset = taosHashGet(pVgOffsetHashMap, vgKey, strlen(vgKey));
+
+ STqOffsetVal offsetNew = {.type = tmq->resetOffsetCfg};
+ if (pOffset != NULL) {
+ offsetNew = *pOffset;
+ }
+
+ SMqClientVg clientVg = {
+ .pollCnt = 0,
+ .currentOffset = offsetNew,
+ .vgId = pVgEp->vgId,
+ .epSet = pVgEp->epSet,
+ .vgStatus = TMQ_VG_STATUS__IDLE,
+ .vgSkipCnt = 0,
+ .emptyBlockReceiveTs = 0,
+ };
+
+ taosArrayPush(pTopic->vgs, &clientVg);
+ }
+}
+
+static void freeClientVgInfo(void* param) {
+ SMqClientTopic* pTopic = param;
+ if (pTopic->schema.nCols) {
+ taosMemoryFreeClear(pTopic->schema.pSchema);
+ }
+
+ taosArrayDestroy(pTopic->vgs);
+}
+
+static bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, const SMqAskEpRsp* pRsp) {
bool set = false;
int32_t topicNumCur = taosArrayGetSize(tmq->clientTopics);
@@ -1341,12 +1432,13 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, const SMqAskEpRsp* pRsp) {
return false;
}
- SHashObj* pHash = taosHashInit(64, MurmurHash3_32, false, HASH_NO_LOCK);
- if (pHash == NULL) {
+ SHashObj* pVgOffsetHashMap = taosHashInit(64, MurmurHash3_32, false, HASH_NO_LOCK);
+ if (pVgOffsetHashMap == NULL) {
taosArrayDestroy(newTopics);
return false;
}
+ // todo extract method
for (int32_t i = 0; i < topicNumCur; i++) {
// find old topic
SMqClientTopic* pTopicCur = taosArrayGet(tmq->clientTopics, i);
@@ -1355,12 +1447,13 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, const SMqAskEpRsp* pRsp) {
tscDebug("consumer:0x%" PRIx64 ", new vg num: %d", tmq->consumerId, vgNumCur);
for (int32_t j = 0; j < vgNumCur; j++) {
SMqClientVg* pVgCur = taosArrayGet(pTopicCur->vgs, j);
- sprintf(vgKey, "%s:%d", pTopicCur->topicName, pVgCur->vgId);
+ makeTopicVgroupKey(vgKey, pTopicCur->topicName, pVgCur->vgId);
+
char buf[80];
tFormatOffset(buf, 80, &pVgCur->currentOffset);
tscDebug("consumer:0x%" PRIx64 ", epoch:%d vgId:%d vgKey:%s, offset:%s", tmq->consumerId, epoch,
pVgCur->vgId, vgKey, buf);
- taosHashPut(pHash, vgKey, strlen(vgKey), &pVgCur->currentOffset, sizeof(STqOffsetVal));
+ taosHashPut(pVgOffsetHashMap, vgKey, strlen(vgKey), &pVgCur->currentOffset, sizeof(STqOffsetVal));
}
}
}
@@ -1368,66 +1461,30 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, const SMqAskEpRsp* pRsp) {
for (int32_t i = 0; i < topicNumGet; i++) {
SMqClientTopic topic = {0};
SMqSubTopicEp* pTopicEp = taosArrayGet(pRsp->topics, i);
- topic.schema = pTopicEp->schema;
- pTopicEp->schema.nCols = 0;
- pTopicEp->schema.pSchema = NULL;
- tstrncpy(topic.topicName, pTopicEp->topic, TSDB_TOPIC_FNAME_LEN);
- tstrncpy(topic.db, pTopicEp->db, TSDB_DB_FNAME_LEN);
-
- tscDebug("consumer:0x%" PRIx64 ", update topic: %s", tmq->consumerId, topic.topicName);
-
- int32_t vgNumGet = taosArrayGetSize(pTopicEp->vgs);
- topic.vgs = taosArrayInit(vgNumGet, sizeof(SMqClientVg));
- for (int32_t j = 0; j < vgNumGet; j++) {
- SMqSubVgEp* pVgEp = taosArrayGet(pTopicEp->vgs, j);
- sprintf(vgKey, "%s:%d", topic.topicName, pVgEp->vgId);
- STqOffsetVal* pOffset = taosHashGet(pHash, vgKey, strlen(vgKey));
- STqOffsetVal offsetNew = {.type = tmq->resetOffsetCfg};
- if (pOffset != NULL) {
- offsetNew = *pOffset;
- }
-
- SMqClientVg clientVg = {
- .pollCnt = 0,
- .currentOffset = offsetNew,
- .vgId = pVgEp->vgId,
- .epSet = pVgEp->epSet,
- .vgStatus = TMQ_VG_STATUS__IDLE,
- .vgSkipCnt = 0,
- };
- taosArrayPush(topic.vgs, &clientVg);
- set = true;
- }
+ initClientTopicFromRsp(&topic, pTopicEp, pVgOffsetHashMap, tmq);
taosArrayPush(newTopics, &topic);
}
+ taosHashCleanup(pVgOffsetHashMap);
+
+ taosThreadMutexLock(&tmq->lock);
// destroy current buffered existed topics info
if (tmq->clientTopics) {
- int32_t sz = taosArrayGetSize(tmq->clientTopics);
- for (int32_t i = 0; i < sz; i++) {
- SMqClientTopic* pTopic = taosArrayGet(tmq->clientTopics, i);
- if (pTopic->schema.nCols) taosMemoryFreeClear(pTopic->schema.pSchema);
- taosArrayDestroy(pTopic->vgs);
- }
-
- taosArrayDestroy(tmq->clientTopics);
+ taosArrayDestroyEx(tmq->clientTopics, freeClientVgInfo);
}
- taosHashCleanup(pHash);
tmq->clientTopics = newTopics;
+ taosThreadMutexUnlock(&tmq->lock);
- if (taosArrayGetSize(tmq->clientTopics) == 0) {
- atomic_store_8(&tmq->status, TMQ_CONSUMER_STATUS__NO_TOPIC);
- } else {
- atomic_store_8(&tmq->status, TMQ_CONSUMER_STATUS__READY);
- }
-
+ int8_t flag = (topicNumGet == 0)? TMQ_CONSUMER_STATUS__NO_TOPIC:TMQ_CONSUMER_STATUS__READY;
+ atomic_store_8(&tmq->status, flag);
atomic_store_32(&tmq->epoch, epoch);
+
tscDebug("consumer:0x%" PRIx64 " update topic info completed", tmq->consumerId);
return set;
}
-int32_t tmqAskEpCb(void* param, SDataBuf* pMsg, int32_t code) {
+static int32_t tmqAskEpCb(void* param, SDataBuf* pMsg, int32_t code) {
SMqAskEpCbParam* pParam = (SMqAskEpCbParam*)param;
int8_t async = pParam->async;
tmq_t* tmq = taosAcquireRef(tmqMgmt.rsetId, pParam->refId);
@@ -1445,7 +1502,7 @@ int32_t tmqAskEpCb(void* param, SDataBuf* pMsg, int32_t code) {
}
pParam->code = code;
- if (code != 0) {
+ if (code != TSDB_CODE_SUCCESS) {
tscError("consumer:0x%" PRIx64 ", get topic endpoint error, async:%d, code:%s", tmq->consumerId, pParam->async,
tstrerror(code));
goto END;
@@ -1468,8 +1525,6 @@ int32_t tmqAskEpCb(void* param, SDataBuf* pMsg, int32_t code) {
if (!async) {
SMqAskEpRsp rsp;
tDecodeSMqAskEpRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &rsp);
- /*printf("rsp epoch %" PRId64 " sz %" PRId64 "\n", rsp.epoch, rsp.topics->size);*/
- /*printf("tmq epoch %" PRId64 " sz %" PRId64 "\n", tmq->epoch, tmq->clientTopics->size);*/
tmqUpdateEp(tmq, head->epoch, &rsp);
tDeleteSMqAskEpRsp(&rsp);
} else {
@@ -1490,7 +1545,6 @@ int32_t tmqAskEpCb(void* param, SDataBuf* pMsg, int32_t code) {
}
END:
- /*atomic_store_8(&tmq->epStatus, 0);*/
if (!async) {
tsem_post(&pParam->rspSem);
} else {
@@ -1502,92 +1556,6 @@ END:
return code;
}
-int32_t tmqAskEp(tmq_t* tmq, bool async) {
- int32_t code = TSDB_CODE_SUCCESS;
-#if 0
- int8_t epStatus = atomic_val_compare_exchange_8(&tmq->epStatus, 0, 1);
- if (epStatus == 1) {
- int32_t epSkipCnt = atomic_add_fetch_32(&tmq->epSkipCnt, 1);
- tscTrace("consumer:0x%" PRIx64 ", skip ask ep cnt %d", tmq->consumerId, epSkipCnt);
- if (epSkipCnt < 5000) return 0;
- }
- atomic_store_32(&tmq->epSkipCnt, 0);
-#endif
-
- SMqAskEpReq req = {0};
- req.consumerId = tmq->consumerId;
- req.epoch = tmq->epoch;
- strcpy(req.cgroup, tmq->groupId);
-
- int32_t tlen = tSerializeSMqAskEpReq(NULL, 0, &req);
- if (tlen < 0) {
- tscError("consumer:0x%" PRIx64 ", tSerializeSMqAskEpReq failed", tmq->consumerId);
- return -1;
- }
-
- void* pReq = taosMemoryCalloc(1, tlen);
- if (pReq == NULL) {
- tscError("consumer:0x%" PRIx64 ", failed to malloc askEpReq msg, size:%d", tmq->consumerId, tlen);
- terrno = TSDB_CODE_OUT_OF_MEMORY;
- return -1;
- }
-
- if (tSerializeSMqAskEpReq(pReq, tlen, &req) < 0) {
- tscError("consumer:0x%" PRIx64 ", tSerializeSMqAskEpReq %d failed", tmq->consumerId, tlen);
- taosMemoryFree(pReq);
- return -1;
- }
-
- SMqAskEpCbParam* pParam = taosMemoryCalloc(1, sizeof(SMqAskEpCbParam));
- if (pParam == NULL) {
- tscError("consumer:0x%" PRIx64 ", failed to malloc subscribe param", tmq->consumerId);
- taosMemoryFree(pReq);
- /*atomic_store_8(&tmq->epStatus, 0);*/
- return -1;
- }
-
- pParam->refId = tmq->refId;
- pParam->epoch = tmq->epoch;
- pParam->async = async;
- tsem_init(&pParam->rspSem, 0, 0);
-
- SMsgSendInfo* sendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
- if (sendInfo == NULL) {
- tsem_destroy(&pParam->rspSem);
- taosMemoryFree(pParam);
- taosMemoryFree(pReq);
- /*atomic_store_8(&tmq->epStatus, 0);*/
- return -1;
- }
-
- sendInfo->msgInfo = (SDataBuf){
- .pData = pReq,
- .len = tlen,
- .handle = NULL,
- };
-
- sendInfo->requestId = generateRequestId();
- sendInfo->requestObjRefId = 0;
- sendInfo->param = pParam;
- sendInfo->fp = tmqAskEpCb;
- sendInfo->msgType = TDMT_MND_TMQ_ASK_EP;
-
- SEpSet epSet = getEpSet_s(&tmq->pTscObj->pAppInfo->mgmtEp);
- tscDebug("consumer:0x%" PRIx64 " ask ep from mnode, async:%d, reqId:0x%" PRIx64, tmq->consumerId, async,
- sendInfo->requestId);
-
- int64_t transporterId = 0;
- asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo);
-
- if (!async) {
- tsem_wait(&pParam->rspSem);
- code = pParam->code;
- taosMemoryFree(pParam);
- }
-
- return code;
-}
-
void tmqBuildConsumeReqImpl(SMqPollReq* pReq, tmq_t* tmq, int64_t timeout, SMqClientTopic* pTopic, SMqClientVg* pVg) {
int32_t groupLen = strlen(tmq->groupId);
memcpy(pReq->subKey, tmq->groupId, groupLen);
@@ -1724,7 +1692,7 @@ static int32_t doTmqPollImpl(tmq_t* pTmq, SMqClientTopic* pTopic, SMqClientVg* p
}
// broadcast the poll request to all related vnodes
-int32_t tmqPollImpl(tmq_t* tmq, int64_t timeout) {
+static int32_t tmqPollImpl(tmq_t* tmq, int64_t timeout) {
int32_t numOfTopics = taosArrayGetSize(tmq->clientTopics);
tscDebug("consumer:0x%" PRIx64 " start to poll data, numOfTopics:%d", tmq->consumerId, numOfTopics);
@@ -1734,6 +1702,12 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t timeout) {
for (int j = 0; j < numOfVg; j++) {
SMqClientVg* pVg = taosArrayGet(pTopic->vgs, j);
+ if (taosGetTimestampMs() - pVg->emptyBlockReceiveTs < 100) { // less than 100ms
+ tscTrace("consumer:0x%" PRIx64 " epoch %d, vgId:%d idle for 100ms before start next poll", tmq->consumerId, tmq->epoch,
+ pVg->vgId);
+ continue;
+ }
+
int32_t vgStatus = atomic_val_compare_exchange_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE, TMQ_VG_STATUS__WAIT);
if (vgStatus == TMQ_VG_STATUS__WAIT) {
int32_t vgSkipCnt = atomic_add_fetch_32(&pVg->vgSkipCnt, 1);
@@ -1760,7 +1734,7 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t timeout) {
return 0;
}
-int32_t tmqHandleNoPollRsp(tmq_t* tmq, SMqRspWrapper* rspWrapper, bool* pReset) {
+static int32_t tmqHandleNoPollRsp(tmq_t* tmq, SMqRspWrapper* rspWrapper, bool* pReset) {
if (rspWrapper->tmqRspType == TMQ_MSG_TYPE__EP_RSP) {
/*printf("ep %d %d\n", rspMsg->head.epoch, tmq->epoch);*/
if (rspWrapper->epoch > atomic_load_32(&tmq->epoch)) {
@@ -1780,7 +1754,7 @@ int32_t tmqHandleNoPollRsp(tmq_t* tmq, SMqRspWrapper* rspWrapper, bool* pReset)
return 0;
}
-void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) {
+static void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) {
tscDebug("consumer:0x%" PRIx64 " start to handle the rsp, total:%d", tmq->consumerId, tmq->qall->numOfItems);
while (1) {
@@ -1796,6 +1770,8 @@ void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) {
}
}
+ tscDebug("consumer:0x%"PRIx64" handle rsp, type:%d", tmq->consumerId, rspWrapper->tmqRspType);
+
if (rspWrapper->tmqRspType == TMQ_MSG_TYPE__END_RSP) {
taosFreeQitem(rspWrapper);
terrno = TSDB_CODE_TQ_NO_COMMITTED_OFFSET;
@@ -1812,7 +1788,8 @@ void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) {
atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE);
if (pollRspWrapper->dataRsp.blockNum == 0) {
- tscDebug("consumer:0x%" PRIx64 " empty block received, vgId:%d", tmq->consumerId, pVg->vgId);
+ tscDebug("consumer:0x%" PRIx64 " empty block received, vgId:%d, reqId:0x%" PRIx64, tmq->consumerId, pVg->vgId,
+ pollRspWrapper->reqId);
taosFreeQitem(pollRspWrapper);
rspWrapper = NULL;
continue;
@@ -1822,8 +1799,8 @@ void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) {
char buf[80];
tFormatOffset(buf, 80, &pVg->currentOffset);
SMqRspObj* pRsp = tmqBuildRspFromWrapper(pollRspWrapper);
- tscDebug("consumer:0x%" PRIx64 " process poll rsp, vgId:%d, offset:%s, blocks:%d", tmq->consumerId,
- pVg->vgId, buf, pollRspWrapper->dataRsp.blockNum);
+ tscDebug("consumer:0x%" PRIx64 " process poll rsp, vgId:%d, offset:%s, blocks:%d, reqId:0x%"PRIx64, tmq->consumerId,
+ pVg->vgId, buf, pollRspWrapper->dataRsp.blockNum, pollRspWrapper->reqId);
taosFreeQitem(pollRspWrapper);
return pRsp;
@@ -1841,8 +1818,6 @@ void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) {
if (pollRspWrapper->metaRsp.head.epoch == consumerEpoch) {
SMqClientVg* pVg = pollRspWrapper->vgHandle;
- /*printf("vgId:%d, offset %" PRId64 " up to %" PRId64 "\n", pVg->vgId, pVg->currentOffset,
- * rspMsg->msg.rspOffset);*/
pVg->currentOffset = pollRspWrapper->metaRsp.rspOffset;
atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE);
// build rsp
@@ -1857,18 +1832,22 @@ void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) {
}
} else if (rspWrapper->tmqRspType == TMQ_MSG_TYPE__TAOSX_RSP) {
SMqPollRspWrapper* pollRspWrapper = (SMqPollRspWrapper*)rspWrapper;
- /*atomic_sub_fetch_32(&tmq->readyRequest, 1);*/
int32_t consumerEpoch = atomic_load_32(&tmq->epoch);
+
if (pollRspWrapper->taosxRsp.head.epoch == consumerEpoch) {
SMqClientVg* pVg = pollRspWrapper->vgHandle;
- /*printf("vgId:%d, offset %" PRId64 " up to %" PRId64 "\n", pVg->vgId, pVg->currentOffset,
- * rspMsg->msg.rspOffset);*/
pVg->currentOffset = pollRspWrapper->taosxRsp.rspOffset;
atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE);
+
if (pollRspWrapper->taosxRsp.blockNum == 0) {
- taosFreeQitem(pollRspWrapper);
rspWrapper = NULL;
+ tscDebug("consumer:0x%" PRIx64 " taosx empty block received, vgId:%d, reqId:0x%" PRIx64, tmq->consumerId, pVg->vgId,
+ pollRspWrapper->reqId);
+ pVg->emptyBlockReceiveTs = taosGetTimestampMs();
+ taosFreeQitem(pollRspWrapper);
continue;
+ } else {
+ pVg->emptyBlockReceiveTs = 0; // reset the ts
}
// build rsp
@@ -1878,8 +1857,16 @@ void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) {
} else {
pRsp = tmqBuildTaosxRspFromWrapper(pollRspWrapper);
}
+
+
+ char buf[80];
+ tFormatOffset(buf, 80, &pVg->currentOffset);
+ tscDebug("consumer:0x%" PRIx64 " process taosx poll rsp, vgId:%d, offset:%s, blocks:%d, reqId:0x%"PRIx64, tmq->consumerId, pVg->vgId,
+ buf, pollRspWrapper->dataRsp.blockNum, pollRspWrapper->reqId);
+
taosFreeQitem(pollRspWrapper);
return pRsp;
+
} else {
tscDebug("consumer:0x%" PRIx64 " msg discard since epoch mismatch: msg epoch %d, consumer epoch %d",
tmq->consumerId, pollRspWrapper->taosxRsp.head.epoch, consumerEpoch);
@@ -1887,7 +1874,8 @@ void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) {
taosFreeQitem(pollRspWrapper);
}
} else {
- /*printf("handle ep rsp %d\n", rspMsg->head.mqMsgType);*/
+ tscDebug("consumer:0x%" PRIx64 " not data msg received", tmq->consumerId);
+
bool reset = false;
tmqHandleNoPollRsp(tmq, rspWrapper, &reset);
taosFreeQitem(rspWrapper);
@@ -1897,8 +1885,6 @@ void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) {
}
}
}
-
- tscDebug("consumer:0x%" PRIx64 " handle the rsp completed", tmq->consumerId);
}
TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t timeout) {
@@ -1923,7 +1909,7 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t timeout) {
return NULL;
}
- if (atomic_load_8(&tmq->status) == TMQ_CONSUMER_STATUS__RECOVER) {
+ while (atomic_load_8(&tmq->status) == TMQ_CONSUMER_STATUS__RECOVER) {
int32_t retryCnt = 0;
while (TSDB_CODE_MND_CONSUMER_NOT_READY == tmqAskEp(tmq, false)) {
if (retryCnt++ > 40) {
@@ -1992,6 +1978,7 @@ int32_t tmq_consumer_close(tmq_t* tmq) {
tmq_list_destroy(lst);
}
+
taosRemoveRef(tmqMgmt.rsetId, tmq->refId);
return 0;
}
@@ -2083,11 +2070,141 @@ const char* tmq_get_table_name(TAOS_RES* res) {
}
void tmq_commit_async(tmq_t* tmq, const TAOS_RES* msg, tmq_commit_cb* cb, void* param) {
- //
tmqCommitInner(tmq, msg, 0, 1, cb, param);
}
int32_t tmq_commit_sync(tmq_t* tmq, const TAOS_RES* msg) {
- //
return tmqCommitInner(tmq, msg, 0, 0, NULL, NULL);
}
+
+int32_t tmqAskEp(tmq_t* tmq, bool async) {
+ int32_t code = TSDB_CODE_SUCCESS;
+#if 0
+ int8_t epStatus = atomic_val_compare_exchange_8(&tmq->epStatus, 0, 1);
+ if (epStatus == 1) {
+ int32_t epSkipCnt = atomic_add_fetch_32(&tmq->epSkipCnt, 1);
+ tscTrace("consumer:0x%" PRIx64 ", skip ask ep cnt %d", tmq->consumerId, epSkipCnt);
+ if (epSkipCnt < 5000) return 0;
+ }
+ atomic_store_32(&tmq->epSkipCnt, 0);
+#endif
+
+ SMqAskEpReq req = {0};
+ req.consumerId = tmq->consumerId;
+ req.epoch = tmq->epoch;
+ strcpy(req.cgroup, tmq->groupId);
+
+ int32_t tlen = tSerializeSMqAskEpReq(NULL, 0, &req);
+ if (tlen < 0) {
+ tscError("consumer:0x%" PRIx64 ", tSerializeSMqAskEpReq failed", tmq->consumerId);
+ return -1;
+ }
+
+ void* pReq = taosMemoryCalloc(1, tlen);
+ if (pReq == NULL) {
+ tscError("consumer:0x%" PRIx64 ", failed to malloc askEpReq msg, size:%d", tmq->consumerId, tlen);
+ terrno = TSDB_CODE_OUT_OF_MEMORY;
+ return -1;
+ }
+
+ if (tSerializeSMqAskEpReq(pReq, tlen, &req) < 0) {
+ tscError("consumer:0x%" PRIx64 ", tSerializeSMqAskEpReq %d failed", tmq->consumerId, tlen);
+ taosMemoryFree(pReq);
+ return -1;
+ }
+
+ SMqAskEpCbParam* pParam = taosMemoryCalloc(1, sizeof(SMqAskEpCbParam));
+ if (pParam == NULL) {
+ tscError("consumer:0x%" PRIx64 ", failed to malloc subscribe param", tmq->consumerId);
+ taosMemoryFree(pReq);
+ return -1;
+ }
+
+ pParam->refId = tmq->refId;
+ pParam->epoch = tmq->epoch;
+ pParam->async = async;
+ tsem_init(&pParam->rspSem, 0, 0);
+
+ SMsgSendInfo* sendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
+ if (sendInfo == NULL) {
+ tsem_destroy(&pParam->rspSem);
+ taosMemoryFree(pParam);
+ taosMemoryFree(pReq);
+ return -1;
+ }
+
+ sendInfo->msgInfo = (SDataBuf){
+ .pData = pReq,
+ .len = tlen,
+ .handle = NULL,
+ };
+
+ sendInfo->requestId = generateRequestId();
+ sendInfo->requestObjRefId = 0;
+ sendInfo->param = pParam;
+ sendInfo->fp = tmqAskEpCb;
+ sendInfo->msgType = TDMT_MND_TMQ_ASK_EP;
+
+ SEpSet epSet = getEpSet_s(&tmq->pTscObj->pAppInfo->mgmtEp);
+ tscDebug("consumer:0x%" PRIx64 " ask ep from mnode, async:%d, reqId:0x%" PRIx64, tmq->consumerId, async,
+ sendInfo->requestId);
+
+ int64_t transporterId = 0;
+ asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo);
+
+ if (!async) {
+ tsem_wait(&pParam->rspSem);
+ code = pParam->code;
+ taosMemoryFree(pParam);
+ }
+
+ return code;
+}
+
+int32_t makeTopicVgroupKey(char* dst, const char* topicName, int32_t vg) {
+ return sprintf(dst, "%s:%d", topicName, vg);
+}
+
+int32_t tmqCommitDone(SMqCommitCbParamSet* pParamSet) {
+ tmq_t* tmq = taosAcquireRef(tmqMgmt.rsetId, pParamSet->refId);
+ if (tmq == NULL) {
+ if (!pParamSet->async) {
+ tsem_destroy(&pParamSet->rspSem);
+ }
+ taosMemoryFree(pParamSet);
+ terrno = TSDB_CODE_TMQ_CONSUMER_CLOSED;
+ return -1;
+ }
+
+ // if no more waiting rsp
+ if (pParamSet->async) {
+ // call async cb func
+ if (pParamSet->automatic && tmq->commitCb) {
+ tmq->commitCb(tmq, pParamSet->rspErr, tmq->commitCbUserParam);
+ } else if (!pParamSet->automatic && pParamSet->userCb) { // sem post
+ pParamSet->userCb(tmq, pParamSet->rspErr, pParamSet->userParam);
+ }
+
+ taosMemoryFree(pParamSet);
+ } else {
+ tsem_post(&pParamSet->rspSem);
+ }
+
+#if 0
+ taosArrayDestroyP(pParamSet->successfulOffsets, taosMemoryFree);
+ taosArrayDestroyP(pParamSet->failedOffsets, taosMemoryFree);
+#endif
+ return 0;
+}
+
+void tmqCommitRspCountDown(SMqCommitCbParamSet* pParamSet, int64_t consumerId, const char* pTopic, int32_t vgId) {
+ int32_t waitingRspNum = atomic_sub_fetch_32(&pParamSet->waitingRspNum, 1);
+ if (waitingRspNum == 0) {
+ tscDebug("consumer:0x%" PRIx64 " topic:%s vgId:%d all commit-rsp received, commit completed", consumerId, pTopic,
+ vgId);
+ tmqCommitDone(pParamSet);
+ } else {
+ tscDebug("consumer:0x%" PRIx64 " topic:%s vgId:%d commit-rsp received, remain:%d", consumerId, pTopic, vgId,
+ waitingRspNum);
+ }
+}
diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp
index 2f3d600019..0c7e95f8eb 100644
--- a/source/client/test/clientTests.cpp
+++ b/source/client/test/clientTests.cpp
@@ -898,7 +898,7 @@ TEST(clientCase, update_test) {
}
}
-TEST(clientCase, subscription_test) {
+TEST(clientCase, sub_db_test) {
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
ASSERT_NE(pConn, nullptr);
@@ -912,7 +912,7 @@ TEST(clientCase, subscription_test) {
tmq_conf_t* conf = tmq_conf_new();
tmq_conf_set(conf, "enable.auto.commit", "true");
tmq_conf_set(conf, "auto.commit.interval.ms", "1000");
- tmq_conf_set(conf, "group.id", "cgrpName");
+ tmq_conf_set(conf, "group.id", "cgrpNamedb");
tmq_conf_set(conf, "td.connect.user", "root");
tmq_conf_set(conf, "td.connect.pass", "taosdata");
tmq_conf_set(conf, "auto.offset.reset", "earliest");
@@ -925,7 +925,7 @@ TEST(clientCase, subscription_test) {
// 创建订阅 topics 列表
tmq_list_t* topicList = tmq_list_new();
-// tmq_list_append(topicList, "topic_t1");
+ tmq_list_append(topicList, "topic_db1");
// 启动订阅
tmq_subscribe(tmq, topicList);
@@ -954,7 +954,86 @@ TEST(clientCase, subscription_test) {
printf("db: %s\n", dbName);
printf("vgroup id: %d\n", vgroupId);
- if (count ++ > 20) {
+ if (count ++ > 200) {
+ tmq_unsubscribe(tmq);
+ break;
+ }
+
+ while (1) {
+ TAOS_ROW row = taos_fetch_row(pRes);
+ if (row == NULL) break;
+
+ fields = taos_fetch_fields(pRes);
+ numOfFields = taos_field_count(pRes);
+ precision = taos_result_precision(pRes);
+ rows++;
+ taos_print_row(buf, row, fields, numOfFields);
+ printf("precision: %d, row content: %s\n", precision, buf);
+ }
+ }
+// return rows;
+ }
+
+ fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows);
+}
+
+TEST(clientCase, sub_tb_test) {
+ TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
+ ASSERT_NE(pConn, nullptr);
+
+ // TAOS_RES* pRes = taos_query(pConn, "create topic topic_t1 as select * from t1");
+ // if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
+ // printf("failed to create topic, code:%s", taos_errstr(pRes));
+ // taos_free_result(pRes);
+ // return;
+ // }
+
+ tmq_conf_t* conf = tmq_conf_new();
+ tmq_conf_set(conf, "enable.auto.commit", "true");
+ tmq_conf_set(conf, "auto.commit.interval.ms", "1000");
+ tmq_conf_set(conf, "group.id", "cgrpName");
+ tmq_conf_set(conf, "td.connect.user", "root");
+ tmq_conf_set(conf, "td.connect.pass", "taosdata");
+ tmq_conf_set(conf, "auto.offset.reset", "earliest");
+ tmq_conf_set(conf, "experimental.snapshot.enable", "true");
+ tmq_conf_set(conf, "msg.with.table.name", "true");
+ tmq_conf_set_auto_commit_cb(conf, tmq_commit_cb_print, NULL);
+
+ tmq_t* tmq = tmq_consumer_new(conf, NULL, 0);
+ tmq_conf_destroy(conf);
+
+ // 创建订阅 topics 列表
+ tmq_list_t* topicList = tmq_list_new();
+ tmq_list_append(topicList, "topic_t1");
+
+ // 启动订阅
+ tmq_subscribe(tmq, topicList);
+ tmq_list_destroy(topicList);
+
+ TAOS_FIELD* fields = NULL;
+ int32_t numOfFields = 0;
+ int32_t precision = 0;
+ int32_t totalRows = 0;
+ int32_t msgCnt = 0;
+ int32_t timeout = 5000;
+
+ int32_t count = 0;
+
+ while (1) {
+ TAOS_RES* pRes = tmq_consumer_poll(tmq, timeout);
+ if (pRes) {
+ char buf[1024];
+ int32_t rows = 0;
+
+ const char* topicName = tmq_get_topic_name(pRes);
+ const char* dbName = tmq_get_db_name(pRes);
+ int32_t vgroupId = tmq_get_vgroup_id(pRes);
+
+ printf("topic: %s\n", topicName);
+ printf("db: %s\n", dbName);
+ printf("vgroup id: %d\n", vgroupId);
+
+ if (count ++ > 200) {
tmq_unsubscribe(tmq);
break;
}
diff --git a/source/common/src/systable.c b/source/common/src/systable.c
index 4aa47a3819..141504a7c4 100644
--- a/source/common/src/systable.c
+++ b/source/common/src/systable.c
@@ -233,6 +233,7 @@ static const SSysDbTableSchema vgroupsSchema[] = {
{.name = "v4_dnode", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT, .sysInfo = true},
{.name = "v4_status", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
{.name = "cacheload", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = true},
+ {.name = "cacheTables", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = true},
{.name = "tsma", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT, .sysInfo = true},
// {.name = "compact_start_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = false},
};
diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c
index 8058f9fddd..0b4c7b88d7 100644
--- a/source/common/src/tglobal.c
+++ b/source/common/src/tglobal.c
@@ -154,6 +154,7 @@ char tsTagFilterCache = 0;
// positive value (in MB)
int32_t tsQueryBufferSize = -1;
int64_t tsQueryBufferSizeBytes = -1;
+int32_t tsCacheLazyLoadThreshold = 500;
int32_t tsDiskCfgNum = 0;
SDiskCfg tsDiskCfg[TFS_MAX_DISKS] = {0};
@@ -497,6 +498,8 @@ static int32_t taosAddServerCfg(SConfig *pCfg) {
if (cfgAddBool(pCfg, "disableStream", tsDisableStream, 0) != 0) return -1;
+ if (cfgAddInt32(pCfg, "cacheLazyLoadThreshold", tsCacheLazyLoadThreshold, 0, 100000, 0) != 0) return -1;
+
GRANT_CFG_ADD;
return 0;
}
@@ -824,6 +827,8 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
tsQueryBufferSizeBytes = tsQueryBufferSize * 1048576UL;
}
+ tsCacheLazyLoadThreshold = cfgGetItem(pCfg, "cacheLazyLoadThreshold")->i32;
+
tsDisableStream = cfgGetItem(pCfg, "disableStream")->bval;
GRANT_CFG_GET;
diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c
index 9ad7c72bc0..7a238440a7 100644
--- a/source/common/src/tmsg.c
+++ b/source/common/src/tmsg.c
@@ -1070,7 +1070,8 @@ int32_t tSerializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) {
if (tEncodeI64(&encoder, pload->totalStorage) < 0) return -1;
if (tEncodeI64(&encoder, pload->compStorage) < 0) return -1;
if (tEncodeI64(&encoder, pload->pointsWritten) < 0) return -1;
- if (tEncodeI64(&encoder, reserved) < 0) return -1;
+ if (tEncodeI32(&encoder, pload->numOfCachedTables) < 0) return -1;
+ if (tEncodeI32(&encoder, reserved) < 0) return -1;
if (tEncodeI64(&encoder, reserved) < 0) return -1;
if (tEncodeI64(&encoder, reserved) < 0) return -1;
}
@@ -1148,7 +1149,8 @@ int32_t tDeserializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) {
if (tDecodeI64(&decoder, &vload.totalStorage) < 0) return -1;
if (tDecodeI64(&decoder, &vload.compStorage) < 0) return -1;
if (tDecodeI64(&decoder, &vload.pointsWritten) < 0) return -1;
- if (tDecodeI64(&decoder, &reserved) < 0) return -1;
+ if (tDecodeI32(&decoder, &vload.numOfCachedTables) < 0) return -1;
+ if (tDecodeI32(&decoder, (int32_t*)&reserved) < 0) return -1;
if (tDecodeI64(&decoder, &reserved) < 0) return -1;
if (tDecodeI64(&decoder, &reserved) < 0) return -1;
if (taosArrayPush(pReq->pVloads, &vload) == NULL) {
@@ -6637,8 +6639,9 @@ int32_t tFormatOffset(char *buf, int32_t maxLen, const STqOffsetVal *pVal) {
} else if (pVal->type == TMQ_OFFSET__SNAPSHOT_DATA || pVal->type == TMQ_OFFSET__SNAPSHOT_META) {
snprintf(buf, maxLen, "offset(snapshot) uid:%" PRId64 " ts:%" PRId64, pVal->uid, pVal->ts);
} else {
- ASSERT(0);
+ return TSDB_CODE_INVALID_PARA;
}
+
return 0;
}
@@ -6821,8 +6824,7 @@ int32_t tDecodeSMqDataRsp(SDecoder *pDecoder, SMqDataRsp *pRsp) {
}
void tDeleteSMqDataRsp(SMqDataRsp *pRsp) {
- taosArrayDestroy(pRsp->blockDataLen);
- pRsp->blockDataLen = NULL;
+ pRsp->blockDataLen = taosArrayDestroy(pRsp->blockDataLen);;
taosArrayDestroyP(pRsp->blockData, (FDelete)taosMemoryFree);
pRsp->blockData = NULL;
taosArrayDestroyP(pRsp->blockSchema, (FDelete)tDeleteSSchemaWrapper);
diff --git a/source/dnode/mnode/impl/inc/mndConsumer.h b/source/dnode/mnode/impl/inc/mndConsumer.h
index 1176e1af0b..99b0d06936 100644
--- a/source/dnode/mnode/impl/inc/mndConsumer.h
+++ b/source/dnode/mnode/impl/inc/mndConsumer.h
@@ -24,10 +24,10 @@ extern "C" {
enum {
MQ_CONSUMER_STATUS__MODIFY = 1,
- MQ_CONSUMER_STATUS__MODIFY_IN_REB,
+ MQ_CONSUMER_STATUS__MODIFY_IN_REB, // this value is not used anymore
MQ_CONSUMER_STATUS__READY,
MQ_CONSUMER_STATUS__LOST,
- MQ_CONSUMER_STATUS__LOST_IN_REB,
+ MQ_CONSUMER_STATUS__LOST_IN_REB, // this value is not used anymore
MQ_CONSUMER_STATUS__LOST_REBD,
MQ_CONSUMER_STATUS__REMOVED,
};
diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h
index ebe96fd740..dfc3b3fde8 100644
--- a/source/dnode/mnode/impl/inc/mndDef.h
+++ b/source/dnode/mnode/impl/inc/mndDef.h
@@ -359,6 +359,7 @@ typedef struct {
int8_t replica;
SVnodeGid vnodeGid[TSDB_MAX_REPLICA];
void* pTsma;
+ int32_t numOfCachedTables;
} SVgObj;
typedef struct {
diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h
index 006c74ef3d..ffb2443808 100644
--- a/source/dnode/mnode/impl/inc/mndInt.h
+++ b/source/dnode/mnode/impl/inc/mndInt.h
@@ -113,6 +113,7 @@ typedef struct SMnode {
bool deploy;
char *path;
int64_t checkTime;
+ SyncIndex applied;
SSdb *pSdb;
SArray *pSteps;
SQHandle *pQuery;
diff --git a/source/dnode/mnode/impl/src/mndConsumer.c b/source/dnode/mnode/impl/src/mndConsumer.c
index f1ef83aca5..53421aa45c 100644
--- a/source/dnode/mnode/impl/src/mndConsumer.c
+++ b/source/dnode/mnode/impl/src/mndConsumer.c
@@ -77,7 +77,7 @@ void mndCleanupConsumer(SMnode *pMnode) {}
bool mndRebTryStart() {
int32_t old = atomic_val_compare_exchange_32(&mqRebInExecCnt, 0, 1);
- mInfo("tq timer, rebalance counter old val:%d", old);
+ mDebug("tq timer, rebalance counter old val:%d", old);
return old == 0;
}
@@ -253,11 +253,11 @@ static int32_t mndProcessMqTimerMsg(SRpcMsg *pMsg) {
SMqConsumerObj *pConsumer;
void *pIter = NULL;
- mTrace("start to process mq timer");
+ mDebug("start to process mq timer");
// rebalance cannot be parallel
if (!mndRebTryStart()) {
- mInfo("mq rebalance already in progress, do nothing");
+ mDebug("mq rebalance already in progress, do nothing");
return 0;
}
@@ -317,7 +317,7 @@ static int32_t mndProcessMqTimerMsg(SRpcMsg *pMsg) {
taosArrayPush(pRebSub->removedConsumers, &pConsumer->consumerId);
}
taosRUnLockLatch(&pConsumer->lock);
- } else if (status == MQ_CONSUMER_STATUS__MODIFY) {
+ } else if (status == MQ_CONSUMER_STATUS__MODIFY || status == MQ_CONSUMER_STATUS__MODIFY_IN_REB) {
taosRLockLatch(&pConsumer->lock);
int32_t newTopicNum = taosArrayGetSize(pConsumer->rebNewTopics);
@@ -356,7 +356,7 @@ static int32_t mndProcessMqTimerMsg(SRpcMsg *pMsg) {
} else {
taosHashCleanup(pRebMsg->rebSubHash);
rpcFreeCont(pRebMsg);
- mInfo("mq rebalance finished, no modification");
+ mDebug("mq rebalance finished, no modification");
mndRebEnd();
}
return 0;
diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c
index e848a81d40..126a653a69 100644
--- a/source/dnode/mnode/impl/src/mndDb.c
+++ b/source/dnode/mnode/impl/src/mndDb.c
@@ -279,6 +279,8 @@ static int32_t mndDbActionUpdate(SSdb *pSdb, SDbObj *pOld, SDbObj *pNew) {
pOld->cfg.cacheLast = pNew->cfg.cacheLast;
pOld->cfg.replications = pNew->cfg.replications;
pOld->cfg.sstTrigger = pNew->cfg.sstTrigger;
+ pOld->cfg.minRows = pNew->cfg.minRows;
+ pOld->cfg.maxRows = pNew->cfg.maxRows;
pOld->cfg.tsdbPageSize = pNew->cfg.tsdbPageSize;
pOld->compactStartTime = pNew->compactStartTime;
taosWUnLockLatch(&pOld->lock);
@@ -616,13 +618,8 @@ static int32_t mndProcessCreateDbReq(SRpcMsg *pReq) {
}
} else {
if (terrno == TSDB_CODE_MND_DB_IN_CREATING) {
- if (mndSetRpcInfoForDbTrans(pMnode, pReq, MND_OPER_CREATE_DB, createReq.db) == 0) {
- mInfo("db:%s, is creating and createdb response after trans finished", createReq.db);
- code = TSDB_CODE_ACTION_IN_PROGRESS;
- goto _OVER;
- } else {
- goto _OVER;
- }
+ code = terrno;
+ goto _OVER;
} else if (terrno == TSDB_CODE_MND_DB_IN_DROPPING) {
goto _OVER;
} else if (terrno == TSDB_CODE_MND_DB_NOT_EXIST) {
@@ -1270,14 +1267,9 @@ static int32_t mndProcessUseDbReq(SRpcMsg *pReq) {
usedbRsp.errCode = terrno;
if (terrno == TSDB_CODE_MND_DB_IN_CREATING) {
- if (mndSetRpcInfoForDbTrans(pMnode, pReq, MND_OPER_CREATE_DB, usedbReq.db) == 0) {
- mInfo("db:%s, is creating and usedb response after trans finished", usedbReq.db);
- code = TSDB_CODE_ACTION_IN_PROGRESS;
- goto _OVER;
- }
+ code = terrno;
+ goto _OVER;
}
-
- mError("db:%s, failed to process use db req since %s", usedbReq.db, terrstr());
} else {
if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_USE_DB, pDb) != 0) {
goto _OVER;
diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c
index 1d9db37a7d..adeae45314 100644
--- a/source/dnode/mnode/impl/src/mndDnode.c
+++ b/source/dnode/mnode/impl/src/mndDnode.c
@@ -412,6 +412,7 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) {
if (pVgroup != NULL) {
if (pVload->syncState == TAOS_SYNC_STATE_LEADER) {
pVgroup->cacheUsage = pVload->cacheUsage;
+ pVgroup->numOfCachedTables = pVload->numOfCachedTables;
pVgroup->numOfTables = pVload->numOfTables;
pVgroup->numOfTimeSeries = pVload->numOfTimeSeries;
pVgroup->totalStorage = pVload->totalStorage;
@@ -440,7 +441,8 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) {
if (roleChanged) {
SDbObj *pDb = mndAcquireDb(pMnode, pVgroup->dbName);
if (pDb != NULL && pDb->stateTs != curMs) {
- mInfo("db:%s, stateTs changed by status msg, old stateTs:%" PRId64 " new stateTs:%" PRId64, pDb->name, pDb->stateTs, curMs);
+ mInfo("db:%s, stateTs changed by status msg, old stateTs:%" PRId64 " new stateTs:%" PRId64, pDb->name,
+ pDb->stateTs, curMs);
pDb->stateTs = curMs;
}
mndReleaseDb(pMnode, pDb);
diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c
index d83b969e2d..c32212dfc1 100644
--- a/source/dnode/mnode/impl/src/mndMain.c
+++ b/source/dnode/mnode/impl/src/mndMain.c
@@ -380,11 +380,13 @@ static int32_t mndInitSdb(SMnode *pMnode) {
}
static int32_t mndOpenSdb(SMnode *pMnode) {
+ int32_t code = 0;
if (!pMnode->deploy) {
- return sdbReadFile(pMnode->pSdb);
- } else {
- return 0;
+ code = sdbReadFile(pMnode->pSdb);
}
+
+ atomic_store_64(&pMnode->applied, pMnode->pSdb->commitIndex);
+ return code;
}
static void mndCleanupSdb(SMnode *pMnode) {
diff --git a/source/dnode/mnode/impl/src/mndSubscribe.c b/source/dnode/mnode/impl/src/mndSubscribe.c
index 4d19110f31..924216bcbf 100644
--- a/source/dnode/mnode/impl/src/mndSubscribe.c
+++ b/source/dnode/mnode/impl/src/mndSubscribe.c
@@ -224,7 +224,7 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
.pVgEp = pVgEp,
};
taosHashPut(pHash, &pVgEp->vgId, sizeof(int32_t), &outputVg, sizeof(SMqRebOutputVg));
- mInfo("sub:%s mq re-balance remove vgId:%d from consumer:%" PRIx64, sub, pVgEp->vgId, consumerId);
+ mInfo("sub:%s mq re-balance remove vgId:%d from consumer:0x%" PRIx64, sub, pVgEp->vgId, consumerId);
}
taosArrayDestroy(pConsumerEp->vgs);
taosHashRemove(pOutput->pSub->consumerHash, &consumerId, sizeof(int64_t));
@@ -329,7 +329,7 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
newConsumerEp.vgs = taosArrayInit(0, sizeof(void *));
taosHashPut(pOutput->pSub->consumerHash, &consumerId, sizeof(int64_t), &newConsumerEp, sizeof(SMqConsumerEp));
taosArrayPush(pOutput->newConsumers, &consumerId);
- mInfo("sub:%s mq rebalance add new consumer:%" PRIx64, sub, consumerId);
+ mInfo("sub:%s mq rebalance add new consumer:0x%" PRIx64, sub, consumerId);
}
}
@@ -357,7 +357,7 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
taosArrayPush(pConsumerEp->vgs, &pRebVg->pVgEp);
pRebVg->newConsumerId = pConsumerEp->consumerId;
taosArrayPush(pOutput->rebVgs, pRebVg);
- mInfo("mq rebalance: add vgId:%d to consumer:%" PRIx64 " (second scan) (not enough)", pRebVg->pVgEp->vgId,
+ mInfo("mq rebalance: add vgId:%d to consumer:0x%" PRIx64 " (second scan) (not enough)", pRebVg->pVgEp->vgId,
pConsumerEp->consumerId);
}
}
@@ -387,12 +387,12 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
taosArrayPush(pConsumerEp->vgs, &pRebVg->pVgEp);
pRebVg->newConsumerId = pConsumerEp->consumerId;
if (pRebVg->newConsumerId == pRebVg->oldConsumerId) {
- mInfo("mq rebalance: skip vg %d for same consumer:%" PRIx64 " (second scan)", pRebVg->pVgEp->vgId,
+ mInfo("mq rebalance: skip vg %d for same consumer:0x%" PRIx64 " (second scan)", pRebVg->pVgEp->vgId,
pConsumerEp->consumerId);
continue;
}
taosArrayPush(pOutput->rebVgs, pRebVg);
- mInfo("mq rebalance: add vgId:%d to consumer:%" PRIx64 " (second scan) (unassigned)", pRebVg->pVgEp->vgId,
+ mInfo("mq rebalance: add vgId:%d to consumer:0x%" PRIx64 " (second scan) (unassigned)", pRebVg->pVgEp->vgId,
pConsumerEp->consumerId);
}
} else {
@@ -1019,7 +1019,7 @@ int32_t mndRetrieveSubscribe(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataSetVal(pColInfo, numOfRows, (const char *)&pConsumerEp->consumerId, false);
- mDebug("mnd show subscriptions: topic %s, consumer:%" PRIx64 " cgroup %s vgid %d", varDataVal(topic),
+ mDebug("mnd show subscriptions: topic %s, consumer:0x%" PRIx64 " cgroup %s vgid %d", varDataVal(topic),
pConsumerEp->consumerId, varDataVal(cgroup), pVgEp->vgId);
// offset
diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c
index f702d8f148..18548db56f 100644
--- a/source/dnode/mnode/impl/src/mndSync.c
+++ b/source/dnode/mnode/impl/src/mndSync.c
@@ -129,6 +129,14 @@ int32_t mndProcessWriteMsg(const SSyncFSM *pFsm, SRpcMsg *pMsg, const SFsmCbMeta
int32_t mndSyncCommitMsg(const SSyncFSM *pFsm, SRpcMsg *pMsg, const SFsmCbMeta *pMeta) {
int32_t code = 0;
+ pMsg->info.conn.applyIndex = pMeta->index;
+ pMsg->info.conn.applyTerm = pMeta->term;
+
+ if (pMsg->code == 0) {
+ SMnode *pMnode = pFsm->data;
+ atomic_store_64(&pMnode->applied, pMsg->info.conn.applyIndex);
+ }
+
if (!syncUtilUserCommit(pMsg->msgType)) {
goto _out;
}
@@ -140,6 +148,11 @@ _out:
return code;
}
+SyncIndex mndSyncAppliedIndex(const SSyncFSM *pFSM) {
+ SMnode *pMnode = pFSM->data;
+ return atomic_load_64(&pMnode->applied);
+}
+
int32_t mndSyncGetSnapshot(const SSyncFSM *pFsm, SSnapshot *pSnapshot, void *pReaderParam, void **ppReader) {
mInfo("start to read snapshot from sdb in atomic way");
SMnode *pMnode = pFsm->data;
@@ -153,7 +166,7 @@ static void mndSyncGetSnapshotInfo(const SSyncFSM *pFsm, SSnapshot *pSnapshot) {
sdbGetCommitInfo(pMnode->pSdb, &pSnapshot->lastApplyIndex, &pSnapshot->lastApplyTerm, &pSnapshot->lastConfigIndex);
}
-void mndRestoreFinish(const SSyncFSM *pFsm) {
+void mndRestoreFinish(const SSyncFSM *pFsm, const SyncIndex commitIdx) {
SMnode *pMnode = pFsm->data;
if (!pMnode->deploy) {
@@ -167,6 +180,8 @@ void mndRestoreFinish(const SSyncFSM *pFsm) {
} else {
mInfo("vgId:1, sync restore finished");
}
+
+ ASSERT(commitIdx == mndSyncAppliedIndex(pFsm));
}
int32_t mndSnapshotStartRead(const SSyncFSM *pFsm, void *pParam, void **ppReader) {
@@ -253,6 +268,7 @@ SSyncFSM *mndSyncMakeFsm(SMnode *pMnode) {
SSyncFSM *pFsm = taosMemoryCalloc(1, sizeof(SSyncFSM));
pFsm->data = pMnode;
pFsm->FpCommitCb = mndSyncCommitMsg;
+ pFsm->FpAppliedIndexCb = mndSyncAppliedIndex;
pFsm->FpPreCommitCb = NULL;
pFsm->FpRollBackCb = NULL;
pFsm->FpRestoreFinishCb = mndRestoreFinish;
diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c
index 84e8a9ec43..b747755acc 100644
--- a/source/dnode/mnode/impl/src/mndVgroup.c
+++ b/source/dnode/mnode/impl/src/mndVgroup.c
@@ -803,6 +803,9 @@ static int32_t mndRetrieveVgroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *p
int32_t cacheUsage = (int32_t)pVgroup->cacheUsage;
colDataSetVal(pColInfo, numOfRows, (const char *)&cacheUsage, false);
+ pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
+ colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->numOfCachedTables, false);
+
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->isTsma, false);
diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h
index 1d14829891..906d16ce77 100644
--- a/source/dnode/vnode/inc/vnode.h
+++ b/source/dnode/vnode/inc/vnode.h
@@ -198,9 +198,10 @@ int32_t tsdbRetrieveCacheRows(void *pReader, SSDataBlock *pResBlock, const int32
void *tsdbCacherowsReaderClose(void *pReader);
int32_t tsdbGetTableSchema(SVnode *pVnode, int64_t uid, STSchema **pSchema, int64_t *suid);
-void tsdbCacheSetCapacity(SVnode *pVnode, size_t capacity);
-size_t tsdbCacheGetCapacity(SVnode *pVnode);
-size_t tsdbCacheGetUsage(SVnode *pVnode);
+void tsdbCacheSetCapacity(SVnode *pVnode, size_t capacity);
+size_t tsdbCacheGetCapacity(SVnode *pVnode);
+size_t tsdbCacheGetUsage(SVnode *pVnode);
+int32_t tsdbCacheGetElems(SVnode *pVnode);
// tq
typedef struct SMetaTableInfo {
@@ -264,7 +265,7 @@ int32_t tqReaderSetTbUidList(STqReader *pReader, const SArray *tbUidList);
int32_t tqReaderAddTbUidList(STqReader *pReader, const SArray *tbUidList);
int32_t tqReaderRemoveTbUidList(STqReader *pReader, const SArray *tbUidList);
-int32_t tqSeekVer(STqReader *pReader, int64_t ver, const char* id);
+int32_t tqSeekVer(STqReader *pReader, int64_t ver, const char *id);
int32_t tqNextBlock(STqReader *pReader, SFetchRet *ret);
int32_t tqReaderSetSubmitReq2(STqReader *pReader, void *msgStr, int32_t msgLen, int64_t ver);
diff --git a/source/dnode/vnode/src/inc/tq.h b/source/dnode/vnode/src/inc/tq.h
index 792fed2309..ee2bd007ce 100644
--- a/source/dnode/vnode/src/inc/tq.h
+++ b/source/dnode/vnode/src/inc/tq.h
@@ -79,43 +79,33 @@ typedef struct {
} STqExecDb;
typedef struct {
- int8_t subType;
-
- STqReader* pExecReader;
- qTaskInfo_t task;
+ int8_t subType;
+ STqReader* pExecReader;
+ qTaskInfo_t task;
union {
STqExecCol execCol;
STqExecTb execTb;
STqExecDb execDb;
};
- int32_t numOfCols; // number of out pout column, temporarily used
+ int32_t numOfCols; // number of out pout column, temporarily used
} STqExecHandle;
typedef struct {
- // info
- char subKey[TSDB_SUBSCRIBE_KEY_LEN];
- int64_t consumerId;
- int32_t epoch;
- int8_t fetchMeta;
-
- int64_t snapshotVer;
-
- SWalReader* pWalReader;
-
- SWalRef* pRef;
-
- // push
- STqPushHandle pushHandle;
-
- // exec
- STqExecHandle execHandle;
-
+ char subKey[TSDB_SUBSCRIBE_KEY_LEN];
+ int64_t consumerId;
+ int32_t epoch;
+ int8_t fetchMeta;
+ int64_t snapshotVer;
+ SWalReader* pWalReader;
+ SWalRef* pRef;
+ STqPushHandle pushHandle; // push
+ STqExecHandle execHandle; // exec
} STqHandle;
typedef struct {
- SMqDataRsp dataRsp;
+ SMqDataRsp* pDataRsp;
char subKey[TSDB_SUBSCRIBE_KEY_LEN];
- SRpcHandleInfo pInfo;
+ SRpcHandleInfo info;
} STqPushEntry;
struct STQ {
@@ -151,13 +141,13 @@ int32_t tDecodeSTqHandle(SDecoder* pDecoder, STqHandle* pHandle);
// tqRead
int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqMetaRsp* pMetaRsp, STqOffsetVal* offset);
int32_t tqScanData(STQ* pTq, const STqHandle* pHandle, SMqDataRsp* pRsp, STqOffsetVal* pOffset);
-int64_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, SWalCkHead** pHeadWithCkSum);
+int32_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, SWalCkHead** pHeadWithCkSum);
// tqExec
int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SPackedData submit, STaosxRsp* pRsp);
// int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SSubmitReq* pReq, STaosxRsp* pRsp);
int32_t tqAddBlockDataToRsp(const SSDataBlock* pBlock, SMqDataRsp* pRsp, int32_t numOfCols, int8_t precision);
-int32_t tqSendDataRsp(STQ* pTq, const SRpcMsg* pMsg, const SMqPollReq* pReq, const SMqDataRsp* pRsp);
+int32_t tqSendDataRsp(STQ* pTq, const SRpcMsg* pMsg, const SMqPollReq* pReq, const SMqDataRsp* pRsp, int32_t type);
int32_t tqPushDataRsp(STQ* pTq, STqPushEntry* pPushEntry);
// tqMeta
diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h
index b2e1e8ab34..0b38ce6d24 100644
--- a/source/dnode/vnode/src/inc/tsdb.h
+++ b/source/dnode/vnode/src/inc/tsdb.h
@@ -706,6 +706,7 @@ typedef struct SMergeTree {
bool destroyLoadInfo;
SSttBlockLoadInfo *pLoadInfo;
const char *idStr;
+ bool ignoreEarlierTs;
} SMergeTree;
typedef struct {
@@ -748,9 +749,10 @@ struct SDiskDataBuilder {
int32_t tMergeTreeOpen(SMergeTree *pMTree, int8_t backward, SDataFReader *pFReader, uint64_t suid, uint64_t uid,
STimeWindow *pTimeWindow, SVersionRange *pVerRange, SSttBlockLoadInfo *pBlockLoadInfo,
- bool destroyLoadInfo, const char *idStr);
+ bool destroyLoadInfo, const char *idStr, bool strictTimeRange);
void tMergeTreeAddIter(SMergeTree *pMTree, SLDataIter *pIter);
bool tMergeTreeNext(SMergeTree *pMTree);
+bool tMergeTreeIgnoreEarlierTs(SMergeTree *pMTree);
TSDBROW tMergeTreeGetRow(SMergeTree *pMTree);
void tMergeTreeClose(SMergeTree *pMTree);
diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h
index 0dff2420ec..0fe7f9a773 100644
--- a/source/dnode/vnode/src/inc/vnodeInt.h
+++ b/source/dnode/vnode/src/inc/vnodeInt.h
@@ -192,6 +192,9 @@ void tqCleanUp();
STQ* tqOpen(const char* path, SVnode* pVnode);
void tqClose(STQ*);
int tqPushMsg(STQ*, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver);
+int tqRegisterPushEntry(STQ* pTq, void* pHandle, const SMqPollReq* pRequest, SRpcMsg* pRpcMsg, SMqDataRsp* pDataRsp, int32_t type);
+int tqRemovePushEntry(STQ* pTq, const char* pKey, int32_t keyLen, uint64_t consumerId, bool rspConsumer);
+
int tqCommit(STQ*);
int32_t tqUpdateTbUidList(STQ* pTq, const SArray* tbUidList, bool isAdd);
int32_t tqCheckColModifiable(STQ* pTq, int64_t tbUid, int32_t colId);
diff --git a/source/dnode/vnode/src/meta/metaCache.c b/source/dnode/vnode/src/meta/metaCache.c
index 05889e4767..9501bf4b8e 100644
--- a/source/dnode/vnode/src/meta/metaCache.c
+++ b/source/dnode/vnode/src/meta/metaCache.c
@@ -14,6 +14,7 @@
*/
#include "meta.h"
+#define TAG_FILTER_RES_KEY_LEN 32
#define META_CACHE_BASE_BUCKET 1024
#define META_CACHE_STATS_BUCKET 16
@@ -34,7 +35,6 @@ typedef struct SMetaStbStatsEntry {
typedef struct STagFilterResEntry {
SList list; // the linked list of md5 digest, extracted from the serialized tag query condition
uint32_t hitTimes; // queried times for current super table
- uint32_t accTime;
} STagFilterResEntry;
struct SMetaCache {
@@ -455,26 +455,37 @@ static int checkAllEntriesInCache(const STagFilterResEntry* pEntry, SArray* pInv
return 0;
}
+static FORCE_INLINE void setMD5DigestInKey(uint64_t* pBuf, const char* key, int32_t keyLen) {
+// ASSERT(keyLen == sizeof(int64_t) * 2);
+ memcpy(&pBuf[2], key, keyLen);
+}
+
+// the format of key:
+// hash table address(8bytes) + suid(8bytes) + MD5 digest(16bytes)
+static void initCacheKey(uint64_t* buf, const SHashObj* pHashMap, uint64_t suid, const char* key, int32_t keyLen) {
+ buf[0] = (uint64_t) pHashMap;
+ buf[1] = suid;
+ setMD5DigestInKey(buf, key, keyLen);
+ ASSERT(keyLen == sizeof(uint64_t) * 2);
+}
+
int32_t metaGetCachedTableUidList(SMeta* pMeta, tb_uid_t suid, const uint8_t* pKey, int32_t keyLen, SArray* pList1,
bool* acquireRes) {
+ int32_t vgId = TD_VID(pMeta->pVnode);
+
// generate the composed key for LRU cache
SLRUCache* pCache = pMeta->pCache->sTagFilterResCache.pUidResCache;
SHashObj* pTableMap = pMeta->pCache->sTagFilterResCache.pTableEntry;
TdThreadMutex* pLock = &pMeta->pCache->sTagFilterResCache.lock;
- uint64_t buf[4];
-
*acquireRes = 0;
-
- buf[0] = (uint64_t)pTableMap;
- buf[1] = suid;
- memcpy(&buf[2], pKey, keyLen);
+ uint64_t key[4];
+ initCacheKey(key, pTableMap, suid, (const char*)pKey, keyLen);
taosThreadMutexLock(pLock);
pMeta->pCache->sTagFilterResCache.accTimes += 1;
- int32_t len = keyLen + sizeof(uint64_t) * 2;
- LRUHandle* pHandle = taosLRUCacheLookup(pCache, buf, len);
+ LRUHandle* pHandle = taosLRUCacheLookup(pCache, key, TAG_FILTER_RES_KEY_LEN);
if (pHandle == NULL) {
taosThreadMutexUnlock(pLock);
return TSDB_CODE_SUCCESS;
@@ -499,7 +510,7 @@ int32_t metaGetCachedTableUidList(SMeta* pMeta, tb_uid_t suid, const uint8_t* pK
uint32_t acc = pMeta->pCache->sTagFilterResCache.accTimes;
if ((*pEntry)->hitTimes % 5000 == 0 && (*pEntry)->hitTimes > 0) {
- metaInfo("cache hit:%d, total acc:%d, rate:%.2f", (*pEntry)->hitTimes, acc, ((double)(*pEntry)->hitTimes) / acc);
+ metaInfo("vgId:%d cache hit:%d, total acc:%d, rate:%.2f", vgId, (*pEntry)->hitTimes, acc, ((double)(*pEntry)->hitTimes) / acc);
}
taosLRUCacheRelease(pCache, pHandle, false);
@@ -563,10 +574,13 @@ static int32_t addNewEntry(SHashObj* pTableEntry, const void* pKey, int32_t keyL
// check both the payload size and selectivity ratio
int32_t metaUidFilterCachePut(SMeta* pMeta, uint64_t suid, const void* pKey, int32_t keyLen, void* pPayload,
int32_t payloadLen, double selectivityRatio) {
+ int32_t code = 0;
+ int32_t vgId = TD_VID(pMeta->pVnode);
+
if (selectivityRatio > tsSelectivityRatio) {
metaDebug("vgId:%d, suid:%" PRIu64
" failed to add to uid list cache, due to selectivity ratio %.2f less than threshold %.2f",
- TD_VID(pMeta->pVnode), suid, selectivityRatio, tsSelectivityRatio);
+ vgId, suid, selectivityRatio, tsSelectivityRatio);
taosMemoryFree(pPayload);
return TSDB_CODE_SUCCESS;
}
@@ -574,7 +588,7 @@ int32_t metaUidFilterCachePut(SMeta* pMeta, uint64_t suid, const void* pKey, int
if (payloadLen > tsTagFilterResCacheSize) {
metaDebug("vgId:%d, suid:%" PRIu64
" failed to add to uid list cache, due to payload length %d greater than threshold %d",
- TD_VID(pMeta->pVnode), suid, payloadLen, tsTagFilterResCacheSize);
+ vgId, suid, payloadLen, tsTagFilterResCacheSize);
taosMemoryFree(pPayload);
return TSDB_CODE_SUCCESS;
}
@@ -583,26 +597,17 @@ int32_t metaUidFilterCachePut(SMeta* pMeta, uint64_t suid, const void* pKey, int
SHashObj* pTableEntry = pMeta->pCache->sTagFilterResCache.pTableEntry;
TdThreadMutex* pLock = &pMeta->pCache->sTagFilterResCache.lock;
- // the format of key:
- // hash table address(8bytes) + suid(8bytes) + MD5 digest(16bytes)
+ uint64_t key[4] = {0};
+ initCacheKey(key, pTableEntry, suid, pKey, keyLen);
- uint64_t buf[4] = {0};
- buf[0] = (uint64_t)pTableEntry;
- buf[1] = suid;
- memcpy(&buf[2], pKey, keyLen);
- ASSERT(keyLen == 16);
-
- int32_t code = 0;
taosThreadMutexLock(pLock);
-
STagFilterResEntry** pEntry = taosHashGet(pTableEntry, &suid, sizeof(uint64_t));
if (pEntry == NULL) {
code = addNewEntry(pTableEntry, pKey, keyLen, suid);
if (code != TSDB_CODE_SUCCESS) {
goto _end;
}
- } else {
- // check if it exists or not
+ } else { // check if it exists or not
size_t size = listNEles(&(*pEntry)->list);
if (size == 0) {
tdListAppend(&(*pEntry)->list, pKey);
@@ -620,12 +625,11 @@ int32_t metaUidFilterCachePut(SMeta* pMeta, uint64_t suid, const void* pKey, int
}
// add to cache.
- taosLRUCacheInsert(pCache, buf, sizeof(uint64_t) * 2 + keyLen, pPayload, payloadLen, freePayload, NULL,
+ taosLRUCacheInsert(pCache, key, TAG_FILTER_RES_KEY_LEN, pPayload, payloadLen, freePayload, NULL,
TAOS_LRU_PRIORITY_LOW);
_end:
taosThreadMutexUnlock(pLock);
-
- metaDebug("vgId:%d, suid:%" PRIu64 " list cache added into cache, total:%d, tables:%d", TD_VID(pMeta->pVnode), suid,
+ metaDebug("vgId:%d, suid:%" PRIu64 " list cache added into cache, total:%d, tables:%d", vgId, suid,
(int32_t)taosLRUCacheGetUsage(pCache), taosHashGetSize(pTableEntry));
return code;
@@ -633,33 +637,36 @@ _end:
// remove the lru cache that are expired due to the tags value update, or creating, or dropping, of child tables
int32_t metaUidCacheClear(SMeta* pMeta, uint64_t suid) {
- int32_t keyLen = sizeof(uint64_t) * 3;
- uint64_t p[4] = {0};
+ uint64_t p[4] = {0};
+ int32_t vgId = TD_VID(pMeta->pVnode);
+ SHashObj* pEntryHashMap = pMeta->pCache->sTagFilterResCache.pTableEntry;
- p[0] = (uint64_t)pMeta->pCache->sTagFilterResCache.pTableEntry;
- p[1] = suid;
+ uint64_t dummy[2] = {0};
+ initCacheKey(p, pEntryHashMap, suid, (char*) &dummy[0], 16);
TdThreadMutex* pLock = &pMeta->pCache->sTagFilterResCache.lock;
-
taosThreadMutexLock(pLock);
- STagFilterResEntry** pEntry = taosHashGet(pMeta->pCache->sTagFilterResCache.pTableEntry, &suid, sizeof(uint64_t));
+
+ STagFilterResEntry** pEntry = taosHashGet(pEntryHashMap, &suid, sizeof(uint64_t));
if (pEntry == NULL || listNEles(&(*pEntry)->list) == 0) {
taosThreadMutexUnlock(pLock);
return TSDB_CODE_SUCCESS;
}
+ (*pEntry)->hitTimes = 0;
+
SListIter iter = {0};
tdListInitIter(&(*pEntry)->list, &iter, TD_LIST_FORWARD);
SListNode* pNode = NULL;
while ((pNode = tdListNext(&iter)) != NULL) {
- memcpy(&p[2], pNode->data, 16);
- taosLRUCacheErase(pMeta->pCache->sTagFilterResCache.pUidResCache, p, keyLen);
+ setMD5DigestInKey(p, pNode->data, 2 * sizeof(uint64_t));
+ taosLRUCacheErase(pMeta->pCache->sTagFilterResCache.pUidResCache, p, TAG_FILTER_RES_KEY_LEN);
}
- (*pEntry)->hitTimes = 0;
tdListEmpty(&(*pEntry)->list);
-
taosThreadMutexUnlock(pLock);
+
+ metaDebug("vgId:%d suid:%"PRId64" cached related tag filter uid list cleared", vgId, suid);
return TSDB_CODE_SUCCESS;
}
diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c
index 5d3350a69a..cac5d7a30c 100644
--- a/source/dnode/vnode/src/tq/tq.c
+++ b/source/dnode/vnode/src/tq/tq.c
@@ -68,7 +68,13 @@ static void destroySTqHandle(void* data) {
static void tqPushEntryFree(void* data) {
STqPushEntry* p = *(void**)data;
- tDeleteSMqDataRsp(&p->dataRsp);
+ if (p->pDataRsp->head.mqMsgType == TMQ_MSG_TYPE__POLL_RSP) {
+ tDeleteSMqDataRsp(p->pDataRsp);
+ } else if (p->pDataRsp->head.mqMsgType == TMQ_MSG_TYPE__TAOSX_RSP) {
+ tDeleteSTaosxRsp((STaosxRsp*)p->pDataRsp);
+ }
+
+ taosMemoryFree(p->pDataRsp);
taosMemoryFree(p);
}
@@ -166,8 +172,57 @@ int32_t tqSendMetaPollRsp(STQ* pTq, const SRpcMsg* pMsg, const SMqPollReq* pReq,
return 0;
}
+static int32_t doSendDataRsp(const SRpcHandleInfo* pRpcHandleInfo, const SMqDataRsp* pRsp, int32_t epoch,
+ int64_t consumerId, int32_t type) {
+ int32_t len = 0;
+ int32_t code = 0;
+
+ if (type == TMQ_MSG_TYPE__POLL_RSP) {
+ tEncodeSize(tEncodeSMqDataRsp, pRsp, len, code);
+ } else if (type == TMQ_MSG_TYPE__TAOSX_RSP) {
+ tEncodeSize(tEncodeSTaosxRsp, (STaosxRsp*)pRsp, len, code);
+ }
+
+ if (code < 0) {
+ return -1;
+ }
+
+ int32_t tlen = sizeof(SMqRspHead) + len;
+ void* buf = rpcMallocCont(tlen);
+ if (buf == NULL) {
+ return -1;
+ }
+
+ ((SMqRspHead*)buf)->mqMsgType = type;
+ ((SMqRspHead*)buf)->epoch = epoch;
+ ((SMqRspHead*)buf)->consumerId = consumerId;
+
+ void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
+
+ SEncoder encoder = {0};
+ tEncoderInit(&encoder, abuf, len);
+
+ if (type == TMQ_MSG_TYPE__POLL_RSP) {
+ tEncodeSMqDataRsp(&encoder, pRsp);
+ } else if (type == TMQ_MSG_TYPE__TAOSX_RSP) {
+ tEncodeSTaosxRsp(&encoder, (STaosxRsp*) pRsp);
+ }
+
+ tEncoderClear(&encoder);
+
+ SRpcMsg rsp = {
+ .info = *pRpcHandleInfo,
+ .pCont = buf,
+ .contLen = tlen,
+ .code = 0,
+ };
+
+ tmsgSendRsp(&rsp);
+ return 0;
+}
+
int32_t tqPushDataRsp(STQ* pTq, STqPushEntry* pPushEntry) {
- SMqDataRsp* pRsp = &pPushEntry->dataRsp;
+ SMqDataRsp* pRsp = pPushEntry->pDataRsp;
#if 0
A(taosArrayGetSize(pRsp->blockData) == pRsp->blockNum);
@@ -181,37 +236,40 @@ int32_t tqPushDataRsp(STQ* pTq, STqPushEntry* pPushEntry) {
}
#endif
- int32_t len = 0;
- int32_t code = 0;
- tEncodeSize(tEncodeSMqDataRsp, pRsp, len, code);
+// int32_t len = 0;
+// int32_t code = 0;
+// tEncodeSize(tEncodeSMqDataRsp, pRsp, len, code);
+// if (code < 0) {
+// return -1;
+// }
+//
+// int32_t tlen = sizeof(SMqRspHead) + len;
+// void* buf = rpcMallocCont(tlen);
+// if (buf == NULL) {
+// return -1;
+// }
+//
+// memcpy(buf, &pPushEntry->dataRsp.head, sizeof(SMqRspHead));
+//
+// void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
+//
+// SEncoder encoder = {0};
+// tEncoderInit(&encoder, abuf, len);
+// tEncodeSMqDataRsp(&encoder, pRsp);
+// tEncoderClear(&encoder);
+//
+// SRpcMsg rsp = {
+// .info = pPushEntry->pInfo,
+// .pCont = buf,
+// .contLen = tlen,
+// .code = 0,
+// };
+//
+// tmsgSendRsp(&rsp);
+//
- if (code < 0) {
- return -1;
- }
-
- int32_t tlen = sizeof(SMqRspHead) + len;
- void* buf = rpcMallocCont(tlen);
- if (buf == NULL) {
- return -1;
- }
-
- memcpy(buf, &pPushEntry->dataRsp.head, sizeof(SMqRspHead));
-
- void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
-
- SEncoder encoder = {0};
- tEncoderInit(&encoder, abuf, len);
- tEncodeSMqDataRsp(&encoder, pRsp);
- tEncoderClear(&encoder);
-
- SRpcMsg rsp = {
- .info = pPushEntry->pInfo,
- .pCont = buf,
- .contLen = tlen,
- .code = 0,
- };
-
- tmsgSendRsp(&rsp);
+ SMqRspHead* pHeader = &pPushEntry->pDataRsp->head;
+ doSendDataRsp(&pPushEntry->info, pRsp, pHeader->epoch, pHeader->consumerId, pHeader->mqMsgType);
char buf1[80] = {0};
char buf2[80] = {0};
@@ -219,11 +277,10 @@ int32_t tqPushDataRsp(STQ* pTq, STqPushEntry* pPushEntry) {
tFormatOffset(buf2, tListLen(buf2), &pRsp->rspOffset);
tqDebug("vgId:%d, from consumer:0x%" PRIx64 " (epoch %d) push rsp, block num: %d, req:%s, rsp:%s",
TD_VID(pTq->pVnode), pRsp->head.consumerId, pRsp->head.epoch, pRsp->blockNum, buf1, buf2);
-
return 0;
}
-int32_t tqSendDataRsp(STQ* pTq, const SRpcMsg* pMsg, const SMqPollReq* pReq, const SMqDataRsp* pRsp) {
+int32_t tqSendDataRsp(STQ* pTq, const SRpcMsg* pMsg, const SMqPollReq* pReq, const SMqDataRsp* pRsp, int32_t type) {
#if 0
A(taosArrayGetSize(pRsp->blockData) == pRsp->blockNum);
A(taosArrayGetSize(pRsp->blockDataLen) == pRsp->blockNum);
@@ -240,107 +297,126 @@ int32_t tqSendDataRsp(STQ* pTq, const SRpcMsg* pMsg, const SMqPollReq* pReq, con
}
#endif
- int32_t len = 0;
- int32_t code = 0;
- tEncodeSize(tEncodeSMqDataRsp, pRsp, len, code);
- if (code < 0) {
- return -1;
- }
- int32_t tlen = sizeof(SMqRspHead) + len;
- void* buf = rpcMallocCont(tlen);
- if (buf == NULL) {
- return -1;
- }
-
- ((SMqRspHead*)buf)->mqMsgType = TMQ_MSG_TYPE__POLL_RSP;
- ((SMqRspHead*)buf)->epoch = pReq->epoch;
- ((SMqRspHead*)buf)->consumerId = pReq->consumerId;
-
- void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
-
- SEncoder encoder = {0};
- tEncoderInit(&encoder, abuf, len);
- tEncodeSMqDataRsp(&encoder, pRsp);
- tEncoderClear(&encoder);
-
- SRpcMsg rsp = {
- .info = pMsg->info,
- .pCont = buf,
- .contLen = tlen,
- .code = 0,
- };
- tmsgSendRsp(&rsp);
+// int32_t len = 0;
+// int32_t code = 0;
+//
+// if (type == TMQ_MSG_TYPE__POLL_RSP) {
+// tEncodeSize(tEncodeSMqDataRsp, pRsp, len, code);
+// } else if (type == TMQ_MSG_TYPE__TAOSX_RSP) {
+// tEncodeSize(tEncodeSTaosxRsp, (STaosxRsp*)pRsp, len, code);
+// }
+//
+// if (code < 0) {
+// return -1;
+// }
+//
+// int32_t tlen = sizeof(SMqRspHead) + len;
+// void* buf = rpcMallocCont(tlen);
+// if (buf == NULL) {
+// return -1;
+// }
+//
+// ((SMqRspHead*)buf)->mqMsgType = type;
+// ((SMqRspHead*)buf)->epoch = pReq->epoch;
+// ((SMqRspHead*)buf)->consumerId = pReq->consumerId;
+//
+// void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
+//
+// SEncoder encoder = {0};
+// tEncoderInit(&encoder, abuf, len);
+//
+// if (type == TMQ_MSG_TYPE__POLL_RSP) {
+// tEncodeSMqDataRsp(&encoder, pRsp);
+// } else if (type == TMQ_MSG_TYPE__TAOSX_RSP) {
+// tEncodeSTaosxRsp(&encoder, (STaosxRsp*) pRsp);
+// }
+//
+// tEncoderClear(&encoder);
+//
+// SRpcMsg rsp = {
+// .info = pMsg->info,
+// .pCont = buf,
+// .contLen = tlen,
+// .code = 0,
+// };
+//
+// tmsgSendRsp(&rsp);
+ doSendDataRsp(&pMsg->info, pRsp, pReq->epoch, pReq->consumerId, type);
char buf1[80] = {0};
char buf2[80] = {0};
tFormatOffset(buf1, 80, &pRsp->reqOffset);
tFormatOffset(buf2, 80, &pRsp->rspOffset);
- tqDebug("vgId:%d consumer:0x%" PRIx64 " (epoch %d), block num:%d, req:%s, rsp:%s",
+
+ tqDebug("vgId:%d consumer:0x%" PRIx64 " (epoch %d) send rsp, block num:%d, req:%s, rsp:%s",
TD_VID(pTq->pVnode), pReq->consumerId, pReq->epoch, pRsp->blockNum, buf1, buf2);
return 0;
}
-int32_t tqSendTaosxRsp(STQ* pTq, const SRpcMsg* pMsg, const SMqPollReq* pReq, const STaosxRsp* pRsp) {
-#if 0
- A(taosArrayGetSize(pRsp->blockData) == pRsp->blockNum);
- A(taosArrayGetSize(pRsp->blockDataLen) == pRsp->blockNum);
-
- if (pRsp->withSchema) {
- A(taosArrayGetSize(pRsp->blockSchema) == pRsp->blockNum);
- } else {
- A(taosArrayGetSize(pRsp->blockSchema) == 0);
- }
-
- if (pRsp->reqOffset.type == TMQ_OFFSET__LOG) {
- if (pRsp->blockNum > 0) {
- A(pRsp->rspOffset.version > pRsp->reqOffset.version);
- } else {
- A(pRsp->rspOffset.version >= pRsp->reqOffset.version);
- }
- }
-#endif
-
- int32_t len = 0;
- int32_t code = 0;
- tEncodeSize(tEncodeSTaosxRsp, pRsp, len, code);
- if (code < 0) {
- return -1;
- }
- int32_t tlen = sizeof(SMqRspHead) + len;
- void* buf = rpcMallocCont(tlen);
- if (buf == NULL) {
- return -1;
- }
-
- ((SMqRspHead*)buf)->mqMsgType = TMQ_MSG_TYPE__TAOSX_RSP;
- ((SMqRspHead*)buf)->epoch = pReq->epoch;
- ((SMqRspHead*)buf)->consumerId = pReq->consumerId;
-
- void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
-
- SEncoder encoder = {0};
- tEncoderInit(&encoder, abuf, len);
- tEncodeSTaosxRsp(&encoder, pRsp);
- tEncoderClear(&encoder);
-
- SRpcMsg rsp = {
- .info = pMsg->info,
- .pCont = buf,
- .contLen = tlen,
- .code = 0,
- };
- tmsgSendRsp(&rsp);
-
- char buf1[80] = {0};
- char buf2[80] = {0};
- tFormatOffset(buf1, 80, &pRsp->reqOffset);
- tFormatOffset(buf2, 80, &pRsp->rspOffset);
- tqDebug("taosx rsp, vgId:%d, from consumer:0x%" PRIx64 " (epoch %d) send rsp, numOfBlks:%d, req:%s, rsp:%s",
- TD_VID(pTq->pVnode), pReq->consumerId, pReq->epoch, pRsp->blockNum, buf1, buf2);
-
- return 0;
-}
+//int32_t tqSendTaosxRsp(STQ* pTq, const SRpcMsg* pMsg, const SMqPollReq* pReq, const STaosxRsp* pRsp) {
+//#if 0
+// A(taosArrayGetSize(pRsp->blockData) == pRsp->blockNum);
+// A(taosArrayGetSize(pRsp->blockDataLen) == pRsp->blockNum);
+//
+// if (pRsp->withSchema) {
+// A(taosArrayGetSize(pRsp->blockSchema) == pRsp->blockNum);
+// } else {
+// A(taosArrayGetSize(pRsp->blockSchema) == 0);
+// }
+//
+// if (pRsp->reqOffset.type == TMQ_OFFSET__LOG) {
+// if (pRsp->blockNum > 0) {
+// A(pRsp->rspOffset.version > pRsp->reqOffset.version);
+// } else {
+// A(pRsp->rspOffset.version >= pRsp->reqOffset.version);
+// }
+// }
+//#endif
+//
+// int32_t len = 0;
+// int32_t code = 0;
+// tEncodeSize(tEncodeSTaosxRsp, pRsp, len, code);
+// if (code < 0) {
+// return -1;
+// }
+//
+// int32_t tlen = sizeof(SMqRspHead) + len;
+// void* buf = rpcMallocCont(tlen);
+// if (buf == NULL) {
+// terrno = TSDB_CODE_OUT_OF_MEMORY;
+// return -1;
+// }
+//
+// ((SMqRspHead*)buf)->mqMsgType = TMQ_MSG_TYPE__TAOSX_RSP;
+// ((SMqRspHead*)buf)->epoch = pReq->epoch;
+// ((SMqRspHead*)buf)->consumerId = pReq->consumerId;
+//
+// void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
+//
+// SEncoder encoder = {0};
+// tEncoderInit(&encoder, abuf, len);
+// tEncodeSTaosxRsp(&encoder, pRsp);
+// tEncoderClear(&encoder);
+//
+// SRpcMsg rsp = {
+// .info = pMsg->info,
+// .pCont = buf,
+// .contLen = tlen,
+// .code = 0,
+// };
+//
+// tmsgSendRsp(&rsp);
+//
+// char buf1[80] = {0};
+// char buf2[80] = {0};
+// tFormatOffset(buf1, 80, &pRsp->reqOffset);
+// tFormatOffset(buf2, 80, &pRsp->rspOffset);
+//
+// tqDebug("taosx rsp, vgId:%d, consumer:0x%" PRIx64 " (epoch %d) send rsp, numOfBlks:%d, req:%s, rsp:%s",
+// TD_VID(pTq->pVnode), pReq->consumerId, pReq->epoch, pRsp->blockNum, buf1, buf2);
+// return 0;
+//}
static FORCE_INLINE bool tqOffsetLessOrEqual(const STqOffset* pLeft, const STqOffset* pRight) {
return pLeft->val.type == TMQ_OFFSET__LOG && pRight->val.type == TMQ_OFFSET__LOG &&
@@ -440,9 +516,7 @@ static int32_t tqInitDataRsp(SMqDataRsp* pRsp, const SMqPollReq* pReq, int8_t su
}
#endif
- /*A(subType == TOPIC_SUB_TYPE__COLUMN);*/
pRsp->withSchema = false;
-
return 0;
}
@@ -463,170 +537,147 @@ static int32_t tqInitTaosxRsp(STaosxRsp* pRsp, const SMqPollReq* pReq) {
return 0;
}
-int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) {
- SMqPollReq req = {0};
- int32_t code = 0;
- STqOffsetVal fetchOffsetNew;
- SWalCkHead* pCkHead = NULL;
+static int32_t extractResetOffsetVal(STqOffsetVal* pOffsetVal, STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest,
+ SRpcMsg* pMsg, bool* pBlockReturned) {
+ uint64_t consumerId = pRequest->consumerId;
+ STqOffsetVal reqOffset = pRequest->reqOffset;
+ STqOffset* pOffset = tqOffsetRead(pTq->pOffsetStore, pRequest->subKey);
+ *pBlockReturned = false;
- if (tDeserializeSMqPollReq(pMsg->pCont, pMsg->contLen, &req) < 0) {
- tqError("tDeserializeSMqPollReq %d failed", pMsg->contLen);
- return -1;
- }
+ // In this vnode, data has been polled by consumer for this topic, so let's continue from the last offset value.
+ if (pOffset != NULL) {
+ *pOffsetVal = pOffset->val;
- int64_t consumerId = req.consumerId;
- int32_t reqEpoch = req.epoch;
- STqOffsetVal reqOffset = req.reqOffset;
-
- // 1. find handle
- STqHandle* pHandle = taosHashGet(pTq->pHandle, req.subKey, strlen(req.subKey));
- if (pHandle == NULL) {
- tqError("tmq poll: consumer:0x%" PRIx64 " vgId:%d, subkey %s not found", consumerId, TD_VID(pTq->pVnode),
- req.subKey);
- return -1;
- }
-
- // 2. check rebalance
- if (pHandle->consumerId != consumerId) {
- tqDebug("ERROR tmq poll: consumer:0x%" PRIx64 " vgId:%d, subkey %s, mismatch for saved handle consumer:0x%" PRIx64,
- consumerId, TD_VID(pTq->pVnode), req.subKey, pHandle->consumerId);
- terrno = TSDB_CODE_TMQ_CONSUMER_MISMATCH;
- return -1;
- }
-
- // update epoch if need
- int32_t savedEpoch = atomic_load_32(&pHandle->epoch);
- while (savedEpoch < reqEpoch) {
- tqDebug("tmq poll: consumer:0x%"PRIx64 " epoch update from %d to %d by poll req", consumerId, savedEpoch, reqEpoch);
- savedEpoch = atomic_val_compare_exchange_32(&pHandle->epoch, savedEpoch, reqEpoch);
- }
-
- char buf[80];
- tFormatOffset(buf, 80, &reqOffset);
- tqDebug("tmq poll: consumer:0x%" PRIx64 " (epoch %d), subkey %s, recv poll req vgId:%d, req:%s", consumerId,
- req.epoch, pHandle->subKey, TD_VID(pTq->pVnode), buf);
-
- // 2.reset offset if needed
- if (reqOffset.type > 0) {
- fetchOffsetNew = reqOffset;
+ char formatBuf[80];
+ tFormatOffset(formatBuf, 80, pOffsetVal);
+ tqDebug("tmq poll: consumer:0x%" PRIx64 ", subkey %s, vgId:%d, prev offset found, offset reset to %s and continue.",
+ consumerId, pHandle->subKey, TD_VID(pTq->pVnode), formatBuf);
+ return 0;
} else {
- STqOffset* pOffset = tqOffsetRead(pTq->pOffsetStore, req.subKey);
- if (pOffset != NULL) {
- fetchOffsetNew = pOffset->val;
- char formatBuf[80];
- tFormatOffset(formatBuf, 80, &fetchOffsetNew);
- tqDebug("tmq poll: consumer:0x%" PRIx64 ", subkey %s, vg %d, offset reset to %s", consumerId, pHandle->subKey,
- TD_VID(pTq->pVnode), formatBuf);
- } else {
- if (reqOffset.type == TMQ_OFFSET__RESET_EARLIEAST) {
- if (req.useSnapshot) {
- if (pHandle->fetchMeta) {
- tqOffsetResetToMeta(&fetchOffsetNew, 0);
- } else {
- tqOffsetResetToData(&fetchOffsetNew, 0, 0);
- }
+ // no poll occurs in this vnode for this topic, let's seek to the right offset value.
+ if (reqOffset.type == TMQ_OFFSET__RESET_EARLIEAST) {
+ if (pRequest->useSnapshot) {
+ if (pHandle->fetchMeta) {
+ tqOffsetResetToMeta(pOffsetVal, 0);
} else {
- pHandle->pRef = walRefFirstVer(pTq->pVnode->pWal, pHandle->pRef);
- if (pHandle->pRef == NULL) {
- terrno = TSDB_CODE_OUT_OF_MEMORY;
- return -1;
- }
- tqOffsetResetToLog(&fetchOffsetNew, pHandle->pRef->refVer - 1);
+ tqOffsetResetToData(pOffsetVal, 0, 0);
+ }
+ } else {
+ pHandle->pRef = walRefFirstVer(pTq->pVnode->pWal, pHandle->pRef);
+ if (pHandle->pRef == NULL) {
+ terrno = TSDB_CODE_OUT_OF_MEMORY;
+ return -1;
}
- } else if (reqOffset.type == TMQ_OFFSET__RESET_LATEST) {
- if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
- SMqDataRsp dataRsp = {0};
- tqInitDataRsp(&dataRsp, &req, pHandle->execHandle.subType);
- tqOffsetResetToLog(&dataRsp.rspOffset, walGetLastVer(pTq->pVnode->pWal));
- tqDebug("tmq poll: consumer:0x%" PRIx64 ", subkey %s, vgId:%d, offset reset to %" PRId64, consumerId,
- pHandle->subKey, TD_VID(pTq->pVnode), dataRsp.rspOffset.version);
- if (tqSendDataRsp(pTq, pMsg, &req, &dataRsp) < 0) {
- code = -1;
- }
- tDeleteSMqDataRsp(&dataRsp);
- return code;
- } else {
- STaosxRsp taosxRsp = {0};
- tqInitTaosxRsp(&taosxRsp, &req);
- tqOffsetResetToLog(&taosxRsp.rspOffset, walGetLastVer(pTq->pVnode->pWal));
- if (tqSendTaosxRsp(pTq, pMsg, &req, &taosxRsp) < 0) {
- code = -1;
- }
- tDeleteSTaosxRsp(&taosxRsp);
- return code;
- }
- } else if (reqOffset.type == TMQ_OFFSET__RESET_NONE) {
- tqError("tmq poll: subkey %s, no offset committed for consumer:0x%" PRIx64
- " in vg %d, subkey %s, reset none failed",
- pHandle->subKey, consumerId, TD_VID(pTq->pVnode), req.subKey);
- terrno = TSDB_CODE_TQ_NO_COMMITTED_OFFSET;
- return -1;
+ tqOffsetResetToLog(pOffsetVal, pHandle->pRef->refVer - 1);
}
- }
- }
+ } else if (reqOffset.type == TMQ_OFFSET__RESET_LATEST) {
+ if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
+ SMqDataRsp dataRsp = {0};
+ tqInitDataRsp(&dataRsp, pRequest, pHandle->execHandle.subType);
- if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
- SMqDataRsp dataRsp = {0};
- tqInitDataRsp(&dataRsp, &req, pHandle->execHandle.subType);
- // lock
- taosWLockLatch(&pTq->pushLock);
- if (tqScanData(pTq, pHandle, &dataRsp, &fetchOffsetNew) < 0) {
+ tqOffsetResetToLog(&dataRsp.rspOffset, walGetLastVer(pTq->pVnode->pWal));
+ tqDebug("tmq poll: consumer:0x%" PRIx64 ", subkey %s, vgId:%d, offset reset to %" PRId64, consumerId,
+ pHandle->subKey, TD_VID(pTq->pVnode), dataRsp.rspOffset.version);
+ int32_t code = tqSendDataRsp(pTq, pMsg, pRequest, &dataRsp, TMQ_MSG_TYPE__POLL_RSP);
+ tDeleteSMqDataRsp(&dataRsp);
+
+ *pBlockReturned = true;
+ return code;
+ } else {
+ STaosxRsp taosxRsp = {0};
+ tqInitTaosxRsp(&taosxRsp, pRequest);
+ tqOffsetResetToLog(&taosxRsp.rspOffset, walGetLastVer(pTq->pVnode->pWal));
+ int32_t code = tqSendDataRsp(pTq, pMsg, pRequest, (SMqDataRsp*)&taosxRsp, TMQ_MSG_TYPE__TAOSX_RSP);
+// int32_t code = tqSendTaosxRsp(pTq, pMsg, pRequest, &taosxRsp);
+ tDeleteSTaosxRsp(&taosxRsp);
+
+ *pBlockReturned = true;
+ return code;
+ }
+ } else if (reqOffset.type == TMQ_OFFSET__RESET_NONE) {
+ tqError("tmq poll: subkey %s, no offset committed for consumer:0x%" PRIx64
+ " in vg %d, subkey %s, reset none failed",
+ pHandle->subKey, consumerId, TD_VID(pTq->pVnode), pRequest->subKey);
+ terrno = TSDB_CODE_TQ_NO_COMMITTED_OFFSET;
return -1;
}
+ }
- // till now, all data has been rsp to consumer, new data needs to push client once arrived.
+ return 0;
+}
+
+static int32_t extractDataForMq(STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest, SRpcMsg* pMsg) {
+ int32_t code = -1;
+ STqOffsetVal offset = {0};
+ SWalCkHead* pCkHead = NULL;
+ int32_t vgId = TD_VID(pTq->pVnode);
+
+ STqOffsetVal reqOffset = pRequest->reqOffset;
+ uint64_t consumerId = pRequest->consumerId;
+
+ // 1. reset the offset if needed
+ if (reqOffset.type > 0) {
+ offset = reqOffset;
+ } else { // handle the reset offset cases, according to the consumer's choice.
+ bool blockReturned = false;
+ code = extractResetOffsetVal(&offset, pTq, pHandle, pRequest, pMsg, &blockReturned);
+ if (code != 0) {
+ return code;
+ }
+
+ // empty block returned, quit
+ if (blockReturned) {
+ return 0;
+ }
+ }
+
+ // this is a normal subscription requirement
+ if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
+ SMqDataRsp dataRsp = {0};
+ tqInitDataRsp(&dataRsp, pRequest, pHandle->execHandle.subType);
+
+ // lock
+ taosWLockLatch(&pTq->pushLock);
+ code = tqScanData(pTq, pHandle, &dataRsp, &offset);
+
+ // till now, all data has been transferred to consumer, new data needs to push client once arrived.
if (dataRsp.blockNum == 0 && dataRsp.reqOffset.type == TMQ_OFFSET__LOG &&
- dataRsp.reqOffset.version == dataRsp.rspOffset.version) {
- STqPushEntry* pPushEntry = taosMemoryCalloc(1, sizeof(STqPushEntry));
- if (pPushEntry != NULL) {
- pPushEntry->pInfo = pMsg->info;
- memcpy(pPushEntry->subKey, pHandle->subKey, TSDB_SUBSCRIBE_KEY_LEN);
- dataRsp.withTbName = 0;
- memcpy(&pPushEntry->dataRsp, &dataRsp, sizeof(SMqDataRsp));
- pPushEntry->dataRsp.head.consumerId = consumerId;
- pPushEntry->dataRsp.head.epoch = reqEpoch;
- pPushEntry->dataRsp.head.mqMsgType = TMQ_MSG_TYPE__POLL_RSP;
- taosHashPut(pTq->pPushMgr, pHandle->subKey, strlen(pHandle->subKey) + 1, &pPushEntry, sizeof(void*));
-
- tqDebug("tmq poll: consumer:0x%" PRIx64 ", subkey %s offset:%" PRId64 ", vgId:%d save handle to push mgr",
- consumerId, pHandle->subKey, dataRsp.reqOffset.version, TD_VID(pTq->pVnode));
- // unlock
- taosWUnLockLatch(&pTq->pushLock);
- return 0;
- }
+ dataRsp.reqOffset.version == dataRsp.rspOffset.version && pHandle->consumerId == pRequest->consumerId) {
+ code = tqRegisterPushEntry(pTq, pHandle, pRequest, pMsg, &dataRsp, TMQ_MSG_TYPE__POLL_RSP);
+ taosWUnLockLatch(&pTq->pushLock);
+ return code;
}
+
taosWUnLockLatch(&pTq->pushLock);
+ code = tqSendDataRsp(pTq, pMsg, pRequest, (SMqDataRsp*)&dataRsp, TMQ_MSG_TYPE__POLL_RSP);
- if (tqSendDataRsp(pTq, pMsg, &req, &dataRsp) < 0) {
- code = -1;
- }
-
- tqDebug("tmq poll: consumer:0x%" PRIx64 ", subkey %s, vgId:%d, rsp block:%d, offset type:%d, uid/version:%" PRId64 ", ts:%" PRId64 "",
- consumerId, pHandle->subKey, TD_VID(pTq->pVnode), dataRsp.blockNum, dataRsp.rspOffset.type,
- dataRsp.rspOffset.uid, dataRsp.rspOffset.ts);
+ // NOTE: this pHandle->consumerId may have been changed already.
+ tqDebug("tmq poll: consumer:0x%" PRIx64 ", subkey %s, vgId:%d, rsp block:%d, offset type:%d, uid/version:%" PRId64
+ ", ts:%" PRId64,
+ consumerId, pHandle->subKey, vgId, dataRsp.blockNum, dataRsp.rspOffset.type, dataRsp.rspOffset.uid,
+ dataRsp.rspOffset.ts);
tDeleteSMqDataRsp(&dataRsp);
return code;
}
+ // todo handle the case where re-balance occurs.
// for taosx
SMqMetaRsp metaRsp = {0};
STaosxRsp taosxRsp = {0};
- tqInitTaosxRsp(&taosxRsp, &req);
+ tqInitTaosxRsp(&taosxRsp, pRequest);
- if (fetchOffsetNew.type != TMQ_OFFSET__LOG) {
- if (tqScanTaosx(pTq, pHandle, &taosxRsp, &metaRsp, &fetchOffsetNew) < 0) {
+ if (offset.type != TMQ_OFFSET__LOG) {
+ if (tqScanTaosx(pTq, pHandle, &taosxRsp, &metaRsp, &offset) < 0) {
return -1;
}
if (metaRsp.metaRspLen > 0) {
- if (tqSendMetaPollRsp(pTq, pMsg, &req, &metaRsp) < 0) {
- code = -1;
- }
- tqDebug("tmq poll: consumer:0x%" PRIx64 " subkey %s, vg %d, send meta offset type:%d,uid:%" PRId64
+ code = tqSendMetaPollRsp(pTq, pMsg, pRequest, &metaRsp);
+ tqDebug("tmq poll: consumer:0x%" PRIx64 " subkey:%s vgId:%d, send meta offset type:%d,uid:%" PRId64
",version:%" PRId64,
- consumerId, pHandle->subKey, TD_VID(pTq->pVnode), metaRsp.rspOffset.type, metaRsp.rspOffset.uid,
+ consumerId, pHandle->subKey, vgId, metaRsp.rspOffset.type, metaRsp.rspOffset.uid,
metaRsp.rspOffset.version);
taosMemoryFree(metaRsp.metaRsp);
tDeleteSTaosxRsp(&taosxRsp);
@@ -634,54 +685,56 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) {
}
if (taosxRsp.blockNum > 0) {
- if (tqSendTaosxRsp(pTq, pMsg, &req, &taosxRsp) < 0) {
- code = -1;
- }
+ code = tqSendDataRsp(pTq, pMsg, pRequest, (SMqDataRsp*)&taosxRsp, TMQ_MSG_TYPE__TAOSX_RSP);
tDeleteSTaosxRsp(&taosxRsp);
return code;
} else {
- fetchOffsetNew = taosxRsp.rspOffset;
+ offset = taosxRsp.rspOffset;
}
- tqDebug("taosx poll: consumer:0x%" PRIx64 " subkey %s, vg %d, send data blockNum:%d, offset type:%d,uid:%" PRId64
+ tqDebug("taosx poll: consumer:0x%" PRIx64 " subkey:%s vgId:%d, send data blockNum:%d, offset type:%d,uid:%" PRId64
",version:%" PRId64,
- consumerId, pHandle->subKey, TD_VID(pTq->pVnode), taosxRsp.blockNum, taosxRsp.rspOffset.type,
- taosxRsp.rspOffset.uid, taosxRsp.rspOffset.version);
- }
+ consumerId, pHandle->subKey, vgId, taosxRsp.blockNum, taosxRsp.rspOffset.type, taosxRsp.rspOffset.uid,
+ taosxRsp.rspOffset.version);
+ } else {
- if (fetchOffsetNew.type == TMQ_OFFSET__LOG) {
- int64_t fetchVer = fetchOffsetNew.version + 1;
+// if (offset.type == TMQ_OFFSET__LOG) {
+ int64_t fetchVer = offset.version + 1;
pCkHead = taosMemoryMalloc(sizeof(SWalCkHead) + 2048);
if (pCkHead == NULL) {
tDeleteSTaosxRsp(&taosxRsp);
+ terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
walSetReaderCapacity(pHandle->pWalReader, 2048);
while (1) {
- savedEpoch = atomic_load_32(&pHandle->epoch);
- if (savedEpoch > reqEpoch) {
- tqWarn("tmq poll: consumer:0x%" PRIx64 " (epoch %d), subkey %s, vg %d offset %" PRId64
+ // todo refactor: this is not correct.
+ int32_t savedEpoch = atomic_load_32(&pHandle->epoch);
+ if (savedEpoch > pRequest->epoch) {
+ tqWarn("tmq poll: consumer:0x%" PRIx64 " (epoch %d), subkey:%s vgId:%d offset %" PRId64
", found new consumer epoch %d, discard req epoch %d",
- consumerId, req.epoch, pHandle->subKey, TD_VID(pTq->pVnode), fetchVer, savedEpoch, reqEpoch);
+ consumerId, pRequest->epoch, pHandle->subKey, vgId, fetchVer, savedEpoch, pRequest->epoch);
break;
}
if (tqFetchLog(pTq, pHandle, &fetchVer, &pCkHead) < 0) {
tqOffsetResetToLog(&taosxRsp.rspOffset, fetchVer);
- if (tqSendTaosxRsp(pTq, pMsg, &req, &taosxRsp) < 0) {
- code = -1;
- }
- tDeleteSTaosxRsp(&taosxRsp);
- taosMemoryFreeClear(pCkHead);
- return code;
+// if (terrno == 0) { // failed to seek to given ver, but no errors happen.
+// code = tqRegisterPushEntry(pTq, pHandle, pRequest, pMsg, (SMqDataRsp*) &taosxRsp, TMQ_MSG_TYPE__TAOSX_RSP);
+// return code;
+// } else { // error happens, return to consumers
+ code = tqSendDataRsp(pTq, pMsg, pRequest, (SMqDataRsp*)&taosxRsp, TMQ_MSG_TYPE__TAOSX_RSP);
+ tDeleteSTaosxRsp(&taosxRsp);
+ taosMemoryFreeClear(pCkHead);
+ return code;
+// }
}
SWalCont* pHead = &pCkHead->head;
-
tqDebug("tmq poll: consumer:0x%" PRIx64 " (epoch %d) iter log, vgId:%d offset %" PRId64 " msgType %d", consumerId,
- req.epoch, TD_VID(pTq->pVnode), fetchVer, pHead->msgType);
+ pRequest->epoch, vgId, fetchVer, pHead->msgType);
if (pHead->msgType == TDMT_VND_SUBMIT) {
SPackedData submit = {
@@ -689,16 +742,16 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) {
.msgLen = pHead->bodyLen - sizeof(SSubmitReq2Msg),
.ver = pHead->version,
};
+
if (tqTaosxScanLog(pTq, pHandle, submit, &taosxRsp) < 0) {
- tqError("tmq poll: tqTaosxScanLog error %" PRId64 ", in vgId:%d, subkey %s", consumerId, TD_VID(pTq->pVnode),
- req.subKey);
+ tqError("tmq poll: tqTaosxScanLog error %" PRId64 ", in vgId:%d, subkey %s", consumerId, vgId,
+ pRequest->subKey);
return -1;
}
- if (taosxRsp.blockNum > 0 /* threshold */) {
+
+ if (taosxRsp.blockNum > 0) {
tqOffsetResetToLog(&taosxRsp.rspOffset, fetchVer);
- if (tqSendTaosxRsp(pTq, pMsg, &req, &taosxRsp) < 0) {
- code = -1;
- }
+ code = tqSendDataRsp(pTq, pMsg, pRequest, (SMqDataRsp*)&taosxRsp, TMQ_MSG_TYPE__TAOSX_RSP);
tDeleteSTaosxRsp(&taosxRsp);
taosMemoryFreeClear(pCkHead);
return code;
@@ -714,7 +767,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) {
metaRsp.resMsgType = pHead->msgType;
metaRsp.metaRspLen = pHead->bodyLen;
metaRsp.metaRsp = pHead->body;
- if (tqSendMetaPollRsp(pTq, pMsg, &req, &metaRsp) < 0) {
+ if (tqSendMetaPollRsp(pTq, pMsg, pRequest, &metaRsp) < 0) {
code = -1;
taosMemoryFreeClear(pCkHead);
tDeleteSTaosxRsp(&taosxRsp);
@@ -733,6 +786,55 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) {
return 0;
}
+int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) {
+ SMqPollReq req = {0};
+ if (tDeserializeSMqPollReq(pMsg->pCont, pMsg->contLen, &req) < 0) {
+ tqError("tDeserializeSMqPollReq %d failed", pMsg->contLen);
+ terrno = TSDB_CODE_INVALID_MSG;
+ return -1;
+ }
+
+ int64_t consumerId = req.consumerId;
+ int32_t reqEpoch = req.epoch;
+ STqOffsetVal reqOffset = req.reqOffset;
+ int32_t vgId = TD_VID(pTq->pVnode);
+
+ // 1. find handle
+ STqHandle* pHandle = taosHashGet(pTq->pHandle, req.subKey, strlen(req.subKey));
+ if (pHandle == NULL) {
+ tqError("tmq poll: consumer:0x%" PRIx64 " vgId:%d subkey %s not found", consumerId, vgId, req.subKey);
+ terrno = TSDB_CODE_INVALID_MSG;
+ return -1;
+ }
+
+ // 2. check re-balance status
+ taosRLockLatch(&pTq->pushLock);
+ if (pHandle->consumerId != consumerId) {
+ tqDebug("ERROR tmq poll: consumer:0x%" PRIx64 " vgId:%d, subkey %s, mismatch for saved handle consumer:0x%" PRIx64,
+ consumerId, TD_VID(pTq->pVnode), req.subKey, pHandle->consumerId);
+ terrno = TSDB_CODE_TMQ_CONSUMER_MISMATCH;
+ taosRUnLockLatch(&pTq->pushLock);
+ return -1;
+ }
+ taosRUnLockLatch(&pTq->pushLock);
+
+ taosWLockLatch(&pTq->pushLock);
+ // 3. update the epoch value
+ int32_t savedEpoch = pHandle->epoch;
+ if (savedEpoch < reqEpoch) {
+ tqDebug("tmq poll: consumer:0x%" PRIx64 " epoch update from %d to %d by poll req", consumerId, savedEpoch, reqEpoch);
+ pHandle->epoch = reqEpoch;
+ }
+ taosWUnLockLatch(&pTq->pushLock);
+
+ char buf[80];
+ tFormatOffset(buf, 80, &reqOffset);
+ tqDebug("tmq poll: consumer:0x%" PRIx64 " (epoch %d), subkey %s, recv poll req vgId:%d, req:%s, reqId:0x%" PRIx64,
+ consumerId, req.epoch, pHandle->subKey, vgId, buf, req.reqId);
+
+ return extractDataForMq(pTq, pHandle, &req, pMsg);
+}
+
int32_t tqProcessDeleteSubReq(STQ* pTq, int64_t sversion, char* msg, int32_t msgLen) {
SMqVDeleteReq* pReq = (SMqVDeleteReq*)msg;
@@ -803,9 +905,9 @@ int32_t tqProcessDelCheckInfoReq(STQ* pTq, int64_t sversion, char* msg, int32_t
int32_t tqProcessSubscribeReq(STQ* pTq, int64_t sversion, char* msg, int32_t msgLen) {
SMqRebVgReq req = {0};
tDecodeSMqRebVgReq(msg, &req);
- // todo lock
- tqDebug("vgId:%d, tq process sub req %s", pTq->pVnode->config.vgId, req.subKey);
+ tqDebug("vgId:%d, tq process sub req %s, Id:0x%" PRIx64 " -> Id:0x%" PRIx64, pTq->pVnode->config.vgId, req.subKey,
+ req.oldConsumerId, req.newConsumerId);
STqHandle* pHandle = taosHashGet(pTq->pHandle, req.subKey, strlen(req.subKey));
if (pHandle == NULL) {
@@ -813,11 +915,13 @@ int32_t tqProcessSubscribeReq(STQ* pTq, int64_t sversion, char* msg, int32_t msg
tqError("vgId:%d, build new consumer handle %s for consumer:0x%" PRIx64 ", but old consumerId is %" PRId64 "",
req.vgId, req.subKey, req.newConsumerId, req.oldConsumerId);
}
+
if (req.newConsumerId == -1) {
tqError("vgId:%d, tq invalid rebalance request, new consumerId %" PRId64 "", req.vgId, req.newConsumerId);
taosMemoryFree(req.qmsg);
return 0;
}
+
STqHandle tqHandle = {0};
pHandle = &tqHandle;
/*taosInitRWLatch(&pExec->lock);*/
@@ -833,8 +937,10 @@ int32_t tqProcessSubscribeReq(STQ* pTq, int64_t sversion, char* msg, int32_t msg
// TODO version should be assigned and refed during preprocess
SWalRef* pRef = walRefCommittedVer(pTq->pVnode->pWal);
if (pRef == NULL) {
+ taosMemoryFree(req.qmsg);
return -1;
}
+
int64_t ver = pRef->refVer;
pHandle->pRef = pRef;
@@ -845,6 +951,7 @@ int32_t tqProcessSubscribeReq(STQ* pTq, int64_t sversion, char* msg, int32_t msg
.initTqReader = true,
.version = ver,
};
+
pHandle->snapshotVer = ver;
if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
@@ -859,6 +966,7 @@ int32_t tqProcessSubscribeReq(STQ* pTq, int64_t sversion, char* msg, int32_t msg
} else if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__DB) {
pHandle->pWalReader = walOpenReader(pTq->pVnode->pWal, NULL);
pHandle->execHandle.pExecReader = tqOpenReader(pTq->pVnode);
+
pHandle->execHandle.execDb.pFilterOutTbUid =
taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK);
buildSnapContext(handle.meta, handle.version, 0, pHandle->execHandle.subType, pHandle->fetchMeta,
@@ -867,7 +975,6 @@ int32_t tqProcessSubscribeReq(STQ* pTq, int64_t sversion, char* msg, int32_t msg
pHandle->execHandle.task = qCreateQueueExecTaskInfo(NULL, &handle, NULL, NULL);
} else if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__TABLE) {
pHandle->pWalReader = walOpenReader(pTq->pVnode->pWal, NULL);
-
pHandle->execHandle.execTb.suid = req.suid;
SArray* tbUidList = taosArrayInit(0, sizeof(int64_t));
@@ -887,28 +994,45 @@ int32_t tqProcessSubscribeReq(STQ* pTq, int64_t sversion, char* msg, int32_t msg
}
taosHashPut(pTq->pHandle, req.subKey, strlen(req.subKey), pHandle, sizeof(STqHandle));
- tqDebug("try to persist handle %s consumer:0x%" PRIx64" , old consumer:0x%"PRIx64, req.subKey, pHandle->consumerId,
- oldConsumerId);
+ tqDebug("try to persist handle %s consumer:0x%" PRIx64 " , old consumer:0x%" PRIx64, req.subKey,
+ pHandle->consumerId, oldConsumerId);
if (tqMetaSaveHandle(pTq, req.subKey, pHandle) < 0) {
+ taosMemoryFree(req.qmsg);
return -1;
}
} else {
- // TODO handle qmsg and exec modification
- tqInfo("update the consumer info, old consumer id:0x%"PRIx64", new Id:0x%"PRIx64, pHandle->consumerId, req.newConsumerId);
+ if (pHandle->consumerId == req.newConsumerId) { // do nothing
+ tqInfo("vgId:%d consumer:0x%" PRIx64 " remains, no switch occurs", req.vgId, req.newConsumerId);
+ atomic_store_32(&pHandle->epoch, -1);
+ atomic_add_fetch_32(&pHandle->epoch, 1);
+ taosMemoryFree(req.qmsg);
+ return tqMetaSaveHandle(pTq, req.subKey, pHandle);
+ }
+
+ tqInfo("vgId:%d switch consumer from Id:0x%" PRIx64 " to Id:0x%" PRIx64, req.vgId, pHandle->consumerId,
+ req.newConsumerId);
+
+ taosWLockLatch(&pTq->pushLock);
atomic_store_32(&pHandle->epoch, -1);
+
+ // remove if it has been register in the push manager, and return one empty block to consumer
+ tqRemovePushEntry(pTq, req.subKey, (int32_t) strlen(req.subKey), pHandle->consumerId, true);
+
atomic_store_64(&pHandle->consumerId, req.newConsumerId);
atomic_add_fetch_32(&pHandle->epoch, 1);
- taosMemoryFree(req.qmsg);
+
if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
qStreamCloseTsdbReader(pHandle->execHandle.task);
}
+ taosWUnLockLatch(&pTq->pushLock);
if (tqMetaSaveHandle(pTq, req.subKey, pHandle) < 0) {
+ taosMemoryFree(req.qmsg);
return -1;
}
- // close handle
}
+ taosMemoryFree(req.qmsg);
return 0;
}
@@ -983,16 +1107,18 @@ int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask, int64_t ver) {
pTask->tbSink.vnode = pTq->pVnode;
pTask->tbSink.tbSinkFunc = tqSinkToTablePipeline2;
- int32_t version = 1;
+ int32_t ver1 = 1;
SMetaInfo info = {0};
int32_t code = metaGetInfo(pTq->pVnode->pMeta, pTask->tbSink.stbUid, &info, NULL);
if (code == TSDB_CODE_SUCCESS) {
- version = info.skmVer;
+ ver1 = info.skmVer;
}
pTask->tbSink.pTSchema =
- tBuildTSchema(pTask->tbSink.pSchemaWrapper->pSchema, pTask->tbSink.pSchemaWrapper->nCols, version);
- ASSERT(pTask->tbSink.pTSchema);
+ tBuildTSchema(pTask->tbSink.pSchemaWrapper->pSchema, pTask->tbSink.pSchemaWrapper->nCols, ver1);
+ if(pTask->tbSink.pTSchema == NULL) {
+ return -1;
+ }
}
streamSetupTrigger(pTask);
diff --git a/source/dnode/vnode/src/tq/tqExec.c b/source/dnode/vnode/src/tq/tqExec.c
index f97c5ce93c..73d3ac069f 100644
--- a/source/dnode/vnode/src/tq/tqExec.c
+++ b/source/dnode/vnode/src/tq/tqExec.c
@@ -46,11 +46,13 @@ static int32_t tqAddBlockSchemaToRsp(const STqExecHandle* pExec, STaosxRsp* pRsp
static int32_t tqAddTbNameToRsp(const STQ* pTq, int64_t uid, STaosxRsp* pRsp, int32_t n) {
SMetaReader mr = {0};
metaReaderInit(&mr, pTq->pVnode->pMeta, 0);
+
// TODO add reference to gurantee success
if (metaGetTableEntryByUidCache(&mr, uid) < 0) {
metaReaderClear(&mr);
return -1;
}
+
for (int32_t i = 0; i < n; i++) {
char* tbName = taosStrdup(mr.me.name);
taosArrayPush(pRsp->blockTbName, &tbName);
@@ -83,13 +85,16 @@ int32_t tqScanData(STQ* pTq, const STqHandle* pHandle, SMqDataRsp* pRsp, STqOffs
while (1) {
SSDataBlock* pDataBlock = NULL;
uint64_t ts = 0;
+
tqDebug("vgId:%d, tmq task start to execute", pTq->pVnode->config.vgId);
if (qExecTask(task, &pDataBlock, &ts) < 0) {
tqError("vgId:%d, task exec error since %s", pTq->pVnode->config.vgId, terrstr());
return -1;
}
+
tqDebug("vgId:%d, tmq task executed, get %p", pTq->pVnode->config.vgId, pDataBlock);
+ // current scan should be stopped asap, since the rebalance occurs.
if (pDataBlock == NULL) {
break;
}
@@ -99,7 +104,9 @@ int32_t tqScanData(STQ* pTq, const STqHandle* pHandle, SMqDataRsp* pRsp, STqOffs
if (pOffset->type == TMQ_OFFSET__SNAPSHOT_DATA) {
rowCnt += pDataBlock->info.rows;
- if (rowCnt >= 4096) break;
+ if (rowCnt >= 4096) {
+ break;
+ }
}
}
@@ -113,7 +120,10 @@ int32_t tqScanData(STQ* pTq, const STqHandle* pHandle, SMqDataRsp* pRsp, STqOffs
return -1;
}
- ASSERT(!(pRsp->withTbName || pRsp->withSchema));
+ if(pRsp->withTbName || pRsp->withSchema){
+ tqError("get column should not with meta:%d,%d", pRsp->withTbName, pRsp->withSchema);
+ return -1;
+ }
return 0;
}
diff --git a/source/dnode/vnode/src/tq/tqMeta.c b/source/dnode/vnode/src/tq/tqMeta.c
index a85e6e0a70..ce0aa144f9 100644
--- a/source/dnode/vnode/src/tq/tqMeta.c
+++ b/source/dnode/vnode/src/tq/tqMeta.c
@@ -283,7 +283,7 @@ int32_t tqMetaRestoreHandle(STQ* pTq) {
tdbTbcMoveToFirst(pCur);
while (tdbTbcNext(pCur, &pKey, &kLen, &pVal, &vLen) == 0) {
- STqHandle handle;
+ STqHandle handle = {0};
tDecoderInit(&decoder, (uint8_t*)pVal, vLen);
tDecodeSTqHandle(&decoder, &handle);
tDecoderClear(&decoder);
diff --git a/source/dnode/vnode/src/tq/tqPush.c b/source/dnode/vnode/src/tq/tqPush.c
index 5a25d7e894..01d8e7cf14 100644
--- a/source/dnode/vnode/src/tq/tqPush.c
+++ b/source/dnode/vnode/src/tq/tqPush.c
@@ -209,6 +209,7 @@ int32_t tqPushMsgNew(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_
int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver) {
void* pReq = POINTER_SHIFT(msg, sizeof(SSubmitReq2Msg));
int32_t len = msgLen - sizeof(SSubmitReq2Msg);
+ int32_t vgId = TD_VID(pTq->pVnode);
if (msgType == TDMT_VND_SUBMIT) {
// lock push mgr to avoid potential msg lost
@@ -217,7 +218,7 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver)
int32_t numOfRegisteredPush = taosHashGetSize(pTq->pPushMgr);
if (numOfRegisteredPush > 0) {
tqDebug("vgId:%d tq push msg version:%" PRId64 " type:%s, head:%p, body:%p len:%d, numOfPushed consumers:%d",
- pTq->pVnode->config.vgId, ver, TMSG_INFO(msgType), msg, pReq, len, numOfRegisteredPush);
+ vgId, ver, TMSG_INFO(msgType), msg, pReq, len, numOfRegisteredPush);
SArray* cachedKeys = taosArrayInit(0, sizeof(void*));
SArray* cachedKeyLens = taosArrayInit(0, sizeof(size_t));
@@ -239,7 +240,10 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver)
void* pIter = NULL;
while (1) {
pIter = taosHashIterate(pTq->pPushMgr, pIter);
- if (pIter == NULL) break;
+ if (pIter == NULL) {
+ break;
+ }
+
STqPushEntry* pPushEntry = *(STqPushEntry**)pIter;
STqHandle* pHandle = taosHashGet(pTq->pHandle, pPushEntry->subKey, strlen(pPushEntry->subKey));
@@ -248,31 +252,32 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver)
continue;
}
- if (pPushEntry->dataRsp.reqOffset.version >= ver) {
- tqDebug("vgId:%d, push entry req version %" PRId64 ", while push version %" PRId64 ", skip",
- pTq->pVnode->config.vgId, pPushEntry->dataRsp.reqOffset.version, ver);
+ SMqDataRsp* pRsp = pPushEntry->pDataRsp;
+ if (pRsp->reqOffset.version >= ver) {
+ tqDebug("vgId:%d, push entry req version %" PRId64 ", while push version %" PRId64 ", skip", vgId,
+ pRsp->reqOffset.version, ver);
continue;
}
STqExecHandle* pExec = &pHandle->execHandle;
qTaskInfo_t task = pExec->task;
- SMqDataRsp* pRsp = &pPushEntry->dataRsp;
-
// prepare scan mem data
SPackedData submit = {
.msgStr = data,
.msgLen = len,
.ver = ver,
};
- qStreamSetScanMemData(task, submit);
+ if(qStreamSetScanMemData(task, submit) != 0){
+ continue;
+ }
// here start to scan submit block to extract the subscribed data
while (1) {
SSDataBlock* pDataBlock = NULL;
uint64_t ts = 0;
if (qExecTask(task, &pDataBlock, &ts) < 0) {
- tqDebug("vgId:%d, tq exec error since %s", pTq->pVnode->config.vgId, terrstr());
+ tqDebug("vgId:%d, tq exec error since %s", vgId, terrstr());
}
if (pDataBlock == NULL) {
@@ -283,11 +288,11 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver)
pRsp->blockNum++;
}
- tqDebug("vgId:%d, tq handle push, subkey:%s, block num:%d", pTq->pVnode->config.vgId, pPushEntry->subKey,
- pRsp->blockNum);
+ tqDebug("vgId:%d, tq handle push, subkey:%s, block num:%d", vgId, pPushEntry->subKey, pRsp->blockNum);
if (pRsp->blockNum > 0) {
// set offset
tqOffsetResetToLog(&pRsp->rspOffset, ver);
+
// remove from hash
size_t kLen;
void* key = taosHashGetKey(pIter, &kLen);
@@ -309,6 +314,7 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver)
tqError("vgId:%d, tq push hash remove key error, key: %s", pTq->pVnode->config.vgId, (char*)key);
}
}
+
taosArrayDestroyP(cachedKeys, (FDelete)taosMemoryFree);
taosArrayDestroy(cachedKeyLens);
taosMemoryFree(data);
@@ -334,9 +340,9 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver)
};
tqDebug("tq copy write msg %p %d %" PRId64 " from %p", data, len, ver, pReq);
-
tqProcessSubmitReq(pTq, submit);
}
+
if (msgType == TDMT_VND_DELETE) {
tqProcessDelReq(pTq, POINTER_SHIFT(msg, sizeof(SMsgHead)), msgLen - sizeof(SMsgHead), ver);
}
@@ -344,3 +350,61 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver)
return 0;
}
+
+int32_t tqRegisterPushEntry(STQ* pTq, void* pHandle, const SMqPollReq* pRequest, SRpcMsg* pRpcMsg,
+ SMqDataRsp* pDataRsp, int32_t type) {
+ uint64_t consumerId = pRequest->consumerId;
+ int32_t vgId = TD_VID(pTq->pVnode);
+ STqHandle* pTqHandle = pHandle;
+
+ STqPushEntry* pPushEntry = taosMemoryCalloc(1, sizeof(STqPushEntry));
+ if (pPushEntry == NULL) {
+ tqDebug("tmq poll: consumer:0x%" PRIx64 ", vgId:%d failed to malloc, size:%d", consumerId, vgId,
+ (int32_t)sizeof(STqPushEntry));
+ terrno = TSDB_CODE_OUT_OF_MEMORY;
+ return -1;
+ }
+
+ pPushEntry->info = pRpcMsg->info;
+ memcpy(pPushEntry->subKey, pTqHandle->subKey, TSDB_SUBSCRIBE_KEY_LEN);
+
+ if (type == TMQ_MSG_TYPE__TAOSX_RSP) {
+ pPushEntry->pDataRsp = taosMemoryCalloc(1, sizeof(STaosxRsp));
+ memcpy(pPushEntry->pDataRsp, pDataRsp, sizeof(STaosxRsp));
+ } else if (type == TMQ_MSG_TYPE__POLL_RSP) {
+ pPushEntry->pDataRsp = taosMemoryCalloc(1, sizeof(SMqDataRsp));
+ memcpy(pPushEntry->pDataRsp, pDataRsp, sizeof(SMqDataRsp));
+ }
+
+ SMqRspHead* pHead = &pPushEntry->pDataRsp->head;
+ pHead->consumerId = consumerId;
+ pHead->epoch = pRequest->epoch;
+ pHead->mqMsgType = type;
+
+ taosHashPut(pTq->pPushMgr, pTqHandle->subKey, strlen(pTqHandle->subKey), &pPushEntry, sizeof(void*));
+
+ tqDebug("tmq poll: consumer:0x%" PRIx64 ", subkey %s offset:%" PRId64 ", vgId:%d save handle to push mgr, total:%d", consumerId,
+ pTqHandle->subKey, pDataRsp->reqOffset.version, vgId, taosHashGetSize(pTq->pPushMgr));
+ return 0;
+}
+
+int32_t tqRemovePushEntry(STQ* pTq, const char* pKey, int32_t keyLen, uint64_t consumerId, bool rspConsumer) {
+ int32_t vgId = TD_VID(pTq->pVnode);
+ STqPushEntry** pEntry = taosHashGet(pTq->pPushMgr, pKey, keyLen);
+
+ if (pEntry != NULL) {
+ uint64_t cId = (*pEntry)->pDataRsp->head.consumerId;
+ ASSERT(consumerId == cId);
+
+ tqDebug("tmq poll: consumer:0x%" PRIx64 ", subkey %s vgId:%d remove from push mgr, remains:%d", consumerId,
+ (*pEntry)->subKey, vgId, taosHashGetSize(pTq->pPushMgr) - 1);
+
+ if (rspConsumer) { // rsp the old consumer with empty block.
+ tqPushDataRsp(pTq, *pEntry);
+ }
+
+ taosHashRemove(pTq->pPushMgr, pKey, keyLen);
+ }
+
+ return 0;
+}
diff --git a/source/dnode/vnode/src/tq/tqRead.c b/source/dnode/vnode/src/tq/tqRead.c
index bf73cca925..1c8088be7e 100644
--- a/source/dnode/vnode/src/tq/tqRead.c
+++ b/source/dnode/vnode/src/tq/tqRead.c
@@ -183,14 +183,15 @@ end:
return tbSuid == realTbSuid;
}
-int64_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, SWalCkHead** ppCkHead) {
+int32_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, SWalCkHead** ppCkHead) {
int32_t code = 0;
+
taosThreadMutexLock(&pHandle->pWalReader->mutex);
int64_t offset = *fetchOffset;
while (1) {
if (walFetchHead(pHandle->pWalReader, offset, *ppCkHead) < 0) {
- tqDebug("tmq poll: consumer:%" PRId64 ", (epoch %d) vgId:%d offset %" PRId64 ", no more log to return",
+ tqDebug("tmq poll: consumer:0x%" PRIx64 ", (epoch %d) vgId:%d offset %" PRId64 ", no more log to return",
pHandle->consumerId, pHandle->epoch, TD_VID(pTq->pVnode), offset);
*fetchOffset = offset - 1;
code = -1;
@@ -241,6 +242,7 @@ int64_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, SWalCkHea
offset++;
}
}
+
END:
taosThreadMutexUnlock(&pHandle->pWalReader->mutex);
return code;
@@ -294,7 +296,7 @@ int32_t tqSeekVer(STqReader* pReader, int64_t ver, const char* id) {
// todo set the correct vgId
tqDebug("tmq poll: wal seek to version:%"PRId64" %s", ver, id);
if (walReadSeekVer(pReader->pWalReader, ver) < 0) {
- tqError("tmq poll: wal reader failed to seek to ver:%"PRId64" code:%s, %s", ver, tstrerror(terrno), id);
+ tqDebug("tmq poll: wal reader failed to seek to ver:%"PRId64" code:%s, %s", ver, tstrerror(terrno), id);
return -1;
} else {
tqDebug("tmq poll: wal reader seek to ver:%"PRId64" %s", ver, id);
@@ -707,7 +709,10 @@ int32_t tqRetrieveDataBlock2(SSDataBlock* pBlock, STqReader* pReader, SSubmitTbD
sourceIdx++;
targetIdx++;
} else {
- ASSERT(0);
+ for (int32_t i = 0; i < pCol->nVal; i++) {
+ colDataSetNULL(pColData, i);
+ }
+ targetIdx++;
}
}
} else {
@@ -749,7 +754,8 @@ int32_t tqRetrieveDataBlock2(SSDataBlock* pBlock, STqReader* pReader, SSubmitTbD
sourceIdx++;
break;
} else {
- ASSERT(0);
+ colDataSetNULL(pColData, i);
+ break;
}
}
}
diff --git a/source/dnode/vnode/src/tq/tqSink.c b/source/dnode/vnode/src/tq/tqSink.c
index 56684b691b..dafd4d7485 100644
--- a/source/dnode/vnode/src/tq/tqSink.c
+++ b/source/dnode/vnode/src/tq/tqSink.c
@@ -619,6 +619,7 @@ void tqSinkToTablePipeline2(SStreamTask* pTask, void* vnode, int64_t ver, void*
TD_VID(pVnode), ctbName, suid, mr.me.ctbEntry.suid);
metaReaderClear(&mr);
taosMemoryFree(ctbName);
+ continue;
}
tbData.uid = mr.me.uid;
diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c
index 58401cdf44..9f438a9f97 100644
--- a/source/dnode/vnode/src/tsdb/tsdbCache.c
+++ b/source/dnode/vnode/src/tsdb/tsdbCache.c
@@ -596,7 +596,8 @@ typedef struct {
int64_t lastTs;
} SFSLastNextRowIter;
-static int32_t getNextRowFromFSLast(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlierTs) {
+static int32_t getNextRowFromFSLast(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlierTs, bool isLast, int16_t *aCols,
+ int nCols) {
SFSLastNextRowIter *state = (SFSLastNextRowIter *)iter;
int32_t code = 0;
@@ -632,11 +633,16 @@ static int32_t getNextRowFromFSLast(void *iter, TSDBROW **ppRow, bool *pIgnoreEa
}
tMergeTreeOpen(&state->mergeTree, 1, *state->pDataFReader, state->suid, state->uid,
- &(STimeWindow){.skey = TSKEY_MIN, .ekey = TSKEY_MAX},
- &(SVersionRange){.minVer = 0, .maxVer = UINT64_MAX}, state->pLoadInfo, false, NULL);
+ &(STimeWindow){.skey = state->lastTs, .ekey = TSKEY_MAX},
+ &(SVersionRange){.minVer = 0, .maxVer = UINT64_MAX}, state->pLoadInfo, false, NULL, true);
state->pMergeTree = &state->mergeTree;
bool hasVal = tMergeTreeNext(&state->mergeTree);
if (!hasVal) {
+ if (tMergeTreeIgnoreEarlierTs(&state->mergeTree)) {
+ *pIgnoreEarlierTs = true;
+ *ppRow = NULL;
+ return code;
+ }
state->state = SFSLASTNEXTROW_FILESET;
goto _next_fileset;
}
@@ -644,16 +650,13 @@ static int32_t getNextRowFromFSLast(void *iter, TSDBROW **ppRow, bool *pIgnoreEa
}
case SFSLASTNEXTROW_BLOCKROW: {
bool hasVal = false;
- do {
- state->row = tMergeTreeGetRow(&state->mergeTree);
- *ppRow = &state->row;
- hasVal = tMergeTreeNext(&state->mergeTree);
- } while (TSDBROW_TS(&state->row) <= state->lastTs && hasVal);
-
+ state->row = tMergeTreeGetRow(&state->mergeTree);
+ *ppRow = &state->row;
+ hasVal = tMergeTreeNext(&state->mergeTree);
if (TSDBROW_TS(&state->row) <= state->lastTs) {
*pIgnoreEarlierTs = true;
- state->state = SFSLASTNEXTROW_FILESET;
- goto _next_fileset;
+ *ppRow = NULL;
+ return code;
}
*pIgnoreEarlierTs = false;
@@ -738,7 +741,8 @@ typedef struct SFSNextRowIter {
int64_t lastTs;
} SFSNextRowIter;
-static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlierTs) {
+static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlierTs, bool isLast, int16_t *aCols,
+ int nCols) {
SFSNextRowIter *state = (SFSNextRowIter *)iter;
int32_t code = 0;
@@ -826,8 +830,11 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlie
}
}
case SFSNEXTROW_BLOCKDATA:
+ _next_datablock:
if (state->iBlock >= 0) {
SDataBlk block = {0};
+ bool skipBlock = true;
+ int inputColIndex = 0;
tDataBlkReset(&block);
tBlockDataReset(state->pBlockData);
@@ -835,7 +842,13 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlie
tMapDataGetItemByIdx(&state->blockMap, state->iBlock, &block, tGetDataBlk);
if (block.maxKey.ts <= state->lastTs) {
*pIgnoreEarlierTs = true;
- goto _next_fileset;
+ if (state->pBlockData) {
+ tBlockDataDestroy(state->pBlockData);
+ state->pBlockData = NULL;
+ }
+
+ *ppRow = NULL;
+ return code;
}
*pIgnoreEarlierTs = false;
tBlockDataReset(state->pBlockData);
@@ -846,6 +859,42 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlie
code = tsdbReadDataBlock(*state->pDataFReader, &block, state->pBlockData);
if (code) goto _err;
+ for (int colIndex = 0; colIndex < state->pBlockData->nColData; ++colIndex) {
+ SColData *pColData = &state->pBlockData->aColData[colIndex];
+ int16_t cid = pColData->cid;
+
+ if (inputColIndex < nCols && cid == aCols[inputColIndex++]) {
+ if (isLast && pColData->numOfValue != 0) {
+ skipBlock = false;
+ break;
+ } else if (pColData->numOfNone != pColData->nVal) {
+ skipBlock = false;
+ break;
+ }
+ }
+ }
+
+ if (skipBlock) {
+ if (--state->iBlock < 0) {
+ tsdbDataFReaderClose(state->pDataFReader);
+ *state->pDataFReader = NULL;
+ // resetLastBlockLoadInfo(state->pLoadInfo);
+
+ if (state->aBlockIdx) {
+ // taosArrayDestroy(state->aBlockIdx);
+ tsdbBICacheRelease(state->pTsdb->biCache, state->aBlockIdxHandle);
+
+ state->aBlockIdxHandle = NULL;
+ state->aBlockIdx = NULL;
+ }
+
+ state->state = SFSNEXTROW_FILESET;
+ goto _next_fileset;
+ } else {
+ goto _next_datablock;
+ }
+ }
+
state->nRow = state->blockData.nRow;
state->iRow = state->nRow - 1;
@@ -952,7 +1001,8 @@ typedef struct SMemNextRowIter {
// TSDBROW *curRow;
} SMemNextRowIter;
-static int32_t getNextRowFromMem(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlierTs) {
+static int32_t getNextRowFromMem(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlierTs, bool isLast, int16_t *aCols,
+ int nCols) {
SMemNextRowIter *state = (SMemNextRowIter *)iter;
int32_t code = 0;
*pIgnoreEarlierTs = false;
@@ -1064,7 +1114,8 @@ static bool tsdbKeyDeleted(TSDBKEY *key, SArray *pSkyline, int64_t *iSkyline) {
return deleted;
}
-typedef int32_t (*_next_row_fn_t)(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlierTs);
+typedef int32_t (*_next_row_fn_t)(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlierTs, bool isLast, int16_t *aCols,
+ int nCols);
typedef int32_t (*_next_row_clear_fn_t)(void *iter);
typedef struct {
@@ -1214,12 +1265,14 @@ _err:
}
// iterate next row non deleted backward ts, version (from high to low)
-static int32_t nextRowIterGet(CacheNextRowIter *pIter, TSDBROW **ppRow, bool *pIgnoreEarlierTs) {
+static int32_t nextRowIterGet(CacheNextRowIter *pIter, TSDBROW **ppRow, bool *pIgnoreEarlierTs, bool isLast,
+ int16_t *aCols, int nCols) {
int code = 0;
for (;;) {
for (int i = 0; i < 4; ++i) {
if (pIter->input[i].next && !pIter->input[i].stop) {
- code = pIter->input[i].nextRowFn(pIter->input[i].iter, &pIter->input[i].pRow, &pIter->input[i].ignoreEarlierTs);
+ code = pIter->input[i].nextRowFn(pIter->input[i].iter, &pIter->input[i].pRow, &pIter->input[i].ignoreEarlierTs,
+ isLast, aCols, nCols);
if (code) goto _err;
if (pIter->input[i].pRow == NULL) {
@@ -1350,7 +1403,7 @@ static int32_t mergeLastRow(tb_uid_t uid, STsdb *pTsdb, bool *dup, SArray **ppCo
do {
TSDBROW *pRow = NULL;
- nextRowIterGet(&iter, &pRow, &ignoreEarlierTs);
+ nextRowIterGet(&iter, &pRow, &ignoreEarlierTs, false, NULL, 0);
if (!pRow) {
break;
@@ -1480,11 +1533,18 @@ static int32_t mergeLast(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SCach
bool ignoreEarlierTs = false;
SArray *pColArray = NULL;
SColVal *pColVal = &(SColVal){0};
+ int16_t nCols = nLastCol;
int32_t code = initLastColArray(pTSchema, &pColArray);
if (TSDB_CODE_SUCCESS != code) {
return code;
}
+ SArray *aColArray = taosArrayInit(nCols, sizeof(int16_t));
+ if (NULL == aColArray) {
+ taosArrayDestroy(pColArray);
+
+ return TSDB_CODE_OUT_OF_MEMORY;
+ }
TSKEY lastRowTs = TSKEY_MAX;
@@ -1494,7 +1554,7 @@ static int32_t mergeLast(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SCach
do {
TSDBROW *pRow = NULL;
- nextRowIterGet(&iter, &pRow, &ignoreEarlierTs);
+ nextRowIterGet(&iter, &pRow, &ignoreEarlierTs, true, TARRAY_DATA(aColArray), TARRAY_SIZE(aColArray));
if (!pRow) {
break;
@@ -1539,9 +1599,12 @@ static int32_t mergeLast(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SCach
memcpy(pCol->colVal.value.pData, pColVal->value.pData, pColVal->value.nData);
}
- if (!COL_VAL_IS_VALUE(pColVal) && !setNoneCol) {
- noneCol = iCol;
- setNoneCol = true;
+ if (!COL_VAL_IS_VALUE(pColVal)) {
+ taosArrayPush(aColArray, &pColVal->cid);
+ if (!setNoneCol) {
+ noneCol = iCol;
+ setNoneCol = true;
+ }
}
}
if (!setNoneCol) {
@@ -1582,6 +1645,8 @@ static int32_t mergeLast(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SCach
}
taosArraySet(pColArray, iCol, &lastCol);
+ int32_t aColIndex = taosArraySearchIdx(aColArray, &lastCol.colVal.cid, compareInt16Val, TD_EQ);
+ taosArrayRemove(aColArray, aColIndex);
} else if (!COL_VAL_IS_VALUE(tColVal) && !COL_VAL_IS_VALUE(pColVal) && !setNoneCol) {
noneCol = iCol;
setNoneCol = true;
@@ -1605,6 +1670,7 @@ static int32_t mergeLast(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SCach
//}
nextRowIterClose(&iter);
+ taosArrayDestroy(aColArray);
// taosMemoryFreeClear(pTSchema);
return code;
@@ -1613,6 +1679,7 @@ _err:
// taosMemoryFreeClear(pTSchema);
*ppLastArray = NULL;
taosArrayDestroy(pColArray);
+ taosArrayDestroy(aColArray);
return code;
}
@@ -1724,6 +1791,15 @@ size_t tsdbCacheGetUsage(SVnode *pVnode) {
return usage;
}
+int32_t tsdbCacheGetElems(SVnode *pVnode) {
+ int32_t elems = 0;
+ if (pVnode->pTsdb != NULL) {
+ elems = taosLRUCacheGetElems(pVnode->pTsdb->lruCache);
+ }
+
+ return elems;
+}
+
static void getBICacheKey(int32_t fid, int64_t commitID, char *key, int *len) {
struct {
int32_t fid;
diff --git a/source/dnode/vnode/src/tsdb/tsdbCacheRead.c b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c
index d925950703..e4c23c295a 100644
--- a/source/dnode/vnode/src/tsdb/tsdbCacheRead.c
+++ b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c
@@ -332,6 +332,7 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32
// retrieve the only one last row of all tables in the uid list.
if (HASTYPE(pr->type, CACHESCAN_RETRIEVE_TYPE_SINGLE)) {
+ int64_t st = taosGetTimestampUs();
for (int32_t i = 0; i < pr->numOfTables; ++i) {
STableKeyInfo* pKeyInfo = &pr->pTableList[i];
@@ -407,7 +408,10 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32
}
if (hasNotNullRow) {
- pr->lastTs = minTs;
+ double cost = (taosGetTimestampUs() - st) / 1000.0;
+ if (cost > tsCacheLazyLoadThreshold) {
+ pr->lastTs = minTs;
+ }
}
}
@@ -417,7 +421,6 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32
if (hasRes) {
saveOneRow(pLastCols, pResBlock, pr, slotIds, pRes, pr->idstr);
}
-
} else if (HASTYPE(pr->type, CACHESCAN_RETRIEVE_TYPE_ALL)) {
for (int32_t i = pr->tableIndex; i < pr->numOfTables; ++i) {
STableKeyInfo* pKeyInfo = &pr->pTableList[i];
diff --git a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c
index d9d60442ff..943b16116c 100644
--- a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c
+++ b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c
@@ -29,9 +29,11 @@ struct SLDataIter {
STimeWindow timeWindow;
SVersionRange verRange;
SSttBlockLoadInfo *pBlockLoadInfo;
+ bool ignoreEarlierTs;
};
-SSttBlockLoadInfo *tCreateLastBlockLoadInfo(STSchema *pSchema, int16_t *colList, int32_t numOfCols, int32_t numOfSttTrigger) {
+SSttBlockLoadInfo *tCreateLastBlockLoadInfo(STSchema *pSchema, int16_t *colList, int32_t numOfCols,
+ int32_t numOfSttTrigger) {
SSttBlockLoadInfo *pLoadInfo = taosMemoryCalloc(numOfSttTrigger, sizeof(SSttBlockLoadInfo));
if (pLoadInfo == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
@@ -162,7 +164,8 @@ static SBlockData *loadLastBlock(SLDataIter *pIter, const char *idStr) {
pInfo->blockIndex[pInfo->currentLoadBlockIndex] = pIter->iSttBlk;
pIter->iRow = (pIter->backward) ? pInfo->blockData[pInfo->currentLoadBlockIndex].nRow : -1;
- tsdbDebug("last block index list:%d, %d, rowIndex:%d %s", pInfo->blockIndex[0], pInfo->blockIndex[1], pIter->iRow, idStr);
+ tsdbDebug("last block index list:%d, %d, rowIndex:%d %s", pInfo->blockIndex[0], pInfo->blockIndex[1], pIter->iRow,
+ idStr);
return &pInfo->blockData[pInfo->currentLoadBlockIndex];
_exit:
@@ -263,7 +266,7 @@ static int32_t binarySearchForStartRowIndex(uint64_t *uidList, int32_t num, uint
int32_t tLDataIterOpen(struct SLDataIter **pIter, SDataFReader *pReader, int32_t iStt, int8_t backward, uint64_t suid,
uint64_t uid, STimeWindow *pTimeWindow, SVersionRange *pRange, SSttBlockLoadInfo *pBlockLoadInfo,
- const char *idStr) {
+ const char *idStr, bool strictTimeRange) {
int32_t code = TSDB_CODE_SUCCESS;
*pIter = taosMemoryCalloc(1, sizeof(SLDataIter));
@@ -340,6 +343,17 @@ int32_t tLDataIterOpen(struct SLDataIter **pIter, SDataFReader *pReader, int32_t
if ((*pIter)->iSttBlk != -1) {
(*pIter)->pSttBlk = taosArrayGet(pBlockLoadInfo->aSttBlk, (*pIter)->iSttBlk);
(*pIter)->iRow = ((*pIter)->backward) ? (*pIter)->pSttBlk->nRow : -1;
+
+ if ((!backward) && ((strictTimeRange && (*pIter)->pSttBlk->minKey >= (*pIter)->timeWindow.ekey) ||
+ (!strictTimeRange && (*pIter)->pSttBlk->minKey > (*pIter)->timeWindow.ekey))) {
+ (*pIter)->pSttBlk = NULL;
+ }
+
+ if (backward && ((strictTimeRange && (*pIter)->pSttBlk->maxKey <= (*pIter)->timeWindow.skey) ||
+ (!strictTimeRange && (*pIter)->pSttBlk->maxKey < (*pIter)->timeWindow.skey))) {
+ (*pIter)->pSttBlk = NULL;
+ (*pIter)->ignoreEarlierTs = true;
+ }
}
return code;
@@ -421,7 +435,7 @@ static void findNextValidRow(SLDataIter *pIter, const char *idStr) {
pBlockData->aUid != NULL) {
i = binarySearchForStartRowIndex((uint64_t *)pBlockData->aUid, pBlockData->nRow, pIter->uid, pIter->backward);
if (i == -1) {
- tsdbDebug("failed to find the data in pBlockData, uid:%"PRIu64" , %s", pIter->uid, idStr);
+ tsdbDebug("failed to find the data in pBlockData, uid:%" PRIu64 " , %s", pIter->uid, idStr);
pIter->iRow = -1;
return;
}
@@ -508,7 +522,7 @@ bool tLDataIterNextRow(SLDataIter *pIter, const char *idStr) {
}
// set start row index
- pIter->iRow = pIter->backward? pBlockData->nRow-1:0;
+ pIter->iRow = pIter->backward ? pBlockData->nRow - 1 : 0;
}
}
@@ -551,7 +565,7 @@ static FORCE_INLINE int32_t tLDataIterDescCmprFn(const SRBTreeNode *p1, const SR
int32_t tMergeTreeOpen(SMergeTree *pMTree, int8_t backward, SDataFReader *pFReader, uint64_t suid, uint64_t uid,
STimeWindow *pTimeWindow, SVersionRange *pVerRange, SSttBlockLoadInfo *pBlockLoadInfo,
- bool destroyLoadInfo, const char *idStr) {
+ bool destroyLoadInfo, const char *idStr, bool strictTimeRange) {
pMTree->backward = backward;
pMTree->pIter = NULL;
pMTree->pIterList = taosArrayInit(4, POINTER_BYTES);
@@ -569,11 +583,12 @@ int32_t tMergeTreeOpen(SMergeTree *pMTree, int8_t backward, SDataFReader *pFRead
pMTree->pLoadInfo = pBlockLoadInfo;
pMTree->destroyLoadInfo = destroyLoadInfo;
+ pMTree->ignoreEarlierTs = false;
for (int32_t i = 0; i < pFReader->pSet->nSttF; ++i) { // open all last file
struct SLDataIter *pIter = NULL;
code = tLDataIterOpen(&pIter, pFReader, i, pMTree->backward, suid, uid, pTimeWindow, pVerRange,
- &pMTree->pLoadInfo[i], pMTree->idStr);
+ &pMTree->pLoadInfo[i], pMTree->idStr, strictTimeRange);
if (code != TSDB_CODE_SUCCESS) {
goto _end;
}
@@ -583,6 +598,9 @@ int32_t tMergeTreeOpen(SMergeTree *pMTree, int8_t backward, SDataFReader *pFRead
taosArrayPush(pMTree->pIterList, &pIter);
tMergeTreeAddIter(pMTree, pIter);
} else {
+ if (!pMTree->ignoreEarlierTs) {
+ pMTree->ignoreEarlierTs = pIter->ignoreEarlierTs;
+ }
tLDataIterClose(pIter);
}
}
@@ -596,6 +614,8 @@ _end:
void tMergeTreeAddIter(SMergeTree *pMTree, SLDataIter *pIter) { tRBTreePut(&pMTree->rbt, (SRBTreeNode *)pIter); }
+bool tMergeTreeIgnoreEarlierTs(SMergeTree *pMTree) { return pMTree->ignoreEarlierTs; }
+
bool tMergeTreeNext(SMergeTree *pMTree) {
int32_t code = TSDB_CODE_SUCCESS;
if (pMTree->pIter) {
diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c
index fd19e552c1..2766745cbe 100644
--- a/source/dnode/vnode/src/tsdb/tsdbRead.c
+++ b/source/dnode/vnode/src/tsdb/tsdbRead.c
@@ -315,11 +315,11 @@ static int32_t ensureBlockScanInfoBuf(SBlockInfoBuf* pBuf, int32_t numOfTables)
}
if (pBuf->numOfTables > 0) {
- STableBlockScanInfo **p = (STableBlockScanInfo**)taosArrayPop(pBuf->pData);
+ STableBlockScanInfo** p = (STableBlockScanInfo**)taosArrayPop(pBuf->pData);
taosMemoryFree(*p);
pBuf->numOfTables /= pBuf->numPerBucket;
}
-
+
int32_t num = (numOfTables - pBuf->numOfTables) / pBuf->numPerBucket;
int32_t remainder = (numOfTables - pBuf->numOfTables) % pBuf->numPerBucket;
if (pBuf->pData == NULL) {
@@ -919,7 +919,7 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockN
pBlockNum->numOfBlocks += 1;
}
- if ((pScanInfo->pBlockList != NULL )&& (taosArrayGetSize(pScanInfo->pBlockList) > 0)) {
+ if ((pScanInfo->pBlockList != NULL) && (taosArrayGetSize(pScanInfo->pBlockList) > 0)) {
numOfQTable += 1;
}
}
@@ -1798,7 +1798,7 @@ static bool nextRowFromLastBlocks(SLastBlockReader* pLastBlockReader, STableBloc
while (1) {
bool hasVal = tMergeTreeNext(&pLastBlockReader->mergeTree);
- if (!hasVal) { // the next value will be the accessed key in stt
+ if (!hasVal) { // the next value will be the accessed key in stt
pScanInfo->lastKeyInStt += step;
return false;
}
@@ -2481,7 +2481,7 @@ static bool initLastBlockReader(SLastBlockReader* pLBlockReader, STableBlockScan
pScanInfo->uid, pReader->idStr);
int32_t code = tMergeTreeOpen(&pLBlockReader->mergeTree, (pLBlockReader->order == TSDB_ORDER_DESC),
pReader->pFileReader, pReader->suid, pScanInfo->uid, &w, &pLBlockReader->verRange,
- pLBlockReader->pInfo, false, pReader->idStr);
+ pLBlockReader->pInfo, false, pReader->idStr, false);
if (code != TSDB_CODE_SUCCESS) {
return false;
}
@@ -3512,7 +3512,7 @@ static int32_t checkForNeighborFileBlock(STsdbReader* pReader, STableBlockScanIn
CHECK_FILEBLOCK_STATE* state) {
SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo;
SBlockData* pBlockData = &pReader->status.fileBlockData;
- bool asc = ASCENDING_TRAVERSE(pReader->order);
+ bool asc = ASCENDING_TRAVERSE(pReader->order);
*state = CHECK_FILEBLOCK_QUIT;
int32_t step = ASCENDING_TRAVERSE(pReader->order) ? 1 : -1;
@@ -3927,7 +3927,8 @@ int32_t tsdbSetTableList(STsdbReader* pReader, const void* pTableList, int32_t n
if (code) {
return code;
}
- pReader->status.uidList.tableUidList = (uint64_t*)taosMemoryRealloc(pReader->status.uidList.tableUidList, sizeof(uint64_t) * num);
+ pReader->status.uidList.tableUidList =
+ (uint64_t*)taosMemoryRealloc(pReader->status.uidList.tableUidList, sizeof(uint64_t) * num);
}
taosHashClear(pReader->status.pTableMap);
diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c
index c017266839..303d2a9ca4 100644
--- a/source/dnode/vnode/src/vnd/vnodeQuery.c
+++ b/source/dnode/vnode/src/vnd/vnodeQuery.c
@@ -382,6 +382,7 @@ int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) {
pLoad->syncRestore = state.restored;
pLoad->syncCanRead = state.canRead;
pLoad->cacheUsage = tsdbCacheGetUsage(pVnode);
+ pLoad->numOfCachedTables = tsdbCacheGetElems(pVnode);
pLoad->numOfTables = metaGetTbNum(pVnode->pMeta);
pLoad->numOfTimeSeries = metaGetTimeSeriesNum(pVnode->pMeta);
pLoad->totalStorage = (int64_t)3 * 1073741824;
diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c
index 45113d55d3..d3ba7ad608 100644
--- a/source/dnode/vnode/src/vnd/vnodeSvr.c
+++ b/source/dnode/vnode/src/vnd/vnodeSvr.c
@@ -306,13 +306,7 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp
void *pReq;
int32_t len;
int32_t ret;
- /*
- if (!pVnode->inUse) {
- terrno = TSDB_CODE_VND_NO_AVAIL_BUFPOOL;
- vError("vgId:%d, not ready to write since %s", TD_VID(pVnode), terrstr());
- return -1;
- }
- */
+
if (version <= pVnode->state.applied) {
vError("vgId:%d, duplicate write request. version: %" PRId64 ", applied: %" PRId64 "", TD_VID(pVnode), version,
pVnode->state.applied);
@@ -326,8 +320,8 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp
ASSERT(pVnode->state.applyTerm <= pMsg->info.conn.applyTerm);
ASSERT(pVnode->state.applied + 1 == version);
- pVnode->state.applied = version;
- pVnode->state.applyTerm = pMsg->info.conn.applyTerm;
+ atomic_store_64(&pVnode->state.applied, version);
+ atomic_store_64(&pVnode->state.applyTerm, pMsg->info.conn.applyTerm);
if (!syncUtilUserCommit(pMsg->msgType)) goto _exit;
diff --git a/source/dnode/vnode/src/vnd/vnodeSync.c b/source/dnode/vnode/src/vnd/vnodeSync.c
index e71b03d2af..b49ca70bfa 100644
--- a/source/dnode/vnode/src/vnd/vnodeSync.c
+++ b/source/dnode/vnode/src/vnd/vnodeSync.c
@@ -433,7 +433,23 @@ static int32_t vnodeSyncApplyMsg(const SSyncFSM *pFsm, SRpcMsg *pMsg, const SFsm
}
static int32_t vnodeSyncCommitMsg(const SSyncFSM *pFsm, SRpcMsg *pMsg, const SFsmCbMeta *pMeta) {
- return vnodeSyncApplyMsg(pFsm, pMsg, pMeta);
+ if (pMsg->code == 0) {
+ return vnodeSyncApplyMsg(pFsm, pMsg, pMeta);
+ }
+
+ const STraceId *trace = &pMsg->info.traceId;
+ SVnode *pVnode = pFsm->data;
+ vnodePostBlockMsg(pVnode, pMsg);
+
+ SRpcMsg rsp = {.code = pMsg->code, .info = pMsg->info};
+ if (rsp.info.handle != NULL) {
+ tmsgSendRsp(&rsp);
+ }
+
+ vGTrace("vgId:%d, msg:%p is freed, code:0x%x index:%" PRId64, TD_VID(pVnode), pMsg, rsp.code, pMeta->index);
+ rpcFreeCont(pMsg->pCont);
+ pMsg->pCont = NULL;
+ return 0;
}
static int32_t vnodeSyncPreCommitMsg(const SSyncFSM *pFsm, SRpcMsg *pMsg, const SFsmCbMeta *pMeta) {
@@ -443,6 +459,11 @@ static int32_t vnodeSyncPreCommitMsg(const SSyncFSM *pFsm, SRpcMsg *pMsg, const
return 0;
}
+static SyncIndex vnodeSyncAppliedIndex(const SSyncFSM *pFSM) {
+ SVnode *pVnode = pFSM->data;
+ return atomic_load_64(&pVnode->state.applied);
+}
+
static void vnodeSyncRollBackMsg(const SSyncFSM *pFsm, SRpcMsg *pMsg, const SFsmCbMeta *pMeta) {
SVnode *pVnode = pFsm->data;
vTrace("vgId:%d, rollback-cb is excuted, fsm:%p, index:%" PRId64 ", weak:%d, code:%d, state:%d %s, type:%s",
@@ -505,21 +526,26 @@ static int32_t vnodeSnapshotDoWrite(const SSyncFSM *pFsm, void *pWriter, void *p
return code;
}
-static void vnodeRestoreFinish(const SSyncFSM *pFsm) {
+static void vnodeRestoreFinish(const SSyncFSM *pFsm, const SyncIndex commitIdx) {
SVnode *pVnode = pFsm->data;
+ SyncIndex appliedIdx = -1;
do {
- int32_t itemSize = tmsgGetQueueSize(&pVnode->msgCb, pVnode->config.vgId, APPLY_QUEUE);
- if (itemSize == 0) {
- vInfo("vgId:%d, apply queue is empty, restore finish", pVnode->config.vgId);
+ appliedIdx = vnodeSyncAppliedIndex(pFsm);
+ ASSERT(appliedIdx <= commitIdx);
+ if (appliedIdx == commitIdx) {
+ vInfo("vgId:%d, no items to be applied, restore finish", pVnode->config.vgId);
break;
} else {
- vInfo("vgId:%d, restore not finish since %d items in apply queue", pVnode->config.vgId, itemSize);
+ vInfo("vgId:%d, restore not finish since %" PRId64 " items to be applied. commit-index:%" PRId64
+ ", applied-index:%" PRId64,
+ pVnode->config.vgId, commitIdx - appliedIdx, commitIdx, appliedIdx);
taosMsleep(10);
}
} while (true);
- walApplyVer(pVnode->pWal, pVnode->state.applied);
+ ASSERT(commitIdx == vnodeSyncAppliedIndex(pFsm));
+ walApplyVer(pVnode->pWal, commitIdx);
pVnode->restored = true;
vInfo("vgId:%d, sync restore finished", pVnode->config.vgId);
@@ -569,6 +595,7 @@ static SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode) {
SSyncFSM *pFsm = taosMemoryCalloc(1, sizeof(SSyncFSM));
pFsm->data = pVnode;
pFsm->FpCommitCb = vnodeSyncCommitMsg;
+ pFsm->FpAppliedIndexCb = vnodeSyncAppliedIndex;
pFsm->FpPreCommitCb = vnodeSyncPreCommitMsg;
pFsm->FpRollBackCb = vnodeSyncRollBackMsg;
pFsm->FpGetSnapshotInfo = vnodeSyncGetSnapshotInfo;
diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c
index c862a75ed3..58c43829cf 100644
--- a/source/libs/command/src/command.c
+++ b/source/libs/command/src/command.c
@@ -307,7 +307,7 @@ static void setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName, ch
bool existLeaderRole(TAOS_ROW row, TAOS_FIELD* fields, int nFields) {
// vgroup_id | db_name | tables | v1_dnode | v1_status | v2_dnode | v2_status | v3_dnode | v3_status | v4_dnode |
// v4_status | cacheload | tsma |
- if (nFields != 13) {
+ if (nFields != 14) {
return false;
}
diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c
index ac78ddc23c..a05399615e 100644
--- a/source/libs/executor/src/executor.c
+++ b/source/libs/executor/src/executor.c
@@ -221,12 +221,12 @@ int32_t qSetSMAInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numOfBlocks,
qTaskInfo_t qCreateQueueExecTaskInfo(void* msg, SReadHandle* readers, int32_t* numOfCols, SSchemaWrapper** pSchema) {
if (msg == NULL) {
// create raw scan
-
SExecTaskInfo* pTaskInfo = taosMemoryCalloc(1, sizeof(SExecTaskInfo));
if (NULL == pTaskInfo) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
}
+
setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED);
pTaskInfo->cost.created = taosGetTimestampUs();
@@ -715,7 +715,6 @@ void qStopTaskOperators(SExecTaskInfo* pTaskInfo) {
int32_t qAsyncKillTask(qTaskInfo_t qinfo, int32_t rspCode) {
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)qinfo;
-
if (pTaskInfo == NULL) {
return TSDB_CODE_QRY_INVALID_QHANDLE;
}
@@ -723,7 +722,6 @@ int32_t qAsyncKillTask(qTaskInfo_t qinfo, int32_t rspCode) {
qDebug("%s execTask async killed", GET_TASKID(pTaskInfo));
setTaskKilled(pTaskInfo, rspCode);
-
qStopTaskOperators(pTaskInfo);
return TSDB_CODE_SUCCESS;
@@ -992,19 +990,16 @@ const char* qExtractTbnameFromTask(qTaskInfo_t tinfo) {
SMqMetaRsp* qStreamExtractMetaMsg(qTaskInfo_t tinfo) {
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
- ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE);
return &pTaskInfo->streamInfo.metaRsp;
}
int64_t qStreamExtractPrepareUid(qTaskInfo_t tinfo) {
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
- ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE);
return pTaskInfo->streamInfo.prepareStatus.uid;
}
int32_t qStreamExtractOffset(qTaskInfo_t tinfo, STqOffsetVal* pOffset) {
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
- ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE);
memcpy(pOffset, &pTaskInfo->streamInfo.lastStatus, sizeof(STqOffsetVal));
return 0;
}
@@ -1040,20 +1035,12 @@ int32_t initQueryTableDataCondForTmq(SQueryTableDataCond* pCond, SSnapContext* s
return TSDB_CODE_SUCCESS;
}
-#if 0
-int32_t qStreamScanMemData(qTaskInfo_t tinfo, const SSubmitReq* pReq, int64_t scanVer) {
- SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
- ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE);
- ASSERT(pTaskInfo->streamInfo.pReq == NULL);
- pTaskInfo->streamInfo.pReq = pReq;
- pTaskInfo->streamInfo.scanVer = scanVer;
- return 0;
-}
-#endif
-
int32_t qStreamSetScanMemData(qTaskInfo_t tinfo, SPackedData submit) {
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
- ASSERT((pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE )&& (pTaskInfo->streamInfo.submit.msgStr == NULL));
+ if((pTaskInfo->execModel != OPTR_EXEC_MODEL_QUEUE) || (pTaskInfo->streamInfo.submit.msgStr != NULL)){
+ qError("qStreamSetScanMemData err:%d,%p", pTaskInfo->execModel, pTaskInfo->streamInfo.submit.msgStr);
+ return -1;
+ }
qDebug("set the submit block for future scan");
pTaskInfo->streamInfo.submit = submit;
@@ -1063,7 +1050,6 @@ int32_t qStreamSetScanMemData(qTaskInfo_t tinfo, SPackedData submit) {
int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subType) {
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
SOperatorInfo* pOperator = pTaskInfo->pRoot;
- ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE);
pTaskInfo->streamInfo.prepareStatus = *pOffset;
pTaskInfo->streamInfo.returned = 0;
@@ -1076,7 +1062,10 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
// TODO add more check
if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
- ASSERT(pOperator->numOfDownstream == 1);
+ if(pOperator->numOfDownstream != 1){
+ qError("pOperator->numOfDownstream != 1:%d", pOperator->numOfDownstream);
+ return -1;
+ }
pOperator = pOperator->pDownstream[0];
}
@@ -1087,6 +1076,7 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
pTSInfo->base.dataReader = NULL;
// let's seek to the next version in wal file
if (tqSeekVer(pInfo->tqReader, pOffset->version + 1, pTaskInfo->id.str) < 0) {
+ qError("tqSeekVer failed ver:%" PRId64, pOffset->version + 1);
return -1;
}
} else if (pOffset->type == TMQ_OFFSET__SNAPSHOT_DATA) {
@@ -1101,6 +1091,7 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
uid = pTableInfo->uid;
ts = INT64_MIN;
} else {
+ qError("uid == 0 and tablelist size is 0");
return -1;
}
}
@@ -1124,7 +1115,10 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
}
// TODO after dropping table, table may not found
- ASSERT(found);
+ if(!found){
+ qError("uid not found in tablelist %" PRId64, uid);
+ return -1;
+ }
if (pTableScanInfo->base.dataReader == NULL) {
STableKeyInfo* pList = tableListGetInfo(pTaskInfo->pTableInfoList, 0);
@@ -1133,7 +1127,8 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
if (tsdbReaderOpen(pTableScanInfo->base.readHandle.vnode, &pTableScanInfo->base.cond, pList, num,
pTableScanInfo->pResBlock, &pTableScanInfo->base.dataReader, NULL) < 0 ||
pTableScanInfo->base.dataReader == NULL) {
- ASSERT(0);
+ qError("tsdbReaderOpen failed. uid:%" PRIi64, pOffset->uid);
+ return -1;
}
}
@@ -1148,7 +1143,8 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
qDebug("tsdb reader offset seek to uid %" PRId64 " ts %" PRId64 ", table cur set to %d , all table num %d", uid,
ts, pTableScanInfo->currentTable, numOfTables);
} else {
- ASSERT(0);
+ qError("invalid pOffset->type:%d", pOffset->type);
+ return -1;
}
} else if (pOffset->type == TMQ_OFFSET__SNAPSHOT_DATA) {
SStreamRawScanInfo* pInfo = pOperator->info;
@@ -1180,7 +1176,6 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
STableKeyInfo* pList = tableListGetInfo(pTaskInfo->pTableInfoList, 0);
int32_t size = tableListGetSize(pTaskInfo->pTableInfoList);
- ASSERT(size == 1);
tsdbReaderOpen(pInfo->vnode, &pTaskInfo->streamInfo.tableCond, pList, size, NULL, &pInfo->dataReader, NULL);
@@ -1209,7 +1204,10 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
void qProcessRspMsg(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
SMsgSendInfo* pSendInfo = (SMsgSendInfo*)pMsg->info.ahandle;
- assert(pMsg->info.ahandle != NULL);
+ if(pMsg->info.ahandle == NULL){
+ qError("pMsg->info.ahandle is NULL");
+ return;
+ }
SDataBuf buf = {.len = pMsg->contLen, .pData = NULL};
diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c
index 835a70f313..192b0cbc59 100644
--- a/source/libs/executor/src/executorimpl.c
+++ b/source/libs/executor/src/executorimpl.c
@@ -2774,11 +2774,17 @@ int32_t buildSessionResultDataBlock(SOperatorInfo* pOperator, SStreamState* pSta
}
void qStreamCloseTsdbReader(void* task) {
- if (task == NULL) return;
+ if (task == NULL) {
+ return;
+ }
+
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)task;
SOperatorInfo* pOp = pTaskInfo->pRoot;
- qDebug("stream close tsdb reader, reset status uid %" PRId64 " ts %" PRId64, pTaskInfo->streamInfo.lastStatus.uid,
+
+ qDebug("stream close tsdb reader, reset status uid:%" PRId64 " ts:%" PRId64, pTaskInfo->streamInfo.lastStatus.uid,
pTaskInfo->streamInfo.lastStatus.ts);
+
+ // todo refactor, other thread may already use this read to extract data.
pTaskInfo->streamInfo.lastStatus = (STqOffsetVal){0};
while (pOp->numOfDownstream == 1 && pOp->pDownstream[0]) {
SOperatorInfo* pDownstreamOp = pOp->pDownstream[0];
@@ -2786,8 +2792,19 @@ void qStreamCloseTsdbReader(void* task) {
SStreamScanInfo* pInfo = pDownstreamOp->info;
if (pInfo->pTableScanOp) {
STableScanInfo* pTSInfo = pInfo->pTableScanOp->info;
+
+ setOperatorCompleted(pInfo->pTableScanOp);
+ while(pTaskInfo->owner != 0) {
+ taosMsleep(100);
+ qDebug("wait for the reader stopping");
+ }
+
tsdbReaderClose(pTSInfo->base.dataReader);
pTSInfo->base.dataReader = NULL;
+
+ // restore the status, todo refactor.
+ pInfo->pTableScanOp->status = OP_OPENED;
+ pTaskInfo->status = TASK_NOT_COMPLETED;
return;
}
}
diff --git a/source/libs/executor/src/groupoperator.c b/source/libs/executor/src/groupoperator.c
index a05761382e..a2dc202414 100644
--- a/source/libs/executor/src/groupoperator.c
+++ b/source/libs/executor/src/groupoperator.c
@@ -999,14 +999,14 @@ void appendCreateTableRow(SStreamState* pState, SExprSupp* pTableSup, SExprSupp*
memset(tbName, 0, TSDB_TABLE_NAME_LEN);
int32_t len = 0;
if (colDataIsNull_s(pTbCol, pDestBlock->info.rows - 1)) {
- len = TMIN(sizeof(TSDB_DATA_NULL_STR), TSDB_TABLE_NAME_LEN - 1);
- memcpy(tbName, TSDB_DATA_NULL_STR, len);
+ len = 1;
+ tbName[0] = 0;
} else {
void* pData = colDataGetData(pTbCol, pDestBlock->info.rows - 1);
len = TMIN(varDataLen(pData), TSDB_TABLE_NAME_LEN - 1);
memcpy(tbName, varDataVal(pData), len);
+ streamStatePutParName(pState, groupId, tbName);
}
- streamStatePutParName(pState, groupId, tbName);
memcpy(pTmpBlock->info.parTbName, tbName, len);
pDestBlock->info.rows--;
} else {
diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c
index 40b9597643..29a23cd90b 100644
--- a/source/libs/executor/src/scanoperator.c
+++ b/source/libs/executor/src/scanoperator.c
@@ -751,7 +751,7 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator) {
while (1) {
SSDataBlock* result = doGroupedTableScan(pOperator);
- if (result) {
+ if (result || (pOperator->status == OP_EXEC_DONE)) {
return result;
}
@@ -985,6 +985,7 @@ void resetTableScanInfo(STableScanInfo* pTableScanInfo, STimeWindow* pWin) {
pTableScanInfo->scanTimes = 0;
pTableScanInfo->currentGroupId = -1;
tsdbReaderClose(pTableScanInfo->base.dataReader);
+ qDebug("1");
pTableScanInfo->base.dataReader = NULL;
}
@@ -1143,6 +1144,7 @@ static SSDataBlock* doRangeScan(SStreamScanInfo* pInfo, SSDataBlock* pSDB, int32
pInfo->updateWin = (STimeWindow){.skey = INT64_MIN, .ekey = INT64_MAX};
STableScanInfo* pTableScanInfo = pInfo->pTableScanOp->info;
tsdbReaderClose(pTableScanInfo->base.dataReader);
+ qDebug("2");
pTableScanInfo->base.dataReader = NULL;
return NULL;
}
@@ -1616,6 +1618,7 @@ static SSDataBlock* doQueueScan(SOperatorInfo* pOperator) {
if (!pTaskInfo->streamInfo.returned) {
STableScanInfo* pTSInfo = pInfo->pTableScanOp->info;
tsdbReaderClose(pTSInfo->base.dataReader);
+ qDebug("3");
pTSInfo->base.dataReader = NULL;
tqOffsetResetToLog(&pTaskInfo->streamInfo.prepareStatus, pTaskInfo->streamInfo.snapshotVer);
qDebug("queue scan tsdb over, switch to wal ver %" PRId64 "", pTaskInfo->streamInfo.snapshotVer + 1);
@@ -1767,6 +1770,8 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
/*resetTableScanInfo(pTSInfo, pWin);*/
tsdbReaderClose(pTSInfo->base.dataReader);
+ qDebug("4");
+
pTSInfo->base.dataReader = NULL;
pInfo->pTableScanOp->status = OP_OPENED;
@@ -1837,6 +1842,8 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
pTaskInfo->streamInfo.recoverStep = STREAM_RECOVER_STEP__NONE;
STableScanInfo* pTSInfo = pInfo->pTableScanOp->info;
tsdbReaderClose(pTSInfo->base.dataReader);
+ qDebug("5");
+
pTSInfo->base.dataReader = NULL;
pTSInfo->base.cond.startVersion = -1;
@@ -2635,6 +2642,8 @@ static SSDataBlock* getTableDataBlockImpl(void* param) {
return pBlock;
}
+ qDebug("8");
+
tsdbReaderClose(pInfo->base.dataReader);
pInfo->base.dataReader = NULL;
return NULL;
@@ -3180,7 +3189,7 @@ static SSDataBlock* buildSysDbTableCount(SOperatorInfo* pOperator, STableCountSc
size_t perfdbTableNum;
getPerfDbMeta(NULL, &perfdbTableNum);
- if (pSupp->groupByDbName) {
+ if (pSupp->groupByDbName || pSupp->groupByStbName) {
buildSysDbGroupedTableCount(pOperator, pInfo, pSupp, pRes, infodbTableNum, perfdbTableNum);
return (pRes->info.rows > 0) ? pRes : NULL;
} else {
@@ -3205,11 +3214,23 @@ static void buildSysDbGroupedTableCount(SOperatorInfo* pOperator, STableCountSca
STableCountScanSupp* pSupp, SSDataBlock* pRes, size_t infodbTableNum,
size_t perfdbTableNum) {
if (pInfo->currGrpIdx == 0) {
- uint64_t groupId = calcGroupId(TSDB_INFORMATION_SCHEMA_DB, strlen(TSDB_INFORMATION_SCHEMA_DB));
+ uint64_t groupId = 0;
+ if (pSupp->groupByDbName) {
+ groupId = calcGroupId(TSDB_INFORMATION_SCHEMA_DB, strlen(TSDB_INFORMATION_SCHEMA_DB));
+ } else {
+ groupId = calcGroupId("", 0);
+ }
+
pRes->info.id.groupId = groupId;
fillTableCountScanDataBlock(pSupp, TSDB_INFORMATION_SCHEMA_DB, "", infodbTableNum, pRes);
} else if (pInfo->currGrpIdx == 1) {
- uint64_t groupId = calcGroupId(TSDB_PERFORMANCE_SCHEMA_DB, strlen(TSDB_PERFORMANCE_SCHEMA_DB));
+ uint64_t groupId = 0;
+ if (pSupp->groupByDbName) {
+ groupId = calcGroupId(TSDB_PERFORMANCE_SCHEMA_DB, strlen(TSDB_PERFORMANCE_SCHEMA_DB));
+ } else {
+ groupId = calcGroupId("", 0);
+ }
+
pRes->info.id.groupId = groupId;
fillTableCountScanDataBlock(pSupp, TSDB_PERFORMANCE_SCHEMA_DB, "", perfdbTableNum, pRes);
} else {
@@ -3247,7 +3268,7 @@ static SSDataBlock* buildVnodeDbTableCount(SOperatorInfo* pOperator, STableCount
tNameFromString(&sn, db, T_NAME_ACCT | T_NAME_DB);
tNameGetDbName(&sn, dbName);
- if (pSupp->groupByDbName) {
+ if (pSupp->groupByDbName || pSupp->groupByStbName) {
buildVnodeGroupedTableCount(pOperator, pInfo, pSupp, pRes, vgId, dbName);
} else {
buildVnodeFilteredTbCount(pOperator, pInfo, pSupp, pRes, dbName);
@@ -3308,7 +3329,10 @@ static void buildVnodeFilteredTbCount(SOperatorInfo* pOperator, STableCountScanO
static void buildVnodeGroupedNtbTableCount(STableCountScanOperatorInfo* pInfo, STableCountScanSupp* pSupp,
SSDataBlock* pRes, char* dbName) {
char fullStbName[TSDB_TABLE_FNAME_LEN] = {0};
- snprintf(fullStbName, TSDB_TABLE_FNAME_LEN, "%s.%s", dbName, "");
+ if (pSupp->groupByDbName) {
+ snprintf(fullStbName, TSDB_TABLE_FNAME_LEN, "%s.%s", dbName, "");
+ }
+
uint64_t groupId = calcGroupId(fullStbName, strlen(fullStbName));
pRes->info.id.groupId = groupId;
int64_t ntbNum = metaGetNtbNum(pInfo->readHandle.meta);
@@ -3323,7 +3347,12 @@ static void buildVnodeGroupedStbTableCount(STableCountScanOperatorInfo* pInfo, S
metaGetTableSzNameByUid(pInfo->readHandle.meta, stbUid, stbName);
char fullStbName[TSDB_TABLE_FNAME_LEN] = {0};
- snprintf(fullStbName, TSDB_TABLE_FNAME_LEN, "%s.%s", dbName, stbName);
+ if (pSupp->groupByDbName) {
+ snprintf(fullStbName, TSDB_TABLE_FNAME_LEN, "%s.%s", dbName, stbName);
+ } else {
+ snprintf(fullStbName, TSDB_TABLE_FNAME_LEN, "%s", stbName);
+ }
+
uint64_t groupId = calcGroupId(fullStbName, strlen(fullStbName));
pRes->info.id.groupId = groupId;
diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c
index 709b6fd206..fef588a503 100644
--- a/source/libs/executor/src/timewindowoperator.c
+++ b/source/libs/executor/src/timewindowoperator.c
@@ -939,7 +939,6 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul
TSKEY ekey = ascScan ? win.ekey : win.skey;
int32_t forwardRows =
getNumOfRowsInTimeWindow(&pBlock->info, tsCols, startPos, ekey, binarySearchForKey, NULL, pInfo->inputOrder);
- ASSERT(forwardRows > 0);
// prev time window not interpolation yet.
if (pInfo->timeWindowInterpo) {
@@ -3912,7 +3911,7 @@ static void doStreamStateAggImpl(SOperatorInfo* pOperator, SSDataBlock* pSDataBl
blockDataEnsureCapacity(pAggSup->pScanBlock, rows);
SColumnInfoData* pKeyColInfo = taosArrayGet(pSDataBlock->pDataBlock, pInfo->stateCol.slotId);
for (int32_t i = 0; i < rows; i += winRows) {
- if (pInfo->ignoreExpiredData && isOverdue(tsCols[i], &pInfo->twAggSup)) {
+ if (pInfo->ignoreExpiredData && isOverdue(tsCols[i], &pInfo->twAggSup) || colDataIsNull_s(pKeyColInfo, i)) {
i++;
continue;
}
diff --git a/source/libs/function/src/udfd.c b/source/libs/function/src/udfd.c
index dc6fc3ad74..c368788243 100644
--- a/source/libs/function/src/udfd.c
+++ b/source/libs/function/src/udfd.c
@@ -21,6 +21,7 @@
#include "tudf.h"
#include "tudfInt.h"
+#include "version.h"
#include "tdatablock.h"
#include "tdataformat.h"
@@ -527,6 +528,7 @@ int32_t udfdConnectToMnode() {
tstrncpy(connReq.passwd, pass, sizeof(connReq.passwd));
connReq.pid = taosGetPId();
connReq.startTime = taosGetTimestampMs();
+ strcpy(connReq.sVer, version);
int32_t contLen = tSerializeSConnectReq(NULL, 0, &connReq);
void *pReq = rpcMallocCont(contLen);
diff --git a/source/libs/parser/src/parInsertSml.c b/source/libs/parser/src/parInsertSml.c
index d6c1072669..3c2b6499a4 100644
--- a/source/libs/parser/src/parInsertSml.c
+++ b/source/libs/parser/src/parInsertSml.c
@@ -345,6 +345,7 @@ int32_t smlBindData(SQuery* query, bool dataFormat, SArray* tags, SArray* colsSc
}
if (!taosMbsToUcs4(kv->value, kv->length, (TdUcs4*)pUcs4, pColSchema->bytes - VARSTR_HEADER_SIZE, &len)) {
if (errno == E2BIG) {
+ uError("sml bind taosMbsToUcs4 error, kv length:%d, bytes:%d", (int)kv->length, pColSchema->bytes);
buildInvalidOperationMsg(&pBuf, "value too long");
ret = TSDB_CODE_PAR_VALUE_TOO_LONG;
goto end;
diff --git a/source/libs/stream/src/streamExec.c b/source/libs/stream/src/streamExec.c
index cb9774b584..cb610ad6b5 100644
--- a/source/libs/stream/src/streamExec.c
+++ b/source/libs/stream/src/streamExec.c
@@ -20,7 +20,7 @@
static int32_t streamTaskExecImpl(SStreamTask* pTask, const void* data, SArray* pRes) {
int32_t code;
void* exec = pTask->exec.executor;
- while(atomic_load_8(&pTask->taskStatus) != TASK_STATUS__NORMAL) {
+ while(pTask->taskLevel == TASK_LEVEL__SOURCE && atomic_load_8(&pTask->taskStatus) != TASK_STATUS__NORMAL) {
qError("stream task wait for the end of fill history");
taosMsleep(2);
continue;
diff --git a/source/libs/stream/src/streamState.c b/source/libs/stream/src/streamState.c
index a2b3e20dbf..411726075e 100644
--- a/source/libs/stream/src/streamState.c
+++ b/source/libs/stream/src/streamState.c
@@ -130,21 +130,25 @@ SStreamState* streamStateOpen(char* path, SStreamTask* pTask, bool specPath, int
char cfgPath[1030];
sprintf(cfgPath, "%s/cfg", statePath);
+ szPage = szPage < 0 ? 4096 : szPage;
+ pages = pages < 0 ? 256 : pages;
char cfg[1024];
memset(cfg, 0, 1024);
TdFilePtr pCfgFile = taosOpenFile(cfgPath, TD_FILE_READ);
if (pCfgFile != NULL) {
- int64_t size;
+ int64_t size = 0;
taosFStatFile(pCfgFile, &size, NULL);
- taosReadFile(pCfgFile, cfg, size);
- sscanf(cfg, "%d\n%d\n", &szPage, &pages);
+ if (size > 0) {
+ taosReadFile(pCfgFile, cfg, size);
+ sscanf(cfg, "%d\n%d\n", &szPage, &pages);
+ }
} else {
- taosMulModeMkDir(statePath, 0755);
- pCfgFile = taosOpenFile(cfgPath, TD_FILE_WRITE | TD_FILE_CREATE);
- szPage = szPage < 0 ? 4096 : szPage;
- pages = pages < 0 ? 256 : pages;
- sprintf(cfg, "%d\n%d\n", szPage, pages);
- taosWriteFile(pCfgFile, cfg, strlen(cfg));
+ int32_t code = taosMulModeMkDir(statePath, 0755);
+ if (code == 0) {
+ pCfgFile = taosOpenFile(cfgPath, TD_FILE_WRITE | TD_FILE_CREATE);
+ sprintf(cfg, "%d\n%d\n", szPage, pages);
+ taosWriteFile(pCfgFile, cfg, strlen(cfg));
+ }
}
taosCloseFile(&pCfgFile);
diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c
index 90f79fd93c..e5fe4a2369 100644
--- a/source/libs/sync/src/syncMain.c
+++ b/source/libs/sync/src/syncMain.c
@@ -2160,8 +2160,8 @@ int32_t syncNodeAppend(SSyncNode* ths, SSyncRaftEntry* pEntry) {
// append to log buffer
if (syncLogBufferAppend(ths->pLogBuf, ths, pEntry) < 0) {
sError("vgId:%d, failed to enqueue sync log buffer, index:%" PRId64, ths->vgId, pEntry->index);
- terrno = TSDB_CODE_SYN_BUFFER_FULL;
- (void)syncLogFsmExecute(ths, ths->pFsm, ths->state, raftStoreGetTerm(ths), pEntry, TSDB_CODE_SYN_BUFFER_FULL);
+ ASSERT(terrno != 0);
+ (void)syncLogFsmExecute(ths, ths->pFsm, ths->state, raftStoreGetTerm(ths), pEntry, terrno);
syncEntryDestroy(pEntry);
return -1;
}
diff --git a/source/libs/sync/src/syncPipeline.c b/source/libs/sync/src/syncPipeline.c
index cc1a40a430..6600b505c1 100644
--- a/source/libs/sync/src/syncPipeline.c
+++ b/source/libs/sync/src/syncPipeline.c
@@ -48,7 +48,16 @@ int32_t syncLogBufferAppend(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEnt
SyncIndex index = pEntry->index;
if (index - pBuf->startIndex >= pBuf->size) {
- sError("vgId:%d, failed to append due to sync log buffer full. index:%" PRId64 "", pNode->vgId, index);
+ terrno = TSDB_CODE_SYN_BUFFER_FULL;
+ sError("vgId:%d, failed to append since %s. index:%" PRId64 "", pNode->vgId, terrstr(), index);
+ goto _err;
+ }
+
+ SyncIndex appliedIndex = pNode->pFsm->FpAppliedIndexCb(pNode->pFsm);
+ if (pNode->restoreFinish && pBuf->commitIndex - appliedIndex >= pBuf->size) {
+ terrno = TSDB_CODE_SYN_WRITE_STALL;
+ sError("vgId:%d, failed to append since %s. index:%" PRId64 ", commit-index:%" PRId64 ", applied-index:%" PRId64,
+ pNode->vgId, terrstr(), index, pBuf->commitIndex, appliedIndex);
goto _err;
}
@@ -475,7 +484,7 @@ _out:
int32_t syncLogFsmExecute(SSyncNode* pNode, SSyncFSM* pFsm, ESyncState role, SyncTerm term, SSyncRaftEntry* pEntry,
int32_t applyCode) {
- if ((pNode->replicaNum == 1) && pNode->restoreFinish && pNode->vgId != 1) {
+ if (pNode->replicaNum == 1 && pNode->restoreFinish && pNode->vgId != 1) {
return 0;
}
@@ -587,10 +596,10 @@ _out:
// mark as restored if needed
if (!pNode->restoreFinish && pBuf->commitIndex >= pNode->commitIndex && pEntry != NULL &&
currentTerm <= pEntry->term) {
- pNode->pFsm->FpRestoreFinishCb(pNode->pFsm);
+ pNode->pFsm->FpRestoreFinishCb(pNode->pFsm, pBuf->commitIndex);
pNode->restoreFinish = true;
- sInfo("vgId:%d, restore finished. log buffer: [%" PRId64 " %" PRId64 " %" PRId64 ", %" PRId64 ")", pNode->vgId,
- pBuf->startIndex, pBuf->commitIndex, pBuf->matchIndex, pBuf->endIndex);
+ sInfo("vgId:%d, restore finished. term:%" PRId64 ", log buffer: [%" PRId64 " %" PRId64 " %" PRId64 ", %" PRId64 ")",
+ pNode->vgId, currentTerm, pBuf->startIndex, pBuf->commitIndex, pBuf->matchIndex, pBuf->endIndex);
}
if (!inBuf) {
diff --git a/source/util/src/terror.c b/source/util/src/terror.c
index a6a26988d9..b84d58bfe8 100644
--- a/source/util/src/terror.c
+++ b/source/util/src/terror.c
@@ -412,7 +412,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_TABLE_LIMITED, "Table creation limite
// sync
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_TIMEOUT, "Sync timeout")
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_IS_LEADER, "Sync is leader")
-TAOS_DEFINE_ERROR(TSDB_CODE_SYN_NOT_LEADER, "Sync not leader")
+TAOS_DEFINE_ERROR(TSDB_CODE_SYN_NOT_LEADER, "Sync leader is unreachable")
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_ONE_REPLICA, "Sync one replica")
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_NOT_IN_NEW_CONFIG, "Sync not in new config")
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_NEW_CONFIG_ERROR, "Sync new config error")
@@ -420,9 +420,10 @@ TAOS_DEFINE_ERROR(TSDB_CODE_SYN_RECONFIG_NOT_READY, "Sync not ready for re
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_PROPOSE_NOT_READY, "Sync not ready for propose")
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_STANDBY_NOT_READY, "Sync not ready for standby")
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_BATCH_ERROR, "Sync batch error")
-TAOS_DEFINE_ERROR(TSDB_CODE_SYN_RESTORING, "Sync is restoring")
+TAOS_DEFINE_ERROR(TSDB_CODE_SYN_RESTORING, "Sync leader is restoring")
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_INVALID_SNAPSHOT_MSG, "Sync invalid snapshot msg")
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_BUFFER_FULL, "Sync buffer is full")
+TAOS_DEFINE_ERROR(TSDB_CODE_SYN_WRITE_STALL, "Sync write stall")
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_INTERNAL_ERROR, "Sync internal error")
//tq
diff --git a/source/util/src/tlrucache.c b/source/util/src/tlrucache.c
index 264883be4e..f4172fbb44 100644
--- a/source/util/src/tlrucache.c
+++ b/source/util/src/tlrucache.c
@@ -580,6 +580,16 @@ static size_t taosLRUCacheShardGetUsage(SLRUCacheShard *shard) {
return usage;
}
+static int32_t taosLRUCacheShardGetElems(SLRUCacheShard *shard) {
+ int32_t elems = 0;
+
+ taosThreadMutexLock(&shard->mutex);
+ elems = shard->table.elems;
+ taosThreadMutexUnlock(&shard->mutex);
+
+ return elems;
+}
+
static size_t taosLRUCacheShardGetPinnedUsage(SLRUCacheShard *shard) {
size_t usage = 0;
@@ -755,6 +765,16 @@ size_t taosLRUCacheGetUsage(SLRUCache *cache) {
return usage;
}
+int32_t taosLRUCacheGetElems(SLRUCache *cache) {
+ int32_t elems = 0;
+
+ for (int i = 0; i < cache->numShards; ++i) {
+ elems += taosLRUCacheShardGetElems(&cache->shards[i]);
+ }
+
+ return elems;
+}
+
size_t taosLRUCacheGetPinnedUsage(SLRUCache *cache) {
size_t usage = 0;
diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task
index 87144f5b99..fb367a5773 100644
--- a/tests/parallel_test/cases.task
+++ b/tests/parallel_test/cases.task
@@ -864,6 +864,7 @@
,,y,script,./test.sh -f tsim/query/forceFill.sim
,,y,script,./test.sh -f tsim/query/emptyTsRange.sim
,,y,script,./test.sh -f tsim/query/partitionby.sim
+,,y,script,./test.sh -f tsim/query/tableCount.sim
,,y,script,./test.sh -f tsim/qnode/basic1.sim
,,y,script,./test.sh -f tsim/snode/basic1.sim
,,y,script,./test.sh -f tsim/mnode/basic1.sim
@@ -1096,7 +1097,7 @@
,,n,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/sample_csv_json.py
#,,n,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/sml_json_alltypes.py
,,n,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/taosdemoTestQueryWithJson.py -R
-,,n,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/telnet_tcp.py -R
+#,,n,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/telnet_tcp.py -R
#docs-examples test
,,n,docs-examples-test,bash python.sh
diff --git a/tests/requirements.txt b/tests/requirements.txt
index c6e27fd3be..5cdd9e02be 100644
--- a/tests/requirements.txt
+++ b/tests/requirements.txt
@@ -8,3 +8,4 @@ distro
requests
pexpect
faker
+pyopenssl
diff --git a/tests/script/tsim/query/tableCount.sim b/tests/script/tsim/query/tableCount.sim
new file mode 100644
index 0000000000..d8d9bb9b03
--- /dev/null
+++ b/tests/script/tsim/query/tableCount.sim
@@ -0,0 +1,107 @@
+system sh/stop_dnodes.sh
+system sh/deploy.sh -n dnode1 -i 1
+system sh/exec.sh -n dnode1 -s start
+sql connect
+
+sql drop database if exists db1;
+sql create database db1 vgroups 3;
+sql create database db1;
+sql use db1;
+sql create stable sta (ts timestamp, f1 int, f2 binary(200)) tags(t1 int, t2 int, t3 int);
+sql create stable stb (ts timestamp, f1 int, f2 binary(200)) tags(t1 int, t2 int, t3 int);
+sql create table tba1 using sta tags(1, 1, 1);
+sql create table tba2 using sta tags(2, 2, 2);
+sql create table tba3 using sta tags(3, 3, 3);
+sql create table tba4 using sta tags(3, 3, 3);
+sql create table tba5 using sta tags(3, 3, 3);
+sql create table tba6 using sta tags(3, 3, 3);
+sql create table tba7 using sta tags(3, 3, 3);
+sql create table tba8 using sta tags(3, 3, 3);
+sql create table tbb1 using stb tags(4, 4, 4);
+sql create table tbb2 using stb tags(5, 5, 5);
+sql create table tbb3 using stb tags(6, 6, 6);
+sql create table tbb4 using stb tags(4, 4, 4);
+sql create table tbb5 using stb tags(5, 5, 5);
+sql create table tbb6 using stb tags(6, 6, 6);
+sql create table tbb7 using stb tags(7, 7, 7);
+sql create table tbb8 using stb tags(8, 8, 8);
+sql create table tbn1 (ts timestamp, f1 int);
+sql create database db2 vgroups 3;
+sql create database db2;
+sql use db2;
+sql create stable sta (ts timestamp, f1 int, f2 binary(200)) tags(t1 int, t2 int, t3 int);
+sql create stable stb (ts timestamp, f1 int, f2 binary(200)) tags(t1 int, t2 int, t3 int);
+sql create table tba1 using sta tags(1, 1, 1);
+sql create table tba2 using sta tags(2, 2, 2);
+sql create table tbb1 using stb tags(4, 4, 4);
+sql create table tbb2 using stb tags(5, 5, 5);
+sql create table tbb3 using stb tags(6, 6, 6);
+
+sql select count(table_name) from information_schema.ins_tables group by stable_name;
+if $rows != 3 then
+ return -1
+endi
+sql select count(table_name) from information_schema.ins_tables group by db_name;
+if $rows != 4 then
+ return -1
+endi
+sql select count(table_name) from information_schema.ins_tables group by db_name, stable_name;
+if $rows != 7 then
+ return -1
+endi
+sql select stable_name,count(table_name) from information_schema.ins_tables group by stable_name order by stable_name;
+if $rows != 3 then
+ return -1
+endi
+if $data01 != 30 then
+ return -1
+endi
+if $data11 != 10 then
+ return -1
+endi
+if $data21 != 11 then
+ return -1
+endi
+sql select db_name,count(table_name) from information_schema.ins_tables group by db_name order by db_name;
+if $rows != 4 then
+ return -1
+endi
+if $data01 != 17 then
+ return -1
+endi
+if $data11 != 5 then
+ return -1
+endi
+if $data21 != 24 then
+ return -1
+endi
+if $data31 != 5 then
+ return -1
+endi
+sql select db_name,stable_name,count(table_name) from information_schema.ins_tables group by db_name, stable_name order by db_name, stable_name;
+if $rows != 7 then
+ return -1
+endi
+if $data02 != 1 then
+ return -1
+endi
+if $data12 != 8 then
+ return -1
+endi
+if $data22 != 8 then
+ return -1
+endi
+if $data32 != 2 then
+ return -1
+endi
+if $data42 != 3 then
+ return -1
+endi
+if $data52 != 24 then
+ return -1
+endi
+if $data62 != 5 then
+ return -1
+endi
+
+system sh/exec.sh -n dnode1 -s stop -x SIGINT
diff --git a/tests/script/tsim/stream/deleteState.sim b/tests/script/tsim/stream/deleteState.sim
index dd74b73dce..c84e52067c 100644
--- a/tests/script/tsim/stream/deleteState.sim
+++ b/tests/script/tsim/stream/deleteState.sim
@@ -51,13 +51,8 @@ if $loop_count == 10 then
return -1
endi
-if $data01 != 1 then
- print =====data01=$data01
- goto loop1
-endi
-
-if $data02 != NULL then
- print =====data02=$data02
+if $rows != 0 then
+ print =====rows=$rows
goto loop1
endi
diff --git a/tests/script/tsim/stream/partitionbyColumnState.sim b/tests/script/tsim/stream/partitionbyColumnState.sim
index 62262a490c..b69ab2df52 100644
--- a/tests/script/tsim/stream/partitionbyColumnState.sim
+++ b/tests/script/tsim/stream/partitionbyColumnState.sim
@@ -27,13 +27,8 @@ if $loop_count == 10 then
return -1
endi
-if $data01 != 1 then
- print =====data01=$data01
- goto loop0
-endi
-
-if $data02 != NULL then
- print =====data02=$data02
+if $rows != 0 then
+ print =====rows=$rows
goto loop0
endi
diff --git a/tests/script/tsim/stream/state1.sim b/tests/script/tsim/stream/state1.sim
new file mode 100644
index 0000000000..2ae5739642
--- /dev/null
+++ b/tests/script/tsim/stream/state1.sim
@@ -0,0 +1,101 @@
+system sh/stop_dnodes.sh
+system sh/deploy.sh -n dnode1 -i 1
+system sh/exec.sh -n dnode1 -s start
+sleep 50
+sql connect
+
+print =============== create database
+sql create database test vgroups 4;
+sql select * from information_schema.ins_databases;
+if $rows != 3 then
+ return -1
+endi
+
+print $data00 $data01 $data02
+
+sql use test;
+
+sql create table t1(ts timestamp, a int, b int , c int, d double, id int);
+
+print create stream streams1 trigger at_once IGNORE EXPIRED 0 into streamt1 as select _wstart, count(*) c1 from t1 state_window(a);
+
+sql create stream streams1 trigger at_once IGNORE EXPIRED 0 into streamt1 as select _wstart, count(*) c1 from t1 state_window(a);
+
+sql insert into t1(ts) values(1648791213000);
+
+$loop_count = 0
+loop0:
+
+sleep 300
+$loop_count = $loop_count + 1
+if $loop_count == 10 then
+ return -1
+endi
+
+sql select * from streamt1;
+print data00 data01
+print data10 data11
+
+if $rows != 0 then
+ print =====rows=$rows
+ goto loop0
+endi
+
+sql insert into t1 values(1648791214000,1,2,3,1.0,3);
+$loop_count = 0
+loop1:
+
+sleep 300
+$loop_count = $loop_count + 1
+if $loop_count == 10 then
+ return -1
+endi
+
+sql select * from streamt1;
+print data00 data01
+print data10 data11
+
+if $rows != 1 then
+ print =====rows=$rows
+ goto loop1
+endi
+
+sql insert into t1 values(1648791215000,2,2,3,1.0,4);
+
+$loop_count = 0
+loop2:
+
+sleep 300
+$loop_count = $loop_count + 1
+if $loop_count == 10 then
+ return -1
+endi
+
+sql select * from streamt1;
+
+if $rows != 2 then
+ print =====rows=$rows
+ goto loop2
+endi
+
+sql insert into t1(ts) values(1648791216000);
+
+$loop_count = 0
+loop3:
+
+sleep 300
+$loop_count = $loop_count + 1
+if $loop_count == 10 then
+ return -1
+endi
+
+sql select * from streamt1;
+if $rows != 2 then
+ print =====rows=$rows
+ goto loop2
+endi
+
+
+print state1 end
+
+system sh/stop_dnodes.sh
diff --git a/tests/system-test/2-query/odbc.py b/tests/system-test/2-query/odbc.py
index f26f0abda0..9bbff4af21 100644
--- a/tests/system-test/2-query/odbc.py
+++ b/tests/system-test/2-query/odbc.py
@@ -22,7 +22,7 @@ class TDTestCase:
tdSql.execute("insert into db.ctb using db.stb tags(1) (ts, c1) values (now, 1)")
tdSql.query("select count(*) from information_schema.ins_columns")
- tdSql.checkData(0, 0, 271)
+ tdSql.checkData(0, 0, 272)
tdSql.query("select * from information_schema.ins_columns where table_name = 'ntb'")
tdSql.checkRows(14)
diff --git a/tests/system-test/6-cluster/5dnode1mnode.py b/tests/system-test/6-cluster/5dnode1mnode.py
index f21fae0d7b..d0d9372298 100644
--- a/tests/system-test/6-cluster/5dnode1mnode.py
+++ b/tests/system-test/6-cluster/5dnode1mnode.py
@@ -29,7 +29,7 @@ class TDTestCase:
self.master_dnode = self.TDDnodes.dnodes[0]
self.host=self.master_dnode.cfgDict["fqdn"]
conn1 = taos.connect(self.master_dnode.cfgDict["fqdn"] , config=self.master_dnode.cfgDir)
- tdSql.init(conn1.cursor())
+ tdSql.init(conn1.cursor(), True)
def getBuildPath(self):
diff --git a/tests/system-test/7-tmq/subscribeDb1.py b/tests/system-test/7-tmq/subscribeDb1.py
index c5ae44214a..89bf337a20 100644
--- a/tests/system-test/7-tmq/subscribeDb1.py
+++ b/tests/system-test/7-tmq/subscribeDb1.py
@@ -123,8 +123,9 @@ class TDTestCase:
pre_insert = "insert into "
sql = pre_insert
- t = time.time()
- startTs = int(round(t * 1000))
+ # t = 1678609778776 #time.time()
+ t = 1600000000000
+ startTs = t #int(round(t * 1000))
#tdLog.debug("doing insert data into stable:%s rows:%d ..."%(stbName, allRows))
for i in range(ctbNum):
sql += " %s_%d values "%(stbName,i)
diff --git a/utils/test/c/tmqSim.c b/utils/test/c/tmqSim.c
index 1acf50a7d8..ce61b80d41 100644
--- a/utils/test/c/tmqSim.c
+++ b/utils/test/c/tmqSim.c
@@ -386,7 +386,7 @@ void addRowsToVgroupId(SThreadInfo* pInfo, int32_t vgroupId, int32_t rows) {
pInfo->rowsOfPerVgroups[pInfo->numOfVgroups][1] += rows;
pInfo->numOfVgroups++;
- taosFprintfFile(g_fp, "consume id %d, add one new vogroup id: %d\n", pInfo->consumerId, vgroupId);
+ taosFprintfFile(g_fp, "consume id %d, add new vgroupId:%d\n", pInfo->consumerId, vgroupId);
if (pInfo->numOfVgroups > MAX_VGROUP_CNT) {
taosFprintfFile(g_fp, "====consume id %d, vgroup num %d over than 32. new vgroupId: %d\n", pInfo->consumerId,
pInfo->numOfVgroups, vgroupId);
@@ -578,18 +578,25 @@ static int32_t data_msg_process(TAOS_RES* msg, SThreadInfo* pInfo, int32_t msgIn
char buf[1024];
int32_t totalRows = 0;
- // printf("topic: %s\n", tmq_get_topic_name(msg));
int32_t vgroupId = tmq_get_vgroup_id(msg);
const char* dbName = tmq_get_db_name(msg);
taosFprintfFile(g_fp, "consumerId: %d, msg index:%d\n", pInfo->consumerId, msgIndex);
- taosFprintfFile(g_fp, "dbName: %s, topic: %s, vgroupId: %d\n", dbName != NULL ? dbName : "invalid table",
- tmq_get_topic_name(msg), vgroupId);
+ int32_t index = 0;
+ for (index = 0; index < pInfo->numOfVgroups; index++) {
+ if (vgroupId == pInfo->rowsOfPerVgroups[index][0]) {
+ break;
+ }
+ }
+
+ taosFprintfFile(g_fp, "dbName: %s, topic: %s, vgroupId:%d, currentRows:%d\n", dbName != NULL ? dbName : "invalid table",
+ tmq_get_topic_name(msg), vgroupId, pInfo->rowsOfPerVgroups[index][1]);
while (1) {
TAOS_ROW row = taos_fetch_row(msg);
-
- if (row == NULL) break;
+ if (row == NULL) {
+ break;
+ }
TAOS_FIELD* fields = taos_fetch_fields(msg);
int32_t numOfFields = taos_field_count(msg);
@@ -607,7 +614,6 @@ static int32_t data_msg_process(TAOS_RES* msg, SThreadInfo* pInfo, int32_t msgIn
#endif
dumpToFileForCheck(pInfo->pConsumeRowsFile, row, fields, length, numOfFields, precision);
-
taos_print_row(buf, row, fields, numOfFields);
if (0 != g_stConfInfo.showRowFlag) {
@@ -621,7 +627,6 @@ static int32_t data_msg_process(TAOS_RES* msg, SThreadInfo* pInfo, int32_t msgIn
}
addRowsToVgroupId(pInfo, vgroupId, totalRows);
-
return totalRows;
}
@@ -730,9 +735,7 @@ void build_consumer(SThreadInfo* pInfo) {
}
pInfo->tmq = tmq_consumer_new(conf, NULL, 0);
-
tmq_conf_destroy(conf);
-
return;
}
@@ -817,7 +820,6 @@ void loop_consume(SThreadInfo* pInfo) {
}
taos_free_result(tmqMsg);
-
totalMsgs++;
int64_t currentPrintTime = taosGetTimestampMs();