Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
7eb4153a
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
7eb4153a
编写于
3月 17, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/3.0' into feature/3.0_wxy
上级
83b40fac
ad0cdac4
变更
78
展开全部
显示空白变更内容
内联
并排
Showing
78 changed file
with
2065 addition
and
1072 deletion
+2065
-1072
contrib/CMakeLists.txt
contrib/CMakeLists.txt
+9
-0
include/common/tmsg.h
include/common/tmsg.h
+78
-50
include/common/tmsgdef.h
include/common/tmsgdef.h
+2
-0
include/common/trow.h
include/common/trow.h
+15
-15
include/dnode/snode/snode.h
include/dnode/snode/snode.h
+2
-1
include/libs/nodes/plannodes.h
include/libs/nodes/plannodes.h
+3
-3
include/libs/transport/trpc.h
include/libs/transport/trpc.h
+3
-0
include/os/os.h
include/os/os.h
+8
-6
include/os/osDef.h
include/os/osDef.h
+1
-0
include/os/osFile.h
include/os/osFile.h
+1
-1
include/os/osSocket.h
include/os/osSocket.h
+2
-0
include/os/osSysinfo.h
include/os/osSysinfo.h
+0
-1
include/util/taoserror.h
include/util/taoserror.h
+1
-0
include/util/tencode.h
include/util/tencode.h
+25
-2
include/util/tfreelist.h
include/util/tfreelist.h
+6
-4
include/util/types.h
include/util/types.h
+1
-1
source/common/src/tmsg.c
source/common/src/tmsg.c
+53
-27
source/common/src/tname.c
source/common/src/tname.c
+1
-1
source/dnode/mgmt/impl/src/dndSnode.c
source/dnode/mgmt/impl/src/dndSnode.c
+20
-7
source/dnode/mnode/impl/inc/mndDef.h
source/dnode/mnode/impl/inc/mndDef.h
+3
-7
source/dnode/mnode/impl/inc/mndScheduler.h
source/dnode/mnode/impl/inc/mndScheduler.h
+2
-0
source/dnode/mnode/impl/src/mndDef.c
source/dnode/mnode/impl/src/mndDef.c
+3
-3
source/dnode/mnode/impl/src/mndScheduler.c
source/dnode/mnode/impl/src/mndScheduler.c
+47
-28
source/dnode/mnode/impl/src/mndStream.c
source/dnode/mnode/impl/src/mndStream.c
+7
-0
source/dnode/snode/CMakeLists.txt
source/dnode/snode/CMakeLists.txt
+2
-1
source/dnode/snode/inc/sndInt.h
source/dnode/snode/inc/sndInt.h
+9
-23
source/dnode/snode/src/snode.c
source/dnode/snode/src/snode.c
+83
-11
source/dnode/vnode/inc/tsdb.h
source/dnode/vnode/inc/tsdb.h
+2
-4
source/dnode/vnode/src/inc/tsdbDef.h
source/dnode/vnode/src/inc/tsdbDef.h
+5
-4
source/dnode/vnode/src/meta/metaBDBImpl.c
source/dnode/vnode/src/meta/metaBDBImpl.c
+1
-1
source/dnode/vnode/src/tsdb/tsdbBDBImpl.c
source/dnode/vnode/src/tsdb/tsdbBDBImpl.c
+2
-2
source/dnode/vnode/src/tsdb/tsdbFile.c
source/dnode/vnode/src/tsdb/tsdbFile.c
+2
-2
source/dnode/vnode/src/tsdb/tsdbSma.c
source/dnode/vnode/src/tsdb/tsdbSma.c
+201
-115
source/dnode/vnode/test/tsdbSmaTest.cpp
source/dnode/vnode/test/tsdbSmaTest.cpp
+64
-59
source/libs/parser/src/parInsert.c
source/libs/parser/src/parInsert.c
+3
-3
source/libs/planner/src/planSpliter.c
source/libs/planner/src/planSpliter.c
+1
-1
source/libs/sync/inc/syncEnv.h
source/libs/sync/inc/syncEnv.h
+3
-3
source/libs/sync/inc/syncIO.h
source/libs/sync/inc/syncIO.h
+3
-3
source/libs/sync/inc/syncRaftStore.h
source/libs/sync/inc/syncRaftStore.h
+8
-5
source/libs/sync/src/syncAppendEntries.c
source/libs/sync/src/syncAppendEntries.c
+12
-8
source/libs/sync/src/syncAppendEntriesReply.c
source/libs/sync/src/syncAppendEntriesReply.c
+4
-2
source/libs/sync/src/syncCommit.c
source/libs/sync/src/syncCommit.c
+45
-0
source/libs/sync/src/syncElection.c
source/libs/sync/src/syncElection.c
+10
-1
source/libs/sync/src/syncIO.c
source/libs/sync/src/syncIO.c
+7
-0
source/libs/sync/src/syncIndexMgr.c
source/libs/sync/src/syncIndexMgr.c
+17
-15
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+153
-125
source/libs/sync/src/syncMessage.c
source/libs/sync/src/syncMessage.c
+295
-279
source/libs/sync/src/syncRaftEntry.c
source/libs/sync/src/syncRaftEntry.c
+24
-22
source/libs/sync/src/syncRaftLog.c
source/libs/sync/src/syncRaftLog.c
+34
-29
source/libs/sync/src/syncRaftStore.c
source/libs/sync/src/syncRaftStore.c
+72
-17
source/libs/sync/src/syncReplication.c
source/libs/sync/src/syncReplication.c
+31
-9
source/libs/sync/src/syncRequestVote.c
source/libs/sync/src/syncRequestVote.c
+2
-0
source/libs/sync/src/syncRequestVoteReply.c
source/libs/sync/src/syncRequestVoteReply.c
+14
-1
source/libs/sync/src/syncTimeout.c
source/libs/sync/src/syncTimeout.c
+2
-1
source/libs/sync/src/syncUtil.c
source/libs/sync/src/syncUtil.c
+2
-5
source/libs/sync/src/syncVoteMgr.c
source/libs/sync/src/syncVoteMgr.c
+56
-52
source/libs/sync/test/CMakeLists.txt
source/libs/sync/test/CMakeLists.txt
+47
-0
source/libs/sync/test/syncElectTest.cpp
source/libs/sync/test/syncElectTest.cpp
+124
-0
source/libs/sync/test/syncInitTest.cpp
source/libs/sync/test/syncInitTest.cpp
+1
-2
source/libs/sync/test/syncLogStoreTest.cpp
source/libs/sync/test/syncLogStoreTest.cpp
+3
-3
source/libs/sync/test/syncPingSelfTest.cpp
source/libs/sync/test/syncPingSelfTest.cpp
+102
-0
source/libs/sync/test/syncPingTimerTest.cpp
source/libs/sync/test/syncPingTimerTest.cpp
+1
-0
source/libs/sync/test/syncPingTimerTest2.cpp
source/libs/sync/test/syncPingTimerTest2.cpp
+106
-0
source/libs/sync/test/syncRaftStoreTest.cpp
source/libs/sync/test/syncRaftStoreTest.cpp
+44
-16
source/libs/tdb/src/db/tdbBtree.c
source/libs/tdb/src/db/tdbBtree.c
+3
-1
source/libs/tdb/src/db/tdbEnv.c
source/libs/tdb/src/db/tdbEnv.c
+1
-5
source/libs/tdb/src/db/tdbPgCache.c
source/libs/tdb/src/db/tdbPgCache.c
+1
-5
source/libs/tdb/src/inc/tdbPgFile.h
source/libs/tdb/src/inc/tdbPgFile.h
+3
-1
source/libs/transport/src/transCli.c
source/libs/transport/src/transCli.c
+98
-47
source/libs/transport/src/transSrv.c
source/libs/transport/src/transSrv.c
+16
-9
source/libs/transport/test/transUT.cc
source/libs/transport/test/transUT.cc
+31
-1
source/libs/wal/src/walMeta.c
source/libs/wal/src/walMeta.c
+0
-3
source/os/CMakeLists.txt
source/os/CMakeLists.txt
+4
-3
source/util/src/tcompare.c
source/util/src/tcompare.c
+1
-1
source/util/src/terror.c
source/util/src/terror.c
+1
-0
source/util/src/tuuid.c
source/util/src/tuuid.c
+10
-10
source/util/test/encodeTest.cpp
source/util/test/encodeTest.cpp
+4
-4
source/util/test/freelistTest.cpp
source/util/test/freelistTest.cpp
+2
-1
未找到文件。
contrib/CMakeLists.txt
浏览文件 @
7eb4153a
...
...
@@ -212,6 +212,11 @@ if(${BUILD_WITH_UV})
MESSAGE
(
"Windows need set no-sign-compare"
)
add_compile_options
(
-Wno-sign-compare
)
endif
()
if
(
${
CMAKE_SYSTEM_NAME
}
MATCHES
"Windows"
)
file
(
READ
"libuv/include/uv.h"
CONTENTS
)
string
(
REGEX REPLACE
"/([
\r
]*)
\n
struct uv_tcp_s {"
"/
\\
1
\n
typedef BOOL (PASCAL *LPFN_CONNECTEX) (SOCKET s, const struct sockaddr* name, int namelen, PVOID lpSendBuffer, DWORD dwSendDataLength,LPDWORD lpdwBytesSent, LPOVERLAPPED lpOverlapped);
\\
1
\n
struct uv_tcp_s {"
CONTENTS_NEW
"
${
CONTENTS
}
"
)
file
(
WRITE
"libuv/include/uv.h"
"
${
CONTENTS_NEW
}
"
)
endif
()
add_subdirectory
(
libuv
)
endif
(
${
BUILD_WITH_UV
}
)
...
...
@@ -243,6 +248,10 @@ if(${BUILD_WITH_SQLITE})
endif
(
${
BUILD_WITH_SQLITE
}
)
# pthread
if
(
${
BUILD_PTHREAD
}
)
ADD_DEFINITIONS
(
"-DPTW32_STATIC_LIB"
)
add_subdirectory
(
pthread-win32
)
endif
(
${
BUILD_PTHREAD
}
)
# ================================================================================================
...
...
include/common/tmsg.h
浏览文件 @
7eb4153a
...
...
@@ -24,6 +24,7 @@
#include "thash.h"
#include "tlist.h"
#include "trow.h"
#include "tuuid.h"
#ifdef __cplusplus
extern
"C"
{
...
...
@@ -553,15 +554,13 @@ int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
int32_t
tDeserializeSQnodeListReq
(
void
*
buf
,
int32_t
bufLen
,
SQnodeListReq
*
pReq
);
typedef
struct
{
SArray
*
epSetList
;
// SArray<SEpSet>
SArray
*
epSetList
;
// SArray<SEpSet>
}
SQnodeListRsp
;
int32_t
tSerializeSQnodeListRsp
(
void
*
buf
,
int32_t
bufLen
,
SQnodeListRsp
*
pRsp
);
int32_t
tDeserializeSQnodeListRsp
(
void
*
buf
,
int32_t
bufLen
,
SQnodeListRsp
*
pRsp
);
void
tFreeSQnodeListRsp
(
SQnodeListRsp
*
pRsp
);
typedef
struct
{
SArray
*
pArray
;
// Array of SUseDbRsp
}
SUseDbBatchRsp
;
...
...
@@ -777,7 +776,6 @@ typedef struct SVgroupInfo {
int32_t
numOfTable
;
// unit is TSDB_TABLE_NUM_UNIT
}
SVgroupInfo
;
typedef
struct
{
int32_t
numOfVgroups
;
SVgroupInfo
vgroups
[];
...
...
@@ -1063,7 +1061,7 @@ typedef struct {
typedef
struct
{
int64_t
refId
;
SArray
*
taskStatus
;
//
SArray<STaskStatus>
SArray
*
taskStatus
;
//
SArray<STaskStatus>
}
SSchedulerStatusRsp
;
typedef
struct
{
...
...
@@ -1072,35 +1070,31 @@ typedef struct {
int8_t
action
;
}
STaskAction
;
typedef
struct
SQueryNodeEpId
{
int32_t
nodeId
;
// vgId or qnodeId
SEp
ep
;
}
SQueryNodeEpId
;
typedef
struct
{
SMsgHead
header
;
uint64_t
sId
;
SQueryNodeEpId
epId
;
SArray
*
taskAction
;
//
SArray<STaskAction>
SArray
*
taskAction
;
//
SArray<STaskAction>
}
SSchedulerHbReq
;
int32_t
tSerializeSSchedulerHbReq
(
void
*
buf
,
int32_t
bufLen
,
SSchedulerHbReq
*
pReq
);
int32_t
tDeserializeSSchedulerHbReq
(
void
*
buf
,
int32_t
bufLen
,
SSchedulerHbReq
*
pReq
);
void
tFreeSSchedulerHbReq
(
SSchedulerHbReq
*
pReq
);
int32_t
tSerializeSSchedulerHbReq
(
void
*
buf
,
int32_t
bufLen
,
SSchedulerHbReq
*
pReq
);
int32_t
tDeserializeSSchedulerHbReq
(
void
*
buf
,
int32_t
bufLen
,
SSchedulerHbReq
*
pReq
);
void
tFreeSSchedulerHbReq
(
SSchedulerHbReq
*
pReq
);
typedef
struct
{
uint64_t
seqId
;
SQueryNodeEpId
epId
;
SArray
*
taskStatus
;
//
SArray<STaskStatus>
SArray
*
taskStatus
;
//
SArray<STaskStatus>
}
SSchedulerHbRsp
;
int32_t
tSerializeSSchedulerHbRsp
(
void
*
buf
,
int32_t
bufLen
,
SSchedulerHbRsp
*
pRsp
);
int32_t
tDeserializeSSchedulerHbRsp
(
void
*
buf
,
int32_t
bufLen
,
SSchedulerHbRsp
*
pRsp
);
void
tFreeSSchedulerHbRsp
(
SSchedulerHbRsp
*
pRsp
);
int32_t
tSerializeSSchedulerHbRsp
(
void
*
buf
,
int32_t
bufLen
,
SSchedulerHbRsp
*
pRsp
);
int32_t
tDeserializeSSchedulerHbRsp
(
void
*
buf
,
int32_t
bufLen
,
SSchedulerHbRsp
*
pRsp
);
void
tFreeSSchedulerHbRsp
(
SSchedulerHbRsp
*
pRsp
);
typedef
struct
{
SMsgHead
header
;
...
...
@@ -1896,33 +1890,18 @@ static FORCE_INLINE void* tDecodeSSchemaWrapper(void* buf, SSchemaWrapper* pSW)
}
return
buf
;
}
typedef
enum
{
TD_TIME_UNIT_UNKNOWN
=
-
1
,
TD_TIME_UNIT_YEAR
=
0
,
TD_TIME_UNIT_SEASON
=
1
,
TD_TIME_UNIT_MONTH
=
2
,
TD_TIME_UNIT_WEEK
=
3
,
TD_TIME_UNIT_DAY
=
4
,
TD_TIME_UNIT_HOUR
=
5
,
TD_TIME_UNIT_MINUTE
=
6
,
TD_TIME_UNIT_SEC
=
7
,
TD_TIME_UNIT_MILLISEC
=
8
,
TD_TIME_UNIT_MICROSEC
=
9
,
TD_TIME_UNIT_NANOSEC
=
10
}
ETDTimeUnit
;
typedef
struct
{
int8_t
version
;
// for compatibility(default 0)
int8_t
intervalUnit
;
int8_t
slidingUnit
;
int8_t
intervalUnit
;
// MACRO: TIME_UNIT_XXX
int8_t
slidingUnit
;
// MACRO: TIME_UNIT_XXX
char
indexName
[
TSDB_INDEX_NAME_LEN
];
char
timezone
[
TD_TIMEZONE_LEN
];
// sma data
is invalid if timezone change
.
char
timezone
[
TD_TIMEZONE_LEN
];
// sma data
expired if timezone changes
.
int32_t
exprLen
;
int32_t
tagsFilterLen
;
int64_t
indexUid
;
tb_uid_t
tableUid
;
// super/child/common table uid
int64_t
interval
;
int64_t
offset
;
int64_t
offset
;
// use unit by precision of DB
int64_t
sliding
;
char
*
expr
;
// sma expression
char
*
tagsFilter
;
...
...
@@ -1967,7 +1946,7 @@ typedef struct {
typedef
struct
{
int64_t
indexUid
;
TSKEY
skey
;
// start
TS of one interval/sliding
TSKEY
skey
;
// start
Key of one interval/sliding window
int64_t
interval
;
int32_t
dataLen
;
// not including head
int8_t
intervalUnit
;
...
...
@@ -2267,6 +2246,55 @@ static FORCE_INLINE void* tDecodeSMqCMGetSubEpRsp(void* buf, SMqCMGetSubEpRsp* p
return
buf
;
}
enum
{
STREAM_TASK_STATUS__RUNNING
=
1
,
STREAM_TASK_STATUS__STOP
,
};
typedef
struct
{
int64_t
streamId
;
int32_t
taskId
;
int32_t
level
;
int8_t
status
;
char
*
qmsg
;
void
*
executor
;
// void* stateStore;
// storage handle
}
SStreamTask
;
static
FORCE_INLINE
SStreamTask
*
streamTaskNew
(
int64_t
streamId
,
int32_t
level
)
{
SStreamTask
*
pTask
=
(
SStreamTask
*
)
calloc
(
1
,
sizeof
(
SStreamTask
));
if
(
pTask
==
NULL
)
{
return
NULL
;
}
pTask
->
taskId
=
tGenIdPI32
();
pTask
->
status
=
STREAM_TASK_STATUS__RUNNING
;
pTask
->
qmsg
=
NULL
;
return
pTask
;
}
int32_t
tEncodeSStreamTask
(
SCoder
*
pEncoder
,
const
SStreamTask
*
pTask
);
int32_t
tDecodeSStreamTask
(
SCoder
*
pDecoder
,
SStreamTask
*
pTask
);
void
tFreeSStreamTask
(
SStreamTask
*
pTask
);
typedef
struct
{
SMsgHead
head
;
SStreamTask
*
task
;
}
SStreamTaskDeployReq
;
typedef
struct
{
int32_t
reserved
;
}
SStreamTaskDeployRsp
;
typedef
struct
{
SMsgHead
head
;
// TODO: other info needed by task
}
SStreamTaskExecReq
;
typedef
struct
{
int32_t
reserved
;
}
SStreamTaskExecRsp
;
#pragma pack(pop)
#ifdef __cplusplus
...
...
include/common/tmsgdef.h
浏览文件 @
7eb4153a
...
...
@@ -199,6 +199,8 @@ enum {
// Requests handled by SNODE
TD_NEW_MSG_SEG
(
TDMT_SND_MSG
)
TD_DEF_MSG_TYPE
(
TDMT_SND_TASK_DEPLOY
,
"snode-task-deploy"
,
SStreamTaskDeployReq
,
SStreamTaskDeployRsp
)
TD_DEF_MSG_TYPE
(
TDMT_SND_TASK_EXEC
,
"snode-task-exec"
,
SStreamTaskExecReq
,
SStreamTaskExecRsp
)
#if defined(TD_MSG_NUMBER_)
TDMT_MAX
...
...
include/common/trow.h
浏览文件 @
7eb4153a
...
...
@@ -98,7 +98,7 @@ typedef void *SRow;
typedef
struct
{
TDRowValT
valType
;
void
*
val
;
void
*
val
;
}
SCellVal
;
typedef
struct
{
...
...
@@ -158,8 +158,8 @@ typedef struct {
int16_t
nBitmaps
;
int16_t
nBoundBitmaps
;
int32_t
offset
;
void
*
pBitmap
;
void
*
pOffset
;
void
*
pBitmap
;
void
*
pOffset
;
int32_t
extendedRowSize
;
}
SRowBuilder
;
...
...
@@ -273,7 +273,7 @@ static FORCE_INLINE int32_t tdSetBitmapValType(void *pBitmap, int16_t colIdx, TD
}
int16_t
nBytes
=
colIdx
/
TD_VTYPE_PARTS
;
int16_t
nOffset
=
colIdx
&
TD_VTYPE_OPTR
;
char
*
pDestByte
=
(
char
*
)
POINTER_SHIFT
(
pBitmap
,
nBytes
);
char
*
pDestByte
=
(
char
*
)
POINTER_SHIFT
(
pBitmap
,
nBytes
);
switch
(
nOffset
)
{
case
0
:
*
pDestByte
=
((
*
pDestByte
)
&
0x3F
)
|
(
valType
<<
6
);
...
...
@@ -311,7 +311,7 @@ static FORCE_INLINE int32_t tdGetBitmapValType(void *pBitmap, int16_t colIdx, TD
}
int16_t
nBytes
=
colIdx
/
TD_VTYPE_PARTS
;
int16_t
nOffset
=
colIdx
&
TD_VTYPE_OPTR
;
char
*
pDestByte
=
(
char
*
)
POINTER_SHIFT
(
pBitmap
,
nBytes
);
char
*
pDestByte
=
(
char
*
)
POINTER_SHIFT
(
pBitmap
,
nBytes
);
switch
(
nOffset
)
{
case
0
:
*
pValType
=
(((
*
pDestByte
)
&
0xC0
)
>>
6
);
...
...
@@ -617,7 +617,7 @@ static FORCE_INLINE int32_t tdAppendColValToKvRow(SRowBuilder *pBuilder, TDRowVa
if
(
tdValIsNorm
(
valType
,
val
,
colType
))
{
// ts key stored in STSRow.ts
SKvRowIdx
*
pColIdx
=
(
SKvRowIdx
*
)
POINTER_SHIFT
(
TD_ROW_COL_IDX
(
row
),
offset
);
char
*
ptr
=
(
char
*
)
POINTER_SHIFT
(
row
,
TD_ROW_LEN
(
row
));
char
*
ptr
=
(
char
*
)
POINTER_SHIFT
(
row
,
TD_ROW_LEN
(
row
));
pColIdx
->
colId
=
colId
;
pColIdx
->
offset
=
TD_ROW_LEN
(
row
);
// the offset include the TD_ROW_HEAD_LEN
...
...
@@ -635,7 +635,7 @@ static FORCE_INLINE int32_t tdAppendColValToKvRow(SRowBuilder *pBuilder, TDRowVa
// NULL/None value
else
{
SKvRowIdx
*
pColIdx
=
(
SKvRowIdx
*
)
POINTER_SHIFT
(
TD_ROW_COL_IDX
(
row
),
offset
);
char
*
ptr
=
(
char
*
)
POINTER_SHIFT
(
row
,
TD_ROW_LEN
(
row
));
char
*
ptr
=
(
char
*
)
POINTER_SHIFT
(
row
,
TD_ROW_LEN
(
row
));
pColIdx
->
colId
=
colId
;
pColIdx
->
offset
=
TD_ROW_LEN
(
row
);
// the offset include the TD_ROW_HEAD_LEN
const
void
*
nullVal
=
getNullValue
(
colType
);
...
...
@@ -697,9 +697,9 @@ static FORCE_INLINE int32_t tdAppendColValToRow(SRowBuilder *pBuilder, int16_t c
}
// TODO: We can avoid the type judegement by FP, but would prevent the inline scheme.
if
(
TD_IS_TP_ROW
(
pRow
))
{
tdAppendColValToTpRow
(
pBuilder
,
valType
,
val
,
true
,
colType
,
colIdx
,
offset
);
tdAppendColValToTpRow
(
pBuilder
,
valType
,
val
,
isCopyVarData
,
colType
,
colIdx
,
offset
);
}
else
{
tdAppendColValToKvRow
(
pBuilder
,
valType
,
val
,
true
,
colType
,
colIdx
,
offset
,
colId
);
tdAppendColValToKvRow
(
pBuilder
,
valType
,
val
,
isCopyVarData
,
colType
,
colIdx
,
offset
,
colId
);
}
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -771,8 +771,8 @@ static FORCE_INLINE int32_t tdGetKvRowValOfCol(SCellVal *output, STSRow *pRow, v
typedef
struct
{
STSchema
*
pSchema
;
STSRow
*
pRow
;
void
*
pBitmap
;
STSRow
*
pRow
;
void
*
pBitmap
;
uint32_t
offset
;
col_id_t
maxColId
;
col_id_t
colIdx
;
// [PRIMARYKEY_TIMESTAMP_COL_ID, nSchemaCols], PRIMARYKEY_TIMESTAMP_COL_ID equals 1
...
...
@@ -877,7 +877,7 @@ static FORCE_INLINE bool tdGetTpRowDataOfCol(STSRowIter *pIter, col_type_t colTy
// internal
static
FORCE_INLINE
bool
tdGetKvRowValOfColEx
(
STSRowIter
*
pIter
,
col_id_t
colId
,
col_type_t
colType
,
col_id_t
*
nIdx
,
SCellVal
*
pVal
)
{
STSRow
*
pRow
=
pIter
->
pRow
;
STSRow
*
pRow
=
pIter
->
pRow
;
SKvRowIdx
*
pKvIdx
=
NULL
;
bool
colFound
=
false
;
col_id_t
kvNCols
=
tdRowGetNCols
(
pRow
);
...
...
@@ -1068,7 +1068,7 @@ typedef struct {
typedef
struct
{
STSchema
*
pSchema
;
STSRow
*
pRow
;
STSRow
*
pRow
;
}
STSRowReader
;
typedef
struct
{
...
...
include/dnode/snode/snode.h
浏览文件 @
7eb4153a
...
...
@@ -16,6 +16,7 @@
#ifndef _TD_SNODE_H_
#define _TD_SNODE_H_
#include "tcommon.h"
#include "tmsg.h"
#include "trpc.h"
...
...
@@ -78,7 +79,7 @@ int32_t sndGetLoad(SSnode *pSnode, SSnodeLoad *pLoad);
* @param pRsp The response message
* @return int32_t 0 for success, -1 for failure
*/
int32_t
sndProcessMsg
(
SSnode
*
pSnode
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
pRsp
);
//
int32_t sndProcessMsg(SSnode *pSnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
int32_t
sndProcessUMsg
(
SSnode
*
pSnode
,
SRpcMsg
*
pMsg
);
...
...
include/libs/nodes/plannodes.h
浏览文件 @
7eb4153a
...
...
@@ -69,7 +69,7 @@ typedef struct SProjectLogicNode {
}
SProjectLogicNode
;
typedef
struct
SVnodeModifLogicNode
{
SLogicNode
node
;
;
SLogicNode
node
;
int32_t
msgType
;
SArray
*
pDataBlocks
;
SVgDataBlocks
*
pVgDataBlocks
;
...
...
@@ -124,7 +124,7 @@ typedef struct SSubLogicPlan {
}
SSubLogicPlan
;
typedef
struct
SQueryLogicPlan
{
ENodeType
type
;
;
ENodeType
type
;
int32_t
totalLevel
;
SNodeList
*
pTopSubplans
;
}
SQueryLogicPlan
;
...
...
@@ -252,7 +252,7 @@ typedef struct SSubplan {
}
SSubplan
;
typedef
struct
SQueryPlan
{
ENodeType
type
;
;
ENodeType
type
;
uint64_t
queryId
;
int32_t
numOfSubplans
;
SNodeList
*
pSubplans
;
// Element is SNodeListNode. The execution level of subplan, starting from 0.
...
...
include/libs/transport/trpc.h
浏览文件 @
7eb4153a
...
...
@@ -38,11 +38,14 @@ typedef struct SRpcConnInfo {
typedef
struct
SRpcMsg
{
tmsg_t
msgType
;
tmsg_t
expectMsgType
;
void
*
pCont
;
int
contLen
;
int32_t
code
;
void
*
handle
;
// rpc handle returned to app
void
*
ahandle
;
// app handle set by client
int
noResp
;
// has response or not(default 0 indicate resp);
}
SRpcMsg
;
typedef
struct
SRpcInit
{
...
...
include/os/os.h
浏览文件 @
7eb4153a
...
...
@@ -25,10 +25,11 @@ extern "C" {
#include <pthread.h>
#include <semaphore.h>
#include <regex.h>
#if !defined(WINDOWS)
#include <unistd.h>
#include <dirent.h>
#include <regex.h>
#include <sched.h>
#include <wordexp.h>
#include <libgen.h>
...
...
@@ -36,6 +37,12 @@ extern "C" {
#include <sys/utsname.h>
#include <sys/param.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <termios.h>
#include <sys/statvfs.h>
#if defined(DARWIN)
#else
...
...
@@ -61,12 +68,7 @@ extern "C" {
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <wchar.h>
#include <termios.h>
#include <wctype.h>
...
...
include/os/osDef.h
浏览文件 @
7eb4153a
...
...
@@ -56,6 +56,7 @@ extern "C" {
// specific
typedef
int
(
*
__compar_fn_t
)(
const
void
*
,
const
void
*
);
#define ssize_t int
#define _SSIZE_T_
#define bzero(ptr, size) memset((ptr), 0, (size))
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
...
...
include/os/osFile.h
浏览文件 @
7eb4153a
...
...
@@ -24,7 +24,7 @@ extern "C" {
#if defined(WINDOWS)
typedef
int32_t
FileFd
;
typedef
SOCKET
SocketFd
;
typedef
int32_t
SocketFd
;
#else
typedef
int32_t
FileFd
;
typedef
int32_t
SocketFd
;
...
...
include/os/osSocket.h
浏览文件 @
7eb4153a
...
...
@@ -25,6 +25,8 @@
#define epoll_create EPOLL_CREATE_FUNC_TAOS_FORBID
#define epoll_ctl EPOLL_CTL_FUNC_TAOS_FORBID
#define epoll_wait EPOLL_WAIT_FUNC_TAOS_FORBID
#define inet_addr INET_ADDR_FUNC_TAOS_FORBID
#define inet_ntoa INET_NTOA_FUNC_TAOS_FORBID
#endif
#if defined(WINDOWS)
...
...
include/os/osSysinfo.h
浏览文件 @
7eb4153a
...
...
@@ -16,7 +16,6 @@
#ifndef _TD_OS_SYSINFO_H_
#define _TD_OS_SYSINFO_H_
#include <sys/statvfs.h>
#include "os.h"
#ifdef __cplusplus
...
...
include/util/taoserror.h
浏览文件 @
7eb4153a
...
...
@@ -354,6 +354,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_TDB_IVLD_TAG_VAL TAOS_DEF_ERROR_CODE(0, 0x0615)
#define TSDB_CODE_TDB_NO_CACHE_LAST_ROW TAOS_DEF_ERROR_CODE(0, 0x0616)
#define TSDB_CODE_TDB_NO_SMA_INDEX_IN_META TAOS_DEF_ERROR_CODE(0, 0x0617)
#define TSDB_CODE_TDB_TDB_ENV_OPEN_ERROR TAOS_DEF_ERROR_CODE(0, 0x0618)
// query
#define TSDB_CODE_QRY_INVALID_QHANDLE TAOS_DEF_ERROR_CODE(0, 0x0700)
...
...
include/util/tencode.h
浏览文件 @
7eb4153a
...
...
@@ -75,7 +75,7 @@ typedef struct {
#define TD_CODER_CURRENT(CODER) ((CODER)->data + (CODER)->pos)
#define TD_CODER_MOVE_POS(CODER, MOVE) ((CODER)->pos += (MOVE))
#define TD_CODER_CHECK_CAPACITY_FAILED(CODER, EXPSIZE) (((CODER)->size - (CODER)->pos) < (EXPSIZE))
#define TCODER_MALLOC(
SIZE, CODER) TFL_MALLOC(
SIZE, &((CODER)->fl))
#define TCODER_MALLOC(
PTR, TYPE, SIZE, CODER) TFL_MALLOC(PTR, TYPE,
SIZE, &((CODER)->fl))
void
tCoderInit
(
SCoder
*
pCoder
,
td_endian_t
endian
,
uint8_t
*
data
,
int32_t
size
,
td_coder_t
type
);
void
tCoderClear
(
SCoder
*
pCoder
);
...
...
@@ -402,6 +402,29 @@ static int32_t tDecodeCStrTo(SCoder* pDecoder, char* val) {
return
0
;
}
static
FORCE_INLINE
int32_t
tDecodeBinaryAlloc
(
SCoder
*
pDecoder
,
void
**
val
,
uint64_t
*
len
)
{
if
(
tDecodeU64v
(
pDecoder
,
len
)
<
0
)
return
-
1
;
if
(
TD_CODER_CHECK_CAPACITY_FAILED
(
pDecoder
,
*
len
))
return
-
1
;
*
val
=
malloc
(
*
len
);
if
(
*
val
==
NULL
)
return
-
1
;
memcpy
(
*
val
,
TD_CODER_CURRENT
(
pDecoder
),
*
len
);
TD_CODER_MOVE_POS
(
pDecoder
,
*
len
);
return
0
;
}
static
FORCE_INLINE
int32_t
tDecodeCStrAndLenAlloc
(
SCoder
*
pDecoder
,
char
**
val
,
uint64_t
*
len
)
{
if
(
tDecodeBinaryAlloc
(
pDecoder
,
(
void
**
)
val
,
len
)
<
0
)
return
-
1
;
(
*
len
)
-=
1
;
return
0
;
}
static
FORCE_INLINE
int32_t
tDecodeCStrAlloc
(
SCoder
*
pDecoder
,
char
**
val
)
{
uint64_t
len
;
return
tDecodeCStrAndLenAlloc
(
pDecoder
,
val
,
&
len
);
}
static
FORCE_INLINE
bool
tDecodeIsEnd
(
SCoder
*
pCoder
)
{
return
(
pCoder
->
size
==
pCoder
->
pos
);
}
#ifdef __cplusplus
...
...
include/util/tfreelist.h
浏览文件 @
7eb4153a
...
...
@@ -29,15 +29,17 @@ struct SFreeListNode {
typedef
TD_SLIST
(
SFreeListNode
)
SFreeList
;
#define TFL_MALLOC(
SIZE, LIST)
\
({
\
#define TFL_MALLOC(
PTR, TYPE, SIZE, LIST)
\
do {
\
void *ptr = malloc((SIZE) + sizeof(struct SFreeListNode)); \
if (ptr) { \
TD_SLIST_PUSH((LIST), (struct SFreeListNode *)ptr); \
ptr = ((struct SFreeListNode *)ptr)->payload; \
(PTR) = (TYPE)(ptr); \
}else{ \
(PTR) = NULL; \
} \
ptr; \
})
}while(0);
#define tFreeListInit(pFL) TD_SLIST_INIT(pFL)
...
...
include/util/types.h
浏览文件 @
7eb4153a
...
...
@@ -82,7 +82,7 @@ typedef uint16_t VarDataLenT; // maxVarDataLen: 32767
#define VARSTR_HEADER_SIZE sizeof(VarDataLenT)
#define varDataLen(v) ((VarDataLenT *)(v))[0]
#define varDataVal(v) ((
void *)((char *)v + VARSTR_HEADER_SIZE)
)
#define varDataVal(v) ((
char *)(v) + VARSTR_HEADER_SIZE
)
typedef
int32_t
VarDataOffsetT
;
...
...
source/common/src/tmsg.c
浏览文件 @
7eb4153a
...
...
@@ -1467,8 +1467,7 @@ int32_t tDeserializeSUseDbReq(void *buf, int32_t bufLen, SUseDbReq *pReq) {
return
0
;
}
int32_t
tSerializeSQnodeListReq
(
void
*
buf
,
int32_t
bufLen
,
SQnodeListReq
*
pReq
)
{
int32_t
tSerializeSQnodeListReq
(
void
*
buf
,
int32_t
bufLen
,
SQnodeListReq
*
pReq
)
{
SCoder
encoder
=
{
0
};
tCoderInit
(
&
encoder
,
TD_LITTLE_ENDIAN
,
buf
,
bufLen
,
TD_ENCODER
);
...
...
@@ -2468,7 +2467,7 @@ int32_t tEncodeSMqCMCommitOffsetReq(SCoder *encoder, const SMqCMCommitOffsetReq
int32_t
tDecodeSMqCMCommitOffsetReq
(
SCoder
*
decoder
,
SMqCMCommitOffsetReq
*
pReq
)
{
if
(
tStartDecode
(
decoder
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
decoder
,
&
pReq
->
num
)
<
0
)
return
-
1
;
pReq
->
offsets
=
TCODER_MALLOC
(
pReq
->
num
*
sizeof
(
SMqOffset
),
decoder
);
TCODER_MALLOC
(
pReq
->
offsets
,
SMqOffset
*
,
pReq
->
num
*
sizeof
(
SMqOffset
),
decoder
);
if
(
pReq
->
offsets
==
NULL
)
return
-
1
;
for
(
int32_t
i
=
0
;
i
<
pReq
->
num
;
i
++
)
{
tDecodeSMqOffset
(
decoder
,
&
pReq
->
offsets
[
i
]);
...
...
@@ -2556,8 +2555,6 @@ int32_t tDeserializeSSchedulerHbReq(void *buf, int32_t bufLen, SSchedulerHbReq *
void
tFreeSSchedulerHbReq
(
SSchedulerHbReq
*
pReq
)
{
taosArrayDestroy
(
pReq
->
taskAction
);
}
int32_t
tSerializeSSchedulerHbRsp
(
void
*
buf
,
int32_t
bufLen
,
SSchedulerHbRsp
*
pRsp
)
{
SCoder
encoder
=
{
0
};
tCoderInit
(
&
encoder
,
TD_LITTLE_ENDIAN
,
buf
,
bufLen
,
TD_ENCODER
);
...
...
@@ -2677,9 +2674,9 @@ int32_t tDeserializeSCMCreateStreamReq(void *buf, int32_t bufLen, SCMCreateStrea
if
(
tStartDecode
(
&
decoder
)
<
0
)
return
-
1
;
if
(
tDecodeCStrTo
(
&
decoder
,
pReq
->
name
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
&
decoder
,
&
pReq
->
igExists
)
<
0
)
return
-
1
;
if
(
tDecodeCStr
(
&
decoder
,
(
const
char
**
)
&
pReq
->
sql
)
<
0
)
return
-
1
;
if
(
tDecodeCStr
(
&
decoder
,
(
const
char
**
)
&
pReq
->
physicalPlan
)
<
0
)
return
-
1
;
if
(
tDecodeCStr
(
&
decoder
,
(
const
char
**
)
&
pReq
->
logicalPlan
)
<
0
)
return
-
1
;
if
(
tDecodeCStr
Alloc
(
&
decoder
,
&
pReq
->
sql
)
<
0
)
return
-
1
;
if
(
tDecodeCStr
Alloc
(
&
decoder
,
&
pReq
->
physicalPlan
)
<
0
)
return
-
1
;
if
(
tDecodeCStr
Alloc
(
&
decoder
,
&
pReq
->
logicalPlan
)
<
0
)
return
-
1
;
tEndDecode
(
&
decoder
);
tCoderClear
(
&
decoder
);
...
...
@@ -2691,3 +2688,32 @@ void tFreeSCMCreateStreamReq(SCMCreateStreamReq *pReq) {
tfree
(
pReq
->
physicalPlan
);
tfree
(
pReq
->
logicalPlan
);
}
int32_t
tEncodeSStreamTask
(
SCoder
*
pEncoder
,
const
SStreamTask
*
pTask
)
{
if
(
tStartEncode
(
pEncoder
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pEncoder
,
pTask
->
streamId
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
pEncoder
,
pTask
->
taskId
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
pEncoder
,
pTask
->
level
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pEncoder
,
pTask
->
status
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
pEncoder
,
pTask
->
qmsg
)
<
0
)
return
-
1
;
tEndEncode
(
pEncoder
);
return
pEncoder
->
pos
;
}
int32_t
tDecodeSStreamTask
(
SCoder
*
pDecoder
,
SStreamTask
*
pTask
)
{
if
(
tStartDecode
(
pDecoder
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pDecoder
,
&
pTask
->
streamId
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pDecoder
,
&
pTask
->
taskId
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pDecoder
,
&
pTask
->
level
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pDecoder
,
&
pTask
->
status
)
<
0
)
return
-
1
;
if
(
tDecodeCStrAlloc
(
pDecoder
,
&
pTask
->
qmsg
)
<
0
)
return
-
1
;
tEndDecode
(
pDecoder
);
return
0
;
}
void
tFreeSStreamTask
(
SStreamTask
*
pTask
)
{
// TODO
/*free(pTask->qmsg);*/
/*free(pTask->executor);*/
/*free(pTask);*/
}
source/common/src/tname.c
浏览文件 @
7eb4153a
...
...
@@ -217,7 +217,7 @@ int32_t tNameSetDbName(SName* dst, int32_t acct, const char* dbName, size_t name
}
int32_t
tNameSetAcctId
(
SName
*
dst
,
int32_t
acctId
)
{
assert
(
dst
!=
NULL
&&
acct
!=
NULL
);
assert
(
dst
!=
NULL
);
dst
->
acctId
=
acctId
;
return
0
;
}
...
...
source/dnode/mgmt/impl/src/dndSnode.c
浏览文件 @
7eb4153a
...
...
@@ -323,7 +323,7 @@ int32_t dndProcessDropSnodeReq(SDnode *pDnode, SRpcMsg *pReq) {
}
static
void
dndProcessSnodeUniqueQueue
(
SDnode
*
pDnode
,
STaosQall
*
qall
,
int32_t
numOfMsgs
)
{
SSnodeMgmt
*
pMgmt
=
&
pDnode
->
smgmt
;
/*SSnodeMgmt *pMgmt = &pDnode->smgmt;*/
int32_t
code
=
TSDB_CODE_DND_SNODE_NOT_DEPLOYED
;
SSnode
*
pSnode
=
dndAcquireSnode
(
pDnode
);
...
...
@@ -337,19 +337,32 @@ static void dndProcessSnodeUniqueQueue(SDnode *pDnode, STaosQall *qall, int32_t
rpcFreeCont
(
pMsg
->
pCont
);
taosFreeQitem
(
pMsg
);
}
}
dndReleaseSnode
(
pDnode
,
pSnode
);
}
else
{
for
(
int32_t
i
=
0
;
i
<
numOfMsgs
;
i
++
)
{
SRpcMsg
*
pMsg
=
NULL
;
taosGetQitem
(
qall
,
(
void
**
)
&
pMsg
);
SRpcMsg
rpcRsp
=
{.
handle
=
pMsg
->
handle
,
.
ahandle
=
pMsg
->
ahandle
,
.
code
=
code
};
rpcSendResponse
(
&
rpcRsp
);
rpcFreeCont
(
pMsg
->
pCont
);
taosFreeQitem
(
pMsg
);
}
}
}
static
void
dndProcessSnodeSharedQueue
(
SDnode
*
pDnode
,
SRpcMsg
*
pMsg
)
{
SSnodeMgmt
*
pMgmt
=
&
pDnode
->
smgmt
;
/*SSnodeMgmt *pMgmt = &pDnode->smgmt;*/
int32_t
code
=
TSDB_CODE_DND_SNODE_NOT_DEPLOYED
;
SSnode
*
pSnode
=
dndAcquireSnode
(
pDnode
);
if
(
pSnode
!=
NULL
)
{
code
=
sndProcessSMsg
(
pSnode
,
pMsg
);
}
sndProcessSMsg
(
pSnode
,
pMsg
);
dndReleaseSnode
(
pDnode
,
pSnode
);
}
else
{
SRpcMsg
rpcRsp
=
{.
handle
=
pMsg
->
handle
,
.
ahandle
=
pMsg
->
ahandle
,
.
code
=
code
};
rpcSendResponse
(
&
rpcRsp
);
}
#if 0
if (pMsg->msgType & 1u) {
...
...
source/dnode/mnode/impl/inc/mndDef.h
浏览文件 @
7eb4153a
...
...
@@ -85,6 +85,8 @@ typedef enum {
TRN_TYPE_REBALANCE
=
1017
,
TRN_TYPE_COMMIT_OFFSET
=
1018
,
TRN_TYPE_CREATE_STREAM
=
1019
,
TRN_TYPE_DROP_STREAM
=
1020
,
TRN_TYPE_ALTER_STREAM
=
1021
,
TRN_TYPE_BASIC_SCOPE_END
,
TRN_TYPE_GLOBAL_SCOPE
=
2000
,
TRN_TYPE_CREATE_DNODE
=
2001
,
...
...
@@ -679,12 +681,6 @@ static FORCE_INLINE void* tDecodeSMqConsumerObj(void* buf, SMqConsumerObj* pCons
return
buf
;
}
typedef
struct
{
int32_t
taskId
;
int32_t
level
;
SSubplan
*
plan
;
}
SStreamTaskMeta
;
typedef
struct
{
char
name
[
TSDB_TOPIC_FNAME_LEN
];
char
db
[
TSDB_DB_FNAME_LEN
];
...
...
@@ -700,7 +696,7 @@ typedef struct {
char
*
sql
;
char
*
logicalPlan
;
char
*
physicalPlan
;
SArray
*
tasks
;
// SArray<SArray<SStreamTask
Meta
>>
SArray
*
tasks
;
// SArray<SArray<SStreamTask>>
}
SStreamObj
;
int32_t
tEncodeSStreamObj
(
SCoder
*
pEncoder
,
const
SStreamObj
*
pObj
);
...
...
source/dnode/mnode/impl/inc/mndScheduler.h
浏览文件 @
7eb4153a
...
...
@@ -27,6 +27,8 @@ void mndCleanupScheduler(SMnode* pMnode);
int32_t
mndSchedInitSubEp
(
SMnode
*
pMnode
,
const
SMqTopicObj
*
pTopic
,
SMqSubscribeObj
*
pSub
);
int32_t
mndScheduleStream
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SStreamObj
*
pStream
);
#ifdef __cplusplus
}
#endif
...
...
source/dnode/mnode/impl/src/mndDef.c
浏览文件 @
7eb4153a
...
...
@@ -39,8 +39,8 @@ int32_t tDecodeSStreamObj(SCoder *pDecoder, SStreamObj *pObj) {
if
(
tDecodeI64
(
pDecoder
,
&
pObj
->
dbUid
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pDecoder
,
&
pObj
->
version
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pDecoder
,
&
pObj
->
status
)
<
0
)
return
-
1
;
if
(
tDecodeCStr
(
pDecoder
,
(
const
char
**
)
&
pObj
->
sql
)
<
0
)
return
-
1
;
if
(
tDecodeCStr
(
pDecoder
,
(
const
char
**
)
&
pObj
->
logicalPlan
)
<
0
)
return
-
1
;
if
(
tDecodeCStr
(
pDecoder
,
(
const
char
**
)
&
pObj
->
physicalPlan
)
<
0
)
return
-
1
;
if
(
tDecodeCStr
Alloc
(
pDecoder
,
&
pObj
->
sql
)
<
0
)
return
-
1
;
if
(
tDecodeCStr
Alloc
(
pDecoder
,
&
pObj
->
logicalPlan
)
<
0
)
return
-
1
;
if
(
tDecodeCStr
Alloc
(
pDecoder
,
&
pObj
->
physicalPlan
)
<
0
)
return
-
1
;
return
0
;
}
source/dnode/mnode/impl/src/mndScheduler.c
浏览文件 @
7eb4153a
...
...
@@ -31,7 +31,7 @@
#include "tname.h"
#include "tuuid.h"
int32_t
mndScheduleStream
(
SMnode
*
pMnode
,
SStreamObj
*
pStream
)
{
int32_t
mndScheduleStream
(
SMnode
*
pMnode
,
S
Trans
*
pTrans
,
S
StreamObj
*
pStream
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SVgObj
*
pVgroup
=
NULL
;
SQueryPlan
*
pPlan
=
qStringToQueryPlan
(
pStream
->
physicalPlan
);
...
...
@@ -41,17 +41,18 @@ int32_t mndScheduleStream(SMnode* pMnode, SStreamObj* pStream) {
}
ASSERT
(
pStream
->
vgNum
==
0
);
int32_t
levelNum
=
LIST_LENGTH
(
pPlan
->
pSubplans
);
pStream
->
tasks
=
taosArrayInit
(
levelNum
,
sizeof
(
SArray
));
int32_t
totLevel
=
LIST_LENGTH
(
pPlan
->
pSubplans
);
pStream
->
tasks
=
taosArrayInit
(
totLevel
,
sizeof
(
SArray
));
for
(
int32_t
i
=
0
;
i
<
levelNum
;
i
++
)
{
SArray
*
taskOneLevel
=
taosArrayInit
(
0
,
sizeof
(
SStreamTaskMeta
));
SNodeListNode
*
inner
=
nodesListGetNode
(
pPlan
->
pSubplans
,
i
);
int32_t
msgLen
;
for
(
int32_t
level
=
0
;
level
<
totLevel
;
level
++
)
{
SArray
*
taskOneLevel
=
taosArrayInit
(
0
,
sizeof
(
SStreamTask
));
SNodeListNode
*
inner
=
nodesListGetNode
(
pPlan
->
pSubplans
,
level
);
int32_t
opNum
=
LIST_LENGTH
(
inner
->
pNodeList
);
ASSERT
(
opNum
==
1
);
SSubplan
*
plan
=
nodesListGetNode
(
inner
->
pNodeList
,
0
);
if
(
i
==
0
)
{
SSubplan
*
plan
=
nodesListGetNode
(
inner
->
pNodeList
,
level
);
if
(
level
==
0
)
{
ASSERT
(
plan
->
type
==
SUBPLAN_TYPE_SCAN
);
void
*
pIter
=
NULL
;
while
(
1
)
{
...
...
@@ -63,15 +64,19 @@ int32_t mndScheduleStream(SMnode* pMnode, SStreamObj* pStream) {
}
pStream
->
vgNum
++
;
// send to vnode
SStreamTask
*
pTask
=
streamTaskNew
(
pStream
->
uid
,
level
);
plan
->
execNode
.
nodeId
=
pVgroup
->
vgId
;
plan
->
execNode
.
epSet
=
mndGetVgroupEpset
(
pMnode
,
pVgroup
);
SStreamTaskMeta
task
=
{
.
taskId
=
tGenIdPI32
(),
.
level
=
i
,
.
plan
=
plan
,
}
;
// send to vnode
taosArrayPush
(
taskOneLevel
,
&
t
ask
);
if
(
qSubPlanToString
(
plan
,
&
pTask
->
qmsg
,
&
msgLen
)
<
0
)
{
sdbRelease
(
pSdb
,
pVgroup
);
qDestroyQueryPlan
(
pPlan
);
terrno
=
TSDB_CODE_QRY_INVALID_INPUT
;
return
-
1
;
}
taosArrayPush
(
taskOneLevel
,
pT
ask
);
}
}
else
if
(
plan
->
subplanType
==
SUBPLAN_TYPE_SCAN
)
{
// duplicatable
...
...
@@ -82,22 +87,36 @@ int32_t mndScheduleStream(SMnode* pMnode, SStreamObj* pStream) {
// if has snode, set to shared thread num in snode
parallel
=
SND_SHARED_THREAD_NUM
;
for
(
int32_t
j
=
0
;
j
<
parallel
;
j
++
)
{
SStreamTaskMeta
task
=
{
.
taskId
=
tGenIdPI32
(),
.
level
=
i
,
.
plan
=
plan
,
};
taosArrayPush
(
taskOneLevel
,
&
task
);
for
(
int32_t
i
=
0
;
i
<
parallel
;
i
++
)
{
SStreamTask
*
pTask
=
streamTaskNew
(
pStream
->
uid
,
level
);
// TODO:get snode id and ep
plan
->
execNode
.
nodeId
=
pVgroup
->
vgId
;
plan
->
execNode
.
epSet
=
mndGetVgroupEpset
(
pMnode
,
pVgroup
);
if
(
qSubPlanToString
(
plan
,
&
pTask
->
qmsg
,
&
msgLen
)
<
0
)
{
qDestroyQueryPlan
(
pPlan
);
terrno
=
TSDB_CODE_QRY_INVALID_INPUT
;
return
-
1
;
}
taosArrayPush
(
taskOneLevel
,
pTask
);
}
}
else
{
// not duplicatable
SStreamTaskMeta
task
=
{
.
taskId
=
tGenIdPI32
(),
.
level
=
i
,
.
plan
=
plan
,
};
taosArrayPush
(
taskOneLevel
,
&
task
);
SStreamTask
*
pTask
=
streamTaskNew
(
pStream
->
uid
,
level
);
// TODO:get snode id and ep
plan
->
execNode
.
nodeId
=
pVgroup
->
vgId
;
plan
->
execNode
.
epSet
=
mndGetVgroupEpset
(
pMnode
,
pVgroup
);
if
(
qSubPlanToString
(
plan
,
&
pTask
->
qmsg
,
&
msgLen
)
<
0
)
{
sdbRelease
(
pSdb
,
pVgroup
);
qDestroyQueryPlan
(
pPlan
);
terrno
=
TSDB_CODE_QRY_INVALID_INPUT
;
return
-
1
;
}
taosArrayPush
(
taskOneLevel
,
pTask
);
}
taosArrayPush
(
pStream
->
tasks
,
taskOneLevel
);
}
...
...
source/dnode/mnode/impl/src/mndStream.c
浏览文件 @
7eb4153a
...
...
@@ -18,6 +18,7 @@
#include "mndDb.h"
#include "mndDnode.h"
#include "mndMnode.h"
#include "mndScheduler.h"
#include "mndShow.h"
#include "mndStb.h"
#include "mndTrans.h"
...
...
@@ -237,6 +238,12 @@ static int32_t mndCreateStream(SMnode *pMnode, SMnodeMsg *pReq, SCMCreateStreamR
}
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_READY
);
if
(
mndScheduleStream
(
pMnode
,
pTrans
,
&
streamObj
)
<
0
)
{
mError
(
"stream:%ld, schedule stream since %s"
,
streamObj
.
uid
,
terrstr
());
mndTransDrop
(
pTrans
);
return
-
1
;
}
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
mndTransDrop
(
pTrans
);
...
...
source/dnode/snode/CMakeLists.txt
浏览文件 @
7eb4153a
...
...
@@ -7,6 +7,7 @@ target_include_directories(
)
target_link_libraries
(
snode
PRIVATE executor
PRIVATE transport
PRIVATE os
PRIVATE common
...
...
source/dnode/snode/inc/sndInt.h
浏览文件 @
7eb4153a
...
...
@@ -38,13 +38,8 @@ enum {
STREAM_STATUS__DELETING
,
};
enum
{
STREAM_TASK_STATUS__RUNNING
=
1
,
STREAM_TASK_STATUS__STOP
,
};
typedef
struct
{
SHashObj
*
pHash
;
// taskId ->
s
treamTask
SHashObj
*
pHash
;
// taskId ->
SS
treamTask
}
SStreamMeta
;
typedef
struct
SSnode
{
...
...
@@ -52,26 +47,17 @@ typedef struct SSnode {
SSnodeOpt
cfg
;
}
SSnode
;
typedef
struct
{
int64_t
streamId
;
int32_t
taskId
;
int32_t
IdxInLevel
;
int32_t
level
;
}
SStreamTaskInfo
;
SStreamMeta
*
sndMetaNew
();
void
sndMetaDelete
(
SStreamMeta
*
pMeta
);
typedef
struct
{
SStreamTaskInfo
meta
;
int8_t
status
;
void
*
executor
;
void
*
stateStore
;
// storage handle
}
SStreamTask
;
int32_t
sndMetaDeployTask
(
SStreamMeta
*
pMeta
,
SStreamTask
*
pTask
);
SStreamTask
*
sndMetaGetTask
(
SStreamMeta
*
pMeta
,
int32_t
taskId
);
int32_t
sndMetaRemoveTask
(
SStreamMeta
*
pMeta
,
int32_t
taskId
);
int32_t
sndCreateTask
();
int32_t
sndDropTaskOfStream
(
int64_t
streamId
);
int32_t
sndDropTaskOfStream
(
SStreamMeta
*
pMeta
,
int64_t
streamId
);
int32_t
sndStopTaskOfStream
(
int64_t
streamId
);
int32_t
sndResumeTaskOfStream
(
int64_t
streamId
);
int32_t
sndStopTaskOfStream
(
SStreamMeta
*
pMeta
,
int64_t
streamId
);
int32_t
sndResumeTaskOfStream
(
SStreamMeta
*
pMeta
,
int64_t
streamId
);
#ifdef __cplusplus
}
...
...
source/dnode/snode/src/snode.c
浏览文件 @
7eb4153a
...
...
@@ -13,44 +13,116 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "executor.h"
#include "sndInt.h"
#include "tuuid.h"
SSnode
*
sndOpen
(
const
char
*
path
,
const
SSnodeOpt
*
pOption
)
{
SSnode
*
pSnode
=
calloc
(
1
,
sizeof
(
SSnode
));
if
(
pSnode
==
NULL
)
{
return
NULL
;
}
memcpy
(
&
pSnode
->
cfg
,
pOption
,
sizeof
(
SSnodeOpt
));
pSnode
->
pMeta
=
sndMetaNew
();
if
(
pSnode
->
pMeta
==
NULL
)
{
free
(
pSnode
);
return
NULL
;
}
return
pSnode
;
}
void
sndClose
(
SSnode
*
pSnode
)
{
free
(
pSnode
);
}
void
sndClose
(
SSnode
*
pSnode
)
{
sndMetaDelete
(
pSnode
->
pMeta
);
free
(
pSnode
);
}
int32_t
sndGetLoad
(
SSnode
*
pSnode
,
SSnodeLoad
*
pLoad
)
{
return
0
;
}
int32_t
sndProcessMsg
(
SSnode
*
pSnode
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
pRsp
)
{
*
pRsp
=
NULL
;
return
0
;
}
/*int32_t sndProcessMsg(SSnode *pSnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {*/
/**pRsp = NULL;*/
/*return 0;*/
/*}*/
void
sndDestroy
(
const
char
*
path
)
{}
static
int32_t
sndDeployTask
(
SSnode
*
pSnode
,
SRpcMsg
*
pMsg
)
{
SStreamTask
*
task
=
malloc
(
sizeof
(
SStreamTask
));
if
(
task
==
NULL
)
{
SStreamMeta
*
sndMetaNew
()
{
SStreamMeta
*
pMeta
=
calloc
(
1
,
sizeof
(
SStreamMeta
));
if
(
pMeta
==
NULL
)
{
return
NULL
;
}
pMeta
->
pHash
=
taosHashInit
(
64
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
),
true
,
HASH_NO_LOCK
);
if
(
pMeta
->
pHash
==
NULL
)
{
free
(
pMeta
);
return
NULL
;
}
return
pMeta
;
}
void
sndMetaDelete
(
SStreamMeta
*
pMeta
)
{
taosHashCleanup
(
pMeta
->
pHash
);
free
(
pMeta
);
}
int32_t
sndMetaDeployTask
(
SStreamMeta
*
pMeta
,
SStreamTask
*
pTask
)
{
pTask
->
executor
=
qCreateStreamExecTaskInfo
(
pTask
->
qmsg
,
NULL
);
return
taosHashPut
(
pMeta
->
pHash
,
&
pTask
->
taskId
,
sizeof
(
int32_t
),
pTask
,
sizeof
(
void
*
));
}
SStreamTask
*
sndMetaGetTask
(
SStreamMeta
*
pMeta
,
int32_t
taskId
)
{
return
taosHashGet
(
pMeta
->
pHash
,
&
taskId
,
sizeof
(
int32_t
));
}
int32_t
sndMetaRemoveTask
(
SStreamMeta
*
pMeta
,
int32_t
taskId
)
{
SStreamTask
*
pTask
=
taosHashGet
(
pMeta
->
pHash
,
&
taskId
,
sizeof
(
int32_t
));
if
(
pTask
==
NULL
)
{
return
-
1
;
}
free
(
pTask
->
qmsg
);
// TODO:free executor
free
(
pTask
);
return
taosHashRemove
(
pMeta
->
pHash
,
&
taskId
,
sizeof
(
int32_t
));
}
static
int32_t
sndProcessTaskExecReq
(
SSnode
*
pSnode
,
SRpcMsg
*
pMsg
)
{
SMsgHead
*
pHead
=
pMsg
->
pCont
;
int32_t
taskId
=
pHead
->
streamTaskId
;
SStreamTask
*
pTask
=
sndMetaGetTask
(
pSnode
->
pMeta
,
taskId
);
if
(
pTask
==
NULL
)
{
return
-
1
;
}
task
->
meta
.
taskId
=
tGenIdPI32
();
taosHashPut
(
pSnode
->
pMeta
->
pHash
,
&
task
->
meta
.
taskId
,
sizeof
(
int32_t
),
&
task
,
sizeof
(
void
*
));
return
0
;
}
int32_t
sndProcessUMsg
(
SSnode
*
pSnode
,
SRpcMsg
*
pMsg
)
{
// stream deploy
ment
// stream deploy
// stream stop/resume
// operator exec
if
(
pMsg
->
msgType
==
TDMT_SND_TASK_DEPLOY
)
{
void
*
msg
=
POINTER_SHIFT
(
pMsg
->
pCont
,
sizeof
(
SMsgHead
));
SStreamTask
*
pTask
=
malloc
(
sizeof
(
SStreamTask
));
if
(
pTask
==
NULL
)
{
return
-
1
;
}
SCoder
decoder
;
tCoderInit
(
&
decoder
,
TD_LITTLE_ENDIAN
,
msg
,
pMsg
->
contLen
-
sizeof
(
SMsgHead
),
TD_DECODER
);
tDecodeSStreamTask
(
&
decoder
,
pTask
);
tCoderClear
(
&
decoder
);
sndMetaDeployTask
(
pSnode
->
pMeta
,
pTask
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SND_TASK_EXEC
)
{
sndProcessTaskExecReq
(
pSnode
,
pMsg
);
}
else
{
ASSERT
(
0
);
}
return
0
;
}
int32_t
sndProcessSMsg
(
SSnode
*
pSnode
,
SRpcMsg
*
pMsg
)
{
// operator exec
if
(
pMsg
->
msgType
==
TDMT_SND_TASK_EXEC
)
{
sndProcessTaskExecReq
(
pSnode
,
pMsg
);
}
else
{
ASSERT
(
0
);
}
return
0
;
}
source/dnode/vnode/inc/tsdb.h
浏览文件 @
7eb4153a
...
...
@@ -107,10 +107,8 @@ int32_t tsdbUpdateSmaWindow(STsdb *pTsdb, int8_t smaType, char *msg);
int32_t
tsdbInsertRSmaData
(
STsdb
*
pTsdb
,
char
*
msg
);
// TODO: This is the basic params, and should wrap the params to a queryHandle.
int32_t
tsdbGetTSmaData
(
STsdb
*
pTsdb
,
STSmaDataWrapper
*
pData
,
int64_t
indexUid
,
int64_t
interval
,
int8_t
intervalUnit
,
tb_uid_t
tableUid
,
col_id_t
colId
,
TSKEY
querySkey
,
int32_t
nMaxResult
);
int32_t
tsdbGetTSmaData
(
STsdb
*
pTsdb
,
STSmaDataWrapper
*
pData
,
int64_t
indexUid
,
int64_t
interval
,
int8_t
intervalUnit
,
tb_uid_t
tableUid
,
col_id_t
colId
,
TSKEY
querySKey
,
int32_t
nMaxResult
);
// STsdbCfg
int
tsdbOptionsInit
(
STsdbCfg
*
);
...
...
source/dnode/vnode/src/inc/tsdbDef.h
浏览文件 @
7eb4153a
...
...
@@ -64,6 +64,7 @@ struct STsdb {
#define REPO_CFG(r) (&(r)->config)
#define REPO_FS(r) (r)->fs
#define IS_REPO_LOCKED(r) (r)->repoLocked
#define REPO_SMA_ENV(r, t) ((TSDB_SMA_TYPE_ROLLUP == (t)) ? (r)->pRSmaEnv : (r)->pTSmaEnv)
int
tsdbLockRepo
(
STsdb
*
pTsdb
);
int
tsdbUnlockRepo
(
STsdb
*
pTsdb
);
...
...
source/dnode/vnode/src/meta/metaBDBImpl.c
浏览文件 @
7eb4153a
...
...
@@ -636,7 +636,7 @@ STSma *metaGetSmaInfoByIndex(SMeta *pMeta, int64_t indexUid) {
}
// Decode
pCfg
=
(
STSma
*
)
malloc
(
sizeof
(
STSma
));
pCfg
=
(
STSma
*
)
calloc
(
1
,
sizeof
(
STSma
));
if
(
pCfg
==
NULL
)
{
return
NULL
;
}
...
...
source/dnode/vnode/src/tsdb/tsdbBDBImpl.c
浏览文件 @
7eb4153a
...
...
@@ -68,8 +68,8 @@ int32_t tsdbOpenBDBEnv(DB_ENV **ppEnv, const char *path) {
ret
=
pEnv
->
open
(
pEnv
,
path
,
DB_CREATE
|
DB_INIT_CDB
|
DB_INIT_MPOOL
,
0
);
if
(
ret
!=
0
)
{
// BDB_PERR("Failed to open tsdb env", ret)
;
tsdbWarn
(
"Failed to open tsdb env for path %s since
%d
"
,
path
?
path
:
"NULL"
,
ret
);
terrno
=
TSDB_CODE_TDB_TDB_ENV_OPEN_ERROR
;
tsdbWarn
(
"Failed to open tsdb env for path %s since
ret %d != 0
"
,
path
?
path
:
"NULL"
,
ret
);
return
-
1
;
}
...
...
source/dnode/vnode/src/tsdb/tsdbFile.c
浏览文件 @
7eb4153a
...
...
@@ -23,8 +23,8 @@ static const char *TSDB_FNAME_SUFFIX[] = {
"smal"
,
// TSDB_FILE_SMAL
""
,
// TSDB_FILE_MAX
"meta"
,
// TSDB_FILE_META
"
sma"
,
// TSDB_FILE_TSMA(directory name)
"
sma"
,
// TSDB_FILE_RSMA(directory name)
"
tsma"
,
// TSDB_FILE_TSMA
"
rsma"
,
// TSDB_FILE_RSMA
};
static
void
tsdbGetFilename
(
int
vid
,
int
fid
,
uint32_t
ver
,
TSDB_FILE_T
ftype
,
char
*
fname
);
...
...
source/dnode/vnode/src/tsdb/tsdbSma.c
浏览文件 @
7eb4153a
此差异已折叠。
点击以展开。
source/dnode/vnode/test/tsdbSmaTest.cpp
浏览文件 @
7eb4153a
...
...
@@ -37,9 +37,9 @@ TEST(testCase, tSma_Meta_Encode_Decode_Test) {
// encode
STSma
tSma
=
{
0
};
tSma
.
version
=
0
;
tSma
.
intervalUnit
=
T
D_T
IME_UNIT_DAY
;
tSma
.
intervalUnit
=
TIME_UNIT_DAY
;
tSma
.
interval
=
1
;
tSma
.
slidingUnit
=
T
D_T
IME_UNIT_HOUR
;
tSma
.
slidingUnit
=
TIME_UNIT_HOUR
;
tSma
.
sliding
=
0
;
tstrncpy
(
tSma
.
indexName
,
"sma_index_test"
,
TSDB_INDEX_NAME_LEN
);
tstrncpy
(
tSma
.
timezone
,
"Asia/Shanghai"
,
TD_TIMEZONE_LEN
);
...
...
@@ -50,37 +50,37 @@ TEST(testCase, tSma_Meta_Encode_Decode_Test) {
uint32_t
bufLen
=
tEncodeTSmaWrapper
(
NULL
,
&
tSmaWrapper
);
void
*
buf
=
calloc
(
bufLen
,
1
);
assert
(
buf
!=
NULL
);
ASSERT_NE
(
buf
,
nullptr
);
STSmaWrapper
*
pSW
=
(
STSmaWrapper
*
)
buf
;
uint32_t
len
=
tEncodeTSmaWrapper
(
&
buf
,
&
tSmaWrapper
);
EXPEC
T_EQ
(
len
,
bufLen
);
ASSER
T_EQ
(
len
,
bufLen
);
// decode
STSmaWrapper
dstTSmaWrapper
=
{
0
};
void
*
result
=
tDecodeTSmaWrapper
(
pSW
,
&
dstTSmaWrapper
);
assert
(
result
!=
NULL
);
ASSERT_NE
(
result
,
nullptr
);
EXPEC
T_EQ
(
tSmaWrapper
.
number
,
dstTSmaWrapper
.
number
);
ASSER
T_EQ
(
tSmaWrapper
.
number
,
dstTSmaWrapper
.
number
);
for
(
int
i
=
0
;
i
<
tSmaWrapper
.
number
;
++
i
)
{
STSma
*
pSma
=
tSmaWrapper
.
tSma
+
i
;
STSma
*
qSma
=
dstTSmaWrapper
.
tSma
+
i
;
EXPEC
T_EQ
(
pSma
->
version
,
qSma
->
version
);
EXPEC
T_EQ
(
pSma
->
intervalUnit
,
qSma
->
intervalUnit
);
EXPEC
T_EQ
(
pSma
->
slidingUnit
,
qSma
->
slidingUnit
);
EXPEC
T_STRCASEEQ
(
pSma
->
indexName
,
qSma
->
indexName
);
EXPEC
T_STRCASEEQ
(
pSma
->
timezone
,
qSma
->
timezone
);
EXPEC
T_EQ
(
pSma
->
indexUid
,
qSma
->
indexUid
);
EXPEC
T_EQ
(
pSma
->
tableUid
,
qSma
->
tableUid
);
EXPEC
T_EQ
(
pSma
->
interval
,
qSma
->
interval
);
EXPEC
T_EQ
(
pSma
->
sliding
,
qSma
->
sliding
);
EXPEC
T_EQ
(
pSma
->
exprLen
,
qSma
->
exprLen
);
EXPEC
T_STRCASEEQ
(
pSma
->
expr
,
qSma
->
expr
);
EXPEC
T_EQ
(
pSma
->
tagsFilterLen
,
qSma
->
tagsFilterLen
);
EXPEC
T_STRCASEEQ
(
pSma
->
tagsFilter
,
qSma
->
tagsFilter
);
ASSER
T_EQ
(
pSma
->
version
,
qSma
->
version
);
ASSER
T_EQ
(
pSma
->
intervalUnit
,
qSma
->
intervalUnit
);
ASSER
T_EQ
(
pSma
->
slidingUnit
,
qSma
->
slidingUnit
);
ASSER
T_STRCASEEQ
(
pSma
->
indexName
,
qSma
->
indexName
);
ASSER
T_STRCASEEQ
(
pSma
->
timezone
,
qSma
->
timezone
);
ASSER
T_EQ
(
pSma
->
indexUid
,
qSma
->
indexUid
);
ASSER
T_EQ
(
pSma
->
tableUid
,
qSma
->
tableUid
);
ASSER
T_EQ
(
pSma
->
interval
,
qSma
->
interval
);
ASSER
T_EQ
(
pSma
->
sliding
,
qSma
->
sliding
);
ASSER
T_EQ
(
pSma
->
exprLen
,
qSma
->
exprLen
);
ASSER
T_STRCASEEQ
(
pSma
->
expr
,
qSma
->
expr
);
ASSER
T_EQ
(
pSma
->
tagsFilterLen
,
qSma
->
tagsFilterLen
);
ASSER
T_STRCASEEQ
(
pSma
->
tagsFilter
,
qSma
->
tagsFilter
);
}
// resource release
...
...
@@ -103,9 +103,9 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
// encode
STSma
tSma
=
{
0
};
tSma
.
version
=
0
;
tSma
.
intervalUnit
=
T
D_T
IME_UNIT_DAY
;
tSma
.
intervalUnit
=
TIME_UNIT_DAY
;
tSma
.
interval
=
1
;
tSma
.
slidingUnit
=
T
D_T
IME_UNIT_HOUR
;
tSma
.
slidingUnit
=
TIME_UNIT_HOUR
;
tSma
.
sliding
=
0
;
tSma
.
indexUid
=
indexUid1
;
tstrncpy
(
tSma
.
indexName
,
smaIndexName1
,
TSDB_INDEX_NAME_LEN
);
...
...
@@ -114,10 +114,12 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
tSma
.
exprLen
=
strlen
(
expr
);
tSma
.
expr
=
(
char
*
)
calloc
(
tSma
.
exprLen
+
1
,
1
);
ASSERT_NE
(
tSma
.
expr
,
nullptr
);
tstrncpy
(
tSma
.
expr
,
expr
,
tSma
.
exprLen
+
1
);
tSma
.
tagsFilterLen
=
strlen
(
tagsFilter
);
tSma
.
tagsFilter
=
(
char
*
)
calloc
(
tSma
.
tagsFilterLen
+
1
,
1
);
ASSERT_NE
(
tSma
.
tagsFilter
,
nullptr
);
tstrncpy
(
tSma
.
tagsFilter
,
tagsFilter
,
tSma
.
tagsFilterLen
+
1
);
SMeta
*
pMeta
=
NULL
;
...
...
@@ -129,18 +131,18 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
pMeta
=
metaOpen
(
smaTestDir
,
pMetaCfg
,
NULL
);
assert
(
pMeta
!=
NULL
);
// save index 1
EXPEC
T_EQ
(
metaSaveSmaToDB
(
pMeta
,
pSmaCfg
),
0
);
ASSER
T_EQ
(
metaSaveSmaToDB
(
pMeta
,
pSmaCfg
),
0
);
pSmaCfg
->
indexUid
=
indexUid2
;
tstrncpy
(
pSmaCfg
->
indexName
,
smaIndexName2
,
TSDB_INDEX_NAME_LEN
);
pSmaCfg
->
version
=
1
;
pSmaCfg
->
intervalUnit
=
T
D_T
IME_UNIT_HOUR
;
pSmaCfg
->
intervalUnit
=
TIME_UNIT_HOUR
;
pSmaCfg
->
interval
=
1
;
pSmaCfg
->
slidingUnit
=
T
D_T
IME_UNIT_MINUTE
;
pSmaCfg
->
slidingUnit
=
TIME_UNIT_MINUTE
;
pSmaCfg
->
sliding
=
5
;
// save index 2
EXPEC
T_EQ
(
metaSaveSmaToDB
(
pMeta
,
pSmaCfg
),
0
);
ASSER
T_EQ
(
metaSaveSmaToDB
(
pMeta
,
pSmaCfg
),
0
);
// get value by indexName
STSma
*
qSmaCfg
=
NULL
;
...
...
@@ -150,8 +152,8 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
printf
(
"timezone1 = %s
\n
"
,
qSmaCfg
->
timezone
);
printf
(
"expr1 = %s
\n
"
,
qSmaCfg
->
expr
!=
NULL
?
qSmaCfg
->
expr
:
""
);
printf
(
"tagsFilter1 = %s
\n
"
,
qSmaCfg
->
tagsFilter
!=
NULL
?
qSmaCfg
->
tagsFilter
:
""
);
EXPEC
T_STRCASEEQ
(
qSmaCfg
->
indexName
,
smaIndexName1
);
EXPEC
T_EQ
(
qSmaCfg
->
tableUid
,
tSma
.
tableUid
);
ASSER
T_STRCASEEQ
(
qSmaCfg
->
indexName
,
smaIndexName1
);
ASSER
T_EQ
(
qSmaCfg
->
tableUid
,
tSma
.
tableUid
);
tdDestroyTSma
(
qSmaCfg
);
tfree
(
qSmaCfg
);
...
...
@@ -161,8 +163,8 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
printf
(
"timezone2 = %s
\n
"
,
qSmaCfg
->
timezone
);
printf
(
"expr2 = %s
\n
"
,
qSmaCfg
->
expr
!=
NULL
?
qSmaCfg
->
expr
:
""
);
printf
(
"tagsFilter2 = %s
\n
"
,
qSmaCfg
->
tagsFilter
!=
NULL
?
qSmaCfg
->
tagsFilter
:
""
);
EXPEC
T_STRCASEEQ
(
qSmaCfg
->
indexName
,
smaIndexName2
);
EXPEC
T_EQ
(
qSmaCfg
->
interval
,
tSma
.
interval
);
ASSER
T_STRCASEEQ
(
qSmaCfg
->
indexName
,
smaIndexName2
);
ASSER
T_EQ
(
qSmaCfg
->
interval
,
tSma
.
interval
);
tdDestroyTSma
(
qSmaCfg
);
tfree
(
qSmaCfg
);
...
...
@@ -178,25 +180,25 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
printf
(
"indexName = %s
\n
"
,
indexName
);
++
indexCnt
;
}
EXPEC
T_EQ
(
indexCnt
,
nCntTSma
);
ASSER
T_EQ
(
indexCnt
,
nCntTSma
);
metaCloseSmaCurosr
(
pSmaCur
);
// get wrapper by table uid
STSmaWrapper
*
pSW
=
metaGetSmaInfoByTable
(
pMeta
,
tbUid
);
assert
(
pSW
!=
NULL
);
EXPEC
T_EQ
(
pSW
->
number
,
nCntTSma
);
EXPEC
T_STRCASEEQ
(
pSW
->
tSma
->
indexName
,
smaIndexName1
);
EXPEC
T_STRCASEEQ
(
pSW
->
tSma
->
timezone
,
timezone
);
EXPEC
T_STRCASEEQ
(
pSW
->
tSma
->
expr
,
expr
);
EXPEC
T_STRCASEEQ
(
pSW
->
tSma
->
tagsFilter
,
tagsFilter
);
EXPEC
T_EQ
(
pSW
->
tSma
->
indexUid
,
indexUid1
);
EXPEC
T_EQ
(
pSW
->
tSma
->
tableUid
,
tbUid
);
EXPEC
T_STRCASEEQ
((
pSW
->
tSma
+
1
)
->
indexName
,
smaIndexName2
);
EXPEC
T_STRCASEEQ
((
pSW
->
tSma
+
1
)
->
timezone
,
timezone
);
EXPEC
T_STRCASEEQ
((
pSW
->
tSma
+
1
)
->
expr
,
expr
);
EXPEC
T_STRCASEEQ
((
pSW
->
tSma
+
1
)
->
tagsFilter
,
tagsFilter
);
EXPEC
T_EQ
((
pSW
->
tSma
+
1
)
->
indexUid
,
indexUid2
);
EXPEC
T_EQ
((
pSW
->
tSma
+
1
)
->
tableUid
,
tbUid
);
ASSER
T_EQ
(
pSW
->
number
,
nCntTSma
);
ASSER
T_STRCASEEQ
(
pSW
->
tSma
->
indexName
,
smaIndexName1
);
ASSER
T_STRCASEEQ
(
pSW
->
tSma
->
timezone
,
timezone
);
ASSER
T_STRCASEEQ
(
pSW
->
tSma
->
expr
,
expr
);
ASSER
T_STRCASEEQ
(
pSW
->
tSma
->
tagsFilter
,
tagsFilter
);
ASSER
T_EQ
(
pSW
->
tSma
->
indexUid
,
indexUid1
);
ASSER
T_EQ
(
pSW
->
tSma
->
tableUid
,
tbUid
);
ASSER
T_STRCASEEQ
((
pSW
->
tSma
+
1
)
->
indexName
,
smaIndexName2
);
ASSER
T_STRCASEEQ
((
pSW
->
tSma
+
1
)
->
timezone
,
timezone
);
ASSER
T_STRCASEEQ
((
pSW
->
tSma
+
1
)
->
expr
,
expr
);
ASSER
T_STRCASEEQ
((
pSW
->
tSma
+
1
)
->
tagsFilter
,
tagsFilter
);
ASSER
T_EQ
((
pSW
->
tSma
+
1
)
->
indexUid
,
indexUid2
);
ASSER
T_EQ
((
pSW
->
tSma
+
1
)
->
tableUid
,
tbUid
);
tdDestroyTSmaWrapper
(
pSW
);
tfree
(
pSW
);
...
...
@@ -208,7 +210,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
printf
(
"metaGetSmaTbUids: uid[%"
PRIu32
"] = %"
PRIi64
"
\n
"
,
i
,
*
(
tb_uid_t
*
)
taosArrayGet
(
pUids
,
i
));
// printf("metaGetSmaTbUids: index[%" PRIu32 "] = %s", i, (char *)taosArrayGet(pUids, i));
}
EXPEC
T_EQ
(
taosArrayGetSize
(
pUids
),
1
);
ASSER
T_EQ
(
taosArrayGetSize
(
pUids
),
1
);
taosArrayDestroy
(
pUids
);
// resource release
...
...
@@ -231,7 +233,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
const
tb_uid_t
tbUid
=
1234567890
;
const
int64_t
indexUid1
=
2000000001
;
const
int64_t
interval1
=
1
;
const
int8_t
intervalUnit1
=
T
D_T
IME_UNIT_DAY
;
const
int8_t
intervalUnit1
=
TIME_UNIT_DAY
;
const
uint32_t
nCntTSma
=
2
;
TSKEY
skey1
=
1646987196
;
const
int64_t
testSmaData1
=
100
;
...
...
@@ -239,9 +241,9 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
// encode
STSma
tSma
=
{
0
};
tSma
.
version
=
0
;
tSma
.
intervalUnit
=
T
D_T
IME_UNIT_DAY
;
tSma
.
intervalUnit
=
TIME_UNIT_DAY
;
tSma
.
interval
=
1
;
tSma
.
slidingUnit
=
T
D_T
IME_UNIT_HOUR
;
tSma
.
slidingUnit
=
TIME_UNIT_HOUR
;
tSma
.
sliding
=
0
;
tSma
.
indexUid
=
indexUid1
;
tstrncpy
(
tSma
.
indexName
,
smaIndexName1
,
TSDB_INDEX_NAME_LEN
);
...
...
@@ -250,10 +252,12 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
tSma
.
exprLen
=
strlen
(
expr
);
tSma
.
expr
=
(
char
*
)
calloc
(
tSma
.
exprLen
+
1
,
1
);
ASSERT_NE
(
tSma
.
expr
,
nullptr
);
tstrncpy
(
tSma
.
expr
,
expr
,
tSma
.
exprLen
+
1
);
tSma
.
tagsFilterLen
=
strlen
(
tagsFilter
);
tSma
.
tagsFilter
=
(
char
*
)
calloc
(
tSma
.
tagsFilterLen
+
1
,
1
);
ASSERT_NE
(
tSma
.
tagsFilter
,
nullptr
);
tstrncpy
(
tSma
.
tagsFilter
,
tagsFilter
,
tSma
.
tagsFilterLen
+
1
);
SMeta
*
pMeta
=
NULL
;
...
...
@@ -265,7 +269,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
pMeta
=
metaOpen
(
smaTestDir
,
pMetaCfg
,
NULL
);
assert
(
pMeta
!=
NULL
);
// save index 1
EXPEC
T_EQ
(
metaSaveSmaToDB
(
pMeta
,
pSmaCfg
),
0
);
ASSER
T_EQ
(
metaSaveSmaToDB
(
pMeta
,
pSmaCfg
),
0
);
// step 2: insert data
STSmaDataWrapper
*
pSmaData
=
NULL
;
...
...
@@ -297,19 +301,20 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
break
;
}
char
*
msg
=
(
char
*
)
calloc
(
100
,
1
);
EXPECT_EQ
(
tsdbUpdateSmaWindow
(
&
tsdb
,
TSDB_SMA_TYPE_TIME_RANGE
,
msg
),
0
);
char
*
msg
=
(
char
*
)
calloc
(
1
,
100
);
assert
(
msg
!=
NULL
);
ASSERT_EQ
(
tsdbUpdateSmaWindow
(
&
tsdb
,
TSDB_SMA_TYPE_TIME_RANGE
,
msg
),
0
);
// init
int32_t
allocCnt
=
0
;
int32_t
allocStep
=
40960
;
int32_t
buffer
=
4096
;
int32_t
allocStep
=
16384
;
int32_t
buffer
=
1024
;
void
*
buf
=
NULL
;
EXPEC
T_EQ
(
tsdbMakeRoom
(
&
buf
,
allocStep
),
0
);
ASSER
T_EQ
(
tsdbMakeRoom
(
&
buf
,
allocStep
),
0
);
int32_t
bufSize
=
taosTSizeof
(
buf
);
int32_t
numOfTables
=
10
;
col_id_t
numOfCols
=
4096
;
EXPEC
T_GT
(
numOfCols
,
0
);
ASSER
T_GT
(
numOfCols
,
0
);
pSmaData
=
(
STSmaDataWrapper
*
)
buf
;
printf
(
">> allocate [%d] time to %d and addr is %p
\n
"
,
++
allocCnt
,
bufSize
,
pSmaData
);
...
...
@@ -326,7 +331,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
int32_t
tableDataLen
=
sizeof
(
STSmaTbData
);
for
(
col_id_t
c
=
0
;
c
<
numOfCols
;
++
c
)
{
if
(
bufSize
-
len
-
tableDataLen
<
buffer
)
{
EXPEC
T_EQ
(
tsdbMakeRoom
(
&
buf
,
bufSize
+
allocStep
),
0
);
ASSER
T_EQ
(
tsdbMakeRoom
(
&
buf
,
bufSize
+
allocStep
),
0
);
pSmaData
=
(
STSmaDataWrapper
*
)
buf
;
pTbData
=
(
STSmaTbData
*
)
POINTER_SHIFT
(
pSmaData
,
len
);
bufSize
=
taosTSizeof
(
buf
);
...
...
@@ -353,16 +358,16 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
}
pSmaData
->
dataLen
=
(
len
-
sizeof
(
STSmaDataWrapper
));
EXPEC
T_GE
(
bufSize
,
pSmaData
->
dataLen
);
ASSER
T_GE
(
bufSize
,
pSmaData
->
dataLen
);
// execute
EXPEC
T_EQ
(
tsdbInsertTSmaData
(
&
tsdb
,
(
char
*
)
pSmaData
),
TSDB_CODE_SUCCESS
);
ASSER
T_EQ
(
tsdbInsertTSmaData
(
&
tsdb
,
(
char
*
)
pSmaData
),
TSDB_CODE_SUCCESS
);
// step 3: query
uint32_t
checkDataCnt
=
0
;
for
(
int32_t
t
=
0
;
t
<
numOfTables
;
++
t
)
{
for
(
col_id_t
c
=
0
;
c
<
numOfCols
;
++
c
)
{
EXPEC
T_EQ
(
tsdbGetTSmaData
(
&
tsdb
,
NULL
,
indexUid1
,
interval1
,
intervalUnit1
,
tbUid
+
t
,
ASSER
T_EQ
(
tsdbGetTSmaData
(
&
tsdb
,
NULL
,
indexUid1
,
interval1
,
intervalUnit1
,
tbUid
+
t
,
c
+
PRIMARYKEY_TIMESTAMP_COL_ID
,
skey1
,
1
),
TSDB_CODE_SUCCESS
);
++
checkDataCnt
;
...
...
source/libs/parser/src/parInsert.c
浏览文件 @
7eb4153a
...
...
@@ -617,7 +617,7 @@ static FORCE_INLINE int32_t MemRowAppend(const void* value, int32_t len, void* p
if
(
TSDB_DATA_TYPE_BINARY
==
pa
->
schema
->
type
)
{
const
char
*
rowEnd
=
tdRowEnd
(
rb
->
pBuf
);
STR_WITH_SIZE_TO_VARSTR
(
rowEnd
,
value
,
len
);
tdAppendColValToRow
(
rb
,
pa
->
schema
->
colId
,
pa
->
schema
->
type
,
TD_VTYPE_NORM
,
rowEnd
,
fals
e
,
pa
->
toffset
,
pa
->
colIdx
);
tdAppendColValToRow
(
rb
,
pa
->
schema
->
colId
,
pa
->
schema
->
type
,
TD_VTYPE_NORM
,
rowEnd
,
tru
e
,
pa
->
toffset
,
pa
->
colIdx
);
}
else
if
(
TSDB_DATA_TYPE_NCHAR
==
pa
->
schema
->
type
)
{
// if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long'
int32_t
output
=
0
;
...
...
@@ -626,9 +626,9 @@ static FORCE_INLINE int32_t MemRowAppend(const void* value, int32_t len, void* p
return
TSDB_CODE_TSC_SQL_SYNTAX_ERROR
;
}
varDataSetLen
(
rowEnd
,
output
);
tdAppendColValToRow
(
rb
,
pa
->
schema
->
colId
,
pa
->
schema
->
type
,
TD_VTYPE_NORM
,
rowEnd
,
fals
e
,
pa
->
toffset
,
pa
->
colIdx
);
tdAppendColValToRow
(
rb
,
pa
->
schema
->
colId
,
pa
->
schema
->
type
,
TD_VTYPE_NORM
,
rowEnd
,
tru
e
,
pa
->
toffset
,
pa
->
colIdx
);
}
else
{
tdAppendColValToRow
(
rb
,
pa
->
schema
->
colId
,
pa
->
schema
->
type
,
TD_VTYPE_NORM
,
value
,
tru
e
,
pa
->
toffset
,
pa
->
colIdx
);
tdAppendColValToRow
(
rb
,
pa
->
schema
->
colId
,
pa
->
schema
->
type
,
TD_VTYPE_NORM
,
value
,
fals
e
,
pa
->
toffset
,
pa
->
colIdx
);
}
return
TSDB_CODE_SUCCESS
;
}
...
...
source/libs/planner/src/planSpliter.c
浏览文件 @
7eb4153a
...
...
@@ -89,7 +89,7 @@ static SSubLogicPlan* stsCreateScanSubplan(SSplitContext* pCxt, SScanLogicNode*
pSubplan
->
id
.
groupId
=
pCxt
->
groupId
;
pSubplan
->
subplanType
=
SUBPLAN_TYPE_SCAN
;
pSubplan
->
pNode
=
(
SLogicNode
*
)
nodesCloneNode
(
pScan
);
TSWAP
(
pSubplan
->
pVgroupList
,
((
SScanLogicNode
*
)
pSubplan
->
pNode
)
->
pVgroupList
,
SVgroupsInfo
);
TSWAP
(
pSubplan
->
pVgroupList
,
((
SScanLogicNode
*
)
pSubplan
->
pNode
)
->
pVgroupList
,
SVgroupsInfo
*
);
SPLIT_FLAG_SET_MASK
(
pSubplan
->
splitFlag
,
SPLIT_FLAG_STS
);
return
pSubplan
;
}
...
...
source/libs/sync/inc/syncEnv.h
浏览文件 @
7eb4153a
...
...
@@ -31,10 +31,10 @@ extern "C" {
#define TIMER_MAX_MS 0x7FFFFFFF
#define ENV_TICK_TIMER_MS 1000
#define PING_TIMER_MS 1000
#define ELECT_TIMER_MS_MIN 150
#define ELECT_TIMER_MS_MAX 300
#define ELECT_TIMER_MS_MIN 150
0
#define ELECT_TIMER_MS_MAX 300
0
#define ELECT_TIMER_MS_RANGE (ELECT_TIMER_MS_MAX - ELECT_TIMER_MS_MIN)
#define HEARTBEAT_TIMER_MS 30
#define HEARTBEAT_TIMER_MS 30
0
#define EMPTY_RAFT_ID ((SRaftId){.addr = 0, .vgId = 0})
...
...
source/libs/sync/inc/syncIO.h
浏览文件 @
7eb4153a
...
...
@@ -34,11 +34,11 @@ extern "C" {
typedef
struct
SSyncIO
{
STaosQueue
*
pMsgQ
;
STaosQset
*
pQset
;
STaosQset
*
pQset
;
pthread_t
consumerTid
;
void
*
serverRpc
;
void
*
clientRpc
;
void
*
serverRpc
;
void
*
clientRpc
;
SEpSet
myAddr
;
tmr_h
qTimer
;
...
...
source/libs/sync/inc/syncRaftStore.h
浏览文件 @
7eb4153a
...
...
@@ -48,6 +48,9 @@ void raftStoreVote(SRaftStore *pRaftStore, SRaftId *pRaftId);
void
raftStoreClearVote
(
SRaftStore
*
pRaftStore
);
void
raftStoreNextTerm
(
SRaftStore
*
pRaftStore
);
void
raftStoreSetTerm
(
SRaftStore
*
pRaftStore
,
SyncTerm
term
);
int32_t
raftStoreFromJson
(
SRaftStore
*
pRaftStore
,
cJSON
*
pJson
);
cJSON
*
raftStore2Json
(
SRaftStore
*
pRaftStore
);
char
*
raftStore2Str
(
SRaftStore
*
pRaftStore
);
// for debug -------------------
void
raftStorePrint
(
SRaftStore
*
pObj
);
...
...
source/libs/sync/src/syncAppendEntries.c
浏览文件 @
7eb4153a
...
...
@@ -102,7 +102,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
SyncTerm
localPreLogTerm
=
0
;
if
(
pMsg
->
prevLogTerm
>=
SYNC_INDEX_BEGIN
&&
pMsg
->
prevLogTerm
<=
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
))
{
SSyncRaftEntry
*
pEntry
=
logStoreGetEntry
(
ths
->
pLogStore
,
pMsg
->
prevLog
Term
);
SSyncRaftEntry
*
pEntry
=
logStoreGetEntry
(
ths
->
pLogStore
,
pMsg
->
prevLog
Index
);
assert
(
pEntry
!=
NULL
);
localPreLogTerm
=
pEntry
->
term
;
syncEntryDestory
(
pEntry
);
...
...
@@ -111,9 +111,9 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
bool
logOK
=
(
pMsg
->
prevLogIndex
==
SYNC_INDEX_INVALID
)
||
((
pMsg
->
prevLogIndex
>=
SYNC_INDEX_BEGIN
)
&&
(
pMsg
->
prevLogIndex
<=
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
))
&&
(
pMsg
->
prevLog
Index
==
localPreLogTerm
));
(
pMsg
->
prevLogIndex
<=
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
))
&&
(
pMsg
->
prevLog
Term
==
localPreLogTerm
));
// reject
// reject
request
if
((
pMsg
->
term
<
ths
->
pRaftStore
->
currentTerm
)
||
((
pMsg
->
term
==
ths
->
pRaftStore
->
currentTerm
)
&&
(
ths
->
state
==
TAOS_SYNC_STATE_FOLLOWER
)
&&
!
logOK
))
{
SyncAppendEntriesReply
*
pReply
=
syncAppendEntriesReplyBuild
();
...
...
@@ -134,6 +134,9 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
// return to follower state
if
(
pMsg
->
term
==
ths
->
pRaftStore
->
currentTerm
&&
ths
->
state
==
TAOS_SYNC_STATE_CANDIDATE
)
{
syncNodeBecomeFollower
(
ths
);
// need ret?
return
ret
;
}
// accept request
...
...
@@ -144,17 +147,17 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
matchSuccess
=
true
;
}
if
(
pMsg
->
prevLogIndex
>=
SYNC_INDEX_BEGIN
&&
pMsg
->
prevLogIndex
<=
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
))
{
SSyncRaftEntry
*
p
Entry
=
logStoreGetEntry
(
ths
->
pLogStore
,
pMsg
->
prevLogTerm
);
assert
(
pEntry
!=
NULL
);
if
(
pMsg
->
prevLogTerm
==
pEntry
->
term
)
{
SSyncRaftEntry
*
p
PreEntry
=
logStoreGetEntry
(
ths
->
pLogStore
,
pMsg
->
prevLogIndex
);
assert
(
p
Pre
Entry
!=
NULL
);
if
(
pMsg
->
prevLogTerm
==
p
Pre
Entry
->
term
)
{
matchSuccess
=
true
;
}
syncEntryDestory
(
pEntry
);
syncEntryDestory
(
p
Pre
Entry
);
}
if
(
matchSuccess
)
{
// delete conflict entries
if
(
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
)
>
pMsg
->
prevLogIndex
)
{
if
(
pMsg
->
prevLogIndex
<
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
)
)
{
SyncIndex
fromIndex
=
pMsg
->
prevLogIndex
+
1
;
ths
->
pLogStore
->
truncate
(
ths
->
pLogStore
,
fromIndex
);
}
...
...
@@ -178,6 +181,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
syncNodeSendMsgById
(
&
pReply
->
destId
,
ths
,
&
rpcMsg
);
syncAppendEntriesReplyDestroy
(
pReply
);
}
else
{
SyncAppendEntriesReply
*
pReply
=
syncAppendEntriesReplyBuild
();
pReply
->
srcId
=
ths
->
myRaftId
;
...
...
source/libs/sync/src/syncAppendEntriesReply.c
浏览文件 @
7eb4153a
...
...
@@ -51,10 +51,10 @@ int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* p
assert
(
pMsg
->
term
==
ths
->
pRaftStore
->
currentTerm
);
if
(
pMsg
->
success
)
{
// nextIndex
= reply.matchIndex + 1
// nextIndex
' = [nextIndex EXCEPT ![i][j] = m.mmatchIndex + 1]
syncIndexMgrSetIndex
(
ths
->
pNextIndex
,
&
(
pMsg
->
srcId
),
pMsg
->
matchIndex
+
1
);
// matchIndex
= reply.matchIndex
// matchIndex
' = [matchIndex EXCEPT ![i][j] = m.mmatchIndex]
syncIndexMgrSetIndex
(
ths
->
pMatchIndex
,
&
(
pMsg
->
srcId
),
pMsg
->
matchIndex
);
// maybe commit
...
...
@@ -62,6 +62,8 @@ int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* p
}
else
{
SyncIndex
nextIndex
=
syncIndexMgrGetIndex
(
ths
->
pNextIndex
,
&
(
pMsg
->
srcId
));
// notice! int64, uint64
if
(
nextIndex
>
SYNC_INDEX_BEGIN
)
{
--
nextIndex
;
}
else
{
...
...
source/libs/sync/src/syncCommit.c
0 → 100644
浏览文件 @
7eb4153a
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "syncIndexMgr.h"
#include "syncInt.h"
// \* Leader i advances its commitIndex.
// \* This is done as a separate step from handling AppendEntries responses,
// \* in part to minimize atomic regions, and in part so that leaders of
// \* single-server clusters are able to mark entries committed.
// AdvanceCommitIndex(i) ==
// /\ state[i] = Leader
// /\ LET \* The set of servers that agree up through index.
// Agree(index) == {i} \cup {k \in Server :
// matchIndex[i][k] >= index}
// \* The maximum indexes for which a quorum agrees
// agreeIndexes == {index \in 1..Len(log[i]) :
// Agree(index) \in Quorum}
// \* New value for commitIndex'[i]
// newCommitIndex ==
// IF /\ agreeIndexes /= {}
// /\ log[i][Max(agreeIndexes)].term = currentTerm[i]
// THEN
// Max(agreeIndexes)
// ELSE
// commitIndex[i]
// IN commitIndex' = [commitIndex EXCEPT ![i] = newCommitIndex]
// /\ UNCHANGED <<messages, serverVars, candidateVars, leaderVars, log>>
//
void
syncNodeMaybeAdvanceCommitIndex
(
SSyncNode
*
pSyncNode
)
{
syncIndexMgrLog2
(
"==syncNodeMaybeAdvanceCommitIndex== pNextIndex"
,
pSyncNode
->
pNextIndex
);
syncIndexMgrLog2
(
"==syncNodeMaybeAdvanceCommitIndex== pMatchIndex"
,
pSyncNode
->
pMatchIndex
);
}
\ No newline at end of file
source/libs/sync/src/syncElection.c
浏览文件 @
7eb4153a
...
...
@@ -50,6 +50,7 @@ int32_t syncNodeRequestVotePeers(SSyncNode* pSyncNode) {
}
int32_t
syncNodeElect
(
SSyncNode
*
pSyncNode
)
{
int32_t
ret
=
0
;
if
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_FOLLOWER
)
{
syncNodeFollower2Candidate
(
pSyncNode
);
}
...
...
@@ -62,7 +63,15 @@ int32_t syncNodeElect(SSyncNode* pSyncNode) {
votesRespondReset
(
pSyncNode
->
pVotesRespond
,
pSyncNode
->
pRaftStore
->
currentTerm
);
syncNodeVoteForSelf
(
pSyncNode
);
int32_t
ret
=
syncNodeRequestVotePeers
(
pSyncNode
);
if
(
voteGrantedMajority
(
pSyncNode
->
pVotesGranted
))
{
// only myself, to leader
assert
(
!
pSyncNode
->
pVotesGranted
->
toLeader
);
syncNodeCandidate2Leader
(
pSyncNode
);
pSyncNode
->
pVotesGranted
->
toLeader
=
true
;
return
ret
;
}
ret
=
syncNodeRequestVotePeers
(
pSyncNode
);
assert
(
ret
==
0
);
syncNodeResetElectTimer
(
pSyncNode
);
...
...
source/libs/sync/src/syncIO.c
浏览文件 @
7eb4153a
...
...
@@ -269,6 +269,7 @@ static void *syncIOConsumerFunc(void *param) {
}
else
if
(
pRpcMsg
->
msgType
==
SYNC_PING_REPLY
)
{
if
(
io
->
FpOnSyncPingReply
!=
NULL
)
{
SyncPingReply
*
pSyncMsg
=
syncPingReplyFromRpcMsg2
(
pRpcMsg
);
assert
(
pSyncMsg
!=
NULL
);
io
->
FpOnSyncPingReply
(
io
->
pSyncNode
,
pSyncMsg
);
syncPingReplyDestroy
(
pSyncMsg
);
}
...
...
@@ -276,6 +277,7 @@ static void *syncIOConsumerFunc(void *param) {
}
else
if
(
pRpcMsg
->
msgType
==
SYNC_CLIENT_REQUEST
)
{
if
(
io
->
FpOnSyncClientRequest
!=
NULL
)
{
SyncClientRequest
*
pSyncMsg
=
syncClientRequestFromRpcMsg2
(
pRpcMsg
);
assert
(
pSyncMsg
!=
NULL
);
io
->
FpOnSyncClientRequest
(
io
->
pSyncNode
,
pSyncMsg
);
syncClientRequestDestroy
(
pSyncMsg
);
}
...
...
@@ -283,6 +285,7 @@ static void *syncIOConsumerFunc(void *param) {
}
else
if
(
pRpcMsg
->
msgType
==
SYNC_REQUEST_VOTE
)
{
if
(
io
->
FpOnSyncRequestVote
!=
NULL
)
{
SyncRequestVote
*
pSyncMsg
=
syncRequestVoteFromRpcMsg2
(
pRpcMsg
);
assert
(
pSyncMsg
!=
NULL
);
io
->
FpOnSyncRequestVote
(
io
->
pSyncNode
,
pSyncMsg
);
syncRequestVoteDestroy
(
pSyncMsg
);
}
...
...
@@ -290,6 +293,7 @@ static void *syncIOConsumerFunc(void *param) {
}
else
if
(
pRpcMsg
->
msgType
==
SYNC_REQUEST_VOTE_REPLY
)
{
if
(
io
->
FpOnSyncRequestVoteReply
!=
NULL
)
{
SyncRequestVoteReply
*
pSyncMsg
=
syncRequestVoteReplyFromRpcMsg2
(
pRpcMsg
);
assert
(
pSyncMsg
!=
NULL
);
io
->
FpOnSyncRequestVoteReply
(
io
->
pSyncNode
,
pSyncMsg
);
syncRequestVoteReplyDestroy
(
pSyncMsg
);
}
...
...
@@ -297,6 +301,7 @@ static void *syncIOConsumerFunc(void *param) {
}
else
if
(
pRpcMsg
->
msgType
==
SYNC_APPEND_ENTRIES
)
{
if
(
io
->
FpOnSyncAppendEntries
!=
NULL
)
{
SyncAppendEntries
*
pSyncMsg
=
syncAppendEntriesFromRpcMsg2
(
pRpcMsg
);
assert
(
pSyncMsg
!=
NULL
);
io
->
FpOnSyncAppendEntries
(
io
->
pSyncNode
,
pSyncMsg
);
syncAppendEntriesDestroy
(
pSyncMsg
);
}
...
...
@@ -304,6 +309,7 @@ static void *syncIOConsumerFunc(void *param) {
}
else
if
(
pRpcMsg
->
msgType
==
SYNC_APPEND_ENTRIES_REPLY
)
{
if
(
io
->
FpOnSyncAppendEntriesReply
!=
NULL
)
{
SyncAppendEntriesReply
*
pSyncMsg
=
syncAppendEntriesReplyFromRpcMsg2
(
pRpcMsg
);
assert
(
pSyncMsg
!=
NULL
);
io
->
FpOnSyncAppendEntriesReply
(
io
->
pSyncNode
,
pSyncMsg
);
syncAppendEntriesReplyDestroy
(
pSyncMsg
);
}
...
...
@@ -311,6 +317,7 @@ static void *syncIOConsumerFunc(void *param) {
}
else
if
(
pRpcMsg
->
msgType
==
SYNC_TIMEOUT
)
{
if
(
io
->
FpOnSyncTimeout
!=
NULL
)
{
SyncTimeout
*
pSyncMsg
=
syncTimeoutFromRpcMsg2
(
pRpcMsg
);
assert
(
pSyncMsg
!=
NULL
);
io
->
FpOnSyncTimeout
(
io
->
pSyncNode
,
pSyncMsg
);
syncTimeoutDestroy
(
pSyncMsg
);
}
...
...
source/libs/sync/src/syncIndexMgr.c
浏览文件 @
7eb4153a
...
...
@@ -70,6 +70,7 @@ cJSON *syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr) {
char
u64buf
[
128
];
cJSON
*
pRoot
=
cJSON_CreateObject
();
if
(
pSyncIndexMgr
!=
NULL
)
{
cJSON_AddNumberToObject
(
pRoot
,
"replicaNum"
,
pSyncIndexMgr
->
replicaNum
);
cJSON
*
pReplicas
=
cJSON_CreateArray
();
cJSON_AddItemToObject
(
pRoot
,
"replicas"
,
pReplicas
);
...
...
@@ -86,6 +87,7 @@ cJSON *syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr) {
cJSON_AddItemToObject
(
pRoot
,
"index"
,
pIndex
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSyncIndexMgr
->
pSyncNode
);
cJSON_AddStringToObject
(
pRoot
,
"pSyncNode"
,
u64buf
);
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"pSyncIndexMgr"
,
pRoot
);
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
7eb4153a
...
...
@@ -103,6 +103,12 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) {
assert
(
pSyncNode
!=
NULL
);
memset
(
pSyncNode
,
0
,
sizeof
(
SSyncNode
));
if
(
taosMkDir
(
pSyncInfo
->
path
)
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
sError
(
"failed to create dir:%s since %s"
,
pSyncInfo
->
path
,
terrstr
());
return
NULL
;
}
// init by SSyncInfo
pSyncNode
->
vgId
=
pSyncInfo
->
vgId
;
pSyncNode
->
syncCfg
=
pSyncInfo
->
syncCfg
;
...
...
@@ -200,6 +206,9 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) {
pSyncNode
->
FpOnAppendEntriesReply
=
syncNodeOnAppendEntriesReplyCb
;
pSyncNode
->
FpOnTimeout
=
syncNodeOnTimeoutCb
;
// start raft
syncNodeBecomeFollower
(
pSyncNode
);
return
pSyncNode
;
}
...
...
@@ -355,6 +364,7 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) {
char
u64buf
[
128
];
cJSON
*
pRoot
=
cJSON_CreateObject
();
if
(
pSyncNode
!=
NULL
)
{
// init by SSyncInfo
cJSON_AddNumberToObject
(
pRoot
,
"vgId"
,
pSyncNode
->
vgId
);
cJSON_AddStringToObject
(
pRoot
,
"path"
,
pSyncNode
->
path
);
...
...
@@ -477,6 +487,7 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) {
cJSON_AddStringToObject
(
pRoot
,
"FpOnAppendEntriesReply"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSyncNode
->
FpOnTimeout
);
cJSON_AddStringToObject
(
pRoot
,
"FpOnTimeout"
,
u64buf
);
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SSyncNode"
,
pRoot
);
...
...
@@ -500,15 +511,17 @@ void syncNodeUpdateTerm(SSyncNode* pSyncNode, SyncTerm term) {
}
void
syncNodeBecomeFollower
(
SSyncNode
*
pSyncNode
)
{
// maybe clear leader cache
if
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
pSyncNode
->
leaderCache
=
EMPTY_RAFT_ID
;
}
// state change
pSyncNode
->
state
=
TAOS_SYNC_STATE_FOLLOWER
;
syncNodeStopHeartbeatTimer
(
pSyncNode
);
int32_t
electMS
=
syncUtilElectRandomMS
();
syncNodeRes
tartElectTimer
(
pSyncNode
,
electMS
);
// reset elect timer
syncNodeRes
etElectTimer
(
pSyncNode
);
}
// TLA+ Spec
...
...
@@ -530,20 +543,32 @@ void syncNodeBecomeFollower(SSyncNode* pSyncNode) {
// /\ UNCHANGED <<messages, currentTerm, votedFor, candidateVars, logVars>>
//
void
syncNodeBecomeLeader
(
SSyncNode
*
pSyncNode
)
{
// state change
pSyncNode
->
state
=
TAOS_SYNC_STATE_LEADER
;
// set leader cache
pSyncNode
->
leaderCache
=
pSyncNode
->
myRaftId
;
for
(
int
i
=
0
;
i
<
pSyncNode
->
pNextIndex
->
replicaNum
;
++
i
)
{
// maybe overwrite myself, no harm
// just do it!
pSyncNode
->
pNextIndex
->
index
[
i
]
=
pSyncNode
->
pLogStore
->
getLastIndex
(
pSyncNode
->
pLogStore
)
+
1
;
}
for
(
int
i
=
0
;
i
<
pSyncNode
->
pMatchIndex
->
replicaNum
;
++
i
)
{
// maybe overwrite myself, no harm
// just do it!
pSyncNode
->
pMatchIndex
->
index
[
i
]
=
SYNC_INDEX_INVALID
;
}
// stop elect timer
syncNodeStopElectTimer
(
pSyncNode
);
syncNodeStartHeartbeatTimer
(
pSyncNode
);
// start replicate right now!
syncNodeReplicate
(
pSyncNode
);
// start heartbeat timer
syncNodeStartHeartbeatTimer
(
pSyncNode
);
}
void
syncNodeCandidate2Leader
(
SSyncNode
*
pSyncNode
)
{
...
...
@@ -568,6 +593,9 @@ void syncNodeCandidate2Follower(SSyncNode* pSyncNode) {
}
// raft vote --------------
// just called by syncNodeVoteForSelf
// need assert
void
syncNodeVoteForTerm
(
SSyncNode
*
pSyncNode
,
SyncTerm
term
,
SRaftId
*
pRaftId
)
{
assert
(
term
==
pSyncNode
->
pRaftStore
->
currentTerm
);
assert
(
!
raftStoreHasVoted
(
pSyncNode
->
pRaftStore
));
...
...
@@ -575,6 +603,7 @@ void syncNodeVoteForTerm(SSyncNode* pSyncNode, SyncTerm term, SRaftId* pRaftId)
raftStoreVote
(
pSyncNode
->
pRaftStore
,
pRaftId
);
}
// simulate get vote from outside
void
syncNodeVoteForSelf
(
SSyncNode
*
pSyncNode
)
{
syncNodeVoteForTerm
(
pSyncNode
,
pSyncNode
->
pRaftStore
->
currentTerm
,
&
(
pSyncNode
->
myRaftId
));
...
...
@@ -589,8 +618,6 @@ void syncNodeVoteForSelf(SSyncNode* pSyncNode) {
syncRequestVoteReplyDestroy
(
pMsg
);
}
void
syncNodeMaybeAdvanceCommitIndex
(
SSyncNode
*
pSyncNode
)
{}
// for debug --------------
void
syncNodePrint
(
SSyncNode
*
pObj
)
{
char
*
serialized
=
syncNode2Str
(
pObj
);
...
...
@@ -676,7 +703,8 @@ static void syncNodeEqHeartbeatTimer(void* param, void* tmrId) {
taosTmrReset
(
syncNodeEqHeartbeatTimer
,
pSyncNode
->
heartbeatTimerMS
,
pSyncNode
,
gSyncEnv
->
pTimerManager
,
&
pSyncNode
->
pHeartbeatTimer
);
}
else
{
sTrace
(
"==syncNodeEqHeartbeatTimer== heartbeatTimerLogicClock:%"
PRIu64
", heartbeatTimerLogicClockUser:%"
PRIu64
""
,
sTrace
(
"==syncNodeEqHeartbeatTimer== heartbeatTimerLogicClock:%"
PRIu64
", heartbeatTimerLogicClockUser:%"
PRIu64
""
,
pSyncNode
->
heartbeatTimerLogicClock
,
pSyncNode
->
heartbeatTimerLogicClockUser
);
}
}
...
...
source/libs/sync/src/syncMessage.c
浏览文件 @
7eb4153a
...
...
@@ -213,16 +213,18 @@ SyncTimeout* syncTimeoutFromRpcMsg2(const SRpcMsg* pRpcMsg) {
cJSON
*
syncTimeout2Json
(
const
SyncTimeout
*
pMsg
)
{
char
u64buf
[
128
];
cJSON
*
pRoot
=
cJSON_CreateObject
();
if
(
pMsg
!=
NULL
)
{
cJSON_AddNumberToObject
(
pRoot
,
"bytes"
,
pMsg
->
bytes
);
cJSON_AddNumberToObject
(
pRoot
,
"msgType"
,
pMsg
->
msgType
);
cJSON_AddNumberToObject
(
pRoot
,
"timeoutType"
,
pMsg
->
timeoutType
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
"
"
,
pMsg
->
logicClock
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu
"
,
pMsg
->
logicClock
);
cJSON_AddStringToObject
(
pRoot
,
"logicClock"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"timerMS"
,
pMsg
->
timerMS
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pMsg
->
data
);
cJSON_AddStringToObject
(
pRoot
,
"data"
,
u64buf
);
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SyncTimeout"
,
pRoot
);
...
...
@@ -343,13 +345,14 @@ SyncPing* syncPingFromRpcMsg2(const SRpcMsg* pRpcMsg) {
cJSON
*
syncPing2Json
(
const
SyncPing
*
pMsg
)
{
char
u64buf
[
128
];
cJSON
*
pRoot
=
cJSON_CreateObject
();
if
(
pMsg
!=
NULL
)
{
cJSON_AddNumberToObject
(
pRoot
,
"bytes"
,
pMsg
->
bytes
);
cJSON_AddNumberToObject
(
pRoot
,
"msgType"
,
pMsg
->
msgType
);
cJSON
*
pSrcId
=
cJSON_CreateObject
();
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
"
"
,
pMsg
->
srcId
.
addr
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu
"
,
pMsg
->
srcId
.
addr
);
cJSON_AddStringToObject
(
pSrcId
,
"addr"
,
u64buf
);
{
uint64_t
u64
=
pMsg
->
srcId
.
addr
;
...
...
@@ -364,7 +367,7 @@ cJSON* syncPing2Json(const SyncPing* pMsg) {
cJSON_AddItemToObject
(
pRoot
,
"srcId"
,
pSrcId
);
cJSON
*
pDestId
=
cJSON_CreateObject
();
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
"
"
,
pMsg
->
destId
.
addr
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu
"
,
pMsg
->
destId
.
addr
);
cJSON_AddStringToObject
(
pDestId
,
"addr"
,
u64buf
);
{
uint64_t
u64
=
pMsg
->
destId
.
addr
;
...
...
@@ -386,6 +389,7 @@ cJSON* syncPing2Json(const SyncPing* pMsg) {
s
=
syncUtilprintBin2
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
cJSON_AddStringToObject
(
pRoot
,
"data2"
,
s
);
free
(
s
);
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SyncPing"
,
pRoot
);
...
...
@@ -506,13 +510,14 @@ SyncPingReply* syncPingReplyFromRpcMsg2(const SRpcMsg* pRpcMsg) {
cJSON
*
syncPingReply2Json
(
const
SyncPingReply
*
pMsg
)
{
char
u64buf
[
128
];
cJSON
*
pRoot
=
cJSON_CreateObject
();
if
(
pMsg
!=
NULL
)
{
cJSON_AddNumberToObject
(
pRoot
,
"bytes"
,
pMsg
->
bytes
);
cJSON_AddNumberToObject
(
pRoot
,
"msgType"
,
pMsg
->
msgType
);
cJSON
*
pSrcId
=
cJSON_CreateObject
();
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
"
"
,
pMsg
->
srcId
.
addr
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu
"
,
pMsg
->
srcId
.
addr
);
cJSON_AddStringToObject
(
pSrcId
,
"addr"
,
u64buf
);
{
uint64_t
u64
=
pMsg
->
srcId
.
addr
;
...
...
@@ -527,7 +532,7 @@ cJSON* syncPingReply2Json(const SyncPingReply* pMsg) {
cJSON_AddItemToObject
(
pRoot
,
"srcId"
,
pSrcId
);
cJSON
*
pDestId
=
cJSON_CreateObject
();
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
"
"
,
pMsg
->
destId
.
addr
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu
"
,
pMsg
->
destId
.
addr
);
cJSON_AddStringToObject
(
pDestId
,
"addr"
,
u64buf
);
{
uint64_t
u64
=
pMsg
->
destId
.
addr
;
...
...
@@ -549,6 +554,7 @@ cJSON* syncPingReply2Json(const SyncPingReply* pMsg) {
s
=
syncUtilprintBin2
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
cJSON_AddStringToObject
(
pRoot
,
"data2"
,
s
);
free
(
s
);
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SyncPingReply"
,
pRoot
);
...
...
@@ -665,12 +671,13 @@ SyncClientRequest* syncClientRequestFromRpcMsg2(const SRpcMsg* pRpcMsg) {
cJSON
*
syncClientRequest2Json
(
const
SyncClientRequest
*
pMsg
)
{
char
u64buf
[
128
];
cJSON
*
pRoot
=
cJSON_CreateObject
();
if
(
pMsg
!=
NULL
)
{
cJSON_AddNumberToObject
(
pRoot
,
"bytes"
,
pMsg
->
bytes
);
cJSON_AddNumberToObject
(
pRoot
,
"msgType"
,
pMsg
->
msgType
);
cJSON_AddNumberToObject
(
pRoot
,
"originalRpcType"
,
pMsg
->
originalRpcType
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
"
"
,
pMsg
->
seqNum
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu
"
,
pMsg
->
seqNum
);
cJSON_AddStringToObject
(
pRoot
,
"seqNum"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"isWeak"
,
pMsg
->
isWeak
);
cJSON_AddNumberToObject
(
pRoot
,
"dataLen"
,
pMsg
->
dataLen
);
...
...
@@ -682,6 +689,7 @@ cJSON* syncClientRequest2Json(const SyncClientRequest* pMsg) {
s
=
syncUtilprintBin2
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
cJSON_AddStringToObject
(
pRoot
,
"data2"
,
s
);
free
(
s
);
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SyncClientRequest"
,
pRoot
);
...
...
@@ -786,13 +794,14 @@ SyncRequestVote* syncRequestVoteFromRpcMsg2(const SRpcMsg* pRpcMsg) {
cJSON
*
syncRequestVote2Json
(
const
SyncRequestVote
*
pMsg
)
{
char
u64buf
[
128
];
cJSON
*
pRoot
=
cJSON_CreateObject
();
if
(
pMsg
!=
NULL
)
{
cJSON_AddNumberToObject
(
pRoot
,
"bytes"
,
pMsg
->
bytes
);
cJSON_AddNumberToObject
(
pRoot
,
"msgType"
,
pMsg
->
msgType
);
cJSON
*
pSrcId
=
cJSON_CreateObject
();
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
"
"
,
pMsg
->
srcId
.
addr
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu
"
,
pMsg
->
srcId
.
addr
);
cJSON_AddStringToObject
(
pSrcId
,
"addr"
,
u64buf
);
{
uint64_t
u64
=
pMsg
->
srcId
.
addr
;
...
...
@@ -820,12 +829,13 @@ cJSON* syncRequestVote2Json(const SyncRequestVote* pMsg) {
cJSON_AddNumberToObject
(
pDestId
,
"vgId"
,
pMsg
->
destId
.
vgId
);
cJSON_AddItemToObject
(
pRoot
,
"destId"
,
pDestId
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
"
"
,
pMsg
->
term
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu
"
,
pMsg
->
term
);
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
"
"
,
pMsg
->
lastLogIndex
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu
"
,
pMsg
->
lastLogIndex
);
cJSON_AddStringToObject
(
pRoot
,
"lastLogIndex"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
"
"
,
pMsg
->
lastLogTerm
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu
"
,
pMsg
->
lastLogTerm
);
cJSON_AddStringToObject
(
pRoot
,
"lastLogTerm"
,
u64buf
);
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SyncRequestVote"
,
pRoot
);
...
...
@@ -930,13 +940,14 @@ SyncRequestVoteReply* syncRequestVoteReplyFromRpcMsg2(const SRpcMsg* pRpcMsg) {
cJSON
*
syncRequestVoteReply2Json
(
const
SyncRequestVoteReply
*
pMsg
)
{
char
u64buf
[
128
];
cJSON
*
pRoot
=
cJSON_CreateObject
();
if
(
pMsg
!=
NULL
)
{
cJSON_AddNumberToObject
(
pRoot
,
"bytes"
,
pMsg
->
bytes
);
cJSON_AddNumberToObject
(
pRoot
,
"msgType"
,
pMsg
->
msgType
);
cJSON
*
pSrcId
=
cJSON_CreateObject
();
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
"
"
,
pMsg
->
srcId
.
addr
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu
"
,
pMsg
->
srcId
.
addr
);
cJSON_AddStringToObject
(
pSrcId
,
"addr"
,
u64buf
);
{
uint64_t
u64
=
pMsg
->
srcId
.
addr
;
...
...
@@ -964,9 +975,10 @@ cJSON* syncRequestVoteReply2Json(const SyncRequestVoteReply* pMsg) {
cJSON_AddNumberToObject
(
pDestId
,
"vgId"
,
pMsg
->
destId
.
vgId
);
cJSON_AddItemToObject
(
pRoot
,
"destId"
,
pDestId
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
"
"
,
pMsg
->
term
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu
"
,
pMsg
->
term
);
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"vote_granted"
,
pMsg
->
voteGranted
);
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SyncRequestVoteReply"
,
pRoot
);
...
...
@@ -1073,13 +1085,14 @@ SyncAppendEntries* syncAppendEntriesFromRpcMsg2(const SRpcMsg* pRpcMsg) {
cJSON
*
syncAppendEntries2Json
(
const
SyncAppendEntries
*
pMsg
)
{
char
u64buf
[
128
];
cJSON
*
pRoot
=
cJSON_CreateObject
();
if
(
pMsg
!=
NULL
)
{
cJSON_AddNumberToObject
(
pRoot
,
"bytes"
,
pMsg
->
bytes
);
cJSON_AddNumberToObject
(
pRoot
,
"msgType"
,
pMsg
->
msgType
);
cJSON
*
pSrcId
=
cJSON_CreateObject
();
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
"
"
,
pMsg
->
srcId
.
addr
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu
"
,
pMsg
->
srcId
.
addr
);
cJSON_AddStringToObject
(
pSrcId
,
"addr"
,
u64buf
);
{
uint64_t
u64
=
pMsg
->
srcId
.
addr
;
...
...
@@ -1094,7 +1107,7 @@ cJSON* syncAppendEntries2Json(const SyncAppendEntries* pMsg) {
cJSON_AddItemToObject
(
pRoot
,
"srcId"
,
pSrcId
);
cJSON
*
pDestId
=
cJSON_CreateObject
();
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
"
"
,
pMsg
->
destId
.
addr
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu
"
,
pMsg
->
destId
.
addr
);
cJSON_AddStringToObject
(
pDestId
,
"addr"
,
u64buf
);
{
uint64_t
u64
=
pMsg
->
destId
.
addr
;
...
...
@@ -1108,16 +1121,16 @@ cJSON* syncAppendEntries2Json(const SyncAppendEntries* pMsg) {
cJSON_AddNumberToObject
(
pDestId
,
"vgId"
,
pMsg
->
destId
.
vgId
);
cJSON_AddItemToObject
(
pRoot
,
"destId"
,
pDestId
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
"
"
,
pMsg
->
term
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu
"
,
pMsg
->
term
);
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
"
"
,
pMsg
->
prevLogIndex
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu
"
,
pMsg
->
prevLogIndex
);
cJSON_AddStringToObject
(
pRoot
,
"pre_log_index"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
"
"
,
pMsg
->
prevLogTerm
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu
"
,
pMsg
->
prevLogTerm
);
cJSON_AddStringToObject
(
pRoot
,
"pre_log_term"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
"
"
,
pMsg
->
commitIndex
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu
"
,
pMsg
->
commitIndex
);
cJSON_AddStringToObject
(
pRoot
,
"commit_index"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"dataLen"
,
pMsg
->
dataLen
);
...
...
@@ -1128,6 +1141,7 @@ cJSON* syncAppendEntries2Json(const SyncAppendEntries* pMsg) {
s
=
syncUtilprintBin2
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
cJSON_AddStringToObject
(
pRoot
,
"data2"
,
s
);
free
(
s
);
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SyncAppendEntries"
,
pRoot
);
...
...
@@ -1232,13 +1246,14 @@ SyncAppendEntriesReply* syncAppendEntriesReplyFromRpcMsg2(const SRpcMsg* pRpcMsg
cJSON
*
syncAppendEntriesReply2Json
(
const
SyncAppendEntriesReply
*
pMsg
)
{
char
u64buf
[
128
];
cJSON
*
pRoot
=
cJSON_CreateObject
();
if
(
pMsg
!=
NULL
)
{
cJSON_AddNumberToObject
(
pRoot
,
"bytes"
,
pMsg
->
bytes
);
cJSON_AddNumberToObject
(
pRoot
,
"msgType"
,
pMsg
->
msgType
);
cJSON
*
pSrcId
=
cJSON_CreateObject
();
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
"
"
,
pMsg
->
srcId
.
addr
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu
"
,
pMsg
->
srcId
.
addr
);
cJSON_AddStringToObject
(
pSrcId
,
"addr"
,
u64buf
);
{
uint64_t
u64
=
pMsg
->
srcId
.
addr
;
...
...
@@ -1253,7 +1268,7 @@ cJSON* syncAppendEntriesReply2Json(const SyncAppendEntriesReply* pMsg) {
cJSON_AddItemToObject
(
pRoot
,
"srcId"
,
pSrcId
);
cJSON
*
pDestId
=
cJSON_CreateObject
();
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
"
"
,
pMsg
->
destId
.
addr
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu
"
,
pMsg
->
destId
.
addr
);
cJSON_AddStringToObject
(
pDestId
,
"addr"
,
u64buf
);
{
uint64_t
u64
=
pMsg
->
destId
.
addr
;
...
...
@@ -1267,11 +1282,12 @@ cJSON* syncAppendEntriesReply2Json(const SyncAppendEntriesReply* pMsg) {
cJSON_AddNumberToObject
(
pDestId
,
"vgId"
,
pMsg
->
destId
.
vgId
);
cJSON_AddItemToObject
(
pRoot
,
"destId"
,
pDestId
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
"
"
,
pMsg
->
term
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu
"
,
pMsg
->
term
);
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"success"
,
pMsg
->
success
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
"
"
,
pMsg
->
matchIndex
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu
"
,
pMsg
->
matchIndex
);
cJSON_AddStringToObject
(
pRoot
,
"matchIndex"
,
u64buf
);
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SyncAppendEntriesReply"
,
pRoot
);
...
...
source/libs/sync/src/syncRaftEntry.c
浏览文件 @
7eb4153a
...
...
@@ -69,17 +69,18 @@ SSyncRaftEntry* syncEntryDeserialize(const char* buf, uint32_t len) {
cJSON
*
syncEntry2Json
(
const
SSyncRaftEntry
*
pEntry
)
{
char
u64buf
[
128
];
cJSON
*
pRoot
=
cJSON_CreateObject
();
if
(
pEntry
!=
NULL
)
{
cJSON_AddNumberToObject
(
pRoot
,
"bytes"
,
pEntry
->
bytes
);
cJSON_AddNumberToObject
(
pRoot
,
"msgType"
,
pEntry
->
msgType
);
cJSON_AddNumberToObject
(
pRoot
,
"originalRpcType"
,
pEntry
->
originalRpcType
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
"
"
,
pEntry
->
seqNum
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu
"
,
pEntry
->
seqNum
);
cJSON_AddStringToObject
(
pRoot
,
"seqNum"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"isWeak"
,
pEntry
->
isWeak
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
"
"
,
pEntry
->
term
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu
"
,
pEntry
->
term
);
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
"
"
,
pEntry
->
index
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu
"
,
pEntry
->
index
);
cJSON_AddStringToObject
(
pRoot
,
"index"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"dataLen"
,
pEntry
->
dataLen
);
...
...
@@ -91,6 +92,7 @@ cJSON* syncEntry2Json(const SSyncRaftEntry* pEntry) {
s
=
syncUtilprintBin2
((
char
*
)(
pEntry
->
data
),
pEntry
->
dataLen
);
cJSON_AddStringToObject
(
pRoot
,
"data2"
,
s
);
free
(
s
);
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SSyncRaftEntry"
,
pRoot
);
...
...
source/libs/sync/src/syncRaftLog.c
浏览文件 @
7eb4153a
...
...
@@ -65,8 +65,9 @@ int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) {
SSyncRaftEntry
*
logStoreGetEntry
(
SSyncLogStore
*
pLogStore
,
SyncIndex
index
)
{
SSyncLogStoreData
*
pData
=
pLogStore
->
data
;
SWal
*
pWal
=
pData
->
pWal
;
SSyncRaftEntry
*
pEntry
;
SSyncRaftEntry
*
pEntry
=
NULL
;
if
(
index
>=
SYNC_INDEX_BEGIN
&&
index
<=
logStoreLastIndex
(
pLogStore
))
{
SWalReadHandle
*
pWalHandle
=
walOpenReadHandle
(
pWal
);
walReadWithHandle
(
pWalHandle
,
index
);
pEntry
=
syncEntryDeserialize
(
pWalHandle
->
pHead
->
head
.
body
,
pWalHandle
->
pHead
->
head
.
len
);
...
...
@@ -74,6 +75,8 @@ SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index) {
// need to hold, do not new every time!!
walCloseReadHandle
(
pWalHandle
);
}
return
pEntry
;
}
...
...
@@ -127,16 +130,17 @@ SSyncRaftEntry* logStoreGetLastEntry(SSyncLogStore* pLogStore) {
cJSON
*
logStore2Json
(
SSyncLogStore
*
pLogStore
)
{
char
u64buf
[
128
];
SSyncLogStoreData
*
pData
=
(
SSyncLogStoreData
*
)
pLogStore
->
data
;
cJSON
*
pRoot
=
cJSON_CreateObject
();
if
(
pData
!=
NULL
&&
pData
->
pWal
!=
NULL
)
{
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pData
->
pSyncNode
);
cJSON_AddStringToObject
(
pRoot
,
"pSyncNode"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pData
->
pWal
);
cJSON_AddStringToObject
(
pRoot
,
"pWal"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRId64
"
"
,
logStoreLastIndex
(
pLogStore
));
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%ld
"
,
logStoreLastIndex
(
pLogStore
));
cJSON_AddStringToObject
(
pRoot
,
"LastIndex"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
"
"
,
logStoreLastTerm
(
pLogStore
));
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu
"
,
logStoreLastTerm
(
pLogStore
));
cJSON_AddStringToObject
(
pRoot
,
"LastTerm"
,
u64buf
);
cJSON
*
pEntries
=
cJSON_CreateArray
();
...
...
@@ -147,6 +151,7 @@ cJSON* logStore2Json(SSyncLogStore* pLogStore) {
cJSON_AddItemToArray
(
pEntries
,
syncEntry2Json
(
pEntry
));
syncEntryDestory
(
pEntry
);
}
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SSyncLogStore"
,
pRoot
);
...
...
source/libs/sync/src/syncRaftStore.c
浏览文件 @
7eb4153a
...
...
@@ -97,16 +97,32 @@ int32_t raftStorePersist(SRaftStore *pRaftStore) {
return
0
;
}
static
bool
raftStoreFileExist
(
char
*
path
)
{
return
taosStatFile
(
path
,
NULL
,
NULL
)
>=
0
;
}
static
bool
raftStoreFileExist
(
char
*
path
)
{
bool
b
=
taosStatFile
(
path
,
NULL
,
NULL
)
>=
0
;
return
b
;
}
int32_t
raftStoreSerialize
(
SRaftStore
*
pRaftStore
,
char
*
buf
,
size_t
len
)
{
assert
(
pRaftStore
!=
NULL
);
cJSON
*
pRoot
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
pRoot
,
"current_term"
,
pRaftStore
->
currentTerm
);
cJSON_AddNumberToObject
(
pRoot
,
"vote_for_addr"
,
pRaftStore
->
voteFor
.
addr
);
char
u64Buf
[
128
];
snprintf
(
u64Buf
,
sizeof
(
u64Buf
),
"%lu"
,
pRaftStore
->
currentTerm
);
cJSON_AddStringToObject
(
pRoot
,
"current_term"
,
u64Buf
);
snprintf
(
u64Buf
,
sizeof
(
u64Buf
),
"%lu"
,
pRaftStore
->
voteFor
.
addr
);
cJSON_AddStringToObject
(
pRoot
,
"vote_for_addr"
,
u64Buf
);
cJSON_AddNumberToObject
(
pRoot
,
"vote_for_vgid"
,
pRaftStore
->
voteFor
.
vgId
);
uint64_t
u64
=
pRaftStore
->
voteFor
.
addr
;
char
host
[
128
];
uint16_t
port
;
syncUtilU642Addr
(
u64
,
host
,
sizeof
(
host
),
&
port
);
cJSON_AddStringToObject
(
pRoot
,
"addr_host"
,
host
);
cJSON_AddNumberToObject
(
pRoot
,
"addr_port"
,
port
);
char
*
serialized
=
cJSON_Print
(
pRoot
);
int
len2
=
strlen
(
serialized
);
assert
(
len2
<
len
);
...
...
@@ -125,10 +141,12 @@ int32_t raftStoreDeserialize(SRaftStore *pRaftStore, char *buf, size_t len) {
cJSON
*
pRoot
=
cJSON_Parse
(
buf
);
cJSON
*
pCurrentTerm
=
cJSON_GetObjectItem
(
pRoot
,
"current_term"
);
pRaftStore
->
currentTerm
=
pCurrentTerm
->
valueint
;
assert
(
cJSON_IsString
(
pCurrentTerm
));
sscanf
(
pCurrentTerm
->
valuestring
,
"%lu"
,
&
(
pRaftStore
->
currentTerm
));
cJSON
*
pVoteForAddr
=
cJSON_GetObjectItem
(
pRoot
,
"vote_for_addr"
);
pRaftStore
->
voteFor
.
addr
=
pVoteForAddr
->
valueint
;
assert
(
cJSON_IsString
(
pVoteForAddr
));
sscanf
(
pVoteForAddr
->
valuestring
,
"%lu"
,
&
(
pRaftStore
->
voteFor
.
addr
));
cJSON
*
pVoteForVgid
=
cJSON_GetObjectItem
(
pRoot
,
"vote_for_vgid"
);
pRaftStore
->
voteFor
.
vgId
=
pVoteForVgid
->
valueint
;
...
...
@@ -139,11 +157,10 @@ int32_t raftStoreDeserialize(SRaftStore *pRaftStore, char *buf, size_t len) {
bool
raftStoreHasVoted
(
SRaftStore
*
pRaftStore
)
{
bool
b
=
syncUtilEmptyId
(
&
(
pRaftStore
->
voteFor
));
return
b
;
return
(
!
b
)
;
}
void
raftStoreVote
(
SRaftStore
*
pRaftStore
,
SRaftId
*
pRaftId
)
{
assert
(
!
raftStoreHasVoted
(
pRaftStore
));
assert
(
!
syncUtilEmptyId
(
pRaftId
));
pRaftStore
->
voteFor
=
*
pRaftId
;
raftStorePersist
(
pRaftStore
);
...
...
@@ -164,30 +181,68 @@ void raftStoreSetTerm(SRaftStore *pRaftStore, SyncTerm term) {
raftStorePersist
(
pRaftStore
);
}
int32_t
raftStoreFromJson
(
SRaftStore
*
pRaftStore
,
cJSON
*
pJson
)
{
return
0
;
}
cJSON
*
raftStore2Json
(
SRaftStore
*
pRaftStore
)
{
char
u64buf
[
128
];
cJSON
*
pRoot
=
cJSON_CreateObject
();
if
(
pRaftStore
!=
NULL
)
{
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
pRaftStore
->
currentTerm
);
cJSON_AddStringToObject
(
pRoot
,
"currentTerm"
,
u64buf
);
cJSON
*
pVoteFor
=
cJSON_CreateObject
();
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
pRaftStore
->
voteFor
.
addr
);
cJSON_AddStringToObject
(
pVoteFor
,
"addr"
,
u64buf
);
{
uint64_t
u64
=
pRaftStore
->
voteFor
.
addr
;
char
host
[
128
];
uint16_t
port
;
syncUtilU642Addr
(
u64
,
host
,
sizeof
(
host
),
&
port
);
cJSON_AddStringToObject
(
pVoteFor
,
"addr_host"
,
host
);
cJSON_AddNumberToObject
(
pVoteFor
,
"addr_port"
,
port
);
}
cJSON_AddNumberToObject
(
pVoteFor
,
"vgId"
,
pRaftStore
->
voteFor
.
vgId
);
cJSON_AddItemToObject
(
pRoot
,
"voteFor"
,
pVoteFor
);
int
hasVoted
=
raftStoreHasVoted
(
pRaftStore
);
cJSON_AddNumberToObject
(
pRoot
,
"hasVoted"
,
hasVoted
);
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SRaftStore"
,
pRoot
);
return
pJson
;
}
char
*
raftStore2Str
(
SRaftStore
*
pRaftStore
)
{
cJSON
*
pJson
=
raftStore2Json
(
pRaftStore
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
}
// for debug -------------------
void
raftStorePrint
(
SRaftStore
*
pObj
)
{
char
serialized
[
RAFT_STORE_BLOCK_SIZE
];
raftStoreSerialize
(
pObj
,
serialized
,
sizeof
(
serialized
));
char
*
serialized
=
raftStore2Str
(
pObj
);
printf
(
"raftStorePrint | len:%lu | %s
\n
"
,
strlen
(
serialized
),
serialized
);
fflush
(
NULL
);
free
(
serialized
);
}
void
raftStorePrint2
(
char
*
s
,
SRaftStore
*
pObj
)
{
char
serialized
[
RAFT_STORE_BLOCK_SIZE
];
raftStoreSerialize
(
pObj
,
serialized
,
sizeof
(
serialized
));
char
*
serialized
=
raftStore2Str
(
pObj
);
printf
(
"raftStorePrint2 | len:%lu | %s | %s
\n
"
,
strlen
(
serialized
),
s
,
serialized
);
fflush
(
NULL
);
free
(
serialized
);
}
void
raftStoreLog
(
SRaftStore
*
pObj
)
{
char
serialized
[
RAFT_STORE_BLOCK_SIZE
];
raftStoreSerialize
(
pObj
,
serialized
,
sizeof
(
serialized
));
char
*
serialized
=
raftStore2Str
(
pObj
);
sTrace
(
"raftStoreLog | len:%lu | %s"
,
strlen
(
serialized
),
serialized
);
f
flush
(
NULL
);
f
ree
(
serialized
);
}
void
raftStoreLog2
(
char
*
s
,
SRaftStore
*
pObj
)
{
char
serialized
[
RAFT_STORE_BLOCK_SIZE
];
raftStoreSerialize
(
pObj
,
serialized
,
sizeof
(
serialized
));
char
*
serialized
=
raftStore2Str
(
pObj
);
sTrace
(
"raftStoreLog2 | len:%lu | %s | %s"
,
strlen
(
serialized
),
s
,
serialized
);
f
flush
(
NULL
);
f
ree
(
serialized
);
}
source/libs/sync/src/syncReplication.c
浏览文件 @
7eb4153a
...
...
@@ -18,6 +18,7 @@
#include "syncMessage.h"
#include "syncRaftEntry.h"
#include "syncRaftLog.h"
#include "syncRaftStore.h"
#include "syncUtil.h"
// TLA+ Spec
...
...
@@ -51,32 +52,53 @@ int32_t syncNodeAppendEntriesPeers(SSyncNode* pSyncNode) {
int32_t
ret
=
0
;
for
(
int
i
=
0
;
i
<
pSyncNode
->
peersNum
;
++
i
)
{
SRaftId
*
pDestId
=
&
(
pSyncNode
->
peersId
[
i
]);
SyncIndex
nextIndex
=
syncIndexMgrGetIndex
(
pSyncNode
->
pNextIndex
,
pDestId
);
// set prevLogIndex
SyncIndex
nextIndex
=
syncIndexMgrGetIndex
(
pSyncNode
->
pNextIndex
,
pDestId
);
SyncIndex
preLogIndex
=
nextIndex
-
1
;
// set preLogTerm
SyncTerm
preLogTerm
=
0
;
if
(
preLogIndex
>=
SYNC_INDEX_BEGIN
)
{
SSyncRaftEntry
*
pPreEntry
=
pSyncNode
->
pLogStore
->
getEntry
(
pSyncNode
->
pLogStore
,
preLogIndex
);
assert
(
pPreEntry
!=
NULL
);
preLogTerm
=
pPreEntry
->
term
;
syncEntryDestory
(
pPreEntry
);
}
SyncIndex
lastIndex
=
syncUtilMinIndex
(
pSyncNode
->
pLogStore
->
getLastIndex
(
pSyncNode
->
pLogStore
),
nextIndex
);
assert
(
nextIndex
==
las
tIndex
);
// batch optimized
// SyncIndex lastIndex = syncUtilMinIndex(pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore), nex
tIndex);
SyncAppendEntries
*
pMsg
=
NULL
;
SSyncRaftEntry
*
pEntry
=
logStoreGetEntry
(
pSyncNode
->
pLogStore
,
nextIndex
);
assert
(
pEntry
!=
NULL
);
if
(
pEntry
!=
NULL
)
{
SyncAppendEntries
*
pMsg
=
syncAppendEntriesBuild
(
pEntry
->
bytes
);
// add pEntry into msg
uint32_t
len
;
char
*
serialized
=
syncEntrySerialize
(
pEntry
,
&
len
);
assert
(
len
==
pEntry
->
bytes
);
memcpy
(
pMsg
->
data
,
serialized
,
len
);
free
(
serialized
);
syncEntryDestory
(
pEntry
);
}
else
{
// maybe overflow, send empty record
SyncAppendEntries
*
pMsg
=
syncAppendEntriesBuild
(
0
);
}
pMsg
->
srcId
=
pSyncNode
->
myRaftId
;
pMsg
->
destId
=
*
pDestId
;
pMsg
->
term
=
pSyncNode
->
pRaftStore
->
currentTerm
;
pMsg
->
prevLogIndex
=
preLogIndex
;
pMsg
->
prevLogTerm
=
preLogTerm
;
pMsg
->
commitIndex
=
pSyncNode
->
commitIndex
;
pMsg
->
dataLen
=
pEntry
->
bytes
;
// add pEntry into msg
// send AppendEntries
syncNodeAppendEntries
(
pSyncNode
,
pDestId
,
pMsg
);
syncAppendEntriesDestroy
(
pMsg
);
}
return
ret
;
...
...
source/libs/sync/src/syncRequestVote.c
浏览文件 @
7eb4153a
...
...
@@ -56,6 +56,8 @@ int32_t syncNodeOnRequestVoteCb(SSyncNode* ths, SyncRequestVote* pMsg) {
bool
grant
=
(
pMsg
->
term
==
ths
->
pRaftStore
->
currentTerm
)
&&
logOK
&&
((
!
raftStoreHasVoted
(
ths
->
pRaftStore
))
||
(
syncUtilSameId
(
&
(
ths
->
pRaftStore
->
voteFor
),
&
(
pMsg
->
srcId
))));
if
(
grant
)
{
// maybe has already voted for pMsg->srcId
// vote again, no harm
raftStoreVote
(
ths
->
pRaftStore
,
&
(
pMsg
->
srcId
));
}
...
...
source/libs/sync/src/syncRequestVoteReply.c
浏览文件 @
7eb4153a
...
...
@@ -45,6 +45,7 @@ int32_t syncNodeOnRequestVoteReplyCb(SSyncNode* ths, SyncRequestVoteReply* pMsg)
return
ret
;
}
assert
(
!
(
pMsg
->
term
>
ths
->
pRaftStore
->
currentTerm
));
// no need this code, because if I receive reply.term, then I must have sent for that term.
// if (pMsg->term > ths->pRaftStore->currentTerm) {
// syncNodeUpdateTerm(ths, pMsg->term);
...
...
@@ -52,17 +53,29 @@ int32_t syncNodeOnRequestVoteReplyCb(SSyncNode* ths, SyncRequestVoteReply* pMsg)
assert
(
pMsg
->
term
==
ths
->
pRaftStore
->
currentTerm
);
// This tallies votes even when the current state is not Candidate,
// but they won't be looked at, so it doesn't matter.
if
(
ths
->
state
==
TAOS_SYNC_STATE_CANDIDATE
)
{
votesRespondAdd
(
ths
->
pVotesRespond
,
pMsg
);
if
(
pMsg
->
voteGranted
)
{
// add vote
voteGrantedVote
(
ths
->
pVotesGranted
,
pMsg
);
// maybe to leader
if
(
voteGrantedMajority
(
ths
->
pVotesGranted
))
{
if
(
ths
->
pVotesGranted
->
toLeader
)
{
if
(
!
ths
->
pVotesGranted
->
toLeader
)
{
syncNodeCandidate2Leader
(
ths
);
// prevent to leader again!
ths
->
pVotesGranted
->
toLeader
=
true
;
}
}
}
else
{
;
// do nothing
// UNCHANGED <<votesGranted, voterLog>>
}
}
return
ret
;
}
source/libs/sync/src/syncTimeout.c
浏览文件 @
7eb4153a
...
...
@@ -24,7 +24,8 @@ int32_t syncNodeOnTimeoutCb(SSyncNode* ths, SyncTimeout* pMsg) {
if
(
pMsg
->
timeoutType
==
SYNC_TIMEOUT_PING
)
{
if
(
atomic_load_64
(
&
ths
->
pingTimerLogicClockUser
)
<=
pMsg
->
logicClock
)
{
++
(
ths
->
pingTimerCounter
);
syncNodePingAll
(
ths
);
// syncNodePingAll(ths);
syncNodePingPeers
(
ths
);
}
}
else
if
(
pMsg
->
timeoutType
==
SYNC_TIMEOUT_ELECTION
)
{
...
...
source/libs/sync/src/syncUtil.c
浏览文件 @
7eb4153a
...
...
@@ -14,15 +14,12 @@
*/
#include "syncUtil.h"
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include "syncEnv.h"
// ---- encode / decode
uint64_t
syncUtilAddr2U64
(
const
char
*
host
,
uint16_t
port
)
{
uint64_t
u64
;
uint32_t
hostU32
=
(
uint32_t
)
inet_a
ddr
(
host
);
uint32_t
hostU32
=
(
uint32_t
)
taosInetA
ddr
(
host
);
// assert(hostU32 != (uint32_t)-1);
u64
=
(((
uint64_t
)
hostU32
)
<<
32
)
|
(((
uint32_t
)
port
)
<<
16
);
return
u64
;
...
...
@@ -33,7 +30,7 @@ void syncUtilU642Addr(uint64_t u64, char* host, size_t len, uint16_t* port) {
struct
in_addr
addr
;
addr
.
s_addr
=
hostU32
;
snprintf
(
host
,
len
,
"%s"
,
inet_n
toa
(
addr
));
snprintf
(
host
,
len
,
"%s"
,
taosInetN
toa
(
addr
));
*
port
=
(
uint16_t
)((
u64
&
0x00000000FFFF0000
)
>>
16
);
}
...
...
source/libs/sync/src/syncVoteMgr.c
浏览文件 @
7eb4153a
...
...
@@ -82,6 +82,7 @@ cJSON *voteGranted2Json(SVotesGranted *pVotesGranted) {
char
u64buf
[
128
];
cJSON
*
pRoot
=
cJSON_CreateObject
();
if
(
pVotesGranted
!=
NULL
)
{
cJSON_AddNumberToObject
(
pRoot
,
"replicaNum"
,
pVotesGranted
->
replicaNum
);
cJSON
*
pReplicas
=
cJSON_CreateArray
();
cJSON_AddItemToObject
(
pRoot
,
"replicas"
,
pReplicas
);
...
...
@@ -97,7 +98,7 @@ cJSON *voteGranted2Json(SVotesGranted *pVotesGranted) {
cJSON_AddItemToObject
(
pRoot
,
"isGranted"
,
pIsGranted
);
cJSON_AddNumberToObject
(
pRoot
,
"votes"
,
pVotesGranted
->
votes
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
"
"
,
pVotesGranted
->
term
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu
"
,
pVotesGranted
->
term
);
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"quorum"
,
pVotesGranted
->
quorum
);
cJSON_AddNumberToObject
(
pRoot
,
"toLeader"
,
pVotesGranted
->
toLeader
);
...
...
@@ -106,6 +107,7 @@ cJSON *voteGranted2Json(SVotesGranted *pVotesGranted) {
bool
majority
=
voteGrantedMajority
(
pVotesGranted
);
cJSON_AddNumberToObject
(
pRoot
,
"majority"
,
majority
);
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SVotesGranted"
,
pRoot
);
...
...
@@ -122,27 +124,27 @@ char *voteGranted2Str(SVotesGranted *pVotesGranted) {
// for debug -------------------
void
voteGrantedPrint
(
SVotesGranted
*
pObj
)
{
char
*
serialized
=
voteGranted2Str
(
pObj
);
printf
(
"voteGrantedPrint | len:%
z
u | %s
\n
"
,
strlen
(
serialized
),
serialized
);
printf
(
"voteGrantedPrint | len:%
l
u | %s
\n
"
,
strlen
(
serialized
),
serialized
);
fflush
(
NULL
);
free
(
serialized
);
}
void
voteGrantedPrint2
(
char
*
s
,
SVotesGranted
*
pObj
)
{
char
*
serialized
=
voteGranted2Str
(
pObj
);
printf
(
"voteGrantedPrint2 | len:%
z
u | %s | %s
\n
"
,
strlen
(
serialized
),
s
,
serialized
);
printf
(
"voteGrantedPrint2 | len:%
l
u | %s | %s
\n
"
,
strlen
(
serialized
),
s
,
serialized
);
fflush
(
NULL
);
free
(
serialized
);
}
void
voteGrantedLog
(
SVotesGranted
*
pObj
)
{
char
*
serialized
=
voteGranted2Str
(
pObj
);
sTrace
(
"voteGrantedLog | len:%
z
u | %s"
,
strlen
(
serialized
),
serialized
);
sTrace
(
"voteGrantedLog | len:%
l
u | %s"
,
strlen
(
serialized
),
serialized
);
free
(
serialized
);
}
void
voteGrantedLog2
(
char
*
s
,
SVotesGranted
*
pObj
)
{
char
*
serialized
=
voteGranted2Str
(
pObj
);
sTrace
(
"voteGrantedLog2 | len:%
z
u | %s | %s"
,
strlen
(
serialized
),
s
,
serialized
);
sTrace
(
"voteGrantedLog2 | len:%
l
u | %s | %s"
,
strlen
(
serialized
),
s
,
serialized
);
free
(
serialized
);
}
...
...
@@ -203,6 +205,7 @@ cJSON *votesRespond2Json(SVotesRespond *pVotesRespond) {
char
u64buf
[
128
];
cJSON
*
pRoot
=
cJSON_CreateObject
();
if
(
pVotesRespond
!=
NULL
)
{
cJSON_AddNumberToObject
(
pRoot
,
"replicaNum"
,
pVotesRespond
->
replicaNum
);
cJSON
*
pReplicas
=
cJSON_CreateArray
();
cJSON_AddItemToObject
(
pRoot
,
"replicas"
,
pReplicas
);
...
...
@@ -222,10 +225,11 @@ cJSON *votesRespond2Json(SVotesRespond *pVotesRespond) {
cJSON_AddItemToObject
(
pRoot
,
"isRespond"
,
pIsRespond
);
cJSON_AddNumberToObject
(
pRoot
,
"respondNum"
,
respondNum
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
"
"
,
pVotesRespond
->
term
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu
"
,
pVotesRespond
->
term
);
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pVotesRespond
->
pSyncNode
);
cJSON_AddStringToObject
(
pRoot
,
"pSyncNode"
,
u64buf
);
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SVotesRespond"
,
pRoot
);
...
...
@@ -242,26 +246,26 @@ char *votesRespond2Str(SVotesRespond *pVotesRespond) {
// for debug -------------------
void
votesRespondPrint
(
SVotesRespond
*
pObj
)
{
char
*
serialized
=
votesRespond2Str
(
pObj
);
printf
(
"votesRespondPrint | len:%
z
u | %s
\n
"
,
strlen
(
serialized
),
serialized
);
printf
(
"votesRespondPrint | len:%
l
u | %s
\n
"
,
strlen
(
serialized
),
serialized
);
fflush
(
NULL
);
free
(
serialized
);
}
void
votesRespondPrint2
(
char
*
s
,
SVotesRespond
*
pObj
)
{
char
*
serialized
=
votesRespond2Str
(
pObj
);
printf
(
"votesRespondPrint2 | len:%
z
u | %s | %s
\n
"
,
strlen
(
serialized
),
s
,
serialized
);
printf
(
"votesRespondPrint2 | len:%
l
u | %s | %s
\n
"
,
strlen
(
serialized
),
s
,
serialized
);
fflush
(
NULL
);
free
(
serialized
);
}
void
votesRespondLog
(
SVotesRespond
*
pObj
)
{
char
*
serialized
=
votesRespond2Str
(
pObj
);
sTrace
(
"votesRespondLog | len:%
z
u | %s"
,
strlen
(
serialized
),
serialized
);
sTrace
(
"votesRespondLog | len:%
l
u | %s"
,
strlen
(
serialized
),
serialized
);
free
(
serialized
);
}
void
votesRespondLog2
(
char
*
s
,
SVotesRespond
*
pObj
)
{
char
*
serialized
=
votesRespond2Str
(
pObj
);
sTrace
(
"votesRespondLog2 | len:%
z
u | %s | %s"
,
strlen
(
serialized
),
s
,
serialized
);
sTrace
(
"votesRespondLog2 | len:%
l
u | %s | %s"
,
strlen
(
serialized
),
s
,
serialized
);
free
(
serialized
);
}
source/libs/sync/test/CMakeLists.txt
浏览文件 @
7eb4153a
...
...
@@ -25,6 +25,9 @@ add_executable(syncTimeoutTest "")
add_executable
(
syncPingTest
""
)
add_executable
(
syncPingReplyTest
""
)
add_executable
(
syncRpcMsgTest
""
)
add_executable
(
syncPingTimerTest2
""
)
add_executable
(
syncPingSelfTest
""
)
add_executable
(
syncElectTest
""
)
target_sources
(
syncTest
...
...
@@ -135,6 +138,18 @@ target_sources(syncRpcMsgTest
PRIVATE
"syncRpcMsgTest.cpp"
)
target_sources
(
syncPingTimerTest2
PRIVATE
"syncPingTimerTest2.cpp"
)
target_sources
(
syncPingSelfTest
PRIVATE
"syncPingSelfTest.cpp"
)
target_sources
(
syncElectTest
PRIVATE
"syncElectTest.cpp"
)
target_include_directories
(
syncTest
...
...
@@ -272,6 +287,26 @@ target_include_directories(syncRpcMsgTest
"
${
CMAKE_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncPingTimerTest2
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncPingSelfTest
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncElectTest
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncElectTest
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_link_libraries
(
syncTest
...
...
@@ -382,6 +417,18 @@ target_link_libraries(syncRpcMsgTest
sync
gtest_main
)
target_link_libraries
(
syncPingTimerTest2
sync
gtest_main
)
target_link_libraries
(
syncPingSelfTest
sync
gtest_main
)
target_link_libraries
(
syncElectTest
sync
gtest_main
)
enable_testing
()
...
...
source/libs/sync/test/syncElectTest.cpp
0 → 100644
浏览文件 @
7eb4153a
#include <gtest/gtest.h>
#include <stdio.h>
#include "syncEnv.h"
#include "syncIO.h"
#include "syncInt.h"
#include "syncRaftLog.h"
#include "syncRaftStore.h"
#include "syncUtil.h"
void
logTest
()
{
sTrace
(
"--- sync log test: trace"
);
sDebug
(
"--- sync log test: debug"
);
sInfo
(
"--- sync log test: info"
);
sWarn
(
"--- sync log test: warn"
);
sError
(
"--- sync log test: error"
);
sFatal
(
"--- sync log test: fatal"
);
}
uint16_t
ports
[]
=
{
7010
,
7110
,
7210
,
7310
,
7410
};
int32_t
replicaNum
=
3
;
int32_t
myIndex
=
0
;
SRaftId
ids
[
TSDB_MAX_REPLICA
];
SSyncInfo
syncInfo
;
SSyncFSM
*
pFsm
;
SWal
*
pWal
;
SSyncNode
*
gSyncNode
;
SSyncNode
*
syncNodeInit
()
{
syncInfo
.
vgId
=
1234
;
syncInfo
.
rpcClient
=
gSyncIO
->
clientRpc
;
syncInfo
.
FpSendMsg
=
syncIOSendMsg
;
syncInfo
.
queue
=
gSyncIO
->
pMsgQ
;
syncInfo
.
FpEqMsg
=
syncIOEqMsg
;
syncInfo
.
pFsm
=
pFsm
;
snprintf
(
syncInfo
.
path
,
sizeof
(
syncInfo
.
path
),
"./elect_test_%d"
,
myIndex
);
int
code
=
walInit
();
assert
(
code
==
0
);
SWalCfg
walCfg
;
memset
(
&
walCfg
,
0
,
sizeof
(
SWalCfg
));
walCfg
.
vgId
=
syncInfo
.
vgId
;
walCfg
.
fsyncPeriod
=
1000
;
walCfg
.
retentionPeriod
=
1000
;
walCfg
.
rollPeriod
=
1000
;
walCfg
.
retentionSize
=
1000
;
walCfg
.
segSize
=
1000
;
walCfg
.
level
=
TAOS_WAL_FSYNC
;
char
tmpdir
[
128
];
snprintf
(
tmpdir
,
sizeof
(
tmpdir
),
"./elect_test_wal_%d"
,
myIndex
);
pWal
=
walOpen
(
tmpdir
,
&
walCfg
);
assert
(
pWal
!=
NULL
);
syncInfo
.
pWal
=
pWal
;
SSyncCfg
*
pCfg
=
&
syncInfo
.
syncCfg
;
pCfg
->
myIndex
=
myIndex
;
pCfg
->
replicaNum
=
replicaNum
;
for
(
int
i
=
0
;
i
<
replicaNum
;
++
i
)
{
pCfg
->
nodeInfo
[
i
].
nodePort
=
ports
[
i
];
snprintf
(
pCfg
->
nodeInfo
[
i
].
nodeFqdn
,
sizeof
(
pCfg
->
nodeInfo
[
i
].
nodeFqdn
),
"%s"
,
"127.0.0.1"
);
// taosGetFqdn(pCfg->nodeInfo[0].nodeFqdn);
}
SSyncNode
*
pSyncNode
=
syncNodeOpen
(
&
syncInfo
);
assert
(
pSyncNode
!=
NULL
);
gSyncIO
->
FpOnSyncPing
=
pSyncNode
->
FpOnPing
;
gSyncIO
->
FpOnSyncPingReply
=
pSyncNode
->
FpOnPingReply
;
gSyncIO
->
FpOnSyncRequestVote
=
pSyncNode
->
FpOnRequestVote
;
gSyncIO
->
FpOnSyncRequestVoteReply
=
pSyncNode
->
FpOnRequestVoteReply
;
gSyncIO
->
FpOnSyncAppendEntries
=
pSyncNode
->
FpOnAppendEntries
;
gSyncIO
->
FpOnSyncAppendEntriesReply
=
pSyncNode
->
FpOnAppendEntriesReply
;
gSyncIO
->
FpOnSyncPing
=
pSyncNode
->
FpOnPing
;
gSyncIO
->
FpOnSyncPingReply
=
pSyncNode
->
FpOnPingReply
;
gSyncIO
->
FpOnSyncTimeout
=
pSyncNode
->
FpOnTimeout
;
gSyncIO
->
pSyncNode
=
pSyncNode
;
return
pSyncNode
;
}
SSyncNode
*
syncInitTest
()
{
return
syncNodeInit
();
}
void
initRaftId
(
SSyncNode
*
pSyncNode
)
{
for
(
int
i
=
0
;
i
<
replicaNum
;
++
i
)
{
ids
[
i
]
=
pSyncNode
->
replicasId
[
i
];
char
*
s
=
syncUtilRaftId2Str
(
&
ids
[
i
]);
printf
(
"raftId[%d] : %s
\n
"
,
i
,
s
);
free
(
s
);
}
}
int
main
(
int
argc
,
char
**
argv
)
{
// taosInitLog((char *)"syncTest.log", 100000, 10);
tsAsyncLog
=
0
;
sDebugFlag
=
143
+
64
;
myIndex
=
0
;
if
(
argc
>=
2
)
{
myIndex
=
atoi
(
argv
[
1
]);
}
int32_t
ret
=
syncIOStart
((
char
*
)
"127.0.0.1"
,
ports
[
myIndex
]);
assert
(
ret
==
0
);
ret
=
syncEnvStart
();
assert
(
ret
==
0
);
gSyncNode
=
syncInitTest
();
assert
(
gSyncNode
!=
NULL
);
syncNodePrint2
((
char
*
)
""
,
gSyncNode
);
initRaftId
(
gSyncNode
);
//---------------------------
while
(
1
)
{
sTrace
(
"while 1 sleep, state: %d, %s"
,
gSyncNode
->
state
,
syncUtilState2String
(
gSyncNode
->
state
));
taosMsleep
(
1000
);
}
return
0
;
}
source/libs/sync/test/syncInitTest.cpp
浏览文件 @
7eb4153a
...
...
@@ -47,12 +47,11 @@ SSyncNode* syncNodeInit() {
gSyncIO
->
FpOnSyncPing
=
pSyncNode
->
FpOnPing
;
gSyncIO
->
FpOnSyncPingReply
=
pSyncNode
->
FpOnPingReply
;
gSyncIO
->
FpOnSyncClientRequest
=
pSyncNode
->
FpOnClientRequest
;
gSyncIO
->
FpOnSyncRequestVote
=
pSyncNode
->
FpOnRequestVote
;
gSyncIO
->
FpOnSyncRequestVoteReply
=
pSyncNode
->
FpOnRequestVoteReply
;
gSyncIO
->
FpOnSyncAppendEntries
=
pSyncNode
->
FpOnAppendEntries
;
gSyncIO
->
FpOnSyncAppendEntriesReply
=
pSyncNode
->
FpOnAppendEntriesReply
;
gSyncIO
->
FpOnSyncPing
=
pSyncNode
->
FpOnPing
;
gSyncIO
->
FpOnSyncPingReply
=
pSyncNode
->
FpOnPingReply
;
gSyncIO
->
FpOnSyncTimeout
=
pSyncNode
->
FpOnTimeout
;
gSyncIO
->
pSyncNode
=
pSyncNode
;
...
...
source/libs/sync/test/syncLogStoreTest.cpp
浏览文件 @
7eb4153a
...
...
@@ -81,7 +81,7 @@ SSyncNode* syncNodeInit() {
SSyncNode
*
syncInitTest
()
{
return
syncNodeInit
();
}
void
logStoreTest
()
{
logStorePrint2
((
char
*
)
"logStoreTest
2
"
,
pSyncNode
->
pLogStore
);
logStorePrint2
((
char
*
)
"logStoreTest"
,
pSyncNode
->
pLogStore
);
assert
(
pSyncNode
->
pLogStore
->
getLastIndex
(
pSyncNode
->
pLogStore
)
==
SYNC_INDEX_INVALID
);
...
...
@@ -105,10 +105,10 @@ void logStoreTest() {
assert
(
pSyncNode
->
pLogStore
->
getLastIndex
(
pSyncNode
->
pLogStore
)
==
SYNC_INDEX_BEGIN
);
}
}
logStorePrint
(
pSyncNode
->
pLogStore
);
logStorePrint
2
((
char
*
)
"after appendEntry"
,
pSyncNode
->
pLogStore
);
pSyncNode
->
pLogStore
->
truncate
(
pSyncNode
->
pLogStore
,
3
);
logStorePrint
(
pSyncNode
->
pLogStore
);
logStorePrint
2
((
char
*
)
"after truncate 3"
,
pSyncNode
->
pLogStore
);
}
void
initRaftId
(
SSyncNode
*
pSyncNode
)
{
...
...
source/libs/sync/test/syncPingSelfTest.cpp
0 → 100644
浏览文件 @
7eb4153a
#include <gtest/gtest.h>
#include <stdio.h>
#include "syncEnv.h"
#include "syncIO.h"
#include "syncInt.h"
#include "syncRaftStore.h"
#include "syncUtil.h"
void
logTest
()
{
sTrace
(
"--- sync log test: trace"
);
sDebug
(
"--- sync log test: debug"
);
sInfo
(
"--- sync log test: info"
);
sWarn
(
"--- sync log test: warn"
);
sError
(
"--- sync log test: error"
);
sFatal
(
"--- sync log test: fatal"
);
}
uint16_t
ports
[]
=
{
7010
,
7110
,
7210
,
7310
,
7410
};
int32_t
replicaNum
=
3
;
int32_t
myIndex
=
0
;
SRaftId
ids
[
TSDB_MAX_REPLICA
];
SSyncInfo
syncInfo
;
SSyncFSM
*
pFsm
;
SSyncNode
*
syncNodeInit
()
{
syncInfo
.
vgId
=
1234
;
syncInfo
.
rpcClient
=
gSyncIO
->
clientRpc
;
syncInfo
.
FpSendMsg
=
syncIOSendMsg
;
syncInfo
.
queue
=
gSyncIO
->
pMsgQ
;
syncInfo
.
FpEqMsg
=
syncIOEqMsg
;
syncInfo
.
pFsm
=
pFsm
;
snprintf
(
syncInfo
.
path
,
sizeof
(
syncInfo
.
path
),
"%s"
,
"./"
);
SSyncCfg
*
pCfg
=
&
syncInfo
.
syncCfg
;
pCfg
->
myIndex
=
myIndex
;
pCfg
->
replicaNum
=
replicaNum
;
for
(
int
i
=
0
;
i
<
replicaNum
;
++
i
)
{
pCfg
->
nodeInfo
[
i
].
nodePort
=
ports
[
i
];
snprintf
(
pCfg
->
nodeInfo
[
i
].
nodeFqdn
,
sizeof
(
pCfg
->
nodeInfo
[
i
].
nodeFqdn
),
"%s"
,
"127.0.0.1"
);
// taosGetFqdn(pCfg->nodeInfo[0].nodeFqdn);
}
SSyncNode
*
pSyncNode
=
syncNodeOpen
(
&
syncInfo
);
assert
(
pSyncNode
!=
NULL
);
gSyncIO
->
FpOnSyncPing
=
pSyncNode
->
FpOnPing
;
gSyncIO
->
FpOnSyncPingReply
=
pSyncNode
->
FpOnPingReply
;
gSyncIO
->
FpOnSyncClientRequest
=
pSyncNode
->
FpOnClientRequest
;
gSyncIO
->
FpOnSyncRequestVote
=
pSyncNode
->
FpOnRequestVote
;
gSyncIO
->
FpOnSyncRequestVoteReply
=
pSyncNode
->
FpOnRequestVoteReply
;
gSyncIO
->
FpOnSyncAppendEntries
=
pSyncNode
->
FpOnAppendEntries
;
gSyncIO
->
FpOnSyncAppendEntriesReply
=
pSyncNode
->
FpOnAppendEntriesReply
;
gSyncIO
->
FpOnSyncTimeout
=
pSyncNode
->
FpOnTimeout
;
gSyncIO
->
pSyncNode
=
pSyncNode
;
return
pSyncNode
;
}
SSyncNode
*
syncInitTest
()
{
return
syncNodeInit
();
}
void
initRaftId
(
SSyncNode
*
pSyncNode
)
{
for
(
int
i
=
0
;
i
<
replicaNum
;
++
i
)
{
ids
[
i
]
=
pSyncNode
->
replicasId
[
i
];
char
*
s
=
syncUtilRaftId2Str
(
&
ids
[
i
]);
printf
(
"raftId[%d] : %s
\n
"
,
i
,
s
);
free
(
s
);
}
}
int
main
(
int
argc
,
char
**
argv
)
{
// taosInitLog((char *)"syncTest.log", 100000, 10);
tsAsyncLog
=
0
;
sDebugFlag
=
143
+
64
;
myIndex
=
0
;
if
(
argc
>=
2
)
{
myIndex
=
atoi
(
argv
[
1
]);
}
int32_t
ret
=
syncIOStart
((
char
*
)
"127.0.0.1"
,
ports
[
myIndex
]);
assert
(
ret
==
0
);
ret
=
syncEnvStart
();
assert
(
ret
==
0
);
SSyncNode
*
pSyncNode
=
syncInitTest
();
assert
(
pSyncNode
!=
NULL
);
syncNodePrint2
((
char
*
)
""
,
pSyncNode
);
initRaftId
(
pSyncNode
);
//---------------------------
while
(
1
)
{
syncNodePingSelf
(
pSyncNode
);
taosMsleep
(
1000
);
}
return
0
;
}
source/libs/sync/test/syncPingTimerTest.cpp
浏览文件 @
7eb4153a
...
...
@@ -47,6 +47,7 @@ SSyncNode* syncNodeInit() {
gSyncIO
->
FpOnSyncPing
=
pSyncNode
->
FpOnPing
;
gSyncIO
->
FpOnSyncPingReply
=
pSyncNode
->
FpOnPingReply
;
gSyncIO
->
FpOnSyncClientRequest
=
pSyncNode
->
FpOnClientRequest
;
gSyncIO
->
FpOnSyncRequestVote
=
pSyncNode
->
FpOnRequestVote
;
gSyncIO
->
FpOnSyncRequestVoteReply
=
pSyncNode
->
FpOnRequestVoteReply
;
gSyncIO
->
FpOnSyncAppendEntries
=
pSyncNode
->
FpOnAppendEntries
;
...
...
source/libs/sync/test/syncPingTimerTest2.cpp
0 → 100644
浏览文件 @
7eb4153a
#include <gtest/gtest.h>
#include <stdio.h>
#include "syncEnv.h"
#include "syncIO.h"
#include "syncInt.h"
#include "syncRaftStore.h"
#include "syncUtil.h"
void
logTest
()
{
sTrace
(
"--- sync log test: trace"
);
sDebug
(
"--- sync log test: debug"
);
sInfo
(
"--- sync log test: info"
);
sWarn
(
"--- sync log test: warn"
);
sError
(
"--- sync log test: error"
);
sFatal
(
"--- sync log test: fatal"
);
}
uint16_t
ports
[]
=
{
7010
,
7110
,
7210
,
7310
,
7410
};
int32_t
replicaNum
=
3
;
int32_t
myIndex
=
0
;
SRaftId
ids
[
TSDB_MAX_REPLICA
];
SSyncInfo
syncInfo
;
SSyncFSM
*
pFsm
;
SSyncNode
*
syncNodeInit
()
{
syncInfo
.
vgId
=
1234
;
syncInfo
.
rpcClient
=
gSyncIO
->
clientRpc
;
syncInfo
.
FpSendMsg
=
syncIOSendMsg
;
syncInfo
.
queue
=
gSyncIO
->
pMsgQ
;
syncInfo
.
FpEqMsg
=
syncIOEqMsg
;
syncInfo
.
pFsm
=
pFsm
;
snprintf
(
syncInfo
.
path
,
sizeof
(
syncInfo
.
path
),
"%s"
,
"./"
);
SSyncCfg
*
pCfg
=
&
syncInfo
.
syncCfg
;
pCfg
->
myIndex
=
myIndex
;
pCfg
->
replicaNum
=
replicaNum
;
for
(
int
i
=
0
;
i
<
replicaNum
;
++
i
)
{
pCfg
->
nodeInfo
[
i
].
nodePort
=
ports
[
i
];
snprintf
(
pCfg
->
nodeInfo
[
i
].
nodeFqdn
,
sizeof
(
pCfg
->
nodeInfo
[
i
].
nodeFqdn
),
"%s"
,
"127.0.0.1"
);
// taosGetFqdn(pCfg->nodeInfo[0].nodeFqdn);
}
SSyncNode
*
pSyncNode
=
syncNodeOpen
(
&
syncInfo
);
assert
(
pSyncNode
!=
NULL
);
gSyncIO
->
FpOnSyncPing
=
pSyncNode
->
FpOnPing
;
gSyncIO
->
FpOnSyncPingReply
=
pSyncNode
->
FpOnPingReply
;
gSyncIO
->
FpOnSyncClientRequest
=
pSyncNode
->
FpOnClientRequest
;
gSyncIO
->
FpOnSyncRequestVote
=
pSyncNode
->
FpOnRequestVote
;
gSyncIO
->
FpOnSyncRequestVoteReply
=
pSyncNode
->
FpOnRequestVoteReply
;
gSyncIO
->
FpOnSyncAppendEntries
=
pSyncNode
->
FpOnAppendEntries
;
gSyncIO
->
FpOnSyncAppendEntriesReply
=
pSyncNode
->
FpOnAppendEntriesReply
;
gSyncIO
->
FpOnSyncTimeout
=
pSyncNode
->
FpOnTimeout
;
gSyncIO
->
pSyncNode
=
pSyncNode
;
return
pSyncNode
;
}
SSyncNode
*
syncInitTest
()
{
return
syncNodeInit
();
}
void
initRaftId
(
SSyncNode
*
pSyncNode
)
{
for
(
int
i
=
0
;
i
<
replicaNum
;
++
i
)
{
ids
[
i
]
=
pSyncNode
->
replicasId
[
i
];
char
*
s
=
syncUtilRaftId2Str
(
&
ids
[
i
]);
printf
(
"raftId[%d] : %s
\n
"
,
i
,
s
);
free
(
s
);
}
}
int
main
(
int
argc
,
char
**
argv
)
{
// taosInitLog((char *)"syncTest.log", 100000, 10);
tsAsyncLog
=
0
;
sDebugFlag
=
143
+
64
;
myIndex
=
0
;
if
(
argc
>=
2
)
{
myIndex
=
atoi
(
argv
[
1
]);
}
int32_t
ret
=
syncIOStart
((
char
*
)
"127.0.0.1"
,
ports
[
myIndex
]);
assert
(
ret
==
0
);
ret
=
syncEnvStart
();
assert
(
ret
==
0
);
SSyncNode
*
pSyncNode
=
syncInitTest
();
assert
(
pSyncNode
!=
NULL
);
syncNodePrint2
((
char
*
)
""
,
pSyncNode
);
initRaftId
(
pSyncNode
);
//---------------------------
sTrace
(
"syncNodeStartPingTimer ..."
);
ret
=
syncNodeStartPingTimer
(
pSyncNode
);
assert
(
ret
==
0
);
while
(
1
)
{
sTrace
(
"while 1 sleep ..."
);
taosMsleep
(
1000
);
}
return
0
;
}
source/libs/sync/test/syncRaftStoreTest.cpp
浏览文件 @
7eb4153a
...
...
@@ -3,6 +3,7 @@
#include <stdio.h>
#include "syncIO.h"
#include "syncInt.h"
#include "syncUtil.h"
void
logTest
()
{
sTrace
(
"--- sync log test: trace"
);
...
...
@@ -13,6 +14,21 @@ void logTest() {
sFatal
(
"--- sync log test: fatal"
);
}
uint16_t
ports
[]
=
{
7010
,
7110
,
7210
,
7310
,
7410
};
int32_t
replicaNum
=
5
;
int32_t
myIndex
=
0
;
SRaftId
ids
[
TSDB_MAX_REPLICA
];
void
initRaftId
()
{
for
(
int
i
=
0
;
i
<
replicaNum
;
++
i
)
{
ids
[
i
].
addr
=
syncUtilAddr2U64
(
"127.0.0.1"
,
ports
[
i
]);
ids
[
i
].
vgId
=
1234
;
char
*
s
=
syncUtilRaftId2Str
(
&
ids
[
i
]);
printf
(
"raftId[%d] : %s
\n
"
,
i
,
s
);
free
(
s
);
}
}
int
main
()
{
// taosInitLog((char *)"syncTest.log", 100000, 10);
tsAsyncLog
=
0
;
...
...
@@ -20,23 +36,35 @@ int main() {
logTest
();
SRaftStore
*
pRaftStore
=
raftStoreOpen
(
"./raft_store.json"
);
initRaftId
();
SRaftStore
*
pRaftStore
=
raftStoreOpen
(
"./test_raft_store.json"
);
assert
(
pRaftStore
!=
NULL
);
raftStorePrint
(
pRaftStore
);
#if 0
pRaftStore->currentTerm = 100;
pRaftStore->voteFor.addr = 200;
pRaftStore->voteFor.vgId = 300;
raftStorePersist(pRaftStore);
raftStorePrint(pRaftStore);
#endif
++
(
pRaftStore
->
currentTerm
);
++
(
pRaftStore
->
voteFor
.
addr
);
++
(
pRaftStore
->
voteFor
.
vgId
);
raftStorePersist
(
pRaftStore
);
raftStorePrint
(
pRaftStore
);
raftStorePrint2
((
char
*
)
"==raftStoreOpen=="
,
pRaftStore
);
raftStoreSetTerm
(
pRaftStore
,
100
);
raftStorePrint2
((
char
*
)
"==raftStoreSetTerm=="
,
pRaftStore
);
raftStoreVote
(
pRaftStore
,
&
ids
[
0
]);
raftStorePrint2
((
char
*
)
"==raftStoreVote=="
,
pRaftStore
);
raftStoreClearVote
(
pRaftStore
);
raftStorePrint2
((
char
*
)
"==raftStoreClearVote=="
,
pRaftStore
);
raftStoreVote
(
pRaftStore
,
&
ids
[
1
]);
raftStorePrint2
((
char
*
)
"==raftStoreVote=="
,
pRaftStore
);
raftStoreNextTerm
(
pRaftStore
);
raftStorePrint2
((
char
*
)
"==raftStoreNextTerm=="
,
pRaftStore
);
raftStoreNextTerm
(
pRaftStore
);
raftStorePrint2
((
char
*
)
"==raftStoreNextTerm=="
,
pRaftStore
);
raftStoreNextTerm
(
pRaftStore
);
raftStorePrint2
((
char
*
)
"==raftStoreNextTerm=="
,
pRaftStore
);
raftStoreNextTerm
(
pRaftStore
);
raftStorePrint2
((
char
*
)
"==raftStoreNextTerm=="
,
pRaftStore
);
return
0
;
}
source/libs/tdb/src/db/tdbBtree.c
浏览文件 @
7eb4153a
...
...
@@ -27,7 +27,8 @@ typedef struct {
}
SBtIdx
;
// Btree page header definition
typedef
struct
__attribute__
((
__packed__
))
{
#pragma pack (push,1)
typedef
struct
{
uint8_t
flag
;
// page flag
int32_t
vlen
;
// value length of current page, TDB_VARIANT_LEN for variant length
uint16_t
nPayloads
;
// number of total payloads
...
...
@@ -36,6 +37,7 @@ typedef struct __attribute__((__packed__)) {
pgoff_t
offPayload
;
// payload offset
pgno_t
rChildPgno
;
// right most child page number
}
SBtPgHdr
;
#pragma pack(pop)
typedef
int
(
*
BtreeCmprFn
)(
const
void
*
,
const
void
*
);
...
...
source/libs/tdb/src/db/tdbEnv.c
浏览文件 @
7eb4153a
...
...
@@ -30,11 +30,7 @@ struct STDbEnv {
}
pgfht
;
// page file hash table;
};
#define TDB_ENV_PGF_HASH(fileid) \
({ \
uint8_t *tmp = (uint8_t *)(fileid); \
tmp[0] + tmp[1] + tmp[2]; \
})
#define TDB_ENV_PGF_HASH(fileid) (((uint8_t *)(fileid))[0] + ((uint8_t *)(fileid))[1] + ((uint8_t *)(fileid))[2])
static
int
tdbEnvDestroy
(
TENV
*
pEnv
);
...
...
source/libs/tdb/src/db/tdbPgCache.c
浏览文件 @
7eb4153a
...
...
@@ -106,11 +106,7 @@ int pgCacheClose(SPgCache *pPgCache) {
return
0
;
}
#define PG_CACHE_HASH(fileid, pgno) \
({ \
uint64_t *tmp = (uint64_t *)(fileid); \
(tmp[0] + tmp[1] + tmp[2] + (pgno)); \
})
#define PG_CACHE_HASH(fileid, pgno) (((uint64_t *)(fileid))[0] + ((uint64_t *)(fileid))[1] + ((uint64_t *)(fileid))[2] + (pgno))
SPage
*
pgCacheFetch
(
SPgCache
*
pPgCache
,
pgid_t
pgid
)
{
SPage
*
pPage
;
...
...
source/libs/tdb/src/inc/tdbPgFile.h
浏览文件 @
7eb4153a
...
...
@@ -20,13 +20,15 @@
extern
"C"
{
#endif
typedef
struct
__attribute__
((
__packed__
))
{
#pragma pack (push,1)
typedef
struct
{
char
hdrInfo
[
16
];
// info string
pgsz_t
szPage
;
// page size of current file
int32_t
cno
;
// commit number counter
pgno_t
freePgno
;
// freelist page number
uint8_t
resv
[
100
];
// reserved space
}
SPgFileHdr
;
#pragma pack(pop)
#define TDB_PG_FILE_HDR_SIZE 128
...
...
source/libs/transport/src/transCli.c
浏览文件 @
7eb4153a
...
...
@@ -30,6 +30,7 @@ typedef struct SCliConn {
void
*
hostThrd
;
SConnBuffer
readBuf
;
void
*
data
;
SArray
*
cliMsgs
;
queue
conn
;
uint64_t
expireTime
;
int
hThrdIdx
;
...
...
@@ -106,6 +107,7 @@ static void cliAsyncCb(uv_async_t* handle);
static
SCliConn
*
cliCreateConn
(
SCliThrdObj
*
thrd
);
static
void
cliDestroyConn
(
SCliConn
*
pConn
,
bool
clear
/*clear tcp handle or not*/
);
static
void
cliDestroy
(
uv_handle_t
*
handle
);
static
void
cliSend
(
SCliConn
*
pConn
);
// process data read from server, add decompress etc later
static
void
cliHandleResp
(
SCliConn
*
conn
);
...
...
@@ -156,8 +158,18 @@ static void destroyThrdObj(SCliThrdObj* pThrd);
} while (0)
#define CONN_NO_PERSIST_BY_APP(conn) ((conn)->persist == false)
#define REQUEST_NO_RESP(msg) ((msg)->noResp == 1)
static
void
*
cliWorkThread
(
void
*
arg
);
bool
cliMaySendCachedMsg
(
SCliConn
*
conn
)
{
if
(
taosArrayGetSize
(
conn
->
cliMsgs
)
>
0
)
{
cliSend
(
conn
);
return
true
;
}
else
{
return
false
;
}
}
void
cliHandleResp
(
SCliConn
*
conn
)
{
SCliThrdObj
*
pThrd
=
conn
->
hostThrd
;
STrans
*
pTransInst
=
pThrd
->
pTransInst
;
...
...
@@ -173,18 +185,18 @@ void cliHandleResp(SCliConn* conn) {
transMsg
.
msgType
=
pHead
->
msgType
;
transMsg
.
ahandle
=
NULL
;
SCliMsg
*
pMsg
=
conn
->
data
;
SCliMsg
*
pMsg
=
NULL
;
if
(
taosArrayGetSize
(
conn
->
cliMsgs
)
>
0
)
{
pMsg
=
taosArrayGetP
(
conn
->
cliMsgs
,
0
);
taosArrayRemove
(
conn
->
cliMsgs
,
0
);
}
STransConnCtx
*
pCtx
=
pMsg
?
pMsg
->
ctx
:
NULL
;
if
(
pMsg
==
NULL
&&
!
CONN_NO_PERSIST_BY_APP
(
conn
))
{
transMsg
.
ahandle
=
pTransInst
->
mfp
?
(
*
pTransInst
->
mfp
)(
pTransInst
->
parent
,
transMsg
.
msgType
)
:
NULL
;
}
else
{
transMsg
.
ahandle
=
pCtx
?
pCtx
->
ahandle
:
NULL
;
}
// if (rpcMsg.ahandle == NULL) {
// tDebug("%s cli conn %p handle except", CONN_GET_INST_LABEL(conn), conn);
// return;
//}
// buf's mem alread translated to transMsg.pCont
transClearBuffer
(
&
conn
->
readBuf
);
...
...
@@ -195,8 +207,8 @@ void cliHandleResp(SCliConn* conn) {
}
tDebug
(
"%s cli conn %p %s received from %s:%d, local info: %s:%d, msg size: %d"
,
pTransInst
->
label
,
conn
,
TMSG_INFO
(
pHead
->
msgType
),
inet_n
toa
(
conn
->
addr
.
sin_addr
),
ntohs
(
conn
->
addr
.
sin_port
),
inet_n
toa
(
conn
->
locaddr
.
sin_addr
),
ntohs
(
conn
->
locaddr
.
sin_port
),
transMsg
.
contLen
);
TMSG_INFO
(
pHead
->
msgType
),
taosInetN
toa
(
conn
->
addr
.
sin_addr
),
ntohs
(
conn
->
addr
.
sin_port
),
taosInetN
toa
(
conn
->
locaddr
.
sin_addr
),
ntohs
(
conn
->
locaddr
.
sin_port
),
transMsg
.
contLen
);
conn
->
secured
=
pHead
->
secured
;
...
...
@@ -214,12 +226,15 @@ void cliHandleResp(SCliConn* conn) {
memcpy
((
char
*
)
pCtx
->
pRsp
,
(
char
*
)
&
transMsg
,
sizeof
(
transMsg
));
tsem_post
(
pCtx
->
pSem
);
}
destroyCmsg
(
pMsg
);
if
(
cliMaySendCachedMsg
(
conn
)
==
true
)
{
return
;
}
if
(
CONN_NO_PERSIST_BY_APP
(
conn
))
{
addConnToPool
(
pThrd
->
pool
,
conn
);
}
destroyCmsg
(
conn
->
data
);
conn
->
data
=
NULL
;
uv_read_start
((
uv_stream_t
*
)
conn
->
stream
,
cliAllocRecvBufferCb
,
cliRecvCb
);
// start thread's timer of conn pool if not active
...
...
@@ -229,7 +244,7 @@ void cliHandleResp(SCliConn* conn) {
}
void
cliHandleExcept
(
SCliConn
*
pConn
)
{
if
(
pConn
->
data
==
NULL
)
{
if
(
taosArrayGetSize
(
pConn
->
cliMsgs
)
==
0
)
{
if
(
pConn
->
broken
==
true
||
CONN_NO_PERSIST_BY_APP
(
pConn
))
{
transUnrefCliHandle
(
pConn
);
return
;
...
...
@@ -238,7 +253,13 @@ void cliHandleExcept(SCliConn* pConn) {
SCliThrdObj
*
pThrd
=
pConn
->
hostThrd
;
STrans
*
pTransInst
=
pThrd
->
pTransInst
;
SCliMsg
*
pMsg
=
pConn
->
data
;
do
{
SCliMsg
*
pMsg
=
NULL
;
if
(
taosArrayGetSize
(
pConn
->
cliMsgs
)
>
0
)
{
pMsg
=
taosArrayGetP
(
pConn
->
cliMsgs
,
0
);
taosArrayRemove
(
pConn
->
cliMsgs
,
0
);
}
STransConnCtx
*
pCtx
=
pMsg
?
pMsg
->
ctx
:
NULL
;
STransMsg
transMsg
=
{
0
};
...
...
@@ -260,10 +281,10 @@ void cliHandleExcept(SCliConn* pConn) {
memcpy
((
char
*
)(
pCtx
->
pRsp
),
(
char
*
)(
&
transMsg
),
sizeof
(
transMsg
));
tsem_post
(
pCtx
->
pSem
);
}
destroyCmsg
(
pConn
->
data
);
pConn
->
data
=
NULL
;
destroyCmsg
(
pMsg
);
tTrace
(
"%s cli conn %p start to destroy"
,
CONN_GET_INST_LABEL
(
pConn
),
pConn
);
}
while
(
taosArrayGetSize
(
pConn
->
cliMsgs
)
>
0
);
transUnrefCliHandle
(
pConn
);
}
...
...
@@ -398,6 +419,7 @@ static SCliConn* cliCreateConn(SCliThrdObj* pThrd) {
conn
->
writeReq
.
data
=
conn
;
conn
->
connReq
.
data
=
conn
;
conn
->
cliMsgs
=
taosArrayInit
(
2
,
sizeof
(
void
*
));
QUEUE_INIT
(
&
conn
->
conn
);
conn
->
hostThrd
=
pThrd
;
...
...
@@ -417,32 +439,51 @@ static void cliDestroy(uv_handle_t* handle) {
SCliConn
*
conn
=
handle
->
data
;
free
(
conn
->
ip
);
free
(
conn
->
stream
);
taosArrayDestroy
(
conn
->
cliMsgs
);
tTrace
(
"%s cli conn %p destroy successfully"
,
CONN_GET_INST_LABEL
(
conn
),
conn
);
free
(
conn
);
}
static
bool
cliHandleNoResp
(
SCliConn
*
conn
)
{
bool
res
=
false
;
SArray
*
msgs
=
conn
->
cliMsgs
;
if
(
taosArrayGetSize
(
msgs
)
>
0
)
{
SCliMsg
*
pMsg
=
taosArrayGetP
(
msgs
,
0
);
if
(
REQUEST_NO_RESP
(
&
pMsg
->
msg
))
{
taosArrayRemove
(
msgs
,
0
);
destroyCmsg
(
pMsg
);
res
=
true
;
}
if
(
res
==
true
)
{
if
(
cliMaySendCachedMsg
(
conn
)
==
false
)
{
SCliThrdObj
*
thrd
=
conn
->
hostThrd
;
addConnToPool
(
thrd
->
pool
,
conn
);
}
}
}
return
res
;
}
static
void
cliSendCb
(
uv_write_t
*
req
,
int
status
)
{
SCliConn
*
pConn
=
req
->
data
;
if
(
status
==
0
)
{
tTrace
(
"%s cli conn %p data already was written out"
,
CONN_GET_INST_LABEL
(
pConn
),
pConn
);
SCliMsg
*
pMsg
=
pConn
->
data
;
if
(
pMsg
==
NULL
)
{
return
;
}
destroyUserdata
(
&
pMsg
->
msg
);
}
else
{
tError
(
"%s cli conn %p failed to write: %s"
,
CONN_GET_INST_LABEL
(
pConn
),
pConn
,
uv_err_name
(
status
));
cliHandleExcept
(
pConn
);
return
;
}
if
(
cliHandleNoResp
(
pConn
)
==
true
)
{
tTrace
(
"%s cli conn %p no resp required"
,
CONN_GET_INST_LABEL
(
pConn
),
pConn
);
return
;
}
uv_read_start
((
uv_stream_t
*
)
pConn
->
stream
,
cliAllocRecvBufferCb
,
cliRecvCb
);
}
void
cliSend
(
SCliConn
*
pConn
)
{
CONN_HANDLE_BROKEN
(
pConn
);
SCliMsg
*
pCliMsg
=
pConn
->
data
;
assert
(
taosArrayGetSize
(
pConn
->
cliMsgs
)
>
0
);
SCliMsg
*
pCliMsg
=
taosArrayGetP
(
pConn
->
cliMsgs
,
0
);
STransConnCtx
*
pCtx
=
pCliMsg
->
ctx
;
SCliThrdObj
*
pThrd
=
pConn
->
hostThrd
;
...
...
@@ -472,14 +513,16 @@ void cliSend(SCliConn* pConn) {
msgLen
+=
sizeof
(
STransUserMsg
);
}
pHead
->
resflag
=
REQUEST_NO_RESP
(
pMsg
)
?
1
:
0
;
pHead
->
msgType
=
pMsg
->
msgType
;
pHead
->
msgLen
=
(
int32_t
)
htonl
((
uint32_t
)
msgLen
);
uv_buf_t
wb
=
uv_buf_init
((
char
*
)
pHead
,
msgLen
);
tDebug
(
"%s cli conn %p %s is send to %s:%d, local info %s:%d"
,
CONN_GET_INST_LABEL
(
pConn
),
pConn
,
TMSG_INFO
(
pHead
->
msgType
),
inet_n
toa
(
pConn
->
addr
.
sin_addr
),
ntohs
(
pConn
->
addr
.
sin_port
),
inet_n
toa
(
pConn
->
locaddr
.
sin_addr
),
ntohs
(
pConn
->
locaddr
.
sin_port
));
TMSG_INFO
(
pHead
->
msgType
),
taosInetN
toa
(
pConn
->
addr
.
sin_addr
),
ntohs
(
pConn
->
addr
.
sin_port
),
taosInetN
toa
(
pConn
->
locaddr
.
sin_addr
),
ntohs
(
pConn
->
locaddr
.
sin_port
));
pConn
->
writeReq
.
data
=
pConn
;
uv_write
(
&
pConn
->
writeReq
,
(
uv_stream_t
*
)
pConn
->
stream
,
&
wb
,
1
,
cliSendCb
);
return
;
...
...
@@ -502,8 +545,8 @@ void cliConnCb(uv_connect_t* req, int status) {
uv_tcp_getsockname
((
uv_tcp_t
*
)
pConn
->
stream
,
(
struct
sockaddr
*
)
&
pConn
->
locaddr
,
&
addrlen
);
tTrace
(
"%s cli conn %p connect to server successfully"
,
CONN_GET_INST_LABEL
(
pConn
),
pConn
);
assert
(
pConn
->
stream
==
req
->
handle
);
cliSend
(
pConn
);
}
...
...
@@ -521,8 +564,11 @@ static void cliHandleRelease(SCliMsg* pMsg, SCliThrdObj* pThrd) {
SCliConn
*
conn
=
pMsg
->
msg
.
handle
;
tDebug
(
"%s cli conn %p release to inst"
,
CONN_GET_INST_LABEL
(
conn
),
conn
);
while
(
taosArrayGetSize
(
conn
->
cliMsgs
)
>
0
)
{
SCliMsg
*
pMsg
=
taosArrayGetP
(
conn
->
cliMsgs
,
0
);
destroyCmsg
(
pMsg
);
conn
->
data
=
NULL
;
taosArrayRemove
(
conn
->
cliMsgs
,
0
);
}
transDestroyBuffer
(
&
conn
->
readBuf
);
if
(
conn
->
persist
&&
T_REF_VAL_GET
(
conn
)
>=
2
)
{
...
...
@@ -561,14 +607,19 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrdObj* pThrd) {
SCliConn
*
conn
=
cliGetConn
(
pMsg
,
pThrd
);
if
(
conn
!=
NULL
)
{
conn
->
data
=
pMsg
;
conn
->
hThrdIdx
=
pCtx
->
hThrdIdx
;
if
(
taosArrayGetSize
(
conn
->
cliMsgs
)
>
0
)
{
taosArrayPush
(
conn
->
cliMsgs
,
&
pMsg
);
return
;
}
taosArrayPush
(
conn
->
cliMsgs
,
&
pMsg
);
transDestroyBuffer
(
&
conn
->
readBuf
);
cliSend
(
conn
);
}
else
{
conn
=
cliCreateConn
(
pThrd
);
conn
->
data
=
pMsg
;
taosArrayPush
(
conn
->
cliMsgs
,
&
pMsg
);
conn
->
hThrdIdx
=
pCtx
->
hThrdIdx
;
conn
->
ip
=
strdup
(
pMsg
->
ctx
->
ip
);
conn
->
port
=
pMsg
->
ctx
->
port
;
...
...
source/libs/transport/src/transSrv.c
浏览文件 @
7eb4153a
...
...
@@ -202,7 +202,7 @@ static void uvHandleReq(SSrvConn* pConn) {
STransMsgHead
*
pHead
=
(
STransMsgHead
*
)
p
->
msg
;
if
(
pHead
->
secured
==
1
)
{
STransUserMsg
*
uMsg
=
(
p
->
msg
+
p
->
msgLen
-
sizeof
(
STransUserMsg
));
STransUserMsg
*
uMsg
=
(
STransUserMsg
*
)((
char
*
)
p
->
msg
+
p
->
msgLen
-
sizeof
(
STransUserMsg
));
memcpy
(
pConn
->
user
,
uMsg
->
user
,
tListLen
(
uMsg
->
user
));
memcpy
(
pConn
->
secret
,
uMsg
->
secret
,
tListLen
(
uMsg
->
secret
));
}
...
...
@@ -226,15 +226,22 @@ static void uvHandleReq(SSrvConn* pConn) {
transMsg
.
msgType
=
pHead
->
msgType
;
transMsg
.
code
=
pHead
->
code
;
transMsg
.
ahandle
=
NULL
;
transMsg
.
handle
=
pConn
;
transMsg
.
handle
=
NULL
;
transClearBuffer
(
&
pConn
->
readBuf
);
pConn
->
inType
=
pHead
->
msgType
;
transRefSrvHandle
(
pConn
);
if
(
pHead
->
resflag
==
0
)
{
transRefSrvHandle
(
pConn
);
transMsg
.
handle
=
pConn
;
tDebug
(
"server conn %p %s received from %s:%d, local info: %s:%d, msg size: %d"
,
pConn
,
TMSG_INFO
(
transMsg
.
msgType
),
inet_ntoa
(
pConn
->
addr
.
sin_addr
),
ntohs
(
pConn
->
addr
.
sin_port
),
inet_n
toa
(
pConn
->
locaddr
.
sin_addr
),
taosInetNtoa
(
pConn
->
addr
.
sin_addr
),
ntohs
(
pConn
->
addr
.
sin_port
),
taosInetN
toa
(
pConn
->
locaddr
.
sin_addr
),
ntohs
(
pConn
->
locaddr
.
sin_port
),
transMsg
.
contLen
);
}
else
{
tDebug
(
"server conn %p %s received from %s:%d, local info: %s:%d, msg size: %d, no resp "
,
pConn
,
TMSG_INFO
(
transMsg
.
msgType
),
taosInetNtoa
(
pConn
->
addr
.
sin_addr
),
ntohs
(
pConn
->
addr
.
sin_port
),
taosInetNtoa
(
pConn
->
locaddr
.
sin_addr
),
ntohs
(
pConn
->
locaddr
.
sin_port
),
transMsg
.
contLen
);
}
STrans
*
pTransInst
=
(
STrans
*
)
p
->
shandle
;
(
*
pTransInst
->
cfp
)(
pTransInst
->
parent
,
&
transMsg
,
NULL
);
...
...
@@ -340,7 +347,7 @@ static void uvPrepareSendData(SSrvMsg* smsg, uv_buf_t* wb) {
// impl later
}
tDebug
(
"server conn %p %s is sent to %s:%d, local info: %s:%d"
,
pConn
,
TMSG_INFO
(
pHead
->
msgType
),
inet_ntoa
(
pConn
->
addr
.
sin_addr
),
ntohs
(
pConn
->
addr
.
sin_port
),
inet_n
toa
(
pConn
->
locaddr
.
sin_addr
),
taosInetNtoa
(
pConn
->
addr
.
sin_addr
),
ntohs
(
pConn
->
addr
.
sin_port
),
taosInetN
toa
(
pConn
->
locaddr
.
sin_addr
),
ntohs
(
pConn
->
locaddr
.
sin_port
));
pHead
->
msgLen
=
htonl
(
len
);
...
...
@@ -367,8 +374,8 @@ static void uvStartSendResp(SSrvMsg* smsg) {
transUnrefSrvHandle
(
pConn
);
if
(
taosArrayGetSize
(
pConn
->
srvMsgs
)
>
0
)
{
tDebug
(
"server conn %p push data to client %s:%d, local info: %s:%d"
,
pConn
,
inet_n
toa
(
pConn
->
addr
.
sin_addr
),
ntohs
(
pConn
->
addr
.
sin_port
),
inet_n
toa
(
pConn
->
locaddr
.
sin_addr
),
ntohs
(
pConn
->
locaddr
.
sin_port
));
tDebug
(
"server conn %p push data to client %s:%d, local info: %s:%d"
,
pConn
,
taosInetN
toa
(
pConn
->
addr
.
sin_addr
),
ntohs
(
pConn
->
addr
.
sin_port
),
taosInetN
toa
(
pConn
->
locaddr
.
sin_addr
),
ntohs
(
pConn
->
locaddr
.
sin_port
));
taosArrayPush
(
pConn
->
srvMsgs
,
&
smsg
);
return
;
}
...
...
source/libs/transport/test/transUT.cc
浏览文件 @
7eb4153a
...
...
@@ -50,6 +50,7 @@ static void *ConstructArgForSpecificMsgType(void *parent, tmsg_t msgType) {
}
// server except
static
bool
handleExcept
(
void
*
parent
,
tmsg_t
msgType
)
{
//
return
msgType
==
TDMT_VND_QUERY
||
msgType
==
TDMT_VND_FETCH_RSP
||
msgType
==
TDMT_VND_RES_READY_RSP
;
}
typedef
void
(
*
CB
)(
void
*
parent
,
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
);
...
...
@@ -360,7 +361,7 @@ TEST_F(TransEnv, cliPersistHandle) {
tr
->
SetCliPersistFp
(
cliPersistHandle
);
SRpcMsg
resp
=
{
0
};
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
SRpcMsg
req
=
{.
handle
=
resp
.
handle
};
SRpcMsg
req
=
{.
handle
=
resp
.
handle
,
.
noResp
=
0
};
req
.
msgType
=
1
;
req
.
pCont
=
rpcMallocCont
(
10
);
req
.
contLen
=
10
;
...
...
@@ -447,6 +448,25 @@ TEST_F(TransEnv, srvPersistHandleExcept) {
// conn broken
//
}
TEST_F
(
TransEnv
,
cliPersistHandleExcept
)
{
tr
->
SetSrvContinueSend
(
processContinueSend
);
tr
->
SetCliPersistFp
(
cliPersistHandle
);
SRpcMsg
resp
=
{
0
};
for
(
int
i
=
0
;
i
<
5
;
i
++
)
{
SRpcMsg
req
=
{.
handle
=
resp
.
handle
};
req
.
msgType
=
1
;
req
.
pCont
=
rpcMallocCont
(
10
);
req
.
contLen
=
10
;
tr
->
cliSendAndRecv
(
&
req
,
&
resp
);
if
(
i
>
2
)
{
tr
->
StopSrv
();
break
;
}
}
taosMsleep
(
2000
);
// conn broken
//
}
TEST_F
(
TransEnv
,
multiCliPersistHandleExcept
)
{
// conn broken
...
...
@@ -457,5 +477,15 @@ TEST_F(TransEnv, queryExcept) {
// query and conn is broken
}
TEST_F
(
TransEnv
,
noResp
)
{
SRpcMsg
resp
=
{
0
};
for
(
int
i
=
0
;
i
<
5
;
i
++
)
{
SRpcMsg
req
=
{.
noResp
=
1
};
req
.
msgType
=
1
;
req
.
pCont
=
rpcMallocCont
(
10
);
req
.
contLen
=
10
;
tr
->
cliSendAndRecv
(
&
req
,
&
resp
);
}
taosMsleep
(
2000
);
// no resp
}
source/libs/wal/src/walMeta.c
浏览文件 @
7eb4153a
...
...
@@ -19,9 +19,6 @@
#include "tref.h"
#include "walInt.h"
#include <libgen.h>
#include <regex.h>
int64_t
inline
walGetFirstVer
(
SWal
*
pWal
)
{
return
pWal
->
vers
.
firstVer
;
}
int64_t
inline
walGetSnaphostVer
(
SWal
*
pWal
)
{
return
pWal
->
vers
.
snapshotVer
;
}
...
...
source/os/CMakeLists.txt
浏览文件 @
7eb4153a
...
...
@@ -3,9 +3,10 @@ add_library(os STATIC ${OS_SRC})
target_include_directories
(
os
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/os"
PRIVATE
"
${
CMAKE_SOURCE_DIR
}
/include"
PRIVATE
"
${
CMAKE_SOURCE_DIR
}
/include/util"
PRIVATE
"
${
CMAKE_SOURCE_DIR
}
/contrib/pthread-win32"
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include"
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/util"
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/contrib/pthread-win32"
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/contrib/gnuregex"
)
target_link_libraries
(
os pthread dl rt m
...
...
source/util/src/tcompare.c
浏览文件 @
7eb4153a
...
...
@@ -427,7 +427,7 @@ int32_t compareWStrPatternMatch(const void *pLeft, const void *pRight) {
wchar_t
*
pattern
=
calloc
(
varDataLen
(
pRight
)
+
1
,
sizeof
(
wchar_t
));
memcpy
(
pattern
,
varDataVal
(
pRight
),
varDataLen
(
pRight
));
int32_t
ret
=
WCSPatternMatch
(
pattern
,
varDataVal
(
pLeft
),
varDataLen
(
pLeft
)
/
TSDB_NCHAR_SIZE
,
&
pInfo
);
int32_t
ret
=
WCSPatternMatch
(
pattern
,
(
const
wchar_t
*
)
varDataVal
(
pLeft
),
varDataLen
(
pLeft
)
/
TSDB_NCHAR_SIZE
,
&
pInfo
);
free
(
pattern
);
return
(
ret
==
TSDB_PATTERN_MATCH
)
?
0
:
1
;
...
...
source/util/src/terror.c
浏览文件 @
7eb4153a
...
...
@@ -350,6 +350,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TDB_MESSED_MSG, "TSDB messed message")
TAOS_DEFINE_ERROR
(
TSDB_CODE_TDB_IVLD_TAG_VAL
,
"TSDB invalid tag value"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TDB_NO_CACHE_LAST_ROW
,
"TSDB no cache last row data"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TDB_NO_SMA_INDEX_IN_META
,
"No sma index in meta"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TDB_TDB_ENV_OPEN_ERROR
,
"TDB env open error"
)
// query
TAOS_DEFINE_ERROR
(
TSDB_CODE_QRY_INVALID_QHANDLE
,
"Invalid handle"
)
...
...
source/util/src/tuuid.c
浏览文件 @
7eb4153a
...
...
@@ -15,43 +15,43 @@
#include "tuuid.h"
static
int64_t
h
ashId
=
0
;
static
int32_t
SerialNo
=
0
;
static
int64_t
tUUIDH
ashId
=
0
;
static
int32_t
tUUID
SerialNo
=
0
;
int32_t
tGenIdPI32
(
void
)
{
if
(
h
ashId
==
0
)
{
if
(
tUUIDH
ashId
==
0
)
{
char
uid
[
64
];
int32_t
code
=
taosGetSystemUUID
(
uid
,
tListLen
(
uid
));
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
}
else
{
h
ashId
=
MurmurHash3_32
(
uid
,
strlen
(
uid
));
tUUIDH
ashId
=
MurmurHash3_32
(
uid
,
strlen
(
uid
));
}
}
int64_t
ts
=
taosGetTimestampMs
();
uint64_t
pid
=
taosGetPId
();
int32_t
val
=
atomic_add_fetch_32
(
&
SerialNo
,
1
);
int32_t
val
=
atomic_add_fetch_32
(
&
tUUID
SerialNo
,
1
);
int32_t
id
=
((
h
ashId
&
0x1F
)
<<
26
)
|
((
pid
&
0x3F
)
<<
20
)
|
((
ts
&
0xFFF
)
<<
8
)
|
(
val
&
0xFF
);
int32_t
id
=
((
tUUIDH
ashId
&
0x1F
)
<<
26
)
|
((
pid
&
0x3F
)
<<
20
)
|
((
ts
&
0xFFF
)
<<
8
)
|
(
val
&
0xFF
);
return
id
;
}
int64_t
tGenIdPI64
(
void
)
{
if
(
h
ashId
==
0
)
{
if
(
tUUIDH
ashId
==
0
)
{
char
uid
[
64
];
int32_t
code
=
taosGetSystemUUID
(
uid
,
tListLen
(
uid
));
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
}
else
{
h
ashId
=
MurmurHash3_32
(
uid
,
strlen
(
uid
));
tUUIDH
ashId
=
MurmurHash3_32
(
uid
,
strlen
(
uid
));
}
}
int64_t
ts
=
taosGetTimestampMs
();
uint64_t
pid
=
taosGetPId
();
int32_t
val
=
atomic_add_fetch_32
(
&
SerialNo
,
1
);
int32_t
val
=
atomic_add_fetch_32
(
&
tUUID
SerialNo
,
1
);
int64_t
id
=
((
h
ashId
&
0x07FF
)
<<
52
)
|
((
pid
&
0x0FFF
)
<<
40
)
|
((
ts
&
0xFFFFFF
)
<<
16
)
|
(
val
&
0xFFFF
);
int64_t
id
=
((
tUUIDH
ashId
&
0x07FF
)
<<
52
)
|
((
pid
&
0x0FFF
)
<<
40
)
|
((
ts
&
0xFFFFFF
)
<<
16
)
|
(
val
&
0xFFFF
);
return
id
;
}
source/util/test/encodeTest.cpp
浏览文件 @
7eb4153a
...
...
@@ -230,7 +230,7 @@ static int32_t tSStructA_v1_decode(SCoder *pCoder, SStructA_v1 *pSAV1) {
const
char
*
tstr
;
uint64_t
len
;
if
(
tDecodeCStrAndLen
(
pCoder
,
&
tstr
,
&
len
)
<
0
)
return
-
1
;
pSAV1
->
A_c
=
(
char
*
)
TCODER_MALLOC
(
len
+
1
,
pCoder
);
TCODER_MALLOC
(
pSAV1
->
A_c
,
char
*
,
len
+
1
,
pCoder
);
memcpy
(
pSAV1
->
A_c
,
tstr
,
len
+
1
);
tEndDecode
(
pCoder
);
...
...
@@ -269,7 +269,7 @@ static int32_t tSStructA_v2_decode(SCoder *pCoder, SStructA_v2 *pSAV2) {
const
char
*
tstr
;
uint64_t
len
;
if
(
tDecodeCStrAndLen
(
pCoder
,
&
tstr
,
&
len
)
<
0
)
return
-
1
;
pSAV2
->
A_c
=
(
char
*
)
TCODER_MALLOC
(
len
+
1
,
pCoder
);
TCODER_MALLOC
(
pSAV2
->
A_c
,
char
*
,
len
+
1
,
pCoder
);
memcpy
(
pSAV2
->
A_c
,
tstr
,
len
+
1
);
// ------------------------NEW FIELDS DECODE-------------------------------
...
...
@@ -305,7 +305,7 @@ static int32_t tSFinalReq_v1_encode(SCoder *pCoder, const SFinalReq_v1 *ps1) {
static
int32_t
tSFinalReq_v1_decode
(
SCoder
*
pCoder
,
SFinalReq_v1
*
ps1
)
{
if
(
tStartDecode
(
pCoder
)
<
0
)
return
-
1
;
ps1
->
pA
=
(
SStructA_v1
*
)
TCODER_MALLOC
(
sizeof
(
*
(
ps1
->
pA
)),
pCoder
);
TCODER_MALLOC
(
ps1
->
pA
,
SStructA_v1
*
,
sizeof
(
*
(
ps1
->
pA
)),
pCoder
);
if
(
tSStructA_v1_decode
(
pCoder
,
ps1
->
pA
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pCoder
,
&
ps1
->
v_a
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pCoder
,
&
ps1
->
v_b
)
<
0
)
return
-
1
;
...
...
@@ -339,7 +339,7 @@ static int32_t tSFinalReq_v2_encode(SCoder *pCoder, const SFinalReq_v2 *ps2) {
static
int32_t
tSFinalReq_v2_decode
(
SCoder
*
pCoder
,
SFinalReq_v2
*
ps2
)
{
if
(
tStartDecode
(
pCoder
)
<
0
)
return
-
1
;
ps2
->
pA
=
(
SStructA_v2
*
)
TCODER_MALLOC
(
sizeof
(
*
(
ps2
->
pA
)),
pCoder
);
TCODER_MALLOC
(
ps2
->
pA
,
SStructA_v2
*
,
sizeof
(
*
(
ps2
->
pA
)),
pCoder
);
if
(
tSStructA_v2_decode
(
pCoder
,
ps2
->
pA
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pCoder
,
&
ps2
->
v_a
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pCoder
,
&
ps2
->
v_b
)
<
0
)
return
-
1
;
...
...
source/util/test/freelistTest.cpp
浏览文件 @
7eb4153a
...
...
@@ -8,7 +8,8 @@ TEST(TD_UTIL_FREELIST_TEST, simple_test) {
tFreeListInit
(
&
fl
);
for
(
size_t
i
=
0
;
i
<
1000
;
i
++
)
{
void
*
ptr
=
TFL_MALLOC
(
1024
,
&
fl
);
void
*
ptr
=
NULL
;
TFL_MALLOC
(
ptr
,
void
*
,
1024
,
&
fl
);
GTEST_ASSERT_NE
(
ptr
,
nullptr
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录