Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
3b50fee6
TDengine
项目概览
taosdata
/
TDengine
接近 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
3b50fee6
编写于
7月 04, 2022
作者:
J
jiacy-jcy
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '3.0' into 3.0test/jcy
上级
59964f7e
cce9f262
变更
83
展开全部
隐藏空白更改
内联
并排
Showing
83 changed file
with
3576 addition
and
1506 deletion
+3576
-1506
Jenkinsfile2
Jenkinsfile2
+30
-0
include/libs/nodes/nodes.h
include/libs/nodes/nodes.h
+3
-2
include/libs/scalar/scalar.h
include/libs/scalar/scalar.h
+2
-0
include/libs/sync/sync.h
include/libs/sync/sync.h
+22
-16
include/libs/sync/syncTools.h
include/libs/sync/syncTools.h
+39
-28
include/util/taoserror.h
include/util/taoserror.h
+4
-0
source/common/src/tdatablock.c
source/common/src/tdatablock.c
+10
-9
source/dnode/mgmt/node_mgmt/src/dmProc.c
source/dnode/mgmt/node_mgmt/src/dmProc.c
+10
-10
source/dnode/mgmt/node_mgmt/src/dmTransport.c
source/dnode/mgmt/node_mgmt/src/dmTransport.c
+1
-1
source/dnode/mnode/impl/src/mndMain.c
source/dnode/mnode/impl/src/mndMain.c
+10
-10
source/dnode/mnode/impl/src/mndSync.c
source/dnode/mnode/impl/src/mndSync.c
+2
-2
source/dnode/vnode/src/sma/smaRollup.c
source/dnode/vnode/src/sma/smaRollup.c
+2
-3
source/dnode/vnode/src/vnd/vnodeSync.c
source/dnode/vnode/src/vnd/vnodeSync.c
+128
-64
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+199
-1
source/libs/function/src/functionMgt.c
source/libs/function/src/functionMgt.c
+1
-1
source/libs/index/inc/indexFst.h
source/libs/index/inc/indexFst.h
+7
-7
source/libs/index/inc/indexFstFile.h
source/libs/index/inc/indexFstFile.h
+96
-0
source/libs/index/inc/indexFstNode.h
source/libs/index/inc/indexFstNode.h
+4
-4
source/libs/index/inc/indexTfile.h
source/libs/index/inc/indexTfile.h
+5
-5
source/libs/index/src/index.c
source/libs/index/src/index.c
+2
-2
source/libs/index/src/indexFst.c
source/libs/index/src/indexFst.c
+30
-32
source/libs/index/src/indexFstDfa.c
source/libs/index/src/indexFstDfa.c
+2
-1
source/libs/index/src/indexFstFile.c
source/libs/index/src/indexFstFile.c
+38
-46
source/libs/index/src/indexFstNode.c
source/libs/index/src/indexFstNode.c
+1
-1
source/libs/index/src/indexFstUtil.c
source/libs/index/src/indexFstUtil.c
+0
-14
source/libs/index/src/indexTfile.c
source/libs/index/src/indexTfile.c
+17
-16
source/libs/index/test/fstTest.cc
source/libs/index/test/fstTest.cc
+13
-14
source/libs/index/test/fstUT.cc
source/libs/index/test/fstUT.cc
+13
-14
source/libs/index/test/indexTests.cc
source/libs/index/test/indexTests.cc
+15
-16
source/libs/index/test/jsonUT.cc
source/libs/index/test/jsonUT.cc
+0
-1
source/libs/index/test/utilUT.cc
source/libs/index/test/utilUT.cc
+0
-1
source/libs/nodes/src/nodesUtilFuncs.c
source/libs/nodes/src/nodesUtilFuncs.c
+19
-10
source/libs/parser/inc/parAst.h
source/libs/parser/inc/parAst.h
+1
-0
source/libs/parser/inc/parUtil.h
source/libs/parser/inc/parUtil.h
+1
-0
source/libs/parser/inc/sql.y
source/libs/parser/inc/sql.y
+2
-2
source/libs/parser/src/parAstCreater.c
source/libs/parser/src/parAstCreater.c
+5
-0
source/libs/parser/src/parAstParser.c
source/libs/parser/src/parAstParser.c
+6
-0
source/libs/parser/src/parInsert.c
source/libs/parser/src/parInsert.c
+67
-25
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+203
-140
source/libs/parser/src/parUtil.c
source/libs/parser/src/parUtil.c
+9
-1
source/libs/parser/src/sql.c
source/libs/parser/src/sql.c
+695
-667
source/libs/parser/test/parInitialATest.cpp
source/libs/parser/test/parInitialATest.cpp
+14
-16
source/libs/planner/src/planOptimizer.c
source/libs/planner/src/planOptimizer.c
+4
-2
source/libs/planner/src/planSpliter.c
source/libs/planner/src/planSpliter.c
+4
-0
source/libs/planner/test/planOptimizeTest.cpp
source/libs/planner/test/planOptimizeTest.cpp
+2
-0
source/libs/planner/test/planSetOpTest.cpp
source/libs/planner/test/planSetOpTest.cpp
+9
-1
source/libs/scalar/src/sclfunc.c
source/libs/scalar/src/sclfunc.c
+7
-26
source/libs/sync/inc/syncAppendEntriesReply.h
source/libs/sync/inc/syncAppendEntriesReply.h
+0
-5
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+3
-2
source/libs/sync/inc/syncRaftEntry.h
source/libs/sync/inc/syncRaftEntry.h
+5
-4
source/libs/sync/inc/syncReplication.h
source/libs/sync/inc/syncReplication.h
+1
-0
source/libs/sync/inc/syncSnapshot.h
source/libs/sync/inc/syncSnapshot.h
+26
-23
source/libs/sync/src/syncAppendEntries.c
source/libs/sync/src/syncAppendEntries.c
+98
-36
source/libs/sync/src/syncAppendEntriesReply.c
source/libs/sync/src/syncAppendEntriesReply.c
+11
-11
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+4
-2
source/libs/sync/src/syncMessage.c
source/libs/sync/src/syncMessage.c
+158
-60
source/libs/sync/src/syncRaftEntry.c
source/libs/sync/src/syncRaftEntry.c
+16
-0
source/libs/sync/src/syncRaftLog.c
source/libs/sync/src/syncRaftLog.c
+9
-0
source/libs/sync/src/syncReplication.c
source/libs/sync/src/syncReplication.c
+15
-7
source/libs/sync/src/syncSnapshot.c
source/libs/sync/src/syncSnapshot.c
+9
-3
source/libs/sync/test/CMakeLists.txt
source/libs/sync/test/CMakeLists.txt
+14
-0
source/libs/sync/test/syncAppendEntriesBatchTest.cpp
source/libs/sync/test/syncAppendEntriesBatchTest.cpp
+25
-25
source/libs/sync/test/syncClientRequestBatchTest.cpp
source/libs/sync/test/syncClientRequestBatchTest.cpp
+125
-0
source/libs/sync/test/syncConfigChangeSnapshotTest.cpp
source/libs/sync/test/syncConfigChangeSnapshotTest.cpp
+3
-3
source/libs/sync/test/syncSnapshotReceiverTest.cpp
source/libs/sync/test/syncSnapshotReceiverTest.cpp
+1
-1
source/libs/sync/test/syncSnapshotSenderTest.cpp
source/libs/sync/test/syncSnapshotSenderTest.cpp
+1
-1
source/libs/sync/test/syncTestTool.cpp
source/libs/sync/test/syncTestTool.cpp
+5
-5
source/libs/transport/inc/transComm.h
source/libs/transport/inc/transComm.h
+8
-8
source/libs/transport/src/transCli.c
source/libs/transport/src/transCli.c
+16
-7
source/libs/transport/src/transComm.c
source/libs/transport/src/transComm.c
+11
-6
source/libs/transport/src/transSvr.c
source/libs/transport/src/transSvr.c
+3
-2
source/libs/transport/test/transUT.cpp
source/libs/transport/test/transUT.cpp
+1
-1
source/util/src/terror.c
source/util/src/terror.c
+2
-0
tests/script/tsim/insert/update0.sim
tests/script/tsim/insert/update0.sim
+2
-2
tests/system-test/1-insert/block_wise.py
tests/system-test/1-insert/block_wise.py
+442
-0
tests/system-test/1-insert/create_retentions.py
tests/system-test/1-insert/create_retentions.py
+34
-58
tests/system-test/1-insert/time_range_wise.py
tests/system-test/1-insert/time_range_wise.py
+13
-14
tests/system-test/2-query/json_tag.py
tests/system-test/2-query/json_tag.py
+1
-1
tests/system-test/7-tmq/tmqConsFromTsdb-1ctb.py
tests/system-test/7-tmq/tmqConsFromTsdb-1ctb.py
+263
-0
tests/system-test/7-tmq/tmqConsFromTsdb1-1ctb.py
tests/system-test/7-tmq/tmqConsFromTsdb1-1ctb.py
+241
-0
tests/system-test/7-tmq/tmqConsFromTsdb1-mutilVg.py
tests/system-test/7-tmq/tmqConsFromTsdb1-mutilVg.py
+241
-0
tests/system-test/7-tmq/tmqConsFromTsdb1.py
tests/system-test/7-tmq/tmqConsFromTsdb1.py
+1
-1
tests/system-test/fulltest.sh
tests/system-test/fulltest.sh
+14
-7
未找到文件。
Jenkinsfile2
浏览文件 @
3b50fee6
...
@@ -127,6 +127,25 @@ def pre_test(){
...
@@ -127,6 +127,25 @@ def pre_test(){
'''
'''
return 1
return 1
}
}
def pre_test_build_mac() {
sh '''
hostname
date
'''
sh '''
cd ${WK}
rm -rf debug
mkdir debug
'''
sh '''
cd ${WK}/debug
cmake ..
make -j8
'''
sh '''
date
'''
}
def pre_test_win(){
def pre_test_win(){
bat '''
bat '''
hostname
hostname
...
@@ -334,6 +353,17 @@ pipeline {
...
@@ -334,6 +353,17 @@ pipeline {
}
}
}
}
}
}
stage('mac test') {
agent{label " Mac_catalina "}
steps {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
timeout(time: 20, unit: 'MINUTES'){
pre_test()
pre_test_build_mac()
}
}
}
}
stage('linux test') {
stage('linux test') {
agent{label " worker03 || slave215 || slave217 || slave219 "}
agent{label " worker03 || slave215 || slave217 || slave219 "}
options { skipDefaultCheckout() }
options { skipDefaultCheckout() }
...
...
include/libs/nodes/nodes.h
浏览文件 @
3b50fee6
...
@@ -22,8 +22,8 @@ extern "C" {
...
@@ -22,8 +22,8 @@ extern "C" {
#include "tdef.h"
#include "tdef.h"
#define nodeType(nodeptr) (((const SNode*)(nodeptr))->type)
#define nodeType(nodeptr)
(((const SNode*)(nodeptr))->type)
#define setNodeType(nodeptr,
type) (((SNode*)(nodeptr))->type = (
type))
#define setNodeType(nodeptr,
nodetype) (((SNode*)(nodeptr))->type = (node
type))
#define LIST_LENGTH(l) (NULL != (l) ? (l)->length : 0)
#define LIST_LENGTH(l) (NULL != (l) ? (l)->length : 0)
...
@@ -118,6 +118,7 @@ typedef enum ENodeType {
...
@@ -118,6 +118,7 @@ typedef enum ENodeType {
QUERY_NODE_DROP_TABLE_STMT
,
QUERY_NODE_DROP_TABLE_STMT
,
QUERY_NODE_DROP_SUPER_TABLE_STMT
,
QUERY_NODE_DROP_SUPER_TABLE_STMT
,
QUERY_NODE_ALTER_TABLE_STMT
,
QUERY_NODE_ALTER_TABLE_STMT
,
QUERY_NODE_ALTER_SUPER_TABLE_STMT
,
QUERY_NODE_CREATE_USER_STMT
,
QUERY_NODE_CREATE_USER_STMT
,
QUERY_NODE_ALTER_USER_STMT
,
QUERY_NODE_ALTER_USER_STMT
,
QUERY_NODE_DROP_USER_STMT
,
QUERY_NODE_DROP_USER_STMT
,
...
...
include/libs/scalar/scalar.h
浏览文件 @
3b50fee6
...
@@ -25,6 +25,8 @@ extern "C" {
...
@@ -25,6 +25,8 @@ extern "C" {
typedef
struct
SFilterInfo
SFilterInfo
;
typedef
struct
SFilterInfo
SFilterInfo
;
int32_t
scalarGetOperatorResultType
(
SDataType
left
,
SDataType
right
,
EOperatorType
op
,
SDataType
*
pRes
);
/*
/*
pNode will be freed in API;
pNode will be freed in API;
*pRes need to freed in caller
*pRes need to freed in caller
...
...
include/libs/sync/sync.h
浏览文件 @
3b50fee6
...
@@ -31,6 +31,12 @@ extern bool gRaftDetailLog;
...
@@ -31,6 +31,12 @@ extern bool gRaftDetailLog;
#define SYNC_INDEX_INVALID -1
#define SYNC_INDEX_INVALID -1
#define SYNC_TERM_INVALID 0xFFFFFFFFFFFFFFFF
#define SYNC_TERM_INVALID 0xFFFFFFFFFFFFFFFF
typedef
enum
{
SYNC_STRATEGY_NO_SNAPSHOT
=
0
,
SYNC_STRATEGY_STANDARD_SNAPSHOT
=
1
,
SYNC_STRATEGY_WAL_FIRST
=
2
,
}
ESyncStrategy
;
typedef
uint64_t
SyncNodeId
;
typedef
uint64_t
SyncNodeId
;
typedef
int32_t
SyncGroupId
;
typedef
int32_t
SyncGroupId
;
typedef
int64_t
SyncIndex
;
typedef
int64_t
SyncIndex
;
...
@@ -48,11 +54,6 @@ typedef enum {
...
@@ -48,11 +54,6 @@ typedef enum {
TAOS_SYNC_STATE_ERROR
=
103
,
TAOS_SYNC_STATE_ERROR
=
103
,
}
ESyncState
;
}
ESyncState
;
typedef
enum
{
TAOS_SYNC_FSM_CB_SUCCESS
=
0
,
TAOS_SYNC_FSM_CB_OTHER_ERROR
=
1
,
}
ESyncFsmCbCode
;
typedef
struct
SNodeInfo
{
typedef
struct
SNodeInfo
{
uint16_t
nodePort
;
uint16_t
nodePort
;
char
nodeFqdn
[
TSDB_FQDN_LEN
];
char
nodeFqdn
[
TSDB_FQDN_LEN
];
...
@@ -96,6 +97,11 @@ typedef struct SReConfigCbMeta {
...
@@ -96,6 +97,11 @@ typedef struct SReConfigCbMeta {
}
SReConfigCbMeta
;
}
SReConfigCbMeta
;
typedef
struct
SSnapshotParam
{
SyncIndex
start
;
SyncIndex
end
;
}
SSnapshotParam
;
typedef
struct
SSnapshot
{
typedef
struct
SSnapshot
{
void
*
data
;
void
*
data
;
SyncIndex
lastApplyIndex
;
SyncIndex
lastApplyIndex
;
...
@@ -125,7 +131,7 @@ typedef struct SSyncFSM {
...
@@ -125,7 +131,7 @@ typedef struct SSyncFSM {
int32_t
(
*
FpSnapshotStopRead
)(
struct
SSyncFSM
*
pFsm
,
void
*
pReader
);
int32_t
(
*
FpSnapshotStopRead
)(
struct
SSyncFSM
*
pFsm
,
void
*
pReader
);
int32_t
(
*
FpSnapshotDoRead
)(
struct
SSyncFSM
*
pFsm
,
void
*
pReader
,
void
**
ppBuf
,
int32_t
*
len
);
int32_t
(
*
FpSnapshotDoRead
)(
struct
SSyncFSM
*
pFsm
,
void
*
pReader
,
void
**
ppBuf
,
int32_t
*
len
);
int32_t
(
*
FpSnapshotStartWrite
)(
struct
SSyncFSM
*
pFsm
,
void
**
ppWriter
);
int32_t
(
*
FpSnapshotStartWrite
)(
struct
SSyncFSM
*
pFsm
,
void
*
pWriterParam
,
void
*
*
ppWriter
);
int32_t
(
*
FpSnapshotStopWrite
)(
struct
SSyncFSM
*
pFsm
,
void
*
pWriter
,
bool
isApply
);
int32_t
(
*
FpSnapshotStopWrite
)(
struct
SSyncFSM
*
pFsm
,
void
*
pWriter
,
bool
isApply
);
int32_t
(
*
FpSnapshotDoWrite
)(
struct
SSyncFSM
*
pFsm
,
void
*
pWriter
,
void
*
pBuf
,
int32_t
len
);
int32_t
(
*
FpSnapshotDoWrite
)(
struct
SSyncFSM
*
pFsm
,
void
*
pWriter
,
void
*
pBuf
,
int32_t
len
);
...
@@ -178,15 +184,15 @@ typedef struct SSyncLogStore {
...
@@ -178,15 +184,15 @@ typedef struct SSyncLogStore {
}
SSyncLogStore
;
}
SSyncLogStore
;
typedef
struct
SSyncInfo
{
typedef
struct
SSyncInfo
{
bool
isStandBy
;
bool
isStandBy
;
bool
snapshotEnable
;
ESyncStrategy
snapshotStrategy
;
SyncGroupId
vgId
;
SyncGroupId
vgId
;
int32_t
batchSize
;
int32_t
batchSize
;
SSyncCfg
syncCfg
;
SSyncCfg
syncCfg
;
char
path
[
TSDB_FILENAME_LEN
];
char
path
[
TSDB_FILENAME_LEN
];
SWal
*
pWal
;
SWal
*
pWal
;
SSyncFSM
*
pFsm
;
SSyncFSM
*
pFsm
;
SMsgCb
*
msgcb
;
SMsgCb
*
msgcb
;
int32_t
(
*
FpSendMsg
)(
const
SEpSet
*
pEpSet
,
SRpcMsg
*
pMsg
);
int32_t
(
*
FpSendMsg
)(
const
SEpSet
*
pEpSet
,
SRpcMsg
*
pMsg
);
int32_t
(
*
FpEqMsg
)(
const
SMsgCb
*
msgcb
,
SRpcMsg
*
pMsg
);
int32_t
(
*
FpEqMsg
)(
const
SMsgCb
*
msgcb
,
SRpcMsg
*
pMsg
);
}
SSyncInfo
;
}
SSyncInfo
;
...
@@ -205,7 +211,7 @@ SyncGroupId syncGetVgId(int64_t rid);
...
@@ -205,7 +211,7 @@ SyncGroupId syncGetVgId(int64_t rid);
void
syncGetEpSet
(
int64_t
rid
,
SEpSet
*
pEpSet
);
void
syncGetEpSet
(
int64_t
rid
,
SEpSet
*
pEpSet
);
void
syncGetRetryEpSet
(
int64_t
rid
,
SEpSet
*
pEpSet
);
void
syncGetRetryEpSet
(
int64_t
rid
,
SEpSet
*
pEpSet
);
int32_t
syncPropose
(
int64_t
rid
,
SRpcMsg
*
pMsg
,
bool
isWeak
);
int32_t
syncPropose
(
int64_t
rid
,
SRpcMsg
*
pMsg
,
bool
isWeak
);
//
int32_t syncProposeBatch(int64_t rid, SRpcMsg* pMsgArr, bool* pIsWeakArr, int32_t arrSize);
int32_t
syncProposeBatch
(
int64_t
rid
,
SRpcMsg
*
pMsgArr
,
bool
*
pIsWeakArr
,
int32_t
arrSize
);
bool
syncEnvIsStart
();
bool
syncEnvIsStart
();
const
char
*
syncStr
(
ESyncState
state
);
const
char
*
syncStr
(
ESyncState
state
);
bool
syncIsRestoreFinish
(
int64_t
rid
);
bool
syncIsRestoreFinish
(
int64_t
rid
);
...
...
include/libs/sync/syncTools.h
浏览文件 @
3b50fee6
...
@@ -191,12 +191,12 @@ void syncTimeoutLog2(char* s, const SyncTimeout* pMsg);
...
@@ -191,12 +191,12 @@ void syncTimeoutLog2(char* s, const SyncTimeout* pMsg);
typedef
struct
SyncClientRequest
{
typedef
struct
SyncClientRequest
{
uint32_t
bytes
;
uint32_t
bytes
;
int32_t
vgId
;
int32_t
vgId
;
uint32_t
msgType
;
//
SyncClientRequest msgType
uint32_t
msgType
;
//
TDMT_SYNC_CLIENT_REQUEST
uint32_t
originalRpcType
;
//
user
RpcMsg msgType
uint32_t
originalRpcType
;
//
origin
RpcMsg msgType
uint64_t
seqNum
;
uint64_t
seqNum
;
bool
isWeak
;
bool
isWeak
;
uint32_t
dataLen
;
//
user
RpcMsg.contLen
uint32_t
dataLen
;
//
origin
RpcMsg.contLen
char
data
[];
//
user
RpcMsg.pCont
char
data
[];
//
origin
RpcMsg.pCont
}
SyncClientRequest
;
}
SyncClientRequest
;
SyncClientRequest
*
syncClientRequestBuild
(
uint32_t
dataLen
);
SyncClientRequest
*
syncClientRequestBuild
(
uint32_t
dataLen
);
...
@@ -220,11 +220,6 @@ void syncClientRequestLog(const SyncClientRequest* pMsg);
...
@@ -220,11 +220,6 @@ void syncClientRequestLog(const SyncClientRequest* pMsg);
void
syncClientRequestLog2
(
char
*
s
,
const
SyncClientRequest
*
pMsg
);
void
syncClientRequestLog2
(
char
*
s
,
const
SyncClientRequest
*
pMsg
);
// ---------------------------------------------
// ---------------------------------------------
typedef
struct
SOffsetAndContLen
{
int32_t
offset
;
int32_t
contLen
;
}
SOffsetAndContLen
;
typedef
struct
SRaftMeta
{
typedef
struct
SRaftMeta
{
uint64_t
seqNum
;
uint64_t
seqNum
;
bool
isWeak
;
bool
isWeak
;
...
@@ -232,20 +227,33 @@ typedef struct SRaftMeta {
...
@@ -232,20 +227,33 @@ typedef struct SRaftMeta {
// block1:
// block1:
// block2: SRaftMeta array
// block2: SRaftMeta array
// block3: rpc msg array (with pCont)
// block3: rpc msg array (with pCont
pointer
)
typedef
struct
SyncClientRequestBatch
{
typedef
struct
SyncClientRequestBatch
{
uint32_t
bytes
;
uint32_t
bytes
;
int32_t
vgId
;
int32_t
vgId
;
uint32_t
msgType
;
//
SyncClientRequestBatch msgType
uint32_t
msgType
;
//
TDMT_SYNC_CLIENT_REQUEST_BATCH
uint32_t
dataCount
;
uint32_t
dataCount
;
uint32_t
dataLen
;
// user RpcMsg.contLen
uint32_t
dataLen
;
char
data
[];
// user RpcMsg.pCont
char
data
[];
// block2, block3
}
SyncClientRequestBatch
;
}
SyncClientRequestBatch
;
SyncClientRequestBatch
*
syncClientRequestBatchBuild
(
SRpcMsg
*
rpcMsgArr
,
SRaftMeta
*
raftArr
,
int32_t
arrSize
,
SyncClientRequestBatch
*
syncClientRequestBatchBuild
(
SRpcMsg
*
rpcMsgArr
,
SRaftMeta
*
raftArr
,
int32_t
arrSize
,
int32_t
vgId
);
int32_t
vgId
);
void
syncClientRequestBatch2RpcMsg
(
const
SyncClientRequestBatch
*
pSyncMsg
,
SRpcMsg
*
pRpcMsg
);
void
syncClientRequestBatch2RpcMsg
(
const
SyncClientRequestBatch
*
pSyncMsg
,
SRpcMsg
*
pRpcMsg
);
void
syncClientRequestBatchDestroy
(
SyncClientRequestBatch
*
pMsg
);
void
syncClientRequestBatchDestroyDeep
(
SyncClientRequestBatch
*
pMsg
);
SRaftMeta
*
syncClientRequestBatchMetaArr
(
const
SyncClientRequestBatch
*
pSyncMsg
);
SRpcMsg
*
syncClientRequestBatchRpcMsgArr
(
const
SyncClientRequestBatch
*
pSyncMsg
);
SyncClientRequestBatch
*
syncClientRequestBatchFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
);
cJSON
*
syncClientRequestBatch2Json
(
const
SyncClientRequestBatch
*
pMsg
);
char
*
syncClientRequestBatch2Str
(
const
SyncClientRequestBatch
*
pMsg
);
// for debug ----------------------
void
syncClientRequestBatchPrint
(
const
SyncClientRequestBatch
*
pMsg
);
void
syncClientRequestBatchPrint2
(
char
*
s
,
const
SyncClientRequestBatch
*
pMsg
);
void
syncClientRequestBatchLog
(
const
SyncClientRequestBatch
*
pMsg
);
void
syncClientRequestBatchLog2
(
char
*
s
,
const
SyncClientRequestBatch
*
pMsg
);
// ---------------------------------------------
// ---------------------------------------------
typedef
struct
SyncClientRequestReply
{
typedef
struct
SyncClientRequestReply
{
...
@@ -318,12 +326,15 @@ void syncRequestVoteReplyLog(const SyncRequestVoteReply* pMsg);
...
@@ -318,12 +326,15 @@ void syncRequestVoteReplyLog(const SyncRequestVoteReply* pMsg);
void
syncRequestVoteReplyLog2
(
char
*
s
,
const
SyncRequestVoteReply
*
pMsg
);
void
syncRequestVoteReplyLog2
(
char
*
s
,
const
SyncRequestVoteReply
*
pMsg
);
// ---------------------------------------------
// ---------------------------------------------
// data: entry
typedef
struct
SyncAppendEntries
{
typedef
struct
SyncAppendEntries
{
uint32_t
bytes
;
uint32_t
bytes
;
int32_t
vgId
;
int32_t
vgId
;
uint32_t
msgType
;
uint32_t
msgType
;
SRaftId
srcId
;
SRaftId
srcId
;
SRaftId
destId
;
SRaftId
destId
;
// private data
// private data
SyncTerm
term
;
SyncTerm
term
;
SyncIndex
prevLogIndex
;
SyncIndex
prevLogIndex
;
...
@@ -354,18 +365,14 @@ void syncAppendEntriesLog2(char* s, const SyncAppendEntries* pMsg);
...
@@ -354,18 +365,14 @@ void syncAppendEntriesLog2(char* s, const SyncAppendEntries* pMsg);
// ---------------------------------------------
// ---------------------------------------------
// define ahead
/*
typedef
struct
SOffsetAndContLen
{
typedef
struct
SOffsetAndContLen
{
int32_t
offset
;
int32_t
offset
;
int32_t
contLen
;
int32_t
contLen
;
}
SOffsetAndContLen
;
}
SOffsetAndContLen
;
*/
// block1: SOffsetAndContLen
// data:
// block2: SOffsetAndContLen Array
// block1: SOffsetAndContLen Array
// block3: SRpcMsg Array
// block2: entry Array
// block4: SRpcMsg pCont Array
typedef
struct
SyncAppendEntriesBatch
{
typedef
struct
SyncAppendEntriesBatch
{
uint32_t
bytes
;
uint32_t
bytes
;
...
@@ -382,10 +389,11 @@ typedef struct SyncAppendEntriesBatch {
...
@@ -382,10 +389,11 @@ typedef struct SyncAppendEntriesBatch {
SyncTerm
privateTerm
;
SyncTerm
privateTerm
;
int32_t
dataCount
;
int32_t
dataCount
;
uint32_t
dataLen
;
uint32_t
dataLen
;
char
data
[];
char
data
[];
// block1, block2
}
SyncAppendEntriesBatch
;
}
SyncAppendEntriesBatch
;
SyncAppendEntriesBatch
*
syncAppendEntriesBatchBuild
(
SRpcMsg
*
rpcMsgArr
,
int32_t
arrSize
,
int32_t
vgId
);
SyncAppendEntriesBatch
*
syncAppendEntriesBatchBuild
(
SSyncRaftEntry
**
entryPArr
,
int32_t
arrSize
,
int32_t
vgId
);
SOffsetAndContLen
*
syncAppendEntriesBatchMetaTableArray
(
SyncAppendEntriesBatch
*
pMsg
);
void
syncAppendEntriesBatchDestroy
(
SyncAppendEntriesBatch
*
pMsg
);
void
syncAppendEntriesBatchDestroy
(
SyncAppendEntriesBatch
*
pMsg
);
void
syncAppendEntriesBatchSerialize
(
const
SyncAppendEntriesBatch
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
);
void
syncAppendEntriesBatchSerialize
(
const
SyncAppendEntriesBatch
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
);
void
syncAppendEntriesBatchDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncAppendEntriesBatch
*
pMsg
);
void
syncAppendEntriesBatchDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncAppendEntriesBatch
*
pMsg
);
...
@@ -396,8 +404,6 @@ void syncAppendEntriesBatchFromRpcMsg(const SRpcMsg* pRpcMsg,
...
@@ -396,8 +404,6 @@ void syncAppendEntriesBatchFromRpcMsg(const SRpcMsg* pRpcMsg,
SyncAppendEntriesBatch
*
syncAppendEntriesBatchFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
);
SyncAppendEntriesBatch
*
syncAppendEntriesBatchFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
);
cJSON
*
syncAppendEntriesBatch2Json
(
const
SyncAppendEntriesBatch
*
pMsg
);
cJSON
*
syncAppendEntriesBatch2Json
(
const
SyncAppendEntriesBatch
*
pMsg
);
char
*
syncAppendEntriesBatch2Str
(
const
SyncAppendEntriesBatch
*
pMsg
);
char
*
syncAppendEntriesBatch2Str
(
const
SyncAppendEntriesBatch
*
pMsg
);
void
syncAppendEntriesBatch2RpcMsgArray
(
SyncAppendEntriesBatch
*
pSyncMsg
,
SRpcMsg
*
rpcMsgArr
,
int32_t
maxArrSize
,
int32_t
*
pRetArrSize
);
// for debug ----------------------
// for debug ----------------------
void
syncAppendEntriesBatchPrint
(
const
SyncAppendEntriesBatch
*
pMsg
);
void
syncAppendEntriesBatchPrint
(
const
SyncAppendEntriesBatch
*
pMsg
);
...
@@ -477,9 +483,10 @@ typedef struct SyncSnapshotSend {
...
@@ -477,9 +483,10 @@ typedef struct SyncSnapshotSend {
SRaftId
destId
;
SRaftId
destId
;
SyncTerm
term
;
SyncTerm
term
;
SyncIndex
lastIndex
;
// lastIndex of snapshot
SyncIndex
beginIndex
;
// snapshot.beginIndex
SyncTerm
lastTerm
;
// lastTerm of snapshot
SyncIndex
lastIndex
;
// snapshot.lastIndex
SyncIndex
lastConfigIndex
;
SyncTerm
lastTerm
;
// snapshot.lastTerm
SyncIndex
lastConfigIndex
;
// snapshot.lastConfigIndex
SSyncCfg
lastConfig
;
SSyncCfg
lastConfig
;
SyncTerm
privateTerm
;
SyncTerm
privateTerm
;
int32_t
seq
;
int32_t
seq
;
...
@@ -617,6 +624,9 @@ int32_t syncNodeOnRequestVoteReplySnapshotCb(SSyncNode* ths, SyncRequestVoteRepl
...
@@ -617,6 +624,9 @@ int32_t syncNodeOnRequestVoteReplySnapshotCb(SSyncNode* ths, SyncRequestVoteRepl
int32_t
syncNodeOnAppendEntriesSnapshotCb
(
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
);
int32_t
syncNodeOnAppendEntriesSnapshotCb
(
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
);
int32_t
syncNodeOnAppendEntriesReplySnapshotCb
(
SSyncNode
*
ths
,
SyncAppendEntriesReply
*
pMsg
);
int32_t
syncNodeOnAppendEntriesReplySnapshotCb
(
SSyncNode
*
ths
,
SyncAppendEntriesReply
*
pMsg
);
int32_t
syncNodeOnAppendEntriesSnapshot2Cb
(
SSyncNode
*
ths
,
SyncAppendEntriesBatch
*
pMsg
);
int32_t
syncNodeOnAppendEntriesReplySnapshot2Cb
(
SSyncNode
*
ths
,
SyncAppendEntriesReply
*
pMsg
);
int32_t
syncNodeOnSnapshotSendCb
(
SSyncNode
*
ths
,
SyncSnapshotSend
*
pMsg
);
int32_t
syncNodeOnSnapshotSendCb
(
SSyncNode
*
ths
,
SyncSnapshotSend
*
pMsg
);
int32_t
syncNodeOnSnapshotRspCb
(
SSyncNode
*
ths
,
SyncSnapshotRsp
*
pMsg
);
int32_t
syncNodeOnSnapshotRspCb
(
SSyncNode
*
ths
,
SyncSnapshotRsp
*
pMsg
);
...
@@ -633,7 +643,8 @@ typedef int32_t (*FpOnSnapshotSendCb)(SSyncNode* ths, SyncSnapshotSend* pMsg);
...
@@ -633,7 +643,8 @@ typedef int32_t (*FpOnSnapshotSendCb)(SSyncNode* ths, SyncSnapshotSend* pMsg);
typedef
int32_t
(
*
FpOnSnapshotRspCb
)(
SSyncNode
*
ths
,
SyncSnapshotRsp
*
pMsg
);
typedef
int32_t
(
*
FpOnSnapshotRspCb
)(
SSyncNode
*
ths
,
SyncSnapshotRsp
*
pMsg
);
// option ----------------------------------
// option ----------------------------------
bool
syncNodeSnapshotEnable
(
SSyncNode
*
pSyncNode
);
bool
syncNodeSnapshotEnable
(
SSyncNode
*
pSyncNode
);
ESyncStrategy
syncNodeStrategy
(
SSyncNode
*
pSyncNode
);
// ---------------------------------------------
// ---------------------------------------------
...
...
include/util/taoserror.h
浏览文件 @
3b50fee6
...
@@ -428,6 +428,7 @@ int32_t* taosGetErrno();
...
@@ -428,6 +428,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_SYN_PROPOSE_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0911)
#define TSDB_CODE_SYN_PROPOSE_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0911)
#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_TIMEOUT TAOS_DEF_ERROR_CODE(0, 0x0914)
#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
...
@@ -578,6 +579,7 @@ int32_t* taosGetErrno();
...
@@ -578,6 +579,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_PAR_INVALID_TABLE_OPTION TAOS_DEF_ERROR_CODE(0, 0x265C)
#define TSDB_CODE_PAR_INVALID_TABLE_OPTION TAOS_DEF_ERROR_CODE(0, 0x265C)
#define TSDB_CODE_PAR_INVALID_INTERP_CLAUSE TAOS_DEF_ERROR_CODE(0, 0x265D)
#define TSDB_CODE_PAR_INVALID_INTERP_CLAUSE TAOS_DEF_ERROR_CODE(0, 0x265D)
#define TSDB_CODE_PAR_NO_VALID_FUNC_IN_WIN TAOS_DEF_ERROR_CODE(0, 0x265E)
#define TSDB_CODE_PAR_NO_VALID_FUNC_IN_WIN TAOS_DEF_ERROR_CODE(0, 0x265E)
#define TSDB_CODE_PAR_ONLY_SUPPORT_SINGLE_TABLE TAOS_DEF_ERROR_CODE(0, 0x265F)
//planner
//planner
#define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700)
#define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700)
...
@@ -627,6 +629,8 @@ int32_t* taosGetErrno();
...
@@ -627,6 +629,8 @@ int32_t* taosGetErrno();
//index
//index
#define TSDB_CODE_INDEX_REBUILDING TAOS_DEF_ERROR_CODE(0, 0x3200)
#define TSDB_CODE_INDEX_REBUILDING TAOS_DEF_ERROR_CODE(0, 0x3200)
#define TSDB_CODE_INDEX_INVALID_FILE TAOS_DEF_ERROR_CODE(0, 0x3201)
//tmq
//tmq
#define TSDB_CODE_TMQ_INVALID_MSG TAOS_DEF_ERROR_CODE(0, 0x4000)
#define TSDB_CODE_TMQ_INVALID_MSG TAOS_DEF_ERROR_CODE(0, 0x4000)
...
...
source/common/src/tdatablock.c
浏览文件 @
3b50fee6
...
@@ -895,7 +895,7 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo) {
...
@@ -895,7 +895,7 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo) {
SBlockOrderInfo
*
pOrder
=
taosArrayGet
(
pOrderInfo
,
0
);
SBlockOrderInfo
*
pOrder
=
taosArrayGet
(
pOrderInfo
,
0
);
int64_t
p0
=
taosGetTimestampUs
();
int64_t
p0
=
taosGetTimestampUs
();
__compar_fn_t
fn
=
getKeyComparFunc
(
pColInfoData
->
info
.
type
,
pOrder
->
order
);
__compar_fn_t
fn
=
getKeyComparFunc
(
pColInfoData
->
info
.
type
,
pOrder
->
order
);
taosSort
(
pColInfoData
->
pData
,
pDataBlock
->
info
.
rows
,
pColInfoData
->
info
.
bytes
,
fn
);
taosSort
(
pColInfoData
->
pData
,
pDataBlock
->
info
.
rows
,
pColInfoData
->
info
.
bytes
,
fn
);
...
@@ -923,8 +923,9 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo) {
...
@@ -923,8 +923,9 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo) {
pInfo
->
pColData
=
taosArrayGet
(
pDataBlock
->
pDataBlock
,
pInfo
->
slotId
);
pInfo
->
pColData
=
taosArrayGet
(
pDataBlock
->
pDataBlock
,
pInfo
->
slotId
);
}
}
terrno
=
0
;
taosqsort
(
index
,
rows
,
sizeof
(
int32_t
),
&
helper
,
dataBlockCompar
);
taosqsort
(
index
,
rows
,
sizeof
(
int32_t
),
&
helper
,
dataBlockCompar
);
if
(
terrno
)
return
terrno
;
if
(
terrno
)
return
terrno
;
int64_t
p1
=
taosGetTimestampUs
();
int64_t
p1
=
taosGetTimestampUs
();
...
@@ -1438,21 +1439,21 @@ static void doShiftBitmap(char* nullBitmap, size_t n, size_t total) {
...
@@ -1438,21 +1439,21 @@ static void doShiftBitmap(char* nullBitmap, size_t n, size_t total) {
}
}
}
}
static
int32_t
colDataMoveVarData
(
SColumnInfoData
*
pColInfoData
,
size_t
start
,
size_t
end
){
static
int32_t
colDataMoveVarData
(
SColumnInfoData
*
pColInfoData
,
size_t
start
,
size_t
end
)
{
int32_t
dataOffset
=
-
1
;
int32_t
dataOffset
=
-
1
;
int32_t
dataLen
=
0
;
int32_t
dataLen
=
0
;
int32_t
beigin
=
start
;
int32_t
beigin
=
start
;
while
(
beigin
<
end
)
{
while
(
beigin
<
end
)
{
int32_t
offset
=
pColInfoData
->
varmeta
.
offset
[
beigin
];
int32_t
offset
=
pColInfoData
->
varmeta
.
offset
[
beigin
];
if
(
offset
==
-
1
)
{
if
(
offset
==
-
1
)
{
beigin
++
;
beigin
++
;
continue
;
continue
;
}
}
if
(
start
!=
0
)
{
if
(
start
!=
0
)
{
pColInfoData
->
varmeta
.
offset
[
beigin
]
=
dataLen
;
pColInfoData
->
varmeta
.
offset
[
beigin
]
=
dataLen
;
}
}
char
*
data
=
pColInfoData
->
pData
+
offset
;
char
*
data
=
pColInfoData
->
pData
+
offset
;
if
(
dataOffset
==
-
1
)
dataOffset
=
offset
;
// mark the begin of data
if
(
dataOffset
==
-
1
)
dataOffset
=
offset
;
// mark the begin of data
int32_t
type
=
pColInfoData
->
info
.
type
;
int32_t
type
=
pColInfoData
->
info
.
type
;
if
(
type
==
TSDB_DATA_TYPE_JSON
)
{
if
(
type
==
TSDB_DATA_TYPE_JSON
)
{
dataLen
+=
getJsonValueLen
(
data
);
dataLen
+=
getJsonValueLen
(
data
);
...
@@ -1461,7 +1462,7 @@ static int32_t colDataMoveVarData(SColumnInfoData* pColInfoData, size_t start, s
...
@@ -1461,7 +1462,7 @@ static int32_t colDataMoveVarData(SColumnInfoData* pColInfoData, size_t start, s
}
}
beigin
++
;
beigin
++
;
}
}
if
(
dataOffset
>
0
)
{
if
(
dataOffset
>
0
)
{
memmove
(
pColInfoData
->
pData
,
pColInfoData
->
pData
+
dataOffset
,
dataLen
);
memmove
(
pColInfoData
->
pData
,
pColInfoData
->
pData
+
dataOffset
,
dataLen
);
memmove
(
pColInfoData
->
varmeta
.
offset
,
&
pColInfoData
->
varmeta
.
offset
[
start
],
(
end
-
start
)
*
sizeof
(
int32_t
));
memmove
(
pColInfoData
->
varmeta
.
offset
,
&
pColInfoData
->
varmeta
.
offset
[
start
],
(
end
-
start
)
*
sizeof
(
int32_t
));
}
}
...
...
source/dnode/mgmt/node_mgmt/src/dmProc.c
浏览文件 @
3b50fee6
...
@@ -87,8 +87,8 @@ static SProcQueue *dmInitProcQueue(SProc *proc, char *ptr, int32_t size) {
...
@@ -87,8 +87,8 @@ static SProcQueue *dmInitProcQueue(SProc *proc, char *ptr, int32_t size) {
static
void
dmCleanupProcQueue
(
SProcQueue
*
queue
)
{}
static
void
dmCleanupProcQueue
(
SProcQueue
*
queue
)
{}
static
inline
int32_t
dmPushToProcQueue
(
SProc
*
proc
,
SProcQueue
*
queue
,
SRpcMsg
*
pMsg
,
EProcFuncType
ftype
)
{
static
inline
int32_t
dmPushToProcQueue
(
SProc
*
proc
,
SProcQueue
*
queue
,
SRpcMsg
*
pMsg
,
EProcFuncType
ftype
)
{
const
void
*
pHead
=
pMsg
;
const
void
*
pHead
=
pMsg
;
const
void
*
pBody
=
pMsg
->
pCont
;
const
void
*
pBody
=
pMsg
->
pCont
;
const
int16_t
rawHeadLen
=
sizeof
(
SRpcMsg
);
const
int16_t
rawHeadLen
=
sizeof
(
SRpcMsg
);
const
int32_t
rawBodyLen
=
pMsg
->
contLen
;
const
int32_t
rawBodyLen
=
pMsg
->
contLen
;
const
int16_t
headLen
=
CEIL8
(
rawHeadLen
);
const
int16_t
headLen
=
CEIL8
(
rawHeadLen
);
...
@@ -257,7 +257,7 @@ int32_t dmInitProc(struct SMgmtWrapper *pWrapper) {
...
@@ -257,7 +257,7 @@ int32_t dmInitProc(struct SMgmtWrapper *pWrapper) {
proc
->
wrapper
=
pWrapper
;
proc
->
wrapper
=
pWrapper
;
proc
->
name
=
pWrapper
->
name
;
proc
->
name
=
pWrapper
->
name
;
SShm
*
shm
=
&
proc
->
shm
;
SShm
*
shm
=
&
proc
->
shm
;
int32_t
cstart
=
0
;
int32_t
cstart
=
0
;
int32_t
csize
=
CEIL8
(
shm
->
size
/
2
);
int32_t
csize
=
CEIL8
(
shm
->
size
/
2
);
int32_t
pstart
=
csize
;
int32_t
pstart
=
csize
;
...
@@ -281,13 +281,13 @@ int32_t dmInitProc(struct SMgmtWrapper *pWrapper) {
...
@@ -281,13 +281,13 @@ int32_t dmInitProc(struct SMgmtWrapper *pWrapper) {
}
}
static
void
*
dmConsumChildQueue
(
void
*
param
)
{
static
void
*
dmConsumChildQueue
(
void
*
param
)
{
SProc
*
proc
=
param
;
SProc
*
proc
=
param
;
SMgmtWrapper
*
pWrapper
=
proc
->
wrapper
;
SMgmtWrapper
*
pWrapper
=
proc
->
wrapper
;
SProcQueue
*
queue
=
proc
->
cqueue
;
SProcQueue
*
queue
=
proc
->
cqueue
;
int32_t
numOfMsgs
=
0
;
int32_t
numOfMsgs
=
0
;
int32_t
code
=
0
;
int32_t
code
=
0
;
EProcFuncType
ftype
=
DND_FUNC_REQ
;
EProcFuncType
ftype
=
DND_FUNC_REQ
;
SRpcMsg
*
pMsg
=
NULL
;
SRpcMsg
*
pMsg
=
NULL
;
dDebug
(
"node:%s, start to consume from cqueue"
,
proc
->
name
);
dDebug
(
"node:%s, start to consume from cqueue"
,
proc
->
name
);
do
{
do
{
...
@@ -324,13 +324,13 @@ static void *dmConsumChildQueue(void *param) {
...
@@ -324,13 +324,13 @@ static void *dmConsumChildQueue(void *param) {
}
}
static
void
*
dmConsumParentQueue
(
void
*
param
)
{
static
void
*
dmConsumParentQueue
(
void
*
param
)
{
SProc
*
proc
=
param
;
SProc
*
proc
=
param
;
SMgmtWrapper
*
pWrapper
=
proc
->
wrapper
;
SMgmtWrapper
*
pWrapper
=
proc
->
wrapper
;
SProcQueue
*
queue
=
proc
->
pqueue
;
SProcQueue
*
queue
=
proc
->
pqueue
;
int32_t
numOfMsgs
=
0
;
int32_t
numOfMsgs
=
0
;
int32_t
code
=
0
;
int32_t
code
=
0
;
EProcFuncType
ftype
=
DND_FUNC_REQ
;
EProcFuncType
ftype
=
DND_FUNC_REQ
;
SRpcMsg
*
pMsg
=
NULL
;
SRpcMsg
*
pMsg
=
NULL
;
dDebug
(
"node:%s, start to consume from pqueue"
,
proc
->
name
);
dDebug
(
"node:%s, start to consume from pqueue"
,
proc
->
name
);
do
{
do
{
...
@@ -353,7 +353,7 @@ static void *dmConsumParentQueue(void *param) {
...
@@ -353,7 +353,7 @@ static void *dmConsumParentQueue(void *param) {
rpcRegisterBrokenLinkArg
(
pMsg
);
rpcRegisterBrokenLinkArg
(
pMsg
);
}
else
if
(
ftype
==
DND_FUNC_RELEASE
)
{
}
else
if
(
ftype
==
DND_FUNC_RELEASE
)
{
dmRemoveProcRpcHandle
(
proc
,
pMsg
->
info
.
handle
);
dmRemoveProcRpcHandle
(
proc
,
pMsg
->
info
.
handle
);
rpcReleaseHandle
(
pMsg
->
info
.
handle
,
(
int8_t
)
pMsg
->
code
);
rpcReleaseHandle
(
&
pMsg
->
info
,
TAOS_CONN_SERVER
);
}
else
{
}
else
{
dError
(
"node:%s, invalid ftype:%d from pqueue"
,
proc
->
name
,
ftype
);
dError
(
"node:%s, invalid ftype:%d from pqueue"
,
proc
->
name
,
ftype
);
rpcFreeCont
(
pMsg
->
pCont
);
rpcFreeCont
(
pMsg
->
pCont
);
...
...
source/dnode/mgmt/node_mgmt/src/dmTransport.c
浏览文件 @
3b50fee6
...
@@ -245,7 +245,7 @@ static inline void dmReleaseHandle(SRpcHandleInfo *pHandle, int8_t type) {
...
@@ -245,7 +245,7 @@ static inline void dmReleaseHandle(SRpcHandleInfo *pHandle, int8_t type) {
SRpcMsg
msg
=
{.
code
=
type
,
.
info
=
*
pHandle
};
SRpcMsg
msg
=
{.
code
=
type
,
.
info
=
*
pHandle
};
dmPutToProcPQueue
(
&
pWrapper
->
proc
,
&
msg
,
DND_FUNC_RELEASE
);
dmPutToProcPQueue
(
&
pWrapper
->
proc
,
&
msg
,
DND_FUNC_RELEASE
);
}
else
{
}
else
{
rpcReleaseHandle
(
pHandle
->
handle
,
type
);
rpcReleaseHandle
(
pHandle
,
type
);
}
}
}
}
...
...
source/dnode/mnode/impl/src/mndMain.c
浏览文件 @
3b50fee6
...
@@ -58,7 +58,7 @@ static void *mndBuildTimerMsg(int32_t *pContLen) {
...
@@ -58,7 +58,7 @@ static void *mndBuildTimerMsg(int32_t *pContLen) {
static
void
mndPullupTrans
(
SMnode
*
pMnode
)
{
static
void
mndPullupTrans
(
SMnode
*
pMnode
)
{
int32_t
contLen
=
0
;
int32_t
contLen
=
0
;
void
*
pReq
=
mndBuildTimerMsg
(
&
contLen
);
void
*
pReq
=
mndBuildTimerMsg
(
&
contLen
);
if
(
pReq
!=
NULL
)
{
if
(
pReq
!=
NULL
)
{
SRpcMsg
rpcMsg
=
{.
msgType
=
TDMT_MND_TRANS_TIMER
,
.
pCont
=
pReq
,
.
contLen
=
contLen
};
SRpcMsg
rpcMsg
=
{.
msgType
=
TDMT_MND_TRANS_TIMER
,
.
pCont
=
pReq
,
.
contLen
=
contLen
};
tmsgPutToQueue
(
&
pMnode
->
msgCb
,
WRITE_QUEUE
,
&
rpcMsg
);
tmsgPutToQueue
(
&
pMnode
->
msgCb
,
WRITE_QUEUE
,
&
rpcMsg
);
...
@@ -67,14 +67,14 @@ static void mndPullupTrans(SMnode *pMnode) {
...
@@ -67,14 +67,14 @@ static void mndPullupTrans(SMnode *pMnode) {
static
void
mndTtlTimer
(
SMnode
*
pMnode
)
{
static
void
mndTtlTimer
(
SMnode
*
pMnode
)
{
int32_t
contLen
=
0
;
int32_t
contLen
=
0
;
void
*
pReq
=
mndBuildTimerMsg
(
&
contLen
);
void
*
pReq
=
mndBuildTimerMsg
(
&
contLen
);
SRpcMsg
rpcMsg
=
{.
msgType
=
TDMT_MND_TTL_TIMER
,
.
pCont
=
pReq
,
.
contLen
=
contLen
};
SRpcMsg
rpcMsg
=
{.
msgType
=
TDMT_MND_TTL_TIMER
,
.
pCont
=
pReq
,
.
contLen
=
contLen
};
tmsgPutToQueue
(
&
pMnode
->
msgCb
,
WRITE_QUEUE
,
&
rpcMsg
);
tmsgPutToQueue
(
&
pMnode
->
msgCb
,
WRITE_QUEUE
,
&
rpcMsg
);
}
}
static
void
mndCalMqRebalance
(
SMnode
*
pMnode
)
{
static
void
mndCalMqRebalance
(
SMnode
*
pMnode
)
{
int32_t
contLen
=
0
;
int32_t
contLen
=
0
;
void
*
pReq
=
mndBuildTimerMsg
(
&
contLen
);
void
*
pReq
=
mndBuildTimerMsg
(
&
contLen
);
if
(
pReq
!=
NULL
)
{
if
(
pReq
!=
NULL
)
{
SRpcMsg
rpcMsg
=
{.
msgType
=
TDMT_MND_MQ_TIMER
,
.
pCont
=
pReq
,
.
contLen
=
contLen
};
SRpcMsg
rpcMsg
=
{.
msgType
=
TDMT_MND_MQ_TIMER
,
.
pCont
=
pReq
,
.
contLen
=
contLen
};
tmsgPutToQueue
(
&
pMnode
->
msgCb
,
READ_QUEUE
,
&
rpcMsg
);
tmsgPutToQueue
(
&
pMnode
->
msgCb
,
READ_QUEUE
,
&
rpcMsg
);
...
@@ -83,7 +83,7 @@ static void mndCalMqRebalance(SMnode *pMnode) {
...
@@ -83,7 +83,7 @@ static void mndCalMqRebalance(SMnode *pMnode) {
static
void
mndPullupTelem
(
SMnode
*
pMnode
)
{
static
void
mndPullupTelem
(
SMnode
*
pMnode
)
{
int32_t
contLen
=
0
;
int32_t
contLen
=
0
;
void
*
pReq
=
mndBuildTimerMsg
(
&
contLen
);
void
*
pReq
=
mndBuildTimerMsg
(
&
contLen
);
if
(
pReq
!=
NULL
)
{
if
(
pReq
!=
NULL
)
{
SRpcMsg
rpcMsg
=
{.
msgType
=
TDMT_MND_TELEM_TIMER
,
.
pCont
=
pReq
,
.
contLen
=
contLen
};
SRpcMsg
rpcMsg
=
{.
msgType
=
TDMT_MND_TELEM_TIMER
,
.
pCont
=
pReq
,
.
contLen
=
contLen
};
tmsgPutToQueue
(
&
pMnode
->
msgCb
,
READ_QUEUE
,
&
rpcMsg
);
tmsgPutToQueue
(
&
pMnode
->
msgCb
,
READ_QUEUE
,
&
rpcMsg
);
...
@@ -395,7 +395,7 @@ void mndStop(SMnode *pMnode) {
...
@@ -395,7 +395,7 @@ void mndStop(SMnode *pMnode) {
}
}
int32_t
mndProcessSyncMsg
(
SRpcMsg
*
pMsg
)
{
int32_t
mndProcessSyncMsg
(
SRpcMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
info
.
node
;
SMnode
*
pMnode
=
pMsg
->
info
.
node
;
SSyncMgmt
*
pMgmt
=
&
pMnode
->
syncMgmt
;
SSyncMgmt
*
pMgmt
=
&
pMnode
->
syncMgmt
;
int32_t
code
=
0
;
int32_t
code
=
0
;
...
@@ -413,7 +413,7 @@ int32_t mndProcessSyncMsg(SRpcMsg *pMsg) {
...
@@ -413,7 +413,7 @@ int32_t mndProcessSyncMsg(SRpcMsg *pMsg) {
}
}
do
{
do
{
char
*
syncNodeStr
=
sync2SimpleStr
(
pMgmt
->
sync
);
char
*
syncNodeStr
=
sync2SimpleStr
(
pMgmt
->
sync
);
static
int64_t
mndTick
=
0
;
static
int64_t
mndTick
=
0
;
if
(
++
mndTick
%
10
==
1
)
{
if
(
++
mndTick
%
10
==
1
)
{
mTrace
(
"vgId:%d, sync trace msg:%s, %s"
,
syncGetVgId
(
pMgmt
->
sync
),
TMSG_INFO
(
pMsg
->
msgType
),
syncNodeStr
);
mTrace
(
"vgId:%d, sync trace msg:%s, %s"
,
syncGetVgId
(
pMgmt
->
sync
),
TMSG_INFO
(
pMsg
->
msgType
),
syncNodeStr
);
...
@@ -427,7 +427,7 @@ int32_t mndProcessSyncMsg(SRpcMsg *pMsg) {
...
@@ -427,7 +427,7 @@ int32_t mndProcessSyncMsg(SRpcMsg *pMsg) {
}
while
(
0
);
}
while
(
0
);
// ToDo: ugly! use function pointer
// ToDo: ugly! use function pointer
if
(
syncNodeS
napshotEnable
(
pSyncNode
)
)
{
if
(
syncNodeS
trategy
(
pSyncNode
)
==
SYNC_STRATEGY_STANDARD_SNAPSHOT
)
{
if
(
pMsg
->
msgType
==
TDMT_SYNC_TIMEOUT
)
{
if
(
pMsg
->
msgType
==
TDMT_SYNC_TIMEOUT
)
{
SyncTimeout
*
pSyncMsg
=
syncTimeoutFromRpcMsg2
(
pMsg
);
SyncTimeout
*
pSyncMsg
=
syncTimeoutFromRpcMsg2
(
pMsg
);
code
=
syncNodeOnTimeoutCb
(
pSyncNode
,
pSyncMsg
);
code
=
syncNodeOnTimeoutCb
(
pSyncNode
,
pSyncMsg
);
...
@@ -579,7 +579,7 @@ static int32_t mndCheckMsgContent(SRpcMsg *pMsg) {
...
@@ -579,7 +579,7 @@ static int32_t mndCheckMsgContent(SRpcMsg *pMsg) {
}
}
int32_t
mndProcessRpcMsg
(
SRpcMsg
*
pMsg
)
{
int32_t
mndProcessRpcMsg
(
SRpcMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
info
.
node
;
SMnode
*
pMnode
=
pMsg
->
info
.
node
;
const
STraceId
*
trace
=
&
pMsg
->
info
.
traceId
;
const
STraceId
*
trace
=
&
pMsg
->
info
.
traceId
;
MndMsgFp
fp
=
pMnode
->
msgFp
[
TMSG_INDEX
(
pMsg
->
msgType
)];
MndMsgFp
fp
=
pMnode
->
msgFp
[
TMSG_INDEX
(
pMsg
->
msgType
)];
...
@@ -632,7 +632,7 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr
...
@@ -632,7 +632,7 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr
SMonStbInfo
*
pStbInfo
,
SMonGrantInfo
*
pGrantInfo
)
{
SMonStbInfo
*
pStbInfo
,
SMonGrantInfo
*
pGrantInfo
)
{
if
(
mndAcquireRpcRef
(
pMnode
)
!=
0
)
return
-
1
;
if
(
mndAcquireRpcRef
(
pMnode
)
!=
0
)
return
-
1
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int64_t
ms
=
taosGetTimestampMs
();
int64_t
ms
=
taosGetTimestampMs
();
pClusterInfo
->
dnodes
=
taosArrayInit
(
sdbGetSize
(
pSdb
,
SDB_DNODE
),
sizeof
(
SMonDnodeDesc
));
pClusterInfo
->
dnodes
=
taosArrayInit
(
sdbGetSize
(
pSdb
,
SDB_DNODE
),
sizeof
(
SMonDnodeDesc
));
...
@@ -713,7 +713,7 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr
...
@@ -713,7 +713,7 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr
pGrantInfo
->
timeseries_used
+=
pVgroup
->
numOfTimeSeries
;
pGrantInfo
->
timeseries_used
+=
pVgroup
->
numOfTimeSeries
;
tstrncpy
(
desc
.
status
,
"unsynced"
,
sizeof
(
desc
.
status
));
tstrncpy
(
desc
.
status
,
"unsynced"
,
sizeof
(
desc
.
status
));
for
(
int32_t
i
=
0
;
i
<
pVgroup
->
replica
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pVgroup
->
replica
;
++
i
)
{
SVnodeGid
*
pVgid
=
&
pVgroup
->
vnodeGid
[
i
];
SVnodeGid
*
pVgid
=
&
pVgroup
->
vnodeGid
[
i
];
SMonVnodeDesc
*
pVnDesc
=
&
desc
.
vnodes
[
i
];
SMonVnodeDesc
*
pVnDesc
=
&
desc
.
vnodes
[
i
];
pVnDesc
->
dnode_id
=
pVgid
->
dnodeId
;
pVnDesc
->
dnode_id
=
pVgid
->
dnodeId
;
tstrncpy
(
pVnDesc
->
vnode_role
,
syncStr
(
pVgid
->
role
),
sizeof
(
pVnDesc
->
vnode_role
));
tstrncpy
(
pVnDesc
->
vnode_role
,
syncStr
(
pVgid
->
role
),
sizeof
(
pVnDesc
->
vnode_role
));
...
...
source/dnode/mnode/impl/src/mndSync.c
浏览文件 @
3b50fee6
...
@@ -134,7 +134,7 @@ int32_t mndSnapshotDoRead(struct SSyncFSM *pFsm, void *pReader, void **ppBuf, in
...
@@ -134,7 +134,7 @@ int32_t mndSnapshotDoRead(struct SSyncFSM *pFsm, void *pReader, void **ppBuf, in
return
sdbDoRead
(
pMnode
->
pSdb
,
pReader
,
ppBuf
,
len
);
return
sdbDoRead
(
pMnode
->
pSdb
,
pReader
,
ppBuf
,
len
);
}
}
int32_t
mndSnapshotStartWrite
(
struct
SSyncFSM
*
pFsm
,
void
**
ppWriter
)
{
int32_t
mndSnapshotStartWrite
(
struct
SSyncFSM
*
pFsm
,
void
*
pParam
,
void
*
*
ppWriter
)
{
mInfo
(
"start to apply snapshot to sdb"
);
mInfo
(
"start to apply snapshot to sdb"
);
SMnode
*
pMnode
=
pFsm
->
data
;
SMnode
*
pMnode
=
pFsm
->
data
;
return
sdbStartWrite
(
pMnode
->
pSdb
,
(
SSdbIter
**
)
ppWriter
);
return
sdbStartWrite
(
pMnode
->
pSdb
,
(
SSdbIter
**
)
ppWriter
);
...
@@ -178,7 +178,7 @@ int32_t mndInitSync(SMnode *pMnode) {
...
@@ -178,7 +178,7 @@ int32_t mndInitSync(SMnode *pMnode) {
syncInfo
.
pWal
=
pMnode
->
pWal
;
syncInfo
.
pWal
=
pMnode
->
pWal
;
syncInfo
.
pFsm
=
mndSyncMakeFsm
(
pMnode
);
syncInfo
.
pFsm
=
mndSyncMakeFsm
(
pMnode
);
syncInfo
.
isStandBy
=
pMgmt
->
standby
;
syncInfo
.
isStandBy
=
pMgmt
->
standby
;
syncInfo
.
snapshot
Enable
=
true
;
syncInfo
.
snapshot
Strategy
=
SYNC_STRATEGY_STANDARD_SNAPSHOT
;
mInfo
(
"start to open mnode sync, standby:%d"
,
pMgmt
->
standby
);
mInfo
(
"start to open mnode sync, standby:%d"
,
pMgmt
->
standby
);
if
(
pMgmt
->
standby
||
pMgmt
->
replica
.
id
>
0
)
{
if
(
pMgmt
->
standby
||
pMgmt
->
replica
.
id
>
0
)
{
...
...
source/dnode/vnode/src/sma/smaRollup.c
浏览文件 @
3b50fee6
...
@@ -915,9 +915,9 @@ static int32_t tdRSmaQTaskInfoItemRestore(SSma *pSma, const SRSmaQTaskInfoItem *
...
@@ -915,9 +915,9 @@ static int32_t tdRSmaQTaskInfoItemRestore(SSma *pSma, const SRSmaQTaskInfoItem *
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
if
(
pItem
->
type
==
1
)
{
if
(
pItem
->
type
==
TSDB_RETENTION_L
1
)
{
qTaskInfo
=
pRSmaInfo
->
items
[
0
].
taskInfo
;
qTaskInfo
=
pRSmaInfo
->
items
[
0
].
taskInfo
;
}
else
if
(
pItem
->
type
==
2
)
{
}
else
if
(
pItem
->
type
==
TSDB_RETENTION_L
2
)
{
qTaskInfo
=
pRSmaInfo
->
items
[
1
].
taskInfo
;
qTaskInfo
=
pRSmaInfo
->
items
[
1
].
taskInfo
;
}
else
{
}
else
{
ASSERT
(
0
);
ASSERT
(
0
);
...
@@ -1233,7 +1233,6 @@ static void tdRSmaPersistTask(SRSmaStat *pRSmaStat) {
...
@@ -1233,7 +1233,6 @@ static void tdRSmaPersistTask(SRSmaStat *pRSmaStat) {
}
else
{
}
else
{
smaWarn
(
"vgId:%d, persist task in abnormal stat %"
PRIi8
,
SMA_VID
(
pRSmaStat
->
pSma
),
smaWarn
(
"vgId:%d, persist task in abnormal stat %"
PRIi8
,
SMA_VID
(
pRSmaStat
->
pSma
),
atomic_load_8
(
RSMA_TRIGGER_STAT
(
pRSmaStat
)));
atomic_load_8
(
RSMA_TRIGGER_STAT
(
pRSmaStat
)));
ASSERT
(
0
);
}
}
atomic_store_8
(
RSMA_RUNNING_STAT
(
pRSmaStat
),
0
);
atomic_store_8
(
RSMA_RUNNING_STAT
(
pRSmaStat
),
0
);
taosReleaseRef
(
smaMgmt
.
smaRef
,
pRSmaStat
->
refId
);
taosReleaseRef
(
smaMgmt
.
smaRef
,
pRSmaStat
->
refId
);
...
...
source/dnode/vnode/src/vnd/vnodeSync.c
浏览文件 @
3b50fee6
...
@@ -256,70 +256,133 @@ int32_t vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
...
@@ -256,70 +256,133 @@ int32_t vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
SRpcMsg
*
pRpcMsg
=
pMsg
;
SRpcMsg
*
pRpcMsg
=
pMsg
;
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_TIMEOUT
)
{
// ToDo: ugly! use function pointer
SyncTimeout
*
pSyncMsg
=
syncTimeoutFromRpcMsg2
(
pRpcMsg
);
// use different strategy
assert
(
pSyncMsg
!=
NULL
);
if
(
syncNodeStrategy
(
pSyncNode
)
==
SYNC_STRATEGY_NO_SNAPSHOT
)
{
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_TIMEOUT
)
{
ret
=
syncNodeOnTimeoutCb
(
pSyncNode
,
pSyncMsg
);
SyncTimeout
*
pSyncMsg
=
syncTimeoutFromRpcMsg2
(
pRpcMsg
);
syncTimeoutDestroy
(
pSyncMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnTimeoutCb
(
pSyncNode
,
pSyncMsg
);
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_PING
)
{
syncTimeoutDestroy
(
pSyncMsg
);
SyncPing
*
pSyncMsg
=
syncPingFromRpcMsg2
(
pRpcMsg
);
assert
(
pSyncMsg
!=
NULL
);
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_PING
)
{
SyncPing
*
pSyncMsg
=
syncPingFromRpcMsg2
(
pRpcMsg
);
ret
=
syncNodeOnPingCb
(
pSyncNode
,
pSyncMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
syncPingDestroy
(
pSyncMsg
);
ret
=
syncNodeOnPingCb
(
pSyncNode
,
pSyncMsg
);
syncPingDestroy
(
pSyncMsg
);
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_PING_REPLY
)
{
SyncPingReply
*
pSyncMsg
=
syncPingReplyFromRpcMsg2
(
pRpcMsg
);
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_PING_REPLY
)
{
assert
(
pSyncMsg
!=
NULL
);
SyncPingReply
*
pSyncMsg
=
syncPingReplyFromRpcMsg2
(
pRpcMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnPingReplyCb
(
pSyncNode
,
pSyncMsg
);
ret
=
syncNodeOnPingReplyCb
(
pSyncNode
,
pSyncMsg
);
syncPingReplyDestroy
(
pSyncMsg
);
syncPingReplyDestroy
(
pSyncMsg
);
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_CLIENT_REQUEST
)
{
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_CLIENT_REQUEST
)
{
SyncClientRequest
*
pSyncMsg
=
syncClientRequestFromRpcMsg2
(
pRpcMsg
);
SyncClientRequest
*
pSyncMsg
=
syncClientRequestFromRpcMsg2
(
pRpcMsg
);
assert
(
pSyncMsg
!=
NULL
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnClientRequestCb
(
pSyncNode
,
pSyncMsg
,
NULL
);
ret
=
syncNodeOnClientRequestCb
(
pSyncNode
,
pSyncMsg
,
NULL
);
syncClientRequestDestroy
(
pSyncMsg
);
syncClientRequestDestroy
(
pSyncMsg
);
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_REQUEST_VOTE
)
{
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_REQUEST_VOTE
)
{
SyncRequestVote
*
pSyncMsg
=
syncRequestVoteFromRpcMsg2
(
pRpcMsg
);
SyncRequestVote
*
pSyncMsg
=
syncRequestVoteFromRpcMsg2
(
pRpcMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
assert
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnRequestVoteCb
(
pSyncNode
,
pSyncMsg
);
syncRequestVoteDestroy
(
pSyncMsg
);
ret
=
syncNodeOnRequestVoteCb
(
pSyncNode
,
pSyncMsg
);
syncRequestVoteDestroy
(
pSyncMsg
);
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_REQUEST_VOTE_REPLY
)
{
SyncRequestVoteReply
*
pSyncMsg
=
syncRequestVoteReplyFromRpcMsg2
(
pRpcMsg
);
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_REQUEST_VOTE_REPLY
)
{
ASSERT
(
pSyncMsg
!=
NULL
);
SyncRequestVoteReply
*
pSyncMsg
=
syncRequestVoteReplyFromRpcMsg2
(
pRpcMsg
);
ret
=
syncNodeOnRequestVoteReplyCb
(
pSyncNode
,
pSyncMsg
);
assert
(
pSyncMsg
!=
NULL
);
syncRequestVoteReplyDestroy
(
pSyncMsg
);
ret
=
syncNodeOnRequestVoteReplyCb
(
pSyncNode
,
pSyncMsg
);
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_APPEND_ENTRIES
)
{
syncRequestVoteReplyDestroy
(
pSyncMsg
);
SyncAppendEntries
*
pSyncMsg
=
syncAppendEntriesFromRpcMsg2
(
pRpcMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_APPEND_ENTRIES
)
{
ret
=
syncNodeOnAppendEntriesCb
(
pSyncNode
,
pSyncMsg
);
SyncAppendEntries
*
pSyncMsg
=
syncAppendEntriesFromRpcMsg2
(
pRpcMsg
);
syncAppendEntriesDestroy
(
pSyncMsg
);
assert
(
pSyncMsg
!=
NULL
);
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_APPEND_ENTRIES_REPLY
)
{
ret
=
syncNodeOnAppendEntriesCb
(
pSyncNode
,
pSyncMsg
);
SyncAppendEntriesReply
*
pSyncMsg
=
syncAppendEntriesReplyFromRpcMsg2
(
pRpcMsg
);
syncAppendEntriesDestroy
(
pSyncMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnAppendEntriesReplyCb
(
pSyncNode
,
pSyncMsg
);
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_APPEND_ENTRIES_REPLY
)
{
syncAppendEntriesReplyDestroy
(
pSyncMsg
);
SyncAppendEntriesReply
*
pSyncMsg
=
syncAppendEntriesReplyFromRpcMsg2
(
pRpcMsg
);
assert
(
pSyncMsg
!=
NULL
);
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_SET_VNODE_STANDBY
)
{
ret
=
vnodeSetStandBy
(
pVnode
);
ret
=
syncNodeOnAppendEntriesReplyCb
(
pSyncNode
,
pSyncMsg
);
if
(
ret
!=
0
&&
terrno
!=
0
)
ret
=
terrno
;
syncAppendEntriesReplyDestroy
(
pSyncMsg
);
SRpcMsg
rsp
=
{.
code
=
ret
,
.
info
=
pMsg
->
info
};
tmsgSendRsp
(
&
rsp
);
}
else
{
vError
(
"==vnodeProcessSyncReq== error msg type:%d"
,
pRpcMsg
->
msgType
);
ret
=
-
1
;
}
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_SET_VNODE_STANDBY
)
{
ret
=
vnodeSetStandBy
(
pVnode
);
if
(
ret
!=
0
&&
terrno
!=
0
)
ret
=
terrno
;
SRpcMsg
rsp
=
{.
code
=
ret
,
.
info
=
pMsg
->
info
};
tmsgSendRsp
(
&
rsp
);
}
else
{
}
else
{
vError
(
"==vnodeProcessSyncReq== error msg type:%d"
,
pRpcMsg
->
msgType
);
// use wal first strategy
ret
=
-
1
;
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_TIMEOUT
)
{
SyncTimeout
*
pSyncMsg
=
syncTimeoutFromRpcMsg2
(
pRpcMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnTimeoutCb
(
pSyncNode
,
pSyncMsg
);
syncTimeoutDestroy
(
pSyncMsg
);
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_PING
)
{
SyncPing
*
pSyncMsg
=
syncPingFromRpcMsg2
(
pRpcMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnPingCb
(
pSyncNode
,
pSyncMsg
);
syncPingDestroy
(
pSyncMsg
);
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_PING_REPLY
)
{
SyncPingReply
*
pSyncMsg
=
syncPingReplyFromRpcMsg2
(
pRpcMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnPingReplyCb
(
pSyncNode
,
pSyncMsg
);
syncPingReplyDestroy
(
pSyncMsg
);
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_CLIENT_REQUEST
)
{
SyncClientRequest
*
pSyncMsg
=
syncClientRequestFromRpcMsg2
(
pRpcMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnClientRequestCb
(
pSyncNode
,
pSyncMsg
,
NULL
);
syncClientRequestDestroy
(
pSyncMsg
);
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_CLIENT_REQUEST_BATCH
)
{
SyncClientRequestBatch
*
pSyncMsg
=
syncClientRequestBatchFromRpcMsg
(
pRpcMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnClientRequestBatchCb
(
pSyncNode
,
pSyncMsg
);
syncClientRequestBatchDestroyDeep
(
pSyncMsg
);
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_REQUEST_VOTE
)
{
SyncRequestVote
*
pSyncMsg
=
syncRequestVoteFromRpcMsg2
(
pRpcMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnRequestVoteCb
(
pSyncNode
,
pSyncMsg
);
syncRequestVoteDestroy
(
pSyncMsg
);
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_REQUEST_VOTE_REPLY
)
{
SyncRequestVoteReply
*
pSyncMsg
=
syncRequestVoteReplyFromRpcMsg2
(
pRpcMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnRequestVoteReplyCb
(
pSyncNode
,
pSyncMsg
);
syncRequestVoteReplyDestroy
(
pSyncMsg
);
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_APPEND_ENTRIES_BATCH
)
{
SyncAppendEntriesBatch
*
pSyncMsg
=
syncAppendEntriesBatchFromRpcMsg2
(
pRpcMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnAppendEntriesSnapshot2Cb
(
pSyncNode
,
pSyncMsg
);
syncAppendEntriesBatchDestroy
(
pSyncMsg
);
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_APPEND_ENTRIES_REPLY
)
{
SyncAppendEntriesReply
*
pSyncMsg
=
syncAppendEntriesReplyFromRpcMsg2
(
pRpcMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnAppendEntriesReplySnapshot2Cb
(
pSyncNode
,
pSyncMsg
);
syncAppendEntriesReplyDestroy
(
pSyncMsg
);
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_SET_VNODE_STANDBY
)
{
ret
=
vnodeSetStandBy
(
pVnode
);
if
(
ret
!=
0
&&
terrno
!=
0
)
ret
=
terrno
;
SRpcMsg
rsp
=
{.
code
=
ret
,
.
info
=
pMsg
->
info
};
tmsgSendRsp
(
&
rsp
);
}
else
{
vError
(
"==vnodeProcessSyncReq== error msg type:%d"
,
pRpcMsg
->
msgType
);
ret
=
-
1
;
}
}
}
syncNodeRelease
(
pSyncNode
);
syncNodeRelease
(
pSyncNode
);
...
@@ -415,7 +478,7 @@ static int32_t vnodeSnapshotStopRead(struct SSyncFSM *pFsm, void *pReader) { ret
...
@@ -415,7 +478,7 @@ static int32_t vnodeSnapshotStopRead(struct SSyncFSM *pFsm, void *pReader) { ret
static
int32_t
vnodeSnapshotDoRead
(
struct
SSyncFSM
*
pFsm
,
void
*
pReader
,
void
**
ppBuf
,
int32_t
*
len
)
{
return
0
;
}
static
int32_t
vnodeSnapshotDoRead
(
struct
SSyncFSM
*
pFsm
,
void
*
pReader
,
void
**
ppBuf
,
int32_t
*
len
)
{
return
0
;
}
static
int32_t
vnodeSnapshotStartWrite
(
struct
SSyncFSM
*
pFsm
,
void
**
ppWriter
)
{
return
0
;
}
static
int32_t
vnodeSnapshotStartWrite
(
struct
SSyncFSM
*
pFsm
,
void
*
pParam
,
void
*
*
ppWriter
)
{
return
0
;
}
static
int32_t
vnodeSnapshotStopWrite
(
struct
SSyncFSM
*
pFsm
,
void
*
pWriter
,
bool
isApply
)
{
return
0
;
}
static
int32_t
vnodeSnapshotStopWrite
(
struct
SSyncFSM
*
pFsm
,
void
*
pWriter
,
bool
isApply
)
{
return
0
;
}
...
@@ -442,7 +505,8 @@ static SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode) {
...
@@ -442,7 +505,8 @@ static SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode) {
int32_t
vnodeSyncOpen
(
SVnode
*
pVnode
,
char
*
path
)
{
int32_t
vnodeSyncOpen
(
SVnode
*
pVnode
,
char
*
path
)
{
SSyncInfo
syncInfo
=
{
SSyncInfo
syncInfo
=
{
.
snapshotEnable
=
false
,
.
snapshotStrategy
=
SYNC_STRATEGY_NO_SNAPSHOT
,
.
batchSize
=
10
,
.
vgId
=
pVnode
->
config
.
vgId
,
.
vgId
=
pVnode
->
config
.
vgId
,
.
isStandBy
=
pVnode
->
config
.
standby
,
.
isStandBy
=
pVnode
->
config
.
standby
,
.
syncCfg
=
pVnode
->
config
.
syncCfg
,
.
syncCfg
=
pVnode
->
config
.
syncCfg
,
...
...
source/libs/function/src/builtins.c
浏览文件 @
3b50fee6
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
#include "querynodes.h"
#include "querynodes.h"
#include "scalar.h"
#include "scalar.h"
#include "taoserror.h"
#include "taoserror.h"
#include "cJSON.h"
static
int32_t
buildFuncErrMsg
(
char
*
pErrBuf
,
int32_t
len
,
int32_t
errCode
,
const
char
*
pFormat
,
...)
{
static
int32_t
buildFuncErrMsg
(
char
*
pErrBuf
,
int32_t
len
,
int32_t
errCode
,
const
char
*
pFormat
,
...)
{
va_list
vArgList
;
va_list
vArgList
;
...
@@ -796,6 +797,165 @@ static int32_t translateLeastSQR(SFunctionNode* pFunc, char* pErrBuf, int32_t le
...
@@ -796,6 +797,165 @@ static int32_t translateLeastSQR(SFunctionNode* pFunc, char* pErrBuf, int32_t le
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
typedef
enum
{
UNKNOWN_BIN
=
0
,
USER_INPUT_BIN
,
LINEAR_BIN
,
LOG_BIN
}
EHistoBinType
;
static
int8_t
validateHistogramBinType
(
char
*
binTypeStr
)
{
int8_t
binType
;
if
(
strcasecmp
(
binTypeStr
,
"user_input"
)
==
0
)
{
binType
=
USER_INPUT_BIN
;
}
else
if
(
strcasecmp
(
binTypeStr
,
"linear_bin"
)
==
0
)
{
binType
=
LINEAR_BIN
;
}
else
if
(
strcasecmp
(
binTypeStr
,
"log_bin"
)
==
0
)
{
binType
=
LOG_BIN
;
}
else
{
binType
=
UNKNOWN_BIN
;
}
return
binType
;
}
static
bool
validateHistogramBinDesc
(
char
*
binDescStr
,
int8_t
binType
,
char
*
errMsg
,
int32_t
msgLen
)
{
const
char
*
msg1
=
"HISTOGRAM function requires four parameters"
;
const
char
*
msg3
=
"HISTOGRAM function invalid format for binDesc parameter"
;
const
char
*
msg4
=
"HISTOGRAM function binDesc parameter
\"
count
\"
should be in range [1, 1000]"
;
const
char
*
msg5
=
"HISTOGRAM function bin/parameter should be in range [-DBL_MAX, DBL_MAX]"
;
const
char
*
msg6
=
"HISTOGRAM function binDesc parameter
\"
width
\"
cannot be 0"
;
const
char
*
msg7
=
"HISTOGRAM function binDesc parameter
\"
start
\"
cannot be 0 with
\"
log_bin
\"
type"
;
const
char
*
msg8
=
"HISTOGRAM function binDesc parameter
\"
factor
\"
cannot be negative or equal to 0/1"
;
cJSON
*
binDesc
=
cJSON_Parse
(
binDescStr
);
int32_t
numOfBins
;
double
*
intervals
;
if
(
cJSON_IsObject
(
binDesc
))
{
/* linaer/log bins */
int32_t
numOfParams
=
cJSON_GetArraySize
(
binDesc
);
int32_t
startIndex
;
if
(
numOfParams
!=
4
)
{
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg1
);
return
false
;
}
cJSON
*
start
=
cJSON_GetObjectItem
(
binDesc
,
"start"
);
cJSON
*
factor
=
cJSON_GetObjectItem
(
binDesc
,
"factor"
);
cJSON
*
width
=
cJSON_GetObjectItem
(
binDesc
,
"width"
);
cJSON
*
count
=
cJSON_GetObjectItem
(
binDesc
,
"count"
);
cJSON
*
infinity
=
cJSON_GetObjectItem
(
binDesc
,
"infinity"
);
if
(
!
cJSON_IsNumber
(
start
)
||
!
cJSON_IsNumber
(
count
)
||
!
cJSON_IsBool
(
infinity
))
{
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg3
);
return
false
;
}
if
(
count
->
valueint
<=
0
||
count
->
valueint
>
1000
)
{
// limit count to 1000
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg4
);
return
false
;
}
if
(
isinf
(
start
->
valuedouble
)
||
(
width
!=
NULL
&&
isinf
(
width
->
valuedouble
))
||
(
factor
!=
NULL
&&
isinf
(
factor
->
valuedouble
))
||
(
count
!=
NULL
&&
isinf
(
count
->
valuedouble
)))
{
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg5
);
return
false
;
}
int32_t
counter
=
(
int32_t
)
count
->
valueint
;
if
(
infinity
->
valueint
==
false
)
{
startIndex
=
0
;
numOfBins
=
counter
+
1
;
}
else
{
startIndex
=
1
;
numOfBins
=
counter
+
3
;
}
intervals
=
taosMemoryCalloc
(
numOfBins
,
sizeof
(
double
));
if
(
cJSON_IsNumber
(
width
)
&&
factor
==
NULL
&&
binType
==
LINEAR_BIN
)
{
// linear bin process
if
(
width
->
valuedouble
==
0
)
{
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg6
);
taosMemoryFree
(
intervals
);
return
false
;
}
for
(
int
i
=
0
;
i
<
counter
+
1
;
++
i
)
{
intervals
[
startIndex
]
=
start
->
valuedouble
+
i
*
width
->
valuedouble
;
if
(
isinf
(
intervals
[
startIndex
]))
{
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg5
);
taosMemoryFree
(
intervals
);
return
false
;
}
startIndex
++
;
}
}
else
if
(
cJSON_IsNumber
(
factor
)
&&
width
==
NULL
&&
binType
==
LOG_BIN
)
{
// log bin process
if
(
start
->
valuedouble
==
0
)
{
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg7
);
taosMemoryFree
(
intervals
);
return
false
;
}
if
(
factor
->
valuedouble
<
0
||
factor
->
valuedouble
==
0
||
factor
->
valuedouble
==
1
)
{
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg8
);
taosMemoryFree
(
intervals
);
return
false
;
}
for
(
int
i
=
0
;
i
<
counter
+
1
;
++
i
)
{
intervals
[
startIndex
]
=
start
->
valuedouble
*
pow
(
factor
->
valuedouble
,
i
*
1
.
0
);
if
(
isinf
(
intervals
[
startIndex
]))
{
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg5
);
taosMemoryFree
(
intervals
);
return
false
;
}
startIndex
++
;
}
}
else
{
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg3
);
taosMemoryFree
(
intervals
);
return
false
;
}
if
(
infinity
->
valueint
==
true
)
{
intervals
[
0
]
=
-
INFINITY
;
intervals
[
numOfBins
-
1
]
=
INFINITY
;
// in case of desc bin orders, -inf/inf should be swapped
ASSERT
(
numOfBins
>=
4
);
if
(
intervals
[
1
]
>
intervals
[
numOfBins
-
2
])
{
TSWAP
(
intervals
[
0
],
intervals
[
numOfBins
-
1
]);
}
}
}
else
if
(
cJSON_IsArray
(
binDesc
))
{
/* user input bins */
if
(
binType
!=
USER_INPUT_BIN
)
{
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg3
);
return
false
;
}
numOfBins
=
cJSON_GetArraySize
(
binDesc
);
intervals
=
taosMemoryCalloc
(
numOfBins
,
sizeof
(
double
));
cJSON
*
bin
=
binDesc
->
child
;
if
(
bin
==
NULL
)
{
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg3
);
taosMemoryFree
(
intervals
);
return
false
;
}
int
i
=
0
;
while
(
bin
)
{
intervals
[
i
]
=
bin
->
valuedouble
;
if
(
!
cJSON_IsNumber
(
bin
))
{
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg3
);
taosMemoryFree
(
intervals
);
return
false
;
}
if
(
i
!=
0
&&
intervals
[
i
]
<=
intervals
[
i
-
1
])
{
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg3
);
taosMemoryFree
(
intervals
);
return
false
;
}
bin
=
bin
->
next
;
i
++
;
}
}
else
{
snprintf
(
errMsg
,
msgLen
,
"%s"
,
msg3
);
return
false
;
}
taosMemoryFree
(
intervals
);
return
true
;
}
static
int32_t
translateHistogram
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
)
{
static
int32_t
translateHistogram
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
)
{
int32_t
numOfParams
=
LIST_LENGTH
(
pFunc
->
pParameterList
);
int32_t
numOfParams
=
LIST_LENGTH
(
pFunc
->
pParameterList
);
if
(
4
!=
numOfParams
)
{
if
(
4
!=
numOfParams
)
{
...
@@ -814,6 +974,8 @@ static int32_t translateHistogram(SFunctionNode* pFunc, char* pErrBuf, int32_t l
...
@@ -814,6 +974,8 @@ static int32_t translateHistogram(SFunctionNode* pFunc, char* pErrBuf, int32_t l
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
}
int8_t
binType
;
char
*
binDesc
;
for
(
int32_t
i
=
1
;
i
<
numOfParams
;
++
i
)
{
for
(
int32_t
i
=
1
;
i
<
numOfParams
;
++
i
)
{
SNode
*
pParamNode
=
nodesListGetNode
(
pFunc
->
pParameterList
,
i
);
SNode
*
pParamNode
=
nodesListGetNode
(
pFunc
->
pParameterList
,
i
);
if
(
QUERY_NODE_VALUE
!=
nodeType
(
pParamNode
))
{
if
(
QUERY_NODE_VALUE
!=
nodeType
(
pParamNode
))
{
...
@@ -824,6 +986,23 @@ static int32_t translateHistogram(SFunctionNode* pFunc, char* pErrBuf, int32_t l
...
@@ -824,6 +986,23 @@ static int32_t translateHistogram(SFunctionNode* pFunc, char* pErrBuf, int32_t l
pValue
->
notReserved
=
true
;
pValue
->
notReserved
=
true
;
if
(
i
==
1
)
{
binType
=
validateHistogramBinType
(
varDataVal
(
pValue
->
datum
.
p
));
if
(
binType
==
UNKNOWN_BIN
)
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"HISTOGRAM function binType parameter should be "
"
\"
user_input
\"
,
\"
log_bin
\"
or
\"
linear_bin
\"
"
);
}
}
if
(
i
==
2
)
{
char
errMsg
[
128
]
=
{
0
};
binDesc
=
varDataVal
(
pValue
->
datum
.
p
);
if
(
!
validateHistogramBinDesc
(
binDesc
,
binType
,
errMsg
,
(
int32_t
)
sizeof
(
errMsg
)))
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
errMsg
);
}
}
if
(
i
==
3
&&
pValue
->
datum
.
i
!=
1
&&
pValue
->
datum
.
i
!=
0
)
{
if
(
i
==
3
&&
pValue
->
datum
.
i
!=
1
&&
pValue
->
datum
.
i
!=
0
)
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"HISTOGRAM function normalized parameter should be 0/1"
);
"HISTOGRAM function normalized parameter should be 0/1"
);
...
@@ -853,6 +1032,8 @@ static int32_t translateHistogramImpl(SFunctionNode* pFunc, char* pErrBuf, int32
...
@@ -853,6 +1032,8 @@ static int32_t translateHistogramImpl(SFunctionNode* pFunc, char* pErrBuf, int32
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
}
int8_t
binType
;
char
*
binDesc
;
for
(
int32_t
i
=
1
;
i
<
numOfParams
;
++
i
)
{
for
(
int32_t
i
=
1
;
i
<
numOfParams
;
++
i
)
{
SNode
*
pParamNode
=
nodesListGetNode
(
pFunc
->
pParameterList
,
i
);
SNode
*
pParamNode
=
nodesListGetNode
(
pFunc
->
pParameterList
,
i
);
if
(
QUERY_NODE_VALUE
!=
nodeType
(
pParamNode
))
{
if
(
QUERY_NODE_VALUE
!=
nodeType
(
pParamNode
))
{
...
@@ -863,6 +1044,23 @@ static int32_t translateHistogramImpl(SFunctionNode* pFunc, char* pErrBuf, int32
...
@@ -863,6 +1044,23 @@ static int32_t translateHistogramImpl(SFunctionNode* pFunc, char* pErrBuf, int32
pValue
->
notReserved
=
true
;
pValue
->
notReserved
=
true
;
if
(
i
==
1
)
{
binType
=
validateHistogramBinType
(
varDataVal
(
pValue
->
datum
.
p
));
if
(
binType
==
UNKNOWN_BIN
)
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"HISTOGRAM function binType parameter should be "
"
\"
user_input
\"
,
\"
log_bin
\"
or
\"
linear_bin
\"
"
);
}
}
if
(
i
==
2
)
{
char
errMsg
[
128
]
=
{
0
};
binDesc
=
varDataVal
(
pValue
->
datum
.
p
);
if
(
!
validateHistogramBinDesc
(
binDesc
,
binType
,
errMsg
,
(
int32_t
)
sizeof
(
errMsg
)))
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
errMsg
);
}
}
if
(
i
==
3
&&
pValue
->
datum
.
i
!=
1
&&
pValue
->
datum
.
i
!=
0
)
{
if
(
i
==
3
&&
pValue
->
datum
.
i
!=
1
&&
pValue
->
datum
.
i
!=
0
)
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"HISTOGRAM function normalized parameter should be 0/1"
);
"HISTOGRAM function normalized parameter should be 0/1"
);
...
@@ -2112,7 +2310,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
...
@@ -2112,7 +2310,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
{
.
name
=
"histogram"
,
.
name
=
"histogram"
,
.
type
=
FUNCTION_TYPE_HISTOGRAM
,
.
type
=
FUNCTION_TYPE_HISTOGRAM
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_FORBID_FILL_FUNC
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_
INDEFINITE_ROWS_FUNC
|
FUNC_MGT_
FORBID_FILL_FUNC
,
.
translateFunc
=
translateHistogram
,
.
translateFunc
=
translateHistogram
,
.
getEnvFunc
=
getHistogramFuncEnv
,
.
getEnvFunc
=
getHistogramFuncEnv
,
.
initFunc
=
histogramFunctionSetup
,
.
initFunc
=
histogramFunctionSetup
,
...
...
source/libs/function/src/functionMgt.c
浏览文件 @
3b50fee6
...
@@ -260,7 +260,7 @@ bool fmIsSameInOutType(int32_t funcId) {
...
@@ -260,7 +260,7 @@ bool fmIsSameInOutType(int32_t funcId) {
}
}
static
int32_t
getFuncInfo
(
SFunctionNode
*
pFunc
)
{
static
int32_t
getFuncInfo
(
SFunctionNode
*
pFunc
)
{
char
msg
[
64
]
=
{
0
};
char
msg
[
128
]
=
{
0
};
return
fmGetFuncInfo
(
pFunc
,
msg
,
sizeof
(
msg
));
return
fmGetFuncInfo
(
pFunc
,
msg
,
sizeof
(
msg
));
}
}
...
...
source/libs/index/inc/indexFst.h
浏览文件 @
3b50fee6
...
@@ -21,7 +21,7 @@ extern "C" {
...
@@ -21,7 +21,7 @@ extern "C" {
#endif
#endif
#include "indexFstAutomation.h"
#include "indexFstAutomation.h"
#include "indexFst
CountingWriter
.h"
#include "indexFst
File
.h"
#include "indexFstNode.h"
#include "indexFstNode.h"
#include "indexFstRegistry.h"
#include "indexFstRegistry.h"
#include "indexFstUtil.h"
#include "indexFstUtil.h"
...
@@ -90,8 +90,8 @@ FstBuilderNode* fstUnFinishedNodesPopEmpty(FstUnFinishedNodes* nodes);
...
@@ -90,8 +90,8 @@ FstBuilderNode* fstUnFinishedNodesPopEmpty(FstUnFinishedNodes* nodes);
uint64_t
fstUnFinishedNodesFindCommPrefixAndSetOutput
(
FstUnFinishedNodes
*
node
,
FstSlice
bs
,
Output
in
,
Output
*
out
);
uint64_t
fstUnFinishedNodesFindCommPrefixAndSetOutput
(
FstUnFinishedNodes
*
node
,
FstSlice
bs
,
Output
in
,
Output
*
out
);
typedef
struct
FstBuilder
{
typedef
struct
FstBuilder
{
FstCountingWriter
*
wrt
;
// The FST raw data is written directly to `wtr`.
IdxFstFile
*
wrt
;
// The FST raw data is written directly to `wtr`.
FstUnFinishedNodes
*
unfinished
;
// The stack of unfinished nodes
FstUnFinishedNodes
*
unfinished
;
// The stack of unfinished
nodes
FstRegistry
*
registry
;
// A map of finished nodes.
FstRegistry
*
registry
;
// A map of finished nodes.
FstSlice
last
;
// The last word added
FstSlice
last
;
// The last word added
CompiledAddr
lastAddr
;
// The address of the last compiled node
CompiledAddr
lastAddr
;
// The address of the last compiled node
...
@@ -125,9 +125,9 @@ FstState fstStateCreateFrom(FstSlice* data, CompiledAddr addr);
...
@@ -125,9 +125,9 @@ FstState fstStateCreateFrom(FstSlice* data, CompiledAddr addr);
FstState
fstStateCreate
(
State
state
);
FstState
fstStateCreate
(
State
state
);
// compile
// compile
void
fstStateCompileForOneTransNext
(
FstCountingWriter
*
w
,
CompiledAddr
addr
,
uint8_t
inp
);
void
fstStateCompileForOneTransNext
(
IdxFstFile
*
w
,
CompiledAddr
addr
,
uint8_t
inp
);
void
fstStateCompileForOneTrans
(
FstCountingWriter
*
w
,
CompiledAddr
addr
,
FstTransition
*
trn
);
void
fstStateCompileForOneTrans
(
IdxFstFile
*
w
,
CompiledAddr
addr
,
FstTransition
*
trn
);
void
fstStateCompileForAnyTrans
(
FstCountingWriter
*
w
,
CompiledAddr
addr
,
FstBuilderNode
*
node
);
void
fstStateCompileForAnyTrans
(
IdxFstFile
*
w
,
CompiledAddr
addr
,
FstBuilderNode
*
node
);
// set_comm_input
// set_comm_input
void
fstStateSetCommInput
(
FstState
*
state
,
uint8_t
inp
);
void
fstStateSetCommInput
(
FstState
*
state
,
uint8_t
inp
);
...
@@ -282,7 +282,7 @@ FStmSt* stmBuilderIntoStm(FStmBuilder* sb);
...
@@ -282,7 +282,7 @@ FStmSt* stmBuilderIntoStm(FStmBuilder* sb);
bool
fstVerify
(
Fst
*
fst
);
bool
fstVerify
(
Fst
*
fst
);
// refactor this function
// refactor this function
bool
fstBuilderNodeCompileTo
(
FstBuilderNode
*
b
,
FstCountingWriter
*
wrt
,
CompiledAddr
lastAddr
,
CompiledAddr
startAddr
);
bool
fstBuilderNodeCompileTo
(
FstBuilderNode
*
b
,
IdxFstFile
*
wrt
,
CompiledAddr
lastAddr
,
CompiledAddr
startAddr
);
typedef
struct
StreamState
{
typedef
struct
StreamState
{
FstNode
*
node
;
FstNode
*
node
;
...
...
source/libs/index/inc/indexFst
CountingWriter
.h
→
source/libs/index/inc/indexFst
File
.h
浏览文件 @
3b50fee6
...
@@ -13,8 +13,8 @@
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#ifndef __INDEX_FST_
COUNTING_WRITER
_H__
#ifndef __INDEX_FST_
FILE
_H__
#define __INDEX_FST_
COUNTING_WRITER
_H__
#define __INDEX_FST_
FILE
_H__
#include "indexInt.h"
#include "indexInt.h"
...
@@ -29,65 +29,65 @@ extern "C" {
...
@@ -29,65 +29,65 @@ extern "C" {
static
char
tmpFile
[]
=
"./index"
;
static
char
tmpFile
[]
=
"./index"
;
typedef
enum
WriterType
{
TMemory
,
TFile
}
WriterType
;
typedef
enum
WriterType
{
TMemory
,
TFile
}
WriterType
;
typedef
struct
Writer
Ctx
{
typedef
struct
IFile
Ctx
{
int
(
*
write
)(
struct
Writer
Ctx
*
ctx
,
uint8_t
*
buf
,
int
len
);
int
(
*
write
)(
struct
IFile
Ctx
*
ctx
,
uint8_t
*
buf
,
int
len
);
int
(
*
read
)(
struct
Writer
Ctx
*
ctx
,
uint8_t
*
buf
,
int
len
);
int
(
*
read
)(
struct
IFile
Ctx
*
ctx
,
uint8_t
*
buf
,
int
len
);
int
(
*
flush
)(
struct
Writer
Ctx
*
ctx
);
int
(
*
flush
)(
struct
IFile
Ctx
*
ctx
);
int
(
*
readFrom
)(
struct
Writer
Ctx
*
ctx
,
uint8_t
*
buf
,
int
len
,
int32_t
offset
);
int
(
*
readFrom
)(
struct
IFile
Ctx
*
ctx
,
uint8_t
*
buf
,
int
len
,
int32_t
offset
);
int
(
*
size
)(
struct
Writer
Ctx
*
ctx
);
int
(
*
size
)(
struct
IFile
Ctx
*
ctx
);
WriterType
type
;
WriterType
type
;
union
{
union
{
struct
{
struct
{
TdFilePtr
pFile
;
TdFilePtr
pFile
;
bool
readOnly
;
bool
readOnly
;
char
buf
[
256
];
char
buf
[
256
];
int
size
;
int
64_t
size
;
#ifdef USE_MMAP
#ifdef USE_MMAP
char
*
ptr
;
char
*
ptr
;
#endif
#endif
}
file
;
}
file
;
struct
{
struct
{
int32_t
cap
a
;
int32_t
cap
;
char
*
buf
;
char
*
buf
;
}
mem
;
}
mem
;
};
};
int32_t
offset
;
int32_t
offset
;
int32_t
limit
;
int32_t
limit
;
}
Writer
Ctx
;
}
IFile
Ctx
;
static
int
writeCtxDoWrite
(
Writer
Ctx
*
ctx
,
uint8_t
*
buf
,
int
len
);
static
int
idxFileCtxDoWrite
(
IFile
Ctx
*
ctx
,
uint8_t
*
buf
,
int
len
);
static
int
writeCtxDoRead
(
Writer
Ctx
*
ctx
,
uint8_t
*
buf
,
int
len
);
static
int
idxFileCtxDoRead
(
IFile
Ctx
*
ctx
,
uint8_t
*
buf
,
int
len
);
static
int
writeCtxDoReadFrom
(
Writer
Ctx
*
ctx
,
uint8_t
*
buf
,
int
len
,
int32_t
offset
);
static
int
idxFileCtxDoReadFrom
(
IFile
Ctx
*
ctx
,
uint8_t
*
buf
,
int
len
,
int32_t
offset
);
static
int
writeCtxDoFlush
(
Writer
Ctx
*
ctx
);
static
int
idxFileCtxDoFlush
(
IFile
Ctx
*
ctx
);
WriterCtx
*
writer
CtxCreate
(
WriterType
type
,
const
char
*
path
,
bool
readOnly
,
int32_t
capacity
);
IFileCtx
*
idxFile
CtxCreate
(
WriterType
type
,
const
char
*
path
,
bool
readOnly
,
int32_t
capacity
);
void
writerCtxDestroy
(
Writer
Ctx
*
w
,
bool
remove
);
void
idxFileCtxDestroy
(
IFile
Ctx
*
w
,
bool
remove
);
typedef
uint32_t
CheckSummer
;
typedef
uint32_t
CheckSummer
;
typedef
struct
FstCountingWriter
{
typedef
struct
IdxFstFile
{
void
*
wrt
;
// wrap any writer that counts and checksum bytes written
void
*
wrt
;
// wrap any writer that counts and checksum bytes written
uint64_t
count
;
uint64_t
count
;
CheckSummer
summer
;
CheckSummer
summer
;
}
FstCountingWriter
;
}
IdxFstFile
;
int
fstCountingWriterWrite
(
FstCountingWriter
*
write
,
uint8_t
*
buf
,
uint32_t
len
);
int
idxFileWrite
(
IdxFstFile
*
write
,
uint8_t
*
buf
,
uint32_t
len
);
int
fstCountingWriterRead
(
FstCountingWriter
*
write
,
uint8_t
*
buf
,
uint32_t
len
);
int
idxFileRead
(
IdxFstFile
*
write
,
uint8_t
*
buf
,
uint32_t
len
);
int
fstCountingWriterFlush
(
FstCountingWriter
*
write
);
int
idxFileFlush
(
IdxFstFile
*
write
);
uint32_t
fstCountingWriterMaskedCheckSum
(
FstCountingWriter
*
write
);
uint32_t
idxFileMaskedCheckSum
(
IdxFstFile
*
write
);
FstCountingWriter
*
fstCountingWriter
Create
(
void
*
wtr
);
IdxFstFile
*
idxFile
Create
(
void
*
wtr
);
void
fstCountingWriterDestroy
(
FstCountingWriter
*
w
);
void
idxFileDestroy
(
IdxFstFile
*
w
);
void
fstCountingWriterPackUintIn
(
FstCountingWriter
*
writer
,
uint64_t
n
,
uint8_t
nBytes
);
void
idxFilePackUintIn
(
IdxFstFile
*
writer
,
uint64_t
n
,
uint8_t
nBytes
);
uint8_t
fstCountingWriterPackUint
(
FstCountingWriter
*
writer
,
uint64_t
n
);
uint8_t
idxFilePackUint
(
IdxFstFile
*
writer
,
uint64_t
n
);
#define FST_WRITER_COUNT(writer) (writer->count)
#define FST_WRITER_COUNT(writer)
(writer->count)
#define FST_WRITER_INTER_WRITER(writer) (writer->wtr)
#define FST_WRITER_INTER_WRITER(writer) (writer->wtr)
#define FST_WRITE_CHECK_SUMMER(writer) (writer->summer)
#define FST_WRITE_CHECK_SUMMER(writer)
(writer->summer)
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
source/libs/index/inc/indexFstNode.h
浏览文件 @
3b50fee6
...
@@ -20,12 +20,12 @@
...
@@ -20,12 +20,12 @@
extern
"C"
{
extern
"C"
{
#endif
#endif
#include "indexFst
CountingWriter
.h"
#include "indexFst
File
.h"
#include "indexFstUtil.h"
#include "indexFstUtil.h"
#include "indexInt.h"
#include "indexInt.h"
#define FST_BUILDER_NODE_IS_FINAL(bn) (bn->isFinal)
#define FST_BUILDER_NODE_IS_FINAL(bn)
(bn->isFinal)
#define FST_BUILDER_NODE_TRANS_ISEMPTY(bn) (taosArrayGetSize(bn->trans) == 0)
#define FST_BUILDER_NODE_TRANS_ISEMPTY(bn)
(taosArrayGetSize(bn->trans) == 0)
#define FST_BUILDER_NODE_FINALOUTPUT_ISZERO(bn) (bn->finalOutput == 0)
#define FST_BUILDER_NODE_FINALOUTPUT_ISZERO(bn) (bn->finalOutput == 0)
typedef
struct
FstTransition
{
typedef
struct
FstTransition
{
...
@@ -46,7 +46,7 @@ FstBuilderNode* fstBuilderNodeClone(FstBuilderNode* src);
...
@@ -46,7 +46,7 @@ FstBuilderNode* fstBuilderNodeClone(FstBuilderNode* src);
void
fstBuilderNodeCloneFrom
(
FstBuilderNode
*
dst
,
FstBuilderNode
*
src
);
void
fstBuilderNodeCloneFrom
(
FstBuilderNode
*
dst
,
FstBuilderNode
*
src
);
// bool fstBuilderNodeCompileTo(FstBuilderNode *b,
FstCountingWriter
*wrt,
// bool fstBuilderNodeCompileTo(FstBuilderNode *b,
IdxFile'
*wrt,
// CompiledAddr lastAddr, CompiledAddr startAddr);
// CompiledAddr lastAddr, CompiledAddr startAddr);
bool
fstBuilderNodeEqual
(
FstBuilderNode
*
n1
,
FstBuilderNode
*
n2
);
bool
fstBuilderNodeEqual
(
FstBuilderNode
*
n1
,
FstBuilderNode
*
n2
);
...
...
source/libs/index/inc/indexTfile.h
浏览文件 @
3b50fee6
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
#define __INDEX_TFILE_H__
#define __INDEX_TFILE_H__
#include "indexFst.h"
#include "indexFst.h"
#include "indexFst
CountingWriter
.h"
#include "indexFst
File
.h"
#include "indexInt.h"
#include "indexInt.h"
#include "indexTfile.h"
#include "indexTfile.h"
#include "indexUtil.h"
#include "indexUtil.h"
...
@@ -59,7 +59,7 @@ typedef struct TFileCache {
...
@@ -59,7 +59,7 @@ typedef struct TFileCache {
typedef
struct
TFileWriter
{
typedef
struct
TFileWriter
{
FstBuilder
*
fb
;
FstBuilder
*
fb
;
WriterCtx
*
ctx
;
IFileCtx
*
ctx
;
TFileHeader
header
;
TFileHeader
header
;
uint32_t
offset
;
uint32_t
offset
;
}
TFileWriter
;
}
TFileWriter
;
...
@@ -68,7 +68,7 @@ typedef struct TFileWriter {
...
@@ -68,7 +68,7 @@ typedef struct TFileWriter {
typedef
struct
TFileReader
{
typedef
struct
TFileReader
{
T_REF_DECLARE
()
T_REF_DECLARE
()
Fst
*
fst
;
Fst
*
fst
;
WriterCtx
*
ctx
;
IFileCtx
*
ctx
;
TFileHeader
header
;
TFileHeader
header
;
bool
remove
;
bool
remove
;
}
TFileReader
;
}
TFileReader
;
...
@@ -103,7 +103,7 @@ void tfileCachePut(TFileCache* tcache, ICacheKey* key, TFileReader* read
...
@@ -103,7 +103,7 @@ void tfileCachePut(TFileCache* tcache, ICacheKey* key, TFileReader* read
TFileReader
*
tfileGetReaderByCol
(
IndexTFile
*
tf
,
uint64_t
suid
,
char
*
colName
);
TFileReader
*
tfileGetReaderByCol
(
IndexTFile
*
tf
,
uint64_t
suid
,
char
*
colName
);
TFileReader
*
tfileReaderOpen
(
char
*
path
,
uint64_t
suid
,
int64_t
version
,
const
char
*
colName
);
TFileReader
*
tfileReaderOpen
(
char
*
path
,
uint64_t
suid
,
int64_t
version
,
const
char
*
colName
);
TFileReader
*
tfileReaderCreate
(
Writer
Ctx
*
ctx
);
TFileReader
*
tfileReaderCreate
(
IFile
Ctx
*
ctx
);
void
tfileReaderDestroy
(
TFileReader
*
reader
);
void
tfileReaderDestroy
(
TFileReader
*
reader
);
int
tfileReaderSearch
(
TFileReader
*
reader
,
SIndexTermQuery
*
query
,
SIdxTRslt
*
tr
);
int
tfileReaderSearch
(
TFileReader
*
reader
,
SIndexTermQuery
*
query
,
SIdxTRslt
*
tr
);
void
tfileReaderRef
(
TFileReader
*
reader
);
void
tfileReaderRef
(
TFileReader
*
reader
);
...
@@ -111,7 +111,7 @@ void tfileReaderUnRef(TFileReader* reader);
...
@@ -111,7 +111,7 @@ void tfileReaderUnRef(TFileReader* reader);
TFileWriter
*
tfileWriterOpen
(
char
*
path
,
uint64_t
suid
,
int64_t
version
,
const
char
*
colName
,
uint8_t
type
);
TFileWriter
*
tfileWriterOpen
(
char
*
path
,
uint64_t
suid
,
int64_t
version
,
const
char
*
colName
,
uint8_t
type
);
void
tfileWriterClose
(
TFileWriter
*
tw
);
void
tfileWriterClose
(
TFileWriter
*
tw
);
TFileWriter
*
tfileWriterCreate
(
Writer
Ctx
*
ctx
,
TFileHeader
*
header
);
TFileWriter
*
tfileWriterCreate
(
IFile
Ctx
*
ctx
,
TFileHeader
*
header
);
void
tfileWriterDestroy
(
TFileWriter
*
tw
);
void
tfileWriterDestroy
(
TFileWriter
*
tw
);
int
tfileWriterPut
(
TFileWriter
*
tw
,
void
*
data
,
bool
order
);
int
tfileWriterPut
(
TFileWriter
*
tw
,
void
*
data
,
bool
order
);
int
tfileWriterFinish
(
TFileWriter
*
tw
);
int
tfileWriterFinish
(
TFileWriter
*
tw
);
...
...
source/libs/index/src/index.c
浏览文件 @
3b50fee6
...
@@ -39,7 +39,7 @@
...
@@ -39,7 +39,7 @@
#define INDEX_DATA_BIGINT_NULL 0x8000000000000000LL
#define INDEX_DATA_BIGINT_NULL 0x8000000000000000LL
#define INDEX_DATA_TIMESTAMP_NULL TSDB_DATA_BIGINT_NULL
#define INDEX_DATA_TIMESTAMP_NULL TSDB_DATA_BIGINT_NULL
#define INDEX_DATA_FLOAT_NULL 0x7FF00000 // it is an NAN
#define INDEX_DATA_FLOAT_NULL 0x7FF00000
// it is an NAN
#define INDEX_DATA_DOUBLE_NULL 0x7FFFFF0000000000LL // an NAN
#define INDEX_DATA_DOUBLE_NULL 0x7FFFFF0000000000LL // an NAN
#define INDEX_DATA_NCHAR_NULL 0xFFFFFFFF
#define INDEX_DATA_NCHAR_NULL 0xFFFFFFFF
#define INDEX_DATA_BINARY_NULL 0xFF
#define INDEX_DATA_BINARY_NULL 0xFF
...
@@ -614,7 +614,7 @@ static int idxGenTFile(SIndex* sIdx, IndexCache* cache, SArray* batch) {
...
@@ -614,7 +614,7 @@ static int idxGenTFile(SIndex* sIdx, IndexCache* cache, SArray* batch) {
return
ret
;
return
ret
;
END:
END:
if
(
tw
!=
NULL
)
{
if
(
tw
!=
NULL
)
{
writer
CtxDestroy
(
tw
->
ctx
,
true
);
idxFile
CtxDestroy
(
tw
->
ctx
,
true
);
taosMemoryFree
(
tw
);
taosMemoryFree
(
tw
);
}
}
return
-
1
;
return
-
1
;
...
...
source/libs/index/src/indexFst.c
浏览文件 @
3b50fee6
...
@@ -19,11 +19,11 @@
...
@@ -19,11 +19,11 @@
#include "tchecksum.h"
#include "tchecksum.h"
#include "tcoding.h"
#include "tcoding.h"
static
void
fstPackDeltaIn
(
FstCountingWriter
*
wrt
,
CompiledAddr
nodeAddr
,
CompiledAddr
transAddr
,
uint8_t
nBytes
)
{
static
void
fstPackDeltaIn
(
IdxFstFile
*
wrt
,
CompiledAddr
nodeAddr
,
CompiledAddr
transAddr
,
uint8_t
nBytes
)
{
CompiledAddr
deltaAddr
=
(
transAddr
==
EMPTY_ADDRESS
)
?
EMPTY_ADDRESS
:
nodeAddr
-
transAddr
;
CompiledAddr
deltaAddr
=
(
transAddr
==
EMPTY_ADDRESS
)
?
EMPTY_ADDRESS
:
nodeAddr
-
transAddr
;
fstCountingWriter
PackUintIn
(
wrt
,
deltaAddr
,
nBytes
);
idxFile
PackUintIn
(
wrt
,
deltaAddr
,
nBytes
);
}
}
static
uint8_t
fstPackDetla
(
FstCountingWriter
*
wrt
,
CompiledAddr
nodeAddr
,
CompiledAddr
transAddr
)
{
static
uint8_t
fstPackDetla
(
IdxFstFile
*
wrt
,
CompiledAddr
nodeAddr
,
CompiledAddr
transAddr
)
{
uint8_t
nBytes
=
packDeltaSize
(
nodeAddr
,
transAddr
);
uint8_t
nBytes
=
packDeltaSize
(
nodeAddr
,
transAddr
);
fstPackDeltaIn
(
wrt
,
nodeAddr
,
transAddr
,
nBytes
);
fstPackDeltaIn
(
wrt
,
nodeAddr
,
transAddr
,
nBytes
);
return
nBytes
;
return
nBytes
;
...
@@ -208,7 +208,7 @@ FstState fstStateCreate(State state) {
...
@@ -208,7 +208,7 @@ FstState fstStateCreate(State state) {
return
fstStateDict
[
idx
];
return
fstStateDict
[
idx
];
}
}
// compile
// compile
void
fstStateCompileForOneTransNext
(
FstCountingWriter
*
w
,
CompiledAddr
addr
,
uint8_t
inp
)
{
void
fstStateCompileForOneTransNext
(
IdxFstFile
*
w
,
CompiledAddr
addr
,
uint8_t
inp
)
{
FstState
s
=
fstStateCreate
(
OneTransNext
);
FstState
s
=
fstStateCreate
(
OneTransNext
);
fstStateSetCommInput
(
&
s
,
inp
);
fstStateSetCommInput
(
&
s
,
inp
);
...
@@ -216,21 +216,21 @@ void fstStateCompileForOneTransNext(FstCountingWriter* w, CompiledAddr addr, uin
...
@@ -216,21 +216,21 @@ void fstStateCompileForOneTransNext(FstCountingWriter* w, CompiledAddr addr, uin
uint8_t
v
=
fstStateCommInput
(
&
s
,
&
null
);
uint8_t
v
=
fstStateCommInput
(
&
s
,
&
null
);
if
(
null
)
{
if
(
null
)
{
// w->write_all(&[inp])
// w->write_all(&[inp])
fstCountingWriter
Write
(
w
,
&
inp
,
1
);
idxFile
Write
(
w
,
&
inp
,
1
);
}
}
fstCountingWriter
Write
(
w
,
&
(
s
.
val
),
1
);
idxFile
Write
(
w
,
&
(
s
.
val
),
1
);
// w->write_all(&[s.val])
// w->write_all(&[s.val])
return
;
return
;
}
}
void
fstStateCompileForOneTrans
(
FstCountingWriter
*
w
,
CompiledAddr
addr
,
FstTransition
*
trn
)
{
void
fstStateCompileForOneTrans
(
IdxFstFile
*
w
,
CompiledAddr
addr
,
FstTransition
*
trn
)
{
Output
out
=
trn
->
out
;
Output
out
=
trn
->
out
;
uint8_t
outPackSize
=
(
out
==
0
?
0
:
fstCountingWriter
PackUint
(
w
,
out
));
uint8_t
outPackSize
=
(
out
==
0
?
0
:
idxFile
PackUint
(
w
,
out
));
uint8_t
transPackSize
=
fstPackDetla
(
w
,
addr
,
trn
->
addr
);
uint8_t
transPackSize
=
fstPackDetla
(
w
,
addr
,
trn
->
addr
);
PackSizes
packSizes
=
0
;
PackSizes
packSizes
=
0
;
FST_SET_OUTPUT_PACK_SIZE
(
packSizes
,
outPackSize
);
FST_SET_OUTPUT_PACK_SIZE
(
packSizes
,
outPackSize
);
FST_SET_TRANSITION_PACK_SIZE
(
packSizes
,
transPackSize
);
FST_SET_TRANSITION_PACK_SIZE
(
packSizes
,
transPackSize
);
fstCountingWriter
Write
(
w
,
(
char
*
)
&
packSizes
,
sizeof
(
packSizes
));
idxFile
Write
(
w
,
(
char
*
)
&
packSizes
,
sizeof
(
packSizes
));
FstState
st
=
fstStateCreate
(
OneTrans
);
FstState
st
=
fstStateCreate
(
OneTrans
);
...
@@ -239,12 +239,12 @@ void fstStateCompileForOneTrans(FstCountingWriter* w, CompiledAddr addr, FstTran
...
@@ -239,12 +239,12 @@ void fstStateCompileForOneTrans(FstCountingWriter* w, CompiledAddr addr, FstTran
bool
null
=
false
;
bool
null
=
false
;
uint8_t
inp
=
fstStateCommInput
(
&
st
,
&
null
);
uint8_t
inp
=
fstStateCommInput
(
&
st
,
&
null
);
if
(
null
==
true
)
{
if
(
null
==
true
)
{
fstCountingWriter
Write
(
w
,
(
char
*
)
&
trn
->
inp
,
sizeof
(
trn
->
inp
));
idxFile
Write
(
w
,
(
char
*
)
&
trn
->
inp
,
sizeof
(
trn
->
inp
));
}
}
fstCountingWriter
Write
(
w
,
(
char
*
)(
&
(
st
.
val
)),
sizeof
(
st
.
val
));
idxFile
Write
(
w
,
(
char
*
)(
&
(
st
.
val
)),
sizeof
(
st
.
val
));
return
;
return
;
}
}
void
fstStateCompileForAnyTrans
(
FstCountingWriter
*
w
,
CompiledAddr
addr
,
FstBuilderNode
*
node
)
{
void
fstStateCompileForAnyTrans
(
IdxFstFile
*
w
,
CompiledAddr
addr
,
FstBuilderNode
*
node
)
{
int32_t
sz
=
taosArrayGetSize
(
node
->
trans
);
int32_t
sz
=
taosArrayGetSize
(
node
->
trans
);
assert
(
sz
<=
256
);
assert
(
sz
<=
256
);
...
@@ -275,11 +275,11 @@ void fstStateCompileForAnyTrans(FstCountingWriter* w, CompiledAddr addr, FstBuil
...
@@ -275,11 +275,11 @@ void fstStateCompileForAnyTrans(FstCountingWriter* w, CompiledAddr addr, FstBuil
if
(
anyOuts
)
{
if
(
anyOuts
)
{
if
(
FST_BUILDER_NODE_IS_FINAL
(
node
))
{
if
(
FST_BUILDER_NODE_IS_FINAL
(
node
))
{
fstCountingWriter
PackUintIn
(
w
,
node
->
finalOutput
,
oSize
);
idxFile
PackUintIn
(
w
,
node
->
finalOutput
,
oSize
);
}
}
for
(
int32_t
i
=
sz
-
1
;
i
>=
0
;
i
--
)
{
for
(
int32_t
i
=
sz
-
1
;
i
>=
0
;
i
--
)
{
FstTransition
*
t
=
taosArrayGet
(
node
->
trans
,
i
);
FstTransition
*
t
=
taosArrayGet
(
node
->
trans
,
i
);
fstCountingWriter
PackUintIn
(
w
,
t
->
out
,
oSize
);
idxFile
PackUintIn
(
w
,
t
->
out
,
oSize
);
}
}
}
}
for
(
int32_t
i
=
sz
-
1
;
i
>=
0
;
i
--
)
{
for
(
int32_t
i
=
sz
-
1
;
i
>=
0
;
i
--
)
{
...
@@ -288,7 +288,7 @@ void fstStateCompileForAnyTrans(FstCountingWriter* w, CompiledAddr addr, FstBuil
...
@@ -288,7 +288,7 @@ void fstStateCompileForAnyTrans(FstCountingWriter* w, CompiledAddr addr, FstBuil
}
}
for
(
int32_t
i
=
sz
-
1
;
i
>=
0
;
i
--
)
{
for
(
int32_t
i
=
sz
-
1
;
i
>=
0
;
i
--
)
{
FstTransition
*
t
=
taosArrayGet
(
node
->
trans
,
i
);
FstTransition
*
t
=
taosArrayGet
(
node
->
trans
,
i
);
fstCountingWriter
Write
(
w
,
(
char
*
)
&
t
->
inp
,
1
);
idxFile
Write
(
w
,
(
char
*
)
&
t
->
inp
,
1
);
// fstPackDeltaIn(w, addr, t->addr, tSize);
// fstPackDeltaIn(w, addr, t->addr, tSize);
}
}
if
(
sz
>
TRANS_INDEX_THRESHOLD
)
{
if
(
sz
>
TRANS_INDEX_THRESHOLD
)
{
...
@@ -306,10 +306,10 @@ void fstStateCompileForAnyTrans(FstCountingWriter* w, CompiledAddr addr, FstBuil
...
@@ -306,10 +306,10 @@ void fstStateCompileForAnyTrans(FstCountingWriter* w, CompiledAddr addr, FstBuil
index
[
t
->
inp
]
=
i
;
index
[
t
->
inp
]
=
i
;
// fstPackDeltaIn(w, addr, t->addr, tSize);
// fstPackDeltaIn(w, addr, t->addr, tSize);
}
}
fstCountingWriter
Write
(
w
,
(
char
*
)
index
,
256
);
idxFile
Write
(
w
,
(
char
*
)
index
,
256
);
taosMemoryFree
(
index
);
taosMemoryFree
(
index
);
}
}
fstCountingWriter
Write
(
w
,
(
char
*
)
&
packSizes
,
1
);
idxFile
Write
(
w
,
(
char
*
)
&
packSizes
,
1
);
bool
null
=
false
;
bool
null
=
false
;
fstStateStateNtrans
(
&
st
,
&
null
);
fstStateStateNtrans
(
&
st
,
&
null
);
if
(
null
==
true
)
{
if
(
null
==
true
)
{
...
@@ -318,12 +318,12 @@ void fstStateCompileForAnyTrans(FstCountingWriter* w, CompiledAddr addr, FstBuil
...
@@ -318,12 +318,12 @@ void fstStateCompileForAnyTrans(FstCountingWriter* w, CompiledAddr addr, FstBuil
// encoded in the state byte.
// encoded in the state byte.
uint8_t
v
=
1
;
uint8_t
v
=
1
;
if
(
sz
==
256
)
{
if
(
sz
==
256
)
{
fstCountingWriter
Write
(
w
,
(
char
*
)
&
v
,
1
);
idxFile
Write
(
w
,
(
char
*
)
&
v
,
1
);
}
else
{
}
else
{
fstCountingWriter
Write
(
w
,
(
char
*
)
&
sz
,
1
);
idxFile
Write
(
w
,
(
char
*
)
&
sz
,
1
);
}
}
}
}
fstCountingWriter
Write
(
w
,
(
char
*
)(
&
(
st
.
val
)),
1
);
idxFile
Write
(
w
,
(
char
*
)(
&
(
st
.
val
)),
1
);
return
;
return
;
}
}
...
@@ -753,7 +753,7 @@ bool fstNodeCompile(FstNode* node, void* w, CompiledAddr lastAddr, CompiledAddr
...
@@ -753,7 +753,7 @@ bool fstNodeCompile(FstNode* node, void* w, CompiledAddr lastAddr, CompiledAddr
return
true
;
return
true
;
}
}
bool
fstBuilderNodeCompileTo
(
FstBuilderNode
*
b
,
FstCountingWriter
*
wrt
,
CompiledAddr
lastAddr
,
CompiledAddr
startAddr
)
{
bool
fstBuilderNodeCompileTo
(
FstBuilderNode
*
b
,
IdxFstFile
*
wrt
,
CompiledAddr
lastAddr
,
CompiledAddr
startAddr
)
{
return
fstNodeCompile
(
NULL
,
wrt
,
lastAddr
,
startAddr
,
b
);
return
fstNodeCompile
(
NULL
,
wrt
,
lastAddr
,
startAddr
,
b
);
}
}
...
@@ -763,7 +763,7 @@ FstBuilder* fstBuilderCreate(void* w, FstType ty) {
...
@@ -763,7 +763,7 @@ FstBuilder* fstBuilderCreate(void* w, FstType ty) {
return
b
;
return
b
;
}
}
b
->
wrt
=
fstCountingWriter
Create
(
w
);
b
->
wrt
=
idxFile
Create
(
w
);
b
->
unfinished
=
fstUnFinishedNodesCreate
();
b
->
unfinished
=
fstUnFinishedNodesCreate
();
b
->
registry
=
fstRegistryCreate
(
10000
,
2
);
b
->
registry
=
fstRegistryCreate
(
10000
,
2
);
b
->
last
=
fstSliceCreate
(
NULL
,
0
);
b
->
last
=
fstSliceCreate
(
NULL
,
0
);
...
@@ -773,12 +773,12 @@ FstBuilder* fstBuilderCreate(void* w, FstType ty) {
...
@@ -773,12 +773,12 @@ FstBuilder* fstBuilderCreate(void* w, FstType ty) {
char
buf64
[
8
]
=
{
0
};
char
buf64
[
8
]
=
{
0
};
void
*
pBuf64
=
buf64
;
void
*
pBuf64
=
buf64
;
taosEncodeFixedU64
(
&
pBuf64
,
VERSION
);
taosEncodeFixedU64
(
&
pBuf64
,
VERSION
);
fstCountingWriter
Write
(
b
->
wrt
,
buf64
,
sizeof
(
buf64
));
idxFile
Write
(
b
->
wrt
,
buf64
,
sizeof
(
buf64
));
pBuf64
=
buf64
;
pBuf64
=
buf64
;
memset
(
buf64
,
0
,
sizeof
(
buf64
));
memset
(
buf64
,
0
,
sizeof
(
buf64
));
taosEncodeFixedU64
(
&
pBuf64
,
ty
);
taosEncodeFixedU64
(
&
pBuf64
,
ty
);
fstCountingWriter
Write
(
b
->
wrt
,
buf64
,
sizeof
(
buf64
));
idxFile
Write
(
b
->
wrt
,
buf64
,
sizeof
(
buf64
));
return
b
;
return
b
;
}
}
...
@@ -787,7 +787,7 @@ void fstBuilderDestroy(FstBuilder* b) {
...
@@ -787,7 +787,7 @@ void fstBuilderDestroy(FstBuilder* b) {
return
;
return
;
}
}
fstCountingWriter
Destroy
(
b
->
wrt
);
idxFile
Destroy
(
b
->
wrt
);
fstUnFinishedNodesDestroy
(
b
->
unfinished
);
fstUnFinishedNodesDestroy
(
b
->
unfinished
);
fstRegistryDestroy
(
b
->
registry
);
fstRegistryDestroy
(
b
->
registry
);
fstSliceDestroy
(
&
b
->
last
);
fstSliceDestroy
(
&
b
->
last
);
...
@@ -905,21 +905,19 @@ void* fstBuilderInsertInner(FstBuilder* b) {
...
@@ -905,21 +905,19 @@ void* fstBuilderInsertInner(FstBuilder* b) {
void
*
pBuf64
=
buf64
;
void
*
pBuf64
=
buf64
;
taosEncodeFixedU64
(
&
pBuf64
,
b
->
len
);
taosEncodeFixedU64
(
&
pBuf64
,
b
->
len
);
fstCountingWriter
Write
(
b
->
wrt
,
buf64
,
sizeof
(
buf64
));
idxFile
Write
(
b
->
wrt
,
buf64
,
sizeof
(
buf64
));
pBuf64
=
buf64
;
pBuf64
=
buf64
;
taosEncodeFixedU64
(
&
pBuf64
,
rootAddr
);
taosEncodeFixedU64
(
&
pBuf64
,
rootAddr
);
fstCountingWriter
Write
(
b
->
wrt
,
buf64
,
sizeof
(
buf64
));
idxFile
Write
(
b
->
wrt
,
buf64
,
sizeof
(
buf64
));
char
buf32
[
4
]
=
{
0
};
char
buf32
[
4
]
=
{
0
};
void
*
pBuf32
=
buf32
;
void
*
pBuf32
=
buf32
;
uint32_t
sum
=
fstCountingWriter
MaskedCheckSum
(
b
->
wrt
);
uint32_t
sum
=
idxFile
MaskedCheckSum
(
b
->
wrt
);
taosEncodeFixedU32
(
&
pBuf32
,
sum
);
taosEncodeFixedU32
(
&
pBuf32
,
sum
);
fstCountingWriter
Write
(
b
->
wrt
,
buf32
,
sizeof
(
buf32
));
idxFile
Write
(
b
->
wrt
,
buf32
,
sizeof
(
buf32
));
fstCountingWriterFlush
(
b
->
wrt
);
idxFileFlush
(
b
->
wrt
);
// fstCountingWriterDestroy(b->wrt);
// b->wrt = NULL;
return
b
->
wrt
;
return
b
->
wrt
;
}
}
void
fstBuilderFinish
(
FstBuilder
*
b
)
{
fstBuilderInsertInner
(
b
);
}
void
fstBuilderFinish
(
FstBuilder
*
b
)
{
fstBuilderInsertInner
(
b
);
}
...
...
source/libs/index/src/indexFstDfa.c
浏览文件 @
3b50fee6
...
@@ -61,9 +61,10 @@ void dfaBuilderDestroy(FstDfaBuilder *builder) {
...
@@ -61,9 +61,10 @@ void dfaBuilderDestroy(FstDfaBuilder *builder) {
pIter
=
taosHashIterate
(
builder
->
cache
,
pIter
);
pIter
=
taosHashIterate
(
builder
->
cache
,
pIter
);
}
}
taosHashCleanup
(
builder
->
cache
);
taosHashCleanup
(
builder
->
cache
);
taosMemoryFree
(
builder
);
}
}
FstDfa
*
dfaBuilder
Build
(
FstDfaBuilder
*
builder
)
{
FstDfa
*
dfaBuilder
(
FstDfaBuilder
*
builder
)
{
uint32_t
sz
=
taosArrayGetSize
(
builder
->
dfa
->
insts
);
uint32_t
sz
=
taosArrayGetSize
(
builder
->
dfa
->
insts
);
FstSparseSet
*
cur
=
sparSetCreate
(
sz
);
FstSparseSet
*
cur
=
sparSetCreate
(
sz
);
FstSparseSet
*
nxt
=
sparSetCreate
(
sz
);
FstSparseSet
*
nxt
=
sparSetCreate
(
sz
);
...
...
source/libs/index/src/indexFst
CountingWriter
.c
→
source/libs/index/src/indexFst
File
.c
浏览文件 @
3b50fee6
...
@@ -13,13 +13,13 @@
...
@@ -13,13 +13,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "indexFst
CountingWriter
.h"
#include "indexFst
File
.h"
#include "indexFstUtil.h"
#include "indexFstUtil.h"
#include "indexInt.h"
#include "indexInt.h"
#include "os.h"
#include "os.h"
#include "tutil.h"
#include "tutil.h"
static
int
writeCtxDoWrite
(
Writer
Ctx
*
ctx
,
uint8_t
*
buf
,
int
len
)
{
static
int
idxFileCtxDoWrite
(
IFile
Ctx
*
ctx
,
uint8_t
*
buf
,
int
len
)
{
if
(
ctx
->
type
==
TFile
)
{
if
(
ctx
->
type
==
TFile
)
{
assert
(
len
==
taosWriteFile
(
ctx
->
file
.
pFile
,
buf
,
len
));
assert
(
len
==
taosWriteFile
(
ctx
->
file
.
pFile
,
buf
,
len
));
}
else
{
}
else
{
...
@@ -28,7 +28,7 @@ static int writeCtxDoWrite(WriterCtx* ctx, uint8_t* buf, int len) {
...
@@ -28,7 +28,7 @@ static int writeCtxDoWrite(WriterCtx* ctx, uint8_t* buf, int len) {
ctx
->
offset
+=
len
;
ctx
->
offset
+=
len
;
return
len
;
return
len
;
}
}
static
int
writeCtxDoRead
(
Writer
Ctx
*
ctx
,
uint8_t
*
buf
,
int
len
)
{
static
int
idxFileCtxDoRead
(
IFile
Ctx
*
ctx
,
uint8_t
*
buf
,
int
len
)
{
int
nRead
=
0
;
int
nRead
=
0
;
if
(
ctx
->
type
==
TFile
)
{
if
(
ctx
->
type
==
TFile
)
{
#ifdef USE_MMAP
#ifdef USE_MMAP
...
@@ -44,7 +44,7 @@ static int writeCtxDoRead(WriterCtx* ctx, uint8_t* buf, int len) {
...
@@ -44,7 +44,7 @@ static int writeCtxDoRead(WriterCtx* ctx, uint8_t* buf, int len) {
return
nRead
;
return
nRead
;
}
}
static
int
writeCtxDoReadFrom
(
Writer
Ctx
*
ctx
,
uint8_t
*
buf
,
int
len
,
int32_t
offset
)
{
static
int
idxFileCtxDoReadFrom
(
IFile
Ctx
*
ctx
,
uint8_t
*
buf
,
int
len
,
int32_t
offset
)
{
int
nRead
=
0
;
int
nRead
=
0
;
if
(
ctx
->
type
==
TFile
)
{
if
(
ctx
->
type
==
TFile
)
{
// tfLseek(ctx->file.pFile, offset, 0);
// tfLseek(ctx->file.pFile, offset, 0);
...
@@ -61,7 +61,7 @@ static int writeCtxDoReadFrom(WriterCtx* ctx, uint8_t* buf, int len, int32_t off
...
@@ -61,7 +61,7 @@ static int writeCtxDoReadFrom(WriterCtx* ctx, uint8_t* buf, int len, int32_t off
}
}
return
nRead
;
return
nRead
;
}
}
static
int
writeCtxGetSize
(
Writer
Ctx
*
ctx
)
{
static
int
idxFileCtxGetSize
(
IFile
Ctx
*
ctx
)
{
if
(
ctx
->
type
==
TFile
)
{
if
(
ctx
->
type
==
TFile
)
{
int64_t
file_size
=
0
;
int64_t
file_size
=
0
;
taosStatFile
(
ctx
->
file
.
buf
,
&
file_size
,
NULL
);
taosStatFile
(
ctx
->
file
.
buf
,
&
file_size
,
NULL
);
...
@@ -69,7 +69,7 @@ static int writeCtxGetSize(WriterCtx* ctx) {
...
@@ -69,7 +69,7 @@ static int writeCtxGetSize(WriterCtx* ctx) {
}
}
return
0
;
return
0
;
}
}
static
int
writeCtxDoFlush
(
Writer
Ctx
*
ctx
)
{
static
int
idxFileCtxDoFlush
(
IFile
Ctx
*
ctx
)
{
if
(
ctx
->
type
==
TFile
)
{
if
(
ctx
->
type
==
TFile
)
{
// taosFsyncFile(ctx->file.pFile);
// taosFsyncFile(ctx->file.pFile);
taosFsyncFile
(
ctx
->
file
.
pFile
);
taosFsyncFile
(
ctx
->
file
.
pFile
);
...
@@ -80,8 +80,8 @@ static int writeCtxDoFlush(WriterCtx* ctx) {
...
@@ -80,8 +80,8 @@ static int writeCtxDoFlush(WriterCtx* ctx) {
return
1
;
return
1
;
}
}
WriterCtx
*
writer
CtxCreate
(
WriterType
type
,
const
char
*
path
,
bool
readOnly
,
int32_t
capacity
)
{
IFileCtx
*
idxFile
CtxCreate
(
WriterType
type
,
const
char
*
path
,
bool
readOnly
,
int32_t
capacity
)
{
WriterCtx
*
ctx
=
taosMemoryCalloc
(
1
,
sizeof
(
Writer
Ctx
));
IFileCtx
*
ctx
=
taosMemoryCalloc
(
1
,
sizeof
(
IFile
Ctx
));
if
(
ctx
==
NULL
)
{
if
(
ctx
==
NULL
)
{
return
NULL
;
return
NULL
;
}
}
...
@@ -90,39 +90,36 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int
...
@@ -90,39 +90,36 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int
if
(
ctx
->
type
==
TFile
)
{
if
(
ctx
->
type
==
TFile
)
{
// ugly code, refactor later
// ugly code, refactor later
ctx
->
file
.
readOnly
=
readOnly
;
ctx
->
file
.
readOnly
=
readOnly
;
memcpy
(
ctx
->
file
.
buf
,
path
,
strlen
(
path
));
if
(
readOnly
==
false
)
{
if
(
readOnly
==
false
)
{
// ctx->file.pFile = open(path, O_WRONLY | O_CREAT | O_APPEND, S_IRWXU | S_IRWXG | S_IRWXO);
ctx
->
file
.
pFile
=
taosOpenFile
(
path
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_APPEND
);
ctx
->
file
.
pFile
=
taosOpenFile
(
path
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_APPEND
);
taosFtruncateFile
(
ctx
->
file
.
pFile
,
0
);
taosFtruncateFile
(
ctx
->
file
.
pFile
,
0
);
int64_t
file_size
;
taosStatFile
(
path
,
&
ctx
->
file
.
size
,
NULL
);
taosStatFile
(
path
,
&
file_size
,
NULL
);
// ctx->file.size = (int)size;
ctx
->
file
.
size
=
(
int
)
file_size
;
}
else
{
}
else
{
// ctx->file.pFile = open(path, O_RDONLY, S_IRWXU | S_IRWXG | S_IRWXO);
ctx
->
file
.
pFile
=
taosOpenFile
(
path
,
TD_FILE_READ
);
ctx
->
file
.
pFile
=
taosOpenFile
(
path
,
TD_FILE_READ
);
int64_t
file_
size
=
0
;
int64_t
size
=
0
;
taosFStatFile
(
ctx
->
file
.
pFile
,
&
file_
size
,
NULL
);
taosFStatFile
(
ctx
->
file
.
pFile
,
&
ctx
->
file
.
size
,
NULL
);
ctx
->
file
.
size
=
(
int
)
file_
size
;
ctx
->
file
.
size
=
(
int
)
size
;
#ifdef USE_MMAP
#ifdef USE_MMAP
ctx
->
file
.
ptr
=
(
char
*
)
tfMmapReadOnly
(
ctx
->
file
.
pFile
,
ctx
->
file
.
size
);
ctx
->
file
.
ptr
=
(
char
*
)
tfMmapReadOnly
(
ctx
->
file
.
pFile
,
ctx
->
file
.
size
);
#endif
#endif
}
}
memcpy
(
ctx
->
file
.
buf
,
path
,
strlen
(
path
));
if
(
ctx
->
file
.
pFile
==
NULL
)
{
if
(
ctx
->
file
.
pFile
==
NULL
)
{
indexError
(
"failed to open file, error %d"
,
errno
);
indexError
(
"failed to open file, error %d"
,
errno
);
goto
END
;
goto
END
;
}
}
}
else
if
(
ctx
->
type
==
TMemory
)
{
}
else
if
(
ctx
->
type
==
TMemory
)
{
ctx
->
mem
.
buf
=
taosMemoryCalloc
(
1
,
sizeof
(
char
)
*
capacity
);
ctx
->
mem
.
buf
=
taosMemoryCalloc
(
1
,
sizeof
(
char
)
*
capacity
);
ctx
->
mem
.
cap
a
=
capacity
;
ctx
->
mem
.
cap
=
capacity
;
}
}
ctx
->
write
=
writ
eCtxDoWrite
;
ctx
->
write
=
idxFil
eCtxDoWrite
;
ctx
->
read
=
writ
eCtxDoRead
;
ctx
->
read
=
idxFil
eCtxDoRead
;
ctx
->
flush
=
writ
eCtxDoFlush
;
ctx
->
flush
=
idxFil
eCtxDoFlush
;
ctx
->
readFrom
=
writ
eCtxDoReadFrom
;
ctx
->
readFrom
=
idxFil
eCtxDoReadFrom
;
ctx
->
size
=
writ
eCtxGetSize
;
ctx
->
size
=
idxFil
eCtxGetSize
;
ctx
->
offset
=
0
;
ctx
->
offset
=
0
;
ctx
->
limit
=
capacity
;
ctx
->
limit
=
capacity
;
...
@@ -135,7 +132,7 @@ END:
...
@@ -135,7 +132,7 @@ END:
taosMemoryFree
(
ctx
);
taosMemoryFree
(
ctx
);
return
NULL
;
return
NULL
;
}
}
void
writerCtxDestroy
(
Writer
Ctx
*
ctx
,
bool
remove
)
{
void
idxFileCtxDestroy
(
IFile
Ctx
*
ctx
,
bool
remove
)
{
if
(
ctx
->
type
==
TMemory
)
{
if
(
ctx
->
type
==
TMemory
)
{
taosMemoryFree
(
ctx
->
mem
.
buf
);
taosMemoryFree
(
ctx
->
mem
.
buf
);
}
else
{
}
else
{
...
@@ -149,9 +146,6 @@ void writerCtxDestroy(WriterCtx* ctx, bool remove) {
...
@@ -149,9 +146,6 @@ void writerCtxDestroy(WriterCtx* ctx, bool remove) {
if
(
ctx
->
file
.
readOnly
==
false
)
{
if
(
ctx
->
file
.
readOnly
==
false
)
{
int64_t
file_size
=
0
;
int64_t
file_size
=
0
;
taosStatFile
(
ctx
->
file
.
buf
,
&
file_size
,
NULL
);
taosStatFile
(
ctx
->
file
.
buf
,
&
file_size
,
NULL
);
// struct stat fstat;
// stat(ctx->file.buf, &fstat);
// indexError("write file size: %d", (int)(fstat.st_size));
}
}
if
(
remove
)
{
if
(
remove
)
{
unlink
(
ctx
->
file
.
buf
);
unlink
(
ctx
->
file
.
buf
);
...
@@ -160,30 +154,29 @@ void writerCtxDestroy(WriterCtx* ctx, bool remove) {
...
@@ -160,30 +154,29 @@ void writerCtxDestroy(WriterCtx* ctx, bool remove) {
taosMemoryFree
(
ctx
);
taosMemoryFree
(
ctx
);
}
}
FstCountingWriter
*
fstCountingWriter
Create
(
void
*
wrt
)
{
IdxFstFile
*
idxFile
Create
(
void
*
wrt
)
{
FstCountingWriter
*
cw
=
taosMemoryCalloc
(
1
,
sizeof
(
FstCountingWriter
));
IdxFstFile
*
cw
=
taosMemoryCalloc
(
1
,
sizeof
(
IdxFstFile
));
if
(
cw
==
NULL
)
{
if
(
cw
==
NULL
)
{
return
NULL
;
return
NULL
;
}
}
cw
->
wrt
=
wrt
;
cw
->
wrt
=
wrt
;
//(void *)(writerCtxCreate(TFile, readOnly));
return
cw
;
return
cw
;
}
}
void
fstCountingWriterDestroy
(
FstCountingWriter
*
cw
)
{
void
idxFileDestroy
(
IdxFstFile
*
cw
)
{
// free wrt object: close fd or free mem
// free wrt object: close fd or free mem
fstCountingWriter
Flush
(
cw
);
idxFile
Flush
(
cw
);
//
writerCtxDestroy((Writer
Ctx *)(cw->wrt));
//
idxFileCtxDestroy((IFile
Ctx *)(cw->wrt));
taosMemoryFree
(
cw
);
taosMemoryFree
(
cw
);
}
}
int
fstCountingWriterWrite
(
FstCountingWriter
*
write
,
uint8_t
*
buf
,
uint32_t
len
)
{
int
idxFileWrite
(
IdxFstFile
*
write
,
uint8_t
*
buf
,
uint32_t
len
)
{
if
(
write
==
NULL
)
{
if
(
write
==
NULL
)
{
return
0
;
return
0
;
}
}
// update checksum
// update checksum
// write data to file/socket or mem
// write data to file/socket or mem
Writer
Ctx
*
ctx
=
write
->
wrt
;
IFile
Ctx
*
ctx
=
write
->
wrt
;
int
nWrite
=
ctx
->
write
(
ctx
,
buf
,
len
);
int
nWrite
=
ctx
->
write
(
ctx
,
buf
,
len
);
assert
(
nWrite
==
len
);
assert
(
nWrite
==
len
);
...
@@ -192,42 +185,41 @@ int fstCountingWriterWrite(FstCountingWriter* write, uint8_t* buf, uint32_t len)
...
@@ -192,42 +185,41 @@ int fstCountingWriterWrite(FstCountingWriter* write, uint8_t* buf, uint32_t len)
write
->
summer
=
taosCalcChecksum
(
write
->
summer
,
buf
,
len
);
write
->
summer
=
taosCalcChecksum
(
write
->
summer
,
buf
,
len
);
return
len
;
return
len
;
}
}
int
fstCountingWriterRead
(
FstCountingWriter
*
write
,
uint8_t
*
buf
,
uint32_t
len
)
{
int
idxFileRead
(
IdxFstFile
*
write
,
uint8_t
*
buf
,
uint32_t
len
)
{
if
(
write
==
NULL
)
{
if
(
write
==
NULL
)
{
return
0
;
return
0
;
}
}
Writer
Ctx
*
ctx
=
write
->
wrt
;
IFile
Ctx
*
ctx
=
write
->
wrt
;
int
nRead
=
ctx
->
read
(
ctx
,
buf
,
len
);
int
nRead
=
ctx
->
read
(
ctx
,
buf
,
len
);
// assert(nRead == len);
// assert(nRead == len);
return
nRead
;
return
nRead
;
}
}
uint32_t
fstCountingWriterMaskedCheckSum
(
FstCountingWriter
*
write
)
{
uint32_t
idxFileMaskedCheckSum
(
IdxFstFile
*
write
)
{
// opt
// opt
return
write
->
summer
;
return
write
->
summer
;
}
}
int
fstCountingWriterFlush
(
FstCountingWriter
*
write
)
{
int
idxFileFlush
(
IdxFstFile
*
write
)
{
Writer
Ctx
*
ctx
=
write
->
wrt
;
IFile
Ctx
*
ctx
=
write
->
wrt
;
ctx
->
flush
(
ctx
);
ctx
->
flush
(
ctx
);
// write->wtr->flush
return
1
;
return
1
;
}
}
void
fstCountingWriterPackUintIn
(
FstCountingWriter
*
writer
,
uint64_t
n
,
uint8_t
nBytes
)
{
void
idxFilePackUintIn
(
IdxFstFile
*
writer
,
uint64_t
n
,
uint8_t
nBytes
)
{
assert
(
1
<=
nBytes
&&
nBytes
<=
8
);
assert
(
1
<=
nBytes
&&
nBytes
<=
8
);
uint8_t
*
buf
=
taosMemoryCalloc
(
8
,
sizeof
(
uint8_t
));
uint8_t
*
buf
=
taosMemoryCalloc
(
8
,
sizeof
(
uint8_t
));
for
(
uint8_t
i
=
0
;
i
<
nBytes
;
i
++
)
{
for
(
uint8_t
i
=
0
;
i
<
nBytes
;
i
++
)
{
buf
[
i
]
=
(
uint8_t
)
n
;
buf
[
i
]
=
(
uint8_t
)
n
;
n
=
n
>>
8
;
n
=
n
>>
8
;
}
}
fstCountingWriter
Write
(
writer
,
buf
,
nBytes
);
idxFile
Write
(
writer
,
buf
,
nBytes
);
taosMemoryFree
(
buf
);
taosMemoryFree
(
buf
);
return
;
return
;
}
}
uint8_t
fstCountingWriterPackUint
(
FstCountingWriter
*
writer
,
uint64_t
n
)
{
uint8_t
idxFilePackUint
(
IdxFstFile
*
writer
,
uint64_t
n
)
{
uint8_t
nBytes
=
packSize
(
n
);
uint8_t
nBytes
=
packSize
(
n
);
fstCountingWriter
PackUintIn
(
writer
,
n
,
nBytes
);
idxFile
PackUintIn
(
writer
,
n
,
nBytes
);
return
nBytes
;
return
nBytes
;
}
}
source/libs/index/src/indexFstNode.c
浏览文件 @
3b50fee6
...
@@ -95,7 +95,7 @@ void fstBuilderNodeCloneFrom(FstBuilderNode* dst, FstBuilderNode* src) {
...
@@ -95,7 +95,7 @@ void fstBuilderNodeCloneFrom(FstBuilderNode* dst, FstBuilderNode* src) {
}
}
}
}
// bool fstBuilderNodeCompileTo(FstBuilderNode *b,
FstCountingWriter
*wrt, CompiledAddr lastAddr, CompiledAddr
// bool fstBuilderNodeCompileTo(FstBuilderNode *b,
IdxFile
*wrt, CompiledAddr lastAddr, CompiledAddr
// startAddr) {
// startAddr) {
// size_t sz = taosArrayGetSize(b->trans);
// size_t sz = taosArrayGetSize(b->trans);
...
...
source/libs/index/src/indexFstUtil.c
浏览文件 @
3b50fee6
...
@@ -75,7 +75,6 @@ CompiledAddr unpackDelta(char* data, uint64_t len, uint64_t nodeAddr) {
...
@@ -75,7 +75,6 @@ CompiledAddr unpackDelta(char* data, uint64_t len, uint64_t nodeAddr) {
}
}
// fst slice func
// fst slice func
//
FstSlice
fstSliceCreate
(
uint8_t
*
data
,
uint64_t
len
)
{
FstSlice
fstSliceCreate
(
uint8_t
*
data
,
uint64_t
len
)
{
FstString
*
str
=
(
FstString
*
)
taosMemoryMalloc
(
sizeof
(
FstString
));
FstString
*
str
=
(
FstString
*
)
taosMemoryMalloc
(
sizeof
(
FstString
));
...
@@ -164,16 +163,3 @@ int fstSliceCompare(FstSlice* a, FstSlice* b) {
...
@@ -164,16 +163,3 @@ int fstSliceCompare(FstSlice* a, FstSlice* b) {
return
0
;
return
0
;
}
}
}
}
// FstStack* fstStackCreate(size_t elemSize, StackFreeElem freeFn) {
// FstStack *s = taosMemoryCalloc(1, sizeof(FstStack));
// if (s == NULL) { return NULL; }
// s->
// s->freeFn
//
//}
// void *fstStackPush(FstStack *s, void *elem);
// void *fstStackTop(FstStack *s);
// size_t fstStackLen(FstStack *s);
// void *fstStackGetAt(FstStack *s, size_t i);
// void fstStackDestory(FstStack *);
source/libs/index/src/indexTfile.c
浏览文件 @
3b50fee6
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
#include "index.h"
#include "index.h"
#include "indexComm.h"
#include "indexComm.h"
#include "indexFst.h"
#include "indexFst.h"
#include "indexFst
CountingWriter
.h"
#include "indexFst
File
.h"
#include "indexUtil.h"
#include "indexUtil.h"
#include "taosdef.h"
#include "taosdef.h"
#include "taoserror.h"
#include "taoserror.h"
...
@@ -103,7 +103,7 @@ TFileCache* tfileCacheCreate(const char* path) {
...
@@ -103,7 +103,7 @@ TFileCache* tfileCacheCreate(const char* path) {
for
(
size_t
i
=
0
;
i
<
taosArrayGetSize
(
files
);
i
++
)
{
for
(
size_t
i
=
0
;
i
<
taosArrayGetSize
(
files
);
i
++
)
{
char
*
file
=
taosArrayGetP
(
files
,
i
);
char
*
file
=
taosArrayGetP
(
files
,
i
);
WriterCtx
*
wc
=
writer
CtxCreate
(
TFile
,
file
,
true
,
1024
*
1024
*
64
);
IFileCtx
*
wc
=
idxFile
CtxCreate
(
TFile
,
file
,
true
,
1024
*
1024
*
64
);
if
(
wc
==
NULL
)
{
if
(
wc
==
NULL
)
{
indexError
(
"failed to open index:%s"
,
file
);
indexError
(
"failed to open index:%s"
,
file
);
goto
End
;
goto
End
;
...
@@ -175,7 +175,7 @@ void tfileCachePut(TFileCache* tcache, ICacheKey* key, TFileReader* reader) {
...
@@ -175,7 +175,7 @@ void tfileCachePut(TFileCache* tcache, ICacheKey* key, TFileReader* reader) {
tfileReaderRef
(
reader
);
tfileReaderRef
(
reader
);
return
;
return
;
}
}
TFileReader
*
tfileReaderCreate
(
Writer
Ctx
*
ctx
)
{
TFileReader
*
tfileReaderCreate
(
IFile
Ctx
*
ctx
)
{
TFileReader
*
reader
=
taosMemoryCalloc
(
1
,
sizeof
(
TFileReader
));
TFileReader
*
reader
=
taosMemoryCalloc
(
1
,
sizeof
(
TFileReader
));
if
(
reader
==
NULL
)
{
if
(
reader
==
NULL
)
{
return
NULL
;
return
NULL
;
...
@@ -216,7 +216,7 @@ void tfileReaderDestroy(TFileReader* reader) {
...
@@ -216,7 +216,7 @@ void tfileReaderDestroy(TFileReader* reader) {
}
else
{
}
else
{
indexInfo
(
"%s is not removed"
,
reader
->
ctx
->
file
.
buf
);
indexInfo
(
"%s is not removed"
,
reader
->
ctx
->
file
.
buf
);
}
}
writer
CtxDestroy
(
reader
->
ctx
,
reader
->
remove
);
idxFile
CtxDestroy
(
reader
->
ctx
,
reader
->
remove
);
taosMemoryFree
(
reader
);
taosMemoryFree
(
reader
);
}
}
...
@@ -490,7 +490,7 @@ TFileWriter* tfileWriterOpen(char* path, uint64_t suid, int64_t version, const c
...
@@ -490,7 +490,7 @@ TFileWriter* tfileWriterOpen(char* path, uint64_t suid, int64_t version, const c
char
fullname
[
256
]
=
{
0
};
char
fullname
[
256
]
=
{
0
};
tfileGenFileFullName
(
fullname
,
path
,
suid
,
colName
,
version
);
tfileGenFileFullName
(
fullname
,
path
,
suid
,
colName
,
version
);
// indexInfo("open write file name %s", fullname);
// indexInfo("open write file name %s", fullname);
WriterCtx
*
wcx
=
writer
CtxCreate
(
TFile
,
fullname
,
false
,
1024
*
1024
*
64
);
IFileCtx
*
wcx
=
idxFile
CtxCreate
(
TFile
,
fullname
,
false
,
1024
*
1024
*
64
);
if
(
wcx
==
NULL
)
{
if
(
wcx
==
NULL
)
{
return
NULL
;
return
NULL
;
}
}
...
@@ -507,18 +507,18 @@ TFileReader* tfileReaderOpen(char* path, uint64_t suid, int64_t version, const c
...
@@ -507,18 +507,18 @@ TFileReader* tfileReaderOpen(char* path, uint64_t suid, int64_t version, const c
char
fullname
[
256
]
=
{
0
};
char
fullname
[
256
]
=
{
0
};
tfileGenFileFullName
(
fullname
,
path
,
suid
,
colName
,
version
);
tfileGenFileFullName
(
fullname
,
path
,
suid
,
colName
,
version
);
WriterCtx
*
wc
=
writer
CtxCreate
(
TFile
,
fullname
,
true
,
1024
*
1024
*
1024
);
IFileCtx
*
wc
=
idxFile
CtxCreate
(
TFile
,
fullname
,
true
,
1024
*
1024
*
1024
);
if
(
wc
==
NULL
)
{
if
(
wc
==
NULL
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
indexError
(
"failed to open readonly file: %s, reason: %s"
,
fullname
,
terrstr
());
indexError
(
"failed to open readonly file: %s, reason: %s"
,
fullname
,
terrstr
());
return
NULL
;
return
NULL
;
}
}
indexTrace
(
"open read file name:%s, file size: %
d
"
,
wc
->
file
.
buf
,
wc
->
file
.
size
);
indexTrace
(
"open read file name:%s, file size: %
"
PRId64
"
"
,
wc
->
file
.
buf
,
wc
->
file
.
size
);
TFileReader
*
reader
=
tfileReaderCreate
(
wc
);
TFileReader
*
reader
=
tfileReaderCreate
(
wc
);
return
reader
;
return
reader
;
}
}
TFileWriter
*
tfileWriterCreate
(
Writer
Ctx
*
ctx
,
TFileHeader
*
header
)
{
TFileWriter
*
tfileWriterCreate
(
IFile
Ctx
*
ctx
,
TFileHeader
*
header
)
{
TFileWriter
*
tw
=
taosMemoryCalloc
(
1
,
sizeof
(
TFileWriter
));
TFileWriter
*
tw
=
taosMemoryCalloc
(
1
,
sizeof
(
TFileWriter
));
if
(
tw
==
NULL
)
{
if
(
tw
==
NULL
)
{
indexError
(
"index: %"
PRIu64
" failed to alloc TFilerWriter"
,
header
->
suid
);
indexError
(
"index: %"
PRIu64
" failed to alloc TFilerWriter"
,
header
->
suid
);
...
@@ -609,14 +609,14 @@ void tfileWriterClose(TFileWriter* tw) {
...
@@ -609,14 +609,14 @@ void tfileWriterClose(TFileWriter* tw) {
if
(
tw
==
NULL
)
{
if
(
tw
==
NULL
)
{
return
;
return
;
}
}
writer
CtxDestroy
(
tw
->
ctx
,
false
);
idxFile
CtxDestroy
(
tw
->
ctx
,
false
);
taosMemoryFree
(
tw
);
taosMemoryFree
(
tw
);
}
}
void
tfileWriterDestroy
(
TFileWriter
*
tw
)
{
void
tfileWriterDestroy
(
TFileWriter
*
tw
)
{
if
(
tw
==
NULL
)
{
if
(
tw
==
NULL
)
{
return
;
return
;
}
}
writer
CtxDestroy
(
tw
->
ctx
,
false
);
idxFile
CtxDestroy
(
tw
->
ctx
,
false
);
taosMemoryFree
(
tw
);
taosMemoryFree
(
tw
);
}
}
...
@@ -892,8 +892,8 @@ static int tfileReaderLoadHeader(TFileReader* reader) {
...
@@ -892,8 +892,8 @@ static int tfileReaderLoadHeader(TFileReader* reader) {
return
0
;
return
0
;
}
}
static
int
tfileReaderLoadFst
(
TFileReader
*
reader
)
{
static
int
tfileReaderLoadFst
(
TFileReader
*
reader
)
{
Writer
Ctx
*
ctx
=
reader
->
ctx
;
IFile
Ctx
*
ctx
=
reader
->
ctx
;
int
size
=
ctx
->
size
(
ctx
);
int
size
=
ctx
->
size
(
ctx
);
// current load fst into memory, refactor it later
// current load fst into memory, refactor it later
int
fstSize
=
size
-
reader
->
header
.
fstOffset
-
sizeof
(
tfileMagicNumber
);
int
fstSize
=
size
-
reader
->
header
.
fstOffset
-
sizeof
(
tfileMagicNumber
);
...
@@ -905,8 +905,9 @@ static int tfileReaderLoadFst(TFileReader* reader) {
...
@@ -905,8 +905,9 @@ static int tfileReaderLoadFst(TFileReader* reader) {
int64_t
ts
=
taosGetTimestampUs
();
int64_t
ts
=
taosGetTimestampUs
();
int32_t
nread
=
ctx
->
readFrom
(
ctx
,
buf
,
fstSize
,
reader
->
header
.
fstOffset
);
int32_t
nread
=
ctx
->
readFrom
(
ctx
,
buf
,
fstSize
,
reader
->
header
.
fstOffset
);
int64_t
cost
=
taosGetTimestampUs
()
-
ts
;
int64_t
cost
=
taosGetTimestampUs
()
-
ts
;
indexInfo
(
"nread = %d, and fst offset=%d, fst size: %d, filename: %s, file size: %d, time cost: %"
PRId64
"us"
,
nread
,
indexInfo
(
"nread = %d, and fst offset=%d, fst size: %d, filename: %s, file size: %"
PRId64
", time cost: %"
PRId64
reader
->
header
.
fstOffset
,
fstSize
,
ctx
->
file
.
buf
,
ctx
->
file
.
size
,
cost
);
"us"
,
nread
,
reader
->
header
.
fstOffset
,
fstSize
,
ctx
->
file
.
buf
,
ctx
->
file
.
size
,
cost
);
// we assuse fst size less than FST_MAX_SIZE
// we assuse fst size less than FST_MAX_SIZE
assert
(
nread
>
0
&&
nread
<=
fstSize
);
assert
(
nread
>
0
&&
nread
<=
fstSize
);
...
@@ -919,7 +920,7 @@ static int tfileReaderLoadFst(TFileReader* reader) {
...
@@ -919,7 +920,7 @@ static int tfileReaderLoadFst(TFileReader* reader) {
}
}
static
int
tfileReaderLoadTableIds
(
TFileReader
*
reader
,
int32_t
offset
,
SArray
*
result
)
{
static
int
tfileReaderLoadTableIds
(
TFileReader
*
reader
,
int32_t
offset
,
SArray
*
result
)
{
// TODO(yihao): opt later
// TODO(yihao): opt later
Writer
Ctx
*
ctx
=
reader
->
ctx
;
IFile
Ctx
*
ctx
=
reader
->
ctx
;
// add block cache
// add block cache
char
block
[
4096
]
=
{
0
};
char
block
[
4096
]
=
{
0
};
int32_t
nread
=
ctx
->
readFrom
(
ctx
,
block
,
sizeof
(
block
),
offset
);
int32_t
nread
=
ctx
->
readFrom
(
ctx
,
block
,
sizeof
(
block
),
offset
);
...
@@ -952,7 +953,7 @@ static int tfileReaderLoadTableIds(TFileReader* reader, int32_t offset, SArray*
...
@@ -952,7 +953,7 @@ static int tfileReaderLoadTableIds(TFileReader* reader, int32_t offset, SArray*
}
}
static
int
tfileReaderVerify
(
TFileReader
*
reader
)
{
static
int
tfileReaderVerify
(
TFileReader
*
reader
)
{
// just validate header and Footer, file corrupted also shuild be verified later
// just validate header and Footer, file corrupted also shuild be verified later
Writer
Ctx
*
ctx
=
reader
->
ctx
;
IFile
Ctx
*
ctx
=
reader
->
ctx
;
uint64_t
tMagicNumber
=
0
;
uint64_t
tMagicNumber
=
0
;
...
...
source/libs/index/test/fstTest.cc
浏览文件 @
3b50fee6
...
@@ -7,7 +7,6 @@
...
@@ -7,7 +7,6 @@
#include "index.h"
#include "index.h"
#include "indexCache.h"
#include "indexCache.h"
#include "indexFst.h"
#include "indexFst.h"
#include "indexFstCountingWriter.h"
#include "indexFstUtil.h"
#include "indexFstUtil.h"
#include "indexInt.h"
#include "indexInt.h"
#include "indexTfile.h"
#include "indexTfile.h"
...
@@ -20,7 +19,7 @@ class FstWriter {
...
@@ -20,7 +19,7 @@ class FstWriter {
public:
public:
FstWriter
()
{
FstWriter
()
{
taosRemoveFile
(
fileName
.
c_str
());
taosRemoveFile
(
fileName
.
c_str
());
_wc
=
writer
CtxCreate
(
TFile
,
fileName
.
c_str
(),
false
,
64
*
1024
*
1024
);
_wc
=
idxFile
CtxCreate
(
TFile
,
fileName
.
c_str
(),
false
,
64
*
1024
*
1024
);
_b
=
fstBuilderCreate
(
_wc
,
0
);
_b
=
fstBuilderCreate
(
_wc
,
0
);
}
}
bool
Put
(
const
std
::
string
&
key
,
uint64_t
val
)
{
bool
Put
(
const
std
::
string
&
key
,
uint64_t
val
)
{
...
@@ -38,25 +37,25 @@ class FstWriter {
...
@@ -38,25 +37,25 @@ class FstWriter {
fstBuilderFinish
(
_b
);
fstBuilderFinish
(
_b
);
fstBuilderDestroy
(
_b
);
fstBuilderDestroy
(
_b
);
writer
CtxDestroy
(
_wc
,
false
);
idxFile
CtxDestroy
(
_wc
,
false
);
}
}
private:
private:
FstBuilder
*
_b
;
FstBuilder
*
_b
;
WriterCtx
*
_wc
;
IFileCtx
*
_wc
;
};
};
class
FstReadMemory
{
class
FstReadMemory
{
public:
public:
FstReadMemory
(
int32_t
size
,
const
std
::
string
&
fileName
=
TD_TMP_DIR_PATH
"tindex.tindex"
)
{
FstReadMemory
(
int32_t
size
,
const
std
::
string
&
fileName
=
TD_TMP_DIR_PATH
"tindex.tindex"
)
{
_wc
=
writer
CtxCreate
(
TFile
,
fileName
.
c_str
(),
true
,
64
*
1024
);
_wc
=
idxFile
CtxCreate
(
TFile
,
fileName
.
c_str
(),
true
,
64
*
1024
);
_w
=
fstCountingWriter
Create
(
_wc
);
_w
=
idxFile
Create
(
_wc
);
_size
=
size
;
_size
=
size
;
memset
((
void
*
)
&
_s
,
0
,
sizeof
(
_s
));
memset
((
void
*
)
&
_s
,
0
,
sizeof
(
_s
));
}
}
bool
init
()
{
bool
init
()
{
char
*
buf
=
(
char
*
)
taosMemoryCalloc
(
1
,
sizeof
(
char
)
*
_size
);
char
*
buf
=
(
char
*
)
taosMemoryCalloc
(
1
,
sizeof
(
char
)
*
_size
);
int
nRead
=
fstCountingWriter
Read
(
_w
,
(
uint8_t
*
)
buf
,
_size
);
int
nRead
=
idxFile
Read
(
_w
,
(
uint8_t
*
)
buf
,
_size
);
if
(
nRead
<=
0
)
{
if
(
nRead
<=
0
)
{
return
false
;
return
false
;
}
}
...
@@ -141,18 +140,18 @@ class FstReadMemory {
...
@@ -141,18 +140,18 @@ class FstReadMemory {
}
}
~
FstReadMemory
()
{
~
FstReadMemory
()
{
fstCountingWriter
Destroy
(
_w
);
idxFile
Destroy
(
_w
);
fstDestroy
(
_fst
);
fstDestroy
(
_fst
);
fstSliceDestroy
(
&
_s
);
fstSliceDestroy
(
&
_s
);
writer
CtxDestroy
(
_wc
,
false
);
idxFile
CtxDestroy
(
_wc
,
false
);
}
}
private:
private:
FstCountingWriter
*
_w
;
IdxFstFile
*
_w
;
Fst
*
_fst
;
Fst
*
_fst
;
FstSlice
_s
;
FstSlice
_s
;
WriterCtx
*
_wc
;
IFileCtx
*
_wc
;
int32_t
_size
;
int32_t
_size
;
};
};
#define L 100
#define L 100
...
...
source/libs/index/test/fstUT.cc
浏览文件 @
3b50fee6
...
@@ -8,7 +8,6 @@
...
@@ -8,7 +8,6 @@
#include "index.h"
#include "index.h"
#include "indexCache.h"
#include "indexCache.h"
#include "indexFst.h"
#include "indexFst.h"
#include "indexFstCountingWriter.h"
#include "indexFstUtil.h"
#include "indexFstUtil.h"
#include "indexInt.h"
#include "indexInt.h"
#include "indexTfile.h"
#include "indexTfile.h"
...
@@ -40,7 +39,7 @@ static void EnvCleanup() {}
...
@@ -40,7 +39,7 @@ static void EnvCleanup() {}
class
FstWriter
{
class
FstWriter
{
public:
public:
FstWriter
()
{
FstWriter
()
{
_wc
=
writer
CtxCreate
(
TFile
,
tindex
,
false
,
64
*
1024
*
1024
);
_wc
=
idxFile
CtxCreate
(
TFile
,
tindex
,
false
,
64
*
1024
*
1024
);
_b
=
fstBuilderCreate
(
_wc
,
0
);
_b
=
fstBuilderCreate
(
_wc
,
0
);
}
}
bool
Put
(
const
std
::
string
&
key
,
uint64_t
val
)
{
bool
Put
(
const
std
::
string
&
key
,
uint64_t
val
)
{
...
@@ -58,25 +57,25 @@ class FstWriter {
...
@@ -58,25 +57,25 @@ class FstWriter {
fstBuilderFinish
(
_b
);
fstBuilderFinish
(
_b
);
fstBuilderDestroy
(
_b
);
fstBuilderDestroy
(
_b
);
writer
CtxDestroy
(
_wc
,
false
);
idxFile
CtxDestroy
(
_wc
,
false
);
}
}
private:
private:
FstBuilder
*
_b
;
FstBuilder
*
_b
;
WriterCtx
*
_wc
;
IFileCtx
*
_wc
;
};
};
class
FstReadMemory
{
class
FstReadMemory
{
public:
public:
FstReadMemory
(
size_t
size
)
{
FstReadMemory
(
size_t
size
)
{
_wc
=
writer
CtxCreate
(
TFile
,
tindex
,
true
,
64
*
1024
);
_wc
=
idxFile
CtxCreate
(
TFile
,
tindex
,
true
,
64
*
1024
);
_w
=
fstCountingWriter
Create
(
_wc
);
_w
=
idxFile
Create
(
_wc
);
_size
=
size
;
_size
=
size
;
memset
((
void
*
)
&
_s
,
0
,
sizeof
(
_s
));
memset
((
void
*
)
&
_s
,
0
,
sizeof
(
_s
));
}
}
bool
init
()
{
bool
init
()
{
char
*
buf
=
(
char
*
)
taosMemoryCalloc
(
1
,
sizeof
(
char
)
*
_size
);
char
*
buf
=
(
char
*
)
taosMemoryCalloc
(
1
,
sizeof
(
char
)
*
_size
);
int
nRead
=
fstCountingWriter
Read
(
_w
,
(
uint8_t
*
)
buf
,
_size
);
int
nRead
=
idxFile
Read
(
_w
,
(
uint8_t
*
)
buf
,
_size
);
if
(
nRead
<=
0
)
{
if
(
nRead
<=
0
)
{
return
false
;
return
false
;
}
}
...
@@ -130,18 +129,18 @@ class FstReadMemory {
...
@@ -130,18 +129,18 @@ class FstReadMemory {
}
}
~
FstReadMemory
()
{
~
FstReadMemory
()
{
fstCountingWriter
Destroy
(
_w
);
idxFile
Destroy
(
_w
);
fstDestroy
(
_fst
);
fstDestroy
(
_fst
);
fstSliceDestroy
(
&
_s
);
fstSliceDestroy
(
&
_s
);
writer
CtxDestroy
(
_wc
,
false
);
idxFile
CtxDestroy
(
_wc
,
false
);
}
}
private:
private:
FstCountingWriter
*
_w
;
IdxFstFile
*
_w
;
Fst
*
_fst
;
Fst
*
_fst
;
FstSlice
_s
;
FstSlice
_s
;
WriterCtx
*
_wc
;
IFileCtx
*
_wc
;
size_t
_size
;
size_t
_size
;
};
};
class
FstWriterEnv
:
public
::
testing
::
Test
{
class
FstWriterEnv
:
public
::
testing
::
Test
{
...
...
source/libs/index/test/indexTests.cc
浏览文件 @
3b50fee6
...
@@ -20,7 +20,6 @@
...
@@ -20,7 +20,6 @@
#include "index.h"
#include "index.h"
#include "indexCache.h"
#include "indexCache.h"
#include "indexFst.h"
#include "indexFst.h"
#include "indexFstCountingWriter.h"
#include "indexFstUtil.h"
#include "indexFstUtil.h"
#include "indexInt.h"
#include "indexInt.h"
#include "indexTfile.h"
#include "indexTfile.h"
...
@@ -51,7 +50,7 @@ class DebugInfo {
...
@@ -51,7 +50,7 @@ class DebugInfo {
class
FstWriter
{
class
FstWriter
{
public:
public:
FstWriter
()
{
FstWriter
()
{
_wc
=
writer
CtxCreate
(
TFile
,
TD_TMP_DIR_PATH
"tindex"
,
false
,
64
*
1024
*
1024
);
_wc
=
idxFile
CtxCreate
(
TFile
,
TD_TMP_DIR_PATH
"tindex"
,
false
,
64
*
1024
*
1024
);
_b
=
fstBuilderCreate
(
NULL
,
0
);
_b
=
fstBuilderCreate
(
NULL
,
0
);
}
}
bool
Put
(
const
std
::
string
&
key
,
uint64_t
val
)
{
bool
Put
(
const
std
::
string
&
key
,
uint64_t
val
)
{
...
@@ -64,25 +63,25 @@ class FstWriter {
...
@@ -64,25 +63,25 @@ class FstWriter {
fstBuilderFinish
(
_b
);
fstBuilderFinish
(
_b
);
fstBuilderDestroy
(
_b
);
fstBuilderDestroy
(
_b
);
writer
CtxDestroy
(
_wc
,
false
);
idxFile
CtxDestroy
(
_wc
,
false
);
}
}
private:
private:
FstBuilder
*
_b
;
FstBuilder
*
_b
;
WriterCtx
*
_wc
;
IFileCtx
*
_wc
;
};
};
class
FstReadMemory
{
class
FstReadMemory
{
public:
public:
FstReadMemory
(
size_t
size
)
{
FstReadMemory
(
size_t
size
)
{
_wc
=
writer
CtxCreate
(
TFile
,
TD_TMP_DIR_PATH
"tindex"
,
true
,
64
*
1024
);
_wc
=
idxFile
CtxCreate
(
TFile
,
TD_TMP_DIR_PATH
"tindex"
,
true
,
64
*
1024
);
_w
=
fstCountingWriter
Create
(
_wc
);
_w
=
idxFile
Create
(
_wc
);
_size
=
size
;
_size
=
size
;
memset
((
void
*
)
&
_s
,
0
,
sizeof
(
_s
));
memset
((
void
*
)
&
_s
,
0
,
sizeof
(
_s
));
}
}
bool
init
()
{
bool
init
()
{
char
*
buf
=
(
char
*
)
taosMemoryCalloc
(
1
,
sizeof
(
char
)
*
_size
);
char
*
buf
=
(
char
*
)
taosMemoryCalloc
(
1
,
sizeof
(
char
)
*
_size
);
int
nRead
=
fstCountingWriter
Read
(
_w
,
(
uint8_t
*
)
buf
,
_size
);
int
nRead
=
idxFile
Read
(
_w
,
(
uint8_t
*
)
buf
,
_size
);
if
(
nRead
<=
0
)
{
if
(
nRead
<=
0
)
{
return
false
;
return
false
;
}
}
...
@@ -124,18 +123,18 @@ class FstReadMemory {
...
@@ -124,18 +123,18 @@ class FstReadMemory {
}
}
~
FstReadMemory
()
{
~
FstReadMemory
()
{
fstCountingWriter
Destroy
(
_w
);
idxFile
Destroy
(
_w
);
fstDestroy
(
_fst
);
fstDestroy
(
_fst
);
fstSliceDestroy
(
&
_s
);
fstSliceDestroy
(
&
_s
);
writer
CtxDestroy
(
_wc
,
true
);
idxFile
CtxDestroy
(
_wc
,
true
);
}
}
private:
private:
FstCountingWriter
*
_w
;
IdxFstFile
*
_w
;
Fst
*
_fst
;
Fst
*
_fst
;
FstSlice
_s
;
FstSlice
_s
;
WriterCtx
*
_wc
;
IFileCtx
*
_wc
;
size_t
_size
;
size_t
_size
;
};
};
#define L 100
#define L 100
...
@@ -392,13 +391,13 @@ class TFileObj {
...
@@ -392,13 +391,13 @@ class TFileObj {
fileName_
=
path
;
fileName_
=
path
;
WriterCtx
*
ctx
=
writer
CtxCreate
(
TFile
,
path
.
c_str
(),
false
,
64
*
1024
*
1024
);
IFileCtx
*
ctx
=
idxFile
CtxCreate
(
TFile
,
path
.
c_str
(),
false
,
64
*
1024
*
1024
);
writer_
=
tfileWriterCreate
(
ctx
,
&
header
);
writer_
=
tfileWriterCreate
(
ctx
,
&
header
);
return
writer_
!=
NULL
?
true
:
false
;
return
writer_
!=
NULL
?
true
:
false
;
}
}
bool
InitReader
()
{
bool
InitReader
()
{
WriterCtx
*
ctx
=
writer
CtxCreate
(
TFile
,
fileName_
.
c_str
(),
true
,
64
*
1024
*
1024
);
IFileCtx
*
ctx
=
idxFile
CtxCreate
(
TFile
,
fileName_
.
c_str
(),
true
,
64
*
1024
*
1024
);
reader_
=
tfileReaderCreate
(
ctx
);
reader_
=
tfileReaderCreate
(
ctx
);
return
reader_
!=
NULL
?
true
:
false
;
return
reader_
!=
NULL
?
true
:
false
;
}
}
...
...
source/libs/index/test/jsonUT.cc
浏览文件 @
3b50fee6
...
@@ -7,7 +7,6 @@
...
@@ -7,7 +7,6 @@
#include "index.h"
#include "index.h"
#include "indexCache.h"
#include "indexCache.h"
#include "indexFst.h"
#include "indexFst.h"
#include "indexFstCountingWriter.h"
#include "indexFstUtil.h"
#include "indexFstUtil.h"
#include "indexInt.h"
#include "indexInt.h"
#include "indexTfile.h"
#include "indexTfile.h"
...
...
source/libs/index/test/utilUT.cc
浏览文件 @
3b50fee6
...
@@ -8,7 +8,6 @@
...
@@ -8,7 +8,6 @@
#include "indexCache.h"
#include "indexCache.h"
#include "indexComm.h"
#include "indexComm.h"
#include "indexFst.h"
#include "indexFst.h"
#include "indexFstCountingWriter.h"
#include "indexFstUtil.h"
#include "indexFstUtil.h"
#include "indexInt.h"
#include "indexInt.h"
#include "indexTfile.h"
#include "indexTfile.h"
...
...
source/libs/nodes/src/nodesUtilFuncs.c
浏览文件 @
3b50fee6
...
@@ -19,8 +19,8 @@
...
@@ -19,8 +19,8 @@
#include "querynodes.h"
#include "querynodes.h"
#include "taos.h"
#include "taos.h"
#include "taoserror.h"
#include "taoserror.h"
#include "thash.h"
#include "tdatablock.h"
#include "tdatablock.h"
#include "thash.h"
static
SNode
*
makeNode
(
ENodeType
type
,
size_t
size
)
{
static
SNode
*
makeNode
(
ENodeType
type
,
size_t
size
)
{
SNode
*
p
=
taosMemoryCalloc
(
1
,
size
);
SNode
*
p
=
taosMemoryCalloc
(
1
,
size
);
...
@@ -1497,13 +1497,18 @@ typedef struct SCollectFuncsCxt {
...
@@ -1497,13 +1497,18 @@ typedef struct SCollectFuncsCxt {
int32_t
errCode
;
int32_t
errCode
;
FFuncClassifier
classifier
;
FFuncClassifier
classifier
;
SNodeList
*
pFuncs
;
SNodeList
*
pFuncs
;
SHashObj
*
pAliasName
;
}
SCollectFuncsCxt
;
}
SCollectFuncsCxt
;
static
EDealRes
collectFuncs
(
SNode
*
pNode
,
void
*
pContext
)
{
static
EDealRes
collectFuncs
(
SNode
*
pNode
,
void
*
pContext
)
{
SCollectFuncsCxt
*
pCxt
=
(
SCollectFuncsCxt
*
)
pContext
;
SCollectFuncsCxt
*
pCxt
=
(
SCollectFuncsCxt
*
)
pContext
;
if
(
QUERY_NODE_FUNCTION
==
nodeType
(
pNode
)
&&
pCxt
->
classifier
(((
SFunctionNode
*
)
pNode
)
->
funcId
)
&&
if
(
QUERY_NODE_FUNCTION
==
nodeType
(
pNode
)
&&
pCxt
->
classifier
(((
SFunctionNode
*
)
pNode
)
->
funcId
)
&&
!
(((
SExprNode
*
)
pNode
)
->
orderAlias
))
{
!
(((
SExprNode
*
)
pNode
)
->
orderAlias
))
{
pCxt
->
errCode
=
nodesListStrictAppend
(
pCxt
->
pFuncs
,
nodesCloneNode
(
pNode
));
SExprNode
*
pExpr
=
(
SExprNode
*
)
pNode
;
if
(
NULL
==
taosHashGet
(
pCxt
->
pAliasName
,
pExpr
->
aliasName
,
strlen
(
pExpr
->
aliasName
)))
{
pCxt
->
errCode
=
nodesListStrictAppend
(
pCxt
->
pFuncs
,
nodesCloneNode
(
pNode
));
taosHashPut
(
pCxt
->
pAliasName
,
pExpr
->
aliasName
,
strlen
(
pExpr
->
aliasName
),
&
pExpr
,
POINTER_BYTES
);
}
return
(
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
?
DEAL_RES_IGNORE_CHILD
:
DEAL_RES_ERROR
);
return
(
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
?
DEAL_RES_IGNORE_CHILD
:
DEAL_RES_ERROR
);
}
}
return
DEAL_RES_CONTINUE
;
return
DEAL_RES_CONTINUE
;
...
@@ -1515,23 +1520,27 @@ int32_t nodesCollectFuncs(SSelectStmt* pSelect, ESqlClause clause, FFuncClassifi
...
@@ -1515,23 +1520,27 @@ int32_t nodesCollectFuncs(SSelectStmt* pSelect, ESqlClause clause, FFuncClassifi
}
}
SCollectFuncsCxt
cxt
=
{
SCollectFuncsCxt
cxt
=
{
.
errCode
=
TSDB_CODE_SUCCESS
,
.
classifier
=
classifier
,
.
pFuncs
=
(
NULL
==
*
pFuncs
?
nodesMakeList
()
:
*
pFuncs
)};
.
errCode
=
TSDB_CODE_SUCCESS
,
.
classifier
=
classifier
,
.
pFuncs
=
(
NULL
==
*
pFuncs
?
nodesMakeList
()
:
*
pFuncs
),
.
pAliasName
=
taosHashInit
(
4
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_VARCHAR
),
false
,
false
)};
if
(
NULL
==
cxt
.
pFuncs
)
{
if
(
NULL
==
cxt
.
pFuncs
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_OUT_OF_MEMORY
;
}
}
*
pFuncs
=
NULL
;
*
pFuncs
=
NULL
;
nodesWalkSelectStmt
(
pSelect
,
clause
,
collectFuncs
,
&
cxt
);
nodesWalkSelectStmt
(
pSelect
,
clause
,
collectFuncs
,
&
cxt
);
if
(
TSDB_CODE_SUCCESS
!
=
cxt
.
errCode
)
{
if
(
TSDB_CODE_SUCCESS
=
=
cxt
.
errCode
)
{
nodesDestroyList
(
cxt
.
pFuncs
);
if
(
LIST_LENGTH
(
cxt
.
pFuncs
)
>
0
)
{
return
cxt
.
errCode
;
*
pFuncs
=
cxt
.
pFuncs
;
}
}
else
{
if
(
LIST_LENGTH
(
cxt
.
pFuncs
)
>
0
)
{
nodesDestroyList
(
cxt
.
pFuncs
);
*
pFuncs
=
cxt
.
pFuncs
;
}
}
else
{
}
else
{
nodesDestroyList
(
cxt
.
pFuncs
);
nodesDestroyList
(
cxt
.
pFuncs
);
}
}
taosHashCleanup
(
cxt
.
pAliasName
);
return
TSDB_CODE_SUCCESS
;
return
cxt
.
errCode
;
}
}
typedef
struct
SCollectSpecialNodesCxt
{
typedef
struct
SCollectSpecialNodesCxt
{
...
...
source/libs/parser/inc/parAst.h
浏览文件 @
3b50fee6
...
@@ -154,6 +154,7 @@ SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_
...
@@ -154,6 +154,7 @@ SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_
SNode
*
createAlterTableRenameCol
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
,
int8_t
alterType
,
SToken
*
pOldColName
,
SNode
*
createAlterTableRenameCol
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
,
int8_t
alterType
,
SToken
*
pOldColName
,
SToken
*
pNewColName
);
SToken
*
pNewColName
);
SNode
*
createAlterTableSetTag
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
,
SToken
*
pTagName
,
SNode
*
pVal
);
SNode
*
createAlterTableSetTag
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
,
SToken
*
pTagName
,
SNode
*
pVal
);
SNode
*
setAlterSuperTableType
(
SNode
*
pStmt
);
SNode
*
createUseDatabaseStmt
(
SAstCreateContext
*
pCxt
,
SToken
*
pDbName
);
SNode
*
createUseDatabaseStmt
(
SAstCreateContext
*
pCxt
,
SToken
*
pDbName
);
SNode
*
createShowStmt
(
SAstCreateContext
*
pCxt
,
ENodeType
type
);
SNode
*
createShowStmt
(
SAstCreateContext
*
pCxt
,
ENodeType
type
);
SNode
*
createShowStmtWithCond
(
SAstCreateContext
*
pCxt
,
ENodeType
type
,
SNode
*
pDbName
,
SNode
*
pTbName
,
SNode
*
createShowStmtWithCond
(
SAstCreateContext
*
pCxt
,
ENodeType
type
,
SNode
*
pDbName
,
SNode
*
pTbName
,
...
...
source/libs/parser/inc/parUtil.h
浏览文件 @
3b50fee6
...
@@ -53,6 +53,7 @@ typedef struct SParseMetaCache {
...
@@ -53,6 +53,7 @@ typedef struct SParseMetaCache {
}
SParseMetaCache
;
}
SParseMetaCache
;
int32_t
generateSyntaxErrMsg
(
SMsgBuf
*
pBuf
,
int32_t
errCode
,
...);
int32_t
generateSyntaxErrMsg
(
SMsgBuf
*
pBuf
,
int32_t
errCode
,
...);
int32_t
generateSyntaxErrMsgExt
(
SMsgBuf
*
pBuf
,
int32_t
errCode
,
const
char
*
pFormat
,
...);
int32_t
buildInvalidOperationMsg
(
SMsgBuf
*
pMsgBuf
,
const
char
*
msg
);
int32_t
buildInvalidOperationMsg
(
SMsgBuf
*
pMsgBuf
,
const
char
*
msg
);
int32_t
buildSyntaxErrMsg
(
SMsgBuf
*
pBuf
,
const
char
*
additionalInfo
,
const
char
*
sourceStr
);
int32_t
buildSyntaxErrMsg
(
SMsgBuf
*
pBuf
,
const
char
*
additionalInfo
,
const
char
*
sourceStr
);
...
...
source/libs/parser/inc/sql.y
浏览文件 @
3b50fee6
...
@@ -232,7 +232,7 @@ cmd ::= DROP TABLE multi_drop_clause(A).
...
@@ -232,7 +232,7 @@ cmd ::= DROP TABLE multi_drop_clause(A).
cmd ::= DROP STABLE exists_opt(A) full_table_name(B). { pCxt->pRootNode = createDropSuperTableStmt(pCxt, A, B); }
cmd ::= DROP STABLE exists_opt(A) full_table_name(B). { pCxt->pRootNode = createDropSuperTableStmt(pCxt, A, B); }
cmd ::= ALTER TABLE alter_table_clause(A). { pCxt->pRootNode = A; }
cmd ::= ALTER TABLE alter_table_clause(A). { pCxt->pRootNode = A; }
cmd ::= ALTER STABLE alter_table_clause(A). { pCxt->pRootNode =
A
; }
cmd ::= ALTER STABLE alter_table_clause(A). { pCxt->pRootNode =
setAlterSuperTableType(A)
; }
alter_table_clause(A) ::= full_table_name(B) alter_table_options(C). { A = createAlterTableModifyOptions(pCxt, B, C); }
alter_table_clause(A) ::= full_table_name(B) alter_table_options(C). { A = createAlterTableModifyOptions(pCxt, B, C); }
alter_table_clause(A) ::=
alter_table_clause(A) ::=
...
@@ -259,7 +259,7 @@ multi_create_clause(A) ::= multi_create_clause(B) create_subtable_clause(C).
...
@@ -259,7 +259,7 @@ multi_create_clause(A) ::= multi_create_clause(B) create_subtable_clause(C).
create_subtable_clause(A) ::=
create_subtable_clause(A) ::=
not_exists_opt(B) full_table_name(C) USING full_table_name(D)
not_exists_opt(B) full_table_name(C) USING full_table_name(D)
specific_tags_opt(E) TAGS NK_LP
literal_list(F) NK_RP table_options(G).
{ A = createCreateSubTableClause(pCxt, B, C, D, E, F, G); }
specific_tags_opt(E) TAGS NK_LP
expression_list(F) NK_RP table_options(G).
{ A = createCreateSubTableClause(pCxt, B, C, D, E, F, G); }
%type multi_drop_clause { SNodeList* }
%type multi_drop_clause { SNodeList* }
%destructor multi_drop_clause { nodesDestroyList($$); }
%destructor multi_drop_clause { nodesDestroyList($$); }
...
...
source/libs/parser/src/parAstCreater.c
浏览文件 @
3b50fee6
...
@@ -1127,6 +1127,11 @@ SNode* createAlterTableSetTag(SAstCreateContext* pCxt, SNode* pRealTable, SToken
...
@@ -1127,6 +1127,11 @@ SNode* createAlterTableSetTag(SAstCreateContext* pCxt, SNode* pRealTable, SToken
return
createAlterTableStmtFinalize
(
pRealTable
,
pStmt
);
return
createAlterTableStmtFinalize
(
pRealTable
,
pStmt
);
}
}
SNode
*
setAlterSuperTableType
(
SNode
*
pStmt
)
{
setNodeType
(
pStmt
,
QUERY_NODE_ALTER_SUPER_TABLE_STMT
);
return
pStmt
;
}
SNode
*
createUseDatabaseStmt
(
SAstCreateContext
*
pCxt
,
SToken
*
pDbName
)
{
SNode
*
createUseDatabaseStmt
(
SAstCreateContext
*
pCxt
,
SToken
*
pDbName
)
{
CHECK_PARSER_STATUS
(
pCxt
);
CHECK_PARSER_STATUS
(
pCxt
);
if
(
!
checkDbName
(
pCxt
,
pDbName
,
false
))
{
if
(
!
checkDbName
(
pCxt
,
pDbName
,
false
))
{
...
...
source/libs/parser/src/parAstParser.c
浏览文件 @
3b50fee6
...
@@ -247,6 +247,10 @@ static int32_t collectMetaKeyFromAlterTable(SCollectMetaKeyCxt* pCxt, SAlterTabl
...
@@ -247,6 +247,10 @@ static int32_t collectMetaKeyFromAlterTable(SCollectMetaKeyCxt* pCxt, SAlterTabl
return
code
;
return
code
;
}
}
static
int32_t
collectMetaKeyFromAlterStable
(
SCollectMetaKeyCxt
*
pCxt
,
SAlterTableStmt
*
pStmt
)
{
return
reserveTableMetaInCache
(
pCxt
->
pParseCxt
->
acctId
,
pStmt
->
dbName
,
pStmt
->
tableName
,
pCxt
->
pMetaCache
);
}
static
int32_t
collectMetaKeyFromUseDatabase
(
SCollectMetaKeyCxt
*
pCxt
,
SUseDatabaseStmt
*
pStmt
)
{
static
int32_t
collectMetaKeyFromUseDatabase
(
SCollectMetaKeyCxt
*
pCxt
,
SUseDatabaseStmt
*
pStmt
)
{
return
reserveDbVgVersionInCache
(
pCxt
->
pParseCxt
->
acctId
,
pStmt
->
dbName
,
pCxt
->
pMetaCache
);
return
reserveDbVgVersionInCache
(
pCxt
->
pParseCxt
->
acctId
,
pStmt
->
dbName
,
pCxt
->
pMetaCache
);
}
}
...
@@ -483,6 +487,8 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
...
@@ -483,6 +487,8 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
return
collectMetaKeyFromDropTable
(
pCxt
,
(
SDropTableStmt
*
)
pStmt
);
return
collectMetaKeyFromDropTable
(
pCxt
,
(
SDropTableStmt
*
)
pStmt
);
case
QUERY_NODE_ALTER_TABLE_STMT
:
case
QUERY_NODE_ALTER_TABLE_STMT
:
return
collectMetaKeyFromAlterTable
(
pCxt
,
(
SAlterTableStmt
*
)
pStmt
);
return
collectMetaKeyFromAlterTable
(
pCxt
,
(
SAlterTableStmt
*
)
pStmt
);
case
QUERY_NODE_ALTER_SUPER_TABLE_STMT
:
return
collectMetaKeyFromAlterStable
(
pCxt
,
(
SAlterTableStmt
*
)
pStmt
);
case
QUERY_NODE_USE_DATABASE_STMT
:
case
QUERY_NODE_USE_DATABASE_STMT
:
return
collectMetaKeyFromUseDatabase
(
pCxt
,
(
SUseDatabaseStmt
*
)
pStmt
);
return
collectMetaKeyFromUseDatabase
(
pCxt
,
(
SUseDatabaseStmt
*
)
pStmt
);
case
QUERY_NODE_CREATE_INDEX_STMT
:
case
QUERY_NODE_CREATE_INDEX_STMT
:
...
...
source/libs/parser/src/parInsert.c
浏览文件 @
3b50fee6
...
@@ -48,6 +48,12 @@
...
@@ -48,6 +48,12 @@
pSql += sToken.n; \
pSql += sToken.n; \
} while (TK_NK_SPACE == sToken.type)
} while (TK_NK_SPACE == sToken.type)
typedef
struct
SInsertParseBaseContext
{
SParseContext
*
pComCxt
;
char
*
pSql
;
SMsgBuf
msg
;
}
SInsertParseBaseContext
;
typedef
struct
SInsertParseContext
{
typedef
struct
SInsertParseContext
{
SParseContext
*
pComCxt
;
// input
SParseContext
*
pComCxt
;
// input
char
*
pSql
;
// input
char
*
pSql
;
// input
...
@@ -1105,6 +1111,32 @@ static int32_t storeTableMeta(SInsertParseContext* pCxt, SHashObj* pHash, SName*
...
@@ -1105,6 +1111,32 @@ static int32_t storeTableMeta(SInsertParseContext* pCxt, SHashObj* pHash, SName*
return
taosHashPut
(
pHash
,
pName
,
len
,
&
pBackup
,
POINTER_BYTES
);
return
taosHashPut
(
pHash
,
pName
,
len
,
&
pBackup
,
POINTER_BYTES
);
}
}
static
int32_t
skipParentheses
(
SInsertParseSyntaxCxt
*
pCxt
)
{
SToken
sToken
;
int32_t
expectRightParenthesis
=
1
;
while
(
1
)
{
NEXT_TOKEN
(
pCxt
->
pSql
,
sToken
);
if
(
TK_NK_LP
==
sToken
.
type
)
{
++
expectRightParenthesis
;
}
else
if
(
TK_NK_RP
==
sToken
.
type
&&
0
==
--
expectRightParenthesis
)
{
break
;
}
if
(
0
==
sToken
.
n
)
{
return
buildSyntaxErrMsg
(
&
pCxt
->
msg
,
") expected"
,
NULL
);
}
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
skipBoundColumns
(
SInsertParseSyntaxCxt
*
pCxt
)
{
return
skipParentheses
(
pCxt
);
}
static
int32_t
ignoreBoundColumns
(
SInsertParseContext
*
pCxt
)
{
SInsertParseSyntaxCxt
cxt
=
{.
pComCxt
=
pCxt
->
pComCxt
,
.
pSql
=
pCxt
->
pSql
,
.
msg
=
pCxt
->
msg
,
.
pMetaCache
=
NULL
};
int32_t
code
=
skipBoundColumns
(
&
cxt
);
pCxt
->
pSql
=
cxt
.
pSql
;
return
code
;
}
static
int32_t
skipUsingClause
(
SInsertParseSyntaxCxt
*
pCxt
);
static
int32_t
skipUsingClause
(
SInsertParseSyntaxCxt
*
pCxt
);
// pSql -> stb_name [(tag1_name, ...)] TAGS (tag1_value, ...)
// pSql -> stb_name [(tag1_name, ...)] TAGS (tag1_value, ...)
...
@@ -1453,12 +1485,29 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) {
...
@@ -1453,12 +1485,29 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) {
tNameGetFullDbName
(
&
name
,
dbFName
);
tNameGetFullDbName
(
&
name
,
dbFName
);
CHECK_CODE
(
taosHashPut
(
pCxt
->
pDbFNameHashObj
,
dbFName
,
strlen
(
dbFName
),
dbFName
,
sizeof
(
dbFName
)));
CHECK_CODE
(
taosHashPut
(
pCxt
->
pDbFNameHashObj
,
dbFName
,
strlen
(
dbFName
),
dbFName
,
sizeof
(
dbFName
)));
bool
existedUsing
=
false
;
// USING clause
// USING clause
if
(
TK_USING
==
sToken
.
type
)
{
if
(
TK_USING
==
sToken
.
type
)
{
existedUsing
=
true
;
CHECK_CODE
(
parseUsingClause
(
pCxt
,
&
name
,
tbFName
));
CHECK_CODE
(
parseUsingClause
(
pCxt
,
&
name
,
tbFName
));
NEXT_TOKEN
(
pCxt
->
pSql
,
sToken
);
NEXT_TOKEN
(
pCxt
->
pSql
,
sToken
);
autoCreateTbl
=
true
;
autoCreateTbl
=
true
;
}
else
{
}
char
*
pBoundColsStart
=
NULL
;
if
(
TK_NK_LP
==
sToken
.
type
)
{
// pSql -> field1_name, ...)
pBoundColsStart
=
pCxt
->
pSql
;
CHECK_CODE
(
ignoreBoundColumns
(
pCxt
));
// CHECK_CODE(parseBoundColumns(pCxt, &dataBuf->boundColumnInfo, getTableColumnSchema(pCxt->pTableMeta)));
NEXT_TOKEN
(
pCxt
->
pSql
,
sToken
);
}
if
(
TK_USING
==
sToken
.
type
)
{
CHECK_CODE
(
parseUsingClause
(
pCxt
,
&
name
,
tbFName
));
NEXT_TOKEN
(
pCxt
->
pSql
,
sToken
);
autoCreateTbl
=
true
;
}
else
if
(
!
existedUsing
)
{
CHECK_CODE
(
getTableMeta
(
pCxt
,
&
name
,
dbFName
));
CHECK_CODE
(
getTableMeta
(
pCxt
,
&
name
,
dbFName
));
}
}
...
@@ -1467,10 +1516,11 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) {
...
@@ -1467,10 +1516,11 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) {
sizeof
(
SSubmitBlk
),
getTableInfo
(
pCxt
->
pTableMeta
).
rowSize
,
pCxt
->
pTableMeta
,
sizeof
(
SSubmitBlk
),
getTableInfo
(
pCxt
->
pTableMeta
).
rowSize
,
pCxt
->
pTableMeta
,
&
dataBuf
,
NULL
,
&
pCxt
->
createTblReq
));
&
dataBuf
,
NULL
,
&
pCxt
->
createTblReq
));
if
(
TK_NK_LP
==
sToken
.
type
)
{
if
(
NULL
!=
pBoundColsStart
)
{
// pSql -> field1_name, ...)
char
*
pCurrPos
=
pCxt
->
pSql
;
pCxt
->
pSql
=
pBoundColsStart
;
CHECK_CODE
(
parseBoundColumns
(
pCxt
,
&
dataBuf
->
boundColumnInfo
,
getTableColumnSchema
(
pCxt
->
pTableMeta
)));
CHECK_CODE
(
parseBoundColumns
(
pCxt
,
&
dataBuf
->
boundColumnInfo
,
getTableColumnSchema
(
pCxt
->
pTableMeta
)));
NEXT_TOKEN
(
pCxt
->
pSql
,
sToken
)
;
pCxt
->
pSql
=
pCurrPos
;
}
}
if
(
TK_VALUES
==
sToken
.
type
)
{
if
(
TK_VALUES
==
sToken
.
type
)
{
...
@@ -1610,25 +1660,6 @@ int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery, SParseMetaCache
...
@@ -1610,25 +1660,6 @@ int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery, SParseMetaCache
return
code
;
return
code
;
}
}
static
int32_t
skipParentheses
(
SInsertParseSyntaxCxt
*
pCxt
)
{
SToken
sToken
;
int32_t
expectRightParenthesis
=
1
;
while
(
1
)
{
NEXT_TOKEN
(
pCxt
->
pSql
,
sToken
);
if
(
TK_NK_LP
==
sToken
.
type
)
{
++
expectRightParenthesis
;
}
else
if
(
TK_NK_RP
==
sToken
.
type
&&
0
==
--
expectRightParenthesis
)
{
break
;
}
if
(
0
==
sToken
.
n
)
{
return
buildSyntaxErrMsg
(
&
pCxt
->
msg
,
") expected"
,
NULL
);
}
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
skipBoundColumns
(
SInsertParseSyntaxCxt
*
pCxt
)
{
return
skipParentheses
(
pCxt
);
}
// pSql -> (field1_value, ...) [(field1_value2, ...) ...]
// pSql -> (field1_value, ...) [(field1_value2, ...) ...]
static
int32_t
skipValuesClause
(
SInsertParseSyntaxCxt
*
pCxt
)
{
static
int32_t
skipValuesClause
(
SInsertParseSyntaxCxt
*
pCxt
)
{
int32_t
numOfRows
=
0
;
int32_t
numOfRows
=
0
;
...
@@ -1717,15 +1748,15 @@ static int32_t parseInsertBodySyntax(SInsertParseSyntaxCxt* pCxt) {
...
@@ -1717,15 +1748,15 @@ static int32_t parseInsertBodySyntax(SInsertParseSyntaxCxt* pCxt) {
SToken
tbnameToken
=
sToken
;
SToken
tbnameToken
=
sToken
;
NEXT_TOKEN
(
pCxt
->
pSql
,
sToken
);
NEXT_TOKEN
(
pCxt
->
pSql
,
sToken
);
bool
existedUsing
=
false
;
// USING clause
// USING clause
if
(
TK_USING
==
sToken
.
type
)
{
if
(
TK_USING
==
sToken
.
type
)
{
existedUsing
=
true
;
CHECK_CODE
(
collectAutoCreateTableMetaKey
(
pCxt
,
&
tbnameToken
));
CHECK_CODE
(
collectAutoCreateTableMetaKey
(
pCxt
,
&
tbnameToken
));
NEXT_TOKEN
(
pCxt
->
pSql
,
sToken
);
NEXT_TOKEN
(
pCxt
->
pSql
,
sToken
);
CHECK_CODE
(
collectTableMetaKey
(
pCxt
,
&
sToken
));
CHECK_CODE
(
collectTableMetaKey
(
pCxt
,
&
sToken
));
CHECK_CODE
(
skipUsingClause
(
pCxt
));
CHECK_CODE
(
skipUsingClause
(
pCxt
));
NEXT_TOKEN
(
pCxt
->
pSql
,
sToken
);
NEXT_TOKEN
(
pCxt
->
pSql
,
sToken
);
}
else
{
CHECK_CODE
(
collectTableMetaKey
(
pCxt
,
&
tbnameToken
));
}
}
if
(
TK_NK_LP
==
sToken
.
type
)
{
if
(
TK_NK_LP
==
sToken
.
type
)
{
...
@@ -1734,6 +1765,17 @@ static int32_t parseInsertBodySyntax(SInsertParseSyntaxCxt* pCxt) {
...
@@ -1734,6 +1765,17 @@ static int32_t parseInsertBodySyntax(SInsertParseSyntaxCxt* pCxt) {
NEXT_TOKEN
(
pCxt
->
pSql
,
sToken
);
NEXT_TOKEN
(
pCxt
->
pSql
,
sToken
);
}
}
if
(
TK_USING
==
sToken
.
type
&&
!
existedUsing
)
{
existedUsing
=
true
;
CHECK_CODE
(
collectAutoCreateTableMetaKey
(
pCxt
,
&
tbnameToken
));
NEXT_TOKEN
(
pCxt
->
pSql
,
sToken
);
CHECK_CODE
(
collectTableMetaKey
(
pCxt
,
&
sToken
));
CHECK_CODE
(
skipUsingClause
(
pCxt
));
NEXT_TOKEN
(
pCxt
->
pSql
,
sToken
);
}
else
{
CHECK_CODE
(
collectTableMetaKey
(
pCxt
,
&
tbnameToken
));
}
if
(
TK_VALUES
==
sToken
.
type
)
{
if
(
TK_VALUES
==
sToken
.
type
)
{
// pSql -> (field1_value, ...) [(field1_value2, ...) ...]
// pSql -> (field1_value, ...) [(field1_value2, ...) ...]
CHECK_CODE
(
skipValuesClause
(
pCxt
));
CHECK_CODE
(
skipValuesClause
(
pCxt
));
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
source/libs/parser/src/parUtil.c
浏览文件 @
3b50fee6
...
@@ -215,13 +215,21 @@ int32_t generateSyntaxErrMsg(SMsgBuf* pBuf, int32_t errCode, ...) {
...
@@ -215,13 +215,21 @@ int32_t generateSyntaxErrMsg(SMsgBuf* pBuf, int32_t errCode, ...) {
return
errCode
;
return
errCode
;
}
}
int32_t
generateSyntaxErrMsgExt
(
SMsgBuf
*
pBuf
,
int32_t
errCode
,
const
char
*
pFormat
,
...)
{
va_list
vArgList
;
va_start
(
vArgList
,
pFormat
);
vsnprintf
(
pBuf
->
buf
,
pBuf
->
len
,
pFormat
,
vArgList
);
va_end
(
vArgList
);
return
errCode
;
}
int32_t
buildInvalidOperationMsg
(
SMsgBuf
*
pBuf
,
const
char
*
msg
)
{
int32_t
buildInvalidOperationMsg
(
SMsgBuf
*
pBuf
,
const
char
*
msg
)
{
strncpy
(
pBuf
->
buf
,
msg
,
pBuf
->
len
);
strncpy
(
pBuf
->
buf
,
msg
,
pBuf
->
len
);
return
TSDB_CODE_TSC_INVALID_OPERATION
;
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
int32_t
buildSyntaxErrMsg
(
SMsgBuf
*
pBuf
,
const
char
*
additionalInfo
,
const
char
*
sourceStr
)
{
int32_t
buildSyntaxErrMsg
(
SMsgBuf
*
pBuf
,
const
char
*
additionalInfo
,
const
char
*
sourceStr
)
{
if
(
pBuf
==
NULL
)
return
TSDB_CODE_TSC_SQL_SYNTAX_ERROR
;
if
(
pBuf
==
NULL
)
return
TSDB_CODE_TSC_SQL_SYNTAX_ERROR
;
const
char
*
msgFormat1
=
"syntax error near
\'
%s
\'
"
;
const
char
*
msgFormat1
=
"syntax error near
\'
%s
\'
"
;
const
char
*
msgFormat2
=
"syntax error near
\'
%s
\'
(%s)"
;
const
char
*
msgFormat2
=
"syntax error near
\'
%s
\'
(%s)"
;
const
char
*
msgFormat3
=
"%s"
;
const
char
*
msgFormat3
=
"%s"
;
...
...
source/libs/parser/src/sql.c
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
source/libs/parser/test/parInitialATest.cpp
浏览文件 @
3b50fee6
...
@@ -77,8 +77,6 @@ TEST_F(ParserInitialATest, alterLocal) {
...
@@ -77,8 +77,6 @@ TEST_F(ParserInitialATest, alterLocal) {
clearAlterLocal
();
clearAlterLocal
();
}
}
// todo ALTER stable
/*
/*
* ALTER TABLE [db_name.]tb_name alter_table_clause
* ALTER TABLE [db_name.]tb_name alter_table_clause
*
*
...
@@ -157,7 +155,7 @@ TEST_F(ParserInitialATest, alterSTable) {
...
@@ -157,7 +155,7 @@ TEST_F(ParserInitialATest, alterSTable) {
};
};
setCheckDdlFunc
([
&
](
const
SQuery
*
pQuery
,
ParserStage
stage
)
{
setCheckDdlFunc
([
&
](
const
SQuery
*
pQuery
,
ParserStage
stage
)
{
ASSERT_EQ
(
nodeType
(
pQuery
->
pRoot
),
QUERY_NODE_ALTER_TABLE_STMT
);
ASSERT_EQ
(
nodeType
(
pQuery
->
pRoot
),
QUERY_NODE_ALTER_
SUPER_
TABLE_STMT
);
SMAlterStbReq
req
=
{
0
};
SMAlterStbReq
req
=
{
0
};
ASSERT_EQ
(
tDeserializeSMAlterStbReq
(
pQuery
->
pCmdMsg
->
pMsg
,
pQuery
->
pCmdMsg
->
msgLen
,
&
req
),
TSDB_CODE_SUCCESS
);
ASSERT_EQ
(
tDeserializeSMAlterStbReq
(
pQuery
->
pCmdMsg
->
pMsg
,
pQuery
->
pCmdMsg
->
msgLen
,
&
req
),
TSDB_CODE_SUCCESS
);
ASSERT_EQ
(
std
::
string
(
req
.
name
),
std
::
string
(
expect
.
name
));
ASSERT_EQ
(
std
::
string
(
req
.
name
),
std
::
string
(
expect
.
name
));
...
@@ -181,44 +179,44 @@ TEST_F(ParserInitialATest, alterSTable) {
...
@@ -181,44 +179,44 @@ TEST_F(ParserInitialATest, alterSTable) {
});
});
// setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_OPTIONS, 0, nullptr, 0, 0, nullptr, nullptr, 10);
// setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_OPTIONS, 0, nullptr, 0, 0, nullptr, nullptr, 10);
// run("ALTER TABLE st1 TTL 10");
// run("ALTER
S
TABLE st1 TTL 10");
// clearAlterStbReq();
// clearAlterStbReq();
setAlterStbReqFunc
(
"st1"
,
TSDB_ALTER_TABLE_UPDATE_OPTIONS
,
0
,
nullptr
,
0
,
0
,
nullptr
,
"test"
);
setAlterStbReqFunc
(
"st1"
,
TSDB_ALTER_TABLE_UPDATE_OPTIONS
,
0
,
nullptr
,
0
,
0
,
nullptr
,
"test"
);
run
(
"ALTER TABLE st1 COMMENT 'test'"
);
run
(
"ALTER
S
TABLE st1 COMMENT 'test'"
);
clearAlterStbReq
();
clearAlterStbReq
();
setAlterStbReqFunc
(
"st1"
,
TSDB_ALTER_TABLE_ADD_COLUMN
,
1
,
"cc1"
,
TSDB_DATA_TYPE_BIGINT
);
setAlterStbReqFunc
(
"st1"
,
TSDB_ALTER_TABLE_ADD_COLUMN
,
1
,
"cc1"
,
TSDB_DATA_TYPE_BIGINT
);
run
(
"ALTER TABLE st1 ADD COLUMN cc1 BIGINT"
);
run
(
"ALTER
S
TABLE st1 ADD COLUMN cc1 BIGINT"
);
clearAlterStbReq
();
clearAlterStbReq
();
setAlterStbReqFunc
(
"st1"
,
TSDB_ALTER_TABLE_DROP_COLUMN
,
1
,
"c1"
);
setAlterStbReqFunc
(
"st1"
,
TSDB_ALTER_TABLE_DROP_COLUMN
,
1
,
"c1"
);
run
(
"ALTER TABLE st1 DROP COLUMN c1"
);
run
(
"ALTER
S
TABLE st1 DROP COLUMN c1"
);
clearAlterStbReq
();
clearAlterStbReq
();
setAlterStbReqFunc
(
"st1"
,
TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
,
1
,
"c2"
,
TSDB_DATA_TYPE_VARCHAR
,
setAlterStbReqFunc
(
"st1"
,
TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
,
1
,
"c2"
,
TSDB_DATA_TYPE_VARCHAR
,
30
+
VARSTR_HEADER_SIZE
);
30
+
VARSTR_HEADER_SIZE
);
run
(
"ALTER TABLE st1 MODIFY COLUMN c2 VARCHAR(30)"
);
run
(
"ALTER
S
TABLE st1 MODIFY COLUMN c2 VARCHAR(30)"
);
clearAlterStbReq
();
clearAlterStbReq
();
// setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, 2, "c1", 0, 0, "cc1");
// setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, 2, "c1", 0, 0, "cc1");
// run("ALTER TABLE st1 RENAME COLUMN c1 cc1");
// run("ALTER
S
TABLE st1 RENAME COLUMN c1 cc1");
setAlterStbReqFunc
(
"st1"
,
TSDB_ALTER_TABLE_ADD_TAG
,
1
,
"tag11"
,
TSDB_DATA_TYPE_BIGINT
);
setAlterStbReqFunc
(
"st1"
,
TSDB_ALTER_TABLE_ADD_TAG
,
1
,
"tag11"
,
TSDB_DATA_TYPE_BIGINT
);
run
(
"ALTER TABLE st1 ADD TAG tag11 BIGINT"
);
run
(
"ALTER
S
TABLE st1 ADD TAG tag11 BIGINT"
);
clearAlterStbReq
();
clearAlterStbReq
();
setAlterStbReqFunc
(
"st1"
,
TSDB_ALTER_TABLE_DROP_TAG
,
1
,
"tag1"
);
setAlterStbReqFunc
(
"st1"
,
TSDB_ALTER_TABLE_DROP_TAG
,
1
,
"tag1"
);
run
(
"ALTER TABLE st1 DROP TAG tag1"
);
run
(
"ALTER
S
TABLE st1 DROP TAG tag1"
);
clearAlterStbReq
();
clearAlterStbReq
();
setAlterStbReqFunc
(
"st1"
,
TSDB_ALTER_TABLE_UPDATE_TAG_BYTES
,
1
,
"tag2"
,
TSDB_DATA_TYPE_VARCHAR
,
setAlterStbReqFunc
(
"st1"
,
TSDB_ALTER_TABLE_UPDATE_TAG_BYTES
,
1
,
"tag2"
,
TSDB_DATA_TYPE_VARCHAR
,
30
+
VARSTR_HEADER_SIZE
);
30
+
VARSTR_HEADER_SIZE
);
run
(
"ALTER TABLE st1 MODIFY TAG tag2 VARCHAR(30)"
);
run
(
"ALTER
S
TABLE st1 MODIFY TAG tag2 VARCHAR(30)"
);
clearAlterStbReq
();
clearAlterStbReq
();
setAlterStbReqFunc
(
"st1"
,
TSDB_ALTER_TABLE_UPDATE_TAG_NAME
,
2
,
"tag1"
,
0
,
0
,
"tag11"
);
setAlterStbReqFunc
(
"st1"
,
TSDB_ALTER_TABLE_UPDATE_TAG_NAME
,
2
,
"tag1"
,
0
,
0
,
"tag11"
);
run
(
"ALTER TABLE st1 RENAME TAG tag1 tag11"
);
run
(
"ALTER
S
TABLE st1 RENAME TAG tag1 tag11"
);
clearAlterStbReq
();
clearAlterStbReq
();
// todo
// todo
...
@@ -228,11 +226,11 @@ TEST_F(ParserInitialATest, alterSTable) {
...
@@ -228,11 +226,11 @@ TEST_F(ParserInitialATest, alterSTable) {
TEST_F
(
ParserInitialATest
,
alterSTableSemanticCheck
)
{
TEST_F
(
ParserInitialATest
,
alterSTableSemanticCheck
)
{
useDb
(
"root"
,
"test"
);
useDb
(
"root"
,
"test"
);
run
(
"ALTER TABLE st1 RENAME COLUMN c1 cc1"
,
TSDB_CODE_PAR_INVALID_ALTER_TABLE
);
run
(
"ALTER
S
TABLE st1 RENAME COLUMN c1 cc1"
,
TSDB_CODE_PAR_INVALID_ALTER_TABLE
);
run
(
"ALTER TABLE st1 MODIFY COLUMN c2 NCHAR(10)"
,
TSDB_CODE_PAR_INVALID_MODIFY_COL
);
run
(
"ALTER
S
TABLE st1 MODIFY COLUMN c2 NCHAR(10)"
,
TSDB_CODE_PAR_INVALID_MODIFY_COL
);
run
(
"ALTER TABLE st1 MODIFY TAG tag2 NCHAR(10)"
,
TSDB_CODE_PAR_INVALID_MODIFY_COL
);
run
(
"ALTER
S
TABLE st1 MODIFY TAG tag2 NCHAR(10)"
,
TSDB_CODE_PAR_INVALID_MODIFY_COL
);
}
}
TEST_F
(
ParserInitialATest
,
alterTable
)
{
TEST_F
(
ParserInitialATest
,
alterTable
)
{
...
...
source/libs/planner/src/planOptimizer.c
浏览文件 @
3b50fee6
...
@@ -720,7 +720,7 @@ static int32_t pushDownCondOptDealAgg(SOptimizeContext* pCxt, SAggLogicNode* pAg
...
@@ -720,7 +720,7 @@ static int32_t pushDownCondOptDealAgg(SOptimizeContext* pCxt, SAggLogicNode* pAg
// TODO: remove it after full implementation of pushing down to child
// TODO: remove it after full implementation of pushing down to child
if
(
1
!=
LIST_LENGTH
(
pAgg
->
node
.
pChildren
)
||
if
(
1
!=
LIST_LENGTH
(
pAgg
->
node
.
pChildren
)
||
QUERY_NODE_LOGIC_PLAN_SCAN
!=
nodeType
(
nodesListGetNode
(
pAgg
->
node
.
pChildren
,
0
))
&&
QUERY_NODE_LOGIC_PLAN_SCAN
!=
nodeType
(
nodesListGetNode
(
pAgg
->
node
.
pChildren
,
0
))
&&
QUERY_NODE_LOGIC_PLAN_PROJECT
!=
nodeType
(
nodesListGetNode
(
pAgg
->
node
.
pChildren
,
0
)))
{
QUERY_NODE_LOGIC_PLAN_PROJECT
!=
nodeType
(
nodesListGetNode
(
pAgg
->
node
.
pChildren
,
0
)))
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -1251,7 +1251,7 @@ static SNode* partTagsCreateWrapperFunc(const char* pFuncName, SNode* pNode) {
...
@@ -1251,7 +1251,7 @@ static SNode* partTagsCreateWrapperFunc(const char* pFuncName, SNode* pNode) {
}
}
strcpy
(
pFunc
->
functionName
,
pFuncName
);
strcpy
(
pFunc
->
functionName
,
pFuncName
);
if
(
QUERY_NODE_COLUMN
==
nodeType
(
pNode
))
{
if
(
QUERY_NODE_COLUMN
==
nodeType
(
pNode
)
&&
COLUMN_TYPE_TBNAME
!=
((
SColumnNode
*
)
pNode
)
->
colType
)
{
SColumnNode
*
pCol
=
(
SColumnNode
*
)
pNode
;
SColumnNode
*
pCol
=
(
SColumnNode
*
)
pNode
;
partTagsSetAlias
(
pFunc
->
node
.
aliasName
,
sizeof
(
pFunc
->
node
.
aliasName
),
pCol
->
tableAlias
,
pCol
->
colName
);
partTagsSetAlias
(
pFunc
->
node
.
aliasName
,
sizeof
(
pFunc
->
node
.
aliasName
),
pCol
->
tableAlias
,
pCol
->
colName
);
}
else
{
}
else
{
...
@@ -1868,6 +1868,8 @@ static EDealRes mergeProjectionsExpr(SNode** pNode, void* pContext) {
...
@@ -1868,6 +1868,8 @@ static EDealRes mergeProjectionsExpr(SNode** pNode, void* pContext) {
pCxt
->
errCode
=
terrno
;
pCxt
->
errCode
=
terrno
;
return
DEAL_RES_ERROR
;
return
DEAL_RES_ERROR
;
}
}
snprintf
(((
SExprNode
*
)
pExpr
)
->
aliasName
,
sizeof
(((
SExprNode
*
)
pExpr
)
->
aliasName
),
"%s"
,
((
SExprNode
*
)
*
pNode
)
->
aliasName
);
nodesDestroyNode
(
*
pNode
);
nodesDestroyNode
(
*
pNode
);
*
pNode
=
pExpr
;
*
pNode
=
pExpr
;
}
}
...
...
source/libs/planner/src/planSpliter.c
浏览文件 @
3b50fee6
...
@@ -986,6 +986,10 @@ static bool unionIsChildSubplan(SLogicNode* pLogicNode, int32_t groupId) {
...
@@ -986,6 +986,10 @@ static bool unionIsChildSubplan(SLogicNode* pLogicNode, int32_t groupId) {
return
((
SExchangeLogicNode
*
)
pLogicNode
)
->
srcGroupId
==
groupId
;
return
((
SExchangeLogicNode
*
)
pLogicNode
)
->
srcGroupId
==
groupId
;
}
}
if
(
QUERY_NODE_LOGIC_PLAN_MERGE
==
nodeType
(
pLogicNode
))
{
return
((
SMergeLogicNode
*
)
pLogicNode
)
->
srcGroupId
==
groupId
;
}
SNode
*
pChild
;
SNode
*
pChild
;
FOREACH
(
pChild
,
pLogicNode
->
pChildren
)
{
FOREACH
(
pChild
,
pLogicNode
->
pChildren
)
{
bool
isChild
=
unionIsChildSubplan
((
SLogicNode
*
)
pChild
,
groupId
);
bool
isChild
=
unionIsChildSubplan
((
SLogicNode
*
)
pChild
,
groupId
);
...
...
source/libs/planner/test/planOptimizeTest.cpp
浏览文件 @
3b50fee6
...
@@ -68,6 +68,8 @@ TEST_F(PlanOptimizeTest, PartitionTags) {
...
@@ -68,6 +68,8 @@ TEST_F(PlanOptimizeTest, PartitionTags) {
run
(
"SELECT SUM(c1), tag1 FROM st1 GROUP BY tag1"
);
run
(
"SELECT SUM(c1), tag1 FROM st1 GROUP BY tag1"
);
run
(
"SELECT SUM(c1), tag1 + 10 FROM st1 GROUP BY tag1 + 10"
);
run
(
"SELECT SUM(c1), tag1 + 10 FROM st1 GROUP BY tag1 + 10"
);
run
(
"SELECT SUM(c1), tbname FROM st1 GROUP BY tbname"
);
}
}
TEST_F
(
PlanOptimizeTest
,
eliminateProjection
)
{
TEST_F
(
PlanOptimizeTest
,
eliminateProjection
)
{
...
...
source/libs/planner/test/planSetOpTest.cpp
浏览文件 @
3b50fee6
...
@@ -97,7 +97,15 @@ TEST_F(PlanSetOpTest, unionSubquery) {
...
@@ -97,7 +97,15 @@ TEST_F(PlanSetOpTest, unionSubquery) {
run
(
"SELECT * FROM (SELECT c1, c2 FROM t1 UNION SELECT c1, c2 FROM t1)"
);
run
(
"SELECT * FROM (SELECT c1, c2 FROM t1 UNION SELECT c1, c2 FROM t1)"
);
}
}
TEST_F
(
PlanSetOpTest
,
bug001
)
{
TEST_F
(
PlanSetOpTest
,
unionWithSubquery
)
{
useDb
(
"root"
,
"test"
);
run
(
"SELECT c1 FROM (SELECT c1 FROM st1) UNION SELECT c2 FROM (SELECT c1 AS c2 FROM st2)"
);
run
(
"SELECT c1 FROM (SELECT c1 FROM st1 ORDER BY c2) UNION SELECT c1 FROM (SELECT c1 FROM st2)"
);
}
TEST_F
(
PlanSetOpTest
,
unionDataTypeConversion
)
{
useDb
(
"root"
,
"test"
);
useDb
(
"root"
,
"test"
);
run
(
"SELECT c2 FROM t1 WHERE c1 IS NOT NULL GROUP BY c2 "
run
(
"SELECT c2 FROM t1 WHERE c1 IS NOT NULL GROUP BY c2 "
...
...
source/libs/scalar/src/sclfunc.c
浏览文件 @
3b50fee6
...
@@ -360,9 +360,6 @@ static void trtrim(char *input, char *output, int32_t type, int32_t charLen) {
...
@@ -360,9 +360,6 @@ static void trtrim(char *input, char *output, int32_t type, int32_t charLen) {
static
int32_t
doLengthFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
,
_len_fn
lenFn
)
{
static
int32_t
doLengthFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
,
_len_fn
lenFn
)
{
int32_t
type
=
GET_PARAM_TYPE
(
pInput
);
int32_t
type
=
GET_PARAM_TYPE
(
pInput
);
if
(
inputNum
!=
1
||
!
IS_VAR_DATA_TYPE
(
type
))
{
return
TSDB_CODE_FAILED
;
}
SColumnInfoData
*
pInputData
=
pInput
->
columnData
;
SColumnInfoData
*
pInputData
=
pInput
->
columnData
;
SColumnInfoData
*
pOutputData
=
pOutput
->
columnData
;
SColumnInfoData
*
pOutputData
=
pOutput
->
columnData
;
...
@@ -586,9 +583,6 @@ DONE:
...
@@ -586,9 +583,6 @@ DONE:
static
int32_t
doCaseConvFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
,
_conv_fn
convFn
)
{
static
int32_t
doCaseConvFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
,
_conv_fn
convFn
)
{
int32_t
type
=
GET_PARAM_TYPE
(
pInput
);
int32_t
type
=
GET_PARAM_TYPE
(
pInput
);
if
(
inputNum
!=
1
||
!
IS_VAR_DATA_TYPE
(
type
))
{
return
TSDB_CODE_FAILED
;
}
SColumnInfoData
*
pInputData
=
pInput
->
columnData
;
SColumnInfoData
*
pInputData
=
pInput
->
columnData
;
SColumnInfoData
*
pOutputData
=
pOutput
->
columnData
;
SColumnInfoData
*
pOutputData
=
pOutput
->
columnData
;
...
@@ -628,9 +622,6 @@ static int32_t doCaseConvFunction(SScalarParam *pInput, int32_t inputNum, SScala
...
@@ -628,9 +622,6 @@ static int32_t doCaseConvFunction(SScalarParam *pInput, int32_t inputNum, SScala
static
int32_t
doTrimFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
,
_trim_fn
trimFn
)
{
static
int32_t
doTrimFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
,
_trim_fn
trimFn
)
{
int32_t
type
=
GET_PARAM_TYPE
(
pInput
);
int32_t
type
=
GET_PARAM_TYPE
(
pInput
);
if
(
inputNum
!=
1
||
!
IS_VAR_DATA_TYPE
(
type
))
{
return
TSDB_CODE_FAILED
;
}
SColumnInfoData
*
pInputData
=
pInput
->
columnData
;
SColumnInfoData
*
pInputData
=
pInput
->
columnData
;
SColumnInfoData
*
pOutputData
=
pOutput
->
columnData
;
SColumnInfoData
*
pOutputData
=
pOutput
->
columnData
;
...
@@ -664,16 +655,10 @@ static int32_t doTrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarPar
...
@@ -664,16 +655,10 @@ static int32_t doTrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarPar
int32_t
substrFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
int32_t
substrFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
int32_t
subPos
=
0
;
int32_t
subPos
=
0
;
GET_TYPED_DATA
(
subPos
,
int32_t
,
GET_PARAM_TYPE
(
&
pInput
[
1
]),
pInput
[
1
].
columnData
->
pData
);
GET_TYPED_DATA
(
subPos
,
int32_t
,
GET_PARAM_TYPE
(
&
pInput
[
1
]),
pInput
[
1
].
columnData
->
pData
);
if
(
subPos
==
0
)
{
//subPos needs to be positive or negative values;
return
TSDB_CODE_FAILED
;
}
int32_t
subLen
=
INT16_MAX
;
int32_t
subLen
=
INT16_MAX
;
if
(
inputNum
==
3
)
{
if
(
inputNum
==
3
)
{
GET_TYPED_DATA
(
subLen
,
int32_t
,
GET_PARAM_TYPE
(
&
pInput
[
2
]),
pInput
[
2
].
columnData
->
pData
);
GET_TYPED_DATA
(
subLen
,
int32_t
,
GET_PARAM_TYPE
(
&
pInput
[
2
]),
pInput
[
2
].
columnData
->
pData
);
if
(
subLen
<
0
||
subLen
>
INT16_MAX
)
{
//subLen cannot be negative
return
TSDB_CODE_FAILED
;
}
subLen
=
(
GET_PARAM_TYPE
(
pInput
)
==
TSDB_DATA_TYPE_VARCHAR
)
?
subLen
:
subLen
*
TSDB_NCHAR_SIZE
;
subLen
=
(
GET_PARAM_TYPE
(
pInput
)
==
TSDB_DATA_TYPE_VARCHAR
)
?
subLen
:
subLen
*
TSDB_NCHAR_SIZE
;
}
}
...
@@ -1149,13 +1134,6 @@ int32_t toUnixtimestampFunction(SScalarParam *pInput, int32_t inputNum, SScalarP
...
@@ -1149,13 +1134,6 @@ int32_t toUnixtimestampFunction(SScalarParam *pInput, int32_t inputNum, SScalarP
int32_t
toJsonFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
int32_t
toJsonFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
int32_t
type
=
GET_PARAM_TYPE
(
pInput
);
int32_t
type
=
GET_PARAM_TYPE
(
pInput
);
if
(
type
!=
TSDB_DATA_TYPE_BINARY
&&
type
!=
TSDB_DATA_TYPE_NCHAR
)
{
return
TSDB_CODE_FAILED
;
}
if
(
inputNum
!=
1
)
{
return
TSDB_CODE_FAILED
;
}
char
tmp
[
TSDB_MAX_JSON_TAG_LEN
]
=
{
0
};
char
tmp
[
TSDB_MAX_JSON_TAG_LEN
]
=
{
0
};
for
(
int32_t
i
=
0
;
i
<
pInput
[
0
].
numOfRows
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pInput
[
0
].
numOfRows
;
++
i
)
{
...
@@ -1196,6 +1174,8 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
...
@@ -1196,6 +1174,8 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
int64_t
factor
=
(
timePrec
==
TSDB_TIME_PRECISION_MILLI
)
?
1000
:
int64_t
factor
=
(
timePrec
==
TSDB_TIME_PRECISION_MILLI
)
?
1000
:
(
timePrec
==
TSDB_TIME_PRECISION_MICRO
?
1000000
:
1000000000
);
(
timePrec
==
TSDB_TIME_PRECISION_MICRO
?
1000000
:
1000000000
);
timeUnit
=
timeUnit
*
1000
/
factor
;
for
(
int32_t
i
=
0
;
i
<
pInput
[
0
].
numOfRows
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pInput
[
0
].
numOfRows
;
++
i
)
{
if
(
colDataIsNull_s
(
pInput
[
0
].
columnData
,
i
))
{
if
(
colDataIsNull_s
(
pInput
[
0
].
columnData
,
i
))
{
colDataAppendNULL
(
pOutput
->
columnData
,
i
);
colDataAppendNULL
(
pOutput
->
columnData
,
i
);
...
@@ -1228,7 +1208,6 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
...
@@ -1228,7 +1208,6 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
char
buf
[
20
]
=
{
0
};
char
buf
[
20
]
=
{
0
};
NUM_TO_STRING
(
TSDB_DATA_TYPE_BIGINT
,
&
timeVal
,
sizeof
(
buf
),
buf
);
NUM_TO_STRING
(
TSDB_DATA_TYPE_BIGINT
,
&
timeVal
,
sizeof
(
buf
),
buf
);
int32_t
tsDigits
=
(
int32_t
)
strlen
(
buf
);
int32_t
tsDigits
=
(
int32_t
)
strlen
(
buf
);
timeUnit
=
timeUnit
*
1000
/
factor
;
switch
(
timeUnit
)
{
switch
(
timeUnit
)
{
case
0
:
{
/* 1u */
case
0
:
{
/* 1u */
...
@@ -1384,6 +1363,11 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
...
@@ -1384,6 +1363,11 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
GET_TYPED_DATA
(
timePrec
,
int64_t
,
GET_PARAM_TYPE
(
&
pInput
[
2
]),
pInput
[
2
].
columnData
->
pData
);
GET_TYPED_DATA
(
timePrec
,
int64_t
,
GET_PARAM_TYPE
(
&
pInput
[
2
]),
pInput
[
2
].
columnData
->
pData
);
}
}
int64_t
factor
=
(
timePrec
==
TSDB_TIME_PRECISION_MILLI
)
?
1000
:
(
timePrec
==
TSDB_TIME_PRECISION_MICRO
?
1000000
:
1000000000
);
timeUnit
=
timeUnit
*
1000
/
factor
;
int32_t
numOfRows
=
0
;
int32_t
numOfRows
=
0
;
for
(
int32_t
i
=
0
;
i
<
inputNum
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
inputNum
;
++
i
)
{
if
(
pInput
[
i
].
numOfRows
>
numOfRows
)
{
if
(
pInput
[
i
].
numOfRows
>
numOfRows
)
{
...
@@ -1463,9 +1447,6 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
...
@@ -1463,9 +1447,6 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
}
}
}
}
}
else
{
}
else
{
int64_t
factor
=
(
timePrec
==
TSDB_TIME_PRECISION_MILLI
)
?
1000
:
(
timePrec
==
TSDB_TIME_PRECISION_MICRO
?
1000000
:
1000000000
);
timeUnit
=
timeUnit
*
1000
/
factor
;
switch
(
timeUnit
)
{
switch
(
timeUnit
)
{
case
0
:
{
/* 1u */
case
0
:
{
/* 1u */
result
=
result
/
1000
;
result
=
result
/
1000
;
...
...
source/libs/sync/inc/syncAppendEntriesReply.h
浏览文件 @
3b50fee6
...
@@ -44,11 +44,6 @@ int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* p
...
@@ -44,11 +44,6 @@ int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* p
int32_t
syncNodeOnAppendEntriesReplySnapshotCb
(
SSyncNode
*
ths
,
SyncAppendEntriesReply
*
pMsg
);
int32_t
syncNodeOnAppendEntriesReplySnapshotCb
(
SSyncNode
*
ths
,
SyncAppendEntriesReply
*
pMsg
);
int32_t
syncNodeOnAppendEntriesReplySnapshot2Cb
(
SSyncNode
*
ths
,
SyncAppendEntriesReply
*
pMsg
);
int32_t
syncNodeOnAppendEntriesReplySnapshot2Cb
(
SSyncNode
*
ths
,
SyncAppendEntriesReply
*
pMsg
);
typedef
struct
SReaderParam
{
SyncIndex
start
;
SyncIndex
end
;
}
SReaderParam
;
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
source/libs/sync/inc/syncInt.h
浏览文件 @
3b50fee6
...
@@ -174,8 +174,9 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak);
...
@@ -174,8 +174,9 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak);
int32_t
syncNodeProposeBatch
(
SSyncNode
*
pSyncNode
,
SRpcMsg
*
pMsgArr
,
bool
*
pIsWeakArr
,
int32_t
arrSize
);
int32_t
syncNodeProposeBatch
(
SSyncNode
*
pSyncNode
,
SRpcMsg
*
pMsgArr
,
bool
*
pIsWeakArr
,
int32_t
arrSize
);
// option
// option
bool
syncNodeSnapshotEnable
(
SSyncNode
*
pSyncNode
);
bool
syncNodeSnapshotEnable
(
SSyncNode
*
pSyncNode
);
SyncIndex
syncNodeGetSnapshotConfigIndex
(
SSyncNode
*
pSyncNode
,
SyncIndex
snapshotLastApplyIndex
);
ESyncStrategy
syncNodeStrategy
(
SSyncNode
*
pSyncNode
);
SyncIndex
syncNodeGetSnapshotConfigIndex
(
SSyncNode
*
pSyncNode
,
SyncIndex
snapshotLastApplyIndex
);
// ping --------------
// ping --------------
int32_t
syncNodePing
(
SSyncNode
*
pSyncNode
,
const
SRaftId
*
destRaftId
,
SyncPing
*
pMsg
);
int32_t
syncNodePing
(
SSyncNode
*
pSyncNode
,
const
SRaftId
*
destRaftId
,
SyncPing
*
pMsg
);
...
...
source/libs/sync/inc/syncRaftEntry.h
浏览文件 @
3b50fee6
...
@@ -29,19 +29,20 @@ extern "C" {
...
@@ -29,19 +29,20 @@ extern "C" {
typedef
struct
SSyncRaftEntry
{
typedef
struct
SSyncRaftEntry
{
uint32_t
bytes
;
uint32_t
bytes
;
uint32_t
msgType
;
//
SyncClientRequest msgType
uint32_t
msgType
;
//
TDMT_SYNC_CLIENT_REQUEST
uint32_t
originalRpcType
;
//
user
RpcMsg msgType
uint32_t
originalRpcType
;
//
origin
RpcMsg msgType
uint64_t
seqNum
;
uint64_t
seqNum
;
bool
isWeak
;
bool
isWeak
;
SyncTerm
term
;
SyncTerm
term
;
SyncIndex
index
;
SyncIndex
index
;
uint32_t
dataLen
;
//
user
RpcMsg.contLen
uint32_t
dataLen
;
//
origin
RpcMsg.contLen
char
data
[];
//
user
RpcMsg.pCont
char
data
[];
//
origin
RpcMsg.pCont
}
SSyncRaftEntry
;
}
SSyncRaftEntry
;
SSyncRaftEntry
*
syncEntryBuild
(
uint32_t
dataLen
);
SSyncRaftEntry
*
syncEntryBuild
(
uint32_t
dataLen
);
SSyncRaftEntry
*
syncEntryBuild2
(
SyncClientRequest
*
pMsg
,
SyncTerm
term
,
SyncIndex
index
);
// step 4
SSyncRaftEntry
*
syncEntryBuild2
(
SyncClientRequest
*
pMsg
,
SyncTerm
term
,
SyncIndex
index
);
// step 4
SSyncRaftEntry
*
syncEntryBuild3
(
SyncClientRequest
*
pMsg
,
SyncTerm
term
,
SyncIndex
index
);
SSyncRaftEntry
*
syncEntryBuild3
(
SyncClientRequest
*
pMsg
,
SyncTerm
term
,
SyncIndex
index
);
SSyncRaftEntry
*
syncEntryBuild4
(
SRpcMsg
*
pOriginalMsg
,
SyncTerm
term
,
SyncIndex
index
);
SSyncRaftEntry
*
syncEntryBuildNoop
(
SyncTerm
term
,
SyncIndex
index
,
int32_t
vgId
);
SSyncRaftEntry
*
syncEntryBuildNoop
(
SyncTerm
term
,
SyncIndex
index
,
int32_t
vgId
);
void
syncEntryDestory
(
SSyncRaftEntry
*
pEntry
);
void
syncEntryDestory
(
SSyncRaftEntry
*
pEntry
);
char
*
syncEntrySerialize
(
const
SSyncRaftEntry
*
pEntry
,
uint32_t
*
len
);
// step 5
char
*
syncEntrySerialize
(
const
SSyncRaftEntry
*
pEntry
,
uint32_t
*
len
);
// step 5
...
...
source/libs/sync/inc/syncReplication.h
浏览文件 @
3b50fee6
...
@@ -54,6 +54,7 @@ extern "C" {
...
@@ -54,6 +54,7 @@ extern "C" {
int32_t
syncNodeAppendEntriesPeers
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeAppendEntriesPeers
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeAppendEntriesPeersSnapshot
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeAppendEntriesPeersSnapshot
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeAppendEntriesPeersSnapshot2
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeAppendEntriesPeersSnapshot2
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeReplicate
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeReplicate
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeAppendEntries
(
SSyncNode
*
pSyncNode
,
const
SRaftId
*
destRaftId
,
const
SyncAppendEntries
*
pMsg
);
int32_t
syncNodeAppendEntries
(
SSyncNode
*
pSyncNode
,
const
SRaftId
*
destRaftId
,
const
SyncAppendEntries
*
pMsg
);
int32_t
syncNodeAppendEntriesBatch
(
SSyncNode
*
pSyncNode
,
const
SRaftId
*
destRaftId
,
const
SyncAppendEntriesBatch
*
pMsg
);
int32_t
syncNodeAppendEntriesBatch
(
SSyncNode
*
pSyncNode
,
const
SRaftId
*
destRaftId
,
const
SyncAppendEntriesBatch
*
pMsg
);
...
...
source/libs/sync/inc/syncSnapshot.h
浏览文件 @
3b50fee6
...
@@ -37,26 +37,28 @@ extern "C" {
...
@@ -37,26 +37,28 @@ extern "C" {
//---------------------------------------------------
//---------------------------------------------------
typedef
struct
SSyncSnapshotSender
{
typedef
struct
SSyncSnapshotSender
{
bool
start
;
bool
start
;
int32_t
seq
;
int32_t
seq
;
int32_t
ack
;
int32_t
ack
;
void
*
pReader
;
void
*
pReader
;
void
*
pCurrentBlock
;
void
*
pCurrentBlock
;
int32_t
blockLen
;
int32_t
blockLen
;
SSnapshot
snapshot
;
SSnapshotParam
snapshotParam
;
SSyncCfg
lastConfig
;
SSnapshot
snapshot
;
int64_t
sendingMS
;
SSyncCfg
lastConfig
;
SSyncNode
*
pSyncNode
;
int64_t
sendingMS
;
int32_t
replicaIndex
;
SSyncNode
*
pSyncNode
;
SyncTerm
term
;
int32_t
replicaIndex
;
SyncTerm
privateTerm
;
SyncTerm
term
;
bool
finish
;
SyncTerm
privateTerm
;
bool
finish
;
}
SSyncSnapshotSender
;
}
SSyncSnapshotSender
;
SSyncSnapshotSender
*
snapshotSenderCreate
(
SSyncNode
*
pSyncNode
,
int32_t
replicaIndex
);
SSyncSnapshotSender
*
snapshotSenderCreate
(
SSyncNode
*
pSyncNode
,
int32_t
replicaIndex
);
void
snapshotSenderDestroy
(
SSyncSnapshotSender
*
pSender
);
void
snapshotSenderDestroy
(
SSyncSnapshotSender
*
pSender
);
bool
snapshotSenderIsStart
(
SSyncSnapshotSender
*
pSender
);
bool
snapshotSenderIsStart
(
SSyncSnapshotSender
*
pSender
);
int32_t
snapshotSenderStart
(
SSyncSnapshotSender
*
pSender
,
SSnapshot
snapshot
,
void
*
pReader
);
int32_t
snapshotSenderStart
(
SSyncSnapshotSender
*
pSender
,
SSnapshotParam
snapshotParam
,
SSnapshot
snapshot
,
void
*
pReader
);
int32_t
snapshotSenderStop
(
SSyncSnapshotSender
*
pSender
,
bool
finish
);
int32_t
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
);
...
@@ -67,14 +69,15 @@ char *snapshotSender2SimpleStr(SSyncSnapshotSender *pSender, char *event);
...
@@ -67,14 +69,15 @@ char *snapshotSender2SimpleStr(SSyncSnapshotSender *pSender, char *event);
//---------------------------------------------------
//---------------------------------------------------
typedef
struct
SSyncSnapshotReceiver
{
typedef
struct
SSyncSnapshotReceiver
{
bool
start
;
bool
start
;
int32_t
ack
;
int32_t
ack
;
void
*
pWriter
;
void
*
pWriter
;
SyncTerm
term
;
SyncTerm
term
;
SyncTerm
privateTerm
;
SyncTerm
privateTerm
;
SSnapshot
snapshot
;
SSnapshotParam
snapshotParam
;
SRaftId
fromId
;
SSnapshot
snapshot
;
SSyncNode
*
pSyncNode
;
SRaftId
fromId
;
SSyncNode
*
pSyncNode
;
}
SSyncSnapshotReceiver
;
}
SSyncSnapshotReceiver
;
...
...
source/libs/sync/src/syncAppendEntries.c
浏览文件 @
3b50fee6
...
@@ -628,8 +628,6 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
...
@@ -628,8 +628,6 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
#endif
#endif
static
int32_t
syncNodeMakeLogSame2
(
SSyncNode
*
ths
,
SyncAppendEntriesBatch
*
pMsg
)
{
return
0
;
}
static
int32_t
syncNodeMakeLogSame
(
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
)
{
static
int32_t
syncNodeMakeLogSame
(
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
)
{
int32_t
code
;
int32_t
code
;
...
@@ -675,6 +673,51 @@ static int32_t syncNodeMakeLogSame(SSyncNode* ths, SyncAppendEntries* pMsg) {
...
@@ -675,6 +673,51 @@ static int32_t syncNodeMakeLogSame(SSyncNode* ths, SyncAppendEntries* pMsg) {
return
code
;
return
code
;
}
}
static
int32_t
syncNodeDoMakeLogSame
(
SSyncNode
*
ths
,
SyncIndex
FromIndex
)
{
int32_t
code
;
SyncIndex
delBegin
=
FromIndex
;
SyncIndex
delEnd
=
ths
->
pLogStore
->
syncLogLastIndex
(
ths
->
pLogStore
);
// invert roll back!
for
(
SyncIndex
index
=
delEnd
;
index
>=
delBegin
;
--
index
)
{
if
(
ths
->
pFsm
->
FpRollBackCb
!=
NULL
)
{
SSyncRaftEntry
*
pRollBackEntry
;
code
=
ths
->
pLogStore
->
syncLogGetEntry
(
ths
->
pLogStore
,
index
,
&
pRollBackEntry
);
ASSERT
(
code
==
0
);
ASSERT
(
pRollBackEntry
!=
NULL
);
if
(
syncUtilUserRollback
(
pRollBackEntry
->
msgType
))
{
SRpcMsg
rpcMsg
;
syncEntry2OriginalRpc
(
pRollBackEntry
,
&
rpcMsg
);
SFsmCbMeta
cbMeta
=
{
0
};
cbMeta
.
index
=
pRollBackEntry
->
index
;
cbMeta
.
lastConfigIndex
=
syncNodeGetSnapshotConfigIndex
(
ths
,
cbMeta
.
index
);
cbMeta
.
isWeak
=
pRollBackEntry
->
isWeak
;
cbMeta
.
code
=
0
;
cbMeta
.
state
=
ths
->
state
;
cbMeta
.
seqNum
=
pRollBackEntry
->
seqNum
;
ths
->
pFsm
->
FpRollBackCb
(
ths
->
pFsm
,
&
rpcMsg
,
cbMeta
);
rpcFreeCont
(
rpcMsg
.
pCont
);
}
syncEntryDestory
(
pRollBackEntry
);
}
}
// delete confict entries
code
=
ths
->
pLogStore
->
syncLogTruncate
(
ths
->
pLogStore
,
delBegin
);
ASSERT
(
code
==
0
);
char
eventLog
[
128
];
snprintf
(
eventLog
,
sizeof
(
eventLog
),
"log truncate, from %ld to %ld"
,
delBegin
,
delEnd
);
syncNodeEventLog
(
ths
,
eventLog
);
logStoreSimpleLog2
(
"after syncNodeMakeLogSame"
,
ths
->
pLogStore
);
return
code
;
}
static
int32_t
syncNodePreCommit
(
SSyncNode
*
ths
,
SSyncRaftEntry
*
pEntry
)
{
static
int32_t
syncNodePreCommit
(
SSyncNode
*
ths
,
SSyncRaftEntry
*
pEntry
)
{
SRpcMsg
rpcMsg
;
SRpcMsg
rpcMsg
;
syncEntry2OriginalRpc
(
pEntry
,
&
rpcMsg
);
syncEntry2OriginalRpc
(
pEntry
,
&
rpcMsg
);
...
@@ -694,6 +737,31 @@ static int32_t syncNodePreCommit(SSyncNode* ths, SSyncRaftEntry* pEntry) {
...
@@ -694,6 +737,31 @@ static int32_t syncNodePreCommit(SSyncNode* ths, SSyncRaftEntry* pEntry) {
return
0
;
return
0
;
}
}
static
bool
syncNodeOnAppendEntriesBatchLogOK
(
SSyncNode
*
pSyncNode
,
SyncAppendEntriesBatch
*
pMsg
)
{
if
(
pMsg
->
prevLogIndex
==
SYNC_INDEX_INVALID
)
{
return
true
;
}
SyncIndex
myLastIndex
=
syncNodeGetLastIndex
(
pSyncNode
);
if
(
pMsg
->
prevLogIndex
>
myLastIndex
)
{
sDebug
(
"vgId:%d sync log not ok, preindex:%ld"
,
pSyncNode
->
vgId
,
pMsg
->
prevLogIndex
);
return
false
;
}
SyncTerm
myPreLogTerm
=
syncNodeGetPreTerm
(
pSyncNode
,
pMsg
->
prevLogIndex
+
1
);
if
(
myPreLogTerm
==
SYNC_TERM_INVALID
)
{
sDebug
(
"vgId:%d sync log not ok2, preindex:%ld"
,
pSyncNode
->
vgId
,
pMsg
->
prevLogIndex
);
return
false
;
}
if
(
pMsg
->
prevLogIndex
<=
myLastIndex
&&
pMsg
->
prevLogTerm
==
myPreLogTerm
)
{
return
true
;
}
sDebug
(
"vgId:%d sync log not ok3, preindex:%ld"
,
pSyncNode
->
vgId
,
pMsg
->
prevLogIndex
);
return
false
;
}
// really pre log match
// really pre log match
// prevLogIndex == -1
// prevLogIndex == -1
static
bool
syncNodeOnAppendEntriesLogOK
(
SSyncNode
*
pSyncNode
,
SyncAppendEntries
*
pMsg
)
{
static
bool
syncNodeOnAppendEntriesLogOK
(
SSyncNode
*
pSyncNode
,
SyncAppendEntries
*
pMsg
)
{
...
@@ -767,7 +835,6 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc
...
@@ -767,7 +835,6 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc
// operation:
// operation:
// if hasAppendEntries && pMsg->prevLogIndex == ths->commitIndex, append entry
// if hasAppendEntries && pMsg->prevLogIndex == ths->commitIndex, append entry
// match my-commit-index or my-commit-index + 1
// match my-commit-index or my-commit-index + 1
// no operation on log
do
{
do
{
bool
condition
=
(
pMsg
->
term
==
ths
->
pRaftStore
->
currentTerm
)
&&
(
ths
->
state
==
TAOS_SYNC_STATE_FOLLOWER
)
&&
bool
condition
=
(
pMsg
->
term
==
ths
->
pRaftStore
->
currentTerm
)
&&
(
ths
->
state
==
TAOS_SYNC_STATE_FOLLOWER
)
&&
(
pMsg
->
prevLogIndex
<=
ths
->
commitIndex
);
(
pMsg
->
prevLogIndex
<=
ths
->
commitIndex
);
...
@@ -780,14 +847,11 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc
...
@@ -780,14 +847,11 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc
syncNodeEventLog
(
ths
,
logBuf
);
syncNodeEventLog
(
ths
,
logBuf
);
}
while
(
0
);
}
while
(
0
);
SyncIndex
matchIndex
=
ths
->
commitIndex
;
SyncIndex
matchIndex
=
ths
->
commitIndex
;
bool
hasAppendEntries
=
pMsg
->
dataLen
>
0
;
bool
hasAppendEntries
=
pMsg
->
dataLen
>
0
;
if
(
hasAppendEntries
&&
pMsg
->
prevLogIndex
==
ths
->
commitIndex
)
{
SOffsetAndContLen
*
metaTableArr
=
syncAppendEntriesBatchMetaTableArray
(
pMsg
);
SRpcMsg
rpcMsgArr
[
SYNC_MAX_BATCH_SIZE
];
memset
(
rpcMsgArr
,
0
,
sizeof
(
rpcMsgArr
));
int32_t
retArrSize
=
0
;
syncAppendEntriesBatch2RpcMsgArray
(
pMsg
,
rpcMsgArr
,
SYNC_MAX_BATCH_SIZE
,
&
retArrSize
);
if
(
hasAppendEntries
&&
pMsg
->
prevLogIndex
==
ths
->
commitIndex
)
{
// make log same
// make log same
do
{
do
{
SyncIndex
logLastIndex
=
ths
->
pLogStore
->
syncLogLastIndex
(
ths
->
pLogStore
);
SyncIndex
logLastIndex
=
ths
->
pLogStore
->
syncLogLastIndex
(
ths
->
pLogStore
);
...
@@ -795,15 +859,15 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc
...
@@ -795,15 +859,15 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc
if
(
hasExtraEntries
)
{
if
(
hasExtraEntries
)
{
// make log same, rollback deleted entries
// make log same, rollback deleted entries
code
=
syncNode
MakeLogSame2
(
ths
,
pMsg
);
code
=
syncNode
DoMakeLogSame
(
ths
,
pMsg
->
prevLogIndex
+
1
);
ASSERT
(
code
==
0
);
ASSERT
(
code
==
0
);
}
}
}
while
(
0
);
}
while
(
0
);
// append entry batch
// append entry batch
for
(
int32_t
i
=
0
;
i
<
retArrSize
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pMsg
->
dataCount
;
++
i
)
{
SSyncRaftEntry
*
pAppendEntry
=
syncEntryBuild
(
1234
);
SSyncRaftEntry
*
pAppendEntry
=
(
SSyncRaftEntry
*
)(
pMsg
->
data
+
metaTableArr
[
i
].
offset
);
code
=
ths
->
pLogStore
->
syncLogAppendEntry
(
ths
->
pLogStore
,
pAppendEntry
);
code
=
ths
->
pLogStore
->
syncLogAppendEntry
(
ths
->
pLogStore
,
pAppendEntry
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
return
-
1
;
return
-
1
;
...
@@ -821,7 +885,7 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc
...
@@ -821,7 +885,7 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc
walFsync
(
pWal
,
true
);
walFsync
(
pWal
,
true
);
// update match index
// update match index
matchIndex
=
pMsg
->
prevLogIndex
+
retArrSize
;
matchIndex
=
pMsg
->
prevLogIndex
+
pMsg
->
dataCount
;
}
}
// prepare response msg
// prepare response msg
...
@@ -839,13 +903,12 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc
...
@@ -839,13 +903,12 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc
syncNodeSendMsgById
(
&
pReply
->
destId
,
ths
,
&
rpcMsg
);
syncNodeSendMsgById
(
&
pReply
->
destId
,
ths
,
&
rpcMsg
);
syncAppendEntriesReplyDestroy
(
pReply
);
syncAppendEntriesReplyDestroy
(
pReply
);
return
ret
;
return
0
;
}
}
}
while
(
0
);
}
while
(
0
);
// calculate logOK here, before will coredump, due to fake match
// calculate logOK here, before will coredump, due to fake match
// bool logOK = syncNodeOnAppendEntriesLogOK(ths, pMsg);
bool
logOK
=
syncNodeOnAppendEntriesBatchLogOK
(
ths
,
pMsg
);
bool
logOK
=
true
;
// not match
// not match
//
//
...
@@ -866,8 +929,9 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc
...
@@ -866,8 +929,9 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc
if
(
condition
)
{
if
(
condition
)
{
char
logBuf
[
128
];
char
logBuf
[
128
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"recv sync-append-entries, not match, pre-index:%ld, pre-term:%lu, datalen:%d"
,
snprintf
(
logBuf
,
sizeof
(
logBuf
),
pMsg
->
prevLogIndex
,
pMsg
->
prevLogTerm
,
pMsg
->
dataLen
);
"recv sync-append-entries-batch, not match, pre-index:%ld, pre-term:%lu, datalen:%d"
,
pMsg
->
prevLogIndex
,
pMsg
->
prevLogTerm
,
pMsg
->
dataLen
);
syncNodeEventLog
(
ths
,
logBuf
);
syncNodeEventLog
(
ths
,
logBuf
);
// prepare response msg
// prepare response msg
...
@@ -885,7 +949,7 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc
...
@@ -885,7 +949,7 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc
syncNodeSendMsgById
(
&
pReply
->
destId
,
ths
,
&
rpcMsg
);
syncNodeSendMsgById
(
&
pReply
->
destId
,
ths
,
&
rpcMsg
);
syncAppendEntriesReplyDestroy
(
pReply
);
syncAppendEntriesReplyDestroy
(
pReply
);
return
ret
;
return
0
;
}
}
}
while
(
0
);
}
while
(
0
);
...
@@ -905,28 +969,26 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc
...
@@ -905,28 +969,26 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc
bool
hasExtraEntries
=
myLastIndex
>
pMsg
->
prevLogIndex
;
bool
hasExtraEntries
=
myLastIndex
>
pMsg
->
prevLogIndex
;
// has entries in SyncAppendEntries msg
// has entries in SyncAppendEntries msg
bool
hasAppendEntries
=
pMsg
->
dataLen
>
0
;
bool
hasAppendEntries
=
pMsg
->
dataLen
>
0
;
SOffsetAndContLen
*
metaTableArr
=
syncAppendEntriesBatchMetaTableArray
(
pMsg
);
char
logBuf
[
128
];
do
{
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"recv sync-append-entries, match, pre-index:%ld, pre-term:%lu, datalen:%d"
,
char
logBuf
[
128
];
pMsg
->
prevLogIndex
,
pMsg
->
prevLogTerm
,
pMsg
->
dataLen
);
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"recv sync-append-entries, match, pre-index:%ld, pre-term:%lu, datalen:%d"
,
syncNodeEventLog
(
ths
,
logBuf
);
pMsg
->
prevLogIndex
,
pMsg
->
prevLogTerm
,
pMsg
->
dataLen
);
syncNodeEventLog
(
ths
,
logBuf
);
}
while
(
0
);
if
(
hasExtraEntries
)
{
if
(
hasExtraEntries
)
{
// make log same, rollback deleted entries
// make log same, rollback deleted entries
// code = syncNodeMakeLogSame(ths, pMsg
);
code
=
syncNodeDoMakeLogSame
(
ths
,
pMsg
->
prevLogIndex
+
1
);
ASSERT
(
code
==
0
);
ASSERT
(
code
==
0
);
}
}
int32_t
retArrSize
=
0
;
if
(
hasAppendEntries
)
{
if
(
hasAppendEntries
)
{
SRpcMsg
rpcMsgArr
[
SYNC_MAX_BATCH_SIZE
];
memset
(
rpcMsgArr
,
0
,
sizeof
(
rpcMsgArr
));
syncAppendEntriesBatch2RpcMsgArray
(
pMsg
,
rpcMsgArr
,
SYNC_MAX_BATCH_SIZE
,
&
retArrSize
);
// append entry batch
// append entry batch
for
(
int32_t
i
=
0
;
i
<
retArrSize
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pMsg
->
dataCount
;
++
i
)
{
SSyncRaftEntry
*
pAppendEntry
=
syncEntryBuild
(
1234
);
SSyncRaftEntry
*
pAppendEntry
=
(
SSyncRaftEntry
*
)(
pMsg
->
data
+
metaTableArr
[
i
].
offset
);
code
=
ths
->
pLogStore
->
syncLogAppendEntry
(
ths
->
pLogStore
,
pAppendEntry
);
code
=
ths
->
pLogStore
->
syncLogAppendEntry
(
ths
->
pLogStore
,
pAppendEntry
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
return
-
1
;
return
-
1
;
...
@@ -951,7 +1013,7 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc
...
@@ -951,7 +1013,7 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc
pReply
->
term
=
ths
->
pRaftStore
->
currentTerm
;
pReply
->
term
=
ths
->
pRaftStore
->
currentTerm
;
pReply
->
privateTerm
=
ths
->
pNewNodeReceiver
->
privateTerm
;
pReply
->
privateTerm
=
ths
->
pNewNodeReceiver
->
privateTerm
;
pReply
->
success
=
true
;
pReply
->
success
=
true
;
pReply
->
matchIndex
=
hasAppendEntries
?
pMsg
->
prevLogIndex
+
retArrSize
:
pMsg
->
prevLogIndex
;
pReply
->
matchIndex
=
hasAppendEntries
?
pMsg
->
prevLogIndex
+
pMsg
->
dataCount
:
pMsg
->
prevLogIndex
;
// send response
// send response
SRpcMsg
rpcMsg
;
SRpcMsg
rpcMsg
;
...
@@ -991,11 +1053,11 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc
...
@@ -991,11 +1053,11 @@ int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatc
ASSERT
(
code
==
0
);
ASSERT
(
code
==
0
);
}
}
}
}
return
ret
;
return
0
;
}
}
}
while
(
0
);
}
while
(
0
);
return
ret
;
return
0
;
}
}
int32_t
syncNodeOnAppendEntriesSnapshotCb
(
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
)
{
int32_t
syncNodeOnAppendEntriesSnapshotCb
(
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
)
{
...
...
source/libs/sync/src/syncAppendEntriesReply.c
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
source/libs/sync/src/syncMain.c
浏览文件 @
3b50fee6
...
@@ -815,7 +815,7 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) {
...
@@ -815,7 +815,7 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) {
// create a new raft config file
// create a new raft config file
SRaftCfgMeta
meta
;
SRaftCfgMeta
meta
;
meta
.
isStandBy
=
pSyncInfo
->
isStandBy
;
meta
.
isStandBy
=
pSyncInfo
->
isStandBy
;
meta
.
snapshotEnable
=
pSyncInfo
->
snapshot
Enable
;
meta
.
snapshotEnable
=
pSyncInfo
->
snapshot
Strategy
;
meta
.
lastConfigIndex
=
SYNC_INDEX_INVALID
;
meta
.
lastConfigIndex
=
SYNC_INDEX_INVALID
;
ret
=
raftCfgCreateFile
((
SSyncCfg
*
)
&
(
pSyncInfo
->
syncCfg
),
meta
,
pSyncNode
->
configPath
);
ret
=
raftCfgCreateFile
((
SSyncCfg
*
)
&
(
pSyncInfo
->
syncCfg
),
meta
,
pSyncNode
->
configPath
);
ASSERT
(
ret
==
0
);
ASSERT
(
ret
==
0
);
...
@@ -1100,7 +1100,9 @@ void syncNodeClose(SSyncNode* pSyncNode) {
...
@@ -1100,7 +1100,9 @@ void syncNodeClose(SSyncNode* pSyncNode) {
}
}
// option
// option
bool
syncNodeSnapshotEnable
(
SSyncNode
*
pSyncNode
)
{
return
pSyncNode
->
pRaftCfg
->
snapshotEnable
;
}
// bool syncNodeSnapshotEnable(SSyncNode* pSyncNode) { return pSyncNode->pRaftCfg->snapshotEnable; }
ESyncStrategy
syncNodeStrategy
(
SSyncNode
*
pSyncNode
)
{
return
pSyncNode
->
pRaftCfg
->
snapshotEnable
;
}
// ping --------------
// ping --------------
int32_t
syncNodePing
(
SSyncNode
*
pSyncNode
,
const
SRaftId
*
destRaftId
,
SyncPing
*
pMsg
)
{
int32_t
syncNodePing
(
SSyncNode
*
pSyncNode
,
const
SRaftId
*
destRaftId
,
SyncPing
*
pMsg
)
{
...
...
source/libs/sync/src/syncMessage.c
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
source/libs/sync/src/syncRaftEntry.c
浏览文件 @
3b50fee6
...
@@ -50,6 +50,22 @@ SSyncRaftEntry* syncEntryBuild3(SyncClientRequest* pMsg, SyncTerm term, SyncInde
...
@@ -50,6 +50,22 @@ SSyncRaftEntry* syncEntryBuild3(SyncClientRequest* pMsg, SyncTerm term, SyncInde
return
pEntry
;
return
pEntry
;
}
}
SSyncRaftEntry
*
syncEntryBuild4
(
SRpcMsg
*
pOriginalMsg
,
SyncTerm
term
,
SyncIndex
index
)
{
SSyncRaftEntry
*
pEntry
=
syncEntryBuild
(
pOriginalMsg
->
contLen
);
ASSERT
(
pEntry
!=
NULL
);
pEntry
->
msgType
=
TDMT_SYNC_CLIENT_REQUEST
;
pEntry
->
originalRpcType
=
pOriginalMsg
->
msgType
;
pEntry
->
seqNum
=
0
;
pEntry
->
isWeak
=
0
;
pEntry
->
term
=
term
;
pEntry
->
index
=
index
;
pEntry
->
dataLen
=
pOriginalMsg
->
contLen
;
memcpy
(
pEntry
->
data
,
pOriginalMsg
->
pCont
,
pOriginalMsg
->
contLen
);
return
pEntry
;
}
SSyncRaftEntry
*
syncEntryBuildNoop
(
SyncTerm
term
,
SyncIndex
index
,
int32_t
vgId
)
{
SSyncRaftEntry
*
syncEntryBuildNoop
(
SyncTerm
term
,
SyncIndex
index
,
int32_t
vgId
)
{
// init rpcMsg
// init rpcMsg
SMsgHead
head
;
SMsgHead
head
;
...
...
source/libs/sync/src/syncRaftLog.c
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
source/libs/sync/src/syncReplication.c
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
source/libs/sync/src/syncSnapshot.c
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
source/libs/sync/test/CMakeLists.txt
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
source/libs/sync/test/syncAppendEntriesBatchTest.cpp
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
source/libs/sync/test/syncClientRequestBatchTest.cpp
0 → 100644
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
source/libs/sync/test/syncConfigChangeSnapshotTest.cpp
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
source/libs/sync/test/syncSnapshotReceiverTest.cpp
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
source/libs/sync/test/syncSnapshotSenderTest.cpp
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
source/libs/sync/test/syncTestTool.cpp
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
source/libs/transport/inc/transComm.h
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
source/libs/transport/src/transCli.c
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
source/libs/transport/src/transComm.c
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
source/libs/transport/src/transSvr.c
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
source/libs/transport/test/transUT.cpp
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
source/util/src/terror.c
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
tests/script/tsim/insert/update0.sim
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
tests/system-test/1-insert/block_wise.py
0 → 100644
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
tests/system-test/1-insert/create_retentions.py
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
tests/system-test/1-insert/time_range_wise.py
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
tests/system-test/2-query/json_tag.py
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
tests/system-test/7-tmq/tmqConsFromTsdb-1ctb.py
0 → 100644
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
tests/system-test/7-tmq/tmqConsFromTsdb1-1ctb.py
0 → 100644
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
tests/system-test/7-tmq/tmqConsFromTsdb1-mutilVg.py
0 → 100644
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
tests/system-test/7-tmq/tmqConsFromTsdb1.py
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
tests/system-test/fulltest.sh
浏览文件 @
3b50fee6
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录