Merge branch '3.0' of https://github.com/taosdata/TDengine into feat/vnode_compact
This commit is contained in:
commit
de6be90cb5
|
@ -1,6 +1,7 @@
|
||||||
cmake_minimum_required(VERSION 3.0)
|
cmake_minimum_required(VERSION 3.0)
|
||||||
|
|
||||||
set(CMAKE_VERBOSE_MAKEFILE OFF)
|
set(CMAKE_VERBOSE_MAKEFILE OFF)
|
||||||
|
set(TD_BUILD_TAOSA_INTERNAL FALSE)
|
||||||
|
|
||||||
#set output directory
|
#set output directory
|
||||||
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/build/lib)
|
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/build/lib)
|
||||||
|
|
|
@ -178,76 +178,138 @@ SHOW TABLE DISTRIBUTED table_name;
|
||||||
|
|
||||||
Shows how table data is distributed.
|
Shows how table data is distributed.
|
||||||
|
|
||||||
Examples: show table distributed d0\G; Display the block distribution of table `d0` in detailed format.
|
Examples: Below is an example of this command to display the block distribution of table `d0` in detailed format.
|
||||||
|
|
||||||
|
```sql
|
||||||
|
show table distributed d0\G;
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary> Show Example </summary>
|
||||||
|
<pre><code>
|
||||||
*************************** 1.row ***************************
|
*************************** 1.row ***************************
|
||||||
_block_dist: Total_Blocks=[5] Total_Size=[93.65 Kb] Average_size=[18.73 Kb] Compression_Ratio=[23.98 %]
|
_block_dist: Total_Blocks=[5] Total_Size=[93.65 Kb] Average_size=[18.73 Kb] Compression_Ratio=[23.98 %]
|
||||||
|
|
||||||
Total_Blocks : Table `d0` contains total 5 blocks
|
Total_Blocks : Table `d0` contains total 5 blocks
|
||||||
|
|
||||||
Total_Size: The total size of all the data blocks in table `d0` is 93.65 KB
|
Total_Size: The total size of all the data blocks in table `d0` is 93.65 KB
|
||||||
|
|
||||||
Average_size: The average size of each block is 18.73 KB
|
Average_size: The average size of each block is 18.73 KB
|
||||||
|
|
||||||
Compression_Ratio: The data compression rate is 23.98%
|
Compression_Ratio: The data compression rate is 23.98%
|
||||||
|
|
||||||
*************************** 2.row ***************************
|
*************************** 2.row ***************************
|
||||||
_block_dist: Total_Rows=[20000] Inmem_Rows=[0] MinRows=[3616] MaxRows=[4096] Average_Rows=[4000]
|
_block_dist: Total_Rows=[20000] Inmem_Rows=[0] MinRows=[3616] MaxRows=[4096] Average_Rows=[4000]
|
||||||
|
|
||||||
Total_Rows: Table `d0` contains 20,000 rows
|
Total_Rows: Table `d0` contains 20,000 rows
|
||||||
|
|
||||||
Inmem_Rows: The rows still in memory, i.e. not committed in disk, is 0, i.e. none such rows
|
Inmem_Rows: The rows still in memory, i.e. not committed in disk, is 0, i.e. none such rows
|
||||||
|
|
||||||
MinRows: The minimum number of rows in a block is 3,616
|
MinRows: The minimum number of rows in a block is 3,616
|
||||||
|
|
||||||
MaxRows: The maximum number of rows in a block is 4,096B
|
MaxRows: The maximum number of rows in a block is 4,096B
|
||||||
|
|
||||||
Average_Rows: The average number of rows in a block is 4,000
|
Average_Rows: The average number of rows in a block is 4,000
|
||||||
|
|
||||||
*************************** 3.row ***************************
|
*************************** 3.row ***************************
|
||||||
_block_dist: Total_Tables=[1] Total_Files=[2]
|
_block_dist: Total_Tables=[1] Total_Files=[2]
|
||||||
|
|
||||||
Total_Tables: The number of child tables, 1 in this example
|
Total_Tables: The number of child tables, 1 in this example
|
||||||
|
|
||||||
Total_Files: The number of files storing the table's data, 2 in this example
|
Total_Files: The number of files storing the table's data, 2 in this example
|
||||||
|
|
||||||
*************************** 4.row ***************************
|
*************************** 4.row ***************************
|
||||||
|
|
||||||
_block_dist: --------------------------------------------------------------------------------
|
_block_dist: --------------------------------------------------------------------------------
|
||||||
|
|
||||||
*************************** 5.row ***************************
|
*************************** 5.row ***************************
|
||||||
|
|
||||||
_block_dist: 0100 |
|
_block_dist: 0100 |
|
||||||
|
|
||||||
*************************** 6.row ***************************
|
*************************** 6.row ***************************
|
||||||
|
|
||||||
_block_dist: 0299 |
|
_block_dist: 0299 |
|
||||||
|
|
||||||
*************************** 7.row ***************************
|
*************************** 7.row ***************************
|
||||||
|
|
||||||
_block_dist: 0498 |
|
_block_dist: 0498 |
|
||||||
|
|
||||||
*************************** 8.row ***************************
|
*************************** 8.row ***************************
|
||||||
|
|
||||||
_block_dist: 0697 |
|
_block_dist: 0697 |
|
||||||
|
|
||||||
*************************** 9.row ***************************
|
*************************** 9.row ***************************
|
||||||
|
|
||||||
_block_dist: 0896 |
|
_block_dist: 0896 |
|
||||||
|
|
||||||
*************************** 10.row ***************************
|
*************************** 10.row ***************************
|
||||||
|
|
||||||
_block_dist: 1095 |
|
_block_dist: 1095 |
|
||||||
|
|
||||||
*************************** 11.row ***************************
|
*************************** 11.row ***************************
|
||||||
|
|
||||||
_block_dist: 1294 |
|
_block_dist: 1294 |
|
||||||
|
|
||||||
*************************** 12.row ***************************
|
*************************** 12.row ***************************
|
||||||
|
|
||||||
_block_dist: 1493 |
|
_block_dist: 1493 |
|
||||||
|
|
||||||
*************************** 13.row ***************************
|
*************************** 13.row ***************************
|
||||||
|
|
||||||
_block_dist: 1692 |
|
_block_dist: 1692 |
|
||||||
|
|
||||||
*************************** 14.row ***************************
|
*************************** 14.row ***************************
|
||||||
|
|
||||||
_block_dist: 1891 |
|
_block_dist: 1891 |
|
||||||
|
|
||||||
*************************** 15.row ***************************
|
*************************** 15.row ***************************
|
||||||
|
|
||||||
_block_dist: 2090 |
|
_block_dist: 2090 |
|
||||||
|
|
||||||
*************************** 16.row ***************************
|
*************************** 16.row ***************************
|
||||||
|
|
||||||
_block_dist: 2289 |
|
_block_dist: 2289 |
|
||||||
|
|
||||||
*************************** 17.row ***************************
|
*************************** 17.row ***************************
|
||||||
|
|
||||||
_block_dist: 2488 |
|
_block_dist: 2488 |
|
||||||
|
|
||||||
*************************** 18.row ***************************
|
*************************** 18.row ***************************
|
||||||
|
|
||||||
_block_dist: 2687 |
|
_block_dist: 2687 |
|
||||||
|
|
||||||
*************************** 19.row ***************************
|
*************************** 19.row ***************************
|
||||||
|
|
||||||
_block_dist: 2886 |
|
_block_dist: 2886 |
|
||||||
|
|
||||||
*************************** 20.row ***************************
|
*************************** 20.row ***************************
|
||||||
|
|
||||||
_block_dist: 3085 |
|
_block_dist: 3085 |
|
||||||
|
|
||||||
*************************** 21.row ***************************
|
*************************** 21.row ***************************
|
||||||
|
|
||||||
_block_dist: 3284 |
|
_block_dist: 3284 |
|
||||||
|
|
||||||
*************************** 22.row ***************************
|
*************************** 22.row ***************************
|
||||||
|
|
||||||
_block_dist: 3483 ||||||||||||||||| 1 (20.00%)
|
_block_dist: 3483 ||||||||||||||||| 1 (20.00%)
|
||||||
|
|
||||||
*************************** 23.row ***************************
|
*************************** 23.row ***************************
|
||||||
|
|
||||||
_block_dist: 3682 |
|
_block_dist: 3682 |
|
||||||
|
|
||||||
*************************** 24.row ***************************
|
*************************** 24.row ***************************
|
||||||
|
|
||||||
_block_dist: 3881 ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 4 (80.00%)
|
_block_dist: 3881 ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 4 (80.00%)
|
||||||
|
|
||||||
Query OK, 24 row(s) in set (0.002444s)
|
Query OK, 24 row(s) in set (0.002444s)
|
||||||
|
|
||||||
The above show the block distribution percentage according to the number of rows in each block. In the above example, `_block_dist: 3483 ||||||||||||||||| 1 (20.00%)` means there is one block whose rows is between 3,483 and 3,681. `_block_dist: 3881 ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 4 (80.00%)` means there are 4 blocks whose rows is between 3,881 and 4,096. The number of blocks whose rows fall in other range is zero.
|
</code></pre>
|
||||||
|
</details>
|
||||||
|
|
||||||
|
The above show the block distribution percentage according to the number of rows in each block. In the above example, we can get below information:
|
||||||
|
- `_block_dist: 3483 ||||||||||||||||| 1 (20.00%)` means there is one block whose rows is between 3,483 and 3,681.
|
||||||
|
- `_block_dist: 3881 ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 4 (80.00%)` means there are 4 blocks whose rows is between 3,881 and 4,096. - The number of blocks whose rows fall in other range is zero.
|
||||||
|
|
||||||
## SHOW TAGS
|
## SHOW TAGS
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,10 @@ For TDengine 2.x installation packages by version, please visit [here](https://w
|
||||||
|
|
||||||
import Release from "/components/ReleaseV3";
|
import Release from "/components/ReleaseV3";
|
||||||
|
|
||||||
|
## 3.0.2.2
|
||||||
|
|
||||||
|
<Release type="tdengine" version="3.0.2.2" />
|
||||||
|
|
||||||
## 3.0.2.1
|
## 3.0.2.1
|
||||||
|
|
||||||
<Release type="tdengine" version="3.0.2.1" />
|
<Release type="tdengine" version="3.0.2.1" />
|
||||||
|
|
|
@ -10,6 +10,10 @@ For other historical version installers, please visit [here](https://www.taosdat
|
||||||
|
|
||||||
import Release from "/components/ReleaseV3";
|
import Release from "/components/ReleaseV3";
|
||||||
|
|
||||||
|
## 2.4.0
|
||||||
|
|
||||||
|
<Release type="tools" version="2.4.0" />
|
||||||
|
|
||||||
## 2.3.3
|
## 2.3.3
|
||||||
|
|
||||||
<Release type="tools" version="2.3.3" />
|
<Release type="tools" version="2.3.3" />
|
||||||
|
|
|
@ -183,6 +183,10 @@ SHOW TABLE DISTRIBUTED table_name;
|
||||||
|
|
||||||
语句: show table distributed d0\G; 竖行显示表 d0 的 BLOCK 分布情况
|
语句: show table distributed d0\G; 竖行显示表 d0 的 BLOCK 分布情况
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>显示示例</summary>
|
||||||
|
<pre><code>
|
||||||
|
|
||||||
*************************** 1.row ***************************
|
*************************** 1.row ***************************
|
||||||
|
|
||||||
_block_dist: Total_Blocks=[5] Total_Size=[93.65 Kb] Average_size=[18.73 Kb] Compression_Ratio=[23.98 %]
|
_block_dist: Total_Blocks=[5] Total_Size=[93.65 Kb] Average_size=[18.73 Kb] Compression_Ratio=[23.98 %]
|
||||||
|
@ -244,6 +248,8 @@ _block_dist: 3881 ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||
|
|
||||||
Query OK, 24 row(s) in set (0.002444s)
|
Query OK, 24 row(s) in set (0.002444s)
|
||||||
|
|
||||||
|
</code></pre>
|
||||||
|
</details>
|
||||||
|
|
||||||
上面是块中包含数据行数的块儿分布情况图,这里的 0100 0299 0498 … 表示的是每个块中包含的数据行数,上面的意思就是这个表的 5 个块,分布在 3483 ~3681 行的块有 1 个,占整个块的 20%,分布在 3881 ~ 4096(最大行数)的块数为 4 个,占整个块的 80%, 其它区域内分布块数为 0。
|
上面是块中包含数据行数的块儿分布情况图,这里的 0100 0299 0498 … 表示的是每个块中包含的数据行数,上面的意思就是这个表的 5 个块,分布在 3483 ~3681 行的块有 1 个,占整个块的 20%,分布在 3881 ~ 4096(最大行数)的块数为 4 个,占整个块的 80%, 其它区域内分布块数为 0。
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,10 @@ TDengine 2.x 各版本安装包请访问[这里](https://www.taosdata.com/all-do
|
||||||
|
|
||||||
import Release from "/components/ReleaseV3";
|
import Release from "/components/ReleaseV3";
|
||||||
|
|
||||||
|
## 3.0.2.2
|
||||||
|
|
||||||
|
<Release type="tdengine" version="3.0.2.2" />
|
||||||
|
|
||||||
## 3.0.2.1
|
## 3.0.2.1
|
||||||
|
|
||||||
<Release type="tdengine" version="3.0.2.1" />
|
<Release type="tdengine" version="3.0.2.1" />
|
||||||
|
|
|
@ -10,6 +10,10 @@ taosTools 各版本安装包下载链接如下:
|
||||||
|
|
||||||
import Release from "/components/ReleaseV3";
|
import Release from "/components/ReleaseV3";
|
||||||
|
|
||||||
|
## 2.4.0
|
||||||
|
|
||||||
|
<Release type="tools" version="2.4.0" />
|
||||||
|
|
||||||
## 2.3.3
|
## 2.3.3
|
||||||
|
|
||||||
<Release type="tools" version="2.3.3" />
|
<Release type="tools" version="2.3.3" />
|
||||||
|
|
|
@ -300,7 +300,7 @@ typedef struct SShowTableTagsStmt {
|
||||||
SNodeList* pTags;
|
SNodeList* pTags;
|
||||||
} SShowTableTagsStmt;
|
} SShowTableTagsStmt;
|
||||||
|
|
||||||
typedef enum EIndexType { INDEX_TYPE_SMA = 1, INDEX_TYPE_FULLTEXT } EIndexType;
|
typedef enum EIndexType { INDEX_TYPE_SMA = 1, INDEX_TYPE_FULLTEXT, INDEX_TYPE_NORMAL } EIndexType;
|
||||||
|
|
||||||
typedef struct SIndexOptions {
|
typedef struct SIndexOptions {
|
||||||
ENodeType type;
|
ENodeType type;
|
||||||
|
|
|
@ -286,7 +286,7 @@ extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t
|
||||||
((_code) == TSDB_CODE_SYN_NOT_LEADER || (_code) == TSDB_CODE_SYN_RESTORING || (_code) == TSDB_CODE_SYN_INTERNAL_ERROR)
|
((_code) == TSDB_CODE_SYN_NOT_LEADER || (_code) == TSDB_CODE_SYN_RESTORING || (_code) == TSDB_CODE_SYN_INTERNAL_ERROR)
|
||||||
#define SYNC_OTHER_LEADER_REDIRECT_ERROR(_code) ((_code) == TSDB_CODE_MNODE_NOT_FOUND)
|
#define SYNC_OTHER_LEADER_REDIRECT_ERROR(_code) ((_code) == TSDB_CODE_MNODE_NOT_FOUND)
|
||||||
|
|
||||||
#define NO_RET_REDIRECT_ERROR(_code) ((_code) == TSDB_CODE_RPC_BROKEN_LINK || (_code) == TSDB_CODE_RPC_NETWORK_UNAVAIL)
|
#define NO_RET_REDIRECT_ERROR(_code) ((_code) == TSDB_CODE_RPC_BROKEN_LINK || (_code) == TSDB_CODE_RPC_NETWORK_UNAVAIL || (_code) == TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED)
|
||||||
|
|
||||||
#define NEED_REDIRECT_ERROR(_code) \
|
#define NEED_REDIRECT_ERROR(_code) \
|
||||||
(NO_RET_REDIRECT_ERROR(_code) || SYNC_UNKNOWN_LEADER_REDIRECT_ERROR(_code) || \
|
(NO_RET_REDIRECT_ERROR(_code) || SYNC_UNKNOWN_LEADER_REDIRECT_ERROR(_code) || \
|
||||||
|
|
|
@ -70,6 +70,7 @@ typedef struct {
|
||||||
|
|
||||||
SysNameInfo taosGetSysNameInfo();
|
SysNameInfo taosGetSysNameInfo();
|
||||||
bool taosCheckCurrentInDll();
|
bool taosCheckCurrentInDll();
|
||||||
|
int taosGetlocalhostname(char *hostname, size_t maxLen);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,8 @@ int32_t* taosGetErrno();
|
||||||
#define TSDB_CODE_RPC_PORT_EADDRINUSE TAOS_DEF_ERROR_CODE(0, 0x0017) //
|
#define TSDB_CODE_RPC_PORT_EADDRINUSE TAOS_DEF_ERROR_CODE(0, 0x0017) //
|
||||||
#define TSDB_CODE_RPC_BROKEN_LINK TAOS_DEF_ERROR_CODE(0, 0x0018) //
|
#define TSDB_CODE_RPC_BROKEN_LINK TAOS_DEF_ERROR_CODE(0, 0x0018) //
|
||||||
#define TSDB_CODE_RPC_TIMEOUT TAOS_DEF_ERROR_CODE(0, 0x0019) //
|
#define TSDB_CODE_RPC_TIMEOUT TAOS_DEF_ERROR_CODE(0, 0x0019) //
|
||||||
|
#define TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED TAOS_DEF_ERROR_CODE(0, 0x0020) // "Vgroup could not be connected"
|
||||||
|
#define TSDB_CODE_RPC_SOMENODE_BROKEN_LINK TAOS_DEF_ERROR_CODE(0, 0x0021) //
|
||||||
|
|
||||||
//common & util
|
//common & util
|
||||||
#define TSDB_CODE_OPS_NOT_SUPPORT TAOS_DEF_ERROR_CODE(0, 0x0100) //
|
#define TSDB_CODE_OPS_NOT_SUPPORT TAOS_DEF_ERROR_CODE(0, 0x0100) //
|
||||||
|
@ -518,6 +520,8 @@ int32_t* taosGetErrno();
|
||||||
#define TSDB_CODE_SYN_STANDBY_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0912)
|
#define TSDB_CODE_SYN_STANDBY_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0912)
|
||||||
#define TSDB_CODE_SYN_BATCH_ERROR TAOS_DEF_ERROR_CODE(0, 0x0913)
|
#define TSDB_CODE_SYN_BATCH_ERROR TAOS_DEF_ERROR_CODE(0, 0x0913)
|
||||||
#define TSDB_CODE_SYN_RESTORING TAOS_DEF_ERROR_CODE(0, 0x0914)
|
#define TSDB_CODE_SYN_RESTORING TAOS_DEF_ERROR_CODE(0, 0x0914)
|
||||||
|
#define TSDB_CODE_SYN_INVALID_SNAPSHOT_MSG TAOS_DEF_ERROR_CODE(0, 0x0915) // internal
|
||||||
|
#define TSDB_CODE_SYN_BUFFER_FULL TAOS_DEF_ERROR_CODE(0, 0x0916) //
|
||||||
#define TSDB_CODE_SYN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x09FF)
|
#define TSDB_CODE_SYN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x09FF)
|
||||||
|
|
||||||
// tq
|
// tq
|
||||||
|
|
|
@ -255,7 +255,7 @@ typedef enum ELogicConditionType {
|
||||||
#define TSDB_EP_LEN (TSDB_FQDN_LEN + 6)
|
#define TSDB_EP_LEN (TSDB_FQDN_LEN + 6)
|
||||||
#define TSDB_IPv4ADDR_LEN 16
|
#define TSDB_IPv4ADDR_LEN 16
|
||||||
#define TSDB_FILENAME_LEN 128
|
#define TSDB_FILENAME_LEN 128
|
||||||
#define TSDB_SHOW_SQL_LEN 1024
|
#define TSDB_SHOW_SQL_LEN 2048
|
||||||
#define TSDB_SLOW_QUERY_SQL_LEN 512
|
#define TSDB_SLOW_QUERY_SQL_LEN 512
|
||||||
#define TSDB_SHOW_SUBQUERY_LEN 1000
|
#define TSDB_SHOW_SUBQUERY_LEN 1000
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ if exist %binary_dir%\\build\\lib\\taosws.dll (
|
||||||
if exist %binary_dir%\\build\\bin\\taosdump.exe (
|
if exist %binary_dir%\\build\\bin\\taosdump.exe (
|
||||||
copy %binary_dir%\\build\\bin\\taosdump.exe %target_dir% > nul
|
copy %binary_dir%\\build\\bin\\taosdump.exe %target_dir% > nul
|
||||||
)
|
)
|
||||||
if %Enterprise% (
|
if %Enterprise% == TRUE (
|
||||||
if exist %binary_dir%\\build\\bin\\taosx.exe (
|
if exist %binary_dir%\\build\\bin\\taosx.exe (
|
||||||
copy %binary_dir%\\build\\bin\\taosx.exe %target_dir% > nul
|
copy %binary_dir%\\build\\bin\\taosx.exe %target_dir% > nul
|
||||||
)
|
)
|
||||||
|
|
|
@ -1403,6 +1403,21 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
|
||||||
memcpy((void*)tEpSet, (void*)pEpSet, sizeof(SEpSet));
|
memcpy((void*)tEpSet, (void*)pEpSet, sizeof(SEpSet));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pMsg is response msg
|
||||||
|
if (pMsg->msgType == TDMT_MND_CONNECT + 1) {
|
||||||
|
// restore origin code
|
||||||
|
if (pMsg->code == TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED) {
|
||||||
|
pMsg->code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
||||||
|
} else if (pMsg->code == TSDB_CODE_RPC_SOMENODE_BROKEN_LINK) {
|
||||||
|
pMsg->code = TSDB_CODE_RPC_BROKEN_LINK;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// uniform to one error code: TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED
|
||||||
|
if (pMsg->code == TSDB_CODE_RPC_SOMENODE_BROKEN_LINK) {
|
||||||
|
pMsg->code = TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
AsyncArg* arg = taosMemoryCalloc(1, sizeof(AsyncArg));
|
AsyncArg* arg = taosMemoryCalloc(1, sizeof(AsyncArg));
|
||||||
arg->msg = *pMsg;
|
arg->msg = *pMsg;
|
||||||
arg->pEpset = tEpSet;
|
arg->pEpset = tEpSet;
|
||||||
|
|
|
@ -1316,12 +1316,17 @@ void taosSetDebugFlag(int32_t *pFlagPtr, const char *flagName, int32_t flagVal,
|
||||||
if (pItem != NULL && (rewrite || pItem->i32 == 0)) {
|
if (pItem != NULL && (rewrite || pItem->i32 == 0)) {
|
||||||
pItem->i32 = flagVal;
|
pItem->i32 = flagVal;
|
||||||
}
|
}
|
||||||
*pFlagPtr = flagVal;
|
if (pFlagPtr != NULL) {
|
||||||
|
*pFlagPtr = flagVal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosSetAllDebugFlag(int32_t flag, bool rewrite) {
|
void taosSetAllDebugFlag(int32_t flag, bool rewrite) {
|
||||||
if (flag <= 0) return;
|
if (flag <= 0) return;
|
||||||
|
|
||||||
|
taosSetDebugFlag(NULL, "debugFlag", flag, rewrite);
|
||||||
|
taosSetDebugFlag(NULL, "simDebugFlag", flag, rewrite);
|
||||||
|
taosSetDebugFlag(NULL, "tmrDebugFlag", flag, rewrite);
|
||||||
taosSetDebugFlag(&uDebugFlag, "uDebugFlag", flag, rewrite);
|
taosSetDebugFlag(&uDebugFlag, "uDebugFlag", flag, rewrite);
|
||||||
taosSetDebugFlag(&rpcDebugFlag, "rpcDebugFlag", flag, rewrite);
|
taosSetDebugFlag(&rpcDebugFlag, "rpcDebugFlag", flag, rewrite);
|
||||||
taosSetDebugFlag(&jniDebugFlag, "jniDebugFlag", flag, rewrite);
|
taosSetDebugFlag(&jniDebugFlag, "jniDebugFlag", flag, rewrite);
|
||||||
|
@ -1340,6 +1345,5 @@ void taosSetAllDebugFlag(int32_t flag, bool rewrite) {
|
||||||
taosSetDebugFlag(&idxDebugFlag, "idxDebugFlag", flag, rewrite);
|
taosSetDebugFlag(&idxDebugFlag, "idxDebugFlag", flag, rewrite);
|
||||||
taosSetDebugFlag(&tdbDebugFlag, "tdbDebugFlag", flag, rewrite);
|
taosSetDebugFlag(&tdbDebugFlag, "tdbDebugFlag", flag, rewrite);
|
||||||
taosSetDebugFlag(&metaDebugFlag, "metaDebugFlag", flag, rewrite);
|
taosSetDebugFlag(&metaDebugFlag, "metaDebugFlag", flag, rewrite);
|
||||||
taosSetDebugFlag(&metaDebugFlag, "tmrDebugFlag", flag, rewrite);
|
|
||||||
uInfo("all debug flag are set to %d", flag);
|
uInfo("all debug flag are set to %d", flag);
|
||||||
}
|
}
|
||||||
|
|
|
@ -268,6 +268,11 @@ int mainWindows(int argc, char **argv) {
|
||||||
|
|
||||||
if (dmInit() != 0) {
|
if (dmInit() != 0) {
|
||||||
dError("failed to init dnode since %s", terrstr());
|
dError("failed to init dnode since %s", terrstr());
|
||||||
|
|
||||||
|
taosCleanupCfg();
|
||||||
|
taosCloseLog();
|
||||||
|
taosCleanupArgs();
|
||||||
|
taosConvDestroy();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -140,6 +140,12 @@ static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOf
|
||||||
|
|
||||||
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
|
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
|
||||||
const STraceId *trace = &pMsg->info.traceId;
|
const STraceId *trace = &pMsg->info.traceId;
|
||||||
|
if (pMsg->contLen < sizeof(SMsgHead)) {
|
||||||
|
dGError("invalid rpc msg with no msg head at pCont. pMsg:%p, type:%s, contLen:%d", pMsg, TMSG_INFO(pMsg->msgType),
|
||||||
|
pMsg->contLen);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
SMsgHead *pHead = pMsg->pCont;
|
SMsgHead *pHead = pMsg->pCont;
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
|
@ -233,6 +239,14 @@ int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
||||||
|
if (pRpc->contLen < sizeof(SMsgHead)) {
|
||||||
|
dError("invalid rpc msg with no msg head at pCont. pRpc:%p, type:%s, len:%d", pRpc, TMSG_INFO(pRpc->msgType),
|
||||||
|
pRpc->contLen);
|
||||||
|
rpcFreeCont(pRpc->pCont);
|
||||||
|
pRpc->pCont = NULL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM, pRpc->contLen);
|
SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM, pRpc->contLen);
|
||||||
if (pMsg == NULL) {
|
if (pMsg == NULL) {
|
||||||
rpcFreeCont(pRpc->pCont);
|
rpcFreeCont(pRpc->pCont);
|
||||||
|
|
|
@ -248,6 +248,7 @@ static inline void dmReleaseHandle(SRpcHandleInfo *pHandle, int8_t type) { rpcRe
|
||||||
|
|
||||||
static bool rpcRfp(int32_t code, tmsg_t msgType) {
|
static bool rpcRfp(int32_t code, tmsg_t msgType) {
|
||||||
if (code == TSDB_CODE_RPC_NETWORK_UNAVAIL || code == TSDB_CODE_RPC_BROKEN_LINK || code == TSDB_CODE_MNODE_NOT_FOUND ||
|
if (code == TSDB_CODE_RPC_NETWORK_UNAVAIL || code == TSDB_CODE_RPC_BROKEN_LINK || code == TSDB_CODE_MNODE_NOT_FOUND ||
|
||||||
|
code == TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED ||
|
||||||
code == TSDB_CODE_SYN_NOT_LEADER || code == TSDB_CODE_SYN_RESTORING || code == TSDB_CODE_VND_STOPPED ||
|
code == TSDB_CODE_SYN_NOT_LEADER || code == TSDB_CODE_SYN_RESTORING || code == TSDB_CODE_VND_STOPPED ||
|
||||||
code == TSDB_CODE_APP_IS_STARTING || code == TSDB_CODE_APP_IS_STOPPING) {
|
code == TSDB_CODE_APP_IS_STARTING || code == TSDB_CODE_APP_IS_STOPPING) {
|
||||||
if (msgType == TDMT_SCH_QUERY || msgType == TDMT_SCH_MERGE_QUERY || msgType == TDMT_SCH_FETCH ||
|
if (msgType == TDMT_SCH_QUERY || msgType == TDMT_SCH_MERGE_QUERY || msgType == TDMT_SCH_FETCH ||
|
||||||
|
|
|
@ -957,7 +957,7 @@ static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans) {
|
||||||
for (int32_t i = 0; i < size; ++i) {
|
for (int32_t i = 0; i < size; ++i) {
|
||||||
SRpcHandleInfo *pInfo = taosArrayGet(pTrans->pRpcArray, i);
|
SRpcHandleInfo *pInfo = taosArrayGet(pTrans->pRpcArray, i);
|
||||||
if (pInfo->handle != NULL) {
|
if (pInfo->handle != NULL) {
|
||||||
if (code == TSDB_CODE_RPC_NETWORK_UNAVAIL) {
|
if (code == TSDB_CODE_RPC_NETWORK_UNAVAIL || code == TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED) {
|
||||||
code = TSDB_CODE_MND_TRANS_NETWORK_UNAVAILL;
|
code = TSDB_CODE_MND_TRANS_NETWORK_UNAVAILL;
|
||||||
}
|
}
|
||||||
if (code == TSDB_CODE_SYN_TIMEOUT) {
|
if (code == TSDB_CODE_SYN_TIMEOUT) {
|
||||||
|
|
|
@ -57,7 +57,6 @@ struct SMetaCache {
|
||||||
TdThreadMutex lock;
|
TdThreadMutex lock;
|
||||||
SHashObj* pTableEntry;
|
SHashObj* pTableEntry;
|
||||||
SLRUCache* pUidResCache;
|
SLRUCache* pUidResCache;
|
||||||
uint64_t keyBuf[3];
|
|
||||||
} sTagFilterResCache;
|
} sTagFilterResCache;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -429,20 +428,20 @@ int32_t metaGetCachedTableUidList(SMeta* pMeta, tb_uid_t suid, const uint8_t* pK
|
||||||
bool* acquireRes) {
|
bool* acquireRes) {
|
||||||
// generate the composed key for LRU cache
|
// generate the composed key for LRU cache
|
||||||
SLRUCache* pCache = pMeta->pCache->sTagFilterResCache.pUidResCache;
|
SLRUCache* pCache = pMeta->pCache->sTagFilterResCache.pUidResCache;
|
||||||
uint64_t* pBuf = pMeta->pCache->sTagFilterResCache.keyBuf;
|
|
||||||
SHashObj* pTableMap = pMeta->pCache->sTagFilterResCache.pTableEntry;
|
SHashObj* pTableMap = pMeta->pCache->sTagFilterResCache.pTableEntry;
|
||||||
TdThreadMutex* pLock = &pMeta->pCache->sTagFilterResCache.lock;
|
TdThreadMutex* pLock = &pMeta->pCache->sTagFilterResCache.lock;
|
||||||
|
|
||||||
|
uint64_t buf[3] = {0};
|
||||||
uint32_t times = 0;
|
uint32_t times = 0;
|
||||||
|
|
||||||
*acquireRes = 0;
|
*acquireRes = 0;
|
||||||
pBuf[0] = suid;
|
buf[0] = suid;
|
||||||
memcpy(&pBuf[1], pKey, keyLen);
|
memcpy(&buf[1], pKey, keyLen);
|
||||||
|
|
||||||
taosThreadMutexLock(pLock);
|
taosThreadMutexLock(pLock);
|
||||||
|
|
||||||
int32_t len = keyLen + sizeof(uint64_t);
|
int32_t len = keyLen + sizeof(uint64_t);
|
||||||
LRUHandle* pHandle = taosLRUCacheLookup(pCache, pBuf, len);
|
LRUHandle* pHandle = taosLRUCacheLookup(pCache, buf, len);
|
||||||
if (pHandle == NULL) {
|
if (pHandle == NULL) {
|
||||||
taosThreadMutexUnlock(pLock);
|
taosThreadMutexUnlock(pLock);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -476,10 +475,10 @@ int32_t metaGetCachedTableUidList(SMeta* pMeta, tb_uid_t suid, const uint8_t* pK
|
||||||
|
|
||||||
SListNode* pNode = NULL;
|
SListNode* pNode = NULL;
|
||||||
while ((pNode = tdListNext(&iter)) != NULL) {
|
while ((pNode = tdListNext(&iter)) != NULL) {
|
||||||
memcpy(&pBuf[1], pNode->data, keyLen);
|
memcpy(&buf[1], pNode->data, keyLen);
|
||||||
|
|
||||||
// check whether it is existed in LRU cache, and remove it from linked list if not.
|
// check whether it is existed in LRU cache, and remove it from linked list if not.
|
||||||
LRUHandle* pRes = taosLRUCacheLookup(pCache, pBuf, len);
|
LRUHandle* pRes = taosLRUCacheLookup(pCache, buf, len);
|
||||||
if (pRes == NULL) { // remove the item in the linked list
|
if (pRes == NULL) { // remove the item in the linked list
|
||||||
taosArrayPush(pInvalidRes, &pNode);
|
taosArrayPush(pInvalidRes, &pNode);
|
||||||
} else {
|
} else {
|
||||||
|
@ -547,14 +546,14 @@ int32_t metaUidFilterCachePut(SMeta* pMeta, uint64_t suid, const void* pKey, int
|
||||||
tdListAppend(&(*pEntry)->list, pKey);
|
tdListAppend(&(*pEntry)->list, pKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t* pBuf = pMeta->pCache->sTagFilterResCache.keyBuf;
|
uint64_t buf[3] = {0};
|
||||||
pBuf[0] = suid;
|
buf[0] = suid;
|
||||||
|
|
||||||
memcpy(&pBuf[1], pKey, keyLen);
|
memcpy(&buf[1], pKey, keyLen);
|
||||||
ASSERT(sizeof(uint64_t) + keyLen == 24);
|
ASSERT(sizeof(uint64_t) + keyLen == 24);
|
||||||
|
|
||||||
// add to cache.
|
// add to cache.
|
||||||
taosLRUCacheInsert(pCache, pBuf, sizeof(uint64_t) + keyLen, pPayload, payloadLen, freePayload, NULL,
|
taosLRUCacheInsert(pCache, buf, sizeof(uint64_t) + keyLen, pPayload, payloadLen, freePayload, NULL,
|
||||||
TAOS_LRU_PRIORITY_LOW);
|
TAOS_LRU_PRIORITY_LOW);
|
||||||
|
|
||||||
taosThreadMutexUnlock(pLock);
|
taosThreadMutexUnlock(pLock);
|
||||||
|
|
|
@ -113,8 +113,8 @@ int32_t metaSnapRead(SMetaSnapReader* pReader, uint8_t** ppData) {
|
||||||
pHdr->size = nData;
|
pHdr->size = nData;
|
||||||
memcpy(pHdr->data, pData, nData);
|
memcpy(pHdr->data, pData, nData);
|
||||||
|
|
||||||
metaInfo("vgId:%d, vnode snapshot meta read data, version:%" PRId64 " uid:%" PRId64 " nData:%d",
|
metaDebug("vgId:%d, vnode snapshot meta read data, version:%" PRId64 " uid:%" PRId64 " blockLen:%d",
|
||||||
TD_VID(pReader->pMeta->pVnode), key.version, key.uid, nData);
|
TD_VID(pReader->pMeta->pVnode), key.version, key.uid, nData);
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
return code;
|
return code;
|
||||||
|
|
|
@ -1014,6 +1014,7 @@ int32_t tqProcessStreamTaskCheckReq(STQ* pTq, SRpcMsg* pMsg) {
|
||||||
tqError("unable to encode rsp %d", __LINE__);
|
tqError("unable to encode rsp %d", __LINE__);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* buf = rpcMallocCont(sizeof(SMsgHead) + len);
|
void* buf = rpcMallocCont(sizeof(SMsgHead) + len);
|
||||||
((SMsgHead*)buf)->vgId = htonl(req.upstreamNodeId);
|
((SMsgHead*)buf)->vgId = htonl(req.upstreamNodeId);
|
||||||
|
|
||||||
|
|
|
@ -567,7 +567,6 @@ int32_t tMergeTreeOpen(SMergeTree *pMTree, int8_t backward, SDataFReader *pFRead
|
||||||
|
|
||||||
pMTree->pLoadInfo = pBlockLoadInfo;
|
pMTree->pLoadInfo = pBlockLoadInfo;
|
||||||
pMTree->destroyLoadInfo = destroyLoadInfo;
|
pMTree->destroyLoadInfo = destroyLoadInfo;
|
||||||
ASSERT(pMTree->pLoadInfo != NULL);
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < pFReader->pSet->nSttF; ++i) { // open all last file
|
for (int32_t i = 0; i < pFReader->pSet->nSttF; ++i) { // open all last file
|
||||||
struct SLDataIter *pIter = NULL;
|
struct SLDataIter *pIter = NULL;
|
||||||
|
|
|
@ -244,7 +244,7 @@ static int32_t setColumnIdSlotList(SBlockLoadSuppInfo* pSupInfo, SColumnInfo* pC
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void updateBlockSMAInfo(STSchema* pSchema, SBlockLoadSuppInfo* pSupInfo) {
|
static int32_t updateBlockSMAInfo(STSchema* pSchema, SBlockLoadSuppInfo* pSupInfo) {
|
||||||
int32_t i = 0, j = 0;
|
int32_t i = 0, j = 0;
|
||||||
|
|
||||||
while (i < pSchema->numOfCols && j < pSupInfo->numOfCols) {
|
while (i < pSchema->numOfCols && j < pSupInfo->numOfCols) {
|
||||||
|
@ -252,7 +252,7 @@ static void updateBlockSMAInfo(STSchema* pSchema, SBlockLoadSuppInfo* pSupInfo)
|
||||||
if (pTCol->colId == pSupInfo->colId[j]) {
|
if (pTCol->colId == pSupInfo->colId[j]) {
|
||||||
if (!IS_BSMA_ON(pTCol)) {
|
if (!IS_BSMA_ON(pTCol)) {
|
||||||
pSupInfo->smaValid = false;
|
pSupInfo->smaValid = false;
|
||||||
return;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
i += 1;
|
i += 1;
|
||||||
|
@ -261,9 +261,11 @@ static void updateBlockSMAInfo(STSchema* pSchema, SBlockLoadSuppInfo* pSupInfo)
|
||||||
// do nothing
|
// do nothing
|
||||||
i += 1;
|
i += 1;
|
||||||
} else {
|
} else {
|
||||||
ASSERT(0);
|
return TSDB_CODE_INVALID_PARA;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t initBlockScanInfoBuf(SBlockInfoBuf* pBuf, int32_t numOfTables) {
|
static int32_t initBlockScanInfoBuf(SBlockInfoBuf* pBuf, int32_t numOfTables) {
|
||||||
|
@ -581,7 +583,7 @@ static int32_t tsdbReaderCreate(SVnode* pVnode, SQueryTableDataCond* pCond, STsd
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VND_IS_TSMA(pVnode)) {
|
if (VND_IS_TSMA(pVnode)) {
|
||||||
tsdbDebug("vgId:%d, tsma is selected to query", TD_VID(pVnode));
|
tsdbDebug("vgId:%d, tsma is selected to query, %s", TD_VID(pVnode), idstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
initReaderStatus(&pReader->status);
|
initReaderStatus(&pReader->status);
|
||||||
|
@ -596,7 +598,6 @@ static int32_t tsdbReaderCreate(SVnode* pVnode, SQueryTableDataCond* pCond, STsd
|
||||||
pReader->type = pCond->type;
|
pReader->type = pCond->type;
|
||||||
pReader->window = updateQueryTimeWindow(pReader->pTsdb, &pCond->twindows);
|
pReader->window = updateQueryTimeWindow(pReader->pTsdb, &pCond->twindows);
|
||||||
pReader->blockInfoBuf.numPerBucket = 1000; // 1000 tables per bucket
|
pReader->blockInfoBuf.numPerBucket = 1000; // 1000 tables per bucket
|
||||||
ASSERT(pCond->numOfCols > 0);
|
|
||||||
|
|
||||||
if (pReader->pResBlock == NULL) {
|
if (pReader->pResBlock == NULL) {
|
||||||
pReader->freeBlock = true;
|
pReader->freeBlock = true;
|
||||||
|
@ -607,6 +608,12 @@ static int32_t tsdbReaderCreate(SVnode* pVnode, SQueryTableDataCond* pCond, STsd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pCond->numOfCols <= 0) {
|
||||||
|
tsdbError("vgId:%d, invalid column number %d in query cond, %s", TD_VID(pVnode), pCond->numOfCols, idstr);
|
||||||
|
code = TSDB_CODE_INVALID_PARA;
|
||||||
|
goto _end;
|
||||||
|
}
|
||||||
|
|
||||||
// todo refactor.
|
// todo refactor.
|
||||||
limitOutputBufferSize(pCond, &pReader->capacity);
|
limitOutputBufferSize(pCond, &pReader->capacity);
|
||||||
|
|
||||||
|
@ -795,8 +802,9 @@ static void doCopyColVal(SColumnInfoData* pColInfoData, int32_t rowIndex, int32_
|
||||||
}
|
}
|
||||||
|
|
||||||
static SFileDataBlockInfo* getCurrentBlockInfo(SDataBlockIter* pBlockIter) {
|
static SFileDataBlockInfo* getCurrentBlockInfo(SDataBlockIter* pBlockIter) {
|
||||||
if (taosArrayGetSize(pBlockIter->blockList) == 0) {
|
size_t num = taosArrayGetSize(pBlockIter->blockList);
|
||||||
ASSERT(pBlockIter->numOfBlocks == taosArrayGetSize(pBlockIter->blockList));
|
if (num == 0) {
|
||||||
|
ASSERT(pBlockIter->numOfBlocks == num);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -806,73 +814,6 @@ static SFileDataBlockInfo* getCurrentBlockInfo(SDataBlockIter* pBlockIter) {
|
||||||
|
|
||||||
static SDataBlk* getCurrentBlock(SDataBlockIter* pBlockIter) { return &pBlockIter->block; }
|
static SDataBlk* getCurrentBlock(SDataBlockIter* pBlockIter) { return &pBlockIter->block; }
|
||||||
|
|
||||||
int32_t binarySearchForTs(char* pValue, int num, TSKEY key, int order) {
|
|
||||||
int32_t midPos = -1;
|
|
||||||
int32_t numOfRows;
|
|
||||||
|
|
||||||
ASSERT(order == TSDB_ORDER_ASC || order == TSDB_ORDER_DESC);
|
|
||||||
|
|
||||||
TSKEY* keyList = (TSKEY*)pValue;
|
|
||||||
int32_t firstPos = 0;
|
|
||||||
int32_t lastPos = num - 1;
|
|
||||||
|
|
||||||
if (order == TSDB_ORDER_DESC) {
|
|
||||||
// find the first position which is smaller than the key
|
|
||||||
while (1) {
|
|
||||||
if (key >= keyList[firstPos]) return firstPos;
|
|
||||||
if (key == keyList[lastPos]) return lastPos;
|
|
||||||
|
|
||||||
if (key < keyList[lastPos]) {
|
|
||||||
lastPos += 1;
|
|
||||||
if (lastPos >= num) {
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
return lastPos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
numOfRows = lastPos - firstPos + 1;
|
|
||||||
midPos = (numOfRows >> 1) + firstPos;
|
|
||||||
|
|
||||||
if (key < keyList[midPos]) {
|
|
||||||
firstPos = midPos + 1;
|
|
||||||
} else if (key > keyList[midPos]) {
|
|
||||||
lastPos = midPos - 1;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// find the first position which is bigger than the key
|
|
||||||
while (1) {
|
|
||||||
if (key <= keyList[firstPos]) return firstPos;
|
|
||||||
if (key == keyList[lastPos]) return lastPos;
|
|
||||||
|
|
||||||
if (key > keyList[lastPos]) {
|
|
||||||
lastPos = lastPos + 1;
|
|
||||||
if (lastPos >= num)
|
|
||||||
return -1;
|
|
||||||
else
|
|
||||||
return lastPos;
|
|
||||||
}
|
|
||||||
|
|
||||||
numOfRows = lastPos - firstPos + 1;
|
|
||||||
midPos = (numOfRows >> 1u) + firstPos;
|
|
||||||
|
|
||||||
if (key < keyList[midPos]) {
|
|
||||||
lastPos = midPos - 1;
|
|
||||||
} else if (key > keyList[midPos]) {
|
|
||||||
firstPos = midPos + 1;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return midPos;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int doBinarySearchKey(TSKEY* keyList, int num, int pos, TSKEY key, int order) {
|
static int doBinarySearchKey(TSKEY* keyList, int num, int pos, TSKEY key, int order) {
|
||||||
// start end position
|
// start end position
|
||||||
int s, e;
|
int s, e;
|
||||||
|
@ -973,8 +914,8 @@ static void copyNumericCols(const SColData* pData, SFileBlockDumpInfo* pDumpInfo
|
||||||
|
|
||||||
int32_t step = asc ? 1 : -1;
|
int32_t step = asc ? 1 : -1;
|
||||||
|
|
||||||
// make sure it is aligned to 8bit
|
// make sure it is aligned to 8bit, the allocated memory address is aligned to 256bit
|
||||||
ASSERT((((uint64_t)pColData->pData) & (0x8 - 1)) == 0);
|
// ASSERT((((uint64_t)pColData->pData) & (0x8 - 1)) == 0);
|
||||||
|
|
||||||
// 1. copy data in a batch model
|
// 1. copy data in a batch model
|
||||||
memcpy(pColData->pData, p, dumpedRows * tDataTypes[pData->type].bytes);
|
memcpy(pColData->pData, p, dumpedRows * tDataTypes[pData->type].bytes);
|
||||||
|
@ -1072,11 +1013,20 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader, STableBlockScanIn
|
||||||
// pDumpInfo->rowIndex = 0;
|
// pDumpInfo->rowIndex = 0;
|
||||||
} else if (!asc && pReader->window.ekey >= pBlock->maxKey.ts) {
|
} else if (!asc && pReader->window.ekey >= pBlock->maxKey.ts) {
|
||||||
// pDumpInfo->rowIndex = pBlock->nRow - 1;
|
// pDumpInfo->rowIndex = pBlock->nRow - 1;
|
||||||
} else {
|
} else { // find the appropriate the start position in current block, and set it to be the current rowIndex
|
||||||
int32_t pos = asc ? pBlock->nRow - 1 : 0;
|
int32_t pos = asc ? pBlock->nRow - 1 : 0;
|
||||||
int32_t order = asc ? TSDB_ORDER_DESC : TSDB_ORDER_ASC;
|
int32_t order = asc ? TSDB_ORDER_DESC : TSDB_ORDER_ASC;
|
||||||
int64_t key = asc ? pReader->window.skey : pReader->window.ekey;
|
int64_t key = asc ? pReader->window.skey : pReader->window.ekey;
|
||||||
pDumpInfo->rowIndex = doBinarySearchKey(pBlockData->aTSKEY, pBlock->nRow, pos, key, order);
|
pDumpInfo->rowIndex = doBinarySearchKey(pBlockData->aTSKEY, pBlock->nRow, pos, key, order);
|
||||||
|
|
||||||
|
if (pDumpInfo->rowIndex < 0) {
|
||||||
|
tsdbError(
|
||||||
|
"%p failed to locate the start position in current block, global index:%d, table index:%d, brange:%" PRId64
|
||||||
|
"-%" PRId64 ", minVer:%" PRId64 ", maxVer:%" PRId64 " %s",
|
||||||
|
pReader, pBlockIter->index, pBlockInfo->tbBlockIdx, pBlock->minKey.ts, pBlock->maxKey.ts, pBlock->minVer,
|
||||||
|
pBlock->maxVer, pReader->idStr);
|
||||||
|
return TSDB_CODE_INVALID_PARA;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1185,7 +1135,6 @@ static int32_t doLoadFileBlockData(STsdbReader* pReader, SDataBlockIter* pBlockI
|
||||||
|
|
||||||
SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(pBlockIter);
|
SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(pBlockIter);
|
||||||
SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo;
|
SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo;
|
||||||
ASSERT(pBlockInfo != NULL);
|
|
||||||
|
|
||||||
SDataBlk* pBlock = getCurrentBlock(pBlockIter);
|
SDataBlk* pBlock = getCurrentBlock(pBlockIter);
|
||||||
code = tsdbReadDataBlock(pReader->pFileReader, pBlock, pBlockData);
|
code = tsdbReadDataBlock(pReader->pFileReader, pBlock, pBlockData);
|
||||||
|
@ -1223,8 +1172,6 @@ static void cleanupBlockOrderSupporter(SBlockOrderSupporter* pSup) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t initBlockOrderSupporter(SBlockOrderSupporter* pSup, int32_t numOfTables) {
|
static int32_t initBlockOrderSupporter(SBlockOrderSupporter* pSup, int32_t numOfTables) {
|
||||||
ASSERT(numOfTables >= 1);
|
|
||||||
|
|
||||||
pSup->numOfBlocksPerTable = taosMemoryCalloc(1, sizeof(int32_t) * numOfTables);
|
pSup->numOfBlocksPerTable = taosMemoryCalloc(1, sizeof(int32_t) * numOfTables);
|
||||||
pSup->indexPerTable = taosMemoryCalloc(1, sizeof(int32_t) * numOfTables);
|
pSup->indexPerTable = taosMemoryCalloc(1, sizeof(int32_t) * numOfTables);
|
||||||
pSup->pDataBlockInfo = taosMemoryCalloc(1, POINTER_BYTES * numOfTables);
|
pSup->pDataBlockInfo = taosMemoryCalloc(1, POINTER_BYTES * numOfTables);
|
||||||
|
@ -1331,7 +1278,10 @@ static int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIte
|
||||||
sup.numOfTables += 1;
|
sup.numOfTables += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(numOfBlocks == cnt);
|
if (numOfBlocks != cnt && sup.numOfTables != numOfTables) {
|
||||||
|
cleanupBlockOrderSupporter(&sup);
|
||||||
|
return TSDB_CODE_INVALID_PARA;
|
||||||
|
}
|
||||||
|
|
||||||
// since there is only one table qualified, blocks are not sorted
|
// since there is only one table qualified, blocks are not sorted
|
||||||
if (sup.numOfTables == 1) {
|
if (sup.numOfTables == 1) {
|
||||||
|
@ -1353,10 +1303,9 @@ static int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIte
|
||||||
tsdbDebug("%p create data blocks info struct completed, %d blocks in %d tables %s", pReader, cnt, sup.numOfTables,
|
tsdbDebug("%p create data blocks info struct completed, %d blocks in %d tables %s", pReader, cnt, sup.numOfTables,
|
||||||
pReader->idStr);
|
pReader->idStr);
|
||||||
|
|
||||||
ASSERT(cnt <= numOfBlocks && sup.numOfTables <= numOfTables);
|
|
||||||
|
|
||||||
SMultiwayMergeTreeInfo* pTree = NULL;
|
SMultiwayMergeTreeInfo* pTree = NULL;
|
||||||
uint8_t ret = tMergeTreeCreate(&pTree, sup.numOfTables, &sup, fileDataBlockOrderCompar);
|
|
||||||
|
uint8_t ret = tMergeTreeCreate(&pTree, sup.numOfTables, &sup, fileDataBlockOrderCompar);
|
||||||
if (ret != TSDB_CODE_SUCCESS) {
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
cleanupBlockOrderSupporter(&sup);
|
cleanupBlockOrderSupporter(&sup);
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -1434,8 +1383,6 @@ static bool getNeighborBlockOfSameTable(SFileDataBlockInfo* pBlockInfo, STableBl
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t findFileBlockInfoIndex(SDataBlockIter* pBlockIter, SFileDataBlockInfo* pFBlockInfo) {
|
static int32_t findFileBlockInfoIndex(SDataBlockIter* pBlockIter, SFileDataBlockInfo* pFBlockInfo) {
|
||||||
ASSERT(pBlockIter != NULL && pFBlockInfo != NULL);
|
|
||||||
|
|
||||||
int32_t step = ASCENDING_TRAVERSE(pBlockIter->order) ? 1 : -1;
|
int32_t step = ASCENDING_TRAVERSE(pBlockIter->order) ? 1 : -1;
|
||||||
int32_t index = pBlockIter->index;
|
int32_t index = pBlockIter->index;
|
||||||
|
|
||||||
|
@ -1926,7 +1873,6 @@ static int32_t doMergeFileBlockAndLastBlock(SLastBlockReader* pLastBlockReader,
|
||||||
}
|
}
|
||||||
|
|
||||||
doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLastBlock, &merge, &pReader->verRange);
|
doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLastBlock, &merge, &pReader->verRange);
|
||||||
ASSERT(mergeBlockData);
|
|
||||||
|
|
||||||
// merge with block data if ts == key
|
// merge with block data if ts == key
|
||||||
if (tsLastBlock == pBlockData->aTSKEY[pDumpInfo->rowIndex]) {
|
if (tsLastBlock == pBlockData->aTSKEY[pDumpInfo->rowIndex]) {
|
||||||
|
@ -1992,7 +1938,6 @@ static int32_t mergeFileBlockAndLastBlock(STsdbReader* pReader, SLastBlockReader
|
||||||
tsdbRowMergerClear(&merge);
|
tsdbRowMergerClear(&merge);
|
||||||
return code;
|
return code;
|
||||||
} else {
|
} else {
|
||||||
ASSERT(0);
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
} else { // desc order
|
} else { // desc order
|
||||||
|
@ -2013,7 +1958,6 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
|
|
||||||
TSDBROW* pRow = getValidMemRow(&pBlockScanInfo->iter, pDelList, pReader);
|
TSDBROW* pRow = getValidMemRow(&pBlockScanInfo->iter, pDelList, pReader);
|
||||||
TSDBROW* piRow = getValidMemRow(&pBlockScanInfo->iiter, pDelList, pReader);
|
TSDBROW* piRow = getValidMemRow(&pBlockScanInfo->iiter, pDelList, pReader);
|
||||||
ASSERT(pRow != NULL && piRow != NULL);
|
|
||||||
|
|
||||||
int64_t tsLast = INT64_MIN;
|
int64_t tsLast = INT64_MIN;
|
||||||
if (hasDataInLastBlock(pLastBlockReader)) {
|
if (hasDataInLastBlock(pLastBlockReader)) {
|
||||||
|
@ -2237,7 +2181,6 @@ static int32_t initMemDataIterator(STableBlockScanInfo* pBlockScanInfo, STsdbRea
|
||||||
if (pReader->pReadSnap->pMem != NULL) {
|
if (pReader->pReadSnap->pMem != NULL) {
|
||||||
d = tsdbGetTbDataFromMemTable(pReader->pReadSnap->pMem, pReader->suid, pBlockScanInfo->uid);
|
d = tsdbGetTbDataFromMemTable(pReader->pReadSnap->pMem, pReader->suid, pBlockScanInfo->uid);
|
||||||
if (d != NULL) {
|
if (d != NULL) {
|
||||||
ASSERT(pBlockScanInfo->iter.iter == NULL);
|
|
||||||
code = tsdbTbDataIterCreate(d, &startKey, backward, &pBlockScanInfo->iter.iter);
|
code = tsdbTbDataIterCreate(d, &startKey, backward, &pBlockScanInfo->iter.iter);
|
||||||
if (code == TSDB_CODE_SUCCESS) {
|
if (code == TSDB_CODE_SUCCESS) {
|
||||||
pBlockScanInfo->iter.hasVal = (tsdbTbDataIterGet(pBlockScanInfo->iter.iter) != NULL);
|
pBlockScanInfo->iter.hasVal = (tsdbTbDataIterGet(pBlockScanInfo->iter.iter) != NULL);
|
||||||
|
@ -2351,10 +2294,9 @@ static int64_t getCurrentKeyInLastBlock(SLastBlockReader* pLastBlockReader) {
|
||||||
static bool hasDataInLastBlock(SLastBlockReader* pLastBlockReader) { return pLastBlockReader->mergeTree.pIter != NULL; }
|
static bool hasDataInLastBlock(SLastBlockReader* pLastBlockReader) { return pLastBlockReader->mergeTree.pIter != NULL; }
|
||||||
|
|
||||||
bool hasDataInFileBlock(const SBlockData* pBlockData, const SFileBlockDumpInfo* pDumpInfo) {
|
bool hasDataInFileBlock(const SBlockData* pBlockData, const SFileBlockDumpInfo* pDumpInfo) {
|
||||||
if (pBlockData->nRow > 0) {
|
if ((pBlockData->nRow > 0) && (pBlockData->nRow != pDumpInfo->totalRows)) {
|
||||||
ASSERT(pBlockData->nRow == pDumpInfo->totalRows);
|
return false; // this is an invalid result.
|
||||||
}
|
}
|
||||||
|
|
||||||
return pBlockData->nRow > 0 && (!pDumpInfo->allDumped);
|
return pBlockData->nRow > 0 && (!pDumpInfo->allDumped);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2585,7 +2527,6 @@ int32_t initDelSkylineIterator(STableBlockScanInfo* pBlockScanInfo, STsdbReader*
|
||||||
|
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SArray* pDelData = taosArrayInit(4, sizeof(SDelData));
|
SArray* pDelData = taosArrayInit(4, sizeof(SDelData));
|
||||||
ASSERT(pReader->pReadSnap != NULL);
|
|
||||||
|
|
||||||
SDelFile* pDelFile = pReader->pReadSnap->fs.pDelFile;
|
SDelFile* pDelFile = pReader->pReadSnap->fs.pDelFile;
|
||||||
if (pDelFile && taosArrayGetSize(pReader->pDelIdx) > 0) {
|
if (pDelFile && taosArrayGetSize(pReader->pDelIdx) > 0) {
|
||||||
|
@ -2869,7 +2810,6 @@ static int32_t doBuildDataBlock(STsdbReader* pReader) {
|
||||||
TSDBKEY keyInBuf = getCurrentKeyInBuf(pScanInfo, pReader);
|
TSDBKEY keyInBuf = getCurrentKeyInBuf(pScanInfo, pReader);
|
||||||
|
|
||||||
if (pBlockInfo == NULL) { // build data block from last data file
|
if (pBlockInfo == NULL) { // build data block from last data file
|
||||||
ASSERT(pBlockIter->numOfBlocks == 0);
|
|
||||||
code = buildComposedDataBlock(pReader);
|
code = buildComposedDataBlock(pReader);
|
||||||
} else if (fileBlockShouldLoad(pReader, pBlockInfo, pBlock, pScanInfo, keyInBuf, pLastBlockReader)) {
|
} else if (fileBlockShouldLoad(pReader, pBlockInfo, pBlock, pScanInfo, keyInBuf, pLastBlockReader)) {
|
||||||
code = doLoadFileBlockData(pReader, pBlockIter, &pStatus->fileBlockData, pScanInfo->uid);
|
code = doLoadFileBlockData(pReader, pBlockIter, &pStatus->fileBlockData, pScanInfo->uid);
|
||||||
|
@ -3872,15 +3812,16 @@ int32_t tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, void* pTableL
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pReader->pSchema != NULL) {
|
if (pReader->pSchema != NULL) {
|
||||||
updateBlockSMAInfo(pReader->pSchema, &pReader->suppInfo);
|
code = updateBlockSMAInfo(pReader->pSchema, &pReader->suppInfo);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STsdbReader* p = (pReader->innerReader[0] != NULL) ? pReader->innerReader[0] : pReader;
|
STsdbReader* p = (pReader->innerReader[0] != NULL) ? pReader->innerReader[0] : pReader;
|
||||||
pReader->status.pTableMap = createDataBlockScanInfo(p, &pReader->blockInfoBuf, pTableList, numOfTables);
|
pReader->status.pTableMap = createDataBlockScanInfo(p, &pReader->blockInfoBuf, pTableList, numOfTables);
|
||||||
if (pReader->status.pTableMap == NULL) {
|
if (pReader->status.pTableMap == NULL) {
|
||||||
tsdbReaderClose(p);
|
|
||||||
*ppReader = NULL;
|
*ppReader = NULL;
|
||||||
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
@ -4146,25 +4087,27 @@ static void doFillNullColSMA(SBlockLoadSuppInfo* pSup, int32_t numOfRows, int32_
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbRetrieveDatablockSMA(STsdbReader* pReader, SSDataBlock* pDataBlock, bool* allHave) {
|
int32_t tsdbRetrieveDatablockSMA(STsdbReader* pReader, SSDataBlock* pDataBlock, bool* allHave) {
|
||||||
|
SColumnDataAgg*** pBlockSMA = &pDataBlock->pBlockAgg;
|
||||||
|
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SColumnDataAgg ***pBlockSMA = &pDataBlock->pBlockAgg;
|
|
||||||
*allHave = false;
|
*allHave = false;
|
||||||
|
*pBlockSMA = NULL;
|
||||||
|
|
||||||
if (pReader->type == TIMEWINDOW_RANGE_EXTERNAL) {
|
if (pReader->type == TIMEWINDOW_RANGE_EXTERNAL) {
|
||||||
*pBlockSMA = NULL;
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// there is no statistics data for composed block
|
// there is no statistics data for composed block
|
||||||
if (pReader->status.composedDataBlock || (!pReader->suppInfo.smaValid)) {
|
if (pReader->status.composedDataBlock || (!pReader->suppInfo.smaValid)) {
|
||||||
*pBlockSMA = NULL;
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
SFileDataBlockInfo* pFBlock = getCurrentBlockInfo(&pReader->status.blockIter);
|
SFileDataBlockInfo* pFBlock = getCurrentBlockInfo(&pReader->status.blockIter);
|
||||||
SBlockLoadSuppInfo* pSup = &pReader->suppInfo;
|
SBlockLoadSuppInfo* pSup = &pReader->suppInfo;
|
||||||
|
|
||||||
ASSERT(pReader->pResBlock->info.id.uid == pFBlock->uid);
|
if (pReader->pResBlock->info.id.uid != pFBlock->uid) {
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
SDataBlk* pBlock = getCurrentBlock(&pReader->status.blockIter);
|
SDataBlk* pBlock = getCurrentBlock(&pReader->status.blockIter);
|
||||||
if (tDataBlkHasSma(pBlock)) {
|
if (tDataBlkHasSma(pBlock)) {
|
||||||
|
@ -4192,13 +4135,10 @@ int32_t tsdbRetrieveDatablockSMA(STsdbReader* pReader, SSDataBlock* pDataBlock,
|
||||||
// update the number of NULL data rows
|
// update the number of NULL data rows
|
||||||
size_t numOfCols = pSup->numOfCols;
|
size_t numOfCols = pSup->numOfCols;
|
||||||
|
|
||||||
int32_t i = 0, j = 0;
|
|
||||||
size_t size = taosArrayGetSize(pSup->pColAgg);
|
|
||||||
|
|
||||||
// ensure capacity
|
// ensure capacity
|
||||||
if(pDataBlock->pDataBlock) {
|
if (pDataBlock->pDataBlock) {
|
||||||
size_t colsNum = taosArrayGetSize(pDataBlock->pDataBlock);
|
size_t colsNum = taosArrayGetSize(pDataBlock->pDataBlock);
|
||||||
taosArrayEnsureCap(pSup->pColAgg, colsNum);
|
taosArrayEnsureCap(pSup->pColAgg, colsNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
SSDataBlock* pResBlock = pReader->pResBlock;
|
SSDataBlock* pResBlock = pReader->pResBlock;
|
||||||
|
@ -4209,8 +4149,9 @@ int32_t tsdbRetrieveDatablockSMA(STsdbReader* pReader, SSDataBlock* pDataBlock,
|
||||||
|
|
||||||
// do fill all null column value SMA info
|
// do fill all null column value SMA info
|
||||||
doFillNullColSMA(pSup, pBlock->nRow, numOfCols, pTsAgg);
|
doFillNullColSMA(pSup, pBlock->nRow, numOfCols, pTsAgg);
|
||||||
|
size_t size = taosArrayGetSize(pSup->pColAgg);
|
||||||
|
|
||||||
i = 0, j = 0;
|
int32_t i = 0, j = 0;
|
||||||
while (j < numOfCols && i < size) {
|
while (j < numOfCols && i < size) {
|
||||||
SColumnDataAgg* pAgg = taosArrayGet(pSup->pColAgg, i);
|
SColumnDataAgg* pAgg = taosArrayGet(pSup->pColAgg, i);
|
||||||
if (pAgg->colId == pSup->colId[j]) {
|
if (pAgg->colId == pSup->colId[j]) {
|
||||||
|
@ -4220,15 +4161,8 @@ int32_t tsdbRetrieveDatablockSMA(STsdbReader* pReader, SSDataBlock* pDataBlock,
|
||||||
} else if (pAgg->colId < pSup->colId[j]) {
|
} else if (pAgg->colId < pSup->colId[j]) {
|
||||||
i += 1;
|
i += 1;
|
||||||
} else if (pSup->colId[j] < pAgg->colId) {
|
} else if (pSup->colId[j] < pAgg->colId) {
|
||||||
if (pSup->colId[j] == PRIMARYKEY_TIMESTAMP_COL_ID) {
|
// ASSERT(pSup->colId[j] == PRIMARYKEY_TIMESTAMP_COL_ID);
|
||||||
pResBlock->pBlockAgg[pSup->slotId[j]] = &pSup->tsColAgg;
|
pResBlock->pBlockAgg[pSup->slotId[j]] = &pSup->tsColAgg;
|
||||||
} else {
|
|
||||||
// all date in this block are null
|
|
||||||
SColumnDataAgg nullColAgg = {.colId = pSup->colId[j], .numOfNull = pBlock->nRow};
|
|
||||||
taosArrayPush(pSup->pColAgg, &nullColAgg);
|
|
||||||
|
|
||||||
pResBlock->pBlockAgg[pSup->slotId[j]] = taosArrayGetLast(pSup->pColAgg);
|
|
||||||
}
|
|
||||||
j += 1;
|
j += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4460,9 +4394,12 @@ int32_t tsdbGetTableSchema(SVnode* pVnode, int64_t uid, STSchema** pSchema, int6
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
sversion = mr.me.stbEntry.schemaRow.version;
|
sversion = mr.me.stbEntry.schemaRow.version;
|
||||||
} else {
|
} else if (mr.me.type == TSDB_NORMAL_TABLE) {
|
||||||
ASSERT(mr.me.type == TSDB_NORMAL_TABLE);
|
|
||||||
sversion = mr.me.ntbEntry.schemaRow.version;
|
sversion = mr.me.ntbEntry.schemaRow.version;
|
||||||
|
} else {
|
||||||
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
|
metaReaderClear(&mr);
|
||||||
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
metaReaderClear(&mr);
|
metaReaderClear(&mr);
|
||||||
|
|
|
@ -184,18 +184,51 @@ _err:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t vnodePrepareCommit(SVnode *pVnode) {
|
int32_t vnodePrepareCommit(SVnode *pVnode, SCommitInfo *pInfo) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
int32_t lino = 0;
|
||||||
|
char dir[TSDB_FILENAME_LEN] = {0};
|
||||||
|
|
||||||
tsem_wait(&pVnode->canCommit);
|
tsem_wait(&pVnode->canCommit);
|
||||||
|
|
||||||
|
pVnode->state.commitTerm = pVnode->state.applyTerm;
|
||||||
|
|
||||||
|
pInfo->info.config = pVnode->config;
|
||||||
|
pInfo->info.state.committed = pVnode->state.applied;
|
||||||
|
pInfo->info.state.commitTerm = pVnode->state.applyTerm;
|
||||||
|
pInfo->info.state.commitID = pVnode->state.commitID;
|
||||||
|
pInfo->pVnode = pVnode;
|
||||||
|
pInfo->txn = metaGetTxn(pVnode->pMeta);
|
||||||
|
|
||||||
|
// save info
|
||||||
|
if (pVnode->pTfs) {
|
||||||
|
snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path);
|
||||||
|
} else {
|
||||||
|
snprintf(dir, TSDB_FILENAME_LEN, "%s", pVnode->path);
|
||||||
|
}
|
||||||
|
if (vnodeSaveInfo(dir, &pInfo->info) < 0) {
|
||||||
|
code = terrno;
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
}
|
||||||
|
|
||||||
tsdbPrepareCommit(pVnode->pTsdb);
|
tsdbPrepareCommit(pVnode->pTsdb);
|
||||||
|
|
||||||
metaPrepareAsyncCommit(pVnode->pMeta);
|
metaPrepareAsyncCommit(pVnode->pMeta);
|
||||||
|
|
||||||
code = smaPrepareAsyncCommit(pVnode->pSma);
|
code = smaPrepareAsyncCommit(pVnode->pSma);
|
||||||
if (code) goto _exit;
|
if (code) goto _exit;
|
||||||
|
|
||||||
_exit:
|
|
||||||
vnodeBufPoolUnRef(pVnode->inUse);
|
vnodeBufPoolUnRef(pVnode->inUse);
|
||||||
pVnode->inUse = NULL;
|
pVnode->inUse = NULL;
|
||||||
|
|
||||||
|
_exit:
|
||||||
|
if (code) {
|
||||||
|
vError("vgId:%d, %s failed at line %d since %s, commit id:%" PRId64, TD_VID(pVnode), __func__, lino,
|
||||||
|
tstrerror(code), pVnode->state.commitID);
|
||||||
|
} else {
|
||||||
|
vDebug("vgId:%d, %s done", TD_VID(pVnode), __func__);
|
||||||
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,33 +250,32 @@ _exit:
|
||||||
int vnodeAsyncCommit(SVnode *pVnode) {
|
int vnodeAsyncCommit(SVnode *pVnode) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
// prepare to commit
|
|
||||||
code = vnodePrepareCommit(pVnode);
|
|
||||||
if (code) goto _exit;
|
|
||||||
|
|
||||||
// schedule the task
|
|
||||||
pVnode->state.commitTerm = pVnode->state.applyTerm;
|
|
||||||
|
|
||||||
SCommitInfo *pInfo = (SCommitInfo *)taosMemoryCalloc(1, sizeof(*pInfo));
|
SCommitInfo *pInfo = (SCommitInfo *)taosMemoryCalloc(1, sizeof(*pInfo));
|
||||||
if (NULL == pInfo) {
|
if (NULL == pInfo) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _exit;
|
goto _exit;
|
||||||
}
|
}
|
||||||
pInfo->info.config = pVnode->config;
|
|
||||||
pInfo->info.state.committed = pVnode->state.applied;
|
// prepare to commit
|
||||||
pInfo->info.state.commitTerm = pVnode->state.applyTerm;
|
code = vnodePrepareCommit(pVnode, pInfo);
|
||||||
pInfo->info.state.commitID = pVnode->state.commitID;
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
pInfo->pVnode = pVnode;
|
goto _exit;
|
||||||
pInfo->txn = metaGetTxn(pVnode->pMeta);
|
}
|
||||||
|
|
||||||
|
// schedule the task
|
||||||
code = vnodeScheduleTask(vnodeCommitTask, pInfo);
|
code = vnodeScheduleTask(vnodeCommitTask, pInfo);
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
if (code) {
|
if (code) {
|
||||||
|
if (NULL != pInfo) {
|
||||||
|
taosMemoryFree(pInfo);
|
||||||
|
}
|
||||||
tsem_post(&pVnode->canCommit);
|
tsem_post(&pVnode->canCommit);
|
||||||
vError("vgId:%d, %s failed since %s, commit id:%" PRId64, TD_VID(pVnode), __func__, tstrerror(code),
|
vError("vgId:%d, %s failed since %s, commit id:%" PRId64, TD_VID(pVnode), __func__, tstrerror(code),
|
||||||
pVnode->state.commitID);
|
pVnode->state.commitID);
|
||||||
} else {
|
} else {
|
||||||
vDebug("vgId:%d, %s done", TD_VID(pVnode), __func__);
|
vInfo("vgId:%d, vnode async commit done, commitId:%" PRId64 " term:%" PRId64 " applied:%" PRId64, TD_VID(pVnode),
|
||||||
|
pVnode->state.commitID, pVnode->state.applyTerm, pVnode->state.applied);
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -262,7 +294,7 @@ static int vnodeCommitImpl(SCommitInfo *pInfo) {
|
||||||
char dir[TSDB_FILENAME_LEN] = {0};
|
char dir[TSDB_FILENAME_LEN] = {0};
|
||||||
SVnode *pVnode = pInfo->pVnode;
|
SVnode *pVnode = pInfo->pVnode;
|
||||||
|
|
||||||
vInfo("vgId:%d, start to commit, commit ID:%" PRId64 " version:%" PRId64 " term: %" PRId64, TD_VID(pVnode),
|
vInfo("vgId:%d, start to commit, commitId:%" PRId64 " version:%" PRId64 " term: %" PRId64, TD_VID(pVnode),
|
||||||
pVnode->state.commitID, pVnode->state.applied, pVnode->state.applyTerm);
|
pVnode->state.commitID, pVnode->state.applied, pVnode->state.applyTerm);
|
||||||
|
|
||||||
// persist wal before starting
|
// persist wal before starting
|
||||||
|
@ -271,16 +303,11 @@ static int vnodeCommitImpl(SCommitInfo *pInfo) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// save info
|
|
||||||
if (pVnode->pTfs) {
|
if (pVnode->pTfs) {
|
||||||
snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path);
|
snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path);
|
||||||
} else {
|
} else {
|
||||||
snprintf(dir, TSDB_FILENAME_LEN, "%s", pVnode->path);
|
snprintf(dir, TSDB_FILENAME_LEN, "%s", pVnode->path);
|
||||||
}
|
}
|
||||||
if (vnodeSaveInfo(dir, &pInfo->info) < 0) {
|
|
||||||
code = terrno;
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
}
|
|
||||||
|
|
||||||
// walBeginSnapshot(pVnode->pWal, pVnode->state.applied);
|
// walBeginSnapshot(pVnode->pWal, pVnode->state.applied);
|
||||||
syncBeginSnapshot(pVnode->sync, pVnode->state.applied);
|
syncBeginSnapshot(pVnode->sync, pVnode->state.applied);
|
||||||
|
|
|
@ -257,8 +257,8 @@ _exit:
|
||||||
pReader->index++;
|
pReader->index++;
|
||||||
*nData = sizeof(SSnapDataHdr) + pHdr->size;
|
*nData = sizeof(SSnapDataHdr) + pHdr->size;
|
||||||
pHdr->index = pReader->index;
|
pHdr->index = pReader->index;
|
||||||
vInfo("vgId:%d, vnode snapshot read data,index:%" PRId64 " type:%d nData:%d ", TD_VID(pReader->pVnode),
|
vDebug("vgId:%d, vnode snapshot read data, index:%" PRId64 " type:%d blockLen:%d ", TD_VID(pReader->pVnode),
|
||||||
pReader->index, pHdr->type, *nData);
|
pReader->index, pHdr->type, *nData);
|
||||||
} else {
|
} else {
|
||||||
vInfo("vgId:%d, vnode snapshot read data end, index:%" PRId64, TD_VID(pReader->pVnode), pReader->index);
|
vInfo("vgId:%d, vnode snapshot read data end, index:%" PRId64, TD_VID(pReader->pVnode), pReader->index);
|
||||||
}
|
}
|
||||||
|
@ -423,8 +423,8 @@ int32_t vnodeSnapWrite(SVSnapWriter *pWriter, uint8_t *pData, uint32_t nData) {
|
||||||
ASSERT(pHdr->index == pWriter->index + 1);
|
ASSERT(pHdr->index == pWriter->index + 1);
|
||||||
pWriter->index = pHdr->index;
|
pWriter->index = pHdr->index;
|
||||||
|
|
||||||
vInfo("vgId:%d, vnode snapshot write data, index:%" PRId64 " type:%d nData:%d", TD_VID(pVnode), pHdr->index,
|
vDebug("vgId:%d, vnode snapshot write data, index:%" PRId64 " type:%d blockLen:%d", TD_VID(pVnode), pHdr->index,
|
||||||
pHdr->type, nData);
|
pHdr->type, nData);
|
||||||
|
|
||||||
switch (pHdr->type) {
|
switch (pHdr->type) {
|
||||||
case SNAP_DATA_CFG: {
|
case SNAP_DATA_CFG: {
|
||||||
|
|
|
@ -218,7 +218,7 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp
|
||||||
|
|
||||||
if (!syncUtilUserCommit(pMsg->msgType)) goto _exit;
|
if (!syncUtilUserCommit(pMsg->msgType)) goto _exit;
|
||||||
|
|
||||||
if (pMsg->msgType == TDMT_VND_STREAM_RECOVER_BLOCKING_STAGE) {
|
if (pMsg->msgType == TDMT_VND_STREAM_RECOVER_BLOCKING_STAGE || pMsg->msgType == TDMT_STREAM_TASK_CHECK_RSP) {
|
||||||
if (tqCheckLogInWal(pVnode->pTq, version)) return 0;
|
if (tqCheckLogInWal(pVnode->pTq, version)) return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -391,9 +391,9 @@ static int32_t vnodeSyncApplyMsg(const SSyncFSM *pFsm, SRpcMsg *pMsg, const SFsm
|
||||||
|
|
||||||
const STraceId *trace = &pMsg->info.traceId;
|
const STraceId *trace = &pMsg->info.traceId;
|
||||||
vGTrace("vgId:%d, commit-cb is excuted, fsm:%p, index:%" PRId64 ", term:%" PRIu64 ", msg-index:%" PRId64
|
vGTrace("vgId:%d, commit-cb is excuted, fsm:%p, index:%" PRId64 ", term:%" PRIu64 ", msg-index:%" PRId64
|
||||||
", weak:%d, code:%d, state:%d %s, type:%s",
|
", weak:%d, code:%d, state:%d %s, type:%s code:0x%x",
|
||||||
pVnode->config.vgId, pFsm, pMeta->index, pMeta->term, pMsg->info.conn.applyIndex, pMeta->isWeak, pMeta->code,
|
pVnode->config.vgId, pFsm, pMeta->index, pMeta->term, pMsg->info.conn.applyIndex, pMeta->isWeak, pMeta->code,
|
||||||
pMeta->state, syncStr(pMeta->state), TMSG_INFO(pMsg->msgType));
|
pMeta->state, syncStr(pMeta->state), TMSG_INFO(pMsg->msgType), pMsg->code);
|
||||||
|
|
||||||
return tmsgPutToQueue(&pVnode->msgCb, APPLY_QUEUE, pMsg);
|
return tmsgPutToQueue(&pVnode->msgCb, APPLY_QUEUE, pMsg);
|
||||||
}
|
}
|
||||||
|
@ -465,9 +465,9 @@ static int32_t vnodeSnapshotStopWrite(const SSyncFSM *pFsm, void *pWriter, bool
|
||||||
|
|
||||||
static int32_t vnodeSnapshotDoWrite(const SSyncFSM *pFsm, void *pWriter, void *pBuf, int32_t len) {
|
static int32_t vnodeSnapshotDoWrite(const SSyncFSM *pFsm, void *pWriter, void *pBuf, int32_t len) {
|
||||||
SVnode *pVnode = pFsm->data;
|
SVnode *pVnode = pFsm->data;
|
||||||
vDebug("vgId:%d, continue write vnode snapshot, len:%d", pVnode->config.vgId, len);
|
vDebug("vgId:%d, continue write vnode snapshot, blockLen:%d", pVnode->config.vgId, len);
|
||||||
int32_t code = vnodeSnapWrite(pWriter, pBuf, len);
|
int32_t code = vnodeSnapWrite(pWriter, pBuf, len);
|
||||||
vDebug("vgId:%d, continue write vnode snapshot finished, len:%d", pVnode->config.vgId, len);
|
vDebug("vgId:%d, continue write vnode snapshot finished, blockLen:%d", pVnode->config.vgId, len);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -471,17 +471,20 @@ int32_t ctgHandleForceUpdate(SCatalog* pCtg, int32_t taskNum, SCtgJob* pJob, con
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ctgInitTask(SCtgJob* pJob, CTG_TASK_TYPE type, void* param, int32_t* taskId) {
|
int32_t ctgInitTask(SCtgJob* pJob, CTG_TASK_TYPE type, void* param, int32_t* taskId) {
|
||||||
|
int32_t code = 0;
|
||||||
int32_t tid = atomic_fetch_add_32(&pJob->taskIdx, 1);
|
int32_t tid = atomic_fetch_add_32(&pJob->taskIdx, 1);
|
||||||
|
|
||||||
CTG_LOCK(CTG_WRITE, &pJob->taskLock);
|
CTG_LOCK(CTG_WRITE, &pJob->taskLock);
|
||||||
CTG_ERR_RET((*gCtgAsyncFps[type].initFp)(pJob, tid, param));
|
CTG_ERR_JRET((*gCtgAsyncFps[type].initFp)(pJob, tid, param));
|
||||||
CTG_UNLOCK(CTG_WRITE, &pJob->taskLock);
|
|
||||||
|
|
||||||
if (taskId) {
|
if (taskId) {
|
||||||
*taskId = tid;
|
*taskId = tid;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
_return:
|
||||||
|
CTG_UNLOCK(CTG_WRITE, &pJob->taskLock);
|
||||||
|
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgJob** job, const SCatalogReq* pReq, catalogCallback fp,
|
int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgJob** job, const SCatalogReq* pReq, catalogCallback fp,
|
||||||
|
|
|
@ -2500,6 +2500,7 @@ int32_t ctgGetTbMetasFromCache(SCatalog *pCtg, SRequestConnInfo *pConn, SCtgTbMe
|
||||||
|
|
||||||
CTG_LOCK(CTG_READ, &pCache->metaLock);
|
CTG_LOCK(CTG_READ, &pCache->metaLock);
|
||||||
if (NULL == pCache->pMeta) {
|
if (NULL == pCache->pMeta) {
|
||||||
|
CTG_UNLOCK(CTG_READ, &pCache->metaLock);
|
||||||
ctgDebug("tb %s meta not in cache, dbFName:%s", pName->tname, dbFName);
|
ctgDebug("tb %s meta not in cache, dbFName:%s", pName->tname, dbFName);
|
||||||
ctgAddFetch(&ctx->pFetchs, dbIdx, i, fetchIdx, baseResIdx + i, flag);
|
ctgAddFetch(&ctx->pFetchs, dbIdx, i, fetchIdx, baseResIdx + i, flag);
|
||||||
taosArraySetSize(ctx->pResList, taosArrayGetSize(ctx->pResList) + 1);
|
taosArraySetSize(ctx->pResList, taosArrayGetSize(ctx->pResList) + 1);
|
||||||
|
|
|
@ -62,8 +62,8 @@ static void toDataCacheEntry(SDataDeleterHandle* pHandle, const SInputData* pInp
|
||||||
pEntry->numOfCols = taosArrayGetSize(pInput->pData->pDataBlock);
|
pEntry->numOfCols = taosArrayGetSize(pInput->pData->pDataBlock);
|
||||||
pEntry->dataLen = sizeof(SDeleterRes);
|
pEntry->dataLen = sizeof(SDeleterRes);
|
||||||
|
|
||||||
ASSERT(1 == pEntry->numOfRows);
|
// ASSERT(1 == pEntry->numOfRows);
|
||||||
ASSERT(3 == pEntry->numOfCols);
|
// ASSERT(3 == pEntry->numOfCols);
|
||||||
|
|
||||||
pBuf->useSize = sizeof(SDataCacheEntry);
|
pBuf->useSize = sizeof(SDataCacheEntry);
|
||||||
|
|
||||||
|
@ -167,7 +167,6 @@ static void getDataLength(SDataSinkHandle* pHandle, int64_t* pLen, bool* pQueryE
|
||||||
|
|
||||||
SDataDeleterBuf* pBuf = NULL;
|
SDataDeleterBuf* pBuf = NULL;
|
||||||
taosReadQitem(pDeleter->pDataBlocks, (void**)&pBuf);
|
taosReadQitem(pDeleter->pDataBlocks, (void**)&pBuf);
|
||||||
ASSERT(NULL != pBuf);
|
|
||||||
memcpy(&pDeleter->nextOutput, pBuf, sizeof(SDataDeleterBuf));
|
memcpy(&pDeleter->nextOutput, pBuf, sizeof(SDataDeleterBuf));
|
||||||
taosFreeQitem(pBuf);
|
taosFreeQitem(pBuf);
|
||||||
|
|
||||||
|
|
|
@ -77,8 +77,8 @@ static void toDataCacheEntry(SDataDispatchHandle* pHandle, const SInputData* pIn
|
||||||
|
|
||||||
pBuf->useSize = sizeof(SDataCacheEntry);
|
pBuf->useSize = sizeof(SDataCacheEntry);
|
||||||
pEntry->dataLen = blockEncode(pInput->pData, pEntry->data, numOfCols);
|
pEntry->dataLen = blockEncode(pInput->pData, pEntry->data, numOfCols);
|
||||||
ASSERT(pEntry->numOfRows == *(int32_t*)(pEntry->data + 8));
|
// ASSERT(pEntry->numOfRows == *(int32_t*)(pEntry->data + 8));
|
||||||
ASSERT(pEntry->numOfCols == *(int32_t*)(pEntry->data + 8 + 4));
|
// ASSERT(pEntry->numOfCols == *(int32_t*)(pEntry->data + 8 + 4));
|
||||||
|
|
||||||
pBuf->useSize += pEntry->dataLen;
|
pBuf->useSize += pEntry->dataLen;
|
||||||
|
|
||||||
|
@ -162,15 +162,14 @@ static void getDataLength(SDataSinkHandle* pHandle, int64_t* pLen, bool* pQueryE
|
||||||
|
|
||||||
SDataDispatchBuf* pBuf = NULL;
|
SDataDispatchBuf* pBuf = NULL;
|
||||||
taosReadQitem(pDispatcher->pDataBlocks, (void**)&pBuf);
|
taosReadQitem(pDispatcher->pDataBlocks, (void**)&pBuf);
|
||||||
ASSERT(NULL != pBuf);
|
|
||||||
memcpy(&pDispatcher->nextOutput, pBuf, sizeof(SDataDispatchBuf));
|
memcpy(&pDispatcher->nextOutput, pBuf, sizeof(SDataDispatchBuf));
|
||||||
taosFreeQitem(pBuf);
|
taosFreeQitem(pBuf);
|
||||||
|
|
||||||
SDataCacheEntry* pEntry = (SDataCacheEntry*)pDispatcher->nextOutput.pData;
|
SDataCacheEntry* pEntry = (SDataCacheEntry*)pDispatcher->nextOutput.pData;
|
||||||
*pLen = pEntry->dataLen;
|
*pLen = pEntry->dataLen;
|
||||||
|
|
||||||
ASSERT(pEntry->numOfRows == *(int32_t*)(pEntry->data + 8));
|
// ASSERT(pEntry->numOfRows == *(int32_t*)(pEntry->data + 8));
|
||||||
ASSERT(pEntry->numOfCols == *(int32_t*)(pEntry->data + 8 + 4));
|
// ASSERT(pEntry->numOfCols == *(int32_t*)(pEntry->data + 8 + 4));
|
||||||
|
|
||||||
*pQueryEnd = pDispatcher->queryEnd;
|
*pQueryEnd = pDispatcher->queryEnd;
|
||||||
qDebug("got data len %" PRId64 ", row num %d in sink", *pLen,
|
qDebug("got data len %" PRId64 ", row num %d in sink", *pLen,
|
||||||
|
@ -193,8 +192,8 @@ static int32_t getDataBlock(SDataSinkHandle* pHandle, SOutputData* pOutput) {
|
||||||
pOutput->numOfCols = pEntry->numOfCols;
|
pOutput->numOfCols = pEntry->numOfCols;
|
||||||
pOutput->compressed = pEntry->compressed;
|
pOutput->compressed = pEntry->compressed;
|
||||||
|
|
||||||
ASSERT(pEntry->numOfRows == *(int32_t*)(pEntry->data + 8));
|
// ASSERT(pEntry->numOfRows == *(int32_t*)(pEntry->data + 8));
|
||||||
ASSERT(pEntry->numOfCols == *(int32_t*)(pEntry->data + 8 + 4));
|
// ASSERT(pEntry->numOfCols == *(int32_t*)(pEntry->data + 8 + 4));
|
||||||
|
|
||||||
atomic_sub_fetch_64(&pDispatcher->cachedSize, pEntry->dataLen);
|
atomic_sub_fetch_64(&pDispatcher->cachedSize, pEntry->dataLen);
|
||||||
atomic_sub_fetch_64(&gDataSinkStat.cachedSize, pEntry->dataLen);
|
atomic_sub_fetch_64(&gDataSinkStat.cachedSize, pEntry->dataLen);
|
||||||
|
|
|
@ -373,7 +373,6 @@ int32_t loadRemoteDataCallback(void* param, SDataBuf* pMsg, int32_t code) {
|
||||||
pRsp->useconds = htobe64(pRsp->useconds);
|
pRsp->useconds = htobe64(pRsp->useconds);
|
||||||
pRsp->numOfBlocks = htonl(pRsp->numOfBlocks);
|
pRsp->numOfBlocks = htonl(pRsp->numOfBlocks);
|
||||||
|
|
||||||
ASSERT(pRsp != NULL);
|
|
||||||
qDebug("%s fetch rsp received, index:%d, blocks:%d, rows:%" PRId64 ", %p", pSourceDataInfo->taskId, index, pRsp->numOfBlocks,
|
qDebug("%s fetch rsp received, index:%d, blocks:%d, rows:%" PRId64 ", %p", pSourceDataInfo->taskId, index, pRsp->numOfBlocks,
|
||||||
pRsp->numOfRows, pExchangeInfo);
|
pRsp->numOfRows, pExchangeInfo);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -942,7 +942,6 @@ int32_t qStreamRestoreParam(qTaskInfo_t tinfo) {
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool qStreamRecoverScanFinished(qTaskInfo_t tinfo) {
|
bool qStreamRecoverScanFinished(qTaskInfo_t tinfo) {
|
||||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
||||||
return pTaskInfo->streamInfo.recoverScanFinished;
|
return pTaskInfo->streamInfo.recoverScanFinished;
|
||||||
|
|
|
@ -104,8 +104,6 @@ static int32_t doCopyToSDataBlock(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock,
|
||||||
|
|
||||||
void setOperatorCompleted(SOperatorInfo* pOperator) {
|
void setOperatorCompleted(SOperatorInfo* pOperator) {
|
||||||
pOperator->status = OP_EXEC_DONE;
|
pOperator->status = OP_EXEC_DONE;
|
||||||
ASSERT(pOperator->pTaskInfo != NULL);
|
|
||||||
|
|
||||||
pOperator->cost.totalCost = (taosGetTimestampUs() - pOperator->pTaskInfo->cost.start) / 1000.0;
|
pOperator->cost.totalCost = (taosGetTimestampUs() - pOperator->pTaskInfo->cost.start) / 1000.0;
|
||||||
setTaskStatus(pOperator->pTaskInfo, TASK_COMPLETED);
|
setTaskStatus(pOperator->pTaskInfo, TASK_COMPLETED);
|
||||||
}
|
}
|
||||||
|
@ -524,7 +522,7 @@ bool functionNeedToExecute(SqlFunctionCtx* pCtx) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t doCreateConstantValColumnAggInfo(SInputColumnInfoData* pInput, SFunctParam* pFuncParam, int32_t type,
|
static int32_t doCreateConstantValColumnSMAInfo(SInputColumnInfoData* pInput, SFunctParam* pFuncParam, int32_t type,
|
||||||
int32_t paramIndex, int32_t numOfRows) {
|
int32_t paramIndex, int32_t numOfRows) {
|
||||||
if (pInput->pData[paramIndex] == NULL) {
|
if (pInput->pData[paramIndex] == NULL) {
|
||||||
pInput->pData[paramIndex] = taosMemoryCalloc(1, sizeof(SColumnInfoData));
|
pInput->pData[paramIndex] = taosMemoryCalloc(1, sizeof(SColumnInfoData));
|
||||||
|
@ -548,8 +546,6 @@ static int32_t doCreateConstantValColumnAggInfo(SInputColumnInfoData* pInput, SF
|
||||||
da = pInput->pColumnDataAgg[paramIndex];
|
da = pInput->pColumnDataAgg[paramIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(!IS_VAR_DATA_TYPE(type));
|
|
||||||
|
|
||||||
if (type == TSDB_DATA_TYPE_BIGINT) {
|
if (type == TSDB_DATA_TYPE_BIGINT) {
|
||||||
int64_t v = pFuncParam->param.i;
|
int64_t v = pFuncParam->param.i;
|
||||||
*da = (SColumnDataAgg){.numOfNull = 0, .min = v, .max = v, .sum = v * numOfRows};
|
*da = (SColumnDataAgg){.numOfNull = 0, .min = v, .max = v, .sum = v * numOfRows};
|
||||||
|
@ -570,7 +566,7 @@ static int32_t doCreateConstantValColumnAggInfo(SInputColumnInfoData* pInput, SF
|
||||||
} else if (type == TSDB_DATA_TYPE_TIMESTAMP) {
|
} else if (type == TSDB_DATA_TYPE_TIMESTAMP) {
|
||||||
// do nothing
|
// do nothing
|
||||||
} else {
|
} else {
|
||||||
ASSERT(0);
|
qError("invalid constant type for sma info");
|
||||||
}
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -600,7 +596,7 @@ void setBlockSMAInfo(SqlFunctionCtx* pCtx, SExprInfo* pExprInfo, SSDataBlock* pB
|
||||||
// the data in the corresponding SColumnInfoData will not be used.
|
// the data in the corresponding SColumnInfoData will not be used.
|
||||||
pInput->pData[j] = taosArrayGet(pBlock->pDataBlock, slotId);
|
pInput->pData[j] = taosArrayGet(pBlock->pDataBlock, slotId);
|
||||||
} else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
|
} else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) {
|
||||||
doCreateConstantValColumnAggInfo(pInput, pFuncParam, pFuncParam->param.nType, j, pBlock->info.rows);
|
doCreateConstantValColumnSMAInfo(pInput, pFuncParam, pFuncParam->param.nType, j, pBlock->info.rows);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1577,8 +1573,7 @@ void destroyOperatorInfo(SOperatorInfo* pOperator) {
|
||||||
// each operator should be set their own function to return total cost buffer
|
// each operator should be set their own function to return total cost buffer
|
||||||
int32_t optrDefaultBufFn(SOperatorInfo* pOperator) {
|
int32_t optrDefaultBufFn(SOperatorInfo* pOperator) {
|
||||||
if (pOperator->blocking) {
|
if (pOperator->blocking) {
|
||||||
ASSERT(0);
|
return -1;
|
||||||
return 0;
|
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -2205,7 +2200,6 @@ static int32_t extractTbscanInStreamOpTree(SOperatorInfo* pOperator, STableScanI
|
||||||
return extractTbscanInStreamOpTree(pOperator->pDownstream[0], ppInfo);
|
return extractTbscanInStreamOpTree(pOperator->pDownstream[0], ppInfo);
|
||||||
} else {
|
} else {
|
||||||
SStreamScanInfo* pInfo = pOperator->info;
|
SStreamScanInfo* pInfo = pOperator->info;
|
||||||
ASSERT(pInfo->pTableScanOp->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN);
|
|
||||||
*ppInfo = pInfo->pTableScanOp->info;
|
*ppInfo = pInfo->pTableScanOp->info;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -2217,13 +2211,11 @@ int32_t extractTableScanNode(SPhysiNode* pNode, STableScanPhysiNode** ppNode) {
|
||||||
*ppNode = (STableScanPhysiNode*)pNode;
|
*ppNode = (STableScanPhysiNode*)pNode;
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
ASSERT(0);
|
|
||||||
terrno = TSDB_CODE_APP_ERROR;
|
terrno = TSDB_CODE_APP_ERROR;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (LIST_LENGTH(pNode->pChildren) != 1) {
|
if (LIST_LENGTH(pNode->pChildren) != 1) {
|
||||||
ASSERT(0);
|
|
||||||
terrno = TSDB_CODE_APP_ERROR;
|
terrno = TSDB_CODE_APP_ERROR;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -2233,32 +2225,6 @@ int32_t extractTableScanNode(SPhysiNode* pNode, STableScanPhysiNode** ppNode) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
int32_t rebuildReader(SOperatorInfo* pOperator, SSubplan* plan, SReadHandle* pHandle, int64_t uid, int64_t ts) {
|
|
||||||
STableScanInfo* pTableScanInfo = NULL;
|
|
||||||
if (extractTbscanInStreamOpTree(pOperator, &pTableScanInfo) < 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
STableScanPhysiNode* pNode = NULL;
|
|
||||||
if (extractTableScanNode(plan->pNode, &pNode) < 0) {
|
|
||||||
ASSERT(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
tsdbReaderClose(pTableScanInfo->dataReader);
|
|
||||||
|
|
||||||
STableListInfo info = {0};
|
|
||||||
pTableScanInfo->dataReader = doCreateDataReader(pNode, pHandle, &info, NULL);
|
|
||||||
if (pTableScanInfo->dataReader == NULL) {
|
|
||||||
ASSERT(0);
|
|
||||||
qError("failed to create data reader");
|
|
||||||
return TSDB_CODE_APP_ERROR;
|
|
||||||
}
|
|
||||||
// TODO: set uid and ts to data reader
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, qTaskInfo_t* pTaskInfo, SReadHandle* readHandle) {
|
int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, qTaskInfo_t* pTaskInfo, SReadHandle* readHandle) {
|
||||||
SExecTaskInfo* pTask = *(SExecTaskInfo**)pTaskInfo;
|
SExecTaskInfo* pTask = *(SExecTaskInfo**)pTaskInfo;
|
||||||
|
|
||||||
|
|
|
@ -42,38 +42,40 @@ typedef struct SJoinOperatorInfo {
|
||||||
static void setJoinColumnInfo(SColumnInfo* pColumn, const SColumnNode* pColumnNode);
|
static void setJoinColumnInfo(SColumnInfo* pColumn, const SColumnNode* pColumnNode);
|
||||||
static SSDataBlock* doMergeJoin(struct SOperatorInfo* pOperator);
|
static SSDataBlock* doMergeJoin(struct SOperatorInfo* pOperator);
|
||||||
static void destroyMergeJoinOperator(void* param);
|
static void destroyMergeJoinOperator(void* param);
|
||||||
static void extractTimeCondition(SJoinOperatorInfo* pInfo, SOperatorInfo** pDownstream, int32_t numOfDownstream,
|
static void extractTimeCondition(SJoinOperatorInfo* pInfo, SOperatorInfo** pDownstream, int32_t num,
|
||||||
SSortMergeJoinPhysiNode* pJoinNode);
|
SSortMergeJoinPhysiNode* pJoinNode, const char* idStr);
|
||||||
|
|
||||||
static void extractTimeCondition(SJoinOperatorInfo* pInfo, SOperatorInfo** pDownstream, int32_t numOfDownstream,
|
static void extractTimeCondition(SJoinOperatorInfo* pInfo, SOperatorInfo** pDownstream, int32_t num,
|
||||||
SSortMergeJoinPhysiNode* pJoinNode) {
|
SSortMergeJoinPhysiNode* pJoinNode, const char* idStr) {
|
||||||
SNode* pMergeCondition = pJoinNode->pMergeCondition;
|
SNode* pMergeCondition = pJoinNode->pMergeCondition;
|
||||||
if (nodeType(pMergeCondition) == QUERY_NODE_OPERATOR) {
|
if (nodeType(pMergeCondition) != QUERY_NODE_OPERATOR) {
|
||||||
SOperatorNode* pNode = (SOperatorNode*)pMergeCondition;
|
qError("not support this in join operator, %s", idStr);
|
||||||
SColumnNode* col1 = (SColumnNode*)pNode->pLeft;
|
return; // do not handle this
|
||||||
SColumnNode* col2 = (SColumnNode*)pNode->pRight;
|
}
|
||||||
SColumnNode* leftTsCol = NULL;
|
|
||||||
SColumnNode* rightTsCol = NULL;
|
SOperatorNode* pNode = (SOperatorNode*)pMergeCondition;
|
||||||
if (col1->dataBlockId == col2->dataBlockId ) {
|
SColumnNode* col1 = (SColumnNode*)pNode->pLeft;
|
||||||
|
SColumnNode* col2 = (SColumnNode*)pNode->pRight;
|
||||||
|
SColumnNode* leftTsCol = NULL;
|
||||||
|
SColumnNode* rightTsCol = NULL;
|
||||||
|
if (col1->dataBlockId == col2->dataBlockId) {
|
||||||
|
leftTsCol = col1;
|
||||||
|
rightTsCol = col2;
|
||||||
|
} else {
|
||||||
|
if (col1->dataBlockId == pDownstream[0]->resultDataBlockId) {
|
||||||
|
ASSERT(col2->dataBlockId == pDownstream[1]->resultDataBlockId);
|
||||||
leftTsCol = col1;
|
leftTsCol = col1;
|
||||||
rightTsCol = col2;
|
rightTsCol = col2;
|
||||||
} else {
|
} else {
|
||||||
if (col1->dataBlockId == pDownstream[0]->resultDataBlockId) {
|
ASSERT(col1->dataBlockId == pDownstream[1]->resultDataBlockId);
|
||||||
ASSERT(col2->dataBlockId == pDownstream[1]->resultDataBlockId);
|
ASSERT(col2->dataBlockId == pDownstream[0]->resultDataBlockId);
|
||||||
leftTsCol = col1;
|
leftTsCol = col2;
|
||||||
rightTsCol = col2;
|
rightTsCol = col1;
|
||||||
} else {
|
|
||||||
ASSERT(col1->dataBlockId == pDownstream[1]->resultDataBlockId);
|
|
||||||
ASSERT(col2->dataBlockId == pDownstream[0]->resultDataBlockId);
|
|
||||||
leftTsCol = col2;
|
|
||||||
rightTsCol = col1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
setJoinColumnInfo(&pInfo->leftCol, leftTsCol);
|
}
|
||||||
setJoinColumnInfo(&pInfo->rightCol, rightTsCol);
|
setJoinColumnInfo(&pInfo->leftCol, leftTsCol);
|
||||||
} else {
|
setJoinColumnInfo(&pInfo->rightCol, rightTsCol);
|
||||||
ASSERT(false);
|
}
|
||||||
}}
|
|
||||||
|
|
||||||
SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t numOfDownstream,
|
SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t numOfDownstream,
|
||||||
SSortMergeJoinPhysiNode* pJoinNode, SExecTaskInfo* pTaskInfo) {
|
SSortMergeJoinPhysiNode* pJoinNode, SExecTaskInfo* pTaskInfo) {
|
||||||
|
@ -97,7 +99,7 @@ SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t
|
||||||
pOperator->exprSupp.pExprInfo = pExprInfo;
|
pOperator->exprSupp.pExprInfo = pExprInfo;
|
||||||
pOperator->exprSupp.numOfExprs = numOfCols;
|
pOperator->exprSupp.numOfExprs = numOfCols;
|
||||||
|
|
||||||
extractTimeCondition(pInfo, pDownstream, numOfDownstream, pJoinNode);
|
extractTimeCondition(pInfo, pDownstream, numOfDownstream, pJoinNode, GET_TASKID(pTaskInfo));
|
||||||
|
|
||||||
if (pJoinNode->pOnConditions != NULL && pJoinNode->node.pConditions != NULL) {
|
if (pJoinNode->pOnConditions != NULL && pJoinNode->node.pConditions != NULL) {
|
||||||
pInfo->pCondAfterMerge = nodesMakeNode(QUERY_NODE_LOGIC_CONDITION);
|
pInfo->pCondAfterMerge = nodesMakeNode(QUERY_NODE_LOGIC_CONDITION);
|
||||||
|
@ -364,8 +366,6 @@ static bool mergeJoinGetNextTimestamp(SOperatorInfo* pOperator, int64_t* pLeftTs
|
||||||
char* pRightVal = colDataGetData(pRightCol, pJoinInfo->rightPos);
|
char* pRightVal = colDataGetData(pRightCol, pJoinInfo->rightPos);
|
||||||
*pRightTs = *(int64_t*)pRightVal;
|
*pRightTs = *(int64_t*)pRightVal;
|
||||||
|
|
||||||
ASSERT(pLeftCol->info.type == TSDB_DATA_TYPE_TIMESTAMP);
|
|
||||||
ASSERT(pRightCol->info.type == TSDB_DATA_TYPE_TIMESTAMP);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -232,30 +232,6 @@ static bool doLoadBlockSMA(STableScanBase* pTableScanInfo, SSDataBlock* pBlock,
|
||||||
if (!allColumnsHaveAgg) {
|
if (!allColumnsHaveAgg) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
// if (allColumnsHaveAgg == true) {
|
|
||||||
int32_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
|
|
||||||
|
|
||||||
// todo create this buffer during creating operator
|
|
||||||
if (pBlock->pBlockAgg == NULL) {
|
|
||||||
pBlock->pBlockAgg = taosMemoryCalloc(numOfCols, POINTER_BYTES);
|
|
||||||
if (pBlock->pBlockAgg == NULL) {
|
|
||||||
T_LONG_JMP(pTaskInfo->env, TSDB_CODE_OUT_OF_MEMORY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t num = taosArrayGetSize(pTableScanInfo->matchInfo.pList);
|
|
||||||
for (int32_t i = 0; i < num; ++i) {
|
|
||||||
SColMatchItem* pColMatchInfo = taosArrayGet(pTableScanInfo->matchInfo.pList, i);
|
|
||||||
if (!pColMatchInfo->needOutput) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
pBlock->pBlockAgg[pColMatchInfo->dstSlotId] = pColAgg[i];
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2251,6 +2227,7 @@ static void destroyStreamScanOperatorInfo(void* param) {
|
||||||
|
|
||||||
SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhysiNode* pTableScanNode, SNode* pTagCond,
|
SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhysiNode* pTableScanNode, SNode* pTagCond,
|
||||||
SExecTaskInfo* pTaskInfo) {
|
SExecTaskInfo* pTaskInfo) {
|
||||||
|
SArray* pColIds = NULL;
|
||||||
SStreamScanInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamScanInfo));
|
SStreamScanInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamScanInfo));
|
||||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||||
|
|
||||||
|
@ -2273,7 +2250,7 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t numOfOutput = taosArrayGetSize(pInfo->matchInfo.pList);
|
int32_t numOfOutput = taosArrayGetSize(pInfo->matchInfo.pList);
|
||||||
SArray* pColIds = taosArrayInit(numOfOutput, sizeof(int16_t));
|
pColIds = taosArrayInit(numOfOutput, sizeof(int16_t));
|
||||||
for (int32_t i = 0; i < numOfOutput; ++i) {
|
for (int32_t i = 0; i < numOfOutput; ++i) {
|
||||||
SColMatchItem* id = taosArrayGet(pInfo->matchInfo.pList, i);
|
SColMatchItem* id = taosArrayGet(pInfo->matchInfo.pList, i);
|
||||||
|
|
||||||
|
@ -2370,6 +2347,7 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys
|
||||||
memcpy(&pTaskInfo->streamInfo.tableCond, &pTSInfo->base.cond, sizeof(SQueryTableDataCond));
|
memcpy(&pTaskInfo->streamInfo.tableCond, &pTSInfo->base.cond, sizeof(SQueryTableDataCond));
|
||||||
} else {
|
} else {
|
||||||
taosArrayDestroy(pColIds);
|
taosArrayDestroy(pColIds);
|
||||||
|
pColIds = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the pseduo columns info
|
// create the pseduo columns info
|
||||||
|
|
|
@ -46,13 +46,15 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSortPhysiNode*
|
||||||
pOperator->pTaskInfo = pTaskInfo;
|
pOperator->pTaskInfo = pTaskInfo;
|
||||||
SDataBlockDescNode* pDescNode = pSortNode->node.pOutputDataBlockDesc;
|
SDataBlockDescNode* pDescNode = pSortNode->node.pOutputDataBlockDesc;
|
||||||
|
|
||||||
int32_t numOfCols = 0;
|
int32_t numOfCols = 0;
|
||||||
SSDataBlock* pResBlock = createDataBlockFromDescNode(pDescNode);
|
SExprInfo* pExprInfo = createExprInfo(pSortNode->pExprs, NULL, &numOfCols);
|
||||||
SExprInfo* pExprInfo = createExprInfo(pSortNode->pExprs, NULL, &numOfCols);
|
|
||||||
|
|
||||||
int32_t numOfOutputCols = 0;
|
int32_t numOfOutputCols = 0;
|
||||||
int32_t code =
|
int32_t code =
|
||||||
extractColMatchInfo(pSortNode->pTargets, pDescNode, &numOfOutputCols, COL_MATCH_FROM_SLOT_ID, &pInfo->matchInfo);
|
extractColMatchInfo(pSortNode->pTargets, pDescNode, &numOfOutputCols, COL_MATCH_FROM_SLOT_ID, &pInfo->matchInfo);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
goto _error;
|
||||||
|
}
|
||||||
|
|
||||||
pOperator->exprSupp.pCtx = createSqlFunctionCtx(pExprInfo, numOfCols, &pOperator->exprSupp.rowEntryInfoOffset);
|
pOperator->exprSupp.pCtx = createSqlFunctionCtx(pExprInfo, numOfCols, &pOperator->exprSupp.rowEntryInfoOffset);
|
||||||
initResultSizeInfo(&pOperator->resultInfo, 1024);
|
initResultSizeInfo(&pOperator->resultInfo, 1024);
|
||||||
|
@ -61,7 +63,7 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSortPhysiNode*
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->binfo.pRes = pResBlock;
|
pInfo->binfo.pRes = createDataBlockFromDescNode(pDescNode);
|
||||||
pInfo->pSortInfo = createSortInfo(pSortNode->pSortKeys);
|
pInfo->pSortInfo = createSortInfo(pSortNode->pSortKeys);
|
||||||
initLimitInfo(pSortNode->node.pLimit, pSortNode->node.pSlimit, &pInfo->limitInfo);
|
initLimitInfo(pSortNode->node.pLimit, pSortNode->node.pSlimit, &pInfo->limitInfo);
|
||||||
|
|
||||||
|
@ -86,7 +88,10 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSortPhysiNode*
|
||||||
|
|
||||||
_error:
|
_error:
|
||||||
pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY;
|
pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
taosMemoryFree(pInfo);
|
if (pInfo != NULL) {
|
||||||
|
destroySortOperatorInfo(pInfo);
|
||||||
|
}
|
||||||
|
|
||||||
taosMemoryFree(pOperator);
|
taosMemoryFree(pOperator);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -139,7 +144,6 @@ SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, i
|
||||||
int32_t numOfCols = taosArrayGetSize(pColMatchInfo);
|
int32_t numOfCols = taosArrayGetSize(pColMatchInfo);
|
||||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||||
SColMatchItem* pmInfo = taosArrayGet(pColMatchInfo, i);
|
SColMatchItem* pmInfo = taosArrayGet(pColMatchInfo, i);
|
||||||
// ASSERT(pmInfo->matchType == COL_MATCH_FROM_SLOT_ID);
|
|
||||||
|
|
||||||
SColumnInfoData* pSrc = taosArrayGet(p->pDataBlock, pmInfo->srcSlotId);
|
SColumnInfoData* pSrc = taosArrayGet(p->pDataBlock, pmInfo->srcSlotId);
|
||||||
SColumnInfoData* pDst = taosArrayGet(pDataBlock->pDataBlock, pmInfo->dstSlotId);
|
SColumnInfoData* pDst = taosArrayGet(pDataBlock->pDataBlock, pmInfo->dstSlotId);
|
||||||
|
@ -272,7 +276,6 @@ void destroySortOperatorInfo(void* param) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t getExplainExecInfo(SOperatorInfo* pOptr, void** pOptrExplain, uint32_t* len) {
|
int32_t getExplainExecInfo(SOperatorInfo* pOptr, void** pOptrExplain, uint32_t* len) {
|
||||||
ASSERT(pOptr != NULL);
|
|
||||||
SSortExecInfo* pInfo = taosMemoryCalloc(1, sizeof(SSortExecInfo));
|
SSortExecInfo* pInfo = taosMemoryCalloc(1, sizeof(SSortExecInfo));
|
||||||
|
|
||||||
SSortOperatorInfo* pOperatorInfo = (SSortOperatorInfo*)pOptr->info;
|
SSortOperatorInfo* pOperatorInfo = (SSortOperatorInfo*)pOptr->info;
|
||||||
|
@ -329,7 +332,6 @@ SSDataBlock* getGroupSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlo
|
||||||
int32_t numOfCols = taosArrayGetSize(pColMatchInfo);
|
int32_t numOfCols = taosArrayGetSize(pColMatchInfo);
|
||||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||||
SColMatchItem* pmInfo = taosArrayGet(pColMatchInfo, i);
|
SColMatchItem* pmInfo = taosArrayGet(pColMatchInfo, i);
|
||||||
// ASSERT(pmInfo->matchType == COL_MATCH_FROM_SLOT_ID);
|
|
||||||
|
|
||||||
SColumnInfoData* pSrc = taosArrayGet(p->pDataBlock, pmInfo->srcSlotId);
|
SColumnInfoData* pSrc = taosArrayGet(p->pDataBlock, pmInfo->srcSlotId);
|
||||||
SColumnInfoData* pDst = taosArrayGet(pDataBlock->pDataBlock, pmInfo->dstSlotId);
|
SColumnInfoData* pDst = taosArrayGet(pDataBlock->pDataBlock, pmInfo->dstSlotId);
|
||||||
|
@ -746,7 +748,6 @@ void destroyMultiwayMergeOperatorInfo(void* param) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t getMultiwayMergeExplainExecInfo(SOperatorInfo* pOptr, void** pOptrExplain, uint32_t* len) {
|
int32_t getMultiwayMergeExplainExecInfo(SOperatorInfo* pOptr, void** pOptrExplain, uint32_t* len) {
|
||||||
ASSERT(pOptr != NULL);
|
|
||||||
SSortExecInfo* pSortExecInfo = taosMemoryCalloc(1, sizeof(SSortExecInfo));
|
SSortExecInfo* pSortExecInfo = taosMemoryCalloc(1, sizeof(SSortExecInfo));
|
||||||
|
|
||||||
SMultiwayMergeOperatorInfo* pInfo = (SMultiwayMergeOperatorInfo*)pOptr->info;
|
SMultiwayMergeOperatorInfo* pInfo = (SMultiwayMergeOperatorInfo*)pOptr->info;
|
||||||
|
|
|
@ -907,7 +907,7 @@ static void removeDeleteResults(SHashObj* pUpdatedMap, SArray* pDelWins) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isOverdue(TSKEY ekey, STimeWindowAggSupp* pTwSup) {
|
bool isOverdue(TSKEY ekey, STimeWindowAggSupp* pTwSup) {
|
||||||
ASSERT(pTwSup->maxTs == INT64_MIN || pTwSup->maxTs > 0);
|
ASSERTS(pTwSup->maxTs == INT64_MIN || pTwSup->maxTs > 0, "maxts should greater than 0");
|
||||||
return pTwSup->maxTs != INT64_MIN && ekey < pTwSup->maxTs - pTwSup->waterMark;
|
return pTwSup->maxTs != INT64_MIN && ekey < pTwSup->maxTs - pTwSup->waterMark;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1396,7 +1396,6 @@ static int32_t getAllIntervalWindow(SSHashObj* pHashMap, SHashObj* resWins) {
|
||||||
while ((pIte = tSimpleHashIterate(pHashMap, pIte, &iter)) != NULL) {
|
while ((pIte = tSimpleHashIterate(pHashMap, pIte, &iter)) != NULL) {
|
||||||
void* key = tSimpleHashGetKey(pIte, &keyLen);
|
void* key = tSimpleHashGetKey(pIte, &keyLen);
|
||||||
uint64_t groupId = *(uint64_t*)key;
|
uint64_t groupId = *(uint64_t*)key;
|
||||||
ASSERT(keyLen == GET_RES_WINDOW_KEY_LEN(sizeof(TSKEY)));
|
|
||||||
TSKEY ts = *(int64_t*)((char*)key + sizeof(uint64_t));
|
TSKEY ts = *(int64_t*)((char*)key + sizeof(uint64_t));
|
||||||
SResultRowPosition* pPos = (SResultRowPosition*)pIte;
|
SResultRowPosition* pPos = (SResultRowPosition*)pIte;
|
||||||
int32_t code = saveWinResult(ts, pPos->pageId, pPos->offset, groupId, resWins);
|
int32_t code = saveWinResult(ts, pPos->pageId, pPos->offset, groupId, resWins);
|
||||||
|
@ -1547,7 +1546,7 @@ static void closeChildIntervalWindow(SOperatorInfo* pOperator, SArray* pChildren
|
||||||
for (int32_t i = 0; i < size; i++) {
|
for (int32_t i = 0; i < size; i++) {
|
||||||
SOperatorInfo* pChildOp = taosArrayGetP(pChildren, i);
|
SOperatorInfo* pChildOp = taosArrayGetP(pChildren, i);
|
||||||
SStreamIntervalOperatorInfo* pChInfo = pChildOp->info;
|
SStreamIntervalOperatorInfo* pChInfo = pChildOp->info;
|
||||||
ASSERT(pChInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE);
|
ASSERTS(pChInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE, "children trigger type should be at once");
|
||||||
pChInfo->twAggSup.maxTs = TMAX(pChInfo->twAggSup.maxTs, maxTs);
|
pChInfo->twAggSup.maxTs = TMAX(pChInfo->twAggSup.maxTs, maxTs);
|
||||||
closeStreamIntervalWindow(pChInfo->aggSup.pResultRowHashTable, &pChInfo->twAggSup, &pChInfo->interval, NULL, NULL,
|
closeStreamIntervalWindow(pChInfo->aggSup.pResultRowHashTable, &pChInfo->twAggSup, &pChInfo->interval, NULL, NULL,
|
||||||
NULL, pOperator);
|
NULL, pOperator);
|
||||||
|
@ -1767,8 +1766,6 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SIntervalPh
|
||||||
.maxTs = INT64_MIN,
|
.maxTs = INT64_MIN,
|
||||||
};
|
};
|
||||||
|
|
||||||
ASSERT(as.calTrigger != STREAM_TRIGGER_MAX_DELAY);
|
|
||||||
|
|
||||||
pInfo->win = pTaskInfo->window;
|
pInfo->win = pTaskInfo->window;
|
||||||
pInfo->inputOrder = (pPhyNode->window.inputTsOrder == ORDER_ASC) ? TSDB_ORDER_ASC : TSDB_ORDER_DESC;
|
pInfo->inputOrder = (pPhyNode->window.inputTsOrder == ORDER_ASC) ? TSDB_ORDER_ASC : TSDB_ORDER_DESC;
|
||||||
pInfo->resultTsOrder = (pPhyNode->window.outputTsOrder == ORDER_ASC) ? TSDB_ORDER_ASC : TSDB_ORDER_DESC;
|
pInfo->resultTsOrder = (pPhyNode->window.outputTsOrder == ORDER_ASC) ? TSDB_ORDER_ASC : TSDB_ORDER_DESC;
|
||||||
|
@ -2252,7 +2249,6 @@ static void doBuildPullDataBlock(SArray* array, int32_t* pIndex, SSDataBlock* pB
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
blockDataEnsureCapacity(pBlock, size - (*pIndex));
|
blockDataEnsureCapacity(pBlock, size - (*pIndex));
|
||||||
ASSERT(3 <= taosArrayGetSize(pBlock->pDataBlock));
|
|
||||||
SColumnInfoData* pStartTs = (SColumnInfoData*)taosArrayGet(pBlock->pDataBlock, START_TS_COLUMN_INDEX);
|
SColumnInfoData* pStartTs = (SColumnInfoData*)taosArrayGet(pBlock->pDataBlock, START_TS_COLUMN_INDEX);
|
||||||
SColumnInfoData* pEndTs = (SColumnInfoData*)taosArrayGet(pBlock->pDataBlock, END_TS_COLUMN_INDEX);
|
SColumnInfoData* pEndTs = (SColumnInfoData*)taosArrayGet(pBlock->pDataBlock, END_TS_COLUMN_INDEX);
|
||||||
SColumnInfoData* pGroupId = (SColumnInfoData*)taosArrayGet(pBlock->pDataBlock, GROUPID_COLUMN_INDEX);
|
SColumnInfoData* pGroupId = (SColumnInfoData*)taosArrayGet(pBlock->pDataBlock, GROUPID_COLUMN_INDEX);
|
||||||
|
@ -2346,6 +2342,17 @@ void doBuildResult(SOperatorInfo* pOperator, SStreamState* pState, SSDataBlock*
|
||||||
buildDataBlockFromGroupRes(pOperator, pState, pBlock, &pOperator->exprSupp, pGroupResInfo);
|
buildDataBlockFromGroupRes(pOperator, pState, pBlock, &pOperator->exprSupp, pGroupResInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t getNextQualifiedFinalWindow(SInterval* pInterval, STimeWindow* pNext, SDataBlockInfo* pDataBlockInfo,
|
||||||
|
TSKEY* primaryKeys, int32_t prevPosition) {
|
||||||
|
int32_t startPos = prevPosition + 1;
|
||||||
|
if (startPos == pDataBlockInfo->rows) {
|
||||||
|
startPos = -1;
|
||||||
|
} else {
|
||||||
|
*pNext = getFinalTimeWindow(primaryKeys[startPos], pInterval);
|
||||||
|
}
|
||||||
|
return startPos;
|
||||||
|
}
|
||||||
|
|
||||||
static void doStreamIntervalAggImpl(SOperatorInfo* pOperatorInfo, SSDataBlock* pSDataBlock, uint64_t groupId,
|
static void doStreamIntervalAggImpl(SOperatorInfo* pOperatorInfo, SSDataBlock* pSDataBlock, uint64_t groupId,
|
||||||
SHashObj* pUpdatedMap) {
|
SHashObj* pUpdatedMap) {
|
||||||
SStreamIntervalOperatorInfo* pInfo = (SStreamIntervalOperatorInfo*)pOperatorInfo->info;
|
SStreamIntervalOperatorInfo* pInfo = (SStreamIntervalOperatorInfo*)pOperatorInfo->info;
|
||||||
|
@ -2359,7 +2366,6 @@ static void doStreamIntervalAggImpl(SOperatorInfo* pOperatorInfo, SSDataBlock* p
|
||||||
SResultRow* pResult = NULL;
|
SResultRow* pResult = NULL;
|
||||||
int32_t forwardRows = 0;
|
int32_t forwardRows = 0;
|
||||||
|
|
||||||
ASSERT(pSDataBlock->pDataBlock != NULL);
|
|
||||||
SColumnInfoData* pColDataInfo = taosArrayGet(pSDataBlock->pDataBlock, pInfo->primaryTsIndex);
|
SColumnInfoData* pColDataInfo = taosArrayGet(pSDataBlock->pDataBlock, pInfo->primaryTsIndex);
|
||||||
tsCols = (int64_t*)pColDataInfo->pData;
|
tsCols = (int64_t*)pColDataInfo->pData;
|
||||||
|
|
||||||
|
@ -2456,8 +2462,12 @@ static void doStreamIntervalAggImpl(SOperatorInfo* pOperatorInfo, SSDataBlock* p
|
||||||
}
|
}
|
||||||
int32_t prevEndPos = (forwardRows - 1) * step + startPos;
|
int32_t prevEndPos = (forwardRows - 1) * step + startPos;
|
||||||
ASSERT(pSDataBlock->info.window.skey > 0 && pSDataBlock->info.window.ekey > 0);
|
ASSERT(pSDataBlock->info.window.skey > 0 && pSDataBlock->info.window.ekey > 0);
|
||||||
startPos =
|
if (IS_FINAL_OP(pInfo)) {
|
||||||
getNextQualifiedWindow(&pInfo->interval, &nextWin, &pSDataBlock->info, tsCols, prevEndPos, TSDB_ORDER_ASC);
|
startPos = getNextQualifiedFinalWindow(&pInfo->interval, &nextWin, &pSDataBlock->info, tsCols, prevEndPos);
|
||||||
|
} else {
|
||||||
|
startPos =
|
||||||
|
getNextQualifiedWindow(&pInfo->interval, &nextWin, &pSDataBlock->info, tsCols, prevEndPos, TSDB_ORDER_ASC);
|
||||||
|
}
|
||||||
if (startPos < 0) {
|
if (startPos < 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2482,7 +2492,6 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) {
|
||||||
doBuildPullDataBlock(pInfo->pPullWins, &pInfo->pullIndex, pInfo->pPullDataRes);
|
doBuildPullDataBlock(pInfo->pPullWins, &pInfo->pullIndex, pInfo->pPullDataRes);
|
||||||
if (pInfo->pPullDataRes->info.rows != 0) {
|
if (pInfo->pPullDataRes->info.rows != 0) {
|
||||||
// process the rest of the data
|
// process the rest of the data
|
||||||
ASSERT(IS_FINAL_OP(pInfo));
|
|
||||||
printDataBlock(pInfo->pPullDataRes, IS_FINAL_OP(pInfo) ? "interval final" : "interval semi");
|
printDataBlock(pInfo->pPullDataRes, IS_FINAL_OP(pInfo) ? "interval final" : "interval semi");
|
||||||
return pInfo->pPullDataRes;
|
return pInfo->pPullDataRes;
|
||||||
}
|
}
|
||||||
|
@ -2543,7 +2552,6 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) {
|
||||||
pInfo->numOfDatapack++;
|
pInfo->numOfDatapack++;
|
||||||
printDataBlock(pBlock, IS_FINAL_OP(pInfo) ? "interval final recv" : "interval semi recv");
|
printDataBlock(pBlock, IS_FINAL_OP(pInfo) ? "interval final recv" : "interval semi recv");
|
||||||
|
|
||||||
ASSERT(pBlock->info.type != STREAM_INVERT);
|
|
||||||
if (pBlock->info.type == STREAM_NORMAL || pBlock->info.type == STREAM_PULL_DATA) {
|
if (pBlock->info.type == STREAM_NORMAL || pBlock->info.type == STREAM_PULL_DATA) {
|
||||||
pInfo->binfo.pRes->info.type = pBlock->info.type;
|
pInfo->binfo.pRes->info.type = pBlock->info.type;
|
||||||
} else if (pBlock->info.type == STREAM_DELETE_DATA || pBlock->info.type == STREAM_DELETE_RESULT ||
|
} else if (pBlock->info.type == STREAM_DELETE_DATA || pBlock->info.type == STREAM_DELETE_RESULT ||
|
||||||
|
@ -2633,7 +2641,6 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) {
|
||||||
doBuildPullDataBlock(pInfo->pPullWins, &pInfo->pullIndex, pInfo->pPullDataRes);
|
doBuildPullDataBlock(pInfo->pPullWins, &pInfo->pullIndex, pInfo->pPullDataRes);
|
||||||
if (pInfo->pPullDataRes->info.rows != 0) {
|
if (pInfo->pPullDataRes->info.rows != 0) {
|
||||||
// process the rest of the data
|
// process the rest of the data
|
||||||
ASSERT(IS_FINAL_OP(pInfo));
|
|
||||||
printDataBlock(pInfo->pPullDataRes, IS_FINAL_OP(pInfo) ? "interval final" : "interval semi");
|
printDataBlock(pInfo->pPullDataRes, IS_FINAL_OP(pInfo) ? "interval final" : "interval semi");
|
||||||
return pInfo->pPullDataRes;
|
return pInfo->pPullDataRes;
|
||||||
}
|
}
|
||||||
|
@ -2688,7 +2695,7 @@ SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream,
|
||||||
.deleteMarkSaved = 0,
|
.deleteMarkSaved = 0,
|
||||||
.calTriggerSaved = 0,
|
.calTriggerSaved = 0,
|
||||||
};
|
};
|
||||||
ASSERT(pInfo->twAggSup.calTrigger != STREAM_TRIGGER_MAX_DELAY);
|
ASSERTS(pInfo->twAggSup.calTrigger != STREAM_TRIGGER_MAX_DELAY, "trigger type should not be max delay");
|
||||||
pInfo->primaryTsIndex = ((SColumnNode*)pIntervalPhyNode->window.pTspk)->slotId;
|
pInfo->primaryTsIndex = ((SColumnNode*)pIntervalPhyNode->window.pTspk)->slotId;
|
||||||
size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
|
size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
|
||||||
initResultSizeInfo(&pOperator->resultInfo, 4096);
|
initResultSizeInfo(&pOperator->resultInfo, 4096);
|
||||||
|
@ -2713,7 +2720,6 @@ SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream,
|
||||||
|
|
||||||
initStreamFunciton(pOperator->exprSupp.pCtx, pOperator->exprSupp.numOfExprs);
|
initStreamFunciton(pOperator->exprSupp.pCtx, pOperator->exprSupp.numOfExprs);
|
||||||
|
|
||||||
ASSERT(numOfCols > 0);
|
|
||||||
initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pTaskInfo->window);
|
initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pTaskInfo->window);
|
||||||
|
|
||||||
pInfo->pState = taosMemoryCalloc(1, sizeof(SStreamState));
|
pInfo->pState = taosMemoryCalloc(1, sizeof(SStreamState));
|
||||||
|
@ -2724,6 +2730,9 @@ SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream,
|
||||||
pInfo->pChildren = NULL;
|
pInfo->pChildren = NULL;
|
||||||
if (numOfChild > 0) {
|
if (numOfChild > 0) {
|
||||||
pInfo->pChildren = taosArrayInit(numOfChild, sizeof(void*));
|
pInfo->pChildren = taosArrayInit(numOfChild, sizeof(void*));
|
||||||
|
if (!pInfo->pChildren) {
|
||||||
|
goto _error;
|
||||||
|
}
|
||||||
for (int32_t i = 0; i < numOfChild; i++) {
|
for (int32_t i = 0; i < numOfChild; i++) {
|
||||||
SOperatorInfo* pChildOp = createStreamFinalIntervalOperatorInfo(NULL, pPhyNode, pTaskInfo, 0);
|
SOperatorInfo* pChildOp = createStreamFinalIntervalOperatorInfo(NULL, pPhyNode, pTaskInfo, 0);
|
||||||
if (pChildOp) {
|
if (pChildOp) {
|
||||||
|
@ -2746,7 +2755,6 @@ SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream,
|
||||||
// semi interval operator does not catch result
|
// semi interval operator does not catch result
|
||||||
pInfo->isFinal = false;
|
pInfo->isFinal = false;
|
||||||
pOperator->name = "StreamSemiIntervalOperator";
|
pOperator->name = "StreamSemiIntervalOperator";
|
||||||
ASSERT(pInfo->aggSup.currentPageId == -1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IS_FINAL_OP(pInfo) || numOfChild == 0) {
|
if (!IS_FINAL_OP(pInfo) || numOfChild == 0) {
|
||||||
|
@ -3162,15 +3170,6 @@ static void doStreamSessionAggImpl(SOperatorInfo* pOperator, SSDataBlock* pSData
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void deleteWindow(SArray* pWinInfos, int32_t index, FDelete fp) {
|
|
||||||
ASSERT(index >= 0 && index < taosArrayGetSize(pWinInfos));
|
|
||||||
if (fp) {
|
|
||||||
void* ptr = taosArrayGet(pWinInfos, index);
|
|
||||||
fp(ptr);
|
|
||||||
}
|
|
||||||
taosArrayRemove(pWinInfos, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void doDeleteTimeWindows(SStreamAggSupporter* pAggSup, SSDataBlock* pBlock, SArray* result) {
|
static void doDeleteTimeWindows(SStreamAggSupporter* pAggSup, SSDataBlock* pBlock, SArray* result) {
|
||||||
SColumnInfoData* pStartTsCol = taosArrayGet(pBlock->pDataBlock, START_TS_COLUMN_INDEX);
|
SColumnInfoData* pStartTsCol = taosArrayGet(pBlock->pDataBlock, START_TS_COLUMN_INDEX);
|
||||||
TSKEY* startDatas = (TSKEY*)pStartTsCol->pData;
|
TSKEY* startDatas = (TSKEY*)pStartTsCol->pData;
|
||||||
|
@ -3218,7 +3217,6 @@ static int32_t copyUpdateResult(SSHashObj* pStUpdated, SArray* pUpdated) {
|
||||||
int32_t iter = 0;
|
int32_t iter = 0;
|
||||||
while ((pIte = tSimpleHashIterate(pStUpdated, pIte, &iter)) != NULL) {
|
while ((pIte = tSimpleHashIterate(pStUpdated, pIte, &iter)) != NULL) {
|
||||||
void* key = tSimpleHashGetKey(pIte, &keyLen);
|
void* key = tSimpleHashGetKey(pIte, &keyLen);
|
||||||
ASSERT(keyLen == sizeof(SSessionKey));
|
|
||||||
taosArrayPush(pUpdated, key);
|
taosArrayPush(pUpdated, key);
|
||||||
}
|
}
|
||||||
taosArraySort(pUpdated, sessionKeyCompareAsc);
|
taosArraySort(pUpdated, sessionKeyCompareAsc);
|
||||||
|
@ -3279,7 +3277,6 @@ static void rebuildSessionWindow(SOperatorInfo* pOperator, SArray* pWinArray, SS
|
||||||
SStreamAggSupporter* pAggSup = &pInfo->streamAggSup;
|
SStreamAggSupporter* pAggSup = &pInfo->streamAggSup;
|
||||||
int32_t numOfOutput = pSup->numOfExprs;
|
int32_t numOfOutput = pSup->numOfExprs;
|
||||||
int32_t numOfChildren = taosArrayGetSize(pInfo->pChildren);
|
int32_t numOfChildren = taosArrayGetSize(pInfo->pChildren);
|
||||||
ASSERT(pInfo->pChildren);
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < size; i++) {
|
for (int32_t i = 0; i < size; i++) {
|
||||||
SSessionKey* pWinKey = taosArrayGet(pWinArray, i);
|
SSessionKey* pWinKey = taosArrayGet(pWinArray, i);
|
||||||
|
@ -3380,7 +3377,6 @@ static void copyDeleteWindowInfo(SArray* pResWins, SSHashObj* pStDeleted) {
|
||||||
void initGroupResInfoFromArrayList(SGroupResInfo* pGroupResInfo, SArray* pArrayList) {
|
void initGroupResInfoFromArrayList(SGroupResInfo* pGroupResInfo, SArray* pArrayList) {
|
||||||
pGroupResInfo->pRows = pArrayList;
|
pGroupResInfo->pRows = pArrayList;
|
||||||
pGroupResInfo->index = 0;
|
pGroupResInfo->index = 0;
|
||||||
ASSERT(pGroupResInfo->index <= getNumOfTotalRes(pGroupResInfo));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void doBuildSessionResult(SOperatorInfo* pOperator, SStreamState* pState, SGroupResInfo* pGroupResInfo,
|
void doBuildSessionResult(SOperatorInfo* pOperator, SStreamState* pState, SGroupResInfo* pGroupResInfo,
|
||||||
|
@ -4811,7 +4807,6 @@ SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SPhys
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
int32_t numOfCols = 0;
|
int32_t numOfCols = 0;
|
||||||
SExprInfo* pExprInfo = createExprInfo(pIntervalPhyNode->window.pFuncs, NULL, &numOfCols);
|
SExprInfo* pExprInfo = createExprInfo(pIntervalPhyNode->window.pFuncs, NULL, &numOfCols);
|
||||||
ASSERT(numOfCols > 0);
|
|
||||||
|
|
||||||
SSDataBlock* pResBlock = createDataBlockFromDescNode(pPhyNode->pOutputDataBlockDesc);
|
SSDataBlock* pResBlock = createDataBlockFromDescNode(pPhyNode->pOutputDataBlockDesc);
|
||||||
SInterval interval = {
|
SInterval interval = {
|
||||||
|
@ -4831,7 +4826,7 @@ SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SPhys
|
||||||
.deleteMark = getDeleteMark(pIntervalPhyNode),
|
.deleteMark = getDeleteMark(pIntervalPhyNode),
|
||||||
};
|
};
|
||||||
|
|
||||||
ASSERT(twAggSupp.calTrigger != STREAM_TRIGGER_MAX_DELAY);
|
ASSERTS(twAggSupp.calTrigger != STREAM_TRIGGER_MAX_DELAY, "trigger type should not be max delay");
|
||||||
|
|
||||||
pOperator->pTaskInfo = pTaskInfo;
|
pOperator->pTaskInfo = pTaskInfo;
|
||||||
pInfo->interval = interval;
|
pInfo->interval = interval;
|
||||||
|
|
|
@ -49,7 +49,9 @@ static FORCE_INLINE int32_t taosHashCapacity(int32_t length) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SSHashObj *tSimpleHashInit(size_t capacity, _hash_fn_t fn) {
|
SSHashObj *tSimpleHashInit(size_t capacity, _hash_fn_t fn) {
|
||||||
ASSERT(fn != NULL);
|
if (fn == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (capacity == 0) {
|
if (capacity == 0) {
|
||||||
capacity = 4;
|
capacity = 4;
|
||||||
|
@ -66,7 +68,6 @@ SSHashObj *tSimpleHashInit(size_t capacity, _hash_fn_t fn) {
|
||||||
|
|
||||||
pHashObj->equalFp = memcmp;
|
pHashObj->equalFp = memcmp;
|
||||||
pHashObj->hashFp = fn;
|
pHashObj->hashFp = fn;
|
||||||
ASSERT((pHashObj->capacity & (pHashObj->capacity - 1)) == 0);
|
|
||||||
|
|
||||||
pHashObj->hashList = (SHNode **)taosMemoryCalloc(pHashObj->capacity, sizeof(void *));
|
pHashObj->hashList = (SHNode **)taosMemoryCalloc(pHashObj->capacity, sizeof(void *));
|
||||||
if (!pHashObj->hashList) {
|
if (!pHashObj->hashList) {
|
||||||
|
|
|
@ -800,6 +800,7 @@ STupleHandle* tsortNextTuple(SSortHandle* pHandle) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// all sources are completed.
|
||||||
if (pHandle->cmpParam.numOfSources == pHandle->numOfCompletedSources) {
|
if (pHandle->cmpParam.numOfSources == pHandle->numOfCompletedSources) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -606,6 +606,7 @@ int32_t udfdLoadUdf(char *udfName, SUdf *udf) {
|
||||||
}
|
}
|
||||||
static bool udfdRpcRfp(int32_t code, tmsg_t msgType) {
|
static bool udfdRpcRfp(int32_t code, tmsg_t msgType) {
|
||||||
if (code == TSDB_CODE_RPC_NETWORK_UNAVAIL || code == TSDB_CODE_RPC_BROKEN_LINK || code == TSDB_CODE_SYN_NOT_LEADER ||
|
if (code == TSDB_CODE_RPC_NETWORK_UNAVAIL || code == TSDB_CODE_RPC_BROKEN_LINK || code == TSDB_CODE_SYN_NOT_LEADER ||
|
||||||
|
code == TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED ||
|
||||||
code == TSDB_CODE_SYN_RESTORING || code == TSDB_CODE_MNODE_NOT_FOUND || code == TSDB_CODE_APP_IS_STARTING ||
|
code == TSDB_CODE_SYN_RESTORING || code == TSDB_CODE_MNODE_NOT_FOUND || code == TSDB_CODE_APP_IS_STARTING ||
|
||||||
code == TSDB_CODE_APP_IS_STOPPING) {
|
code == TSDB_CODE_APP_IS_STOPPING) {
|
||||||
if (msgType == TDMT_SCH_QUERY || msgType == TDMT_SCH_MERGE_QUERY || msgType == TDMT_SCH_FETCH ||
|
if (msgType == TDMT_SCH_QUERY || msgType == TDMT_SCH_MERGE_QUERY || msgType == TDMT_SCH_FETCH ||
|
||||||
|
|
|
@ -198,7 +198,7 @@ SNode* createDropComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, cons
|
||||||
SNode* createCreateTopicStmtUseQuery(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName,
|
SNode* createCreateTopicStmtUseQuery(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName,
|
||||||
SNode* pQuery);
|
SNode* pQuery);
|
||||||
SNode* createCreateTopicStmtUseDb(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName,
|
SNode* createCreateTopicStmtUseDb(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName,
|
||||||
const SToken* pSubDbName, bool withMeta);
|
SToken* pSubDbName, bool withMeta);
|
||||||
SNode* createCreateTopicStmtUseTable(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName,
|
SNode* createCreateTopicStmtUseTable(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName,
|
||||||
SNode* pRealTable, bool withMeta);
|
SNode* pRealTable, bool withMeta);
|
||||||
SNode* createDropTopicStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pTopicName);
|
SNode* createDropTopicStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pTopicName);
|
||||||
|
|
|
@ -35,128 +35,27 @@ struct SToken;
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define IS_DATA_COL_ORDERED(spd) ((spd->orderStatus) == (int8_t)ORDER_STATUS_ORDERED)
|
|
||||||
|
|
||||||
typedef enum EOrderStatus {
|
|
||||||
ORDER_STATUS_UNKNOWN = 0,
|
|
||||||
ORDER_STATUS_ORDERED = 1,
|
|
||||||
ORDER_STATUS_DISORDERED = 2,
|
|
||||||
} EOrderStatus;
|
|
||||||
|
|
||||||
typedef enum EValStat {
|
|
||||||
VAL_STAT_HAS = 0x0, // 0 means has val
|
|
||||||
VAL_STAT_NONE = 0x01, // 1 means no val
|
|
||||||
} EValStat;
|
|
||||||
|
|
||||||
typedef struct SBoundColumn {
|
|
||||||
int32_t offset; // all column offset value
|
|
||||||
int32_t toffset; // first part offset for SDataRow TODO: get offset from STSchema on future
|
|
||||||
uint8_t valStat; // EValStat. denote if current column bound or not(0 means has val, 1 means no val)
|
|
||||||
} SBoundColumn;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
col_id_t schemaColIdx;
|
|
||||||
col_id_t boundIdx;
|
|
||||||
col_id_t finalIdx;
|
|
||||||
} SBoundIdxInfo;
|
|
||||||
|
|
||||||
typedef struct SParsedDataColInfo {
|
|
||||||
col_id_t numOfCols;
|
|
||||||
col_id_t numOfBound;
|
|
||||||
uint16_t flen; // TODO: get from STSchema
|
|
||||||
uint16_t allNullLen; // TODO: get from STSchema(base on SDataRow)
|
|
||||||
uint16_t extendedVarLen;
|
|
||||||
uint16_t boundNullLen; // bound column len with all NULL value(without VarDataOffsetT/SColIdx part)
|
|
||||||
col_id_t *boundColumns; // bound column idx according to schema
|
|
||||||
SBoundColumn *cols;
|
|
||||||
SBoundIdxInfo *colIdxInfo;
|
|
||||||
int8_t orderStatus; // bound columns
|
|
||||||
} SParsedDataColInfo;
|
|
||||||
|
|
||||||
typedef struct SInsertParseBaseContext {
|
|
||||||
SParseContext *pComCxt;
|
|
||||||
char *pSql;
|
|
||||||
SMsgBuf msg;
|
|
||||||
} SInsertParseBaseContext;
|
|
||||||
|
|
||||||
typedef struct SInsertParseSyntaxCxt {
|
|
||||||
SParseContext *pComCxt;
|
|
||||||
char *pSql;
|
|
||||||
SMsgBuf msg;
|
|
||||||
SParseMetaCache *pMetaCache;
|
|
||||||
} SInsertParseSyntaxCxt;
|
|
||||||
|
|
||||||
typedef struct SMemParam {
|
|
||||||
SRowBuilder *rb;
|
|
||||||
SSchema *schema;
|
|
||||||
int32_t toffset;
|
|
||||||
col_id_t colIdx;
|
|
||||||
} SMemParam;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint8_t rowType; // default is 0, that is SDataRow
|
|
||||||
int32_t rowSize;
|
|
||||||
} SMemRowBuilder;
|
|
||||||
|
|
||||||
typedef struct STableDataBlocks {
|
|
||||||
int8_t tsSource; // where does the UNIX timestamp come from, server or client
|
|
||||||
bool ordered; // if current rows are ordered or not
|
|
||||||
int32_t vgId; // virtual group id
|
|
||||||
int64_t prevTS; // previous timestamp, recorded to decide if the records array is ts ascending
|
|
||||||
int32_t numOfTables; // number of tables in current submit block
|
|
||||||
int32_t rowSize; // row size for current table
|
|
||||||
uint32_t nAllocSize;
|
|
||||||
uint32_t headerSize; // header for table info (uid, tid, submit metadata)
|
|
||||||
uint32_t size;
|
|
||||||
STableMeta *pTableMeta; // the tableMeta of current table, the table meta will be used during submit, keep a ref to
|
|
||||||
// avoid to be removed from cache
|
|
||||||
char *pData;
|
|
||||||
bool cloned;
|
|
||||||
int32_t createTbReqLen;
|
|
||||||
SParsedDataColInfo boundColumnInfo;
|
|
||||||
SRowBuilder rowBuilder;
|
|
||||||
} STableDataBlocks;
|
|
||||||
|
|
||||||
int32_t insGetExtendedRowSize(STableDataBlocks *pBlock);
|
|
||||||
void insGetSTSRowAppendInfo(uint8_t rowType, SParsedDataColInfo *spd, col_id_t idx, int32_t *toffset, col_id_t *colIdx);
|
|
||||||
int32_t insSetBlockInfo(SSubmitBlk *pBlocks, STableDataBlocks *dataBuf, int32_t numOfRows, SMsgBuf *pMsg);
|
|
||||||
int32_t insSchemaIdxCompar(const void *lhs, const void *rhs);
|
|
||||||
int32_t insBoundIdxCompar(const void *lhs, const void *rhs);
|
|
||||||
void insSetBoundColumnInfo(SParsedDataColInfo *pColList, SSchema *pSchema, col_id_t numOfCols);
|
|
||||||
void insDestroyBlockArrayList(SArray *pDataBlockList);
|
|
||||||
void insDestroyBlockHashmap(SHashObj *pDataBlockHash);
|
|
||||||
int32_t insInitRowBuilder(SRowBuilder *pBuilder, int16_t schemaVer, SParsedDataColInfo *pColInfo);
|
|
||||||
int32_t insGetDataBlockFromList(SHashObj *pHashList, void *id, int32_t idLen, int32_t size, int32_t startOffset,
|
|
||||||
int32_t rowSize, STableMeta *pTableMeta, STableDataBlocks **dataBlocks,
|
|
||||||
SArray *pBlockList, SVCreateTbReq *pCreateTbReq);
|
|
||||||
int32_t insMergeTableDataBlocks(SHashObj *pHashObj, SArray **pVgDataBlocks);
|
|
||||||
int32_t insBuildCreateTbMsg(STableDataBlocks *pBlocks, SVCreateTbReq *pCreateTbReq);
|
|
||||||
int32_t insAllocateMemForSize(STableDataBlocks *pDataBlock, int32_t allSize);
|
|
||||||
int32_t insCreateSName(SName *pName, struct SToken *pTableName, int32_t acctId, const char *dbName, SMsgBuf *pMsgBuf);
|
|
||||||
int16_t insFindCol(struct SToken *pColname, int16_t start, int16_t end, SSchema *pSchema);
|
|
||||||
void insBuildCreateTbReq(SVCreateTbReq *pTbReq, const char *tname, STag *pTag, int64_t suid, const char *sname,
|
|
||||||
SArray *tagName, uint8_t tagNum, int32_t ttl);
|
|
||||||
int32_t insMemRowAppend(SMsgBuf *pMsgBuf, const void *value, int32_t len, void *param);
|
|
||||||
int32_t insCheckTimestamp(STableDataBlocks *pDataBlocks, const char *start);
|
|
||||||
int32_t insBuildOutput(SHashObj *pVgroupsHashObj, SArray *pVgDataBlocks, SArray **pDataBlocks);
|
|
||||||
void insDestroyDataBlock(STableDataBlocks *pDataBlock);
|
|
||||||
|
|
||||||
typedef struct SVgroupDataCxt {
|
typedef struct SVgroupDataCxt {
|
||||||
int32_t vgId;
|
int32_t vgId;
|
||||||
SSubmitReq2 *pData;
|
SSubmitReq2 *pData;
|
||||||
} SVgroupDataCxt;
|
} SVgroupDataCxt;
|
||||||
|
|
||||||
|
int32_t insCreateSName(SName *pName, struct SToken *pTableName, int32_t acctId, const char *dbName, SMsgBuf *pMsgBuf);
|
||||||
|
int16_t insFindCol(struct SToken *pColname, int16_t start, int16_t end, SSchema *pSchema);
|
||||||
|
void insBuildCreateTbReq(SVCreateTbReq *pTbReq, const char *tname, STag *pTag, int64_t suid, const char *sname,
|
||||||
|
SArray *tagName, uint8_t tagNum, int32_t ttl);
|
||||||
int32_t insInitBoundColsInfo(int32_t numOfBound, SBoundColInfo *pInfo);
|
int32_t insInitBoundColsInfo(int32_t numOfBound, SBoundColInfo *pInfo);
|
||||||
void insCheckTableDataOrder(STableDataCxt *pTableCxt, TSKEY tsKey);
|
void insCheckTableDataOrder(STableDataCxt *pTableCxt, TSKEY tsKey);
|
||||||
int32_t insGetTableDataCxt(SHashObj *pHash, void *id, int32_t idLen, STableMeta *pTableMeta,
|
int32_t insGetTableDataCxt(SHashObj *pHash, void *id, int32_t idLen, STableMeta *pTableMeta,
|
||||||
SVCreateTbReq **pCreateTbReq, STableDataCxt **pTableCxt, bool colMode);
|
SVCreateTbReq **pCreateTbReq, STableDataCxt **pTableCxt, bool colMode);
|
||||||
int32_t initTableColSubmitData(STableDataCxt* pTableCxt);
|
int32_t initTableColSubmitData(STableDataCxt *pTableCxt);
|
||||||
int32_t insMergeTableDataCxt(SHashObj *pTableHash, SArray **pVgDataBlocks);
|
int32_t insMergeTableDataCxt(SHashObj *pTableHash, SArray **pVgDataBlocks);
|
||||||
int32_t insBuildVgDataBlocks(SHashObj *pVgroupsHashObj, SArray *pVgDataBlocks, SArray **pDataBlocks);
|
int32_t insBuildVgDataBlocks(SHashObj *pVgroupsHashObj, SArray *pVgDataBlocks, SArray **pDataBlocks);
|
||||||
void insDestroyTableDataCxtHashMap(SHashObj *pTableCxtHash);
|
void insDestroyTableDataCxtHashMap(SHashObj *pTableCxtHash);
|
||||||
void insDestroyVgroupDataCxt(SVgroupDataCxt *pVgCxt);
|
void insDestroyVgroupDataCxt(SVgroupDataCxt *pVgCxt);
|
||||||
void insDestroyVgroupDataCxtList(SArray *pVgCxtList);
|
void insDestroyVgroupDataCxtList(SArray *pVgCxtList);
|
||||||
void insDestroyVgroupDataCxtHashMap(SHashObj *pVgCxtHash);
|
void insDestroyVgroupDataCxtHashMap(SHashObj *pVgCxtHash);
|
||||||
void insDestroyTableDataCxt(STableDataCxt* pTableCxt);
|
void insDestroyTableDataCxt(STableDataCxt *pTableCxt);
|
||||||
void destroyBoundColInfo(SBoundColInfo* pInfo);
|
void insDestroyBoundColInfo(SBoundColInfo *pInfo);
|
||||||
|
|
||||||
#endif // TDENGINE_PAR_INSERT_UTIL_H
|
#endif // TDENGINE_PAR_INSERT_UTIL_H
|
||||||
|
|
|
@ -461,6 +461,8 @@ tag_item(A) ::= column_name(B) AS column_alias(C).
|
||||||
/************************************************ create index ********************************************************/
|
/************************************************ create index ********************************************************/
|
||||||
cmd ::= CREATE SMA INDEX not_exists_opt(D)
|
cmd ::= CREATE SMA INDEX not_exists_opt(D)
|
||||||
full_table_name(A) ON full_table_name(B) index_options(C). { pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, D, A, B, NULL, C); }
|
full_table_name(A) ON full_table_name(B) index_options(C). { pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, D, A, B, NULL, C); }
|
||||||
|
cmd ::= CREATE INDEX not_exists_opt(D)
|
||||||
|
full_table_name(A) ON full_table_name(B) NK_LP col_name_list(C) NK_RP. { pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_NORMAL, D, A, B, C, NULL); }
|
||||||
cmd ::= DROP INDEX exists_opt(B) full_table_name(A). { pCxt->pRootNode = createDropIndexStmt(pCxt, B, A); }
|
cmd ::= DROP INDEX exists_opt(B) full_table_name(A). { pCxt->pRootNode = createDropIndexStmt(pCxt, B, A); }
|
||||||
|
|
||||||
index_options(A) ::= FUNCTION NK_LP func_list(B) NK_RP INTERVAL
|
index_options(A) ::= FUNCTION NK_LP func_list(B) NK_RP INTERVAL
|
||||||
|
|
|
@ -1604,8 +1604,11 @@ SNode* createCreateTopicStmtUseQuery(SAstCreateContext* pCxt, bool ignoreExists,
|
||||||
}
|
}
|
||||||
|
|
||||||
SNode* createCreateTopicStmtUseDb(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName,
|
SNode* createCreateTopicStmtUseDb(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName,
|
||||||
const SToken* pSubDbName, bool withMeta) {
|
SToken* pSubDbName, bool withMeta) {
|
||||||
CHECK_PARSER_STATUS(pCxt);
|
CHECK_PARSER_STATUS(pCxt);
|
||||||
|
if (!checkDbName(pCxt, pSubDbName, true)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
SCreateTopicStmt* pStmt = (SCreateTopicStmt*)nodesMakeNode(QUERY_NODE_CREATE_TOPIC_STMT);
|
SCreateTopicStmt* pStmt = (SCreateTopicStmt*)nodesMakeNode(QUERY_NODE_CREATE_TOPIC_STMT);
|
||||||
CHECK_OUT_OF_MEM(pStmt);
|
CHECK_OUT_OF_MEM(pStmt);
|
||||||
COPY_STRING_FORM_ID_TOKEN(pStmt->topicName, pTopicName);
|
COPY_STRING_FORM_ID_TOKEN(pStmt->topicName, pTopicName);
|
||||||
|
|
|
@ -348,7 +348,7 @@ int32_t smlBindData(SQuery* query, bool dataFormat, SArray* tags, SArray* colsSc
|
||||||
}
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
destroyBoundColInfo(&bindTags);
|
insDestroyBoundColInfo(&bindTags);
|
||||||
taosMemoryFree(pCreateTblReq);
|
taosMemoryFree(pCreateTblReq);
|
||||||
taosArrayDestroy(tagName);
|
taosArrayDestroy(tagName);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -1466,7 +1466,7 @@ static int32_t parseInsertTableClauseBottom(SInsertParseContext* pCxt, SVnodeMod
|
||||||
}
|
}
|
||||||
|
|
||||||
static void resetEnvPreTable(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt) {
|
static void resetEnvPreTable(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt) {
|
||||||
destroyBoundColInfo(&pCxt->tags);
|
insDestroyBoundColInfo(&pCxt->tags);
|
||||||
taosMemoryFreeClear(pStmt->pTableMeta);
|
taosMemoryFreeClear(pStmt->pTableMeta);
|
||||||
tdDestroySVCreateTbReq(pStmt->pCreateTblReq);
|
tdDestroySVCreateTbReq(pStmt->pCreateTblReq);
|
||||||
taosMemoryFreeClear(pStmt->pCreateTblReq);
|
taosMemoryFreeClear(pStmt->pCreateTblReq);
|
||||||
|
@ -1527,7 +1527,7 @@ static int32_t checkTableClauseFirstToken(SInsertParseContext* pCxt, SVnodeModif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t setStmtInfo(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt) {
|
static int32_t setStmtInfo(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt) {
|
||||||
SParsedDataColInfo* tags = taosMemoryMalloc(sizeof(pCxt->tags));
|
SBoundColInfo* tags = taosMemoryMalloc(sizeof(pCxt->tags));
|
||||||
if (NULL == tags) {
|
if (NULL == tags) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
@ -1937,6 +1937,6 @@ int32_t parseInsertSql(SParseContext* pCxt, SQuery** pQuery, SCatalogReq* pCatal
|
||||||
QUERY_EXEC_STAGE_SCHEDULE == (*pQuery)->execStage) {
|
QUERY_EXEC_STAGE_SCHEDULE == (*pQuery)->execStage) {
|
||||||
code = setRefreshMate(*pQuery);
|
code = setRefreshMate(*pQuery);
|
||||||
}
|
}
|
||||||
destroyBoundColInfo(&context.tags);
|
insDestroyBoundColInfo(&context.tags);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,179 +22,6 @@
|
||||||
#include "tRealloc.h"
|
#include "tRealloc.h"
|
||||||
#include "tdatablock.h"
|
#include "tdatablock.h"
|
||||||
|
|
||||||
typedef struct SBlockKeyTuple {
|
|
||||||
TSKEY skey;
|
|
||||||
void* payloadAddr;
|
|
||||||
int16_t index;
|
|
||||||
} SBlockKeyTuple;
|
|
||||||
|
|
||||||
typedef struct SBlockKeyInfo {
|
|
||||||
int32_t maxBytesAlloc;
|
|
||||||
SBlockKeyTuple* pKeyTuple;
|
|
||||||
} SBlockKeyInfo;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int32_t index;
|
|
||||||
SArray* rowArray; // array of merged rows(mem allocated by tRealloc/free by tFree)
|
|
||||||
STSchema* pSchema;
|
|
||||||
int64_t tbUid; // suid for child table, uid for normal table
|
|
||||||
} SBlockRowMerger;
|
|
||||||
|
|
||||||
static FORCE_INLINE void tdResetSBlockRowMerger(SBlockRowMerger* pMerger) {
|
|
||||||
if (pMerger) {
|
|
||||||
pMerger->index = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tdFreeSBlockRowMerger(SBlockRowMerger* pMerger) {
|
|
||||||
if (pMerger) {
|
|
||||||
int32_t size = taosArrayGetSize(pMerger->rowArray);
|
|
||||||
for (int32_t i = 0; i < size; ++i) {
|
|
||||||
tFree(*(void**)taosArrayGet(pMerger->rowArray, i));
|
|
||||||
}
|
|
||||||
taosArrayDestroy(pMerger->rowArray);
|
|
||||||
|
|
||||||
taosMemoryFreeClear(pMerger->pSchema);
|
|
||||||
taosMemoryFree(pMerger);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t rowDataCompar(const void* lhs, const void* rhs) {
|
|
||||||
TSKEY left = *(TSKEY*)lhs;
|
|
||||||
TSKEY right = *(TSKEY*)rhs;
|
|
||||||
if (left == right) {
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
return left > right ? 1 : -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t rowDataComparStable(const void* lhs, const void* rhs) {
|
|
||||||
TSKEY left = *(TSKEY*)lhs;
|
|
||||||
TSKEY right = *(TSKEY*)rhs;
|
|
||||||
if (left == right) {
|
|
||||||
return ((SBlockKeyTuple*)lhs)->index - ((SBlockKeyTuple*)rhs)->index;
|
|
||||||
} else {
|
|
||||||
return left > right ? 1 : -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t insGetExtendedRowSize(STableDataBlocks* pBlock) {
|
|
||||||
STableComInfo* pTableInfo = &pBlock->pTableMeta->tableInfo;
|
|
||||||
ASSERT(pBlock->rowSize == pTableInfo->rowSize);
|
|
||||||
return pBlock->rowSize + TD_ROW_HEAD_LEN - sizeof(TSKEY) + pBlock->boundColumnInfo.extendedVarLen +
|
|
||||||
(int32_t)TD_BITMAP_BYTES(pTableInfo->numOfColumns - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void insGetSTSRowAppendInfo(uint8_t rowType, SParsedDataColInfo* spd, col_id_t idx, int32_t* toffset,
|
|
||||||
col_id_t* colIdx) {
|
|
||||||
col_id_t schemaIdx = 0;
|
|
||||||
if (IS_DATA_COL_ORDERED(spd)) {
|
|
||||||
schemaIdx = spd->boundColumns[idx];
|
|
||||||
if (TD_IS_TP_ROW_T(rowType)) {
|
|
||||||
*toffset = (spd->cols + schemaIdx)->toffset; // the offset of firstPart
|
|
||||||
*colIdx = schemaIdx;
|
|
||||||
} else {
|
|
||||||
*toffset = idx * sizeof(SKvRowIdx); // the offset of SKvRowIdx
|
|
||||||
*colIdx = idx;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ASSERT(idx == (spd->colIdxInfo + idx)->boundIdx);
|
|
||||||
schemaIdx = (spd->colIdxInfo + idx)->schemaColIdx;
|
|
||||||
if (TD_IS_TP_ROW_T(rowType)) {
|
|
||||||
*toffset = (spd->cols + schemaIdx)->toffset;
|
|
||||||
*colIdx = schemaIdx;
|
|
||||||
} else {
|
|
||||||
*toffset = ((spd->colIdxInfo + idx)->finalIdx) * sizeof(SKvRowIdx);
|
|
||||||
*colIdx = (spd->colIdxInfo + idx)->finalIdx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t insSetBlockInfo(SSubmitBlk* pBlocks, STableDataBlocks* dataBuf, int32_t numOfRows, SMsgBuf* pMsg) {
|
|
||||||
pBlocks->suid = (TSDB_NORMAL_TABLE == dataBuf->pTableMeta->tableType ? 0 : dataBuf->pTableMeta->suid);
|
|
||||||
pBlocks->uid = dataBuf->pTableMeta->uid;
|
|
||||||
pBlocks->sversion = dataBuf->pTableMeta->sversion;
|
|
||||||
pBlocks->schemaLen = dataBuf->createTbReqLen;
|
|
||||||
|
|
||||||
if (pBlocks->numOfRows + numOfRows >= INT32_MAX) {
|
|
||||||
return buildInvalidOperationMsg(pMsg, "too many rows in sql, total number of rows should be less than INT32_MAX");
|
|
||||||
}
|
|
||||||
pBlocks->numOfRows += numOfRows;
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
void insSetBoundColumnInfo(SParsedDataColInfo* pColList, SSchema* pSchema, col_id_t numOfCols) {
|
|
||||||
pColList->numOfCols = numOfCols;
|
|
||||||
pColList->numOfBound = numOfCols;
|
|
||||||
pColList->orderStatus = ORDER_STATUS_ORDERED; // default is ORDERED for non-bound mode
|
|
||||||
pColList->boundColumns = taosMemoryCalloc(pColList->numOfCols, sizeof(col_id_t));
|
|
||||||
pColList->cols = taosMemoryCalloc(pColList->numOfCols, sizeof(SBoundColumn));
|
|
||||||
pColList->colIdxInfo = NULL;
|
|
||||||
pColList->flen = 0;
|
|
||||||
pColList->allNullLen = 0;
|
|
||||||
|
|
||||||
int32_t nVar = 0;
|
|
||||||
for (int32_t i = 0; i < pColList->numOfCols; ++i) {
|
|
||||||
uint8_t type = pSchema[i].type;
|
|
||||||
if (i > 0) {
|
|
||||||
pColList->cols[i].offset = pColList->cols[i - 1].offset + pSchema[i - 1].bytes;
|
|
||||||
pColList->cols[i].toffset = pColList->flen;
|
|
||||||
pColList->flen += TYPE_BYTES[type];
|
|
||||||
}
|
|
||||||
switch (type) {
|
|
||||||
case TSDB_DATA_TYPE_BINARY:
|
|
||||||
pColList->allNullLen += (VARSTR_HEADER_SIZE + CHAR_BYTES);
|
|
||||||
++nVar;
|
|
||||||
break;
|
|
||||||
case TSDB_DATA_TYPE_NCHAR:
|
|
||||||
pColList->allNullLen += (VARSTR_HEADER_SIZE + TSDB_NCHAR_SIZE);
|
|
||||||
++nVar;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
pColList->boundColumns[i] = i;
|
|
||||||
}
|
|
||||||
pColList->allNullLen += pColList->flen;
|
|
||||||
pColList->boundNullLen = pColList->allNullLen; // default set allNullLen
|
|
||||||
pColList->extendedVarLen = (uint16_t)(nVar * sizeof(VarDataOffsetT));
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t insSchemaIdxCompar(const void* lhs, const void* rhs) {
|
|
||||||
uint16_t left = *(uint16_t*)lhs;
|
|
||||||
uint16_t right = *(uint16_t*)rhs;
|
|
||||||
|
|
||||||
if (left == right) {
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
return left > right ? 1 : -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t insBoundIdxCompar(const void* lhs, const void* rhs) {
|
|
||||||
uint16_t left = *(uint16_t*)POINTER_SHIFT(lhs, sizeof(uint16_t));
|
|
||||||
uint16_t right = *(uint16_t*)POINTER_SHIFT(rhs, sizeof(uint16_t));
|
|
||||||
|
|
||||||
if (left == right) {
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
return left > right ? 1 : -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void destroyBoundColumnInfo(void* pBoundInfo) {
|
|
||||||
if (NULL == pBoundInfo) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SParsedDataColInfo* pColList = (SParsedDataColInfo*)pBoundInfo;
|
|
||||||
|
|
||||||
taosMemoryFreeClear(pColList->boundColumns);
|
|
||||||
taosMemoryFreeClear(pColList->cols);
|
|
||||||
taosMemoryFreeClear(pColList->colIdxInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
void qDestroyBoundColInfo(void* pInfo) {
|
void qDestroyBoundColInfo(void* pInfo) {
|
||||||
if (NULL == pInfo) {
|
if (NULL == pInfo) {
|
||||||
return;
|
return;
|
||||||
|
@ -205,548 +32,6 @@ void qDestroyBoundColInfo(void* pInfo) {
|
||||||
taosMemoryFreeClear(pBoundInfo->pColIndex);
|
taosMemoryFreeClear(pBoundInfo->pColIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createTableDataBlock(size_t defaultSize, int32_t rowSize, int32_t startOffset, STableMeta* pTableMeta,
|
|
||||||
STableDataBlocks** dataBlocks) {
|
|
||||||
STableDataBlocks* dataBuf = (STableDataBlocks*)taosMemoryCalloc(1, sizeof(STableDataBlocks));
|
|
||||||
if (dataBuf == NULL) {
|
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
dataBuf->nAllocSize = (uint32_t)defaultSize;
|
|
||||||
dataBuf->headerSize = startOffset;
|
|
||||||
|
|
||||||
// the header size will always be the startOffset value, reserved for the subumit block header
|
|
||||||
if (dataBuf->nAllocSize <= dataBuf->headerSize) {
|
|
||||||
dataBuf->nAllocSize = dataBuf->headerSize * 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
dataBuf->pData = taosMemoryMalloc(dataBuf->nAllocSize);
|
|
||||||
if (dataBuf->pData == NULL) {
|
|
||||||
taosMemoryFreeClear(dataBuf);
|
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
memset(dataBuf->pData, 0, sizeof(SSubmitBlk));
|
|
||||||
|
|
||||||
dataBuf->pTableMeta = tableMetaDup(pTableMeta);
|
|
||||||
|
|
||||||
SParsedDataColInfo* pColInfo = &dataBuf->boundColumnInfo;
|
|
||||||
SSchema* pSchema = getTableColumnSchema(dataBuf->pTableMeta);
|
|
||||||
insSetBoundColumnInfo(pColInfo, pSchema, dataBuf->pTableMeta->tableInfo.numOfColumns);
|
|
||||||
|
|
||||||
dataBuf->ordered = true;
|
|
||||||
dataBuf->prevTS = INT64_MIN;
|
|
||||||
dataBuf->rowSize = rowSize;
|
|
||||||
dataBuf->size = startOffset;
|
|
||||||
dataBuf->vgId = dataBuf->pTableMeta->vgId;
|
|
||||||
|
|
||||||
assert(defaultSize > 0 && pTableMeta != NULL && dataBuf->pTableMeta != NULL);
|
|
||||||
|
|
||||||
*dataBlocks = dataBuf;
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t insBuildCreateTbMsg(STableDataBlocks* pBlocks, SVCreateTbReq* pCreateTbReq) {
|
|
||||||
SEncoder coder = {0};
|
|
||||||
char* pBuf;
|
|
||||||
int32_t len;
|
|
||||||
|
|
||||||
int32_t ret = 0;
|
|
||||||
tEncodeSize(tEncodeSVCreateTbReq, pCreateTbReq, len, ret);
|
|
||||||
if (pBlocks->nAllocSize - pBlocks->size < len) {
|
|
||||||
pBlocks->nAllocSize += len + pBlocks->rowSize;
|
|
||||||
char* pTmp = taosMemoryRealloc(pBlocks->pData, pBlocks->nAllocSize);
|
|
||||||
if (pTmp != NULL) {
|
|
||||||
pBlocks->pData = pTmp;
|
|
||||||
memset(pBlocks->pData + pBlocks->size, 0, pBlocks->nAllocSize - pBlocks->size);
|
|
||||||
} else {
|
|
||||||
pBlocks->nAllocSize -= len + pBlocks->rowSize;
|
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pBuf = pBlocks->pData + pBlocks->size;
|
|
||||||
|
|
||||||
tEncoderInit(&coder, pBuf, len);
|
|
||||||
int32_t code = tEncodeSVCreateTbReq(&coder, pCreateTbReq);
|
|
||||||
tEncoderClear(&coder);
|
|
||||||
pBlocks->size += len;
|
|
||||||
pBlocks->createTbReqLen = len;
|
|
||||||
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
void insDestroyDataBlock(STableDataBlocks* pDataBlock) {
|
|
||||||
if (pDataBlock == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
taosMemoryFreeClear(pDataBlock->pData);
|
|
||||||
taosMemoryFreeClear(pDataBlock->pTableMeta);
|
|
||||||
destroyBoundColumnInfo(&pDataBlock->boundColumnInfo);
|
|
||||||
taosMemoryFreeClear(pDataBlock);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t insGetDataBlockFromList(SHashObj* pHashList, void* id, int32_t idLen, int32_t size, int32_t startOffset,
|
|
||||||
int32_t rowSize, STableMeta* pTableMeta, STableDataBlocks** dataBlocks,
|
|
||||||
SArray* pBlockList, SVCreateTbReq* pCreateTbReq) {
|
|
||||||
*dataBlocks = NULL;
|
|
||||||
STableDataBlocks** t1 = (STableDataBlocks**)taosHashGet(pHashList, (const char*)id, idLen);
|
|
||||||
if (t1 != NULL) {
|
|
||||||
*dataBlocks = *t1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*dataBlocks == NULL) {
|
|
||||||
int32_t ret = createTableDataBlock((size_t)size, rowSize, startOffset, pTableMeta, dataBlocks);
|
|
||||||
if (ret != TSDB_CODE_SUCCESS) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (NULL != pCreateTbReq && NULL != pCreateTbReq->ctb.pTag) {
|
|
||||||
ret = insBuildCreateTbMsg(*dataBlocks, pCreateTbReq);
|
|
||||||
if (ret != TSDB_CODE_SUCCESS) {
|
|
||||||
insDestroyDataBlock(*dataBlocks);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// converting to 'const char*' is to handle coverity scan errors
|
|
||||||
taosHashPut(pHashList, (const char*)id, idLen, (const char*)dataBlocks, POINTER_BYTES);
|
|
||||||
if (pBlockList) {
|
|
||||||
taosArrayPush(pBlockList, dataBlocks);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
void insDestroyBlockArrayList(SArray* pDataBlockList) {
|
|
||||||
if (pDataBlockList == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t size = taosArrayGetSize(pDataBlockList);
|
|
||||||
for (int32_t i = 0; i < size; i++) {
|
|
||||||
void* p = taosArrayGetP(pDataBlockList, i);
|
|
||||||
insDestroyDataBlock(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
taosArrayDestroy(pDataBlockList);
|
|
||||||
}
|
|
||||||
|
|
||||||
void insDestroyBlockHashmap(SHashObj* pDataBlockHash) {
|
|
||||||
if (pDataBlockHash == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void** p1 = taosHashIterate(pDataBlockHash, NULL);
|
|
||||||
while (p1) {
|
|
||||||
SBoundColInfo* pBlocks = *p1;
|
|
||||||
destroyBoundColInfo(pBlocks);
|
|
||||||
|
|
||||||
p1 = taosHashIterate(pDataBlockHash, p1);
|
|
||||||
}
|
|
||||||
|
|
||||||
taosHashCleanup(pDataBlockHash);
|
|
||||||
}
|
|
||||||
|
|
||||||
// data block is disordered, sort it in ascending order
|
|
||||||
static int sortRemoveDataBlockDupRows(STableDataBlocks* dataBuf, SBlockKeyInfo* pBlkKeyInfo) {
|
|
||||||
SSubmitBlk* pBlocks = (SSubmitBlk*)dataBuf->pData;
|
|
||||||
int16_t nRows = pBlocks->numOfRows;
|
|
||||||
|
|
||||||
// size is less than the total size, since duplicated rows may be removed yet.
|
|
||||||
|
|
||||||
// allocate memory
|
|
||||||
size_t nAlloc = nRows * sizeof(SBlockKeyTuple);
|
|
||||||
if (pBlkKeyInfo->pKeyTuple == NULL || pBlkKeyInfo->maxBytesAlloc < nAlloc) {
|
|
||||||
char* tmp = taosMemoryRealloc(pBlkKeyInfo->pKeyTuple, nAlloc);
|
|
||||||
if (tmp == NULL) {
|
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
pBlkKeyInfo->pKeyTuple = (SBlockKeyTuple*)tmp;
|
|
||||||
pBlkKeyInfo->maxBytesAlloc = (int32_t)nAlloc;
|
|
||||||
}
|
|
||||||
memset(pBlkKeyInfo->pKeyTuple, 0, nAlloc);
|
|
||||||
|
|
||||||
int32_t extendedRowSize = insGetExtendedRowSize(dataBuf);
|
|
||||||
SBlockKeyTuple* pBlkKeyTuple = pBlkKeyInfo->pKeyTuple;
|
|
||||||
char* pBlockData = pBlocks->data + pBlocks->schemaLen;
|
|
||||||
int n = 0;
|
|
||||||
while (n < nRows) {
|
|
||||||
pBlkKeyTuple->skey = TD_ROW_KEY((STSRow*)pBlockData);
|
|
||||||
pBlkKeyTuple->payloadAddr = pBlockData;
|
|
||||||
pBlkKeyTuple->index = n;
|
|
||||||
|
|
||||||
// next loop
|
|
||||||
pBlockData += extendedRowSize;
|
|
||||||
++pBlkKeyTuple;
|
|
||||||
++n;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!dataBuf->ordered) {
|
|
||||||
pBlkKeyTuple = pBlkKeyInfo->pKeyTuple;
|
|
||||||
|
|
||||||
// todo. qsort is unstable, if timestamp is same, should get the last one
|
|
||||||
taosSort(pBlkKeyTuple, nRows, sizeof(SBlockKeyTuple), rowDataComparStable);
|
|
||||||
|
|
||||||
pBlkKeyTuple = pBlkKeyInfo->pKeyTuple;
|
|
||||||
int32_t i = 0;
|
|
||||||
int32_t j = 1;
|
|
||||||
while (j < nRows) {
|
|
||||||
TSKEY ti = (pBlkKeyTuple + i)->skey;
|
|
||||||
TSKEY tj = (pBlkKeyTuple + j)->skey;
|
|
||||||
|
|
||||||
if (ti == tj) {
|
|
||||||
++j;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t nextPos = (++i);
|
|
||||||
if (nextPos != j) {
|
|
||||||
memmove(pBlkKeyTuple + nextPos, pBlkKeyTuple + j, sizeof(SBlockKeyTuple));
|
|
||||||
}
|
|
||||||
++j;
|
|
||||||
}
|
|
||||||
|
|
||||||
dataBuf->ordered = true;
|
|
||||||
pBlocks->numOfRows = i + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
dataBuf->size = sizeof(SSubmitBlk) + pBlocks->numOfRows * extendedRowSize;
|
|
||||||
dataBuf->prevTS = INT64_MIN;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void* tdGetCurRowFromBlockMerger(SBlockRowMerger* pBlkRowMerger) {
|
|
||||||
if (pBlkRowMerger && (pBlkRowMerger->index >= 0)) {
|
|
||||||
ASSERT(pBlkRowMerger->index < taosArrayGetSize(pBlkRowMerger->rowArray));
|
|
||||||
return *(void**)taosArrayGet(pBlkRowMerger->rowArray, pBlkRowMerger->index);
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t tdBlockRowMerge(STableMeta* pTableMeta, SBlockKeyTuple* pEndKeyTp, int32_t nDupRows,
|
|
||||||
SBlockRowMerger** pBlkRowMerger, int32_t rowSize) {
|
|
||||||
ASSERT(nDupRows > 1);
|
|
||||||
SBlockKeyTuple* pStartKeyTp = pEndKeyTp - (nDupRows - 1);
|
|
||||||
ASSERT(pStartKeyTp->skey == pEndKeyTp->skey);
|
|
||||||
|
|
||||||
// TODO: optimization if end row is all normal
|
|
||||||
#if 0
|
|
||||||
STSRow* pEndRow = (STSRow*)pEndKeyTp->payloadAddr;
|
|
||||||
if(isNormal(pEndRow)) { // set the end row if it is normal and return directly
|
|
||||||
pStartKeyTp->payloadAddr = pEndKeyTp->payloadAddr;
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!(*pBlkRowMerger)) {
|
|
||||||
(*pBlkRowMerger) = taosMemoryCalloc(1, sizeof(**pBlkRowMerger));
|
|
||||||
if (!(*pBlkRowMerger)) {
|
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
return TSDB_CODE_FAILED;
|
|
||||||
}
|
|
||||||
(*pBlkRowMerger)->index = -1;
|
|
||||||
if (!(*pBlkRowMerger)->rowArray) {
|
|
||||||
(*pBlkRowMerger)->rowArray = taosArrayInit(1, sizeof(void*));
|
|
||||||
if (!(*pBlkRowMerger)->rowArray) {
|
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
return TSDB_CODE_FAILED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((*pBlkRowMerger)->pSchema) {
|
|
||||||
if ((*pBlkRowMerger)->pSchema->version != pTableMeta->sversion) {
|
|
||||||
taosMemoryFreeClear((*pBlkRowMerger)->pSchema);
|
|
||||||
} else {
|
|
||||||
if ((*pBlkRowMerger)->tbUid != (pTableMeta->suid > 0 ? pTableMeta->suid : pTableMeta->uid)) {
|
|
||||||
taosMemoryFreeClear((*pBlkRowMerger)->pSchema);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(*pBlkRowMerger)->pSchema) {
|
|
||||||
(*pBlkRowMerger)->pSchema =
|
|
||||||
tBuildTSchema(pTableMeta->schema, pTableMeta->tableInfo.numOfColumns, pTableMeta->sversion);
|
|
||||||
|
|
||||||
if (!(*pBlkRowMerger)->pSchema) {
|
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
return TSDB_CODE_FAILED;
|
|
||||||
}
|
|
||||||
(*pBlkRowMerger)->tbUid = pTableMeta->suid > 0 ? pTableMeta->suid : pTableMeta->uid;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* pDestRow = NULL;
|
|
||||||
++((*pBlkRowMerger)->index);
|
|
||||||
if ((*pBlkRowMerger)->index < taosArrayGetSize((*pBlkRowMerger)->rowArray)) {
|
|
||||||
void** pAlloc = (void**)taosArrayGet((*pBlkRowMerger)->rowArray, (*pBlkRowMerger)->index);
|
|
||||||
if (tRealloc((uint8_t**)pAlloc, rowSize) != 0) {
|
|
||||||
return TSDB_CODE_FAILED;
|
|
||||||
}
|
|
||||||
pDestRow = *pAlloc;
|
|
||||||
} else {
|
|
||||||
if (tRealloc((uint8_t**)&pDestRow, rowSize) != 0) {
|
|
||||||
return TSDB_CODE_FAILED;
|
|
||||||
}
|
|
||||||
taosArrayPush((*pBlkRowMerger)->rowArray, &pDestRow);
|
|
||||||
}
|
|
||||||
|
|
||||||
// merge rows to pDestRow
|
|
||||||
STSchema* pSchema = (*pBlkRowMerger)->pSchema;
|
|
||||||
SArray* pArray = taosArrayInit(pSchema->numOfCols, sizeof(SColVal));
|
|
||||||
for (int32_t i = 0; i < pSchema->numOfCols; ++i) {
|
|
||||||
SColVal colVal = {0};
|
|
||||||
for (int32_t j = 0; j < nDupRows; ++j) {
|
|
||||||
tTSRowGetVal((pEndKeyTp - j)->payloadAddr, pSchema, i, &colVal);
|
|
||||||
if (!COL_VAL_IS_NONE(&colVal)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
taosArrayPush(pArray, &colVal);
|
|
||||||
}
|
|
||||||
if (tdSTSRowNew(pArray, pSchema, (STSRow**)&pDestRow) < 0) {
|
|
||||||
taosArrayDestroy(pArray);
|
|
||||||
return TSDB_CODE_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
taosArrayDestroy(pArray);
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
// data block is disordered, sort it in ascending order, and merge dup rows if exists
|
|
||||||
static int sortMergeDataBlockDupRows(STableDataBlocks* dataBuf, SBlockKeyInfo* pBlkKeyInfo,
|
|
||||||
SBlockRowMerger** ppBlkRowMerger) {
|
|
||||||
SSubmitBlk* pBlocks = (SSubmitBlk*)dataBuf->pData;
|
|
||||||
STableMeta* pTableMeta = dataBuf->pTableMeta;
|
|
||||||
int32_t nRows = pBlocks->numOfRows;
|
|
||||||
|
|
||||||
// size is less than the total size, since duplicated rows may be removed.
|
|
||||||
|
|
||||||
// allocate memory
|
|
||||||
size_t nAlloc = nRows * sizeof(SBlockKeyTuple);
|
|
||||||
if (pBlkKeyInfo->pKeyTuple == NULL || pBlkKeyInfo->maxBytesAlloc < nAlloc) {
|
|
||||||
char* tmp = taosMemoryRealloc(pBlkKeyInfo->pKeyTuple, nAlloc);
|
|
||||||
if (tmp == NULL) {
|
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
pBlkKeyInfo->pKeyTuple = (SBlockKeyTuple*)tmp;
|
|
||||||
pBlkKeyInfo->maxBytesAlloc = (int32_t)nAlloc;
|
|
||||||
}
|
|
||||||
memset(pBlkKeyInfo->pKeyTuple, 0, nAlloc);
|
|
||||||
|
|
||||||
tdResetSBlockRowMerger(*ppBlkRowMerger);
|
|
||||||
|
|
||||||
int32_t extendedRowSize = insGetExtendedRowSize(dataBuf);
|
|
||||||
SBlockKeyTuple* pBlkKeyTuple = pBlkKeyInfo->pKeyTuple;
|
|
||||||
char* pBlockData = pBlocks->data + pBlocks->schemaLen;
|
|
||||||
int32_t n = 0;
|
|
||||||
while (n < nRows) {
|
|
||||||
pBlkKeyTuple->skey = TD_ROW_KEY((STSRow*)pBlockData);
|
|
||||||
pBlkKeyTuple->payloadAddr = pBlockData;
|
|
||||||
pBlkKeyTuple->index = n;
|
|
||||||
|
|
||||||
// next loop
|
|
||||||
pBlockData += extendedRowSize;
|
|
||||||
++pBlkKeyTuple;
|
|
||||||
++n;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!dataBuf->ordered) {
|
|
||||||
pBlkKeyTuple = pBlkKeyInfo->pKeyTuple;
|
|
||||||
|
|
||||||
taosSort(pBlkKeyTuple, nRows, sizeof(SBlockKeyTuple), rowDataComparStable);
|
|
||||||
|
|
||||||
pBlkKeyTuple = pBlkKeyInfo->pKeyTuple;
|
|
||||||
bool hasDup = false;
|
|
||||||
int32_t nextPos = 0;
|
|
||||||
int32_t i = 0;
|
|
||||||
int32_t j = 1;
|
|
||||||
|
|
||||||
while (j < nRows) {
|
|
||||||
TSKEY ti = (pBlkKeyTuple + i)->skey;
|
|
||||||
TSKEY tj = (pBlkKeyTuple + j)->skey;
|
|
||||||
|
|
||||||
if (ti == tj) {
|
|
||||||
++j;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((j - i) > 1) {
|
|
||||||
if (tdBlockRowMerge(pTableMeta, (pBlkKeyTuple + j - 1), j - i, ppBlkRowMerger, extendedRowSize) < 0) {
|
|
||||||
return TSDB_CODE_FAILED;
|
|
||||||
}
|
|
||||||
(pBlkKeyTuple + nextPos)->payloadAddr = tdGetCurRowFromBlockMerger(*ppBlkRowMerger);
|
|
||||||
if (!hasDup) {
|
|
||||||
hasDup = true;
|
|
||||||
}
|
|
||||||
i = j;
|
|
||||||
} else {
|
|
||||||
if (hasDup) {
|
|
||||||
memmove(pBlkKeyTuple + nextPos, pBlkKeyTuple + i, sizeof(SBlockKeyTuple));
|
|
||||||
}
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
|
|
||||||
++nextPos;
|
|
||||||
++j;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((j - i) > 1) {
|
|
||||||
ASSERT((pBlkKeyTuple + i)->skey == (pBlkKeyTuple + j - 1)->skey);
|
|
||||||
if (tdBlockRowMerge(pTableMeta, (pBlkKeyTuple + j - 1), j - i, ppBlkRowMerger, extendedRowSize) < 0) {
|
|
||||||
return TSDB_CODE_FAILED;
|
|
||||||
}
|
|
||||||
(pBlkKeyTuple + nextPos)->payloadAddr = tdGetCurRowFromBlockMerger(*ppBlkRowMerger);
|
|
||||||
} else if (hasDup) {
|
|
||||||
memmove(pBlkKeyTuple + nextPos, pBlkKeyTuple + i, sizeof(SBlockKeyTuple));
|
|
||||||
}
|
|
||||||
|
|
||||||
dataBuf->ordered = true;
|
|
||||||
pBlocks->numOfRows = nextPos + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
dataBuf->size = sizeof(SSubmitBlk) + pBlocks->numOfRows * extendedRowSize;
|
|
||||||
dataBuf->prevTS = INT64_MIN;
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Erase the empty space reserved for binary data
|
|
||||||
static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, SBlockKeyTuple* blkKeyTuple) {
|
|
||||||
// TODO: optimize this function, handle the case while binary is not presented
|
|
||||||
int32_t nonDataLen = sizeof(SSubmitBlk) + pTableDataBlock->createTbReqLen;
|
|
||||||
SSubmitBlk* pBlock = pDataBlock;
|
|
||||||
memcpy(pDataBlock, pTableDataBlock->pData, nonDataLen);
|
|
||||||
pDataBlock = (char*)pDataBlock + nonDataLen;
|
|
||||||
|
|
||||||
pBlock->schemaLen = pTableDataBlock->createTbReqLen;
|
|
||||||
pBlock->dataLen = 0;
|
|
||||||
|
|
||||||
int32_t numOfRows = pBlock->numOfRows;
|
|
||||||
for (int32_t i = 0; i < numOfRows; ++i) {
|
|
||||||
void* payload = (blkKeyTuple + i)->payloadAddr;
|
|
||||||
TDRowLenT rowTLen = TD_ROW_LEN((STSRow*)payload);
|
|
||||||
memcpy(pDataBlock, payload, rowTLen);
|
|
||||||
pDataBlock = POINTER_SHIFT(pDataBlock, rowTLen);
|
|
||||||
pBlock->dataLen += rowTLen;
|
|
||||||
}
|
|
||||||
|
|
||||||
return pBlock->dataLen + pBlock->schemaLen;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t insMergeTableDataBlocks(SHashObj* pHashObj, SArray** pVgDataBlocks) {
|
|
||||||
const int INSERT_HEAD_SIZE = sizeof(SSubmitReq);
|
|
||||||
int code = 0;
|
|
||||||
SHashObj* pVnodeDataBlockHashList = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, false);
|
|
||||||
SArray* pVnodeDataBlockList = taosArrayInit(8, POINTER_BYTES);
|
|
||||||
|
|
||||||
STableDataBlocks** p = taosHashIterate(pHashObj, NULL);
|
|
||||||
STableDataBlocks* pOneTableBlock = *p;
|
|
||||||
SBlockKeyInfo blkKeyInfo = {0}; // share by pOneTableBlock
|
|
||||||
SBlockRowMerger* pBlkRowMerger = NULL;
|
|
||||||
|
|
||||||
while (pOneTableBlock) {
|
|
||||||
SSubmitBlk* pBlocks = (SSubmitBlk*)pOneTableBlock->pData;
|
|
||||||
if (pBlocks->numOfRows > 0) {
|
|
||||||
STableDataBlocks* dataBuf = NULL;
|
|
||||||
pOneTableBlock->pTableMeta->vgId = pOneTableBlock->vgId; // for schemaless, restore origin vgId
|
|
||||||
int32_t ret = insGetDataBlockFromList(pVnodeDataBlockHashList, &pOneTableBlock->vgId,
|
|
||||||
sizeof(pOneTableBlock->vgId), TSDB_PAYLOAD_SIZE, INSERT_HEAD_SIZE, 0,
|
|
||||||
pOneTableBlock->pTableMeta, &dataBuf, pVnodeDataBlockList, NULL);
|
|
||||||
if (ret != TSDB_CODE_SUCCESS) {
|
|
||||||
tdFreeSBlockRowMerger(pBlkRowMerger);
|
|
||||||
taosHashCleanup(pVnodeDataBlockHashList);
|
|
||||||
insDestroyBlockArrayList(pVnodeDataBlockList);
|
|
||||||
taosMemoryFreeClear(blkKeyInfo.pKeyTuple);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
ASSERT(pOneTableBlock->pTableMeta->tableInfo.rowSize > 0);
|
|
||||||
// the maximum expanded size in byte when a row-wise data is converted to SDataRow format
|
|
||||||
int64_t destSize = dataBuf->size + pOneTableBlock->size +
|
|
||||||
sizeof(STColumn) * getNumOfColumns(pOneTableBlock->pTableMeta) +
|
|
||||||
pOneTableBlock->createTbReqLen;
|
|
||||||
|
|
||||||
if (dataBuf->nAllocSize < destSize) {
|
|
||||||
dataBuf->nAllocSize = (uint32_t)(destSize * 1.5);
|
|
||||||
char* tmp = taosMemoryRealloc(dataBuf->pData, dataBuf->nAllocSize);
|
|
||||||
if (tmp != NULL) {
|
|
||||||
dataBuf->pData = tmp;
|
|
||||||
} else { // failed to allocate memory, free already allocated memory and return error code
|
|
||||||
tdFreeSBlockRowMerger(pBlkRowMerger);
|
|
||||||
taosHashCleanup(pVnodeDataBlockHashList);
|
|
||||||
insDestroyBlockArrayList(pVnodeDataBlockList);
|
|
||||||
taosMemoryFreeClear(dataBuf->pData);
|
|
||||||
taosMemoryFreeClear(blkKeyInfo.pKeyTuple);
|
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((code = sortMergeDataBlockDupRows(pOneTableBlock, &blkKeyInfo, &pBlkRowMerger)) != 0) {
|
|
||||||
tdFreeSBlockRowMerger(pBlkRowMerger);
|
|
||||||
taosHashCleanup(pVnodeDataBlockHashList);
|
|
||||||
insDestroyBlockArrayList(pVnodeDataBlockList);
|
|
||||||
taosMemoryFreeClear(dataBuf->pData);
|
|
||||||
taosMemoryFreeClear(blkKeyInfo.pKeyTuple);
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
ASSERT(blkKeyInfo.pKeyTuple != NULL && pBlocks->numOfRows > 0);
|
|
||||||
|
|
||||||
// erase the empty space reserved for binary data
|
|
||||||
int32_t finalLen = trimDataBlock(dataBuf->pData + dataBuf->size, pOneTableBlock, blkKeyInfo.pKeyTuple);
|
|
||||||
|
|
||||||
dataBuf->size += (finalLen + sizeof(SSubmitBlk));
|
|
||||||
assert(dataBuf->size <= dataBuf->nAllocSize);
|
|
||||||
dataBuf->numOfTables += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
p = taosHashIterate(pHashObj, p);
|
|
||||||
if (p == NULL) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
pOneTableBlock = *p;
|
|
||||||
}
|
|
||||||
|
|
||||||
// free the table data blocks;
|
|
||||||
tdFreeSBlockRowMerger(pBlkRowMerger);
|
|
||||||
taosHashCleanup(pVnodeDataBlockHashList);
|
|
||||||
taosMemoryFreeClear(blkKeyInfo.pKeyTuple);
|
|
||||||
*pVgDataBlocks = pVnodeDataBlockList;
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t insAllocateMemForSize(STableDataBlocks* pDataBlock, int32_t allSize) {
|
|
||||||
size_t remain = pDataBlock->nAllocSize - pDataBlock->size;
|
|
||||||
uint32_t nAllocSizeOld = pDataBlock->nAllocSize;
|
|
||||||
|
|
||||||
// expand the allocated size
|
|
||||||
if (remain < allSize) {
|
|
||||||
pDataBlock->nAllocSize = (pDataBlock->size + allSize) * 1.5;
|
|
||||||
|
|
||||||
char* tmp = taosMemoryRealloc(pDataBlock->pData, (size_t)pDataBlock->nAllocSize);
|
|
||||||
if (tmp != NULL) {
|
|
||||||
pDataBlock->pData = tmp;
|
|
||||||
memset(pDataBlock->pData + pDataBlock->size, 0, pDataBlock->nAllocSize - pDataBlock->size);
|
|
||||||
} else {
|
|
||||||
// do nothing, if allocate more memory failed
|
|
||||||
pDataBlock->nAllocSize = nAllocSizeOld;
|
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t insInitRowBuilder(SRowBuilder* pBuilder, int16_t schemaVer, SParsedDataColInfo* pColInfo) {
|
|
||||||
ASSERT(pColInfo->numOfCols > 0 && (pColInfo->numOfBound <= pColInfo->numOfCols));
|
|
||||||
tdSRowInit(pBuilder, schemaVer);
|
|
||||||
tdSRowSetExtendedInfo(pBuilder, pColInfo->numOfCols, pColInfo->numOfBound, pColInfo->flen, pColInfo->allNullLen,
|
|
||||||
pColInfo->boundNullLen);
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char* tableNameGetPosition(SToken* pToken, char target) {
|
static char* tableNameGetPosition(SToken* pToken, char target) {
|
||||||
bool inEscape = false;
|
bool inEscape = false;
|
||||||
bool inQuote = false;
|
bool inQuote = false;
|
||||||
|
@ -875,98 +160,6 @@ void insBuildCreateTbReq(SVCreateTbReq* pTbReq, const char* tname, STag* pTag, i
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t insMemRowAppend(SMsgBuf* pMsgBuf, const void* value, int32_t len, void* param) {
|
|
||||||
SMemParam* pa = (SMemParam*)param;
|
|
||||||
SRowBuilder* rb = pa->rb;
|
|
||||||
|
|
||||||
if (value == NULL) { // it is a null data
|
|
||||||
tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NULL, value, false, pa->toffset, pa->colIdx);
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TSDB_DATA_TYPE_BINARY == pa->schema->type) {
|
|
||||||
const char* rowEnd = tdRowEnd(rb->pBuf);
|
|
||||||
STR_WITH_SIZE_TO_VARSTR(rowEnd, value, len);
|
|
||||||
tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, rowEnd, false, pa->toffset, pa->colIdx);
|
|
||||||
} else if (TSDB_DATA_TYPE_NCHAR == pa->schema->type) {
|
|
||||||
// if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long'
|
|
||||||
int32_t output = 0;
|
|
||||||
const char* rowEnd = tdRowEnd(rb->pBuf);
|
|
||||||
if (!taosMbsToUcs4(value, len, (TdUcs4*)varDataVal(rowEnd), pa->schema->bytes - VARSTR_HEADER_SIZE, &output)) {
|
|
||||||
if (errno == E2BIG) {
|
|
||||||
return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pa->schema->name);
|
|
||||||
}
|
|
||||||
char buf[512] = {0};
|
|
||||||
snprintf(buf, tListLen(buf), "%s", strerror(errno));
|
|
||||||
return buildSyntaxErrMsg(pMsgBuf, buf, value);
|
|
||||||
}
|
|
||||||
varDataSetLen(rowEnd, output);
|
|
||||||
tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, rowEnd, false, pa->toffset, pa->colIdx);
|
|
||||||
} else {
|
|
||||||
tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, value, false, pa->toffset, pa->colIdx);
|
|
||||||
}
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t insCheckTimestamp(STableDataBlocks* pDataBlocks, const char* start) {
|
|
||||||
// once the data block is disordered, we do NOT keep previous timestamp any more
|
|
||||||
if (!pDataBlocks->ordered) {
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
TSKEY k = *(TSKEY*)start;
|
|
||||||
if (k <= pDataBlocks->prevTS) {
|
|
||||||
pDataBlocks->ordered = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
pDataBlocks->prevTS = k;
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void buildMsgHeader(STableDataBlocks* src, SVgDataBlocks* blocks) {
|
|
||||||
SSubmitReq* submit = (SSubmitReq*)blocks->pData;
|
|
||||||
submit->header.vgId = htonl(blocks->vg.vgId);
|
|
||||||
submit->header.contLen = htonl(blocks->size);
|
|
||||||
submit->length = submit->header.contLen;
|
|
||||||
submit->numOfBlocks = htonl(blocks->numOfTables);
|
|
||||||
SSubmitBlk* blk = (SSubmitBlk*)(submit + 1);
|
|
||||||
int32_t numOfBlocks = blocks->numOfTables;
|
|
||||||
while (numOfBlocks--) {
|
|
||||||
int32_t dataLen = blk->dataLen;
|
|
||||||
int32_t schemaLen = blk->schemaLen;
|
|
||||||
blk->uid = htobe64(blk->uid);
|
|
||||||
blk->suid = htobe64(blk->suid);
|
|
||||||
blk->sversion = htonl(blk->sversion);
|
|
||||||
blk->dataLen = htonl(blk->dataLen);
|
|
||||||
blk->schemaLen = htonl(blk->schemaLen);
|
|
||||||
blk->numOfRows = htonl(blk->numOfRows);
|
|
||||||
blk = (SSubmitBlk*)(blk->data + schemaLen + dataLen);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t insBuildOutput(SHashObj* pVgroupsHashObj, SArray* pVgDataBlocks, SArray** pDataBlocks) {
|
|
||||||
size_t numOfVg = taosArrayGetSize(pVgDataBlocks);
|
|
||||||
*pDataBlocks = taosArrayInit(numOfVg, POINTER_BYTES);
|
|
||||||
if (NULL == *pDataBlocks) {
|
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
for (size_t i = 0; i < numOfVg; ++i) {
|
|
||||||
STableDataBlocks* src = taosArrayGetP(pVgDataBlocks, i);
|
|
||||||
SVgDataBlocks* dst = taosMemoryCalloc(1, sizeof(SVgDataBlocks));
|
|
||||||
if (NULL == dst) {
|
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
taosHashGetDup(pVgroupsHashObj, (const char*)&src->vgId, sizeof(src->vgId), &dst->vg);
|
|
||||||
dst->numOfTables = src->numOfTables;
|
|
||||||
dst->size = src->size;
|
|
||||||
TSWAP(dst->pData, src->pData);
|
|
||||||
buildMsgHeader(src, dst);
|
|
||||||
taosArrayPush(*pDataBlocks, &dst);
|
|
||||||
}
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void initBoundCols(int32_t ncols, int16_t* pBoundCols) {
|
static void initBoundCols(int32_t ncols, int16_t* pBoundCols) {
|
||||||
for (int32_t i = 0; i < ncols; ++i) {
|
for (int32_t i = 0; i < ncols; ++i) {
|
||||||
pBoundCols[i] = i;
|
pBoundCols[i] = i;
|
||||||
|
@ -1010,7 +203,7 @@ void insCheckTableDataOrder(STableDataCxt* pTableCxt, TSKEY tsKey) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroyBoundColInfo(SBoundColInfo* pInfo) { taosMemoryFreeClear(pInfo->pColIndex); }
|
void insDestroyBoundColInfo(SBoundColInfo* pInfo) { taosMemoryFreeClear(pInfo->pColIndex); }
|
||||||
|
|
||||||
static int32_t createTableDataCxt(STableMeta* pTableMeta, SVCreateTbReq** pCreateTbReq, STableDataCxt** pOutput,
|
static int32_t createTableDataCxt(STableMeta* pTableMeta, SVCreateTbReq** pCreateTbReq, STableDataCxt** pOutput,
|
||||||
bool colMode) {
|
bool colMode) {
|
||||||
|
@ -1120,7 +313,7 @@ void insDestroyTableDataCxt(STableDataCxt* pTableCxt) {
|
||||||
|
|
||||||
taosMemoryFreeClear(pTableCxt->pMeta);
|
taosMemoryFreeClear(pTableCxt->pMeta);
|
||||||
tDestroyTSchema(pTableCxt->pSchema);
|
tDestroyTSchema(pTableCxt->pSchema);
|
||||||
destroyBoundColInfo(&pTableCxt->boundColsInfo);
|
insDestroyBoundColInfo(&pTableCxt->boundColsInfo);
|
||||||
taosArrayDestroyEx(pTableCxt->pValues, destroyColVal);
|
taosArrayDestroyEx(pTableCxt->pValues, destroyColVal);
|
||||||
if (pTableCxt->pData) {
|
if (pTableCxt->pData) {
|
||||||
tDestroySSubmitTbData(pTableCxt->pData, TSDB_MSG_FLG_ENCODE);
|
tDestroySSubmitTbData(pTableCxt->pData, TSDB_MSG_FLG_ENCODE);
|
||||||
|
|
|
@ -4569,8 +4569,89 @@ typedef struct SSampleAstInfo {
|
||||||
SNode* pSliding;
|
SNode* pSliding;
|
||||||
SNodeList* pPartitionByList;
|
SNodeList* pPartitionByList;
|
||||||
STableMeta* pRollupTableMeta;
|
STableMeta* pRollupTableMeta;
|
||||||
|
bool createSmaIndex;
|
||||||
} SSampleAstInfo;
|
} SSampleAstInfo;
|
||||||
|
|
||||||
|
static int32_t buildTableForSampleAst(SSampleAstInfo* pInfo, SNode** pOutput) {
|
||||||
|
SRealTableNode* pTable = (SRealTableNode*)nodesMakeNode(QUERY_NODE_REAL_TABLE);
|
||||||
|
if (NULL == pTable) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
snprintf(pTable->table.dbName, sizeof(pTable->table.dbName), "%s", pInfo->pDbName);
|
||||||
|
snprintf(pTable->table.tableName, sizeof(pTable->table.tableName), "%s", pInfo->pTableName);
|
||||||
|
TSWAP(pTable->pMeta, pInfo->pRollupTableMeta);
|
||||||
|
*pOutput = (SNode*)pTable;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t addWstartToSampleProjects(SNodeList* pProjectionList) {
|
||||||
|
SFunctionNode* pFunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION);
|
||||||
|
if (NULL == pFunc) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
strcpy(pFunc->functionName, "_wstart");
|
||||||
|
return nodesListPushFront(pProjectionList, (SNode*)pFunc);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t addWendToSampleProjects(SNodeList* pProjectionList) {
|
||||||
|
SFunctionNode* pFunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION);
|
||||||
|
if (NULL == pFunc) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
strcpy(pFunc->functionName, "_wend");
|
||||||
|
return nodesListAppend(pProjectionList, (SNode*)pFunc);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t addWdurationToSampleProjects(SNodeList* pProjectionList) {
|
||||||
|
SFunctionNode* pFunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION);
|
||||||
|
if (NULL == pFunc) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
strcpy(pFunc->functionName, "_wduration");
|
||||||
|
return nodesListAppend(pProjectionList, (SNode*)pFunc);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t buildProjectsForSampleAst(SSampleAstInfo* pInfo, SNodeList** pList) {
|
||||||
|
SNodeList* pProjectionList = pInfo->pFuncs;
|
||||||
|
pInfo->pFuncs = NULL;
|
||||||
|
|
||||||
|
int32_t code = addWstartToSampleProjects(pProjectionList);
|
||||||
|
if (TSDB_CODE_SUCCESS == code && pInfo->createSmaIndex) {
|
||||||
|
code = addWendToSampleProjects(pProjectionList);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = addWdurationToSampleProjects(pProjectionList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
SNode* pProject = NULL;
|
||||||
|
FOREACH(pProject, pProjectionList) { sprintf(((SExprNode*)pProject)->aliasName, "#%p", pProject); }
|
||||||
|
*pList = pProjectionList;
|
||||||
|
} else {
|
||||||
|
nodesDestroyList(pProjectionList);
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t buildIntervalForSampleAst(SSampleAstInfo* pInfo, SNode** pOutput) {
|
||||||
|
SIntervalWindowNode* pInterval = (SIntervalWindowNode*)nodesMakeNode(QUERY_NODE_INTERVAL_WINDOW);
|
||||||
|
if (NULL == pInterval) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
TSWAP(pInterval->pInterval, pInfo->pInterval);
|
||||||
|
TSWAP(pInterval->pOffset, pInfo->pOffset);
|
||||||
|
TSWAP(pInterval->pSliding, pInfo->pSliding);
|
||||||
|
pInterval->pCol = nodesMakeNode(QUERY_NODE_COLUMN);
|
||||||
|
if (NULL == pInterval->pCol) {
|
||||||
|
nodesDestroyNode((SNode*)pInterval);
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
((SColumnNode*)pInterval->pCol)->colId = PRIMARYKEY_TIMESTAMP_COL_ID;
|
||||||
|
strcpy(((SColumnNode*)pInterval->pCol)->colName, ROWTS_PSEUDO_COLUMN_NAME);
|
||||||
|
*pOutput = (SNode*)pInterval;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t buildSampleAst(STranslateContext* pCxt, SSampleAstInfo* pInfo, char** pAst, int32_t* pLen, char** pExpr,
|
static int32_t buildSampleAst(STranslateContext* pCxt, SSampleAstInfo* pInfo, char** pAst, int32_t* pLen, char** pExpr,
|
||||||
int32_t* pExprLen) {
|
int32_t* pExprLen) {
|
||||||
SSelectStmt* pSelect = (SSelectStmt*)nodesMakeNode(QUERY_NODE_SELECT_STMT);
|
SSelectStmt* pSelect = (SSelectStmt*)nodesMakeNode(QUERY_NODE_SELECT_STMT);
|
||||||
|
@ -4579,48 +4660,18 @@ static int32_t buildSampleAst(STranslateContext* pCxt, SSampleAstInfo* pInfo, ch
|
||||||
}
|
}
|
||||||
sprintf(pSelect->stmtName, "%p", pSelect);
|
sprintf(pSelect->stmtName, "%p", pSelect);
|
||||||
|
|
||||||
SRealTableNode* pTable = (SRealTableNode*)nodesMakeNode(QUERY_NODE_REAL_TABLE);
|
int32_t code = buildTableForSampleAst(pInfo, &pSelect->pFromTable);
|
||||||
if (NULL == pTable) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
nodesDestroyNode((SNode*)pSelect);
|
code = buildProjectsForSampleAst(pInfo, &pSelect->pProjectionList);
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
}
|
}
|
||||||
snprintf(pTable->table.dbName, sizeof(pTable->table.dbName), "%s", pInfo->pDbName);
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
snprintf(pTable->table.tableName, sizeof(pTable->table.tableName), "%s", pInfo->pTableName);
|
TSWAP(pSelect->pPartitionByList, pInfo->pPartitionByList);
|
||||||
TSWAP(pTable->pMeta, pInfo->pRollupTableMeta);
|
code = buildIntervalForSampleAst(pInfo, &pSelect->pWindow);
|
||||||
pSelect->pFromTable = (SNode*)pTable;
|
|
||||||
|
|
||||||
TSWAP(pSelect->pProjectionList, pInfo->pFuncs);
|
|
||||||
SFunctionNode* pFunc = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION);
|
|
||||||
if (NULL == pSelect->pProjectionList || NULL == pFunc) {
|
|
||||||
nodesDestroyNode((SNode*)pSelect);
|
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
}
|
}
|
||||||
strcpy(pFunc->functionName, "_wstart");
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
nodesListPushFront(pSelect->pProjectionList, (SNode*)pFunc);
|
pCxt->createStream = true;
|
||||||
SNode* pProject = NULL;
|
code = translateQuery(pCxt, (SNode*)pSelect);
|
||||||
FOREACH(pProject, pSelect->pProjectionList) { sprintf(((SExprNode*)pProject)->aliasName, "#%p", pProject); }
|
|
||||||
|
|
||||||
TSWAP(pSelect->pPartitionByList, pInfo->pPartitionByList);
|
|
||||||
|
|
||||||
SIntervalWindowNode* pInterval = (SIntervalWindowNode*)nodesMakeNode(QUERY_NODE_INTERVAL_WINDOW);
|
|
||||||
if (NULL == pInterval) {
|
|
||||||
nodesDestroyNode((SNode*)pSelect);
|
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
}
|
}
|
||||||
pSelect->pWindow = (SNode*)pInterval;
|
|
||||||
TSWAP(pInterval->pInterval, pInfo->pInterval);
|
|
||||||
TSWAP(pInterval->pOffset, pInfo->pOffset);
|
|
||||||
TSWAP(pInterval->pSliding, pInfo->pSliding);
|
|
||||||
pInterval->pCol = nodesMakeNode(QUERY_NODE_COLUMN);
|
|
||||||
if (NULL == pInterval->pCol) {
|
|
||||||
nodesDestroyNode((SNode*)pSelect);
|
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
((SColumnNode*)pInterval->pCol)->colId = PRIMARYKEY_TIMESTAMP_COL_ID;
|
|
||||||
strcpy(((SColumnNode*)pInterval->pCol)->colName, ROWTS_PSEUDO_COLUMN_NAME);
|
|
||||||
|
|
||||||
pCxt->createStream = true;
|
|
||||||
int32_t code = translateQuery(pCxt, (SNode*)pSelect);
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = nodesNodeToString((SNode*)pSelect, false, pAst, pLen);
|
code = nodesNodeToString((SNode*)pSelect, false, pAst, pLen);
|
||||||
}
|
}
|
||||||
|
@ -5162,6 +5213,7 @@ static int32_t getSmaIndexSql(STranslateContext* pCxt, char** pSql, int32_t* pLe
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t buildSampleAstInfoByIndex(STranslateContext* pCxt, SCreateIndexStmt* pStmt, SSampleAstInfo* pInfo) {
|
static int32_t buildSampleAstInfoByIndex(STranslateContext* pCxt, SCreateIndexStmt* pStmt, SSampleAstInfo* pInfo) {
|
||||||
|
pInfo->createSmaIndex = true;
|
||||||
pInfo->pDbName = pStmt->dbName;
|
pInfo->pDbName = pStmt->dbName;
|
||||||
pInfo->pTableName = pStmt->tableName;
|
pInfo->pTableName = pStmt->tableName;
|
||||||
pInfo->pFuncs = nodesCloneList(pStmt->pOptions->pFuncs);
|
pInfo->pFuncs = nodesCloneList(pStmt->pOptions->pFuncs);
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1284,18 +1284,14 @@ static int32_t smaIndexOptFindSmaFunc(SNode* pQueryFunc, SNodeList* pSmaFuncs) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t smaIndexOptCreateSmaCols(SNodeList* pFuncs, uint64_t tableId, SNodeList* pSmaFuncs, SNodeList** pOutput,
|
static int32_t smaIndexOptCreateSmaCols(SNodeList* pFuncs, uint64_t tableId, SNodeList* pSmaFuncs,
|
||||||
int32_t* pWStrartIndex) {
|
SNodeList** pOutput) {
|
||||||
SNodeList* pCols = NULL;
|
SNodeList* pCols = NULL;
|
||||||
SNode* pFunc = NULL;
|
SNode* pFunc = NULL;
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
int32_t index = 0;
|
int32_t index = 0;
|
||||||
int32_t smaFuncIndex = -1;
|
int32_t smaFuncIndex = -1;
|
||||||
*pWStrartIndex = -1;
|
|
||||||
FOREACH(pFunc, pFuncs) {
|
FOREACH(pFunc, pFuncs) {
|
||||||
if (FUNCTION_TYPE_WSTART == ((SFunctionNode*)pFunc)->funcType) {
|
|
||||||
*pWStrartIndex = index;
|
|
||||||
}
|
|
||||||
smaFuncIndex = smaIndexOptFindSmaFunc(pFunc, pSmaFuncs);
|
smaFuncIndex = smaIndexOptFindSmaFunc(pFunc, pSmaFuncs);
|
||||||
if (smaFuncIndex < 0) {
|
if (smaFuncIndex < 0) {
|
||||||
break;
|
break;
|
||||||
|
@ -1317,8 +1313,7 @@ static int32_t smaIndexOptCreateSmaCols(SNodeList* pFuncs, uint64_t tableId, SNo
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t smaIndexOptCouldApplyIndex(SScanLogicNode* pScan, STableIndexInfo* pIndex, SNodeList** pCols,
|
static int32_t smaIndexOptCouldApplyIndex(SScanLogicNode* pScan, STableIndexInfo* pIndex, SNodeList** pCols) {
|
||||||
int32_t* pWStrartIndex) {
|
|
||||||
SWindowLogicNode* pWindow = (SWindowLogicNode*)pScan->node.pParent;
|
SWindowLogicNode* pWindow = (SWindowLogicNode*)pScan->node.pParent;
|
||||||
if (!smaIndexOptEqualInterval(pScan, pWindow, pIndex)) {
|
if (!smaIndexOptEqualInterval(pScan, pWindow, pIndex)) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -1326,14 +1321,14 @@ static int32_t smaIndexOptCouldApplyIndex(SScanLogicNode* pScan, STableIndexInfo
|
||||||
SNodeList* pSmaFuncs = NULL;
|
SNodeList* pSmaFuncs = NULL;
|
||||||
int32_t code = nodesStringToList(pIndex->expr, &pSmaFuncs);
|
int32_t code = nodesStringToList(pIndex->expr, &pSmaFuncs);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = smaIndexOptCreateSmaCols(pWindow->pFuncs, pIndex->dstTbUid, pSmaFuncs, pCols, pWStrartIndex);
|
code = smaIndexOptCreateSmaCols(pWindow->pFuncs, pIndex->dstTbUid, pSmaFuncs, pCols);
|
||||||
}
|
}
|
||||||
nodesDestroyList(pSmaFuncs);
|
nodesDestroyList(pSmaFuncs);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t smaIndexOptApplyIndex(SLogicSubplan* pLogicSubplan, SScanLogicNode* pScan, STableIndexInfo* pIndex,
|
static int32_t smaIndexOptApplyIndex(SLogicSubplan* pLogicSubplan, SScanLogicNode* pScan, STableIndexInfo* pIndex,
|
||||||
SNodeList* pSmaCols, int32_t wstrartIndex) {
|
SNodeList* pSmaCols) {
|
||||||
SLogicNode* pSmaScan = NULL;
|
SLogicNode* pSmaScan = NULL;
|
||||||
int32_t code = smaIndexOptCreateSmaScan(pScan, pIndex, pSmaCols, &pSmaScan);
|
int32_t code = smaIndexOptCreateSmaScan(pScan, pIndex, pSmaCols, &pSmaScan);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
@ -1350,10 +1345,9 @@ static int32_t smaIndexOptimizeImpl(SOptimizeContext* pCxt, SLogicSubplan* pLogi
|
||||||
for (int32_t i = 0; i < nindexes; ++i) {
|
for (int32_t i = 0; i < nindexes; ++i) {
|
||||||
STableIndexInfo* pIndex = taosArrayGet(pScan->pSmaIndexes, i);
|
STableIndexInfo* pIndex = taosArrayGet(pScan->pSmaIndexes, i);
|
||||||
SNodeList* pSmaCols = NULL;
|
SNodeList* pSmaCols = NULL;
|
||||||
int32_t wstrartIndex = -1;
|
code = smaIndexOptCouldApplyIndex(pScan, pIndex, &pSmaCols);
|
||||||
code = smaIndexOptCouldApplyIndex(pScan, pIndex, &pSmaCols, &wstrartIndex);
|
|
||||||
if (TSDB_CODE_SUCCESS == code && NULL != pSmaCols) {
|
if (TSDB_CODE_SUCCESS == code && NULL != pSmaCols) {
|
||||||
code = smaIndexOptApplyIndex(pLogicSubplan, pScan, pIndex, pSmaCols, wstrartIndex);
|
code = smaIndexOptApplyIndex(pLogicSubplan, pScan, pIndex, pSmaCols);
|
||||||
taosArrayDestroyEx(pScan->pSmaIndexes, smaIndexOptDestroySmaIndex);
|
taosArrayDestroyEx(pScan->pSmaIndexes, smaIndexOptDestroySmaIndex);
|
||||||
pScan->pSmaIndexes = NULL;
|
pScan->pSmaIndexes = NULL;
|
||||||
pCxt->optimized = true;
|
pCxt->optimized = true;
|
||||||
|
|
|
@ -375,7 +375,7 @@ extern SSchedulerMgmt schMgmt;
|
||||||
#define SCH_JOB_NEED_WAIT(_job) (!SCH_IS_QUERY_JOB(_job))
|
#define SCH_JOB_NEED_WAIT(_job) (!SCH_IS_QUERY_JOB(_job))
|
||||||
#define SCH_JOB_NEED_DROP(_job) (SCH_IS_QUERY_JOB(_job))
|
#define SCH_JOB_NEED_DROP(_job) (SCH_IS_QUERY_JOB(_job))
|
||||||
#define SCH_IS_EXPLAIN_JOB(_job) (EXPLAIN_MODE_ANALYZE == (_job)->attr.explainMode)
|
#define SCH_IS_EXPLAIN_JOB(_job) (EXPLAIN_MODE_ANALYZE == (_job)->attr.explainMode)
|
||||||
#define SCH_NETWORK_ERR(_code) ((_code) == TSDB_CODE_RPC_BROKEN_LINK || (_code) == TSDB_CODE_RPC_NETWORK_UNAVAIL)
|
#define SCH_NETWORK_ERR(_code) ((_code) == TSDB_CODE_RPC_BROKEN_LINK || (_code) == TSDB_CODE_RPC_NETWORK_UNAVAIL || (_code) == TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED)
|
||||||
#define SCH_MERGE_TASK_NETWORK_ERR(_task, _code, _len) \
|
#define SCH_MERGE_TASK_NETWORK_ERR(_task, _code, _len) \
|
||||||
(SCH_NETWORK_ERR(_code) && (((_len) > 0) || (!SCH_IS_DATA_BIND_TASK(_task)) || (_task)->redirectCtx.inRedirect))
|
(SCH_NETWORK_ERR(_code) && (((_len) > 0) || (!SCH_IS_DATA_BIND_TASK(_task)) || (_task)->redirectCtx.inRedirect))
|
||||||
#define SCH_REDIRECT_MSGTYPE(_msgType) \
|
#define SCH_REDIRECT_MSGTYPE(_msgType) \
|
||||||
|
|
|
@ -668,6 +668,7 @@ void schFreeJobImpl(void *job) {
|
||||||
taosMemoryFreeClear(pJob->userRes.execRes);
|
taosMemoryFreeClear(pJob->userRes.execRes);
|
||||||
taosMemoryFreeClear(pJob->fetchRes);
|
taosMemoryFreeClear(pJob->fetchRes);
|
||||||
taosMemoryFreeClear(pJob->sql);
|
taosMemoryFreeClear(pJob->sql);
|
||||||
|
tsem_destroy(&pJob->rspSem);
|
||||||
taosMemoryFree(pJob);
|
taosMemoryFree(pJob);
|
||||||
|
|
||||||
int32_t jobNum = atomic_sub_fetch_32(&schMgmt.jobNum, 1);
|
int32_t jobNum = atomic_sub_fetch_32(&schMgmt.jobNum, 1);
|
||||||
|
@ -748,7 +749,10 @@ int32_t schInitJob(int64_t *pJobId, SSchedulerReq *pReq) {
|
||||||
SCH_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
SCH_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
tsem_init(&pJob->rspSem, 0, 0);
|
if (tsem_init(&pJob->rspSem, 0, 0)) {
|
||||||
|
SCH_JOB_ELOG("tsem_init failed, errno:%d", errno);
|
||||||
|
SCH_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||||
|
}
|
||||||
|
|
||||||
pJob->refId = taosAddRef(schMgmt.jobRef, pJob);
|
pJob->refId = taosAddRef(schMgmt.jobRef, pJob);
|
||||||
if (pJob->refId < 0) {
|
if (pJob->refId < 0) {
|
||||||
|
|
|
@ -49,6 +49,10 @@ static int32_t streamTaskExecImpl(SStreamTask* pTask, const void* data, SArray*
|
||||||
|
|
||||||
// exec
|
// exec
|
||||||
while (1) {
|
while (1) {
|
||||||
|
if (pTask->taskStatus == TASK_STATUS__DROPPING) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
SSDataBlock* output = NULL;
|
SSDataBlock* output = NULL;
|
||||||
uint64_t ts = 0;
|
uint64_t ts = 0;
|
||||||
if ((code = qExecTask(exec, &output, &ts)) < 0) {
|
if ((code = qExecTask(exec, &output, &ts)) < 0) {
|
||||||
|
|
|
@ -663,8 +663,7 @@ int32_t streamStateSessionClear(SStreamState* pState) {
|
||||||
void* buf = NULL;
|
void* buf = NULL;
|
||||||
int32_t size = 0;
|
int32_t size = 0;
|
||||||
int32_t code = streamStateSessionGetKVByCur(pCur, &delKey, &buf, &size);
|
int32_t code = streamStateSessionGetKVByCur(pCur, &delKey, &buf, &size);
|
||||||
if (code == 0) {
|
if (code == 0 && size > 0) {
|
||||||
ASSERT(size > 0);
|
|
||||||
memset(buf, 0, size);
|
memset(buf, 0, size);
|
||||||
streamStateSessionPut(pState, &delKey, buf, size);
|
streamStateSessionPut(pState, &delKey, buf, size);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -238,7 +238,7 @@ int32_t syncNodeStopPingTimer(SSyncNode* pSyncNode);
|
||||||
int32_t syncNodeStartElectTimer(SSyncNode* pSyncNode, int32_t ms);
|
int32_t syncNodeStartElectTimer(SSyncNode* pSyncNode, int32_t ms);
|
||||||
int32_t syncNodeStopElectTimer(SSyncNode* pSyncNode);
|
int32_t syncNodeStopElectTimer(SSyncNode* pSyncNode);
|
||||||
int32_t syncNodeRestartElectTimer(SSyncNode* pSyncNode, int32_t ms);
|
int32_t syncNodeRestartElectTimer(SSyncNode* pSyncNode, int32_t ms);
|
||||||
int32_t syncNodeResetElectTimer(SSyncNode* pSyncNode);
|
void syncNodeResetElectTimer(SSyncNode* pSyncNode);
|
||||||
int32_t syncNodeStartHeartbeatTimer(SSyncNode* pSyncNode);
|
int32_t syncNodeStartHeartbeatTimer(SSyncNode* pSyncNode);
|
||||||
int32_t syncNodeStopHeartbeatTimer(SSyncNode* pSyncNode);
|
int32_t syncNodeStopHeartbeatTimer(SSyncNode* pSyncNode);
|
||||||
int32_t syncNodeRestartHeartbeatTimer(SSyncNode* pSyncNode);
|
int32_t syncNodeRestartHeartbeatTimer(SSyncNode* pSyncNode);
|
||||||
|
|
|
@ -61,7 +61,7 @@ typedef struct SSyncLogBuffer {
|
||||||
// SSyncLogRepMgr
|
// SSyncLogRepMgr
|
||||||
SSyncLogReplMgr* syncLogReplMgrCreate();
|
SSyncLogReplMgr* syncLogReplMgrCreate();
|
||||||
void syncLogReplMgrDestroy(SSyncLogReplMgr* pMgr);
|
void syncLogReplMgrDestroy(SSyncLogReplMgr* pMgr);
|
||||||
int32_t syncLogReplMgrReset(SSyncLogReplMgr* pMgr);
|
void syncLogReplMgrReset(SSyncLogReplMgr* pMgr);
|
||||||
|
|
||||||
int32_t syncNodeLogReplMgrInit(SSyncNode* pNode);
|
int32_t syncNodeLogReplMgrInit(SSyncNode* pNode);
|
||||||
void syncNodeLogReplMgrDestroy(SSyncNode* pNode);
|
void syncNodeLogReplMgrDestroy(SSyncNode* pNode);
|
||||||
|
@ -109,6 +109,8 @@ SSyncRaftEntry* syncLogBufferGetOneEntry(SSyncLogBuffer* pBuf, SSyncNode* pNode,
|
||||||
int32_t syncLogBufferValidate(SSyncLogBuffer* pBuf);
|
int32_t syncLogBufferValidate(SSyncLogBuffer* pBuf);
|
||||||
int32_t syncLogBufferRollback(SSyncLogBuffer* pBuf, SSyncNode* pNode, SyncIndex toIndex);
|
int32_t syncLogBufferRollback(SSyncLogBuffer* pBuf, SSyncNode* pNode, SyncIndex toIndex);
|
||||||
|
|
||||||
|
int32_t syncLogFsmExecute(SSyncNode* pNode, SSyncFSM* pFsm, ESyncState role, SyncTerm term, SSyncRaftEntry* pEntry,
|
||||||
|
int32_t applyCode);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -56,7 +56,7 @@ SSyncSnapshotSender *snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaI
|
||||||
void snapshotSenderDestroy(SSyncSnapshotSender *pSender);
|
void snapshotSenderDestroy(SSyncSnapshotSender *pSender);
|
||||||
bool snapshotSenderIsStart(SSyncSnapshotSender *pSender);
|
bool snapshotSenderIsStart(SSyncSnapshotSender *pSender);
|
||||||
int32_t snapshotSenderStart(SSyncSnapshotSender *pSender);
|
int32_t snapshotSenderStart(SSyncSnapshotSender *pSender);
|
||||||
int32_t snapshotSenderStop(SSyncSnapshotSender *pSender, bool finish);
|
void snapshotSenderStop(SSyncSnapshotSender *pSender, bool finish);
|
||||||
int32_t snapshotSend(SSyncSnapshotSender *pSender);
|
int32_t snapshotSend(SSyncSnapshotSender *pSender);
|
||||||
int32_t snapshotReSend(SSyncSnapshotSender *pSender);
|
int32_t snapshotReSend(SSyncSnapshotSender *pSender);
|
||||||
|
|
||||||
|
@ -79,8 +79,8 @@ typedef struct SSyncSnapshotReceiver {
|
||||||
|
|
||||||
SSyncSnapshotReceiver *snapshotReceiverCreate(SSyncNode *pSyncNode, SRaftId fromId);
|
SSyncSnapshotReceiver *snapshotReceiverCreate(SSyncNode *pSyncNode, SRaftId fromId);
|
||||||
void snapshotReceiverDestroy(SSyncSnapshotReceiver *pReceiver);
|
void snapshotReceiverDestroy(SSyncSnapshotReceiver *pReceiver);
|
||||||
int32_t snapshotReceiverStart(SSyncSnapshotReceiver *pReceiver, SyncSnapshotSend *pBeginMsg);
|
void snapshotReceiverStart(SSyncSnapshotReceiver *pReceiver, SyncSnapshotSend *pBeginMsg);
|
||||||
int32_t snapshotReceiverStop(SSyncSnapshotReceiver *pReceiver);
|
void snapshotReceiverStop(SSyncSnapshotReceiver *pReceiver);
|
||||||
bool snapshotReceiverIsStart(SSyncSnapshotReceiver *pReceiver);
|
bool snapshotReceiverIsStart(SSyncSnapshotReceiver *pReceiver);
|
||||||
void snapshotReceiverForceStop(SSyncSnapshotReceiver *pReceiver);
|
void snapshotReceiverForceStop(SSyncSnapshotReceiver *pReceiver);
|
||||||
|
|
||||||
|
|
|
@ -200,12 +200,15 @@ int32_t syncProcessMsg(int64_t rid, SRpcMsg* pMsg) {
|
||||||
code = syncNodeOnLocalCmd(pSyncNode, pMsg);
|
code = syncNodeOnLocalCmd(pSyncNode, pMsg);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
sError("vgId:%d, failed to process msg:%p since invalid type:%s", pSyncNode->vgId, pMsg,
|
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||||
TMSG_INFO(pMsg->msgType));
|
|
||||||
code = -1;
|
code = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
syncNodeRelease(pSyncNode);
|
syncNodeRelease(pSyncNode);
|
||||||
|
if (code != 0) {
|
||||||
|
sDebug("vgId:%d, failed to process sync msg:%p type:%s since 0x%x", pSyncNode->vgId, pMsg, TMSG_INFO(pMsg->msgType),
|
||||||
|
terrno);
|
||||||
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,8 +231,7 @@ int32_t syncSendTimeoutRsp(int64_t rid, int64_t seq) {
|
||||||
|
|
||||||
syncNodeRelease(pNode);
|
syncNodeRelease(pNode);
|
||||||
if (ret == 1) {
|
if (ret == 1) {
|
||||||
sInfo("send timeout response, seq:%" PRId64 " handle:%p ahandle:%p", seq, rpcMsg.info.handle,
|
sInfo("send timeout response, seq:%" PRId64 " handle:%p ahandle:%p", seq, rpcMsg.info.handle, rpcMsg.info.ahandle);
|
||||||
rpcMsg.info.ahandle);
|
|
||||||
rpcSendResponse(&rpcMsg);
|
rpcSendResponse(&rpcMsg);
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1084,13 +1086,17 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) {
|
||||||
// snapshot senders
|
// snapshot senders
|
||||||
for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) {
|
for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) {
|
||||||
SSyncSnapshotSender* pSender = snapshotSenderCreate(pSyncNode, i);
|
SSyncSnapshotSender* pSender = snapshotSenderCreate(pSyncNode, i);
|
||||||
// ASSERT(pSender != NULL);
|
if (pSender == NULL) return NULL;
|
||||||
(pSyncNode->senders)[i] = pSender;
|
|
||||||
sSDebug(pSender, "snapshot sender create new while open, data:%p", pSender);
|
pSyncNode->senders[i] = pSender;
|
||||||
|
sSDebug(pSender, "snapshot sender create while open sync node, data:%p", pSender);
|
||||||
}
|
}
|
||||||
|
|
||||||
// snapshot receivers
|
// snapshot receivers
|
||||||
pSyncNode->pNewNodeReceiver = snapshotReceiverCreate(pSyncNode, EMPTY_RAFT_ID);
|
pSyncNode->pNewNodeReceiver = snapshotReceiverCreate(pSyncNode, EMPTY_RAFT_ID);
|
||||||
|
if (pSyncNode->pNewNodeReceiver == NULL) return NULL;
|
||||||
|
sRDebug(pSyncNode->pNewNodeReceiver, "snapshot receiver create while open sync node, data:%p",
|
||||||
|
pSyncNode->pNewNodeReceiver);
|
||||||
|
|
||||||
// is config changing
|
// is config changing
|
||||||
pSyncNode->changing = false;
|
pSyncNode->changing = false;
|
||||||
|
@ -1131,10 +1137,8 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) {
|
||||||
pSyncNode->hbrSlowNum = 0;
|
pSyncNode->hbrSlowNum = 0;
|
||||||
pSyncNode->tmrRoutineNum = 0;
|
pSyncNode->tmrRoutineNum = 0;
|
||||||
|
|
||||||
sNInfo(pSyncNode, "sync open, node:%p", pSyncNode);
|
sNInfo(pSyncNode, "sync open, node:%p electInterval:%d heartbeatInterval:%d heartbeatTimeout:%d", pSyncNode,
|
||||||
sTrace("vgId:%d, tsElectInterval:%d, tsHeartbeatInterval:%d, tsHeartbeatTimeout:%d", pSyncNode->vgId, tsElectInterval,
|
tsElectInterval, tsHeartbeatInterval, tsHeartbeatTimeout);
|
||||||
tsHeartbeatInterval, tsHeartbeatTimeout);
|
|
||||||
|
|
||||||
return pSyncNode;
|
return pSyncNode;
|
||||||
|
|
||||||
_error:
|
_error:
|
||||||
|
@ -1251,6 +1255,8 @@ void syncNodePreClose(SSyncNode* pSyncNode) {
|
||||||
snapshotReceiverForceStop(pSyncNode->pNewNodeReceiver);
|
snapshotReceiverForceStop(pSyncNode->pNewNodeReceiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sDebug("vgId:%d, snapshot receiver destroy while preclose sync node, data:%p", pSyncNode->vgId,
|
||||||
|
pSyncNode->pNewNodeReceiver);
|
||||||
snapshotReceiverDestroy(pSyncNode->pNewNodeReceiver);
|
snapshotReceiverDestroy(pSyncNode->pNewNodeReceiver);
|
||||||
pSyncNode->pNewNodeReceiver = NULL;
|
pSyncNode->pNewNodeReceiver = NULL;
|
||||||
}
|
}
|
||||||
|
@ -1295,15 +1301,15 @@ void syncNodeClose(SSyncNode* pSyncNode) {
|
||||||
syncNodeStopHeartbeatTimer(pSyncNode);
|
syncNodeStopHeartbeatTimer(pSyncNode);
|
||||||
|
|
||||||
for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) {
|
for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) {
|
||||||
if ((pSyncNode->senders)[i] != NULL) {
|
if (pSyncNode->senders[i] != NULL) {
|
||||||
sSTrace((pSyncNode->senders)[i], "snapshot sender destroy while close, data:%p", (pSyncNode->senders)[i]);
|
sDebug("vgId:%d, snapshot sender destroy while close, data:%p", pSyncNode->vgId, pSyncNode->senders[i]);
|
||||||
|
|
||||||
if (snapshotSenderIsStart((pSyncNode->senders)[i])) {
|
if (snapshotSenderIsStart(pSyncNode->senders[i])) {
|
||||||
snapshotSenderStop((pSyncNode->senders)[i], false);
|
snapshotSenderStop(pSyncNode->senders[i], false);
|
||||||
}
|
}
|
||||||
|
|
||||||
snapshotSenderDestroy((pSyncNode->senders)[i]);
|
snapshotSenderDestroy(pSyncNode->senders[i]);
|
||||||
(pSyncNode->senders)[i] = NULL;
|
pSyncNode->senders[i] = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1312,6 +1318,7 @@ void syncNodeClose(SSyncNode* pSyncNode) {
|
||||||
snapshotReceiverForceStop(pSyncNode->pNewNodeReceiver);
|
snapshotReceiverForceStop(pSyncNode->pNewNodeReceiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sDebug("vgId:%d, snapshot receiver destroy while close, data:%p", pSyncNode->vgId, pSyncNode->pNewNodeReceiver);
|
||||||
snapshotReceiverDestroy(pSyncNode->pNewNodeReceiver);
|
snapshotReceiverDestroy(pSyncNode->pNewNodeReceiver);
|
||||||
pSyncNode->pNewNodeReceiver = NULL;
|
pSyncNode->pNewNodeReceiver = NULL;
|
||||||
}
|
}
|
||||||
|
@ -1382,8 +1389,7 @@ int32_t syncNodeRestartElectTimer(SSyncNode* pSyncNode, int32_t ms) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncNodeResetElectTimer(SSyncNode* pSyncNode) {
|
void syncNodeResetElectTimer(SSyncNode* pSyncNode) {
|
||||||
int32_t ret = 0;
|
|
||||||
int32_t electMS;
|
int32_t electMS;
|
||||||
|
|
||||||
if (pSyncNode->pRaftCfg->isStandBy) {
|
if (pSyncNode->pRaftCfg->isStandBy) {
|
||||||
|
@ -1391,11 +1397,11 @@ int32_t syncNodeResetElectTimer(SSyncNode* pSyncNode) {
|
||||||
} else {
|
} else {
|
||||||
electMS = syncUtilElectRandomMS(pSyncNode->electBaseLine, 2 * pSyncNode->electBaseLine);
|
electMS = syncUtilElectRandomMS(pSyncNode->electBaseLine, 2 * pSyncNode->electBaseLine);
|
||||||
}
|
}
|
||||||
ret = syncNodeRestartElectTimer(pSyncNode, electMS);
|
|
||||||
|
(void)syncNodeRestartElectTimer(pSyncNode, electMS);
|
||||||
|
|
||||||
sNTrace(pSyncNode, "reset elect timer, min:%d, max:%d, ms:%d", pSyncNode->electBaseLine, 2 * pSyncNode->electBaseLine,
|
sNTrace(pSyncNode, "reset elect timer, min:%d, max:%d, ms:%d", pSyncNode->electBaseLine, 2 * pSyncNode->electBaseLine,
|
||||||
electMS);
|
electMS);
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t syncNodeDoStartHeartbeatTimer(SSyncNode* pSyncNode) {
|
static int32_t syncNodeDoStartHeartbeatTimer(SSyncNode* pSyncNode) {
|
||||||
|
@ -1455,23 +1461,20 @@ int32_t syncNodeRestartHeartbeatTimer(SSyncNode* pSyncNode) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// utils --------------
|
|
||||||
int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, SRpcMsg* pMsg) {
|
int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, SRpcMsg* pMsg) {
|
||||||
SEpSet epSet;
|
SEpSet epSet;
|
||||||
syncUtilRaftId2EpSet(destRaftId, &epSet);
|
syncUtilRaftId2EpSet(destRaftId, &epSet);
|
||||||
if (pSyncNode->syncSendMSg != NULL) {
|
|
||||||
// htonl
|
|
||||||
syncUtilMsgHtoN(pMsg->pCont);
|
|
||||||
|
|
||||||
|
if (pSyncNode->syncSendMSg != NULL) {
|
||||||
|
syncUtilMsgHtoN(pMsg->pCont);
|
||||||
pMsg->info.noResp = 1;
|
pMsg->info.noResp = 1;
|
||||||
pSyncNode->syncSendMSg(&epSet, pMsg);
|
return pSyncNode->syncSendMSg(&epSet, pMsg);
|
||||||
} else {
|
} else {
|
||||||
sError("vgId:%d, sync send msg by id error, fp-send-msg is null", pSyncNode->vgId);
|
sError("vgId:%d, sync send msg by id error, fp-send-msg is null", pSyncNode->vgId);
|
||||||
rpcFreeCont(pMsg->pCont);
|
rpcFreeCont(pMsg->pCont);
|
||||||
|
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncNodeSendMsgByInfo(const SNodeInfo* nodeInfo, SSyncNode* pSyncNode, SRpcMsg* pMsg) {
|
int32_t syncNodeSendMsgByInfo(const SNodeInfo* nodeInfo, SSyncNode* pSyncNode, SRpcMsg* pMsg) {
|
||||||
|
@ -1586,7 +1589,7 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde
|
||||||
memcpy(oldReplicasId, pSyncNode->replicasId, sizeof(oldReplicasId));
|
memcpy(oldReplicasId, pSyncNode->replicasId, sizeof(oldReplicasId));
|
||||||
SSyncSnapshotSender* oldSenders[TSDB_MAX_REPLICA];
|
SSyncSnapshotSender* oldSenders[TSDB_MAX_REPLICA];
|
||||||
for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) {
|
for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) {
|
||||||
oldSenders[i] = (pSyncNode->senders)[i];
|
oldSenders[i] = pSyncNode->senders[i];
|
||||||
sSTrace(oldSenders[i], "snapshot sender save old");
|
sSTrace(oldSenders[i], "snapshot sender save old");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1625,7 +1628,7 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde
|
||||||
|
|
||||||
// clear new
|
// clear new
|
||||||
for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) {
|
for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) {
|
||||||
(pSyncNode->senders)[i] = NULL;
|
pSyncNode->senders[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset new
|
// reset new
|
||||||
|
@ -1640,16 +1643,16 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde
|
||||||
sNTrace(pSyncNode, "snapshot sender reset for: %" PRId64 ", newIndex:%d, %s:%d, %p",
|
sNTrace(pSyncNode, "snapshot sender reset for: %" PRId64 ", newIndex:%d, %s:%d, %p",
|
||||||
(pSyncNode->replicasId)[i].addr, i, host, port, oldSenders[j]);
|
(pSyncNode->replicasId)[i].addr, i, host, port, oldSenders[j]);
|
||||||
|
|
||||||
(pSyncNode->senders)[i] = oldSenders[j];
|
pSyncNode->senders[i] = oldSenders[j];
|
||||||
oldSenders[j] = NULL;
|
oldSenders[j] = NULL;
|
||||||
reset = true;
|
reset = true;
|
||||||
|
|
||||||
// reset replicaIndex
|
// reset replicaIndex
|
||||||
int32_t oldreplicaIndex = (pSyncNode->senders)[i]->replicaIndex;
|
int32_t oldreplicaIndex = pSyncNode->senders[i]->replicaIndex;
|
||||||
(pSyncNode->senders)[i]->replicaIndex = i;
|
pSyncNode->senders[i]->replicaIndex = i;
|
||||||
|
|
||||||
sNTrace(pSyncNode, "snapshot sender udpate replicaIndex from %d to %d, %s:%d, %p, reset:%d", oldreplicaIndex,
|
sNTrace(pSyncNode, "snapshot sender udpate replicaIndex from %d to %d, %s:%d, %p, reset:%d", oldreplicaIndex,
|
||||||
i, host, port, (pSyncNode->senders)[i], reset);
|
i, host, port, pSyncNode->senders[i], reset);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1658,18 +1661,23 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde
|
||||||
|
|
||||||
// create new
|
// create new
|
||||||
for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) {
|
for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) {
|
||||||
if ((pSyncNode->senders)[i] == NULL) {
|
if (pSyncNode->senders[i] == NULL) {
|
||||||
(pSyncNode->senders)[i] = snapshotSenderCreate(pSyncNode, i);
|
pSyncNode->senders[i] = snapshotSenderCreate(pSyncNode, i);
|
||||||
sSTrace((pSyncNode->senders)[i], "snapshot sender create new while reconfig, data:%p", (pSyncNode->senders)[i]);
|
if (pSyncNode->senders[i] == NULL) {
|
||||||
|
// will be created later while send snapshot
|
||||||
|
sSError(pSyncNode->senders[i], "snapshot sender create failed while reconfig");
|
||||||
|
} else {
|
||||||
|
sSDebug(pSyncNode->senders[i], "snapshot sender create while reconfig, data:%p", pSyncNode->senders[i]);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sSTrace((pSyncNode->senders)[i], "snapshot sender already exist, data:%p", (pSyncNode->senders)[i]);
|
sSDebug(pSyncNode->senders[i], "snapshot sender already exist, data:%p", pSyncNode->senders[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// free old
|
// free old
|
||||||
for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) {
|
for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) {
|
||||||
if (oldSenders[i] != NULL) {
|
if (oldSenders[i] != NULL) {
|
||||||
sNTrace(pSyncNode, "snapshot sender destroy old, data:%p replica-index:%d", oldSenders[i], i);
|
sSDebug(oldSenders[i], "snapshot sender destroy old, data:%p replica-index:%d", oldSenders[i], i);
|
||||||
snapshotSenderDestroy(oldSenders[i]);
|
snapshotSenderDestroy(oldSenders[i]);
|
||||||
oldSenders[i] = NULL;
|
oldSenders[i] = NULL;
|
||||||
}
|
}
|
||||||
|
@ -1844,8 +1852,8 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr) {
|
||||||
SSyncSnapshotSender* pMySender = syncNodeGetSnapshotSender(pSyncNode, &(pSyncNode->myRaftId));
|
SSyncSnapshotSender* pMySender = syncNodeGetSnapshotSender(pSyncNode, &(pSyncNode->myRaftId));
|
||||||
if (pMySender != NULL) {
|
if (pMySender != NULL) {
|
||||||
for (int32_t i = 0; i < pSyncNode->pMatchIndex->replicaNum; ++i) {
|
for (int32_t i = 0; i < pSyncNode->pMatchIndex->replicaNum; ++i) {
|
||||||
if ((pSyncNode->senders)[i]->privateTerm > pMySender->privateTerm) {
|
if (pSyncNode->senders[i]->privateTerm > pMySender->privateTerm) {
|
||||||
pMySender->privateTerm = (pSyncNode->senders)[i]->privateTerm;
|
pMySender->privateTerm = pSyncNode->senders[i]->privateTerm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(pMySender->privateTerm) += 100;
|
(pMySender->privateTerm) += 100;
|
||||||
|
@ -2376,9 +2384,20 @@ int32_t syncCacheEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry, LRUHand
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncNodeAppend(SSyncNode* ths, SSyncRaftEntry* pEntry) {
|
int32_t syncNodeAppend(SSyncNode* ths, SSyncRaftEntry* pEntry) {
|
||||||
|
if (pEntry->dataLen < sizeof(SMsgHead)) {
|
||||||
|
sError("vgId:%d, cannot append an invalid client request with no msg head. type:%s, dataLen:%d", ths->vgId,
|
||||||
|
TMSG_INFO(pEntry->originalRpcType), pEntry->dataLen);
|
||||||
|
syncEntryDestroy(pEntry);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// append to log buffer
|
// append to log buffer
|
||||||
if (syncLogBufferAppend(ths->pLogBuf, ths, pEntry) < 0) {
|
if (syncLogBufferAppend(ths->pLogBuf, ths, pEntry) < 0) {
|
||||||
sError("vgId:%d, failed to enqueue sync log buffer. index:%" PRId64 "", ths->vgId, pEntry->index);
|
sError("vgId:%d, failed to enqueue sync log buffer, index:%" PRId64, ths->vgId, pEntry->index);
|
||||||
|
terrno = TSDB_CODE_SYN_BUFFER_FULL;
|
||||||
|
(void)syncLogFsmExecute(ths, ths->pFsm, ths->state, ths->pRaftStore->currentTerm, pEntry,
|
||||||
|
TSDB_CODE_SYN_BUFFER_FULL);
|
||||||
|
syncEntryDestroy(pEntry);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2671,16 +2690,24 @@ int32_t syncNodeOnClientRequest(SSyncNode* ths, SRpcMsg* pMsg, SyncIndex* pRetIn
|
||||||
pEntry = syncEntryBuildFromRpcMsg(pMsg, term, index);
|
pEntry = syncEntryBuildFromRpcMsg(pMsg, term, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pEntry == NULL) {
|
||||||
|
sError("vgId:%d, failed to process client request since %s.", ths->vgId, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (ths->state == TAOS_SYNC_STATE_LEADER) {
|
if (ths->state == TAOS_SYNC_STATE_LEADER) {
|
||||||
if (pRetIndex) {
|
if (pRetIndex) {
|
||||||
(*pRetIndex) = index;
|
(*pRetIndex) = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = syncNodeAppend(ths, pEntry);
|
int32_t code = syncNodeAppend(ths, pEntry);
|
||||||
if (code < 0 && ths->vgId != 1 && vnodeIsMsgBlock(pEntry->originalRpcType)) {
|
if (code < 0) {
|
||||||
ASSERTS(false, "failed to append blocking msg");
|
sNError(ths, "failed to append blocking msg");
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
|
} else {
|
||||||
|
syncEntryDestroy(pEntry);
|
||||||
|
pEntry = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -26,6 +26,11 @@
|
||||||
#include "syncSnapshot.h"
|
#include "syncSnapshot.h"
|
||||||
#include "syncUtil.h"
|
#include "syncUtil.h"
|
||||||
|
|
||||||
|
static bool syncIsMsgBlock(tmsg_t type) {
|
||||||
|
return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
|
||||||
|
(type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM);
|
||||||
|
}
|
||||||
|
|
||||||
int64_t syncLogBufferGetEndIndex(SSyncLogBuffer* pBuf) {
|
int64_t syncLogBufferGetEndIndex(SSyncLogBuffer* pBuf) {
|
||||||
taosThreadMutexLock(&pBuf->mutex);
|
taosThreadMutexLock(&pBuf->mutex);
|
||||||
int64_t index = pBuf->endIndex;
|
int64_t index = pBuf->endIndex;
|
||||||
|
@ -40,7 +45,7 @@ int32_t syncLogBufferAppend(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEnt
|
||||||
|
|
||||||
if (index - pBuf->startIndex >= pBuf->size) {
|
if (index - pBuf->startIndex >= pBuf->size) {
|
||||||
sError("vgId:%d, failed to append due to sync log buffer full. index:%" PRId64 "", pNode->vgId, index);
|
sError("vgId:%d, failed to append due to sync log buffer full. index:%" PRId64 "", pNode->vgId, index);
|
||||||
goto _out;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(index == pBuf->endIndex);
|
ASSERT(index == pBuf->endIndex);
|
||||||
|
@ -61,9 +66,8 @@ int32_t syncLogBufferAppend(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEnt
|
||||||
taosThreadMutexUnlock(&pBuf->mutex);
|
taosThreadMutexUnlock(&pBuf->mutex);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
_out:
|
_err:
|
||||||
syncLogBufferValidate(pBuf);
|
syncLogBufferValidate(pBuf);
|
||||||
syncEntryDestroy(pEntry);
|
|
||||||
taosThreadMutexUnlock(&pBuf->mutex);
|
taosThreadMutexUnlock(&pBuf->mutex);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -112,7 +116,7 @@ SyncTerm syncLogReplMgrGetPrevLogTerm(SSyncLogReplMgr* pMgr, SSyncNode* pNode, S
|
||||||
return prevLogTerm;
|
return prevLogTerm;
|
||||||
}
|
}
|
||||||
|
|
||||||
sError("vgId:%d, failed to get log term since %s. index: %" PRId64 "", pNode->vgId, terrstr(), prevIndex);
|
sInfo("vgId:%d, failed to get log term since %s. index:%" PRId64, pNode->vgId, terrstr(), prevIndex);
|
||||||
terrno = TSDB_CODE_WAL_LOG_NOT_EXIST;
|
terrno = TSDB_CODE_WAL_LOG_NOT_EXIST;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -441,26 +445,25 @@ _out:
|
||||||
return matchIndex;
|
return matchIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncLogFsmExecute(SSyncNode* pNode, SSyncFSM* pFsm, ESyncState role, SyncTerm term, SSyncRaftEntry* pEntry) {
|
int32_t syncLogFsmExecute(SSyncNode* pNode, SSyncFSM* pFsm, ESyncState role, SyncTerm term, SSyncRaftEntry* pEntry,
|
||||||
ASSERTS(pFsm->FpCommitCb != NULL, "No commit cb registered for the FSM");
|
int32_t applyCode) {
|
||||||
|
|
||||||
if ((pNode->replicaNum == 1) && pNode->restoreFinish && pNode->vgId != 1) {
|
if ((pNode->replicaNum == 1) && pNode->restoreFinish && pNode->vgId != 1) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pNode->vgId != 1 && vnodeIsMsgBlock(pEntry->originalRpcType)) {
|
if (pNode->vgId != 1 && syncIsMsgBlock(pEntry->originalRpcType)) {
|
||||||
sTrace("vgId:%d, blocking msg ready to execute. index:%" PRId64 ", term: %" PRId64 ", type: %s", pNode->vgId,
|
sTrace("vgId:%d, blocking msg ready to execute, index:%" PRId64 ", term:%" PRId64 ", type:%s code:0x%x",
|
||||||
pEntry->index, pEntry->term, TMSG_INFO(pEntry->originalRpcType));
|
pNode->vgId, pEntry->index, pEntry->term, TMSG_INFO(pEntry->originalRpcType), applyCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg rpcMsg = {.code = applyCode};
|
||||||
syncEntry2OriginalRpc(pEntry, &rpcMsg);
|
syncEntry2OriginalRpc(pEntry, &rpcMsg);
|
||||||
|
|
||||||
SFsmCbMeta cbMeta = {0};
|
SFsmCbMeta cbMeta = {0};
|
||||||
cbMeta.index = pEntry->index;
|
cbMeta.index = pEntry->index;
|
||||||
cbMeta.lastConfigIndex = syncNodeGetSnapshotConfigIndex(pNode, pEntry->index);
|
cbMeta.lastConfigIndex = syncNodeGetSnapshotConfigIndex(pNode, pEntry->index);
|
||||||
cbMeta.isWeak = pEntry->isWeak;
|
cbMeta.isWeak = pEntry->isWeak;
|
||||||
cbMeta.code = 0;
|
cbMeta.code = applyCode;
|
||||||
cbMeta.state = role;
|
cbMeta.state = role;
|
||||||
cbMeta.seqNum = pEntry->seqNum;
|
cbMeta.seqNum = pEntry->seqNum;
|
||||||
cbMeta.term = pEntry->term;
|
cbMeta.term = pEntry->term;
|
||||||
|
@ -469,7 +472,6 @@ int32_t syncLogFsmExecute(SSyncNode* pNode, SSyncFSM* pFsm, ESyncState role, Syn
|
||||||
|
|
||||||
(void)syncRespMgrGetAndDel(pNode->pSyncRespMgr, cbMeta.seqNum, &rpcMsg.info);
|
(void)syncRespMgrGetAndDel(pNode->pSyncRespMgr, cbMeta.seqNum, &rpcMsg.info);
|
||||||
int32_t code = pFsm->FpCommitCb(pFsm, &rpcMsg, &cbMeta);
|
int32_t code = pFsm->FpCommitCb(pFsm, &rpcMsg, &cbMeta);
|
||||||
ASSERT(rpcMsg.pCont == NULL);
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -520,7 +522,7 @@ int32_t syncLogBufferCommit(SSyncLogBuffer* pBuf, SSyncNode* pNode, int64_t comm
|
||||||
pEntry->term, TMSG_INFO(pEntry->originalRpcType));
|
pEntry->term, TMSG_INFO(pEntry->originalRpcType));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (syncLogFsmExecute(pNode, pFsm, role, term, pEntry) != 0) {
|
if (syncLogFsmExecute(pNode, pFsm, role, term, pEntry, 0) != 0) {
|
||||||
sError("vgId:%d, failed to execute sync log entry. index:%" PRId64 ", term:%" PRId64
|
sError("vgId:%d, failed to execute sync log entry. index:%" PRId64 ", term:%" PRId64
|
||||||
", role: %d, current term: %" PRId64,
|
", role: %d, current term: %" PRId64,
|
||||||
vgId, pEntry->index, pEntry->term, role, term);
|
vgId, pEntry->index, pEntry->term, role, term);
|
||||||
|
@ -566,7 +568,9 @@ _out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncLogReplMgrReset(SSyncLogReplMgr* pMgr) {
|
void syncLogReplMgrReset(SSyncLogReplMgr* pMgr) {
|
||||||
|
if (pMgr == NULL) return;
|
||||||
|
|
||||||
ASSERT(pMgr->startIndex >= 0);
|
ASSERT(pMgr->startIndex >= 0);
|
||||||
for (SyncIndex index = pMgr->startIndex; index < pMgr->endIndex; index++) {
|
for (SyncIndex index = pMgr->startIndex; index < pMgr->endIndex; index++) {
|
||||||
memset(&pMgr->states[index % pMgr->size], 0, sizeof(pMgr->states[0]));
|
memset(&pMgr->states[index % pMgr->size], 0, sizeof(pMgr->states[0]));
|
||||||
|
@ -576,7 +580,6 @@ int32_t syncLogReplMgrReset(SSyncLogReplMgr* pMgr) {
|
||||||
pMgr->endIndex = 0;
|
pMgr->endIndex = 0;
|
||||||
pMgr->restored = false;
|
pMgr->restored = false;
|
||||||
pMgr->retryBackoff = 0;
|
pMgr->retryBackoff = 0;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncLogReplMgrRetryOnNeed(SSyncLogReplMgr* pMgr, SSyncNode* pNode) {
|
int32_t syncLogReplMgrRetryOnNeed(SSyncLogReplMgr* pMgr, SSyncNode* pNode) {
|
||||||
|
|
|
@ -115,8 +115,8 @@ static int32_t raftLogRestoreFromSnapshot(struct SSyncLogStore* pLogStore, SyncI
|
||||||
const char* sysErrStr = strerror(errno);
|
const char* sysErrStr = strerror(errno);
|
||||||
|
|
||||||
sNError(pData->pSyncNode,
|
sNError(pData->pSyncNode,
|
||||||
"wal restore from snapshot error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s",
|
"wal restore from snapshot error, index:%" PRId64 ", err:0x%x, msg:%s, syserr:%d, sysmsg:%s", snapshotIndex,
|
||||||
snapshotIndex, err, err, errStr, sysErr, sysErrStr);
|
err, errStr, sysErr, sysErrStr);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,8 +212,8 @@ static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntr
|
||||||
int32_t sysErr = errno;
|
int32_t sysErr = errno;
|
||||||
const char* sysErrStr = strerror(errno);
|
const char* sysErrStr = strerror(errno);
|
||||||
|
|
||||||
sNError(pData->pSyncNode, "wal write error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s",
|
sNError(pData->pSyncNode, "wal write error, index:%" PRId64 ", err:0x%x, msg:%s, syserr:%d, sysmsg:%s",
|
||||||
pEntry->index, err, err, errStr, sysErr, sysErrStr);
|
pEntry->index, err, errStr, sysErr, sysErrStr);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,11 +257,11 @@ int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, SSyncR
|
||||||
const char* sysErrStr = strerror(errno);
|
const char* sysErrStr = strerror(errno);
|
||||||
|
|
||||||
if (terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) {
|
if (terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) {
|
||||||
sNTrace(pData->pSyncNode, "wal read not exist, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", index,
|
sNTrace(pData->pSyncNode, "wal read not exist, index:%" PRId64 ", err:0x%x, msg:%s, syserr:%d, sysmsg:%s", index,
|
||||||
err, err, errStr, sysErr, sysErrStr);
|
err, errStr, sysErr, sysErrStr);
|
||||||
} else {
|
} else {
|
||||||
sNTrace(pData->pSyncNode, "wal read error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", index,
|
sNTrace(pData->pSyncNode, "wal read error, index:%" PRId64 ", err:0x%x, msg:%s, syserr:%d, sysmsg:%s", index, err,
|
||||||
err, err, errStr, sysErr, sysErrStr);
|
errStr, sysErr, sysErrStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -341,8 +341,8 @@ static int32_t raftLogTruncate(struct SSyncLogStore* pLogStore, SyncIndex fromIn
|
||||||
const char* errStr = tstrerror(err);
|
const char* errStr = tstrerror(err);
|
||||||
int32_t sysErr = errno;
|
int32_t sysErr = errno;
|
||||||
const char* sysErrStr = strerror(errno);
|
const char* sysErrStr = strerror(errno);
|
||||||
sError("vgId:%d, wal truncate error, from-index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s",
|
sError("vgId:%d, wal truncate error, from-index:%" PRId64 ", err:0x%x, msg:%s, syserr:%d, sysmsg:%s",
|
||||||
pData->pSyncNode->vgId, fromIndex, err, err, errStr, sysErr, sysErrStr);
|
pData->pSyncNode->vgId, fromIndex, err, errStr, sysErr, sysErrStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// event log
|
// event log
|
||||||
|
@ -392,8 +392,8 @@ int32_t raftLogUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index) {
|
||||||
const char* errStr = tstrerror(err);
|
const char* errStr = tstrerror(err);
|
||||||
int32_t sysErr = errno;
|
int32_t sysErr = errno;
|
||||||
const char* sysErrStr = strerror(errno);
|
const char* sysErrStr = strerror(errno);
|
||||||
sError("vgId:%d, wal update commit index error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s",
|
sError("vgId:%d, wal update commit index error, index:%" PRId64 ", err:0x%x, msg:%s, syserr:%d, sysmsg:%s",
|
||||||
pData->pSyncNode->vgId, index, err, err, errStr, sysErr, sysErrStr);
|
pData->pSyncNode->vgId, index, err, errStr, sysErr, sysErrStr);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -49,13 +49,11 @@ SSyncSnapshotSender *snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaI
|
||||||
pSender->pSyncNode->pFsm->FpGetSnapshotInfo(pSender->pSyncNode->pFsm, &pSender->snapshot);
|
pSender->pSyncNode->pFsm->FpGetSnapshotInfo(pSender->pSyncNode->pFsm, &pSender->snapshot);
|
||||||
pSender->finish = false;
|
pSender->finish = false;
|
||||||
|
|
||||||
sDebug("vgId:%d, snapshot sender create", pSender->pSyncNode->vgId);
|
|
||||||
return pSender;
|
return pSender;
|
||||||
}
|
}
|
||||||
|
|
||||||
void snapshotSenderDestroy(SSyncSnapshotSender *pSender) {
|
void snapshotSenderDestroy(SSyncSnapshotSender *pSender) {
|
||||||
if (pSender == NULL) return;
|
if (pSender == NULL) return;
|
||||||
sDebug("vgId:%d, snapshot sender destroy", pSender->pSyncNode->vgId);
|
|
||||||
|
|
||||||
// free current block
|
// free current block
|
||||||
if (pSender->pCurrentBlock != NULL) {
|
if (pSender->pCurrentBlock != NULL) {
|
||||||
|
@ -76,12 +74,6 @@ void snapshotSenderDestroy(SSyncSnapshotSender *pSender) {
|
||||||
bool snapshotSenderIsStart(SSyncSnapshotSender *pSender) { return pSender->start; }
|
bool snapshotSenderIsStart(SSyncSnapshotSender *pSender) { return pSender->start; }
|
||||||
|
|
||||||
int32_t snapshotSenderStart(SSyncSnapshotSender *pSender) {
|
int32_t snapshotSenderStart(SSyncSnapshotSender *pSender) {
|
||||||
if (snapshotSenderIsStart(pSender)) {
|
|
||||||
sSError(pSender, "vgId:%d, snapshot sender is already start");
|
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
pSender->start = true;
|
pSender->start = true;
|
||||||
pSender->seq = SYNC_SNAPSHOT_SEQ_BEGIN;
|
pSender->seq = SYNC_SNAPSHOT_SEQ_BEGIN;
|
||||||
pSender->ack = SYNC_SNAPSHOT_SEQ_INVALID;
|
pSender->ack = SYNC_SNAPSHOT_SEQ_INVALID;
|
||||||
|
@ -96,7 +88,7 @@ int32_t snapshotSenderStart(SSyncSnapshotSender *pSender) {
|
||||||
pSender->snapshot.lastApplyTerm = SYNC_TERM_INVALID;
|
pSender->snapshot.lastApplyTerm = SYNC_TERM_INVALID;
|
||||||
pSender->snapshot.lastConfigIndex = SYNC_INDEX_INVALID;
|
pSender->snapshot.lastConfigIndex = SYNC_INDEX_INVALID;
|
||||||
|
|
||||||
memset(&(pSender->lastConfig), 0, sizeof(pSender->lastConfig));
|
memset(&pSender->lastConfig, 0, sizeof(pSender->lastConfig));
|
||||||
pSender->sendingMS = 0;
|
pSender->sendingMS = 0;
|
||||||
pSender->term = pSender->pSyncNode->pRaftStore->currentTerm;
|
pSender->term = pSender->pSyncNode->pRaftStore->currentTerm;
|
||||||
pSender->startTime = taosGetTimestampMs();
|
pSender->startTime = taosGetTimestampMs();
|
||||||
|
@ -112,7 +104,7 @@ int32_t snapshotSenderStart(SSyncSnapshotSender *pSender) {
|
||||||
|
|
||||||
SyncSnapshotSend *pMsg = rpcMsg.pCont;
|
SyncSnapshotSend *pMsg = rpcMsg.pCont;
|
||||||
pMsg->srcId = pSender->pSyncNode->myRaftId;
|
pMsg->srcId = pSender->pSyncNode->myRaftId;
|
||||||
pMsg->destId = (pSender->pSyncNode->replicasId)[pSender->replicaIndex];
|
pMsg->destId = pSender->pSyncNode->replicasId[pSender->replicaIndex];
|
||||||
pMsg->term = pSender->pSyncNode->pRaftStore->currentTerm;
|
pMsg->term = pSender->pSyncNode->pRaftStore->currentTerm;
|
||||||
pMsg->beginIndex = pSender->snapshotParam.start;
|
pMsg->beginIndex = pSender->snapshotParam.start;
|
||||||
pMsg->lastIndex = pSender->snapshot.lastApplyIndex;
|
pMsg->lastIndex = pSender->snapshot.lastApplyIndex;
|
||||||
|
@ -123,7 +115,6 @@ int32_t snapshotSenderStart(SSyncSnapshotSender *pSender) {
|
||||||
pMsg->seq = SYNC_SNAPSHOT_SEQ_PRE_SNAPSHOT;
|
pMsg->seq = SYNC_SNAPSHOT_SEQ_PRE_SNAPSHOT;
|
||||||
|
|
||||||
// event log
|
// event log
|
||||||
sSDebug(pSender, "snapshot sender start");
|
|
||||||
syncLogSendSyncSnapshotSend(pSender->pSyncNode, pMsg, "snapshot sender start");
|
syncLogSendSyncSnapshotSend(pSender->pSyncNode, pMsg, "snapshot sender start");
|
||||||
|
|
||||||
// send msg
|
// send msg
|
||||||
|
@ -135,7 +126,7 @@ int32_t snapshotSenderStart(SSyncSnapshotSender *pSender) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t snapshotSenderStop(SSyncSnapshotSender *pSender, bool finish) {
|
void snapshotSenderStop(SSyncSnapshotSender *pSender, bool finish) {
|
||||||
sSDebug(pSender, "snapshot sender stop, finish:%d reader:%p", finish, pSender->pReader);
|
sSDebug(pSender, "snapshot sender stop, finish:%d reader:%p", finish, pSender->pReader);
|
||||||
|
|
||||||
// update flag
|
// update flag
|
||||||
|
@ -155,8 +146,6 @@ int32_t snapshotSenderStop(SSyncSnapshotSender *pSender, bool finish) {
|
||||||
pSender->pCurrentBlock = NULL;
|
pSender->pCurrentBlock = NULL;
|
||||||
pSender->blockLen = 0;
|
pSender->blockLen = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// when sender receive ack, call this function to send msg from seq
|
// when sender receive ack, call this function to send msg from seq
|
||||||
|
@ -178,8 +167,8 @@ int32_t snapshotSend(SSyncSnapshotSender *pSender) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pSender->blockLen > 0) {
|
if (pSender->blockLen > 0) {
|
||||||
sSDebug(pSender, "snapshot sender continue to read, blockLen:%d seq:%d", pSender->blockLen, pSender->seq);
|
|
||||||
// has read data
|
// has read data
|
||||||
|
sSDebug(pSender, "snapshot sender continue to read, blockLen:%d seq:%d", pSender->blockLen, pSender->seq);
|
||||||
} else {
|
} else {
|
||||||
// read finish, update seq to end
|
// read finish, update seq to end
|
||||||
pSender->seq = SYNC_SNAPSHOT_SEQ_END;
|
pSender->seq = SYNC_SNAPSHOT_SEQ_END;
|
||||||
|
@ -195,7 +184,7 @@ int32_t snapshotSend(SSyncSnapshotSender *pSender) {
|
||||||
|
|
||||||
SyncSnapshotSend *pMsg = rpcMsg.pCont;
|
SyncSnapshotSend *pMsg = rpcMsg.pCont;
|
||||||
pMsg->srcId = pSender->pSyncNode->myRaftId;
|
pMsg->srcId = pSender->pSyncNode->myRaftId;
|
||||||
pMsg->destId = (pSender->pSyncNode->replicasId)[pSender->replicaIndex];
|
pMsg->destId = pSender->pSyncNode->replicasId[pSender->replicaIndex];
|
||||||
pMsg->term = pSender->pSyncNode->pRaftStore->currentTerm;
|
pMsg->term = pSender->pSyncNode->pRaftStore->currentTerm;
|
||||||
pMsg->beginIndex = pSender->snapshotParam.start;
|
pMsg->beginIndex = pSender->snapshotParam.start;
|
||||||
pMsg->lastIndex = pSender->snapshot.lastApplyIndex;
|
pMsg->lastIndex = pSender->snapshot.lastApplyIndex;
|
||||||
|
@ -203,7 +192,6 @@ int32_t snapshotSend(SSyncSnapshotSender *pSender) {
|
||||||
pMsg->lastConfigIndex = pSender->snapshot.lastConfigIndex;
|
pMsg->lastConfigIndex = pSender->snapshot.lastConfigIndex;
|
||||||
pMsg->lastConfig = pSender->lastConfig;
|
pMsg->lastConfig = pSender->lastConfig;
|
||||||
pMsg->seq = pSender->seq;
|
pMsg->seq = pSender->seq;
|
||||||
// pMsg->privateTerm = pSender->privateTerm;
|
|
||||||
|
|
||||||
if (pSender->pCurrentBlock != NULL) {
|
if (pSender->pCurrentBlock != NULL) {
|
||||||
memcpy(pMsg->data, pSender->pCurrentBlock, pSender->blockLen);
|
memcpy(pMsg->data, pSender->pCurrentBlock, pSender->blockLen);
|
||||||
|
@ -211,10 +199,8 @@ int32_t snapshotSend(SSyncSnapshotSender *pSender) {
|
||||||
|
|
||||||
// event log
|
// event log
|
||||||
if (pSender->seq == SYNC_SNAPSHOT_SEQ_END) {
|
if (pSender->seq == SYNC_SNAPSHOT_SEQ_END) {
|
||||||
sSDebug(pSender, "snapshot sender finish, seq:%d", pSender->seq);
|
|
||||||
syncLogSendSyncSnapshotSend(pSender->pSyncNode, pMsg, "snapshot sender finish");
|
syncLogSendSyncSnapshotSend(pSender->pSyncNode, pMsg, "snapshot sender finish");
|
||||||
} else {
|
} else {
|
||||||
sSDebug(pSender, "snapshot sender sending, seq:%d", pSender->seq);
|
|
||||||
syncLogSendSyncSnapshotSend(pSender->pSyncNode, pMsg, "snapshot sender sending");
|
syncLogSendSyncSnapshotSend(pSender->pSyncNode, pMsg, "snapshot sender sending");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,7 +225,7 @@ int32_t snapshotReSend(SSyncSnapshotSender *pSender) {
|
||||||
|
|
||||||
SyncSnapshotSend *pMsg = rpcMsg.pCont;
|
SyncSnapshotSend *pMsg = rpcMsg.pCont;
|
||||||
pMsg->srcId = pSender->pSyncNode->myRaftId;
|
pMsg->srcId = pSender->pSyncNode->myRaftId;
|
||||||
pMsg->destId = (pSender->pSyncNode->replicasId)[pSender->replicaIndex];
|
pMsg->destId = pSender->pSyncNode->replicasId[pSender->replicaIndex];
|
||||||
pMsg->term = pSender->pSyncNode->pRaftStore->currentTerm;
|
pMsg->term = pSender->pSyncNode->pRaftStore->currentTerm;
|
||||||
pMsg->beginIndex = pSender->snapshotParam.start;
|
pMsg->beginIndex = pSender->snapshotParam.start;
|
||||||
pMsg->lastIndex = pSender->snapshot.lastApplyIndex;
|
pMsg->lastIndex = pSender->snapshot.lastApplyIndex;
|
||||||
|
@ -249,12 +235,10 @@ int32_t snapshotReSend(SSyncSnapshotSender *pSender) {
|
||||||
pMsg->seq = pSender->seq;
|
pMsg->seq = pSender->seq;
|
||||||
|
|
||||||
if (pSender->pCurrentBlock != NULL && pSender->blockLen > 0) {
|
if (pSender->pCurrentBlock != NULL && pSender->blockLen > 0) {
|
||||||
// pMsg->privateTerm = pSender->privateTerm;
|
|
||||||
memcpy(pMsg->data, pSender->pCurrentBlock, pSender->blockLen);
|
memcpy(pMsg->data, pSender->pCurrentBlock, pSender->blockLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
// event log
|
// event log
|
||||||
sSDebug(pSender, "snapshot sender resend, seq:%d", pSender->seq);
|
|
||||||
syncLogSendSyncSnapshotSend(pSender->pSyncNode, pMsg, "snapshot sender resend");
|
syncLogSendSyncSnapshotSend(pSender->pSyncNode, pMsg, "snapshot sender resend");
|
||||||
|
|
||||||
// send msg
|
// send msg
|
||||||
|
@ -294,19 +278,16 @@ int32_t syncNodeStartSnapshot(SSyncNode *pSyncNode, SRaftId *pDestId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (snapshotSenderIsStart(pSender)) {
|
if (snapshotSenderIsStart(pSender)) {
|
||||||
sSError(pSender, "snapshot sender already start, ignore");
|
sSInfo(pSender, "snapshot sender already start, ignore");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pSender->finish && taosGetTimestampMs() - pSender->endTime < SNAPSHOT_WAIT_MS) {
|
if (pSender->finish && taosGetTimestampMs() - pSender->endTime < SNAPSHOT_WAIT_MS) {
|
||||||
sSInfo(pSender, "snapshot sender start too frequently, ignore");
|
sSInfo(pSender, "snapshot sender start too frequently, ignore");
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char host[64];
|
sSInfo(pSender, "snapshot sender start");
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(pDestId->addr, host, sizeof(host), &port);
|
|
||||||
sSInfo(pSender, "snapshot sender start for peer:%s:%u", host, port);
|
|
||||||
|
|
||||||
int32_t code = snapshotSenderStart(pSender);
|
int32_t code = snapshotSenderStart(pSender);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
|
@ -339,13 +320,11 @@ SSyncSnapshotReceiver *snapshotReceiverCreate(SSyncNode *pSyncNode, SRaftId from
|
||||||
pReceiver->snapshot.lastApplyTerm = 0;
|
pReceiver->snapshot.lastApplyTerm = 0;
|
||||||
pReceiver->snapshot.lastConfigIndex = SYNC_INDEX_INVALID;
|
pReceiver->snapshot.lastConfigIndex = SYNC_INDEX_INVALID;
|
||||||
|
|
||||||
sDebug("vgId:%d, snapshot receiver create", pSyncNode->vgId);
|
|
||||||
return pReceiver;
|
return pReceiver;
|
||||||
}
|
}
|
||||||
|
|
||||||
void snapshotReceiverDestroy(SSyncSnapshotReceiver *pReceiver) {
|
void snapshotReceiverDestroy(SSyncSnapshotReceiver *pReceiver) {
|
||||||
if (pReceiver == NULL) return;
|
if (pReceiver == NULL) return;
|
||||||
sDebug("vgId:%d, snapshot receiver destroy", pReceiver->pSyncNode->vgId);
|
|
||||||
|
|
||||||
// close writer
|
// close writer
|
||||||
if (pReceiver->pWriter != NULL) {
|
if (pReceiver->pWriter != NULL) {
|
||||||
|
@ -369,7 +348,6 @@ void snapshotReceiverForceStop(SSyncSnapshotReceiver *pReceiver) {
|
||||||
|
|
||||||
// force close, abandon incomplete data
|
// force close, abandon incomplete data
|
||||||
if (pReceiver->pWriter != NULL) {
|
if (pReceiver->pWriter != NULL) {
|
||||||
// event log
|
|
||||||
int32_t ret = pReceiver->pSyncNode->pFsm->FpSnapshotStopWrite(pReceiver->pSyncNode->pFsm, pReceiver->pWriter, false,
|
int32_t ret = pReceiver->pSyncNode->pFsm->FpSnapshotStopWrite(pReceiver->pSyncNode->pFsm, pReceiver->pWriter, false,
|
||||||
&pReceiver->snapshot);
|
&pReceiver->snapshot);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
|
@ -381,13 +359,7 @@ void snapshotReceiverForceStop(SSyncSnapshotReceiver *pReceiver) {
|
||||||
pReceiver->start = false;
|
pReceiver->start = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t snapshotReceiverStartWriter(SSyncSnapshotReceiver *pReceiver, SyncSnapshotSend *pBeginMsg) {
|
static int32_t snapshotReceiverStartWriter(SSyncSnapshotReceiver *pReceiver, SyncSnapshotSend *pBeginMsg) {
|
||||||
if (!snapshotReceiverIsStart(pReceiver)) {
|
|
||||||
sRError(pReceiver, "snapshot receiver is not start");
|
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pReceiver->pWriter != NULL) {
|
if (pReceiver->pWriter != NULL) {
|
||||||
sRError(pReceiver, "vgId:%d, snapshot receiver writer is not null");
|
sRError(pReceiver, "vgId:%d, snapshot receiver writer is not null");
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||||
|
@ -417,10 +389,10 @@ int32_t snapshotReceiverStartWriter(SSyncSnapshotReceiver *pReceiver, SyncSnapsh
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t snapshotReceiverStart(SSyncSnapshotReceiver *pReceiver, SyncSnapshotSend *pPreMsg) {
|
void snapshotReceiverStart(SSyncSnapshotReceiver *pReceiver, SyncSnapshotSend *pPreMsg) {
|
||||||
if (snapshotReceiverIsStart(pReceiver)) {
|
if (snapshotReceiverIsStart(pReceiver)) {
|
||||||
sRInfo(pReceiver, "snapshot receiver has started");
|
sRInfo(pReceiver, "snapshot receiver has started");
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pReceiver->start = true;
|
pReceiver->start = true;
|
||||||
|
@ -431,12 +403,11 @@ int32_t snapshotReceiverStart(SSyncSnapshotReceiver *pReceiver, SyncSnapshotSend
|
||||||
|
|
||||||
// event log
|
// event log
|
||||||
sRInfo(pReceiver, "snapshot receiver is start");
|
sRInfo(pReceiver, "snapshot receiver is start");
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// just set start = false
|
// just set start = false
|
||||||
// FpSnapshotStopWrite should not be called, assert writer == NULL
|
// FpSnapshotStopWrite should not be called, assert writer == NULL
|
||||||
int32_t snapshotReceiverStop(SSyncSnapshotReceiver *pReceiver) {
|
void snapshotReceiverStop(SSyncSnapshotReceiver *pReceiver) {
|
||||||
sRInfo(pReceiver, "snapshot receiver stop, not apply, writer:%p", pReceiver->pWriter);
|
sRInfo(pReceiver, "snapshot receiver stop, not apply, writer:%p", pReceiver->pWriter);
|
||||||
|
|
||||||
if (pReceiver->pWriter != NULL) {
|
if (pReceiver->pWriter != NULL) {
|
||||||
|
@ -451,17 +422,10 @@ int32_t snapshotReceiverStop(SSyncSnapshotReceiver *pReceiver) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pReceiver->start = false;
|
pReceiver->start = false;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// when recv last snapshot block, apply data into snapshot
|
// when recv last snapshot block, apply data into snapshot
|
||||||
static int32_t snapshotReceiverFinish(SSyncSnapshotReceiver *pReceiver, SyncSnapshotSend *pMsg) {
|
static int32_t snapshotReceiverFinish(SSyncSnapshotReceiver *pReceiver, SyncSnapshotSend *pMsg) {
|
||||||
if (pMsg->seq != SYNC_SNAPSHOT_SEQ_END) {
|
|
||||||
sRError(pReceiver, "snapshot receiver seq:%d is invalid", pMsg->seq);
|
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
if (pReceiver->pWriter != NULL) {
|
if (pReceiver->pWriter != NULL) {
|
||||||
// write data
|
// write data
|
||||||
|
@ -523,7 +487,7 @@ static int32_t snapshotReceiverFinish(SSyncSnapshotReceiver *pReceiver, SyncSnap
|
||||||
static int32_t snapshotReceiverGotData(SSyncSnapshotReceiver *pReceiver, SyncSnapshotSend *pMsg) {
|
static int32_t snapshotReceiverGotData(SSyncSnapshotReceiver *pReceiver, SyncSnapshotSend *pMsg) {
|
||||||
if (pMsg->seq != pReceiver->ack + 1) {
|
if (pMsg->seq != pReceiver->ack + 1) {
|
||||||
sRError(pReceiver, "snapshot receiver invalid seq, ack:%d seq:%d", pReceiver->ack, pMsg->seq);
|
sRError(pReceiver, "snapshot receiver invalid seq, ack:%d seq:%d", pReceiver->ack, pMsg->seq);
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
terrno = TSDB_CODE_SYN_INVALID_SNAPSHOT_MSG;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -583,6 +547,7 @@ SyncIndex syncNodeGetSnapBeginIndex(SSyncNode *ths) {
|
||||||
static int32_t syncNodeOnSnapshotPre(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
|
static int32_t syncNodeOnSnapshotPre(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
|
||||||
SSyncSnapshotReceiver *pReceiver = pSyncNode->pNewNodeReceiver;
|
SSyncSnapshotReceiver *pReceiver = pSyncNode->pNewNodeReceiver;
|
||||||
int64_t timeNow = taosGetTimestampMs();
|
int64_t timeNow = taosGetTimestampMs();
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
if (snapshotReceiverIsStart(pReceiver)) {
|
if (snapshotReceiverIsStart(pReceiver)) {
|
||||||
// already start
|
// already start
|
||||||
|
@ -594,14 +559,14 @@ static int32_t syncNodeOnSnapshotPre(SSyncNode *pSyncNode, SyncSnapshotSend *pMs
|
||||||
sRInfo(pReceiver, "snapshot receiver startTime:%" PRId64 " == msg startTime:%" PRId64 " send reply",
|
sRInfo(pReceiver, "snapshot receiver startTime:%" PRId64 " == msg startTime:%" PRId64 " send reply",
|
||||||
pReceiver->startTime, pMsg->startTime);
|
pReceiver->startTime, pMsg->startTime);
|
||||||
goto _SEND_REPLY;
|
goto _SEND_REPLY;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// ignore
|
// ignore
|
||||||
sRInfo(pReceiver, "snapshot receiver startTime:%" PRId64 " < msg startTime:%" PRId64 " ignore",
|
sRError(pReceiver, "snapshot receiver startTime:%" PRId64 " < msg startTime:%" PRId64 " ignore",
|
||||||
pReceiver->startTime, pMsg->startTime);
|
pReceiver->startTime, pMsg->startTime);
|
||||||
return 0;
|
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||||
|
code = terrno;
|
||||||
|
goto _SEND_REPLY;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// start new
|
// start new
|
||||||
sRInfo(pReceiver, "snapshot receiver not start yet so start new one");
|
sRInfo(pReceiver, "snapshot receiver not start yet so start new one");
|
||||||
|
@ -612,7 +577,8 @@ _START_RECEIVER:
|
||||||
if (timeNow - pMsg->startTime > SNAPSHOT_MAX_CLOCK_SKEW_MS) {
|
if (timeNow - pMsg->startTime > SNAPSHOT_MAX_CLOCK_SKEW_MS) {
|
||||||
sRError(pReceiver, "snapshot receiver time skew too much, now:%" PRId64 " msg startTime:%" PRId64, timeNow,
|
sRError(pReceiver, "snapshot receiver time skew too much, now:%" PRId64 " msg startTime:%" PRId64, timeNow,
|
||||||
pMsg->startTime);
|
pMsg->startTime);
|
||||||
return -1;
|
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||||
|
code = terrno;
|
||||||
} else {
|
} else {
|
||||||
// waiting for clock match
|
// waiting for clock match
|
||||||
while (timeNow < pMsg->startTime) {
|
while (timeNow < pMsg->startTime) {
|
||||||
|
@ -648,7 +614,7 @@ _SEND_REPLY:
|
||||||
pRspMsg->lastTerm = pMsg->lastTerm;
|
pRspMsg->lastTerm = pMsg->lastTerm;
|
||||||
pRspMsg->startTime = pReceiver->startTime;
|
pRspMsg->startTime = pReceiver->startTime;
|
||||||
pRspMsg->ack = pMsg->seq; // receiver maybe already closed
|
pRspMsg->ack = pMsg->seq; // receiver maybe already closed
|
||||||
pRspMsg->code = 0;
|
pRspMsg->code = code;
|
||||||
pRspMsg->snapBeginIndex = syncNodeGetSnapBeginIndex(pSyncNode);
|
pRspMsg->snapBeginIndex = syncNodeGetSnapBeginIndex(pSyncNode);
|
||||||
|
|
||||||
// send msg
|
// send msg
|
||||||
|
@ -658,26 +624,36 @@ _SEND_REPLY:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t syncNodeOnSnapshotBegin(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
|
static int32_t syncNodeOnSnapshotBegin(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
|
||||||
// condition 1
|
// condition 1
|
||||||
SSyncSnapshotReceiver *pReceiver = pSyncNode->pNewNodeReceiver;
|
SSyncSnapshotReceiver *pReceiver = pSyncNode->pNewNodeReceiver;
|
||||||
|
int32_t code = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||||
|
|
||||||
if (!snapshotReceiverIsStart(pReceiver)) {
|
if (!snapshotReceiverIsStart(pReceiver)) {
|
||||||
sRError(pReceiver, "snapshot receiver not start");
|
sRError(pReceiver, "snapshot receiver begin failed since not start");
|
||||||
return -1;
|
goto _SEND_REPLY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pReceiver->startTime != pMsg->startTime) {
|
if (pReceiver->startTime != pMsg->startTime) {
|
||||||
sRError(pReceiver, "snapshot receiver startTime:%" PRId64 " not equal to msg startTime:%" PRId64,
|
sRError(pReceiver, "snapshot receiver begin failed since startTime:%" PRId64 " not equal to msg startTime:%" PRId64,
|
||||||
pReceiver->startTime, pMsg->startTime);
|
pReceiver->startTime, pMsg->startTime);
|
||||||
return -1;
|
goto _SEND_REPLY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// start writer
|
// start writer
|
||||||
snapshotReceiverStartWriter(pReceiver, pMsg);
|
if (snapshotReceiverStartWriter(pReceiver, pMsg) != 0) {
|
||||||
|
sRError(pReceiver, "snapshot receiver begin failed since start writer failed");
|
||||||
|
goto _SEND_REPLY;
|
||||||
|
}
|
||||||
|
|
||||||
|
code = 0;
|
||||||
|
_SEND_REPLY:
|
||||||
|
if (code != 0 && terrno != 0) {
|
||||||
|
code = terrno;
|
||||||
|
}
|
||||||
|
|
||||||
// build msg
|
// build msg
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg rpcMsg = {0};
|
||||||
|
@ -694,7 +670,7 @@ static int32_t syncNodeOnSnapshotBegin(SSyncNode *pSyncNode, SyncSnapshotSend *p
|
||||||
pRspMsg->lastTerm = pMsg->lastTerm;
|
pRspMsg->lastTerm = pMsg->lastTerm;
|
||||||
pRspMsg->startTime = pReceiver->startTime;
|
pRspMsg->startTime = pReceiver->startTime;
|
||||||
pRspMsg->ack = pReceiver->ack; // receiver maybe already closed
|
pRspMsg->ack = pReceiver->ack; // receiver maybe already closed
|
||||||
pRspMsg->code = 0;
|
pRspMsg->code = code;
|
||||||
pRspMsg->snapBeginIndex = pReceiver->snapshotParam.start;
|
pRspMsg->snapBeginIndex = pReceiver->snapshotParam.start;
|
||||||
|
|
||||||
// send msg
|
// send msg
|
||||||
|
@ -704,10 +680,10 @@ static int32_t syncNodeOnSnapshotBegin(SSyncNode *pSyncNode, SyncSnapshotSend *p
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t syncNodeOnSnapshotTransfering(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
|
static int32_t syncNodeOnSnapshotReceive(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
|
||||||
// condition 4
|
// condition 4
|
||||||
// transfering
|
// transfering
|
||||||
SSyncSnapshotReceiver *pReceiver = pSyncNode->pNewNodeReceiver;
|
SSyncSnapshotReceiver *pReceiver = pSyncNode->pNewNodeReceiver;
|
||||||
|
@ -721,8 +697,12 @@ static int32_t syncNodeOnSnapshotTransfering(SSyncNode *pSyncNode, SyncSnapshotS
|
||||||
timeNow = taosGetTimestampMs();
|
timeNow = taosGetTimestampMs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t code = 0;
|
||||||
if (snapshotReceiverGotData(pReceiver, pMsg) != 0) {
|
if (snapshotReceiverGotData(pReceiver, pMsg) != 0) {
|
||||||
return -1;
|
code = terrno;
|
||||||
|
if (code >= SYNC_SNAPSHOT_SEQ_INVALID) {
|
||||||
|
code = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// build msg
|
// build msg
|
||||||
|
@ -740,17 +720,17 @@ static int32_t syncNodeOnSnapshotTransfering(SSyncNode *pSyncNode, SyncSnapshotS
|
||||||
pRspMsg->lastTerm = pMsg->lastTerm;
|
pRspMsg->lastTerm = pMsg->lastTerm;
|
||||||
pRspMsg->startTime = pReceiver->startTime;
|
pRspMsg->startTime = pReceiver->startTime;
|
||||||
pRspMsg->ack = pReceiver->ack; // receiver maybe already closed
|
pRspMsg->ack = pReceiver->ack; // receiver maybe already closed
|
||||||
pRspMsg->code = 0;
|
pRspMsg->code = code;
|
||||||
pRspMsg->snapBeginIndex = pReceiver->snapshotParam.start;
|
pRspMsg->snapBeginIndex = pReceiver->snapshotParam.start;
|
||||||
|
|
||||||
// send msg
|
// send msg
|
||||||
syncLogSendSyncSnapshotRsp(pSyncNode, pRspMsg, "snapshot receiver receiving");
|
syncLogSendSyncSnapshotRsp(pSyncNode, pRspMsg, "snapshot receiver received");
|
||||||
if (syncNodeSendMsgById(&pRspMsg->destId, pSyncNode, &rpcMsg) != 0) {
|
if (syncNodeSendMsgById(&pRspMsg->destId, pSyncNode, &rpcMsg) != 0) {
|
||||||
sRError(pReceiver, "snapshot receiver send resp failed since %s", terrstr());
|
sRError(pReceiver, "snapshot receiver send resp failed since %s", terrstr());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t syncNodeOnSnapshotEnd(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
|
static int32_t syncNodeOnSnapshotEnd(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
|
||||||
|
@ -787,7 +767,7 @@ static int32_t syncNodeOnSnapshotEnd(SSyncNode *pSyncNode, SyncSnapshotSend *pMs
|
||||||
pRspMsg->lastTerm = pMsg->lastTerm;
|
pRspMsg->lastTerm = pMsg->lastTerm;
|
||||||
pRspMsg->startTime = pReceiver->startTime;
|
pRspMsg->startTime = pReceiver->startTime;
|
||||||
pRspMsg->ack = pReceiver->ack; // receiver maybe already closed
|
pRspMsg->ack = pReceiver->ack; // receiver maybe already closed
|
||||||
pRspMsg->code = 0;
|
pRspMsg->code = code;
|
||||||
pRspMsg->snapBeginIndex = pReceiver->snapshotParam.start;
|
pRspMsg->snapBeginIndex = pReceiver->snapshotParam.start;
|
||||||
|
|
||||||
// send msg
|
// send msg
|
||||||
|
@ -797,7 +777,7 @@ static int32_t syncNodeOnSnapshotEnd(SSyncNode *pSyncNode, SyncSnapshotSend *pMs
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
// receiver on message
|
// receiver on message
|
||||||
|
@ -827,12 +807,14 @@ int32_t syncNodeOnSnapshot(SSyncNode *pSyncNode, const SRpcMsg *pRpcMsg) {
|
||||||
// if already drop replica, do not process
|
// if already drop replica, do not process
|
||||||
if (!syncNodeInRaftGroup(pSyncNode, &pMsg->srcId)) {
|
if (!syncNodeInRaftGroup(pSyncNode, &pMsg->srcId)) {
|
||||||
syncLogRecvSyncSnapshotSend(pSyncNode, pMsg, "not in my config");
|
syncLogRecvSyncSnapshotSend(pSyncNode, pMsg, "not in my config");
|
||||||
return 0;
|
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pMsg->term < pSyncNode->pRaftStore->currentTerm) {
|
if (pMsg->term < pSyncNode->pRaftStore->currentTerm) {
|
||||||
syncLogRecvSyncSnapshotSend(pSyncNode, pMsg, "reject since small term");
|
syncLogRecvSyncSnapshotSend(pSyncNode, pMsg, "reject since small term");
|
||||||
return 0;
|
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pMsg->term > pSyncNode->pRaftStore->currentTerm) {
|
if (pMsg->term > pSyncNode->pRaftStore->currentTerm) {
|
||||||
|
@ -841,56 +823,49 @@ int32_t syncNodeOnSnapshot(SSyncNode *pSyncNode, const SRpcMsg *pRpcMsg) {
|
||||||
syncNodeResetElectTimer(pSyncNode);
|
syncNodeResetElectTimer(pSyncNode);
|
||||||
|
|
||||||
// state, term, seq/ack
|
// state, term, seq/ack
|
||||||
|
int32_t code = 0;
|
||||||
if (pSyncNode->state == TAOS_SYNC_STATE_FOLLOWER) {
|
if (pSyncNode->state == TAOS_SYNC_STATE_FOLLOWER) {
|
||||||
if (pMsg->term == pSyncNode->pRaftStore->currentTerm) {
|
if (pMsg->term == pSyncNode->pRaftStore->currentTerm) {
|
||||||
if (pMsg->seq == SYNC_SNAPSHOT_SEQ_PRE_SNAPSHOT) {
|
if (pMsg->seq == SYNC_SNAPSHOT_SEQ_PRE_SNAPSHOT) {
|
||||||
syncLogRecvSyncSnapshotSend(pSyncNode, pMsg, "process seq pre-snapshot");
|
syncLogRecvSyncSnapshotSend(pSyncNode, pMsg, "process seq pre-snapshot");
|
||||||
syncNodeOnSnapshotPre(pSyncNode, pMsg);
|
code = syncNodeOnSnapshotPre(pSyncNode, pMsg);
|
||||||
} else if (pMsg->seq == SYNC_SNAPSHOT_SEQ_BEGIN) {
|
} else if (pMsg->seq == SYNC_SNAPSHOT_SEQ_BEGIN) {
|
||||||
syncLogRecvSyncSnapshotSend(pSyncNode, pMsg, "process seq begin");
|
syncLogRecvSyncSnapshotSend(pSyncNode, pMsg, "process seq begin");
|
||||||
syncNodeOnSnapshotBegin(pSyncNode, pMsg);
|
code = syncNodeOnSnapshotBegin(pSyncNode, pMsg);
|
||||||
} else if (pMsg->seq == SYNC_SNAPSHOT_SEQ_END) {
|
} else if (pMsg->seq == SYNC_SNAPSHOT_SEQ_END) {
|
||||||
syncLogRecvSyncSnapshotSend(pSyncNode, pMsg, "process seq end");
|
syncLogRecvSyncSnapshotSend(pSyncNode, pMsg, "process seq end");
|
||||||
syncNodeOnSnapshotEnd(pSyncNode, pMsg);
|
code = syncNodeOnSnapshotEnd(pSyncNode, pMsg);
|
||||||
if (syncLogBufferReInit(pSyncNode->pLogBuf, pSyncNode) != 0) {
|
if (syncLogBufferReInit(pSyncNode->pLogBuf, pSyncNode) != 0) {
|
||||||
sRError(pReceiver, "failed to reinit log buffer since %s", terrstr());
|
sRError(pReceiver, "failed to reinit log buffer since %s", terrstr());
|
||||||
return -1;
|
code = -1;
|
||||||
}
|
}
|
||||||
} else if (pMsg->seq == SYNC_SNAPSHOT_SEQ_FORCE_CLOSE) {
|
} else if (pMsg->seq == SYNC_SNAPSHOT_SEQ_FORCE_CLOSE) {
|
||||||
// force close, no response
|
// force close, no response
|
||||||
syncLogRecvSyncSnapshotSend(pSyncNode, pMsg, "process force stop");
|
syncLogRecvSyncSnapshotSend(pSyncNode, pMsg, "process force stop");
|
||||||
snapshotReceiverForceStop(pReceiver);
|
snapshotReceiverForceStop(pReceiver);
|
||||||
} else if (pMsg->seq > SYNC_SNAPSHOT_SEQ_BEGIN && pMsg->seq < SYNC_SNAPSHOT_SEQ_END) {
|
} else if (pMsg->seq > SYNC_SNAPSHOT_SEQ_BEGIN && pMsg->seq < SYNC_SNAPSHOT_SEQ_END) {
|
||||||
syncLogRecvSyncSnapshotSend(pSyncNode, pMsg, "process seq");
|
syncLogRecvSyncSnapshotSend(pSyncNode, pMsg, "process seq data");
|
||||||
syncNodeOnSnapshotTransfering(pSyncNode, pMsg);
|
code = syncNodeOnSnapshotReceive(pSyncNode, pMsg);
|
||||||
} else {
|
} else {
|
||||||
// error log
|
// error log
|
||||||
sRError(pReceiver, "snapshot receiver recv error seq:%d, my ack:%d", pMsg->seq, pReceiver->ack);
|
sRError(pReceiver, "snapshot receiver recv error seq:%d, my ack:%d", pMsg->seq, pReceiver->ack);
|
||||||
return -1;
|
code = -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// error log
|
// error log
|
||||||
sRError(pReceiver, "snapshot receiver term not equal");
|
sRError(pReceiver, "snapshot receiver term not equal");
|
||||||
return -1;
|
code = -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// error log
|
// error log
|
||||||
sRError(pReceiver, "snapshot receiver not follower");
|
sRError(pReceiver, "snapshot receiver not follower");
|
||||||
return -1;
|
code = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncNodeOnSnapshotReplyPre(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg) {
|
static int32_t syncNodeOnSnapshotPreRsp(SSyncNode *pSyncNode, SSyncSnapshotSender *pSender, SyncSnapshotRsp *pMsg) {
|
||||||
// get sender
|
|
||||||
SSyncSnapshotSender *pSender = syncNodeGetSnapshotSender(pSyncNode, &(pMsg->srcId));
|
|
||||||
if (pSender == NULL) {
|
|
||||||
sNError(pSyncNode, "prepare snapshot error since sender is null");
|
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SSnapshot snapshot = {0};
|
SSnapshot snapshot = {0};
|
||||||
pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot);
|
pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot);
|
||||||
|
|
||||||
|
@ -912,7 +887,7 @@ int32_t syncNodeOnSnapshotReplyPre(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg)
|
||||||
pSender->snapshot = snapshot;
|
pSender->snapshot = snapshot;
|
||||||
|
|
||||||
// start reader
|
// start reader
|
||||||
int32_t code = pSyncNode->pFsm->FpSnapshotStartRead(pSyncNode->pFsm, &(pSender->snapshotParam), &(pSender->pReader));
|
int32_t code = pSyncNode->pFsm->FpSnapshotStartRead(pSyncNode->pFsm, &pSender->snapshotParam, &pSender->pReader);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
sSError(pSender, "prepare snapshot failed since %s", terrstr());
|
sSError(pSender, "prepare snapshot failed since %s", terrstr());
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -933,7 +908,7 @@ int32_t syncNodeOnSnapshotReplyPre(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg)
|
||||||
|
|
||||||
SyncSnapshotSend *pSendMsg = rpcMsg.pCont;
|
SyncSnapshotSend *pSendMsg = rpcMsg.pCont;
|
||||||
pSendMsg->srcId = pSender->pSyncNode->myRaftId;
|
pSendMsg->srcId = pSender->pSyncNode->myRaftId;
|
||||||
pSendMsg->destId = (pSender->pSyncNode->replicasId)[pSender->replicaIndex];
|
pSendMsg->destId = pSender->pSyncNode->replicasId[pSender->replicaIndex];
|
||||||
pSendMsg->term = pSender->pSyncNode->pRaftStore->currentTerm;
|
pSendMsg->term = pSender->pSyncNode->pRaftStore->currentTerm;
|
||||||
pSendMsg->beginIndex = pSender->snapshotParam.start;
|
pSendMsg->beginIndex = pSender->snapshotParam.start;
|
||||||
pSendMsg->lastIndex = pSender->snapshot.lastApplyIndex;
|
pSendMsg->lastIndex = pSender->snapshot.lastApplyIndex;
|
||||||
|
@ -963,8 +938,9 @@ int32_t syncNodeOnSnapshotRsp(SSyncNode *pSyncNode, const SRpcMsg *pRpcMsg) {
|
||||||
SyncSnapshotRsp *pMsg = pRpcMsg->pCont;
|
SyncSnapshotRsp *pMsg = pRpcMsg->pCont;
|
||||||
|
|
||||||
// if already drop replica, do not process
|
// if already drop replica, do not process
|
||||||
if (!syncNodeInRaftGroup(pSyncNode, &(pMsg->srcId))) {
|
if (!syncNodeInRaftGroup(pSyncNode, &pMsg->srcId)) {
|
||||||
syncLogRecvSyncSnapshotRsp(pSyncNode, pMsg, "maybe replica already dropped");
|
syncLogRecvSyncSnapshotRsp(pSyncNode, pMsg, "maybe replica already dropped");
|
||||||
|
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -976,76 +952,96 @@ int32_t syncNodeOnSnapshotRsp(SSyncNode *pSyncNode, const SRpcMsg *pRpcMsg) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pMsg->startTime != pSender->startTime) {
|
// state, term, seq/ack
|
||||||
syncLogRecvSyncSnapshotRsp(pSyncNode, pMsg, "sender:% " PRId64 " receiver:%" PRId64 " time not match");
|
if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) {
|
||||||
return -1;
|
syncLogRecvSyncSnapshotRsp(pSyncNode, pMsg, "snapshot sender not leader");
|
||||||
|
sSError(pSender, "snapshot sender not leader");
|
||||||
|
terrno = TSDB_CODE_SYN_NOT_LEADER;
|
||||||
|
goto _ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// state, term, seq/ack
|
if (pMsg->startTime != pSender->startTime) {
|
||||||
if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) {
|
syncLogRecvSyncSnapshotRsp(pSyncNode, pMsg, "snapshot sender and receiver time not match");
|
||||||
if (pMsg->term == pSyncNode->pRaftStore->currentTerm) {
|
sSError(pSender, "sender:%" PRId64 " receiver:%" PRId64 " time not match, code:0x%x", pMsg->startTime,
|
||||||
// prepare <begin, end>, send begin msg
|
pSender->startTime, pMsg->code);
|
||||||
if (pMsg->ack == SYNC_SNAPSHOT_SEQ_PRE_SNAPSHOT) {
|
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||||
syncLogRecvSyncSnapshotRsp(pSyncNode, pMsg, "process seq pre-snapshot");
|
goto _ERROR;
|
||||||
syncNodeOnSnapshotReplyPre(pSyncNode, pMsg);
|
}
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pMsg->ack == SYNC_SNAPSHOT_SEQ_BEGIN) {
|
if (pMsg->term != pSyncNode->pRaftStore->currentTerm) {
|
||||||
syncLogRecvSyncSnapshotRsp(pSyncNode, pMsg, "process seq begin");
|
syncLogRecvSyncSnapshotRsp(pSyncNode, pMsg, "snapshot sender and receiver term not match");
|
||||||
if (snapshotSenderUpdateProgress(pSender, pMsg) != 0) {
|
sSError(pSender, "snapshot sender term not equal, msg term:%" PRId64 " currentTerm:%" PRId64, pMsg->term,
|
||||||
return -1;
|
pSyncNode->pRaftStore->currentTerm);
|
||||||
}
|
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||||
|
goto _ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
if (snapshotSend(pSender) != 0) {
|
if (pMsg->code != 0) {
|
||||||
return -1;
|
syncLogRecvSyncSnapshotRsp(pSyncNode, pMsg, "receive error code");
|
||||||
}
|
sSError(pSender, "snapshot sender receive error code:0x%x and stop sender", pMsg->code);
|
||||||
return 0;
|
terrno = pMsg->code;
|
||||||
}
|
goto _ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
// receive ack is finish, close sender
|
// prepare <begin, end>, send begin msg
|
||||||
if (pMsg->ack == SYNC_SNAPSHOT_SEQ_END) {
|
if (pMsg->ack == SYNC_SNAPSHOT_SEQ_PRE_SNAPSHOT) {
|
||||||
syncLogRecvSyncSnapshotRsp(pSyncNode, pMsg, "process seq end");
|
syncLogRecvSyncSnapshotRsp(pSyncNode, pMsg, "process seq pre-snapshot");
|
||||||
snapshotSenderStop(pSender, true);
|
return syncNodeOnSnapshotPreRsp(pSyncNode, pSender, pMsg);
|
||||||
SSyncLogReplMgr *pMgr = syncNodeGetLogReplMgr(pSyncNode, &pMsg->srcId);
|
}
|
||||||
if (pMgr) {
|
|
||||||
syncLogRecvSyncSnapshotRsp(pSyncNode, pMsg, "reset repl mgr");
|
|
||||||
syncLogReplMgrReset(pMgr);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// send next msg
|
if (pMsg->ack == SYNC_SNAPSHOT_SEQ_BEGIN) {
|
||||||
if (pMsg->ack == pSender->seq) {
|
syncLogRecvSyncSnapshotRsp(pSyncNode, pMsg, "process seq begin");
|
||||||
syncLogRecvSyncSnapshotRsp(pSyncNode, pMsg, "process seq");
|
if (snapshotSenderUpdateProgress(pSender, pMsg) != 0) {
|
||||||
// update sender ack
|
return -1;
|
||||||
if (snapshotSenderUpdateProgress(pSender, pMsg) != 0) {
|
}
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (snapshotSend(pSender) != 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (pMsg->ack == pSender->seq - 1) {
|
if (snapshotSend(pSender) != 0) {
|
||||||
// maybe resend
|
return -1;
|
||||||
syncLogRecvSyncSnapshotRsp(pSyncNode, pMsg, "process seq and resend");
|
}
|
||||||
snapshotReSend(pSender);
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
// receive ack is finish, close sender
|
||||||
// error log
|
if (pMsg->ack == SYNC_SNAPSHOT_SEQ_END) {
|
||||||
sSError(pSender, "snapshot sender recv error ack:%d, my seq:%d", pMsg->ack, pSender->seq);
|
syncLogRecvSyncSnapshotRsp(pSyncNode, pMsg, "process seq end");
|
||||||
return -1;
|
snapshotSenderStop(pSender, true);
|
||||||
}
|
SSyncLogReplMgr *pMgr = syncNodeGetLogReplMgr(pSyncNode, &pMsg->srcId);
|
||||||
} else {
|
syncLogReplMgrReset(pMgr);
|
||||||
// error log
|
return 0;
|
||||||
sSError(pSender, "snapshot sender term not equal");
|
}
|
||||||
|
|
||||||
|
// send next msg
|
||||||
|
if (pMsg->ack == pSender->seq) {
|
||||||
|
syncLogRecvSyncSnapshotRsp(pSyncNode, pMsg, "process seq data");
|
||||||
|
// update sender ack
|
||||||
|
if (snapshotSenderUpdateProgress(pSender, pMsg) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (snapshotSend(pSender) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} else if (pMsg->ack == pSender->seq - 1) {
|
||||||
|
// maybe resend
|
||||||
|
syncLogRecvSyncSnapshotRsp(pSyncNode, pMsg, "process seq and resend");
|
||||||
|
if (snapshotReSend(pSender) != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// error log
|
// error log
|
||||||
sSError(pSender, "snapshot sender not leader");
|
syncLogRecvSyncSnapshotRsp(pSyncNode, pMsg, "receive error ack");
|
||||||
|
sSError(pSender, "snapshot sender receive error ack:%d, my seq:%d", pMsg->ack, pSender->seq);
|
||||||
|
snapshotSenderStop(pSender, true);
|
||||||
|
SSyncLogReplMgr *pMgr = syncNodeGetLogReplMgr(pSyncNode, &pMsg->srcId);
|
||||||
|
syncLogReplMgrReset(pMgr);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
_ERROR:
|
||||||
|
snapshotSenderStop(pSender, true);
|
||||||
|
SSyncLogReplMgr *pMgr = syncNodeGetLogReplMgr(pSyncNode, &pMsg->srcId);
|
||||||
|
syncLogReplMgrReset(pMgr);
|
||||||
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -869,11 +869,19 @@ static int tdbPagerRestore(SPager *pPager, const char *jFileName) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tdbOsLSeek(jfd, 0L, SEEK_SET) < 0) {
|
||||||
|
tdbError("failed to lseek jfd due to %s. file:%s, offset:0", strerror(errno), pPager->dbFileName);
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
pageBuf = tdbOsCalloc(1, pPager->pageSize);
|
pageBuf = tdbOsCalloc(1, pPager->pageSize);
|
||||||
if (pageBuf == NULL) {
|
if (pageBuf == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tdbDebug("pager/restore: %p, %d/%d, txnId:%s", pPager, pPager->dbOrigSize, pPager->dbFileSize, jFileName);
|
||||||
|
|
||||||
for (int pgIndex = 0; pgIndex < journalSize; ++pgIndex) {
|
for (int pgIndex = 0; pgIndex < journalSize; ++pgIndex) {
|
||||||
// read pgno & the page from journal
|
// read pgno & the page from journal
|
||||||
SPgno pgno;
|
SPgno pgno;
|
||||||
|
@ -884,6 +892,8 @@ static int tdbPagerRestore(SPager *pPager, const char *jFileName) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tdbTrace("pager/restore: restore pgno:%d,", pgno);
|
||||||
|
|
||||||
ret = tdbOsRead(jfd, pageBuf, pPager->pageSize);
|
ret = tdbOsRead(jfd, pageBuf, pPager->pageSize);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
tdbOsFree(pageBuf);
|
tdbOsFree(pageBuf);
|
||||||
|
@ -923,7 +933,7 @@ static int tdbPagerRestore(SPager *pPager, const char *jFileName) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tdbOsRemove(pPager->jFileName) < 0 && errno != ENOENT) {
|
if (tdbOsRemove(jFileName) < 0 && errno != ENOENT) {
|
||||||
tdbError("failed to remove file due to %s. jFileName:%s", strerror(errno), pPager->jFileName);
|
tdbError("failed to remove file due to %s. jFileName:%s", strerror(errno), pPager->jFileName);
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -943,7 +953,12 @@ int tdbPagerRestoreJournals(SPager *pPager) {
|
||||||
while ((pDirEntry = tdbReadDir(pDir)) != NULL) {
|
while ((pDirEntry = tdbReadDir(pDir)) != NULL) {
|
||||||
char *name = tdbDirEntryBaseName(tdbGetDirEntryName(pDirEntry));
|
char *name = tdbDirEntryBaseName(tdbGetDirEntryName(pDirEntry));
|
||||||
if (strncmp(TDB_MAINDB_NAME "-journal", name, 16) == 0) {
|
if (strncmp(TDB_MAINDB_NAME "-journal", name, 16) == 0) {
|
||||||
if (tdbPagerRestore(pPager, name) < 0) {
|
char jname[TD_PATH_MAX] = {0};
|
||||||
|
int dirLen = strlen(pPager->pEnv->dbName);
|
||||||
|
memcpy(jname, pPager->pEnv->dbName, dirLen);
|
||||||
|
jname[dirLen] = '/';
|
||||||
|
memcpy(jname + dirLen + 1, name, strlen(name));
|
||||||
|
if (tdbPagerRestore(pPager, jname) < 0) {
|
||||||
tdbCloseDir(&pDir);
|
tdbCloseDir(&pDir);
|
||||||
|
|
||||||
tdbError("failed to restore file due to %s. jFileName:%s", strerror(errno), name);
|
tdbError("failed to restore file due to %s. jFileName:%s", strerror(errno), name);
|
||||||
|
@ -969,7 +984,12 @@ int tdbPagerRollback(SPager *pPager) {
|
||||||
char *name = tdbDirEntryBaseName(tdbGetDirEntryName(pDirEntry));
|
char *name = tdbDirEntryBaseName(tdbGetDirEntryName(pDirEntry));
|
||||||
|
|
||||||
if (strncmp(TDB_MAINDB_NAME "-journal", name, 16) == 0) {
|
if (strncmp(TDB_MAINDB_NAME "-journal", name, 16) == 0) {
|
||||||
if (tdbOsRemove(name) < 0 && errno != ENOENT) {
|
char jname[TD_PATH_MAX] = {0};
|
||||||
|
int dirLen = strlen(pPager->pEnv->dbName);
|
||||||
|
memcpy(jname, pPager->pEnv->dbName, dirLen);
|
||||||
|
jname[dirLen] = '/';
|
||||||
|
memcpy(jname + dirLen + 1, name, strlen(name));
|
||||||
|
if (tdbOsRemove(jname) < 0 && errno != ENOENT) {
|
||||||
tdbCloseDir(&pDir);
|
tdbCloseDir(&pDir);
|
||||||
|
|
||||||
tdbError("failed to remove file due to %s. jFileName:%s", strerror(errno), name);
|
tdbError("failed to remove file due to %s. jFileName:%s", strerror(errno), name);
|
||||||
|
|
|
@ -108,13 +108,13 @@ int tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprF
|
||||||
ASSERT(pPager != NULL);
|
ASSERT(pPager != NULL);
|
||||||
|
|
||||||
if (rollback) {
|
if (rollback) {
|
||||||
tdbPagerRollback(pPager);
|
|
||||||
} else {
|
|
||||||
ret = tdbPagerRestoreJournals(pPager);
|
ret = tdbPagerRestoreJournals(pPager);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
tdbOsFree(pTb);
|
tdbOsFree(pTb);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
tdbPagerRollback(pPager);
|
||||||
}
|
}
|
||||||
|
|
||||||
// pTb->pBt
|
// pTb->pBt
|
||||||
|
|
|
@ -1665,11 +1665,20 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) {
|
||||||
if (pCtx->retryCode != TSDB_CODE_SUCCESS) {
|
if (pCtx->retryCode != TSDB_CODE_SUCCESS) {
|
||||||
int32_t code = pResp->code;
|
int32_t code = pResp->code;
|
||||||
// return internal code app
|
// return internal code app
|
||||||
if (code == TSDB_CODE_RPC_NETWORK_UNAVAIL || code == TSDB_CODE_RPC_BROKEN_LINK) {
|
if (code == TSDB_CODE_RPC_NETWORK_UNAVAIL || code == TSDB_CODE_RPC_BROKEN_LINK || code == TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED) {
|
||||||
pResp->code = pCtx->retryCode;
|
pResp->code = pCtx->retryCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check whole vnodes is offline on this vgroup
|
||||||
|
if (pCtx->epsetRetryCnt >= pCtx->epSet.numOfEps || pCtx->retryStep > 0) {
|
||||||
|
if (pResp->code == TSDB_CODE_RPC_NETWORK_UNAVAIL) {
|
||||||
|
pResp->code = TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED;
|
||||||
|
} else if (pResp->code == TSDB_CODE_RPC_BROKEN_LINK) {
|
||||||
|
pResp->code = TSDB_CODE_RPC_SOMENODE_BROKEN_LINK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
STraceId* trace = &pResp->info.traceId;
|
STraceId* trace = &pResp->info.traceId;
|
||||||
bool hasEpSet = cliTryExtractEpSet(pResp, &pCtx->epSet);
|
bool hasEpSet = cliTryExtractEpSet(pResp, &pCtx->epSet);
|
||||||
if (hasEpSet) {
|
if (hasEpSet) {
|
||||||
|
|
|
@ -1001,6 +1001,13 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads,
|
||||||
uv_loop_init(srv->loop);
|
uv_loop_init(srv->loop);
|
||||||
|
|
||||||
char pipeName[PATH_MAX];
|
char pipeName[PATH_MAX];
|
||||||
|
|
||||||
|
if (false == taosValidIpAndPort(srv->ip, srv->port)) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
tError("invalid ip/port, %d:%d, reason:%s", srv->ip, srv->port, terrstr());
|
||||||
|
goto End;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(WINDOWS) || defined(DARWIN)
|
#if defined(WINDOWS) || defined(DARWIN)
|
||||||
int ret = uv_pipe_init(srv->loop, &srv->pipeListen, 0);
|
int ret = uv_pipe_init(srv->loop, &srv->pipeListen, 0);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
|
@ -1087,12 +1094,6 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (false == taosValidIpAndPort(srv->ip, srv->port)) {
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
tError("invalid ip/port, %d:%d, reason:%s", srv->ip, srv->port, terrstr());
|
|
||||||
goto End;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (false == addHandleToAcceptloop(srv)) {
|
if (false == addHandleToAcceptloop(srv)) {
|
||||||
goto End;
|
goto End;
|
||||||
}
|
}
|
||||||
|
@ -1185,8 +1186,8 @@ void transCloseServer(void* arg) {
|
||||||
// impl later
|
// impl later
|
||||||
SServerObj* srv = arg;
|
SServerObj* srv = arg;
|
||||||
|
|
||||||
tDebug("send quit msg to accept thread");
|
|
||||||
if (srv->inited) {
|
if (srv->inited) {
|
||||||
|
tDebug("send quit msg to accept thread");
|
||||||
uv_async_send(srv->pAcceptAsync);
|
uv_async_send(srv->pAcceptAsync);
|
||||||
taosThreadJoin(srv->thread, NULL);
|
taosThreadJoin(srv->thread, NULL);
|
||||||
SRV_RELEASE_UV(srv->loop);
|
SRV_RELEASE_UV(srv->loop);
|
||||||
|
|
|
@ -44,6 +44,10 @@ if(TD_WINDOWS)
|
||||||
os PUBLIC ws2_32 iconv msvcregex wcwidth winmm crashdump
|
os PUBLIC ws2_32 iconv msvcregex wcwidth winmm crashdump
|
||||||
)
|
)
|
||||||
elseif(TD_DARWIN_64)
|
elseif(TD_DARWIN_64)
|
||||||
|
find_library(CORE_FOUNDATION_FRAMEWORK CoreFoundation)
|
||||||
|
target_link_libraries(os PUBLIC ${CORE_FOUNDATION_FRAMEWORK})
|
||||||
|
find_library(SYSTEM_CONFIGURATION_FRAMEWORK SystemConfiguration)
|
||||||
|
target_link_libraries(os PUBLIC ${SYSTEM_CONFIGURATION_FRAMEWORK})
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
os PUBLIC dl m iconv
|
os PUBLIC dl m iconv
|
||||||
)
|
)
|
||||||
|
|
|
@ -988,7 +988,7 @@ int32_t taosGetFqdn(char *fqdn) {
|
||||||
#endif
|
#endif
|
||||||
char hostname[1024];
|
char hostname[1024];
|
||||||
hostname[1023] = '\0';
|
hostname[1023] = '\0';
|
||||||
if (gethostname(hostname, 1023) == -1) {
|
if (taosGetlocalhostname(hostname, 1023) == -1) {
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
printf("failed to get hostname, reason:%s\n", strerror(WSAGetLastError()));
|
printf("failed to get hostname, reason:%s\n", strerror(WSAGetLastError()));
|
||||||
#else
|
#else
|
||||||
|
@ -998,30 +998,28 @@ int32_t taosGetFqdn(char *fqdn) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct addrinfo hints = {0};
|
|
||||||
struct addrinfo *result = NULL;
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
// on macosx, hostname -f has the form of xxx.local
|
// on macosx, hostname -f has the form of xxx.local
|
||||||
// which will block getaddrinfo for a few seconds if AI_CANONNAME is set
|
// which will block getaddrinfo for a few seconds if AI_CANONNAME is set
|
||||||
// thus, we choose AF_INET (ipv4 for the moment) to make getaddrinfo return
|
// thus, we choose AF_INET (ipv4 for the moment) to make getaddrinfo return
|
||||||
// immediately
|
// immediately
|
||||||
hints.ai_family = AF_INET;
|
// hints.ai_family = AF_INET;
|
||||||
|
strcpy(fqdn, hostname);
|
||||||
|
strcpy(fqdn+strlen(hostname), ".local");
|
||||||
#else // __APPLE__
|
#else // __APPLE__
|
||||||
|
struct addrinfo hints = {0};
|
||||||
|
struct addrinfo *result = NULL;
|
||||||
hints.ai_flags = AI_CANONNAME;
|
hints.ai_flags = AI_CANONNAME;
|
||||||
#endif // __APPLE__
|
|
||||||
int32_t ret = getaddrinfo(hostname, NULL, &hints, &result);
|
int32_t ret = getaddrinfo(hostname, NULL, &hints, &result);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
fprintf(stderr, "failed to get fqdn, code:%d, reason:%s\n", ret, gai_strerror(ret));
|
fprintf(stderr, "failed to get fqdn, code:%d, reason:%s\n", ret, gai_strerror(ret));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
// refer to comments above
|
|
||||||
strcpy(fqdn, hostname);
|
|
||||||
#else // __APPLE__
|
|
||||||
strcpy(fqdn, result->ai_canonname);
|
strcpy(fqdn, result->ai_canonname);
|
||||||
#endif // __APPLE__
|
|
||||||
freeaddrinfo(result);
|
freeaddrinfo(result);
|
||||||
|
#endif // __APPLE__
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,6 +98,9 @@ LONG WINAPI exceptionHandler(LPEXCEPTION_POINTERS exception);
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <libproc.h>
|
#include <libproc.h>
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
|
#include <SystemConfiguration/SCDynamicStoreCopySpecific.h>
|
||||||
|
#include <CoreFoundation/CFString.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
@ -1007,6 +1010,11 @@ SysNameInfo taosGetSysNameInfo() {
|
||||||
tstrncpy(info.machine, uts.machine, sizeof(info.machine));
|
tstrncpy(info.machine, uts.machine, sizeof(info.machine));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char localHostName[512];
|
||||||
|
taosGetlocalhostname(localHostName, 512);
|
||||||
|
TdCmdPtr pCmd = taosOpenCmd("scutil --get LocalHostName");
|
||||||
|
tstrncpy(info.nodename, localHostName, sizeof(info.nodename));
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
#else
|
#else
|
||||||
SysNameInfo info = {0};
|
SysNameInfo info = {0};
|
||||||
|
@ -1042,3 +1050,46 @@ bool taosCheckCurrentInDll() {
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _TD_DARWIN_64
|
||||||
|
int taosGetMaclocalhostnameByCommand(char *hostname, size_t maxLen) {
|
||||||
|
TdCmdPtr pCmd = taosOpenCmd("scutil --get LocalHostName");
|
||||||
|
if (pCmd != NULL) {
|
||||||
|
if (taosGetsCmd(pCmd, maxLen - 1, hostname) > 0) {
|
||||||
|
int len = strlen(hostname);
|
||||||
|
if (hostname[len - 1] == '\n') {
|
||||||
|
hostname[len - 1] = '\0';
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
taosCloseCmd(&pCmd);
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getMacLocalHostNameBySCD(char *hostname, size_t maxLen) {
|
||||||
|
SCDynamicStoreRef store = SCDynamicStoreCreate(NULL, CFSTR(""), NULL, NULL);
|
||||||
|
CFStringRef hostname_cfstr = SCDynamicStoreCopyLocalHostName(store);
|
||||||
|
if (hostname_cfstr != NULL) {
|
||||||
|
CFStringGetCString(hostname_cfstr, hostname, maxLen - 1, kCFStringEncodingMacRoman);
|
||||||
|
CFRelease(hostname_cfstr);
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
CFRelease(store);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int taosGetlocalhostname(char *hostname, size_t maxLen) {
|
||||||
|
#ifdef _TD_DARWIN_64
|
||||||
|
int res = getMacLocalHostNameBySCD(hostname, maxLen);
|
||||||
|
if (res != 0) {
|
||||||
|
return taosGetMaclocalhostnameByCommand(hostname, maxLen);
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
return gethostname(hostname, maxLen);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
|
@ -51,6 +51,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_RPC_FQDN_ERROR, "Unable to resolve FQD
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_RPC_PORT_EADDRINUSE, "Port already in use")
|
TAOS_DEFINE_ERROR(TSDB_CODE_RPC_PORT_EADDRINUSE, "Port already in use")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_RPC_BROKEN_LINK, "Conn is broken")
|
TAOS_DEFINE_ERROR(TSDB_CODE_RPC_BROKEN_LINK, "Conn is broken")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_RPC_TIMEOUT, "Conn read timeout")
|
TAOS_DEFINE_ERROR(TSDB_CODE_RPC_TIMEOUT, "Conn read timeout")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED, "some vnode/qnode/mnode(s) out of service")
|
||||||
|
|
||||||
//common & util
|
//common & util
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_TIME_UNSYNCED, "Client and server's time is not synchronized")
|
TAOS_DEFINE_ERROR(TSDB_CODE_TIME_UNSYNCED, "Client and server's time is not synchronized")
|
||||||
|
@ -406,6 +407,8 @@ TAOS_DEFINE_ERROR(TSDB_CODE_SYN_PROPOSE_NOT_READY, "Sync not ready for pr
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_STANDBY_NOT_READY, "Sync not ready for standby")
|
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_STANDBY_NOT_READY, "Sync not ready for standby")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_BATCH_ERROR, "Sync batch error")
|
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_BATCH_ERROR, "Sync batch error")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_RESTORING, "Sync is restoring")
|
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_RESTORING, "Sync is restoring")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_INVALID_SNAPSHOT_MSG, "Sync invalid snapshot msg")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_BUFFER_FULL, "Sync buffer is full")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_INTERNAL_ERROR, "Sync internal error")
|
TAOS_DEFINE_ERROR(TSDB_CODE_SYN_INTERNAL_ERROR, "Sync internal error")
|
||||||
|
|
||||||
//tq
|
//tq
|
||||||
|
@ -645,13 +648,10 @@ const char* tstrerror(int32_t err) {
|
||||||
// this is a system errno
|
// this is a system errno
|
||||||
if ((err & 0x00ff0000) == 0x00ff0000) {
|
if ((err & 0x00ff0000) == 0x00ff0000) {
|
||||||
int32_t code = err & 0x0000ffff;
|
int32_t code = err & 0x0000ffff;
|
||||||
if (code >= 0 && code < 36) {
|
// strerror can handle any invalid code
|
||||||
return strerror(code);
|
// invalid code return Unknown error
|
||||||
} else {
|
return strerror(code);
|
||||||
return "unknown err";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t s = 0;
|
int32_t s = 0;
|
||||||
int32_t e = sizeof(errors) / sizeof(errors[0]);
|
int32_t e = sizeof(errors) / sizeof(errors[0]);
|
||||||
|
|
||||||
|
|
|
@ -681,8 +681,8 @@
|
||||||
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/create_wrong_topic.py
|
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/create_wrong_topic.py
|
||||||
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/dropDbR3ConflictTransaction.py -N 3
|
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/dropDbR3ConflictTransaction.py -N 3
|
||||||
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/basic5.py
|
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/basic5.py
|
||||||
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/subscribeDb.py
|
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/subscribeDb.py -N 3 -n 3
|
||||||
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/subscribeDb0.py
|
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/subscribeDb0.py -N 3 -n 3
|
||||||
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/subscribeDb1.py
|
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/subscribeDb1.py
|
||||||
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/subscribeDb2.py
|
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/subscribeDb2.py
|
||||||
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/subscribeDb3.py
|
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/subscribeDb3.py
|
||||||
|
|
|
@ -134,6 +134,7 @@ echo "mDebugFlag 143" >> $TAOS_CFG
|
||||||
echo "wDebugFlag 143" >> $TAOS_CFG
|
echo "wDebugFlag 143" >> $TAOS_CFG
|
||||||
echo "sDebugFlag 143" >> $TAOS_CFG
|
echo "sDebugFlag 143" >> $TAOS_CFG
|
||||||
echo "tsdbDebugFlag 143" >> $TAOS_CFG
|
echo "tsdbDebugFlag 143" >> $TAOS_CFG
|
||||||
|
echo "tdbDebugFlag 143" >> $TAOS_CFG
|
||||||
echo "tqDebugFlag 143" >> $TAOS_CFG
|
echo "tqDebugFlag 143" >> $TAOS_CFG
|
||||||
echo "fsDebugFlag 143" >> $TAOS_CFG
|
echo "fsDebugFlag 143" >> $TAOS_CFG
|
||||||
echo "idxDebugFlag 143" >> $TAOS_CFG
|
echo "idxDebugFlag 143" >> $TAOS_CFG
|
||||||
|
|
|
@ -10,13 +10,11 @@ set +e
|
||||||
#set -x
|
#set -x
|
||||||
|
|
||||||
FILE_NAME=
|
FILE_NAME=
|
||||||
RELEASE=0
|
|
||||||
ASYNC=0
|
|
||||||
VALGRIND=0
|
VALGRIND=0
|
||||||
UNIQUE=0
|
TEST=0
|
||||||
UNAME_BIN=`which uname`
|
UNAME_BIN=`which uname`
|
||||||
OS_TYPE=`$UNAME_BIN`
|
OS_TYPE=`$UNAME_BIN`
|
||||||
while getopts "f:agvum" arg
|
while getopts "f:tgv" arg
|
||||||
do
|
do
|
||||||
case $arg in
|
case $arg in
|
||||||
f)
|
f)
|
||||||
|
@ -25,8 +23,8 @@ do
|
||||||
v)
|
v)
|
||||||
VALGRIND=1
|
VALGRIND=1
|
||||||
;;
|
;;
|
||||||
u)
|
t)
|
||||||
UNIQUE=1
|
TEST=1
|
||||||
;;
|
;;
|
||||||
g)
|
g)
|
||||||
VALGRIND=2
|
VALGRIND=2
|
||||||
|
@ -140,6 +138,11 @@ if [ -n "$FILE_NAME" ]; then
|
||||||
result=$?
|
result=$?
|
||||||
echo "Execute result:" $result
|
echo "Execute result:" $result
|
||||||
|
|
||||||
|
if [ $TEST -eq 1 ]; then
|
||||||
|
echo "Exit without check asan errors"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
if [ $result -eq 0 ]; then
|
if [ $result -eq 0 ]; then
|
||||||
$CODE_DIR/sh/sigint_stop_dnodes.sh
|
$CODE_DIR/sh/sigint_stop_dnodes.sh
|
||||||
$CODE_DIR/sh/checkAsan.sh
|
$CODE_DIR/sh/checkAsan.sh
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
system sh/stop_dnodes.sh
|
system sh/stop_dnodes.sh
|
||||||
system sh/deploy.sh -n dnode1 -i 1
|
system sh/deploy.sh -n dnode1 -i 1
|
||||||
system sh/cfg.sh -n dnode1 -c debugflag -v 131
|
system sh/cfg.sh -n dnode1 -c debugflag 131
|
||||||
system sh/exec.sh -n dnode1 -s start -v
|
system sh/exec.sh -n dnode1 -s start
|
||||||
|
|
||||||
sleep 5000
|
sleep 5000
|
||||||
|
|
||||||
|
|
|
@ -672,6 +672,123 @@ if $data61 != 1 then
|
||||||
goto loop5
|
goto loop5
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
print step 8
|
||||||
|
|
||||||
|
sql drop stream IF EXISTS streams4;
|
||||||
|
sql drop database IF EXISTS test4;
|
||||||
|
|
||||||
|
sql create database test4 vgroups 6;
|
||||||
|
sql use test4;
|
||||||
|
sql create stable st(ts timestamp, a int, b int, c int, d double) tags(ta int,tb int,tc int);
|
||||||
|
sql create table t1 using st tags(1,1,1);
|
||||||
|
sql create table t2 using st tags(2,2,2);
|
||||||
|
|
||||||
|
sql create stream streams4 trigger at_once into streamt4 as select _wstart as ts, count(*),min(a) c1 from st interval(10s) sliding(5s);
|
||||||
|
|
||||||
|
sql insert into t1 values(1648791213000,1,1,1,1.0);
|
||||||
|
sql insert into t1 values(1648791243000,2,1,1,1.0);
|
||||||
|
|
||||||
|
sql insert into t2 values(1648791273000,3,1,1,1.0);
|
||||||
|
sql insert into t2 values(1648791313000,4,1,1,1.0);
|
||||||
|
|
||||||
|
$loop_count = 0
|
||||||
|
|
||||||
|
loop6:
|
||||||
|
sleep 200
|
||||||
|
|
||||||
|
$loop_count = $loop_count + 1
|
||||||
|
if $loop_count == 10 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
sql select * from streamt4 order by 1;
|
||||||
|
|
||||||
|
# row 0
|
||||||
|
if $rows != 8 then
|
||||||
|
print ====loop6=rows=$rows
|
||||||
|
goto loop6
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data01 != 1 then
|
||||||
|
print ====loop6=data01=$data01
|
||||||
|
goto loop6
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data02 != 1 then
|
||||||
|
print ====loop6=data02=$data02
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data11 != 1 then
|
||||||
|
print ====loop6=data11=$data11
|
||||||
|
goto loop6
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data12 != 1 then
|
||||||
|
print ====loop6=data12=$data12
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data21 != 1 then
|
||||||
|
print ====loop6=data21=$data21
|
||||||
|
goto loop6
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data22 != 2 then
|
||||||
|
print ====loop6=data22=$data22
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data31 != 1 then
|
||||||
|
print ====loop6=data31=$data31
|
||||||
|
goto loop6
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data32 != 2 then
|
||||||
|
print ====loop6=data32=$data32
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data41 != 1 then
|
||||||
|
print ====loop6=data41=$data41
|
||||||
|
goto loop6
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data42 != 3 then
|
||||||
|
print ====loop6=data42=$data42
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data51 != 1 then
|
||||||
|
print ====loop6=data51=$data51
|
||||||
|
goto loop6
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data52 != 3 then
|
||||||
|
print ====loop6=data52=$data52
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data61 != 1 then
|
||||||
|
print ====loop6=data61=$data61
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data62 != 4 then
|
||||||
|
print ====loop6=data62=$data62
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data71 != 1 then
|
||||||
|
print ====loop6=data71=$data71
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data72 != 4 then
|
||||||
|
print ====loop6=data72=$data72
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
$loop_all = $loop_all + 1
|
$loop_all = $loop_all + 1
|
||||||
print ============loop_all=$loop_all
|
print ============loop_all=$loop_all
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ class TDTestCase:
|
||||||
|
|
||||||
def insertConsumerInfo(self,consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifmanualcommit,cdbName='cdb'):
|
def insertConsumerInfo(self,consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifmanualcommit,cdbName='cdb'):
|
||||||
sql = "insert into %s.consumeinfo values "%cdbName
|
sql = "insert into %s.consumeinfo values "%cdbName
|
||||||
sql += "(now, %d, '%s', '%s', %d, %d, %d)"%(consumerId, topicList, keyList, expectrowcnt, ifcheckdata, ifmanualcommit)
|
sql += "(now + %ds, %d, '%s', '%s', %d, %d, %d)"%(consumerId, consumerId, topicList, keyList, expectrowcnt, ifcheckdata, ifmanualcommit)
|
||||||
tdLog.info("consume info sql: %s"%sql)
|
tdLog.info("consume info sql: %s"%sql)
|
||||||
tdSql.query(sql)
|
tdSql.query(sql)
|
||||||
|
|
||||||
|
@ -174,12 +174,13 @@ class TDTestCase:
|
||||||
'ctbNum': 10, \
|
'ctbNum': 10, \
|
||||||
'rowsPerTbl': 5000, \
|
'rowsPerTbl': 5000, \
|
||||||
'batchNum': 100, \
|
'batchNum': 100, \
|
||||||
|
'replica': self.replicaVar, \
|
||||||
'startTs': 1640966400000} # 2022-01-01 00:00:00.000
|
'startTs': 1640966400000} # 2022-01-01 00:00:00.000
|
||||||
parameterDict['cfg'] = cfgPath
|
parameterDict['cfg'] = cfgPath
|
||||||
|
|
||||||
self.initConsumerTable()
|
self.initConsumerTable()
|
||||||
|
|
||||||
tdSql.execute("create database if not exists %s vgroups %d" %(parameterDict['dbName'], parameterDict['vgroups']))
|
tdSql.execute("create database if not exists %s vgroups %d replica %d" %(parameterDict['dbName'], parameterDict['vgroups'], parameterDict['replica']))
|
||||||
|
|
||||||
prepareEnvThread = threading.Thread(target=self.prepareEnv, kwargs=parameterDict)
|
prepareEnvThread = threading.Thread(target=self.prepareEnv, kwargs=parameterDict)
|
||||||
prepareEnvThread.start()
|
prepareEnvThread.start()
|
||||||
|
@ -271,12 +272,13 @@ class TDTestCase:
|
||||||
'ctbNum': 10, \
|
'ctbNum': 10, \
|
||||||
'rowsPerTbl': 5000, \
|
'rowsPerTbl': 5000, \
|
||||||
'batchNum': 100, \
|
'batchNum': 100, \
|
||||||
|
'replica': self.replicaVar, \
|
||||||
'startTs': 1640966400000} # 2022-01-01 00:00:00.000
|
'startTs': 1640966400000} # 2022-01-01 00:00:00.000
|
||||||
parameterDict['cfg'] = cfgPath
|
parameterDict['cfg'] = cfgPath
|
||||||
|
|
||||||
self.initConsumerTable()
|
self.initConsumerTable()
|
||||||
|
|
||||||
tdSql.execute("create database if not exists %s vgroups %d" %(parameterDict['dbName'], parameterDict['vgroups']))
|
tdSql.execute("create database if not exists %s vgroups %d replica %d" %(parameterDict['dbName'], parameterDict['vgroups'], parameterDict['replica']))
|
||||||
|
|
||||||
prepareEnvThread = threading.Thread(target=self.prepareEnv, kwargs=parameterDict)
|
prepareEnvThread = threading.Thread(target=self.prepareEnv, kwargs=parameterDict)
|
||||||
prepareEnvThread.start()
|
prepareEnvThread.start()
|
||||||
|
@ -337,6 +339,7 @@ class TDTestCase:
|
||||||
'ctbNum': 10, \
|
'ctbNum': 10, \
|
||||||
'rowsPerTbl': 5000, \
|
'rowsPerTbl': 5000, \
|
||||||
'batchNum': 100, \
|
'batchNum': 100, \
|
||||||
|
'replica': self.replicaVar, \
|
||||||
'startTs': 1640966400000} # 2022-01-01 00:00:00.000
|
'startTs': 1640966400000} # 2022-01-01 00:00:00.000
|
||||||
parameterDict['cfg'] = cfgPath
|
parameterDict['cfg'] = cfgPath
|
||||||
|
|
||||||
|
@ -406,12 +409,13 @@ class TDTestCase:
|
||||||
'ctbNum': 10, \
|
'ctbNum': 10, \
|
||||||
'rowsPerTbl': 5000, \
|
'rowsPerTbl': 5000, \
|
||||||
'batchNum': 100, \
|
'batchNum': 100, \
|
||||||
|
'replica': self.replicaVar, \
|
||||||
'startTs': 1640966400000} # 2022-01-01 00:00:00.000
|
'startTs': 1640966400000} # 2022-01-01 00:00:00.000
|
||||||
parameterDict['cfg'] = cfgPath
|
parameterDict['cfg'] = cfgPath
|
||||||
|
|
||||||
self.initConsumerTable()
|
self.initConsumerTable()
|
||||||
|
|
||||||
tdSql.execute("create database if not exists %s vgroups %d" %(parameterDict['dbName'], parameterDict['vgroups']))
|
tdSql.execute("create database if not exists %s vgroups %d replica %d" %(parameterDict['dbName'], parameterDict['vgroups'], parameterDict['replica']))
|
||||||
|
|
||||||
prepareEnvThread = threading.Thread(target=self.prepareEnv, kwargs=parameterDict)
|
prepareEnvThread = threading.Thread(target=self.prepareEnv, kwargs=parameterDict)
|
||||||
prepareEnvThread.start()
|
prepareEnvThread.start()
|
||||||
|
|
|
@ -174,12 +174,13 @@ class TDTestCase:
|
||||||
'ctbNum': 10, \
|
'ctbNum': 10, \
|
||||||
'rowsPerTbl': 5000, \
|
'rowsPerTbl': 5000, \
|
||||||
'batchNum': 100, \
|
'batchNum': 100, \
|
||||||
|
'replica': self.replicaVar, \
|
||||||
'startTs': 1640966400000} # 2022-01-01 00:00:00.000
|
'startTs': 1640966400000} # 2022-01-01 00:00:00.000
|
||||||
parameterDict['cfg'] = cfgPath
|
parameterDict['cfg'] = cfgPath
|
||||||
|
|
||||||
self.initConsumerTable()
|
self.initConsumerTable()
|
||||||
|
|
||||||
tdSql.execute("create database if not exists %s vgroups %d" %(parameterDict['dbName'], parameterDict['vgroups']))
|
tdSql.execute("create database if not exists %s vgroups %d replica %d" %(parameterDict['dbName'], parameterDict['vgroups'], parameterDict['replica']))
|
||||||
|
|
||||||
prepareEnvThread = threading.Thread(target=self.prepareEnv, kwargs=parameterDict)
|
prepareEnvThread = threading.Thread(target=self.prepareEnv, kwargs=parameterDict)
|
||||||
prepareEnvThread.start()
|
prepareEnvThread.start()
|
||||||
|
@ -191,6 +192,7 @@ class TDTestCase:
|
||||||
'ctbNum': 10, \
|
'ctbNum': 10, \
|
||||||
'rowsPerTbl': 5000, \
|
'rowsPerTbl': 5000, \
|
||||||
'batchNum': 100, \
|
'batchNum': 100, \
|
||||||
|
'replica': self.replicaVar, \
|
||||||
'startTs': 1640966400000} # 2022-01-01 00:00:00.000
|
'startTs': 1640966400000} # 2022-01-01 00:00:00.000
|
||||||
parameterDict['cfg'] = cfgPath
|
parameterDict['cfg'] = cfgPath
|
||||||
|
|
||||||
|
@ -254,12 +256,13 @@ class TDTestCase:
|
||||||
'ctbNum': 10, \
|
'ctbNum': 10, \
|
||||||
'rowsPerTbl': 5000, \
|
'rowsPerTbl': 5000, \
|
||||||
'batchNum': 100, \
|
'batchNum': 100, \
|
||||||
|
'replica': self.replicaVar, \
|
||||||
'startTs': 1640966400000} # 2022-01-01 00:00:00.000
|
'startTs': 1640966400000} # 2022-01-01 00:00:00.000
|
||||||
parameterDict['cfg'] = cfgPath
|
parameterDict['cfg'] = cfgPath
|
||||||
|
|
||||||
self.initConsumerTable()
|
self.initConsumerTable()
|
||||||
|
|
||||||
tdSql.execute("create database if not exists %s vgroups %d" %(parameterDict['dbName'], parameterDict['vgroups']))
|
tdSql.execute("create database if not exists %s vgroups %d replica %d" %(parameterDict['dbName'], parameterDict['vgroups'], parameterDict['replica']))
|
||||||
|
|
||||||
prepareEnvThread = threading.Thread(target=self.prepareEnv, kwargs=parameterDict)
|
prepareEnvThread = threading.Thread(target=self.prepareEnv, kwargs=parameterDict)
|
||||||
prepareEnvThread.start()
|
prepareEnvThread.start()
|
||||||
|
|
|
@ -60,7 +60,7 @@ class TMQCom:
|
||||||
|
|
||||||
def insertConsumerInfo(self,consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifmanualcommit,cdbName='cdb'):
|
def insertConsumerInfo(self,consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifmanualcommit,cdbName='cdb'):
|
||||||
sql = "insert into %s.consumeinfo values "%cdbName
|
sql = "insert into %s.consumeinfo values "%cdbName
|
||||||
sql += "(now, %d, '%s', '%s', %d, %d, %d)"%(consumerId, topicList, keyList, expectrowcnt, ifcheckdata, ifmanualcommit)
|
sql += "(now + %ds, %d, '%s', '%s', %d, %d, %d)"%(consumerId, consumerId, topicList, keyList, expectrowcnt, ifcheckdata, ifmanualcommit)
|
||||||
tdLog.info("consume info sql: %s"%sql)
|
tdLog.info("consume info sql: %s"%sql)
|
||||||
tdSql.query(sql)
|
tdSql.query(sql)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue