Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
7bf10f1a
T
TDengine
项目概览
taosdata
/
TDengine
接近 2 年 前同步成功
通知
1191
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看板
提交
7bf10f1a
编写于
12月 17, 2021
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/3.0' into feature/dnode3
上级
f991a732
540516aa
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
168 addition
and
195 deletion
+168
-195
include/common/taosmsg.h
include/common/taosmsg.h
+2
-3
include/dnode/vnode/tq/tq.h
include/dnode/vnode/tq/tq.h
+7
-6
source/dnode/mgmt/impl/src/dndTransport.c
source/dnode/mgmt/impl/src/dndTransport.c
+1
-2
source/dnode/vnode/impl/inc/vnodeStateMgr.h
source/dnode/vnode/impl/inc/vnodeStateMgr.h
+4
-4
source/dnode/vnode/impl/src/vnodeWrite.c
source/dnode/vnode/impl/src/vnodeWrite.c
+19
-4
source/dnode/vnode/tq/inc/tqInt.h
source/dnode/vnode/tq/inc/tqInt.h
+10
-10
source/dnode/vnode/tq/inc/tqMetaStore.h
source/dnode/vnode/tq/inc/tqMetaStore.h
+12
-17
source/dnode/vnode/tq/src/tq.c
source/dnode/vnode/tq/src/tq.c
+6
-2
source/libs/catalog/inc/catalogInt.h
source/libs/catalog/inc/catalogInt.h
+4
-3
source/libs/catalog/src/catalog.c
source/libs/catalog/src/catalog.c
+41
-80
source/libs/wal/inc/walInt.h
source/libs/wal/inc/walInt.h
+26
-28
source/libs/wal/src/walMeta.c
source/libs/wal/src/walMeta.c
+7
-7
source/libs/wal/src/walMgmt.c
source/libs/wal/src/walMgmt.c
+1
-1
source/libs/wal/src/walRead.c
source/libs/wal/src/walRead.c
+6
-6
source/libs/wal/src/walSeek.c
source/libs/wal/src/walSeek.c
+6
-6
source/libs/wal/src/walWrite.c
source/libs/wal/src/walWrite.c
+16
-16
未找到文件。
include/common/taosmsg.h
浏览文件 @
7bf10f1a
...
...
@@ -50,10 +50,9 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_CONSUME, "mq-consume" )
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_MQ_QUERY
,
"mq-query"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_MQ_CONNECT
,
"mq-connect"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_MQ_DISCONNECT
,
"mq-disconnect"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_MQ_ACK
,
"mq-ack"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_MQ_RESET
,
"mq-reset"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_MQ_SET
,
"mq-set"
)
// message from client to mnode
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_CONNECT
,
"connect"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_CONNECT
,
"connect"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_CREATE_ACCT
,
"create-acct"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_ALTER_ACCT
,
"alter-acct"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_DROP_ACCT
,
"drop-acct"
)
...
...
include/dnode/vnode/tq/tq.h
浏览文件 @
7bf10f1a
...
...
@@ -62,10 +62,10 @@ typedef struct TmqDisconnectRsp {
int8_t
status
;
}
TmqDisconnectRsp
;
typedef
struct
Tm
qConsumeReq
{
typedef
struct
ST
qConsumeReq
{
TmqMsgHead
head
;
TmqAcks
acks
;
}
Tm
qConsumeReq
;
}
ST
qConsumeReq
;
typedef
struct
TmqMsgContent
{
int64_t
topicId
;
...
...
@@ -73,11 +73,11 @@ typedef struct TmqMsgContent {
char
msg
[];
}
TmqMsgContent
;
typedef
struct
Tm
qConsumeRsp
{
typedef
struct
ST
qConsumeRsp
{
TmqMsgHead
head
;
int64_t
bodySize
;
TmqMsgContent
msgs
[];
}
Tm
qConsumeRsp
;
}
ST
qConsumeRsp
;
typedef
struct
TmqSubscribeReq
{
TmqMsgHead
head
;
...
...
@@ -261,13 +261,14 @@ typedef struct STQ {
// open in each vnode
STQ
*
tqOpen
(
const
char
*
path
,
STqCfg
*
tqConfig
,
STqLogReader
*
tqLogReader
,
SMemAllocatorFactory
*
allocFac
);
void
tq
Destroy
(
STQ
*
);
void
tq
Close
(
STQ
*
);
// void* will be replace by a msg type
int
tqPushMsg
(
STQ
*
,
void
*
msg
,
int64_t
version
);
int
tqCommit
(
STQ
*
);
int
tqSetCursor
(
STQ
*
,
void
*
msg
);
int
tqConsume
(
STQ
*
,
Tm
qConsumeReq
*
);
int
tqConsume
(
STQ
*
,
ST
qConsumeReq
*
);
STqGroupHandle
*
tqGetGroupHandle
(
STQ
*
,
int64_t
cId
);
...
...
source/dnode/mgmt/impl/src/dndTransport.c
浏览文件 @
7bf10f1a
...
...
@@ -44,8 +44,7 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_MQ_CONSUME
]
=
dndProcessVnodeQueryMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_MQ_CONNECT
]
=
dndProcessVnodeWriteMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_MQ_DISCONNECT
]
=
dndProcessVnodeWriteMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_MQ_ACK
]
=
dndProcessVnodeWriteMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_MQ_RESET
]
=
dndProcessVnodeWriteMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_MQ_SET
]
=
dndProcessVnodeWriteMsg
;
// msg from client to mnode
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_CONNECT
]
=
dndProcessMnodeReadMsg
;
...
...
source/dnode/vnode/impl/inc/vnodeStateMgr.h
浏览文件 @
7bf10f1a
...
...
@@ -21,13 +21,13 @@ extern "C" {
#endif
typedef
struct
{
u
int64_t
processed
;
u
int64_t
committed
;
u
int64_t
applied
;
int64_t
processed
;
int64_t
committed
;
int64_t
applied
;
}
SVState
;
#ifdef __cplusplus
}
#endif
#endif
/*_TD_VNODE_STATE_MGR_H_*/
\ No newline at end of file
#endif
/*_TD_VNODE_STATE_MGR_H_*/
source/dnode/vnode/impl/src/vnodeWrite.c
浏览文件 @
7bf10f1a
...
...
@@ -15,16 +15,31 @@
#include "vnodeDef.h"
int
vnodeProcessNoWalWMsgs
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
)
{
SVnodeReq
*
pVnodeReq
;
switch
(
pMsg
->
msgType
)
{
case
TSDB_MSG_TYPE_MQ_SET
:
if
(
tqSetCursor
(
pVnode
->
pTq
,
pMsg
->
pCont
)
<
0
)
{
// TODO: handle error
}
break
;
}
void
*
pBuf
=
pMsg
->
pCont
;
return
0
;
}
int
vnodeProcessWMsgs
(
SVnode
*
pVnode
,
SArray
*
pMsgs
)
{
SRpcMsg
*
pMsg
;
SRpcMsg
*
pMsg
;
SVnodeReq
*
pVnodeReq
;
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
pMsgs
);
i
++
)
{
pMsg
=
*
(
SRpcMsg
**
)
taosArrayGet
(
pMsgs
,
i
);
// ser request version
void
*
pBuf
=
pMsg
->
pCont
;
u
int64_t
ver
=
pVnode
->
state
.
processed
++
;
void
*
pBuf
=
pMsg
->
pCont
;
int64_t
ver
=
pVnode
->
state
.
processed
++
;
taosEncodeFixedU64
(
&
pBuf
,
ver
);
if
(
walWrite
(
pVnode
->
pWal
,
ver
,
pMsg
->
msgType
,
pMsg
->
pCont
,
pMsg
->
contLen
)
<
0
)
{
...
...
@@ -99,4 +114,4 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
return
0
;
}
/* ------------------------ STATIC METHODS ------------------------ */
\ No newline at end of file
/* ------------------------ STATIC METHODS ------------------------ */
source/dnode/vnode/tq/inc/tqInt.h
浏览文件 @
7bf10f1a
...
...
@@ -22,16 +22,16 @@
extern
"C"
{
#endif
//create persistent storage for meta info such as consuming offset
//return value > 0: cgId
//return value <= 0: error code
//int tqCreateTCGroup(STQ*, const char* topic, int cgId, tqBufferHandle** handle);
//create ring buffer in memory and load consuming offset
//int tqOpenTCGroup(STQ*, const char* topic, int cgId);
//destroy ring buffer and persist consuming offset
//int tqCloseTCGroup(STQ*, const char* topic, int cgId);
//delete persistent storage for meta info
//int tqDropTCGroup(STQ*, const char* topic, int cgId);
//
create persistent storage for meta info such as consuming offset
//
return value > 0: cgId
//
return value <= 0: error code
//
int tqCreateTCGroup(STQ*, const char* topic, int cgId, tqBufferHandle** handle);
//
create ring buffer in memory and load consuming offset
//
int tqOpenTCGroup(STQ*, const char* topic, int cgId);
//
destroy ring buffer and persist consuming offset
//
int tqCloseTCGroup(STQ*, const char* topic, int cgId);
//
delete persistent storage for meta info
//
int tqDropTCGroup(STQ*, const char* topic, int cgId);
#ifdef __cplusplus
}
...
...
source/dnode/vnode/tq/inc/tqMetaStore.h
浏览文件 @
7bf10f1a
...
...
@@ -23,27 +23,22 @@
extern
"C"
{
#endif
STqMetaStore
*
tqStoreOpen
(
const
char
*
path
,
FTqSerialize
pSerializer
,
FTqDeserialize
pDeserializer
,
FTqDelete
pDeleter
,
int32_t
tqConfigFlag
);
STqMetaStore
*
tqStoreOpen
(
const
char
*
path
,
FTqSerialize
pSerializer
,
FTqDeserialize
pDeserializer
,
FTqDelete
pDeleter
,
int32_t
tqConfigFlag
);
int32_t
tqStoreClose
(
STqMetaStore
*
);
//int32_t tqStoreDelete(TqMetaStore*);
//int32_t tqStoreCommitAll(TqMetaStore*);
int32_t
tqStorePersist
(
STqMetaStore
*
);
//clean deleted idx and data from persistent file
int32_t
tqStoreCompact
(
STqMetaStore
*
);
void
*
tqHandleGet
(
STqMetaStore
*
,
int64_t
key
);
//make it unpersist
//
int32_t tqStoreDelete(TqMetaStore*);
//
int32_t tqStoreCommitAll(TqMetaStore*);
int32_t
tqStorePersist
(
STqMetaStore
*
);
//
clean deleted idx and data from persistent file
int32_t
tqStoreCompact
(
STqMetaStore
*
);
void
*
tqHandleGet
(
STqMetaStore
*
,
int64_t
key
);
//
make it unpersist
void
*
tqHandleTouchGet
(
STqMetaStore
*
,
int64_t
key
);
int32_t
tqHandleMovePut
(
STqMetaStore
*
,
int64_t
key
,
void
*
value
);
int32_t
tqHandleCopyPut
(
STqMetaStore
*
,
int64_t
key
,
void
*
value
,
size_t
vsize
);
//delete committed kv pair
//notice that a delete action still needs to be committed
//
delete committed kv pair
//
notice that a delete action still needs to be committed
int32_t
tqHandleDel
(
STqMetaStore
*
,
int64_t
key
);
int32_t
tqHandleCommit
(
STqMetaStore
*
,
int64_t
key
);
int32_t
tqHandleAbort
(
STqMetaStore
*
,
int64_t
key
);
...
...
source/dnode/vnode/tq/src/tq.c
浏览文件 @
7bf10f1a
...
...
@@ -214,7 +214,11 @@ int tqCommit(STQ* pTq) {
return
0
;
}
int
tqConsume
(
STQ
*
pTq
,
TmqConsumeReq
*
pMsg
)
{
int
tqSetCursor
(
STQ
*
pTq
,
void
*
msg
)
{
return
0
;
}
int
tqConsume
(
STQ
*
pTq
,
STqConsumeReq
*
pMsg
)
{
if
(
!
tqProtoCheck
((
TmqMsgHead
*
)
pMsg
))
{
// proto version invalid
return
-
1
;
...
...
@@ -232,7 +236,7 @@ int tqConsume(STQ* pTq, TmqConsumeReq* pMsg) {
}
}
TmqConsumeRsp
*
pRsp
=
(
Tm
qConsumeRsp
*
)
pMsg
;
STqConsumeRsp
*
pRsp
=
(
ST
qConsumeRsp
*
)
pMsg
;
if
(
tqFetch
(
gHandle
,
(
void
**
)
&
pRsp
->
msgs
)
<=
0
)
{
// fetch error
...
...
source/libs/catalog/inc/catalogInt.h
浏览文件 @
7bf10f1a
...
...
@@ -70,9 +70,10 @@ extern int32_t ctgDebugFlag;
#define ctgDebugL(...) do { if (ctgDebugFlag & DEBUG_DEBUG) { taosPrintLongString("CTG ", ctgDebugFlag, __VA_ARGS__); }} while(0)
#define CTG_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { return _code; } } while (0)
#define CTG_ERR_LRET(c,...) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { ctgError(__VA_ARGS__); return _code; } } while (0)
#define CTG_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { goto _return; } } while (0)
#define CTG_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0)
#define CTG_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0)
#define CTG_ERR_LRET(c,...) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { ctgError(__VA_ARGS__); terrno = _code; return _code; } } while (0)
#define CTG_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0)
#ifdef __cplusplus
...
...
source/libs/catalog/src/catalog.c
浏览文件 @
7bf10f1a
...
...
@@ -49,16 +49,13 @@ int32_t ctgGetDBVgroupFromMnode(struct SCatalog* pCatalog, void *pRpc, const SEp
SEpSet
*
pVnodeEpSet
=
NULL
;
int32_t
msgLen
=
0
;
int32_t
code
=
queryBuildMsg
[
TSDB_MSG_TYPE_USE_DB
](
input
,
&
msg
,
0
,
&
msgLen
);
if
(
code
)
{
return
code
;
}
CTG_ERR_RET
(
queryBuildMsg
[
TSDB_MSG_TYPE_USE_DB
](
input
,
&
msg
,
0
,
&
msgLen
));
char
*
pMsg
=
rpcMallocCont
(
msgLen
);
if
(
NULL
==
pMsg
)
{
ctgError
(
"rpc malloc %d failed"
,
msgLen
);
tfree
(
msg
);
return
TSDB_CODE_CTG_MEM_ERROR
;
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
)
;
}
memcpy
(
pMsg
,
msg
,
msgLen
);
...
...
@@ -76,13 +73,10 @@ int32_t ctgGetDBVgroupFromMnode(struct SCatalog* pCatalog, void *pRpc, const SEp
rpcSendRecv
(
pRpc
,
(
SEpSet
*
)
pMgmtEps
,
&
rpcMsg
,
&
rpcRsp
);
if
(
TSDB_CODE_SUCCESS
!=
rpcRsp
.
code
)
{
ctgError
(
"error rsp for use db, code:%x"
,
rpcRsp
.
code
);
return
rpcRsp
.
code
;
CTG_ERR_RET
(
rpcRsp
.
code
)
;
}
code
=
queryProcessMsgRsp
[
TSDB_MSG_TYPE_USE_DB
](
out
,
rpcRsp
.
pCont
,
rpcRsp
.
contLen
);
if
(
code
)
{
return
code
;
}
CTG_ERR_RET
(
queryProcessMsgRsp
[
TSDB_MSG_TYPE_USE_DB
](
out
,
rpcRsp
.
pCont
,
rpcRsp
.
contLen
));
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -114,14 +108,14 @@ int32_t ctgGetTableMetaFromCache(struct SCatalog* pCatalog, const char *dbName,
if
((
*
stbMeta
)
->
suid
!=
tbMeta
->
suid
)
{
ctgError
(
"stable cache error, expected suid:%"
PRId64
",actual suid:%"
PRId64
,
tbMeta
->
suid
,
(
*
stbMeta
)
->
suid
);
return
TSDB_CODE_CTG_INTERNAL_ERROR
;
CTG_ERR_RET
(
TSDB_CODE_CTG_INTERNAL_ERROR
)
;
}
int32_t
metaSize
=
sizeof
(
STableMeta
)
+
((
*
stbMeta
)
->
tableInfo
.
numOfTags
+
(
*
stbMeta
)
->
tableInfo
.
numOfColumns
)
*
sizeof
(
SSchema
);
*
pTableMeta
=
calloc
(
1
,
metaSize
);
if
(
NULL
==
*
pTableMeta
)
{
ctgError
(
"calloc size[%d] failed"
,
metaSize
);
return
TSDB_CODE_CTG_MEM_ERROR
;
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
)
;
}
memcpy
(
*
pTableMeta
,
tbMeta
,
sizeof
(
SCTableMeta
));
...
...
@@ -131,7 +125,7 @@ int32_t ctgGetTableMetaFromCache(struct SCatalog* pCatalog, const char *dbName,
*
pTableMeta
=
calloc
(
1
,
metaSize
);
if
(
NULL
==
*
pTableMeta
)
{
ctgError
(
"calloc size[%d] failed"
,
metaSize
);
return
TSDB_CODE_CTG_MEM_ERROR
;
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
)
;
}
memcpy
(
*
pTableMeta
,
tbMeta
,
metaSize
);
...
...
@@ -155,7 +149,7 @@ void ctgGenEpSet(SEpSet *epSet, SVgroupInfo *vgroupInfo) {
int32_t
ctgGetTableMetaFromMnode
(
struct
SCatalog
*
pCatalog
,
void
*
pRpc
,
const
SEpSet
*
pMgmtEps
,
const
char
*
pDBName
,
const
char
*
pTableName
,
SVgroupInfo
*
vgroupInfo
,
STableMetaOutput
*
output
)
{
if
(
NULL
==
pCatalog
||
NULL
==
pRpc
||
NULL
==
pMgmtEps
||
NULL
==
pDBName
||
NULL
==
pTableName
||
NULL
==
vgroupInfo
||
NULL
==
output
)
{
return
TSDB_CODE_CTG_INVALID_INPUT
;
CTG_ERR_RET
(
TSDB_CODE_CTG_INVALID_INPUT
)
;
}
char
tbFullName
[
TSDB_TABLE_FNAME_LEN
];
...
...
@@ -167,10 +161,7 @@ int32_t ctgGetTableMetaFromMnode(struct SCatalog* pCatalog, void *pRpc, const SE
SEpSet
*
pVnodeEpSet
=
NULL
;
int32_t
msgLen
=
0
;
int32_t
code
=
queryBuildMsg
[
TSDB_MSG_TYPE_TABLE_META
](
&
bInput
,
&
msg
,
0
,
&
msgLen
);
if
(
code
)
{
return
code
;
}
CTG_ERR_RET
(
queryBuildMsg
[
TSDB_MSG_TYPE_TABLE_META
](
&
bInput
,
&
msg
,
0
,
&
msgLen
));
SRpcMsg
rpcMsg
=
{
.
msgType
=
TSDB_MSG_TYPE_TABLE_META
,
...
...
@@ -187,13 +178,10 @@ int32_t ctgGetTableMetaFromMnode(struct SCatalog* pCatalog, void *pRpc, const SE
if
(
TSDB_CODE_SUCCESS
!=
rpcRsp
.
code
)
{
ctgError
(
"error rsp for table meta, code:%x"
,
rpcRsp
.
code
);
return
rpcRsp
.
code
;
CTG_ERR_RET
(
rpcRsp
.
code
)
;
}
code
=
queryProcessMsgRsp
[
TSDB_MSG_TYPE_TABLE_META
](
output
,
rpcRsp
.
pCont
,
rpcRsp
.
contLen
);
if
(
code
)
{
return
code
;
}
CTG_ERR_RET
(
queryProcessMsgRsp
[
TSDB_MSG_TYPE_TABLE_META
](
output
,
rpcRsp
.
pCont
,
rpcRsp
.
contLen
));
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -219,7 +207,7 @@ int32_t ctgGetVgInfoFromDB(struct SCatalog *pCatalog, void *pRpc, const SEpSet *
if
(
NULL
==
taosArrayPush
(
vgroupList
,
vgInfo
))
{
ctgError
(
"taosArrayPush failed"
);
break
;
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
)
;
}
pIter
=
taosHashIterate
(
dbInfo
->
vgInfo
,
pIter
);
...
...
@@ -233,7 +221,7 @@ int32_t ctgGetVgInfoFromHashValue(SDBVgroupInfo *dbInfo, const char *pDBName, co
int32_t
vgNum
=
taosHashGetSize
(
dbInfo
->
vgInfo
);
if
(
vgNum
<=
0
)
{
ctgError
(
"db[%s] vgroup cache invalid, vgroup number:%d"
,
pDBName
,
vgNum
);
return
TSDB_CODE_TSC_DB_NOT_SELECTED
;
CTG_ERR_RET
(
TSDB_CODE_TSC_DB_NOT_SELECTED
)
;
}
tableNameHashFp
fp
=
NULL
;
...
...
@@ -260,7 +248,7 @@ int32_t ctgGetVgInfoFromHashValue(SDBVgroupInfo *dbInfo, const char *pDBName, co
if
(
NULL
==
vgInfo
)
{
ctgError
(
"no hash range found for hashvalue[%u]"
,
hashValue
);
return
TSDB_CODE_CTG_INTERNAL_ERROR
;
CTG_ERR_RET
(
TSDB_CODE_CTG_INTERNAL_ERROR
)
;
}
*
pVgroup
=
*
vgInfo
;
...
...
@@ -268,35 +256,9 @@ int32_t ctgGetVgInfoFromHashValue(SDBVgroupInfo *dbInfo, const char *pDBName, co
return
TSDB_CODE_SUCCESS
;
}
STableMeta
*
ctgCreateSTableMeta
(
STableMetaMsg
*
pChild
)
{
assert
(
pChild
!=
NULL
);
int32_t
total
=
pChild
->
numOfColumns
+
pChild
->
numOfTags
;
STableMeta
*
pTableMeta
=
calloc
(
1
,
sizeof
(
STableMeta
)
+
sizeof
(
SSchema
)
*
total
);
pTableMeta
->
tableType
=
TSDB_SUPER_TABLE
;
pTableMeta
->
tableInfo
.
numOfTags
=
pChild
->
numOfTags
;
pTableMeta
->
tableInfo
.
numOfColumns
=
pChild
->
numOfColumns
;
pTableMeta
->
tableInfo
.
precision
=
pChild
->
precision
;
pTableMeta
->
uid
=
pChild
->
suid
;
pTableMeta
->
tversion
=
pChild
->
tversion
;
pTableMeta
->
sversion
=
pChild
->
sversion
;
memcpy
(
pTableMeta
->
schema
,
pChild
->
pSchema
,
sizeof
(
SSchema
)
*
total
);
int32_t
num
=
pTableMeta
->
tableInfo
.
numOfColumns
;
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
pTableMeta
->
tableInfo
.
rowSize
+=
pTableMeta
->
schema
[
i
].
bytes
;
}
return
pTableMeta
;
}
int32_t
ctgGetTableMetaImpl
(
struct
SCatalog
*
pCatalog
,
void
*
pRpc
,
const
SEpSet
*
pMgmtEps
,
const
char
*
pDBName
,
const
char
*
pTableName
,
bool
forceUpdate
,
STableMeta
**
pTableMeta
)
{
if
(
NULL
==
pCatalog
||
NULL
==
pDBName
||
NULL
==
pRpc
||
NULL
==
pMgmtEps
||
NULL
==
pTableName
||
NULL
==
pTableMeta
)
{
return
TSDB_CODE_CTG_INVALID_INPUT
;
CTG_ERR_RET
(
TSDB_CODE_CTG_INVALID_INPUT
)
;
}
int32_t
exist
=
0
;
...
...
@@ -315,7 +277,7 @@ int32_t ctgGetTableMetaImpl(struct SCatalog* pCatalog, void *pRpc, const SEpSet*
if
(
0
==
exist
)
{
ctgError
(
"get table meta from cache failed, but fetch succeed"
);
return
TSDB_CODE_CTG_INTERNAL_ERROR
;
CTG_ERR_RET
(
TSDB_CODE_CTG_INTERNAL_ERROR
)
;
}
return
TSDB_CODE_SUCCESS
;
...
...
@@ -325,19 +287,19 @@ int32_t ctgGetTableMetaImpl(struct SCatalog* pCatalog, void *pRpc, const SEpSet*
int32_t
ctgUpdateTableMetaCache
(
struct
SCatalog
*
pCatalog
,
STableMetaOutput
*
output
)
{
if
(
output
->
metaNum
!=
1
&&
output
->
metaNum
!=
2
)
{
ctgError
(
"invalid table meta number[%d] got from meta rsp"
,
output
->
metaNum
);
return
TSDB_CODE_CTG_INTERNAL_ERROR
;
CTG_ERR_RET
(
TSDB_CODE_CTG_INTERNAL_ERROR
)
;
}
if
(
NULL
==
output
->
tbMeta
)
{
ctgError
(
"no valid table meta got from meta rsp"
);
return
TSDB_CODE_CTG_INTERNAL_ERROR
;
CTG_ERR_RET
(
TSDB_CODE_CTG_INTERNAL_ERROR
)
;
}
if
(
NULL
==
pCatalog
->
tableCache
.
cache
)
{
pCatalog
->
tableCache
.
cache
=
taosHashInit
(
ctgMgmt
.
cfg
.
maxTblCacheNum
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_ENTRY_LOCK
);
if
(
NULL
==
pCatalog
->
tableCache
.
cache
)
{
ctgError
(
"init hash[%d] for tablemeta cache failed"
,
ctgMgmt
.
cfg
.
maxTblCacheNum
);
return
TSDB_CODE_CTG_MEM_ERROR
;
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
)
;
}
}
...
...
@@ -345,13 +307,13 @@ int32_t ctgUpdateTableMetaCache(struct SCatalog *pCatalog, STableMetaOutput *out
pCatalog
->
tableCache
.
cache
=
taosHashInit
(
ctgMgmt
.
cfg
.
maxTblCacheNum
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_ENTRY_LOCK
);
if
(
NULL
==
pCatalog
->
tableCache
.
cache
)
{
ctgError
(
"init hash[%d] for tablemeta cache failed"
,
ctgMgmt
.
cfg
.
maxTblCacheNum
);
return
TSDB_CODE_CTG_MEM_ERROR
;
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
)
;
}
pCatalog
->
tableCache
.
stableCache
=
taosHashInit
(
ctgMgmt
.
cfg
.
maxTblCacheNum
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_UBIGINT
),
true
,
HASH_ENTRY_LOCK
);
if
(
NULL
==
pCatalog
->
tableCache
.
stableCache
)
{
ctgError
(
"init hash[%d] for stablemeta cache failed"
,
ctgMgmt
.
cfg
.
maxTblCacheNum
);
return
TSDB_CODE_CTG_MEM_ERROR
;
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
)
;
}
}
...
...
@@ -389,7 +351,7 @@ error_exit:
pCatalog
->
vgroupCache
.
vgroupVersion
=
CTG_DEFAULT_INVALID_VERSION
;
return
TSDB_CODE_CTG_INTERNAL_ERROR
;
CTG_ERR_RET
(
TSDB_CODE_CTG_INTERNAL_ERROR
)
;
}
int32_t
catalogInit
(
SCatalogCfg
*
cfg
)
{
...
...
@@ -411,12 +373,12 @@ int32_t catalogInit(SCatalogCfg *cfg) {
int32_t
catalogGetHandle
(
const
char
*
clusterId
,
struct
SCatalog
**
catalogHandle
)
{
if
(
NULL
==
clusterId
||
NULL
==
catalogHandle
)
{
return
TSDB_CODE_CTG_INVALID_INPUT
;
CTG_ERR_RET
(
TSDB_CODE_CTG_INVALID_INPUT
)
;
}
if
(
NULL
==
ctgMgmt
.
pCluster
)
{
ctgError
(
"cluster cache are not ready"
);
return
TSDB_CODE_CTG_NOT_READY
;
CTG_ERR_RET
(
TSDB_CODE_CTG_NOT_READY
)
;
}
size_t
clen
=
strlen
(
clusterId
);
...
...
@@ -430,7 +392,7 @@ int32_t catalogGetHandle(const char *clusterId, struct SCatalog** catalogHandle)
clusterCtg
=
calloc
(
1
,
sizeof
(
*
clusterCtg
));
if
(
NULL
==
clusterCtg
)
{
ctgError
(
"calloc %d failed"
,
(
int32_t
)
sizeof
(
*
clusterCtg
));
return
TSDB_CODE_CTG_MEM_ERROR
;
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
)
;
}
clusterCtg
->
vgroupCache
.
vgroupVersion
=
CTG_DEFAULT_INVALID_VERSION
;
...
...
@@ -438,7 +400,7 @@ int32_t catalogGetHandle(const char *clusterId, struct SCatalog** catalogHandle)
if
(
taosHashPut
(
ctgMgmt
.
pCluster
,
clusterId
,
clen
,
&
clusterCtg
,
POINTER_BYTES
))
{
ctgError
(
"put cluster %s cache to hash failed"
,
clusterId
);
tfree
(
clusterCtg
);
return
TSDB_CODE_CTG_INTERNAL_ERROR
;
CTG_ERR_RET
(
TSDB_CODE_CTG_INTERNAL_ERROR
)
;
}
*
catalogHandle
=
clusterCtg
;
...
...
@@ -448,7 +410,7 @@ int32_t catalogGetHandle(const char *clusterId, struct SCatalog** catalogHandle)
int32_t
catalogGetDBVgroupVersion
(
struct
SCatalog
*
pCatalog
,
const
char
*
dbName
,
int32_t
*
version
)
{
if
(
NULL
==
pCatalog
||
NULL
==
dbName
||
NULL
==
version
)
{
return
TSDB_CODE_CTG_INVALID_INPUT
;
CTG_ERR_RET
(
TSDB_CODE_CTG_INVALID_INPUT
)
;
}
if
(
NULL
==
pCatalog
->
dbCache
.
cache
)
{
...
...
@@ -469,7 +431,7 @@ int32_t catalogGetDBVgroupVersion(struct SCatalog* pCatalog, const char* dbName,
int32_t
catalogUpdateDBVgroupCache
(
struct
SCatalog
*
pCatalog
,
const
char
*
dbName
,
SDBVgroupInfo
*
dbInfo
)
{
if
(
NULL
==
pCatalog
||
NULL
==
dbName
||
NULL
==
dbInfo
)
{
return
TSDB_CODE_CTG_INVALID_INPUT
;
CTG_ERR_RET
(
TSDB_CODE_CTG_INVALID_INPUT
)
;
}
if
(
dbInfo
->
vgVersion
<
0
)
{
...
...
@@ -485,7 +447,7 @@ int32_t catalogUpdateDBVgroupCache(struct SCatalog* pCatalog, const char* dbName
pCatalog
->
dbCache
.
cache
=
taosHashInit
(
CTG_DEFAULT_CACHE_DB_NUMBER
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_ENTRY_LOCK
);
if
(
NULL
==
pCatalog
->
dbCache
.
cache
)
{
ctgError
(
"init hash[%d] for db cache failed"
,
CTG_DEFAULT_CACHE_DB_NUMBER
);
return
TSDB_CODE_CTG_MEM_ERROR
;
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
)
;
}
}
else
{
SDBVgroupInfo
*
oldInfo
=
taosHashGet
(
pCatalog
->
dbCache
.
cache
,
dbName
,
strlen
(
dbName
));
...
...
@@ -497,7 +459,7 @@ int32_t catalogUpdateDBVgroupCache(struct SCatalog* pCatalog, const char* dbName
if
(
taosHashPut
(
pCatalog
->
dbCache
.
cache
,
dbName
,
strlen
(
dbName
),
dbInfo
,
sizeof
(
*
dbInfo
))
!=
0
)
{
ctgError
(
"push to vgroup hash cache failed"
);
return
TSDB_CODE_CTG_MEM_ERROR
;
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
)
;
}
return
TSDB_CODE_SUCCESS
;
...
...
@@ -508,11 +470,10 @@ int32_t catalogUpdateDBVgroupCache(struct SCatalog* pCatalog, const char* dbName
int32_t
catalogGetDBVgroup
(
struct
SCatalog
*
pCatalog
,
void
*
pRpc
,
const
SEpSet
*
pMgmtEps
,
const
char
*
dbName
,
int32_t
forceUpdate
,
SDBVgroupInfo
*
dbInfo
)
{
if
(
NULL
==
pCatalog
||
NULL
==
dbName
||
NULL
==
pRpc
||
NULL
==
pMgmtEps
)
{
return
TSDB_CODE_CTG_INVALID_INPUT
;
CTG_ERR_RET
(
TSDB_CODE_CTG_INVALID_INPUT
)
;
}
int32_t
exist
=
0
;
int32_t
code
=
0
;
if
(
0
==
forceUpdate
)
{
CTG_ERR_RET
(
ctgGetDBVgroupFromCache
(
pCatalog
,
dbName
,
dbInfo
,
&
exist
));
...
...
@@ -537,7 +498,7 @@ int32_t catalogGetDBVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet*
*
dbInfo
=
DbOut
.
dbVgroup
;
}
return
code
;
return
TSDB_CODE_SUCCESS
;
}
int32_t
catalogGetTableMeta
(
struct
SCatalog
*
pCatalog
,
void
*
pRpc
,
const
SEpSet
*
pMgmtEps
,
const
char
*
pDBName
,
const
char
*
pTableName
,
STableMeta
**
pTableMeta
)
{
...
...
@@ -546,7 +507,7 @@ int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet*
int32_t
catalogRenewTableMeta
(
struct
SCatalog
*
pCatalog
,
void
*
pRpc
,
const
SEpSet
*
pMgmtEps
,
const
char
*
pDBName
,
const
char
*
pTableName
)
{
if
(
NULL
==
pCatalog
||
NULL
==
pDBName
||
NULL
==
pRpc
||
NULL
==
pMgmtEps
||
NULL
==
pTableName
)
{
return
TSDB_CODE_CTG_INVALID_INPUT
;
CTG_ERR_RET
(
TSDB_CODE_CTG_INVALID_INPUT
)
;
}
SVgroupInfo
vgroupInfo
=
{
0
};
...
...
@@ -570,7 +531,7 @@ int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const
int32_t
catalogGetTableDistVgroup
(
struct
SCatalog
*
pCatalog
,
void
*
pRpc
,
const
SEpSet
*
pMgmtEps
,
const
char
*
pDBName
,
const
char
*
pTableName
,
SArray
*
pVgroupList
)
{
if
(
NULL
==
pCatalog
||
NULL
==
pRpc
||
NULL
==
pMgmtEps
||
NULL
==
pDBName
||
NULL
==
pTableName
||
NULL
==
pVgroupList
)
{
return
TSDB_CODE_CTG_INVALID_INPUT
;
CTG_ERR_RET
(
TSDB_CODE_CTG_INVALID_INPUT
)
;
}
STableMeta
*
tbMeta
=
NULL
;
...
...
@@ -588,7 +549,7 @@ int32_t catalogGetTableDistVgroup(struct SCatalog* pCatalog, void *pRpc, const S
int32_t
vgId
=
tbMeta
->
vgId
;
if
(
NULL
==
taosHashGetClone
(
dbVgroup
.
vgInfo
,
&
vgId
,
sizeof
(
vgId
),
&
vgroupInfo
))
{
ctgError
(
"vgId[%d] not found in vgroup list"
,
vgId
);
return
TSDB_CODE_CTG_INTERNAL_ERROR
;
CTG_ERR_RET
(
TSDB_CODE_CTG_INTERNAL_ERROR
)
;
}
if
(
NULL
==
taosArrayPush
(
pVgroupList
,
&
vgroupInfo
))
{
...
...
@@ -600,7 +561,7 @@ int32_t catalogGetTableDistVgroup(struct SCatalog* pCatalog, void *pRpc, const S
_return:
tfree
(
tbMeta
);
return
code
;
CTG_RET
(
code
)
;
}
...
...
@@ -613,18 +574,18 @@ int32_t catalogGetTableHashVgroup(struct SCatalog *pCatalog, void *pRpc, const S
if
(
dbInfo
.
vgVersion
<
0
||
NULL
==
dbInfo
.
vgInfo
)
{
ctgError
(
"db[%s] vgroup cache invalid, vgroup version:%d, vgInfo:%p"
,
pDBName
,
dbInfo
.
vgVersion
,
dbInfo
.
vgInfo
);
return
TSDB_CODE_TSC_DB_NOT_SELECTED
;
CTG_ERR_RET
(
TSDB_CODE_TSC_DB_NOT_SELECTED
)
;
}
CTG_ERR_RET
(
ctgGetVgInfoFromHashValue
(
&
dbInfo
,
pDBName
,
pTableName
,
pVgroup
));
return
code
;
CTG_RET
(
code
)
;
}
int32_t
catalogGetAllMeta
(
struct
SCatalog
*
pCatalog
,
void
*
pRpc
,
const
SEpSet
*
pMgmtEps
,
const
SCatalogReq
*
pReq
,
SMetaData
*
pRsp
)
{
if
(
NULL
==
pCatalog
||
NULL
==
pRpc
||
NULL
==
pMgmtEps
||
NULL
==
pReq
||
NULL
==
pRsp
)
{
return
TSDB_CODE_CTG_INVALID_INPUT
;
CTG_ERR_RET
(
TSDB_CODE_CTG_INVALID_INPUT
)
;
}
int32_t
code
=
0
;
...
...
@@ -636,7 +597,7 @@ int32_t catalogGetAllMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* p
pRsp
->
pTableMeta
=
taosArrayInit
(
tbNum
,
POINTER_BYTES
);
if
(
NULL
==
pRsp
->
pTableMeta
)
{
ctgError
(
"taosArrayInit num[%d] failed"
,
tbNum
);
return
TSDB_CODE_CTG_MEM_ERROR
;
CTG_ERR_RET
(
TSDB_CODE_CTG_MEM_ERROR
)
;
}
}
...
...
@@ -670,7 +631,7 @@ _return:
taosArrayDestroy
(
pRsp
->
pTableMeta
);
}
return
code
;
CTG_RET
(
code
)
;
}
void
catalogDestroy
(
void
)
{
...
...
source/libs/wal/inc/walInt.h
浏览文件 @
7bf10f1a
...
...
@@ -16,72 +16,70 @@
#ifndef _TD_WAL_INT_H_
#define _TD_WAL_INT_H_
#include "wal.h"
#include "compare.h"
#include "tchecksum.h"
#include "wal.h"
#ifdef __cplusplus
extern
"C"
{
#endif
//meta section begin
//
meta section begin
typedef
struct
WalFileInfo
{
int64_t
firstVer
;
int64_t
lastVer
;
int64_t
createTs
;
int64_t
closeTs
;
int64_t
fileSize
;
}
WalFileInfo
;
}
S
WalFileInfo
;
typedef
struct
WalIdxEntry
{
int64_t
ver
;
int64_t
offset
;
}
WalIdxEntry
;
}
S
WalIdxEntry
;
static
inline
int32_t
compareWalFileInfo
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
WalFileInfo
*
pInfoLeft
=
(
WalFileInfo
*
)
pLeft
;
WalFileInfo
*
pInfoRight
=
(
WalFileInfo
*
)
pRight
;
SWalFileInfo
*
pInfoLeft
=
(
S
WalFileInfo
*
)
pLeft
;
SWalFileInfo
*
pInfoRight
=
(
S
WalFileInfo
*
)
pRight
;
return
compareInt64Val
(
&
pInfoLeft
->
firstVer
,
&
pInfoRight
->
firstVer
);
}
static
inline
int64_t
walGetLastFileSize
(
SWal
*
pWal
)
{
WalFileInfo
*
pInfo
=
(
WalFileInfo
*
)
taosArrayGetLast
(
pWal
->
fileInfoSet
);
SWalFileInfo
*
pInfo
=
(
S
WalFileInfo
*
)
taosArrayGetLast
(
pWal
->
fileInfoSet
);
return
pInfo
->
fileSize
;
}
static
inline
int64_t
walGetLastFileFirstVer
(
SWal
*
pWal
)
{
WalFileInfo
*
pInfo
=
(
WalFileInfo
*
)
taosArrayGetLast
(
pWal
->
fileInfoSet
);
SWalFileInfo
*
pInfo
=
(
S
WalFileInfo
*
)
taosArrayGetLast
(
pWal
->
fileInfoSet
);
return
pInfo
->
firstVer
;
}
static
inline
int64_t
walGetCurFileFirstVer
(
SWal
*
pWal
)
{
WalFileInfo
*
pInfo
=
(
WalFileInfo
*
)
taosArrayGet
(
pWal
->
fileInfoSet
,
pWal
->
writeCur
);
SWalFileInfo
*
pInfo
=
(
S
WalFileInfo
*
)
taosArrayGet
(
pWal
->
fileInfoSet
,
pWal
->
writeCur
);
return
pInfo
->
firstVer
;
}
static
inline
int64_t
walGetCurFileLastVer
(
SWal
*
pWal
)
{
WalFileInfo
*
pInfo
=
(
WalFileInfo
*
)
taosArrayGet
(
pWal
->
fileInfoSet
,
pWal
->
writeCur
);
SWalFileInfo
*
pInfo
=
(
S
WalFileInfo
*
)
taosArrayGet
(
pWal
->
fileInfoSet
,
pWal
->
writeCur
);
return
pInfo
->
firstVer
;
}
static
inline
int64_t
walGetCurFileOffset
(
SWal
*
pWal
)
{
WalFileInfo
*
pInfo
=
(
WalFileInfo
*
)
taosArrayGet
(
pWal
->
fileInfoSet
,
pWal
->
writeCur
);
SWalFileInfo
*
pInfo
=
(
S
WalFileInfo
*
)
taosArrayGet
(
pWal
->
fileInfoSet
,
pWal
->
writeCur
);
return
pInfo
->
fileSize
;
}
static
inline
bool
walCurFileClosed
(
SWal
*
pWal
)
{
return
taosArrayGetSize
(
pWal
->
fileInfoSet
)
!=
pWal
->
writeCur
;
}
static
inline
bool
walCurFileClosed
(
SWal
*
pWal
)
{
return
taosArrayGetSize
(
pWal
->
fileInfoSet
)
!=
pWal
->
writeCur
;
}
static
inline
WalFileInfo
*
walGetCurFileInfo
(
SWal
*
pWal
)
{
return
(
WalFileInfo
*
)
taosArrayGet
(
pWal
->
fileInfoSet
,
pWal
->
writeCur
);
static
inline
S
WalFileInfo
*
walGetCurFileInfo
(
SWal
*
pWal
)
{
return
(
S
WalFileInfo
*
)
taosArrayGet
(
pWal
->
fileInfoSet
,
pWal
->
writeCur
);
}
static
inline
int
walBuildLogName
(
SWal
*
pWal
,
int64_t
fileFirstVer
,
char
*
buf
)
{
static
inline
int
walBuildLogName
(
SWal
*
pWal
,
int64_t
fileFirstVer
,
char
*
buf
)
{
return
sprintf
(
buf
,
"%s/%020"
PRId64
"."
WAL_LOG_SUFFIX
,
pWal
->
path
,
fileFirstVer
);
}
static
inline
int
walBuildIdxName
(
SWal
*
pWal
,
int64_t
fileFirstVer
,
char
*
buf
)
{
static
inline
int
walBuildIdxName
(
SWal
*
pWal
,
int64_t
fileFirstVer
,
char
*
buf
)
{
return
sprintf
(
buf
,
"%s/%020"
PRId64
"."
WAL_INDEX_SUFFIX
,
pWal
->
path
,
fileFirstVer
);
}
...
...
@@ -93,11 +91,11 @@ static inline int walValidBodyCksum(SWalHead* pHead) {
return
taosCheckChecksum
((
uint8_t
*
)
pHead
->
head
.
body
,
pHead
->
head
.
len
,
pHead
->
cksumBody
);
}
static
inline
int
walValidCksum
(
SWalHead
*
pHead
,
void
*
body
,
int64_t
bodyLen
)
{
static
inline
int
walValidCksum
(
SWalHead
*
pHead
,
void
*
body
,
int64_t
bodyLen
)
{
return
walValidHeadCksum
(
pHead
)
&&
walValidBodyCksum
(
pHead
);
}
static
inline
uint32_t
walCalcHeadCksum
(
SWalHead
*
pHead
)
{
static
inline
uint32_t
walCalcHeadCksum
(
SWalHead
*
pHead
)
{
return
taosCalcChecksum
(
0
,
(
uint8_t
*
)
&
pHead
->
head
,
sizeof
(
SWalReadHead
));
}
...
...
@@ -106,7 +104,7 @@ static inline uint32_t walCalcBodyCksum(const void* body, uint32_t len) {
}
static
inline
int64_t
walGetVerIdxOffset
(
SWal
*
pWal
,
int64_t
ver
)
{
return
(
ver
-
walGetCurFileFirstVer
(
pWal
))
*
sizeof
(
WalIdxEntry
);
return
(
ver
-
walGetCurFileFirstVer
(
pWal
))
*
sizeof
(
S
WalIdxEntry
);
}
static
inline
void
walResetVer
(
SWalVer
*
pVer
)
{
...
...
@@ -126,16 +124,16 @@ int walCheckAndRepairMeta(SWal* pWal);
int
walCheckAndRepairIdx
(
SWal
*
pWal
);
char
*
walMetaSerialize
(
SWal
*
pWal
);
int
walMetaDeserialize
(
SWal
*
pWal
,
const
char
*
bytes
);
//meta section end
int
walMetaDeserialize
(
SWal
*
pWal
,
const
char
*
bytes
);
//
meta section end
//seek section
int
walChangeFile
(
SWal
*
pWal
,
int64_t
ver
);
//seek section end
//
seek section
int
walChangeFile
(
SWal
*
pWal
,
int64_t
ver
);
//
seek section end
int64_t
walGetSeq
();
int
walSeekVer
(
SWal
*
pWal
,
int64_t
ver
);
int
walRoll
(
SWal
*
pWal
);
int
walSeekVer
(
SWal
*
pWal
,
int64_t
ver
);
int
walRoll
(
SWal
*
pWal
);
#ifdef __cplusplus
}
...
...
source/libs/wal/src/walMeta.c
浏览文件 @
7bf10f1a
...
...
@@ -79,13 +79,13 @@ int walRollFileInfo(SWal* pWal) {
SArray
*
pArray
=
pWal
->
fileInfoSet
;
if
(
taosArrayGetSize
(
pArray
)
!=
0
)
{
WalFileInfo
*
pInfo
=
taosArrayGetLast
(
pArray
);
S
WalFileInfo
*
pInfo
=
taosArrayGetLast
(
pArray
);
pInfo
->
lastVer
=
pWal
->
vers
.
lastVer
;
pInfo
->
closeTs
=
ts
;
}
// TODO: change to emplace back
WalFileInfo
*
pNewInfo
=
malloc
(
sizeof
(
WalFileInfo
));
SWalFileInfo
*
pNewInfo
=
malloc
(
sizeof
(
S
WalFileInfo
));
if
(
pNewInfo
==
NULL
)
{
return
-
1
;
}
...
...
@@ -122,9 +122,9 @@ char* walMetaSerialize(SWal* pWal) {
cJSON_AddStringToObject
(
pMeta
,
"lastVer"
,
buf
);
cJSON_AddItemToObject
(
pRoot
,
"files"
,
pFiles
);
WalFileInfo
*
pData
=
pWal
->
fileInfoSet
->
pData
;
S
WalFileInfo
*
pData
=
pWal
->
fileInfoSet
->
pData
;
for
(
int
i
=
0
;
i
<
sz
;
i
++
)
{
WalFileInfo
*
pInfo
=
&
pData
[
i
];
S
WalFileInfo
*
pInfo
=
&
pData
[
i
];
cJSON_AddItemToArray
(
pFiles
,
pField
=
cJSON_CreateObject
());
if
(
pField
==
NULL
)
{
cJSON_Delete
(
pRoot
);
...
...
@@ -167,10 +167,10 @@ int walMetaDeserialize(SWal* pWal, const char* bytes) {
// deserialize
SArray
*
pArray
=
pWal
->
fileInfoSet
;
taosArrayEnsureCap
(
pArray
,
sz
);
WalFileInfo
*
pData
=
pArray
->
pData
;
S
WalFileInfo
*
pData
=
pArray
->
pData
;
for
(
int
i
=
0
;
i
<
sz
;
i
++
)
{
cJSON
*
pInfoJson
=
cJSON_GetArrayItem
(
pFiles
,
i
);
WalFileInfo
*
pInfo
=
&
pData
[
i
];
cJSON
*
pInfoJson
=
cJSON_GetArrayItem
(
pFiles
,
i
);
S
WalFileInfo
*
pInfo
=
&
pData
[
i
];
pField
=
cJSON_GetObjectItem
(
pInfoJson
,
"firstVer"
);
pInfo
->
firstVer
=
atoll
(
cJSON_GetStringValue
(
pField
));
pField
=
cJSON_GetObjectItem
(
pInfoJson
,
"lastVer"
);
...
...
source/libs/wal/src/walMgmt.c
浏览文件 @
7bf10f1a
...
...
@@ -92,7 +92,7 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) {
pWal
->
writeLogTfd
=
-
1
;
pWal
->
writeIdxTfd
=
-
1
;
pWal
->
writeCur
=
-
1
;
pWal
->
fileInfoSet
=
taosArrayInit
(
8
,
sizeof
(
WalFileInfo
));
pWal
->
fileInfoSet
=
taosArrayInit
(
8
,
sizeof
(
S
WalFileInfo
));
if
(
pWal
->
fileInfoSet
==
NULL
)
{
wError
(
"vgId:%d, path:%s, failed to init taosArray %s"
,
pWal
->
cfg
.
vgId
,
pWal
->
path
,
strerror
(
errno
));
free
(
pWal
);
...
...
source/libs/wal/src/walRead.c
浏览文件 @
7bf10f1a
...
...
@@ -52,13 +52,13 @@ static int32_t walReadSeekFilePos(SWalReadHandle *pRead, int64_t fileFirstVer, i
int64_t
logTfd
=
pRead
->
readLogTfd
;
// seek position
int64_t
offset
=
(
ver
-
fileFirstVer
)
*
sizeof
(
WalIdxEntry
);
int64_t
offset
=
(
ver
-
fileFirstVer
)
*
sizeof
(
S
WalIdxEntry
);
code
=
tfLseek
(
idxTfd
,
offset
,
SEEK_SET
);
if
(
code
<
0
)
{
return
-
1
;
}
WalIdxEntry
entry
;
if
(
tfRead
(
idxTfd
,
&
entry
,
sizeof
(
WalIdxEntry
))
!=
sizeof
(
WalIdxEntry
))
{
S
WalIdxEntry
entry
;
if
(
tfRead
(
idxTfd
,
&
entry
,
sizeof
(
SWalIdxEntry
))
!=
sizeof
(
S
WalIdxEntry
))
{
return
-
1
;
}
// TODO:deserialize
...
...
@@ -105,10 +105,10 @@ static int32_t walReadSeekVer(SWalReadHandle *pRead, int64_t ver) {
if
(
ver
<
pWal
->
vers
.
snapshotVer
)
{
}
WalFileInfo
tmpInfo
;
S
WalFileInfo
tmpInfo
;
tmpInfo
.
firstVer
=
ver
;
// bsearch in fileSet
WalFileInfo
*
pRet
=
taosArraySearch
(
pWal
->
fileInfoSet
,
&
tmpInfo
,
compareWalFileInfo
,
TD_LE
);
S
WalFileInfo
*
pRet
=
taosArraySearch
(
pWal
->
fileInfoSet
,
&
tmpInfo
,
compareWalFileInfo
,
TD_LE
);
ASSERT
(
pRet
!=
NULL
);
if
(
pRead
->
curFileFirstVer
!=
pRet
->
firstVer
)
{
code
=
walReadChangeFile
(
pRead
,
pRet
->
firstVer
);
...
...
@@ -159,9 +159,9 @@ int32_t walReadWithHandle(SWalReadHandle *pRead, int64_t ver) {
return
-
1
;
}
/*code = walValidBodyCksum(pRead->pHead);*/
ASSERT
(
pRead
->
pHead
->
head
.
version
==
ver
);
code
=
walValidBodyCksum
(
pRead
->
pHead
);
if
(
code
!=
0
)
{
return
-
1
;
}
...
...
source/libs/wal/src/walSeek.c
浏览文件 @
7bf10f1a
...
...
@@ -32,9 +32,9 @@ static int walSeekFilePos(SWal* pWal, int64_t ver) {
if
(
code
!=
0
)
{
return
-
1
;
}
WalIdxEntry
entry
;
S
WalIdxEntry
entry
;
// TODO:deserialize
code
=
tfRead
(
idxTfd
,
&
entry
,
sizeof
(
WalIdxEntry
));
code
=
tfRead
(
idxTfd
,
&
entry
,
sizeof
(
S
WalIdxEntry
));
if
(
code
!=
0
)
{
return
-
1
;
}
...
...
@@ -47,8 +47,8 @@ static int walSeekFilePos(SWal* pWal, int64_t ver) {
}
int
walChangeFileToLast
(
SWal
*
pWal
)
{
int64_t
idxTfd
,
logTfd
;
WalFileInfo
*
pRet
=
taosArrayGetLast
(
pWal
->
fileInfoSet
);
int64_t
idxTfd
,
logTfd
;
S
WalFileInfo
*
pRet
=
taosArrayGetLast
(
pWal
->
fileInfoSet
);
ASSERT
(
pRet
!=
NULL
);
int64_t
fileFirstVer
=
pRet
->
firstVer
;
...
...
@@ -83,10 +83,10 @@ int walChangeFile(SWal* pWal, int64_t ver) {
// TODO
return
-
1
;
}
WalFileInfo
tmpInfo
;
S
WalFileInfo
tmpInfo
;
tmpInfo
.
firstVer
=
ver
;
// bsearch in fileSet
WalFileInfo
*
pRet
=
taosArraySearch
(
pWal
->
fileInfoSet
,
&
tmpInfo
,
compareWalFileInfo
,
TD_LE
);
S
WalFileInfo
*
pRet
=
taosArraySearch
(
pWal
->
fileInfoSet
,
&
tmpInfo
,
compareWalFileInfo
,
TD_LE
);
ASSERT
(
pRet
!=
NULL
);
int64_t
fileFirstVer
=
pRet
->
firstVer
;
// closed
...
...
source/libs/wal/src/walWrite.c
浏览文件 @
7bf10f1a
...
...
@@ -56,9 +56,9 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
// delete files
int
fileSetSize
=
taosArrayGetSize
(
pWal
->
fileInfoSet
);
for
(
int
i
=
pWal
->
writeCur
;
i
<
fileSetSize
;
i
++
)
{
walBuildLogName
(
pWal
,
((
WalFileInfo
*
)
taosArrayGet
(
pWal
->
fileInfoSet
,
i
))
->
firstVer
,
fnameStr
);
walBuildLogName
(
pWal
,
((
S
WalFileInfo
*
)
taosArrayGet
(
pWal
->
fileInfoSet
,
i
))
->
firstVer
,
fnameStr
);
remove
(
fnameStr
);
walBuildIdxName
(
pWal
,
((
WalFileInfo
*
)
taosArrayGet
(
pWal
->
fileInfoSet
,
i
))
->
firstVer
,
fnameStr
);
walBuildIdxName
(
pWal
,
((
S
WalFileInfo
*
)
taosArrayGet
(
pWal
->
fileInfoSet
,
i
))
->
firstVer
,
fnameStr
);
remove
(
fnameStr
);
}
// pop from fileInfoSet
...
...
@@ -81,8 +81,8 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
}
// read idx file and get log file pos
// TODO:change to deserialize function
WalIdxEntry
entry
;
if
(
tfRead
(
idxTfd
,
&
entry
,
sizeof
(
WalIdxEntry
))
!=
sizeof
(
WalIdxEntry
))
{
S
WalIdxEntry
entry
;
if
(
tfRead
(
idxTfd
,
&
entry
,
sizeof
(
SWalIdxEntry
))
!=
sizeof
(
S
WalIdxEntry
))
{
pthread_mutex_unlock
(
&
pWal
->
mutex
);
return
-
1
;
}
...
...
@@ -128,8 +128,8 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
return
-
1
;
}
pWal
->
vers
.
lastVer
=
ver
-
1
;
((
WalFileInfo
*
)
taosArrayGetLast
(
pWal
->
fileInfoSet
))
->
lastVer
=
ver
-
1
;
((
WalFileInfo
*
)
taosArrayGetLast
(
pWal
->
fileInfoSet
))
->
fileSize
=
entry
.
offset
;
((
S
WalFileInfo
*
)
taosArrayGetLast
(
pWal
->
fileInfoSet
))
->
lastVer
=
ver
-
1
;
((
S
WalFileInfo
*
)
taosArrayGetLast
(
pWal
->
fileInfoSet
))
->
fileSize
=
entry
.
offset
;
// unlock
pthread_mutex_unlock
(
&
pWal
->
mutex
);
...
...
@@ -153,17 +153,17 @@ int32_t walEndSnapshot(SWal *pWal) {
pWal
->
vers
.
snapshotVer
=
ver
;
int
ts
=
taosGetTimestampSec
();
int
deleteCnt
=
0
;
int64_t
newTotSize
=
pWal
->
totSize
;
WalFileInfo
tmp
;
int
deleteCnt
=
0
;
int64_t
newTotSize
=
pWal
->
totSize
;
S
WalFileInfo
tmp
;
tmp
.
firstVer
=
ver
;
// find files safe to delete
WalFileInfo
*
pInfo
=
taosArraySearch
(
pWal
->
fileInfoSet
,
&
tmp
,
compareWalFileInfo
,
TD_LE
);
S
WalFileInfo
*
pInfo
=
taosArraySearch
(
pWal
->
fileInfoSet
,
&
tmp
,
compareWalFileInfo
,
TD_LE
);
if
(
ver
>=
pInfo
->
lastVer
)
{
pInfo
++
;
}
// iterate files, until the searched result
for
(
WalFileInfo
*
iter
=
pWal
->
fileInfoSet
->
pData
;
iter
<
pInfo
;
iter
++
)
{
for
(
S
WalFileInfo
*
iter
=
pWal
->
fileInfoSet
->
pData
;
iter
<
pInfo
;
iter
++
)
{
if
(
pWal
->
totSize
>
pWal
->
cfg
.
retentionSize
||
iter
->
closeTs
+
pWal
->
cfg
.
retentionPeriod
>
ts
)
{
// delete according to file size or close time
deleteCnt
++
;
...
...
@@ -173,7 +173,7 @@ int32_t walEndSnapshot(SWal *pWal) {
char
fnameStr
[
WAL_FILE_LEN
];
// remove file
for
(
int
i
=
0
;
i
<
deleteCnt
;
i
++
)
{
WalFileInfo
*
pInfo
=
taosArrayGet
(
pWal
->
fileInfoSet
,
i
);
S
WalFileInfo
*
pInfo
=
taosArrayGet
(
pWal
->
fileInfoSet
,
i
);
walBuildLogName
(
pWal
,
pInfo
->
firstVer
,
fnameStr
);
remove
(
fnameStr
);
walBuildIdxName
(
pWal
,
pInfo
->
firstVer
,
fnameStr
);
...
...
@@ -186,7 +186,7 @@ int32_t walEndSnapshot(SWal *pWal) {
pWal
->
writeCur
=
-
1
;
pWal
->
vers
.
firstVer
=
-
1
;
}
else
{
pWal
->
vers
.
firstVer
=
((
WalFileInfo
*
)
taosArrayGet
(
pWal
->
fileInfoSet
,
0
))
->
firstVer
;
pWal
->
vers
.
firstVer
=
((
S
WalFileInfo
*
)
taosArrayGet
(
pWal
->
fileInfoSet
,
0
))
->
firstVer
;
}
pWal
->
writeCur
=
taosArrayGetSize
(
pWal
->
fileInfoSet
)
-
1
;
;
...
...
@@ -248,9 +248,9 @@ int walRoll(SWal *pWal) {
}
static
int
walWriteIndex
(
SWal
*
pWal
,
int64_t
ver
,
int64_t
offset
)
{
WalIdxEntry
entry
=
{.
ver
=
ver
,
.
offset
=
offset
};
int
size
=
tfWrite
(
pWal
->
writeIdxTfd
,
&
entry
,
sizeof
(
WalIdxEntry
));
if
(
size
!=
sizeof
(
WalIdxEntry
))
{
S
WalIdxEntry
entry
=
{.
ver
=
ver
,
.
offset
=
offset
};
int
size
=
tfWrite
(
pWal
->
writeIdxTfd
,
&
entry
,
sizeof
(
S
WalIdxEntry
));
if
(
size
!=
sizeof
(
S
WalIdxEntry
))
{
// TODO truncate
return
-
1
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录