fix(sync): fix AddressSanitizer error: TD-20372
This commit is contained in:
commit
c20627c1d6
|
@ -102,6 +102,12 @@ IF ("${CPUTYPE}" STREQUAL "")
|
|||
SET(TD_ARM_64 TRUE)
|
||||
ADD_DEFINITIONS("-D_TD_ARM_")
|
||||
ADD_DEFINITIONS("-D_TD_ARM_64")
|
||||
ELSEIF (CMAKE_SYSTEM_PROCESSOR MATCHES "loongarch64")
|
||||
MESSAGE(STATUS "The current platform is loongarch64")
|
||||
SET(PLATFORM_ARCH_STR "loongarch64")
|
||||
SET(TD_LOONGARCH_64 TRUE)
|
||||
ADD_DEFINITIONS("-D_TD_LOONGARCH_")
|
||||
ADD_DEFINITIONS("-D_TD_LOONGARCH_64")
|
||||
ENDIF ()
|
||||
ELSE ()
|
||||
# if generate ARM version:
|
||||
|
@ -118,6 +124,12 @@ ELSE ()
|
|||
ADD_DEFINITIONS("-D_TD_ARM_")
|
||||
ADD_DEFINITIONS("-D_TD_ARM_64")
|
||||
SET(TD_ARM_64 TRUE)
|
||||
ELSEIF (${CPUTYPE} MATCHES "loongarch64")
|
||||
SET(PLATFORM_ARCH_STR "loongarch64")
|
||||
MESSAGE(STATUS "input cpuType: loongarch64")
|
||||
SET(TD_LOONGARCH_64 TRUE)
|
||||
ADD_DEFINITIONS("-D_TD_LOONGARCH_")
|
||||
ADD_DEFINITIONS("-D_TD_LOONGARCH_64")
|
||||
ELSEIF (${CPUTYPE} MATCHES "mips64")
|
||||
SET(PLATFORM_ARCH_STR "mips")
|
||||
MESSAGE(STATUS "input cpuType: mips64")
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# taos-tools
|
||||
ExternalProject_Add(taos-tools
|
||||
GIT_REPOSITORY https://github.com/taosdata/taos-tools.git
|
||||
GIT_TAG a921bd4
|
||||
GIT_TAG 23e2b73
|
||||
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taos-tools"
|
||||
BINARY_DIR ""
|
||||
#BUILD_IN_SOURCE TRUE
|
||||
|
|
|
@ -14,7 +14,7 @@ Note: ● means officially tested and verified, ○ means unofficially tested an
|
|||
|
||||
## List of supported platforms for TDengine clients and connectors
|
||||
|
||||
TDengine's connector can support a wide range of platforms, including X64/X86/ARM64/ARM32/MIPS/Alpha hardware platforms and Linux/Win64/Win32/macOS development environments.
|
||||
TDengine's connector can support a wide range of platforms, including X64/X86/ARM64/ARM32/MIPS/Alpha/LoongArch64 hardware platforms and Linux/Win64/Win32/macOS development environments.
|
||||
|
||||
The comparison matrix is as follows.
|
||||
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
---
|
||||
sidebar_label: TDengine
|
||||
title: TDengine
|
||||
title: TDengine Release History and Download Links
|
||||
description: TDengine release history, Release Notes and download links.
|
||||
---
|
||||
|
||||
TDengine 3.x installation packages can be downloaded at the following links:
|
||||
|
||||
For TDengine 2.x installation packages by version, please visit [here](https://www.taosdata.com/all-downloads).
|
||||
|
||||
import Release from "/components/ReleaseV3";
|
||||
|
||||
## 3.0.1.6
|
||||
|
@ -33,4 +37,3 @@ import Release from "/components/ReleaseV3";
|
|||
## 3.0.1.0
|
||||
|
||||
<Release type="tdengine" version="3.0.1.0" />
|
||||
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
---
|
||||
sidebar_label: taosTools
|
||||
title: taosTools
|
||||
sidebar_label: taosTools
|
||||
title: taosTools Release History and Download Links
|
||||
description: taosTools release history, Release Notes, download links.
|
||||
---
|
||||
|
||||
taosTools installation packages can be downloaded at the following links:
|
||||
|
||||
For other historical version installers, please visit [here](https://www.taosdata.com/all-downloads).
|
||||
|
||||
import Release from "/components/ReleaseV3";
|
||||
|
||||
## 2.2.7
|
||||
|
|
|
@ -3,6 +3,8 @@ title: 立即开始
|
|||
description: '快速设置 TDengine 环境并体验其高效写入和查询'
|
||||
---
|
||||
|
||||
import xiaot from './tdengine.webp'
|
||||
|
||||
TDengine 完整的软件包包括服务端(taosd)、用于与第三方系统对接并提供 RESTful 接口的 taosAdapter、应用驱动(taosc)、命令行程序 (CLI,taos) 和一些工具软件。TDengine 除了提供多种语言的连接器之外,还通过 [taosAdapter](../reference/taosadapter) 提供 [RESTful 接口](../connector/rest-api)。
|
||||
|
||||
本章主要介绍如何利用 Docker 或者安装包快速设置 TDengine 环境并体验其高效写入和查询。
|
||||
|
@ -12,4 +14,10 @@ import DocCardList from '@theme/DocCardList';
|
|||
import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
||||
|
||||
<DocCardList items={useCurrentSidebarCategory().items}/>
|
||||
```
|
||||
```
|
||||
|
||||
### 开发者技术交流群
|
||||
|
||||
微信扫描下面二维码,加“小 T”为好友,即可加入“物联网大数据技术前沿群”,与大家共同交流物联网大数据技术应用、TDengine 使用问题和技巧等话题。
|
||||
|
||||
<img src={xiaot} alt="小 T 的二维码" width="200" />
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
|
@ -115,6 +115,7 @@ TDengine 客户端驱动的安装请参考 [安装指南](../#安装步骤)
|
|||
<summary>订阅和消费</summary>
|
||||
|
||||
```c
|
||||
{{#include examples/c/tmq.c}}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
|
|
@ -45,6 +45,7 @@ CREATE DATABASE db_name PRECISION 'ns';
|
|||
|
||||
:::note
|
||||
|
||||
- 表的每行长度不能超过 48KB(注意:每个 BINARY/NCHAR 类型的列还会额外占用 2 个字节的存储位置)。
|
||||
- 虽然 BINARY 类型在底层存储上支持字节型的二进制字符,但不同编程语言对二进制数据的处理方式并不保证一致,因此建议在 BINARY 类型中只存储 ASCII 可见字符,而避免存储不可见字符。多字节的数据,例如中文字符,则需要使用 NCHAR 类型进行保存。如果强行使用 BINARY 类型保存中文字符,虽然有时也能正常读写,但并不带有字符集信息,很容易出现数据乱码甚至数据损坏等情况。
|
||||
- BINARY 类型理论上最长可以有 16,374 字节。BINARY 仅支持字符串输入,字符串两端需使用单引号引用。使用时须指定大小,如 BINARY(20) 定义了最长为 20 个单字节字符的字符串,每个字符占 1 字节的存储空间,总共固定占用 20 字节的空间,此时如果用户字符串超出 20 字节将会报错。对于字符串内的单引号,可以用转义字符反斜线加单引号来表示,即 `\'`。
|
||||
- SQL 语句中的数值类型将依据是否存在小数点,或使用科学计数法表示,来判断数值类型是否为整型或者浮点型,因此在使用时要注意相应类型越界的情况。例如,9999999999999999999 会认为超过长整型的上边界而溢出,而 9999999999999999999.0 会被认为是有效的浮点数。
|
||||
|
|
|
@ -16,7 +16,7 @@ description: "TDengine 服务端、客户端和连接器支持的平台列表"
|
|||
|
||||
## TDengine 客户端和连接器支持的平台列表
|
||||
|
||||
目前 TDengine 的连接器可支持的平台广泛,目前包括:X64/X86/ARM64/ARM32/MIPS/Alpha 等硬件平台,以及 Linux/Win64/Win32/macOS 等开发环境。
|
||||
目前 TDengine 的连接器可支持的平台广泛,目前包括:X64/X86/ARM64/ARM32/MIPS/LoongArch64 等硬件平台,以及 Linux/Win64/Win32/macOS 等开发环境。
|
||||
|
||||
对照矩阵如下:
|
||||
|
||||
|
|
|
@ -119,7 +119,7 @@ taos -h tdengine -P 6030
|
|||
FROM ubuntu:20.04
|
||||
RUN apt-get update && apt-get install -y wget
|
||||
ENV TDENGINE_VERSION=3.0.0.0
|
||||
RUN wget -c https://www.tdengine.com/assets-download/TDengine-client-${TDENGINE_VERSION}-Linux-x64.tar.gz \
|
||||
RUN wget -c https://www.tdengine.com/assets-download/3.0/TDengine-client-${TDENGINE_VERSION}-Linux-x64.tar.gz \
|
||||
&& tar xvf TDengine-client-${TDENGINE_VERSION}-Linux-x64.tar.gz \
|
||||
&& cd TDengine-client-${TDENGINE_VERSION} \
|
||||
&& ./install_client.sh \
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
---
|
||||
sidebar_label: TDengine 发布历史
|
||||
title: TDengine 发布历史
|
||||
title: TDengine 发布历史及下载链接
|
||||
description: TDengine 发布历史、Release Notes 及下载链接
|
||||
---
|
||||
|
||||
TDengine 3.x 各版本安装包下载链接如下:
|
||||
|
||||
TDengine 2.x 各版本安装包请访问[这里](https://www.taosdata.com/all-downloads)
|
||||
|
||||
import Release from "/components/ReleaseV3";
|
||||
|
||||
## 3.0.1.6
|
||||
|
@ -33,4 +37,3 @@ import Release from "/components/ReleaseV3";
|
|||
## 3.0.1.0
|
||||
|
||||
<Release type="tdengine" version="3.0.1.0" />
|
||||
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
---
|
||||
sidebar_label: taosTools 发布历史
|
||||
title: taosTools 发布历史
|
||||
title: taosTools 发布历史及下载链接
|
||||
description: taosTools 的发布历史、Release Notes 和下载链接
|
||||
---
|
||||
|
||||
taosTools 各版本安装包下载链接如下:
|
||||
|
||||
其他历史版本安装包请访问[这里](https://www.taosdata.com/all-downloads)
|
||||
|
||||
import Release from "/components/ReleaseV3";
|
||||
|
||||
## 2.2.7
|
||||
|
|
|
@ -418,13 +418,17 @@ static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWr
|
|||
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
|
||||
buf = taosDecodeVariantI32(buf, &pSW->nCols);
|
||||
buf = taosDecodeVariantI32(buf, &pSW->version);
|
||||
pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
|
||||
if (pSW->pSchema == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (pSW->nCols > 0) {
|
||||
pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
|
||||
if (pSW->pSchema == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pSW->nCols; i++) {
|
||||
buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
|
||||
for (int32_t i = 0; i < pSW->nCols; i++) {
|
||||
buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
|
||||
}
|
||||
} else {
|
||||
pSW->pSchema = NULL;
|
||||
}
|
||||
return (void*)buf;
|
||||
}
|
||||
|
@ -839,7 +843,7 @@ typedef struct {
|
|||
int64_t dbId;
|
||||
int32_t vgVersion;
|
||||
int32_t numOfTable; // unit is TSDB_TABLE_NUM_UNIT
|
||||
int64_t stateTs; // ms
|
||||
int64_t stateTs; // ms
|
||||
} SUseDbReq;
|
||||
|
||||
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
|
||||
|
@ -2990,7 +2994,8 @@ static FORCE_INLINE void* tDecodeSMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicE
|
|||
}
|
||||
|
||||
static FORCE_INLINE void tDeleteSMqSubTopicEp(SMqSubTopicEp* pSubTopicEp) {
|
||||
if (pSubTopicEp->schema.nCols) taosMemoryFreeClear(pSubTopicEp->schema.pSchema);
|
||||
taosMemoryFreeClear(pSubTopicEp->schema.pSchema);
|
||||
pSubTopicEp->schema.nCols = 0;
|
||||
taosArrayDestroy(pSubTopicEp->vgs);
|
||||
}
|
||||
|
||||
|
|
|
@ -250,8 +250,8 @@ enum {
|
|||
|
||||
TD_NEW_MSG_SEG(TDMT_SYNC_MSG)
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_TIMEOUT, "sync-timer", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_PING, "sync-ping", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_PING_REPLY, "sync-ping-reply", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_PING, "sync-ping", NULL, NULL) // no longer used
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_PING_REPLY, "sync-ping-reply", NULL, NULL) // no longer used
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_CLIENT_REQUEST, "sync-client-request", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_CLIENT_REQUEST_BATCH, "sync-client-request-batch", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_CLIENT_REQUEST_REPLY, "sync-client-request-reply", NULL, NULL)
|
||||
|
@ -274,8 +274,8 @@ enum {
|
|||
TD_DEF_MSG_TYPE(TDMT_SYNC_HEARTBEAT, "sync-heartbeat", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_HEARTBEAT_REPLY, "sync-heartbeat-reply", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_LOCAL_CMD, "sync-local-cmd", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_PRE_SNAPSHOT, "sync-pre-snapshot", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_PRE_SNAPSHOT_REPLY, "sync-pre-snapshot-reply", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_PRE_SNAPSHOT, "sync-pre-snapshot", NULL, NULL) // no longer used
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_PRE_SNAPSHOT_REPLY, "sync-pre-snapshot-reply", NULL, NULL) // no longer used
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_MAX_MSG, "sync-max", NULL, NULL)
|
||||
|
||||
TD_NEW_MSG_SEG(TDMT_VND_STREAM_MSG)
|
||||
|
|
|
@ -94,6 +94,8 @@ int32_t qWorkerProcessHbMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int64_
|
|||
|
||||
int32_t qWorkerProcessDeleteMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SDeleteRes *pRes);
|
||||
|
||||
void qWorkerStopAllTasks(void *qWorkerMgmt);
|
||||
|
||||
void qWorkerDestroy(void **qWorkerMgmt);
|
||||
|
||||
int32_t qWorkerGetStat(SReadHandle *handle, void *qWorkerMgmt, SQWorkerStat *pStat);
|
||||
|
|
|
@ -59,7 +59,6 @@ typedef int64_t SyncIndex;
|
|||
typedef uint64_t SyncTerm;
|
||||
|
||||
typedef struct SSyncNode SSyncNode;
|
||||
typedef struct SSyncBuffer SSyncBuffer;
|
||||
typedef struct SWal SWal;
|
||||
typedef struct SSyncRaftEntry SSyncRaftEntry;
|
||||
|
||||
|
|
|
@ -385,6 +385,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR TAOS_DEF_ERROR_CODE(0, 0x072D)
|
||||
#define TSDB_CODE_QRY_JSON_IN_GROUP_ERROR TAOS_DEF_ERROR_CODE(0, 0x072E)
|
||||
#define TSDB_CODE_QRY_JOB_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x072F)
|
||||
#define TSDB_CODE_QRY_QWORKER_QUIT TAOS_DEF_ERROR_CODE(0, 0x0730)
|
||||
|
||||
// grant
|
||||
#define TSDB_CODE_GRANT_EXPIRED TAOS_DEF_ERROR_CODE(0, 0x0800)
|
||||
|
|
|
@ -5,7 +5,7 @@ set -e
|
|||
#set -x
|
||||
|
||||
# dockerbuild.sh
|
||||
# -c [aarch32 | aarch64 | amd64 | x86 | mips64 ...]
|
||||
# -c [aarch32 | aarch64 | amd64 | x86 | mips64 | loongarch64...]
|
||||
# -n [version number]
|
||||
# -p [password for docker hub]
|
||||
# -V [stable | beta]
|
||||
|
@ -57,7 +57,7 @@ do
|
|||
dockerLatest=$(echo $OPTARG)
|
||||
;;
|
||||
h)
|
||||
echo "Usage: `basename $0` -c [aarch32 | aarch64 | amd64 | x86 | mips64 ...] "
|
||||
echo "Usage: `basename $0` -c [aarch32 | aarch64 | amd64 | x86 | mips64 | loongarch64...] "
|
||||
echo " -n [version number] "
|
||||
echo " -p [password for docker hub] "
|
||||
echo " -V [stable | beta] "
|
||||
|
@ -136,4 +136,4 @@ if [ "$cloudBuild" != "y" ] && [ ${dockerLatest} == 'y' ] ;then
|
|||
docker push tdengine/tdengine-${dockername}:latest
|
||||
fi
|
||||
|
||||
rm -f ${pkgFile}
|
||||
rm -f ${pkgFile}
|
||||
|
|
|
@ -5,7 +5,7 @@ set -e
|
|||
#set -x
|
||||
|
||||
# dockerbuild.sh
|
||||
# -c [aarch32 | aarch64 | amd64 | x86 | mips64 ...]
|
||||
# -c [aarch32 | aarch64 | amd64 | x86 | mips64 | loongarch64...]
|
||||
# -n [version number]
|
||||
# -p [password for docker hub]
|
||||
|
||||
|
@ -30,7 +30,7 @@ do
|
|||
passWord=$(echo $OPTARG)
|
||||
;;
|
||||
h)
|
||||
echo "Usage: `basename $0` -c [aarch32 | aarch64 | amd64 | x86 | mips64 ...] "
|
||||
echo "Usage: `basename $0` -c [aarch32 | aarch64 | amd64 | x86 | mips64 | loongarch64...] "
|
||||
echo " -n [version number] "
|
||||
echo " -p [password for docker hub] "
|
||||
exit 0
|
||||
|
|
|
@ -6,7 +6,7 @@ set -e
|
|||
#set -x
|
||||
|
||||
# release.sh -v [cluster | edge]
|
||||
# -c [aarch32 | aarch64 | x64 | x86 | mips64 ...]
|
||||
# -c [aarch32 | aarch64 | x64 | x86 | mips64 | loongarch64...]
|
||||
# -o [Linux | Kylin | Alpine | Raspberrypi | Darwin | Windows | Ningsi60 | Ningsi80 |...]
|
||||
# -V [stable | beta]
|
||||
# -l [full | lite]
|
||||
|
@ -19,7 +19,7 @@ set -e
|
|||
# set parameters by default value
|
||||
verMode=edge # [cluster, edge, cloud]
|
||||
verType=stable # [stable, beta]
|
||||
cpuType=x64 # [aarch32 | aarch64 | x64 | x86 | mips64 ...]
|
||||
cpuType=x64 # [aarch32 | aarch64 | x64 | x86 | mips64 loongarch64...]
|
||||
osType=Linux # [Linux | Kylin | Alpine | Raspberrypi | Darwin | Windows | Ningsi60 | Ningsi80 |...]
|
||||
pagMode=full # [full | lite]
|
||||
soMode=dynamic # [static | dynamic]
|
||||
|
@ -77,7 +77,7 @@ while getopts "hv:V:c:o:l:s:d:a:n:m:H:" arg; do
|
|||
;;
|
||||
h)
|
||||
echo "Usage: $(basename $0) -v [cluster | edge] "
|
||||
echo " -c [aarch32 | aarch64 | x64 | x86 | mips64 ...] "
|
||||
echo " -c [aarch32 | aarch64 | x64 | x86 | mips64 | loongarch64 ...] "
|
||||
echo " -o [Linux | Kylin | Alpine | Raspberrypi | Darwin | Windows | Ningsi60 | Ningsi80 |...] "
|
||||
echo " -V [stable | beta] "
|
||||
echo " -l [full | lite] "
|
||||
|
@ -216,7 +216,7 @@ else
|
|||
fi
|
||||
|
||||
# check support cpu type
|
||||
if [[ "$cpuType" == "x64" ]] || [[ "$cpuType" == "aarch64" ]] || [[ "$cpuType" == "aarch32" ]] || [[ "$cpuType" == "arm64" ]] || [[ "$cpuType" == "arm32" ]] || [[ "$cpuType" == "mips64" ]]; then
|
||||
if [[ "$cpuType" == "x64" ]] || [[ "$cpuType" == "aarch64" ]] || [[ "$cpuType" == "aarch32" ]] || [[ "$cpuType" == "arm64" ]] || [[ "$cpuType" == "arm32" ]] || [[ "$cpuType" == "mips64" ]] || [[ "$cpuType" == "loongarch64" ]] ; then
|
||||
if [ "$verMode" == "edge" ]; then
|
||||
# community-version compile
|
||||
cmake ../ -DCPUTYPE=${cpuType} -DWEBSOCKET=true -DOSTYPE=${osType} -DSOMODE=${soMode} -DDBNAME=${dbName} -DVERTYPE=${verType} -DVERDATE="${build_time}" -DGITINFO=${gitinfo} -DGITINFOI=${gitinfoOfInternal} -DVERNUMBER=${verNumber} -DVERCOMPATIBLE=${verNumberComp} -DPAGMODE=${pagMode} -DBUILD_HTTP=${BUILD_HTTP} -DBUILD_TOOLS=${BUILD_TOOLS} ${allocator_macro}
|
||||
|
|
|
@ -61,7 +61,8 @@ static int32_t hbProcessDBInfoRsp(void *value, int32_t valueLen, struct SCatalog
|
|||
int32_t numOfBatchs = taosArrayGetSize(batchUseRsp.pArray);
|
||||
for (int32_t i = 0; i < numOfBatchs; ++i) {
|
||||
SUseDbRsp *rsp = taosArrayGet(batchUseRsp.pArray, i);
|
||||
tscDebug("hb db rsp, db:%s, vgVersion:%d, stateTs:%" PRId64 ", uid:%" PRIx64, rsp->db, rsp->vgVersion, rsp->stateTs, rsp->uid);
|
||||
tscDebug("hb db rsp, db:%s, vgVersion:%d, stateTs:%" PRId64 ", uid:%" PRIx64, rsp->db, rsp->vgVersion, rsp->stateTs,
|
||||
rsp->uid);
|
||||
|
||||
if (rsp->vgVersion < 0) {
|
||||
code = catalogRemoveDB(pCatalog, rsp->db, rsp->uid);
|
||||
|
@ -293,6 +294,7 @@ static int32_t hbAsyncCallBack(void *param, SDataBuf *pMsg, int32_t code) {
|
|||
taosThreadMutexUnlock(&appInfo.mutex);
|
||||
tscError("cluster not exist, key:%s", key);
|
||||
taosMemoryFree(pMsg->pData);
|
||||
taosMemoryFree(pMsg->pEpSet);
|
||||
tFreeClientHbBatchRsp(&pRsp);
|
||||
return -1;
|
||||
}
|
||||
|
@ -322,6 +324,7 @@ static int32_t hbAsyncCallBack(void *param, SDataBuf *pMsg, int32_t code) {
|
|||
|
||||
tFreeClientHbBatchRsp(&pRsp);
|
||||
taosMemoryFree(pMsg->pData);
|
||||
taosMemoryFree(pMsg->pEpSet);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
|
|
@ -2082,7 +2082,7 @@ static int32_t smlParseJSONString(SSmlHandle *info, cJSON *root, SSmlTableInfo *
|
|||
|
||||
static int32_t smlParseInfluxLine(SSmlHandle *info, const char *sql, const int len) {
|
||||
SSmlLineInfo elements = {0};
|
||||
uDebug("SML:0x%" PRIx64 " smlParseInfluxLine sql:%s, hello", info->id, sql);
|
||||
uDebug("SML:0x%" PRIx64 " smlParseInfluxLine sql", info->id);
|
||||
|
||||
int ret = smlParseInfluxString(sql, sql + len, &elements, &info->msgBuf);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
|
|
|
@ -334,10 +334,12 @@ int32_t colDataAssign(SColumnInfoData* pColumnInfoData, const SColumnInfoData* p
|
|||
}
|
||||
|
||||
pColumnInfoData->varmeta.length = pSource->varmeta.length;
|
||||
memcpy(pColumnInfoData->pData, pSource->pData, pSource->varmeta.length);
|
||||
if (pColumnInfoData->pData != NULL && pSource->pData != NULL) {
|
||||
memcpy(pColumnInfoData->pData, pSource->pData, pSource->varmeta.length);
|
||||
}
|
||||
} else {
|
||||
memcpy(pColumnInfoData->nullbitmap, pSource->nullbitmap, BitmapLen(numOfRows));
|
||||
if (pSource->pData) {
|
||||
if (pSource->pData != NULL) {
|
||||
memcpy(pColumnInfoData->pData, pSource->pData, pSource->info.bytes * numOfRows);
|
||||
}
|
||||
}
|
||||
|
@ -2261,7 +2263,9 @@ int32_t blockEncode(const SSDataBlock* pBlock, char* data, int32_t numOfCols) {
|
|||
|
||||
colSizes[col] = colDataGetLength(pColRes, numOfRows);
|
||||
dataLen += colSizes[col];
|
||||
memmove(data, pColRes->pData, colSizes[col]);
|
||||
if (pColRes->pData != NULL) {
|
||||
memmove(data, pColRes->pData, colSizes[col]);
|
||||
}
|
||||
data += colSizes[col];
|
||||
|
||||
colSizes[col] = htonl(colSizes[col]);
|
||||
|
|
|
@ -183,8 +183,6 @@ SArray *mmGetMsgHandles() {
|
|||
if (dmSetMgmtHandle(pArray, TDMT_VND_COMPACT_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_TIMEOUT, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_PING, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_PING_REPLY, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_CLIENT_REQUEST, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_CLIENT_REQUEST_BATCH, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_CLIENT_REQUEST_REPLY, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
|
||||
|
@ -197,7 +195,6 @@ SArray *mmGetMsgHandles() {
|
|||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_RSP, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_PRE_SNAPSHOT, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_PRE_SNAPSHOT_REPLY, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
|
||||
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_HEARTBEAT, mmPutMsgToSyncCtrlQueue, 1) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_HEARTBEAT_REPLY, mmPutMsgToSyncCtrlQueue, 1) == NULL) goto _OVER;
|
||||
|
||||
|
|
|
@ -450,8 +450,6 @@ SArray *vmGetMsgHandles() {
|
|||
if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_VNODE, vmPutMsgToMgmtQueue, 0) == NULL) goto _OVER;
|
||||
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_TIMEOUT, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_PING, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_PING_REPLY, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_CLIENT_REQUEST, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_CLIENT_REQUEST_BATCH, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_CLIENT_REQUEST_REPLY, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
|
||||
|
|
|
@ -532,6 +532,7 @@ static int32_t mndCreateSma(SMnode *pMnode, SRpcMsg *pReq, SMCreateSmaReq *pCrea
|
|||
streamObj.sql = strdup(pCreate->sql);
|
||||
streamObj.smaId = smaObj.uid;
|
||||
streamObj.watermark = pCreate->watermark;
|
||||
streamObj.fillHistory = STREAM_FILL_HISTORY_ON;
|
||||
streamObj.trigger = STREAM_TRIGGER_WINDOW_CLOSE;
|
||||
streamObj.triggerParam = pCreate->maxDelay;
|
||||
streamObj.ast = strdup(smaObj.ast);
|
||||
|
|
|
@ -944,6 +944,8 @@ static int32_t mndRetrieveSubscribe(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock
|
|||
int32_t numOfRows = 0;
|
||||
SMqSubscribeObj *pSub = NULL;
|
||||
|
||||
mDebug("mnd show subscriptions begin");
|
||||
|
||||
while (numOfRows < rowsCapacity) {
|
||||
pShow->pIter = sdbFetch(pSdb, SDB_SUBSCRIBE, pShow->pIter, (void **)&pSub);
|
||||
if (pShow->pIter == NULL) break;
|
||||
|
@ -989,6 +991,9 @@ static int32_t mndRetrieveSubscribe(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock
|
|||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pConsumerEp->consumerId, false);
|
||||
|
||||
mDebug("mnd show subscrptions: topic %s, consumer %" PRId64 "cgroup %s vgid %d", varDataVal(topic),
|
||||
pConsumerEp->consumerId, varDataVal(cgroup), pVgEp->vgId);
|
||||
|
||||
// offset
|
||||
#if 0
|
||||
// subscribe time
|
||||
|
@ -1034,6 +1039,9 @@ static int32_t mndRetrieveSubscribe(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock
|
|||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, NULL, true);
|
||||
|
||||
mDebug("mnd show subscrptions(unassigned): topic %s, cgroup %s vgid %d", varDataVal(topic), varDataVal(cgroup),
|
||||
pVgEp->vgId);
|
||||
|
||||
// offset
|
||||
#if 0
|
||||
// subscribe time
|
||||
|
@ -1053,6 +1061,8 @@ static int32_t mndRetrieveSubscribe(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock
|
|||
sdbRelease(pSdb, pSub);
|
||||
}
|
||||
|
||||
mDebug("mnd end show subscriptions");
|
||||
|
||||
pShow->numOfRows += numOfRows;
|
||||
return numOfRows;
|
||||
}
|
||||
|
|
|
@ -637,6 +637,7 @@ static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) {
|
|||
if (pIter == NULL) break;
|
||||
|
||||
if (pConsumer->status == MQ_CONSUMER_STATUS__LOST_REBD) continue;
|
||||
|
||||
int32_t sz = taosArrayGetSize(pConsumer->assignedTopics);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
char *name = taosArrayGetP(pConsumer->assignedTopics, i);
|
||||
|
@ -649,6 +650,33 @@ static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) {
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
sz = taosArrayGetSize(pConsumer->rebNewTopics);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
char *name = taosArrayGetP(pConsumer->rebNewTopics, i);
|
||||
if (strcmp(name, pTopic->name) == 0) {
|
||||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
mndReleaseTopic(pMnode, pTopic);
|
||||
terrno = TSDB_CODE_MND_TOPIC_SUBSCRIBED;
|
||||
mError("topic:%s, failed to drop since subscribed by consumer:%" PRId64 ", in consumer group %s (reb new)",
|
||||
dropReq.name, pConsumer->consumerId, pConsumer->cgroup);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
sz = taosArrayGetSize(pConsumer->rebRemovedTopics);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
char *name = taosArrayGetP(pConsumer->rebRemovedTopics, i);
|
||||
if (strcmp(name, pTopic->name) == 0) {
|
||||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
mndReleaseTopic(pMnode, pTopic);
|
||||
terrno = TSDB_CODE_MND_TOPIC_SUBSCRIBED;
|
||||
mError("topic:%s, failed to drop since subscribed by consumer:%" PRId64 ", in consumer group %s (reb remove)",
|
||||
dropReq.name, pConsumer->consumerId, pConsumer->cgroup);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
sdbRelease(pSdb, pConsumer);
|
||||
}
|
||||
|
||||
|
@ -675,15 +703,6 @@ static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) {
|
|||
|
||||
mInfo("trans:%d, used to drop topic:%s", pTrans->id, pTopic->name);
|
||||
|
||||
#if 0
|
||||
if (mndDropOffsetByTopic(pMnode, pTrans, dropReq.name) < 0) {
|
||||
ASSERT(0);
|
||||
mndTransDrop(pTrans);
|
||||
mndReleaseTopic(pMnode, pTopic);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
// TODO check if rebalancing
|
||||
if (mndDropSubByTopic(pMnode, pTrans, dropReq.name) < 0) {
|
||||
/*ASSERT(0);*/
|
||||
|
|
|
@ -70,6 +70,7 @@ int32_t metaCacheDrop(SMeta* pMeta, int64_t uid);
|
|||
int32_t metaStatsCacheUpsert(SMeta* pMeta, SMetaStbStats* pInfo);
|
||||
int32_t metaStatsCacheDrop(SMeta* pMeta, int64_t uid);
|
||||
int32_t metaStatsCacheGet(SMeta* pMeta, int64_t uid, SMetaStbStats* pInfo);
|
||||
void metaUpdateStbStats(SMeta *pMeta, int64_t uid, int64_t delta);
|
||||
|
||||
struct SMeta {
|
||||
TdThreadRwlock lock;
|
||||
|
|
|
@ -61,14 +61,14 @@ struct SVBufPoolNode {
|
|||
};
|
||||
|
||||
struct SVBufPool {
|
||||
SVBufPool* next;
|
||||
SVnode* pVnode;
|
||||
volatile int32_t nRef;
|
||||
TdThreadSpinlock lock;
|
||||
int64_t size;
|
||||
uint8_t* ptr;
|
||||
SVBufPoolNode* pTail;
|
||||
SVBufPoolNode node;
|
||||
SVBufPool* next;
|
||||
SVnode* pVnode;
|
||||
TdThreadSpinlock* lock;
|
||||
volatile int32_t nRef;
|
||||
int64_t size;
|
||||
uint8_t* ptr;
|
||||
SVBufPoolNode* pTail;
|
||||
SVBufPoolNode node;
|
||||
};
|
||||
|
||||
int32_t vnodeOpenBufPool(SVnode* pVnode);
|
||||
|
@ -77,6 +77,7 @@ void vnodeBufPoolReset(SVBufPool* pPool);
|
|||
|
||||
// vnodeQuery.c
|
||||
int32_t vnodeQueryOpen(SVnode* pVnode);
|
||||
void vnodeQueryPreClose(SVnode *pVnode);
|
||||
void vnodeQueryClose(SVnode* pVnode);
|
||||
int32_t vnodeGetTableMeta(SVnode* pVnode, SRpcMsg* pMsg, bool direct);
|
||||
int vnodeGetTableCfg(SVnode* pVnode, SRpcMsg* pMsg, bool direct);
|
||||
|
|
|
@ -1445,3 +1445,13 @@ int32_t metaGetStbStats(SMeta *pMeta, int64_t uid, SMetaStbStats *pInfo) {
|
|||
_exit:
|
||||
return code;
|
||||
}
|
||||
|
||||
void metaUpdateStbStats(SMeta *pMeta, int64_t uid, int64_t delta) {
|
||||
SMetaStbStats stats = {0};
|
||||
|
||||
if (metaStatsCacheGet(pMeta, uid, &stats) == TSDB_CODE_SUCCESS) {
|
||||
stats.ctbNum += delta;
|
||||
|
||||
metaStatsCacheUpsert(pMeta, &stats);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -371,7 +371,7 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
|||
// update uid index
|
||||
metaUpdateUidIdx(pMeta, &nStbEntry);
|
||||
|
||||
metaStatsCacheDrop(pMeta, nStbEntry.uid);
|
||||
// metaStatsCacheDrop(pMeta, nStbEntry.uid);
|
||||
|
||||
metaULock(pMeta);
|
||||
|
||||
|
@ -450,6 +450,10 @@ int metaCreateTable(SMeta *pMeta, int64_t version, SVCreateTbReq *pReq, STableMe
|
|||
#endif
|
||||
|
||||
++pMeta->pVnode->config.vndStats.numOfCTables;
|
||||
|
||||
metaWLock(pMeta);
|
||||
metaUpdateStbStats(pMeta, me.ctbEntry.suid, 1);
|
||||
metaULock(pMeta);
|
||||
} else {
|
||||
me.ntbEntry.ctime = pReq->ctime;
|
||||
me.ntbEntry.ttlDays = pReq->ttl;
|
||||
|
@ -670,6 +674,8 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) {
|
|||
tdbTbDelete(pMeta->pCtbIdx, &(SCtbIdxKey){.suid = e.ctbEntry.suid, .uid = uid}, sizeof(SCtbIdxKey), &pMeta->txn);
|
||||
|
||||
--pMeta->pVnode->config.vndStats.numOfCTables;
|
||||
|
||||
metaUpdateStbStats(pMeta, e.ctbEntry.suid, -1);
|
||||
} else if (e.type == TSDB_NORMAL_TABLE) {
|
||||
// drop schema.db (todo)
|
||||
|
||||
|
|
|
@ -582,10 +582,10 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) {
|
|||
code = -1;
|
||||
}
|
||||
|
||||
tqDebug("tmq poll: consumer %" PRId64 ", subkey %s, vg %d, send data blockNum:%d, offset type:%d, uid:%" PRId64
|
||||
", version:%" PRId64 "",
|
||||
tqDebug("tmq poll: consumer %" PRId64
|
||||
", subkey %s, vg %d, send data blockNum:%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.version);
|
||||
dataRsp.rspOffset.uid, dataRsp.rspOffset.ts);
|
||||
|
||||
tDeleteSMqDataRsp(&dataRsp);
|
||||
return code;
|
||||
|
|
|
@ -244,7 +244,7 @@ SSubmitReq* tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchem
|
|||
|
||||
int32_t rows = pDataBlock->info.rows;
|
||||
|
||||
tqDebug("tq sink, convert block %d, rows: %d", i, rows);
|
||||
tqDebug("tq sink, convert block1 %d, rows: %d", i, rows);
|
||||
|
||||
int32_t dataLen = 0;
|
||||
int32_t schemaLen = 0;
|
||||
|
@ -486,7 +486,7 @@ void tqSinkToTablePipeline(SStreamTask* pTask, void* vnode, int64_t ver, void* d
|
|||
blkHead->uid = 0;
|
||||
blkHead->schemaLen = 0;
|
||||
|
||||
tqDebug("tq sink, convert block %d, rows: %d", i, rows);
|
||||
tqDebug("tq sink, convert block2 %d, rows: %d", i, rows);
|
||||
|
||||
int32_t dataLen = 0;
|
||||
void* blkSchema = POINTER_SHIFT(blkHead, sizeof(SSubmitBlk));
|
||||
|
@ -514,6 +514,9 @@ void tqSinkToTablePipeline(SStreamTask* pTask, void* vnode, int64_t ver, void* d
|
|||
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NULL, NULL, false, pColumn->offset, k);
|
||||
} else {
|
||||
void* colData = colDataGetData(pColData, j);
|
||||
if (k == 0) {
|
||||
tqDebug("tq sink, row %d ts %" PRId64, j, *(int64_t*)colData);
|
||||
}
|
||||
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NORM, colData, true, pColumn->offset, k);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -458,11 +458,10 @@ static void tbDataMovePosTo(STbData *pTbData, SMemSkipListNode **pos, TSDBKEY *p
|
|||
}
|
||||
|
||||
static FORCE_INLINE int8_t tsdbMemSkipListRandLevel(SMemSkipList *pSl) {
|
||||
int8_t level = 1;
|
||||
int8_t tlevel = TMIN(pSl->maxLevel, pSl->level + 1);
|
||||
const uint32_t factor = 4;
|
||||
int8_t level = 1;
|
||||
int8_t tlevel = TMIN(pSl->maxLevel, pSl->level + 1);
|
||||
|
||||
while ((taosRandR(&pSl->seed) % factor) == 0 && level < tlevel) {
|
||||
while ((taosRandR(&pSl->seed) & 0x3) == 0 && level < tlevel) {
|
||||
level++;
|
||||
}
|
||||
|
||||
|
@ -568,7 +567,9 @@ static int32_t tsdbInsertTableDataImpl(SMemTable *pMemTable, STbData *pTbData, i
|
|||
do {
|
||||
key.ts = row.pTSRow->ts;
|
||||
nRow++;
|
||||
tbDataMovePosTo(pTbData, pos, &key, SL_MOVE_FROM_POS);
|
||||
if (SL_NODE_FORWARD(pos[0], 0) != pTbData->sl.pTail) {
|
||||
tbDataMovePosTo(pTbData, pos, &key, SL_MOVE_FROM_POS);
|
||||
}
|
||||
code = tbDataDoPut(pMemTable, pTbData, pos, &row, 1);
|
||||
if (code) {
|
||||
goto _err;
|
||||
|
|
|
@ -1015,6 +1015,191 @@ _err:
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t tBlockDataAppendBlockRow(SBlockData *pBlockData, SBlockData *pBlockDataFrom, int32_t iRow) {
|
||||
int32_t code = 0;
|
||||
|
||||
SColVal cv = {0};
|
||||
int32_t iColDataFrom = 0;
|
||||
SColData *pColDataFrom =
|
||||
(iColDataFrom < pBlockDataFrom->nColData) ? &((SColData *)pBlockDataFrom->aColData->pData)[iColDataFrom] : NULL;
|
||||
|
||||
for (int32_t iColDataTo = 0; iColDataTo < pBlockData->nColData; iColDataTo++) {
|
||||
SColData *pColDataTo = &((SColData *)pBlockData->aColData->pData)[iColDataTo];
|
||||
|
||||
while (pColDataFrom && pColDataFrom->cid < pColDataTo->cid) {
|
||||
iColDataFrom++;
|
||||
pColDataFrom = (iColDataFrom < pBlockDataFrom->nColData)
|
||||
? &((SColData *)pBlockDataFrom->aColData->pData)[iColDataFrom]
|
||||
: NULL;
|
||||
}
|
||||
|
||||
if (pColDataFrom == NULL || pColDataFrom->cid > pColDataTo->cid) {
|
||||
code = tColDataAppendValue(pColDataTo, &COL_VAL_NONE(pColDataTo->cid, pColDataTo->type));
|
||||
if (code) goto _exit;
|
||||
} else {
|
||||
tColDataGetValue(pColDataFrom, iRow, &cv);
|
||||
|
||||
code = tColDataAppendValue(pColDataTo, &cv);
|
||||
if (code) goto _exit;
|
||||
|
||||
iColDataFrom++;
|
||||
pColDataFrom = (iColDataFrom < pBlockDataFrom->nColData)
|
||||
? &((SColData *)pBlockDataFrom->aColData->pData)[iColDataFrom]
|
||||
: NULL;
|
||||
}
|
||||
}
|
||||
|
||||
_exit:
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t tBlockDataAppendTPRow(SBlockData *pBlockData, STSRow *pRow, STSchema *pTSchema) {
|
||||
int32_t code = 0;
|
||||
|
||||
int32_t iTColumn = 1;
|
||||
STColumn *pTColumn = (iTColumn < pTSchema->numOfCols) ? &pTSchema->columns[iTColumn] : NULL;
|
||||
void *pBitmap = pRow->statis ? tdGetBitmapAddrTp(pRow, pTSchema->flen) : NULL;
|
||||
|
||||
for (int32_t iColData = 0; iColData < pBlockData->nColData; iColData++) {
|
||||
SColData *pColData = &((SColData *)pBlockData->aColData->pData)[iColData];
|
||||
|
||||
while (pTColumn && pTColumn->colId < pColData->cid) {
|
||||
iTColumn++;
|
||||
pTColumn = (iTColumn < pTSchema->numOfCols) ? &pTSchema->columns[iTColumn] : NULL;
|
||||
}
|
||||
|
||||
if (pTColumn == NULL || pTColumn->colId > pColData->cid) {
|
||||
code = tColDataAppendValue(pColData, &COL_VAL_NONE(pColData->cid, pColData->type));
|
||||
if (code) goto _exit;
|
||||
} else {
|
||||
ASSERT(pTColumn->type == pColData->type);
|
||||
|
||||
SColVal cv = {.cid = pTColumn->colId, .type = pTColumn->type};
|
||||
|
||||
if (pRow->statis) {
|
||||
TDRowValT vt = TD_VTYPE_MAX;
|
||||
tdGetBitmapValTypeII(pBitmap, iTColumn - 1, &vt);
|
||||
|
||||
if (vt == TD_VTYPE_NORM) {
|
||||
cv.flag = CV_FLAG_VALUE;
|
||||
|
||||
if (IS_VAR_DATA_TYPE(pTColumn->type)) {
|
||||
void *pData = (char*)pRow + *(int32_t *)(pRow->data + pTColumn->offset - sizeof(TSKEY));
|
||||
cv.value.nData = varDataLen(pData);
|
||||
cv.value.pData = varDataVal(pData);
|
||||
} else {
|
||||
memcpy(&cv.value.val, pRow->data + pTColumn->offset - sizeof(TSKEY), pTColumn->bytes);
|
||||
}
|
||||
|
||||
code = tColDataAppendValue(pColData, &cv);
|
||||
if (code) goto _exit;
|
||||
} else if (vt == TD_VTYPE_NONE) {
|
||||
code = tColDataAppendValue(pColData, &COL_VAL_NONE(pColData->cid, pColData->type));
|
||||
if (code) goto _exit;
|
||||
} else if (vt == TD_VTYPE_NULL) {
|
||||
code = tColDataAppendValue(pColData, &COL_VAL_NULL(pColData->cid, pColData->type));
|
||||
if (code) goto _exit;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
} else {
|
||||
cv.flag = CV_FLAG_VALUE;
|
||||
|
||||
if (IS_VAR_DATA_TYPE(pTColumn->type)) {
|
||||
void *pData = (char*)pRow + *(int32_t *)(pRow->data + pTColumn->offset - sizeof(TSKEY));
|
||||
cv.value.nData = varDataLen(pData);
|
||||
cv.value.pData = varDataVal(pData);
|
||||
} else {
|
||||
memcpy(&cv.value.val, pRow->data + pTColumn->offset - sizeof(TSKEY), pTColumn->bytes);
|
||||
}
|
||||
|
||||
code = tColDataAppendValue(pColData, &cv);
|
||||
if (code) goto _exit;
|
||||
}
|
||||
|
||||
iTColumn++;
|
||||
pTColumn = (iTColumn < pTSchema->numOfCols) ? &pTSchema->columns[iTColumn] : NULL;
|
||||
}
|
||||
}
|
||||
|
||||
_exit:
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t tBlockDataAppendKVRow(SBlockData *pBlockData, STSRow *pRow, STSchema *pTSchema) {
|
||||
int32_t code = 0;
|
||||
|
||||
col_id_t kvIter = 0;
|
||||
col_id_t nKvCols = tdRowGetNCols(pRow) - 1;
|
||||
void *pColIdx = TD_ROW_COL_IDX(pRow);
|
||||
void *pBitmap = tdGetBitmapAddrKv(pRow, tdRowGetNCols(pRow));
|
||||
int32_t iTColumn = 1;
|
||||
STColumn *pTColumn = (iTColumn < pTSchema->numOfCols) ? &pTSchema->columns[iTColumn] : NULL;
|
||||
|
||||
for (int32_t iColData = 0; iColData < pBlockData->nColData; iColData++) {
|
||||
SColData *pColData = &((SColData *)pBlockData->aColData->pData)[iColData];
|
||||
|
||||
while (pTColumn && pTColumn->colId < pColData->cid) {
|
||||
iTColumn++;
|
||||
pTColumn = (iTColumn < pTSchema->numOfCols) ? &pTSchema->columns[iTColumn] : NULL;
|
||||
}
|
||||
|
||||
if (pTColumn == NULL || pTColumn->colId > pColData->cid) {
|
||||
code = tColDataAppendValue(pColData, &COL_VAL_NONE(pColData->cid, pColData->type));
|
||||
if (code) goto _exit;
|
||||
} else {
|
||||
ASSERT(pTColumn->type == pColData->type);
|
||||
|
||||
SColVal cv = {.cid = pTColumn->colId, .type = pTColumn->type};
|
||||
TDRowValT vt = TD_VTYPE_NONE; // default is NONE
|
||||
SKvRowIdx *pKvIdx = NULL;
|
||||
|
||||
while (kvIter < nKvCols) {
|
||||
pKvIdx = (SKvRowIdx *)POINTER_SHIFT(pColIdx, kvIter * sizeof(SKvRowIdx));
|
||||
if (pKvIdx->colId == pTColumn->colId) {
|
||||
tdGetBitmapValTypeII(pBitmap, kvIter, &vt);
|
||||
++kvIter;
|
||||
break;
|
||||
} else if (pKvIdx->colId > pTColumn->colId) {
|
||||
vt = TD_VTYPE_NONE;
|
||||
break;
|
||||
} else {
|
||||
++kvIter;
|
||||
}
|
||||
}
|
||||
|
||||
if (vt == TD_VTYPE_NORM) {
|
||||
cv.flag = CV_FLAG_VALUE;
|
||||
|
||||
void *pData = POINTER_SHIFT(pRow, pKvIdx->offset);
|
||||
if (IS_VAR_DATA_TYPE(pTColumn->type)) {
|
||||
cv.value.nData = varDataLen(pData);
|
||||
cv.value.pData = varDataVal(pData);
|
||||
} else {
|
||||
memcpy(&cv.value.val, pData, pTColumn->bytes);
|
||||
}
|
||||
|
||||
code = tColDataAppendValue(pColData, &cv);
|
||||
if (code) goto _exit;
|
||||
} else if (vt == TD_VTYPE_NONE) {
|
||||
code = tColDataAppendValue(pColData, &COL_VAL_NONE(pColData->cid, pColData->type));
|
||||
if (code) goto _exit;
|
||||
} else if (vt == TD_VTYPE_NULL) {
|
||||
code = tColDataAppendValue(pColData, &COL_VAL_NULL(pColData->cid, pColData->type));
|
||||
if (code) goto _exit;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
iTColumn++;
|
||||
pTColumn = (iTColumn < pTSchema->numOfCols) ? &pTSchema->columns[iTColumn] : NULL;
|
||||
}
|
||||
}
|
||||
|
||||
_exit:
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tBlockDataAppendRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTSchema, int64_t uid) {
|
||||
int32_t code = 0;
|
||||
|
||||
|
@ -1036,27 +1221,20 @@ int32_t tBlockDataAppendRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTS
|
|||
if (code) goto _err;
|
||||
pBlockData->aTSKEY[pBlockData->nRow] = TSDBROW_TS(pRow);
|
||||
|
||||
// OTHER
|
||||
SRowIter rIter = {0};
|
||||
SColVal *pColVal;
|
||||
|
||||
tRowIterInit(&rIter, pRow, pTSchema);
|
||||
pColVal = tRowIterNext(&rIter);
|
||||
for (int32_t iColData = 0; iColData < pBlockData->nColData; iColData++) {
|
||||
SColData *pColData = &((SColData *)pBlockData->aColData->pData)[iColData];
|
||||
|
||||
while (pColVal && pColVal->cid < pColData->cid) {
|
||||
pColVal = tRowIterNext(&rIter);
|
||||
}
|
||||
|
||||
if (pColVal == NULL || pColVal->cid > pColData->cid) {
|
||||
code = tColDataAppendValue(pColData, &COL_VAL_NONE(pColData->cid, pColData->type));
|
||||
SColVal cv = {0};
|
||||
if (pRow->type == 0) {
|
||||
if (TD_IS_TP_ROW(pRow->pTSRow)) {
|
||||
code = tBlockDataAppendTPRow(pBlockData, pRow->pTSRow, pTSchema);
|
||||
if (code) goto _err;
|
||||
} else if (TD_IS_KV_ROW(pRow->pTSRow)) {
|
||||
code = tBlockDataAppendKVRow(pBlockData, pRow->pTSRow, pTSchema);
|
||||
if (code) goto _err;
|
||||
} else {
|
||||
code = tColDataAppendValue(pColData, pColVal);
|
||||
if (code) goto _err;
|
||||
pColVal = tRowIterNext(&rIter);
|
||||
ASSERT(0);
|
||||
}
|
||||
} else {
|
||||
code = tBlockDataAppendBlockRow(pBlockData, pRow->pBlockData, pRow->iRow);
|
||||
if (code) goto _err;
|
||||
}
|
||||
pBlockData->nRow++;
|
||||
|
||||
|
|
|
@ -27,10 +27,21 @@ static int vnodeBufPoolCreate(SVnode *pVnode, int64_t size, SVBufPool **ppPool)
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (taosThreadSpinInit(&pPool->lock, 0) != 0) {
|
||||
taosMemoryFree(pPool);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
if (VND_IS_RSMA(pVnode)) {
|
||||
pPool->lock = taosMemoryMalloc(sizeof(TdThreadSpinlock));
|
||||
if (!pPool->lock) {
|
||||
taosMemoryFree(pPool);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
if (taosThreadSpinInit(pPool->lock, 0) != 0) {
|
||||
taosMemoryFree((void*)pPool->lock);
|
||||
taosMemoryFree(pPool);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
pPool->lock = NULL;
|
||||
}
|
||||
|
||||
pPool->next = NULL;
|
||||
|
@ -49,7 +60,10 @@ static int vnodeBufPoolCreate(SVnode *pVnode, int64_t size, SVBufPool **ppPool)
|
|||
|
||||
static int vnodeBufPoolDestroy(SVBufPool *pPool) {
|
||||
vnodeBufPoolReset(pPool);
|
||||
taosThreadSpinDestroy(&pPool->lock);
|
||||
if (pPool->lock) {
|
||||
taosThreadSpinDestroy(pPool->lock);
|
||||
taosMemoryFree((void*)pPool->lock);
|
||||
}
|
||||
taosMemoryFree(pPool);
|
||||
return 0;
|
||||
}
|
||||
|
@ -114,7 +128,7 @@ void *vnodeBufPoolMalloc(SVBufPool *pPool, int size) {
|
|||
void *p = NULL;
|
||||
ASSERT(pPool != NULL);
|
||||
|
||||
taosThreadSpinLock(&pPool->lock);
|
||||
if (pPool->lock) taosThreadSpinLock(pPool->lock);
|
||||
if (pPool->node.size >= pPool->ptr - pPool->node.data + size) {
|
||||
// allocate from the anchor node
|
||||
p = pPool->ptr;
|
||||
|
@ -125,7 +139,7 @@ void *vnodeBufPoolMalloc(SVBufPool *pPool, int size) {
|
|||
pNode = taosMemoryMalloc(sizeof(*pNode) + size);
|
||||
if (pNode == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
taosThreadSpinUnlock(&pPool->lock);
|
||||
if (pPool->lock) taosThreadSpinUnlock(pPool->lock);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -138,7 +152,7 @@ void *vnodeBufPoolMalloc(SVBufPool *pPool, int size) {
|
|||
|
||||
pPool->size = pPool->size + sizeof(*pNode) + size;
|
||||
}
|
||||
taosThreadSpinUnlock(&pPool->lock);
|
||||
if (pPool->lock) taosThreadSpinUnlock(pPool->lock);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
|
|
@ -242,7 +242,10 @@ _err:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void vnodePreClose(SVnode *pVnode) { vnodeSyncPreClose(pVnode); }
|
||||
void vnodePreClose(SVnode *pVnode) {
|
||||
vnodeQueryPreClose(pVnode);
|
||||
vnodeSyncPreClose(pVnode);
|
||||
}
|
||||
|
||||
void vnodeClose(SVnode *pVnode) {
|
||||
if (pVnode) {
|
||||
|
|
|
@ -28,6 +28,8 @@ int vnodeQueryOpen(SVnode *pVnode) {
|
|||
return qWorkerInit(NODE_TYPE_VNODE, TD_VID(pVnode), (void **)&pVnode->pQuery, &pVnode->msgCb);
|
||||
}
|
||||
|
||||
void vnodeQueryPreClose(SVnode *pVnode) { qWorkerStopAllTasks((void *)pVnode->pQuery); }
|
||||
|
||||
void vnodeQueryClose(SVnode *pVnode) { qWorkerDestroy((void **)&pVnode->pQuery); }
|
||||
|
||||
int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, bool direct) {
|
||||
|
|
|
@ -1204,11 +1204,12 @@ int32_t ctgHandleGetTbMetasRsp(SCtgTaskReq* tReq, int32_t reqType, const SDataBu
|
|||
stbCtx.flag = flag;
|
||||
stbCtx.pName = &stbName;
|
||||
|
||||
STableMeta *stbMeta = NULL;
|
||||
STableMeta* stbMeta = NULL;
|
||||
ctgReadTbMetaFromCache(pCtg, &stbCtx, &stbMeta);
|
||||
if (stbMeta && stbMeta->sversion >= pOut->tbMeta->sversion) {
|
||||
ctgDebug("use cached stb meta, tbName:%s", tNameGetTableName(pName));
|
||||
exist = 1;
|
||||
taosMemoryFreeClear(stbMeta);
|
||||
} else {
|
||||
ctgDebug("need to get/update stb meta, tbName:%s", tNameGetTableName(pName));
|
||||
taosMemoryFreeClear(pOut->tbMeta);
|
||||
|
|
|
@ -72,8 +72,8 @@ void ctgRUnlockVgInfo(SCtgDBCache *dbCache) { CTG_UNLOCK(CTG_READ, &dbCache->vgC
|
|||
|
||||
void ctgWUnlockVgInfo(SCtgDBCache *dbCache) { CTG_UNLOCK(CTG_WRITE, &dbCache->vgCache.vgLock); }
|
||||
|
||||
void ctgReleaseDBCache(SCatalog *pCtg, SCtgDBCache *dbCache) {
|
||||
CTG_UNLOCK(CTG_READ, &dbCache->dbLock);
|
||||
void ctgReleaseDBCache(SCatalog *pCtg, SCtgDBCache *dbCache) {
|
||||
CTG_UNLOCK(CTG_READ, &dbCache->dbLock);
|
||||
taosHashRelease(pCtg->dbCache, dbCache);
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ int32_t ctgAcquireDBCacheImpl(SCatalog *pCtg, const char *dbFName, SCtgDBCache *
|
|||
} else {
|
||||
dbCache = (SCtgDBCache *)taosHashGet(pCtg->dbCache, dbFName, strlen(dbFName));
|
||||
}
|
||||
|
||||
|
||||
if (NULL == dbCache) {
|
||||
*pCache = NULL;
|
||||
ctgDebug("db not in cache, dbFName:%s", dbFName);
|
||||
|
@ -422,6 +422,7 @@ _return:
|
|||
|
||||
ctgReleaseTbMetaToCache(pCtg, dbCache, tbCache);
|
||||
taosMemoryFreeClear(*pTableMeta);
|
||||
*pTableMeta = NULL;
|
||||
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
@ -1436,7 +1437,7 @@ int32_t ctgWriteTbMetaToCache(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFNam
|
|||
if (pCache) {
|
||||
CTG_ERR_RET(ctgUpdateRentStbVersion(pCtg, dbFName, tbName, dbId, meta->suid, pCache));
|
||||
}
|
||||
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1565,7 +1566,8 @@ int32_t ctgOpUpdateVgroup(SCtgCacheOperation *operation) {
|
|||
}
|
||||
|
||||
bool newAdded = false;
|
||||
SDbVgVersion vgVersion = {.dbId = msg->dbId, .vgVersion = dbInfo->vgVersion, .numOfTable = dbInfo->numOfTable, .stateTs = dbInfo->stateTs};
|
||||
SDbVgVersion vgVersion = {
|
||||
.dbId = msg->dbId, .vgVersion = dbInfo->vgVersion, .numOfTable = dbInfo->numOfTable, .stateTs = dbInfo->stateTs};
|
||||
|
||||
SCtgDBCache *dbCache = NULL;
|
||||
CTG_ERR_JRET(ctgGetAddDBCache(msg->pCtg, dbFName, msg->dbId, &dbCache));
|
||||
|
@ -1581,15 +1583,17 @@ int32_t ctgOpUpdateVgroup(SCtgCacheOperation *operation) {
|
|||
SDBVgInfo *vgInfo = vgCache->vgInfo;
|
||||
|
||||
if (dbInfo->vgVersion < vgInfo->vgVersion) {
|
||||
ctgDebug("db updateVgroup is ignored, dbFName:%s, vgVer:%d, curVer:%d", dbFName, dbInfo->vgVersion, vgInfo->vgVersion);
|
||||
ctgDebug("db updateVgroup is ignored, dbFName:%s, vgVer:%d, curVer:%d", dbFName, dbInfo->vgVersion,
|
||||
vgInfo->vgVersion);
|
||||
ctgWUnlockVgInfo(dbCache);
|
||||
|
||||
goto _return;
|
||||
}
|
||||
|
||||
if (dbInfo->vgVersion == vgInfo->vgVersion && dbInfo->numOfTable == vgInfo->numOfTable && dbInfo->stateTs == vgInfo->stateTs) {
|
||||
ctgDebug("no new db vgroup update info, dbFName:%s, vgVer:%d, numOfTable:%d, stateTs:%" PRId64, dbFName, dbInfo->vgVersion,
|
||||
dbInfo->numOfTable, dbInfo->stateTs);
|
||||
if (dbInfo->vgVersion == vgInfo->vgVersion && dbInfo->numOfTable == vgInfo->numOfTable &&
|
||||
dbInfo->stateTs == vgInfo->stateTs) {
|
||||
ctgDebug("no new db vgroup update info, dbFName:%s, vgVer:%d, numOfTable:%d, stateTs:%" PRId64, dbFName,
|
||||
dbInfo->vgVersion, dbInfo->numOfTable, dbInfo->stateTs);
|
||||
ctgWUnlockVgInfo(dbCache);
|
||||
|
||||
goto _return;
|
||||
|
@ -1601,7 +1605,8 @@ int32_t ctgOpUpdateVgroup(SCtgCacheOperation *operation) {
|
|||
vgCache->vgInfo = dbInfo;
|
||||
msg->dbInfo = NULL;
|
||||
|
||||
ctgDebug("db vgInfo updated, dbFName:%s, vgVer:%d, stateTs:%" PRId64 ", dbId:0x%" PRIx64, dbFName, vgVersion.vgVersion, vgVersion.stateTs, vgVersion.dbId);
|
||||
ctgDebug("db vgInfo updated, dbFName:%s, vgVer:%d, stateTs:%" PRId64 ", dbId:0x%" PRIx64, dbFName,
|
||||
vgVersion.vgVersion, vgVersion.stateTs, vgVersion.dbId);
|
||||
|
||||
ctgWUnlockVgInfo(dbCache);
|
||||
|
||||
|
@ -1692,7 +1697,7 @@ int32_t ctgOpUpdateTbMeta(SCtgCacheOperation *operation) {
|
|||
if (pCtg->stopUpdate) {
|
||||
goto _return;
|
||||
}
|
||||
|
||||
|
||||
if ((!CTG_IS_META_CTABLE(pMeta->metaType)) && NULL == pMeta->tbMeta) {
|
||||
ctgError("no valid tbmeta got from meta rsp, dbFName:%s, tbName:%s", pMeta->dbFName, pMeta->tbName);
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||
|
@ -1902,7 +1907,7 @@ int32_t ctgOpUpdateEpset(SCtgCacheOperation *operation) {
|
|||
int32_t code = 0;
|
||||
SCtgUpdateEpsetMsg *msg = operation->data;
|
||||
SCatalog *pCtg = msg->pCtg;
|
||||
SCtgDBCache *dbCache = NULL;
|
||||
SCtgDBCache *dbCache = NULL;
|
||||
|
||||
if (pCtg->stopUpdate) {
|
||||
goto _return;
|
||||
|
@ -2209,6 +2214,7 @@ int32_t ctgGetTbMetaFromCache(SCatalog *pCtg, SCtgTbMetaCtx *ctx, STableMeta **p
|
|||
}
|
||||
|
||||
taosMemoryFreeClear(*pTableMeta);
|
||||
*pTableMeta = NULL;
|
||||
}
|
||||
|
||||
if (CTG_FLAG_IS_UNKNOWN_STB(ctx->flag)) {
|
||||
|
|
|
@ -153,6 +153,16 @@ typedef struct {
|
|||
SSchemaWrapper* qsw;
|
||||
} SSchemaInfo;
|
||||
|
||||
typedef struct {
|
||||
int32_t operatorType;
|
||||
int64_t refId;
|
||||
} SExchangeOpStopInfo;
|
||||
|
||||
typedef struct {
|
||||
SRWLatch lock;
|
||||
SArray* pStopInfo;
|
||||
} STaskStopInfo;
|
||||
|
||||
typedef struct SExecTaskInfo {
|
||||
STaskIdInfo id;
|
||||
uint32_t status;
|
||||
|
@ -171,6 +181,7 @@ typedef struct SExecTaskInfo {
|
|||
SSubplan* pSubplan;
|
||||
struct SOperatorInfo* pRoot;
|
||||
SLocalFetch localFetch;
|
||||
STaskStopInfo stopInfo;
|
||||
} SExecTaskInfo;
|
||||
|
||||
enum {
|
||||
|
@ -981,6 +992,7 @@ void setTaskKilled(SExecTaskInfo* pTaskInfo);
|
|||
void queryCostStatis(SExecTaskInfo* pTaskInfo);
|
||||
|
||||
void doDestroyTask(SExecTaskInfo* pTaskInfo);
|
||||
void destroyOperatorInfo(SOperatorInfo* pOperator);
|
||||
int32_t getMaximumIdleDurationSec();
|
||||
|
||||
/*
|
||||
|
@ -1049,6 +1061,7 @@ int32_t setOutputBuf(SStreamState* pState, STimeWindow* win, SResultRow** pResul
|
|||
int32_t releaseOutputBuf(SStreamState* pState, SWinKey* pKey, SResultRow* pResult);
|
||||
int32_t saveOutputBuf(SStreamState* pState, SWinKey* pKey, SResultRow* pResult, int32_t resSize);
|
||||
void getNextIntervalWindow(SInterval* pInterval, STimeWindow* tw, int32_t order);
|
||||
int32_t qAppendTaskStopInfo(SExecTaskInfo* pTaskInfo, SExchangeOpStopInfo *pInfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -65,6 +65,9 @@ static void concurrentlyLoadRemoteDataImpl(SOperatorInfo* pOperator, SExchangeIn
|
|||
|
||||
while (1) {
|
||||
tsem_wait(&pExchangeInfo->ready);
|
||||
if (isTaskKilled(pTaskInfo)) {
|
||||
longjmp(pTaskInfo->env, TSDB_CODE_TSC_QUERY_CANCELLED);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < totalSources; ++i) {
|
||||
SSourceDataInfo* pDataInfo = taosArrayGet(pExchangeInfo->pSourceDataInfo, i);
|
||||
|
@ -286,6 +289,9 @@ SOperatorInfo* createExchangeOperatorInfo(void* pTransporter, SExchangePhysiNode
|
|||
pInfo->pDummyBlock = createResDataBlock(pExNode->node.pOutputDataBlockDesc);
|
||||
pInfo->pResultBlockList = taosArrayInit(1, POINTER_BYTES);
|
||||
|
||||
SExchangeOpStopInfo stopInfo = {QUERY_NODE_PHYSICAL_PLAN_EXCHANGE, pInfo->self};
|
||||
qAppendTaskStopInfo(pTaskInfo, &stopInfo);
|
||||
|
||||
pInfo->seqLoadData = false;
|
||||
pInfo->pTransporter = pTransporter;
|
||||
|
||||
|
@ -543,6 +549,10 @@ int32_t prepareConcurrentlyLoad(SOperatorInfo* pOperator) {
|
|||
pOperator->cost.openCost = taosGetTimestampUs() - startTs;
|
||||
|
||||
tsem_wait(&pExchangeInfo->ready);
|
||||
if (isTaskKilled(pTaskInfo)) {
|
||||
longjmp(pTaskInfo->env, TSDB_CODE_TSC_QUERY_CANCELLED);
|
||||
}
|
||||
|
||||
tsem_post(&pExchangeInfo->ready);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -562,6 +572,9 @@ int32_t seqLoadRemoteData(SOperatorInfo* pOperator) {
|
|||
|
||||
doSendFetchDataRequest(pExchangeInfo, pTaskInfo, pExchangeInfo->current);
|
||||
tsem_wait(&pExchangeInfo->ready);
|
||||
if (isTaskKilled(pTaskInfo)) {
|
||||
longjmp(pTaskInfo->env, TSDB_CODE_TSC_QUERY_CANCELLED);
|
||||
}
|
||||
|
||||
SSourceDataInfo* pDataInfo = taosArrayGet(pExchangeInfo->pSourceDataInfo, pExchangeInfo->current);
|
||||
SDownstreamSourceNode* pSource = taosArrayGet(pExchangeInfo->pSources, pExchangeInfo->current);
|
||||
|
|
|
@ -659,6 +659,54 @@ int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t* useconds) {
|
|||
return pTaskInfo->code;
|
||||
}
|
||||
|
||||
int32_t qAppendTaskStopInfo(SExecTaskInfo* pTaskInfo, SExchangeOpStopInfo *pInfo) {
|
||||
taosWLockLatch(&pTaskInfo->stopInfo.lock);
|
||||
taosArrayPush(pTaskInfo->stopInfo.pStopInfo, pInfo);
|
||||
taosWUnLockLatch(&pTaskInfo->stopInfo.lock);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t stopInfoComp(void const* lp, void const* rp) {
|
||||
SExchangeOpStopInfo* key = (SExchangeOpStopInfo*)lp;
|
||||
SExchangeOpStopInfo* pInfo = (SExchangeOpStopInfo*)rp;
|
||||
|
||||
if (key->refId < pInfo->refId) {
|
||||
return -1;
|
||||
} else if (key->refId > pInfo->refId) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void qRemoveTaskStopInfo(SExecTaskInfo* pTaskInfo, SExchangeOpStopInfo *pInfo) {
|
||||
taosWLockLatch(&pTaskInfo->stopInfo.lock);
|
||||
int32_t idx = taosArraySearchIdx(pTaskInfo->stopInfo.pStopInfo, pInfo, stopInfoComp, TD_EQ);
|
||||
if (idx >= 0) {
|
||||
taosArrayRemove(pTaskInfo->stopInfo.pStopInfo, idx);
|
||||
}
|
||||
taosWUnLockLatch(&pTaskInfo->stopInfo.lock);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void qStopTaskOperators(SExecTaskInfo* pTaskInfo) {
|
||||
taosWLockLatch(&pTaskInfo->stopInfo.lock);
|
||||
|
||||
int32_t num = taosArrayGetSize(pTaskInfo->stopInfo.pStopInfo);
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
SExchangeOpStopInfo *pStop = taosArrayGet(pTaskInfo->stopInfo.pStopInfo, i);
|
||||
SExchangeInfo* pExchangeInfo = taosAcquireRef(exchangeObjRefPool, pStop->refId);
|
||||
if (pExchangeInfo) {
|
||||
tsem_post(&pExchangeInfo->ready);
|
||||
taosReleaseRef(exchangeObjRefPool, pStop->refId);
|
||||
}
|
||||
}
|
||||
|
||||
taosWUnLockLatch(&pTaskInfo->stopInfo.lock);
|
||||
}
|
||||
|
||||
int32_t qAsyncKillTask(qTaskInfo_t qinfo) {
|
||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)qinfo;
|
||||
|
||||
|
@ -667,7 +715,11 @@ int32_t qAsyncKillTask(qTaskInfo_t qinfo) {
|
|||
}
|
||||
|
||||
qDebug("%s execTask async killed", GET_TASKID(pTaskInfo));
|
||||
|
||||
setTaskKilled(pTaskInfo);
|
||||
|
||||
qStopTaskOperators(pTaskInfo);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -91,9 +91,6 @@ static void destroyAggOperatorInfo(void* param);
|
|||
|
||||
static void destroyIntervalOperatorInfo(void* param);
|
||||
|
||||
|
||||
static void destroyOperatorInfo(SOperatorInfo* pOperator);
|
||||
|
||||
void setOperatorCompleted(SOperatorInfo* pOperator) {
|
||||
pOperator->status = OP_EXEC_DONE;
|
||||
ASSERT(pOperator->pTaskInfo != NULL);
|
||||
|
@ -2172,7 +2169,7 @@ void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs) {
|
|||
}
|
||||
}
|
||||
|
||||
static void destroyOperatorInfo(SOperatorInfo* pOperator) {
|
||||
void destroyOperatorInfo(SOperatorInfo* pOperator) {
|
||||
if (pOperator == NULL) {
|
||||
return;
|
||||
}
|
||||
|
@ -2600,6 +2597,7 @@ static SExecTaskInfo* createExecTaskInfo(uint64_t queryId, uint64_t taskId, EOPT
|
|||
pTaskInfo->id.queryId = queryId;
|
||||
pTaskInfo->execModel = model;
|
||||
pTaskInfo->pTableInfoList = tableListCreate();
|
||||
pTaskInfo->stopInfo.pStopInfo = taosArrayInit(4, sizeof(SExchangeOpStopInfo));
|
||||
|
||||
char* p = taosMemoryCalloc(1, 128);
|
||||
snprintf(p, 128, "TID:0x%" PRIx64 " QID:0x%" PRIx64, taskId, queryId);
|
||||
|
@ -3213,6 +3211,7 @@ void doDestroyTask(SExecTaskInfo* pTaskInfo) {
|
|||
nodesDestroyNode((SNode*)pTaskInfo->pSubplan);
|
||||
}
|
||||
|
||||
taosArrayDestroy(pTaskInfo->stopInfo.pStopInfo);
|
||||
taosMemoryFreeClear(pTaskInfo->sql);
|
||||
taosMemoryFreeClear(pTaskInfo->id.str);
|
||||
taosMemoryFreeClear(pTaskInfo);
|
||||
|
@ -3426,6 +3425,7 @@ int32_t buildSessionResultDataBlock(SOperatorInfo* pOperator, SStreamState* pSta
|
|||
ASSERT(code == 0);
|
||||
if (code == -1) {
|
||||
// coverity scan
|
||||
pGroupResInfo->index += 1;
|
||||
continue;
|
||||
}
|
||||
SResultRow* pRow = (SResultRow*)pVal;
|
||||
|
|
|
@ -816,12 +816,12 @@ SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartition
|
|||
goto _error;
|
||||
}
|
||||
|
||||
setOperatorInfo(pOperator, "PartitionOperator", QUERY_NODE_PHYSICAL_PLAN_PARTITION, false, OP_NOT_OPENED, pInfo, pTaskInfo);
|
||||
setOperatorInfo(pOperator, "PartitionOperator", QUERY_NODE_PHYSICAL_PLAN_PARTITION, false, OP_NOT_OPENED, pInfo,
|
||||
pTaskInfo);
|
||||
pOperator->exprSupp.numOfExprs = numOfCols;
|
||||
pOperator->exprSupp.pExprInfo = pExprInfo;
|
||||
|
||||
pOperator->fpSet =
|
||||
createOperatorFpSet(operatorDummyOpenFn, hashPartition, NULL, destroyPartitionOperatorInfo, NULL);
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, hashPartition, NULL, destroyPartitionOperatorInfo, NULL);
|
||||
|
||||
code = appendDownstream(pOperator, &downstream, 1);
|
||||
return pOperator;
|
||||
|
@ -900,7 +900,7 @@ static SSDataBlock* buildStreamPartitionResult(SOperatorInfo* pOperator) {
|
|||
// TODO check tbname validity
|
||||
if (pData != (void*)-1) {
|
||||
memset(pDest->info.parTbName, 0, TSDB_TABLE_NAME_LEN);
|
||||
int32_t len = TMIN(varDataLen(pData), TSDB_TABLE_NAME_LEN);
|
||||
int32_t len = TMIN(varDataLen(pData), TSDB_TABLE_NAME_LEN - 1);
|
||||
memcpy(pDest->info.parTbName, varDataVal(pData), len);
|
||||
/*pDest->info.parTbName[len + 1] = 0;*/
|
||||
} else {
|
||||
|
@ -1099,11 +1099,12 @@ SOperatorInfo* createStreamPartitionOperatorInfo(SOperatorInfo* downstream, SStr
|
|||
int32_t numOfCols = 0;
|
||||
SExprInfo* pExprInfo = createExprInfo(pPartNode->part.pTargets, NULL, &numOfCols);
|
||||
|
||||
setOperatorInfo(pOperator, "StreamPartitionOperator", QUERY_NODE_PHYSICAL_PLAN_STREAM_PARTITION, false, OP_NOT_OPENED, pInfo, pTaskInfo);
|
||||
setOperatorInfo(pOperator, "StreamPartitionOperator", QUERY_NODE_PHYSICAL_PLAN_STREAM_PARTITION, false, OP_NOT_OPENED,
|
||||
pInfo, pTaskInfo);
|
||||
pOperator->exprSupp.numOfExprs = numOfCols;
|
||||
pOperator->exprSupp.pExprInfo = pExprInfo;
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doStreamHashPartition, NULL,
|
||||
destroyStreamPartitionOperatorInfo, NULL);
|
||||
pOperator->fpSet =
|
||||
createOperatorFpSet(operatorDummyOpenFn, doStreamHashPartition, NULL, destroyStreamPartitionOperatorInfo, NULL);
|
||||
|
||||
initParDownStream(downstream, &pInfo->partitionSup, &pInfo->scalarSup);
|
||||
code = appendDownstream(pOperator, &downstream, 1);
|
||||
|
|
|
@ -946,7 +946,8 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode,
|
|||
pInfo->currentGroupId = -1;
|
||||
pInfo->assignBlockUid = pTableScanNode->assignBlockUid;
|
||||
|
||||
setOperatorInfo(pOperator, "TableScanOperator", QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN, false, OP_NOT_OPENED, pInfo, pTaskInfo);
|
||||
setOperatorInfo(pOperator, "TableScanOperator", QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN, false, OP_NOT_OPENED, pInfo,
|
||||
pTaskInfo);
|
||||
pOperator->exprSupp.numOfExprs = numOfCols;
|
||||
|
||||
pInfo->metaCache.pTableMetaEntryCache = taosLRUCacheInit(1024 * 128, -1, .5);
|
||||
|
@ -980,7 +981,8 @@ SOperatorInfo* createTableSeqScanOperatorInfo(void* pReadHandle, SExecTaskInfo*
|
|||
pInfo->dataReader = pReadHandle;
|
||||
// pInfo->prevGroupId = -1;
|
||||
|
||||
setOperatorInfo(pOperator, "TableSeqScanOperator", QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN, false, OP_NOT_OPENED, pInfo, pTaskInfo);
|
||||
setOperatorInfo(pOperator, "TableSeqScanOperator", QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN, false, OP_NOT_OPENED,
|
||||
pInfo, pTaskInfo);
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTableScanImpl, NULL, NULL, NULL);
|
||||
return pOperator;
|
||||
}
|
||||
|
@ -1136,8 +1138,10 @@ SOperatorInfo* createDataBlockInfoScanOperator(SReadHandle* readHandle, SBlockDi
|
|||
goto _error;
|
||||
}
|
||||
|
||||
setOperatorInfo(pOperator, "DataBlockDistScanOperator", QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN, false, OP_NOT_OPENED, pInfo, pTaskInfo);
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doBlockInfoScan, NULL, destroyBlockDistScanOperatorInfo, NULL);
|
||||
setOperatorInfo(pOperator, "DataBlockDistScanOperator", QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN, false,
|
||||
OP_NOT_OPENED, pInfo, pTaskInfo);
|
||||
pOperator->fpSet =
|
||||
createOperatorFpSet(operatorDummyOpenFn, doBlockInfoScan, NULL, destroyBlockDistScanOperatorInfo, NULL);
|
||||
return pOperator;
|
||||
|
||||
_error:
|
||||
|
@ -1581,7 +1585,7 @@ static void calBlockTbName(SExprSupp* pTbNameCalSup, SSDataBlock* pBlock) {
|
|||
// TODO check tbname validation
|
||||
if (pData != (void*)-1 && pData != NULL) {
|
||||
memset(pBlock->info.parTbName, 0, TSDB_TABLE_NAME_LEN);
|
||||
int32_t len = TMIN(varDataLen(pData), TSDB_TABLE_NAME_LEN);
|
||||
int32_t len = TMIN(varDataLen(pData), TSDB_TABLE_NAME_LEN - 1);
|
||||
memcpy(pBlock->info.parTbName, varDataVal(pData), len);
|
||||
/*pBlock->info.parTbName[len + 1] = 0;*/
|
||||
} else {
|
||||
|
@ -1769,6 +1773,7 @@ static SSDataBlock* doQueueScan(SOperatorInfo* pOperator) {
|
|||
tqOffsetResetToLog(&pTaskInfo->streamInfo.prepareStatus, pTaskInfo->streamInfo.snapshotVer);
|
||||
qDebug("queue scan tsdb over, switch to wal ver %" PRId64 "", pTaskInfo->streamInfo.snapshotVer + 1);
|
||||
if (tqSeekVer(pInfo->tqReader, pTaskInfo->streamInfo.snapshotVer + 1) < 0) {
|
||||
tqOffsetResetToLog(&pTaskInfo->streamInfo.lastStatus, pTaskInfo->streamInfo.snapshotVer);
|
||||
return NULL;
|
||||
}
|
||||
ASSERT(pInfo->tqReader->pWalReader->curVersion == pTaskInfo->streamInfo.snapshotVer + 1);
|
||||
|
@ -2351,7 +2356,8 @@ SOperatorInfo* createRawScanOperatorInfo(SReadHandle* pHandle, SExecTaskInfo* pT
|
|||
pInfo->vnode = pHandle->vnode;
|
||||
|
||||
pInfo->sContext = pHandle->sContext;
|
||||
setOperatorInfo(pOperator, "RawScanOperator", QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN, false, OP_NOT_OPENED, pInfo, pTaskInfo);
|
||||
setOperatorInfo(pOperator, "RawScanOperator", QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN, false, OP_NOT_OPENED, pInfo,
|
||||
pTaskInfo);
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(NULL, doRawScan, NULL, destroyRawScanOperatorInfo, NULL);
|
||||
return pOperator;
|
||||
|
@ -2366,9 +2372,7 @@ _end:
|
|||
static void destroyStreamScanOperatorInfo(void* param) {
|
||||
SStreamScanInfo* pStreamScan = (SStreamScanInfo*)param;
|
||||
if (pStreamScan->pTableScanOp && pStreamScan->pTableScanOp->info) {
|
||||
STableScanInfo* pTableScanInfo = pStreamScan->pTableScanOp->info;
|
||||
destroyTableScanOperatorInfo(pTableScanInfo);
|
||||
taosMemoryFreeClear(pStreamScan->pTableScanOp);
|
||||
destroyOperatorInfo(pStreamScan->pTableScanOp);
|
||||
}
|
||||
if (pStreamScan->tqReader) {
|
||||
tqCloseReader(pStreamScan->tqReader);
|
||||
|
@ -2537,7 +2541,8 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys
|
|||
pInfo->assignBlockUid = pTableScanNode->assignBlockUid;
|
||||
pInfo->partitionSup.needCalc = false;
|
||||
|
||||
setOperatorInfo(pOperator, "StreamScanOperator", QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN, false, OP_NOT_OPENED, pInfo, pTaskInfo);
|
||||
setOperatorInfo(pOperator, "StreamScanOperator", QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN, false, OP_NOT_OPENED, pInfo,
|
||||
pTaskInfo);
|
||||
pOperator->exprSupp.numOfExprs = taosArrayGetSize(pInfo->pRes->pDataBlock);
|
||||
|
||||
__optr_fn_t nextFn = pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM ? doStreamScan : doQueueScan;
|
||||
|
@ -4175,7 +4180,8 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSystemTableScan
|
|||
pInfo->readHandle = *(SReadHandle*)readHandle;
|
||||
}
|
||||
|
||||
setOperatorInfo(pOperator, "SysTableScanOperator", QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN, false, OP_NOT_OPENED, pInfo, pTaskInfo);
|
||||
setOperatorInfo(pOperator, "SysTableScanOperator", QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN, false, OP_NOT_OPENED,
|
||||
pInfo, pTaskInfo);
|
||||
pOperator->exprSupp.numOfExprs = taosArrayGetSize(pInfo->pRes->pDataBlock);
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doSysTableScan, NULL, destroySysScanOperator, NULL);
|
||||
return pOperator;
|
||||
|
@ -4305,7 +4311,8 @@ SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysi
|
|||
pInfo->readHandle = *pReadHandle;
|
||||
pInfo->curPos = 0;
|
||||
|
||||
setOperatorInfo(pOperator, "TagScanOperator", QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN, false, OP_NOT_OPENED, pInfo, pTaskInfo);
|
||||
setOperatorInfo(pOperator, "TagScanOperator", QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN, false, OP_NOT_OPENED, pInfo,
|
||||
pTaskInfo);
|
||||
initResultSizeInfo(&pOperator->resultInfo, 4096);
|
||||
blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity);
|
||||
|
||||
|
@ -4815,11 +4822,12 @@ SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanN
|
|||
int32_t rowSize = pInfo->pResBlock->info.rowSize;
|
||||
pInfo->bufPageSize = getProperSortPageSize(rowSize);
|
||||
|
||||
setOperatorInfo(pOperator, "TableMergeScanOperator", QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN, false, OP_NOT_OPENED, pInfo, pTaskInfo);
|
||||
setOperatorInfo(pOperator, "TableMergeScanOperator", QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN, false, OP_NOT_OPENED,
|
||||
pInfo, pTaskInfo);
|
||||
pOperator->exprSupp.numOfExprs = numOfCols;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTableMergeScan, NULL,
|
||||
destroyTableMergeScanOperatorInfo, getTableMergeScanExplainExecInfo);
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTableMergeScan, NULL, destroyTableMergeScanOperatorInfo,
|
||||
getTableMergeScanExplainExecInfo);
|
||||
pOperator->cost.openCost = 0;
|
||||
return pOperator;
|
||||
|
||||
|
|
|
@ -680,9 +680,9 @@ SResultCellData* getResultCell(SResultRowData* pRaw, int32_t index) {
|
|||
void* destroyFillColumnInfo(SFillColInfo* pFillCol, int32_t start, int32_t end) {
|
||||
for (int32_t i = start; i < end; i++) {
|
||||
destroyExprInfo(pFillCol[i].pExpr, 1);
|
||||
taosMemoryFreeClear(pFillCol[i].pExpr);
|
||||
taosVariantDestroy(&pFillCol[i].fillVal);
|
||||
}
|
||||
taosMemoryFreeClear(pFillCol[start].pExpr);
|
||||
taosMemoryFree(pFillCol);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -3580,6 +3580,11 @@ static void removeSessionResult(SSHashObj* pHashMap, SSHashObj* pResMap, SSessio
|
|||
tSimpleHashRemove(pResMap, &key, sizeof(SSessionKey));
|
||||
}
|
||||
|
||||
static void getSessionHashKey(const SSessionKey* pKey, SSessionKey* pHashKey) {
|
||||
*pHashKey = *pKey;
|
||||
pHashKey->win.ekey = pKey->win.skey;
|
||||
}
|
||||
|
||||
static void removeSessionResults(SSHashObj* pHashMap, SArray* pWins) {
|
||||
if (tSimpleHashGetSize(pHashMap) == 0) {
|
||||
return;
|
||||
|
@ -3588,8 +3593,8 @@ static void removeSessionResults(SSHashObj* pHashMap, SArray* pWins) {
|
|||
for (int32_t i = 0; i < size; i++) {
|
||||
SSessionKey* pWin = taosArrayGet(pWins, i);
|
||||
if (!pWin) continue;
|
||||
SSessionKey key = *pWin;
|
||||
key.win.ekey = key.win.skey;
|
||||
SSessionKey key = {0};
|
||||
getSessionHashKey(pWin, &key);
|
||||
tSimpleHashRemove(pHashMap, &key, sizeof(SSessionKey));
|
||||
}
|
||||
}
|
||||
|
@ -3642,7 +3647,9 @@ static int32_t doOneWindowAggImpl(SColumnInfoData* pTimeWindowData, SResultWindo
|
|||
|
||||
static bool doDeleteSessionWindow(SStreamAggSupporter* pAggSup, SSessionKey* pKey) {
|
||||
streamStateSessionDel(pAggSup->pState, pKey);
|
||||
tSimpleHashRemove(pAggSup->pResultRows, pKey, sizeof(SSessionKey));
|
||||
SSessionKey hashKey = {0};
|
||||
getSessionHashKey(pKey, &hashKey);
|
||||
tSimpleHashRemove(pAggSup->pResultRows, &hashKey, sizeof(SSessionKey));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -3753,8 +3760,8 @@ static void doStreamSessionAggImpl(SOperatorInfo* pOperator, SSDataBlock* pSData
|
|||
}
|
||||
}
|
||||
if (pInfo->twAggSup.calTrigger == STREAM_TRIGGER_WINDOW_CLOSE) {
|
||||
SSessionKey key = winInfo.sessionWin;
|
||||
key.win.ekey = key.win.skey;
|
||||
SSessionKey key = {0};
|
||||
getSessionHashKey(&winInfo.sessionWin, &key);
|
||||
tSimpleHashPut(pAggSup->pResultRows, &key, sizeof(SSessionKey), &winInfo, sizeof(SResultWindowInfo));
|
||||
}
|
||||
|
||||
|
@ -3853,23 +3860,28 @@ void doBuildDeleteDataBlock(SOperatorInfo* pOp, SSHashObj* pStDeleted, SSDataBlo
|
|||
colDataAppendNULL(pCalEdCol, pBlock->info.rows);
|
||||
|
||||
SHashObj* pGroupIdTbNameMap = NULL;
|
||||
if (pOp->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION ||
|
||||
if (pOp->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION ||
|
||||
pOp->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION ||
|
||||
pOp->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION) {
|
||||
SStreamSessionAggOperatorInfo* pInfo = pOp->info;
|
||||
pGroupIdTbNameMap = pInfo->pGroupIdTbNameMap;
|
||||
} else if (pOp->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE) {
|
||||
SStreamStateAggOperatorInfo* pInfo = pOp->info;
|
||||
pGroupIdTbNameMap = pInfo->pGroupIdTbNameMap;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
char* tbname = taosHashGet(pGroupIdTbNameMap, &res->groupId, sizeof(int64_t));
|
||||
SColumnInfoData* pTableCol = taosArrayGet(pBlock->pDataBlock, TABLE_NAME_COLUMN_INDEX);
|
||||
if (tbname == NULL) {
|
||||
/*printf("\n\n no tbname for group id %" PRId64 "%p %p\n\n", res->groupId, pOp->info, pGroupIdTbNameMap);*/
|
||||
colDataAppendNULL(pTableCol, pBlock->info.rows);
|
||||
} else {
|
||||
char parTbName[VARSTR_HEADER_SIZE + TSDB_TABLE_NAME_LEN];
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(parTbName, tbname, sizeof(parTbName));
|
||||
colDataAppend(pTableCol, pBlock->info.rows, (const char*)parTbName, false);
|
||||
/*printf("\n\n get tbname %s group id %" PRId64 "\n\n", tbname, res->groupId);*/
|
||||
}
|
||||
pBlock->info.rows += 1;
|
||||
}
|
||||
|
@ -3896,8 +3908,8 @@ static void rebuildSessionWindow(SOperatorInfo* pOperator, SArray* pWinArray, SS
|
|||
SOperatorInfo* pChild = taosArrayGetP(pInfo->pChildren, j);
|
||||
SStreamSessionAggOperatorInfo* pChInfo = pChild->info;
|
||||
SStreamAggSupporter* pChAggSup = &pChInfo->streamAggSup;
|
||||
SSessionKey chWinKey = *pWinKey;
|
||||
chWinKey.win.ekey = chWinKey.win.skey;
|
||||
SSessionKey chWinKey = {0};
|
||||
getSessionHashKey(pWinKey, &chWinKey);
|
||||
SStreamStateCur* pCur = streamStateSessionSeekKeyCurrentNext(pChAggSup->pState, &chWinKey);
|
||||
SResultRow* pResult = NULL;
|
||||
SResultRow* pChResult = NULL;
|
||||
|
@ -3978,8 +3990,8 @@ static void copyDeleteWindowInfo(SArray* pResWins, SSHashObj* pStDeleted) {
|
|||
for (int32_t i = 0; i < size; i++) {
|
||||
SSessionKey* pWinKey = taosArrayGet(pResWins, i);
|
||||
if (!pWinKey) continue;
|
||||
SSessionKey winInfo = *pWinKey;
|
||||
winInfo.win.ekey = winInfo.win.skey;
|
||||
SSessionKey winInfo = {0};
|
||||
getSessionHashKey(pWinKey, &winInfo);
|
||||
tSimpleHashPut(pStDeleted, &winInfo, sizeof(SSessionKey), NULL, 0);
|
||||
}
|
||||
}
|
||||
|
@ -4046,7 +4058,8 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) {
|
|||
if (pBlock->info.parTbName[0]) {
|
||||
taosHashPut(pInfo->pGroupIdTbNameMap, &pBlock->info.groupId, sizeof(int64_t), &pBlock->info.parTbName,
|
||||
TSDB_TABLE_NAME_LEN);
|
||||
/*printf("\n\n put tbname %s\n\n", pBlock->info.parTbName);*/
|
||||
/*printf("\n\n put tbname %s group id %" PRId64 "\n\n into %p %p", pBlock->info.parTbName, pBlock->info.groupId,*/
|
||||
/*pInfo, pInfo->pGroupIdTbNameMap);*/
|
||||
}
|
||||
|
||||
if (pBlock->info.parTbName[0]) {
|
||||
|
@ -4561,8 +4574,8 @@ static void doStreamStateAggImpl(SOperatorInfo* pOperator, SSDataBlock* pSDataBl
|
|||
}
|
||||
|
||||
if (pInfo->twAggSup.calTrigger == STREAM_TRIGGER_WINDOW_CLOSE) {
|
||||
SSessionKey key = curWin.winInfo.sessionWin;
|
||||
key.win.ekey = key.win.skey;
|
||||
SSessionKey key = {0};
|
||||
getSessionHashKey(&curWin.winInfo.sessionWin, &key);
|
||||
tSimpleHashPut(pAggSup->pResultRows, &key, sizeof(SSessionKey), &curWin.winInfo, sizeof(SResultWindowInfo));
|
||||
}
|
||||
}
|
||||
|
@ -4645,6 +4658,12 @@ static SSDataBlock* doStreamStateAgg(SOperatorInfo* pOperator) {
|
|||
initGroupResInfoFromArrayList(&pInfo->groupResInfo, pUpdated);
|
||||
blockDataEnsureCapacity(pInfo->binfo.pRes, pOperator->resultInfo.capacity);
|
||||
|
||||
#if 0
|
||||
char* pBuf = streamStateSessionDump(pInfo->streamAggSup.pState);
|
||||
qDebug("===stream===final session%s", pBuf);
|
||||
taosMemoryFree(pBuf);
|
||||
#endif
|
||||
|
||||
doBuildDeleteDataBlock(pOperator, pInfo->pSeDeleted, pInfo->pDelRes, &pInfo->pDelIterator);
|
||||
if (pInfo->pDelRes->info.rows > 0) {
|
||||
printDataBlock(pInfo->pDelRes, "single state delete");
|
||||
|
|
|
@ -269,7 +269,7 @@ typedef struct SModeInfo {
|
|||
STuplePos nullTuplePos;
|
||||
bool nullTupleSaved;
|
||||
|
||||
char pItems[];
|
||||
char pItems[];
|
||||
} SModeInfo;
|
||||
|
||||
typedef struct SDerivInfo {
|
||||
|
@ -911,7 +911,7 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) {
|
|||
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
float* plist = (float*)pCol->pData;
|
||||
// float val = 0;
|
||||
// float val = 0;
|
||||
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
|
||||
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||
continue;
|
||||
|
@ -919,9 +919,9 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) {
|
|||
|
||||
numOfElem += 1;
|
||||
pAvgRes->count += 1;
|
||||
pAvgRes->sum.dsum += plist[i];
|
||||
pAvgRes->sum.dsum += plist[i];
|
||||
}
|
||||
// pAvgRes->sum.dsum = val;
|
||||
// pAvgRes->sum.dsum = val;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1187,7 +1187,11 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
|
|||
}
|
||||
|
||||
if (!pBuf->assign) {
|
||||
pBuf->v = *(int64_t*)tval;
|
||||
if (type == TSDB_DATA_TYPE_FLOAT) {
|
||||
*(float*)&pBuf->v = GET_DOUBLE_VAL(tval);
|
||||
} else {
|
||||
pBuf->v = *(int64_t*)tval;
|
||||
}
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
index = findRowIndex(pInput->startRowIndex, pInput->numOfRows, pCol, tval);
|
||||
if (index >= 0) {
|
||||
|
@ -3007,7 +3011,7 @@ int32_t firstFunction(SqlFunctionCtx* pCtx) {
|
|||
}
|
||||
}
|
||||
#else
|
||||
int64_t* pts = (int64_t*) pInput->pPTS->pData;
|
||||
int64_t* pts = (int64_t*)pInput->pPTS->pData;
|
||||
for (int32_t i = pInput->startRowIndex; i < pInput->startRowIndex + pInput->numOfRows; ++i) {
|
||||
if (pInputCol->hasNull && colDataIsNull(pInputCol, pInput->totalRows, i, pColAgg)) {
|
||||
continue;
|
||||
|
@ -3111,61 +3115,61 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) {
|
|||
}
|
||||
}
|
||||
#else
|
||||
if (!pInputCol->hasNull) {
|
||||
numOfElems = 1;
|
||||
if (!pInputCol->hasNull) {
|
||||
numOfElems = 1;
|
||||
|
||||
int32_t round = pInput->numOfRows >> 2;
|
||||
int32_t reminder = pInput->numOfRows & 0x03;
|
||||
int32_t round = pInput->numOfRows >> 2;
|
||||
int32_t reminder = pInput->numOfRows & 0x03;
|
||||
|
||||
int32_t tick = 0;
|
||||
for (int32_t i = pInput->startRowIndex; tick < round; i += 4, tick += 1) {
|
||||
int64_t cts = pts[i];
|
||||
int32_t chosen = i;
|
||||
int32_t tick = 0;
|
||||
for (int32_t i = pInput->startRowIndex; tick < round; i += 4, tick += 1) {
|
||||
int64_t cts = pts[i];
|
||||
int32_t chosen = i;
|
||||
|
||||
if (cts < pts[i + 1]) {
|
||||
cts = pts[i + 1];
|
||||
chosen = i + 1;
|
||||
}
|
||||
|
||||
if (cts < pts[i + 2]) {
|
||||
cts = pts[i + 2];
|
||||
chosen = i + 2;
|
||||
}
|
||||
|
||||
if (cts < pts[i + 3]) {
|
||||
cts = pts[i + 3];
|
||||
chosen = i + 3;
|
||||
}
|
||||
|
||||
if (pResInfo->numOfRes == 0 || pInfo->ts < cts) {
|
||||
char* data = colDataGetData(pInputCol, chosen);
|
||||
doSaveCurrentVal(pCtx, i, cts, type, data);
|
||||
pResInfo->numOfRes = 1;
|
||||
}
|
||||
if (cts < pts[i + 1]) {
|
||||
cts = pts[i + 1];
|
||||
chosen = i + 1;
|
||||
}
|
||||
|
||||
for (int32_t i = pInput->startRowIndex + round * 4; i < pInput->startRowIndex + pInput->numOfRows; ++i) {
|
||||
if (pResInfo->numOfRes == 0 || pInfo->ts < pts[i]) {
|
||||
char* data = colDataGetData(pInputCol, i);
|
||||
doSaveCurrentVal(pCtx, i, pts[i], type, data);
|
||||
pResInfo->numOfRes = 1;
|
||||
}
|
||||
if (cts < pts[i + 2]) {
|
||||
cts = pts[i + 2];
|
||||
chosen = i + 2;
|
||||
}
|
||||
} else {
|
||||
for (int32_t i = pInput->startRowIndex; i < pInput->startRowIndex + pInput->numOfRows; ++i) {
|
||||
if (pInputCol->hasNull && colDataIsNull(pInputCol, pInput->totalRows, i, pColAgg)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
numOfElems++;
|
||||
if (cts < pts[i + 3]) {
|
||||
cts = pts[i + 3];
|
||||
chosen = i + 3;
|
||||
}
|
||||
|
||||
if (pResInfo->numOfRes == 0 || pInfo->ts < pts[i]) {
|
||||
char* data = colDataGetData(pInputCol, i);
|
||||
doSaveCurrentVal(pCtx, i, pts[i], type, data);
|
||||
pResInfo->numOfRes = 1;
|
||||
}
|
||||
if (pResInfo->numOfRes == 0 || pInfo->ts < cts) {
|
||||
char* data = colDataGetData(pInputCol, chosen);
|
||||
doSaveCurrentVal(pCtx, i, cts, type, data);
|
||||
pResInfo->numOfRes = 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t i = pInput->startRowIndex + round * 4; i < pInput->startRowIndex + pInput->numOfRows; ++i) {
|
||||
if (pResInfo->numOfRes == 0 || pInfo->ts < pts[i]) {
|
||||
char* data = colDataGetData(pInputCol, i);
|
||||
doSaveCurrentVal(pCtx, i, pts[i], type, data);
|
||||
pResInfo->numOfRes = 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int32_t i = pInput->startRowIndex; i < pInput->startRowIndex + pInput->numOfRows; ++i) {
|
||||
if (pInputCol->hasNull && colDataIsNull(pInputCol, pInput->totalRows, i, pColAgg)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
numOfElems++;
|
||||
|
||||
if (pResInfo->numOfRes == 0 || pInfo->ts < pts[i]) {
|
||||
char* data = colDataGetData(pInputCol, i);
|
||||
doSaveCurrentVal(pCtx, i, pts[i], type, data);
|
||||
pResInfo->numOfRes = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -3175,7 +3179,7 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) {
|
|||
firstlastSaveTupleData(pCtx->pSrcBlock, pInput->startRowIndex, pCtx, pInfo);
|
||||
}
|
||||
|
||||
// SET_VAL(pResInfo, numOfElems, 1);
|
||||
// SET_VAL(pResInfo, numOfElems, 1);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -5276,7 +5280,6 @@ int32_t sampleFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
return pInfo->numSampled;
|
||||
}
|
||||
|
||||
|
||||
bool getTailFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
|
||||
#if 0
|
||||
SColumnNode* pCol = (SColumnNode*)nodesListGetNode(pFunc->pParameterList, 0);
|
||||
|
@ -6073,11 +6076,19 @@ int32_t blockDistFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
|
||||
int32_t row = 0;
|
||||
char st[256] = {0};
|
||||
double totalRawSize = pData->totalRows * pData->rowSize;
|
||||
double averageSize = 0;
|
||||
if (pData->numOfBlocks != 0) {
|
||||
averageSize = ((double)pData->totalSize) / pData->numOfBlocks;
|
||||
}
|
||||
uint64_t totalRawSize = pData->totalRows * pData->rowSize;
|
||||
double compRatio = 0;
|
||||
if (totalRawSize != 0) {
|
||||
compRatio = pData->totalSize * 100 / (double)totalRawSize;
|
||||
}
|
||||
|
||||
int32_t len = sprintf(st + VARSTR_HEADER_SIZE,
|
||||
"Total_Blocks=[%d] Total_Size=[%.2f Kb] Average_size=[%.2f Kb] Compression_Ratio=[%.2f %c]",
|
||||
pData->numOfBlocks, pData->totalSize / 1024.0, ((double)pData->totalSize) / pData->numOfBlocks,
|
||||
pData->totalSize * 100 / totalRawSize, '%');
|
||||
pData->numOfBlocks, pData->totalSize / 1024.0, averageSize, compRatio, '%');
|
||||
|
||||
varDataSetLen(st, len);
|
||||
colDataAppend(pColInfo, row++, st, false);
|
||||
|
|
|
@ -864,6 +864,7 @@ void udfdCtrlAllocBufCb(uv_handle_t *handle, size_t suggested_size, uv_buf_t *bu
|
|||
void udfdCtrlReadCb(uv_stream_t *q, ssize_t nread, const uv_buf_t *buf) {
|
||||
if (nread < 0) {
|
||||
fnError("udfd ctrl pipe read error. %s", uv_err_name(nread));
|
||||
taosMemoryFree(buf->base);
|
||||
uv_close((uv_handle_t *)q, NULL);
|
||||
uv_stop(global.loop);
|
||||
return;
|
||||
|
|
|
@ -1878,6 +1878,7 @@ static int32_t rewriteIsTrue(SNode* pSrc, SNode** pIsTrue) {
|
|||
|
||||
static EDealRes translateCaseWhen(STranslateContext* pCxt, SCaseWhenNode* pCaseWhen) {
|
||||
bool first = true;
|
||||
bool allNullThen = true;
|
||||
SNode* pNode = NULL;
|
||||
FOREACH(pNode, pCaseWhen->pWhenThenList) {
|
||||
SWhenThenNode* pWhenThen = (SWhenThenNode*)pNode;
|
||||
|
@ -1889,12 +1890,28 @@ static EDealRes translateCaseWhen(STranslateContext* pCxt, SCaseWhenNode* pCaseW
|
|||
}
|
||||
pWhenThen->pWhen = pIsTrue;
|
||||
}
|
||||
if (first || dataTypeComp(&pCaseWhen->node.resType, &((SExprNode*)pNode)->resType) < 0) {
|
||||
pCaseWhen->node.resType = ((SExprNode*)pNode)->resType;
|
||||
|
||||
SExprNode* pThenExpr = (SExprNode*)pNode;
|
||||
if (TSDB_DATA_TYPE_NULL == pThenExpr->resType.type) {
|
||||
continue;
|
||||
}
|
||||
allNullThen = false;
|
||||
if (first || dataTypeComp(&pCaseWhen->node.resType, &pThenExpr->resType) < 0) {
|
||||
pCaseWhen->node.resType = pThenExpr->resType;
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
|
||||
if (allNullThen) {
|
||||
if (NULL != pCaseWhen->pElse) {
|
||||
pCaseWhen->node.resType = ((SExprNode*)pCaseWhen->pElse)->resType;
|
||||
} else {
|
||||
pCaseWhen->node.resType.type = TSDB_DATA_TYPE_NULL;
|
||||
pCaseWhen->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_NULL].bytes;
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
}
|
||||
|
||||
FOREACH(pNode, pCaseWhen->pWhenThenList) {
|
||||
SWhenThenNode* pWhenThen = (SWhenThenNode*)pNode;
|
||||
if (!dataTypeEqual(&pCaseWhen->node.resType, &((SExprNode*)pNode)->resType)) {
|
||||
|
|
|
@ -138,7 +138,7 @@ static char* getSyntaxErrFormat(int32_t errCode) {
|
|||
case TSDB_CODE_PAR_CANNOT_DROP_PRIMARY_KEY:
|
||||
return "Primary timestamp column cannot be dropped";
|
||||
case TSDB_CODE_PAR_INVALID_MODIFY_COL:
|
||||
return "Only binary/nchar column length could be modified";
|
||||
return "Only binary/nchar column length could be modified, and the length can only be increased, not decreased";
|
||||
case TSDB_CODE_PAR_INVALID_TBNAME:
|
||||
return "Invalid tbname pseudo column";
|
||||
case TSDB_CODE_PAR_INVALID_FUNCTION_NAME:
|
||||
|
|
|
@ -246,7 +246,7 @@ typedef struct SQWorkerMgmt {
|
|||
|
||||
#define QW_ERR_RET(c) \
|
||||
do { \
|
||||
int32_t _code = c; \
|
||||
int32_t _code = (c); \
|
||||
if (_code != TSDB_CODE_SUCCESS) { \
|
||||
terrno = _code; \
|
||||
return _code; \
|
||||
|
@ -254,7 +254,7 @@ typedef struct SQWorkerMgmt {
|
|||
} while (0)
|
||||
#define QW_RET(c) \
|
||||
do { \
|
||||
int32_t _code = c; \
|
||||
int32_t _code = (c); \
|
||||
if (_code != TSDB_CODE_SUCCESS) { \
|
||||
terrno = _code; \
|
||||
} \
|
||||
|
@ -262,7 +262,7 @@ typedef struct SQWorkerMgmt {
|
|||
} while (0)
|
||||
#define QW_ERR_JRET(c) \
|
||||
do { \
|
||||
code = c; \
|
||||
code = (c); \
|
||||
if (code != TSDB_CODE_SUCCESS) { \
|
||||
terrno = code; \
|
||||
goto _return; \
|
||||
|
|
|
@ -91,11 +91,53 @@ _return:
|
|||
|
||||
void qwDbgDumpSchInfo(SQWorker *mgmt, SQWSchStatus *sch, int32_t i) {
|
||||
QW_LOCK(QW_READ, &sch->tasksLock);
|
||||
QW_DLOG("the %dth scheduler status, hbBrokenTs:%" PRId64 ",taskNum:%d", i, sch->hbBrokenTs,
|
||||
taosHashGetSize(sch->tasksHash));
|
||||
int32_t taskNum = taosHashGetSize(sch->tasksHash);
|
||||
QW_DLOG("***The %dth scheduler status, hbBrokenTs:%" PRId64 ",taskNum:%d", i, sch->hbBrokenTs, taskNum);
|
||||
|
||||
uint64_t qId, tId;
|
||||
int32_t eId;
|
||||
SQWTaskStatus *pTask = NULL;
|
||||
void *pIter = taosHashIterate(sch->tasksHash, NULL);
|
||||
while (pIter) {
|
||||
pTask = (SQWTaskStatus *)pIter;
|
||||
void *key = taosHashGetKey(pIter, NULL);
|
||||
QW_GET_QTID(key, qId, tId, eId);
|
||||
|
||||
QW_TASK_DLOG("job refId:%" PRIx64 ", code:%x, task status:%d", pTask->refId, pTask->code, pTask->status);
|
||||
|
||||
pIter = taosHashIterate(sch->tasksHash, pIter);
|
||||
}
|
||||
|
||||
QW_UNLOCK(QW_READ, &sch->tasksLock);
|
||||
}
|
||||
|
||||
void qwDbgDumpTasksInfo(SQWorker *mgmt) {
|
||||
QW_DUMP("***Total remain ctx num %d", taosHashGetSize(mgmt->ctxHash));
|
||||
|
||||
int32_t i = 0;
|
||||
SQWTaskCtx *ctx = NULL;
|
||||
uint64_t qId, tId;
|
||||
int32_t eId;
|
||||
void *pIter = taosHashIterate(mgmt->ctxHash, NULL);
|
||||
while (pIter) {
|
||||
ctx = (SQWTaskCtx *)pIter;
|
||||
void *key = taosHashGetKey(pIter, NULL);
|
||||
QW_GET_QTID(key, qId, tId, eId);
|
||||
|
||||
QW_TASK_DLOG("%p lock:%x, phase:%d, type:%d, explain:%d, needFetch:%d, localExec:%d, msgType:%d, fetchType:%d, "
|
||||
"execId:%x, level:%d, queryGotData:%d, queryRsped:%d, queryEnd:%d, queryContinue:%d, queryInQueue:%d, "
|
||||
"rspCode:%x, affectedRows:%" PRId64 ", taskHandle:%p, sinkHandle:%p, tbFName:%s, sver:%d, tver:%d, events:%d,%d,%d,%d,%d",
|
||||
ctx, ctx->lock, ctx->phase, ctx->taskType, ctx->explain, ctx->needFetch, ctx->localExec, ctx->msgType,
|
||||
ctx->fetchType, ctx->execId, ctx->level, ctx->queryGotData, ctx->queryRsped, ctx->queryEnd, ctx->queryContinue,
|
||||
ctx->queryInQueue, ctx->rspCode, ctx->affectedRows, ctx->taskHandle, ctx->sinkHandle, ctx->tbInfo.tbFName,
|
||||
ctx->tbInfo.sversion, ctx->tbInfo.tversion, ctx->events[QW_EVENT_CANCEL], ctx->events[QW_EVENT_READY],
|
||||
ctx->events[QW_EVENT_FETCH], ctx->events[QW_EVENT_DROP], ctx->events[QW_EVENT_CQUERY]);
|
||||
|
||||
pIter = taosHashIterate(mgmt->ctxHash, pIter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void qwDbgDumpMgmtInfo(SQWorker *mgmt) {
|
||||
if (!gQWDebug.dumpEnable) {
|
||||
return;
|
||||
|
@ -120,7 +162,7 @@ void qwDbgDumpMgmtInfo(SQWorker *mgmt) {
|
|||
|
||||
QW_UNLOCK(QW_READ, &mgmt->schLock);
|
||||
|
||||
QW_DUMP("total remain ctx num %d", taosHashGetSize(mgmt->ctxHash));
|
||||
qwDbgDumpTasksInfo(mgmt);
|
||||
}
|
||||
|
||||
int32_t qwDbgBuildAndSendRedirectRsp(int32_t rspType, SRpcHandleInfo *pConn, int32_t code, SEpSet *pEpSet) {
|
||||
|
|
|
@ -281,9 +281,11 @@ void qwFreeTaskHandle(qTaskInfo_t *taskHandle) {
|
|||
|
||||
int32_t qwKillTaskHandle(SQWTaskCtx *ctx) {
|
||||
int32_t code = 0;
|
||||
|
||||
// Note: free/kill may in RC
|
||||
qTaskInfo_t taskHandle = atomic_load_ptr(&ctx->taskHandle);
|
||||
if (taskHandle && atomic_val_compare_exchange_ptr(&ctx->taskHandle, taskHandle, NULL)) {
|
||||
qDebug("start to kill task");
|
||||
code = qAsyncKillTask(taskHandle);
|
||||
atomic_store_ptr(&ctx->taskHandle, taskHandle);
|
||||
}
|
||||
|
|
|
@ -683,6 +683,8 @@ int32_t qwProcessCQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg) {
|
|||
bool queryStop = false;
|
||||
|
||||
do {
|
||||
ctx = NULL;
|
||||
|
||||
QW_ERR_JRET(qwHandlePrePhaseEvents(QW_FPARAMS(), QW_PHASE_PRE_CQUERY, &input, NULL));
|
||||
|
||||
QW_ERR_JRET(qwGetTaskCtx(QW_FPARAMS(), &ctx));
|
||||
|
@ -1162,6 +1164,41 @@ _return:
|
|||
QW_RET(code);
|
||||
}
|
||||
|
||||
void qWorkerStopAllTasks(void *qWorkerMgmt) {
|
||||
SQWorker *mgmt = (SQWorker *)qWorkerMgmt;
|
||||
|
||||
QW_DLOG("start to stop all tasks, taskNum:%d", taosHashGetSize(mgmt->ctxHash));
|
||||
|
||||
uint64_t qId, tId;
|
||||
int32_t eId;
|
||||
void *pIter = taosHashIterate(mgmt->ctxHash, NULL);
|
||||
while (pIter) {
|
||||
SQWTaskCtx *ctx = (SQWTaskCtx *)pIter;
|
||||
void *key = taosHashGetKey(pIter, NULL);
|
||||
QW_GET_QTID(key, qId, tId, eId);
|
||||
|
||||
QW_LOCK(QW_WRITE, &ctx->lock);
|
||||
|
||||
QW_TASK_DLOG_E("start to force stop task");
|
||||
|
||||
if (QW_EVENT_RECEIVED(ctx, QW_EVENT_DROP) || QW_EVENT_PROCESSED(ctx, QW_EVENT_DROP)) {
|
||||
QW_TASK_WLOG_E("task already dropping");
|
||||
QW_UNLOCK(QW_WRITE, &ctx->lock);
|
||||
|
||||
pIter = taosHashIterate(mgmt->ctxHash, pIter);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (QW_QUERY_RUNNING(ctx)) {
|
||||
qwKillTaskHandle(ctx);
|
||||
}
|
||||
|
||||
QW_UNLOCK(QW_WRITE, &ctx->lock);
|
||||
|
||||
pIter = taosHashIterate(mgmt->ctxHash, pIter);
|
||||
}
|
||||
}
|
||||
|
||||
void qWorkerDestroy(void **qWorkerMgmt) {
|
||||
if (NULL == qWorkerMgmt || NULL == *qWorkerMgmt) {
|
||||
return;
|
||||
|
|
|
@ -521,9 +521,13 @@ int32_t streamStateSessionGet(SStreamState* pState, SSessionKey* key, void** pVa
|
|||
void* tmp = NULL;
|
||||
int32_t code = streamStateSessionGetKVByCur(pCur, &resKey, &tmp, pVLen);
|
||||
if (code == 0) {
|
||||
*key = resKey;
|
||||
*pVal = tdbRealloc(NULL, *pVLen);
|
||||
memcpy(*pVal, tmp, *pVLen);
|
||||
if (key->win.skey != resKey.win.skey) {
|
||||
code = -1;
|
||||
} else {
|
||||
*key = resKey;
|
||||
*pVal = tdbRealloc(NULL, *pVLen);
|
||||
memcpy(*pVal, tmp, *pVLen);
|
||||
}
|
||||
}
|
||||
streamStateFreeCur(pCur);
|
||||
return code;
|
||||
|
|
|
@ -21,7 +21,6 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include "syncInt.h"
|
||||
#include "syncMessage.h"
|
||||
|
||||
// TLA+ Spec
|
||||
// HandleAppendEntriesRequest(i, j, m) ==
|
||||
|
@ -89,7 +88,7 @@ extern "C" {
|
|||
// /\ UNCHANGED <<candidateVars, leaderVars>>
|
||||
//
|
||||
|
||||
int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg);
|
||||
int32_t syncNodeOnAppendEntries(SSyncNode* ths, const SRpcMsg* pMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include "syncInt.h"
|
||||
#include "syncMessage.h"
|
||||
|
||||
// TLA+ Spec
|
||||
// HandleAppendEntriesResponse(i, j, m) ==
|
||||
|
@ -36,7 +35,7 @@ extern "C" {
|
|||
// /\ Discard(m)
|
||||
// /\ UNCHANGED <<serverVars, candidateVars, logVars, elections>>
|
||||
//
|
||||
int32_t syncNodeOnAppendEntriesReply(SSyncNode* ths, SyncAppendEntriesReply* pMsg);
|
||||
int32_t syncNodeOnAppendEntriesReply(SSyncNode* ths, const SRpcMsg* pMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -34,9 +34,7 @@ extern "C" {
|
|||
// mdest |-> j])
|
||||
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
|
||||
|
||||
int32_t syncNodeElect(SSyncNode* pSyncNode);
|
||||
int32_t syncNodeRequestVotePeers(SSyncNode* pSyncNode);
|
||||
int32_t syncNodeSendRequestVote(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncRequestVote* pMsg);
|
||||
int32_t syncNodeElect(SSyncNode* pNode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -30,8 +30,6 @@ extern "C" {
|
|||
#define ELECT_TIMER_MS_RANGE (ELECT_TIMER_MS_MAX - ELECT_TIMER_MS_MIN)
|
||||
#define HEARTBEAT_TIMER_MS 1000
|
||||
|
||||
#define EMPTY_RAFT_ID ((SRaftId){.addr = 0, .vgId = 0})
|
||||
|
||||
typedef struct SSyncEnv {
|
||||
uint8_t isStart;
|
||||
|
||||
|
|
|
@ -41,22 +41,13 @@ void syncIndexMgrDestroy(SSyncIndexMgr *pSyncIndexMgr);
|
|||
void syncIndexMgrClear(SSyncIndexMgr *pSyncIndexMgr);
|
||||
void syncIndexMgrSetIndex(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId, SyncIndex index);
|
||||
SyncIndex syncIndexMgrGetIndex(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId);
|
||||
cJSON * syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr);
|
||||
char * syncIndexMgr2Str(SSyncIndexMgr *pSyncIndexMgr);
|
||||
|
||||
void syncIndexMgrSetStartTime(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId, int64_t startTime);
|
||||
int64_t syncIndexMgrGetStartTime(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId);
|
||||
void syncIndexMgrSetRecvTime(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId, int64_t recvTime);
|
||||
int64_t syncIndexMgrGetRecvTime(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId);
|
||||
|
||||
// void syncIndexMgrSetTerm(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId, SyncTerm term);
|
||||
// SyncTerm syncIndexMgrGetTerm(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId);
|
||||
|
||||
// for debug -------------------
|
||||
void syncIndexMgrPrint(SSyncIndexMgr *pObj);
|
||||
void syncIndexMgrPrint2(char *s, SSyncIndexMgr *pObj);
|
||||
void syncIndexMgrLog(SSyncIndexMgr *pObj);
|
||||
void syncIndexMgrLog2(char *s, SSyncIndexMgr *pObj);
|
||||
void syncIndexMgrSetStartTime(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId, int64_t startTime);
|
||||
int64_t syncIndexMgrGetStartTime(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId);
|
||||
void syncIndexMgrSetRecvTime(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId, int64_t recvTime);
|
||||
int64_t syncIndexMgrGetRecvTime(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId);
|
||||
void syncIndexMgrSetTerm(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId, SyncTerm term);
|
||||
SyncTerm syncIndexMgrGetTerm(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -21,55 +21,12 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include "sync.h"
|
||||
#include "syncTools.h"
|
||||
#include "taosdef.h"
|
||||
#include "tlog.h"
|
||||
#include "trpc.h"
|
||||
#include "ttimer.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
#define sFatal(...) if (sDebugFlag & DEBUG_FATAL) { taosPrintLog("SYN FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }
|
||||
#define sError(...) if (sDebugFlag & DEBUG_ERROR) { taosPrintLog("SYN ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }
|
||||
#define sWarn(...) if (sDebugFlag & DEBUG_WARN) { taosPrintLog("SYN WARN ", DEBUG_WARN, 255, __VA_ARGS__); }
|
||||
#define sInfo(...) if (sDebugFlag & DEBUG_INFO) { taosPrintLog("SYN ", DEBUG_INFO, 255, __VA_ARGS__); }
|
||||
#define sDebug(...) if (sDebugFlag & DEBUG_DEBUG) { taosPrintLog("SYN ", DEBUG_DEBUG, sDebugFlag, __VA_ARGS__); }
|
||||
#define sTrace(...) if (sDebugFlag & DEBUG_TRACE) { taosPrintLog("SYN ", DEBUG_TRACE, sDebugFlag, __VA_ARGS__); }
|
||||
|
||||
#define sLFatal(...) if (sDebugFlag & DEBUG_FATAL) { taosPrintLongString("SYN FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }
|
||||
#define sLError(...) if (sDebugFlag & DEBUG_ERROR) { taosPrintLongString("SYN ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }
|
||||
#define sLWarn(...) if (sDebugFlag & DEBUG_WARN) { taosPrintLongString("SYN WARN ", DEBUG_WARN, 255, __VA_ARGS__); }
|
||||
#define sLInfo(...) if (sDebugFlag & DEBUG_INFO) { taosPrintLongString("SYN ", DEBUG_INFO, 255, __VA_ARGS__); }
|
||||
#define sLDebug(...) if (sDebugFlag & DEBUG_DEBUG) { taosPrintLongString("SYN ", DEBUG_DEBUG, sDebugFlag, __VA_ARGS__); }
|
||||
#define sLTrace(...) if (sDebugFlag & DEBUG_TRACE) { taosPrintLongString("SYN ", DEBUG_TRACE, sDebugFlag, __VA_ARGS__); }
|
||||
|
||||
#define sNFatal(pNode, ...) if (sDebugFlag & DEBUG_FATAL) { syncPrintNodeLog("SYN FATAL ", DEBUG_FATAL, 255, pNode, __VA_ARGS__); }
|
||||
#define sNError(pNode, ...) if (sDebugFlag & DEBUG_ERROR) { syncPrintNodeLog("SYN ERROR ", DEBUG_ERROR, 255, pNode, __VA_ARGS__); }
|
||||
#define sNWarn(pNode, ...) if (sDebugFlag & DEBUG_WARN) { syncPrintNodeLog("SYN WARN ", DEBUG_WARN, 255, pNode, __VA_ARGS__); }
|
||||
#define sNInfo(pNode, ...) if (sDebugFlag & DEBUG_INFO) { syncPrintNodeLog("SYN ", DEBUG_INFO, 255, pNode, __VA_ARGS__); }
|
||||
#define sNDebug(pNode, ...) if (sDebugFlag & DEBUG_DEBUG) { syncPrintNodeLog("SYN ", DEBUG_DEBUG, sDebugFlag, pNode, __VA_ARGS__); }
|
||||
#define sNTrace(pNode, ...) if (sDebugFlag & DEBUG_TRACE) { syncPrintNodeLog("SYN ", DEBUG_TRACE, sDebugFlag, pNode, __VA_ARGS__); }
|
||||
|
||||
#define sSFatal(pSender, ...) if (sDebugFlag & DEBUG_FATAL) { syncPrintSnapshotSenderLog("SYN FATAL ", DEBUG_FATAL, 255, pSender, __VA_ARGS__); }
|
||||
#define sSError(pSender, ...) if (sDebugFlag & DEBUG_ERROR) { syncPrintSnapshotSenderLog("SYN ERROR ", DEBUG_ERROR, 255, pSender, __VA_ARGS__); }
|
||||
#define sSWarn(pSender, ...) if (sDebugFlag & DEBUG_WARN) { syncPrintSnapshotSenderLog("SYN WARN ", DEBUG_WARN, 255, pSender, __VA_ARGS__); }
|
||||
#define sSInfo(pSender, ...) if (sDebugFlag & DEBUG_INFO) { syncPrintSnapshotSenderLog("SYN ", DEBUG_INFO, 255, pSender, __VA_ARGS__); }
|
||||
#define sSDebug(pSender, ...) if (sDebugFlag & DEBUG_DEBUG) { syncPrintSnapshotSenderLog("SYN ", DEBUG_DEBUG, sDebugFlag, pSender, __VA_ARGS__); }
|
||||
#define sSTrace(pSender, ...) if (sDebugFlag & DEBUG_TRACE) { syncPrintSnapshotSenderLog("SYN ", DEBUG_TRACE, sDebugFlag, pSender, __VA_ARGS__); }
|
||||
|
||||
#define sRFatal(pReceiver, ...) if (sDebugFlag & DEBUG_FATAL) { syncPrintSnapshotReceiverLog("SYN FATAL ", DEBUG_FATAL, 255, pReceiver, __VA_ARGS__); }
|
||||
#define sRError(pReceiver, ...) if (sDebugFlag & DEBUG_ERROR) { syncPrintSnapshotReceiverLog("SYN ERROR ", DEBUG_ERROR, 255, pReceiver, __VA_ARGS__); }
|
||||
#define sRWarn(pReceiver, ...) if (sDebugFlag & DEBUG_WARN) { syncPrintSnapshotReceiverLog("SYN WARN ", DEBUG_WARN, 255, pReceiver, __VA_ARGS__); }
|
||||
#define sRInfo(pReceiver, ...) if (sDebugFlag & DEBUG_INFO) { syncPrintSnapshotReceiverLog("SYN ", DEBUG_INFO, 255, pReceiver, __VA_ARGS__); }
|
||||
#define sRDebug(pReceiver, ...) if (sDebugFlag & DEBUG_DEBUG) { syncPrintSnapshotReceiverLog("SYN ", DEBUG_DEBUG, sDebugFlag, pReceiver, __VA_ARGS__); }
|
||||
#define sRTrace(pReceiver, ...) if (sDebugFlag & DEBUG_TRACE) { syncPrintSnapshotReceiverLog("SYN ", DEBUG_TRACE, sDebugFlag, pReceiver, __VA_ARGS__); }
|
||||
|
||||
// clang-format on
|
||||
|
||||
typedef struct SyncTimeout SyncTimeout;
|
||||
typedef struct SyncClientRequest SyncClientRequest;
|
||||
typedef struct SyncPing SyncPing;
|
||||
typedef struct SyncPingReply SyncPingReply;
|
||||
typedef struct SyncRequestVote SyncRequestVote;
|
||||
typedef struct SyncRequestVoteReply SyncRequestVoteReply;
|
||||
typedef struct SyncAppendEntries SyncAppendEntries;
|
||||
|
@ -85,8 +42,19 @@ typedef struct SSyncSnapshotSender SSyncSnapshotSender;
|
|||
typedef struct SSyncSnapshotReceiver SSyncSnapshotReceiver;
|
||||
typedef struct SSyncTimer SSyncTimer;
|
||||
typedef struct SSyncHbTimerData SSyncHbTimerData;
|
||||
typedef struct SyncSnapshotSend SyncSnapshotSend;
|
||||
typedef struct SyncSnapshotRsp SyncSnapshotRsp;
|
||||
typedef struct SyncLocalCmd SyncLocalCmd;
|
||||
typedef struct SyncAppendEntriesBatch SyncAppendEntriesBatch;
|
||||
typedef struct SyncPreSnapshotReply SyncPreSnapshotReply;
|
||||
typedef struct SyncHeartbeatReply SyncHeartbeatReply;
|
||||
typedef struct SyncHeartbeat SyncHeartbeat;
|
||||
typedef struct SyncPreSnapshot SyncPreSnapshot;
|
||||
|
||||
extern bool gRaftDetailLog;
|
||||
typedef struct SRaftId {
|
||||
SyncNodeId addr;
|
||||
SyncGroupId vgId;
|
||||
} SRaftId;
|
||||
|
||||
typedef struct SSyncHbTimerData {
|
||||
SSyncNode* pSyncNode;
|
||||
|
@ -197,18 +165,6 @@ typedef struct SSyncNode {
|
|||
// peer heartbeat timer
|
||||
SSyncTimer peerHeartbeatTimerArr[TSDB_MAX_REPLICA];
|
||||
|
||||
// callback
|
||||
FpOnPingCb FpOnPing;
|
||||
FpOnPingReplyCb FpOnPingReply;
|
||||
FpOnClientRequestCb FpOnClientRequest;
|
||||
FpOnTimeoutCb FpOnTimeout;
|
||||
FpOnRequestVoteCb FpOnRequestVote;
|
||||
FpOnRequestVoteReplyCb FpOnRequestVoteReply;
|
||||
FpOnAppendEntriesCb FpOnAppendEntries;
|
||||
FpOnAppendEntriesReplyCb FpOnAppendEntriesReply;
|
||||
FpOnSnapshotCb FpOnSnapshot;
|
||||
FpOnSnapshotReplyCb FpOnSnapshotReply;
|
||||
|
||||
// tools
|
||||
SSyncRespMgr* pSyncRespMgr;
|
||||
|
||||
|
@ -241,26 +197,26 @@ void syncNodeClose(SSyncNode* pSyncNode);
|
|||
void syncNodePreClose(SSyncNode* pSyncNode);
|
||||
int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak);
|
||||
|
||||
// option
|
||||
bool syncNodeSnapshotEnable(SSyncNode* pSyncNode);
|
||||
ESyncStrategy syncNodeStrategy(SSyncNode* pSyncNode);
|
||||
SyncIndex syncNodeGetSnapshotConfigIndex(SSyncNode* pSyncNode, SyncIndex snapshotLastApplyIndex);
|
||||
|
||||
// ping --------------
|
||||
int32_t syncNodePing(SSyncNode* pSyncNode, const SRaftId* destRaftId, SyncPing* pMsg);
|
||||
int32_t syncNodePingSelf(SSyncNode* pSyncNode);
|
||||
int32_t syncNodePingPeers(SSyncNode* pSyncNode);
|
||||
int32_t syncNodePingAll(SSyncNode* pSyncNode);
|
||||
// on message ---------------------
|
||||
int32_t syncNodeOnTimeout(SSyncNode* ths, const SRpcMsg* pMsg);
|
||||
int32_t syncNodeOnClientRequest(SSyncNode* ths, SRpcMsg* pMsg, SyncIndex* pRetIndex);
|
||||
int32_t syncNodeOnRequestVote(SSyncNode* pNode, const SRpcMsg* pMsg);
|
||||
int32_t syncNodeOnRequestVoteReply(SSyncNode* pNode, const SRpcMsg* pMsg);
|
||||
int32_t syncNodeOnAppendEntries(SSyncNode* pNode, const SRpcMsg* pMsg);
|
||||
int32_t syncNodeOnAppendEntriesReply(SSyncNode* ths, const SRpcMsg* pMsg);
|
||||
int32_t syncNodeOnSnapshot(SSyncNode* ths, const SRpcMsg* pMsg);
|
||||
int32_t syncNodeOnSnapshotReply(SSyncNode* ths, const SRpcMsg* pMsg);
|
||||
int32_t syncNodeOnHeartbeat(SSyncNode* ths, const SRpcMsg* pMsg);
|
||||
int32_t syncNodeOnHeartbeatReply(SSyncNode* ths, const SRpcMsg* pMsg);
|
||||
int32_t syncNodeOnLocalCmd(SSyncNode* ths, const SRpcMsg* pMsg);
|
||||
|
||||
// timer control --------------
|
||||
int32_t syncNodeStartPingTimer(SSyncNode* pSyncNode);
|
||||
int32_t syncNodeStopPingTimer(SSyncNode* pSyncNode);
|
||||
|
||||
int32_t syncNodeStartElectTimer(SSyncNode* pSyncNode, int32_t ms);
|
||||
int32_t syncNodeStopElectTimer(SSyncNode* pSyncNode);
|
||||
int32_t syncNodeRestartElectTimer(SSyncNode* pSyncNode, int32_t ms);
|
||||
int32_t syncNodeResetElectTimer(SSyncNode* pSyncNode);
|
||||
|
||||
int32_t syncNodeStartHeartbeatTimer(SSyncNode* pSyncNode);
|
||||
int32_t syncNodeStopHeartbeatTimer(SSyncNode* pSyncNode);
|
||||
int32_t syncNodeRestartHeartbeatTimer(SSyncNode* pSyncNode);
|
||||
|
@ -268,9 +224,6 @@ int32_t syncNodeRestartHeartbeatTimer(SSyncNode* pSyncNode);
|
|||
// utils --------------
|
||||
int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, SRpcMsg* pMsg);
|
||||
int32_t syncNodeSendMsgByInfo(const SNodeInfo* nodeInfo, SSyncNode* pSyncNode, SRpcMsg* pMsg);
|
||||
char* syncNode2SimpleStr(const SSyncNode* pSyncNode);
|
||||
bool syncNodeInConfig(SSyncNode* pSyncNode, const SSyncCfg* config);
|
||||
void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* newConfig, SyncIndex lastConfigChangeIndex);
|
||||
SyncIndex syncMinMatchIndex(SSyncNode* pSyncNode);
|
||||
|
||||
// raft state change --------------
|
||||
|
@ -279,7 +232,6 @@ void syncNodeUpdateTermWithoutStepDown(SSyncNode* pSyncNode, SyncTerm term);
|
|||
void syncNodeStepDown(SSyncNode* pSyncNode, SyncTerm newTerm);
|
||||
void syncNodeBecomeFollower(SSyncNode* pSyncNode, const char* debugStr);
|
||||
void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr);
|
||||
|
||||
void syncNodeCandidate2Leader(SSyncNode* pSyncNode);
|
||||
void syncNodeFollower2Candidate(SSyncNode* pSyncNode);
|
||||
void syncNodeLeader2Follower(SSyncNode* pSyncNode);
|
||||
|
@ -302,13 +254,10 @@ SyncIndex syncNodeGetPreIndex(SSyncNode* pSyncNode, SyncIndex index);
|
|||
SyncTerm syncNodeGetPreTerm(SSyncNode* pSyncNode, SyncIndex index);
|
||||
int32_t syncNodeGetPreIndexTerm(SSyncNode* pSyncNode, SyncIndex index, SyncIndex* pPreIndex, SyncTerm* pPreTerm);
|
||||
|
||||
bool syncNodeIsOptimizedOneReplica(SSyncNode* ths, SRpcMsg* pMsg);
|
||||
int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex, uint64_t flag);
|
||||
int32_t syncNodeFollowerCommit(SSyncNode* ths, SyncIndex newCommitIndex);
|
||||
int32_t syncNodePreCommit(SSyncNode* ths, SSyncRaftEntry* pEntry, int32_t code);
|
||||
|
||||
int32_t syncNodeUpdateNewConfigIndex(SSyncNode* ths, SSyncCfg* pNewCfg);
|
||||
|
||||
bool syncNodeInRaftGroup(SSyncNode* ths, SRaftId* pRaftId);
|
||||
SSyncSnapshotSender* syncNodeGetSnapshotSender(SSyncNode* ths, SRaftId* pDestId);
|
||||
SSyncTimer* syncNodeGetHbTimer(SSyncNode* ths, SRaftId* pDestId);
|
||||
|
@ -318,61 +267,10 @@ bool syncNodeNeedSendAppendEntries(SSyncNode* ths, const SRaftId* pDestId, const
|
|||
int32_t syncGetSnapshotMeta(int64_t rid, struct SSnapshotMeta* sMeta);
|
||||
int32_t syncGetSnapshotMetaByIndex(int64_t rid, SyncIndex snapshotIndex, struct SSnapshotMeta* sMeta);
|
||||
|
||||
bool syncNodeCanChange(SSyncNode* pSyncNode);
|
||||
|
||||
int32_t syncNodeLeaderTransfer(SSyncNode* pSyncNode);
|
||||
int32_t syncNodeLeaderTransferTo(SSyncNode* pSyncNode, SNodeInfo newLeader);
|
||||
int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* pEntry);
|
||||
|
||||
int32_t syncNodeDynamicQuorum(const SSyncNode* pSyncNode);
|
||||
|
||||
bool syncNodeIsMnode(SSyncNode* pSyncNode);
|
||||
int32_t syncNodePeerStateInit(SSyncNode* pSyncNode);
|
||||
|
||||
// trace log
|
||||
void syncLogRecvTimer(SSyncNode* pSyncNode, const SyncTimeout* pMsg, const char* s);
|
||||
void syncLogRecvLocalCmd(SSyncNode* pSyncNode, const SyncLocalCmd* pMsg, const char* s);
|
||||
|
||||
void syncLogSendRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, const char* s);
|
||||
void syncLogRecvRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, const char* s);
|
||||
|
||||
void syncLogSendRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s);
|
||||
void syncLogRecvRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s);
|
||||
|
||||
void syncLogSendAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMsg, const char* s);
|
||||
void syncLogRecvAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMsg, const char* s);
|
||||
|
||||
void syncLogSendAppendEntriesBatch(SSyncNode* pSyncNode, const SyncAppendEntriesBatch* pMsg, const char* s);
|
||||
void syncLogRecvAppendEntriesBatch(SSyncNode* pSyncNode, const SyncAppendEntriesBatch* pMsg, const char* s);
|
||||
|
||||
void syncLogSendAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s);
|
||||
void syncLogRecvAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s);
|
||||
|
||||
void syncLogSendHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, const char* s);
|
||||
void syncLogRecvHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, const char* s);
|
||||
|
||||
void syncLogSendHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s);
|
||||
void syncLogRecvHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s);
|
||||
|
||||
void syncLogSendSyncPreSnapshot(SSyncNode* pSyncNode, const SyncPreSnapshot* pMsg, const char* s);
|
||||
void syncLogRecvSyncPreSnapshot(SSyncNode* pSyncNode, const SyncPreSnapshot* pMsg, const char* s);
|
||||
|
||||
void syncLogSendSyncPreSnapshotReply(SSyncNode* pSyncNode, const SyncPreSnapshotReply* pMsg, const char* s);
|
||||
void syncLogRecvSyncPreSnapshotReply(SSyncNode* pSyncNode, const SyncPreSnapshotReply* pMsg, const char* s);
|
||||
|
||||
void syncLogSendSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* pMsg, const char* s);
|
||||
void syncLogRecvSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* pMsg, const char* s);
|
||||
|
||||
void syncLogSendSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s);
|
||||
void syncLogRecvSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s);
|
||||
|
||||
// syncUtil.h
|
||||
void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNode* pNode, const char* format, ...);
|
||||
void syncPrintSnapshotSenderLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotSender* pSender,
|
||||
const char* format, ...);
|
||||
void syncPrintSnapshotReceiverLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotReceiver* pReceiver,
|
||||
const char* format, ...);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -22,17 +22,239 @@ extern "C" {
|
|||
|
||||
#include "syncInt.h"
|
||||
|
||||
// ---------------------------------------------
|
||||
cJSON* syncRpcMsg2Json(SRpcMsg* pRpcMsg);
|
||||
cJSON* syncRpcUnknownMsg2Json();
|
||||
char* syncRpcMsg2Str(SRpcMsg* pRpcMsg);
|
||||
typedef enum ESyncTimeoutType {
|
||||
SYNC_TIMEOUT_PING = 100,
|
||||
SYNC_TIMEOUT_ELECTION,
|
||||
SYNC_TIMEOUT_HEARTBEAT,
|
||||
} ESyncTimeoutType;
|
||||
|
||||
// for debug ----------------------
|
||||
void syncRpcMsgPrint(SRpcMsg* pMsg);
|
||||
void syncRpcMsgPrint2(char* s, SRpcMsg* pMsg);
|
||||
void syncRpcMsgLog(SRpcMsg* pMsg);
|
||||
void syncRpcMsgLog2(char* s, SRpcMsg* pMsg);
|
||||
// ---------------------------------------------
|
||||
typedef struct SyncTimeout {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
ESyncTimeoutType timeoutType;
|
||||
uint64_t logicClock;
|
||||
int32_t timerMS;
|
||||
void* data; // need optimized
|
||||
} SyncTimeout;
|
||||
|
||||
typedef struct SyncClientRequest {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType; // TDMT_SYNC_CLIENT_REQUEST
|
||||
uint32_t originalRpcType; // origin RpcMsg msgType
|
||||
uint64_t seqNum;
|
||||
bool isWeak;
|
||||
uint32_t dataLen; // origin RpcMsg.contLen
|
||||
char data[]; // origin RpcMsg.pCont
|
||||
} SyncClientRequest;
|
||||
|
||||
typedef struct SyncClientRequestReply {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
int32_t errCode;
|
||||
SRaftId leaderHint;
|
||||
} SyncClientRequestReply;
|
||||
|
||||
typedef struct SyncRequestVote {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
// private data
|
||||
SyncTerm term;
|
||||
SyncIndex lastLogIndex;
|
||||
SyncTerm lastLogTerm;
|
||||
} SyncRequestVote;
|
||||
|
||||
typedef struct SyncRequestVoteReply {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
// private data
|
||||
SyncTerm term;
|
||||
bool voteGranted;
|
||||
} SyncRequestVoteReply;
|
||||
|
||||
typedef struct SyncAppendEntries {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
|
||||
// private data
|
||||
SyncTerm term;
|
||||
SyncIndex prevLogIndex;
|
||||
SyncTerm prevLogTerm;
|
||||
SyncIndex commitIndex;
|
||||
SyncTerm privateTerm;
|
||||
uint32_t dataLen;
|
||||
char data[];
|
||||
} SyncAppendEntries;
|
||||
|
||||
typedef struct SyncAppendEntriesReply {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
// private data
|
||||
SyncTerm term;
|
||||
SyncTerm privateTerm;
|
||||
bool success;
|
||||
SyncIndex matchIndex;
|
||||
SyncIndex lastSendIndex;
|
||||
int64_t startTime;
|
||||
} SyncAppendEntriesReply;
|
||||
|
||||
typedef struct SyncHeartbeat {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
|
||||
// private data
|
||||
SyncTerm term;
|
||||
SyncIndex commitIndex;
|
||||
SyncTerm privateTerm;
|
||||
SyncTerm minMatchIndex;
|
||||
} SyncHeartbeat;
|
||||
|
||||
typedef struct SyncHeartbeatReply {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
|
||||
// private data
|
||||
SyncTerm term;
|
||||
SyncTerm privateTerm;
|
||||
int64_t startTime;
|
||||
} SyncHeartbeatReply;
|
||||
|
||||
typedef struct SyncPreSnapshot {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
|
||||
// private data
|
||||
SyncTerm term;
|
||||
} SyncPreSnapshot;
|
||||
|
||||
typedef struct SyncPreSnapshotReply {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
|
||||
// private data
|
||||
SyncTerm term;
|
||||
SyncIndex snapStart;
|
||||
} SyncPreSnapshotReply;
|
||||
|
||||
typedef struct SyncApplyMsg {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType; // user SyncApplyMsg msgType
|
||||
uint32_t originalRpcType; // user RpcMsg msgType
|
||||
SFsmCbMeta fsmMeta;
|
||||
uint32_t dataLen; // user RpcMsg.contLen
|
||||
char data[]; // user RpcMsg.pCont
|
||||
} SyncApplyMsg;
|
||||
|
||||
typedef struct SyncSnapshotSend {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
|
||||
SyncTerm term;
|
||||
SyncIndex beginIndex; // snapshot.beginIndex
|
||||
SyncIndex lastIndex; // snapshot.lastIndex
|
||||
SyncTerm lastTerm; // snapshot.lastTerm
|
||||
SyncIndex lastConfigIndex; // snapshot.lastConfigIndex
|
||||
SSyncCfg lastConfig;
|
||||
int64_t startTime;
|
||||
int32_t seq;
|
||||
uint32_t dataLen;
|
||||
char data[];
|
||||
} SyncSnapshotSend;
|
||||
|
||||
typedef struct SyncSnapshotRsp {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
|
||||
SyncTerm term;
|
||||
SyncIndex lastIndex;
|
||||
SyncTerm lastTerm;
|
||||
int64_t startTime;
|
||||
int32_t ack;
|
||||
int32_t code;
|
||||
SyncIndex snapBeginIndex; // when ack = SYNC_SNAPSHOT_SEQ_BEGIN, it's valid
|
||||
} SyncSnapshotRsp;
|
||||
|
||||
typedef struct SyncLeaderTransfer {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
/*
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
*/
|
||||
SNodeInfo newNodeInfo;
|
||||
SRaftId newLeaderId;
|
||||
} SyncLeaderTransfer;
|
||||
|
||||
typedef enum {
|
||||
SYNC_LOCAL_CMD_STEP_DOWN = 100,
|
||||
SYNC_LOCAL_CMD_FOLLOWER_CMT,
|
||||
} ESyncLocalCmd;
|
||||
|
||||
typedef struct SyncLocalCmd {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
|
||||
int32_t cmd;
|
||||
SyncTerm sdNewTerm; // step down new term
|
||||
SyncIndex fcIndex; // follower commit index
|
||||
} SyncLocalCmd;
|
||||
|
||||
int32_t syncBuildTimeout(SRpcMsg* pMsg, ESyncTimeoutType ttype, uint64_t logicClock, int32_t ms, SSyncNode* pNode);
|
||||
int32_t syncBuildClientRequest(SRpcMsg* pMsg, const SRpcMsg* pOriginal, uint64_t seq, bool isWeak, int32_t vgId);
|
||||
int32_t syncBuildClientRequestFromNoopEntry(SRpcMsg* pMsg, const SSyncRaftEntry* pEntry, int32_t vgId);
|
||||
int32_t syncBuildRequestVote(SRpcMsg* pMsg, int32_t vgId);
|
||||
int32_t syncBuildRequestVoteReply(SRpcMsg* pMsg, int32_t vgId);
|
||||
int32_t syncBuildAppendEntries(SRpcMsg* pMsg, int32_t dataLen, int32_t vgId);
|
||||
int32_t syncBuildAppendEntriesReply(SRpcMsg* pMsg, int32_t vgId);
|
||||
int32_t syncBuildHeartbeat(SRpcMsg* pMsg, int32_t vgId);
|
||||
int32_t syncBuildHeartbeatReply(SRpcMsg* pMsg, int32_t vgId);
|
||||
int32_t syncBuildPreSnapshot(SRpcMsg* pMsg, int32_t vgId);
|
||||
int32_t syncBuildPreSnapshotReply(SRpcMsg* pMsg, int32_t vgId);
|
||||
int32_t syncBuildApplyMsg(SRpcMsg* pMsg, const SRpcMsg* pOriginal, int32_t vgId, SFsmCbMeta* pMeta);
|
||||
int32_t syncBuildSnapshotSend(SRpcMsg* pMsg, int32_t dataLen, int32_t vgId);
|
||||
int32_t syncBuildSnapshotSendRsp(SRpcMsg* pMsg, int32_t vgId);
|
||||
int32_t syncBuildLeaderTransfer(SRpcMsg* pMsg, int32_t vgId);
|
||||
int32_t syncBuildLocalCmd(SRpcMsg* pMsg, int32_t vgId);
|
||||
|
||||
const char* syncTimerTypeStr(ESyncTimeoutType timerType);
|
||||
const char* syncLocalCmdGetStr(ESyncLocalCmd cmd);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -22,11 +22,9 @@ extern "C" {
|
|||
|
||||
#include "syncInt.h"
|
||||
|
||||
#define CONFIG_FILE_LEN 2048
|
||||
|
||||
#define CONFIG_FILE_LEN 2048
|
||||
#define MAX_CONFIG_INDEX_COUNT 256
|
||||
|
||||
// SRaftCfgIndex ------------------------------------------
|
||||
typedef struct SRaftCfgIndex {
|
||||
TdFilePtr pFile;
|
||||
char path[TSDB_FILENAME_LEN * 2];
|
||||
|
@ -44,11 +42,8 @@ cJSON *raftCfgIndex2Json(SRaftCfgIndex *pRaftCfgIndex);
|
|||
char *raftCfgIndex2Str(SRaftCfgIndex *pRaftCfgIndex);
|
||||
int32_t raftCfgIndexFromJson(const cJSON *pRoot, SRaftCfgIndex *pRaftCfgIndex);
|
||||
int32_t raftCfgIndexFromStr(const char *s, SRaftCfgIndex *pRaftCfgIndex);
|
||||
|
||||
int32_t raftCfgIndexCreateFile(const char *path);
|
||||
|
||||
// ---------------------------------------------------------
|
||||
|
||||
typedef struct SRaftCfg {
|
||||
SSyncCfg cfg;
|
||||
TdFilePtr pFile;
|
||||
|
@ -68,11 +63,9 @@ int32_t raftCfgClose(SRaftCfg *pRaftCfg);
|
|||
int32_t raftCfgPersist(SRaftCfg *pRaftCfg);
|
||||
int32_t raftCfgAddConfigIndex(SRaftCfg *pRaftCfg, SyncIndex configIndex);
|
||||
|
||||
cJSON *syncCfg2Json(SSyncCfg *pSyncCfg);
|
||||
char *syncCfg2Str(SSyncCfg *pSyncCfg);
|
||||
void syncCfg2SimpleStr(const SSyncCfg *pCfg, char *str, int32_t bufLen);
|
||||
cJSON *syncCfg2Json(SSyncCfg *pSyncCfg);
|
||||
int32_t syncCfgFromJson(const cJSON *pRoot, SSyncCfg *pSyncCfg);
|
||||
int32_t syncCfgFromStr(const char *s, SSyncCfg *pSyncCfg);
|
||||
|
||||
cJSON *raftCfg2Json(SRaftCfg *pRaftCfg);
|
||||
char *raftCfg2Str(SRaftCfg *pRaftCfg);
|
||||
|
|
|
@ -38,7 +38,6 @@ SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode);
|
|||
void logStoreDestory(SSyncLogStore* pLogStore);
|
||||
|
||||
SyncIndex logStoreFirstIndex(SSyncLogStore* pLogStore);
|
||||
|
||||
SyncIndex logStoreWalCommitVer(SSyncLogStore* pLogStore);
|
||||
|
||||
SyncIndex raftLogWriteIndex(struct SSyncLogStore* pLogStore);
|
||||
|
|
|
@ -25,6 +25,8 @@ extern "C" {
|
|||
#define RAFT_STORE_BLOCK_SIZE 512
|
||||
#define RAFT_STORE_PATH_LEN (TSDB_FILENAME_LEN * 2)
|
||||
|
||||
#define EMPTY_RAFT_ID ((SRaftId){.addr = 0, .vgId = 0})
|
||||
|
||||
typedef struct SRaftStore {
|
||||
SyncTerm currentTerm;
|
||||
SRaftId voteFor;
|
||||
|
@ -38,20 +40,11 @@ int32_t raftStorePersist(SRaftStore *pRaftStore);
|
|||
int32_t raftStoreSerialize(SRaftStore *pRaftStore, char *buf, size_t len);
|
||||
int32_t raftStoreDeserialize(SRaftStore *pRaftStore, char *buf, size_t len);
|
||||
|
||||
bool raftStoreHasVoted(SRaftStore *pRaftStore);
|
||||
void raftStoreVote(SRaftStore *pRaftStore, SRaftId *pRaftId);
|
||||
void raftStoreClearVote(SRaftStore *pRaftStore);
|
||||
void raftStoreNextTerm(SRaftStore *pRaftStore);
|
||||
void raftStoreSetTerm(SRaftStore *pRaftStore, SyncTerm term);
|
||||
int32_t raftStoreFromJson(SRaftStore *pRaftStore, cJSON *pJson);
|
||||
cJSON *raftStore2Json(SRaftStore *pRaftStore);
|
||||
char *raftStore2Str(SRaftStore *pRaftStore);
|
||||
|
||||
// for debug -------------------
|
||||
void raftStorePrint(SRaftStore *pObj);
|
||||
void raftStorePrint2(char *s, SRaftStore *pObj);
|
||||
void raftStoreLog(SRaftStore *pObj);
|
||||
void raftStoreLog2(char *s, SRaftStore *pObj);
|
||||
bool raftStoreHasVoted(SRaftStore *pRaftStore);
|
||||
void raftStoreVote(SRaftStore *pRaftStore, SRaftId *pRaftId);
|
||||
void raftStoreClearVote(SRaftStore *pRaftStore);
|
||||
void raftStoreNextTerm(SRaftStore *pRaftStore);
|
||||
void raftStoreSetTerm(SRaftStore *pRaftStore, SyncTerm term);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -48,14 +48,11 @@ extern "C" {
|
|||
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
|
||||
|
||||
int32_t syncNodeHeartbeatPeers(SSyncNode* pSyncNode);
|
||||
int32_t syncNodeSendHeartbeat(SSyncNode* pSyncNode, const SRaftId* pDestId, const SyncHeartbeat* pMsg);
|
||||
int32_t syncNodeSendHeartbeat(SSyncNode* pSyncNode, const SRaftId* pDestId, SRpcMsg* pMsg);
|
||||
|
||||
int32_t syncNodeReplicate(SSyncNode* pSyncNode);
|
||||
int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId, bool snapshot);
|
||||
|
||||
int32_t syncNodeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* pDestId, const SyncAppendEntries* pMsg);
|
||||
int32_t syncNodeMaybeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* pDestId, const SyncAppendEntries* pMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -21,7 +21,6 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include "syncInt.h"
|
||||
#include "syncMessage.h"
|
||||
|
||||
// TLA+ Spec
|
||||
// HandleRequestVoteRequest(i, j, m) ==
|
||||
|
@ -45,7 +44,7 @@ extern "C" {
|
|||
// m)
|
||||
// /\ UNCHANGED <<state, currentTerm, candidateVars, leaderVars, logVars>>
|
||||
//
|
||||
int32_t syncNodeOnRequestVote(SSyncNode* ths, SyncRequestVote* pMsg);
|
||||
int32_t syncNodeOnRequestVote(SSyncNode* pNode, const SRpcMsg* pMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include "syncInt.h"
|
||||
#include "syncMessage.h"
|
||||
|
||||
// TLA+ Spec
|
||||
// HandleRequestVoteResponse(i, j, m) ==
|
||||
|
@ -40,7 +39,7 @@ extern "C" {
|
|||
// /\ Discard(m)
|
||||
// /\ UNCHANGED <<serverVars, votedFor, leaderVars, logVars>>
|
||||
//
|
||||
int32_t syncNodeOnRequestVoteReply(SSyncNode* ths, SyncRequestVoteReply* pMsg);
|
||||
int32_t syncNodeOnRequestVoteReply(SSyncNode* ths, const SRpcMsg* pMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -84,8 +84,8 @@ bool snapshotReceiverIsStart(SSyncSnapshotReceiver *pReceiver)
|
|||
void snapshotReceiverForceStop(SSyncSnapshotReceiver *pReceiver);
|
||||
|
||||
// on message
|
||||
int32_t syncNodeOnSnapshot(SSyncNode *ths, SyncSnapshotSend *pMsg);
|
||||
int32_t syncNodeOnSnapshotReply(SSyncNode *ths, SyncSnapshotRsp *pMsg);
|
||||
int32_t syncNodeOnSnapshot(SSyncNode *ths, const SRpcMsg *pMsg);
|
||||
int32_t syncNodeOnSnapshotReply(SSyncNode *ths, const SRpcMsg *pMsg);
|
||||
|
||||
// start
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ extern "C" {
|
|||
// /\ voterLog' = [voterLog EXCEPT ![i] = [j \in {} |-> <<>>]]
|
||||
// /\ UNCHANGED <<messages, leaderVars, logVars>>
|
||||
//
|
||||
int32_t syncNodeOnTimer(SSyncNode* ths, SyncTimeout* pMsg);
|
||||
int32_t syncNodeOnTimeout(SSyncNode* ths, const SRpcMsg* pMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,755 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_LIBS_SYNC_TOOLS_H
|
||||
#define _TD_LIBS_SYNC_TOOLS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// ------------------ ds -------------------
|
||||
typedef struct SRaftId {
|
||||
SyncNodeId addr;
|
||||
SyncGroupId vgId;
|
||||
} SRaftId;
|
||||
|
||||
// ------------------ for debug -------------------
|
||||
void syncRpcMsgPrint(SRpcMsg* pMsg);
|
||||
void syncRpcMsgPrint2(char* s, SRpcMsg* pMsg);
|
||||
void syncRpcMsgLog(SRpcMsg* pMsg);
|
||||
void syncRpcMsgLog2(char* s, SRpcMsg* pMsg);
|
||||
|
||||
// ------------------ for compile -------------------
|
||||
typedef struct SSyncBuffer {
|
||||
void* data;
|
||||
size_t len;
|
||||
} SSyncBuffer;
|
||||
|
||||
typedef struct SNodesRole {
|
||||
int32_t replicaNum;
|
||||
SNodeInfo nodeInfo[TSDB_MAX_REPLICA];
|
||||
ESyncState role[TSDB_MAX_REPLICA];
|
||||
} SNodesRole;
|
||||
|
||||
typedef struct SStateMgr {
|
||||
void* data;
|
||||
|
||||
int32_t (*getCurrentTerm)(struct SStateMgr* pMgr, SyncTerm* pCurrentTerm);
|
||||
int32_t (*persistCurrentTerm)(struct SStateMgr* pMgr, SyncTerm pCurrentTerm);
|
||||
|
||||
int32_t (*getVoteFor)(struct SStateMgr* pMgr, SyncNodeId* pVoteFor);
|
||||
int32_t (*persistVoteFor)(struct SStateMgr* pMgr, SyncNodeId voteFor);
|
||||
|
||||
int32_t (*getSyncCfg)(struct SStateMgr* pMgr, SSyncCfg* pSyncCfg);
|
||||
int32_t (*persistSyncCfg)(struct SStateMgr* pMgr, SSyncCfg* pSyncCfg);
|
||||
|
||||
} SStateMgr;
|
||||
|
||||
// ------------------ for message process -------------------
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef struct SyncPing {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
// private data
|
||||
uint32_t dataLen;
|
||||
char data[];
|
||||
} SyncPing;
|
||||
|
||||
SyncPing* syncPingBuild(uint32_t dataLen);
|
||||
SyncPing* syncPingBuild2(const SRaftId* srcId, const SRaftId* destId, int32_t vgId, const char* str);
|
||||
SyncPing* syncPingBuild3(const SRaftId* srcId, const SRaftId* destId, int32_t vgId);
|
||||
void syncPingDestroy(SyncPing* pMsg);
|
||||
void syncPingSerialize(const SyncPing* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncPingDeserialize(const char* buf, uint32_t len, SyncPing* pMsg);
|
||||
char* syncPingSerialize2(const SyncPing* pMsg, uint32_t* len);
|
||||
SyncPing* syncPingDeserialize2(const char* buf, uint32_t len);
|
||||
int32_t syncPingSerialize3(const SyncPing* pMsg, char* buf, int32_t bufLen);
|
||||
SyncPing* syncPingDeserialize3(void* buf, int32_t bufLen);
|
||||
void syncPing2RpcMsg(const SyncPing* pMsg, SRpcMsg* pRpcMsg);
|
||||
void syncPingFromRpcMsg(const SRpcMsg* pRpcMsg, SyncPing* pMsg);
|
||||
SyncPing* syncPingFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||
cJSON* syncPing2Json(const SyncPing* pMsg);
|
||||
char* syncPing2Str(const SyncPing* pMsg);
|
||||
|
||||
// for debug ----------------------
|
||||
void syncPingPrint(const SyncPing* pMsg);
|
||||
void syncPingPrint2(char* s, const SyncPing* pMsg);
|
||||
void syncPingLog(const SyncPing* pMsg);
|
||||
void syncPingLog2(char* s, const SyncPing* pMsg);
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef struct SyncPingReply {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
// private data
|
||||
uint32_t dataLen;
|
||||
char data[];
|
||||
} SyncPingReply;
|
||||
|
||||
SyncPingReply* syncPingReplyBuild(uint32_t dataLen);
|
||||
SyncPingReply* syncPingReplyBuild2(const SRaftId* srcId, const SRaftId* destId, int32_t vgId, const char* str);
|
||||
SyncPingReply* syncPingReplyBuild3(const SRaftId* srcId, const SRaftId* destId, int32_t vgId);
|
||||
void syncPingReplyDestroy(SyncPingReply* pMsg);
|
||||
void syncPingReplySerialize(const SyncPingReply* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncPingReplyDeserialize(const char* buf, uint32_t len, SyncPingReply* pMsg);
|
||||
char* syncPingReplySerialize2(const SyncPingReply* pMsg, uint32_t* len);
|
||||
SyncPingReply* syncPingReplyDeserialize2(const char* buf, uint32_t len);
|
||||
int32_t syncPingReplySerialize3(const SyncPingReply* pMsg, char* buf, int32_t bufLen);
|
||||
SyncPingReply* syncPingReplyDeserialize3(void* buf, int32_t bufLen);
|
||||
void syncPingReply2RpcMsg(const SyncPingReply* pMsg, SRpcMsg* pRpcMsg);
|
||||
void syncPingReplyFromRpcMsg(const SRpcMsg* pRpcMsg, SyncPingReply* pMsg);
|
||||
SyncPingReply* syncPingReplyFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||
cJSON* syncPingReply2Json(const SyncPingReply* pMsg);
|
||||
char* syncPingReply2Str(const SyncPingReply* pMsg);
|
||||
|
||||
// for debug ----------------------
|
||||
void syncPingReplyPrint(const SyncPingReply* pMsg);
|
||||
void syncPingReplyPrint2(char* s, const SyncPingReply* pMsg);
|
||||
void syncPingReplyLog(const SyncPingReply* pMsg);
|
||||
void syncPingReplyLog2(char* s, const SyncPingReply* pMsg);
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef enum ESyncTimeoutType {
|
||||
SYNC_TIMEOUT_PING = 100,
|
||||
SYNC_TIMEOUT_ELECTION,
|
||||
SYNC_TIMEOUT_HEARTBEAT,
|
||||
} ESyncTimeoutType;
|
||||
|
||||
const char* syncTimerTypeStr(enum ESyncTimeoutType timerType);
|
||||
|
||||
typedef struct SyncTimeout {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
ESyncTimeoutType timeoutType;
|
||||
uint64_t logicClock;
|
||||
int32_t timerMS;
|
||||
void* data; // need optimized
|
||||
} SyncTimeout;
|
||||
|
||||
SyncTimeout* syncTimeoutBuild();
|
||||
SyncTimeout* syncTimeoutBuild2(ESyncTimeoutType timeoutType, uint64_t logicClock, int32_t timerMS, int32_t vgId,
|
||||
void* data);
|
||||
void syncTimeoutDestroy(SyncTimeout* pMsg);
|
||||
void syncTimeoutSerialize(const SyncTimeout* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncTimeoutDeserialize(const char* buf, uint32_t len, SyncTimeout* pMsg);
|
||||
char* syncTimeoutSerialize2(const SyncTimeout* pMsg, uint32_t* len);
|
||||
SyncTimeout* syncTimeoutDeserialize2(const char* buf, uint32_t len);
|
||||
void syncTimeout2RpcMsg(const SyncTimeout* pMsg, SRpcMsg* pRpcMsg);
|
||||
void syncTimeoutFromRpcMsg(const SRpcMsg* pRpcMsg, SyncTimeout* pMsg);
|
||||
SyncTimeout* syncTimeoutFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||
cJSON* syncTimeout2Json(const SyncTimeout* pMsg);
|
||||
char* syncTimeout2Str(const SyncTimeout* pMsg);
|
||||
|
||||
// for debug ----------------------
|
||||
void syncTimeoutPrint(const SyncTimeout* pMsg);
|
||||
void syncTimeoutPrint2(char* s, const SyncTimeout* pMsg);
|
||||
void syncTimeoutLog(const SyncTimeout* pMsg);
|
||||
void syncTimeoutLog2(char* s, const SyncTimeout* pMsg);
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef struct SyncClientRequest {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType; // TDMT_SYNC_CLIENT_REQUEST
|
||||
uint32_t originalRpcType; // origin RpcMsg msgType
|
||||
uint64_t seqNum;
|
||||
bool isWeak;
|
||||
uint32_t dataLen; // origin RpcMsg.contLen
|
||||
char data[]; // origin RpcMsg.pCont
|
||||
} SyncClientRequest;
|
||||
|
||||
SyncClientRequest* syncClientRequestAlloc(uint32_t dataLen);
|
||||
int32_t syncClientRequestBuildFromRpcMsg(SRpcMsg* pClientRequestRpcMsg, const SRpcMsg* pOriginalRpcMsg, uint64_t seqNum,
|
||||
bool isWeak, int32_t vgId);
|
||||
int32_t syncClientRequestBuildFromNoopEntry(SRpcMsg* pClientRequestRpcMsg, const SSyncRaftEntry* pEntry, int32_t vgId);
|
||||
void syncClientRequest2RpcMsg(const SyncClientRequest* pMsg, SRpcMsg* pRpcMsg); // step 2
|
||||
void syncClientRequestFromRpcMsg(const SRpcMsg* pRpcMsg, SyncClientRequest* pMsg);
|
||||
cJSON* syncClientRequest2Json(const SyncClientRequest* pMsg);
|
||||
char* syncClientRequest2Str(const SyncClientRequest* pMsg);
|
||||
|
||||
// for debug ----------------------
|
||||
void syncClientRequestPrint(const SyncClientRequest* pMsg);
|
||||
void syncClientRequestPrint2(char* s, const SyncClientRequest* pMsg);
|
||||
void syncClientRequestLog(const SyncClientRequest* pMsg);
|
||||
void syncClientRequestLog2(char* s, const SyncClientRequest* pMsg);
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef struct SRaftMeta {
|
||||
uint64_t seqNum;
|
||||
bool isWeak;
|
||||
} SRaftMeta;
|
||||
|
||||
// block1:
|
||||
// block2: SRaftMeta array
|
||||
// block3: rpc msg array (with pCont pointer)
|
||||
|
||||
typedef struct SyncClientRequestBatch {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType; // TDMT_SYNC_CLIENT_REQUEST_BATCH
|
||||
uint32_t dataCount;
|
||||
uint32_t dataLen;
|
||||
char data[]; // block2, block3
|
||||
} SyncClientRequestBatch;
|
||||
|
||||
SyncClientRequestBatch* syncClientRequestBatchBuild(SRpcMsg** rpcMsgPArr, SRaftMeta* raftArr, int32_t arrSize,
|
||||
int32_t vgId);
|
||||
void syncClientRequestBatch2RpcMsg(const SyncClientRequestBatch* pSyncMsg, SRpcMsg* pRpcMsg);
|
||||
void syncClientRequestBatchDestroy(SyncClientRequestBatch* pMsg);
|
||||
void syncClientRequestBatchDestroyDeep(SyncClientRequestBatch* pMsg);
|
||||
SRaftMeta* syncClientRequestBatchMetaArr(const SyncClientRequestBatch* pSyncMsg);
|
||||
SRpcMsg* syncClientRequestBatchRpcMsgArr(const SyncClientRequestBatch* pSyncMsg);
|
||||
SyncClientRequestBatch* syncClientRequestBatchFromRpcMsg(const SRpcMsg* pRpcMsg);
|
||||
cJSON* syncClientRequestBatch2Json(const SyncClientRequestBatch* pMsg);
|
||||
char* syncClientRequestBatch2Str(const SyncClientRequestBatch* pMsg);
|
||||
|
||||
// for debug ----------------------
|
||||
void syncClientRequestBatchPrint(const SyncClientRequestBatch* pMsg);
|
||||
void syncClientRequestBatchPrint2(char* s, const SyncClientRequestBatch* pMsg);
|
||||
void syncClientRequestBatchLog(const SyncClientRequestBatch* pMsg);
|
||||
void syncClientRequestBatchLog2(char* s, const SyncClientRequestBatch* pMsg);
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef struct SyncClientRequestReply {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
int32_t errCode;
|
||||
SRaftId leaderHint;
|
||||
} SyncClientRequestReply;
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef struct SyncRequestVote {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
// private data
|
||||
SyncTerm term;
|
||||
SyncIndex lastLogIndex;
|
||||
SyncTerm lastLogTerm;
|
||||
} SyncRequestVote;
|
||||
|
||||
SyncRequestVote* syncRequestVoteBuild(int32_t vgId);
|
||||
void syncRequestVoteDestroy(SyncRequestVote* pMsg);
|
||||
void syncRequestVoteSerialize(const SyncRequestVote* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncRequestVoteDeserialize(const char* buf, uint32_t len, SyncRequestVote* pMsg);
|
||||
char* syncRequestVoteSerialize2(const SyncRequestVote* pMsg, uint32_t* len);
|
||||
SyncRequestVote* syncRequestVoteDeserialize2(const char* buf, uint32_t len);
|
||||
void syncRequestVote2RpcMsg(const SyncRequestVote* pMsg, SRpcMsg* pRpcMsg);
|
||||
void syncRequestVoteFromRpcMsg(const SRpcMsg* pRpcMsg, SyncRequestVote* pMsg);
|
||||
SyncRequestVote* syncRequestVoteFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||
cJSON* syncRequestVote2Json(const SyncRequestVote* pMsg);
|
||||
char* syncRequestVote2Str(const SyncRequestVote* pMsg);
|
||||
|
||||
// for debug ----------------------
|
||||
void syncRequestVotePrint(const SyncRequestVote* pMsg);
|
||||
void syncRequestVotePrint2(char* s, const SyncRequestVote* pMsg);
|
||||
void syncRequestVoteLog(const SyncRequestVote* pMsg);
|
||||
void syncRequestVoteLog2(char* s, const SyncRequestVote* pMsg);
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef struct SyncRequestVoteReply {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
// private data
|
||||
SyncTerm term;
|
||||
bool voteGranted;
|
||||
} SyncRequestVoteReply;
|
||||
|
||||
SyncRequestVoteReply* syncRequestVoteReplyBuild(int32_t vgId);
|
||||
void syncRequestVoteReplyDestroy(SyncRequestVoteReply* pMsg);
|
||||
void syncRequestVoteReplySerialize(const SyncRequestVoteReply* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncRequestVoteReplyDeserialize(const char* buf, uint32_t len, SyncRequestVoteReply* pMsg);
|
||||
char* syncRequestVoteReplySerialize2(const SyncRequestVoteReply* pMsg, uint32_t* len);
|
||||
SyncRequestVoteReply* syncRequestVoteReplyDeserialize2(const char* buf, uint32_t len);
|
||||
void syncRequestVoteReply2RpcMsg(const SyncRequestVoteReply* pMsg, SRpcMsg* pRpcMsg);
|
||||
void syncRequestVoteReplyFromRpcMsg(const SRpcMsg* pRpcMsg, SyncRequestVoteReply* pMsg);
|
||||
SyncRequestVoteReply* syncRequestVoteReplyFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||
cJSON* syncRequestVoteReply2Json(const SyncRequestVoteReply* pMsg);
|
||||
char* syncRequestVoteReply2Str(const SyncRequestVoteReply* pMsg);
|
||||
|
||||
// for debug ----------------------
|
||||
void syncRequestVoteReplyPrint(const SyncRequestVoteReply* pMsg);
|
||||
void syncRequestVoteReplyPrint2(char* s, const SyncRequestVoteReply* pMsg);
|
||||
void syncRequestVoteReplyLog(const SyncRequestVoteReply* pMsg);
|
||||
void syncRequestVoteReplyLog2(char* s, const SyncRequestVoteReply* pMsg);
|
||||
|
||||
// ---------------------------------------------
|
||||
// data: entry
|
||||
|
||||
typedef struct SyncAppendEntries {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
|
||||
// private data
|
||||
SyncTerm term;
|
||||
SyncIndex prevLogIndex;
|
||||
SyncTerm prevLogTerm;
|
||||
SyncIndex commitIndex;
|
||||
SyncTerm privateTerm;
|
||||
uint32_t dataLen;
|
||||
char data[];
|
||||
} SyncAppendEntries;
|
||||
|
||||
SyncAppendEntries* syncAppendEntriesBuild(uint32_t dataLen, int32_t vgId);
|
||||
void syncAppendEntriesDestroy(SyncAppendEntries* pMsg);
|
||||
void syncAppendEntriesSerialize(const SyncAppendEntries* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncAppendEntriesDeserialize(const char* buf, uint32_t len, SyncAppendEntries* pMsg);
|
||||
char* syncAppendEntriesSerialize2(const SyncAppendEntries* pMsg, uint32_t* len);
|
||||
SyncAppendEntries* syncAppendEntriesDeserialize2(const char* buf, uint32_t len);
|
||||
void syncAppendEntries2RpcMsg(const SyncAppendEntries* pMsg, SRpcMsg* pRpcMsg);
|
||||
void syncAppendEntriesFromRpcMsg(const SRpcMsg* pRpcMsg, SyncAppendEntries* pMsg);
|
||||
SyncAppendEntries* syncAppendEntriesFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||
cJSON* syncAppendEntries2Json(const SyncAppendEntries* pMsg);
|
||||
char* syncAppendEntries2Str(const SyncAppendEntries* pMsg);
|
||||
|
||||
// for debug ----------------------
|
||||
void syncAppendEntriesPrint(const SyncAppendEntries* pMsg);
|
||||
void syncAppendEntriesPrint2(char* s, const SyncAppendEntries* pMsg);
|
||||
void syncAppendEntriesLog(const SyncAppendEntries* pMsg);
|
||||
void syncAppendEntriesLog2(char* s, const SyncAppendEntries* pMsg);
|
||||
|
||||
// ---------------------------------------------
|
||||
|
||||
typedef struct SOffsetAndContLen {
|
||||
int32_t offset;
|
||||
int32_t contLen;
|
||||
} SOffsetAndContLen;
|
||||
|
||||
// data:
|
||||
// block1: SOffsetAndContLen Array
|
||||
// block2: entry Array
|
||||
|
||||
typedef struct SyncAppendEntriesBatch {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
|
||||
// private data
|
||||
SyncTerm term;
|
||||
SyncIndex prevLogIndex;
|
||||
SyncTerm prevLogTerm;
|
||||
SyncIndex commitIndex;
|
||||
SyncTerm privateTerm;
|
||||
int32_t dataCount;
|
||||
uint32_t dataLen;
|
||||
char data[]; // block1, block2
|
||||
} SyncAppendEntriesBatch;
|
||||
|
||||
SyncAppendEntriesBatch* syncAppendEntriesBatchBuild(SSyncRaftEntry** entryPArr, int32_t arrSize, int32_t vgId);
|
||||
SOffsetAndContLen* syncAppendEntriesBatchMetaTableArray(SyncAppendEntriesBatch* pMsg);
|
||||
void syncAppendEntriesBatchDestroy(SyncAppendEntriesBatch* pMsg);
|
||||
void syncAppendEntriesBatchSerialize(const SyncAppendEntriesBatch* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncAppendEntriesBatchDeserialize(const char* buf, uint32_t len, SyncAppendEntriesBatch* pMsg);
|
||||
char* syncAppendEntriesBatchSerialize2(const SyncAppendEntriesBatch* pMsg, uint32_t* len);
|
||||
SyncAppendEntriesBatch* syncAppendEntriesBatchDeserialize2(const char* buf, uint32_t len);
|
||||
void syncAppendEntriesBatch2RpcMsg(const SyncAppendEntriesBatch* pMsg, SRpcMsg* pRpcMsg);
|
||||
void syncAppendEntriesBatchFromRpcMsg(const SRpcMsg* pRpcMsg, SyncAppendEntriesBatch* pMsg);
|
||||
SyncAppendEntriesBatch* syncAppendEntriesBatchFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef struct SyncAppendEntriesReply {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
// private data
|
||||
SyncTerm term;
|
||||
SyncTerm privateTerm;
|
||||
bool success;
|
||||
SyncIndex matchIndex;
|
||||
SyncIndex lastSendIndex;
|
||||
int64_t startTime;
|
||||
} SyncAppendEntriesReply;
|
||||
|
||||
SyncAppendEntriesReply* syncAppendEntriesReplyBuild(int32_t vgId);
|
||||
void syncAppendEntriesReplyDestroy(SyncAppendEntriesReply* pMsg);
|
||||
void syncAppendEntriesReplySerialize(const SyncAppendEntriesReply* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncAppendEntriesReplyDeserialize(const char* buf, uint32_t len, SyncAppendEntriesReply* pMsg);
|
||||
char* syncAppendEntriesReplySerialize2(const SyncAppendEntriesReply* pMsg, uint32_t* len);
|
||||
SyncAppendEntriesReply* syncAppendEntriesReplyDeserialize2(const char* buf, uint32_t len);
|
||||
void syncAppendEntriesReply2RpcMsg(const SyncAppendEntriesReply* pMsg, SRpcMsg* pRpcMsg);
|
||||
void syncAppendEntriesReplyFromRpcMsg(const SRpcMsg* pRpcMsg, SyncAppendEntriesReply* pMsg);
|
||||
SyncAppendEntriesReply* syncAppendEntriesReplyFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||
cJSON* syncAppendEntriesReply2Json(const SyncAppendEntriesReply* pMsg);
|
||||
char* syncAppendEntriesReply2Str(const SyncAppendEntriesReply* pMsg);
|
||||
|
||||
// for debug ----------------------
|
||||
void syncAppendEntriesReplyPrint(const SyncAppendEntriesReply* pMsg);
|
||||
void syncAppendEntriesReplyPrint2(char* s, const SyncAppendEntriesReply* pMsg);
|
||||
void syncAppendEntriesReplyLog(const SyncAppendEntriesReply* pMsg);
|
||||
void syncAppendEntriesReplyLog2(char* s, const SyncAppendEntriesReply* pMsg);
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef struct SyncHeartbeat {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
|
||||
// private data
|
||||
SyncTerm term;
|
||||
SyncIndex commitIndex;
|
||||
SyncTerm privateTerm;
|
||||
SyncTerm minMatchIndex;
|
||||
|
||||
} SyncHeartbeat;
|
||||
|
||||
SyncHeartbeat* syncHeartbeatBuild(int32_t vgId);
|
||||
void syncHeartbeatDestroy(SyncHeartbeat* pMsg);
|
||||
void syncHeartbeatSerialize(const SyncHeartbeat* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncHeartbeatDeserialize(const char* buf, uint32_t len, SyncHeartbeat* pMsg);
|
||||
char* syncHeartbeatSerialize2(const SyncHeartbeat* pMsg, uint32_t* len);
|
||||
SyncHeartbeat* syncHeartbeatDeserialize2(const char* buf, uint32_t len);
|
||||
void syncHeartbeat2RpcMsg(const SyncHeartbeat* pMsg, SRpcMsg* pRpcMsg);
|
||||
void syncHeartbeatFromRpcMsg(const SRpcMsg* pRpcMsg, SyncHeartbeat* pMsg);
|
||||
SyncHeartbeat* syncHeartbeatFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||
cJSON* syncHeartbeat2Json(const SyncHeartbeat* pMsg);
|
||||
char* syncHeartbeat2Str(const SyncHeartbeat* pMsg);
|
||||
|
||||
// for debug ----------------------
|
||||
void syncHeartbeatPrint(const SyncHeartbeat* pMsg);
|
||||
void syncHeartbeatPrint2(char* s, const SyncHeartbeat* pMsg);
|
||||
void syncHeartbeatLog(const SyncHeartbeat* pMsg);
|
||||
void syncHeartbeatLog2(char* s, const SyncHeartbeat* pMsg);
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef struct SyncHeartbeatReply {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
|
||||
// private data
|
||||
SyncTerm term;
|
||||
SyncTerm privateTerm;
|
||||
int64_t startTime;
|
||||
} SyncHeartbeatReply;
|
||||
|
||||
SyncHeartbeatReply* syncHeartbeatReplyBuild(int32_t vgId);
|
||||
void syncHeartbeatReplyDestroy(SyncHeartbeatReply* pMsg);
|
||||
void syncHeartbeatReplySerialize(const SyncHeartbeatReply* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncHeartbeatReplyDeserialize(const char* buf, uint32_t len, SyncHeartbeatReply* pMsg);
|
||||
char* syncHeartbeatReplySerialize2(const SyncHeartbeatReply* pMsg, uint32_t* len);
|
||||
SyncHeartbeatReply* syncHeartbeatReplyDeserialize2(const char* buf, uint32_t len);
|
||||
void syncHeartbeatReply2RpcMsg(const SyncHeartbeatReply* pMsg, SRpcMsg* pRpcMsg);
|
||||
void syncHeartbeatReplyFromRpcMsg(const SRpcMsg* pRpcMsg, SyncHeartbeatReply* pMsg);
|
||||
SyncHeartbeatReply* syncHeartbeatReplyFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||
cJSON* syncHeartbeatReply2Json(const SyncHeartbeatReply* pMsg);
|
||||
char* syncHeartbeatReply2Str(const SyncHeartbeatReply* pMsg);
|
||||
|
||||
// for debug ----------------------
|
||||
void syncHeartbeatReplyPrint(const SyncHeartbeatReply* pMsg);
|
||||
void syncHeartbeatReplyPrint2(char* s, const SyncHeartbeatReply* pMsg);
|
||||
void syncHeartbeatReplyLog(const SyncHeartbeatReply* pMsg);
|
||||
void syncHeartbeatReplyLog2(char* s, const SyncHeartbeatReply* pMsg);
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef struct SyncPreSnapshot {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
|
||||
// private data
|
||||
SyncTerm term;
|
||||
|
||||
} SyncPreSnapshot;
|
||||
|
||||
SyncPreSnapshot* syncPreSnapshotBuild(int32_t vgId);
|
||||
void syncPreSnapshotDestroy(SyncPreSnapshot* pMsg);
|
||||
void syncPreSnapshotSerialize(const SyncPreSnapshot* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncPreSnapshotDeserialize(const char* buf, uint32_t len, SyncPreSnapshot* pMsg);
|
||||
char* syncPreSnapshotSerialize2(const SyncPreSnapshot* pMsg, uint32_t* len);
|
||||
SyncPreSnapshot* syncPreSnapshotDeserialize2(const char* buf, uint32_t len);
|
||||
void syncPreSnapshot2RpcMsg(const SyncPreSnapshot* pMsg, SRpcMsg* pRpcMsg);
|
||||
void syncPreSnapshotFromRpcMsg(const SRpcMsg* pRpcMsg, SyncPreSnapshot* pMsg);
|
||||
SyncPreSnapshot* syncPreSnapshotFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||
cJSON* syncPreSnapshot2Json(const SyncPreSnapshot* pMsg);
|
||||
char* syncPreSnapshot2Str(const SyncPreSnapshot* pMsg);
|
||||
|
||||
// for debug ----------------------
|
||||
void syncPreSnapshotPrint(const SyncPreSnapshot* pMsg);
|
||||
void syncPreSnapshotPrint2(char* s, const SyncPreSnapshot* pMsg);
|
||||
void syncPreSnapshotLog(const SyncPreSnapshot* pMsg);
|
||||
void syncPreSnapshotLog2(char* s, const SyncPreSnapshot* pMsg);
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef struct SyncPreSnapshotReply {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
|
||||
// private data
|
||||
SyncTerm term;
|
||||
SyncIndex snapStart;
|
||||
|
||||
} SyncPreSnapshotReply;
|
||||
|
||||
SyncPreSnapshotReply* syncPreSnapshotReplyBuild(int32_t vgId);
|
||||
void syncPreSnapshotReplyDestroy(SyncPreSnapshotReply* pMsg);
|
||||
void syncPreSnapshotReplySerialize(const SyncPreSnapshotReply* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncPreSnapshotReplyDeserialize(const char* buf, uint32_t len, SyncPreSnapshotReply* pMsg);
|
||||
char* syncPreSnapshotReplySerialize2(const SyncPreSnapshotReply* pMsg, uint32_t* len);
|
||||
SyncPreSnapshotReply* syncPreSnapshotReplyDeserialize2(const char* buf, uint32_t len);
|
||||
void syncPreSnapshotReply2RpcMsg(const SyncPreSnapshotReply* pMsg, SRpcMsg* pRpcMsg);
|
||||
void syncPreSnapshotReplyFromRpcMsg(const SRpcMsg* pRpcMsg, SyncPreSnapshotReply* pMsg);
|
||||
SyncPreSnapshotReply* syncPreSnapshotReplyFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||
cJSON* syncPreSnapshotReply2Json(const SyncPreSnapshotReply* pMsg);
|
||||
char* syncPreSnapshotReply2Str(const SyncPreSnapshotReply* pMsg);
|
||||
|
||||
// for debug ----------------------
|
||||
void syncPreSnapshotReplyPrint(const SyncPreSnapshotReply* pMsg);
|
||||
void syncPreSnapshotReplyPrint2(char* s, const SyncPreSnapshotReply* pMsg);
|
||||
void syncPreSnapshotReplyLog(const SyncPreSnapshotReply* pMsg);
|
||||
void syncPreSnapshotReplyLog2(char* s, const SyncPreSnapshotReply* pMsg);
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef struct SyncApplyMsg {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType; // user SyncApplyMsg msgType
|
||||
uint32_t originalRpcType; // user RpcMsg msgType
|
||||
SFsmCbMeta fsmMeta;
|
||||
uint32_t dataLen; // user RpcMsg.contLen
|
||||
char data[]; // user RpcMsg.pCont
|
||||
} SyncApplyMsg;
|
||||
|
||||
SyncApplyMsg* syncApplyMsgBuild(uint32_t dataLen);
|
||||
SyncApplyMsg* syncApplyMsgBuild2(const SRpcMsg* pOriginalRpcMsg, int32_t vgId, SFsmCbMeta* pMeta);
|
||||
void syncApplyMsgDestroy(SyncApplyMsg* pMsg);
|
||||
void syncApplyMsgSerialize(const SyncApplyMsg* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncApplyMsgDeserialize(const char* buf, uint32_t len, SyncApplyMsg* pMsg);
|
||||
char* syncApplyMsgSerialize2(const SyncApplyMsg* pMsg, uint32_t* len);
|
||||
SyncApplyMsg* syncApplyMsgDeserialize2(const char* buf, uint32_t len);
|
||||
void syncApplyMsg2RpcMsg(const SyncApplyMsg* pMsg, SRpcMsg* pRpcMsg); // SyncApplyMsg to SRpcMsg, put it into ApplyQ
|
||||
void syncApplyMsgFromRpcMsg(const SRpcMsg* pRpcMsg, SyncApplyMsg* pMsg); // get SRpcMsg from ApplyQ, to SyncApplyMsg
|
||||
SyncApplyMsg* syncApplyMsgFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||
void syncApplyMsg2OriginalRpcMsg(const SyncApplyMsg* pMsg, SRpcMsg* pOriginalRpcMsg); // SyncApplyMsg to OriginalRpcMsg
|
||||
cJSON* syncApplyMsg2Json(const SyncApplyMsg* pMsg);
|
||||
char* syncApplyMsg2Str(const SyncApplyMsg* pMsg);
|
||||
|
||||
// for debug ----------------------
|
||||
void syncApplyMsgPrint(const SyncApplyMsg* pMsg);
|
||||
void syncApplyMsgPrint2(char* s, const SyncApplyMsg* pMsg);
|
||||
void syncApplyMsgLog(const SyncApplyMsg* pMsg);
|
||||
void syncApplyMsgLog2(char* s, const SyncApplyMsg* pMsg);
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef struct SyncSnapshotSend {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
|
||||
SyncTerm term;
|
||||
SyncIndex beginIndex; // snapshot.beginIndex
|
||||
SyncIndex lastIndex; // snapshot.lastIndex
|
||||
SyncTerm lastTerm; // snapshot.lastTerm
|
||||
SyncIndex lastConfigIndex; // snapshot.lastConfigIndex
|
||||
SSyncCfg lastConfig;
|
||||
int64_t startTime;
|
||||
int32_t seq;
|
||||
uint32_t dataLen;
|
||||
char data[];
|
||||
} SyncSnapshotSend;
|
||||
|
||||
SyncSnapshotSend* syncSnapshotSendBuild(uint32_t dataLen, int32_t vgId);
|
||||
void syncSnapshotSendDestroy(SyncSnapshotSend* pMsg);
|
||||
void syncSnapshotSendSerialize(const SyncSnapshotSend* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncSnapshotSendDeserialize(const char* buf, uint32_t len, SyncSnapshotSend* pMsg);
|
||||
char* syncSnapshotSendSerialize2(const SyncSnapshotSend* pMsg, uint32_t* len);
|
||||
SyncSnapshotSend* syncSnapshotSendDeserialize2(const char* buf, uint32_t len);
|
||||
void syncSnapshotSend2RpcMsg(const SyncSnapshotSend* pMsg, SRpcMsg* pRpcMsg);
|
||||
void syncSnapshotSendFromRpcMsg(const SRpcMsg* pRpcMsg, SyncSnapshotSend* pMsg);
|
||||
SyncSnapshotSend* syncSnapshotSendFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||
cJSON* syncSnapshotSend2Json(const SyncSnapshotSend* pMsg);
|
||||
char* syncSnapshotSend2Str(const SyncSnapshotSend* pMsg);
|
||||
|
||||
// for debug ----------------------
|
||||
void syncSnapshotSendPrint(const SyncSnapshotSend* pMsg);
|
||||
void syncSnapshotSendPrint2(char* s, const SyncSnapshotSend* pMsg);
|
||||
void syncSnapshotSendLog(const SyncSnapshotSend* pMsg);
|
||||
void syncSnapshotSendLog2(char* s, const SyncSnapshotSend* pMsg);
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef struct SyncSnapshotRsp {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
|
||||
SyncTerm term;
|
||||
SyncIndex lastIndex;
|
||||
SyncTerm lastTerm;
|
||||
int64_t startTime;
|
||||
int32_t ack;
|
||||
int32_t code;
|
||||
SyncIndex snapBeginIndex; // when ack = SYNC_SNAPSHOT_SEQ_BEGIN, it's valid
|
||||
} SyncSnapshotRsp;
|
||||
|
||||
SyncSnapshotRsp* syncSnapshotRspBuild(int32_t vgId);
|
||||
void syncSnapshotRspDestroy(SyncSnapshotRsp* pMsg);
|
||||
void syncSnapshotRspSerialize(const SyncSnapshotRsp* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncSnapshotRspDeserialize(const char* buf, uint32_t len, SyncSnapshotRsp* pMsg);
|
||||
char* syncSnapshotRspSerialize2(const SyncSnapshotRsp* pMsg, uint32_t* len);
|
||||
SyncSnapshotRsp* syncSnapshotRspDeserialize2(const char* buf, uint32_t len);
|
||||
void syncSnapshotRsp2RpcMsg(const SyncSnapshotRsp* pMsg, SRpcMsg* pRpcMsg);
|
||||
void syncSnapshotRspFromRpcMsg(const SRpcMsg* pRpcMsg, SyncSnapshotRsp* pMsg);
|
||||
SyncSnapshotRsp* syncSnapshotRspFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||
cJSON* syncSnapshotRsp2Json(const SyncSnapshotRsp* pMsg);
|
||||
char* syncSnapshotRsp2Str(const SyncSnapshotRsp* pMsg);
|
||||
|
||||
// for debug ----------------------
|
||||
void syncSnapshotRspPrint(const SyncSnapshotRsp* pMsg);
|
||||
void syncSnapshotRspPrint2(char* s, const SyncSnapshotRsp* pMsg);
|
||||
void syncSnapshotRspLog(const SyncSnapshotRsp* pMsg);
|
||||
void syncSnapshotRspLog2(char* s, const SyncSnapshotRsp* pMsg);
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef struct SyncLeaderTransfer {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
/*
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
*/
|
||||
SNodeInfo newNodeInfo;
|
||||
SRaftId newLeaderId;
|
||||
} SyncLeaderTransfer;
|
||||
|
||||
SyncLeaderTransfer* syncLeaderTransferBuild(int32_t vgId);
|
||||
void syncLeaderTransferDestroy(SyncLeaderTransfer* pMsg);
|
||||
void syncLeaderTransferSerialize(const SyncLeaderTransfer* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncLeaderTransferDeserialize(const char* buf, uint32_t len, SyncLeaderTransfer* pMsg);
|
||||
char* syncLeaderTransferSerialize2(const SyncLeaderTransfer* pMsg, uint32_t* len);
|
||||
SyncLeaderTransfer* syncLeaderTransferDeserialize2(const char* buf, uint32_t len);
|
||||
void syncLeaderTransfer2RpcMsg(const SyncLeaderTransfer* pMsg, SRpcMsg* pRpcMsg);
|
||||
void syncLeaderTransferFromRpcMsg(const SRpcMsg* pRpcMsg, SyncLeaderTransfer* pMsg);
|
||||
SyncLeaderTransfer* syncLeaderTransferFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||
cJSON* syncLeaderTransfer2Json(const SyncLeaderTransfer* pMsg);
|
||||
char* syncLeaderTransfer2Str(const SyncLeaderTransfer* pMsg);
|
||||
|
||||
typedef enum {
|
||||
SYNC_LOCAL_CMD_STEP_DOWN = 100,
|
||||
SYNC_LOCAL_CMD_FOLLOWER_CMT,
|
||||
} ESyncLocalCmd;
|
||||
|
||||
const char* syncLocalCmdGetStr(int32_t cmd);
|
||||
|
||||
typedef struct SyncLocalCmd {
|
||||
uint32_t bytes;
|
||||
int32_t vgId;
|
||||
uint32_t msgType;
|
||||
SRaftId srcId;
|
||||
SRaftId destId;
|
||||
|
||||
int32_t cmd;
|
||||
SyncTerm sdNewTerm; // step down new term
|
||||
SyncIndex fcIndex;// follower commit index
|
||||
|
||||
} SyncLocalCmd;
|
||||
|
||||
SyncLocalCmd* syncLocalCmdBuild(int32_t vgId);
|
||||
void syncLocalCmdDestroy(SyncLocalCmd* pMsg);
|
||||
void syncLocalCmdSerialize(const SyncLocalCmd* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncLocalCmdDeserialize(const char* buf, uint32_t len, SyncLocalCmd* pMsg);
|
||||
char* syncLocalCmdSerialize2(const SyncLocalCmd* pMsg, uint32_t* len);
|
||||
SyncLocalCmd* syncLocalCmdDeserialize2(const char* buf, uint32_t len);
|
||||
void syncLocalCmd2RpcMsg(const SyncLocalCmd* pMsg, SRpcMsg* pRpcMsg);
|
||||
void syncLocalCmdFromRpcMsg(const SRpcMsg* pRpcMsg, SyncLocalCmd* pMsg);
|
||||
SyncLocalCmd* syncLocalCmdFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||
cJSON* syncLocalCmd2Json(const SyncLocalCmd* pMsg);
|
||||
char* syncLocalCmd2Str(const SyncLocalCmd* pMsg);
|
||||
|
||||
// for debug ----------------------
|
||||
void syncLocalCmdPrint(const SyncLocalCmd* pMsg);
|
||||
void syncLocalCmdPrint2(char* s, const SyncLocalCmd* pMsg);
|
||||
void syncLocalCmdLog(const SyncLocalCmd* pMsg);
|
||||
void syncLocalCmdLog2(char* s, const SyncLocalCmd* pMsg);
|
||||
|
||||
// on message ----------------------
|
||||
int32_t syncNodeOnPing(SSyncNode* ths, SyncPing* pMsg);
|
||||
int32_t syncNodeOnPingReply(SSyncNode* ths, SyncPingReply* pMsg);
|
||||
|
||||
int32_t syncNodeOnRequestVote(SSyncNode* ths, SyncRequestVote* pMsg);
|
||||
int32_t syncNodeOnRequestVoteReply(SSyncNode* ths, SyncRequestVoteReply* pMsg);
|
||||
|
||||
int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg);
|
||||
int32_t syncNodeOnAppendEntriesReply(SSyncNode* ths, SyncAppendEntriesReply* pMsg);
|
||||
|
||||
int32_t syncNodeOnPreSnapshot(SSyncNode* ths, SyncPreSnapshot* pMsg);
|
||||
int32_t syncNodeOnPreSnapshotReply(SSyncNode* ths, SyncPreSnapshotReply* pMsg);
|
||||
|
||||
int32_t syncNodeOnSnapshot(SSyncNode* ths, SyncSnapshotSend* pMsg);
|
||||
int32_t syncNodeOnSnapshotReply(SSyncNode* ths, SyncSnapshotRsp* pMsg);
|
||||
|
||||
int32_t syncNodeOnHeartbeat(SSyncNode* ths, SyncHeartbeat* pMsg);
|
||||
int32_t syncNodeOnHeartbeatReply(SSyncNode* ths, SyncHeartbeatReply* pMsg);
|
||||
|
||||
int32_t syncNodeOnClientRequest(SSyncNode* ths, SRpcMsg* pMsg, SyncIndex* pRetIndex);
|
||||
int32_t syncNodeOnLocalCmd(SSyncNode* ths, SyncLocalCmd* pMsg);
|
||||
|
||||
// -----------------------------------------
|
||||
typedef int32_t (*FpOnPingCb)(SSyncNode* ths, SyncPing* pMsg);
|
||||
typedef int32_t (*FpOnPingReplyCb)(SSyncNode* ths, SyncPingReply* pMsg);
|
||||
typedef int32_t (*FpOnClientRequestCb)(SSyncNode* ths, SRpcMsg* pMsg, SyncIndex* pRetIndex);
|
||||
typedef int32_t (*FpOnRequestVoteCb)(SSyncNode* ths, SyncRequestVote* pMsg);
|
||||
typedef int32_t (*FpOnRequestVoteReplyCb)(SSyncNode* ths, SyncRequestVoteReply* pMsg);
|
||||
typedef int32_t (*FpOnAppendEntriesCb)(SSyncNode* ths, SyncAppendEntries* pMsg);
|
||||
typedef int32_t (*FpOnAppendEntriesReplyCb)(SSyncNode* ths, SyncAppendEntriesReply* pMsg);
|
||||
typedef int32_t (*FpOnTimeoutCb)(SSyncNode* pSyncNode, SyncTimeout* pMsg);
|
||||
typedef int32_t (*FpOnSnapshotCb)(SSyncNode* ths, SyncSnapshotSend* pMsg);
|
||||
typedef int32_t (*FpOnSnapshotReplyCb)(SSyncNode* ths, SyncSnapshotRsp* pMsg);
|
||||
|
||||
// option ----------------------------------
|
||||
bool syncNodeSnapshotEnable(SSyncNode* pSyncNode);
|
||||
ESyncStrategy syncNodeStrategy(SSyncNode* pSyncNode);
|
||||
|
||||
// ---------------------------------------------
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_LIBS_SYNC_TOOLS_H*/
|
|
@ -21,6 +21,46 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include "syncInt.h"
|
||||
#include "tlog.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
#define sFatal(...) if (sDebugFlag & DEBUG_FATAL) { taosPrintLog("SYN FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }
|
||||
#define sError(...) if (sDebugFlag & DEBUG_ERROR) { taosPrintLog("SYN ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }
|
||||
#define sWarn(...) if (sDebugFlag & DEBUG_WARN) { taosPrintLog("SYN WARN ", DEBUG_WARN, 255, __VA_ARGS__); }
|
||||
#define sInfo(...) if (sDebugFlag & DEBUG_INFO) { taosPrintLog("SYN ", DEBUG_INFO, 255, __VA_ARGS__); }
|
||||
#define sDebug(...) if (sDebugFlag & DEBUG_DEBUG) { taosPrintLog("SYN ", DEBUG_DEBUG, sDebugFlag, __VA_ARGS__); }
|
||||
#define sTrace(...) if (sDebugFlag & DEBUG_TRACE) { taosPrintLog("SYN ", DEBUG_TRACE, sDebugFlag, __VA_ARGS__); }
|
||||
|
||||
#define sLFatal(...) if (sDebugFlag & DEBUG_FATAL) { taosPrintLongString("SYN FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }
|
||||
#define sLError(...) if (sDebugFlag & DEBUG_ERROR) { taosPrintLongString("SYN ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }
|
||||
#define sLWarn(...) if (sDebugFlag & DEBUG_WARN) { taosPrintLongString("SYN WARN ", DEBUG_WARN, 255, __VA_ARGS__); }
|
||||
#define sLInfo(...) if (sDebugFlag & DEBUG_INFO) { taosPrintLongString("SYN ", DEBUG_INFO, 255, __VA_ARGS__); }
|
||||
#define sLDebug(...) if (sDebugFlag & DEBUG_DEBUG) { taosPrintLongString("SYN ", DEBUG_DEBUG, sDebugFlag, __VA_ARGS__); }
|
||||
#define sLTrace(...) if (sDebugFlag & DEBUG_TRACE) { taosPrintLongString("SYN ", DEBUG_TRACE, sDebugFlag, __VA_ARGS__); }
|
||||
|
||||
#define sNFatal(pNode, ...) if (sDebugFlag & DEBUG_FATAL) { syncPrintNodeLog("SYN FATAL ", DEBUG_FATAL, 255, pNode, __VA_ARGS__); }
|
||||
#define sNError(pNode, ...) if (sDebugFlag & DEBUG_ERROR) { syncPrintNodeLog("SYN ERROR ", DEBUG_ERROR, 255, pNode, __VA_ARGS__); }
|
||||
#define sNWarn(pNode, ...) if (sDebugFlag & DEBUG_WARN) { syncPrintNodeLog("SYN WARN ", DEBUG_WARN, 255, pNode, __VA_ARGS__); }
|
||||
#define sNInfo(pNode, ...) if (sDebugFlag & DEBUG_INFO) { syncPrintNodeLog("SYN ", DEBUG_INFO, 255, pNode, __VA_ARGS__); }
|
||||
#define sNDebug(pNode, ...) if (sDebugFlag & DEBUG_DEBUG) { syncPrintNodeLog("SYN ", DEBUG_DEBUG, sDebugFlag, pNode, __VA_ARGS__); }
|
||||
#define sNTrace(pNode, ...) if (sDebugFlag & DEBUG_TRACE) { syncPrintNodeLog("SYN ", DEBUG_TRACE, sDebugFlag, pNode, __VA_ARGS__); }
|
||||
|
||||
#define sSFatal(pSender, ...) if (sDebugFlag & DEBUG_FATAL) { syncPrintSnapshotSenderLog("SYN FATAL ", DEBUG_FATAL, 255, pSender, __VA_ARGS__); }
|
||||
#define sSError(pSender, ...) if (sDebugFlag & DEBUG_ERROR) { syncPrintSnapshotSenderLog("SYN ERROR ", DEBUG_ERROR, 255, pSender, __VA_ARGS__); }
|
||||
#define sSWarn(pSender, ...) if (sDebugFlag & DEBUG_WARN) { syncPrintSnapshotSenderLog("SYN WARN ", DEBUG_WARN, 255, pSender, __VA_ARGS__); }
|
||||
#define sSInfo(pSender, ...) if (sDebugFlag & DEBUG_INFO) { syncPrintSnapshotSenderLog("SYN ", DEBUG_INFO, 255, pSender, __VA_ARGS__); }
|
||||
#define sSDebug(pSender, ...) if (sDebugFlag & DEBUG_DEBUG) { syncPrintSnapshotSenderLog("SYN ", DEBUG_DEBUG, sDebugFlag, pSender, __VA_ARGS__); }
|
||||
#define sSTrace(pSender, ...) if (sDebugFlag & DEBUG_TRACE) { syncPrintSnapshotSenderLog("SYN ", DEBUG_TRACE, sDebugFlag, pSender, __VA_ARGS__); }
|
||||
|
||||
#define sRFatal(pReceiver, ...) if (sDebugFlag & DEBUG_FATAL) { syncPrintSnapshotReceiverLog("SYN FATAL ", DEBUG_FATAL, 255, pReceiver, __VA_ARGS__); }
|
||||
#define sRError(pReceiver, ...) if (sDebugFlag & DEBUG_ERROR) { syncPrintSnapshotReceiverLog("SYN ERROR ", DEBUG_ERROR, 255, pReceiver, __VA_ARGS__); }
|
||||
#define sRWarn(pReceiver, ...) if (sDebugFlag & DEBUG_WARN) { syncPrintSnapshotReceiverLog("SYN WARN ", DEBUG_WARN, 255, pReceiver, __VA_ARGS__); }
|
||||
#define sRInfo(pReceiver, ...) if (sDebugFlag & DEBUG_INFO) { syncPrintSnapshotReceiverLog("SYN ", DEBUG_INFO, 255, pReceiver, __VA_ARGS__); }
|
||||
#define sRDebug(pReceiver, ...) if (sDebugFlag & DEBUG_DEBUG) { syncPrintSnapshotReceiverLog("SYN ", DEBUG_DEBUG, sDebugFlag, pReceiver, __VA_ARGS__); }
|
||||
#define sRTrace(pReceiver, ...) if (sDebugFlag & DEBUG_TRACE) { syncPrintSnapshotReceiverLog("SYN ", DEBUG_TRACE, sDebugFlag, pReceiver, __VA_ARGS__); }
|
||||
|
||||
// clang-format on
|
||||
|
||||
uint64_t syncUtilAddr2U64(const char* host, uint16_t port);
|
||||
void syncUtilU642Addr(uint64_t u64, char* host, int64_t len, uint16_t* port);
|
||||
|
@ -48,6 +88,39 @@ void syncPrintSnapshotSenderLog(const char* flags, ELogLevel level, int32_t dfla
|
|||
void syncPrintSnapshotReceiverLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotReceiver* pReceiver,
|
||||
const char* format, ...);
|
||||
|
||||
void syncLogRecvTimer(SSyncNode* pSyncNode, const SyncTimeout* pMsg, const char* s);
|
||||
void syncLogRecvLocalCmd(SSyncNode* pSyncNode, const SyncLocalCmd* pMsg, const char* s);
|
||||
|
||||
void syncLogSendAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s);
|
||||
void syncLogRecvAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s);
|
||||
|
||||
void syncLogSendHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, const char* s);
|
||||
void syncLogRecvHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, const char* s);
|
||||
|
||||
void syncLogSendHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s);
|
||||
void syncLogRecvHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s);
|
||||
|
||||
void syncLogSendSyncPreSnapshot(SSyncNode* pSyncNode, const SyncPreSnapshot* pMsg, const char* s);
|
||||
void syncLogRecvSyncPreSnapshot(SSyncNode* pSyncNode, const SyncPreSnapshot* pMsg, const char* s);
|
||||
|
||||
void syncLogSendSyncPreSnapshotReply(SSyncNode* pSyncNode, const SyncPreSnapshotReply* pMsg, const char* s);
|
||||
void syncLogRecvSyncPreSnapshotReply(SSyncNode* pSyncNode, const SyncPreSnapshotReply* pMsg, const char* s);
|
||||
|
||||
void syncLogSendSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* pMsg, const char* s);
|
||||
void syncLogRecvSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* pMsg, const char* s);
|
||||
|
||||
void syncLogSendSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s);
|
||||
void syncLogRecvSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s);
|
||||
|
||||
void syncLogRecvAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMsg, const char* s);
|
||||
void syncLogSendAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMsg, const char* s);
|
||||
|
||||
void syncLogRecvRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, const char* s);
|
||||
void syncLogSendRequestVote(SSyncNode* pNode, const SyncRequestVote* pMsg, const char* s);
|
||||
|
||||
void syncLogRecvRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s);
|
||||
void syncLogSendRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -13,15 +13,12 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "syncAppendEntries.h"
|
||||
#include "syncInt.h"
|
||||
#include "syncRaftCfg.h"
|
||||
#include "syncMessage.h"
|
||||
#include "syncRaftLog.h"
|
||||
#include "syncRaftStore.h"
|
||||
#include "syncSnapshot.h"
|
||||
#include "syncUtil.h"
|
||||
#include "syncVoteMgr.h"
|
||||
#include "wal.h"
|
||||
|
||||
// TLA+ Spec
|
||||
// HandleAppendEntriesRequest(i, j, m) ==
|
||||
|
@ -127,7 +124,10 @@ int32_t syncNodeFollowerCommit(SSyncNode* ths, SyncIndex newCommitIndex) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
||||
int32_t syncNodeOnAppendEntries(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
||||
SyncAppendEntries* pMsg = pRpcMsg->pCont;
|
||||
SRpcMsg rpcRsp = {0};
|
||||
|
||||
// if already drop replica, do not process
|
||||
if (!syncNodeInRaftGroup(ths, &(pMsg->srcId))) {
|
||||
syncLogRecvAppendEntries(ths, pMsg, "not in my config");
|
||||
|
@ -135,7 +135,13 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
|||
}
|
||||
|
||||
// prepare response msg
|
||||
SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(ths->vgId);
|
||||
int32_t code = syncBuildAppendEntriesReply(&rpcRsp, ths->vgId);
|
||||
if (code != 0) {
|
||||
syncLogRecvAppendEntries(ths, pMsg, "build rsp error");
|
||||
goto _IGNORE;
|
||||
}
|
||||
|
||||
SyncAppendEntriesReply* pReply = rpcRsp.pCont;
|
||||
pReply->srcId = ths->myRaftId;
|
||||
pReply->destId = pMsg->srcId;
|
||||
pReply->term = ths->pRaftStore->currentTerm;
|
||||
|
@ -281,7 +287,7 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
|||
goto _SEND_RESPONSE;
|
||||
|
||||
_IGNORE:
|
||||
syncAppendEntriesReplyDestroy(pReply);
|
||||
rpcFreeCont(rpcRsp.pCont);
|
||||
return 0;
|
||||
|
||||
_SEND_RESPONSE:
|
||||
|
@ -289,10 +295,6 @@ _SEND_RESPONSE:
|
|||
syncLogSendAppendEntriesReply(ths, pReply, "");
|
||||
|
||||
// send response
|
||||
SRpcMsg rpcMsg;
|
||||
syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg);
|
||||
syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg);
|
||||
syncAppendEntriesReplyDestroy(pReply);
|
||||
|
||||
syncNodeSendMsgById(&pReply->destId, ths, &rpcRsp);
|
||||
return 0;
|
||||
}
|
|
@ -13,17 +13,15 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "syncAppendEntriesReply.h"
|
||||
#include "syncCommit.h"
|
||||
#include "syncIndexMgr.h"
|
||||
#include "syncInt.h"
|
||||
#include "syncRaftCfg.h"
|
||||
#include "syncRaftLog.h"
|
||||
#include "syncMessage.h"
|
||||
#include "syncRaftStore.h"
|
||||
#include "syncReplication.h"
|
||||
#include "syncSnapshot.h"
|
||||
#include "syncUtil.h"
|
||||
#include "syncVoteMgr.h"
|
||||
|
||||
// TLA+ Spec
|
||||
// HandleAppendEntriesResponse(i, j, m) ==
|
||||
|
@ -39,8 +37,9 @@
|
|||
// /\ UNCHANGED <<serverVars, candidateVars, logVars, elections>>
|
||||
//
|
||||
|
||||
int32_t syncNodeOnAppendEntriesReply(SSyncNode* ths, SyncAppendEntriesReply* pMsg) {
|
||||
int32_t ret = 0;
|
||||
int32_t syncNodeOnAppendEntriesReply(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
||||
int32_t ret = 0;
|
||||
SyncAppendEntriesReply* pMsg = pRpcMsg->pCont;
|
||||
|
||||
// if already drop replica, do not process
|
||||
if (!syncNodeInRaftGroup(ths, &(pMsg->srcId))) {
|
||||
|
|
|
@ -13,10 +13,9 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "syncCommit.h"
|
||||
#include "syncIndexMgr.h"
|
||||
#include "syncInt.h"
|
||||
#include "syncRaftCfg.h"
|
||||
#include "syncRaftLog.h"
|
||||
#include "syncRaftStore.h"
|
||||
#include "syncUtil.h"
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
#include "syncMessage.h"
|
||||
#include "syncRaftCfg.h"
|
||||
#include "syncRaftStore.h"
|
||||
#include "syncVoteMgr.h"
|
||||
#include "syncUtil.h"
|
||||
#include "syncVoteMgr.h"
|
||||
|
||||
// TLA+ Spec
|
||||
// RequestVote(i, j) ==
|
||||
|
@ -33,6 +33,33 @@
|
|||
// mdest |-> j])
|
||||
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
|
||||
|
||||
static int32_t syncNodeRequestVotePeers(SSyncNode* pNode) {
|
||||
if (pNode->state != TAOS_SYNC_STATE_CANDIDATE) {
|
||||
sNTrace(pNode, "not candidate, stop elect");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t ret = 0;
|
||||
for (int i = 0; i < pNode->peersNum; ++i) {
|
||||
SRpcMsg rpcMsg = {0};
|
||||
ret = syncBuildRequestVote(&rpcMsg, pNode->vgId);
|
||||
ASSERT(ret == 0);
|
||||
|
||||
SyncRequestVote* pMsg = rpcMsg.pCont;
|
||||
pMsg->srcId = pNode->myRaftId;
|
||||
pMsg->destId = pNode->peersId[i];
|
||||
pMsg->term = pNode->pRaftStore->currentTerm;
|
||||
|
||||
ret = syncNodeGetLastIndexTerm(pNode, &pMsg->lastLogIndex, &pMsg->lastLogTerm);
|
||||
ASSERT(ret == 0);
|
||||
|
||||
ret = syncNodeSendMsgById(&pNode->peersId[i], pNode, &rpcMsg);
|
||||
ASSERT(ret == 0);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t syncNodeElect(SSyncNode* pSyncNode) {
|
||||
sNTrace(pSyncNode, "begin election");
|
||||
|
||||
|
@ -81,36 +108,3 @@ int32_t syncNodeElect(SSyncNode* pSyncNode) {
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t syncNodeRequestVotePeers(SSyncNode* pSyncNode) {
|
||||
if (pSyncNode->state != TAOS_SYNC_STATE_CANDIDATE) {
|
||||
sNTrace(pSyncNode, "not candidate, stop elect");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t ret = 0;
|
||||
for (int i = 0; i < pSyncNode->peersNum; ++i) {
|
||||
SyncRequestVote* pMsg = syncRequestVoteBuild(pSyncNode->vgId);
|
||||
pMsg->srcId = pSyncNode->myRaftId;
|
||||
pMsg->destId = pSyncNode->peersId[i];
|
||||
pMsg->term = pSyncNode->pRaftStore->currentTerm;
|
||||
|
||||
ret = syncNodeGetLastIndexTerm(pSyncNode, &(pMsg->lastLogIndex), &(pMsg->lastLogTerm));
|
||||
ASSERT(ret == 0);
|
||||
|
||||
ret = syncNodeSendRequestVote(pSyncNode, &pSyncNode->peersId[i], pMsg);
|
||||
ASSERT(ret == 0);
|
||||
syncRequestVoteDestroy(pMsg);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t syncNodeSendRequestVote(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncRequestVote* pMsg) {
|
||||
int32_t ret = 0;
|
||||
syncLogSendRequestVote(pSyncNode, pMsg, "");
|
||||
|
||||
SRpcMsg rpcMsg;
|
||||
syncRequestVote2RpcMsg(pMsg, &rpcMsg);
|
||||
syncNodeSendMsgById(destRaftId, pSyncNode, &rpcMsg);
|
||||
return ret;
|
||||
}
|
|
@ -15,11 +15,11 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "syncEnv.h"
|
||||
#include "syncUtil.h"
|
||||
#include "tref.h"
|
||||
|
||||
static SSyncEnv gSyncEnv = {0};
|
||||
static int32_t gNodeRefId = -1;
|
||||
bool gRaftDetailLog = false;
|
||||
static void syncEnvTick(void *param, void *tmrId);
|
||||
|
||||
SSyncEnv *syncEnv() { return &gSyncEnv; }
|
||||
|
@ -105,6 +105,7 @@ void syncEnvStopTimer() {
|
|||
#endif
|
||||
|
||||
static void syncEnvTick(void *param, void *tmrId) {
|
||||
#if 0
|
||||
SSyncEnv *pSyncEnv = param;
|
||||
if (atomic_load_64(&gSyncEnv.envTickTimerLogicClockUser) <= atomic_load_64(&gSyncEnv.envTickTimerLogicClock)) {
|
||||
gSyncEnv.envTickTimerCounter++;
|
||||
|
@ -121,4 +122,5 @@ static void syncEnvTick(void *param, void *tmrId) {
|
|||
gSyncEnv.envTickTimerLogicClockUser, gSyncEnv.envTickTimerLogicClock, gSyncEnv.envTickTimerCounter,
|
||||
gSyncEnv.envTickTimerMS, tmrId);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -13,18 +13,16 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "syncIndexMgr.h"
|
||||
#include "syncUtil.h"
|
||||
|
||||
// SMatchIndex -----------------------------
|
||||
|
||||
SSyncIndexMgr *syncIndexMgrCreate(SSyncNode *pSyncNode) {
|
||||
SSyncIndexMgr *pSyncIndexMgr = taosMemoryMalloc(sizeof(SSyncIndexMgr));
|
||||
SSyncIndexMgr *pSyncIndexMgr = taosMemoryCalloc(1, sizeof(SSyncIndexMgr));
|
||||
if (pSyncIndexMgr == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
memset(pSyncIndexMgr, 0, sizeof(SSyncIndexMgr));
|
||||
|
||||
pSyncIndexMgr->replicas = &(pSyncNode->replicasId);
|
||||
pSyncIndexMgr->replicaNum = pSyncNode->replicaNum;
|
||||
|
@ -97,54 +95,6 @@ SyncIndex syncIndexMgrGetIndex(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaf
|
|||
return SYNC_INDEX_INVALID;
|
||||
}
|
||||
|
||||
cJSON *syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr) {
|
||||
char u64buf[128] = {0};
|
||||
cJSON *pRoot = cJSON_CreateObject();
|
||||
|
||||
if (pSyncIndexMgr != NULL) {
|
||||
cJSON_AddNumberToObject(pRoot, "replicaNum", pSyncIndexMgr->replicaNum);
|
||||
cJSON *pReplicas = cJSON_CreateArray();
|
||||
cJSON_AddItemToObject(pRoot, "replicas", pReplicas);
|
||||
for (int i = 0; i < pSyncIndexMgr->replicaNum; ++i) {
|
||||
cJSON_AddItemToArray(pReplicas, syncUtilRaftId2Json(&(*(pSyncIndexMgr->replicas))[i]));
|
||||
}
|
||||
|
||||
{
|
||||
int *arr = (int *)taosMemoryMalloc(sizeof(int) * pSyncIndexMgr->replicaNum);
|
||||
for (int i = 0; i < pSyncIndexMgr->replicaNum; ++i) {
|
||||
arr[i] = pSyncIndexMgr->index[i];
|
||||
}
|
||||
cJSON *pIndex = cJSON_CreateIntArray(arr, pSyncIndexMgr->replicaNum);
|
||||
taosMemoryFree(arr);
|
||||
cJSON_AddItemToObject(pRoot, "index", pIndex);
|
||||
}
|
||||
|
||||
{
|
||||
int *arr = (int *)taosMemoryMalloc(sizeof(int) * pSyncIndexMgr->replicaNum);
|
||||
for (int i = 0; i < pSyncIndexMgr->replicaNum; ++i) {
|
||||
arr[i] = pSyncIndexMgr->privateTerm[i];
|
||||
}
|
||||
cJSON *pIndex = cJSON_CreateIntArray(arr, pSyncIndexMgr->replicaNum);
|
||||
taosMemoryFree(arr);
|
||||
cJSON_AddItemToObject(pRoot, "privateTerm", pIndex);
|
||||
}
|
||||
|
||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncIndexMgr->pSyncNode);
|
||||
cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf);
|
||||
}
|
||||
|
||||
cJSON *pJson = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(pJson, "pSyncIndexMgr", pRoot);
|
||||
return pJson;
|
||||
}
|
||||
|
||||
char *syncIndexMgr2Str(SSyncIndexMgr *pSyncIndexMgr) {
|
||||
cJSON *pJson = syncIndexMgr2Json(pSyncIndexMgr);
|
||||
char *serialized = cJSON_Print(pJson);
|
||||
cJSON_Delete(pJson);
|
||||
return serialized;
|
||||
}
|
||||
|
||||
void syncIndexMgrSetStartTime(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId, int64_t startTime) {
|
||||
for (int i = 0; i < pSyncIndexMgr->replicaNum; ++i) {
|
||||
if (syncUtilSameId(&((*(pSyncIndexMgr->replicas))[i]), pRaftId)) {
|
||||
|
@ -201,35 +151,6 @@ int64_t syncIndexMgrGetRecvTime(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRa
|
|||
return -1;
|
||||
}
|
||||
|
||||
// for debug -------------------
|
||||
void syncIndexMgrPrint(SSyncIndexMgr *pObj) {
|
||||
char *serialized = syncIndexMgr2Str(pObj);
|
||||
printf("syncIndexMgrPrint | len:%" PRIu64 " | %s \n", (uint64_t)strlen(serialized), serialized);
|
||||
fflush(NULL);
|
||||
taosMemoryFree(serialized);
|
||||
}
|
||||
|
||||
void syncIndexMgrPrint2(char *s, SSyncIndexMgr *pObj) {
|
||||
char *serialized = syncIndexMgr2Str(pObj);
|
||||
printf("syncIndexMgrPrint2 | len:%" PRIu64 " | %s | %s \n", (uint64_t)strlen(serialized), s, serialized);
|
||||
fflush(NULL);
|
||||
taosMemoryFree(serialized);
|
||||
}
|
||||
|
||||
void syncIndexMgrLog(SSyncIndexMgr *pObj) {
|
||||
char *serialized = syncIndexMgr2Str(pObj);
|
||||
sTrace("syncIndexMgrLog | len:%" PRIu64 " | %s", (uint64_t)strlen(serialized), serialized);
|
||||
taosMemoryFree(serialized);
|
||||
}
|
||||
|
||||
void syncIndexMgrLog2(char *s, SSyncIndexMgr *pObj) {
|
||||
if (gRaftDetailLog) {
|
||||
char *serialized = syncIndexMgr2Str(pObj);
|
||||
sTrace("syncIndexMgrLog2 | len:%" PRIu64 " | %s | %s", (uint64_t)strlen(serialized), s, serialized);
|
||||
taosMemoryFree(serialized);
|
||||
}
|
||||
}
|
||||
|
||||
void syncIndexMgrSetTerm(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId, SyncTerm term) {
|
||||
for (int i = 0; i < pSyncIndexMgr->replicaNum; ++i) {
|
||||
if (syncUtilSameId(&((*(pSyncIndexMgr->replicas))[i]), pRaftId)) {
|
||||
|
|
|
@ -45,6 +45,18 @@ static bool syncIsConfigChanged(const SSyncCfg* pOldCfg, const SSyncCfg* pNew
|
|||
static int32_t syncHbTimerInit(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer, SRaftId destId);
|
||||
static int32_t syncHbTimerStart(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer);
|
||||
static int32_t syncHbTimerStop(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer);
|
||||
static int32_t syncNodeUpdateNewConfigIndex(SSyncNode* ths, SSyncCfg* pNewCfg);
|
||||
static bool syncNodeInConfig(SSyncNode* pSyncNode, const SSyncCfg* config);
|
||||
static void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* newConfig, SyncIndex lastConfigChangeIndex);
|
||||
static bool syncNodeIsOptimizedOneReplica(SSyncNode* ths, SRpcMsg* pMsg);
|
||||
|
||||
static bool syncNodeCanChange(SSyncNode* pSyncNode);
|
||||
static int32_t syncNodeLeaderTransfer(SSyncNode* pSyncNode);
|
||||
static int32_t syncNodeLeaderTransferTo(SSyncNode* pSyncNode, SNodeInfo newLeader);
|
||||
static int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* pEntry);
|
||||
|
||||
static ESyncStrategy syncNodeStrategy(SSyncNode* pSyncNode);
|
||||
static SyncIndex syncNodeGetSnapshotConfigIndex(SSyncNode* pSyncNode, SyncIndex snapshotLastApplyIndex);
|
||||
|
||||
int64_t syncOpen(SSyncInfo* pSyncInfo) {
|
||||
SSyncNode* pSyncNode = syncNodeOpen(pSyncInfo);
|
||||
|
@ -133,59 +145,44 @@ int32_t syncProcessMsg(int64_t rid, SRpcMsg* pMsg) {
|
|||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) return code;
|
||||
|
||||
if (pMsg->msgType == TDMT_SYNC_HEARTBEAT) {
|
||||
SyncHeartbeat* pSyncMsg = syncHeartbeatFromRpcMsg2(pMsg);
|
||||
code = syncNodeOnHeartbeat(pSyncNode, pSyncMsg);
|
||||
syncHeartbeatDestroy(pSyncMsg);
|
||||
} else if (pMsg->msgType == TDMT_SYNC_HEARTBEAT_REPLY) {
|
||||
SyncHeartbeatReply* pSyncMsg = syncHeartbeatReplyFromRpcMsg2(pMsg);
|
||||
code = syncNodeOnHeartbeatReply(pSyncNode, pSyncMsg);
|
||||
syncHeartbeatReplyDestroy(pSyncMsg);
|
||||
} else if (pMsg->msgType == TDMT_SYNC_TIMEOUT) {
|
||||
SyncTimeout* pSyncMsg = syncTimeoutFromRpcMsg2(pMsg);
|
||||
code = syncNodeOnTimer(pSyncNode, pSyncMsg);
|
||||
syncTimeoutDestroy(pSyncMsg);
|
||||
} else if (pMsg->msgType == TDMT_SYNC_PING) {
|
||||
SyncPing* pSyncMsg = syncPingFromRpcMsg2(pMsg);
|
||||
code = syncNodeOnPing(pSyncNode, pSyncMsg);
|
||||
syncPingDestroy(pSyncMsg);
|
||||
} else if (pMsg->msgType == TDMT_SYNC_PING_REPLY) {
|
||||
SyncPingReply* pSyncMsg = syncPingReplyFromRpcMsg2(pMsg);
|
||||
code = syncNodeOnPingReply(pSyncNode, pSyncMsg);
|
||||
syncPingReplyDestroy(pSyncMsg);
|
||||
} else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) {
|
||||
code = syncNodeOnClientRequest(pSyncNode, pMsg, NULL);
|
||||
} else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE) {
|
||||
SyncRequestVote* pSyncMsg = syncRequestVoteFromRpcMsg2(pMsg);
|
||||
code = syncNodeOnRequestVote(pSyncNode, pSyncMsg);
|
||||
syncRequestVoteDestroy(pSyncMsg);
|
||||
} else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) {
|
||||
SyncRequestVoteReply* pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pMsg);
|
||||
code = syncNodeOnRequestVoteReply(pSyncNode, pSyncMsg);
|
||||
syncRequestVoteReplyDestroy(pSyncMsg);
|
||||
} else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES) {
|
||||
SyncAppendEntries* pSyncMsg = syncAppendEntriesFromRpcMsg2(pMsg);
|
||||
code = syncNodeOnAppendEntries(pSyncNode, pSyncMsg);
|
||||
syncAppendEntriesDestroy(pSyncMsg);
|
||||
} else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_REPLY) {
|
||||
SyncAppendEntriesReply* pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pMsg);
|
||||
code = syncNodeOnAppendEntriesReply(pSyncNode, pSyncMsg);
|
||||
syncAppendEntriesReplyDestroy(pSyncMsg);
|
||||
} else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_SEND) {
|
||||
SyncSnapshotSend* pSyncMsg = syncSnapshotSendFromRpcMsg2(pMsg);
|
||||
code = syncNodeOnSnapshot(pSyncNode, pSyncMsg);
|
||||
syncSnapshotSendDestroy(pSyncMsg);
|
||||
} else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_RSP) {
|
||||
SyncSnapshotRsp* pSyncMsg = syncSnapshotRspFromRpcMsg2(pMsg);
|
||||
code = syncNodeOnSnapshotReply(pSyncNode, pSyncMsg);
|
||||
syncSnapshotRspDestroy(pSyncMsg);
|
||||
} else if (pMsg->msgType == TDMT_SYNC_LOCAL_CMD) {
|
||||
SyncLocalCmd* pSyncMsg = syncLocalCmdFromRpcMsg2(pMsg);
|
||||
code = syncNodeOnLocalCmd(pSyncNode, pSyncMsg);
|
||||
syncLocalCmdDestroy(pSyncMsg);
|
||||
} else {
|
||||
sError("vgId:%d, failed to process msg:%p since invalid type:%s", pSyncNode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
|
||||
code = -1;
|
||||
switch (pMsg->msgType) {
|
||||
case TDMT_SYNC_HEARTBEAT:
|
||||
code = syncNodeOnHeartbeat(pSyncNode, pMsg);
|
||||
break;
|
||||
case TDMT_SYNC_HEARTBEAT_REPLY:
|
||||
code = syncNodeOnHeartbeatReply(pSyncNode, pMsg);
|
||||
break;
|
||||
case TDMT_SYNC_TIMEOUT:
|
||||
code = syncNodeOnTimeout(pSyncNode, pMsg);
|
||||
break;
|
||||
case TDMT_SYNC_CLIENT_REQUEST:
|
||||
code = syncNodeOnClientRequest(pSyncNode, pMsg, NULL);
|
||||
break;
|
||||
case TDMT_SYNC_REQUEST_VOTE:
|
||||
code = syncNodeOnRequestVote(pSyncNode, pMsg);
|
||||
break;
|
||||
case TDMT_SYNC_REQUEST_VOTE_REPLY:
|
||||
code = syncNodeOnRequestVoteReply(pSyncNode, pMsg);
|
||||
break;
|
||||
case TDMT_SYNC_APPEND_ENTRIES:
|
||||
code = syncNodeOnAppendEntries(pSyncNode, pMsg);
|
||||
break;
|
||||
case TDMT_SYNC_APPEND_ENTRIES_REPLY:
|
||||
code = syncNodeOnAppendEntriesReply(pSyncNode, pMsg);
|
||||
break;
|
||||
case TDMT_SYNC_SNAPSHOT_SEND:
|
||||
code = syncNodeOnSnapshot(pSyncNode, pMsg);
|
||||
break;
|
||||
case TDMT_SYNC_SNAPSHOT_RSP:
|
||||
code = syncNodeOnSnapshotReply(pSyncNode, pMsg);
|
||||
break;
|
||||
case TDMT_SYNC_LOCAL_CMD:
|
||||
code = syncNodeOnLocalCmd(pSyncNode, pMsg);
|
||||
break;
|
||||
default:
|
||||
sError("vgId:%d, failed to process msg:%p since invalid type:%s", pSyncNode->vgId, pMsg,
|
||||
TMSG_INFO(pMsg->msgType));
|
||||
code = -1;
|
||||
}
|
||||
|
||||
syncNodeRelease(pSyncNode);
|
||||
|
@ -388,7 +385,7 @@ bool syncIsReadyForRead(int64_t rid) {
|
|||
if (!pSyncNode->pLogStore->syncLogIsEmpty(pSyncNode->pLogStore)) {
|
||||
SSyncRaftEntry* pEntry = NULL;
|
||||
int32_t code = pSyncNode->pLogStore->syncLogGetEntry(
|
||||
pSyncNode->pLogStore, pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore), &pEntry);
|
||||
pSyncNode->pLogStore, pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore), &pEntry);
|
||||
if (code == 0 && pEntry != NULL) {
|
||||
if (pEntry->originalRpcType == TDMT_SYNC_NOOP && pEntry->term == pSyncNode->pRaftStore->currentTerm) {
|
||||
ready = true;
|
||||
|
@ -437,17 +434,15 @@ int32_t syncNodeLeaderTransferTo(SSyncNode* pSyncNode, SNodeInfo newLeader) {
|
|||
|
||||
sNTrace(pSyncNode, "begin leader transfer to %s:%u", newLeader.nodeFqdn, newLeader.nodePort);
|
||||
|
||||
SyncLeaderTransfer* pMsg = syncLeaderTransferBuild(pSyncNode->vgId);
|
||||
SRpcMsg rpcMsg = {0};
|
||||
(void)syncBuildLeaderTransfer(&rpcMsg, pSyncNode->vgId);
|
||||
|
||||
SyncLeaderTransfer* pMsg = rpcMsg.pCont;
|
||||
pMsg->newLeaderId.addr = syncUtilAddr2U64(newLeader.nodeFqdn, newLeader.nodePort);
|
||||
pMsg->newLeaderId.vgId = pSyncNode->vgId;
|
||||
pMsg->newNodeInfo = newLeader;
|
||||
ASSERT(pMsg != NULL);
|
||||
SRpcMsg rpcMsg = {0};
|
||||
syncLeaderTransfer2RpcMsg(pMsg, &rpcMsg);
|
||||
syncLeaderTransferDestroy(pMsg);
|
||||
|
||||
int32_t ret = syncNodePropose(pSyncNode, &rpcMsg, false);
|
||||
return ret;
|
||||
return syncNodePropose(pSyncNode, &rpcMsg, false);
|
||||
}
|
||||
|
||||
SSyncState syncGetState(int64_t rid) {
|
||||
|
@ -619,7 +614,7 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak) {
|
|||
SRespStub stub = {.createTime = taosGetTimestampMs(), .rpcMsg = *pMsg};
|
||||
uint64_t seqNum = syncRespMgrAdd(pSyncNode->pSyncRespMgr, &stub);
|
||||
SRpcMsg rpcMsg = {0};
|
||||
int32_t code = syncClientRequestBuildFromRpcMsg(&rpcMsg, pMsg, seqNum, isWeak, pSyncNode->vgId);
|
||||
int32_t code = syncBuildClientRequest(&rpcMsg, pMsg, seqNum, isWeak, pSyncNode->vgId);
|
||||
if (code != 0) {
|
||||
sError("vgId:%d, failed to propose msg while serialize since %s", pSyncNode->vgId, terrstr());
|
||||
(void)syncRespMgrDel(pSyncNode->pSyncRespMgr, seqNum);
|
||||
|
@ -906,18 +901,6 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) {
|
|||
syncHbTimerInit(pSyncNode, &(pSyncNode->peerHeartbeatTimerArr[i]), (pSyncNode->replicasId)[i]);
|
||||
}
|
||||
|
||||
// init callback
|
||||
pSyncNode->FpOnPing = syncNodeOnPing;
|
||||
pSyncNode->FpOnPingReply = syncNodeOnPingReply;
|
||||
pSyncNode->FpOnClientRequest = syncNodeOnClientRequest;
|
||||
pSyncNode->FpOnTimeout = syncNodeOnTimer;
|
||||
pSyncNode->FpOnSnapshot = syncNodeOnSnapshot;
|
||||
pSyncNode->FpOnSnapshotReply = syncNodeOnSnapshotReply;
|
||||
pSyncNode->FpOnRequestVote = syncNodeOnRequestVote;
|
||||
pSyncNode->FpOnRequestVoteReply = syncNodeOnRequestVoteReply;
|
||||
pSyncNode->FpOnAppendEntries = syncNodeOnAppendEntries;
|
||||
pSyncNode->FpOnAppendEntriesReply = syncNodeOnAppendEntriesReply;
|
||||
|
||||
// tools
|
||||
pSyncNode->pSyncRespMgr = syncRespMgrCreate(pSyncNode, SYNC_RESP_TTL_MS);
|
||||
if (pSyncNode->pSyncRespMgr == NULL) {
|
||||
|
@ -1076,9 +1059,6 @@ void syncNodeClose(SSyncNode* pSyncNode) {
|
|||
taosMemoryFree(pSyncNode);
|
||||
}
|
||||
|
||||
// option
|
||||
// bool syncNodeSnapshotEnable(SSyncNode* pSyncNode) { return pSyncNode->pRaftCfg->snapshotEnable; }
|
||||
|
||||
ESyncStrategy syncNodeStrategy(SSyncNode* pSyncNode) { return pSyncNode->pRaftCfg->snapshotStrategy; }
|
||||
|
||||
// timer control --------------
|
||||
|
@ -1222,6 +1202,7 @@ int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, SRp
|
|||
pSyncNode->syncSendMSg(&epSet, pMsg);
|
||||
} else {
|
||||
sError("vgId:%d, sync send msg by id error, fp-send-msg is null", pSyncNode->vgId);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1663,8 +1644,6 @@ void syncNodeCandidate2Follower(SSyncNode* pSyncNode) {
|
|||
sNTrace(pSyncNode, "candidate to follower");
|
||||
}
|
||||
|
||||
// raft vote --------------
|
||||
|
||||
// just called by syncNodeVoteForSelf
|
||||
// need assert
|
||||
void syncNodeVoteForTerm(SSyncNode* pSyncNode, SyncTerm term, SRaftId* pRaftId) {
|
||||
|
@ -1676,9 +1655,13 @@ void syncNodeVoteForTerm(SSyncNode* pSyncNode, SyncTerm term, SRaftId* pRaftId)
|
|||
|
||||
// simulate get vote from outside
|
||||
void syncNodeVoteForSelf(SSyncNode* pSyncNode) {
|
||||
syncNodeVoteForTerm(pSyncNode, pSyncNode->pRaftStore->currentTerm, &(pSyncNode->myRaftId));
|
||||
syncNodeVoteForTerm(pSyncNode, pSyncNode->pRaftStore->currentTerm, &pSyncNode->myRaftId);
|
||||
|
||||
SyncRequestVoteReply* pMsg = syncRequestVoteReplyBuild(pSyncNode->vgId);
|
||||
SRpcMsg rpcMsg = {0};
|
||||
int32_t ret = syncBuildRequestVoteReply(&rpcMsg, pSyncNode->vgId);
|
||||
if (ret != 0) return;
|
||||
|
||||
SyncRequestVoteReply* pMsg = rpcMsg.pCont;
|
||||
pMsg->srcId = pSyncNode->myRaftId;
|
||||
pMsg->destId = pSyncNode->myRaftId;
|
||||
pMsg->term = pSyncNode->pRaftStore->currentTerm;
|
||||
|
@ -1686,11 +1669,9 @@ void syncNodeVoteForSelf(SSyncNode* pSyncNode) {
|
|||
|
||||
voteGrantedVote(pSyncNode->pVotesGranted, pMsg);
|
||||
votesRespondAdd(pSyncNode->pVotesRespond, pMsg);
|
||||
syncRequestVoteReplyDestroy(pMsg);
|
||||
rpcFreeCont(rpcMsg.pCont);
|
||||
}
|
||||
|
||||
// snapshot --------------
|
||||
|
||||
// return if has a snapshot
|
||||
bool syncNodeHasSnapshot(SSyncNode* pSyncNode) {
|
||||
bool ret = false;
|
||||
|
@ -1817,70 +1798,67 @@ int32_t syncNodeGetPreIndexTerm(SSyncNode* pSyncNode, SyncIndex index, SyncIndex
|
|||
}
|
||||
|
||||
static void syncNodeEqPingTimer(void* param, void* tmrId) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)param;
|
||||
if (atomic_load_64(&pSyncNode->pingTimerLogicClockUser) <= atomic_load_64(&pSyncNode->pingTimerLogicClock)) {
|
||||
SyncTimeout* pSyncMsg = syncTimeoutBuild2(SYNC_TIMEOUT_PING, atomic_load_64(&pSyncNode->pingTimerLogicClock),
|
||||
pSyncNode->pingTimerMS, pSyncNode->vgId, pSyncNode);
|
||||
SRpcMsg rpcMsg;
|
||||
syncTimeout2RpcMsg(pSyncMsg, &rpcMsg);
|
||||
sNTrace(pSyncNode, "enqueue ping timer");
|
||||
if (pSyncNode->syncEqMsg != NULL) {
|
||||
int32_t code = pSyncNode->syncEqMsg(pSyncNode->msgcb, &rpcMsg);
|
||||
if (code != 0) {
|
||||
sError("vgId:%d, sync enqueue ping msg error, code:%d", pSyncNode->vgId, code);
|
||||
rpcFreeCont(rpcMsg.pCont);
|
||||
syncTimeoutDestroy(pSyncMsg);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
sTrace("syncNodeEqPingTimer pSyncNode->syncEqMsg is NULL");
|
||||
}
|
||||
syncTimeoutDestroy(pSyncMsg);
|
||||
if (!syncIsInit()) return;
|
||||
|
||||
if (syncIsInit()) {
|
||||
taosTmrReset(syncNodeEqPingTimer, pSyncNode->pingTimerMS, pSyncNode, syncEnv()->pTimerManager,
|
||||
&pSyncNode->pPingTimer);
|
||||
} else {
|
||||
sError("sync env is stop, syncNodeEqPingTimer");
|
||||
SSyncNode* pNode = param;
|
||||
if (atomic_load_64(&pNode->pingTimerLogicClockUser) <= atomic_load_64(&pNode->pingTimerLogicClock)) {
|
||||
SRpcMsg rpcMsg = {0};
|
||||
int32_t code = syncBuildTimeout(&rpcMsg, SYNC_TIMEOUT_PING, atomic_load_64(&pNode->pingTimerLogicClock),
|
||||
pNode->pingTimerMS, pNode);
|
||||
if (code != 0) {
|
||||
sNError(pNode, "failed to build ping msg");
|
||||
rpcFreeCont(rpcMsg.pCont);
|
||||
return;
|
||||
}
|
||||
|
||||
sNTrace(pNode, "enqueue ping msg");
|
||||
code = pNode->syncEqMsg(pNode->msgcb, &rpcMsg);
|
||||
if (code != 0) {
|
||||
sNError(pNode, "failed to sync enqueue ping msg since %s", terrstr());
|
||||
rpcFreeCont(rpcMsg.pCont);
|
||||
return;
|
||||
}
|
||||
|
||||
taosTmrReset(syncNodeEqPingTimer, pNode->pingTimerMS, pNode, syncEnv()->pTimerManager, &pNode->pPingTimer);
|
||||
} else {
|
||||
sTrace("==syncNodeEqPingTimer== pingTimerLogicClock:%" PRId64 ", pingTimerLogicClockUser:%" PRId64,
|
||||
pSyncNode->pingTimerLogicClock, pSyncNode->pingTimerLogicClockUser);
|
||||
pNode->pingTimerLogicClock, pNode->pingTimerLogicClockUser);
|
||||
}
|
||||
}
|
||||
|
||||
static void syncNodeEqElectTimer(void* param, void* tmrId) {
|
||||
SElectTimer* pElectTimer = (SElectTimer*)param;
|
||||
SSyncNode* pSyncNode = pElectTimer->pSyncNode;
|
||||
if (!syncIsInit()) return;
|
||||
|
||||
SyncTimeout* pSyncMsg = syncTimeoutBuild2(SYNC_TIMEOUT_ELECTION, pElectTimer->logicClock, pSyncNode->electTimerMS,
|
||||
pSyncNode->vgId, pSyncNode);
|
||||
SRpcMsg rpcMsg;
|
||||
syncTimeout2RpcMsg(pSyncMsg, &rpcMsg);
|
||||
if (pSyncNode->syncEqMsg != NULL && pSyncNode->msgcb != NULL && pSyncNode->msgcb->putToQueueFp != NULL) {
|
||||
int32_t code = pSyncNode->syncEqMsg(pSyncNode->msgcb, &rpcMsg);
|
||||
if (code != 0) {
|
||||
sError("vgId:%d, sync enqueue elect msg error, code:%d", pSyncNode->vgId, code);
|
||||
rpcFreeCont(rpcMsg.pCont);
|
||||
syncTimeoutDestroy(pSyncMsg);
|
||||
taosMemoryFree(pElectTimer);
|
||||
return;
|
||||
}
|
||||
sNTrace(pSyncNode, "eq elect timer lc:%" PRId64, pSyncMsg->logicClock);
|
||||
} else {
|
||||
sTrace("syncNodeEqElectTimer syncEqMsg is NULL");
|
||||
SElectTimer* pElectTimer = param;
|
||||
SSyncNode* pNode = pElectTimer->pSyncNode;
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
int32_t code = syncBuildTimeout(&rpcMsg, SYNC_TIMEOUT_ELECTION, pElectTimer->logicClock, pNode->electTimerMS, pNode);
|
||||
|
||||
if (code != 0) {
|
||||
sNError(pNode, "failed to build elect msg");
|
||||
taosMemoryFree(pElectTimer);
|
||||
return;
|
||||
}
|
||||
|
||||
SyncTimeout* pTimeout = rpcMsg.pCont;
|
||||
sNTrace(pNode, "enqueue elect msg lc:%" PRId64, pTimeout->logicClock);
|
||||
|
||||
code = pNode->syncEqMsg(pNode->msgcb, &rpcMsg);
|
||||
if (code != 0) {
|
||||
sNError(pNode, "failed to sync enqueue elect msg since %s", terrstr());
|
||||
rpcFreeCont(rpcMsg.pCont);
|
||||
taosMemoryFree(pElectTimer);
|
||||
return;
|
||||
}
|
||||
|
||||
syncTimeoutDestroy(pSyncMsg);
|
||||
taosMemoryFree(pElectTimer);
|
||||
|
||||
#if 0
|
||||
// reset timer ms
|
||||
if (syncIsInit() && pSyncNode->electBaseLine > 0) {
|
||||
pSyncNode->electTimerMS = syncUtilElectRandomMS(pSyncNode->electBaseLine, 2 * pSyncNode->electBaseLine);
|
||||
taosTmrReset(syncNodeEqElectTimer, pSyncNode->electTimerMS, pSyncNode, syncEnv()->pTimerManager,
|
||||
&pSyncNode->pElectTimer);
|
||||
if (syncIsInit() && pNode->electBaseLine > 0) {
|
||||
pNode->electTimerMS = syncUtilElectRandomMS(pNode->electBaseLine, 2 * pNode->electBaseLine);
|
||||
taosTmrReset(syncNodeEqElectTimer, pNode->electTimerMS, pNode, syncEnv()->pTimerManager, &pNode->pElectTimer);
|
||||
} else {
|
||||
sError("sync env is stop, syncNodeEqElectTimer");
|
||||
}
|
||||
|
@ -1888,41 +1866,34 @@ static void syncNodeEqElectTimer(void* param, void* tmrId) {
|
|||
}
|
||||
|
||||
static void syncNodeEqHeartbeatTimer(void* param, void* tmrId) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)param;
|
||||
sNTrace(pSyncNode, "eq hb timer");
|
||||
if (!syncIsInit()) return;
|
||||
|
||||
if (pSyncNode->replicaNum > 1) {
|
||||
if (atomic_load_64(&pSyncNode->heartbeatTimerLogicClockUser) <=
|
||||
atomic_load_64(&pSyncNode->heartbeatTimerLogicClock)) {
|
||||
SyncTimeout* pSyncMsg =
|
||||
syncTimeoutBuild2(SYNC_TIMEOUT_HEARTBEAT, atomic_load_64(&pSyncNode->heartbeatTimerLogicClock),
|
||||
pSyncNode->heartbeatTimerMS, pSyncNode->vgId, pSyncNode);
|
||||
SRpcMsg rpcMsg;
|
||||
syncTimeout2RpcMsg(pSyncMsg, &rpcMsg);
|
||||
sNTrace(pSyncNode, "enqueue heartbeat timer");
|
||||
if (pSyncNode->syncEqMsg != NULL) {
|
||||
int32_t code = pSyncNode->syncEqMsg(pSyncNode->msgcb, &rpcMsg);
|
||||
if (code != 0) {
|
||||
sError("vgId:%d, sync enqueue timer msg error, code:%d", pSyncNode->vgId, code);
|
||||
rpcFreeCont(rpcMsg.pCont);
|
||||
syncTimeoutDestroy(pSyncMsg);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
sError("vgId:%d, enqueue msg cb ptr (i.e. syncEqMsg) not set.", pSyncNode->vgId);
|
||||
}
|
||||
syncTimeoutDestroy(pSyncMsg);
|
||||
SSyncNode* pNode = param;
|
||||
if (pNode->replicaNum > 1) {
|
||||
if (atomic_load_64(&pNode->heartbeatTimerLogicClockUser) <= atomic_load_64(&pNode->heartbeatTimerLogicClock)) {
|
||||
SRpcMsg rpcMsg = {0};
|
||||
int32_t code = syncBuildTimeout(&rpcMsg, SYNC_TIMEOUT_HEARTBEAT, atomic_load_64(&pNode->heartbeatTimerLogicClock),
|
||||
pNode->heartbeatTimerMS, pNode);
|
||||
|
||||
if (syncIsInit()) {
|
||||
taosTmrReset(syncNodeEqHeartbeatTimer, pSyncNode->heartbeatTimerMS, pSyncNode, syncEnv()->pTimerManager,
|
||||
&pSyncNode->pHeartbeatTimer);
|
||||
} else {
|
||||
sError("sync env is stop, syncNodeEqHeartbeatTimer");
|
||||
if (code != 0) {
|
||||
sNError(pNode, "failed to build heartbeat msg");
|
||||
return;
|
||||
}
|
||||
|
||||
sNTrace(pNode, "enqueue heartbeat timer");
|
||||
code = pNode->syncEqMsg(pNode->msgcb, &rpcMsg);
|
||||
if (code != 0) {
|
||||
sNError(pNode, "failed to enqueue heartbeat msg since %s", terrstr());
|
||||
rpcFreeCont(rpcMsg.pCont);
|
||||
return;
|
||||
}
|
||||
|
||||
taosTmrReset(syncNodeEqHeartbeatTimer, pNode->heartbeatTimerMS, pNode, syncEnv()->pTimerManager,
|
||||
&pNode->pHeartbeatTimer);
|
||||
|
||||
} else {
|
||||
sTrace("==syncNodeEqHeartbeatTimer== heartbeatTimerLogicClock:%" PRId64 ", heartbeatTimerLogicClockUser:%" PRId64
|
||||
"",
|
||||
pSyncNode->heartbeatTimerLogicClock, pSyncNode->heartbeatTimerLogicClockUser);
|
||||
sTrace("==syncNodeEqHeartbeatTimer== heartbeatTimerLogicClock:%" PRId64 ", heartbeatTimerLogicClockUser:%" PRId64,
|
||||
pNode->heartbeatTimerLogicClock, pNode->heartbeatTimerLogicClockUser);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1951,7 +1922,10 @@ static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId) {
|
|||
|
||||
if (pSyncNode->replicaNum > 1) {
|
||||
if (timerLogicClock == msgLogicClock) {
|
||||
SyncHeartbeat* pSyncMsg = syncHeartbeatBuild(pSyncNode->vgId);
|
||||
SRpcMsg rpcMsg = {0};
|
||||
(void)syncBuildHeartbeat(&rpcMsg, pSyncNode->vgId);
|
||||
|
||||
SyncHeartbeat* pSyncMsg = rpcMsg.pCont;
|
||||
pSyncMsg->srcId = pSyncNode->myRaftId;
|
||||
pSyncMsg->destId = pData->destId;
|
||||
pSyncMsg->term = pSyncNode->pRaftStore->currentTerm;
|
||||
|
@ -1959,28 +1933,8 @@ static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId) {
|
|||
pSyncMsg->minMatchIndex = syncMinMatchIndex(pSyncNode);
|
||||
pSyncMsg->privateTerm = 0;
|
||||
|
||||
SRpcMsg rpcMsg;
|
||||
syncHeartbeat2RpcMsg(pSyncMsg, &rpcMsg);
|
||||
|
||||
// eq msg
|
||||
#if 0
|
||||
if (pSyncNode->syncEqCtrlMsg != NULL) {
|
||||
int32_t code = pSyncNode->syncEqCtrlMsg(pSyncNode->msgcb, &rpcMsg);
|
||||
if (code != 0) {
|
||||
sError("vgId:%d, sync ctrl enqueue timer msg error, code:%d", pSyncNode->vgId, code);
|
||||
rpcFreeCont(rpcMsg.pCont);
|
||||
syncHeartbeatDestroy(pSyncMsg);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
sError("vgId:%d, enqueue ctrl msg cb ptr (i.e. syncEqMsg) not set.", pSyncNode->vgId);
|
||||
}
|
||||
#endif
|
||||
|
||||
// send msg
|
||||
syncNodeSendHeartbeat(pSyncNode, &(pSyncMsg->destId), pSyncMsg);
|
||||
|
||||
syncHeartbeatDestroy(pSyncMsg);
|
||||
syncNodeSendHeartbeat(pSyncNode, &pSyncMsg->destId, &rpcMsg);
|
||||
|
||||
if (syncIsInit()) {
|
||||
taosTmrReset(syncNodeEqPeerHeartbeatTimer, pSyncTimer->timerMS, pData, syncEnv()->pTimerManager,
|
||||
|
@ -2008,7 +1962,7 @@ static int32_t syncNodeEqNoop(SSyncNode* pNode) {
|
|||
if (pEntry == NULL) return -1;
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
int32_t code = syncClientRequestBuildFromNoopEntry(&rpcMsg, pEntry, pNode->vgId);
|
||||
int32_t code = syncBuildClientRequestFromNoopEntry(&rpcMsg, pEntry, pNode->vgId);
|
||||
syncEntryDestory(pEntry);
|
||||
|
||||
sNTrace(pNode, "propose msg, type:noop");
|
||||
|
@ -2062,58 +2016,32 @@ static int32_t syncNodeAppendNoop(SSyncNode* ths) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
// on message ----
|
||||
int32_t syncNodeOnPing(SSyncNode* ths, SyncPing* pMsg) {
|
||||
sTrace("vgId:%d, recv sync-ping", ths->vgId);
|
||||
|
||||
SyncPingReply* pMsgReply = syncPingReplyBuild3(&ths->myRaftId, &pMsg->srcId, ths->vgId);
|
||||
SRpcMsg rpcMsg;
|
||||
syncPingReply2RpcMsg(pMsgReply, &rpcMsg);
|
||||
|
||||
/*
|
||||
// htonl
|
||||
SMsgHead* pHead = rpcMsg.pCont;
|
||||
pHead->contLen = htonl(pHead->contLen);
|
||||
pHead->vgId = htonl(pHead->vgId);
|
||||
*/
|
||||
|
||||
syncNodeSendMsgById(&pMsgReply->destId, ths, &rpcMsg);
|
||||
syncPingReplyDestroy(pMsgReply);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t syncNodeOnPingReply(SSyncNode* ths, SyncPingReply* pMsg) {
|
||||
int32_t ret = 0;
|
||||
sTrace("vgId:%d, recv sync-ping-reply", ths->vgId);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t syncNodeOnHeartbeat(SSyncNode* ths, SyncHeartbeat* pMsg) {
|
||||
int32_t syncNodeOnHeartbeat(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
||||
SyncHeartbeat* pMsg = pRpcMsg->pCont;
|
||||
syncLogRecvHeartbeat(ths, pMsg, "");
|
||||
|
||||
SyncHeartbeatReply* pMsgReply = syncHeartbeatReplyBuild(ths->vgId);
|
||||
SRpcMsg rpcMsg = {0};
|
||||
(void)syncBuildHeartbeatReply(&rpcMsg, ths->vgId);
|
||||
|
||||
SyncHeartbeatReply* pMsgReply = rpcMsg.pCont;
|
||||
pMsgReply->destId = pMsg->srcId;
|
||||
pMsgReply->srcId = ths->myRaftId;
|
||||
pMsgReply->term = ths->pRaftStore->currentTerm;
|
||||
pMsgReply->privateTerm = 8864; // magic number
|
||||
|
||||
SRpcMsg rpcMsg;
|
||||
syncHeartbeatReply2RpcMsg(pMsgReply, &rpcMsg);
|
||||
|
||||
if (pMsg->term == ths->pRaftStore->currentTerm && ths->state != TAOS_SYNC_STATE_LEADER) {
|
||||
syncNodeResetElectTimer(ths);
|
||||
ths->minMatchIndex = pMsg->minMatchIndex;
|
||||
|
||||
if (ths->state == TAOS_SYNC_STATE_FOLLOWER) {
|
||||
// syncNodeFollowerCommit(ths, pMsg->commitIndex);
|
||||
SyncLocalCmd* pSyncMsg = syncLocalCmdBuild(ths->vgId);
|
||||
SRpcMsg rpcMsgLocalCmd = {0};
|
||||
(void)syncBuildLocalCmd(&rpcMsgLocalCmd, ths->vgId);
|
||||
|
||||
SyncLocalCmd* pSyncMsg = rpcMsgLocalCmd.pCont;
|
||||
pSyncMsg->cmd = SYNC_LOCAL_CMD_FOLLOWER_CMT;
|
||||
pSyncMsg->fcIndex = pMsg->commitIndex;
|
||||
|
||||
SRpcMsg rpcMsgLocalCmd;
|
||||
syncLocalCmd2RpcMsg(pSyncMsg, &rpcMsgLocalCmd);
|
||||
|
||||
if (ths->syncEqMsg != NULL && ths->msgcb != NULL) {
|
||||
int32_t code = ths->syncEqMsg(ths->msgcb, &rpcMsgLocalCmd);
|
||||
if (code != 0) {
|
||||
|
@ -2128,13 +2056,13 @@ int32_t syncNodeOnHeartbeat(SSyncNode* ths, SyncHeartbeat* pMsg) {
|
|||
|
||||
if (pMsg->term >= ths->pRaftStore->currentTerm && ths->state != TAOS_SYNC_STATE_FOLLOWER) {
|
||||
// syncNodeStepDown(ths, pMsg->term);
|
||||
SyncLocalCmd* pSyncMsg = syncLocalCmdBuild(ths->vgId);
|
||||
SRpcMsg rpcMsgLocalCmd = {0};
|
||||
(void)syncBuildLocalCmd(&rpcMsgLocalCmd, ths->vgId);
|
||||
|
||||
SyncLocalCmd* pSyncMsg = rpcMsgLocalCmd.pCont;
|
||||
pSyncMsg->cmd = SYNC_LOCAL_CMD_STEP_DOWN;
|
||||
pSyncMsg->sdNewTerm = pMsg->term;
|
||||
|
||||
SRpcMsg rpcMsgLocalCmd;
|
||||
syncLocalCmd2RpcMsg(pSyncMsg, &rpcMsgLocalCmd);
|
||||
|
||||
if (ths->syncEqMsg != NULL && ths->msgcb != NULL) {
|
||||
int32_t code = ths->syncEqMsg(ths->msgcb, &rpcMsgLocalCmd);
|
||||
if (code != 0) {
|
||||
|
@ -2144,8 +2072,6 @@ int32_t syncNodeOnHeartbeat(SSyncNode* ths, SyncHeartbeat* pMsg) {
|
|||
sTrace("vgId:%d, sync enqueue step-down msg, new-term: %" PRId64, ths->vgId, pSyncMsg->sdNewTerm);
|
||||
}
|
||||
}
|
||||
|
||||
syncLocalCmdDestroy(pSyncMsg);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -2157,21 +2083,20 @@ int32_t syncNodeOnHeartbeat(SSyncNode* ths, SyncHeartbeat* pMsg) {
|
|||
|
||||
// reply
|
||||
syncNodeSendMsgById(&pMsgReply->destId, ths, &rpcMsg);
|
||||
syncHeartbeatReplyDestroy(pMsgReply);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t syncNodeOnHeartbeatReply(SSyncNode* ths, SyncHeartbeatReply* pMsg) {
|
||||
int32_t syncNodeOnHeartbeatReply(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
||||
SyncHeartbeatReply* pMsg = pRpcMsg->pCont;
|
||||
syncLogRecvHeartbeatReply(ths, pMsg, "");
|
||||
|
||||
// update last reply time, make decision whether the other node is alive or not
|
||||
syncIndexMgrSetRecvTime(ths->pMatchIndex, &(pMsg->destId), pMsg->startTime);
|
||||
|
||||
syncIndexMgrSetRecvTime(ths->pMatchIndex, &pMsg->destId, pMsg->startTime);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t syncNodeOnLocalCmd(SSyncNode* ths, SyncLocalCmd* pMsg) {
|
||||
int32_t syncNodeOnLocalCmd(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
||||
SyncLocalCmd* pMsg = pRpcMsg->pCont;
|
||||
syncLogRecvLocalCmd(ths, pMsg, "");
|
||||
|
||||
if (pMsg->cmd == SYNC_LOCAL_CMD_STEP_DOWN) {
|
||||
|
@ -2300,6 +2225,7 @@ const char* syncStr(ESyncState state) {
|
|||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* pEntry) {
|
||||
if (ths->state != TAOS_SYNC_STATE_FOLLOWER) {
|
||||
sNTrace(ths, "I am not follower, can not do leader transfer");
|
||||
|
@ -2328,7 +2254,7 @@ int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* p
|
|||
}
|
||||
*/
|
||||
|
||||
SyncLeaderTransfer* pSyncLeaderTransfer = syncLeaderTransferFromRpcMsg2(pRpcMsg);
|
||||
SyncLeaderTransfer* pSyncLeaderTransfer = pRpcMsg->pCont;
|
||||
sNTrace(ths, "do leader transfer, index:%" PRId64, pEntry->index);
|
||||
|
||||
bool sameId = syncUtilSameId(&(pSyncLeaderTransfer->newLeaderId), &(ths->myRaftId));
|
||||
|
@ -2361,10 +2287,11 @@ int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* p
|
|||
ths->pFsm->FpLeaderTransferCb(ths->pFsm, pRpcMsg, &cbMeta);
|
||||
}
|
||||
|
||||
syncLeaderTransferDestroy(pSyncLeaderTransfer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int32_t syncNodeUpdateNewConfigIndex(SSyncNode* ths, SSyncCfg* pNewCfg) {
|
||||
for (int32_t i = 0; i < pNewCfg->replicaNum; ++i) {
|
||||
SRaftId raftId;
|
||||
|
@ -2576,241 +2503,3 @@ bool syncNodeCanChange(SSyncNode* pSyncNode) {
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
const char* syncTimerTypeStr(enum ESyncTimeoutType timerType) {
|
||||
if (timerType == SYNC_TIMEOUT_PING) {
|
||||
return "ping";
|
||||
} else if (timerType == SYNC_TIMEOUT_ELECTION) {
|
||||
return "elect";
|
||||
} else if (timerType == SYNC_TIMEOUT_HEARTBEAT) {
|
||||
return "heartbeat";
|
||||
} else {
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
void syncLogRecvTimer(SSyncNode* pSyncNode, const SyncTimeout* pMsg, const char* s) {
|
||||
sNTrace(pSyncNode, "recv sync-timer {type:%s, lc:%" PRId64 ", ms:%d, data:%p}, %s",
|
||||
syncTimerTypeStr(pMsg->timeoutType), pMsg->logicClock, pMsg->timerMS, pMsg->data, s);
|
||||
}
|
||||
|
||||
void syncLogSendRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||
sNTrace(pSyncNode, "send sync-request-vote to %s:%d {term:%" PRId64 ", lindex:%" PRId64 ", lterm:%" PRId64 "}, %s",
|
||||
host, port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, s);
|
||||
}
|
||||
|
||||
void syncLogRecvRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, const char* s) {
|
||||
char logBuf[256];
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||
sNTrace(pSyncNode, "recv sync-request-vote from %s:%d, {term:%" PRId64 ", lindex:%" PRId64 ", lterm:%" PRId64 "}, %s",
|
||||
host, port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, s);
|
||||
}
|
||||
|
||||
void syncLogSendRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||
sNTrace(pSyncNode, "send sync-request-vote-reply to %s:%d {term:%" PRId64 ", grant:%d}, %s", host, port, pMsg->term,
|
||||
pMsg->voteGranted, s);
|
||||
}
|
||||
|
||||
void syncLogRecvRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||
sNTrace(pSyncNode, "recv sync-request-vote-reply from %s:%d {term:%" PRId64 ", grant:%d}, %s", host, port, pMsg->term,
|
||||
pMsg->voteGranted, s);
|
||||
}
|
||||
|
||||
void syncLogSendAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||
sNTrace(pSyncNode,
|
||||
"send sync-append-entries to %s:%d, {term:%" PRId64 ", pre-index:%" PRId64 ", pre-term:%" PRId64
|
||||
", pterm:%" PRId64 ", cmt:%" PRId64 ", datalen:%d}, %s",
|
||||
host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex,
|
||||
pMsg->dataLen, s);
|
||||
}
|
||||
|
||||
void syncLogRecvAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||
|
||||
sNTrace(pSyncNode,
|
||||
"recv sync-append-entries from %s:%d {term:%" PRId64 ", pre-index:%" PRId64 ", pre-term:%" PRId64
|
||||
", cmt:%" PRId64 ", pterm:%" PRId64 ", datalen:%d}, %s",
|
||||
host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm,
|
||||
pMsg->dataLen, s);
|
||||
}
|
||||
|
||||
void syncLogSendAppendEntriesBatch(SSyncNode* pSyncNode, const SyncAppendEntriesBatch* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||
|
||||
sNTrace(pSyncNode,
|
||||
"send sync-append-entries-batch to %s:%d, {term:%" PRId64 ", pre-index:%" PRId64 ", pre-term:%" PRId64
|
||||
", pterm:%" PRId64 ", cmt:%" PRId64 ", datalen:%d, count:%d}, %s",
|
||||
host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex,
|
||||
pMsg->dataLen, pMsg->dataCount, s);
|
||||
}
|
||||
|
||||
void syncLogRecvAppendEntriesBatch(SSyncNode* pSyncNode, const SyncAppendEntriesBatch* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||
|
||||
sNTrace(pSyncNode,
|
||||
"recv sync-append-entries-batch from %s:%d, {term:%" PRId64 ", pre-index:%" PRId64 ", pre-term:%" PRId64
|
||||
", pterm:%" PRId64 ", cmt:%" PRId64 ", datalen:%d, count:%d}, %s",
|
||||
host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex,
|
||||
pMsg->dataLen, pMsg->dataCount, s);
|
||||
}
|
||||
|
||||
void syncLogSendAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||
|
||||
sNTrace(pSyncNode,
|
||||
"send sync-append-entries-reply to %s:%d, {term:%" PRId64 ", pterm:%" PRId64 ", success:%d, match:%" PRId64
|
||||
"}, %s",
|
||||
host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex, s);
|
||||
}
|
||||
|
||||
void syncLogRecvAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||
|
||||
sNTrace(pSyncNode,
|
||||
"recv sync-append-entries-reply from %s:%d {term:%" PRId64 ", pterm:%" PRId64 ", success:%d, match:%" PRId64
|
||||
"}, %s",
|
||||
host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex, s);
|
||||
}
|
||||
|
||||
void syncLogSendHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||
|
||||
sNTrace(pSyncNode,
|
||||
"send sync-heartbeat to %s:%d {term:%" PRId64 ", cmt:%" PRId64 ", min-match:%" PRId64 ", pterm:%" PRId64
|
||||
"}, %s",
|
||||
host, port, pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->privateTerm, s);
|
||||
}
|
||||
|
||||
void syncLogRecvHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||
|
||||
sNTrace(pSyncNode,
|
||||
"recv sync-heartbeat from %s:%d {term:%" PRId64 ", cmt:%" PRId64 ", min-match:%" PRId64 ", pterm:%" PRId64
|
||||
"}, %s",
|
||||
host, port, pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->privateTerm, s);
|
||||
}
|
||||
|
||||
void syncLogSendHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||
|
||||
sNTrace(pSyncNode, "send sync-heartbeat-reply from %s:%d {term:%" PRId64 ", pterm:%" PRId64 "}, %s", host, port,
|
||||
pMsg->term, pMsg->privateTerm, s);
|
||||
}
|
||||
|
||||
void syncLogRecvHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||
sNTrace(pSyncNode, "recv sync-heartbeat-reply from %s:%d {term:%" PRId64 ", pterm:%" PRId64 "}, %s", host, port,
|
||||
pMsg->term, pMsg->privateTerm, s);
|
||||
}
|
||||
|
||||
void syncLogRecvLocalCmd(SSyncNode* pSyncNode, const SyncLocalCmd* pMsg, const char* s) {
|
||||
sNTrace(pSyncNode, "recv sync-local-cmd {cmd:%d-%s, sd-new-term:%" PRId64 ", fc-index:%" PRId64 "}, %s", pMsg->cmd,
|
||||
syncLocalCmdGetStr(pMsg->cmd), pMsg->sdNewTerm, pMsg->fcIndex, s);
|
||||
}
|
||||
|
||||
void syncLogSendSyncPreSnapshot(SSyncNode* pSyncNode, const SyncPreSnapshot* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||
sNTrace(pSyncNode, "send sync-pre-snapshot to %s:%d {term:%" PRId64 "}, %s", host, port, pMsg->term, s);
|
||||
}
|
||||
|
||||
void syncLogRecvSyncPreSnapshot(SSyncNode* pSyncNode, const SyncPreSnapshot* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||
sNTrace(pSyncNode, "recv sync-pre-snapshot from %s:%d {term:%" PRId64 "}, %s", host, port, pMsg->term, s);
|
||||
}
|
||||
|
||||
void syncLogSendSyncPreSnapshotReply(SSyncNode* pSyncNode, const SyncPreSnapshotReply* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||
sNTrace(pSyncNode, "send sync-pre-snapshot-reply to %s:%d {term:%" PRId64 ", snap-start:%" PRId64 "}, %s", host, port,
|
||||
pMsg->term, pMsg->snapStart, s);
|
||||
}
|
||||
|
||||
void syncLogRecvSyncPreSnapshotReply(SSyncNode* pSyncNode, const SyncPreSnapshotReply* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||
sNTrace(pSyncNode, "recv sync-pre-snapshot-reply from %s:%d {term:%" PRId64 ", snap-start:%" PRId64 "}, %s", host,
|
||||
port, pMsg->term, pMsg->snapStart, s);
|
||||
}
|
||||
|
||||
void syncLogSendSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||
|
||||
sNTrace(pSyncNode,
|
||||
"send sync-snapshot-send from %s:%d {term:%" PRId64 ", begin:%" PRId64 ", end:%" PRId64 ", lterm:%" PRId64
|
||||
", stime:%" PRId64 ", seq:%d}, %s",
|
||||
host, port, pMsg->term, pMsg->beginIndex, pMsg->lastIndex, pMsg->lastTerm, pMsg->startTime, pMsg->seq, s);
|
||||
}
|
||||
|
||||
void syncLogRecvSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||
|
||||
sNTrace(pSyncNode,
|
||||
"recv sync-snapshot-send from %s:%d {term:%" PRId64 ", begin:%" PRId64 ", lst:%" PRId64 ", lterm:%" PRId64
|
||||
", stime:%" PRId64 ", seq:%d, len:%u}, %s",
|
||||
host, port, pMsg->term, pMsg->beginIndex, pMsg->lastIndex, pMsg->lastTerm, pMsg->startTime, pMsg->seq,
|
||||
pMsg->dataLen, s);
|
||||
}
|
||||
|
||||
void syncLogSendSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||
|
||||
sNTrace(pSyncNode,
|
||||
"send sync-snapshot-rsp from %s:%d {term:%" PRId64 ", begin:%" PRId64 ", lst:%" PRId64 ", lterm:%" PRId64
|
||||
", stime:%" PRId64 ", ack:%d}, %s",
|
||||
host, port, pMsg->term, pMsg->snapBeginIndex, pMsg->lastIndex, pMsg->lastTerm, pMsg->startTime, pMsg->ack, s);
|
||||
}
|
||||
|
||||
void syncLogRecvSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||
|
||||
sNTrace(pSyncNode,
|
||||
"recv sync-snapshot-rsp from %s:%d {term:%" PRId64 ", begin:%" PRId64 ", lst:%" PRId64 ", lterm:%" PRId64
|
||||
", stime:%" PRId64 ", ack:%d}, %s",
|
||||
host, port, pMsg->term, pMsg->snapBeginIndex, pMsg->lastIndex, pMsg->lastTerm, pMsg->startTime, pMsg->ack, s);
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -13,9 +13,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "syncRaftCfg.h"
|
||||
#include "cJSON.h"
|
||||
#include "syncEnv.h"
|
||||
#include "syncUtil.h"
|
||||
|
||||
// file must already exist!
|
||||
|
@ -242,13 +241,6 @@ cJSON *syncCfg2Json(SSyncCfg *pSyncCfg) {
|
|||
return pRoot;
|
||||
}
|
||||
|
||||
char *syncCfg2Str(SSyncCfg *pSyncCfg) {
|
||||
cJSON *pJson = syncCfg2Json(pSyncCfg);
|
||||
char *serialized = cJSON_Print(pJson);
|
||||
cJSON_Delete(pJson);
|
||||
return serialized;
|
||||
}
|
||||
|
||||
int32_t syncCfgFromJson(const cJSON *pRoot, SSyncCfg *pSyncCfg) {
|
||||
memset(pSyncCfg, 0, sizeof(SSyncCfg));
|
||||
// cJSON *pJson = cJSON_GetObjectItem(pRoot, "SSyncCfg");
|
||||
|
@ -283,17 +275,6 @@ int32_t syncCfgFromJson(const cJSON *pRoot, SSyncCfg *pSyncCfg) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t syncCfgFromStr(const char *s, SSyncCfg *pSyncCfg) {
|
||||
cJSON *pRoot = cJSON_Parse(s);
|
||||
ASSERT(pRoot != NULL);
|
||||
|
||||
int32_t ret = syncCfgFromJson(pRoot, pSyncCfg);
|
||||
ASSERT(ret == 0);
|
||||
|
||||
cJSON_Delete(pRoot);
|
||||
return 0;
|
||||
}
|
||||
|
||||
cJSON *raftCfg2Json(SRaftCfg *pRaftCfg) {
|
||||
cJSON *pRoot = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(pRoot, "SSyncCfg", syncCfg2Json(&(pRaftCfg->cfg)));
|
||||
|
|
|
@ -102,7 +102,6 @@ void syncEntry2OriginalRpc(const SSyncRaftEntry* pEntry, SRpcMsg* pRpcMsg) {
|
|||
memcpy(pRpcMsg->pCont, pEntry->data, pRpcMsg->contLen);
|
||||
}
|
||||
|
||||
//-----------------------------------
|
||||
SRaftEntryHashCache* raftCacheCreate(SSyncNode* pSyncNode, int32_t maxCount) {
|
||||
SRaftEntryHashCache* pCache = taosMemoryMalloc(sizeof(SRaftEntryHashCache));
|
||||
if (pCache == NULL) {
|
||||
|
@ -256,8 +255,6 @@ int32_t raftCacheClear(struct SRaftEntryHashCache* pCache) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------
|
||||
static char* keyFn(const void* pData) {
|
||||
SSyncRaftEntry* pEntry = (SSyncRaftEntry*)pData;
|
||||
return (char*)(&(pEntry->index));
|
||||
|
|
|
@ -13,33 +13,34 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "syncRaftLog.h"
|
||||
#include "syncRaftCfg.h"
|
||||
#include "syncRaftStore.h"
|
||||
#include "syncUtil.h"
|
||||
|
||||
//-------------------------------
|
||||
// log[m .. n]
|
||||
|
||||
// public function
|
||||
static int32_t raftLogRestoreFromSnapshot(struct SSyncLogStore* pLogStore, SyncIndex snapshotIndex);
|
||||
|
||||
static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry);
|
||||
static int32_t raftLogTruncate(struct SSyncLogStore* pLogStore, SyncIndex fromIndex);
|
||||
static bool raftLogExist(struct SSyncLogStore* pLogStore, SyncIndex index);
|
||||
static int32_t raftLogUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index);
|
||||
static SyncIndex raftlogCommitIndex(SSyncLogStore* pLogStore);
|
||||
static int32_t raftLogGetLastEntry(SSyncLogStore* pLogStore, SSyncRaftEntry** ppLastEntry);
|
||||
|
||||
static int32_t raftLogGetLastEntry(SSyncLogStore* pLogStore, SSyncRaftEntry** ppLastEntry);
|
||||
|
||||
//-------------------------------
|
||||
SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode) {
|
||||
SSyncLogStore* pLogStore = taosMemoryMalloc(sizeof(SSyncLogStore));
|
||||
ASSERT(pLogStore != NULL);
|
||||
SSyncLogStore* pLogStore = taosMemoryCalloc(1, sizeof(SSyncLogStore));
|
||||
if (pLogStore == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pLogStore->pCache = taosLRUCacheInit(10 * 1024 * 1024, 1, .5);
|
||||
if (pLogStore->pCache == NULL) {
|
||||
terrno = TSDB_CODE_WAL_OUT_OF_MEMORY;
|
||||
taosMemoryFree(pLogStore);
|
||||
terrno = TSDB_CODE_WAL_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -96,7 +97,6 @@ void logStoreDestory(SSyncLogStore* pLogStore) {
|
|||
}
|
||||
}
|
||||
|
||||
//-------------------------------
|
||||
// log[m .. n]
|
||||
static int32_t raftLogRestoreFromSnapshot(struct SSyncLogStore* pLogStore, SyncIndex snapshotIndex) {
|
||||
ASSERT(snapshotIndex >= 0);
|
||||
|
|
|
@ -13,9 +13,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "syncRaftStore.h"
|
||||
#include "cJSON.h"
|
||||
#include "syncEnv.h"
|
||||
#include "syncUtil.h"
|
||||
|
||||
// private function
|
||||
|
@ -26,22 +25,19 @@ static bool raftStoreFileExist(char *path);
|
|||
SRaftStore *raftStoreOpen(const char *path) {
|
||||
int32_t ret;
|
||||
|
||||
SRaftStore *pRaftStore = taosMemoryMalloc(sizeof(SRaftStore));
|
||||
SRaftStore *pRaftStore = taosMemoryCalloc(1, sizeof(SRaftStore));
|
||||
if (pRaftStore == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
memset(pRaftStore, 0, sizeof(*pRaftStore));
|
||||
|
||||
snprintf(pRaftStore->path, sizeof(pRaftStore->path), "%s", path);
|
||||
|
||||
char storeBuf[RAFT_STORE_BLOCK_SIZE] = {0};
|
||||
memset(storeBuf, 0, sizeof(storeBuf));
|
||||
|
||||
if (!raftStoreFileExist(pRaftStore->path)) {
|
||||
ret = raftStoreInit(pRaftStore);
|
||||
ASSERT(ret == 0);
|
||||
}
|
||||
|
||||
char storeBuf[RAFT_STORE_BLOCK_SIZE] = {0};
|
||||
pRaftStore->pFile = taosOpenFile(path, TD_FILE_READ | TD_FILE_WRITE);
|
||||
ASSERT(pRaftStore->pFile != NULL);
|
||||
|
||||
|
@ -72,9 +68,7 @@ static int32_t raftStoreInit(SRaftStore *pRaftStore) {
|
|||
}
|
||||
|
||||
int32_t raftStoreClose(SRaftStore *pRaftStore) {
|
||||
if (pRaftStore == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (pRaftStore == NULL) return 0;
|
||||
|
||||
taosCloseFile(&pRaftStore->pFile);
|
||||
taosMemoryFree(pRaftStore);
|
||||
|
@ -182,69 +176,3 @@ void raftStoreSetTerm(SRaftStore *pRaftStore, SyncTerm term) {
|
|||
pRaftStore->currentTerm = term;
|
||||
raftStorePersist(pRaftStore);
|
||||
}
|
||||
|
||||
int32_t raftStoreFromJson(SRaftStore *pRaftStore, cJSON *pJson) { return 0; }
|
||||
|
||||
cJSON *raftStore2Json(SRaftStore *pRaftStore) {
|
||||
char u64buf[128] = {0};
|
||||
cJSON *pRoot = cJSON_CreateObject();
|
||||
|
||||
if (pRaftStore != NULL) {
|
||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64 "", pRaftStore->currentTerm);
|
||||
cJSON_AddStringToObject(pRoot, "currentTerm", u64buf);
|
||||
|
||||
cJSON *pVoteFor = cJSON_CreateObject();
|
||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64 "", pRaftStore->voteFor.addr);
|
||||
cJSON_AddStringToObject(pVoteFor, "addr", u64buf);
|
||||
{
|
||||
uint64_t u64 = pRaftStore->voteFor.addr;
|
||||
char host[128] = {0};
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
||||
cJSON_AddStringToObject(pVoteFor, "addr_host", host);
|
||||
cJSON_AddNumberToObject(pVoteFor, "addr_port", port);
|
||||
}
|
||||
cJSON_AddNumberToObject(pVoteFor, "vgId", pRaftStore->voteFor.vgId);
|
||||
cJSON_AddItemToObject(pRoot, "voteFor", pVoteFor);
|
||||
|
||||
int hasVoted = raftStoreHasVoted(pRaftStore);
|
||||
cJSON_AddNumberToObject(pRoot, "hasVoted", hasVoted);
|
||||
}
|
||||
|
||||
cJSON *pJson = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(pJson, "SRaftStore", pRoot);
|
||||
return pJson;
|
||||
}
|
||||
|
||||
char *raftStore2Str(SRaftStore *pRaftStore) {
|
||||
cJSON *pJson = raftStore2Json(pRaftStore);
|
||||
char *serialized = cJSON_Print(pJson);
|
||||
cJSON_Delete(pJson);
|
||||
return serialized;
|
||||
}
|
||||
|
||||
// for debug -------------------
|
||||
void raftStorePrint(SRaftStore *pObj) {
|
||||
char *serialized = raftStore2Str(pObj);
|
||||
printf("raftStorePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||
fflush(NULL);
|
||||
taosMemoryFree(serialized);
|
||||
}
|
||||
|
||||
void raftStorePrint2(char *s, SRaftStore *pObj) {
|
||||
char *serialized = raftStore2Str(pObj);
|
||||
printf("raftStorePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||
fflush(NULL);
|
||||
taosMemoryFree(serialized);
|
||||
}
|
||||
void raftStoreLog(SRaftStore *pObj) {
|
||||
char *serialized = raftStore2Str(pObj);
|
||||
sTrace("raftStoreLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||
taosMemoryFree(serialized);
|
||||
}
|
||||
|
||||
void raftStoreLog2(char *s, SRaftStore *pObj) {
|
||||
char *serialized = raftStore2Str(pObj);
|
||||
sTrace("raftStoreLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||
taosMemoryFree(serialized);
|
||||
}
|
||||
|
|
|
@ -13,15 +13,16 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "syncReplication.h"
|
||||
#include "syncIndexMgr.h"
|
||||
#include "syncMessage.h"
|
||||
#include "syncRaftCfg.h"
|
||||
#include "syncRaftEntry.h"
|
||||
#include "syncRaftLog.h"
|
||||
#include "syncRaftStore.h"
|
||||
#include "syncUtil.h"
|
||||
|
||||
static int32_t syncNodeSendAppendEntries(SSyncNode* pNode, const SRaftId* destRaftId, SRpcMsg* pRpcMsg);
|
||||
static int32_t syncNodeMaybeSendAppendEntries(SSyncNode* pNode, const SRaftId* destRaftId, SRpcMsg* pRpcMsg);
|
||||
|
||||
// TLA+ Spec
|
||||
// AppendEntries(i, j) ==
|
||||
// /\ i /= j
|
||||
|
@ -68,6 +69,7 @@ int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId, bool snapsh
|
|||
SyncTerm preLogTerm = syncNodeGetPreTerm(pSyncNode, nextIndex);
|
||||
|
||||
// prepare entry
|
||||
SRpcMsg rpcMsg = {0};
|
||||
SyncAppendEntries* pMsg = NULL;
|
||||
|
||||
SSyncRaftEntry* pEntry;
|
||||
|
@ -76,26 +78,23 @@ int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId, bool snapsh
|
|||
if (code == 0) {
|
||||
ASSERT(pEntry != NULL);
|
||||
|
||||
pMsg = syncAppendEntriesBuild(pEntry->bytes, pSyncNode->vgId);
|
||||
ASSERT(pMsg != NULL);
|
||||
memcpy(pMsg->data, pEntry, pEntry->bytes);
|
||||
syncEntryDestory(pEntry);
|
||||
code = syncBuildAppendEntries(&rpcMsg, pEntry->bytes, pSyncNode->vgId);
|
||||
ASSERT(code == 0);
|
||||
|
||||
pMsg = rpcMsg.pCont;
|
||||
memcpy(pMsg->data, pEntry, pEntry->bytes);
|
||||
} else {
|
||||
if (terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) {
|
||||
// no entry in log
|
||||
pMsg = syncAppendEntriesBuild(0, pSyncNode->vgId);
|
||||
ASSERT(pMsg != NULL);
|
||||
code = syncBuildAppendEntries(&rpcMsg, 0, pSyncNode->vgId);
|
||||
ASSERT(code == 0);
|
||||
|
||||
pMsg = rpcMsg.pCont;
|
||||
} else {
|
||||
do {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pDestId->addr, host, sizeof(host), &port);
|
||||
sNError(pSyncNode, "replicate to %s:%d error, next-index:%" PRId64, host, port, nextIndex);
|
||||
} while (0);
|
||||
|
||||
syncAppendEntriesDestroy(pMsg);
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pDestId->addr, host, sizeof(host), &port);
|
||||
sNError(pSyncNode, "replicate to %s:%d error, next-index:%" PRId64, host, port, nextIndex);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -112,9 +111,7 @@ int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId, bool snapsh
|
|||
// pMsg->privateTerm = syncIndexMgrGetTerm(pSyncNode->pNextIndex, pDestId);
|
||||
|
||||
// send msg
|
||||
syncNodeMaybeSendAppendEntries(pSyncNode, pDestId, pMsg);
|
||||
syncAppendEntriesDestroy(pMsg);
|
||||
|
||||
syncNodeMaybeSendAppendEntries(pSyncNode, pDestId, &rpcMsg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -140,13 +137,13 @@ int32_t syncNodeReplicate(SSyncNode* pSyncNode) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t syncNodeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncAppendEntries* pMsg) {
|
||||
int32_t ret = 0;
|
||||
syncLogSendAppendEntries(pSyncNode, pMsg, "");
|
||||
|
||||
SRpcMsg rpcMsg;
|
||||
syncAppendEntries2RpcMsg(pMsg, &rpcMsg);
|
||||
syncNodeSendMsgById(destRaftId, pSyncNode, &rpcMsg);
|
||||
int32_t syncNodeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, SRpcMsg* pRpcMsg) {
|
||||
int32_t ret = 0;
|
||||
SyncAppendEntries* pMsg = pRpcMsg->pCont;
|
||||
if (pMsg == NULL) {
|
||||
sError("vgId:%d, sync-append-entries msg is NULL", pSyncNode->vgId);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPeerState* pState = syncNodeGetPeerState(pSyncNode, destRaftId);
|
||||
if (pState == NULL) {
|
||||
|
@ -154,53 +151,54 @@ int32_t syncNodeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftI
|
|||
return 0;
|
||||
}
|
||||
|
||||
// save index, otherwise pMsg will be free by rpc
|
||||
SyncIndex saveLastSendIndex = pState->lastSendIndex;
|
||||
if (pMsg->dataLen > 0) {
|
||||
pState->lastSendIndex = pMsg->prevLogIndex + 1;
|
||||
saveLastSendIndex = pMsg->prevLogIndex + 1;
|
||||
}
|
||||
|
||||
syncLogSendAppendEntries(pSyncNode, pMsg, "");
|
||||
syncNodeSendMsgById(destRaftId, pSyncNode, pRpcMsg);
|
||||
|
||||
if (pMsg->dataLen > 0) {
|
||||
pState->lastSendIndex = saveLastSendIndex;
|
||||
pState->lastSendTime = taosGetTimestampMs();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t syncNodeMaybeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncAppendEntries* pMsg) {
|
||||
int32_t ret = 0;
|
||||
if (syncNodeNeedSendAppendEntries(pSyncNode, destRaftId, pMsg)) {
|
||||
ret = syncNodeSendAppendEntries(pSyncNode, destRaftId, pMsg);
|
||||
int32_t syncNodeMaybeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, SRpcMsg* pRpcMsg) {
|
||||
int32_t ret = 0;
|
||||
SyncAppendEntries* pMsg = pRpcMsg->pCont;
|
||||
|
||||
if (syncNodeNeedSendAppendEntries(pSyncNode, destRaftId, pMsg)) {
|
||||
ret = syncNodeSendAppendEntries(pSyncNode, destRaftId, pRpcMsg);
|
||||
} else {
|
||||
char logBuf[128];
|
||||
char host[64];
|
||||
int16_t port;
|
||||
syncUtilU642Addr(destRaftId->addr, host, sizeof(host), &port);
|
||||
sNTrace(pSyncNode, "do not repcate to %s:%d for index:%" PRId64, host, port, pMsg->prevLogIndex + 1);
|
||||
rpcFreeCont(pRpcMsg->pCont);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t syncNodeAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncAppendEntries* pMsg) {
|
||||
int32_t ret = 0;
|
||||
syncLogSendAppendEntries(pSyncNode, pMsg, "");
|
||||
|
||||
SRpcMsg rpcMsg;
|
||||
syncAppendEntries2RpcMsg(pMsg, &rpcMsg);
|
||||
syncNodeSendMsgById(destRaftId, pSyncNode, &rpcMsg);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t syncNodeSendHeartbeat(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncHeartbeat* pMsg) {
|
||||
int32_t ret = 0;
|
||||
syncLogSendHeartbeat(pSyncNode, pMsg, "");
|
||||
|
||||
SRpcMsg rpcMsg;
|
||||
syncHeartbeat2RpcMsg(pMsg, &rpcMsg);
|
||||
syncNodeSendMsgById(&(pMsg->destId), pSyncNode, &rpcMsg);
|
||||
return ret;
|
||||
int32_t syncNodeSendHeartbeat(SSyncNode* pSyncNode, const SRaftId* destId, SRpcMsg* pMsg) {
|
||||
syncLogSendHeartbeat(pSyncNode, pMsg->pCont, "");
|
||||
return syncNodeSendMsgById(destId, pSyncNode, pMsg);
|
||||
}
|
||||
|
||||
int32_t syncNodeHeartbeatPeers(SSyncNode* pSyncNode) {
|
||||
for (int32_t i = 0; i < pSyncNode->peersNum; ++i) {
|
||||
SyncHeartbeat* pSyncMsg = syncHeartbeatBuild(pSyncNode->vgId);
|
||||
SRpcMsg rpcMsg = {0};
|
||||
if (syncBuildHeartbeat(&rpcMsg, pSyncNode->vgId) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SyncHeartbeat* pSyncMsg = rpcMsg.pCont;
|
||||
pSyncMsg->srcId = pSyncNode->myRaftId;
|
||||
pSyncMsg->destId = pSyncNode->peersId[i];
|
||||
pSyncMsg->term = pSyncNode->pRaftStore->currentTerm;
|
||||
|
@ -208,13 +206,8 @@ int32_t syncNodeHeartbeatPeers(SSyncNode* pSyncNode) {
|
|||
pSyncMsg->minMatchIndex = syncMinMatchIndex(pSyncNode);
|
||||
pSyncMsg->privateTerm = 0;
|
||||
|
||||
SRpcMsg rpcMsg;
|
||||
syncHeartbeat2RpcMsg(pSyncMsg, &rpcMsg);
|
||||
|
||||
// send msg
|
||||
syncNodeSendHeartbeat(pSyncNode, &(pSyncMsg->destId), pSyncMsg);
|
||||
|
||||
syncHeartbeatDestroy(pSyncMsg);
|
||||
syncNodeSendHeartbeat(pSyncNode, &pSyncMsg->destId, &rpcMsg);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -13,8 +13,9 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "syncRequestVote.h"
|
||||
#include "syncInt.h"
|
||||
#include "syncMessage.h"
|
||||
#include "syncRaftCfg.h"
|
||||
#include "syncRaftStore.h"
|
||||
#include "syncUtil.h"
|
||||
|
@ -87,8 +88,9 @@ static bool syncNodeOnRequestVoteLogOK(SSyncNode* pSyncNode, SyncRequestVote* pM
|
|||
return false;
|
||||
}
|
||||
|
||||
int32_t syncNodeOnRequestVote(SSyncNode* ths, SyncRequestVote* pMsg) {
|
||||
int32_t ret = 0;
|
||||
int32_t syncNodeOnRequestVote(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
||||
int32_t ret = 0;
|
||||
SyncRequestVote* pMsg = pRpcMsg->pCont;
|
||||
|
||||
// if already drop replica, do not process
|
||||
if (!syncNodeInRaftGroup(ths, &(pMsg->srcId))) {
|
||||
|
@ -120,7 +122,11 @@ int32_t syncNodeOnRequestVote(SSyncNode* ths, SyncRequestVote* pMsg) {
|
|||
}
|
||||
|
||||
// send msg
|
||||
SyncRequestVoteReply* pReply = syncRequestVoteReplyBuild(ths->vgId);
|
||||
SRpcMsg rpcMsg = {0};
|
||||
ret = syncBuildRequestVoteReply(&rpcMsg, ths->vgId);
|
||||
ASSERT(ret == 0 );
|
||||
|
||||
SyncRequestVoteReply* pReply = rpcMsg.pCont;
|
||||
pReply->srcId = ths->myRaftId;
|
||||
pReply->destId = pMsg->srcId;
|
||||
pReply->term = ths->pRaftStore->currentTerm;
|
||||
|
@ -134,10 +140,6 @@ int32_t syncNodeOnRequestVote(SSyncNode* ths, SyncRequestVote* pMsg) {
|
|||
syncLogSendRequestVoteReply(ths, pReply, "");
|
||||
} while (0);
|
||||
|
||||
SRpcMsg rpcMsg;
|
||||
syncRequestVoteReply2RpcMsg(pReply, &rpcMsg);
|
||||
syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg);
|
||||
syncRequestVoteReplyDestroy(pReply);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -13,9 +13,9 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "syncRequestVoteReply.h"
|
||||
#include "syncInt.h"
|
||||
#include "syncRaftCfg.h"
|
||||
#include "syncMessage.h"
|
||||
#include "syncRaftStore.h"
|
||||
#include "syncUtil.h"
|
||||
#include "syncVoteMgr.h"
|
||||
|
@ -37,8 +37,10 @@
|
|||
// /\ Discard(m)
|
||||
// /\ UNCHANGED <<serverVars, votedFor, leaderVars, logVars>>
|
||||
//
|
||||
int32_t syncNodeOnRequestVoteReply(SSyncNode* ths, SyncRequestVoteReply* pMsg) {
|
||||
int32_t ret = 0;
|
||||
|
||||
int32_t syncNodeOnRequestVoteReply(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
||||
int32_t ret = 0;
|
||||
SyncRequestVoteReply* pMsg = pRpcMsg->pCont;
|
||||
|
||||
// if already drop replica, do not process
|
||||
if (!syncNodeInRaftGroup(ths, &(pMsg->srcId))) {
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "syncRespMgr.h"
|
||||
#include "syncRaftEntry.h"
|
||||
#include "syncRaftStore.h"
|
||||
#include "syncUtil.h"
|
||||
|
||||
SSyncRespMgr *syncRespMgrCreate(void *data, int64_t ttl) {
|
||||
SSyncRespMgr *pObj = taosMemoryCalloc(1, sizeof(SSyncRespMgr));
|
||||
|
|
|
@ -105,7 +105,10 @@ int32_t snapshotSenderStart(SSyncSnapshotSender *pSender) {
|
|||
pSender->finish = false;
|
||||
|
||||
// build begin msg
|
||||
SyncSnapshotSend *pMsg = syncSnapshotSendBuild(0, pSender->pSyncNode->vgId);
|
||||
SRpcMsg rpcMsg = {0};
|
||||
(void)syncBuildSnapshotSend(&rpcMsg, 0, pSender->pSyncNode->vgId);
|
||||
|
||||
SyncSnapshotSend *pMsg = rpcMsg.pCont;
|
||||
pMsg->srcId = pSender->pSyncNode->myRaftId;
|
||||
pMsg->destId = (pSender->pSyncNode->replicasId)[pSender->replicaIndex];
|
||||
pMsg->term = pSender->pSyncNode->pRaftStore->currentTerm;
|
||||
|
@ -118,11 +121,8 @@ int32_t snapshotSenderStart(SSyncSnapshotSender *pSender) {
|
|||
pMsg->seq = SYNC_SNAPSHOT_SEQ_PRE_SNAPSHOT;
|
||||
|
||||
// send msg
|
||||
SRpcMsg rpcMsg;
|
||||
syncSnapshotSend2RpcMsg(pMsg, &rpcMsg);
|
||||
syncNodeSendMsgById(&(pMsg->destId), pSender->pSyncNode, &rpcMsg);
|
||||
syncNodeSendMsgById(&pMsg->destId, pSender->pSyncNode, &rpcMsg);
|
||||
syncLogSendSyncSnapshotSend(pSender->pSyncNode, pMsg, "");
|
||||
syncSnapshotSendDestroy(pMsg);
|
||||
|
||||
// event log
|
||||
sSTrace(pSender, "snapshot sender start");
|
||||
|
@ -176,7 +176,10 @@ int32_t snapshotSend(SSyncSnapshotSender *pSender) {
|
|||
}
|
||||
|
||||
// build msg
|
||||
SyncSnapshotSend *pMsg = syncSnapshotSendBuild(pSender->blockLen, pSender->pSyncNode->vgId);
|
||||
SRpcMsg rpcMsg = {0};
|
||||
(void)syncBuildSnapshotSend(&rpcMsg, pSender->blockLen, pSender->pSyncNode->vgId);
|
||||
|
||||
SyncSnapshotSend *pMsg = rpcMsg.pCont;
|
||||
pMsg->srcId = pSender->pSyncNode->myRaftId;
|
||||
pMsg->destId = (pSender->pSyncNode->replicasId)[pSender->replicaIndex];
|
||||
pMsg->term = pSender->pSyncNode->pRaftStore->currentTerm;
|
||||
|
@ -192,11 +195,8 @@ int32_t snapshotSend(SSyncSnapshotSender *pSender) {
|
|||
memcpy(pMsg->data, pSender->pCurrentBlock, pSender->blockLen);
|
||||
|
||||
// send msg
|
||||
SRpcMsg rpcMsg;
|
||||
syncSnapshotSend2RpcMsg(pMsg, &rpcMsg);
|
||||
syncNodeSendMsgById(&(pMsg->destId), pSender->pSyncNode, &rpcMsg);
|
||||
syncNodeSendMsgById(&pMsg->destId, pSender->pSyncNode, &rpcMsg);
|
||||
syncLogSendSyncSnapshotSend(pSender->pSyncNode, pMsg, "");
|
||||
syncSnapshotSendDestroy(pMsg);
|
||||
|
||||
// event log
|
||||
if (pSender->seq == SYNC_SNAPSHOT_SEQ_END) {
|
||||
|
@ -212,7 +212,10 @@ int32_t snapshotReSend(SSyncSnapshotSender *pSender) {
|
|||
// send current block data
|
||||
if (pSender->pCurrentBlock != NULL && pSender->blockLen > 0) {
|
||||
// build msg
|
||||
SyncSnapshotSend *pMsg = syncSnapshotSendBuild(pSender->blockLen, pSender->pSyncNode->vgId);
|
||||
SRpcMsg rpcMsg = {0};
|
||||
(void)syncBuildSnapshotSend(&rpcMsg, pSender->blockLen, pSender->pSyncNode->vgId);
|
||||
|
||||
SyncSnapshotSend *pMsg = rpcMsg.pCont;
|
||||
pMsg->srcId = pSender->pSyncNode->myRaftId;
|
||||
pMsg->destId = (pSender->pSyncNode->replicasId)[pSender->replicaIndex];
|
||||
pMsg->term = pSender->pSyncNode->pRaftStore->currentTerm;
|
||||
|
@ -224,15 +227,11 @@ int32_t snapshotReSend(SSyncSnapshotSender *pSender) {
|
|||
pMsg->seq = pSender->seq;
|
||||
|
||||
// pMsg->privateTerm = pSender->privateTerm;
|
||||
|
||||
memcpy(pMsg->data, pSender->pCurrentBlock, pSender->blockLen);
|
||||
|
||||
// send msg
|
||||
SRpcMsg rpcMsg;
|
||||
syncSnapshotSend2RpcMsg(pMsg, &rpcMsg);
|
||||
syncNodeSendMsgById(&(pMsg->destId), pSender->pSyncNode, &rpcMsg);
|
||||
syncNodeSendMsgById(&pMsg->destId, pSender->pSyncNode, &rpcMsg);
|
||||
syncLogSendSyncSnapshotSend(pSender->pSyncNode, pMsg, "");
|
||||
syncSnapshotSendDestroy(pMsg);
|
||||
|
||||
// event log
|
||||
sSTrace(pSender, "snapshot sender resend");
|
||||
|
@ -546,7 +545,11 @@ _START_RECEIVER:
|
|||
_SEND_REPLY:
|
||||
// build msg
|
||||
; // make complier happy
|
||||
SyncSnapshotRsp *pRspMsg = syncSnapshotRspBuild(pSyncNode->vgId);
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
(void)syncBuildSnapshotSendRsp(&rpcMsg, pSyncNode->vgId);
|
||||
|
||||
SyncSnapshotRsp *pRspMsg = rpcMsg.pCont;
|
||||
pRspMsg->srcId = pSyncNode->myRaftId;
|
||||
pRspMsg->destId = pMsg->srcId;
|
||||
pRspMsg->term = pSyncNode->pRaftStore->currentTerm;
|
||||
|
@ -558,12 +561,8 @@ _SEND_REPLY:
|
|||
pRspMsg->snapBeginIndex = syncNodeGetSnapBeginIndex(pSyncNode);
|
||||
|
||||
// send msg
|
||||
SRpcMsg rpcMsg;
|
||||
syncSnapshotRsp2RpcMsg(pRspMsg, &rpcMsg);
|
||||
syncNodeSendMsgById(&(pRspMsg->destId), pSyncNode, &rpcMsg);
|
||||
syncNodeSendMsgById(&pRspMsg->destId, pSyncNode, &rpcMsg);
|
||||
syncLogSendSyncSnapshotRsp(pSyncNode, pRspMsg, "");
|
||||
syncSnapshotRspDestroy(pRspMsg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -585,7 +584,10 @@ static int32_t syncNodeOnSnapshotBegin(SSyncNode *pSyncNode, SyncSnapshotSend *p
|
|||
snapshotReceiverStartWriter(pReceiver, pMsg);
|
||||
|
||||
// build msg
|
||||
SyncSnapshotRsp *pRspMsg = syncSnapshotRspBuild(pSyncNode->vgId);
|
||||
SRpcMsg rpcMsg = {0};
|
||||
(void)syncBuildSnapshotSendRsp(&rpcMsg, pSyncNode->vgId);
|
||||
|
||||
SyncSnapshotRsp *pRspMsg = rpcMsg.pCont;
|
||||
pRspMsg->srcId = pSyncNode->myRaftId;
|
||||
pRspMsg->destId = pMsg->srcId;
|
||||
pRspMsg->term = pSyncNode->pRaftStore->currentTerm;
|
||||
|
@ -597,12 +599,8 @@ static int32_t syncNodeOnSnapshotBegin(SSyncNode *pSyncNode, SyncSnapshotSend *p
|
|||
pRspMsg->snapBeginIndex = pReceiver->snapshotParam.start;
|
||||
|
||||
// send msg
|
||||
SRpcMsg rpcMsg;
|
||||
syncSnapshotRsp2RpcMsg(pRspMsg, &rpcMsg);
|
||||
syncNodeSendMsgById(&(pRspMsg->destId), pSyncNode, &rpcMsg);
|
||||
syncNodeSendMsgById(&pRspMsg->destId, pSyncNode, &rpcMsg);
|
||||
syncLogSendSyncSnapshotRsp(pSyncNode, pRspMsg, "");
|
||||
syncSnapshotRspDestroy(pRspMsg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -624,7 +622,10 @@ static int32_t syncNodeOnSnapshotTransfering(SSyncNode *pSyncNode, SyncSnapshotS
|
|||
}
|
||||
|
||||
// build msg
|
||||
SyncSnapshotRsp *pRspMsg = syncSnapshotRspBuild(pSyncNode->vgId);
|
||||
SRpcMsg rpcMsg = {0};
|
||||
(void)syncBuildSnapshotSendRsp(&rpcMsg, pSyncNode->vgId);
|
||||
|
||||
SyncSnapshotRsp *pRspMsg = rpcMsg.pCont;
|
||||
pRspMsg->srcId = pSyncNode->myRaftId;
|
||||
pRspMsg->destId = pMsg->srcId;
|
||||
pRspMsg->term = pSyncNode->pRaftStore->currentTerm;
|
||||
|
@ -636,12 +637,8 @@ static int32_t syncNodeOnSnapshotTransfering(SSyncNode *pSyncNode, SyncSnapshotS
|
|||
pRspMsg->snapBeginIndex = pReceiver->snapshotParam.start;
|
||||
|
||||
// send msg
|
||||
SRpcMsg rpcMsg;
|
||||
syncSnapshotRsp2RpcMsg(pRspMsg, &rpcMsg);
|
||||
syncNodeSendMsgById(&(pRspMsg->destId), pSyncNode, &rpcMsg);
|
||||
syncNodeSendMsgById(&pRspMsg->destId, pSyncNode, &rpcMsg);
|
||||
syncLogSendSyncSnapshotRsp(pSyncNode, pRspMsg, "");
|
||||
syncSnapshotRspDestroy(pRspMsg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -664,7 +661,10 @@ static int32_t syncNodeOnSnapshotEnd(SSyncNode *pSyncNode, SyncSnapshotSend *pMs
|
|||
}
|
||||
|
||||
// build msg
|
||||
SyncSnapshotRsp *pRspMsg = syncSnapshotRspBuild(pSyncNode->vgId);
|
||||
SRpcMsg rpcMsg = {0};
|
||||
(void)syncBuildSnapshotSendRsp(&rpcMsg, pSyncNode->vgId);
|
||||
|
||||
SyncSnapshotRsp *pRspMsg = rpcMsg.pCont;
|
||||
pRspMsg->srcId = pSyncNode->myRaftId;
|
||||
pRspMsg->destId = pMsg->srcId;
|
||||
pRspMsg->term = pSyncNode->pRaftStore->currentTerm;
|
||||
|
@ -676,12 +676,8 @@ static int32_t syncNodeOnSnapshotEnd(SSyncNode *pSyncNode, SyncSnapshotSend *pMs
|
|||
pRspMsg->snapBeginIndex = pReceiver->snapshotParam.start;
|
||||
|
||||
// send msg
|
||||
SRpcMsg rpcMsg;
|
||||
syncSnapshotRsp2RpcMsg(pRspMsg, &rpcMsg);
|
||||
syncNodeSendMsgById(&(pRspMsg->destId), pSyncNode, &rpcMsg);
|
||||
syncNodeSendMsgById(&pRspMsg->destId, pSyncNode, &rpcMsg);
|
||||
syncLogSendSyncSnapshotRsp(pSyncNode, pRspMsg, "");
|
||||
syncSnapshotRspDestroy(pRspMsg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -705,7 +701,9 @@ static int32_t syncNodeOnSnapshotEnd(SSyncNode *pSyncNode, SyncSnapshotSend *pMs
|
|||
//
|
||||
// condition 5, got data, update ack
|
||||
//
|
||||
int32_t syncNodeOnSnapshot(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
|
||||
int32_t syncNodeOnSnapshot(SSyncNode *pSyncNode, const SRpcMsg *pRpcMsg) {
|
||||
SyncSnapshotSend *pMsg = pRpcMsg->pCont;
|
||||
|
||||
// if already drop replica, do not process
|
||||
if (!syncNodeInRaftGroup(pSyncNode, &(pMsg->srcId))) {
|
||||
syncLogRecvSyncSnapshotSend(pSyncNode, pMsg, "not in my config");
|
||||
|
@ -797,13 +795,16 @@ int32_t syncNodeOnSnapshotReplyPre(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg)
|
|||
}
|
||||
|
||||
// update next index
|
||||
syncIndexMgrSetIndex(pSyncNode->pNextIndex, &(pMsg->srcId), snapshot.lastApplyIndex + 1);
|
||||
syncIndexMgrSetIndex(pSyncNode->pNextIndex, &pMsg->srcId, snapshot.lastApplyIndex + 1);
|
||||
|
||||
// update seq
|
||||
pSender->seq = SYNC_SNAPSHOT_SEQ_BEGIN;
|
||||
|
||||
// build begin msg
|
||||
SyncSnapshotSend *pSendMsg = syncSnapshotSendBuild(0, pSender->pSyncNode->vgId);
|
||||
SRpcMsg rpcMsg = {0};
|
||||
(void)syncBuildSnapshotSend(&rpcMsg, 0, pSender->pSyncNode->vgId);
|
||||
|
||||
SyncSnapshotSend *pSendMsg = rpcMsg.pCont;
|
||||
pSendMsg->srcId = pSender->pSyncNode->myRaftId;
|
||||
pSendMsg->destId = (pSender->pSyncNode->replicasId)[pSender->replicaIndex];
|
||||
pSendMsg->term = pSender->pSyncNode->pRaftStore->currentTerm;
|
||||
|
@ -816,11 +817,8 @@ int32_t syncNodeOnSnapshotReplyPre(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg)
|
|||
pSendMsg->seq = SYNC_SNAPSHOT_SEQ_BEGIN;
|
||||
|
||||
// send msg
|
||||
SRpcMsg rpcMsg;
|
||||
syncSnapshotSend2RpcMsg(pSendMsg, &rpcMsg);
|
||||
syncNodeSendMsgById(&(pSendMsg->destId), pSender->pSyncNode, &rpcMsg);
|
||||
syncNodeSendMsgById(&pSendMsg->destId, pSender->pSyncNode, &rpcMsg);
|
||||
syncLogSendSyncSnapshotSend(pSyncNode, pSendMsg, "");
|
||||
syncSnapshotSendDestroy(pSendMsg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -831,7 +829,9 @@ int32_t syncNodeOnSnapshotReplyPre(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg)
|
|||
// condition 2 sender receives ack, set seq = ack + 1, send msg from seq
|
||||
// condition 3 sender receives error msg, just print error log
|
||||
//
|
||||
int32_t syncNodeOnSnapshotReply(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg) {
|
||||
int32_t syncNodeOnSnapshotReply(SSyncNode *pSyncNode, const SRpcMsg *pRpcMsg) {
|
||||
SyncSnapshotRsp *pMsg = pRpcMsg->pCont;
|
||||
|
||||
// if already drop replica, do not process
|
||||
if (!syncNodeInRaftGroup(pSyncNode, &(pMsg->srcId))) {
|
||||
syncLogRecvSyncSnapshotRsp(pSyncNode, pMsg, "maybe replica already dropped");
|
||||
|
@ -903,60 +903,3 @@ int32_t syncNodeOnSnapshotReply(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg) {
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t syncNodeOnPreSnapshot(SSyncNode *ths, SyncPreSnapshot *pMsg) {
|
||||
syncLogRecvSyncPreSnapshot(ths, pMsg, "");
|
||||
|
||||
SyncPreSnapshotReply *pMsgReply = syncPreSnapshotReplyBuild(ths->vgId);
|
||||
pMsgReply->srcId = ths->myRaftId;
|
||||
pMsgReply->destId = pMsg->srcId;
|
||||
pMsgReply->term = ths->pRaftStore->currentTerm;
|
||||
|
||||
SSyncLogStoreData *pData = ths->pLogStore->data;
|
||||
SWal *pWal = pData->pWal;
|
||||
|
||||
if (syncNodeIsMnode(ths)) {
|
||||
pMsgReply->snapStart = SYNC_INDEX_BEGIN;
|
||||
|
||||
} else {
|
||||
bool isEmpty = ths->pLogStore->syncLogIsEmpty(ths->pLogStore);
|
||||
int64_t walCommitVer = walGetCommittedVer(pWal);
|
||||
|
||||
if (!isEmpty && ths->commitIndex != walCommitVer) {
|
||||
sNError(ths, "commit not same, wal-commit:%" PRId64 ", commit:%" PRId64 ", ignore", walCommitVer,
|
||||
ths->commitIndex);
|
||||
goto _IGNORE;
|
||||
}
|
||||
|
||||
pMsgReply->snapStart = ths->commitIndex + 1;
|
||||
|
||||
// make local log clean
|
||||
int32_t code = ths->pLogStore->syncLogTruncate(ths->pLogStore, pMsgReply->snapStart);
|
||||
if (code != 0) {
|
||||
sNError(ths, "truncate wal error");
|
||||
goto _IGNORE;
|
||||
}
|
||||
}
|
||||
|
||||
// can not write behind _RESPONSE
|
||||
SRpcMsg rpcMsg;
|
||||
|
||||
_RESPONSE:
|
||||
syncPreSnapshotReply2RpcMsg(pMsgReply, &rpcMsg);
|
||||
syncNodeSendMsgById(&pMsgReply->destId, ths, &rpcMsg);
|
||||
|
||||
syncPreSnapshotReplyDestroy(pMsgReply);
|
||||
return 0;
|
||||
|
||||
_IGNORE:
|
||||
syncPreSnapshotReplyDestroy(pMsgReply);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t syncNodeOnPreSnapshotReply(SSyncNode *ths, SyncPreSnapshotReply *pMsg) {
|
||||
syncLogRecvSyncPreSnapshotReply(ths, pMsg, "");
|
||||
|
||||
// start snapshot
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -19,12 +19,13 @@
|
|||
#include "syncRaftCfg.h"
|
||||
#include "syncRaftLog.h"
|
||||
#include "syncReplication.h"
|
||||
#include "syncUtil.h"
|
||||
|
||||
static void syncNodeCleanConfigIndex(SSyncNode* ths) {
|
||||
int32_t newArrIndex = 0;
|
||||
SyncIndex newConfigIndexArr[MAX_CONFIG_INDEX_COUNT] = {0};
|
||||
SSnapshot snapshot = {0};
|
||||
|
||||
|
||||
ths->pFsm->FpGetSnapshotInfo(ths->pFsm, &snapshot);
|
||||
if (snapshot.lastApplyIndex != SYNC_INDEX_INVALID) {
|
||||
for (int32_t i = 0; i < ths->pRaftCfg->configIndexCount; ++i) {
|
||||
|
@ -85,8 +86,10 @@ static int32_t syncNodeTimerRoutine(SSyncNode* ths) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t syncNodeOnTimer(SSyncNode* ths, SyncTimeout* pMsg) {
|
||||
int32_t ret = 0;
|
||||
int32_t syncNodeOnTimeout(SSyncNode* ths, const SRpcMsg* pRpc) {
|
||||
int32_t ret = 0;
|
||||
SyncTimeout* pMsg = pRpc->pCont;
|
||||
|
||||
syncLogRecvTimer(ths, pMsg, "");
|
||||
|
||||
if (pMsg->timeoutType == SYNC_TIMEOUT_PING) {
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "syncUtil.h"
|
||||
#include "syncMessage.h"
|
||||
#include "syncRaftCfg.h"
|
||||
#include "syncRaftStore.h"
|
||||
#include "syncSnapshot.h"
|
||||
|
@ -345,3 +346,205 @@ void syncPrintSnapshotReceiverLog(const char* flags, ELogLevel level, int32_t df
|
|||
pNode->replicaNum, pNode->pRaftCfg->lastConfigIndex, pNode->changing, pNode->restoreFinish, quorum,
|
||||
pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser, peerStr, cfgStr);
|
||||
}
|
||||
|
||||
void syncLogRecvTimer(SSyncNode* pSyncNode, const SyncTimeout* pMsg, const char* s) {
|
||||
sNTrace(pSyncNode, "recv sync-timer {type:%s, lc:%" PRId64 ", ms:%d, data:%p}, %s",
|
||||
syncTimerTypeStr(pMsg->timeoutType), pMsg->logicClock, pMsg->timerMS, pMsg->data, s);
|
||||
}
|
||||
|
||||
void syncLogRecvLocalCmd(SSyncNode* pSyncNode, const SyncLocalCmd* pMsg, const char* s) {
|
||||
sNTrace(pSyncNode, "recv sync-local-cmd {cmd:%d-%s, sd-new-term:%" PRId64 ", fc-index:%" PRId64 "}, %s", pMsg->cmd,
|
||||
syncLocalCmdGetStr(pMsg->cmd), pMsg->sdNewTerm, pMsg->fcIndex, s);
|
||||
}
|
||||
|
||||
void syncLogSendAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||
|
||||
sNTrace(pSyncNode,
|
||||
"send sync-append-entries-reply to %s:%d, {term:%" PRId64 ", pterm:%" PRId64 ", success:%d, match:%" PRId64
|
||||
"}, %s",
|
||||
host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex, s);
|
||||
}
|
||||
|
||||
void syncLogRecvAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||
|
||||
sNTrace(pSyncNode,
|
||||
"recv sync-append-entries-reply from %s:%d {term:%" PRId64 ", pterm:%" PRId64 ", success:%d, match:%" PRId64
|
||||
"}, %s",
|
||||
host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex, s);
|
||||
}
|
||||
|
||||
void syncLogSendHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||
|
||||
sNTrace(pSyncNode,
|
||||
"send sync-heartbeat to %s:%d {term:%" PRId64 ", cmt:%" PRId64 ", min-match:%" PRId64 ", pterm:%" PRId64
|
||||
"}, %s",
|
||||
host, port, pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->privateTerm, s);
|
||||
}
|
||||
|
||||
void syncLogRecvHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||
|
||||
sNTrace(pSyncNode,
|
||||
"recv sync-heartbeat from %s:%d {term:%" PRId64 ", cmt:%" PRId64 ", min-match:%" PRId64 ", pterm:%" PRId64
|
||||
"}, %s",
|
||||
host, port, pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->privateTerm, s);
|
||||
}
|
||||
|
||||
void syncLogSendHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||
|
||||
sNTrace(pSyncNode, "send sync-heartbeat-reply from %s:%d {term:%" PRId64 ", pterm:%" PRId64 "}, %s", host, port,
|
||||
pMsg->term, pMsg->privateTerm, s);
|
||||
}
|
||||
|
||||
void syncLogRecvHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||
sNTrace(pSyncNode, "recv sync-heartbeat-reply from %s:%d {term:%" PRId64 ", pterm:%" PRId64 "}, %s", host, port,
|
||||
pMsg->term, pMsg->privateTerm, s);
|
||||
}
|
||||
|
||||
void syncLogSendSyncPreSnapshot(SSyncNode* pSyncNode, const SyncPreSnapshot* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||
sNTrace(pSyncNode, "send sync-pre-snapshot to %s:%d {term:%" PRId64 "}, %s", host, port, pMsg->term, s);
|
||||
}
|
||||
|
||||
void syncLogRecvSyncPreSnapshot(SSyncNode* pSyncNode, const SyncPreSnapshot* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||
sNTrace(pSyncNode, "recv sync-pre-snapshot from %s:%d {term:%" PRId64 "}, %s", host, port, pMsg->term, s);
|
||||
}
|
||||
|
||||
void syncLogSendSyncPreSnapshotReply(SSyncNode* pSyncNode, const SyncPreSnapshotReply* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||
sNTrace(pSyncNode, "send sync-pre-snapshot-reply to %s:%d {term:%" PRId64 ", snap-start:%" PRId64 "}, %s", host, port,
|
||||
pMsg->term, pMsg->snapStart, s);
|
||||
}
|
||||
|
||||
void syncLogRecvSyncPreSnapshotReply(SSyncNode* pSyncNode, const SyncPreSnapshotReply* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||
sNTrace(pSyncNode, "recv sync-pre-snapshot-reply from %s:%d {term:%" PRId64 ", snap-start:%" PRId64 "}, %s", host,
|
||||
port, pMsg->term, pMsg->snapStart, s);
|
||||
}
|
||||
|
||||
void syncLogSendSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||
|
||||
sNTrace(pSyncNode,
|
||||
"send sync-snapshot-send from %s:%d {term:%" PRId64 ", begin:%" PRId64 ", end:%" PRId64 ", lterm:%" PRId64
|
||||
", stime:%" PRId64 ", seq:%d}, %s",
|
||||
host, port, pMsg->term, pMsg->beginIndex, pMsg->lastIndex, pMsg->lastTerm, pMsg->startTime, pMsg->seq, s);
|
||||
}
|
||||
|
||||
void syncLogRecvSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||
|
||||
sNTrace(pSyncNode,
|
||||
"recv sync-snapshot-send from %s:%d {term:%" PRId64 ", begin:%" PRId64 ", lst:%" PRId64 ", lterm:%" PRId64
|
||||
", stime:%" PRId64 ", seq:%d, len:%u}, %s",
|
||||
host, port, pMsg->term, pMsg->beginIndex, pMsg->lastIndex, pMsg->lastTerm, pMsg->startTime, pMsg->seq,
|
||||
pMsg->dataLen, s);
|
||||
}
|
||||
|
||||
void syncLogSendSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||
|
||||
sNTrace(pSyncNode,
|
||||
"send sync-snapshot-rsp from %s:%d {term:%" PRId64 ", begin:%" PRId64 ", lst:%" PRId64 ", lterm:%" PRId64
|
||||
", stime:%" PRId64 ", ack:%d}, %s",
|
||||
host, port, pMsg->term, pMsg->snapBeginIndex, pMsg->lastIndex, pMsg->lastTerm, pMsg->startTime, pMsg->ack, s);
|
||||
}
|
||||
|
||||
void syncLogRecvSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||
|
||||
sNTrace(pSyncNode,
|
||||
"recv sync-snapshot-rsp from %s:%d {term:%" PRId64 ", begin:%" PRId64 ", lst:%" PRId64 ", lterm:%" PRId64
|
||||
", stime:%" PRId64 ", ack:%d}, %s",
|
||||
host, port, pMsg->term, pMsg->snapBeginIndex, pMsg->lastIndex, pMsg->lastTerm, pMsg->startTime, pMsg->ack, s);
|
||||
}
|
||||
|
||||
void syncLogRecvAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||
|
||||
sNTrace(pSyncNode,
|
||||
"recv sync-append-entries from %s:%d {term:%" PRId64 ", pre-index:%" PRId64 ", pre-term:%" PRId64
|
||||
", cmt:%" PRId64 ", pterm:%" PRId64 ", datalen:%d}, %s",
|
||||
host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm,
|
||||
pMsg->dataLen, s);
|
||||
}
|
||||
|
||||
void syncLogSendAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||
sNTrace(pSyncNode,
|
||||
"send sync-append-entries to %s:%d, {term:%" PRId64 ", pre-index:%" PRId64 ", pre-term:%" PRId64
|
||||
", pterm:%" PRId64 ", cmt:%" PRId64 ", datalen:%d}, %s",
|
||||
host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex,
|
||||
pMsg->dataLen, s);
|
||||
}
|
||||
|
||||
void syncLogRecvRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, const char* s) {
|
||||
char logBuf[256];
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||
sNTrace(pSyncNode, "recv sync-request-vote from %s:%d, {term:%" PRId64 ", lindex:%" PRId64 ", lterm:%" PRId64 "}, %s",
|
||||
host, port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, s);
|
||||
}
|
||||
|
||||
void syncLogSendRequestVote(SSyncNode* pNode, const SyncRequestVote* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||
sNTrace(pNode, "send sync-request-vote to %s:%d {term:%" PRId64 ", lindex:%" PRId64 ", lterm:%" PRId64 "}, %s", host,
|
||||
port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, s);
|
||||
}
|
||||
|
||||
void syncLogRecvRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||
sNTrace(pSyncNode, "recv sync-request-vote-reply from %s:%d {term:%" PRId64 ", grant:%d}, %s", host, port, pMsg->term,
|
||||
pMsg->voteGranted, s);
|
||||
}
|
||||
|
||||
void syncLogSendRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s) {
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||
sNTrace(pSyncNode, "send sync-request-vote-reply to %s:%d {term:%" PRId64 ", grant:%d}, %s", host, port, pMsg->term,
|
||||
pMsg->voteGranted, s);
|
||||
}
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "syncVoteMgr.h"
|
||||
#include "syncMessage.h"
|
||||
#include "syncUtil.h"
|
||||
|
||||
static void voteGrantedClearVotes(SVotesGranted *pVotesGranted) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//#include <gtest/gtest.h>
|
||||
#include "syncTest.h"
|
||||
#include "syncBatch.h"
|
||||
|
||||
void logTest() {
|
||||
sTrace("--- sync log test: trace");
|
||||
|
|
|
@ -143,7 +143,8 @@ int32_t SnapshotDoWrite(struct SSyncFSM* pFsm, void* pWriter, void* pBuf, int32_
|
|||
void RestoreFinishCb(struct SSyncFSM* pFsm) { sTrace("==callback== ==RestoreFinishCb=="); }
|
||||
|
||||
void ReConfigCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta* cbMeta) {
|
||||
sTrace("==callback== ==ReConfigCb== flag:0x%lX, index:%" PRId64 ", code:%d, currentTerm:%" PRIu64 ", term:%" PRIu64,
|
||||
sTrace("==callback== ==ReConfigCb== flag:%" PRIx64 ", index:%" PRId64 ", code:%d, currentTerm:%" PRIu64
|
||||
", term:%" PRIu64,
|
||||
cbMeta->flag, cbMeta->index, cbMeta->code, cbMeta->currentTerm, cbMeta->term);
|
||||
}
|
||||
|
||||
|
@ -222,18 +223,18 @@ int64_t createSyncNode(int32_t replicaNum, int32_t myIndex, int32_t vgId, SWal*
|
|||
|
||||
SSyncNode* pSyncNode = (SSyncNode*)syncNodeAcquire(rid);
|
||||
assert(pSyncNode != NULL);
|
||||
gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing;
|
||||
gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply;
|
||||
gSyncIO->FpOnSyncTimeout = pSyncNode->FpOnTimeout;
|
||||
gSyncIO->FpOnSyncClientRequest = pSyncNode->FpOnClientRequest;
|
||||
// gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing;
|
||||
// gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply;
|
||||
// gSyncIO->FpOnSyncTimeout = pSyncNode->FpOnTimeout;
|
||||
// gSyncIO->FpOnSyncClientRequest = pSyncNode->FpOnClientRequest;
|
||||
|
||||
gSyncIO->FpOnSyncRequestVote = pSyncNode->FpOnRequestVote;
|
||||
gSyncIO->FpOnSyncRequestVoteReply = pSyncNode->FpOnRequestVoteReply;
|
||||
gSyncIO->FpOnSyncAppendEntries = pSyncNode->FpOnAppendEntries;
|
||||
gSyncIO->FpOnSyncAppendEntriesReply = pSyncNode->FpOnAppendEntriesReply;
|
||||
// gSyncIO->FpOnSyncRequestVote = pSyncNode->FpOnRequestVote;
|
||||
// gSyncIO->FpOnSyncRequestVoteReply = pSyncNode->FpOnRequestVoteReply;
|
||||
// gSyncIO->FpOnSyncAppendEntries = pSyncNode->FpOnAppendEntries;
|
||||
// gSyncIO->FpOnSyncAppendEntriesReply = pSyncNode->FpOnAppendEntriesReply;
|
||||
|
||||
gSyncIO->FpOnSyncSnapshot = pSyncNode->FpOnSnapshot;
|
||||
gSyncIO->FpOnSyncSnapshotReply = pSyncNode->FpOnSnapshotReply;
|
||||
// gSyncIO->FpOnSyncSnapshot = pSyncNode->FpOnSnapshot;
|
||||
// gSyncIO->FpOnSyncSnapshotReply = pSyncNode->FpOnSnapshotReply;
|
||||
|
||||
gSyncIO->pSyncNode = pSyncNode;
|
||||
syncNodeRelease(pSyncNode);
|
||||
|
|
|
@ -73,7 +73,8 @@ int32_t GetSnapshotCb(const struct SSyncFSM* pFsm, SSnapshot* pSnapshot) {
|
|||
void RestoreFinishCb(struct SSyncFSM* pFsm) { sTrace("==callback== ==RestoreFinishCb=="); }
|
||||
|
||||
void ReConfigCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta* cbMeta) {
|
||||
sTrace("==callback== ==ReConfigCb== flag:0x%lX, index:%" PRId64 ", code:%d, currentTerm:%" PRIu64 ", term:%" PRIu64,
|
||||
sTrace("==callback== ==ReConfigCb== flag:%" PRIx64 ", index:%" PRId64 ", code:%d, currentTerm:%" PRIu64
|
||||
", term:%" PRIu64,
|
||||
cbMeta->flag, cbMeta->index, cbMeta->code, cbMeta->currentTerm, cbMeta->term);
|
||||
}
|
||||
|
||||
|
@ -145,16 +146,16 @@ int64_t createSyncNode(int32_t replicaNum, int32_t myIndex, int32_t vgId, SWal*
|
|||
|
||||
SSyncNode* pSyncNode = (SSyncNode*)syncNodeAcquire(rid);
|
||||
assert(pSyncNode != NULL);
|
||||
gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing;
|
||||
gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply;
|
||||
gSyncIO->FpOnSyncRequestVote = pSyncNode->FpOnRequestVote;
|
||||
gSyncIO->FpOnSyncRequestVoteReply = pSyncNode->FpOnRequestVoteReply;
|
||||
gSyncIO->FpOnSyncAppendEntries = pSyncNode->FpOnAppendEntries;
|
||||
gSyncIO->FpOnSyncAppendEntriesReply = pSyncNode->FpOnAppendEntriesReply;
|
||||
gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing;
|
||||
gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply;
|
||||
gSyncIO->FpOnSyncTimeout = pSyncNode->FpOnTimeout;
|
||||
gSyncIO->FpOnSyncClientRequest = pSyncNode->FpOnClientRequest;
|
||||
// gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing;
|
||||
// gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply;
|
||||
// gSyncIO->FpOnSyncRequestVote = pSyncNode->FpOnRequestVote;
|
||||
// gSyncIO->FpOnSyncRequestVoteReply = pSyncNode->FpOnRequestVoteReply;
|
||||
// gSyncIO->FpOnSyncAppendEntries = pSyncNode->FpOnAppendEntries;
|
||||
// gSyncIO->FpOnSyncAppendEntriesReply = pSyncNode->FpOnAppendEntriesReply;
|
||||
// gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing;
|
||||
// gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply;
|
||||
// gSyncIO->FpOnSyncTimeout = pSyncNode->FpOnTimeout;
|
||||
// gSyncIO->FpOnSyncClientRequest = pSyncNode->FpOnClientRequest;
|
||||
gSyncIO->pSyncNode = pSyncNode;
|
||||
syncNodeRelease(pSyncNode);
|
||||
|
||||
|
|
|
@ -59,15 +59,15 @@ SSyncNode* createSyncNode(int32_t replicaNum, int32_t myIndex, int32_t vgId, SWa
|
|||
SSyncNode* pSyncNode = syncNodeOpen(&syncInfo);
|
||||
assert(pSyncNode != NULL);
|
||||
|
||||
gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing;
|
||||
gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply;
|
||||
gSyncIO->FpOnSyncRequestVote = pSyncNode->FpOnRequestVote;
|
||||
gSyncIO->FpOnSyncRequestVoteReply = pSyncNode->FpOnRequestVoteReply;
|
||||
gSyncIO->FpOnSyncAppendEntries = pSyncNode->FpOnAppendEntries;
|
||||
gSyncIO->FpOnSyncAppendEntriesReply = pSyncNode->FpOnAppendEntriesReply;
|
||||
gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing;
|
||||
gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply;
|
||||
gSyncIO->FpOnSyncTimeout = pSyncNode->FpOnTimeout;
|
||||
// gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing;
|
||||
// gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply;
|
||||
// gSyncIO->FpOnSyncRequestVote = pSyncNode->FpOnRequestVote;
|
||||
// gSyncIO->FpOnSyncRequestVoteReply = pSyncNode->FpOnRequestVoteReply;
|
||||
// gSyncIO->FpOnSyncAppendEntries = pSyncNode->FpOnAppendEntries;
|
||||
// gSyncIO->FpOnSyncAppendEntriesReply = pSyncNode->FpOnAppendEntriesReply;
|
||||
// gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing;
|
||||
// gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply;
|
||||
// gSyncIO->FpOnSyncTimeout = pSyncNode->FpOnTimeout;
|
||||
gSyncIO->pSyncNode = pSyncNode;
|
||||
|
||||
syncNodeStart(pSyncNode);
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue