diff --git a/cmake/taosadapter_CMakeLists.txt.in b/cmake/taosadapter_CMakeLists.txt.in
index 79d54f522e..cc46ef9938 100644
--- a/cmake/taosadapter_CMakeLists.txt.in
+++ b/cmake/taosadapter_CMakeLists.txt.in
@@ -2,7 +2,7 @@
# taosadapter
ExternalProject_Add(taosadapter
GIT_REPOSITORY https://github.com/taosdata/taosadapter.git
- GIT_TAG 0d5663d
+ GIT_TAG ff7de07
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taosadapter"
BINARY_DIR ""
#BUILD_IN_SOURCE TRUE
diff --git a/docs/en/28-releases/01-tdengine.md b/docs/en/28-releases/01-tdengine.md
index 74eeeb5efb..eee2f94ee1 100644
--- a/docs/en/28-releases/01-tdengine.md
+++ b/docs/en/28-releases/01-tdengine.md
@@ -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
-
diff --git a/docs/en/28-releases/02-tools.md b/docs/en/28-releases/02-tools.md
index 0a96c776e0..6e8a040f8b 100644
--- a/docs/en/28-releases/02-tools.md
+++ b/docs/en/28-releases/02-tools.md
@@ -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
diff --git a/docs/zh/12-taos-sql/01-data-type.md b/docs/zh/12-taos-sql/01-data-type.md
index a59330546b..f014573ca6 100644
--- a/docs/zh/12-taos-sql/01-data-type.md
+++ b/docs/zh/12-taos-sql/01-data-type.md
@@ -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 会被认为是有效的浮点数。
diff --git a/docs/zh/14-reference/11-docker/index.md b/docs/zh/14-reference/11-docker/index.md
index 58bbe1e117..086d72940c 100644
--- a/docs/zh/14-reference/11-docker/index.md
+++ b/docs/zh/14-reference/11-docker/index.md
@@ -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 \
diff --git a/docs/zh/28-releases/01-tdengine.md b/docs/zh/28-releases/01-tdengine.md
index f72735d903..4108212c55 100644
--- a/docs/zh/28-releases/01-tdengine.md
+++ b/docs/zh/28-releases/01-tdengine.md
@@ -4,7 +4,9 @@ title: TDengine 发布历史及下载链接
description: TDengine 发布历史、Release Notes 及下载链接
---
-各版本 TDengine 安装包下载链接如下:
+TDengine 3.x 各版本安装包下载链接如下:
+
+TDengine 2.x 各版本安装包请访问[这里](https://www.taosdata.com/all-downloads)
import Release from "/components/ReleaseV3";
diff --git a/docs/zh/28-releases/02-tools.md b/docs/zh/28-releases/02-tools.md
index ac4a884f8b..28e0d4bca9 100644
--- a/docs/zh/28-releases/02-tools.md
+++ b/docs/zh/28-releases/02-tools.md
@@ -4,7 +4,9 @@ title: taosTools 发布历史及下载链接
description: taosTools 的发布历史、Release Notes 和下载链接
---
-各版本 taosTools 安装包下载链接如下:
+taosTools 各版本安装包下载链接如下:
+
+其他历史版本安装包请访问[这里](https://www.taosdata.com/all-downloads)
import Release from "/components/ReleaseV3";
diff --git a/include/common/systable.h b/include/common/systable.h
index 8b29525db3..57f85f16bc 100644
--- a/include/common/systable.h
+++ b/include/common/systable.h
@@ -46,6 +46,7 @@ extern "C" {
#define TSDB_INS_TABLE_SUBSCRIPTIONS "ins_subscriptions"
#define TSDB_INS_TABLE_TOPICS "ins_topics"
#define TSDB_INS_TABLE_STREAMS "ins_streams"
+#define TSDB_INS_TABLE_STREAM_TASKS "ins_stream_tasks"
#define TSDB_PERFORMANCE_SCHEMA_DB "performance_schema"
#define TSDB_PERFS_TABLE_SMAS "perf_smas"
diff --git a/include/common/tmsg.h b/include/common/tmsg.h
index 99c5c72e2f..3281bca96a 100644
--- a/include/common/tmsg.h
+++ b/include/common/tmsg.h
@@ -119,6 +119,7 @@ typedef enum _mgmt_table {
TSDB_MGMT_TABLE_QUERIES,
TSDB_MGMT_TABLE_VNODES,
TSDB_MGMT_TABLE_APPS,
+ TSDB_MGMT_TABLE_STREAM_TASKS,
TSDB_MGMT_TABLE_MAX,
} EShowType;
diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h
index f4890206fe..7ca552f179 100644
--- a/include/common/tmsgdef.h
+++ b/include/common/tmsgdef.h
@@ -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)
diff --git a/include/common/ttypes.h b/include/common/ttypes.h
index bfd6a75c3a..761ffd0f1c 100644
--- a/include/common/ttypes.h
+++ b/include/common/ttypes.h
@@ -346,8 +346,8 @@ bool isValidDataType(int32_t type);
void assignVal(char *val, const char *src, int32_t len, int32_t type);
void operateVal(void *dst, void *s1, void *s2, int32_t optr, int32_t type);
-void *getDataMin(int32_t type);
-void *getDataMax(int32_t type);
+void *getDataMin(int32_t type, void* value);
+void *getDataMax(int32_t type, void* value);
#ifdef __cplusplus
}
diff --git a/include/libs/function/taosudf.h b/include/libs/function/taosudf.h
index 3fe3bb7d3b..5f57e203b9 100644
--- a/include/libs/function/taosudf.h
+++ b/include/libs/function/taosudf.h
@@ -104,7 +104,7 @@ typedef int32_t (*TUdfDestroyFunc)();
} while (0)
#define udfColDataSetNull_var(pColumn, row) ((pColumn->colData.varLenCol.varOffsets)[row] = -1)
-typedef uint16_t VarDataLenT; // maxVarDataLen: 32767
+typedef uint16_t VarDataLenT; // maxVarDataLen: 65535
#define VARSTR_HEADER_SIZE sizeof(VarDataLenT)
#define varDataLen(v) ((VarDataLenT *)(v))[0]
#define varDataVal(v) ((char *)(v) + VARSTR_HEADER_SIZE)
diff --git a/include/libs/nodes/querynodes.h b/include/libs/nodes/querynodes.h
index a1dad1806d..d0971b013f 100644
--- a/include/libs/nodes/querynodes.h
+++ b/include/libs/nodes/querynodes.h
@@ -74,9 +74,8 @@ typedef struct SColumnNode {
char tableName[TSDB_TABLE_NAME_LEN];
char tableAlias[TSDB_TABLE_NAME_LEN];
char colName[TSDB_COL_NAME_LEN];
- // SNode* pProjectRef;
- int16_t dataBlockId;
- int16_t slotId;
+ int16_t dataBlockId;
+ int16_t slotId;
} SColumnNode;
typedef struct SColumnRefNode {
diff --git a/include/libs/qworker/qworker.h b/include/libs/qworker/qworker.h
index 6ddd906700..2be0561ce7 100644
--- a/include/libs/qworker/qworker.h
+++ b/include/libs/qworker/qworker.h
@@ -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);
diff --git a/include/libs/sync/sync.h b/include/libs/sync/sync.h
index 0b997690a1..3a808ac6f3 100644
--- a/include/libs/sync/sync.h
+++ b/include/libs/sync/sync.h
@@ -38,6 +38,7 @@ extern "C" {
#define SYNC_MNODE_LOG_RETENTION 10000
#define SYNC_VNODE_LOG_RETENTION 100
#define SNAPSHOT_MAX_CLOCK_SKEW_MS 1000 * 10
+#define SNAPSHOT_WAIT_MS 1000 * 30
#define SYNC_APPEND_ENTRIES_TIMEOUT_MS 10000
diff --git a/include/util/taoserror.h b/include/util/taoserror.h
index a03dc7d9f9..636decc60b 100644
--- a/include/util/taoserror.h
+++ b/include/util/taoserror.h
@@ -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)
diff --git a/include/util/types.h b/include/util/types.h
index 8dd0947e9c..b49670220b 100644
--- a/include/util/types.h
+++ b/include/util/types.h
@@ -78,7 +78,7 @@ static FORCE_INLINE double taos_align_get_double(const char *pBuf) {
{ (*(double *)(x)) = (*(double *)(y)); }
// #endif
-typedef uint16_t VarDataLenT; // maxVarDataLen: 32767
+typedef uint16_t VarDataLenT; // maxVarDataLen: 65535
#define VARSTR_HEADER_SIZE sizeof(VarDataLenT)
#define varDataLen(v) ((VarDataLenT *)(v))[0]
diff --git a/packaging/release.bat b/packaging/release.bat
index 4ab7297f03..4c82c5ead5 100644
--- a/packaging/release.bat
+++ b/packaging/release.bat
@@ -39,7 +39,7 @@ if not exist %work_dir%\debug\ver-%2-x86 (
md %work_dir%\debug\ver-%2-x86
)
cd %work_dir%\debug\ver-%2-x64
-rem #call vcvarsall.bat x64
+call vcvarsall.bat x64
cmake ../../ -G "NMake Makefiles JOM" -DCMAKE_MAKE_PROGRAM=jom -DBUILD_TOOLS=true -DWEBSOCKET=true -DBUILD_HTTP=false -DBUILD_TEST=false -DVERNUMBER=%2 -DCPUTYPE=x64
cmake --build .
rd /s /Q C:\TDengine
diff --git a/packaging/tools/tdengine.iss b/packaging/tools/tdengine.iss
index 981bee91b8..1c0c105179 100644
--- a/packaging/tools/tdengine.iss
+++ b/packaging/tools/tdengine.iss
@@ -61,6 +61,16 @@ Source: {#MyAppSourceDir}{#MyAppExeName}; DestDir: "{app}"; Excludes: {#MyAppExc
Source: {#MyAppSourceDir}{#MyAppTaosdemoExeName}; DestDir: "{app}"; Flags: igNoreversion recursesubdirs createallsubdirs
+[run]
+Filename: {sys}\sc.exe; Parameters: "create taosd start= DEMAND binPath= ""C:\\TDengine\\taosd.exe --win_service""" ; Flags: runhidden
+Filename: {sys}\sc.exe; Parameters: "create taosadapter start= DEMAND binPath= ""C:\\TDengine\\taosadapter.exe --win_service""" ; Flags: runhidden
+
+[UninstallRun]
+RunOnceId: "stoptaosd"; Filename: {sys}\sc.exe; Parameters: "stop taosd" ; Flags: runhidden
+RunOnceId: "stoptaosadapter"; Filename: {sys}\sc.exe; Parameters: "stop taosadapter" ; Flags: runhidden
+RunOnceId: "deltaosd"; Filename: {sys}\sc.exe; Parameters: "delete taosd" ; Flags: runhidden
+RunOnceId: "deltaosadapter"; Filename: {sys}\sc.exe; Parameters: "delete taosadapter" ; Flags: runhidden
+
[Registry]
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; \
ValueType: expandsz; ValueName: "Path"; ValueData: "{olddata};C:\TDengine"; \
diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c
index efa7d095c5..0aa88382fe 100644
--- a/source/client/src/clientMain.c
+++ b/source/client/src/clientMain.c
@@ -677,6 +677,7 @@ static void destoryCatalogReq(SCatalogReq *pCatalogReq) {
taosArrayDestroy(pCatalogReq->pIndex);
taosArrayDestroy(pCatalogReq->pUser);
taosArrayDestroy(pCatalogReq->pTableIndex);
+ taosArrayDestroy(pCatalogReq->pTableCfg);
taosMemoryFree(pCatalogReq);
}
diff --git a/source/common/src/systable.c b/source/common/src/systable.c
index d3d006ab35..c3a1f9f67e 100644
--- a/source/common/src/systable.c
+++ b/source/common/src/systable.c
@@ -134,7 +134,7 @@ static const SSysDbTableSchema userStbsSchema[] = {
};
static const SSysDbTableSchema streamSchema[] = {
- {.name = "stream_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
+ {.name = "stream_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = false},
{.name = "sql", .bytes = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
{.name = "status", .bytes = 20 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
@@ -145,6 +145,15 @@ static const SSysDbTableSchema streamSchema[] = {
{.name = "trigger", .bytes = 20 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
};
+static const SSysDbTableSchema streamTaskSchema[] = {
+ {.name = "stream_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
+ {.name = "task_id", .bytes = 8, .type = TSDB_DATA_TYPE_INT, .sysInfo = false},
+ {.name = "node_type", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
+ {.name = "node_id", .bytes = 8, .type = TSDB_DATA_TYPE_INT, .sysInfo = false},
+ {.name = "level", .bytes = 20 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
+ {.name = "status", .bytes = 20 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
+};
+
static const SSysDbTableSchema userTblsSchema[] = {
{.name = "table_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
{.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
@@ -287,6 +296,7 @@ static const SSysTableMeta infosMeta[] = {
{TSDB_INS_TABLE_TOPICS, topicSchema, tListLen(topicSchema), false},
{TSDB_INS_TABLE_SUBSCRIPTIONS, subscriptionSchema, tListLen(subscriptionSchema), false},
{TSDB_INS_TABLE_STREAMS, streamSchema, tListLen(streamSchema), false},
+ {TSDB_INS_TABLE_STREAM_TASKS, streamTaskSchema, tListLen(streamTaskSchema), false},
{TSDB_INS_TABLE_VNODES, vnodesSchema, tListLen(vnodesSchema), true},
};
diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c
index e8d5989e4d..f7b1196248 100644
--- a/source/common/src/tdatablock.c
+++ b/source/common/src/tdatablock.c
@@ -277,7 +277,9 @@ int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, int32_t numOfRow1, int
pColumnInfoData->varmeta.allocLen = len + oldLen;
}
- memcpy(pColumnInfoData->pData + oldLen, pSource->pData, len);
+ if (pColumnInfoData->pData && pSource->pData) { // TD-20382
+ memcpy(pColumnInfoData->pData + oldLen, pSource->pData, len);
+ }
pColumnInfoData->varmeta.length = len + oldLen;
} else {
if (finalNumOfRows > (*capacity)) {
diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c
index 2eb94773e9..bd8e34a395 100644
--- a/source/common/src/tmsg.c
+++ b/source/common/src/tmsg.c
@@ -2591,7 +2591,10 @@ int32_t tDeserializeSUseDbBatchRsp(void *buf, int32_t bufLen, SUseDbBatchRsp *pR
for (int32_t i = 0; i < numOfBatch; ++i) {
SUseDbRsp usedbRsp = {0};
- if (tDeserializeSUseDbRspImp(&decoder, &usedbRsp) < 0) return -1;
+ if (tDeserializeSUseDbRspImp(&decoder, &usedbRsp) < 0) {
+ tDecoderClear(&decoder);
+ return -1;
+ }
taosArrayPush(pRsp->pArray, &usedbRsp);
}
tEndDecode(&decoder);
diff --git a/source/common/src/ttypes.c b/source/common/src/ttypes.c
index a4e7a12ce4..8c5d44b8d5 100644
--- a/source/common/src/ttypes.c
+++ b/source/common/src/ttypes.c
@@ -61,26 +61,36 @@ tDataTypeDescriptor tDataTypes[TSDB_DATA_TYPE_MAX] = {
static float floatMin = -FLT_MAX, floatMax = FLT_MAX;
static double doubleMin = -DBL_MAX, doubleMax = DBL_MAX;
-FORCE_INLINE void *getDataMin(int32_t type) {
+FORCE_INLINE void *getDataMin(int32_t type, void* value) {
switch (type) {
case TSDB_DATA_TYPE_FLOAT:
- return &floatMin;
+ *(float *)value = floatMin;
+ break;
case TSDB_DATA_TYPE_DOUBLE:
- return &doubleMin;
+ *(double *)value = doubleMin;
+ break;
default:
- return &tDataTypes[type].minValue;
+ *(int64_t *)value = tDataTypes[type].minValue;
+ break;
}
+
+ return value;
}
-FORCE_INLINE void *getDataMax(int32_t type) {
+FORCE_INLINE void *getDataMax(int32_t type, void* value) {
switch (type) {
case TSDB_DATA_TYPE_FLOAT:
- return &floatMax;
+ *(float *)value = floatMax;
+ break;
case TSDB_DATA_TYPE_DOUBLE:
- return &doubleMax;
+ *(double *)value = doubleMax;
+ break;
default:
- return &tDataTypes[type].maxValue;
+ *(int64_t *)value = tDataTypes[type].maxValue;
+ break;
}
+
+ return value;
}
bool isValidDataType(int32_t type) { return type >= TSDB_DATA_TYPE_NULL && type < TSDB_DATA_TYPE_MAX; }
diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c
index a322f76800..16fe6c1b91 100644
--- a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c
+++ b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c
@@ -195,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;
diff --git a/source/dnode/mnode/impl/src/mndQuery.c b/source/dnode/mnode/impl/src/mndQuery.c
index 2b0edfebc2..3a7c25f7f9 100644
--- a/source/dnode/mnode/impl/src/mndQuery.c
+++ b/source/dnode/mnode/impl/src/mndQuery.c
@@ -178,8 +178,10 @@ int32_t mndProcessBatchMetaMsg(SRpcMsg *pMsg) {
offset += sizeof(p->msgLen);
*(int32_t *)((char *)pRsp + offset) = htonl(p->rspCode);
offset += sizeof(p->rspCode);
- memcpy((char *)pRsp + offset, p->msg, p->msgLen);
- offset += p->msgLen;
+ if (p->msg != NULL) {
+ memcpy((char *)pRsp + offset, p->msg, p->msgLen);
+ offset += p->msgLen;
+ }
rpcFreeCont(p->msg);
}
diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c
index b0af98b933..20c2ebb0a4 100644
--- a/source/dnode/mnode/impl/src/mndShow.c
+++ b/source/dnode/mnode/impl/src/mndShow.c
@@ -106,6 +106,8 @@ static int32_t convertToRetrieveType(char *name, int32_t len) {
type = TSDB_MGMT_TABLE_STREAMS;
} else if (strncasecmp(name, TSDB_PERFS_TABLE_APPS, len) == 0) {
type = TSDB_MGMT_TABLE_APPS;
+ } else if (strncasecmp(name, TSDB_INS_TABLE_STREAM_TASKS, len) == 0) {
+ type = TSDB_MGMT_TABLE_STREAM_TASKS;
} else {
// ASSERT(0);
}
diff --git a/source/dnode/mnode/impl/src/mndStream.c b/source/dnode/mnode/impl/src/mndStream.c
index 594c13f957..c649180285 100644
--- a/source/dnode/mnode/impl/src/mndStream.c
+++ b/source/dnode/mnode/impl/src/mndStream.c
@@ -41,6 +41,8 @@ static int32_t mndProcessStreamMetaReq(SRpcMsg *pReq);
static int32_t mndGetStreamMeta(SRpcMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta);
static int32_t mndRetrieveStream(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
static void mndCancelGetNextStream(SMnode *pMnode, void *pIter);
+static int32_t mndRetrieveStreamTask(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
+static void mndCancelGetNextStreamTask(SMnode *pMnode, void *pIter);
int32_t mndInitStream(SMnode *pMnode) {
SSdbTable table = {
@@ -62,6 +64,8 @@ int32_t mndInitStream(SMnode *pMnode) {
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_STREAMS, mndRetrieveStream);
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_STREAMS, mndCancelGetNextStream);
+ mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_STREAM_TASKS, mndRetrieveStreamTask);
+ mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_STREAM_TASKS, mndCancelGetNextStreamTask);
return sdbSetTable(pMnode->pSdb, table);
}
@@ -891,7 +895,7 @@ static int32_t mndRetrieveStream(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB
SName n;
int32_t cols = 0;
- char streamName[TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
+ char streamName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
STR_WITH_MAXSIZE_TO_VARSTR(streamName, mndGetDbStr(pStream->name), sizeof(streamName));
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataAppend(pColInfo, numOfRows, (const char *)streamName, false);
@@ -953,3 +957,105 @@ static void mndCancelGetNextStream(SMnode *pMnode, void *pIter) {
SSdb *pSdb = pMnode->pSdb;
sdbCancelFetch(pSdb, pIter);
}
+
+static int32_t mndRetrieveStreamTask(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rowsCapacity) {
+ SMnode *pMnode = pReq->info.node;
+ SSdb *pSdb = pMnode->pSdb;
+ int32_t numOfRows = 0;
+ SStreamObj *pStream = NULL;
+
+ while (numOfRows < rowsCapacity) {
+ pShow->pIter = sdbFetch(pSdb, SDB_STREAM, pShow->pIter, (void **)&pStream);
+ if (pShow->pIter == NULL) break;
+
+ // lock
+ taosRLockLatch(&pStream->lock);
+ // count task num
+ int32_t sz = taosArrayGetSize(pStream->tasks);
+ int32_t count = 0;
+ for (int32_t i = 0; i < sz; i++) {
+ SArray *pLevel = taosArrayGetP(pStream->tasks, i);
+ count += taosArrayGetSize(pLevel);
+ }
+
+ if (numOfRows + count > rowsCapacity) {
+ blockDataEnsureCapacity(pBlock, numOfRows + count);
+ }
+ // add row for each task
+ for (int32_t i = 0; i < sz; i++) {
+ SArray *pLevel = taosArrayGetP(pStream->tasks, i);
+ int32_t levelCnt = taosArrayGetSize(pLevel);
+ for (int32_t j = 0; j < levelCnt; j++) {
+ SStreamTask *pTask = taosArrayGetP(pLevel, j);
+
+ SColumnInfoData *pColInfo;
+ int32_t cols = 0;
+
+ // stream name
+ char streamName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
+ STR_WITH_MAXSIZE_TO_VARSTR(streamName, mndGetDbStr(pStream->name), sizeof(streamName));
+ pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
+ colDataAppend(pColInfo, numOfRows, (const char *)streamName, false);
+
+ // task id
+ pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
+ colDataAppend(pColInfo, numOfRows, (const char *)&pTask->taskId, false);
+
+ // node type
+ char nodeType[20 + VARSTR_HEADER_SIZE] = {0};
+ varDataSetLen(nodeType, 5);
+ pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
+ if (pTask->nodeId > 0) {
+ memcpy(varDataVal(nodeType), "vnode", 5);
+ } else {
+ memcpy(varDataVal(nodeType), "snode", 5);
+ }
+ colDataAppend(pColInfo, numOfRows, nodeType, false);
+
+ // node id
+ pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
+ int32_t nodeId = TMAX(pTask->nodeId, 0);
+ colDataAppend(pColInfo, numOfRows, (const char *)&nodeId, false);
+
+ // level
+ char level[20 + VARSTR_HEADER_SIZE] = {0};
+ if (pTask->taskLevel == TASK_LEVEL__SOURCE) {
+ memcpy(varDataVal(level), "source", 6);
+ varDataSetLen(level, 6);
+ } else if (pTask->taskLevel == TASK_LEVEL__AGG) {
+ memcpy(varDataVal(level), "agg", 3);
+ varDataSetLen(level, 3);
+ } else if (pTask->taskLevel == TASK_LEVEL__SINK) {
+ memcpy(varDataVal(level), "sink", 4);
+ varDataSetLen(level, 4);
+ } else if (pTask->taskLevel == TASK_LEVEL__SINK) {
+ }
+ pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
+ colDataAppend(pColInfo, numOfRows, (const char *)&level, false);
+
+ // status
+ char status[20 + VARSTR_HEADER_SIZE] = {0};
+ char status2[20] = {0};
+ strcpy(status, "normal");
+ STR_WITH_MAXSIZE_TO_VARSTR(status, status2, sizeof(status));
+ pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
+ colDataAppend(pColInfo, numOfRows, (const char *)&status, false);
+
+ numOfRows++;
+ }
+ }
+
+ // unlock
+ taosRUnLockLatch(&pStream->lock);
+
+ sdbRelease(pSdb, pStream);
+ }
+
+ pShow->numOfRows += numOfRows;
+ return numOfRows;
+}
+
+static void mndCancelGetNextStreamTask(SMnode *pMnode, void *pIter) {
+ SSdb *pSdb = pMnode->pSdb;
+ sdbCancelFetch(pSdb, pIter);
+}
diff --git a/source/dnode/mnode/impl/src/mndSubscribe.c b/source/dnode/mnode/impl/src/mndSubscribe.c
index a62f15f978..71e0b09e02 100644
--- a/source/dnode/mnode/impl/src/mndSubscribe.c
+++ b/source/dnode/mnode/impl/src/mndSubscribe.c
@@ -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;
}
diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h
index ba9d68ee7f..c6e2842c32 100644
--- a/source/dnode/vnode/src/inc/tsdb.h
+++ b/source/dnode/vnode/src/inc/tsdb.h
@@ -108,8 +108,8 @@ static FORCE_INLINE int64_t tsdbLogicToFileSize(int64_t lSize, int32_t szPage) {
#define TSDBROW_KEY(ROW) ((TSDBKEY){.version = TSDBROW_VERSION(ROW), .ts = TSDBROW_TS(ROW)})
#define tsdbRowFromTSRow(VERSION, TSROW) ((TSDBROW){.type = 0, .version = (VERSION), .pTSRow = (TSROW)})
#define tsdbRowFromBlockData(BLOCKDATA, IROW) ((TSDBROW){.type = 1, .pBlockData = (BLOCKDATA), .iRow = (IROW)})
-void tsdbRowGetColVal(TSDBROW *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal);
-int32_t tPutTSDBRow(uint8_t *p, TSDBROW *pRow);
+void tsdbRowGetColVal(TSDBROW *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal);
+// int32_t tPutTSDBRow(uint8_t *p, TSDBROW *pRow);
int32_t tsdbRowCmprFn(const void *p1, const void *p2);
// SRowIter
void tRowIterInit(SRowIter *pIter, TSDBROW *pRow, STSchema *pTSchema);
@@ -333,6 +333,8 @@ struct SVersionRange {
typedef struct SMemSkipListNode SMemSkipListNode;
struct SMemSkipListNode {
int8_t level;
+ int64_t version;
+ STSRow *pTSRow;
SMemSkipListNode *forwards[0];
};
typedef struct SMemSkipList {
@@ -772,14 +774,6 @@ static FORCE_INLINE int32_t tsdbKeyCmprFn(const void *p1, const void *p2) {
#define SL_NODE_FORWARD(n, l) ((n)->forwards[l])
#define SL_NODE_BACKWARD(n, l) ((n)->forwards[(n)->level + (l)])
-#define SL_NODE_DATA(n) (&SL_NODE_BACKWARD(n, (n)->level))
-
-static FORCE_INLINE int32_t tGetTSDBRow(uint8_t *p, TSDBROW *pRow) {
- int32_t n = tGetI64(p, &pRow->version);
- pRow->pTSRow = (STSRow *)(p + n);
- n += pRow->pTSRow->len;
- return n;
-}
static FORCE_INLINE TSDBROW *tsdbTbDataIterGet(STbDataIter *pIter) {
if (pIter == NULL) return NULL;
@@ -798,8 +792,9 @@ static FORCE_INLINE TSDBROW *tsdbTbDataIterGet(STbDataIter *pIter) {
}
}
- tGetTSDBRow((uint8_t *)SL_NODE_DATA(pIter->pNode), &pIter->row);
pIter->pRow = &pIter->row;
+ pIter->pRow->version = pIter->pNode->version;
+ pIter->pRow->pTSRow = pIter->pNode->pTSRow;
return pIter->pRow;
}
diff --git a/source/dnode/vnode/src/inc/vnd.h b/source/dnode/vnode/src/inc/vnd.h
index 29af2bda67..83f375c986 100644
--- a/source/dnode/vnode/src/inc/vnd.h
+++ b/source/dnode/vnode/src/inc/vnd.h
@@ -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);
diff --git a/source/dnode/vnode/src/tsdb/tsdbMemTable.c b/source/dnode/vnode/src/tsdb/tsdbMemTable.c
index 654afe1b6a..ddf2949607 100644
--- a/source/dnode/vnode/src/tsdb/tsdbMemTable.c
+++ b/source/dnode/vnode/src/tsdb/tsdbMemTable.c
@@ -18,10 +18,10 @@
#define MEM_MIN_HASH 1024
#define SL_MAX_LEVEL 5
-#define SL_NODE_SIZE(l) (sizeof(SMemSkipListNode) + sizeof(SMemSkipListNode *) * (l)*2)
+// sizeof(SMemSkipListNode) + sizeof(SMemSkipListNode *) * (l) * 2
+#define SL_NODE_SIZE(l) (sizeof(SMemSkipListNode) + ((l) << 4))
#define SL_NODE_FORWARD(n, l) ((n)->forwards[l])
#define SL_NODE_BACKWARD(n, l) ((n)->forwards[(n)->level + (l)])
-#define SL_NODE_DATA(n) (&SL_NODE_BACKWARD(n, (n)->level))
#define SL_MOVE_BACKWARD 0x1
#define SL_MOVE_FROM_POS 0x2
@@ -263,30 +263,27 @@ void tsdbTbDataIterOpen(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDa
}
bool tsdbTbDataIterNext(STbDataIter *pIter) {
- SMemSkipListNode *pHead = pIter->pTbData->sl.pHead;
- SMemSkipListNode *pTail = pIter->pTbData->sl.pTail;
-
pIter->pRow = NULL;
if (pIter->backward) {
- ASSERT(pIter->pNode != pTail);
+ ASSERT(pIter->pNode != pIter->pTbData->sl.pTail);
- if (pIter->pNode == pHead) {
+ if (pIter->pNode == pIter->pTbData->sl.pHead) {
return false;
}
pIter->pNode = SL_NODE_BACKWARD(pIter->pNode, 0);
- if (pIter->pNode == pHead) {
+ if (pIter->pNode == pIter->pTbData->sl.pHead) {
return false;
}
} else {
- ASSERT(pIter->pNode != pHead);
+ ASSERT(pIter->pNode != pIter->pTbData->sl.pHead);
- if (pIter->pNode == pTail) {
+ if (pIter->pNode == pIter->pTbData->sl.pTail) {
return false;
}
pIter->pNode = SL_NODE_FORWARD(pIter->pNode, 0);
- if (pIter->pNode == pTail) {
+ if (pIter->pNode == pIter->pTbData->sl.pTail) {
return false;
}
}
@@ -394,7 +391,7 @@ _err:
static void tbDataMovePosTo(STbData *pTbData, SMemSkipListNode **pos, TSDBKEY *pKey, int32_t flags) {
SMemSkipListNode *px;
SMemSkipListNode *pn;
- TSDBKEY *pTKey;
+ TSDBKEY tKey = {0};
int32_t backward = flags & SL_MOVE_BACKWARD;
int32_t fromPos = flags & SL_MOVE_FROM_POS;
@@ -413,9 +410,10 @@ static void tbDataMovePosTo(STbData *pTbData, SMemSkipListNode **pos, TSDBKEY *p
for (int8_t iLevel = pTbData->sl.level - 1; iLevel >= 0; iLevel--) {
pn = SL_NODE_BACKWARD(px, iLevel);
while (pn != pTbData->sl.pHead) {
- pTKey = (TSDBKEY *)SL_NODE_DATA(pn);
+ tKey.version = pn->version;
+ tKey.ts = pn->pTSRow->ts;
- int32_t c = tsdbKeyCmprFn(pTKey, pKey);
+ int32_t c = tsdbKeyCmprFn(&tKey, pKey);
if (c <= 0) {
break;
} else {
@@ -442,7 +440,10 @@ static void tbDataMovePosTo(STbData *pTbData, SMemSkipListNode **pos, TSDBKEY *p
for (int8_t iLevel = pTbData->sl.level - 1; iLevel >= 0; iLevel--) {
pn = SL_NODE_FORWARD(px, iLevel);
while (pn != pTbData->sl.pTail) {
- int32_t c = tsdbKeyCmprFn(SL_NODE_DATA(pn), pKey);
+ tKey.version = pn->version;
+ tKey.ts = pn->pTSRow->ts;
+
+ int32_t c = tsdbKeyCmprFn(&tKey, pKey);
if (c >= 0) {
break;
} else {
@@ -467,8 +468,8 @@ static FORCE_INLINE int8_t tsdbMemSkipListRandLevel(SMemSkipList *pSl) {
return level;
}
-static int32_t tbDataDoPut(SMemTable *pMemTable, STbData *pTbData, SMemSkipListNode **pos, TSDBROW *pRow,
- int8_t forward) {
+static int32_t tbDataDoPut(SMemTable *pMemTable, STbData *pTbData, SMemSkipListNode **pos, int64_t version,
+ STSRow *pRow, int8_t forward) {
int32_t code = 0;
int8_t level;
SMemSkipListNode *pNode;
@@ -477,13 +478,19 @@ static int32_t tbDataDoPut(SMemTable *pMemTable, STbData *pTbData, SMemSkipListN
// node
level = tsdbMemSkipListRandLevel(&pTbData->sl);
ASSERT(pPool != NULL);
- pNode = (SMemSkipListNode *)vnodeBufPoolMalloc(pPool, SL_NODE_SIZE(level) + tPutTSDBRow(NULL, pRow));
+ pNode = (SMemSkipListNode *)vnodeBufPoolMalloc(pPool, SL_NODE_SIZE(level));
if (pNode == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
goto _exit;
}
pNode->level = level;
- tPutTSDBRow((uint8_t *)SL_NODE_DATA(pNode), pRow);
+ pNode->version = version;
+ pNode->pTSRow = vnodeBufPoolMalloc(pPool, pRow->len);
+ if (NULL == pNode->pTSRow) {
+ code = TSDB_CODE_OUT_OF_MEMORY;
+ goto _exit;
+ }
+ memcpy(pNode->pTSRow, pRow, pRow->len);
for (int8_t iLevel = level - 1; iLevel >= 0; iLevel--) {
SMemSkipListNode *pn = pos[iLevel];
@@ -549,7 +556,7 @@ static int32_t tsdbInsertTableDataImpl(SMemTable *pMemTable, STbData *pTbData, i
key.ts = row.pTSRow->ts;
nRow++;
tbDataMovePosTo(pTbData, pos, &key, SL_MOVE_BACKWARD);
- code = tbDataDoPut(pMemTable, pTbData, pos, &row, 0);
+ code = tbDataDoPut(pMemTable, pTbData, pos, version, row.pTSRow, 0);
if (code) {
goto _err;
}
@@ -570,7 +577,7 @@ static int32_t tsdbInsertTableDataImpl(SMemTable *pMemTable, STbData *pTbData, i
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);
+ code = tbDataDoPut(pMemTable, pTbData, pos, version, row.pTSRow, 1);
if (code) {
goto _err;
}
diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c
index c157faecb1..af368d33e0 100644
--- a/source/dnode/vnode/src/tsdb/tsdbRead.c
+++ b/source/dnode/vnode/src/tsdb/tsdbRead.c
@@ -3219,7 +3219,7 @@ int32_t doMergeRowsInBuf(SIterInfo* pIter, uint64_t uid, int64_t ts, SArray* pDe
static int32_t doMergeRowsInFileBlockImpl(SBlockData* pBlockData, int32_t rowIndex, int64_t key, SRowMerger* pMerger,
SVersionRange* pVerRange, int32_t step) {
- while (pBlockData->aTSKEY[rowIndex] == key && rowIndex < pBlockData->nRow && rowIndex >= 0) {
+ while (rowIndex < pBlockData->nRow && rowIndex >= 0 && pBlockData->aTSKEY[rowIndex] == key) {
if (pBlockData->aVersion[rowIndex] > pVerRange->maxVer || pBlockData->aVersion[rowIndex] < pVerRange->minVer) {
rowIndex += step;
continue;
diff --git a/source/dnode/vnode/src/tsdb/tsdbUtil.c b/source/dnode/vnode/src/tsdb/tsdbUtil.c
index 755a551e20..0aa2c6ab83 100644
--- a/source/dnode/vnode/src/tsdb/tsdbUtil.c
+++ b/source/dnode/vnode/src/tsdb/tsdbUtil.c
@@ -565,15 +565,15 @@ void tsdbRowGetColVal(TSDBROW *pRow, STSchema *pTSchema, int32_t iCol, SColVal *
}
}
-int32_t tPutTSDBRow(uint8_t *p, TSDBROW *pRow) {
- int32_t n = 0;
+// int32_t tPutTSDBRow(uint8_t *p, TSDBROW *pRow) {
+// int32_t n = 0;
- n += tPutI64(p, pRow->version);
- if (p) memcpy(p + n, pRow->pTSRow, pRow->pTSRow->len);
- n += pRow->pTSRow->len;
+// n += tPutI64(p, pRow->version);
+// if (p) memcpy(p + n, pRow->pTSRow, pRow->pTSRow->len);
+// n += pRow->pTSRow->len;
- return n;
-}
+// return n;
+// }
int32_t tsdbRowCmprFn(const void *p1, const void *p2) {
return tsdbKeyCmprFn(&TSDBROW_KEY((TSDBROW *)p1), &TSDBROW_KEY((TSDBROW *)p2));
@@ -1084,7 +1084,7 @@ static int32_t tBlockDataAppendTPRow(SBlockData *pBlockData, STSRow *pRow, STSch
cv.flag = CV_FLAG_VALUE;
if (IS_VAR_DATA_TYPE(pTColumn->type)) {
- void *pData = (char*)pRow + *(int32_t *)(pRow->data + pTColumn->offset - sizeof(TSKEY));
+ void *pData = (char *)pRow + *(int32_t *)(pRow->data + pTColumn->offset - sizeof(TSKEY));
cv.value.nData = varDataLen(pData);
cv.value.pData = varDataVal(pData);
} else {
@@ -1106,7 +1106,7 @@ static int32_t tBlockDataAppendTPRow(SBlockData *pBlockData, STSRow *pRow, STSch
cv.flag = CV_FLAG_VALUE;
if (IS_VAR_DATA_TYPE(pTColumn->type)) {
- void *pData = (char*)pRow + *(int32_t *)(pRow->data + pTColumn->offset - sizeof(TSKEY));
+ void *pData = (char *)pRow + *(int32_t *)(pRow->data + pTColumn->offset - sizeof(TSKEY));
cv.value.nData = varDataLen(pData);
cv.value.pData = varDataVal(pData);
} else {
@@ -1151,7 +1151,7 @@ static int32_t tBlockDataAppendKVRow(SBlockData *pBlockData, STSRow *pRow, STSch
ASSERT(pTColumn->type == pColData->type);
SColVal cv = {.cid = pTColumn->colId, .type = pTColumn->type};
- TDRowValT vt = TD_VTYPE_NONE; // default is NONE
+ TDRowValT vt = TD_VTYPE_NONE; // default is NONE
SKvRowIdx *pKvIdx = NULL;
while (kvIter < nKvCols) {
diff --git a/source/dnode/vnode/src/vnd/vnodeOpen.c b/source/dnode/vnode/src/vnd/vnodeOpen.c
index 8c2036b97b..77d375bc45 100644
--- a/source/dnode/vnode/src/vnd/vnodeOpen.c
+++ b/source/dnode/vnode/src/vnd/vnodeOpen.c
@@ -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) {
diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c
index efedc12d80..15769ef4c9 100644
--- a/source/dnode/vnode/src/vnd/vnodeQuery.c
+++ b/source/dnode/vnode/src/vnd/vnodeQuery.c
@@ -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) {
@@ -386,8 +388,10 @@ int32_t vnodeGetBatchMeta(SVnode *pVnode, SRpcMsg *pMsg) {
offset += sizeof(p->msgLen);
*(int32_t *)((char *)pRsp + offset) = htonl(p->rspCode);
offset += sizeof(p->rspCode);
- memcpy((char *)pRsp + offset, p->msg, p->msgLen);
- offset += p->msgLen;
+ if (p->msg) {
+ memcpy((char *)pRsp + offset, p->msg, p->msgLen);
+ offset += p->msgLen;
+ }
taosMemoryFreeClear(p->msg);
}
diff --git a/source/libs/catalog/src/ctgAsync.c b/source/libs/catalog/src/ctgAsync.c
index ff3bd4d33c..2a032de003 100644
--- a/source/libs/catalog/src/ctgAsync.c
+++ b/source/libs/catalog/src/ctgAsync.c
@@ -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);
diff --git a/source/libs/catalog/src/ctgCache.c b/source/libs/catalog/src/ctgCache.c
index e99beca69a..fa38eeba0c 100644
--- a/source/libs/catalog/src/ctgCache.c
+++ b/source/libs/catalog/src/ctgCache.c
@@ -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)) {
diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c
index 1c2d7e1f66..64fec145ef 100644
--- a/source/libs/command/src/command.c
+++ b/source/libs/command/src/command.c
@@ -528,7 +528,7 @@ static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, SDbCfgInfo* p
appendTableOptions(buf2, &len, pDbCfg, pCfg);
}
- varDataLen(buf2) = len;
+ varDataLen(buf2) = (len > 65535) ? 65535 : len;
colDataAppend(pCol2, 0, buf2, false);
diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h
index e1db1f4729..b0da277cfb 100644
--- a/source/libs/executor/inc/executorimpl.h
+++ b/source/libs/executor/inc/executorimpl.h
@@ -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 {
@@ -1050,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
}
diff --git a/source/libs/executor/src/exchangeoperator.c b/source/libs/executor/src/exchangeoperator.c
index 049de727df..c57a1b38eb 100644
--- a/source/libs/executor/src/exchangeoperator.c
+++ b/source/libs/executor/src/exchangeoperator.c
@@ -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);
diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c
index 1aa9a3c613..428af19a6c 100644
--- a/source/libs/executor/src/executor.c
+++ b/source/libs/executor/src/executor.c
@@ -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;
}
diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c
index 7fd288cd57..baa5cb6479 100644
--- a/source/libs/executor/src/executorimpl.c
+++ b/source/libs/executor/src/executorimpl.c
@@ -2597,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);
@@ -3210,6 +3211,7 @@ void doDestroyTask(SExecTaskInfo* pTaskInfo) {
nodesDestroyNode((SNode*)pTaskInfo->pSubplan);
}
+ taosArrayDestroy(pTaskInfo->stopInfo.pStopInfo);
taosMemoryFreeClear(pTaskInfo->sql);
taosMemoryFreeClear(pTaskInfo->id.str);
taosMemoryFreeClear(pTaskInfo);
diff --git a/source/libs/executor/src/tfill.c b/source/libs/executor/src/tfill.c
index ddd948a6dd..c41376b2dc 100644
--- a/source/libs/executor/src/tfill.c
+++ b/source/libs/executor/src/tfill.c
@@ -513,6 +513,22 @@ void* taosDestroyFillInfo(SFillInfo* pFillInfo) {
// taosMemoryFreeClear(pFillInfo->pTags[i].tagVal);
// }
+ // free pFillCol
+ if (pFillInfo->pFillCol) {
+ for (int32_t i = 0; i < pFillInfo->numOfCols; i++) {
+ SFillColInfo* pCol = &pFillInfo->pFillCol[i];
+ if (!pCol->notFillCol) {
+ if (pCol->fillVal.nType == TSDB_DATA_TYPE_VARBINARY || pCol->fillVal.nType == TSDB_DATA_TYPE_VARCHAR ||
+ pCol->fillVal.nType == TSDB_DATA_TYPE_NCHAR || pCol->fillVal.nType == TSDB_DATA_TYPE_JSON) {
+ if (pCol->fillVal.pz) {
+ taosMemoryFree(pCol->fillVal.pz);
+ pCol->fillVal.pz = NULL;
+ }
+ }
+ }
+ }
+ }
+
taosMemoryFreeClear(pFillInfo->pTags);
taosMemoryFreeClear(pFillInfo->pFillCol);
taosMemoryFreeClear(pFillInfo);
diff --git a/source/libs/executor/src/tsimplehash.c b/source/libs/executor/src/tsimplehash.c
index a5168d24ba..9fbe94200c 100644
--- a/source/libs/executor/src/tsimplehash.c
+++ b/source/libs/executor/src/tsimplehash.c
@@ -189,7 +189,7 @@ int32_t tSimpleHashPut(SSHashObj *pHashObj, const void *key, size_t keyLen, cons
}
while (pNode) {
- if ((*(pHashObj->equalFp))(GET_SHASH_NODE_KEY(pNode, pNode->dataLen), key, keyLen) == 0) {
+ if ((keyLen == pNode->keyLen) && (*(pHashObj->equalFp))(GET_SHASH_NODE_KEY(pNode, pNode->dataLen), key, keyLen) == 0) {
break;
}
pNode = pNode->next;
@@ -213,10 +213,12 @@ int32_t tSimpleHashPut(SSHashObj *pHashObj, const void *key, size_t keyLen, cons
static FORCE_INLINE SHNode *doSearchInEntryList(SSHashObj *pHashObj, const void *key, size_t keyLen, int32_t index) {
SHNode *pNode = pHashObj->hashList[index];
while (pNode) {
- if ((*(pHashObj->equalFp))(GET_SHASH_NODE_KEY(pNode, pNode->dataLen), key, keyLen) == 0) {
+ const char* p = GET_SHASH_NODE_KEY(pNode, pNode->dataLen);
+ ASSERT(keyLen > 0);
+
+ if (pNode->keyLen == keyLen && ((*(pHashObj->equalFp))(p, key, keyLen) == 0)) {
break;
}
-
pNode = pNode->next;
}
diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c
index d3f03e8e9c..8249a8f6b1 100644
--- a/source/libs/function/src/builtins.c
+++ b/source/libs/function/src/builtins.c
@@ -475,7 +475,7 @@ static int32_t translateNowToday(SFunctionNode* pFunc, char* pErrBuf, int32_t le
// add database precision as param
uint8_t dbPrec = pFunc->node.resType.precision;
- int32_t code = addDbPrecisonParam(&pFunc->pParameterList, dbPrec);
+ int32_t code = addDbPrecisonParam(&pFunc->pParameterList, dbPrec);
if (code != TSDB_CODE_SUCCESS) {
return code;
}
@@ -1506,7 +1506,7 @@ static int32_t translateIrate(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
// add database precision as param
uint8_t dbPrec = pFunc->node.resType.precision;
- int32_t code = addDbPrecisonParam(&pFunc->pParameterList, dbPrec);
+ int32_t code = addDbPrecisonParam(&pFunc->pParameterList, dbPrec);
if (code != TSDB_CODE_SUCCESS) {
return code;
}
@@ -1519,7 +1519,7 @@ static int32_t translateInterp(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
int32_t numOfParams = LIST_LENGTH(pFunc->pParameterList);
uint8_t dbPrec = pFunc->node.resType.precision;
- //if (1 != numOfParams && 3 != numOfParams && 4 != numOfParams) {
+ // if (1 != numOfParams && 3 != numOfParams && 4 != numOfParams) {
if (1 != numOfParams) {
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
}
@@ -1835,7 +1835,7 @@ static int32_t translateCast(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
// add database precision as param
uint8_t dbPrec = pFunc->node.resType.precision;
- int32_t code = addDbPrecisonParam(&pFunc->pParameterList, dbPrec);
+ int32_t code = addDbPrecisonParam(&pFunc->pParameterList, dbPrec);
if (code != TSDB_CODE_SUCCESS) {
return code;
}
@@ -1894,7 +1894,7 @@ static int32_t translateToUnixtimestamp(SFunctionNode* pFunc, char* pErrBuf, int
// add database precision as param
uint8_t dbPrec = pFunc->node.resType.precision;
- int32_t code = addDbPrecisonParam(&pFunc->pParameterList, dbPrec);
+ int32_t code = addDbPrecisonParam(&pFunc->pParameterList, dbPrec);
if (code != TSDB_CODE_SUCCESS) {
return code;
}
@@ -2474,7 +2474,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
.name = "first",
.type = FUNCTION_TYPE_FIRST,
- .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SELECT_FUNC | FUNC_MGT_MULTI_RES_FUNC | FUNC_MGT_IMPLICIT_TS_FUNC,
+ .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SELECT_FUNC | FUNC_MGT_MULTI_RES_FUNC | FUNC_MGT_IMPLICIT_TS_FUNC | FUNC_MGT_KEEP_ORDER_FUNC,
.translateFunc = translateFirstLast,
.dynDataRequiredFunc = firstDynDataReq,
.getEnvFunc = getFirstLastFuncEnv,
@@ -2512,7 +2512,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
.name = "last",
.type = FUNCTION_TYPE_LAST,
- .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SELECT_FUNC | FUNC_MGT_MULTI_RES_FUNC | FUNC_MGT_IMPLICIT_TS_FUNC,
+ .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SELECT_FUNC | FUNC_MGT_MULTI_RES_FUNC | FUNC_MGT_IMPLICIT_TS_FUNC | FUNC_MGT_KEEP_ORDER_FUNC,
.translateFunc = translateFirstLast,
.dynDataRequiredFunc = lastDynDataReq,
.getEnvFunc = getFirstLastFuncEnv,
diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c
index 079e553b07..d02d30dc60 100644
--- a/source/libs/function/src/builtinsimpl.c
+++ b/source/libs/function/src/builtinsimpl.c
@@ -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);
diff --git a/source/libs/function/src/udfd.c b/source/libs/function/src/udfd.c
index 088aa62248..f5682b69bf 100644
--- a/source/libs/function/src/udfd.c
+++ b/source/libs/function/src/udfd.c
@@ -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;
diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c
index 39d17153d0..cc1bae6a3c 100644
--- a/source/libs/nodes/src/nodesUtilFuncs.c
+++ b/source/libs/nodes/src/nodesUtilFuncs.c
@@ -622,7 +622,7 @@ void nodesDestroyNode(SNode* pNode) {
}
switch (nodeType(pNode)) {
- case QUERY_NODE_COLUMN: // pProjectRef is weak reference, no need to release
+ case QUERY_NODE_COLUMN:
destroyExprNode((SExprNode*)pNode);
break;
case QUERY_NODE_VALUE: {
diff --git a/source/libs/parser/src/parInsertSql.c b/source/libs/parser/src/parInsertSql.c
index 7a38f48cb2..411adc680c 100644
--- a/source/libs/parser/src/parInsertSql.c
+++ b/source/libs/parser/src/parInsertSql.c
@@ -1364,6 +1364,7 @@ static int32_t parseCsvFile(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt,
break;
}
}
+ taosMemoryFree(pLine);
if (TSDB_CODE_SUCCESS == code && 0 == (*pNumOfRows) &&
(!TSDB_QUERY_HAS_TYPE(pStmt->insertType, TSDB_QUERY_TYPE_STMT_INSERT)) && !pStmt->fileProcessing) {
diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c
index 0e5cb14208..8de130bbb5 100644
--- a/source/libs/parser/src/parTranslater.c
+++ b/source/libs/parser/src/parTranslater.c
@@ -744,7 +744,8 @@ static bool isPrimaryKeyImpl(SNode* pExpr) {
return (PRIMARYKEY_TIMESTAMP_COL_ID == ((SColumnNode*)pExpr)->colId);
} else if (QUERY_NODE_FUNCTION == nodeType(pExpr)) {
SFunctionNode* pFunc = (SFunctionNode*)pExpr;
- if (FUNCTION_TYPE_SELECT_VALUE == pFunc->funcType) {
+ if (FUNCTION_TYPE_SELECT_VALUE == pFunc->funcType || FUNCTION_TYPE_FIRST == pFunc->funcType ||
+ FUNCTION_TYPE_LAST == pFunc->funcType) {
return isPrimaryKeyImpl(nodesListGetNode(pFunc->pParameterList, 0));
} else if (FUNCTION_TYPE_WSTART == pFunc->funcType || FUNCTION_TYPE_WEND == pFunc->funcType) {
return true;
@@ -787,7 +788,6 @@ static void setColumnInfoBySchema(const SRealTableNode* pTable, const SSchema* p
static void setColumnInfoByExpr(STempTableNode* pTable, SExprNode* pExpr, SColumnNode** pColRef) {
SColumnNode* pCol = *pColRef;
- // pCol->pProjectRef = (SNode*)pExpr;
if (NULL == pExpr->pAssociation) {
pExpr->pAssociation = taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES);
}
@@ -2932,8 +2932,8 @@ static int32_t checkFill(STranslateContext* pCxt, SFillNode* pFill, SValueNode*
return TSDB_CODE_SUCCESS;
}
- if (TSWINDOW_IS_EQUAL(pFill->timeRange, TSWINDOW_INITIALIZER) ||
- TSWINDOW_IS_EQUAL(pFill->timeRange, TSWINDOW_DESC_INITIALIZER)) {
+ if (!pCxt->createStream && (TSWINDOW_IS_EQUAL(pFill->timeRange, TSWINDOW_INITIALIZER) ||
+ TSWINDOW_IS_EQUAL(pFill->timeRange, TSWINDOW_DESC_INITIALIZER))) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_FILL_TIME_RANGE);
}
@@ -5268,9 +5268,7 @@ static int32_t checkTopicQuery(STranslateContext* pCxt, SSelectStmt* pSelect) {
}
static int32_t buildCreateTopicReq(STranslateContext* pCxt, SCreateTopicStmt* pStmt, SCMCreateTopicReq* pReq) {
- SName name;
- tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->topicName, strlen(pStmt->topicName));
- tNameGetFullDbName(&name, pReq->name);
+ snprintf(pReq->name, sizeof(pReq->name), "%d.%s", pCxt->pParseCxt->acctId, pStmt->topicName);
pReq->igExists = pStmt->ignoreExists;
pReq->withMeta = pStmt->withMeta;
@@ -5280,7 +5278,7 @@ static int32_t buildCreateTopicReq(STranslateContext* pCxt, SCreateTopicStmt* pS
}
int32_t code = TSDB_CODE_SUCCESS;
-
+ SName name;
if ('\0' != pStmt->subSTbName[0]) {
pReq->subType = TOPIC_SUB_TYPE__TABLE;
toName(pCxt->pParseCxt->acctId, pStmt->subDbName, pStmt->subSTbName, &name);
@@ -5548,6 +5546,10 @@ static int32_t checkStreamQuery(STranslateContext* pCxt, SSelectStmt* pSelect) {
crossTableWithUdaf(pSelect)) {
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY, "Unsupported stream query");
}
+ if (NULL != pSelect->pSubtable && TSDB_DATA_TYPE_VARCHAR != ((SExprNode*)pSelect->pSubtable)->resType.type) {
+ return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY,
+ "SUBTABLE expression must be of VARCHAR type");
+ }
return TSDB_CODE_SUCCESS;
}
@@ -6060,11 +6062,11 @@ static int32_t extractShowCreateTableResultSchema(int32_t* numOfCols, SSchema**
}
(*pSchema)[0].type = TSDB_DATA_TYPE_BINARY;
- (*pSchema)[0].bytes = TSDB_TABLE_NAME_LEN;
+ (*pSchema)[0].bytes = SHOW_CREATE_TB_RESULT_FIELD1_LEN;
strcpy((*pSchema)[0].name, "Table");
(*pSchema)[1].type = TSDB_DATA_TYPE_BINARY;
- (*pSchema)[1].bytes = TSDB_MAX_BINARY_LEN;
+ (*pSchema)[1].bytes = SHOW_CREATE_TB_RESULT_FIELD2_LEN;
strcpy((*pSchema)[1].name, "Create Table");
return TSDB_CODE_SUCCESS;
diff --git a/source/libs/qworker/inc/qwInt.h b/source/libs/qworker/inc/qwInt.h
index 36c6817595..a9eca64675 100644
--- a/source/libs/qworker/inc/qwInt.h
+++ b/source/libs/qworker/inc/qwInt.h
@@ -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; \
diff --git a/source/libs/qworker/src/qwDbg.c b/source/libs/qworker/src/qwDbg.c
index 1871316260..4c4a41df82 100644
--- a/source/libs/qworker/src/qwDbg.c
+++ b/source/libs/qworker/src/qwDbg.c
@@ -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) {
diff --git a/source/libs/qworker/src/qwUtil.c b/source/libs/qworker/src/qwUtil.c
index e9ded9b269..e13791ae89 100644
--- a/source/libs/qworker/src/qwUtil.c
+++ b/source/libs/qworker/src/qwUtil.c
@@ -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);
}
diff --git a/source/libs/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c
index a7cd3db824..e45beb7e13 100644
--- a/source/libs/qworker/src/qworker.c
+++ b/source/libs/qworker/src/qworker.c
@@ -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;
diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c
index df9a818fee..be085e6cbd 100644
--- a/source/libs/scalar/src/filter.c
+++ b/source/libs/scalar/src/filter.c
@@ -512,15 +512,17 @@ int32_t filterReuseRangeCtx(SFilterRangeCtx *ctx, int32_t type, int32_t options)
}
int32_t filterConvertRange(SFilterRangeCtx *cur, SFilterRange *ra, bool *notNull) {
+ int64_t tmp = 0;
+
if (!FILTER_GET_FLAG(ra->sflag, RANGE_FLG_NULL)) {
- int32_t sr = cur->pCompareFunc(&ra->s, getDataMin(cur->type));
+ int32_t sr = cur->pCompareFunc(&ra->s, getDataMin(cur->type, &tmp));
if (sr == 0) {
FILTER_SET_FLAG(ra->sflag, RANGE_FLG_NULL);
}
}
if (!FILTER_GET_FLAG(ra->eflag, RANGE_FLG_NULL)) {
- int32_t er = cur->pCompareFunc(&ra->e, getDataMax(cur->type));
+ int32_t er = cur->pCompareFunc(&ra->e, getDataMax(cur->type, &tmp));
if (er == 0) {
FILTER_SET_FLAG(ra->eflag, RANGE_FLG_NULL);
}
@@ -696,14 +698,15 @@ int32_t filterAddRangeImpl(void *h, SFilterRange *ra, int32_t optr) {
int32_t filterAddRange(void *h, SFilterRange *ra, int32_t optr) {
SFilterRangeCtx *ctx = (SFilterRangeCtx *)h;
-
+ int64_t tmp = 0;
+
if (FILTER_GET_FLAG(ra->sflag, RANGE_FLG_NULL)) {
- SIMPLE_COPY_VALUES(&ra->s, getDataMin(ctx->type));
+ SIMPLE_COPY_VALUES(&ra->s, getDataMin(ctx->type, &tmp));
// FILTER_CLR_FLAG(ra->sflag, RA_NULL);
}
if (FILTER_GET_FLAG(ra->eflag, RANGE_FLG_NULL)) {
- SIMPLE_COPY_VALUES(&ra->e, getDataMax(ctx->type));
+ SIMPLE_COPY_VALUES(&ra->e, getDataMax(ctx->type, &tmp));
// FILTER_CLR_FLAG(ra->eflag, RA_NULL);
}
diff --git a/source/libs/scheduler/src/schRemote.c b/source/libs/scheduler/src/schRemote.c
index 22fb66d92f..a6a2a6c301 100644
--- a/source/libs/scheduler/src/schRemote.c
+++ b/source/libs/scheduler/src/schRemote.c
@@ -286,9 +286,11 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa
if (pJob->execRes.res) {
SSubmitRsp *sum = pJob->execRes.res;
sum->affectedRows += rsp->affectedRows;
- sum->nBlocks += rsp->nBlocks;
- sum->pBlocks = taosMemoryRealloc(sum->pBlocks, sum->nBlocks * sizeof(*sum->pBlocks));
- memcpy(sum->pBlocks + sum->nBlocks - rsp->nBlocks, rsp->pBlocks, rsp->nBlocks * sizeof(*sum->pBlocks));
+ sum->nBlocks += rsp->nBlocks;
+ if (rsp->nBlocks > 0 && rsp->pBlocks) {
+ sum->pBlocks = taosMemoryRealloc(sum->pBlocks, sum->nBlocks * sizeof(*sum->pBlocks));
+ memcpy(sum->pBlocks + sum->nBlocks - rsp->nBlocks, rsp->pBlocks, rsp->nBlocks * sizeof(*sum->pBlocks));
+ }
taosMemoryFree(rsp->pBlocks);
taosMemoryFree(rsp);
} else {
diff --git a/source/libs/stream/src/streamState.c b/source/libs/stream/src/streamState.c
index 88c39c1157..aefe30116b 100644
--- a/source/libs/stream/src/streamState.c
+++ b/source/libs/stream/src/streamState.c
@@ -114,12 +114,12 @@ SStreamState* streamStateOpen(char* path, SStreamTask* pTask, bool specPath, int
return NULL;
}
- char statePath[300];
+ char statePath[1024];
if (!specPath) {
sprintf(statePath, "%s/%d", path, pTask->taskId);
} else {
- memset(statePath, 0, 300);
- tstrncpy(statePath, path, 300);
+ memset(statePath, 0, 1024);
+ tstrncpy(statePath, path, 1024);
}
if (tdbOpen(statePath, szPage, pages, &pState->db, 0) < 0) {
goto _err;
diff --git a/source/libs/sync/inc/syncAppendEntries.h b/source/libs/sync/inc/syncAppendEntries.h
index a87a28baf5..7791160afa 100644
--- a/source/libs/sync/inc/syncAppendEntries.h
+++ b/source/libs/sync/inc/syncAppendEntries.h
@@ -88,7 +88,7 @@ extern "C" {
// /\ UNCHANGED <>
//
-int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg);
+int32_t syncNodeOnAppendEntries(SSyncNode* ths, const SRpcMsg* pMsg);
#ifdef __cplusplus
}
diff --git a/source/libs/sync/inc/syncAppendEntriesReply.h b/source/libs/sync/inc/syncAppendEntriesReply.h
index 09750864d5..199a895961 100644
--- a/source/libs/sync/inc/syncAppendEntriesReply.h
+++ b/source/libs/sync/inc/syncAppendEntriesReply.h
@@ -35,7 +35,7 @@ extern "C" {
// /\ Discard(m)
// /\ UNCHANGED <>
//
-int32_t syncNodeOnAppendEntriesReply(SSyncNode* ths, SyncAppendEntriesReply* pMsg);
+int32_t syncNodeOnAppendEntriesReply(SSyncNode* ths, const SRpcMsg* pMsg);
#ifdef __cplusplus
}
diff --git a/source/libs/sync/inc/syncInt.h b/source/libs/sync/inc/syncInt.h
index 369aee8116..e81f63d871 100644
--- a/source/libs/sync/inc/syncInt.h
+++ b/source/libs/sync/inc/syncInt.h
@@ -22,49 +22,9 @@ extern "C" {
#include "sync.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 SyncRequestVote SyncRequestVote;
@@ -91,8 +51,6 @@ typedef struct SyncHeartbeatReply SyncHeartbeatReply;
typedef struct SyncHeartbeat SyncHeartbeat;
typedef struct SyncPreSnapshot SyncPreSnapshot;
-extern bool gRaftDetailLog;
-
typedef struct SRaftId {
SyncNodeId addr;
SyncGroupId vgId;
@@ -239,20 +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);
+// 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);
@@ -260,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 --------------
@@ -271,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);
@@ -282,8 +242,9 @@ void syncNodeVoteForTerm(SSyncNode* pSyncNode, SyncTerm term, SRaftId* pRaftId);
void syncNodeVoteForSelf(SSyncNode* pSyncNode);
// snapshot --------------
-bool syncNodeHasSnapshot(SSyncNode* pSyncNode);
-void syncNodeMaybeUpdateCommitBySnapshot(SSyncNode* pSyncNode);
+bool syncNodeHasSnapshot(SSyncNode* pSyncNode);
+void syncNodeMaybeUpdateCommitBySnapshot(SSyncNode* pSyncNode);
+int32_t syncNodeStartSnapshot(SSyncNode* pSyncNode, SRaftId* pDestId);
SyncIndex syncNodeGetLastIndex(const SSyncNode* pSyncNode);
SyncTerm syncNodeGetLastTerm(SSyncNode* pSyncNode);
@@ -293,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);
@@ -309,52 +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 syncLogSendAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMsg, const char* s);
-void syncLogRecvAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* 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
diff --git a/source/libs/sync/inc/syncMessage.h b/source/libs/sync/inc/syncMessage.h
index 25bf097faf..92e7b555a4 100644
--- a/source/libs/sync/inc/syncMessage.h
+++ b/source/libs/sync/inc/syncMessage.h
@@ -97,24 +97,6 @@ typedef struct SyncAppendEntries {
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 SyncAppendEntriesReply {
uint32_t bytes;
int32_t vgId;
@@ -130,25 +112,6 @@ typedef struct SyncAppendEntriesReply {
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;
@@ -161,28 +124,8 @@ typedef struct SyncHeartbeat {
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;
@@ -196,25 +139,6 @@ typedef struct SyncHeartbeatReply {
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;
@@ -224,28 +148,8 @@ typedef struct SyncPreSnapshot {
// 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;
@@ -256,28 +160,8 @@ typedef struct SyncPreSnapshotReply {
// 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;
@@ -288,27 +172,6 @@ typedef struct SyncApplyMsg {
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;
@@ -328,25 +191,6 @@ typedef struct SyncSnapshotSend {
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;
@@ -363,25 +207,6 @@ typedef struct SyncSnapshotRsp {
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;
@@ -394,25 +219,11 @@ typedef struct SyncLeaderTransfer {
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;
@@ -423,61 +234,27 @@ typedef struct SyncLocalCmd {
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 syncNodeOnRequestVote(SSyncNode* pNode, const SRpcMsg* pMsg);
-int32_t syncNodeOnRequestVoteReply(SSyncNode* ths, const SRpcMsg* 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);
-
-// -----------------------------------------
-
-// option ----------------------------------
-bool syncNodeSnapshotEnable(SSyncNode* pSyncNode);
-ESyncStrategy syncNodeStrategy(SSyncNode* pSyncNode);
-
-const char* syncTimerTypeStr(enum ESyncTimeoutType timerType);
-
-int32_t syncTimeoutBuild(SRpcMsg* pTimeoutRpcMsg, ESyncTimeoutType timeoutType, uint64_t logicClock, int32_t timerMS,
- SSyncNode* pNode);
-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);
+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
}
diff --git a/source/libs/sync/inc/syncReplication.h b/source/libs/sync/inc/syncReplication.h
index e08430327b..7da610a9ed 100644
--- a/source/libs/sync/inc/syncReplication.h
+++ b/source/libs/sync/inc/syncReplication.h
@@ -48,13 +48,10 @@ extern "C" {
// /\ UNCHANGED <>
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);
-
-int32_t syncNodeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* pDestId, const SyncAppendEntries* pMsg);
-int32_t syncNodeMaybeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* pDestId, const SyncAppendEntries* pMsg);
+int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId, bool snapshot);
#ifdef __cplusplus
}
diff --git a/source/libs/sync/inc/syncSnapshot.h b/source/libs/sync/inc/syncSnapshot.h
index 963fedce31..7b8e768391 100644
--- a/source/libs/sync/inc/syncSnapshot.h
+++ b/source/libs/sync/inc/syncSnapshot.h
@@ -43,6 +43,7 @@ typedef struct SSyncSnapshotSender {
int64_t sendingMS;
SyncTerm term;
int64_t startTime;
+ int64_t endTime;
bool finish;
// init when create
@@ -59,14 +60,17 @@ int32_t snapshotSend(SSyncSnapshotSender *pSender);
int32_t snapshotReSend(SSyncSnapshotSender *pSender);
typedef struct SSyncSnapshotReceiver {
- bool start;
- int32_t ack;
+ // update when pre snapshot
+ bool start;
+ int32_t ack;
+ SyncTerm term;
+ SRaftId fromId;
+ int64_t startTime;
+
+ // update when begin
void *pWriter;
- SyncTerm term;
SSnapshotParam snapshotParam;
SSnapshot snapshot;
- SRaftId fromId;
- int64_t startTime;
// init when create
SSyncNode *pSyncNode;
@@ -80,9 +84,10 @@ 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 syncNodeStartSnapshot(SSyncNode *pSyncNode, SRaftId *pDestId);
+int32_t syncNodeOnSnapshot(SSyncNode *ths, const SRpcMsg *pMsg);
+int32_t syncNodeOnSnapshotReply(SSyncNode *ths, const SRpcMsg *pMsg);
+
+// start
#ifdef __cplusplus
}
diff --git a/source/libs/sync/inc/syncTimeout.h b/source/libs/sync/inc/syncTimeout.h
index 85c8e8f58f..66f6e6ee18 100644
--- a/source/libs/sync/inc/syncTimeout.h
+++ b/source/libs/sync/inc/syncTimeout.h
@@ -34,7 +34,7 @@ extern "C" {
// /\ voterLog' = [voterLog EXCEPT ![i] = [j \in {} |-> <<>>]]
// /\ UNCHANGED <>
//
-int32_t syncNodeOnTimer(SSyncNode* ths, const SRpcMsg* pMsg);
+int32_t syncNodeOnTimeout(SSyncNode* ths, const SRpcMsg* pMsg);
#ifdef __cplusplus
}
diff --git a/source/libs/sync/inc/syncUtil.h b/source/libs/sync/inc/syncUtil.h
index 076101ef43..b7ee320aa5 100644
--- a/source/libs/sync/inc/syncUtil.h
+++ b/source/libs/sync/inc/syncUtil.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
diff --git a/source/libs/sync/src/syncAppendEntries.c b/source/libs/sync/src/syncAppendEntries.c
index c9c1baa4bc..4551702b34 100644
--- a/source/libs/sync/src/syncAppendEntries.c
+++ b/source/libs/sync/src/syncAppendEntries.c
@@ -18,6 +18,7 @@
#include "syncMessage.h"
#include "syncRaftLog.h"
#include "syncRaftStore.h"
+#include "syncUtil.h"
// TLA+ Spec
// HandleAppendEntriesRequest(i, j, m) ==
@@ -123,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");
@@ -131,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;
@@ -163,7 +173,11 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) {
if (pMsg->prevLogIndex >= startIndex) {
SyncTerm myPreLogTerm = syncNodeGetPreTerm(ths, pMsg->prevLogIndex + 1);
- ASSERT(myPreLogTerm != SYNC_TERM_INVALID);
+ // ASSERT(myPreLogTerm != SYNC_TERM_INVALID);
+ if (myPreLogTerm == SYNC_TERM_INVALID) {
+ syncLogRecvAppendEntries(ths, pMsg, "reject, pre-term invalid");
+ goto _SEND_RESPONSE;
+ }
if (myPreLogTerm != pMsg->prevLogTerm) {
syncLogRecvAppendEntries(ths, pMsg, "reject, pre-term not match");
@@ -273,7 +287,7 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) {
goto _SEND_RESPONSE;
_IGNORE:
- syncAppendEntriesReplyDestroy(pReply);
+ rpcFreeCont(rpcRsp.pCont);
return 0;
_SEND_RESPONSE:
@@ -281,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;
}
\ No newline at end of file
diff --git a/source/libs/sync/src/syncAppendEntriesReply.c b/source/libs/sync/src/syncAppendEntriesReply.c
index 53d6b5d92f..875204c0a9 100644
--- a/source/libs/sync/src/syncAppendEntriesReply.c
+++ b/source/libs/sync/src/syncAppendEntriesReply.c
@@ -15,12 +15,13 @@
#define _DEFAULT_SOURCE
#include "syncAppendEntriesReply.h"
-#include "syncMessage.h"
#include "syncCommit.h"
#include "syncIndexMgr.h"
+#include "syncMessage.h"
#include "syncRaftStore.h"
#include "syncReplication.h"
#include "syncSnapshot.h"
+#include "syncUtil.h"
// TLA+ Spec
// HandleAppendEntriesResponse(i, j, m) ==
@@ -36,45 +37,9 @@
// /\ UNCHANGED <>
//
-// only start once
-static void syncNodeStartSnapshotOnce(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex, SyncTerm lastApplyTerm,
- SyncAppendEntriesReply* pMsg) {
- if (beginIndex > endIndex) {
- sNError(ths, "snapshot param error, start:%" PRId64 ", end:%" PRId64, beginIndex, endIndex);
- return;
- }
-
- // get sender
- SSyncSnapshotSender* pSender = syncNodeGetSnapshotSender(ths, &(pMsg->srcId));
- ASSERT(pSender != NULL);
-
- if (snapshotSenderIsStart(pSender)) {
- sSError(pSender, "snapshot sender already start");
- return;
- }
-
- SSnapshot snapshot = {
- .data = NULL, .lastApplyIndex = endIndex, .lastApplyTerm = lastApplyTerm, .lastConfigIndex = SYNC_INDEX_INVALID};
- void* pReader = NULL;
- SSnapshotParam readerParam = {.start = beginIndex, .end = endIndex};
- int32_t code = ths->pFsm->FpSnapshotStartRead(ths->pFsm, &readerParam, &pReader);
- ASSERT(code == 0);
-
-#if 0
- if (pMsg->privateTerm < pSender->privateTerm) {
- ASSERT(pReader != NULL);
- snapshotSenderStart(pSender, readerParam, snapshot, pReader);
-
- } else {
- if (pReader != NULL) {
- ths->pFsm->FpSnapshotStopRead(ths->pFsm, pReader);
- }
- }
-#endif
-}
-
-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))) {
@@ -118,7 +83,7 @@ int32_t syncNodeOnAppendEntriesReply(SSyncNode* ths, SyncAppendEntriesReply* pMs
ASSERT(pState != NULL);
if (pMsg->lastSendIndex == pState->lastSendIndex) {
- syncNodeReplicateOne(ths, &(pMsg->srcId));
+ syncNodeReplicateOne(ths, &(pMsg->srcId), true);
}
}
diff --git a/source/libs/sync/src/syncElection.c b/source/libs/sync/src/syncElection.c
index 9f0839fc02..5c41e43fd4 100644
--- a/source/libs/sync/src/syncElection.c
+++ b/source/libs/sync/src/syncElection.c
@@ -33,14 +33,6 @@
// mdest |-> j])
// /\ UNCHANGED <>
-static 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);
-}
-
static int32_t syncNodeRequestVotePeers(SSyncNode* pNode) {
if (pNode->state != TAOS_SYNC_STATE_CANDIDATE) {
sNTrace(pNode, "not candidate, stop elect");
diff --git a/source/libs/sync/src/syncEnv.c b/source/libs/sync/src/syncEnv.c
index a0e0a5a2c2..2abc8c0b7f 100644
--- a/source/libs/sync/src/syncEnv.c
+++ b/source/libs/sync/src/syncEnv.c
@@ -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; }
diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c
index 636bf9410e..e802f60f30 100644
--- a/source/libs/sync/src/syncMain.c
+++ b/source/libs/sync/src/syncMain.c
@@ -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,45 +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) {
- code = syncNodeOnTimer(pSyncNode, pMsg);
- } else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) {
- code = syncNodeOnClientRequest(pSyncNode, pMsg, NULL);
- } else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE) {
- syncNodeOnRequestVote(pSyncNode, pMsg);
- } else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) {
- code = syncNodeOnRequestVoteReply(pSyncNode, pMsg);
- } 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);
@@ -374,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;
@@ -423,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) {
@@ -605,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);
@@ -1050,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 --------------
@@ -1196,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;
}
@@ -1637,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) {
@@ -1798,10 +1803,10 @@ static void syncNodeEqPingTimer(void* param, void* tmrId) {
SSyncNode* pNode = param;
if (atomic_load_64(&pNode->pingTimerLogicClockUser) <= atomic_load_64(&pNode->pingTimerLogicClock)) {
SRpcMsg rpcMsg = {0};
- int32_t code = syncTimeoutBuild(&rpcMsg, SYNC_TIMEOUT_PING, atomic_load_64(&pNode->pingTimerLogicClock),
+ 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");
+ sError("failed to build ping msg");
rpcFreeCont(rpcMsg.pCont);
return;
}
@@ -1809,7 +1814,7 @@ static void syncNodeEqPingTimer(void* param, void* tmrId) {
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());
+ sError("failed to sync enqueue ping msg since %s", terrstr());
rpcFreeCont(rpcMsg.pCont);
return;
}
@@ -1827,11 +1832,14 @@ static void syncNodeEqElectTimer(void* param, void* tmrId) {
SElectTimer* pElectTimer = param;
SSyncNode* pNode = pElectTimer->pSyncNode;
+ if (pNode == NULL) return;
+ if (pNode->syncEqMsg == NULL) return;
+
SRpcMsg rpcMsg = {0};
- int32_t code = syncTimeoutBuild(&rpcMsg, SYNC_TIMEOUT_ELECTION, pElectTimer->logicClock, pNode->electTimerMS, pNode);
+ int32_t code = syncBuildTimeout(&rpcMsg, SYNC_TIMEOUT_ELECTION, pElectTimer->logicClock, pNode->electTimerMS, pNode);
if (code != 0) {
- sNError(pNode, "failed to build elect msg");
+ sError("failed to build elect msg");
taosMemoryFree(pElectTimer);
return;
}
@@ -1841,7 +1849,7 @@ static void syncNodeEqElectTimer(void* param, void* tmrId) {
code = pNode->syncEqMsg(pNode->msgcb, &rpcMsg);
if (code != 0) {
- sNError(pNode, "failed to sync enqueue elect msg since %s", terrstr());
+ sError("failed to sync enqueue elect msg since %s", terrstr());
rpcFreeCont(rpcMsg.pCont);
taosMemoryFree(pElectTimer);
return;
@@ -1867,18 +1875,18 @@ static void syncNodeEqHeartbeatTimer(void* param, void* tmrId) {
if (pNode->replicaNum > 1) {
if (atomic_load_64(&pNode->heartbeatTimerLogicClockUser) <= atomic_load_64(&pNode->heartbeatTimerLogicClock)) {
SRpcMsg rpcMsg = {0};
- int32_t code = syncTimeoutBuild(&rpcMsg, SYNC_TIMEOUT_HEARTBEAT, atomic_load_64(&pNode->heartbeatTimerLogicClock),
+ int32_t code = syncBuildTimeout(&rpcMsg, SYNC_TIMEOUT_HEARTBEAT, atomic_load_64(&pNode->heartbeatTimerLogicClock),
pNode->heartbeatTimerMS, pNode);
if (code != 0) {
- sNError(pNode, "failed to build heartbeat msg");
+ sError("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());
+ sError("failed to enqueue heartbeat msg since %s", terrstr());
rpcFreeCont(rpcMsg.pCont);
return;
}
@@ -1917,7 +1925,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;
@@ -1925,28 +1936,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,
@@ -1974,13 +1965,13 @@ 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");
code = (*pNode->syncEqMsg)(pNode->msgcb, &rpcMsg);
if (code != 0) {
- sNError(pNode, "failed to propose noop msg while enqueue since %s", terrstr());
+ sError("failed to propose noop msg while enqueue since %s", terrstr());
}
return code;
@@ -2014,7 +2005,7 @@ static int32_t syncNodeAppendNoop(SSyncNode* ths) {
if (ths->state == TAOS_SYNC_STATE_LEADER) {
int32_t code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pEntry);
if (code != 0) {
- sNError(ths, "append noop error");
+ sError("append noop error");
return -1;
}
}
@@ -2028,31 +2019,32 @@ static int32_t syncNodeAppendNoop(SSyncNode* ths) {
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) {
@@ -2067,13 +2059,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) {
@@ -2083,8 +2075,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);
}
/*
@@ -2096,21 +2086,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) {
@@ -2120,7 +2109,7 @@ int32_t syncNodeOnLocalCmd(SSyncNode* ths, SyncLocalCmd* pMsg) {
syncNodeFollowerCommit(ths, pMsg->fcIndex);
} else {
- sNError(ths, "error local cmd");
+ sError("error local cmd");
}
return 0;
@@ -2239,6 +2228,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");
@@ -2267,7 +2257,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));
@@ -2300,10 +2290,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;
@@ -2515,147 +2506,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 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 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) {}
-
-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) {}
diff --git a/source/libs/sync/src/syncMessage.c b/source/libs/sync/src/syncMessage.c
index 7e1883d530..ce98419980 100644
--- a/source/libs/sync/src/syncMessage.c
+++ b/source/libs/sync/src/syncMessage.c
@@ -15,23 +15,20 @@
#define _DEFAULT_SOURCE
#include "syncMessage.h"
-#include "syncRaftCfg.h"
#include "syncRaftEntry.h"
-#include "syncUtil.h"
-#include "tcoding.h"
-int32_t syncTimeoutBuild(SRpcMsg* pTimeoutRpcMsg, ESyncTimeoutType timeoutType, uint64_t logicClock, int32_t timerMS,
+int32_t syncBuildTimeout(SRpcMsg* pMsg, ESyncTimeoutType timeoutType, uint64_t logicClock, int32_t timerMS,
SSyncNode* pNode) {
int32_t bytes = sizeof(SyncTimeout);
- pTimeoutRpcMsg->pCont = rpcMallocCont(bytes);
- pTimeoutRpcMsg->msgType = TDMT_SYNC_TIMEOUT;
- pTimeoutRpcMsg->contLen = bytes;
- if (pTimeoutRpcMsg->pCont == NULL) {
+ pMsg->pCont = rpcMallocCont(bytes);
+ pMsg->msgType = TDMT_SYNC_TIMEOUT;
+ pMsg->contLen = bytes;
+ if (pMsg->pCont == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
- SyncTimeout* pTimeout = pTimeoutRpcMsg->pCont;
+ SyncTimeout* pTimeout = pMsg->pCont;
pTimeout->bytes = bytes;
pTimeout->msgType = TDMT_SYNC_TIMEOUT;
pTimeout->vgId = pNode->vgId;
@@ -42,42 +39,40 @@ int32_t syncTimeoutBuild(SRpcMsg* pTimeoutRpcMsg, ESyncTimeoutType timeoutType,
return 0;
}
-int32_t syncClientRequestBuildFromRpcMsg(SRpcMsg* pClientRequestRpcMsg, const SRpcMsg* pOriginalRpcMsg, uint64_t seqNum,
- bool isWeak, int32_t vgId) {
- int32_t bytes = sizeof(SyncClientRequest) + pOriginalRpcMsg->contLen;
- pClientRequestRpcMsg->pCont = rpcMallocCont(bytes);
- pClientRequestRpcMsg->msgType = TDMT_SYNC_CLIENT_REQUEST;
- pClientRequestRpcMsg->contLen = bytes;
- if (pClientRequestRpcMsg->pCont == NULL) {
+int32_t syncBuildClientRequest(SRpcMsg* pMsg, const SRpcMsg* pOriginal, uint64_t seqNum, bool isWeak, int32_t vgId) {
+ int32_t bytes = sizeof(SyncClientRequest) + pOriginal->contLen;
+ pMsg->pCont = rpcMallocCont(bytes);
+ pMsg->msgType = TDMT_SYNC_CLIENT_REQUEST;
+ pMsg->contLen = bytes;
+ if (pMsg->pCont == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
- SyncClientRequest* pClientRequest = pClientRequestRpcMsg->pCont;
+ SyncClientRequest* pClientRequest = pMsg->pCont;
pClientRequest->bytes = bytes;
pClientRequest->vgId = vgId;
pClientRequest->msgType = TDMT_SYNC_CLIENT_REQUEST;
- pClientRequest->originalRpcType = pOriginalRpcMsg->msgType;
+ pClientRequest->originalRpcType = pOriginal->msgType;
pClientRequest->seqNum = seqNum;
pClientRequest->isWeak = isWeak;
- pClientRequest->dataLen = pOriginalRpcMsg->contLen;
- memcpy(pClientRequest->data, (char*)pOriginalRpcMsg->pCont, pOriginalRpcMsg->contLen);
-
+ pClientRequest->dataLen = pOriginal->contLen;
+ memcpy(pClientRequest->data, (char*)pOriginal->pCont, pOriginal->contLen);
return 0;
}
-int32_t syncClientRequestBuildFromNoopEntry(SRpcMsg* pClientRequestRpcMsg, const SSyncRaftEntry* pEntry, int32_t vgId) {
+int32_t syncBuildClientRequestFromNoopEntry(SRpcMsg* pMsg, const SSyncRaftEntry* pEntry, int32_t vgId) {
int32_t bytes = sizeof(SyncClientRequest) + pEntry->bytes;
- pClientRequestRpcMsg->pCont = rpcMallocCont(bytes);
- pClientRequestRpcMsg->msgType = TDMT_SYNC_CLIENT_REQUEST;
- pClientRequestRpcMsg->contLen = bytes;
- if (pClientRequestRpcMsg->pCont == NULL) {
+ pMsg->pCont = rpcMallocCont(bytes);
+ pMsg->msgType = TDMT_SYNC_CLIENT_REQUEST;
+ pMsg->contLen = bytes;
+ if (pMsg->pCont == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
- SyncClientRequest* pClientRequest = pClientRequestRpcMsg->pCont;
+ SyncClientRequest* pClientRequest = pMsg->pCont;
pClientRequest->bytes = bytes;
pClientRequest->vgId = vgId;
pClientRequest->msgType = TDMT_SYNC_CLIENT_REQUEST;
@@ -94,7 +89,7 @@ int32_t syncBuildRequestVote(SRpcMsg* pMsg, int32_t vgId) {
pMsg->msgType = TDMT_SYNC_REQUEST_VOTE;
pMsg->contLen = bytes;
if (pMsg->pCont == NULL) {
- terrno = TDMT_SYNC_REQUEST_VOTE;
+ terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
@@ -111,7 +106,7 @@ int32_t syncBuildRequestVoteReply(SRpcMsg* pMsg, int32_t vgId) {
pMsg->msgType = TDMT_SYNC_REQUEST_VOTE_REPLY;
pMsg->contLen = bytes;
if (pMsg->pCont == NULL) {
- terrno = TDMT_SYNC_REQUEST_VOTE;
+ terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
@@ -122,1609 +117,200 @@ int32_t syncBuildRequestVoteReply(SRpcMsg* pMsg, int32_t vgId) {
return 0;
}
-// ---- message process SyncAppendEntries----
-SyncAppendEntries* syncAppendEntriesBuild(uint32_t dataLen, int32_t vgId) {
- uint32_t bytes = sizeof(SyncAppendEntries) + dataLen;
- SyncAppendEntries* pMsg = taosMemoryMalloc(bytes);
- memset(pMsg, 0, bytes);
- pMsg->bytes = bytes;
- pMsg->vgId = vgId;
+int32_t syncBuildAppendEntries(SRpcMsg* pMsg, int32_t dataLen, int32_t vgId) {
+ int32_t bytes = sizeof(SyncAppendEntries) + dataLen;
+ pMsg->pCont = rpcMallocCont(bytes);
pMsg->msgType = TDMT_SYNC_APPEND_ENTRIES;
- pMsg->dataLen = dataLen;
- return pMsg;
-}
-
-void syncAppendEntriesDestroy(SyncAppendEntries* pMsg) {
- if (pMsg != NULL) {
- taosMemoryFree(pMsg);
- }
-}
-
-void syncAppendEntriesSerialize(const SyncAppendEntries* pMsg, char* buf, uint32_t bufLen) {
- ASSERT(pMsg->bytes <= bufLen);
- memcpy(buf, pMsg, pMsg->bytes);
-}
-
-void syncAppendEntriesDeserialize(const char* buf, uint32_t len, SyncAppendEntries* pMsg) {
- memcpy(pMsg, buf, len);
- ASSERT(len == pMsg->bytes);
- ASSERT(pMsg->bytes == sizeof(SyncAppendEntries) + pMsg->dataLen);
-}
-
-char* syncAppendEntriesSerialize2(const SyncAppendEntries* pMsg, uint32_t* len) {
- char* buf = taosMemoryMalloc(pMsg->bytes);
- ASSERT(buf != NULL);
- syncAppendEntriesSerialize(pMsg, buf, pMsg->bytes);
- if (len != NULL) {
- *len = pMsg->bytes;
- }
- return buf;
-}
-
-SyncAppendEntries* syncAppendEntriesDeserialize2(const char* buf, uint32_t len) {
- uint32_t bytes = *((uint32_t*)buf);
- SyncAppendEntries* pMsg = taosMemoryMalloc(bytes);
- ASSERT(pMsg != NULL);
- syncAppendEntriesDeserialize(buf, len, pMsg);
- ASSERT(len == pMsg->bytes);
- return pMsg;
-}
-
-void syncAppendEntries2RpcMsg(const SyncAppendEntries* pMsg, SRpcMsg* pRpcMsg) {
- memset(pRpcMsg, 0, sizeof(*pRpcMsg));
- pRpcMsg->msgType = pMsg->msgType;
- pRpcMsg->contLen = pMsg->bytes;
- pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
- syncAppendEntriesSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen);
-}
-
-void syncAppendEntriesFromRpcMsg(const SRpcMsg* pRpcMsg, SyncAppendEntries* pMsg) {
- syncAppendEntriesDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
-}
-
-SyncAppendEntries* syncAppendEntriesFromRpcMsg2(const SRpcMsg* pRpcMsg) {
- SyncAppendEntries* pMsg = syncAppendEntriesDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
- ASSERT(pMsg != NULL);
- return pMsg;
-}
-
-cJSON* syncAppendEntries2Json(const SyncAppendEntries* pMsg) {
- char u64buf[128] = {0};
- cJSON* pRoot = cJSON_CreateObject();
-
- if (pMsg != NULL) {
- cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
- cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
- cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
-
- cJSON* pSrcId = cJSON_CreateObject();
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr);
- cJSON_AddStringToObject(pSrcId, "addr", u64buf);
- {
- uint64_t u64 = pMsg->srcId.addr;
- cJSON* pTmp = pSrcId;
- char host[128] = {0};
- uint16_t port;
- syncUtilU642Addr(u64, host, sizeof(host), &port);
- cJSON_AddStringToObject(pTmp, "addr_host", host);
- cJSON_AddNumberToObject(pTmp, "addr_port", port);
- }
- cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
- cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
-
- cJSON* pDestId = cJSON_CreateObject();
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr);
- cJSON_AddStringToObject(pDestId, "addr", u64buf);
- {
- uint64_t u64 = pMsg->destId.addr;
- cJSON* pTmp = pDestId;
- char host[128] = {0};
- uint16_t port;
- syncUtilU642Addr(u64, host, sizeof(host), &port);
- cJSON_AddStringToObject(pTmp, "addr_host", host);
- cJSON_AddNumberToObject(pTmp, "addr_port", port);
- }
- cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
- cJSON_AddItemToObject(pRoot, "destId", pDestId);
-
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term);
- cJSON_AddStringToObject(pRoot, "term", u64buf);
-
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->privateTerm);
- cJSON_AddStringToObject(pRoot, "privateTerm", u64buf);
-
- snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->prevLogIndex);
- cJSON_AddStringToObject(pRoot, "prevLogIndex", u64buf);
-
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->prevLogTerm);
- cJSON_AddStringToObject(pRoot, "pre_log_term", u64buf);
-
- snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->commitIndex);
- cJSON_AddStringToObject(pRoot, "commitIndex", u64buf);
-
- cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
- char* s;
- s = syncUtilPrintBin((char*)(pMsg->data), pMsg->dataLen);
- cJSON_AddStringToObject(pRoot, "data", s);
- taosMemoryFree(s);
- s = syncUtilPrintBin2((char*)(pMsg->data), pMsg->dataLen);
- cJSON_AddStringToObject(pRoot, "data2", s);
- taosMemoryFree(s);
+ pMsg->contLen = bytes;
+ if (pMsg->pCont == NULL) {
+ terrno = TSDB_CODE_OUT_OF_MEMORY;
+ return -1;
}
- cJSON* pJson = cJSON_CreateObject();
- cJSON_AddItemToObject(pJson, "SyncAppendEntries", pRoot);
- return pJson;
+ SyncAppendEntries* pAppendEntries = pMsg->pCont;
+ pAppendEntries->bytes = bytes;
+ pAppendEntries->vgId = vgId;
+ pAppendEntries->msgType = TDMT_SYNC_APPEND_ENTRIES;
+ pAppendEntries->dataLen = dataLen;
+ return 0;
}
-char* syncAppendEntries2Str(const SyncAppendEntries* pMsg) {
- cJSON* pJson = syncAppendEntries2Json(pMsg);
- char* serialized = cJSON_Print(pJson);
- cJSON_Delete(pJson);
- return serialized;
-}
-
-// for debug ----------------------
-void syncAppendEntriesPrint(const SyncAppendEntries* pMsg) {
- char* serialized = syncAppendEntries2Str(pMsg);
- printf("syncAppendEntriesPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
- fflush(NULL);
- taosMemoryFree(serialized);
-}
-
-void syncAppendEntriesPrint2(char* s, const SyncAppendEntries* pMsg) {
- char* serialized = syncAppendEntries2Str(pMsg);
- printf("syncAppendEntriesPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
- fflush(NULL);
- taosMemoryFree(serialized);
-}
-
-void syncAppendEntriesLog(const SyncAppendEntries* pMsg) {
- char* serialized = syncAppendEntries2Str(pMsg);
- sTrace("syncAppendEntriesLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
- taosMemoryFree(serialized);
-}
-
-void syncAppendEntriesLog2(char* s, const SyncAppendEntries* pMsg) {
- if (gRaftDetailLog) {
- char* serialized = syncAppendEntries2Str(pMsg);
- sTrace("syncAppendEntriesLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
- taosMemoryFree(serialized);
- }
-}
-
-// ---- message process SyncAppendEntriesReply----
-SyncAppendEntriesReply* syncAppendEntriesReplyBuild(int32_t vgId) {
- uint32_t bytes = sizeof(SyncAppendEntriesReply);
- SyncAppendEntriesReply* pMsg = taosMemoryMalloc(bytes);
- memset(pMsg, 0, bytes);
- pMsg->bytes = bytes;
- pMsg->vgId = vgId;
+int32_t syncBuildAppendEntriesReply(SRpcMsg* pMsg, int32_t vgId) {
+ int32_t bytes = sizeof(SyncAppendEntriesReply);
+ pMsg->pCont = rpcMallocCont(bytes);
pMsg->msgType = TDMT_SYNC_APPEND_ENTRIES_REPLY;
- return pMsg;
-}
-
-void syncAppendEntriesReplyDestroy(SyncAppendEntriesReply* pMsg) {
- if (pMsg != NULL) {
- taosMemoryFree(pMsg);
- }
-}
-
-void syncAppendEntriesReplySerialize(const SyncAppendEntriesReply* pMsg, char* buf, uint32_t bufLen) {
- ASSERT(pMsg->bytes <= bufLen);
- memcpy(buf, pMsg, pMsg->bytes);
-}
-
-void syncAppendEntriesReplyDeserialize(const char* buf, uint32_t len, SyncAppendEntriesReply* pMsg) {
- memcpy(pMsg, buf, len);
- ASSERT(len == pMsg->bytes);
-}
-
-char* syncAppendEntriesReplySerialize2(const SyncAppendEntriesReply* pMsg, uint32_t* len) {
- char* buf = taosMemoryMalloc(pMsg->bytes);
- ASSERT(buf != NULL);
- syncAppendEntriesReplySerialize(pMsg, buf, pMsg->bytes);
- if (len != NULL) {
- *len = pMsg->bytes;
- }
- return buf;
-}
-
-SyncAppendEntriesReply* syncAppendEntriesReplyDeserialize2(const char* buf, uint32_t len) {
- uint32_t bytes = *((uint32_t*)buf);
- SyncAppendEntriesReply* pMsg = taosMemoryMalloc(bytes);
- ASSERT(pMsg != NULL);
- syncAppendEntriesReplyDeserialize(buf, len, pMsg);
- ASSERT(len == pMsg->bytes);
- return pMsg;
-}
-
-void syncAppendEntriesReply2RpcMsg(const SyncAppendEntriesReply* pMsg, SRpcMsg* pRpcMsg) {
- memset(pRpcMsg, 0, sizeof(*pRpcMsg));
- pRpcMsg->msgType = pMsg->msgType;
- pRpcMsg->contLen = pMsg->bytes;
- pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
- syncAppendEntriesReplySerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen);
-}
-
-void syncAppendEntriesReplyFromRpcMsg(const SRpcMsg* pRpcMsg, SyncAppendEntriesReply* pMsg) {
- syncAppendEntriesReplyDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
-}
-
-SyncAppendEntriesReply* syncAppendEntriesReplyFromRpcMsg2(const SRpcMsg* pRpcMsg) {
- SyncAppendEntriesReply* pMsg = syncAppendEntriesReplyDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
- ASSERT(pMsg != NULL);
- return pMsg;
-}
-
-cJSON* syncAppendEntriesReply2Json(const SyncAppendEntriesReply* pMsg) {
- char u64buf[128] = {0};
- cJSON* pRoot = cJSON_CreateObject();
-
- if (pMsg != NULL) {
- cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
- cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
- cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
-
- cJSON* pSrcId = cJSON_CreateObject();
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr);
- cJSON_AddStringToObject(pSrcId, "addr", u64buf);
- {
- uint64_t u64 = pMsg->srcId.addr;
- cJSON* pTmp = pSrcId;
- char host[128] = {0};
- uint16_t port;
- syncUtilU642Addr(u64, host, sizeof(host), &port);
- cJSON_AddStringToObject(pTmp, "addr_host", host);
- cJSON_AddNumberToObject(pTmp, "addr_port", port);
- }
- cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
- cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
-
- cJSON* pDestId = cJSON_CreateObject();
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr);
- cJSON_AddStringToObject(pDestId, "addr", u64buf);
- {
- uint64_t u64 = pMsg->destId.addr;
- cJSON* pTmp = pDestId;
- char host[128] = {0};
- uint16_t port;
- syncUtilU642Addr(u64, host, sizeof(host), &port);
- cJSON_AddStringToObject(pTmp, "addr_host", host);
- cJSON_AddNumberToObject(pTmp, "addr_port", port);
- }
- cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
- cJSON_AddItemToObject(pRoot, "destId", pDestId);
-
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->privateTerm);
- cJSON_AddStringToObject(pRoot, "privateTerm", u64buf);
-
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term);
- cJSON_AddStringToObject(pRoot, "term", u64buf);
- cJSON_AddNumberToObject(pRoot, "success", pMsg->success);
- snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->matchIndex);
- cJSON_AddStringToObject(pRoot, "matchIndex", u64buf);
- snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->startTime);
- cJSON_AddStringToObject(pRoot, "startTime", u64buf);
+ pMsg->contLen = bytes;
+ if (pMsg->pCont == NULL) {
+ terrno = TSDB_CODE_OUT_OF_MEMORY;
+ return -1;
}
- cJSON* pJson = cJSON_CreateObject();
- cJSON_AddItemToObject(pJson, "SyncAppendEntriesReply", pRoot);
- return pJson;
+ SyncAppendEntriesReply* pAppendEntriesReply = pMsg->pCont;
+ pAppendEntriesReply->bytes = bytes;
+ pAppendEntriesReply->msgType = TDMT_SYNC_APPEND_ENTRIES_REPLY;
+ pAppendEntriesReply->vgId = vgId;
+ return 0;
}
-char* syncAppendEntriesReply2Str(const SyncAppendEntriesReply* pMsg) {
- cJSON* pJson = syncAppendEntriesReply2Json(pMsg);
- char* serialized = cJSON_Print(pJson);
- cJSON_Delete(pJson);
- return serialized;
-}
-
-// for debug ----------------------
-void syncAppendEntriesReplyPrint(const SyncAppendEntriesReply* pMsg) {
- char* serialized = syncAppendEntriesReply2Str(pMsg);
- printf("syncAppendEntriesReplyPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
- fflush(NULL);
- taosMemoryFree(serialized);
-}
-
-void syncAppendEntriesReplyPrint2(char* s, const SyncAppendEntriesReply* pMsg) {
- char* serialized = syncAppendEntriesReply2Str(pMsg);
- printf("syncAppendEntriesReplyPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
- fflush(NULL);
- taosMemoryFree(serialized);
-}
-
-void syncAppendEntriesReplyLog(const SyncAppendEntriesReply* pMsg) {
- char* serialized = syncAppendEntriesReply2Str(pMsg);
- sTrace("syncAppendEntriesReplyLog | len:%d| %s", (int32_t)strlen(serialized), serialized);
- taosMemoryFree(serialized);
-}
-
-void syncAppendEntriesReplyLog2(char* s, const SyncAppendEntriesReply* pMsg) {
- if (gRaftDetailLog) {
- char* serialized = syncAppendEntriesReply2Str(pMsg);
- sTrace("syncAppendEntriesReplyLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
- taosMemoryFree(serialized);
- }
-}
-
-// ---- message process SyncHeartbeat----
-SyncHeartbeat* syncHeartbeatBuild(int32_t vgId) {
- uint32_t bytes = sizeof(SyncHeartbeat);
- SyncHeartbeat* pMsg = taosMemoryMalloc(bytes);
- memset(pMsg, 0, bytes);
- pMsg->bytes = bytes;
- pMsg->vgId = vgId;
+int32_t syncBuildHeartbeat(SRpcMsg* pMsg, int32_t vgId) {
+ int32_t bytes = sizeof(SyncHeartbeat);
+ pMsg->pCont = rpcMallocCont(bytes);
pMsg->msgType = TDMT_SYNC_HEARTBEAT;
- return pMsg;
-}
-
-void syncHeartbeatDestroy(SyncHeartbeat* pMsg) {
- if (pMsg != NULL) {
- taosMemoryFree(pMsg);
- }
-}
-
-void syncHeartbeatSerialize(const SyncHeartbeat* pMsg, char* buf, uint32_t bufLen) {
- ASSERT(pMsg->bytes <= bufLen);
- memcpy(buf, pMsg, pMsg->bytes);
-}
-
-void syncHeartbeatDeserialize(const char* buf, uint32_t len, SyncHeartbeat* pMsg) {
- memcpy(pMsg, buf, len);
- ASSERT(len == pMsg->bytes);
-}
-
-char* syncHeartbeatSerialize2(const SyncHeartbeat* pMsg, uint32_t* len) {
- char* buf = taosMemoryMalloc(pMsg->bytes);
- ASSERT(buf != NULL);
- syncHeartbeatSerialize(pMsg, buf, pMsg->bytes);
- if (len != NULL) {
- *len = pMsg->bytes;
- }
- return buf;
-}
-
-SyncHeartbeat* syncHeartbeatDeserialize2(const char* buf, uint32_t len) {
- uint32_t bytes = *((uint32_t*)buf);
- SyncHeartbeat* pMsg = taosMemoryMalloc(bytes);
- ASSERT(pMsg != NULL);
- syncHeartbeatDeserialize(buf, len, pMsg);
- ASSERT(len == pMsg->bytes);
- return pMsg;
-}
-
-void syncHeartbeat2RpcMsg(const SyncHeartbeat* pMsg, SRpcMsg* pRpcMsg) {
- memset(pRpcMsg, 0, sizeof(*pRpcMsg));
- pRpcMsg->msgType = pMsg->msgType;
- pRpcMsg->contLen = pMsg->bytes;
- pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
- syncHeartbeatSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen);
-}
-
-void syncHeartbeatFromRpcMsg(const SRpcMsg* pRpcMsg, SyncHeartbeat* pMsg) {
- syncHeartbeatDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
-}
-
-SyncHeartbeat* syncHeartbeatFromRpcMsg2(const SRpcMsg* pRpcMsg) {
- SyncHeartbeat* pMsg = syncHeartbeatDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
- ASSERT(pMsg != NULL);
- return pMsg;
-}
-
-cJSON* syncHeartbeat2Json(const SyncHeartbeat* pMsg) {
- char u64buf[128] = {0};
- cJSON* pRoot = cJSON_CreateObject();
-
- if (pMsg != NULL) {
- cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
- cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
- cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
-
- cJSON* pSrcId = cJSON_CreateObject();
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr);
- cJSON_AddStringToObject(pSrcId, "addr", u64buf);
- {
- uint64_t u64 = pMsg->srcId.addr;
- cJSON* pTmp = pSrcId;
- char host[128] = {0};
- uint16_t port;
- syncUtilU642Addr(u64, host, sizeof(host), &port);
- cJSON_AddStringToObject(pTmp, "addr_host", host);
- cJSON_AddNumberToObject(pTmp, "addr_port", port);
- }
- cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
- cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
-
- cJSON* pDestId = cJSON_CreateObject();
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr);
- cJSON_AddStringToObject(pDestId, "addr", u64buf);
- {
- uint64_t u64 = pMsg->destId.addr;
- cJSON* pTmp = pDestId;
- char host[128] = {0};
- uint16_t port;
- syncUtilU642Addr(u64, host, sizeof(host), &port);
- cJSON_AddStringToObject(pTmp, "addr_host", host);
- cJSON_AddNumberToObject(pTmp, "addr_port", port);
- }
- cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
- cJSON_AddItemToObject(pRoot, "destId", pDestId);
-
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term);
- cJSON_AddStringToObject(pRoot, "term", u64buf);
-
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->privateTerm);
- cJSON_AddStringToObject(pRoot, "privateTerm", u64buf);
-
- snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->commitIndex);
- cJSON_AddStringToObject(pRoot, "commitIndex", u64buf);
+ pMsg->contLen = bytes;
+ if (pMsg->pCont == NULL) {
+ terrno = TSDB_CODE_OUT_OF_MEMORY;
+ return -1;
}
- cJSON* pJson = cJSON_CreateObject();
- cJSON_AddItemToObject(pJson, "SyncHeartbeat", pRoot);
- return pJson;
+ SyncHeartbeat* pHeartbeat = pMsg->pCont;
+ pHeartbeat->bytes = bytes;
+ pHeartbeat->msgType = TDMT_SYNC_HEARTBEAT;
+ pHeartbeat->vgId = vgId;
+ return 0;
}
-char* syncHeartbeat2Str(const SyncHeartbeat* pMsg) {
- cJSON* pJson = syncHeartbeat2Json(pMsg);
- char* serialized = cJSON_Print(pJson);
- cJSON_Delete(pJson);
- return serialized;
-}
-
-void syncHeartbeatPrint(const SyncHeartbeat* pMsg) {
- char* serialized = syncHeartbeat2Str(pMsg);
- printf("syncHeartbeatPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
- fflush(NULL);
- taosMemoryFree(serialized);
-}
-
-void syncHeartbeatPrint2(char* s, const SyncHeartbeat* pMsg) {
- char* serialized = syncHeartbeat2Str(pMsg);
- printf("syncHeartbeatPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
- fflush(NULL);
- taosMemoryFree(serialized);
-}
-
-void syncHeartbeatLog(const SyncHeartbeat* pMsg) {
- char* serialized = syncHeartbeat2Str(pMsg);
- sTrace("syncHeartbeatLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
- taosMemoryFree(serialized);
-}
-
-void syncHeartbeatLog2(char* s, const SyncHeartbeat* pMsg) {
- if (gRaftDetailLog) {
- char* serialized = syncHeartbeat2Str(pMsg);
- sTrace("syncHeartbeatLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
- taosMemoryFree(serialized);
- }
-}
-
-// ---- message process SyncHeartbeatReply----
-SyncHeartbeatReply* syncHeartbeatReplyBuild(int32_t vgId) {
- uint32_t bytes = sizeof(SyncHeartbeatReply);
- SyncHeartbeatReply* pMsg = taosMemoryMalloc(bytes);
- memset(pMsg, 0, bytes);
- pMsg->bytes = bytes;
- pMsg->vgId = vgId;
+int32_t syncBuildHeartbeatReply(SRpcMsg* pMsg, int32_t vgId) {
+ int32_t bytes = sizeof(SyncHeartbeatReply);
+ pMsg->pCont = rpcMallocCont(bytes);
pMsg->msgType = TDMT_SYNC_HEARTBEAT_REPLY;
- return pMsg;
-}
-
-void syncHeartbeatReplyDestroy(SyncHeartbeatReply* pMsg) {
- if (pMsg != NULL) {
- taosMemoryFree(pMsg);
- }
-}
-
-void syncHeartbeatReplySerialize(const SyncHeartbeatReply* pMsg, char* buf, uint32_t bufLen) {
- ASSERT(pMsg->bytes <= bufLen);
- memcpy(buf, pMsg, pMsg->bytes);
-}
-
-void syncHeartbeatReplyDeserialize(const char* buf, uint32_t len, SyncHeartbeatReply* pMsg) {
- memcpy(pMsg, buf, len);
- ASSERT(len == pMsg->bytes);
-}
-
-char* syncHeartbeatReplySerialize2(const SyncHeartbeatReply* pMsg, uint32_t* len) {
- char* buf = taosMemoryMalloc(pMsg->bytes);
- ASSERT(buf != NULL);
- syncHeartbeatReplySerialize(pMsg, buf, pMsg->bytes);
- if (len != NULL) {
- *len = pMsg->bytes;
- }
- return buf;
-}
-
-SyncHeartbeatReply* syncHeartbeatReplyDeserialize2(const char* buf, uint32_t len) {
- uint32_t bytes = *((uint32_t*)buf);
- SyncHeartbeatReply* pMsg = taosMemoryMalloc(bytes);
- ASSERT(pMsg != NULL);
- syncHeartbeatReplyDeserialize(buf, len, pMsg);
- ASSERT(len == pMsg->bytes);
- return pMsg;
-}
-
-void syncHeartbeatReply2RpcMsg(const SyncHeartbeatReply* pMsg, SRpcMsg* pRpcMsg) {
- memset(pRpcMsg, 0, sizeof(*pRpcMsg));
- pRpcMsg->msgType = pMsg->msgType;
- pRpcMsg->contLen = pMsg->bytes;
- pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
- syncHeartbeatReplySerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen);
-}
-
-void syncHeartbeatReplyFromRpcMsg(const SRpcMsg* pRpcMsg, SyncHeartbeatReply* pMsg) {
- syncHeartbeatReplyDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
-}
-
-SyncHeartbeatReply* syncHeartbeatReplyFromRpcMsg2(const SRpcMsg* pRpcMsg) {
- SyncHeartbeatReply* pMsg = syncHeartbeatReplyDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
- ASSERT(pMsg != NULL);
- return pMsg;
-}
-
-cJSON* syncHeartbeatReply2Json(const SyncHeartbeatReply* pMsg) {
- char u64buf[128] = {0};
- cJSON* pRoot = cJSON_CreateObject();
-
- if (pMsg != NULL) {
- cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
- cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
- cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
-
- cJSON* pSrcId = cJSON_CreateObject();
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr);
- cJSON_AddStringToObject(pSrcId, "addr", u64buf);
- {
- uint64_t u64 = pMsg->srcId.addr;
- cJSON* pTmp = pSrcId;
- char host[128] = {0};
- uint16_t port;
- syncUtilU642Addr(u64, host, sizeof(host), &port);
- cJSON_AddStringToObject(pTmp, "addr_host", host);
- cJSON_AddNumberToObject(pTmp, "addr_port", port);
- }
- cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
- cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
-
- cJSON* pDestId = cJSON_CreateObject();
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr);
- cJSON_AddStringToObject(pDestId, "addr", u64buf);
- {
- uint64_t u64 = pMsg->destId.addr;
- cJSON* pTmp = pDestId;
- char host[128] = {0};
- uint16_t port;
- syncUtilU642Addr(u64, host, sizeof(host), &port);
- cJSON_AddStringToObject(pTmp, "addr_host", host);
- cJSON_AddNumberToObject(pTmp, "addr_port", port);
- }
- cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
- cJSON_AddItemToObject(pRoot, "destId", pDestId);
-
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->privateTerm);
- cJSON_AddStringToObject(pRoot, "privateTerm", u64buf);
-
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term);
- cJSON_AddStringToObject(pRoot, "term", u64buf);
-
- cJSON_AddStringToObject(pRoot, "matchIndex", u64buf);
- snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->startTime);
- cJSON_AddStringToObject(pRoot, "startTime", u64buf);
+ pMsg->contLen = bytes;
+ if (pMsg->pCont == NULL) {
+ terrno = TSDB_CODE_OUT_OF_MEMORY;
+ return -1;
}
- cJSON* pJson = cJSON_CreateObject();
- cJSON_AddItemToObject(pJson, "SyncHeartbeatReply", pRoot);
- return pJson;
+ SyncHeartbeatReply* pHeartbeatReply = pMsg->pCont;
+ pHeartbeatReply->bytes = bytes;
+ pHeartbeatReply->msgType = TDMT_SYNC_HEARTBEAT_REPLY;
+ pHeartbeatReply->vgId = vgId;
+ return 0;
}
-char* syncHeartbeatReply2Str(const SyncHeartbeatReply* pMsg) {
- cJSON* pJson = syncHeartbeatReply2Json(pMsg);
- char* serialized = cJSON_Print(pJson);
- cJSON_Delete(pJson);
- return serialized;
-}
-
-void syncHeartbeatReplyPrint(const SyncHeartbeatReply* pMsg) {
- char* serialized = syncHeartbeatReply2Str(pMsg);
- printf("syncHeartbeatReplyPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
- fflush(NULL);
- taosMemoryFree(serialized);
-}
-
-void syncHeartbeatReplyPrint2(char* s, const SyncHeartbeatReply* pMsg) {
- char* serialized = syncHeartbeatReply2Str(pMsg);
- printf("syncHeartbeatReplyPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
- fflush(NULL);
- taosMemoryFree(serialized);
-}
-
-void syncHeartbeatReplyLog(const SyncHeartbeatReply* pMsg) {
- char* serialized = syncHeartbeatReply2Str(pMsg);
- sTrace("syncHeartbeatReplyLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
- taosMemoryFree(serialized);
-}
-
-void syncHeartbeatReplyLog2(char* s, const SyncHeartbeatReply* pMsg) {
- if (gRaftDetailLog) {
- char* serialized = syncHeartbeatReply2Str(pMsg);
- sTrace("syncHeartbeatReplyLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
- taosMemoryFree(serialized);
- }
-}
-
-// ---- message process SyncPreSnapshot----
-SyncPreSnapshot* syncPreSnapshotBuild(int32_t vgId) {
- uint32_t bytes = sizeof(SyncPreSnapshot);
- SyncPreSnapshot* pMsg = taosMemoryMalloc(bytes);
- memset(pMsg, 0, bytes);
- pMsg->bytes = bytes;
- pMsg->vgId = vgId;
+#if 0
+int32_t syncBuildPreSnapshot(SRpcMsg* pMsg, int32_t vgId) {
+ int32_t bytes = sizeof(SyncPreSnapshot);
+ pMsg->pCont = rpcMallocCont(bytes);
pMsg->msgType = TDMT_SYNC_PRE_SNAPSHOT;
- return pMsg;
-}
-
-void syncPreSnapshotDestroy(SyncPreSnapshot* pMsg) {
- if (pMsg != NULL) {
- taosMemoryFree(pMsg);
- }
-}
-
-void syncPreSnapshotSerialize(const SyncPreSnapshot* pMsg, char* buf, uint32_t bufLen) {
- ASSERT(pMsg->bytes <= bufLen);
- memcpy(buf, pMsg, pMsg->bytes);
-}
-
-void syncPreSnapshotDeserialize(const char* buf, uint32_t len, SyncPreSnapshot* pMsg) {
- memcpy(pMsg, buf, len);
- ASSERT(len == pMsg->bytes);
-}
-
-char* syncPreSnapshotSerialize2(const SyncPreSnapshot* pMsg, uint32_t* len) {
- char* buf = taosMemoryMalloc(pMsg->bytes);
- ASSERT(buf != NULL);
- syncPreSnapshotSerialize(pMsg, buf, pMsg->bytes);
- if (len != NULL) {
- *len = pMsg->bytes;
- }
- return buf;
-}
-
-SyncPreSnapshot* syncPreSnapshotDeserialize2(const char* buf, uint32_t len) {
- uint32_t bytes = *((uint32_t*)buf);
- SyncPreSnapshot* pMsg = taosMemoryMalloc(bytes);
- ASSERT(pMsg != NULL);
- syncPreSnapshotDeserialize(buf, len, pMsg);
- ASSERT(len == pMsg->bytes);
- return pMsg;
-}
-
-void syncPreSnapshot2RpcMsg(const SyncPreSnapshot* pMsg, SRpcMsg* pRpcMsg) {
- memset(pRpcMsg, 0, sizeof(*pRpcMsg));
- pRpcMsg->msgType = pMsg->msgType;
- pRpcMsg->contLen = pMsg->bytes;
- pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
- syncPreSnapshotSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen);
-}
-
-void syncPreSnapshotFromRpcMsg(const SRpcMsg* pRpcMsg, SyncPreSnapshot* pMsg) {
- syncPreSnapshotDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
-}
-
-SyncPreSnapshot* syncPreSnapshotFromRpcMsg2(const SRpcMsg* pRpcMsg) {
- SyncPreSnapshot* pMsg = syncPreSnapshotDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
- ASSERT(pMsg != NULL);
- return pMsg;
-}
-
-cJSON* syncPreSnapshot2Json(const SyncPreSnapshot* pMsg) {
- char u64buf[128] = {0};
- cJSON* pRoot = cJSON_CreateObject();
-
- if (pMsg != NULL) {
- cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
- cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
- cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
-
- cJSON* pSrcId = cJSON_CreateObject();
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr);
- cJSON_AddStringToObject(pSrcId, "addr", u64buf);
- {
- uint64_t u64 = pMsg->srcId.addr;
- cJSON* pTmp = pSrcId;
- char host[128] = {0};
- uint16_t port;
- syncUtilU642Addr(u64, host, sizeof(host), &port);
- cJSON_AddStringToObject(pTmp, "addr_host", host);
- cJSON_AddNumberToObject(pTmp, "addr_port", port);
- }
- cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
- cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
-
- cJSON* pDestId = cJSON_CreateObject();
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr);
- cJSON_AddStringToObject(pDestId, "addr", u64buf);
- {
- uint64_t u64 = pMsg->destId.addr;
- cJSON* pTmp = pDestId;
- char host[128] = {0};
- uint16_t port;
- syncUtilU642Addr(u64, host, sizeof(host), &port);
- cJSON_AddStringToObject(pTmp, "addr_host", host);
- cJSON_AddNumberToObject(pTmp, "addr_port", port);
- }
- cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
- cJSON_AddItemToObject(pRoot, "destId", pDestId);
-
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term);
- cJSON_AddStringToObject(pRoot, "term", u64buf);
+ pMsg->contLen = bytes;
+ if (pMsg->pCont == NULL) {
+ terrno = TSDB_CODE_OUT_OF_MEMORY;
+ return -1;
}
- cJSON* pJson = cJSON_CreateObject();
- cJSON_AddItemToObject(pJson, "SyncPreSnapshot", pRoot);
- return pJson;
+ SyncPreSnapshot* pPreSnapshot = pMsg->pCont;
+ pPreSnapshot->bytes = bytes;
+ pPreSnapshot->msgType = TDMT_SYNC_PRE_SNAPSHOT;
+ pPreSnapshot->vgId = vgId;
+ return 0;
}
-char* syncPreSnapshot2Str(const SyncPreSnapshot* pMsg) {
- cJSON* pJson = syncPreSnapshot2Json(pMsg);
- char* serialized = cJSON_Print(pJson);
- cJSON_Delete(pJson);
- return serialized;
-}
-
-void syncPreSnapshotPrint(const SyncPreSnapshot* pMsg) {
- char* serialized = syncPreSnapshot2Str(pMsg);
- printf("syncPreSnapshotPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
- fflush(NULL);
- taosMemoryFree(serialized);
-}
-
-void syncPreSnapshotPrint2(char* s, const SyncPreSnapshot* pMsg) {
- char* serialized = syncPreSnapshot2Str(pMsg);
- printf("syncPreSnapshotPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
- fflush(NULL);
- taosMemoryFree(serialized);
-}
-
-void syncPreSnapshotLog(const SyncPreSnapshot* pMsg) {
- char* serialized = syncPreSnapshot2Str(pMsg);
- sTrace("syncPreSnapshotLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
- taosMemoryFree(serialized);
-}
-
-void syncPreSnapshotLog2(char* s, const SyncPreSnapshot* pMsg) {
- if (gRaftDetailLog) {
- char* serialized = syncPreSnapshot2Str(pMsg);
- sTrace("syncPreSnapshotLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
- taosMemoryFree(serialized);
- }
-}
-
-// ---- message process SyncPreSnapshotReply----
-SyncPreSnapshotReply* syncPreSnapshotReplyBuild(int32_t vgId) {
- uint32_t bytes = sizeof(SyncPreSnapshotReply);
- SyncPreSnapshotReply* pMsg = taosMemoryMalloc(bytes);
- memset(pMsg, 0, bytes);
- pMsg->bytes = bytes;
- pMsg->vgId = vgId;
+int32_t syncBuildPreSnapshotReply(SRpcMsg* pMsg, int32_t vgId) {
+ int32_t bytes = sizeof(SyncPreSnapshotReply);
+ pMsg->pCont = rpcMallocCont(bytes);
pMsg->msgType = TDMT_SYNC_PRE_SNAPSHOT_REPLY;
- return pMsg;
-}
-
-void syncPreSnapshotReplyDestroy(SyncPreSnapshotReply* pMsg) {
- if (pMsg != NULL) {
- taosMemoryFree(pMsg);
- }
-}
-
-void syncPreSnapshotReplySerialize(const SyncPreSnapshotReply* pMsg, char* buf, uint32_t bufLen) {
- ASSERT(pMsg->bytes <= bufLen);
- memcpy(buf, pMsg, pMsg->bytes);
-}
-
-void syncPreSnapshotReplyDeserialize(const char* buf, uint32_t len, SyncPreSnapshotReply* pMsg) {
- memcpy(pMsg, buf, len);
- ASSERT(len == pMsg->bytes);
-}
-
-char* syncPreSnapshotReplySerialize2(const SyncPreSnapshotReply* pMsg, uint32_t* len) {
- char* buf = taosMemoryMalloc(pMsg->bytes);
- ASSERT(buf != NULL);
- syncPreSnapshotReplySerialize(pMsg, buf, pMsg->bytes);
- if (len != NULL) {
- *len = pMsg->bytes;
- }
- return buf;
-}
-
-SyncPreSnapshotReply* syncPreSnapshotReplyDeserialize2(const char* buf, uint32_t len) {
- uint32_t bytes = *((uint32_t*)buf);
- SyncPreSnapshotReply* pMsg = taosMemoryMalloc(bytes);
- ASSERT(pMsg != NULL);
- syncPreSnapshotReplyDeserialize(buf, len, pMsg);
- ASSERT(len == pMsg->bytes);
- return pMsg;
-}
-
-void syncPreSnapshotReply2RpcMsg(const SyncPreSnapshotReply* pMsg, SRpcMsg* pRpcMsg) {
- memset(pRpcMsg, 0, sizeof(*pRpcMsg));
- pRpcMsg->msgType = pMsg->msgType;
- pRpcMsg->contLen = pMsg->bytes;
- pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
- syncPreSnapshotReplySerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen);
-}
-
-void syncPreSnapshotReplyFromRpcMsg(const SRpcMsg* pRpcMsg, SyncPreSnapshotReply* pMsg) {
- syncPreSnapshotReplyDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
-}
-
-SyncPreSnapshotReply* syncPreSnapshotReplyFromRpcMsg2(const SRpcMsg* pRpcMsg) {
- SyncPreSnapshotReply* pMsg = syncPreSnapshotReplyDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
- ASSERT(pMsg != NULL);
- return pMsg;
-}
-
-cJSON* syncPreSnapshotReply2Json(const SyncPreSnapshotReply* pMsg) {
- char u64buf[128] = {0};
- cJSON* pRoot = cJSON_CreateObject();
-
- if (pMsg != NULL) {
- cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
- cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
- cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
-
- cJSON* pSrcId = cJSON_CreateObject();
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr);
- cJSON_AddStringToObject(pSrcId, "addr", u64buf);
- {
- uint64_t u64 = pMsg->srcId.addr;
- cJSON* pTmp = pSrcId;
- char host[128] = {0};
- uint16_t port;
- syncUtilU642Addr(u64, host, sizeof(host), &port);
- cJSON_AddStringToObject(pTmp, "addr_host", host);
- cJSON_AddNumberToObject(pTmp, "addr_port", port);
- }
- cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
- cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
-
- cJSON* pDestId = cJSON_CreateObject();
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr);
- cJSON_AddStringToObject(pDestId, "addr", u64buf);
- {
- uint64_t u64 = pMsg->destId.addr;
- cJSON* pTmp = pDestId;
- char host[128] = {0};
- uint16_t port;
- syncUtilU642Addr(u64, host, sizeof(host), &port);
- cJSON_AddStringToObject(pTmp, "addr_host", host);
- cJSON_AddNumberToObject(pTmp, "addr_port", port);
- }
- cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
- cJSON_AddItemToObject(pRoot, "destId", pDestId);
-
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term);
- cJSON_AddStringToObject(pRoot, "term", u64buf);
-
- snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->snapStart);
- cJSON_AddStringToObject(pRoot, "snap-start", u64buf);
+ pMsg->contLen = bytes;
+ if (pMsg->pCont == NULL) {
+ terrno = TSDB_CODE_OUT_OF_MEMORY;
+ return -1;
}
- cJSON* pJson = cJSON_CreateObject();
- cJSON_AddItemToObject(pJson, "SyncPreSnapshotReply", pRoot);
- return pJson;
+ SyncPreSnapshotReply* pPreSnapshotReply = pMsg->pCont;
+ pPreSnapshotReply->bytes = bytes;
+ pPreSnapshotReply->msgType = TDMT_SYNC_PRE_SNAPSHOT_REPLY;
+ pPreSnapshotReply->vgId = vgId;
+ return 0;
}
+#endif
-char* syncPreSnapshotReply2Str(const SyncPreSnapshotReply* pMsg) {
- cJSON* pJson = syncPreSnapshotReply2Json(pMsg);
- char* serialized = cJSON_Print(pJson);
- cJSON_Delete(pJson);
- return serialized;
-}
-
-void syncPreSnapshotReplyPrint(const SyncPreSnapshotReply* pMsg) {
- char* serialized = syncPreSnapshotReply2Str(pMsg);
- printf("syncPreSnapshotReplyPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
- fflush(NULL);
- taosMemoryFree(serialized);
-}
-
-void syncPreSnapshotReplyPrint2(char* s, const SyncPreSnapshotReply* pMsg) {
- char* serialized = syncPreSnapshotReply2Str(pMsg);
- printf("syncPreSnapshotReplyPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
- fflush(NULL);
- taosMemoryFree(serialized);
-}
-
-void syncPreSnapshotReplyLog(const SyncPreSnapshotReply* pMsg) {
- char* serialized = syncPreSnapshotReply2Str(pMsg);
- sTrace("syncPreSnapshotReplyLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
- taosMemoryFree(serialized);
-}
-
-void syncPreSnapshotReplyLog2(char* s, const SyncPreSnapshotReply* pMsg) {
- if (gRaftDetailLog) {
- char* serialized = syncPreSnapshotReply2Str(pMsg);
- sTrace("syncPreSnapshotReplyLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
- taosMemoryFree(serialized);
- }
-}
-
-// ---- message process SyncApplyMsg----
-SyncApplyMsg* syncApplyMsgBuild(uint32_t dataLen) {
- uint32_t bytes = sizeof(SyncApplyMsg) + dataLen;
- SyncApplyMsg* pMsg = taosMemoryMalloc(bytes);
- memset(pMsg, 0, bytes);
- pMsg->bytes = bytes;
- pMsg->msgType = TDMT_SYNC_APPLY_MSG;
- pMsg->dataLen = dataLen;
- return pMsg;
-}
-
-SyncApplyMsg* syncApplyMsgBuild2(const SRpcMsg* pOriginalRpcMsg, int32_t vgId, SFsmCbMeta* pMeta) {
- SyncApplyMsg* pMsg = syncApplyMsgBuild(pOriginalRpcMsg->contLen);
- pMsg->vgId = vgId;
- pMsg->originalRpcType = pOriginalRpcMsg->msgType;
- pMsg->fsmMeta = *pMeta;
- memcpy(pMsg->data, pOriginalRpcMsg->pCont, pOriginalRpcMsg->contLen);
- return pMsg;
-}
-
-void syncApplyMsgDestroy(SyncApplyMsg* pMsg) {
- if (pMsg != NULL) {
- taosMemoryFree(pMsg);
- }
-}
-
-void syncApplyMsgSerialize(const SyncApplyMsg* pMsg, char* buf, uint32_t bufLen) {
- ASSERT(pMsg->bytes <= bufLen);
- memcpy(buf, pMsg, pMsg->bytes);
-}
-
-void syncApplyMsgDeserialize(const char* buf, uint32_t len, SyncApplyMsg* pMsg) {
- memcpy(pMsg, buf, len);
- ASSERT(len == pMsg->bytes);
-}
-
-char* syncApplyMsgSerialize2(const SyncApplyMsg* pMsg, uint32_t* len) {
- char* buf = taosMemoryMalloc(pMsg->bytes);
- ASSERT(buf != NULL);
- syncApplyMsgSerialize(pMsg, buf, pMsg->bytes);
- if (len != NULL) {
- *len = pMsg->bytes;
- }
- return buf;
-}
-
-SyncApplyMsg* syncApplyMsgDeserialize2(const char* buf, uint32_t len) {
- uint32_t bytes = *((uint32_t*)buf);
- SyncApplyMsg* pMsg = taosMemoryMalloc(bytes);
- ASSERT(pMsg != NULL);
- syncApplyMsgDeserialize(buf, len, pMsg);
- ASSERT(len == pMsg->bytes);
- return pMsg;
-}
-
-// SyncApplyMsg to SRpcMsg, put it into ApplyQ
-void syncApplyMsg2RpcMsg(const SyncApplyMsg* pMsg, SRpcMsg* pRpcMsg) {
- memset(pRpcMsg, 0, sizeof(*pRpcMsg));
- pRpcMsg->msgType = pMsg->msgType;
- pRpcMsg->contLen = pMsg->bytes;
- pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
- syncApplyMsgSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen);
-}
-
-// get SRpcMsg from ApplyQ, to SyncApplyMsg
-void syncApplyMsgFromRpcMsg(const SRpcMsg* pRpcMsg, SyncApplyMsg* pMsg) {
- syncApplyMsgDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
-}
-
-SyncApplyMsg* syncApplyMsgFromRpcMsg2(const SRpcMsg* pRpcMsg) {
- SyncApplyMsg* pMsg = syncApplyMsgDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
- return pMsg;
-}
-
-// SyncApplyMsg to OriginalRpcMsg
-void syncApplyMsg2OriginalRpcMsg(const SyncApplyMsg* pMsg, SRpcMsg* pOriginalRpcMsg) {
- memset(pOriginalRpcMsg, 0, sizeof(*pOriginalRpcMsg));
- pOriginalRpcMsg->msgType = pMsg->originalRpcType;
- pOriginalRpcMsg->contLen = pMsg->dataLen;
- pOriginalRpcMsg->pCont = rpcMallocCont(pOriginalRpcMsg->contLen);
- memcpy(pOriginalRpcMsg->pCont, pMsg->data, pOriginalRpcMsg->contLen);
-}
-
-cJSON* syncApplyMsg2Json(const SyncApplyMsg* pMsg) {
- char u64buf[128] = {0};
- cJSON* pRoot = cJSON_CreateObject();
-
- if (pMsg != NULL) {
- cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
- cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
- cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
- cJSON_AddNumberToObject(pRoot, "originalRpcType", pMsg->originalRpcType);
-
- snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->fsmMeta.index);
- cJSON_AddStringToObject(pRoot, "fsmMeta.index", u64buf);
- cJSON_AddNumberToObject(pRoot, "fsmMeta.isWeak", pMsg->fsmMeta.isWeak);
- cJSON_AddNumberToObject(pRoot, "fsmMeta.code", pMsg->fsmMeta.code);
- cJSON_AddNumberToObject(pRoot, "fsmMeta.state", pMsg->fsmMeta.state);
- cJSON_AddStringToObject(pRoot, "fsmMeta.state.str", syncStr(pMsg->fsmMeta.state));
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->fsmMeta.seqNum);
- cJSON_AddStringToObject(pRoot, "fsmMeta.seqNum", u64buf);
-
- cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
- char* s;
- s = syncUtilPrintBin((char*)(pMsg->data), pMsg->dataLen);
- cJSON_AddStringToObject(pRoot, "data", s);
- taosMemoryFree(s);
- s = syncUtilPrintBin2((char*)(pMsg->data), pMsg->dataLen);
- cJSON_AddStringToObject(pRoot, "data2", s);
- taosMemoryFree(s);
- }
-
- cJSON* pJson = cJSON_CreateObject();
- cJSON_AddItemToObject(pJson, "SyncApplyMsg", pRoot);
- return pJson;
-}
-
-char* syncApplyMsg2Str(const SyncApplyMsg* pMsg) {
- cJSON* pJson = syncApplyMsg2Json(pMsg);
- char* serialized = cJSON_Print(pJson);
- cJSON_Delete(pJson);
- return serialized;
-}
-
-// for debug ----------------------
-void syncApplyMsgPrint(const SyncApplyMsg* pMsg) {
- char* serialized = syncApplyMsg2Str(pMsg);
- printf("syncApplyMsgPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
- fflush(NULL);
- taosMemoryFree(serialized);
-}
-
-void syncApplyMsgPrint2(char* s, const SyncApplyMsg* pMsg) {
- char* serialized = syncApplyMsg2Str(pMsg);
- printf("syncApplyMsgPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
- fflush(NULL);
- taosMemoryFree(serialized);
-}
-
-void syncApplyMsgLog(const SyncApplyMsg* pMsg) {
- char* serialized = syncApplyMsg2Str(pMsg);
- sTrace("ssyncApplyMsgLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
- taosMemoryFree(serialized);
-}
-
-void syncApplyMsgLog2(char* s, const SyncApplyMsg* pMsg) {
- if (gRaftDetailLog) {
- char* serialized = syncApplyMsg2Str(pMsg);
- sTrace("syncApplyMsgLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
- taosMemoryFree(serialized);
- }
-}
-
-// ---------------------------------------------
-SyncSnapshotSend* syncSnapshotSendBuild(uint32_t dataLen, int32_t vgId) {
- uint32_t bytes = sizeof(SyncSnapshotSend) + dataLen;
- SyncSnapshotSend* pMsg = taosMemoryMalloc(bytes);
- memset(pMsg, 0, bytes);
- pMsg->bytes = bytes;
- pMsg->vgId = vgId;
+int32_t syncBuildSnapshotSend(SRpcMsg* pMsg, int32_t dataLen, int32_t vgId) {
+ int32_t bytes = sizeof(SyncSnapshotSend) + dataLen;
+ pMsg->pCont = rpcMallocCont(bytes);
pMsg->msgType = TDMT_SYNC_SNAPSHOT_SEND;
- pMsg->dataLen = dataLen;
- return pMsg;
-}
-
-void syncSnapshotSendDestroy(SyncSnapshotSend* pMsg) {
- if (pMsg != NULL) {
- taosMemoryFree(pMsg);
+ pMsg->contLen = bytes;
+ if (pMsg->pCont == NULL) {
+ terrno = TSDB_CODE_OUT_OF_MEMORY;
+ return -1;
}
+
+ SyncSnapshotSend* pSnapshotSend = pMsg->pCont;
+ pSnapshotSend->bytes = bytes;
+ pSnapshotSend->vgId = vgId;
+ pSnapshotSend->msgType = TDMT_SYNC_SNAPSHOT_SEND;
+ pSnapshotSend->dataLen = dataLen;
+ return 0;
}
-void syncSnapshotSendSerialize(const SyncSnapshotSend* pMsg, char* buf, uint32_t bufLen) {
- ASSERT(pMsg->bytes <= bufLen);
- memcpy(buf, pMsg, pMsg->bytes);
-}
-
-void syncSnapshotSendDeserialize(const char* buf, uint32_t len, SyncSnapshotSend* pMsg) {
- memcpy(pMsg, buf, len);
- ASSERT(len == pMsg->bytes);
- ASSERT(pMsg->bytes == sizeof(SyncSnapshotSend) + pMsg->dataLen);
-}
-
-char* syncSnapshotSendSerialize2(const SyncSnapshotSend* pMsg, uint32_t* len) {
- char* buf = taosMemoryMalloc(pMsg->bytes);
- ASSERT(buf != NULL);
- syncSnapshotSendSerialize(pMsg, buf, pMsg->bytes);
- if (len != NULL) {
- *len = pMsg->bytes;
- }
- return buf;
-}
-
-SyncSnapshotSend* syncSnapshotSendDeserialize2(const char* buf, uint32_t len) {
- uint32_t bytes = *((uint32_t*)buf);
- SyncSnapshotSend* pMsg = taosMemoryMalloc(bytes);
- ASSERT(pMsg != NULL);
- syncSnapshotSendDeserialize(buf, len, pMsg);
- ASSERT(len == pMsg->bytes);
- return pMsg;
-}
-
-void syncSnapshotSend2RpcMsg(const SyncSnapshotSend* pMsg, SRpcMsg* pRpcMsg) {
- memset(pRpcMsg, 0, sizeof(*pRpcMsg));
- pRpcMsg->msgType = pMsg->msgType;
- pRpcMsg->contLen = pMsg->bytes;
- pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
- syncSnapshotSendSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen);
-}
-
-void syncSnapshotSendFromRpcMsg(const SRpcMsg* pRpcMsg, SyncSnapshotSend* pMsg) {
- syncSnapshotSendDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
-}
-
-SyncSnapshotSend* syncSnapshotSendFromRpcMsg2(const SRpcMsg* pRpcMsg) {
- SyncSnapshotSend* pMsg = syncSnapshotSendDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
- ASSERT(pMsg != NULL);
- return pMsg;
-}
-
-SyncSnapshotRsp* syncSnapshotRspBuild(int32_t vgId) {
- uint32_t bytes = sizeof(SyncSnapshotRsp);
- SyncSnapshotRsp* pMsg = taosMemoryMalloc(bytes);
- memset(pMsg, 0, bytes);
- pMsg->bytes = bytes;
- pMsg->vgId = vgId;
+int32_t syncBuildSnapshotSendRsp(SRpcMsg* pMsg, int32_t vgId) {
+ int32_t bytes = sizeof(SyncSnapshotRsp);
+ pMsg->pCont = rpcMallocCont(bytes);
pMsg->msgType = TDMT_SYNC_SNAPSHOT_RSP;
- return pMsg;
-}
-
-void syncSnapshotRspDestroy(SyncSnapshotRsp* pMsg) {
- if (pMsg != NULL) {
- taosMemoryFree(pMsg);
- }
-}
-
-void syncSnapshotRspSerialize(const SyncSnapshotRsp* pMsg, char* buf, uint32_t bufLen) {
- ASSERT(pMsg->bytes <= bufLen);
- memcpy(buf, pMsg, pMsg->bytes);
-}
-
-void syncSnapshotRspDeserialize(const char* buf, uint32_t len, SyncSnapshotRsp* pMsg) {
- memcpy(pMsg, buf, len);
- ASSERT(len == pMsg->bytes);
-}
-
-char* syncSnapshotRspSerialize2(const SyncSnapshotRsp* pMsg, uint32_t* len) {
- char* buf = taosMemoryMalloc(pMsg->bytes);
- ASSERT(buf != NULL);
- syncSnapshotRspSerialize(pMsg, buf, pMsg->bytes);
- if (len != NULL) {
- *len = pMsg->bytes;
- }
- return buf;
-}
-
-SyncSnapshotRsp* syncSnapshotRspDeserialize2(const char* buf, uint32_t len) {
- uint32_t bytes = *((uint32_t*)buf);
- SyncSnapshotRsp* pMsg = taosMemoryMalloc(bytes);
- ASSERT(pMsg != NULL);
- syncSnapshotRspDeserialize(buf, len, pMsg);
- ASSERT(len == pMsg->bytes);
- return pMsg;
-}
-
-void syncSnapshotRsp2RpcMsg(const SyncSnapshotRsp* pMsg, SRpcMsg* pRpcMsg) {
- memset(pRpcMsg, 0, sizeof(*pRpcMsg));
- pRpcMsg->msgType = pMsg->msgType;
- pRpcMsg->contLen = pMsg->bytes;
- pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
- syncSnapshotRspSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen);
-}
-
-void syncSnapshotRspFromRpcMsg(const SRpcMsg* pRpcMsg, SyncSnapshotRsp* pMsg) {
- syncSnapshotRspDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
-}
-
-SyncSnapshotRsp* syncSnapshotRspFromRpcMsg2(const SRpcMsg* pRpcMsg) {
- SyncSnapshotRsp* pMsg = syncSnapshotRspDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
- ASSERT(pMsg != NULL);
- return pMsg;
-}
-
-cJSON* syncSnapshotRsp2Json(const SyncSnapshotRsp* pMsg) {
- char u64buf[128];
- cJSON* pRoot = cJSON_CreateObject();
-
- if (pMsg != NULL) {
- cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
- cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
- cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
-
- cJSON* pSrcId = cJSON_CreateObject();
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr);
- cJSON_AddStringToObject(pSrcId, "addr", u64buf);
- {
- uint64_t u64 = pMsg->srcId.addr;
- cJSON* pTmp = pSrcId;
- char host[128];
- uint16_t port;
- syncUtilU642Addr(u64, host, sizeof(host), &port);
- cJSON_AddStringToObject(pTmp, "addr_host", host);
- cJSON_AddNumberToObject(pTmp, "addr_port", port);
- }
- cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
- cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
-
- cJSON* pDestId = cJSON_CreateObject();
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr);
- cJSON_AddStringToObject(pDestId, "addr", u64buf);
- {
- uint64_t u64 = pMsg->destId.addr;
- cJSON* pTmp = pDestId;
- char host[128];
- uint16_t port;
- syncUtilU642Addr(u64, host, sizeof(host), &port);
- cJSON_AddStringToObject(pTmp, "addr_host", host);
- cJSON_AddNumberToObject(pTmp, "addr_port", port);
- }
- cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
- cJSON_AddItemToObject(pRoot, "destId", pDestId);
-
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term);
- cJSON_AddStringToObject(pRoot, "term", u64buf);
-
- snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->startTime);
- cJSON_AddStringToObject(pRoot, "startTime", u64buf);
-
- snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->lastIndex);
- cJSON_AddStringToObject(pRoot, "lastIndex", u64buf);
-
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->lastTerm);
- cJSON_AddStringToObject(pRoot, "lastTerm", u64buf);
-
- cJSON_AddNumberToObject(pRoot, "ack", pMsg->ack);
- cJSON_AddNumberToObject(pRoot, "code", pMsg->code);
-
- snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->snapBeginIndex);
- cJSON_AddStringToObject(pRoot, "snap-begin", u64buf);
+ pMsg->contLen = bytes;
+ if (pMsg->pCont == NULL) {
+ terrno = TSDB_CODE_OUT_OF_MEMORY;
+ return -1;
}
- cJSON* pJson = cJSON_CreateObject();
- cJSON_AddItemToObject(pJson, "SyncSnapshotRsp", pRoot);
- return pJson;
+ SyncSnapshotRsp* pPreSnapshotRsp = pMsg->pCont;
+ pPreSnapshotRsp->bytes = bytes;
+ pPreSnapshotRsp->msgType = TDMT_SYNC_SNAPSHOT_RSP;
+ pPreSnapshotRsp->vgId = vgId;
+ return 0;
}
-char* syncSnapshotRsp2Str(const SyncSnapshotRsp* pMsg) {
- cJSON* pJson = syncSnapshotRsp2Json(pMsg);
- char* serialized = cJSON_Print(pJson);
- cJSON_Delete(pJson);
- return serialized;
-}
-
-// for debug ----------------------
-void syncSnapshotRspPrint(const SyncSnapshotRsp* pMsg) {
- char* serialized = syncSnapshotRsp2Str(pMsg);
- printf("syncSnapshotRspPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
- fflush(NULL);
- taosMemoryFree(serialized);
-}
-
-void syncSnapshotRspPrint2(char* s, const SyncSnapshotRsp* pMsg) {
- char* serialized = syncSnapshotRsp2Str(pMsg);
- printf("syncSnapshotRspPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
- fflush(NULL);
- taosMemoryFree(serialized);
-}
-
-void syncSnapshotRspLog(const SyncSnapshotRsp* pMsg) {
- char* serialized = syncSnapshotRsp2Str(pMsg);
- sTrace("syncSnapshotRspLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
- taosMemoryFree(serialized);
-}
-
-void syncSnapshotRspLog2(char* s, const SyncSnapshotRsp* pMsg) {
- if (gRaftDetailLog) {
- char* serialized = syncSnapshotRsp2Str(pMsg);
- sTrace("syncSnapshotRspLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
- taosMemoryFree(serialized);
- }
-}
-
-// ---------------------------------------------
-SyncLeaderTransfer* syncLeaderTransferBuild(int32_t vgId) {
- uint32_t bytes = sizeof(SyncLeaderTransfer);
- SyncLeaderTransfer* pMsg = taosMemoryMalloc(bytes);
- memset(pMsg, 0, bytes);
- pMsg->bytes = bytes;
- pMsg->vgId = vgId;
+int32_t syncBuildLeaderTransfer(SRpcMsg* pMsg, int32_t vgId) {
+ int32_t bytes = sizeof(SyncLeaderTransfer);
+ pMsg->pCont = rpcMallocCont(bytes);
pMsg->msgType = TDMT_SYNC_LEADER_TRANSFER;
- return pMsg;
-}
-
-void syncLeaderTransferDestroy(SyncLeaderTransfer* pMsg) {
- if (pMsg != NULL) {
- taosMemoryFree(pMsg);
- }
-}
-
-void syncLeaderTransferSerialize(const SyncLeaderTransfer* pMsg, char* buf, uint32_t bufLen) {
- ASSERT(pMsg->bytes <= bufLen);
- memcpy(buf, pMsg, pMsg->bytes);
-}
-
-void syncLeaderTransferDeserialize(const char* buf, uint32_t len, SyncLeaderTransfer* pMsg) {
- memcpy(pMsg, buf, len);
- ASSERT(len == pMsg->bytes);
-}
-
-char* syncLeaderTransferSerialize2(const SyncLeaderTransfer* pMsg, uint32_t* len) {
- char* buf = taosMemoryMalloc(pMsg->bytes);
- ASSERT(buf != NULL);
- syncLeaderTransferSerialize(pMsg, buf, pMsg->bytes);
- if (len != NULL) {
- *len = pMsg->bytes;
- }
- return buf;
-}
-
-SyncLeaderTransfer* syncLeaderTransferDeserialize2(const char* buf, uint32_t len) {
- uint32_t bytes = *((uint32_t*)buf);
- SyncLeaderTransfer* pMsg = taosMemoryMalloc(bytes);
- ASSERT(pMsg != NULL);
- syncLeaderTransferDeserialize(buf, len, pMsg);
- ASSERT(len == pMsg->bytes);
- return pMsg;
-}
-
-void syncLeaderTransfer2RpcMsg(const SyncLeaderTransfer* pMsg, SRpcMsg* pRpcMsg) {
- memset(pRpcMsg, 0, sizeof(*pRpcMsg));
- pRpcMsg->msgType = pMsg->msgType;
- pRpcMsg->contLen = pMsg->bytes;
- pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
- syncLeaderTransferSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen);
-}
-
-void syncLeaderTransferFromRpcMsg(const SRpcMsg* pRpcMsg, SyncLeaderTransfer* pMsg) {
- syncLeaderTransferDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
-}
-
-SyncLeaderTransfer* syncLeaderTransferFromRpcMsg2(const SRpcMsg* pRpcMsg) {
- SyncLeaderTransfer* pMsg = syncLeaderTransferDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
- ASSERT(pMsg != NULL);
- return pMsg;
-}
-
-cJSON* syncLeaderTransfer2Json(const SyncLeaderTransfer* pMsg) {
- char u64buf[128];
- cJSON* pRoot = cJSON_CreateObject();
-
- if (pMsg != NULL) {
- cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
- cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
- cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
-
- /*
- cJSON* pSrcId = cJSON_CreateObject();
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr);
- cJSON_AddStringToObject(pSrcId, "addr", u64buf);
- {
- uint64_t u64 = pMsg->srcId.addr;
- cJSON* pTmp = pSrcId;
- char host[128];
- uint16_t port;
- syncUtilU642Addr(u64, host, sizeof(host), &port);
- cJSON_AddStringToObject(pTmp, "addr_host", host);
- cJSON_AddNumberToObject(pTmp, "addr_port", port);
- }
- cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
- cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
-
- cJSON* pDestId = cJSON_CreateObject();
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr);
- cJSON_AddStringToObject(pDestId, "addr", u64buf);
- {
- uint64_t u64 = pMsg->destId.addr;
- cJSON* pTmp = pDestId;
- char host[128];
- uint16_t port;
- syncUtilU642Addr(u64, host, sizeof(host), &port);
- cJSON_AddStringToObject(pTmp, "addr_host", host);
- cJSON_AddNumberToObject(pTmp, "addr_port", port);
- }
- cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
- cJSON_AddItemToObject(pRoot, "destId", pDestId);
- */
-
- cJSON* pNewerId = cJSON_CreateObject();
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->newLeaderId.addr);
- cJSON_AddStringToObject(pNewerId, "addr", u64buf);
- {
- uint64_t u64 = pMsg->newLeaderId.addr;
- cJSON* pTmp = pNewerId;
- char host[128];
- uint16_t port;
- syncUtilU642Addr(u64, host, sizeof(host), &port);
- cJSON_AddStringToObject(pTmp, "addr_host", host);
- cJSON_AddNumberToObject(pTmp, "addr_port", port);
- }
- cJSON_AddNumberToObject(pNewerId, "vgId", pMsg->newLeaderId.vgId);
- cJSON_AddItemToObject(pRoot, "newLeaderId", pNewerId);
+ pMsg->contLen = bytes;
+ if (pMsg->pCont == NULL) {
+ terrno = TSDB_CODE_OUT_OF_MEMORY;
+ return -1;
}
- cJSON* pJson = cJSON_CreateObject();
- cJSON_AddItemToObject(pJson, "SyncLeaderTransfer", pRoot);
- return pJson;
+ SyncLeaderTransfer* pLeaderTransfer = pMsg->pCont;
+ pLeaderTransfer->bytes = bytes;
+ pLeaderTransfer->msgType = TDMT_SYNC_LEADER_TRANSFER;
+ pLeaderTransfer->vgId = vgId;
+ return 0;
}
-char* syncLeaderTransfer2Str(const SyncLeaderTransfer* pMsg) {
- cJSON* pJson = syncLeaderTransfer2Json(pMsg);
- char* serialized = cJSON_Print(pJson);
- cJSON_Delete(pJson);
- return serialized;
-}
-
-const char* syncLocalCmdGetStr(int32_t cmd) {
- if (cmd == SYNC_LOCAL_CMD_STEP_DOWN) {
- return "step-down";
- } else if (cmd == SYNC_LOCAL_CMD_FOLLOWER_CMT) {
- return "follower-commit";
- }
-
- return "unknown-local-cmd";
-}
-
-SyncLocalCmd* syncLocalCmdBuild(int32_t vgId) {
- uint32_t bytes = sizeof(SyncLocalCmd);
- SyncLocalCmd* pMsg = taosMemoryMalloc(bytes);
- memset(pMsg, 0, bytes);
- pMsg->bytes = bytes;
- pMsg->vgId = vgId;
+int32_t syncBuildLocalCmd(SRpcMsg* pMsg, int32_t vgId) {
+ int32_t bytes = sizeof(SyncLocalCmd);
+ pMsg->pCont = rpcMallocCont(bytes);
pMsg->msgType = TDMT_SYNC_LOCAL_CMD;
- return pMsg;
+ pMsg->contLen = bytes;
+ if (pMsg->pCont == NULL) {
+ terrno = TSDB_CODE_OUT_OF_MEMORY;
+ return -1;
+ }
+
+ SyncLocalCmd* pLocalCmd = pMsg->pCont;
+ pLocalCmd->bytes = bytes;
+ pLocalCmd->msgType = TDMT_SYNC_LOCAL_CMD;
+ pLocalCmd->vgId = vgId;
+ return 0;
}
-void syncLocalCmdDestroy(SyncLocalCmd* pMsg) {
- if (pMsg != NULL) {
- taosMemoryFree(pMsg);
+const char* syncTimerTypeStr(enum ESyncTimeoutType timerType) {
+ switch (timerType) {
+ case SYNC_TIMEOUT_PING:
+ return "ping";
+ case SYNC_TIMEOUT_ELECTION:
+ return "elect";
+ case SYNC_TIMEOUT_HEARTBEAT:
+ return "heartbeat";
+ default:
+ return "unknown";
}
}
-void syncLocalCmdSerialize(const SyncLocalCmd* pMsg, char* buf, uint32_t bufLen) {
- ASSERT(pMsg->bytes <= bufLen);
- memcpy(buf, pMsg, pMsg->bytes);
-}
-
-void syncLocalCmdDeserialize(const char* buf, uint32_t len, SyncLocalCmd* pMsg) {
- memcpy(pMsg, buf, len);
- ASSERT(len == pMsg->bytes);
-}
-
-char* syncLocalCmdSerialize2(const SyncLocalCmd* pMsg, uint32_t* len) {
- char* buf = taosMemoryMalloc(pMsg->bytes);
- ASSERT(buf != NULL);
- syncLocalCmdSerialize(pMsg, buf, pMsg->bytes);
- if (len != NULL) {
- *len = pMsg->bytes;
- }
- return buf;
-}
-
-SyncLocalCmd* syncLocalCmdDeserialize2(const char* buf, uint32_t len) {
- uint32_t bytes = *((uint32_t*)buf);
- SyncLocalCmd* pMsg = taosMemoryMalloc(bytes);
- ASSERT(pMsg != NULL);
- syncLocalCmdDeserialize(buf, len, pMsg);
- ASSERT(len == pMsg->bytes);
- return pMsg;
-}
-
-void syncLocalCmd2RpcMsg(const SyncLocalCmd* pMsg, SRpcMsg* pRpcMsg) {
- memset(pRpcMsg, 0, sizeof(*pRpcMsg));
- pRpcMsg->msgType = pMsg->msgType;
- pRpcMsg->contLen = pMsg->bytes;
- pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
- syncLocalCmdSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen);
-}
-
-void syncLocalCmdFromRpcMsg(const SRpcMsg* pRpcMsg, SyncLocalCmd* pMsg) {
- syncLocalCmdDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
-}
-
-SyncLocalCmd* syncLocalCmdFromRpcMsg2(const SRpcMsg* pRpcMsg) {
- SyncLocalCmd* pMsg = syncLocalCmdDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
- ASSERT(pMsg != NULL);
- return pMsg;
-}
-
-cJSON* syncLocalCmd2Json(const SyncLocalCmd* pMsg) {
- char u64buf[128];
- cJSON* pRoot = cJSON_CreateObject();
-
- if (pMsg != NULL) {
- cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
- cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
- cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
-
- cJSON* pSrcId = cJSON_CreateObject();
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr);
- cJSON_AddStringToObject(pSrcId, "addr", u64buf);
- {
- uint64_t u64 = pMsg->srcId.addr;
- cJSON* pTmp = pSrcId;
- char host[128];
- uint16_t port;
- syncUtilU642Addr(u64, host, sizeof(host), &port);
- cJSON_AddStringToObject(pTmp, "addr_host", host);
- cJSON_AddNumberToObject(pTmp, "addr_port", port);
- }
- cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
- cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
-
- cJSON* pDestId = cJSON_CreateObject();
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr);
- cJSON_AddStringToObject(pDestId, "addr", u64buf);
- {
- uint64_t u64 = pMsg->destId.addr;
- cJSON* pTmp = pDestId;
- char host[128];
- uint16_t port;
- syncUtilU642Addr(u64, host, sizeof(host), &port);
- cJSON_AddStringToObject(pTmp, "addr_host", host);
- cJSON_AddNumberToObject(pTmp, "addr_port", port);
- }
- cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
- cJSON_AddItemToObject(pRoot, "destId", pDestId);
-
- cJSON_AddNumberToObject(pRoot, "cmd", pMsg->cmd);
-
- snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->sdNewTerm);
- cJSON_AddStringToObject(pRoot, "sd-new-term", u64buf);
-
- snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->fcIndex);
- cJSON_AddStringToObject(pRoot, "fc-index", u64buf);
- }
-
- cJSON* pJson = cJSON_CreateObject();
- cJSON_AddItemToObject(pJson, "SyncLocalCmd2Json", pRoot);
- return pJson;
-}
-
-char* syncLocalCmd2Str(const SyncLocalCmd* pMsg) {
- cJSON* pJson = syncLocalCmd2Json(pMsg);
- char* serialized = cJSON_Print(pJson);
- cJSON_Delete(pJson);
- return serialized;
-}
-
-// for debug ----------------------
-void syncLocalCmdPrint(const SyncLocalCmd* pMsg) {
- char* serialized = syncLocalCmd2Str(pMsg);
- printf("syncLocalCmdPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
- fflush(NULL);
- taosMemoryFree(serialized);
-}
-
-void syncLocalCmdPrint2(char* s, const SyncLocalCmd* pMsg) {
- char* serialized = syncLocalCmd2Str(pMsg);
- printf("syncLocalCmdPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
- fflush(NULL);
- taosMemoryFree(serialized);
-}
-
-void syncLocalCmdLog(const SyncLocalCmd* pMsg) {
- char* serialized = syncLocalCmd2Str(pMsg);
- sTrace("syncLocalCmdLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
- taosMemoryFree(serialized);
-}
-
-void syncLocalCmdLog2(char* s, const SyncLocalCmd* pMsg) {
- if (gRaftDetailLog) {
- char* serialized = syncLocalCmd2Str(pMsg);
- sTrace("syncLocalCmdLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
- taosMemoryFree(serialized);
+const char* syncLocalCmdGetStr(ESyncLocalCmd cmd) {
+ switch (cmd) {
+ case SYNC_LOCAL_CMD_STEP_DOWN:
+ return "step-down";
+ case SYNC_LOCAL_CMD_FOLLOWER_CMT:
+ return "follower-commit";
+ default:
+ return "unknown-local-cmd";
}
}
diff --git a/source/libs/sync/src/syncRaftCfg.c b/source/libs/sync/src/syncRaftCfg.c
index b6b2616973..b425b0dba7 100644
--- a/source/libs/sync/src/syncRaftCfg.c
+++ b/source/libs/sync/src/syncRaftCfg.c
@@ -15,6 +15,7 @@
#define _DEFAULT_SOURCE
#include "syncRaftCfg.h"
+#include "syncUtil.h"
// file must already exist!
SRaftCfgIndex *raftCfgIndexOpen(const char *path) {
diff --git a/source/libs/sync/src/syncRaftLog.c b/source/libs/sync/src/syncRaftLog.c
index 2cdb18a109..b00ba3918c 100644
--- a/source/libs/sync/src/syncRaftLog.c
+++ b/source/libs/sync/src/syncRaftLog.c
@@ -17,6 +17,7 @@
#include "syncRaftLog.h"
#include "syncRaftCfg.h"
#include "syncRaftStore.h"
+#include "syncUtil.h"
// log[m .. n]
@@ -196,7 +197,12 @@ static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntr
syncMeta.isWeek = pEntry->isWeak;
syncMeta.seqNum = pEntry->seqNum;
syncMeta.term = pEntry->term;
+
+ int64_t tsWriteBegin = taosGetTimestampNs();
index = walAppendLog(pWal, pEntry->originalRpcType, syncMeta, pEntry->data, pEntry->dataLen);
+ int64_t tsWriteEnd = taosGetTimestampNs();
+ int64_t tsElapsed = tsWriteEnd - tsWriteBegin;
+
if (index < 0) {
int32_t err = terrno;
const char* errStr = tstrerror(err);
@@ -209,8 +215,8 @@ static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntr
}
pEntry->index = index;
- sNTrace(pData->pSyncNode, "write index:%" PRId64 ", type:%s, origin type:%s", pEntry->index,
- TMSG_INFO(pEntry->msgType), TMSG_INFO(pEntry->originalRpcType));
+ sNTrace(pData->pSyncNode, "write index:%" PRId64 ", type:%s, origin type:%s, elapsed:%" PRId64, pEntry->index,
+ TMSG_INFO(pEntry->msgType), TMSG_INFO(pEntry->originalRpcType), tsElapsed);
return 0;
}
@@ -233,9 +239,13 @@ int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, SSyncR
return -1;
}
+ int64_t ts1 = taosGetTimestampNs();
taosThreadMutexLock(&(pData->mutex));
+ int64_t ts2 = taosGetTimestampNs();
code = walReadVer(pWalHandle, index);
+ int64_t ts3 = taosGetTimestampNs();
+
// code = walReadVerCached(pWalHandle, index);
if (code != 0) {
int32_t err = terrno;
@@ -279,6 +289,18 @@ int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, SSyncR
*/
taosThreadMutexUnlock(&(pData->mutex));
+ int64_t ts4 = taosGetTimestampNs();
+
+ int64_t tsElapsed = ts4 - ts1;
+ int64_t tsElapsedLock = ts2 - ts1;
+ int64_t tsElapsedRead = ts3 - ts2;
+ int64_t tsElapsedBuild = ts4 - ts3;
+
+ sNTrace(pData->pSyncNode,
+ "read index:%" PRId64 ", elapsed:%" PRId64 ", elapsed-lock:%" PRId64 ", elapsed-read:%" PRId64
+ ", elapsed-build:%" PRId64,
+ index, tsElapsed, tsElapsedLock, tsElapsedRead, tsElapsedBuild);
+
return code;
}
diff --git a/source/libs/sync/src/syncReplication.c b/source/libs/sync/src/syncReplication.c
index 2a3705e139..6a7a2c18c1 100644
--- a/source/libs/sync/src/syncReplication.c
+++ b/source/libs/sync/src/syncReplication.c
@@ -20,6 +20,9 @@
#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
@@ -45,19 +48,20 @@
// mdest |-> j])
// /\ UNCHANGED <>
-int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId) {
+int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId, bool snapshot) {
// next index
SyncIndex nextIndex = syncIndexMgrGetIndex(pSyncNode->pNextIndex, pDestId);
- // maybe start snapshot
- SyncIndex logStartIndex = pSyncNode->pLogStore->syncLogBeginIndex(pSyncNode->pLogStore);
- SyncIndex logEndIndex = pSyncNode->pLogStore->syncLogEndIndex(pSyncNode->pLogStore);
- if (nextIndex < logStartIndex || nextIndex - 1 > logEndIndex) {
- sNTrace(pSyncNode, "maybe start snapshot for next-index:%" PRId64 ", start:%" PRId64 ", end:%" PRId64, nextIndex,
- logStartIndex, logEndIndex);
- // start snapshot
- // int32_t code = syncNodeStartSnapshot(pSyncNode, pDestId);
- return 0;
+ if (snapshot) {
+ // maybe start snapshot
+ SyncIndex logStartIndex = pSyncNode->pLogStore->syncLogBeginIndex(pSyncNode->pLogStore);
+ SyncIndex logEndIndex = pSyncNode->pLogStore->syncLogEndIndex(pSyncNode->pLogStore);
+ if (nextIndex < logStartIndex || nextIndex - 1 > logEndIndex) {
+ sNTrace(pSyncNode, "maybe start snapshot for next-index:%" PRId64 ", start:%" PRId64 ", end:%" PRId64, nextIndex,
+ logStartIndex, logEndIndex);
+ // start snapshot
+ int32_t code = syncNodeStartSnapshot(pSyncNode, pDestId);
+ }
}
// pre index, pre term
@@ -65,38 +69,38 @@ int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId) {
SyncTerm preLogTerm = syncNodeGetPreTerm(pSyncNode, nextIndex);
// prepare entry
+ SRpcMsg rpcMsg = {0};
SyncAppendEntries* pMsg = NULL;
- SSyncRaftEntry* pEntry;
+ SSyncRaftEntry* pEntry = NULL;
int32_t code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, nextIndex, &pEntry);
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;
}
}
+ syncEntryDestory(pEntry);
+
// prepare msg
ASSERT(pMsg != NULL);
pMsg->srcId = pSyncNode->myRaftId;
@@ -109,9 +113,7 @@ int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId) {
// pMsg->privateTerm = syncIndexMgrGetTerm(pSyncNode->pNextIndex, pDestId);
// send msg
- syncNodeMaybeSendAppendEntries(pSyncNode, pDestId, pMsg);
- syncAppendEntriesDestroy(pMsg);
-
+ syncNodeMaybeSendAppendEntries(pSyncNode, pDestId, &rpcMsg);
return 0;
}
@@ -125,7 +127,7 @@ int32_t syncNodeReplicate(SSyncNode* pSyncNode) {
int32_t ret = 0;
for (int i = 0; i < pSyncNode->peersNum; ++i) {
SRaftId* pDestId = &(pSyncNode->peersId[i]);
- ret = syncNodeReplicateOne(pSyncNode, pDestId);
+ ret = syncNodeReplicateOne(pSyncNode, pDestId, true);
if (ret != 0) {
char host[64];
int16_t port;
@@ -137,13 +139,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) {
@@ -151,53 +153,56 @@ int32_t syncNodeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftI
return 0;
}
+ // save index, otherwise pMsg will be free by rpc
+ SyncIndex saveLastSendIndex = pState->lastSendIndex;
+ bool update = false;
if (pMsg->dataLen > 0) {
- pState->lastSendIndex = pMsg->prevLogIndex + 1;
+ saveLastSendIndex = pMsg->prevLogIndex + 1;
+ update = true;
+ }
+
+ syncLogSendAppendEntries(pSyncNode, pMsg, "");
+ syncNodeSendMsgById(destRaftId, pSyncNode, pRpcMsg);
+
+ if (update) {
+ 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;
@@ -205,13 +210,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;
diff --git a/source/libs/sync/src/syncRequestVote.c b/source/libs/sync/src/syncRequestVote.c
index e2cce28671..8ffc22ee25 100644
--- a/source/libs/sync/src/syncRequestVote.c
+++ b/source/libs/sync/src/syncRequestVote.c
@@ -88,23 +88,6 @@ static bool syncNodeOnRequestVoteLogOK(SSyncNode* pSyncNode, SyncRequestVote* pM
return false;
}
-static 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);
-}
-
-static 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);
-}
-
int32_t syncNodeOnRequestVote(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
int32_t ret = 0;
SyncRequestVote* pMsg = pRpcMsg->pCont;
diff --git a/source/libs/sync/src/syncRequestVoteReply.c b/source/libs/sync/src/syncRequestVoteReply.c
index a9d363630e..563f475070 100644
--- a/source/libs/sync/src/syncRequestVoteReply.c
+++ b/source/libs/sync/src/syncRequestVoteReply.c
@@ -38,14 +38,6 @@
// /\ UNCHANGED <>
//
-static 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);
-}
-
int32_t syncNodeOnRequestVoteReply(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
int32_t ret = 0;
SyncRequestVoteReply* pMsg = pRpcMsg->pCont;
diff --git a/source/libs/sync/src/syncRespMgr.c b/source/libs/sync/src/syncRespMgr.c
index de8f1927ae..049b02d73e 100644
--- a/source/libs/sync/src/syncRespMgr.c
+++ b/source/libs/sync/src/syncRespMgr.c
@@ -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));
diff --git a/source/libs/sync/src/syncSnapshot.c b/source/libs/sync/src/syncSnapshot.c
index 3273718f7d..9bc0a07d48 100644
--- a/source/libs/sync/src/syncSnapshot.c
+++ b/source/libs/sync/src/syncSnapshot.c
@@ -19,6 +19,7 @@
#include "syncRaftCfg.h"
#include "syncRaftLog.h"
#include "syncRaftStore.h"
+#include "syncReplication.h"
#include "syncUtil.h"
SSyncSnapshotSender *snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaIndex) {
@@ -44,6 +45,7 @@ SSyncSnapshotSender *snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaI
pSender->replicaIndex = replicaIndex;
pSender->term = pSyncNode->pRaftStore->currentTerm;
pSender->startTime = 0;
+ pSender->endTime = 0;
pSender->pSyncNode->pFsm->FpGetSnapshotInfo(pSender->pSyncNode->pFsm, &(pSender->snapshot));
pSender->finish = false;
} else {
@@ -103,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;
@@ -116,10 +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);
- syncSnapshotSendDestroy(pMsg);
+ syncNodeSendMsgById(&pMsg->destId, pSender->pSyncNode, &rpcMsg);
+ syncLogSendSyncSnapshotSend(pSender->pSyncNode, pMsg, "");
// event log
sSTrace(pSender, "snapshot sender start");
@@ -130,6 +133,7 @@ int32_t snapshotSenderStop(SSyncSnapshotSender *pSender, bool finish) {
// update flag
pSender->start = false;
pSender->finish = finish;
+ pSender->endTime = taosGetTimestampMs();
// close reader
if (pSender->pReader != NULL) {
@@ -172,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;
@@ -188,10 +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);
- syncSnapshotSendDestroy(pMsg);
+ syncNodeSendMsgById(&pMsg->destId, pSender->pSyncNode, &rpcMsg);
+ syncLogSendSyncSnapshotSend(pSender->pSyncNode, pMsg, "");
// event log
if (pSender->seq == SYNC_SNAPSHOT_SEQ_END) {
@@ -207,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;
@@ -219,14 +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);
- syncSnapshotSendDestroy(pMsg);
+ syncNodeSendMsgById(&pMsg->destId, pSender->pSyncNode, &rpcMsg);
+ syncLogSendSyncSnapshotSend(pSender->pSyncNode, pMsg, "");
// event log
sSTrace(pSender, "snapshot sender resend");
@@ -241,6 +246,9 @@ static void snapshotSenderUpdateProgress(SSyncSnapshotSender *pSender, SyncSnaps
++(pSender->seq);
}
+// return 0, start ok
+// return 1, last snapshot finish ok
+// return -1, error
int32_t syncNodeStartSnapshot(SSyncNode *pSyncNode, SRaftId *pDestId) {
sNTrace(pSyncNode, "starting snapshot ...");
@@ -253,11 +261,14 @@ int32_t syncNodeStartSnapshot(SSyncNode *pSyncNode, SRaftId *pDestId) {
int32_t code = 0;
if (snapshotSenderIsStart(pSender)) {
- code = snapshotSenderStop(pSender, false);
- if (code != 0) {
- sNError(pSyncNode, "snapshot sender stop error");
- return -1;
- }
+ sNTrace(pSyncNode, "snapshot sender already start, ignore");
+ return 0;
+ }
+
+ if (!snapshotSenderIsStart(pSender) && pSender->finish &&
+ taosGetTimestampMs() - pSender->endTime < SNAPSHOT_WAIT_MS) {
+ sNTrace(pSyncNode, "snapshot sender too frequently, ignore");
+ return 1;
}
code = snapshotSenderStart(pSender);
@@ -316,36 +327,6 @@ void snapshotReceiverDestroy(SSyncSnapshotReceiver *pReceiver) {
bool snapshotReceiverIsStart(SSyncSnapshotReceiver *pReceiver) { return pReceiver->start; }
-// static do start by privateTerm, pBeginMsg
-// receive first snapshot data
-// write first block data
-static void snapshotReceiverDoStart(SSyncSnapshotReceiver *pReceiver, SyncSnapshotSend *pBeginMsg) {
- pReceiver->start = true;
- pReceiver->ack = SYNC_SNAPSHOT_SEQ_BEGIN;
-
- // start writer
- ASSERT(pReceiver->pWriter == NULL);
- int32_t ret = pReceiver->pSyncNode->pFsm->FpSnapshotStartWrite(pReceiver->pSyncNode->pFsm,
- &(pReceiver->snapshotParam), &(pReceiver->pWriter));
- ASSERT(ret == 0);
-
- pReceiver->term = pReceiver->pSyncNode->pRaftStore->currentTerm;
- pReceiver->snapshotParam.start = pBeginMsg->beginIndex;
- pReceiver->snapshotParam.end = pBeginMsg->lastIndex;
-
- pReceiver->fromId = pBeginMsg->srcId;
-
- // update snapshot
- pReceiver->snapshot.lastApplyIndex = pBeginMsg->lastIndex;
- pReceiver->snapshot.lastApplyTerm = pBeginMsg->lastTerm;
- pReceiver->snapshot.lastConfigIndex = pBeginMsg->lastConfigIndex;
-
- pReceiver->startTime = pBeginMsg->startTime;
-
- // event log
- sRTrace(pReceiver, "snapshot receiver start");
-}
-
// force stop
void snapshotReceiverForceStop(SSyncSnapshotReceiver *pReceiver) {
// force close, abandon incomplete data
@@ -362,10 +343,43 @@ void snapshotReceiverForceStop(SSyncSnapshotReceiver *pReceiver) {
sRTrace(pReceiver, "snapshot receiver force stop");
}
-// if receiver receive msg from seq = SYNC_SNAPSHOT_SEQ_BEGIN, start receiver
-int32_t snapshotReceiverStart(SSyncSnapshotReceiver *pReceiver, SyncSnapshotSend *pBeginMsg) {
+int32_t snapshotReceiverStartWriter(SSyncSnapshotReceiver *pReceiver, SyncSnapshotSend *pBeginMsg) {
+ ASSERT(snapshotReceiverIsStart(pReceiver));
+
+ // update ack
+ pReceiver->ack = SYNC_SNAPSHOT_SEQ_BEGIN;
+
+ // update snapshot
+ pReceiver->snapshot.lastApplyIndex = pBeginMsg->lastIndex;
+ pReceiver->snapshot.lastApplyTerm = pBeginMsg->lastTerm;
+ pReceiver->snapshot.lastConfigIndex = pBeginMsg->lastConfigIndex;
+
+ pReceiver->snapshotParam.start = pBeginMsg->beginIndex;
+ pReceiver->snapshotParam.end = pBeginMsg->lastIndex;
+
+ // start writer
+ ASSERT(pReceiver->pWriter == NULL);
+ int32_t ret = pReceiver->pSyncNode->pFsm->FpSnapshotStartWrite(pReceiver->pSyncNode->pFsm,
+ &(pReceiver->snapshotParam), &(pReceiver->pWriter));
+ ASSERT(ret == 0);
+
+ // event log
+ sRTrace(pReceiver, "snapshot receiver start writer");
+
+ return 0;
+}
+
+int32_t snapshotReceiverStart(SSyncSnapshotReceiver *pReceiver, SyncSnapshotSend *pPreMsg) {
ASSERT(!snapshotReceiverIsStart(pReceiver));
- snapshotReceiverDoStart(pReceiver, pBeginMsg);
+
+ pReceiver->start = true;
+ pReceiver->ack = SYNC_SNAPSHOT_SEQ_PRE_SNAPSHOT;
+ pReceiver->term = pReceiver->pSyncNode->pRaftStore->currentTerm;
+ pReceiver->fromId = pPreMsg->srcId;
+ pReceiver->startTime = pPreMsg->startTime;
+
+ // event log
+ sRTrace(pReceiver, "snapshot receiver start");
return 0;
}
@@ -518,7 +532,10 @@ _START_RECEIVER:
return -1;
} else {
// waiting for clock match
- while (taosGetTimestampMs() > pMsg->startTime) {
+ int64_t timeNow = taosGetTimestampMs();
+ while (timeNow < pMsg->startTime) {
+ sNTrace(pSyncNode, "snapshot receiver pre waitting for true time, now:%" PRId64 ", stime:%" PRId64, timeNow,
+ pMsg->startTime);
taosMsleep(10);
}
@@ -528,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;
@@ -540,11 +561,8 @@ _SEND_REPLY:
pRspMsg->snapBeginIndex = syncNodeGetSnapBeginIndex(pSyncNode);
// send msg
- SRpcMsg rpcMsg;
- syncSnapshotRsp2RpcMsg(pRspMsg, &rpcMsg);
- syncNodeSendMsgById(&(pRspMsg->destId), pSyncNode, &rpcMsg);
- syncSnapshotRspDestroy(pRspMsg);
-
+ syncNodeSendMsgById(&pRspMsg->destId, pSyncNode, &rpcMsg);
+ syncLogSendSyncSnapshotRsp(pSyncNode, pRspMsg, "");
return 0;
}
@@ -552,54 +570,116 @@ static int32_t syncNodeOnSnapshotBegin(SSyncNode *pSyncNode, SyncSnapshotSend *p
// condition 1
SSyncSnapshotReceiver *pReceiver = pSyncNode->pNewNodeReceiver;
- if (snapshotReceiverIsStart(pReceiver)) {
- if (pMsg->startTime > pReceiver->startTime) {
- snapshotReceiverStop(pReceiver);
-
- } else if (pMsg->startTime == pReceiver->startTime) {
- return 0;
- } else {
- // ignore
- sNTrace(pSyncNode, "msg ignore");
- return 0;
- }
- }
-
-_START_RECEIVER:
- if (taosGetTimestampMs() - pMsg->startTime > SNAPSHOT_MAX_CLOCK_SKEW_MS) {
- sNError(pSyncNode, "snapshot receiver time skew too much");
+ if (!snapshotReceiverIsStart(pReceiver)) {
+ sNError(pSyncNode, "snapshot receiver not start");
return -1;
- } else {
- // waiting for clock match
- while (taosGetTimestampMs() > pMsg->startTime) {
- taosMsleep(10);
- }
-
- snapshotReceiverStart(pReceiver, pMsg);
-
- // build msg
- SyncSnapshotRsp *pRspMsg = syncSnapshotRspBuild(pSyncNode->vgId);
- pRspMsg->srcId = pSyncNode->myRaftId;
- pRspMsg->destId = pMsg->srcId;
- pRspMsg->term = pSyncNode->pRaftStore->currentTerm;
- pRspMsg->lastIndex = pMsg->lastIndex;
- pRspMsg->lastTerm = pMsg->lastTerm;
- pRspMsg->ack = pReceiver->ack; // receiver maybe already closed
- pRspMsg->code = 0;
-
- // send msg
- SRpcMsg rpcMsg;
- syncSnapshotRsp2RpcMsg(pRspMsg, &rpcMsg);
- syncNodeSendMsgById(&(pRspMsg->destId), pSyncNode, &rpcMsg);
- syncSnapshotRspDestroy(pRspMsg);
}
+ if (pReceiver->startTime != pMsg->startTime) {
+ sNError(pSyncNode, "snapshot receiver time not equal");
+ return -1;
+ }
+
+ // start writer
+ snapshotReceiverStartWriter(pReceiver, pMsg);
+
+ // build msg
+ 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;
+ pRspMsg->lastIndex = pMsg->lastIndex;
+ pRspMsg->lastTerm = pMsg->lastTerm;
+ pRspMsg->startTime = pReceiver->startTime;
+ pRspMsg->ack = pReceiver->ack; // receiver maybe already closed
+ pRspMsg->code = 0;
+ pRspMsg->snapBeginIndex = pReceiver->snapshotParam.start;
+
+ // send msg
+ syncNodeSendMsgById(&pRspMsg->destId, pSyncNode, &rpcMsg);
+ syncLogSendSyncSnapshotRsp(pSyncNode, pRspMsg, "");
return 0;
}
-static int32_t syncNodeOnSnapshotTransfer(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) { return 0; }
+static int32_t syncNodeOnSnapshotTransfering(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
+ // condition 4
+ // transfering
+ SSyncSnapshotReceiver *pReceiver = pSyncNode->pNewNodeReceiver;
-static int32_t syncNodeOnSnapshotEnd(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) { return 0; }
+ // waiting for clock match
+ int64_t timeNow = taosGetTimestampMs();
+ while (timeNow < pMsg->startTime) {
+ sNTrace(pSyncNode, "snapshot receiver transfering waitting for true time, now:%" PRId64 ", stime:%" PRId64, timeNow,
+ pMsg->startTime);
+ taosMsleep(10);
+ }
+
+ if (pMsg->seq == pReceiver->ack + 1) {
+ snapshotReceiverGotData(pReceiver, pMsg);
+ }
+
+ // build msg
+ 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;
+ pRspMsg->lastIndex = pMsg->lastIndex;
+ pRspMsg->lastTerm = pMsg->lastTerm;
+ pRspMsg->startTime = pReceiver->startTime;
+ pRspMsg->ack = pReceiver->ack; // receiver maybe already closed
+ pRspMsg->code = 0;
+ pRspMsg->snapBeginIndex = pReceiver->snapshotParam.start;
+
+ // send msg
+ syncNodeSendMsgById(&pRspMsg->destId, pSyncNode, &rpcMsg);
+ syncLogSendSyncSnapshotRsp(pSyncNode, pRspMsg, "");
+ return 0;
+}
+
+static int32_t syncNodeOnSnapshotEnd(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
+ // condition 2
+ // end, finish FSM
+ SSyncSnapshotReceiver *pReceiver = pSyncNode->pNewNodeReceiver;
+
+ // waiting for clock match
+ int64_t timeNow = taosGetTimestampMs();
+ while (timeNow < pMsg->startTime) {
+ sNTrace(pSyncNode, "snapshot receiver finish waitting for true time, now:%" PRId64 ", stime:%" PRId64, timeNow,
+ pMsg->startTime);
+ taosMsleep(10);
+ }
+
+ int32_t code = snapshotReceiverFinish(pReceiver, pMsg);
+ if (code == 0) {
+ snapshotReceiverStop(pReceiver);
+ }
+
+ // build msg
+ 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;
+ pRspMsg->lastIndex = pMsg->lastIndex;
+ pRspMsg->lastTerm = pMsg->lastTerm;
+ pRspMsg->startTime = pReceiver->startTime;
+ pRspMsg->ack = pReceiver->ack; // receiver maybe already closed
+ pRspMsg->code = 0;
+ pRspMsg->snapBeginIndex = pReceiver->snapshotParam.start;
+
+ // send msg
+ syncNodeSendMsgById(&pRspMsg->destId, pSyncNode, &rpcMsg);
+ syncLogSendSyncSnapshotRsp(pSyncNode, pRspMsg, "");
+ return 0;
+}
// receiver on message
//
@@ -621,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");
@@ -641,6 +723,8 @@ int32_t syncNodeOnSnapshot(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
int32_t code = 0;
SSyncSnapshotReceiver *pReceiver = pSyncNode->pNewNodeReceiver;
+ syncLogRecvSyncSnapshotSend(pSyncNode, pMsg, "");
+
// state, term, seq/ack
if (pSyncNode->state == TAOS_SYNC_STATE_FOLLOWER) {
if (pMsg->term == pSyncNode->pRaftStore->currentTerm) {
@@ -651,39 +735,14 @@ int32_t syncNodeOnSnapshot(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
syncNodeOnSnapshotBegin(pSyncNode, pMsg);
} else if (pMsg->seq == SYNC_SNAPSHOT_SEQ_END) {
- // condition 2
- // end, finish FSM
- code = snapshotReceiverFinish(pReceiver, pMsg);
- if (code == 0) {
- snapshotReceiverStop(pReceiver);
- }
- bool needRsp = true;
-
- // maybe update lastconfig
- if (pMsg->lastConfigIndex >= SYNC_INDEX_BEGIN) {
- SSyncCfg oldSyncCfg = pSyncNode->pRaftCfg->cfg;
-
- // update new config myIndex
- SSyncCfg newSyncCfg = pMsg->lastConfig;
- syncNodeUpdateNewConfigIndex(pSyncNode, &newSyncCfg);
-
- // do config change
- syncNodeDoConfigChange(pSyncNode, &newSyncCfg, pMsg->lastConfigIndex);
- }
+ syncNodeOnSnapshotEnd(pSyncNode, pMsg);
} else if (pMsg->seq == SYNC_SNAPSHOT_SEQ_FORCE_CLOSE) {
- // condition 3
- // force close
+ // force close, no response
snapshotReceiverForceStop(pReceiver);
- bool needRsp = false;
} else if (pMsg->seq > SYNC_SNAPSHOT_SEQ_BEGIN && pMsg->seq < SYNC_SNAPSHOT_SEQ_END) {
- // condition 4
- // transfering
- if (pMsg->seq == pReceiver->ack + 1) {
- snapshotReceiverGotData(pReceiver, pMsg);
- }
- bool needRsp = true;
+ syncNodeOnSnapshotTransfering(pSyncNode, pMsg);
} else {
// error log
@@ -717,11 +776,17 @@ int32_t syncNodeOnSnapshotReplyPre(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg)
pSender->snapshotParam.start = pMsg->snapBeginIndex;
pSender->snapshotParam.end = snapshot.lastApplyIndex;
+ sNTrace(pSyncNode, "prepare snapshot, recv-begin:%" PRId64 ", snapshot.last:%" PRId64 ", snapshot.term:%" PRId64,
+ pMsg->snapBeginIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm);
+
if (pMsg->snapBeginIndex > snapshot.lastApplyIndex) {
sNError(pSyncNode, "snapshot last index too small");
return -1;
}
+ // update sender
+ pSender->snapshot = snapshot;
+
// start reader
int32_t code = pSyncNode->pFsm->FpSnapshotStartRead(pSyncNode->pFsm, &(pSender->snapshotParam), &(pSender->pReader));
if (code != 0) {
@@ -729,8 +794,17 @@ int32_t syncNodeOnSnapshotReplyPre(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg)
return -1;
}
+ // update next index
+ 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;
@@ -743,10 +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);
- syncSnapshotSendDestroy(pSendMsg);
+ syncNodeSendMsgById(&pSendMsg->destId, pSender->pSyncNode, &rpcMsg);
+ syncLogSendSyncSnapshotSend(pSyncNode, pSendMsg, "");
return 0;
}
@@ -757,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");
@@ -773,6 +847,8 @@ int32_t syncNodeOnSnapshotReply(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg) {
return -1;
}
+ syncLogRecvSyncSnapshotRsp(pSyncNode, pMsg, "");
+
// state, term, seq/ack
if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) {
if (pMsg->term == pSyncNode->pRaftStore->currentTerm) {
@@ -782,9 +858,20 @@ int32_t syncNodeOnSnapshotReply(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg) {
return 0;
}
+ if (pMsg->ack == SYNC_SNAPSHOT_SEQ_BEGIN) {
+ snapshotSenderUpdateProgress(pSender, pMsg);
+ snapshotSend(pSender);
+ return 0;
+ }
+
// receive ack is finish, close sender
if (pMsg->ack == SYNC_SNAPSHOT_SEQ_END) {
snapshotSenderStop(pSender, true);
+
+ // update next-index
+ syncIndexMgrSetIndex(pSyncNode->pNextIndex, &(pMsg->srcId), pMsg->lastIndex + 1);
+ syncNodeReplicateOne(pSyncNode, &(pMsg->srcId), false);
+
return 0;
}
@@ -816,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;
-}
\ No newline at end of file
diff --git a/source/libs/sync/src/syncTimeout.c b/source/libs/sync/src/syncTimeout.c
index 9bf2bb5697..3d4583aadb 100644
--- a/source/libs/sync/src/syncTimeout.c
+++ b/source/libs/sync/src/syncTimeout.c
@@ -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,7 +86,7 @@ static int32_t syncNodeTimerRoutine(SSyncNode* ths) {
return 0;
}
-int32_t syncNodeOnTimer(SSyncNode* ths, const SRpcMsg* pRpc) {
+int32_t syncNodeOnTimeout(SSyncNode* ths, const SRpcMsg* pRpc) {
int32_t ret = 0;
SyncTimeout* pMsg = pRpc->pCont;
diff --git a/source/libs/sync/src/syncUtil.c b/source/libs/sync/src/syncUtil.c
index 894aa05aad..b9a271ab9d 100644
--- a/source/libs/sync/src/syncUtil.c
+++ b/source/libs/sync/src/syncUtil.c
@@ -15,6 +15,7 @@
#define _DEFAULT_SOURCE
#include "syncUtil.h"
+#include "syncMessage.h"
#include "syncRaftCfg.h"
#include "syncRaftStore.h"
#include "syncSnapshot.h"
@@ -193,6 +194,7 @@ static void syncPeerState2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNode* pNode, const char* format, ...) {
if (pNode == NULL || pNode->pRaftCfg != NULL && pNode->pRaftStore == NULL || pNode->pLogStore == NULL) return;
+ int64_t currentTerm = pNode->pRaftStore->currentTerm;
// save error code, otherwise it will be overwritten
int32_t errCode = terrno;
@@ -234,8 +236,8 @@ void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNo
", tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", min:%" PRId64 ", snap:%" PRId64
", snap-tm:%" PRIu64 ", sby:%d, aq:%d, bch:%d, r-num:%d, lcfg:%" PRId64
", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s, %s",
- pNode->vgId, syncStr(pNode->state), eventLog, pNode->pRaftStore->currentTerm, pNode->commitIndex,
- logBeginIndex, logLastIndex, pNode->minMatchIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm,
+ pNode->vgId, syncStr(pNode->state), eventLog, currentTerm, pNode->commitIndex, logBeginIndex,
+ logLastIndex, pNode->minMatchIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm,
pNode->pRaftCfg->isStandBy, aqItems, pNode->pRaftCfg->batchSize, pNode->replicaNum,
pNode->pRaftCfg->lastConfigIndex, pNode->changing, pNode->restoreFinish, quorum,
pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser, peerStr, cfgStr);
@@ -345,3 +347,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, lsend-index:%" PRId64 ", match:%" PRId64 "}, %s",
+ host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->lastSendIndex, 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
+ ", lsend-index:%" PRId64 ", cmt:%" PRId64 ", datalen:%d}, %s",
+ host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, (pMsg->prevLogIndex + 1), 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);
+}
\ No newline at end of file
diff --git a/source/libs/sync/test/syncRespMgrTest.cpp b/source/libs/sync/test/syncRespMgrTest.cpp
index 8d709e8c81..b609ef1a0e 100644
--- a/source/libs/sync/test/syncRespMgrTest.cpp
+++ b/source/libs/sync/test/syncRespMgrTest.cpp
@@ -60,13 +60,13 @@ void syncRespMgrGetTest(uint64_t i) {
void syncRespMgrGetAndDelTest(uint64_t i) {
printf("------syncRespMgrGetAndDelTest-------%" PRIu64 "-- \n", i);
- // SRespStub stub;
- // int32_t ret = syncRespMgrGetAndDel(pMgr, i, &stub);
- // if (ret == 1) {
- // printStub(&stub);
- // } else if (ret == 0) {
- // printf("%" PRId64 " notFound \n", i);
- // }
+ SRpcHandleInfo stub;
+ int32_t ret = syncRespMgrGetAndDel(pMgr, i, &stub);
+ if (ret == 1) {
+ //printStub(&stub);
+ } else if (ret == 0) {
+ printf("%" PRId64 " notFound \n", i);
+ }
}
SSyncNode *createSyncNode() {
diff --git a/source/libs/sync/test/syncRpcMsgTest.cpp b/source/libs/sync/test/syncRpcMsgTest.cpp
index 3f66cd9d1c..5fb622d791 100644
--- a/source/libs/sync/test/syncRpcMsgTest.cpp
+++ b/source/libs/sync/test/syncRpcMsgTest.cpp
@@ -45,7 +45,7 @@ SyncClientRequest *createSyncClientRequest() {
strcpy((char *)rpcMsg.pCont, "hello rpc");
SRpcMsg clientRequestMsg;
- syncClientRequestBuildFromRpcMsg(&clientRequestMsg, &rpcMsg, 123, true, 1000);
+ syncBuildClientRequest(&clientRequestMsg, &rpcMsg, 123, true, 1000);
SyncClientRequest *pMsg = (SyncClientRequest *)taosMemoryMalloc(clientRequestMsg.contLen);
memcpy(pMsg->data, clientRequestMsg.pCont, clientRequestMsg.contLen);
return pMsg;
diff --git a/source/libs/sync/test/syncSnapshotTest.cpp b/source/libs/sync/test/syncSnapshotTest.cpp
index 15854eeca6..000348bf1b 100644
--- a/source/libs/sync/test/syncSnapshotTest.cpp
+++ b/source/libs/sync/test/syncSnapshotTest.cpp
@@ -154,7 +154,7 @@ SRpcMsg *step0() {
SyncClientRequest *step1(const SRpcMsg *pMsg) {
SRpcMsg clientRequestMsg;
- syncClientRequestBuildFromRpcMsg(&clientRequestMsg, pMsg, 123, true, 1000);
+ syncBuildClientRequest(&clientRequestMsg, pMsg, 123, true, 1000);
SyncClientRequest *pMsg2 = (SyncClientRequest *)taosMemoryMalloc(clientRequestMsg.contLen);
memcpy(pMsg2->data, clientRequestMsg.pCont, clientRequestMsg.contLen);
return pMsg2;
diff --git a/source/libs/sync/test/sync_test_lib/inc/syncIO.h b/source/libs/sync/test/sync_test_lib/inc/syncIO.h
index 2c5e19d863..19f896182e 100644
--- a/source/libs/sync/test/sync_test_lib/inc/syncIO.h
+++ b/source/libs/sync/test/sync_test_lib/inc/syncIO.h
@@ -36,6 +36,8 @@ extern "C" {
typedef struct SyncPing SyncPing;
typedef struct SyncPingReply SyncPingReply;
+extern bool gRaftDetailLog;
+
typedef struct SSyncIO {
STaosQueue *pMsgQ;
STaosQset *pQset;
diff --git a/source/libs/sync/test/sync_test_lib/inc/syncTest.h b/source/libs/sync/test/sync_test_lib/inc/syncTest.h
index b930367870..443d3a45d6 100644
--- a/source/libs/sync/test/sync_test_lib/inc/syncTest.h
+++ b/source/libs/sync/test/sync_test_lib/inc/syncTest.h
@@ -110,6 +110,7 @@ void logStoreSimpleLog2(char* s, SSyncLogStore* pLogStore);
cJSON* syncNode2Json(const SSyncNode* pSyncNode);
char* syncNode2Str(const SSyncNode* pSyncNode);
+char* syncNode2SimpleStr(const SSyncNode* pSyncNode);
cJSON* voteGranted2Json(SVotesGranted* pVotesGranted);
char* voteGranted2Str(SVotesGranted* pVotesGranted);
@@ -277,6 +278,204 @@ void syncRequestVoteReplyPrint2(char* s, const SyncRequestVoteReply* pMsg);
void syncRequestVoteReplyLog(const SyncRequestVoteReply* pMsg);
void syncRequestVoteReplyLog2(char* s, const SyncRequestVoteReply* pMsg);
+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);
+
+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);
+
+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);
+
+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);
+
+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);
+
+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);
+
+// ---------------------------------------------
+int32_t syncNodeOnPreSnapshot(SSyncNode* ths, SyncPreSnapshot* pMsg);
+int32_t syncNodeOnPreSnapshotReply(SSyncNode* ths, SyncPreSnapshotReply* pMsg);
+
+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);
+
+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);
+
+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);
+
+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);
+
+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);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/libs/sync/test/sync_test_lib/src/syncIO.c b/source/libs/sync/test/sync_test_lib/src/syncIO.c
index 14adc18c66..2c24451713 100644
--- a/source/libs/sync/test/sync_test_lib/src/syncIO.c
+++ b/source/libs/sync/test/sync_test_lib/src/syncIO.c
@@ -22,6 +22,7 @@
#include "ttimer.h"
#include "tutil.h"
+bool gRaftDetailLog = false;
SSyncIO *gSyncIO = NULL;
// local function ------------
diff --git a/source/libs/sync/test/sync_test_lib/src/syncMessageDebug.c b/source/libs/sync/test/sync_test_lib/src/syncMessageDebug.c
index ad8a019f0f..1ea7629601 100644
--- a/source/libs/sync/test/sync_test_lib/src/syncMessageDebug.c
+++ b/source/libs/sync/test/sync_test_lib/src/syncMessageDebug.c
@@ -1307,4 +1307,1601 @@ void syncRequestVoteReplyLog2(char* s, const SyncRequestVoteReply* pMsg) {
sTrace("syncRequestVoteReplyLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
taosMemoryFree(serialized);
}
+}
+
+// ---- message process SyncAppendEntries----
+SyncAppendEntries* syncAppendEntriesBuild(uint32_t dataLen, int32_t vgId) {
+ uint32_t bytes = sizeof(SyncAppendEntries) + dataLen;
+ SyncAppendEntries* pMsg = taosMemoryMalloc(bytes);
+ memset(pMsg, 0, bytes);
+ pMsg->bytes = bytes;
+ pMsg->vgId = vgId;
+ pMsg->msgType = TDMT_SYNC_APPEND_ENTRIES;
+ pMsg->dataLen = dataLen;
+ return pMsg;
+}
+
+void syncAppendEntriesDestroy(SyncAppendEntries* pMsg) {
+ if (pMsg != NULL) {
+ taosMemoryFree(pMsg);
+ }
+}
+
+void syncAppendEntriesSerialize(const SyncAppendEntries* pMsg, char* buf, uint32_t bufLen) {
+ ASSERT(pMsg->bytes <= bufLen);
+ memcpy(buf, pMsg, pMsg->bytes);
+}
+
+void syncAppendEntriesDeserialize(const char* buf, uint32_t len, SyncAppendEntries* pMsg) {
+ memcpy(pMsg, buf, len);
+ ASSERT(len == pMsg->bytes);
+ ASSERT(pMsg->bytes == sizeof(SyncAppendEntries) + pMsg->dataLen);
+}
+
+char* syncAppendEntriesSerialize2(const SyncAppendEntries* pMsg, uint32_t* len) {
+ char* buf = taosMemoryMalloc(pMsg->bytes);
+ ASSERT(buf != NULL);
+ syncAppendEntriesSerialize(pMsg, buf, pMsg->bytes);
+ if (len != NULL) {
+ *len = pMsg->bytes;
+ }
+ return buf;
+}
+
+SyncAppendEntries* syncAppendEntriesDeserialize2(const char* buf, uint32_t len) {
+ uint32_t bytes = *((uint32_t*)buf);
+ SyncAppendEntries* pMsg = taosMemoryMalloc(bytes);
+ ASSERT(pMsg != NULL);
+ syncAppendEntriesDeserialize(buf, len, pMsg);
+ ASSERT(len == pMsg->bytes);
+ return pMsg;
+}
+
+void syncAppendEntries2RpcMsg(const SyncAppendEntries* pMsg, SRpcMsg* pRpcMsg) {
+ memset(pRpcMsg, 0, sizeof(*pRpcMsg));
+ pRpcMsg->msgType = pMsg->msgType;
+ pRpcMsg->contLen = pMsg->bytes;
+ pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
+ syncAppendEntriesSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen);
+}
+
+void syncAppendEntriesFromRpcMsg(const SRpcMsg* pRpcMsg, SyncAppendEntries* pMsg) {
+ syncAppendEntriesDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
+}
+
+SyncAppendEntries* syncAppendEntriesFromRpcMsg2(const SRpcMsg* pRpcMsg) {
+ SyncAppendEntries* pMsg = syncAppendEntriesDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
+ ASSERT(pMsg != NULL);
+ return pMsg;
+}
+
+cJSON* syncAppendEntries2Json(const SyncAppendEntries* pMsg) {
+ char u64buf[128] = {0};
+ cJSON* pRoot = cJSON_CreateObject();
+
+ if (pMsg != NULL) {
+ cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
+ cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
+ cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
+
+ cJSON* pSrcId = cJSON_CreateObject();
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr);
+ cJSON_AddStringToObject(pSrcId, "addr", u64buf);
+ {
+ uint64_t u64 = pMsg->srcId.addr;
+ cJSON* pTmp = pSrcId;
+ char host[128] = {0};
+ uint16_t port;
+ syncUtilU642Addr(u64, host, sizeof(host), &port);
+ cJSON_AddStringToObject(pTmp, "addr_host", host);
+ cJSON_AddNumberToObject(pTmp, "addr_port", port);
+ }
+ cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
+ cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
+
+ cJSON* pDestId = cJSON_CreateObject();
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr);
+ cJSON_AddStringToObject(pDestId, "addr", u64buf);
+ {
+ uint64_t u64 = pMsg->destId.addr;
+ cJSON* pTmp = pDestId;
+ char host[128] = {0};
+ uint16_t port;
+ syncUtilU642Addr(u64, host, sizeof(host), &port);
+ cJSON_AddStringToObject(pTmp, "addr_host", host);
+ cJSON_AddNumberToObject(pTmp, "addr_port", port);
+ }
+ cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
+ cJSON_AddItemToObject(pRoot, "destId", pDestId);
+
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term);
+ cJSON_AddStringToObject(pRoot, "term", u64buf);
+
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->privateTerm);
+ cJSON_AddStringToObject(pRoot, "privateTerm", u64buf);
+
+ snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->prevLogIndex);
+ cJSON_AddStringToObject(pRoot, "prevLogIndex", u64buf);
+
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->prevLogTerm);
+ cJSON_AddStringToObject(pRoot, "pre_log_term", u64buf);
+
+ snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->commitIndex);
+ cJSON_AddStringToObject(pRoot, "commitIndex", u64buf);
+
+ cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
+ char* s;
+ s = syncUtilPrintBin((char*)(pMsg->data), pMsg->dataLen);
+ cJSON_AddStringToObject(pRoot, "data", s);
+ taosMemoryFree(s);
+ s = syncUtilPrintBin2((char*)(pMsg->data), pMsg->dataLen);
+ cJSON_AddStringToObject(pRoot, "data2", s);
+ taosMemoryFree(s);
+ }
+
+ cJSON* pJson = cJSON_CreateObject();
+ cJSON_AddItemToObject(pJson, "SyncAppendEntries", pRoot);
+ return pJson;
+}
+
+char* syncAppendEntries2Str(const SyncAppendEntries* pMsg) {
+ cJSON* pJson = syncAppendEntries2Json(pMsg);
+ char* serialized = cJSON_Print(pJson);
+ cJSON_Delete(pJson);
+ return serialized;
+}
+
+// for debug ----------------------
+void syncAppendEntriesPrint(const SyncAppendEntries* pMsg) {
+ char* serialized = syncAppendEntries2Str(pMsg);
+ printf("syncAppendEntriesPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
+ fflush(NULL);
+ taosMemoryFree(serialized);
+}
+
+void syncAppendEntriesPrint2(char* s, const SyncAppendEntries* pMsg) {
+ char* serialized = syncAppendEntries2Str(pMsg);
+ printf("syncAppendEntriesPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
+ fflush(NULL);
+ taosMemoryFree(serialized);
+}
+
+void syncAppendEntriesLog(const SyncAppendEntries* pMsg) {
+ char* serialized = syncAppendEntries2Str(pMsg);
+ sTrace("syncAppendEntriesLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
+ taosMemoryFree(serialized);
+}
+
+void syncAppendEntriesLog2(char* s, const SyncAppendEntries* pMsg) {
+ if (gRaftDetailLog) {
+ char* serialized = syncAppendEntries2Str(pMsg);
+ sTrace("syncAppendEntriesLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
+ taosMemoryFree(serialized);
+ }
+}
+
+// ---- message process SyncAppendEntriesReply----
+SyncAppendEntriesReply* syncAppendEntriesReplyBuild(int32_t vgId) {
+ uint32_t bytes = sizeof(SyncAppendEntriesReply);
+ SyncAppendEntriesReply* pMsg = taosMemoryMalloc(bytes);
+ memset(pMsg, 0, bytes);
+ pMsg->bytes = bytes;
+ pMsg->vgId = vgId;
+ pMsg->msgType = TDMT_SYNC_APPEND_ENTRIES_REPLY;
+ return pMsg;
+}
+
+void syncAppendEntriesReplyDestroy(SyncAppendEntriesReply* pMsg) {
+ if (pMsg != NULL) {
+ taosMemoryFree(pMsg);
+ }
+}
+
+void syncAppendEntriesReplySerialize(const SyncAppendEntriesReply* pMsg, char* buf, uint32_t bufLen) {
+ ASSERT(pMsg->bytes <= bufLen);
+ memcpy(buf, pMsg, pMsg->bytes);
+}
+
+void syncAppendEntriesReplyDeserialize(const char* buf, uint32_t len, SyncAppendEntriesReply* pMsg) {
+ memcpy(pMsg, buf, len);
+ ASSERT(len == pMsg->bytes);
+}
+
+char* syncAppendEntriesReplySerialize2(const SyncAppendEntriesReply* pMsg, uint32_t* len) {
+ char* buf = taosMemoryMalloc(pMsg->bytes);
+ ASSERT(buf != NULL);
+ syncAppendEntriesReplySerialize(pMsg, buf, pMsg->bytes);
+ if (len != NULL) {
+ *len = pMsg->bytes;
+ }
+ return buf;
+}
+
+SyncAppendEntriesReply* syncAppendEntriesReplyDeserialize2(const char* buf, uint32_t len) {
+ uint32_t bytes = *((uint32_t*)buf);
+ SyncAppendEntriesReply* pMsg = taosMemoryMalloc(bytes);
+ ASSERT(pMsg != NULL);
+ syncAppendEntriesReplyDeserialize(buf, len, pMsg);
+ ASSERT(len == pMsg->bytes);
+ return pMsg;
+}
+
+void syncAppendEntriesReply2RpcMsg(const SyncAppendEntriesReply* pMsg, SRpcMsg* pRpcMsg) {
+ memset(pRpcMsg, 0, sizeof(*pRpcMsg));
+ pRpcMsg->msgType = pMsg->msgType;
+ pRpcMsg->contLen = pMsg->bytes;
+ pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
+ syncAppendEntriesReplySerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen);
+}
+
+void syncAppendEntriesReplyFromRpcMsg(const SRpcMsg* pRpcMsg, SyncAppendEntriesReply* pMsg) {
+ syncAppendEntriesReplyDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
+}
+
+SyncAppendEntriesReply* syncAppendEntriesReplyFromRpcMsg2(const SRpcMsg* pRpcMsg) {
+ SyncAppendEntriesReply* pMsg = syncAppendEntriesReplyDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
+ ASSERT(pMsg != NULL);
+ return pMsg;
+}
+
+cJSON* syncAppendEntriesReply2Json(const SyncAppendEntriesReply* pMsg) {
+ char u64buf[128] = {0};
+ cJSON* pRoot = cJSON_CreateObject();
+
+ if (pMsg != NULL) {
+ cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
+ cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
+ cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
+
+ cJSON* pSrcId = cJSON_CreateObject();
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr);
+ cJSON_AddStringToObject(pSrcId, "addr", u64buf);
+ {
+ uint64_t u64 = pMsg->srcId.addr;
+ cJSON* pTmp = pSrcId;
+ char host[128] = {0};
+ uint16_t port;
+ syncUtilU642Addr(u64, host, sizeof(host), &port);
+ cJSON_AddStringToObject(pTmp, "addr_host", host);
+ cJSON_AddNumberToObject(pTmp, "addr_port", port);
+ }
+ cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
+ cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
+
+ cJSON* pDestId = cJSON_CreateObject();
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr);
+ cJSON_AddStringToObject(pDestId, "addr", u64buf);
+ {
+ uint64_t u64 = pMsg->destId.addr;
+ cJSON* pTmp = pDestId;
+ char host[128] = {0};
+ uint16_t port;
+ syncUtilU642Addr(u64, host, sizeof(host), &port);
+ cJSON_AddStringToObject(pTmp, "addr_host", host);
+ cJSON_AddNumberToObject(pTmp, "addr_port", port);
+ }
+ cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
+ cJSON_AddItemToObject(pRoot, "destId", pDestId);
+
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->privateTerm);
+ cJSON_AddStringToObject(pRoot, "privateTerm", u64buf);
+
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term);
+ cJSON_AddStringToObject(pRoot, "term", u64buf);
+ cJSON_AddNumberToObject(pRoot, "success", pMsg->success);
+ snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->matchIndex);
+ cJSON_AddStringToObject(pRoot, "matchIndex", u64buf);
+ snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->startTime);
+ cJSON_AddStringToObject(pRoot, "startTime", u64buf);
+ }
+
+ cJSON* pJson = cJSON_CreateObject();
+ cJSON_AddItemToObject(pJson, "SyncAppendEntriesReply", pRoot);
+ return pJson;
+}
+
+char* syncAppendEntriesReply2Str(const SyncAppendEntriesReply* pMsg) {
+ cJSON* pJson = syncAppendEntriesReply2Json(pMsg);
+ char* serialized = cJSON_Print(pJson);
+ cJSON_Delete(pJson);
+ return serialized;
+}
+
+// for debug ----------------------
+void syncAppendEntriesReplyPrint(const SyncAppendEntriesReply* pMsg) {
+ char* serialized = syncAppendEntriesReply2Str(pMsg);
+ printf("syncAppendEntriesReplyPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
+ fflush(NULL);
+ taosMemoryFree(serialized);
+}
+
+void syncAppendEntriesReplyPrint2(char* s, const SyncAppendEntriesReply* pMsg) {
+ char* serialized = syncAppendEntriesReply2Str(pMsg);
+ printf("syncAppendEntriesReplyPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
+ fflush(NULL);
+ taosMemoryFree(serialized);
+}
+
+void syncAppendEntriesReplyLog(const SyncAppendEntriesReply* pMsg) {
+ char* serialized = syncAppendEntriesReply2Str(pMsg);
+ sTrace("syncAppendEntriesReplyLog | len:%d| %s", (int32_t)strlen(serialized), serialized);
+ taosMemoryFree(serialized);
+}
+
+void syncAppendEntriesReplyLog2(char* s, const SyncAppendEntriesReply* pMsg) {
+ if (gRaftDetailLog) {
+ char* serialized = syncAppendEntriesReply2Str(pMsg);
+ sTrace("syncAppendEntriesReplyLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
+ taosMemoryFree(serialized);
+ }
+}
+
+// ---- message process SyncHeartbeat----
+SyncHeartbeat* syncHeartbeatBuild(int32_t vgId) {
+ uint32_t bytes = sizeof(SyncHeartbeat);
+ SyncHeartbeat* pMsg = taosMemoryMalloc(bytes);
+ memset(pMsg, 0, bytes);
+ pMsg->bytes = bytes;
+ pMsg->vgId = vgId;
+ pMsg->msgType = TDMT_SYNC_HEARTBEAT;
+ return pMsg;
+}
+
+void syncHeartbeatDestroy(SyncHeartbeat* pMsg) {
+ if (pMsg != NULL) {
+ taosMemoryFree(pMsg);
+ }
+}
+
+void syncHeartbeatSerialize(const SyncHeartbeat* pMsg, char* buf, uint32_t bufLen) {
+ ASSERT(pMsg->bytes <= bufLen);
+ memcpy(buf, pMsg, pMsg->bytes);
+}
+
+void syncHeartbeatDeserialize(const char* buf, uint32_t len, SyncHeartbeat* pMsg) {
+ memcpy(pMsg, buf, len);
+ ASSERT(len == pMsg->bytes);
+}
+
+char* syncHeartbeatSerialize2(const SyncHeartbeat* pMsg, uint32_t* len) {
+ char* buf = taosMemoryMalloc(pMsg->bytes);
+ ASSERT(buf != NULL);
+ syncHeartbeatSerialize(pMsg, buf, pMsg->bytes);
+ if (len != NULL) {
+ *len = pMsg->bytes;
+ }
+ return buf;
+}
+
+SyncHeartbeat* syncHeartbeatDeserialize2(const char* buf, uint32_t len) {
+ uint32_t bytes = *((uint32_t*)buf);
+ SyncHeartbeat* pMsg = taosMemoryMalloc(bytes);
+ ASSERT(pMsg != NULL);
+ syncHeartbeatDeserialize(buf, len, pMsg);
+ ASSERT(len == pMsg->bytes);
+ return pMsg;
+}
+
+void syncHeartbeat2RpcMsg(const SyncHeartbeat* pMsg, SRpcMsg* pRpcMsg) {
+ memset(pRpcMsg, 0, sizeof(*pRpcMsg));
+ pRpcMsg->msgType = pMsg->msgType;
+ pRpcMsg->contLen = pMsg->bytes;
+ pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
+ syncHeartbeatSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen);
+}
+
+void syncHeartbeatFromRpcMsg(const SRpcMsg* pRpcMsg, SyncHeartbeat* pMsg) {
+ syncHeartbeatDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
+}
+
+SyncHeartbeat* syncHeartbeatFromRpcMsg2(const SRpcMsg* pRpcMsg) {
+ SyncHeartbeat* pMsg = syncHeartbeatDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
+ ASSERT(pMsg != NULL);
+ return pMsg;
+}
+
+cJSON* syncHeartbeat2Json(const SyncHeartbeat* pMsg) {
+ char u64buf[128] = {0};
+ cJSON* pRoot = cJSON_CreateObject();
+
+ if (pMsg != NULL) {
+ cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
+ cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
+ cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
+
+ cJSON* pSrcId = cJSON_CreateObject();
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr);
+ cJSON_AddStringToObject(pSrcId, "addr", u64buf);
+ {
+ uint64_t u64 = pMsg->srcId.addr;
+ cJSON* pTmp = pSrcId;
+ char host[128] = {0};
+ uint16_t port;
+ syncUtilU642Addr(u64, host, sizeof(host), &port);
+ cJSON_AddStringToObject(pTmp, "addr_host", host);
+ cJSON_AddNumberToObject(pTmp, "addr_port", port);
+ }
+ cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
+ cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
+
+ cJSON* pDestId = cJSON_CreateObject();
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr);
+ cJSON_AddStringToObject(pDestId, "addr", u64buf);
+ {
+ uint64_t u64 = pMsg->destId.addr;
+ cJSON* pTmp = pDestId;
+ char host[128] = {0};
+ uint16_t port;
+ syncUtilU642Addr(u64, host, sizeof(host), &port);
+ cJSON_AddStringToObject(pTmp, "addr_host", host);
+ cJSON_AddNumberToObject(pTmp, "addr_port", port);
+ }
+ cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
+ cJSON_AddItemToObject(pRoot, "destId", pDestId);
+
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term);
+ cJSON_AddStringToObject(pRoot, "term", u64buf);
+
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->privateTerm);
+ cJSON_AddStringToObject(pRoot, "privateTerm", u64buf);
+
+ snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->commitIndex);
+ cJSON_AddStringToObject(pRoot, "commitIndex", u64buf);
+ }
+
+ cJSON* pJson = cJSON_CreateObject();
+ cJSON_AddItemToObject(pJson, "SyncHeartbeat", pRoot);
+ return pJson;
+}
+
+char* syncHeartbeat2Str(const SyncHeartbeat* pMsg) {
+ cJSON* pJson = syncHeartbeat2Json(pMsg);
+ char* serialized = cJSON_Print(pJson);
+ cJSON_Delete(pJson);
+ return serialized;
+}
+
+void syncHeartbeatPrint(const SyncHeartbeat* pMsg) {
+ char* serialized = syncHeartbeat2Str(pMsg);
+ printf("syncHeartbeatPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
+ fflush(NULL);
+ taosMemoryFree(serialized);
+}
+
+void syncHeartbeatPrint2(char* s, const SyncHeartbeat* pMsg) {
+ char* serialized = syncHeartbeat2Str(pMsg);
+ printf("syncHeartbeatPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
+ fflush(NULL);
+ taosMemoryFree(serialized);
+}
+
+void syncHeartbeatLog(const SyncHeartbeat* pMsg) {
+ char* serialized = syncHeartbeat2Str(pMsg);
+ sTrace("syncHeartbeatLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
+ taosMemoryFree(serialized);
+}
+
+void syncHeartbeatLog2(char* s, const SyncHeartbeat* pMsg) {
+ if (gRaftDetailLog) {
+ char* serialized = syncHeartbeat2Str(pMsg);
+ sTrace("syncHeartbeatLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
+ taosMemoryFree(serialized);
+ }
+}
+
+// ---- message process SyncHeartbeatReply----
+SyncHeartbeatReply* syncHeartbeatReplyBuild(int32_t vgId) {
+ uint32_t bytes = sizeof(SyncHeartbeatReply);
+ SyncHeartbeatReply* pMsg = taosMemoryMalloc(bytes);
+ memset(pMsg, 0, bytes);
+ pMsg->bytes = bytes;
+ pMsg->vgId = vgId;
+ pMsg->msgType = TDMT_SYNC_HEARTBEAT_REPLY;
+ return pMsg;
+}
+
+void syncHeartbeatReplyDestroy(SyncHeartbeatReply* pMsg) {
+ if (pMsg != NULL) {
+ taosMemoryFree(pMsg);
+ }
+}
+
+void syncHeartbeatReplySerialize(const SyncHeartbeatReply* pMsg, char* buf, uint32_t bufLen) {
+ ASSERT(pMsg->bytes <= bufLen);
+ memcpy(buf, pMsg, pMsg->bytes);
+}
+
+void syncHeartbeatReplyDeserialize(const char* buf, uint32_t len, SyncHeartbeatReply* pMsg) {
+ memcpy(pMsg, buf, len);
+ ASSERT(len == pMsg->bytes);
+}
+
+char* syncHeartbeatReplySerialize2(const SyncHeartbeatReply* pMsg, uint32_t* len) {
+ char* buf = taosMemoryMalloc(pMsg->bytes);
+ ASSERT(buf != NULL);
+ syncHeartbeatReplySerialize(pMsg, buf, pMsg->bytes);
+ if (len != NULL) {
+ *len = pMsg->bytes;
+ }
+ return buf;
+}
+
+SyncHeartbeatReply* syncHeartbeatReplyDeserialize2(const char* buf, uint32_t len) {
+ uint32_t bytes = *((uint32_t*)buf);
+ SyncHeartbeatReply* pMsg = taosMemoryMalloc(bytes);
+ ASSERT(pMsg != NULL);
+ syncHeartbeatReplyDeserialize(buf, len, pMsg);
+ ASSERT(len == pMsg->bytes);
+ return pMsg;
+}
+
+void syncHeartbeatReply2RpcMsg(const SyncHeartbeatReply* pMsg, SRpcMsg* pRpcMsg) {
+ memset(pRpcMsg, 0, sizeof(*pRpcMsg));
+ pRpcMsg->msgType = pMsg->msgType;
+ pRpcMsg->contLen = pMsg->bytes;
+ pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
+ syncHeartbeatReplySerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen);
+}
+
+void syncHeartbeatReplyFromRpcMsg(const SRpcMsg* pRpcMsg, SyncHeartbeatReply* pMsg) {
+ syncHeartbeatReplyDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
+}
+
+SyncHeartbeatReply* syncHeartbeatReplyFromRpcMsg2(const SRpcMsg* pRpcMsg) {
+ SyncHeartbeatReply* pMsg = syncHeartbeatReplyDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
+ ASSERT(pMsg != NULL);
+ return pMsg;
+}
+
+cJSON* syncHeartbeatReply2Json(const SyncHeartbeatReply* pMsg) {
+ char u64buf[128] = {0};
+ cJSON* pRoot = cJSON_CreateObject();
+
+ if (pMsg != NULL) {
+ cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
+ cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
+ cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
+
+ cJSON* pSrcId = cJSON_CreateObject();
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr);
+ cJSON_AddStringToObject(pSrcId, "addr", u64buf);
+ {
+ uint64_t u64 = pMsg->srcId.addr;
+ cJSON* pTmp = pSrcId;
+ char host[128] = {0};
+ uint16_t port;
+ syncUtilU642Addr(u64, host, sizeof(host), &port);
+ cJSON_AddStringToObject(pTmp, "addr_host", host);
+ cJSON_AddNumberToObject(pTmp, "addr_port", port);
+ }
+ cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
+ cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
+
+ cJSON* pDestId = cJSON_CreateObject();
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr);
+ cJSON_AddStringToObject(pDestId, "addr", u64buf);
+ {
+ uint64_t u64 = pMsg->destId.addr;
+ cJSON* pTmp = pDestId;
+ char host[128] = {0};
+ uint16_t port;
+ syncUtilU642Addr(u64, host, sizeof(host), &port);
+ cJSON_AddStringToObject(pTmp, "addr_host", host);
+ cJSON_AddNumberToObject(pTmp, "addr_port", port);
+ }
+ cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
+ cJSON_AddItemToObject(pRoot, "destId", pDestId);
+
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->privateTerm);
+ cJSON_AddStringToObject(pRoot, "privateTerm", u64buf);
+
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term);
+ cJSON_AddStringToObject(pRoot, "term", u64buf);
+
+ cJSON_AddStringToObject(pRoot, "matchIndex", u64buf);
+ snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->startTime);
+ cJSON_AddStringToObject(pRoot, "startTime", u64buf);
+ }
+
+ cJSON* pJson = cJSON_CreateObject();
+ cJSON_AddItemToObject(pJson, "SyncHeartbeatReply", pRoot);
+ return pJson;
+}
+
+char* syncHeartbeatReply2Str(const SyncHeartbeatReply* pMsg) {
+ cJSON* pJson = syncHeartbeatReply2Json(pMsg);
+ char* serialized = cJSON_Print(pJson);
+ cJSON_Delete(pJson);
+ return serialized;
+}
+
+void syncHeartbeatReplyPrint(const SyncHeartbeatReply* pMsg) {
+ char* serialized = syncHeartbeatReply2Str(pMsg);
+ printf("syncHeartbeatReplyPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
+ fflush(NULL);
+ taosMemoryFree(serialized);
+}
+
+void syncHeartbeatReplyPrint2(char* s, const SyncHeartbeatReply* pMsg) {
+ char* serialized = syncHeartbeatReply2Str(pMsg);
+ printf("syncHeartbeatReplyPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
+ fflush(NULL);
+ taosMemoryFree(serialized);
+}
+
+void syncHeartbeatReplyLog(const SyncHeartbeatReply* pMsg) {
+ char* serialized = syncHeartbeatReply2Str(pMsg);
+ sTrace("syncHeartbeatReplyLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
+ taosMemoryFree(serialized);
+}
+
+void syncHeartbeatReplyLog2(char* s, const SyncHeartbeatReply* pMsg) {
+ if (gRaftDetailLog) {
+ char* serialized = syncHeartbeatReply2Str(pMsg);
+ sTrace("syncHeartbeatReplyLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
+ taosMemoryFree(serialized);
+ }
+}
+
+// ---- message process SyncPreSnapshot----
+SyncPreSnapshot* syncPreSnapshotBuild(int32_t vgId) {
+ uint32_t bytes = sizeof(SyncPreSnapshot);
+ SyncPreSnapshot* pMsg = taosMemoryMalloc(bytes);
+ memset(pMsg, 0, bytes);
+ pMsg->bytes = bytes;
+ pMsg->vgId = vgId;
+ pMsg->msgType = TDMT_SYNC_PRE_SNAPSHOT;
+ return pMsg;
+}
+
+void syncPreSnapshotDestroy(SyncPreSnapshot* pMsg) {
+ if (pMsg != NULL) {
+ taosMemoryFree(pMsg);
+ }
+}
+
+void syncPreSnapshotSerialize(const SyncPreSnapshot* pMsg, char* buf, uint32_t bufLen) {
+ ASSERT(pMsg->bytes <= bufLen);
+ memcpy(buf, pMsg, pMsg->bytes);
+}
+
+void syncPreSnapshotDeserialize(const char* buf, uint32_t len, SyncPreSnapshot* pMsg) {
+ memcpy(pMsg, buf, len);
+ ASSERT(len == pMsg->bytes);
+}
+
+char* syncPreSnapshotSerialize2(const SyncPreSnapshot* pMsg, uint32_t* len) {
+ char* buf = taosMemoryMalloc(pMsg->bytes);
+ ASSERT(buf != NULL);
+ syncPreSnapshotSerialize(pMsg, buf, pMsg->bytes);
+ if (len != NULL) {
+ *len = pMsg->bytes;
+ }
+ return buf;
+}
+
+SyncPreSnapshot* syncPreSnapshotDeserialize2(const char* buf, uint32_t len) {
+ uint32_t bytes = *((uint32_t*)buf);
+ SyncPreSnapshot* pMsg = taosMemoryMalloc(bytes);
+ ASSERT(pMsg != NULL);
+ syncPreSnapshotDeserialize(buf, len, pMsg);
+ ASSERT(len == pMsg->bytes);
+ return pMsg;
+}
+
+void syncPreSnapshot2RpcMsg(const SyncPreSnapshot* pMsg, SRpcMsg* pRpcMsg) {
+ memset(pRpcMsg, 0, sizeof(*pRpcMsg));
+ pRpcMsg->msgType = pMsg->msgType;
+ pRpcMsg->contLen = pMsg->bytes;
+ pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
+ syncPreSnapshotSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen);
+}
+
+void syncPreSnapshotFromRpcMsg(const SRpcMsg* pRpcMsg, SyncPreSnapshot* pMsg) {
+ syncPreSnapshotDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
+}
+
+SyncPreSnapshot* syncPreSnapshotFromRpcMsg2(const SRpcMsg* pRpcMsg) {
+ SyncPreSnapshot* pMsg = syncPreSnapshotDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
+ ASSERT(pMsg != NULL);
+ return pMsg;
+}
+
+cJSON* syncPreSnapshot2Json(const SyncPreSnapshot* pMsg) {
+ char u64buf[128] = {0};
+ cJSON* pRoot = cJSON_CreateObject();
+
+ if (pMsg != NULL) {
+ cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
+ cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
+ cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
+
+ cJSON* pSrcId = cJSON_CreateObject();
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr);
+ cJSON_AddStringToObject(pSrcId, "addr", u64buf);
+ {
+ uint64_t u64 = pMsg->srcId.addr;
+ cJSON* pTmp = pSrcId;
+ char host[128] = {0};
+ uint16_t port;
+ syncUtilU642Addr(u64, host, sizeof(host), &port);
+ cJSON_AddStringToObject(pTmp, "addr_host", host);
+ cJSON_AddNumberToObject(pTmp, "addr_port", port);
+ }
+ cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
+ cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
+
+ cJSON* pDestId = cJSON_CreateObject();
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr);
+ cJSON_AddStringToObject(pDestId, "addr", u64buf);
+ {
+ uint64_t u64 = pMsg->destId.addr;
+ cJSON* pTmp = pDestId;
+ char host[128] = {0};
+ uint16_t port;
+ syncUtilU642Addr(u64, host, sizeof(host), &port);
+ cJSON_AddStringToObject(pTmp, "addr_host", host);
+ cJSON_AddNumberToObject(pTmp, "addr_port", port);
+ }
+ cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
+ cJSON_AddItemToObject(pRoot, "destId", pDestId);
+
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term);
+ cJSON_AddStringToObject(pRoot, "term", u64buf);
+ }
+
+ cJSON* pJson = cJSON_CreateObject();
+ cJSON_AddItemToObject(pJson, "SyncPreSnapshot", pRoot);
+ return pJson;
+}
+
+char* syncPreSnapshot2Str(const SyncPreSnapshot* pMsg) {
+ cJSON* pJson = syncPreSnapshot2Json(pMsg);
+ char* serialized = cJSON_Print(pJson);
+ cJSON_Delete(pJson);
+ return serialized;
+}
+
+void syncPreSnapshotPrint(const SyncPreSnapshot* pMsg) {
+ char* serialized = syncPreSnapshot2Str(pMsg);
+ printf("syncPreSnapshotPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
+ fflush(NULL);
+ taosMemoryFree(serialized);
+}
+
+void syncPreSnapshotPrint2(char* s, const SyncPreSnapshot* pMsg) {
+ char* serialized = syncPreSnapshot2Str(pMsg);
+ printf("syncPreSnapshotPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
+ fflush(NULL);
+ taosMemoryFree(serialized);
+}
+
+void syncPreSnapshotLog(const SyncPreSnapshot* pMsg) {
+ char* serialized = syncPreSnapshot2Str(pMsg);
+ sTrace("syncPreSnapshotLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
+ taosMemoryFree(serialized);
+}
+
+void syncPreSnapshotLog2(char* s, const SyncPreSnapshot* pMsg) {
+ if (gRaftDetailLog) {
+ char* serialized = syncPreSnapshot2Str(pMsg);
+ sTrace("syncPreSnapshotLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
+ taosMemoryFree(serialized);
+ }
+}
+
+// ---- message process SyncPreSnapshotReply----
+SyncPreSnapshotReply* syncPreSnapshotReplyBuild(int32_t vgId) {
+ uint32_t bytes = sizeof(SyncPreSnapshotReply);
+ SyncPreSnapshotReply* pMsg = taosMemoryMalloc(bytes);
+ memset(pMsg, 0, bytes);
+ pMsg->bytes = bytes;
+ pMsg->vgId = vgId;
+ pMsg->msgType = TDMT_SYNC_PRE_SNAPSHOT_REPLY;
+ return pMsg;
+}
+
+void syncPreSnapshotReplyDestroy(SyncPreSnapshotReply* pMsg) {
+ if (pMsg != NULL) {
+ taosMemoryFree(pMsg);
+ }
+}
+
+void syncPreSnapshotReplySerialize(const SyncPreSnapshotReply* pMsg, char* buf, uint32_t bufLen) {
+ ASSERT(pMsg->bytes <= bufLen);
+ memcpy(buf, pMsg, pMsg->bytes);
+}
+
+void syncPreSnapshotReplyDeserialize(const char* buf, uint32_t len, SyncPreSnapshotReply* pMsg) {
+ memcpy(pMsg, buf, len);
+ ASSERT(len == pMsg->bytes);
+}
+
+char* syncPreSnapshotReplySerialize2(const SyncPreSnapshotReply* pMsg, uint32_t* len) {
+ char* buf = taosMemoryMalloc(pMsg->bytes);
+ ASSERT(buf != NULL);
+ syncPreSnapshotReplySerialize(pMsg, buf, pMsg->bytes);
+ if (len != NULL) {
+ *len = pMsg->bytes;
+ }
+ return buf;
+}
+
+SyncPreSnapshotReply* syncPreSnapshotReplyDeserialize2(const char* buf, uint32_t len) {
+ uint32_t bytes = *((uint32_t*)buf);
+ SyncPreSnapshotReply* pMsg = taosMemoryMalloc(bytes);
+ ASSERT(pMsg != NULL);
+ syncPreSnapshotReplyDeserialize(buf, len, pMsg);
+ ASSERT(len == pMsg->bytes);
+ return pMsg;
+}
+
+void syncPreSnapshotReply2RpcMsg(const SyncPreSnapshotReply* pMsg, SRpcMsg* pRpcMsg) {
+ memset(pRpcMsg, 0, sizeof(*pRpcMsg));
+ pRpcMsg->msgType = pMsg->msgType;
+ pRpcMsg->contLen = pMsg->bytes;
+ pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
+ syncPreSnapshotReplySerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen);
+}
+
+void syncPreSnapshotReplyFromRpcMsg(const SRpcMsg* pRpcMsg, SyncPreSnapshotReply* pMsg) {
+ syncPreSnapshotReplyDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
+}
+
+SyncPreSnapshotReply* syncPreSnapshotReplyFromRpcMsg2(const SRpcMsg* pRpcMsg) {
+ SyncPreSnapshotReply* pMsg = syncPreSnapshotReplyDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
+ ASSERT(pMsg != NULL);
+ return pMsg;
+}
+
+cJSON* syncPreSnapshotReply2Json(const SyncPreSnapshotReply* pMsg) {
+ char u64buf[128] = {0};
+ cJSON* pRoot = cJSON_CreateObject();
+
+ if (pMsg != NULL) {
+ cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
+ cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
+ cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
+
+ cJSON* pSrcId = cJSON_CreateObject();
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr);
+ cJSON_AddStringToObject(pSrcId, "addr", u64buf);
+ {
+ uint64_t u64 = pMsg->srcId.addr;
+ cJSON* pTmp = pSrcId;
+ char host[128] = {0};
+ uint16_t port;
+ syncUtilU642Addr(u64, host, sizeof(host), &port);
+ cJSON_AddStringToObject(pTmp, "addr_host", host);
+ cJSON_AddNumberToObject(pTmp, "addr_port", port);
+ }
+ cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
+ cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
+
+ cJSON* pDestId = cJSON_CreateObject();
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr);
+ cJSON_AddStringToObject(pDestId, "addr", u64buf);
+ {
+ uint64_t u64 = pMsg->destId.addr;
+ cJSON* pTmp = pDestId;
+ char host[128] = {0};
+ uint16_t port;
+ syncUtilU642Addr(u64, host, sizeof(host), &port);
+ cJSON_AddStringToObject(pTmp, "addr_host", host);
+ cJSON_AddNumberToObject(pTmp, "addr_port", port);
+ }
+ cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
+ cJSON_AddItemToObject(pRoot, "destId", pDestId);
+
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term);
+ cJSON_AddStringToObject(pRoot, "term", u64buf);
+
+ snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->snapStart);
+ cJSON_AddStringToObject(pRoot, "snap-start", u64buf);
+ }
+
+ cJSON* pJson = cJSON_CreateObject();
+ cJSON_AddItemToObject(pJson, "SyncPreSnapshotReply", pRoot);
+ return pJson;
+}
+
+char* syncPreSnapshotReply2Str(const SyncPreSnapshotReply* pMsg) {
+ cJSON* pJson = syncPreSnapshotReply2Json(pMsg);
+ char* serialized = cJSON_Print(pJson);
+ cJSON_Delete(pJson);
+ return serialized;
+}
+
+void syncPreSnapshotReplyPrint(const SyncPreSnapshotReply* pMsg) {
+ char* serialized = syncPreSnapshotReply2Str(pMsg);
+ printf("syncPreSnapshotReplyPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
+ fflush(NULL);
+ taosMemoryFree(serialized);
+}
+
+void syncPreSnapshotReplyPrint2(char* s, const SyncPreSnapshotReply* pMsg) {
+ char* serialized = syncPreSnapshotReply2Str(pMsg);
+ printf("syncPreSnapshotReplyPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
+ fflush(NULL);
+ taosMemoryFree(serialized);
+}
+
+void syncPreSnapshotReplyLog(const SyncPreSnapshotReply* pMsg) {
+ char* serialized = syncPreSnapshotReply2Str(pMsg);
+ sTrace("syncPreSnapshotReplyLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
+ taosMemoryFree(serialized);
+}
+
+void syncPreSnapshotReplyLog2(char* s, const SyncPreSnapshotReply* pMsg) {
+ if (gRaftDetailLog) {
+ char* serialized = syncPreSnapshotReply2Str(pMsg);
+ sTrace("syncPreSnapshotReplyLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
+ taosMemoryFree(serialized);
+ }
+}
+
+// ---- message process SyncApplyMsg----
+SyncApplyMsg* syncApplyMsgBuild(uint32_t dataLen) {
+ uint32_t bytes = sizeof(SyncApplyMsg) + dataLen;
+ SyncApplyMsg* pMsg = taosMemoryMalloc(bytes);
+ memset(pMsg, 0, bytes);
+ pMsg->bytes = bytes;
+ pMsg->msgType = TDMT_SYNC_APPLY_MSG;
+ pMsg->dataLen = dataLen;
+ return pMsg;
+}
+
+SyncApplyMsg* syncApplyMsgBuild2(const SRpcMsg* pOriginalRpcMsg, int32_t vgId, SFsmCbMeta* pMeta) {
+ SyncApplyMsg* pMsg = syncApplyMsgBuild(pOriginalRpcMsg->contLen);
+ pMsg->vgId = vgId;
+ pMsg->originalRpcType = pOriginalRpcMsg->msgType;
+ pMsg->fsmMeta = *pMeta;
+ memcpy(pMsg->data, pOriginalRpcMsg->pCont, pOriginalRpcMsg->contLen);
+ return pMsg;
+}
+
+void syncApplyMsgDestroy(SyncApplyMsg* pMsg) {
+ if (pMsg != NULL) {
+ taosMemoryFree(pMsg);
+ }
+}
+
+void syncApplyMsgSerialize(const SyncApplyMsg* pMsg, char* buf, uint32_t bufLen) {
+ ASSERT(pMsg->bytes <= bufLen);
+ memcpy(buf, pMsg, pMsg->bytes);
+}
+
+void syncApplyMsgDeserialize(const char* buf, uint32_t len, SyncApplyMsg* pMsg) {
+ memcpy(pMsg, buf, len);
+ ASSERT(len == pMsg->bytes);
+}
+
+char* syncApplyMsgSerialize2(const SyncApplyMsg* pMsg, uint32_t* len) {
+ char* buf = taosMemoryMalloc(pMsg->bytes);
+ ASSERT(buf != NULL);
+ syncApplyMsgSerialize(pMsg, buf, pMsg->bytes);
+ if (len != NULL) {
+ *len = pMsg->bytes;
+ }
+ return buf;
+}
+
+SyncApplyMsg* syncApplyMsgDeserialize2(const char* buf, uint32_t len) {
+ uint32_t bytes = *((uint32_t*)buf);
+ SyncApplyMsg* pMsg = taosMemoryMalloc(bytes);
+ ASSERT(pMsg != NULL);
+ syncApplyMsgDeserialize(buf, len, pMsg);
+ ASSERT(len == pMsg->bytes);
+ return pMsg;
+}
+
+// SyncApplyMsg to SRpcMsg, put it into ApplyQ
+void syncApplyMsg2RpcMsg(const SyncApplyMsg* pMsg, SRpcMsg* pRpcMsg) {
+ memset(pRpcMsg, 0, sizeof(*pRpcMsg));
+ pRpcMsg->msgType = pMsg->msgType;
+ pRpcMsg->contLen = pMsg->bytes;
+ pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
+ syncApplyMsgSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen);
+}
+
+// get SRpcMsg from ApplyQ, to SyncApplyMsg
+void syncApplyMsgFromRpcMsg(const SRpcMsg* pRpcMsg, SyncApplyMsg* pMsg) {
+ syncApplyMsgDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
+}
+
+SyncApplyMsg* syncApplyMsgFromRpcMsg2(const SRpcMsg* pRpcMsg) {
+ SyncApplyMsg* pMsg = syncApplyMsgDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
+ return pMsg;
+}
+
+// SyncApplyMsg to OriginalRpcMsg
+void syncApplyMsg2OriginalRpcMsg(const SyncApplyMsg* pMsg, SRpcMsg* pOriginalRpcMsg) {
+ memset(pOriginalRpcMsg, 0, sizeof(*pOriginalRpcMsg));
+ pOriginalRpcMsg->msgType = pMsg->originalRpcType;
+ pOriginalRpcMsg->contLen = pMsg->dataLen;
+ pOriginalRpcMsg->pCont = rpcMallocCont(pOriginalRpcMsg->contLen);
+ memcpy(pOriginalRpcMsg->pCont, pMsg->data, pOriginalRpcMsg->contLen);
+}
+
+cJSON* syncApplyMsg2Json(const SyncApplyMsg* pMsg) {
+ char u64buf[128] = {0};
+ cJSON* pRoot = cJSON_CreateObject();
+
+ if (pMsg != NULL) {
+ cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
+ cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
+ cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
+ cJSON_AddNumberToObject(pRoot, "originalRpcType", pMsg->originalRpcType);
+
+ snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->fsmMeta.index);
+ cJSON_AddStringToObject(pRoot, "fsmMeta.index", u64buf);
+ cJSON_AddNumberToObject(pRoot, "fsmMeta.isWeak", pMsg->fsmMeta.isWeak);
+ cJSON_AddNumberToObject(pRoot, "fsmMeta.code", pMsg->fsmMeta.code);
+ cJSON_AddNumberToObject(pRoot, "fsmMeta.state", pMsg->fsmMeta.state);
+ cJSON_AddStringToObject(pRoot, "fsmMeta.state.str", syncStr(pMsg->fsmMeta.state));
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->fsmMeta.seqNum);
+ cJSON_AddStringToObject(pRoot, "fsmMeta.seqNum", u64buf);
+
+ cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
+ char* s;
+ s = syncUtilPrintBin((char*)(pMsg->data), pMsg->dataLen);
+ cJSON_AddStringToObject(pRoot, "data", s);
+ taosMemoryFree(s);
+ s = syncUtilPrintBin2((char*)(pMsg->data), pMsg->dataLen);
+ cJSON_AddStringToObject(pRoot, "data2", s);
+ taosMemoryFree(s);
+ }
+
+ cJSON* pJson = cJSON_CreateObject();
+ cJSON_AddItemToObject(pJson, "SyncApplyMsg", pRoot);
+ return pJson;
+}
+
+char* syncApplyMsg2Str(const SyncApplyMsg* pMsg) {
+ cJSON* pJson = syncApplyMsg2Json(pMsg);
+ char* serialized = cJSON_Print(pJson);
+ cJSON_Delete(pJson);
+ return serialized;
+}
+
+// for debug ----------------------
+void syncApplyMsgPrint(const SyncApplyMsg* pMsg) {
+ char* serialized = syncApplyMsg2Str(pMsg);
+ printf("syncApplyMsgPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
+ fflush(NULL);
+ taosMemoryFree(serialized);
+}
+
+void syncApplyMsgPrint2(char* s, const SyncApplyMsg* pMsg) {
+ char* serialized = syncApplyMsg2Str(pMsg);
+ printf("syncApplyMsgPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
+ fflush(NULL);
+ taosMemoryFree(serialized);
+}
+
+void syncApplyMsgLog(const SyncApplyMsg* pMsg) {
+ char* serialized = syncApplyMsg2Str(pMsg);
+ sTrace("ssyncApplyMsgLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
+ taosMemoryFree(serialized);
+}
+
+void syncApplyMsgLog2(char* s, const SyncApplyMsg* pMsg) {
+ if (gRaftDetailLog) {
+ char* serialized = syncApplyMsg2Str(pMsg);
+ sTrace("syncApplyMsgLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
+ taosMemoryFree(serialized);
+ }
+}
+
+// ---------------------------------------------
+SyncSnapshotSend* syncSnapshotSendBuild(uint32_t dataLen, int32_t vgId) {
+ uint32_t bytes = sizeof(SyncSnapshotSend) + dataLen;
+ SyncSnapshotSend* pMsg = taosMemoryMalloc(bytes);
+ memset(pMsg, 0, bytes);
+ pMsg->bytes = bytes;
+ pMsg->vgId = vgId;
+ pMsg->msgType = TDMT_SYNC_SNAPSHOT_SEND;
+ pMsg->dataLen = dataLen;
+ return pMsg;
+}
+
+void syncSnapshotSendDestroy(SyncSnapshotSend* pMsg) {
+ if (pMsg != NULL) {
+ taosMemoryFree(pMsg);
+ }
+}
+
+void syncSnapshotSendSerialize(const SyncSnapshotSend* pMsg, char* buf, uint32_t bufLen) {
+ ASSERT(pMsg->bytes <= bufLen);
+ memcpy(buf, pMsg, pMsg->bytes);
+}
+
+void syncSnapshotSendDeserialize(const char* buf, uint32_t len, SyncSnapshotSend* pMsg) {
+ memcpy(pMsg, buf, len);
+ ASSERT(len == pMsg->bytes);
+ ASSERT(pMsg->bytes == sizeof(SyncSnapshotSend) + pMsg->dataLen);
+}
+
+char* syncSnapshotSendSerialize2(const SyncSnapshotSend* pMsg, uint32_t* len) {
+ char* buf = taosMemoryMalloc(pMsg->bytes);
+ ASSERT(buf != NULL);
+ syncSnapshotSendSerialize(pMsg, buf, pMsg->bytes);
+ if (len != NULL) {
+ *len = pMsg->bytes;
+ }
+ return buf;
+}
+
+SyncSnapshotSend* syncSnapshotSendDeserialize2(const char* buf, uint32_t len) {
+ uint32_t bytes = *((uint32_t*)buf);
+ SyncSnapshotSend* pMsg = taosMemoryMalloc(bytes);
+ ASSERT(pMsg != NULL);
+ syncSnapshotSendDeserialize(buf, len, pMsg);
+ ASSERT(len == pMsg->bytes);
+ return pMsg;
+}
+
+void syncSnapshotSend2RpcMsg(const SyncSnapshotSend* pMsg, SRpcMsg* pRpcMsg) {
+ memset(pRpcMsg, 0, sizeof(*pRpcMsg));
+ pRpcMsg->msgType = pMsg->msgType;
+ pRpcMsg->contLen = pMsg->bytes;
+ pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
+ syncSnapshotSendSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen);
+}
+
+void syncSnapshotSendFromRpcMsg(const SRpcMsg* pRpcMsg, SyncSnapshotSend* pMsg) {
+ syncSnapshotSendDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
+}
+
+SyncSnapshotSend* syncSnapshotSendFromRpcMsg2(const SRpcMsg* pRpcMsg) {
+ SyncSnapshotSend* pMsg = syncSnapshotSendDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
+ ASSERT(pMsg != NULL);
+ return pMsg;
+}
+
+SyncSnapshotRsp* syncSnapshotRspBuild(int32_t vgId) {
+ uint32_t bytes = sizeof(SyncSnapshotRsp);
+ SyncSnapshotRsp* pMsg = taosMemoryMalloc(bytes);
+ memset(pMsg, 0, bytes);
+ pMsg->bytes = bytes;
+ pMsg->vgId = vgId;
+ pMsg->msgType = TDMT_SYNC_SNAPSHOT_RSP;
+ return pMsg;
+}
+
+void syncSnapshotRspDestroy(SyncSnapshotRsp* pMsg) {
+ if (pMsg != NULL) {
+ taosMemoryFree(pMsg);
+ }
+}
+
+void syncSnapshotRspSerialize(const SyncSnapshotRsp* pMsg, char* buf, uint32_t bufLen) {
+ ASSERT(pMsg->bytes <= bufLen);
+ memcpy(buf, pMsg, pMsg->bytes);
+}
+
+void syncSnapshotRspDeserialize(const char* buf, uint32_t len, SyncSnapshotRsp* pMsg) {
+ memcpy(pMsg, buf, len);
+ ASSERT(len == pMsg->bytes);
+}
+
+char* syncSnapshotRspSerialize2(const SyncSnapshotRsp* pMsg, uint32_t* len) {
+ char* buf = taosMemoryMalloc(pMsg->bytes);
+ ASSERT(buf != NULL);
+ syncSnapshotRspSerialize(pMsg, buf, pMsg->bytes);
+ if (len != NULL) {
+ *len = pMsg->bytes;
+ }
+ return buf;
+}
+
+SyncSnapshotRsp* syncSnapshotRspDeserialize2(const char* buf, uint32_t len) {
+ uint32_t bytes = *((uint32_t*)buf);
+ SyncSnapshotRsp* pMsg = taosMemoryMalloc(bytes);
+ ASSERT(pMsg != NULL);
+ syncSnapshotRspDeserialize(buf, len, pMsg);
+ ASSERT(len == pMsg->bytes);
+ return pMsg;
+}
+
+void syncSnapshotRsp2RpcMsg(const SyncSnapshotRsp* pMsg, SRpcMsg* pRpcMsg) {
+ memset(pRpcMsg, 0, sizeof(*pRpcMsg));
+ pRpcMsg->msgType = pMsg->msgType;
+ pRpcMsg->contLen = pMsg->bytes;
+ pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
+ syncSnapshotRspSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen);
+}
+
+void syncSnapshotRspFromRpcMsg(const SRpcMsg* pRpcMsg, SyncSnapshotRsp* pMsg) {
+ syncSnapshotRspDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
+}
+
+SyncSnapshotRsp* syncSnapshotRspFromRpcMsg2(const SRpcMsg* pRpcMsg) {
+ SyncSnapshotRsp* pMsg = syncSnapshotRspDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
+ ASSERT(pMsg != NULL);
+ return pMsg;
+}
+
+cJSON* syncSnapshotRsp2Json(const SyncSnapshotRsp* pMsg) {
+ char u64buf[128];
+ cJSON* pRoot = cJSON_CreateObject();
+
+ if (pMsg != NULL) {
+ cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
+ cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
+ cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
+
+ cJSON* pSrcId = cJSON_CreateObject();
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr);
+ cJSON_AddStringToObject(pSrcId, "addr", u64buf);
+ {
+ uint64_t u64 = pMsg->srcId.addr;
+ cJSON* pTmp = pSrcId;
+ char host[128];
+ uint16_t port;
+ syncUtilU642Addr(u64, host, sizeof(host), &port);
+ cJSON_AddStringToObject(pTmp, "addr_host", host);
+ cJSON_AddNumberToObject(pTmp, "addr_port", port);
+ }
+ cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
+ cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
+
+ cJSON* pDestId = cJSON_CreateObject();
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr);
+ cJSON_AddStringToObject(pDestId, "addr", u64buf);
+ {
+ uint64_t u64 = pMsg->destId.addr;
+ cJSON* pTmp = pDestId;
+ char host[128];
+ uint16_t port;
+ syncUtilU642Addr(u64, host, sizeof(host), &port);
+ cJSON_AddStringToObject(pTmp, "addr_host", host);
+ cJSON_AddNumberToObject(pTmp, "addr_port", port);
+ }
+ cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
+ cJSON_AddItemToObject(pRoot, "destId", pDestId);
+
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term);
+ cJSON_AddStringToObject(pRoot, "term", u64buf);
+
+ snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->startTime);
+ cJSON_AddStringToObject(pRoot, "startTime", u64buf);
+
+ snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->lastIndex);
+ cJSON_AddStringToObject(pRoot, "lastIndex", u64buf);
+
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->lastTerm);
+ cJSON_AddStringToObject(pRoot, "lastTerm", u64buf);
+
+ cJSON_AddNumberToObject(pRoot, "ack", pMsg->ack);
+ cJSON_AddNumberToObject(pRoot, "code", pMsg->code);
+
+ snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->snapBeginIndex);
+ cJSON_AddStringToObject(pRoot, "snap-begin", u64buf);
+ }
+
+ cJSON* pJson = cJSON_CreateObject();
+ cJSON_AddItemToObject(pJson, "SyncSnapshotRsp", pRoot);
+ return pJson;
+}
+
+char* syncSnapshotRsp2Str(const SyncSnapshotRsp* pMsg) {
+ cJSON* pJson = syncSnapshotRsp2Json(pMsg);
+ char* serialized = cJSON_Print(pJson);
+ cJSON_Delete(pJson);
+ return serialized;
+}
+
+// for debug ----------------------
+void syncSnapshotRspPrint(const SyncSnapshotRsp* pMsg) {
+ char* serialized = syncSnapshotRsp2Str(pMsg);
+ printf("syncSnapshotRspPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
+ fflush(NULL);
+ taosMemoryFree(serialized);
+}
+
+void syncSnapshotRspPrint2(char* s, const SyncSnapshotRsp* pMsg) {
+ char* serialized = syncSnapshotRsp2Str(pMsg);
+ printf("syncSnapshotRspPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
+ fflush(NULL);
+ taosMemoryFree(serialized);
+}
+
+void syncSnapshotRspLog(const SyncSnapshotRsp* pMsg) {
+ char* serialized = syncSnapshotRsp2Str(pMsg);
+ sTrace("syncSnapshotRspLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
+ taosMemoryFree(serialized);
+}
+
+void syncSnapshotRspLog2(char* s, const SyncSnapshotRsp* pMsg) {
+ if (gRaftDetailLog) {
+ char* serialized = syncSnapshotRsp2Str(pMsg);
+ sTrace("syncSnapshotRspLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
+ taosMemoryFree(serialized);
+ }
+}
+
+// ---------------------------------------------
+SyncLeaderTransfer* syncLeaderTransferBuild(int32_t vgId) {
+ uint32_t bytes = sizeof(SyncLeaderTransfer);
+ SyncLeaderTransfer* pMsg = taosMemoryMalloc(bytes);
+ memset(pMsg, 0, bytes);
+ pMsg->bytes = bytes;
+ pMsg->vgId = vgId;
+ pMsg->msgType = TDMT_SYNC_LEADER_TRANSFER;
+ return pMsg;
+}
+
+void syncLeaderTransferDestroy(SyncLeaderTransfer* pMsg) {
+ if (pMsg != NULL) {
+ taosMemoryFree(pMsg);
+ }
+}
+
+void syncLeaderTransferSerialize(const SyncLeaderTransfer* pMsg, char* buf, uint32_t bufLen) {
+ ASSERT(pMsg->bytes <= bufLen);
+ memcpy(buf, pMsg, pMsg->bytes);
+}
+
+void syncLeaderTransferDeserialize(const char* buf, uint32_t len, SyncLeaderTransfer* pMsg) {
+ memcpy(pMsg, buf, len);
+ ASSERT(len == pMsg->bytes);
+}
+
+char* syncLeaderTransferSerialize2(const SyncLeaderTransfer* pMsg, uint32_t* len) {
+ char* buf = taosMemoryMalloc(pMsg->bytes);
+ ASSERT(buf != NULL);
+ syncLeaderTransferSerialize(pMsg, buf, pMsg->bytes);
+ if (len != NULL) {
+ *len = pMsg->bytes;
+ }
+ return buf;
+}
+
+SyncLeaderTransfer* syncLeaderTransferDeserialize2(const char* buf, uint32_t len) {
+ uint32_t bytes = *((uint32_t*)buf);
+ SyncLeaderTransfer* pMsg = taosMemoryMalloc(bytes);
+ ASSERT(pMsg != NULL);
+ syncLeaderTransferDeserialize(buf, len, pMsg);
+ ASSERT(len == pMsg->bytes);
+ return pMsg;
+}
+
+void syncLeaderTransfer2RpcMsg(const SyncLeaderTransfer* pMsg, SRpcMsg* pRpcMsg) {
+ memset(pRpcMsg, 0, sizeof(*pRpcMsg));
+ pRpcMsg->msgType = pMsg->msgType;
+ pRpcMsg->contLen = pMsg->bytes;
+ pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
+ syncLeaderTransferSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen);
+}
+
+void syncLeaderTransferFromRpcMsg(const SRpcMsg* pRpcMsg, SyncLeaderTransfer* pMsg) {
+ syncLeaderTransferDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
+}
+
+SyncLeaderTransfer* syncLeaderTransferFromRpcMsg2(const SRpcMsg* pRpcMsg) {
+ SyncLeaderTransfer* pMsg = syncLeaderTransferDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
+ ASSERT(pMsg != NULL);
+ return pMsg;
+}
+
+cJSON* syncLeaderTransfer2Json(const SyncLeaderTransfer* pMsg) {
+ char u64buf[128];
+ cJSON* pRoot = cJSON_CreateObject();
+
+ if (pMsg != NULL) {
+ cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
+ cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
+ cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
+
+ /*
+ cJSON* pSrcId = cJSON_CreateObject();
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr);
+ cJSON_AddStringToObject(pSrcId, "addr", u64buf);
+ {
+ uint64_t u64 = pMsg->srcId.addr;
+ cJSON* pTmp = pSrcId;
+ char host[128];
+ uint16_t port;
+ syncUtilU642Addr(u64, host, sizeof(host), &port);
+ cJSON_AddStringToObject(pTmp, "addr_host", host);
+ cJSON_AddNumberToObject(pTmp, "addr_port", port);
+ }
+ cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
+ cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
+
+ cJSON* pDestId = cJSON_CreateObject();
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr);
+ cJSON_AddStringToObject(pDestId, "addr", u64buf);
+ {
+ uint64_t u64 = pMsg->destId.addr;
+ cJSON* pTmp = pDestId;
+ char host[128];
+ uint16_t port;
+ syncUtilU642Addr(u64, host, sizeof(host), &port);
+ cJSON_AddStringToObject(pTmp, "addr_host", host);
+ cJSON_AddNumberToObject(pTmp, "addr_port", port);
+ }
+ cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
+ cJSON_AddItemToObject(pRoot, "destId", pDestId);
+ */
+
+ cJSON* pNewerId = cJSON_CreateObject();
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->newLeaderId.addr);
+ cJSON_AddStringToObject(pNewerId, "addr", u64buf);
+ {
+ uint64_t u64 = pMsg->newLeaderId.addr;
+ cJSON* pTmp = pNewerId;
+ char host[128];
+ uint16_t port;
+ syncUtilU642Addr(u64, host, sizeof(host), &port);
+ cJSON_AddStringToObject(pTmp, "addr_host", host);
+ cJSON_AddNumberToObject(pTmp, "addr_port", port);
+ }
+ cJSON_AddNumberToObject(pNewerId, "vgId", pMsg->newLeaderId.vgId);
+ cJSON_AddItemToObject(pRoot, "newLeaderId", pNewerId);
+ }
+
+ cJSON* pJson = cJSON_CreateObject();
+ cJSON_AddItemToObject(pJson, "SyncLeaderTransfer", pRoot);
+ return pJson;
+}
+
+char* syncLeaderTransfer2Str(const SyncLeaderTransfer* pMsg) {
+ cJSON* pJson = syncLeaderTransfer2Json(pMsg);
+ char* serialized = cJSON_Print(pJson);
+ cJSON_Delete(pJson);
+ return serialized;
+}
+
+SyncLocalCmd* syncLocalCmdBuild(int32_t vgId) {
+ uint32_t bytes = sizeof(SyncLocalCmd);
+ SyncLocalCmd* pMsg = taosMemoryMalloc(bytes);
+ memset(pMsg, 0, bytes);
+ pMsg->bytes = bytes;
+ pMsg->vgId = vgId;
+ pMsg->msgType = TDMT_SYNC_LOCAL_CMD;
+ return pMsg;
+}
+
+void syncLocalCmdDestroy(SyncLocalCmd* pMsg) {
+ if (pMsg != NULL) {
+ taosMemoryFree(pMsg);
+ }
+}
+
+void syncLocalCmdSerialize(const SyncLocalCmd* pMsg, char* buf, uint32_t bufLen) {
+ ASSERT(pMsg->bytes <= bufLen);
+ memcpy(buf, pMsg, pMsg->bytes);
+}
+
+void syncLocalCmdDeserialize(const char* buf, uint32_t len, SyncLocalCmd* pMsg) {
+ memcpy(pMsg, buf, len);
+ ASSERT(len == pMsg->bytes);
+}
+
+char* syncLocalCmdSerialize2(const SyncLocalCmd* pMsg, uint32_t* len) {
+ char* buf = taosMemoryMalloc(pMsg->bytes);
+ ASSERT(buf != NULL);
+ syncLocalCmdSerialize(pMsg, buf, pMsg->bytes);
+ if (len != NULL) {
+ *len = pMsg->bytes;
+ }
+ return buf;
+}
+
+SyncLocalCmd* syncLocalCmdDeserialize2(const char* buf, uint32_t len) {
+ uint32_t bytes = *((uint32_t*)buf);
+ SyncLocalCmd* pMsg = taosMemoryMalloc(bytes);
+ ASSERT(pMsg != NULL);
+ syncLocalCmdDeserialize(buf, len, pMsg);
+ ASSERT(len == pMsg->bytes);
+ return pMsg;
+}
+
+void syncLocalCmd2RpcMsg(const SyncLocalCmd* pMsg, SRpcMsg* pRpcMsg) {
+ memset(pRpcMsg, 0, sizeof(*pRpcMsg));
+ pRpcMsg->msgType = pMsg->msgType;
+ pRpcMsg->contLen = pMsg->bytes;
+ pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
+ syncLocalCmdSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen);
+}
+
+void syncLocalCmdFromRpcMsg(const SRpcMsg* pRpcMsg, SyncLocalCmd* pMsg) {
+ syncLocalCmdDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
+}
+
+SyncLocalCmd* syncLocalCmdFromRpcMsg2(const SRpcMsg* pRpcMsg) {
+ SyncLocalCmd* pMsg = syncLocalCmdDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
+ ASSERT(pMsg != NULL);
+ return pMsg;
+}
+
+cJSON* syncLocalCmd2Json(const SyncLocalCmd* pMsg) {
+ char u64buf[128];
+ cJSON* pRoot = cJSON_CreateObject();
+
+ if (pMsg != NULL) {
+ cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
+ cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
+ cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
+
+ cJSON* pSrcId = cJSON_CreateObject();
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr);
+ cJSON_AddStringToObject(pSrcId, "addr", u64buf);
+ {
+ uint64_t u64 = pMsg->srcId.addr;
+ cJSON* pTmp = pSrcId;
+ char host[128];
+ uint16_t port;
+ syncUtilU642Addr(u64, host, sizeof(host), &port);
+ cJSON_AddStringToObject(pTmp, "addr_host", host);
+ cJSON_AddNumberToObject(pTmp, "addr_port", port);
+ }
+ cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
+ cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
+
+ cJSON* pDestId = cJSON_CreateObject();
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr);
+ cJSON_AddStringToObject(pDestId, "addr", u64buf);
+ {
+ uint64_t u64 = pMsg->destId.addr;
+ cJSON* pTmp = pDestId;
+ char host[128];
+ uint16_t port;
+ syncUtilU642Addr(u64, host, sizeof(host), &port);
+ cJSON_AddStringToObject(pTmp, "addr_host", host);
+ cJSON_AddNumberToObject(pTmp, "addr_port", port);
+ }
+ cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
+ cJSON_AddItemToObject(pRoot, "destId", pDestId);
+
+ cJSON_AddNumberToObject(pRoot, "cmd", pMsg->cmd);
+
+ snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->sdNewTerm);
+ cJSON_AddStringToObject(pRoot, "sd-new-term", u64buf);
+
+ snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->fcIndex);
+ cJSON_AddStringToObject(pRoot, "fc-index", u64buf);
+ }
+
+ cJSON* pJson = cJSON_CreateObject();
+ cJSON_AddItemToObject(pJson, "SyncLocalCmd2Json", pRoot);
+ return pJson;
+}
+
+char* syncLocalCmd2Str(const SyncLocalCmd* pMsg) {
+ cJSON* pJson = syncLocalCmd2Json(pMsg);
+ char* serialized = cJSON_Print(pJson);
+ cJSON_Delete(pJson);
+ return serialized;
+}
+
+// for debug ----------------------
+void syncLocalCmdPrint(const SyncLocalCmd* pMsg) {
+ char* serialized = syncLocalCmd2Str(pMsg);
+ printf("syncLocalCmdPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
+ fflush(NULL);
+ taosMemoryFree(serialized);
+}
+
+void syncLocalCmdPrint2(char* s, const SyncLocalCmd* pMsg) {
+ char* serialized = syncLocalCmd2Str(pMsg);
+ printf("syncLocalCmdPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
+ fflush(NULL);
+ taosMemoryFree(serialized);
+}
+
+void syncLocalCmdLog(const SyncLocalCmd* pMsg) {
+ char* serialized = syncLocalCmd2Str(pMsg);
+ sTrace("syncLocalCmdLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
+ taosMemoryFree(serialized);
+}
+
+void syncLocalCmdLog2(char* s, const SyncLocalCmd* pMsg) {
+ if (gRaftDetailLog) {
+ char* serialized = syncLocalCmd2Str(pMsg);
+ sTrace("syncLocalCmdLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
+ taosMemoryFree(serialized);
+ }
}
\ No newline at end of file
diff --git a/source/libs/sync/test/sync_test_lib/src/syncSnapshotDebug.c b/source/libs/sync/test/sync_test_lib/src/syncSnapshotDebug.c
index fdaf4b8b34..82e23b2885 100644
--- a/source/libs/sync/test/sync_test_lib/src/syncSnapshotDebug.c
+++ b/source/libs/sync/test/sync_test_lib/src/syncSnapshotDebug.c
@@ -130,3 +130,60 @@ char *snapshotReceiver2Str(SSyncSnapshotReceiver *pReceiver) {
cJSON_Delete(pJson);
return serialized;
}
+
+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;
+}
\ No newline at end of file
diff --git a/source/libs/tdb/src/db/tdbPCache.c b/source/libs/tdb/src/db/tdbPCache.c
index bdbd6c2f3d..e7254c8bc6 100644
--- a/source/libs/tdb/src/db/tdbPCache.c
+++ b/source/libs/tdb/src/db/tdbPCache.c
@@ -169,7 +169,7 @@ int tdbPCacheAlter(SPCache *pCache, int32_t nPage) {
SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, TXN *pTxn) {
SPage *pPage;
- i32 nRef;
+ i32 nRef = 0;
tdbPCacheLock(pCache);
@@ -178,14 +178,17 @@ SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, TXN *pTxn) {
nRef = tdbRefPage(pPage);
}
- ASSERT(pPage);
-
tdbPCacheUnlock(pCache);
// printf("thread %" PRId64 " fetch page %d pgno %d pPage %p nRef %d\n", taosGetSelfPthreadId(), pPage->id,
// TDB_PAGE_PGNO(pPage), pPage, nRef);
- tdbDebug("pcache/fetch page %p/%d/%d/%d", pPage, TDB_PAGE_PGNO(pPage), pPage->id, nRef);
+ if (pPage) {
+ tdbDebug("pcache/fetch page %p/%d/%d/%d", pPage, TDB_PAGE_PGNO(pPage), pPage->id, nRef);
+ } else {
+ tdbDebug("pcache/fetch page %p", pPage);
+ }
+
return pPage;
}
@@ -266,7 +269,7 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, TXN *pTxn)
}
// 4. Try a create new page
- if (!pPage) {
+ if (!pPage && pTxn->xMalloc != NULL) {
ret = tdbPageCreate(pCache->szPage, &pPage, pTxn->xMalloc, pTxn->xArg);
if (ret < 0 || pPage == NULL) {
// TODO
diff --git a/source/libs/tdb/src/db/tdbPager.c b/source/libs/tdb/src/db/tdbPager.c
index c3ae1dc739..abbad06515 100644
--- a/source/libs/tdb/src/db/tdbPager.c
+++ b/source/libs/tdb/src/db/tdbPager.c
@@ -27,6 +27,116 @@ typedef struct {
TDB_STATIC_ASSERT(sizeof(SFileHdr) == 128, "Size of file header is not correct");
+struct hashset_st {
+ size_t nbits;
+ size_t mask;
+ size_t capacity;
+ size_t *items;
+ size_t nitems;
+ double load_factor;
+};
+
+static const unsigned int prime = 39;
+static const unsigned int prime2 = 5009;
+
+hashset_t hashset_create(void) {
+ hashset_t set = tdbOsCalloc(1, sizeof(struct hashset_st));
+ if (!set) {
+ return NULL;
+ }
+
+ set->nbits = 4;
+ set->capacity = (size_t)(1 << set->nbits);
+ set->items = tdbOsCalloc(set->capacity, sizeof(size_t));
+ if (!set->items) {
+ tdbOsFree(set);
+ return NULL;
+ }
+ set->mask = set->capacity - 1;
+ set->nitems = 0;
+
+ set->load_factor = 0.75;
+
+ return set;
+}
+
+void hashset_destroy(hashset_t set) {
+ if (set) {
+ tdbOsFree(set->items);
+ tdbOsFree(set);
+ }
+}
+
+int hashset_add_member(hashset_t set, void *item) {
+ size_t value = (size_t) item;
+ size_t h;
+
+ if (value == 0) {
+ return -1;
+ }
+
+ for (h = set->mask & (prime * value); set->items[h] != 0; h = set->mask & (h + prime2)) {
+ if (set->items[h] == value) {
+ return 0;
+ }
+ }
+
+ set->items[h] = value;
+ ++set->nitems;
+ return 1;
+}
+
+int hashset_add(hashset_t set, void *item) {
+ int ret = hashset_add_member(set, item);
+
+ size_t old_capacity = set->capacity;
+ if (set->nitems >= (double)old_capacity * set->load_factor) {
+ size_t *old_items = set->items;
+ ++set->nbits;
+ set->capacity = (size_t)(1 << set->nbits);
+ set->mask = set->capacity - 1;
+
+ set->items = tdbOsCalloc(set->capacity, sizeof(size_t));
+ if (!set->items) {
+ return -1;
+ }
+
+ set->nitems = 0;
+ for (size_t i = 0; i < old_capacity; ++i) {
+ hashset_add_member(set, (void*)old_items[i]);
+ }
+ tdbOsFree(old_items);
+ }
+
+ return ret;
+}
+
+int hashset_remove(hashset_t set, void *item) {
+ size_t value = (size_t) item;
+
+ for (size_t h = set->mask & (prime * value); set->items[h] != 0; h = set->mask & (h + prime2)) {
+ if (set->items[h] == value) {
+ set->items[h] = 0;
+ --set->nitems;
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+int hashset_contains(hashset_t set, void *item) {
+ size_t value = (size_t) item;
+
+ for (size_t h = set->mask & (prime * value); set->items[h] != 0; h = set->mask & (h + prime2)) {
+ if (set->items[h] == value) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
#define TDB_PAGE_INITIALIZED(pPage) ((pPage)->pPager != NULL)
static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage *, void *, int), void *arg,
@@ -209,12 +319,16 @@ int tdbPagerWrite(SPager *pPager, SPage *pPage) {
tRBTreePut(&pPager->rbt, (SRBTreeNode *)pPage);
// Write page to journal if neccessary
- if (TDB_PAGE_PGNO(pPage) <= pPager->dbOrigSize) {
+ if (TDB_PAGE_PGNO(pPage) <= pPager->dbOrigSize && (pPager->jPageSet == NULL || !hashset_contains(pPager->jPageSet, (void*)((long)TDB_PAGE_PGNO(pPage))))) {
ret = tdbPagerWritePageToJournal(pPager, pPage);
if (ret < 0) {
tdbError("failed to write page to journal since %s", tstrerror(terrno));
return -1;
}
+
+ if (pPager->jPageSet) {
+ hashset_add(pPager->jPageSet, (void*)((long)TDB_PAGE_PGNO(pPage)));
+ }
}
return 0;
@@ -233,6 +347,7 @@ int tdbPagerBegin(SPager *pPager, TXN *pTxn) {
return -1;
}
+ pPager->jPageSet = hashset_create();
// TODO: write the size of the file
pPager->inTran = 1;
@@ -275,6 +390,9 @@ int tdbPagerCommit(SPager *pPager, TXN *pTxn) {
pPage->isDirty = 0;
tRBTreeDrop(&pPager->rbt, (SRBTreeNode *)pPage);
+ if (pPager->jPageSet) {
+ hashset_remove(pPager->jPageSet, (void*)((long)TDB_PAGE_PGNO(pPage)));
+ }
tdbPCacheRelease(pPager->pCache, pPage, pTxn);
}
@@ -304,6 +422,9 @@ int tdbPagerPostCommit(SPager *pPager, TXN *pTxn) {
return -1;
}
+ if (pPager->jPageSet) {
+ hashset_destroy(pPager->jPageSet);
+ }
pPager->inTran = 0;
return 0;
@@ -375,36 +496,61 @@ int tdbPagerAbort(SPager *pPager, TXN *pTxn) {
return -1;
}
- tdb_fd_t jfd = tdbOsOpen(pPager->jFileName, TDB_O_RDWR, 0755);
- if (jfd == NULL) {
- return -1;
- }
+ tdb_fd_t jfd = pPager->jfd;
ret = tdbGetFileSize(jfd, pPager->pageSize, &journalSize);
if (ret < 0) {
return -1;
}
- // 1, read pages from jounal file
- // 2, write original pages to buffered ones
+ u8 *pageBuf = tdbOsCalloc(1, pPager->pageSize);
+ if (pageBuf == NULL) {
+ return -1;
+ }
- /* TODO: reset the buffered pages instead of releasing them
- // loop to reset the dirty pages from file
- for (pgIdx = 0, pPage = pPager->pDirty; pPage != NULL && pgIndex < journalSize; pPage = pPage->pDirtyNext, ++pgIdx) {
+ for (int pgIndex = 0; pgIndex < journalSize; ++pgIndex) {
// read pgno & the page from journal
SPgno pgno;
int ret = tdbOsRead(jfd, &pgno, sizeof(pgno));
if (ret < 0) {
+ tdbOsFree(pageBuf);
return -1;
}
ret = tdbOsRead(jfd, pageBuf, pPager->pageSize);
if (ret < 0) {
+ tdbOsFree(pageBuf);
+ return -1;
+ }
+
+ i64 offset = pPager->pageSize * (pgno - 1);
+ if (tdbOsLSeek(pPager->fd, offset, SEEK_SET) < 0) {
+ tdbError("failed to lseek fd due to %s. file:%s, offset:%" PRId64, strerror(errno), pPager->dbFileName, offset);
+ terrno = TAOS_SYSTEM_ERROR(errno);
+ tdbOsFree(pageBuf);
+ return -1;
+ }
+
+ ret = tdbOsWrite(pPager->fd, pageBuf, pPager->pageSize);
+ if (ret < 0) {
+ tdbError("failed to write buf due to %s. file: %s, bufsize:%d", strerror(errno), pPager->dbFileName,
+ pPager->pageSize);
+ terrno = TAOS_SYSTEM_ERROR(errno);
+ tdbOsFree(pageBuf);
return -1;
}
}
- */
+
+ if (tdbOsFSync(pPager->fd) < 0) {
+ tdbError("failed to fsync fd due to %s. dbfile:%s", strerror(errno), pPager->dbFileName);
+ terrno = TAOS_SYSTEM_ERROR(errno);
+ tdbOsFree(pageBuf);
+ return -1;
+ }
+
+ tdbOsFree(pageBuf);
+
// 3, release the dirty pages
SRBTreeIter iter = tRBTreeIterCreate(&pPager->rbt, 1);
SRBTreeNode *pNode = NULL;
@@ -413,17 +559,55 @@ int tdbPagerAbort(SPager *pPager, TXN *pTxn) {
pPage->isDirty = 0;
+ tRBTreeDrop(&pPager->rbt, (SRBTreeNode *)pPage);
+ hashset_remove(pPager->jPageSet, (void*)((long)TDB_PAGE_PGNO(pPage)));
+ tdbPCacheRelease(pPager->pCache, pPage, pTxn);
+ }
+
+ tRBTreeCreate(&pPager->rbt, pageCmpFn);
+
+ // 4, remove the journal file
+ tdbOsClose(pPager->jfd);
+ (void)tdbOsRemove(pPager->jFileName);
+ hashset_destroy(pPager->jPageSet);
+
+ pPager->inTran = 0;
+
+ return 0;
+}
+
+int tdbPagerFlushPage(SPager *pPager, TXN *pTxn) {
+ SPage *pPage;
+ int ret;
+
+ // loop to write the dirty pages to file
+ SRBTreeIter iter = tRBTreeIterCreate(&pPager->rbt, 1);
+ SRBTreeNode *pNode = NULL;
+ while ((pNode = tRBTreeIterNext(&iter)) != NULL) {
+ pPage = (SPage *)pNode;
+ ret = tdbPagerWritePageToDB(pPager, pPage);
+ if (ret < 0) {
+ tdbError("failed to write page to db since %s", tstrerror(terrno));
+ return -1;
+ }
+ }
+
+ tdbTrace("tdbttl commit:%p, %d/%d", pPager, pPager->dbOrigSize, pPager->dbFileSize);
+ pPager->dbOrigSize = pPager->dbFileSize;
+
+ // release the page
+ iter = tRBTreeIterCreate(&pPager->rbt, 1);
+ while ((pNode = tRBTreeIterNext(&iter)) != NULL) {
+ pPage = (SPage *)pNode;
+
+ pPage->isDirty = 0;
+
tRBTreeDrop(&pPager->rbt, (SRBTreeNode *)pPage);
tdbPCacheRelease(pPager->pCache, pPage, pTxn);
}
tRBTreeCreate(&pPager->rbt, pageCmpFn);
- // 4, remove the journal file
- tdbOsClose(pPager->jfd);
- (void)tdbOsRemove(pPager->jFileName);
- pPager->inTran = 0;
-
return 0;
}
@@ -453,10 +637,8 @@ int tdbPagerFetchPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPa
// fetch a page container
memcpy(&pgid, pPager->fid, TDB_FILE_ID_LEN);
pgid.pgno = pgno;
- pPage = tdbPCacheFetch(pPager->pCache, &pgid, pTxn);
- if (pPage == NULL) {
- ASSERT(0);
- return -1;
+ while ((pPage = tdbPCacheFetch(pPager->pCache, &pgid, pTxn)) == NULL) {
+ tdbPagerFlushPage(pPager, pTxn);
}
tdbTrace("tdbttl fetch pager:%p", pPage->pPager);
diff --git a/source/libs/tdb/src/inc/tdbInt.h b/source/libs/tdb/src/inc/tdbInt.h
index e5ece98b28..731b1927e7 100644
--- a/source/libs/tdb/src/inc/tdbInt.h
+++ b/source/libs/tdb/src/inc/tdbInt.h
@@ -384,6 +384,8 @@ struct STDB {
#endif
};
+typedef struct hashset_st *hashset_t;
+
struct SPager {
char *dbFileName;
char *jFileName;
@@ -394,7 +396,8 @@ struct SPager {
SPCache *pCache;
SPgno dbFileSize;
SPgno dbOrigSize;
- SPage *pDirty;
+ //SPage *pDirty;
+ hashset_t jPageSet;
SRBTree rbt;
u8 inTran;
SPager *pNext; // used by TDB
diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c
index 1c6e1a2e17..6cac4b6093 100644
--- a/source/libs/wal/src/walMeta.c
+++ b/source/libs/wal/src/walMeta.c
@@ -124,8 +124,8 @@ static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx) {
goto _err;
}
- char* candidate = NULL;
- char* haystack = buf;
+ char* candidate = NULL;
+ char* haystack = buf;
int64_t pos = 0;
SWalCkHead* logContent = NULL;
@@ -414,8 +414,10 @@ int walCheckAndRepairMeta(SWal* pWal) {
}
ASSERT(pFileInfo->fileSize == 0);
// remove the empty wal log, and its idx
+ wInfo("vgId:%d, wal remove empty file %s", pWal->cfg.vgId, fnameStr);
taosRemoveFile(fnameStr);
walBuildIdxName(pWal, pFileInfo->firstVer, fnameStr);
+ wInfo("vgId:%d, wal remove empty file %s", pWal->cfg.vgId, fnameStr);
taosRemoveFile(fnameStr);
// remove its meta entry
taosArrayRemove(pWal->fileInfoSet, fileIdx);
diff --git a/source/libs/wal/src/walWrite.c b/source/libs/wal/src/walWrite.c
index b683ba1926..216dd5fcb1 100644
--- a/source/libs/wal/src/walWrite.c
+++ b/source/libs/wal/src/walWrite.c
@@ -319,7 +319,7 @@ int32_t walEndSnapshot(SWal *pWal) {
SWalFileInfo *pInfo = taosArraySearch(pWal->fileInfoSet, &tmp, compareWalFileInfo, TD_LE);
if (pInfo) {
if (ver >= pInfo->lastVer) {
- pInfo--;
+ pInfo++;
}
if (POINTER_DISTANCE(pInfo, pWal->fileInfoSet->pData) > 0) {
wDebug("vgId:%d, begin remove from %" PRId64, pWal->cfg.vgId, pInfo->firstVer);
@@ -407,6 +407,7 @@ int32_t walRollImpl(SWal *pWal) {
}
walBuildLogName(pWal, newFileFirstVer, fnameStr);
pLogFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
+ wDebug("vgId:%d, wal create new file for write:%s", pWal->cfg.vgId, fnameStr);
if (pLogFile == NULL) {
terrno = TAOS_SYSTEM_ERROR(errno);
code = -1;
diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c
index c1fee37610..76a312cd91 100644
--- a/source/util/src/tconfig.c
+++ b/source/util/src/tconfig.c
@@ -271,8 +271,11 @@ static int32_t cfgSetTimezone(SConfigItem *pItem, const char *value, ECfgSrcType
cfgStypeStr(stype), value, terrstr());
return -1;
}
-
pItem->stype = stype;
+
+ // apply new timezone
+ osSetTimezone(value);
+
return 0;
}
diff --git a/source/util/src/terror.c b/source/util/src/terror.c
index a1162d2e94..b406432616 100644
--- a/source/util/src/terror.c
+++ b/source/util/src/terror.c
@@ -377,6 +377,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_QRY_JSON_IN_ERROR, "Json not support in i
TAOS_DEFINE_ERROR(TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR, "Json not support in this place")
TAOS_DEFINE_ERROR(TSDB_CODE_QRY_JSON_IN_GROUP_ERROR, "Json not support in group/partition by")
TAOS_DEFINE_ERROR(TSDB_CODE_QRY_JOB_NOT_EXIST, "Job not exist")
+TAOS_DEFINE_ERROR(TSDB_CODE_QRY_QWORKER_QUIT, "Vnode/Qnode is quitting")
// grant
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_EXPIRED, "License expired")
diff --git a/tests/develop-test/5-taos-tools/taosbenchmark/json/sml_telnet_tcp.json b/tests/develop-test/5-taos-tools/taosbenchmark/json/sml_telnet_tcp.json
index 29cd677038..9e1241397f 100644
--- a/tests/develop-test/5-taos-tools/taosbenchmark/json/sml_telnet_tcp.json
+++ b/tests/develop-test/5-taos-tools/taosbenchmark/json/sml_telnet_tcp.json
@@ -17,13 +17,7 @@
"databases": [{
"dbinfo": {
"name": "db",
- "drop": "yes",
- "replica": 1,
- "precision": "ms",
- "keep": 36500,
- "minRows": 100,
- "maxRows": 4096,
- "comp":2
+ "drop": "yes"
},
"super_tables": [{
"name": "stb1",
diff --git a/tests/develop-test/5-taos-tools/taosbenchmark/telnet_tcp.py b/tests/develop-test/5-taos-tools/taosbenchmark/telnet_tcp.py
index 78cb49846e..23e788916f 100644
--- a/tests/develop-test/5-taos-tools/taosbenchmark/telnet_tcp.py
+++ b/tests/develop-test/5-taos-tools/taosbenchmark/telnet_tcp.py
@@ -16,36 +16,40 @@ from util.log import *
from util.cases import *
from util.sql import *
from util.dnodes import *
-from util.taosadapter import *
+
class TDTestCase:
def caseDescription(self):
- '''
+ """
[TD-11510] taosBenchmark test cases
- '''
- return
+ """
def init(self, conn, logSql, replicaVar=1):
- self.replicaVar = int(replicaVar)
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor(), logSql)
def getPath(self, tool="taosBenchmark"):
selfPath = os.path.dirname(os.path.realpath(__file__))
- if ("community" in selfPath):
- projPath = selfPath[:selfPath.find("community")]
+ if "community" in selfPath:
+ projPath = selfPath[: selfPath.find("community")]
+ elif "src" in selfPath:
+ projPath = selfPath[: selfPath.find("src")]
+ elif "/tools/" in selfPath:
+ projPath = selfPath[: selfPath.find("/tools/")]
+ elif "/tests/" in selfPath:
+ projPath = selfPath[: selfPath.find("/tests/")]
else:
- projPath = selfPath[:selfPath.find("tests")]
+ tdLog.exit("cannot found %s in path: %s, use system's" % (tool, selfPath))
paths = []
for root, dirs, files in os.walk(projPath):
- if ((tool) in files):
+ if (tool) in files:
rootRealPath = os.path.dirname(os.path.realpath(root))
- if ("packaging" not in rootRealPath):
+ if "packaging" not in rootRealPath:
paths.append(os.path.join(root, tool))
break
- if (len(paths) == 0):
+ if len(paths) == 0:
tdLog.exit("taosBenchmark not found!")
return
else:
@@ -53,38 +57,30 @@ class TDTestCase:
return paths[0]
def run(self):
- tAdapter.init("")
- adapter_cfg = {
- "influxdb": {
- "enable": True
- },
- "opentsdb": {
- "enable": True
- },
- "opentsdb_telnet": {
- "enable": True,
- "maxTCPConnection": 250,
- "tcpKeepAlive": True,
- "dbs": ["opentsdb_telnet", "collectd", "icinga2", "tcollector"],
- "ports": [6046, 6047, 6048, 6049],
- "user": "root",
- "password": "taosdata"
- }
- }
- tAdapter.update_cfg(adapter_cfg)
- tAdapter.deploy()
- tAdapter.start()
binPath = self.getPath()
- cmd = "%s -f ./5-taos-tools/taosbenchmark/json/sml_telnet_tcp.json" %binPath
+ cmd = "%s -f ./5-taos-tools/taosbenchmark/json/sml_telnet_tcp.json" % binPath
tdLog.info("%s" % cmd)
os.system("%s" % cmd)
time.sleep(5)
tdSql.execute("reset query cache")
- tdSql.query("select count(*) from (select distinct(tbname) from opentsdb_telnet.stb1)")
+ tdSql.query("select client_version()")
+ client_ver = "".join(tdSql.queryResult[0])
+ major_ver = client_ver.split(".")[0]
+ if major_ver == "3":
+ tdSql.query(
+ "select count(*) from (select distinct(tbname) from opentsdb_telnet.stb1)"
+ )
+ else:
+ tdSql.query("select count(tbname) from opentsdb_telnet.stb1")
tdSql.checkData(0, 0, 8)
tdSql.query("select count(*) from opentsdb_telnet.stb1")
tdSql.checkData(0, 0, 160)
- tdSql.query("select count(*) from (select distinct(tbname) from opentsdb_telnet.stb2)")
+ if major_ver == "3":
+ tdSql.query(
+ "select count(*) from (select distinct(tbname) from opentsdb_telnet.stb2)"
+ )
+ else:
+ tdSql.query("select count(tbname) from opentsdb_telnet.stb2")
tdSql.checkData(0, 0, 8)
tdSql.query("select count(*) from opentsdb_telnet.stb2")
tdSql.checkData(0, 0, 160)
diff --git a/tests/develop-test/test.py b/tests/develop-test/test.py
index 062e48b94b..1b0f0d0aed 100644
--- a/tests/develop-test/test.py
+++ b/tests/develop-test/test.py
@@ -238,7 +238,7 @@ if __name__ == "__main__":
time.sleep(2)
if restful:
- toBeKilled = "taosadapt"
+ toBeKilled = "taosadapter"
# killCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}' | xargs kill -TERM > /dev/null 2>&1" % toBeKilled
killCmd = f"pkill {toBeKilled}"
diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task
index 8955a65dfa..ac001896c7 100644
--- a/tests/parallel_test/cases.task
+++ b/tests/parallel_test/cases.task
@@ -6,42 +6,42 @@
,,y,unit-test,bash test.sh
#tsim test
-,,,script,./test.sh -f tsim/user/basic.sim
-,,,script,./test.sh -f tsim/user/password.sim
-,,,script,./test.sh -f tsim/user/privilege_db.sim
-,,,script,./test.sh -f tsim/user/privilege_sysinfo.sim
+,,y,script,./test.sh -f tsim/user/basic.sim
+,,y,script,./test.sh -f tsim/user/password.sim
+,,y,script,./test.sh -f tsim/user/privilege_db.sim
+,,y,script,./test.sh -f tsim/user/privilege_sysinfo.sim
,,,script,./test.sh -f tsim/db/alter_option.sim
,,,script,./test.sh -f tsim/db/alter_replica_13.sim
,,,script,./test.sh -f tsim/db/alter_replica_31.sim
-,,,script,./test.sh -f tsim/db/basic1.sim
-,,,script,./test.sh -f tsim/db/basic2.sim
-,,,script,./test.sh -f tsim/db/basic3.sim
-,,,script,./test.sh -f tsim/db/basic4.sim
-,,,script,./test.sh -f tsim/db/basic5.sim
-,,,script,./test.sh -f tsim/db/basic6.sim
-,,,script,./test.sh -f tsim/db/commit.sim
+,,y,script,./test.sh -f tsim/db/basic1.sim
+,,y,script,./test.sh -f tsim/db/basic2.sim
+,,y,script,./test.sh -f tsim/db/basic3.sim
+,,y,script,./test.sh -f tsim/db/basic4.sim
+,,y,script,./test.sh -f tsim/db/basic5.sim
+,,y,script,./test.sh -f tsim/db/basic6.sim
+,,y,script,./test.sh -f tsim/db/commit.sim
,,,script,./test.sh -f tsim/db/create_all_options.sim
-,,,script,./test.sh -f tsim/db/delete_reuse1.sim
-,,,script,./test.sh -f tsim/db/delete_reuse2.sim
-,,,script,./test.sh -f tsim/db/delete_reusevnode.sim
-,,,script,./test.sh -f tsim/db/delete_reusevnode2.sim
-,,,script,./test.sh -f tsim/db/delete_writing1.sim
-,,,script,./test.sh -f tsim/db/delete_writing2.sim
-,,,script,./test.sh -f tsim/db/error1.sim
-,,,script,./test.sh -f tsim/db/keep.sim
-,,,script,./test.sh -f tsim/db/len.sim
-,,,script,./test.sh -f tsim/db/repeat.sim
-,,,script,./test.sh -f tsim/db/show_create_db.sim
-,,,script,./test.sh -f tsim/db/show_create_table.sim
-,,,script,./test.sh -f tsim/db/tables.sim
-,,,script,./test.sh -f tsim/db/taosdlog.sim
+,,y,script,./test.sh -f tsim/db/delete_reuse1.sim
+,,y,script,./test.sh -f tsim/db/delete_reuse2.sim
+,,y,script,./test.sh -f tsim/db/delete_reusevnode.sim
+,,y,script,./test.sh -f tsim/db/delete_reusevnode2.sim
+,,y,script,./test.sh -f tsim/db/delete_writing1.sim
+,,y,script,./test.sh -f tsim/db/delete_writing2.sim
+,,y,script,./test.sh -f tsim/db/error1.sim
+,,y,script,./test.sh -f tsim/db/keep.sim
+,,y,script,./test.sh -f tsim/db/len.sim
+,,y,script,./test.sh -f tsim/db/repeat.sim
+,,y,script,./test.sh -f tsim/db/show_create_db.sim
+,,y,script,./test.sh -f tsim/db/show_create_table.sim
+,,y,script,./test.sh -f tsim/db/tables.sim
+,,y,script,./test.sh -f tsim/db/taosdlog.sim
,,,script,./test.sh -f tsim/dnode/balance_replica1.sim
,,,script,./test.sh -f tsim/dnode/balance_replica3.sim
,,,script,./test.sh -f tsim/dnode/balance1.sim
,,,script,./test.sh -f tsim/dnode/balance2.sim
,,,script,./test.sh -f tsim/dnode/balance3.sim
,,,script,./test.sh -f tsim/dnode/balancex.sim
-,,,script,./test.sh -f tsim/dnode/create_dnode.sim
+,,y,script,./test.sh -f tsim/dnode/create_dnode.sim
,,,script,./test.sh -f tsim/dnode/drop_dnode_has_mnode.sim
,,,script,./test.sh -f tsim/dnode/drop_dnode_has_qnode_snode.sim
,,,script,./test.sh -f tsim/dnode/drop_dnode_has_vnode_replica1.sim
@@ -49,7 +49,7 @@
,,,script,./test.sh -f tsim/dnode/drop_dnode_has_multi_vnode_replica1.sim
,,,script,./test.sh -f tsim/dnode/drop_dnode_has_multi_vnode_replica3.sim
,,,script,./test.sh -f tsim/dnode/drop_dnode_force.sim
-,,,script,./test.sh -f tsim/dnode/offline_reason.sim
+,,y,script,./test.sh -f tsim/dnode/offline_reason.sim
,,,script,./test.sh -f tsim/dnode/redistribute_vgroup_replica1.sim
,,,script,./test.sh -f tsim/dnode/redistribute_vgroup_replica3_v1_leader.sim
,,,script,./test.sh -f tsim/dnode/redistribute_vgroup_replica3_v1_follower.sim
@@ -59,119 +59,119 @@
,,,script,./test.sh -f tsim/dnode/use_dropped_dnode.sim
,,,script,./test.sh -f tsim/dnode/split_vgroup_replica1.sim
,,,script,./test.sh -f tsim/dnode/split_vgroup_replica3.sim
-,,,script,./test.sh -f tsim/import/basic.sim
-,,,script,./test.sh -f tsim/import/commit.sim
-,,,script,./test.sh -f tsim/import/large.sim
-,,,script,./test.sh -f tsim/import/replica1.sim
-,,,script,./test.sh -f tsim/insert/backquote.sim
-,,,script,./test.sh -f tsim/insert/basic.sim
-,,,script,./test.sh -f tsim/insert/basic0.sim
-,,,script,./test.sh -f tsim/insert/basic1.sim
-,,,script,./test.sh -f tsim/insert/basic2.sim
+,,y,script,./test.sh -f tsim/import/basic.sim
+,,y,script,./test.sh -f tsim/import/commit.sim
+,,y,script,./test.sh -f tsim/import/large.sim
+,,y,script,./test.sh -f tsim/import/replica1.sim
+,,y,script,./test.sh -f tsim/insert/backquote.sim
+,,y,script,./test.sh -f tsim/insert/basic.sim
+,,y,script,./test.sh -f tsim/insert/basic0.sim
+,,y,script,./test.sh -f tsim/insert/basic1.sim
+,,y,script,./test.sh -f tsim/insert/basic2.sim
,,,script,./test.sh -f tsim/insert/commit-merge0.sim
-,,,script,./test.sh -f tsim/insert/insert_drop.sim
-,,,script,./test.sh -f tsim/insert/insert_select.sim
-,,,script,./test.sh -f tsim/insert/null.sim
-,,,script,./test.sh -f tsim/insert/query_block1_file.sim
-,,,script,./test.sh -f tsim/insert/query_block1_memory.sim
-,,,script,./test.sh -f tsim/insert/query_block2_file.sim
-,,,script,./test.sh -f tsim/insert/query_block2_memory.sim
-,,,script,./test.sh -f tsim/insert/query_file_memory.sim
-,,,script,./test.sh -f tsim/insert/query_multi_file.sim
-,,,script,./test.sh -f tsim/insert/tcp.sim
-,,,script,./test.sh -f tsim/insert/update0.sim
-,,,script,./test.sh -f tsim/insert/update1_sort_merge.sim
-,,,script,./test.sh -f tsim/parser/alter__for_community_version.sim
-,,,script,./test.sh -f tsim/parser/alter_column.sim
-,,,script,./test.sh -f tsim/parser/alter_stable.sim
-,,,script,./test.sh -f tsim/parser/alter.sim
-,,,script,./test.sh -f tsim/parser/alter1.sim
-,,,script,./test.sh -f tsim/parser/auto_create_tb_drop_tb.sim
-,,,script,./test.sh -f tsim/parser/auto_create_tb.sim
-,,,script,./test.sh -f tsim/parser/between_and.sim
-,,,script,./test.sh -f tsim/parser/binary_escapeCharacter.sim
+,,y,script,./test.sh -f tsim/insert/insert_drop.sim
+,,y,script,./test.sh -f tsim/insert/insert_select.sim
+,,y,script,./test.sh -f tsim/insert/null.sim
+,,y,script,./test.sh -f tsim/insert/query_block1_file.sim
+,,y,script,./test.sh -f tsim/insert/query_block1_memory.sim
+,,y,script,./test.sh -f tsim/insert/query_block2_file.sim
+,,y,script,./test.sh -f tsim/insert/query_block2_memory.sim
+,,y,script,./test.sh -f tsim/insert/query_file_memory.sim
+,,y,script,./test.sh -f tsim/insert/query_multi_file.sim
+,,y,script,./test.sh -f tsim/insert/tcp.sim
+,,y,script,./test.sh -f tsim/insert/update0.sim
+,,y,script,./test.sh -f tsim/insert/update1_sort_merge.sim
+,,y,script,./test.sh -f tsim/parser/alter__for_community_version.sim
+,,y,script,./test.sh -f tsim/parser/alter_column.sim
+,,y,script,./test.sh -f tsim/parser/alter_stable.sim
+,,y,script,./test.sh -f tsim/parser/alter.sim
+,,y,script,./test.sh -f tsim/parser/alter1.sim
+,,y,script,./test.sh -f tsim/parser/auto_create_tb_drop_tb.sim
+,,y,script,./test.sh -f tsim/parser/auto_create_tb.sim
+,,y,script,./test.sh -f tsim/parser/between_and.sim
+,,y,script,./test.sh -f tsim/parser/binary_escapeCharacter.sim
,,,script,./test.sh -f tsim/parser/col_arithmetic_operation.sim
-,,,script,./test.sh -f tsim/parser/columnValue_bigint.sim
-,,,script,./test.sh -f tsim/parser/columnValue_bool.sim
-,,,script,./test.sh -f tsim/parser/columnValue_double.sim
-,,,script,./test.sh -f tsim/parser/columnValue_float.sim
-,,,script,./test.sh -f tsim/parser/columnValue_int.sim
-,,,script,./test.sh -f tsim/parser/columnValue_smallint.sim
-,,,script,./test.sh -f tsim/parser/columnValue_tinyint.sim
+,,y,script,./test.sh -f tsim/parser/columnValue_bigint.sim
+,,y,script,./test.sh -f tsim/parser/columnValue_bool.sim
+,,y,script,./test.sh -f tsim/parser/columnValue_double.sim
+,,y,script,./test.sh -f tsim/parser/columnValue_float.sim
+,,y,script,./test.sh -f tsim/parser/columnValue_int.sim
+,,y,script,./test.sh -f tsim/parser/columnValue_smallint.sim
+,,y,script,./test.sh -f tsim/parser/columnValue_tinyint.sim
,,,script,./test.sh -f tsim/parser/columnValue_unsign.sim
-,,,script,./test.sh -f tsim/parser/commit.sim
-,,,script,./test.sh -f tsim/parser/condition.sim
-,,,script,./test.sh -f tsim/parser/constCol.sim
-,,,script,./test.sh -f tsim/parser/create_db.sim
-,,,script,./test.sh -f tsim/parser/create_mt.sim
-,,,script,./test.sh -f tsim/parser/create_tb_with_tag_name.sim
-,,,script,./test.sh -f tsim/parser/create_tb.sim
-,,,script,./test.sh -f tsim/parser/dbtbnameValidate.sim
-,,,script,./test.sh -f tsim/parser/distinct.sim
-,,,script,./test.sh -f tsim/parser/fill_us.sim
+,,y,script,./test.sh -f tsim/parser/commit.sim
+,,y,script,./test.sh -f tsim/parser/condition.sim
+,,y,script,./test.sh -f tsim/parser/constCol.sim
+,,y,script,./test.sh -f tsim/parser/create_db.sim
+,,y,script,./test.sh -f tsim/parser/create_mt.sim
+,,y,script,./test.sh -f tsim/parser/create_tb_with_tag_name.sim
+,,y,script,./test.sh -f tsim/parser/create_tb.sim
+,,y,script,./test.sh -f tsim/parser/dbtbnameValidate.sim
+,,y,script,./test.sh -f tsim/parser/distinct.sim
+,,y,script,./test.sh -f tsim/parser/fill_us.sim
,,,script,./test.sh -f tsim/parser/fill.sim
-,,,script,./test.sh -f tsim/parser/first_last.sim
-,,,script,./test.sh -f tsim/parser/fourArithmetic-basic.sim
+,,y,script,./test.sh -f tsim/parser/first_last.sim
+,,y,script,./test.sh -f tsim/parser/fourArithmetic-basic.sim
,,,script,./test.sh -f tsim/parser/function.sim
-,,,script,./test.sh -f tsim/parser/groupby-basic.sim
+,,y,script,./test.sh -f tsim/parser/groupby-basic.sim
,,,script,./test.sh -f tsim/parser/groupby.sim
,,,script,./test.sh -f tsim/parser/having_child.sim
,,,script,./test.sh -f tsim/parser/having.sim
-,,,script,./test.sh -f tsim/parser/import_commit1.sim
-,,,script,./test.sh -f tsim/parser/import_commit2.sim
-,,,script,./test.sh -f tsim/parser/import_commit3.sim
-,,,script,./test.sh -f tsim/parser/import_file.sim
-,,,script,./test.sh -f tsim/parser/import.sim
-,,,script,./test.sh -f tsim/parser/insert_multiTbl.sim
-,,,script,./test.sh -f tsim/parser/insert_tb.sim
+,,y,script,./test.sh -f tsim/parser/import_commit1.sim
+,,y,script,./test.sh -f tsim/parser/import_commit2.sim
+,,y,script,./test.sh -f tsim/parser/import_commit3.sim
+,,y,script,./test.sh -f tsim/parser/import_file.sim
+,,y,script,./test.sh -f tsim/parser/import.sim
+,,y,script,./test.sh -f tsim/parser/insert_multiTbl.sim
+,,y,script,./test.sh -f tsim/parser/insert_tb.sim
,,,script,./test.sh -f tsim/parser/join_manyblocks.sim
-,,,script,./test.sh -f tsim/parser/join_multitables.sim
-,,,script,./test.sh -f tsim/parser/join_multivnode.sim
-,,,script,./test.sh -f tsim/parser/join.sim
-,,,script,./test.sh -f tsim/parser/last_cache.sim
-,,,script,./test.sh -f tsim/parser/last_groupby.sim
-,,,script,./test.sh -f tsim/parser/lastrow.sim
-,,,script,./test.sh -f tsim/parser/lastrow2.sim
-,,,script,./test.sh -f tsim/parser/like.sim
+,,y,script,./test.sh -f tsim/parser/join_multitables.sim
+,,y,script,./test.sh -f tsim/parser/join_multivnode.sim
+,,y,script,./test.sh -f tsim/parser/join.sim
+,,y,script,./test.sh -f tsim/parser/last_cache.sim
+,,y,script,./test.sh -f tsim/parser/last_groupby.sim
+,,y,script,./test.sh -f tsim/parser/lastrow.sim
+,,y,script,./test.sh -f tsim/parser/lastrow2.sim
+,,y,script,./test.sh -f tsim/parser/like.sim
,,,script,./test.sh -f tsim/parser/limit.sim
,,,script,./test.sh -f tsim/parser/limit1.sim
-,,,script,./test.sh -f tsim/parser/mixed_blocks.sim
-,,,script,./test.sh -f tsim/parser/nchar.sim
+,,y,script,./test.sh -f tsim/parser/mixed_blocks.sim
+,,y,script,./test.sh -f tsim/parser/nchar.sim
,,,script,./test.sh -f tsim/parser/nestquery.sim
,,,script,./test.sh -f tsim/parser/null_char.sim
-,,,script,./test.sh -f tsim/parser/precision_ns.sim
+,,y,script,./test.sh -f tsim/parser/precision_ns.sim
,,,script,./test.sh -f tsim/parser/projection_limit_offset.sim
-,,,script,./test.sh -f tsim/parser/regex.sim
-,,,script,./test.sh -f tsim/parser/select_across_vnodes.sim
-,,,script,./test.sh -f tsim/parser/select_distinct_tag.sim
-,,,script,./test.sh -f tsim/parser/select_from_cache_disk.sim
-,,,script,./test.sh -f tsim/parser/select_with_tags.sim
-,,,script,./test.sh -f tsim/parser/selectResNum.sim
+,,y,script,./test.sh -f tsim/parser/regex.sim
+,,y,script,./test.sh -f tsim/parser/select_across_vnodes.sim
+,,y,script,./test.sh -f tsim/parser/select_distinct_tag.sim
+,,y,script,./test.sh -f tsim/parser/select_from_cache_disk.sim
+,,y,script,./test.sh -f tsim/parser/select_with_tags.sim
+,,y,script,./test.sh -f tsim/parser/selectResNum.sim
,,,script,./test.sh -f tsim/parser/set_tag_vals.sim
-,,,script,./test.sh -f tsim/parser/single_row_in_tb.sim
+,,y,script,./test.sh -f tsim/parser/single_row_in_tb.sim
,,,script,./test.sh -f tsim/parser/sliding.sim
-,,,script,./test.sh -f tsim/parser/slimit_alter_tags.sim
-,,,script,./test.sh -f tsim/parser/slimit.sim
-,,,script,./test.sh -f tsim/parser/slimit1.sim
-,,,script,./test.sh -f tsim/parser/stableOp.sim
-,,,script,./test.sh -f tsim/parser/tags_dynamically_specifiy.sim
+,,y,script,./test.sh -f tsim/parser/slimit_alter_tags.sim
+,,y,script,./test.sh -f tsim/parser/slimit.sim
+,,y,script,./test.sh -f tsim/parser/slimit1.sim
+,,y,script,./test.sh -f tsim/parser/stableOp.sim
+,,y,script,./test.sh -f tsim/parser/tags_dynamically_specifiy.sim
,,,script,./test.sh -f tsim/parser/tags_filter.sim
,,,script,./test.sh -f tsim/parser/tbnameIn.sim
-,,,script,./test.sh -f tsim/parser/timestamp.sim
-,,,script,./test.sh -f tsim/parser/top_groupby.sim
-,,,script,./test.sh -f tsim/parser/topbot.sim
+,,y,script,./test.sh -f tsim/parser/timestamp.sim
+,,y,script,./test.sh -f tsim/parser/top_groupby.sim
+,,y,script,./test.sh -f tsim/parser/topbot.sim
,,,script,./test.sh -f tsim/parser/union.sim
-,,,script,./test.sh -f tsim/parser/union_sysinfo.sim
+,,y,script,./test.sh -f tsim/parser/union_sysinfo.sim
,,,script,./test.sh -f tsim/parser/where.sim
-,,,script,./test.sh -f tsim/query/charScalarFunction.sim
-,,,script,./test.sh -f tsim/query/explain.sim
-,,,script,./test.sh -f tsim/query/interval-offset.sim
-,,,script,./test.sh -f tsim/query/interval.sim
-,,,script,./test.sh -f tsim/query/scalarFunction.sim
-,,,script,./test.sh -f tsim/query/scalarNull.sim
+,,y,script,./test.sh -f tsim/query/charScalarFunction.sim
+,,y,script,./test.sh -f tsim/query/explain.sim
+,,y,script,./test.sh -f tsim/query/interval-offset.sim
+,,y,script,./test.sh -f tsim/query/interval.sim
+,,y,script,./test.sh -f tsim/query/scalarFunction.sim
+,,y,script,./test.sh -f tsim/query/scalarNull.sim
,,,script,./test.sh -f tsim/query/session.sim
,,,script,./test.sh -f tsim/query/udf.sim
-,,,script,./test.sh -f tsim/qnode/basic1.sim
+,,y,script,./test.sh -f tsim/qnode/basic1.sim
,,,script,./test.sh -f tsim/snode/basic1.sim
,,,script,./test.sh -f tsim/mnode/basic1.sim
,,,script,./test.sh -f tsim/mnode/basic2.sim
@@ -179,41 +179,41 @@
,,,script,./test.sh -f tsim/mnode/basic4.sim
,,,script,./test.sh -f tsim/mnode/basic5.sim
,,,script,./test.sh -f tsim/show/basic.sim
-,,,script,./test.sh -f tsim/table/autocreate.sim
-,,,script,./test.sh -f tsim/table/basic1.sim
+,,y,script,./test.sh -f tsim/table/autocreate.sim
+,,y,script,./test.sh -f tsim/table/basic1.sim
,,,script,./test.sh -f tsim/table/basic2.sim
-,,,script,./test.sh -f tsim/table/basic3.sim
-,,,script,./test.sh -f tsim/table/bigint.sim
-,,,script,./test.sh -f tsim/table/binary.sim
-,,,script,./test.sh -f tsim/table/bool.sim
+,,y,script,./test.sh -f tsim/table/basic3.sim
+,,y,script,./test.sh -f tsim/table/bigint.sim
+,,y,script,./test.sh -f tsim/table/binary.sim
+,,y,script,./test.sh -f tsim/table/bool.sim
,,,script,./test.sh -f tsim/table/column_name.sim
-,,,script,./test.sh -f tsim/table/column_num.sim
-,,,script,./test.sh -f tsim/table/column_value.sim
-,,,script,./test.sh -f tsim/table/column2.sim
-,,,script,./test.sh -f tsim/table/createmulti.sim
-,,,script,./test.sh -f tsim/table/date.sim
-,,,script,./test.sh -f tsim/table/db.table.sim
+,,y,script,./test.sh -f tsim/table/column_num.sim
+,,y,script,./test.sh -f tsim/table/column_value.sim
+,,y,script,./test.sh -f tsim/table/column2.sim
+,,y,script,./test.sh -f tsim/table/createmulti.sim
+,,y,script,./test.sh -f tsim/table/date.sim
+,,y,script,./test.sh -f tsim/table/db.table.sim
,,,script,./test.sh -f tsim/table/delete_reuse1.sim
,,,script,./test.sh -f tsim/table/delete_reuse2.sim
,,,script,./test.sh -f tsim/table/delete_writing.sim
-,,,script,./test.sh -f tsim/table/describe.sim
-,,,script,./test.sh -f tsim/table/double.sim
-,,,script,./test.sh -f tsim/table/float.sim
-,,,script,./test.sh -f tsim/table/hash.sim
-,,,script,./test.sh -f tsim/table/int.sim
-,,,script,./test.sh -f tsim/table/limit.sim
-,,,script,./test.sh -f tsim/table/smallint.sim
+,,y,script,./test.sh -f tsim/table/describe.sim
+,,y,script,./test.sh -f tsim/table/double.sim
+,,y,script,./test.sh -f tsim/table/float.sim
+,,y,script,./test.sh -f tsim/table/hash.sim
+,,y,script,./test.sh -f tsim/table/int.sim
+,,y,script,./test.sh -f tsim/table/limit.sim
+,,y,script,./test.sh -f tsim/table/smallint.sim
,,,script,./test.sh -f tsim/table/table_len.sim
-,,,script,./test.sh -f tsim/table/table.sim
-,,,script,./test.sh -f tsim/table/tinyint.sim
-,,,script,./test.sh -f tsim/table/vgroup.sim
+,,y,script,./test.sh -f tsim/table/table.sim
+,,y,script,./test.sh -f tsim/table/tinyint.sim
+,,y,script,./test.sh -f tsim/table/vgroup.sim
,,,script,./test.sh -f tsim/stream/basic0.sim -g
-,,,script,./test.sh -f tsim/stream/basic2.sim
+,,y,script,./test.sh -f tsim/stream/basic2.sim
,,,script,./test.sh -f tsim/stream/drop_stream.sim
-,,,script,./test.sh -f tsim/stream/fillHistoryBasic1.sim
-,,,script,./test.sh -f tsim/stream/fillHistoryBasic2.sim
+,,y,script,./test.sh -f tsim/stream/fillHistoryBasic1.sim
+,,y,script,./test.sh -f tsim/stream/fillHistoryBasic2.sim
,,,script,./test.sh -f tsim/stream/fillHistoryBasic3.sim
-,,,script,./test.sh -f tsim/stream/distributeInterval0.sim
+,,y,script,./test.sh -f tsim/stream/distributeInterval0.sim
,,,script,./test.sh -f tsim/stream/distributeIntervalRetrive0.sim
,,,script,./test.sh -f tsim/stream/distributeSession0.sim
,,,script,./test.sh -f tsim/stream/session0.sim
@@ -223,24 +223,24 @@
,,,script,./test.sh -f tsim/stream/triggerSession0.sim
,,,script,./test.sh -f tsim/stream/partitionby.sim
,,,script,./test.sh -f tsim/stream/partitionby1.sim
-,,,script,./test.sh -f tsim/stream/schedSnode.sim
+,,y,script,./test.sh -f tsim/stream/schedSnode.sim
,,,script,./test.sh -f tsim/stream/windowClose.sim
,,,script,./test.sh -f tsim/stream/ignoreExpiredData.sim
-,,,script,./test.sh -f tsim/stream/sliding.sim
+,,y,script,./test.sh -f tsim/stream/sliding.sim
,,,script,./test.sh -f tsim/stream/partitionbyColumnInterval.sim
,,,script,./test.sh -f tsim/stream/partitionbyColumnSession.sim
,,,script,./test.sh -f tsim/stream/partitionbyColumnState.sim
,,,script,./test.sh -f tsim/stream/deleteInterval.sim
,,,script,./test.sh -f tsim/stream/deleteSession.sim
,,,script,./test.sh -f tsim/stream/deleteState.sim
-,,,script,./test.sh -f tsim/stream/fillIntervalDelete0.sim
+,,y,script,./test.sh -f tsim/stream/fillIntervalDelete0.sim
,,,script,./test.sh -f tsim/stream/fillIntervalDelete1.sim
-,,,script,./test.sh -f tsim/stream/fillIntervalLinear.sim
-,,,script,./test.sh -f tsim/stream/fillIntervalPartitionBy.sim
-,,,script,./test.sh -f tsim/stream/fillIntervalPrevNext.sim
-,,,script,./test.sh -f tsim/stream/fillIntervalValue.sim
-,,,script,./test.sh -f tsim/trans/lossdata1.sim
-,,,script,./test.sh -f tsim/trans/create_db.sim
+,,y,script,./test.sh -f tsim/stream/fillIntervalLinear.sim
+,,y,script,./test.sh -f tsim/stream/fillIntervalPartitionBy.sim
+,,y,script,./test.sh -f tsim/stream/fillIntervalPrevNext.sim
+,,y,script,./test.sh -f tsim/stream/fillIntervalValue.sim
+,,y,script,./test.sh -f tsim/trans/lossdata1.sim
+,,y,script,./test.sh -f tsim/trans/create_db.sim
,,,script,./test.sh -f tsim/tmq/basic1.sim
,,,script,./test.sh -f tsim/tmq/basic2.sim
,,,script,./test.sh -f tsim/tmq/basic3.sim
@@ -253,30 +253,30 @@
,,,script,./test.sh -f tsim/tmq/topic.sim
,,,script,./test.sh -f tsim/tmq/snapshot.sim
,,,script,./test.sh -f tsim/tmq/snapshot1.sim
-,,,script,./test.sh -f tsim/stable/alter_comment.sim
-,,,script,./test.sh -f tsim/stable/alter_count.sim
-,,,script,./test.sh -f tsim/stable/alter_import.sim
-,,,script,./test.sh -f tsim/stable/alter_insert1.sim
-,,,script,./test.sh -f tsim/stable/alter_insert2.sim
-,,,script,./test.sh -f tsim/stable/alter_metrics.sim
-,,,script,./test.sh -f tsim/stable/column_add.sim
-,,,script,./test.sh -f tsim/stable/column_drop.sim
-,,,script,./test.sh -f tsim/stable/column_modify.sim
-,,,script,./test.sh -f tsim/stable/disk.sim
-,,,script,./test.sh -f tsim/stable/dnode3.sim
-,,,script,./test.sh -f tsim/stable/metrics.sim
-,,,script,./test.sh -f tsim/stable/refcount.sim
-,,,script,./test.sh -f tsim/stable/tag_add.sim
-,,,script,./test.sh -f tsim/stable/tag_drop.sim
-,,,script,./test.sh -f tsim/stable/tag_filter.sim
-,,,script,./test.sh -f tsim/stable/tag_modify.sim
-,,,script,./test.sh -f tsim/stable/tag_rename.sim
-,,,script,./test.sh -f tsim/stable/values.sim
-,,,script,./test.sh -f tsim/stable/vnode3.sim
-,,,script,./test.sh -f tsim/stable/metrics_idx.sim
+,,y,script,./test.sh -f tsim/stable/alter_comment.sim
+,,y,script,./test.sh -f tsim/stable/alter_count.sim
+,,y,script,./test.sh -f tsim/stable/alter_import.sim
+,,y,script,./test.sh -f tsim/stable/alter_insert1.sim
+,,y,script,./test.sh -f tsim/stable/alter_insert2.sim
+,,y,script,./test.sh -f tsim/stable/alter_metrics.sim
+,,y,script,./test.sh -f tsim/stable/column_add.sim
+,,y,script,./test.sh -f tsim/stable/column_drop.sim
+,,y,script,./test.sh -f tsim/stable/column_modify.sim
+,,y,script,./test.sh -f tsim/stable/disk.sim
+,,y,script,./test.sh -f tsim/stable/dnode3.sim
+,,y,script,./test.sh -f tsim/stable/metrics.sim
+,,y,script,./test.sh -f tsim/stable/refcount.sim
+,,y,script,./test.sh -f tsim/stable/tag_add.sim
+,,y,script,./test.sh -f tsim/stable/tag_drop.sim
+,,y,script,./test.sh -f tsim/stable/tag_filter.sim
+,,y,script,./test.sh -f tsim/stable/tag_modify.sim
+,,y,script,./test.sh -f tsim/stable/tag_rename.sim
+,,y,script,./test.sh -f tsim/stable/values.sim
+,,y,script,./test.sh -f tsim/stable/vnode3.sim
+,,y,script,./test.sh -f tsim/stable/metrics_idx.sim
,,,script,./test.sh -f tsim/sma/drop_sma.sim
,,,script,./test.sh -f tsim/sma/tsmaCreateInsertQuery.sim
-,,,script,./test.sh -f tsim/sma/rsmaCreateInsertQuery.sim
+,,y,script,./test.sh -f tsim/sma/rsmaCreateInsertQuery.sim
,,,script,./test.sh -f tsim/sma/rsmaPersistenceRecovery.sim
,,,script,./test.sh -f tsim/valgrind/checkError1.sim
,,,script,./test.sh -f tsim/valgrind/checkError2.sim
@@ -293,106 +293,106 @@
,,,script,./test.sh -f tsim/vnode/replica3_many.sim
,,,script,./test.sh -f tsim/vnode/replica3_import.sim
,,,script,./test.sh -f tsim/vnode/stable_balance_replica1.sim
-,,,script,./test.sh -f tsim/vnode/stable_dnode2_stop.sim
-,,,script,./test.sh -f tsim/vnode/stable_dnode2.sim
-,,,script,./test.sh -f tsim/vnode/stable_dnode3.sim
+,,y,script,./test.sh -f tsim/vnode/stable_dnode2_stop.sim
+,,y,script,./test.sh -f tsim/vnode/stable_dnode2.sim
+,,y,script,./test.sh -f tsim/vnode/stable_dnode3.sim
,,,script,./test.sh -f tsim/vnode/stable_replica3_dnode6.sim
,,,script,./test.sh -f tsim/vnode/stable_replica3_vnode3.sim
,,,script,./test.sh -f tsim/sync/3Replica1VgElect.sim
,,,script,./test.sh -f tsim/sync/3Replica5VgElect.sim
,,,script,./test.sh -f tsim/sync/oneReplica1VgElect.sim
,,,script,./test.sh -f tsim/sync/oneReplica5VgElect.sim
-,,,script,./test.sh -f tsim/catalog/alterInCurrent.sim
-,,,script,./test.sh -f tsim/scalar/in.sim
-,,,script,./test.sh -f tsim/scalar/scalar.sim
-,,,script,./test.sh -f tsim/scalar/filter.sim
+,,y,script,./test.sh -f tsim/catalog/alterInCurrent.sim
+,,y,script,./test.sh -f tsim/scalar/in.sim
+,,y,script,./test.sh -f tsim/scalar/scalar.sim
+,,y,script,./test.sh -f tsim/scalar/filter.sim
,,,script,./test.sh -f tsim/scalar/caseWhen.sim
-,,,script,./test.sh -f tsim/alter/cached_schema_after_alter.sim
-,,,script,./test.sh -f tsim/alter/dnode.sim
-,,,script,./test.sh -f tsim/alter/table.sim
-,,,script,./test.sh -f tsim/cache/new_metrics.sim
-,,,script,./test.sh -f tsim/cache/restart_table.sim
-,,,script,./test.sh -f tsim/cache/restart_metrics.sim
-,,,script,./test.sh -f tsim/column/commit.sim
-,,,script,./test.sh -f tsim/column/metrics.sim
-,,,script,./test.sh -f tsim/column/table.sim
-,,,script,./test.sh -f tsim/compress/commitlog.sim
-,,,script,./test.sh -f tsim/compress/compress2.sim
-,,,script,./test.sh -f tsim/compress/compress.sim
-,,,script,./test.sh -f tsim/compress/uncompress.sim
-,,,script,./test.sh -f tsim/compute/avg.sim
-,,,script,./test.sh -f tsim/compute/block_dist.sim
-,,,script,./test.sh -f tsim/compute/bottom.sim
-,,,script,./test.sh -f tsim/compute/count.sim
-,,,script,./test.sh -f tsim/compute/diff.sim
-,,,script,./test.sh -f tsim/compute/diff2.sim
-,,,script,./test.sh -f tsim/compute/first.sim
-,,,script,./test.sh -f tsim/compute/interval.sim
-,,,script,./test.sh -f tsim/compute/last_row.sim
-,,,script,./test.sh -f tsim/compute/last.sim
-,,,script,./test.sh -f tsim/compute/leastsquare.sim
-,,,script,./test.sh -f tsim/compute/max.sim
-,,,script,./test.sh -f tsim/compute/min.sim
-,,,script,./test.sh -f tsim/compute/null.sim
-,,,script,./test.sh -f tsim/compute/percentile.sim
-,,,script,./test.sh -f tsim/compute/stddev.sim
-,,,script,./test.sh -f tsim/compute/sum.sim
-,,,script,./test.sh -f tsim/compute/top.sim
-,,,script,./test.sh -f tsim/field/2.sim
-,,,script,./test.sh -f tsim/field/3.sim
-,,,script,./test.sh -f tsim/field/4.sim
-,,,script,./test.sh -f tsim/field/5.sim
-,,,script,./test.sh -f tsim/field/6.sim
-,,,script,./test.sh -f tsim/field/binary.sim
-,,,script,./test.sh -f tsim/field/bigint.sim
-,,,script,./test.sh -f tsim/field/bool.sim
-,,,script,./test.sh -f tsim/field/double.sim
-,,,script,./test.sh -f tsim/field/float.sim
-,,,script,./test.sh -f tsim/field/int.sim
-,,,script,./test.sh -f tsim/field/single.sim
-,,,script,./test.sh -f tsim/field/smallint.sim
-,,,script,./test.sh -f tsim/field/tinyint.sim
-,,,script,./test.sh -f tsim/field/unsigined_bigint.sim
-,,,script,./test.sh -f tsim/vector/metrics_field.sim
-,,,script,./test.sh -f tsim/vector/metrics_mix.sim
-,,,script,./test.sh -f tsim/vector/metrics_query.sim
-,,,script,./test.sh -f tsim/vector/metrics_tag.sim
-,,,script,./test.sh -f tsim/vector/metrics_time.sim
-,,,script,./test.sh -f tsim/vector/multi.sim
-,,,script,./test.sh -f tsim/vector/single.sim
-,,,script,./test.sh -f tsim/vector/table_field.sim
-,,,script,./test.sh -f tsim/vector/table_mix.sim
-,,,script,./test.sh -f tsim/vector/table_query.sim
-,,,script,./test.sh -f tsim/vector/table_time.sim
-,,,script,./test.sh -f tsim/wal/kill.sim
-,,,script,./test.sh -f tsim/tag/3.sim
-,,,script,./test.sh -f tsim/tag/4.sim
-,,,script,./test.sh -f tsim/tag/5.sim
-,,,script,./test.sh -f tsim/tag/6.sim
-,,,script,./test.sh -f tsim/tag/add.sim
-,,,script,./test.sh -f tsim/tag/bigint.sim
-,,,script,./test.sh -f tsim/tag/binary_binary.sim
-,,,script,./test.sh -f tsim/tag/binary.sim
-,,,script,./test.sh -f tsim/tag/bool_binary.sim
-,,,script,./test.sh -f tsim/tag/bool_int.sim
-,,,script,./test.sh -f tsim/tag/bool.sim
-,,,script,./test.sh -f tsim/tag/change.sim
-,,,script,./test.sh -f tsim/tag/column.sim
-,,,script,./test.sh -f tsim/tag/commit.sim
-,,,script,./test.sh -f tsim/tag/create.sim
-,,,script,./test.sh -f tsim/tag/delete.sim
-,,,script,./test.sh -f tsim/tag/double.sim
-,,,script,./test.sh -f tsim/tag/filter.sim
-,,,script,./test.sh -f tsim/tag/float.sim
-,,,script,./test.sh -f tsim/tag/int_binary.sim
-,,,script,./test.sh -f tsim/tag/int_float.sim
-,,,script,./test.sh -f tsim/tag/int.sim
-,,,script,./test.sh -f tsim/tag/set.sim
-,,,script,./test.sh -f tsim/tag/smallint.sim
-,,,script,./test.sh -f tsim/tag/tinyint.sim
-,,,script,./test.sh -f tsim/tag/drop_tag.sim
-,,,script,./test.sh -f tsim/tag/tbNameIn.sim
-,,,script,./test.sh -f tmp/monitor.sim
+,,y,script,./test.sh -f tsim/alter/cached_schema_after_alter.sim
+,,y,script,./test.sh -f tsim/alter/dnode.sim
+,,y,script,./test.sh -f tsim/alter/table.sim
+,,y,script,./test.sh -f tsim/cache/new_metrics.sim
+,,y,script,./test.sh -f tsim/cache/restart_table.sim
+,,y,script,./test.sh -f tsim/cache/restart_metrics.sim
+,,y,script,./test.sh -f tsim/column/commit.sim
+,,y,script,./test.sh -f tsim/column/metrics.sim
+,,y,script,./test.sh -f tsim/column/table.sim
+,,y,script,./test.sh -f tsim/compress/commitlog.sim
+,,y,script,./test.sh -f tsim/compress/compress2.sim
+,,y,script,./test.sh -f tsim/compress/compress.sim
+,,y,script,./test.sh -f tsim/compress/uncompress.sim
+,,y,script,./test.sh -f tsim/compute/avg.sim
+,,y,script,./test.sh -f tsim/compute/block_dist.sim
+,,y,script,./test.sh -f tsim/compute/bottom.sim
+,,y,script,./test.sh -f tsim/compute/count.sim
+,,y,script,./test.sh -f tsim/compute/diff.sim
+,,y,script,./test.sh -f tsim/compute/diff2.sim
+,,y,script,./test.sh -f tsim/compute/first.sim
+,,y,script,./test.sh -f tsim/compute/interval.sim
+,,y,script,./test.sh -f tsim/compute/last_row.sim
+,,y,script,./test.sh -f tsim/compute/last.sim
+,,y,script,./test.sh -f tsim/compute/leastsquare.sim
+,,y,script,./test.sh -f tsim/compute/max.sim
+,,y,script,./test.sh -f tsim/compute/min.sim
+,,y,script,./test.sh -f tsim/compute/null.sim
+,,y,script,./test.sh -f tsim/compute/percentile.sim
+,,y,script,./test.sh -f tsim/compute/stddev.sim
+,,y,script,./test.sh -f tsim/compute/sum.sim
+,,y,script,./test.sh -f tsim/compute/top.sim
+,,y,script,./test.sh -f tsim/field/2.sim
+,,y,script,./test.sh -f tsim/field/3.sim
+,,y,script,./test.sh -f tsim/field/4.sim
+,,y,script,./test.sh -f tsim/field/5.sim
+,,y,script,./test.sh -f tsim/field/6.sim
+,,y,script,./test.sh -f tsim/field/binary.sim
+,,y,script,./test.sh -f tsim/field/bigint.sim
+,,y,script,./test.sh -f tsim/field/bool.sim
+,,y,script,./test.sh -f tsim/field/double.sim
+,,y,script,./test.sh -f tsim/field/float.sim
+,,y,script,./test.sh -f tsim/field/int.sim
+,,y,script,./test.sh -f tsim/field/single.sim
+,,y,script,./test.sh -f tsim/field/smallint.sim
+,,y,script,./test.sh -f tsim/field/tinyint.sim
+,,y,script,./test.sh -f tsim/field/unsigined_bigint.sim
+,,y,script,./test.sh -f tsim/vector/metrics_field.sim
+,,y,script,./test.sh -f tsim/vector/metrics_mix.sim
+,,y,script,./test.sh -f tsim/vector/metrics_query.sim
+,,y,script,./test.sh -f tsim/vector/metrics_tag.sim
+,,y,script,./test.sh -f tsim/vector/metrics_time.sim
+,,y,script,./test.sh -f tsim/vector/multi.sim
+,,y,script,./test.sh -f tsim/vector/single.sim
+,,y,script,./test.sh -f tsim/vector/table_field.sim
+,,y,script,./test.sh -f tsim/vector/table_mix.sim
+,,y,script,./test.sh -f tsim/vector/table_query.sim
+,,y,script,./test.sh -f tsim/vector/table_time.sim
+,,y,script,./test.sh -f tsim/wal/kill.sim
+,,y,script,./test.sh -f tsim/tag/3.sim
+,,y,script,./test.sh -f tsim/tag/4.sim
+,,y,script,./test.sh -f tsim/tag/5.sim
+,,y,script,./test.sh -f tsim/tag/6.sim
+,,y,script,./test.sh -f tsim/tag/add.sim
+,,y,script,./test.sh -f tsim/tag/bigint.sim
+,,y,script,./test.sh -f tsim/tag/binary_binary.sim
+,,y,script,./test.sh -f tsim/tag/binary.sim
+,,y,script,./test.sh -f tsim/tag/bool_binary.sim
+,,y,script,./test.sh -f tsim/tag/bool_int.sim
+,,y,script,./test.sh -f tsim/tag/bool.sim
+,,y,script,./test.sh -f tsim/tag/change.sim
+,,y,script,./test.sh -f tsim/tag/column.sim
+,,y,script,./test.sh -f tsim/tag/commit.sim
+,,y,script,./test.sh -f tsim/tag/create.sim
+,,y,script,./test.sh -f tsim/tag/delete.sim
+,,y,script,./test.sh -f tsim/tag/double.sim
+,,y,script,./test.sh -f tsim/tag/filter.sim
+,,y,script,./test.sh -f tsim/tag/float.sim
+,,y,script,./test.sh -f tsim/tag/int_binary.sim
+,,y,script,./test.sh -f tsim/tag/int_float.sim
+,,y,script,./test.sh -f tsim/tag/int.sim
+,,y,script,./test.sh -f tsim/tag/set.sim
+,,y,script,./test.sh -f tsim/tag/smallint.sim
+,,y,script,./test.sh -f tsim/tag/tinyint.sim
+,,y,script,./test.sh -f tsim/tag/drop_tag.sim
+,,y,script,./test.sh -f tsim/tag/tbNameIn.sim
+,,y,script,./test.sh -f tmp/monitor.sim
#system test
@@ -1006,6 +1006,7 @@
,,,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/sample_csv_json.py
,,,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/sml_json_alltypes.py
,,,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/taosdemoTestQueryWithJson.py -R
+,,,develop-test,python3 ./test.py -f 5-taos-tools/taosbenchmark/telnet_tcp.py -R
#docs-examples test
,,,docs-examples-test,bash python.sh
diff --git a/tests/pytest/util/taosadapter.py b/tests/pytest/util/taosadapter.py
index 0307675dfb..440c23dc65 100644
--- a/tests/pytest/util/taosadapter.py
+++ b/tests/pytest/util/taosadapter.py
@@ -13,7 +13,7 @@ class TAdapter:
"debug" : True,
"taosConfigDir" : "",
"port" : 6041,
- "logLevel" : "debug",
+ "logLevel" : "error",
"cors" : {
"allowAllOrigins" : True,
},
@@ -49,25 +49,25 @@ class TAdapter:
"writeInterval" : "30s"
},
"opentsdb" : {
- "enable" : False
+ "enable" : True
},
"influxdb" : {
- "enable" : False
+ "enable" : True
},
"statsd" : {
- "enable" : False
+ "enable" : True
},
"collectd" : {
- "enable" : False
+ "enable" : True
},
"opentsdb_telnet" : {
- "enable" : False
+ "enable" : True
},
"node_exporter" : {
- "enable" : False
+ "enable" : True
},
"prometheus" : {
- "enable" : False
+ "enable" : True
},
}
# TODO: add taosadapter env:
@@ -164,7 +164,7 @@ class TAdapter:
if platform.system().lower() == 'windows':
cmd = f"mintty -h never {bin_path} -c {self.cfg_dir}"
else:
- cmd = f"nohup {bin_path} -c {self.cfg_path} > /dev/null 2>&1 & "
+ cmd = f"nohup {bin_path} -c {self.cfg_path} > /dev/null & "
if self.remoteIP:
self.remote_exec(self.taosadapter_cfg_dict, f"tAdapter.deployed=1\ntAdapter.log_dir={self.log_dir}\ntAdapter.cfg_dir={self.cfg_dir}\ntAdapter.start()")
@@ -213,7 +213,7 @@ class TAdapter:
if platform.system().lower() == 'windows':
cmd = f"mintty -h never {bin_path} -c {self.cfg_dir}"
else:
- cmd = f"nohup {bin_path} -c {self.cfg_path} > /dev/null 2>&1 & "
+ cmd = f"nohup {bin_path} -c {self.cfg_path} > /dev/null & "
if self.remoteIP:
self.remote_exec(self.taosadapter_cfg_dict, f"tAdapter.deployed=1\ntAdapter.log_dir={self.log_dir}\ntAdapter.cfg_dir={self.cfg_dir}\ntAdapter.start()")
@@ -243,7 +243,7 @@ class TAdapter:
psCmd, shell=True)
while(processID):
- killCmd = f"pkill {signal} {processID} > /dev/null 2>&1"
+ killCmd = f"pkill {signal} {processID} > /dev/null "
os.system(killCmd)
time.sleep(1)
processID = subprocess.check_output(
@@ -256,9 +256,9 @@ class TAdapter:
# fuserCmd = f"fuser -k -n tcp {port} > /dev/null"
# os.system(fuserCmd)
- self.running = 0
- tdLog.debug(f"taosadapter is stopped by kill {signal}")
+ self.running = 0
+ tdLog.debug(f"taosadapter is stopped by kill {signal}")
-tAdapter = TAdapter()
\ No newline at end of file
+tAdapter = TAdapter()
diff --git a/tests/script/sh/checkAsan.sh b/tests/script/sh/checkAsan.sh
index 4d1b0a3d6b..184dc9a88f 100755
--- a/tests/script/sh/checkAsan.sh
+++ b/tests/script/sh/checkAsan.sh
@@ -20,7 +20,7 @@ LOG_DIR=$TAOS_DIR/sim/tsim/asan
error_num=`cat ${LOG_DIR}/*.asan | grep "ERROR" | wc -l`
memory_leak=`cat ${LOG_DIR}/*.asan | grep "Direct leak" | wc -l`
indirect_leak=`cat ${LOG_DIR}/*.asan | grep "Indirect leak" | wc -l`
-runtime_error=`cat ${LOG_DIR}/*.asan | grep "runtime error" | wc -l`
+runtime_error=`cat ${LOG_DIR}/*.asan | grep "runtime error" | grep -v "trees.c:873" | wc -l`
echo -e "\033[44;32;1m"asan error_num: $error_num"\033[0m"
echo -e "\033[44;32;1m"asan memory_leak: $memory_leak"\033[0m"
diff --git a/tests/system-test/test.py b/tests/system-test/test.py
index e171baa656..d942147c03 100644
--- a/tests/system-test/test.py
+++ b/tests/system-test/test.py
@@ -215,7 +215,7 @@ if __name__ == "__main__":
time.sleep(2)
if restful:
- toBeKilled = "taosadapt"
+ toBeKilled = "taosadapter"
# killCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}' | xargs kill -TERM > /dev/null 2>&1" % toBeKilled
killCmd = f"pkill {toBeKilled}"
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
index 79be05e9fc..0f3c383b9e 100644
--- a/tools/CMakeLists.txt
+++ b/tools/CMakeLists.txt
@@ -87,6 +87,7 @@ ELSE ()
MESSAGE("CURRENT SOURCE DIR ${CMAKE_CURRENT_SOURCE_DIR}")
IF (TD_WINDOWS)
+ MESSAGE("Building taosAdapter on Windows")
INCLUDE(ExternalProject)
ExternalProject_Add(taosadapter
PREFIX "taosadapter"
@@ -104,14 +105,18 @@ ELSE ()
COMMAND go build -a -o taosadapter-debug.exe -ldflags "-X github.com/taosdata/taosadapter/v3/version.Version=${taos_version} -X github.com/taosdata/taosadapter/v3/version.CommitID=${taosadapter_commit_sha1}"
INSTALL_COMMAND
- COMMAND cmake -E time upx taosadapter ||:
- COMMAND cmake -E copy taosadapter.exe ${CMAKE_BINARY_DIR}/build/bin
+ COMMAND cmake -E echo "Comparessing taosadapter.exe"
+ COMMAND cmake -E time upx taosadapter.exe
+ COMMAND cmake -E echo "Copy taosadapter.exe"
+ COMMAND cmake -E copy taosadapter.exe ${CMAKE_BINARY_DIR}/build/bin/taosadapter.exe
COMMAND cmake -E make_directory ${CMAKE_BINARY_DIR}/test/cfg/
+ COMMAND cmake -E echo "Copy taosadapter.toml"
COMMAND cmake -E copy ./example/config/taosadapter.toml ${CMAKE_BINARY_DIR}/test/cfg/
- COMMAND cmake -E copy ./taosadapter.service ${CMAKE_BINARY_DIR}/test/cfg/
+ COMMAND cmake -E echo "Copy taosadapter-debug.exe"
COMMAND cmake -E copy taosadapter-debug.exe ${CMAKE_BINARY_DIR}/build/bin
)
ELSE (TD_WINDOWS)
+ MESSAGE("Building taosAdapter on non-Windows")
INCLUDE(ExternalProject)
ExternalProject_Add(taosadapter
PREFIX "taosadapter"
@@ -126,11 +131,15 @@ ELSE ()
COMMAND CGO_CFLAGS=-I${CMAKE_CURRENT_SOURCE_DIR}/../include/client CGO_LDFLAGS=-L${CMAKE_BINARY_DIR}/build/lib go build -a -ldflags "-s -w -X github.com/taosdata/taosadapter/v3/version.Version=${taos_version} -X github.com/taosdata/taosadapter/v3/version.CommitID=${taosadapter_commit_sha1}"
COMMAND CGO_CFLAGS=-I${CMAKE_CURRENT_SOURCE_DIR}/../include/client CGO_LDFLAGS=-L${CMAKE_BINARY_DIR}/build/lib go build -a -o taosadapter-debug -ldflags "-X github.com/taosdata/taosadapter/v3/version.Version=${taos_version} -X github.com/taosdata/taosadapter/v3/version.CommitID=${taosadapter_commit_sha1}"
INSTALL_COMMAND
+ COMMAND cmake -E echo "Comparessing taosadapter.exe"
COMMAND upx taosadapter || :
+ COMMAND cmake -E echo "Copy taosadapter"
COMMAND cmake -E copy taosadapter ${CMAKE_BINARY_DIR}/build/bin
COMMAND cmake -E make_directory ${CMAKE_BINARY_DIR}/test/cfg/
+ COMMAND cmake -E echo "Copy taosadapter.toml"
COMMAND cmake -E copy ./example/config/taosadapter.toml ${CMAKE_BINARY_DIR}/test/cfg/
COMMAND cmake -E copy ./taosadapter.service ${CMAKE_BINARY_DIR}/test/cfg/
+ COMMAND cmake -E echo "Copy taosadapter-debug"
COMMAND cmake -E copy taosadapter-debug ${CMAKE_BINARY_DIR}/build/bin
)
ENDIF (TD_WINDOWS)