Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f904401d
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
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看板
未验证
提交
f904401d
编写于
1月 04, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
1月 04, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9574 from taosdata/feature/dnode3
mnode integration with wal module
上级
679553f7
c94f30e3
变更
25
隐藏空白更改
内联
并排
Showing
25 changed file
with
413 addition
and
88 deletion
+413
-88
include/dnode/mnode/sdb/sdb.h
include/dnode/mnode/sdb/sdb.h
+37
-21
include/util/taoserror.h
include/util/taoserror.h
+1
-0
source/dnode/mgmt/impl/test/CMakeLists.txt
source/dnode/mgmt/impl/test/CMakeLists.txt
+0
-2
source/dnode/mnode/impl/CMakeLists.txt
source/dnode/mnode/impl/CMakeLists.txt
+6
-1
source/dnode/mnode/impl/inc/mndInt.h
source/dnode/mnode/impl/inc/mndInt.h
+3
-0
source/dnode/mnode/impl/src/mndDnode.c
source/dnode/mnode/impl/src/mndDnode.c
+1
-1
source/dnode/mnode/impl/src/mndShow.c
source/dnode/mnode/impl/src/mndShow.c
+1
-1
source/dnode/mnode/impl/src/mndSync.c
source/dnode/mnode/impl/src/mndSync.c
+114
-0
source/dnode/mnode/impl/src/mndTrans.c
source/dnode/mnode/impl/src/mndTrans.c
+9
-5
source/dnode/mnode/impl/src/mnode.c
source/dnode/mnode/impl/src/mnode.c
+14
-14
source/dnode/mnode/impl/test/CMakeLists.txt
source/dnode/mnode/impl/test/CMakeLists.txt
+4
-0
source/dnode/mnode/impl/test/acct/CMakeLists.txt
source/dnode/mnode/impl/test/acct/CMakeLists.txt
+11
-0
source/dnode/mnode/impl/test/acct/acct.cpp
source/dnode/mnode/impl/test/acct/acct.cpp
+2
-2
source/dnode/mnode/impl/test/mnodeTests.cpp
source/dnode/mnode/impl/test/mnodeTests.cpp
+0
-0
source/dnode/mnode/impl/test/user/CMakeLists.txt
source/dnode/mnode/impl/test/user/CMakeLists.txt
+11
-0
source/dnode/mnode/impl/test/user/user.cpp
source/dnode/mnode/impl/test/user/user.cpp
+2
-2
source/dnode/mnode/sdb/inc/sdbInt.h
source/dnode/mnode/sdb/inc/sdbInt.h
+4
-4
source/dnode/mnode/sdb/src/sdb.c
source/dnode/mnode/sdb/src/sdb.c
+15
-5
source/dnode/mnode/sdb/src/sdbFile.c
source/dnode/mnode/sdb/src/sdbFile.c
+122
-7
source/dnode/mnode/sdb/src/sdbHash.c
source/dnode/mnode/sdb/src/sdbHash.c
+48
-21
source/libs/wal/inc/walInt.h
source/libs/wal/inc/walInt.h
+2
-0
source/libs/wal/src/walRead.c
source/libs/wal/src/walRead.c
+2
-0
source/libs/wal/src/walWrite.c
source/libs/wal/src/walWrite.c
+1
-1
source/util/src/terror.c
source/util/src/terror.c
+1
-0
tests/script/general/table/basic1.sim
tests/script/general/table/basic1.sim
+2
-1
未找到文件。
include/dnode/mnode/sdb/sdb.h
浏览文件 @
f904401d
...
@@ -102,25 +102,24 @@ typedef enum {
...
@@ -102,25 +102,24 @@ typedef enum {
}
ESdbStatus
;
}
ESdbStatus
;
typedef
enum
{
typedef
enum
{
SDB_START
=
0
,
SDB_TRANS
=
0
,
SDB_TRANS
=
1
,
SDB_CLUSTER
=
1
,
SDB_CLUSTER
=
2
,
SDB_MNODE
=
2
,
SDB_MNODE
=
3
,
SDB_QNODE
=
3
,
SDB_QNODE
=
4
,
SDB_SNODE
=
4
,
SDB_SNODE
=
5
,
SDB_BNODE
=
5
,
SDB_BNODE
=
6
,
SDB_DNODE
=
6
,
SDB_DNODE
=
7
,
SDB_USER
=
7
,
SDB_USER
=
8
,
SDB_AUTH
=
8
,
SDB_AUTH
=
9
,
SDB_ACCT
=
9
,
SDB_ACCT
=
10
,
SDB_CONSUMER
=
10
,
SDB_CONSUMER
=
11
,
SDB_CGROUP
=
11
,
SDB_CGROUP
=
12
,
SDB_TOPIC
=
12
,
SDB_TOPIC
=
13
,
SDB_VGROUP
=
13
,
SDB_VGROUP
=
14
,
SDB_STB
=
14
,
SDB_STB
=
15
,
SDB_DB
=
15
,
SDB_DB
=
16
,
SDB_FUNC
=
16
,
SDB_FUNC
=
17
,
SDB_MAX
=
17
SDB_MAX
=
18
}
ESdbType
;
}
ESdbType
;
typedef
struct
SSdb
SSdb
;
typedef
struct
SSdb
SSdb
;
...
@@ -188,6 +187,14 @@ int32_t sdbDeploy(SSdb *pSdb);
...
@@ -188,6 +187,14 @@ int32_t sdbDeploy(SSdb *pSdb);
*/
*/
int32_t
sdbReadFile
(
SSdb
*
pSdb
);
int32_t
sdbReadFile
(
SSdb
*
pSdb
);
/**
* @brief Write sdb file.
*
* @param pSdb The sdb object.
* @return int32_t 0 for success, -1 for failure.
*/
int32_t
sdbWriteFile
(
SSdb
*
pSdb
);
/**
/**
* @brief Parse and write raw data to sdb, then free the pRaw object
* @brief Parse and write raw data to sdb, then free the pRaw object
*
*
...
@@ -260,7 +267,7 @@ void sdbTraverse(SSdb *pSdb, ESdbType type, sdbTraverseFp fp, void *p1, void *p2
...
@@ -260,7 +267,7 @@ void sdbTraverse(SSdb *pSdb, ESdbType type, sdbTraverseFp fp, void *p1, void *p2
*
*
* @param pSdb The sdb object.
* @param pSdb The sdb object.
* @param pIter The type of the table.
* @param pIter The type of the table.
* @re
cord
int32_t The number of rows in the table
* @re
turn
int32_t The number of rows in the table
*/
*/
int32_t
sdbGetSize
(
SSdb
*
pSdb
,
ESdbType
type
);
int32_t
sdbGetSize
(
SSdb
*
pSdb
,
ESdbType
type
);
...
@@ -269,10 +276,19 @@ int32_t sdbGetSize(SSdb *pSdb, ESdbType type);
...
@@ -269,10 +276,19 @@ int32_t sdbGetSize(SSdb *pSdb, ESdbType type);
*
*
* @param pSdb The sdb object.
* @param pSdb The sdb object.
* @param pIter The type of the table.
* @param pIter The type of the table.
* @re
cord
int32_t The max id of the table
* @re
turn
int32_t The max id of the table
*/
*/
int32_t
sdbGetMaxId
(
SSdb
*
pSdb
,
ESdbType
type
);
int32_t
sdbGetMaxId
(
SSdb
*
pSdb
,
ESdbType
type
);
/**
* @brief Update the version of sdb
*
* @param pSdb The sdb object.
* @param val The update value of the version.
* @return int32_t The current version of sdb
*/
int64_t
sdbUpdateVer
(
SSdb
*
pSdb
,
int32_t
val
);
SSdbRaw
*
sdbAllocRaw
(
ESdbType
type
,
int8_t
sver
,
int32_t
dataLen
);
SSdbRaw
*
sdbAllocRaw
(
ESdbType
type
,
int8_t
sver
,
int32_t
dataLen
);
void
sdbFreeRaw
(
SSdbRaw
*
pRaw
);
void
sdbFreeRaw
(
SSdbRaw
*
pRaw
);
int32_t
sdbSetRawInt8
(
SSdbRaw
*
pRaw
,
int32_t
dataPos
,
int8_t
val
);
int32_t
sdbSetRawInt8
(
SSdbRaw
*
pRaw
,
int32_t
dataPos
,
int8_t
val
);
...
...
include/util/taoserror.h
浏览文件 @
f904401d
...
@@ -160,6 +160,7 @@ int32_t* taosGetErrno();
...
@@ -160,6 +160,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_SDB_INVALID_DATA_VER TAOS_DEF_ERROR_CODE(0, 0x0339)
#define TSDB_CODE_SDB_INVALID_DATA_VER TAOS_DEF_ERROR_CODE(0, 0x0339)
#define TSDB_CODE_SDB_INVALID_DATA_LEN TAOS_DEF_ERROR_CODE(0, 0x033A)
#define TSDB_CODE_SDB_INVALID_DATA_LEN TAOS_DEF_ERROR_CODE(0, 0x033A)
#define TSDB_CODE_SDB_INVALID_DATA_CONTENT TAOS_DEF_ERROR_CODE(0, 0x033B)
#define TSDB_CODE_SDB_INVALID_DATA_CONTENT TAOS_DEF_ERROR_CODE(0, 0x033B)
#define TSDB_CODE_SDB_INVALID_WAl_VER TAOS_DEF_ERROR_CODE(0, 0x033C)
// mnode-dnode
// mnode-dnode
#define TSDB_CODE_MND_DNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0340)
#define TSDB_CODE_MND_DNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0340)
...
...
source/dnode/mgmt/impl/test/CMakeLists.txt
浏览文件 @
f904401d
enable_testing
()
enable_testing
()
add_subdirectory
(
acct
)
# add_subdirectory(auth)
# add_subdirectory(auth)
# add_subdirectory(balance)
# add_subdirectory(balance)
add_subdirectory
(
cluster
)
add_subdirectory
(
cluster
)
...
@@ -17,7 +16,6 @@ add_subdirectory(stb)
...
@@ -17,7 +16,6 @@ add_subdirectory(stb)
# add_subdirectory(sync)
# add_subdirectory(sync)
# add_subdirectory(telem)
# add_subdirectory(telem)
# add_subdirectory(trans)
# add_subdirectory(trans)
add_subdirectory
(
user
)
add_subdirectory
(
vgroup
)
add_subdirectory
(
vgroup
)
add_subdirectory
(
sut
)
add_subdirectory
(
sut
)
source/dnode/mnode/impl/CMakeLists.txt
浏览文件 @
f904401d
...
@@ -8,7 +8,12 @@ target_include_directories(
...
@@ -8,7 +8,12 @@ target_include_directories(
target_link_libraries
(
target_link_libraries
(
mnode
mnode
PRIVATE sdb
PRIVATE sdb
PRIVATE wal
PRIVATE transport
PRIVATE transport
PRIVATE cjson
PRIVATE cjson
PRIVATE sync
PRIVATE sync
)
)
\ No newline at end of file
if
(
${
BUILD_TEST
}
)
add_subdirectory
(
test
)
endif
(
${
BUILD_TEST
}
)
\ No newline at end of file
source/dnode/mnode/impl/inc/mndInt.h
浏览文件 @
f904401d
...
@@ -17,11 +17,13 @@
...
@@ -17,11 +17,13 @@
#define _TD_MND_INT_H_
#define _TD_MND_INT_H_
#include "mndDef.h"
#include "mndDef.h"
#include "sdb.h"
#include "sdb.h"
#include "tcache.h"
#include "tcache.h"
#include "tep.h"
#include "tep.h"
#include "tqueue.h"
#include "tqueue.h"
#include "ttime.h"
#include "ttime.h"
#include "wal.h"
#ifdef __cplusplus
#ifdef __cplusplus
extern
"C"
{
extern
"C"
{
...
@@ -65,6 +67,7 @@ typedef struct {
...
@@ -65,6 +67,7 @@ typedef struct {
typedef
struct
{
typedef
struct
{
int32_t
errCode
;
int32_t
errCode
;
sem_t
syncSem
;
sem_t
syncSem
;
SWal
*
pWal
;
SSyncNode
*
pSyncNode
;
SSyncNode
*
pSyncNode
;
ESyncState
state
;
ESyncState
state
;
}
SSyncMgmt
;
}
SSyncMgmt
;
...
...
source/dnode/mnode/impl/src/mndDnode.c
浏览文件 @
f904401d
...
@@ -354,7 +354,7 @@ static int32_t mndProcessStatusMsg(SMnodeMsg *pMsg) {
...
@@ -354,7 +354,7 @@ static int32_t mndProcessStatusMsg(SMnodeMsg *pMsg) {
}
}
if
(
pStatus
->
dnodeId
==
0
)
{
if
(
pStatus
->
dnodeId
==
0
)
{
mDebug
(
"dnode:%d
%s,
first access, set clusterId %"
PRId64
,
pDnode
->
id
,
pDnode
->
ep
,
pMnode
->
clusterId
);
mDebug
(
"dnode:%d
, %s
first access, set clusterId %"
PRId64
,
pDnode
->
id
,
pDnode
->
ep
,
pMnode
->
clusterId
);
}
else
{
}
else
{
if
(
pStatus
->
clusterId
!=
pMnode
->
clusterId
)
{
if
(
pStatus
->
clusterId
!=
pMnode
->
clusterId
)
{
if
(
pDnode
!=
NULL
)
{
if
(
pDnode
!=
NULL
)
{
...
...
source/dnode/mnode/impl/src/mndShow.c
浏览文件 @
f904401d
...
@@ -152,7 +152,7 @@ static int32_t mndProcessShowMsg(SMnodeMsg *pMnodeMsg) {
...
@@ -152,7 +152,7 @@ static int32_t mndProcessShowMsg(SMnodeMsg *pMnodeMsg) {
}
}
int32_t
code
=
(
*
metaFp
)(
pMnodeMsg
,
pShow
,
&
pRsp
->
tableMeta
);
int32_t
code
=
(
*
metaFp
)(
pMnodeMsg
,
pShow
,
&
pRsp
->
tableMeta
);
mDebug
(
"show:0x%"
PRIx64
", get meta finished, numOfRows:%d cols:%d type:%s result:%s"
,
pShow
->
id
,
pShow
->
numOfRows
,
mDebug
(
"show:0x%"
PRIx64
", get meta finished, numOfRows:%d cols:%d type:%s
,
result:%s"
,
pShow
->
id
,
pShow
->
numOfRows
,
pShow
->
numOfColumns
,
mndShowStr
(
type
),
tstrerror
(
code
));
pShow
->
numOfColumns
,
mndShowStr
(
type
),
tstrerror
(
code
));
if
(
code
==
TSDB_CODE_SUCCESS
)
{
if
(
code
==
TSDB_CODE_SUCCESS
)
{
...
...
source/dnode/mnode/impl/src/mndSync.c
浏览文件 @
f904401d
...
@@ -15,11 +15,110 @@
...
@@ -15,11 +15,110 @@
#define _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#include "mndSync.h"
#include "mndSync.h"
#include "mndTrans.h"
static
int32_t
mndInitWal
(
SMnode
*
pMnode
)
{
SSyncMgmt
*
pMgmt
=
&
pMnode
->
syncMgmt
;
char
path
[
PATH_MAX
]
=
{
0
};
snprintf
(
path
,
sizeof
(
path
),
"%s%swal"
,
pMnode
->
path
,
TD_DIRSEP
);
SWalCfg
cfg
=
{.
vgId
=
1
,
.
fsyncPeriod
=
0
,
.
rollPeriod
=
-
1
,
.
segSize
=
-
1
,
.
retentionPeriod
=
-
1
,
.
retentionSize
=
-
1
,
.
level
=
TAOS_WAL_FSYNC
};
pMgmt
->
pWal
=
walOpen
(
path
,
&
cfg
);
if
(
pMgmt
->
pWal
==
NULL
)
return
-
1
;
return
0
;
}
static
void
mndCloseWal
(
SMnode
*
pMnode
)
{
SSyncMgmt
*
pMgmt
=
&
pMnode
->
syncMgmt
;
if
(
pMgmt
->
pWal
!=
NULL
)
{
walClose
(
pMgmt
->
pWal
);
pMgmt
->
pWal
=
NULL
;
}
}
static
int32_t
mndRestoreWal
(
SMnode
*
pMnode
)
{
SWal
*
pWal
=
pMnode
->
syncMgmt
.
pWal
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int64_t
lastSdbVer
=
sdbUpdateVer
(
pSdb
,
0
);
int32_t
code
=
-
1
;
SWalReadHandle
*
pHandle
=
walOpenReadHandle
(
pWal
);
if
(
pHandle
==
NULL
)
return
-
1
;
int64_t
first
=
walGetFirstVer
(
pWal
);
int64_t
last
=
walGetLastVer
(
pWal
);
mDebug
(
"restore sdb wal start, sdb ver:%"
PRId64
", wal first:%"
PRId64
" last:%"
PRId64
,
lastSdbVer
,
first
,
last
);
first
=
MAX
(
lastSdbVer
+
1
,
first
);
for
(
int64_t
ver
=
first
;
ver
>=
0
&&
ver
<=
last
;
++
ver
)
{
if
(
walReadWithHandle
(
pHandle
,
ver
)
<
0
)
{
mError
(
"failed to read by wal handle since %s, ver:%"
PRId64
,
terrstr
(),
ver
);
goto
WAL_RESTORE_OVER
;
}
SWalHead
*
pHead
=
pHandle
->
pHead
;
int64_t
sdbVer
=
sdbUpdateVer
(
pSdb
,
0
);
if
(
sdbVer
+
1
!=
ver
)
{
terrno
=
TSDB_CODE_SDB_INVALID_WAl_VER
;
mError
(
"failed to read wal from sdb, sdbVer:%"
PRId64
" inconsistent with ver:%"
PRId64
,
sdbVer
,
ver
);
goto
WAL_RESTORE_OVER
;
}
if
(
sdbWriteNotFree
(
pSdb
,
(
void
*
)
pHead
->
head
.
body
)
<
0
)
{
mError
(
"failed to read wal from sdb since %s, ver:%"
PRId64
,
terrstr
(),
ver
);
goto
WAL_RESTORE_OVER
;
}
sdbUpdateVer
(
pSdb
,
1
);
mDebug
(
"wal:%"
PRId64
", is restored"
,
ver
);
}
int64_t
sdbVer
=
sdbUpdateVer
(
pSdb
,
0
);
mDebug
(
"restore sdb wal finished, sdb ver:%"
PRId64
,
sdbVer
);
if
(
walBeginSnapshot
(
pWal
,
sdbVer
)
<
0
)
{
goto
WAL_RESTORE_OVER
;
}
if
(
sdbVer
!=
lastSdbVer
)
{
mInfo
(
"sdb restored from %"
PRId64
" to %"
PRId64
", write file"
,
lastSdbVer
,
sdbVer
);
if
(
sdbWriteFile
(
pSdb
)
!=
0
)
{
goto
WAL_RESTORE_OVER
;
}
}
if
(
walEndSnapshot
(
pWal
)
<
0
)
{
goto
WAL_RESTORE_OVER
;
}
code
=
0
;
WAL_RESTORE_OVER:
walCloseReadHandle
(
pHandle
);
return
code
;
}
int32_t
mndInitSync
(
SMnode
*
pMnode
)
{
int32_t
mndInitSync
(
SMnode
*
pMnode
)
{
SSyncMgmt
*
pMgmt
=
&
pMnode
->
syncMgmt
;
SSyncMgmt
*
pMgmt
=
&
pMnode
->
syncMgmt
;
tsem_init
(
&
pMgmt
->
syncSem
,
0
,
0
);
tsem_init
(
&
pMgmt
->
syncSem
,
0
,
0
);
if
(
mndInitWal
(
pMnode
)
<
0
)
{
mError
(
"failed to open wal since %s"
,
terrstr
());
return
-
1
;
}
if
(
mndRestoreWal
(
pMnode
)
<
0
)
{
mError
(
"failed to restore wal since %s"
,
terrstr
());
return
-
1
;
}
pMgmt
->
state
=
TAOS_SYNC_STATE_LEADER
;
pMgmt
->
state
=
TAOS_SYNC_STATE_LEADER
;
pMgmt
->
pSyncNode
=
NULL
;
pMgmt
->
pSyncNode
=
NULL
;
return
0
;
return
0
;
...
@@ -28,6 +127,7 @@ int32_t mndInitSync(SMnode *pMnode) {
...
@@ -28,6 +127,7 @@ int32_t mndInitSync(SMnode *pMnode) {
void
mndCleanupSync
(
SMnode
*
pMnode
)
{
void
mndCleanupSync
(
SMnode
*
pMnode
)
{
SSyncMgmt
*
pMgmt
=
&
pMnode
->
syncMgmt
;
SSyncMgmt
*
pMgmt
=
&
pMnode
->
syncMgmt
;
tsem_destroy
(
&
pMgmt
->
syncSem
);
tsem_destroy
(
&
pMgmt
->
syncSem
);
mndCloseWal
(
pMnode
);
}
}
static
int32_t
mndSyncApplyCb
(
struct
SSyncFSM
*
fsm
,
SyncIndex
index
,
const
SSyncBuffer
*
buf
,
void
*
pData
)
{
static
int32_t
mndSyncApplyCb
(
struct
SSyncFSM
*
fsm
,
SyncIndex
index
,
const
SSyncBuffer
*
buf
,
void
*
pData
)
{
...
@@ -41,6 +141,20 @@ static int32_t mndSyncApplyCb(struct SSyncFSM *fsm, SyncIndex index, const SSync
...
@@ -41,6 +141,20 @@ static int32_t mndSyncApplyCb(struct SSyncFSM *fsm, SyncIndex index, const SSync
}
}
int32_t
mndSyncPropose
(
SMnode
*
pMnode
,
SSdbRaw
*
pRaw
)
{
int32_t
mndSyncPropose
(
SMnode
*
pMnode
,
SSdbRaw
*
pRaw
)
{
SWal
*
pWal
=
pMnode
->
syncMgmt
.
pWal
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int64_t
ver
=
sdbUpdateVer
(
pSdb
,
1
);
if
(
walWrite
(
pWal
,
ver
,
1
,
pRaw
,
sdbGetRawTotalSize
(
pRaw
))
<
0
)
{
sdbUpdateVer
(
pSdb
,
-
1
);
mError
(
"failed to write raw:%p since %s, ver:%"
PRId64
,
pRaw
,
terrstr
(),
ver
);
return
-
1
;
}
mTrace
(
"raw:%p, write to wal, ver:%"
PRId64
,
pRaw
,
ver
);
walCommit
(
pWal
,
ver
);
walFsync
(
pWal
,
true
);
#if 1
#if 1
return
0
;
return
0
;
#else
#else
...
...
source/dnode/mnode/impl/src/mndTrans.c
浏览文件 @
f904401d
...
@@ -169,7 +169,7 @@ TRANS_ENCODE_OVER:
...
@@ -169,7 +169,7 @@ TRANS_ENCODE_OVER:
return
NULL
;
return
NULL
;
}
}
mTrace
(
"trans:%d, encode to raw:%p,
len:%d"
,
pTrans
->
id
,
pRaw
,
dataPos
);
mTrace
(
"trans:%d, encode to raw:%p,
row:%p len:%d"
,
pTrans
->
id
,
pRaw
,
pTrans
,
dataPos
);
return
pRaw
;
return
pRaw
;
}
}
...
@@ -226,6 +226,7 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
...
@@ -226,6 +226,7 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
dataLen
,
TRANS_DECODE_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
dataLen
,
TRANS_DECODE_OVER
)
pData
=
malloc
(
dataLen
);
pData
=
malloc
(
dataLen
);
if
(
pData
==
NULL
)
goto
TRANS_DECODE_OVER
;
if
(
pData
==
NULL
)
goto
TRANS_DECODE_OVER
;
mTrace
(
"raw:%p, is created"
,
pData
);
SDB_GET_BINARY
(
pRaw
,
dataPos
,
pData
,
dataLen
,
TRANS_DECODE_OVER
);
SDB_GET_BINARY
(
pRaw
,
dataPos
,
pData
,
dataLen
,
TRANS_DECODE_OVER
);
if
(
taosArrayPush
(
pTrans
->
redoLogs
,
&
pData
)
==
NULL
)
goto
TRANS_DECODE_OVER
;
if
(
taosArrayPush
(
pTrans
->
redoLogs
,
&
pData
)
==
NULL
)
goto
TRANS_DECODE_OVER
;
pData
=
NULL
;
pData
=
NULL
;
...
@@ -235,6 +236,7 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
...
@@ -235,6 +236,7 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
dataLen
,
TRANS_DECODE_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
dataLen
,
TRANS_DECODE_OVER
)
pData
=
malloc
(
dataLen
);
pData
=
malloc
(
dataLen
);
if
(
pData
==
NULL
)
goto
TRANS_DECODE_OVER
;
if
(
pData
==
NULL
)
goto
TRANS_DECODE_OVER
;
mTrace
(
"raw:%p, is created"
,
pData
);
SDB_GET_BINARY
(
pRaw
,
dataPos
,
pData
,
dataLen
,
TRANS_DECODE_OVER
);
SDB_GET_BINARY
(
pRaw
,
dataPos
,
pData
,
dataLen
,
TRANS_DECODE_OVER
);
if
(
taosArrayPush
(
pTrans
->
undoLogs
,
&
pData
)
==
NULL
)
goto
TRANS_DECODE_OVER
;
if
(
taosArrayPush
(
pTrans
->
undoLogs
,
&
pData
)
==
NULL
)
goto
TRANS_DECODE_OVER
;
pData
=
NULL
;
pData
=
NULL
;
...
@@ -243,6 +245,8 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
...
@@ -243,6 +245,8 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
for
(
int32_t
i
=
0
;
i
<
commitLogNum
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
commitLogNum
;
++
i
)
{
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
dataLen
,
TRANS_DECODE_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
dataLen
,
TRANS_DECODE_OVER
)
pData
=
malloc
(
dataLen
);
pData
=
malloc
(
dataLen
);
if
(
pData
==
NULL
)
goto
TRANS_DECODE_OVER
;
mTrace
(
"raw:%p, is created"
,
pData
);
SDB_GET_BINARY
(
pRaw
,
dataPos
,
pData
,
dataLen
,
TRANS_DECODE_OVER
);
SDB_GET_BINARY
(
pRaw
,
dataPos
,
pData
,
dataLen
,
TRANS_DECODE_OVER
);
if
(
taosArrayPush
(
pTrans
->
commitLogs
,
&
pData
)
==
NULL
)
goto
TRANS_DECODE_OVER
;
if
(
taosArrayPush
(
pTrans
->
commitLogs
,
&
pData
)
==
NULL
)
goto
TRANS_DECODE_OVER
;
pData
=
NULL
;
pData
=
NULL
;
...
@@ -284,13 +288,13 @@ TRANS_DECODE_OVER:
...
@@ -284,13 +288,13 @@ TRANS_DECODE_OVER:
return
NULL
;
return
NULL
;
}
}
mTrace
(
"trans:%d, decode from raw:%p,
data
:%p"
,
pTrans
->
id
,
pRaw
,
pTrans
);
mTrace
(
"trans:%d, decode from raw:%p,
row
:%p"
,
pTrans
->
id
,
pRaw
,
pTrans
);
return
pRow
;
return
pRow
;
}
}
static
int32_t
mndTransActionInsert
(
SSdb
*
pSdb
,
STrans
*
pTrans
)
{
static
int32_t
mndTransActionInsert
(
SSdb
*
pSdb
,
STrans
*
pTrans
)
{
pTrans
->
stage
=
TRN_STAGE_PREPARE
;
pTrans
->
stage
=
TRN_STAGE_PREPARE
;
mTrace
(
"trans:%d, perform insert action,
data
:%p"
,
pTrans
->
id
,
pTrans
);
mTrace
(
"trans:%d, perform insert action,
row
:%p"
,
pTrans
->
id
,
pTrans
);
return
0
;
return
0
;
}
}
...
@@ -303,13 +307,13 @@ static void mndTransDropData(STrans *pTrans) {
...
@@ -303,13 +307,13 @@ static void mndTransDropData(STrans *pTrans) {
}
}
static
int32_t
mndTransActionDelete
(
SSdb
*
pSdb
,
STrans
*
pTrans
)
{
static
int32_t
mndTransActionDelete
(
SSdb
*
pSdb
,
STrans
*
pTrans
)
{
mTrace
(
"trans:%d, perform delete action,
data
:%p"
,
pTrans
->
id
,
pTrans
);
mTrace
(
"trans:%d, perform delete action,
row
:%p"
,
pTrans
->
id
,
pTrans
);
mndTransDropData
(
pTrans
);
mndTransDropData
(
pTrans
);
return
0
;
return
0
;
}
}
static
int32_t
mndTransActionUpdate
(
SSdb
*
pSdb
,
STrans
*
pOldTrans
,
STrans
*
pNewTrans
)
{
static
int32_t
mndTransActionUpdate
(
SSdb
*
pSdb
,
STrans
*
pOldTrans
,
STrans
*
pNewTrans
)
{
mTrace
(
"trans:%d, perform update action,
data:%p"
,
pOldTrans
->
id
,
pOld
Trans
);
mTrace
(
"trans:%d, perform update action,
old_row:%p new_row:%p"
,
pOldTrans
->
id
,
pOldTrans
,
pNew
Trans
);
pOldTrans
->
stage
=
pNewTrans
->
stage
;
pOldTrans
->
stage
=
pNewTrans
->
stage
;
return
0
;
return
0
;
}
}
...
...
source/dnode/mnode/impl/src/mnode.c
浏览文件 @
f904401d
...
@@ -185,7 +185,7 @@ static void mndCleanupSteps(SMnode *pMnode, int32_t pos) {
...
@@ -185,7 +185,7 @@ static void mndCleanupSteps(SMnode *pMnode, int32_t pos) {
for
(
int32_t
s
=
pos
;
s
>=
0
;
s
--
)
{
for
(
int32_t
s
=
pos
;
s
>=
0
;
s
--
)
{
SMnodeStep
*
pStep
=
taosArrayGet
(
pMnode
->
pSteps
,
s
);
SMnodeStep
*
pStep
=
taosArrayGet
(
pMnode
->
pSteps
,
s
);
mDebug
(
"
step:
%s will cleanup"
,
pStep
->
name
);
mDebug
(
"%s will cleanup"
,
pStep
->
name
);
if
(
pStep
->
cleanupFp
!=
NULL
)
{
if
(
pStep
->
cleanupFp
!=
NULL
)
{
(
*
pStep
->
cleanupFp
)(
pMnode
);
(
*
pStep
->
cleanupFp
)(
pMnode
);
}
}
...
@@ -204,12 +204,12 @@ static int32_t mndExecSteps(SMnode *pMnode) {
...
@@ -204,12 +204,12 @@ static int32_t mndExecSteps(SMnode *pMnode) {
if
((
*
pStep
->
initFp
)(
pMnode
)
!=
0
)
{
if
((
*
pStep
->
initFp
)(
pMnode
)
!=
0
)
{
int32_t
code
=
terrno
;
int32_t
code
=
terrno
;
mError
(
"
step:
%s exec failed since %s, start to cleanup"
,
pStep
->
name
,
terrstr
());
mError
(
"%s exec failed since %s, start to cleanup"
,
pStep
->
name
,
terrstr
());
mndCleanupSteps
(
pMnode
,
pos
);
mndCleanupSteps
(
pMnode
,
pos
);
terrno
=
code
;
terrno
=
code
;
return
-
1
;
return
-
1
;
}
else
{
}
else
{
mDebug
(
"
step:
%s is initialized"
,
pStep
->
name
);
mDebug
(
"%s is initialized"
,
pStep
->
name
);
}
}
}
}
...
@@ -357,7 +357,7 @@ SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) {
...
@@ -357,7 +357,7 @@ SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) {
SMnodeMsg
*
pMsg
=
taosAllocateQitem
(
sizeof
(
SMnodeMsg
));
SMnodeMsg
*
pMsg
=
taosAllocateQitem
(
sizeof
(
SMnodeMsg
));
if
(
pMsg
==
NULL
)
{
if
(
pMsg
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
mError
(
"
RPC:%p, app:%p failed to create msg since %s"
,
pRpcMsg
->
handle
,
pRpcMsg
->
ahandle
,
terrstr
()
);
mError
(
"
failed to create msg since %s, app:%p RPC:%p"
,
terrstr
(),
pRpcMsg
->
ahandle
,
pRpcMsg
->
handle
);
return
NULL
;
return
NULL
;
}
}
...
@@ -365,7 +365,7 @@ SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) {
...
@@ -365,7 +365,7 @@ SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) {
if
((
pRpcMsg
->
msgType
&
1U
)
&&
rpcGetConnInfo
(
pRpcMsg
->
handle
,
&
connInfo
)
!=
0
)
{
if
((
pRpcMsg
->
msgType
&
1U
)
&&
rpcGetConnInfo
(
pRpcMsg
->
handle
,
&
connInfo
)
!=
0
)
{
taosFreeQitem
(
pMsg
);
taosFreeQitem
(
pMsg
);
terrno
=
TSDB_CODE_MND_NO_USER_FROM_CONN
;
terrno
=
TSDB_CODE_MND_NO_USER_FROM_CONN
;
mError
(
"
RPC:%p, app:%p failed to create msg since %s"
,
pRpcMsg
->
handle
,
pRpcMsg
->
ahandle
,
terrstr
()
);
mError
(
"
failed to create msg since %s, app:%p RPC:%p"
,
terrstr
(),
pRpcMsg
->
ahandle
,
pRpcMsg
->
handle
);
return
NULL
;
return
NULL
;
}
}
memcpy
(
pMsg
->
user
,
connInfo
.
user
,
TSDB_USER_LEN
);
memcpy
(
pMsg
->
user
,
connInfo
.
user
,
TSDB_USER_LEN
);
...
@@ -374,12 +374,12 @@ SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) {
...
@@ -374,12 +374,12 @@ SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) {
pMsg
->
rpcMsg
=
*
pRpcMsg
;
pMsg
->
rpcMsg
=
*
pRpcMsg
;
pMsg
->
createdTime
=
taosGetTimestampSec
();
pMsg
->
createdTime
=
taosGetTimestampSec
();
mTrace
(
"msg:%p,
app:%p is created, RPC:%p"
,
pMsg
,
pRpcMsg
->
ahandle
,
pRpcMsg
->
handle
);
mTrace
(
"msg:%p,
is created, app:%p RPC:%p user:%s"
,
pMsg
,
pRpcMsg
->
ahandle
,
pRpcMsg
->
handle
,
pMsg
->
user
);
return
pMsg
;
return
pMsg
;
}
}
void
mndCleanupMsg
(
SMnodeMsg
*
pMsg
)
{
void
mndCleanupMsg
(
SMnodeMsg
*
pMsg
)
{
mTrace
(
"msg:%p,
app:%p is destroyed,
RPC:%p"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
->
rpcMsg
.
handle
);
mTrace
(
"msg:%p,
is destroyed, app:%p
RPC:%p"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
->
rpcMsg
.
handle
);
rpcFreeCont
(
pMsg
->
rpcMsg
.
pCont
);
rpcFreeCont
(
pMsg
->
rpcMsg
.
pCont
);
pMsg
->
rpcMsg
.
pCont
=
NULL
;
pMsg
->
rpcMsg
.
pCont
=
NULL
;
taosFreeQitem
(
pMsg
);
taosFreeQitem
(
pMsg
);
...
@@ -397,37 +397,37 @@ void mndProcessMsg(SMnodeMsg *pMsg) {
...
@@ -397,37 +397,37 @@ void mndProcessMsg(SMnodeMsg *pMsg) {
void
*
ahandle
=
pMsg
->
rpcMsg
.
ahandle
;
void
*
ahandle
=
pMsg
->
rpcMsg
.
ahandle
;
bool
isReq
=
(
msgType
&
1U
);
bool
isReq
=
(
msgType
&
1U
);
mTrace
(
"msg:%p,
app:%p type:%s will be processed"
,
pMsg
,
ahandle
,
TMSG_INFO
(
msgType
)
);
mTrace
(
"msg:%p,
type:%s will be processed, app:%p"
,
pMsg
,
TMSG_INFO
(
msgType
),
ahandle
);
if
(
isReq
&&
!
mndIsMaster
(
pMnode
))
{
if
(
isReq
&&
!
mndIsMaster
(
pMnode
))
{
code
=
TSDB_CODE_APP_NOT_READY
;
code
=
TSDB_CODE_APP_NOT_READY
;
mDebug
(
"msg:%p,
app:%p failed to process since %s"
,
pMsg
,
ahandle
,
terrstr
()
);
mDebug
(
"msg:%p,
failed to process since %s, app:%p"
,
pMsg
,
terrstr
(),
ahandle
);
goto
PROCESS_RPC_END
;
goto
PROCESS_RPC_END
;
}
}
if
(
isReq
&&
pMsg
->
rpcMsg
.
pCont
==
NULL
)
{
if
(
isReq
&&
pMsg
->
rpcMsg
.
pCont
==
NULL
)
{
code
=
TSDB_CODE_MND_INVALID_MSG_LEN
;
code
=
TSDB_CODE_MND_INVALID_MSG_LEN
;
mError
(
"msg:%p,
app:%p failed to process since %s"
,
pMsg
,
ahandle
,
terrstr
()
);
mError
(
"msg:%p,
failed to process since %s, app:%p"
,
pMsg
,
terrstr
(),
ahandle
);
goto
PROCESS_RPC_END
;
goto
PROCESS_RPC_END
;
}
}
MndMsgFp
fp
=
pMnode
->
msgFp
[
TMSG_INDEX
(
msgType
)];
MndMsgFp
fp
=
pMnode
->
msgFp
[
TMSG_INDEX
(
msgType
)];
if
(
fp
==
NULL
)
{
if
(
fp
==
NULL
)
{
code
=
TSDB_CODE_MSG_NOT_PROCESSED
;
code
=
TSDB_CODE_MSG_NOT_PROCESSED
;
mError
(
"msg:%p,
app:%p failed to process since no handle
"
,
pMsg
,
ahandle
);
mError
(
"msg:%p,
failed to process since no msg handle, app:%p
"
,
pMsg
,
ahandle
);
goto
PROCESS_RPC_END
;
goto
PROCESS_RPC_END
;
}
}
code
=
(
*
fp
)(
pMsg
);
code
=
(
*
fp
)(
pMsg
);
if
(
code
==
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
if
(
code
==
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
mTrace
(
"msg:%p,
app:%p in progressing
"
,
pMsg
,
ahandle
);
mTrace
(
"msg:%p,
in progress, app:%p
"
,
pMsg
,
ahandle
);
return
;
return
;
}
else
if
(
code
!=
0
)
{
}
else
if
(
code
!=
0
)
{
code
=
terrno
;
code
=
terrno
;
mError
(
"msg:%p,
app:%p failed to process since %s"
,
pMsg
,
ahandle
,
terrstr
()
);
mError
(
"msg:%p,
failed to process since %s, app:%p"
,
pMsg
,
terrstr
(),
ahandle
);
goto
PROCESS_RPC_END
;
goto
PROCESS_RPC_END
;
}
else
{
}
else
{
mTrace
(
"msg:%p,
app:%p is processed
"
,
pMsg
,
ahandle
);
mTrace
(
"msg:%p,
is processed, app:%p
"
,
pMsg
,
ahandle
);
}
}
PROCESS_RPC_END:
PROCESS_RPC_END:
...
...
source/dnode/mnode/impl/test/CMakeLists.txt
0 → 100644
浏览文件 @
f904401d
enable_testing
()
add_subdirectory
(
acct
)
add_subdirectory
(
user
)
source/dnode/m
gmt
/impl/test/acct/CMakeLists.txt
→
source/dnode/m
node
/impl/test/acct/CMakeLists.txt
浏览文件 @
f904401d
aux_source_directory
(
. ACCT_SRC
)
aux_source_directory
(
. ACCT_SRC
)
add_executable
(
d
node_test_acct
${
ACCT_SRC
}
)
add_executable
(
m
node_test_acct
${
ACCT_SRC
}
)
target_link_libraries
(
target_link_libraries
(
d
node_test_acct
m
node_test_acct
PUBLIC sut
PUBLIC sut
)
)
add_test
(
add_test
(
NAME
d
node_test_acct
NAME
m
node_test_acct
COMMAND
d
node_test_acct
COMMAND
m
node_test_acct
)
)
source/dnode/m
gmt
/impl/test/acct/acct.cpp
→
source/dnode/m
node
/impl/test/acct/acct.cpp
浏览文件 @
f904401d
/**
/**
* @file acct.cpp
* @file acct.cpp
* @author slguan (slguan@taosdata.com)
* @author slguan (slguan@taosdata.com)
* @brief
D
NODE module acct-msg tests
* @brief
M
NODE module acct-msg tests
* @version 0.1
* @version 0.1
* @date 2021-12-15
* @date 2021-12-15
*
*
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
class
DndTestAcct
:
public
::
testing
::
Test
{
class
DndTestAcct
:
public
::
testing
::
Test
{
protected:
protected:
static
void
SetUpTestSuite
()
{
test
.
Init
(
"/tmp/
d
node_test_acct"
,
9012
);
}
static
void
SetUpTestSuite
()
{
test
.
Init
(
"/tmp/
m
node_test_acct"
,
9012
);
}
static
void
TearDownTestSuite
()
{
test
.
Cleanup
();
}
static
void
TearDownTestSuite
()
{
test
.
Cleanup
();
}
static
Testbase
test
;
static
Testbase
test
;
...
...
source/dnode/mnode/impl/test/mnodeTests.cpp
已删除
100644 → 0
浏览文件 @
679553f7
source/dnode/m
gmt
/impl/test/user/CMakeLists.txt
→
source/dnode/m
node
/impl/test/user/CMakeLists.txt
浏览文件 @
f904401d
aux_source_directory
(
. USER_SRC
)
aux_source_directory
(
. USER_SRC
)
add_executable
(
d
node_test_user
${
USER_SRC
}
)
add_executable
(
m
node_test_user
${
USER_SRC
}
)
target_link_libraries
(
target_link_libraries
(
d
node_test_user
m
node_test_user
PUBLIC sut
PUBLIC sut
)
)
add_test
(
add_test
(
NAME
d
node_test_user
NAME
m
node_test_user
COMMAND
d
node_test_user
COMMAND
m
node_test_user
)
)
source/dnode/m
gmt
/impl/test/user/user.cpp
→
source/dnode/m
node
/impl/test/user/user.cpp
浏览文件 @
f904401d
/**
/**
* @file user.cpp
* @file user.cpp
* @author slguan (slguan@taosdata.com)
* @author slguan (slguan@taosdata.com)
* @brief
D
NODE module user-msg tests
* @brief
M
NODE module user-msg tests
* @version 0.1
* @version 0.1
* @date 2021-12-15
* @date 2021-12-15
*
*
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
class
DndTestUser
:
public
::
testing
::
Test
{
class
DndTestUser
:
public
::
testing
::
Test
{
protected:
protected:
static
void
SetUpTestSuite
()
{
test
.
Init
(
"/tmp/
d
node_test_user"
,
9140
);
}
static
void
SetUpTestSuite
()
{
test
.
Init
(
"/tmp/
m
node_test_user"
,
9140
);
}
static
void
TearDownTestSuite
()
{
test
.
Cleanup
();
}
static
void
TearDownTestSuite
()
{
test
.
Cleanup
();
}
static
Testbase
test
;
static
Testbase
test
;
...
...
source/dnode/mnode/sdb/inc/sdbInt.h
浏览文件 @
f904401d
...
@@ -17,11 +17,12 @@
...
@@ -17,11 +17,12 @@
#define _TD_SDB_INT_H_
#define _TD_SDB_INT_H_
#include "os.h"
#include "os.h"
#include "sdb.h"
#include "sdb.h"
#include "tmsg.h"
#include "thash.h"
#include "thash.h"
#include "tlockfree.h"
#include "tlockfree.h"
#include "tlog.h"
#include "tlog.h"
#include "tmsg.h"
#ifdef __cplusplus
#ifdef __cplusplus
extern
"C"
{
extern
"C"
{
...
@@ -59,7 +60,8 @@ typedef struct SSdb {
...
@@ -59,7 +60,8 @@ typedef struct SSdb {
char
*
tmpDir
;
char
*
tmpDir
;
int64_t
lastCommitVer
;
int64_t
lastCommitVer
;
int64_t
curVer
;
int64_t
curVer
;
int32_t
maxId
[
SDB_MAX
];
int64_t
tableVer
[
SDB_MAX
];
int64_t
maxId
[
SDB_MAX
];
EKeyType
keyTypes
[
SDB_MAX
];
EKeyType
keyTypes
[
SDB_MAX
];
SHashObj
*
hashObjs
[
SDB_MAX
];
SHashObj
*
hashObjs
[
SDB_MAX
];
SRWLatch
locks
[
SDB_MAX
];
SRWLatch
locks
[
SDB_MAX
];
...
@@ -71,8 +73,6 @@ typedef struct SSdb {
...
@@ -71,8 +73,6 @@ typedef struct SSdb {
SdbDecodeFp
decodeFps
[
SDB_MAX
];
SdbDecodeFp
decodeFps
[
SDB_MAX
];
}
SSdb
;
}
SSdb
;
int32_t
sdbWriteFile
(
SSdb
*
pSdb
);
const
char
*
sdbTableName
(
ESdbType
type
);
const
char
*
sdbTableName
(
ESdbType
type
);
void
sdbPrintOper
(
SSdb
*
pSdb
,
SSdbRow
*
pRow
,
const
char
*
oper
);
void
sdbPrintOper
(
SSdb
*
pSdb
,
SSdbRow
*
pRow
,
const
char
*
oper
);
...
...
source/dnode/mnode/sdb/src/sdb.c
浏览文件 @
f904401d
...
@@ -49,8 +49,13 @@ SSdb *sdbInit(SSdbOpt *pOption) {
...
@@ -49,8 +49,13 @@ SSdb *sdbInit(SSdbOpt *pOption) {
for
(
ESdbType
i
=
0
;
i
<
SDB_MAX
;
++
i
)
{
for
(
ESdbType
i
=
0
;
i
<
SDB_MAX
;
++
i
)
{
taosInitRWLatch
(
&
pSdb
->
locks
[
i
]);
taosInitRWLatch
(
&
pSdb
->
locks
[
i
]);
pSdb
->
maxId
[
i
]
=
0
;
pSdb
->
tableVer
[
i
]
=
-
1
;
pSdb
->
keyTypes
[
i
]
=
SDB_KEY_INT32
;
}
}
pSdb
->
curVer
=
-
1
;
pSdb
->
lastCommitVer
=
-
1
;
pSdb
->
pMnode
=
pOption
->
pMnode
;
pSdb
->
pMnode
=
pOption
->
pMnode
;
mDebug
(
"sdb init successfully"
);
mDebug
(
"sdb init successfully"
);
return
pSdb
;
return
pSdb
;
...
@@ -59,10 +64,10 @@ SSdb *sdbInit(SSdbOpt *pOption) {
...
@@ -59,10 +64,10 @@ SSdb *sdbInit(SSdbOpt *pOption) {
void
sdbCleanup
(
SSdb
*
pSdb
)
{
void
sdbCleanup
(
SSdb
*
pSdb
)
{
mDebug
(
"start to cleanup sdb"
);
mDebug
(
"start to cleanup sdb"
);
//
if (pSdb->curVer != pSdb->lastCommitVer) {
if
(
pSdb
->
curVer
!=
pSdb
->
lastCommitVer
)
{
mDebug
(
"write sdb file for curVer:% "
PRId64
" and lastV
er:%"
PRId64
,
pSdb
->
curVer
,
pSdb
->
lastCommitVer
);
mDebug
(
"write sdb file for current ver:%"
PRId64
" != last commit v
er:%"
PRId64
,
pSdb
->
curVer
,
pSdb
->
lastCommitVer
);
sdbWriteFile
(
pSdb
);
sdbWriteFile
(
pSdb
);
//
}
}
if
(
pSdb
->
currDir
!=
NULL
)
{
if
(
pSdb
->
currDir
!=
NULL
)
{
tfree
(
pSdb
->
currDir
);
tfree
(
pSdb
->
currDir
);
...
@@ -133,7 +138,7 @@ int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) {
...
@@ -133,7 +138,7 @@ int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) {
pSdb
->
maxId
[
sdbType
]
=
0
;
pSdb
->
maxId
[
sdbType
]
=
0
;
pSdb
->
hashObjs
[
sdbType
]
=
hash
;
pSdb
->
hashObjs
[
sdbType
]
=
hash
;
taosInitRWLatch
(
&
pSdb
->
locks
[
sdbType
]);
taosInitRWLatch
(
&
pSdb
->
locks
[
sdbType
]);
mDebug
(
"sdb table:%
d is initialized"
,
sdbType
);
mDebug
(
"sdb table:%
s is initialized"
,
sdbTableName
(
sdbType
)
);
return
0
;
return
0
;
}
}
...
@@ -159,3 +164,8 @@ static int32_t sdbCreateDir(SSdb *pSdb) {
...
@@ -159,3 +164,8 @@ static int32_t sdbCreateDir(SSdb *pSdb) {
return
0
;
return
0
;
}
}
int64_t
sdbUpdateVer
(
SSdb
*
pSdb
,
int32_t
val
)
{
pSdb
->
curVer
+=
val
;
return
pSdb
->
curVer
;
}
\ No newline at end of file
source/dnode/mnode/sdb/src/sdbFile.c
浏览文件 @
f904401d
...
@@ -17,10 +17,13 @@
...
@@ -17,10 +17,13 @@
#include "sdbInt.h"
#include "sdbInt.h"
#include "tchecksum.h"
#include "tchecksum.h"
#define SDB_TABLE_SIZE 24
#define SDB_RESERVE_SIZE 512
static
int32_t
sdbRunDeployFp
(
SSdb
*
pSdb
)
{
static
int32_t
sdbRunDeployFp
(
SSdb
*
pSdb
)
{
mDebug
(
"start to deploy sdb"
);
mDebug
(
"start to deploy sdb"
);
for
(
ESdbType
i
=
SDB_MAX
-
1
;
i
>
SDB_START
;
--
i
)
{
for
(
int32_t
i
=
SDB_MAX
-
1
;
i
>=
0
;
--
i
)
{
SdbDeployFp
fp
=
pSdb
->
deployFps
[
i
];
SdbDeployFp
fp
=
pSdb
->
deployFps
[
i
];
if
(
fp
==
NULL
)
continue
;
if
(
fp
==
NULL
)
continue
;
...
@@ -34,6 +37,100 @@ static int32_t sdbRunDeployFp(SSdb *pSdb) {
...
@@ -34,6 +37,100 @@ static int32_t sdbRunDeployFp(SSdb *pSdb) {
return
0
;
return
0
;
}
}
static
int32_t
sdbReadFileHead
(
SSdb
*
pSdb
,
FileFd
fd
)
{
int32_t
ret
=
taosReadFile
(
fd
,
&
pSdb
->
curVer
,
sizeof
(
int64_t
));
if
(
ret
<
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
if
(
ret
!=
sizeof
(
int64_t
))
{
terrno
=
TSDB_CODE_FILE_CORRUPTED
;
return
-
1
;
}
for
(
int32_t
i
=
0
;
i
<
SDB_TABLE_SIZE
;
++
i
)
{
int64_t
maxId
=
-
1
;
ret
=
taosReadFile
(
fd
,
&
maxId
,
sizeof
(
int64_t
));
if
(
ret
<
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
if
(
ret
!=
sizeof
(
int64_t
))
{
terrno
=
TSDB_CODE_FILE_CORRUPTED
;
return
-
1
;
}
if
(
i
<
SDB_MAX
)
{
pSdb
->
maxId
[
i
]
=
maxId
;
}
}
for
(
int32_t
i
=
0
;
i
<
SDB_TABLE_SIZE
;
++
i
)
{
int64_t
ver
=
-
1
;
ret
=
taosReadFile
(
fd
,
&
ver
,
sizeof
(
int64_t
));
if
(
ret
<
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
if
(
ret
!=
sizeof
(
int64_t
))
{
terrno
=
TSDB_CODE_FILE_CORRUPTED
;
return
-
1
;
}
if
(
i
<
SDB_MAX
)
{
pSdb
->
tableVer
[
i
]
=
ver
;
}
}
char
reserve
[
SDB_RESERVE_SIZE
]
=
{
0
};
ret
=
taosReadFile
(
fd
,
reserve
,
sizeof
(
reserve
));
if
(
ret
<
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
if
(
ret
!=
sizeof
(
reserve
))
{
terrno
=
TSDB_CODE_FILE_CORRUPTED
;
return
-
1
;
}
return
0
;
}
static
int32_t
sdbWriteFileHead
(
SSdb
*
pSdb
,
FileFd
fd
)
{
if
(
taosWriteFile
(
fd
,
&
pSdb
->
curVer
,
sizeof
(
int64_t
))
!=
sizeof
(
int64_t
))
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
for
(
int32_t
i
=
0
;
i
<
SDB_TABLE_SIZE
;
++
i
)
{
int64_t
maxId
=
-
1
;
if
(
i
<
SDB_MAX
)
{
maxId
=
pSdb
->
maxId
[
i
];
}
if
(
taosWriteFile
(
fd
,
&
maxId
,
sizeof
(
int64_t
))
!=
sizeof
(
int64_t
))
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
}
for
(
int32_t
i
=
0
;
i
<
SDB_TABLE_SIZE
;
++
i
)
{
int64_t
ver
=
-
1
;
if
(
i
<
SDB_MAX
)
{
ver
=
pSdb
->
tableVer
[
i
];
}
if
(
taosWriteFile
(
fd
,
&
ver
,
sizeof
(
int64_t
))
!=
sizeof
(
int64_t
))
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
}
char
reserve
[
SDB_RESERVE_SIZE
]
=
{
0
};
if
(
taosWriteFile
(
fd
,
reserve
,
sizeof
(
reserve
))
!=
sizeof
(
reserve
))
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
return
0
;
}
int32_t
sdbReadFile
(
SSdb
*
pSdb
)
{
int32_t
sdbReadFile
(
SSdb
*
pSdb
)
{
int64_t
offset
=
0
;
int64_t
offset
=
0
;
int32_t
code
=
0
;
int32_t
code
=
0
;
...
@@ -43,12 +140,13 @@ int32_t sdbReadFile(SSdb *pSdb) {
...
@@ -43,12 +140,13 @@ int32_t sdbReadFile(SSdb *pSdb) {
SSdbRaw
*
pRaw
=
malloc
(
SDB_MAX_SIZE
);
SSdbRaw
*
pRaw
=
malloc
(
SDB_MAX_SIZE
);
if
(
pRaw
==
NULL
)
{
if
(
pRaw
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
mError
(
"failed read file since %s"
,
terrstr
());
mError
(
"failed read file since %s"
,
terrstr
());
return
-
1
;
return
-
1
;
}
}
char
file
[
PATH_MAX
]
=
{
0
};
char
file
[
PATH_MAX
]
=
{
0
};
snprintf
(
file
,
sizeof
(
file
),
"%s%ssdb.data"
,
pSdb
->
currDir
,
TD_DIRSEP
);
snprintf
(
file
,
sizeof
(
file
),
"%s%ssdb.data"
,
pSdb
->
currDir
,
TD_DIRSEP
);
mDebug
(
"start to read file:%s"
,
file
);
FileFd
fd
=
taosOpenFileRead
(
file
);
FileFd
fd
=
taosOpenFileRead
(
file
);
if
(
fd
<=
0
)
{
if
(
fd
<=
0
)
{
...
@@ -58,6 +156,14 @@ int32_t sdbReadFile(SSdb *pSdb) {
...
@@ -58,6 +156,14 @@ int32_t sdbReadFile(SSdb *pSdb) {
return
0
;
return
0
;
}
}
if
(
sdbReadFileHead
(
pSdb
,
fd
)
!=
0
)
{
mError
(
"failed to read file:%s head since %s"
,
file
,
terrstr
());
pSdb
->
curVer
=
-
1
;
free
(
pRaw
);
taosCloseFile
(
fd
);
return
-
1
;
}
while
(
1
)
{
while
(
1
)
{
readLen
=
sizeof
(
SSdbRaw
);
readLen
=
sizeof
(
SSdbRaw
);
ret
=
taosReadFile
(
fd
,
pRaw
,
readLen
);
ret
=
taosReadFile
(
fd
,
pRaw
,
readLen
);
...
@@ -104,6 +210,8 @@ int32_t sdbReadFile(SSdb *pSdb) {
...
@@ -104,6 +210,8 @@ int32_t sdbReadFile(SSdb *pSdb) {
}
}
code
=
0
;
code
=
0
;
pSdb
->
lastCommitVer
=
pSdb
->
curVer
;
mDebug
(
"read file:%s successfully, ver:%"
PRId64
,
file
,
pSdb
->
lastCommitVer
);
PARSE_SDB_DATA_ERROR:
PARSE_SDB_DATA_ERROR:
taosCloseFile
(
fd
);
taosCloseFile
(
fd
);
...
@@ -130,11 +238,17 @@ int32_t sdbWriteFile(SSdb *pSdb) {
...
@@ -130,11 +238,17 @@ int32_t sdbWriteFile(SSdb *pSdb) {
return
-
1
;
return
-
1
;
}
}
for
(
ESdbType
i
=
SDB_MAX
-
1
;
i
>
SDB_START
;
--
i
)
{
if
(
sdbWriteFileHead
(
pSdb
,
fd
)
!=
0
)
{
mError
(
"failed to write file:%s head since %s"
,
tmpfile
,
terrstr
());
taosCloseFile
(
fd
);
return
-
1
;
}
for
(
int32_t
i
=
SDB_MAX
-
1
;
i
>=
0
;
--
i
)
{
SdbEncodeFp
encodeFp
=
pSdb
->
encodeFps
[
i
];
SdbEncodeFp
encodeFp
=
pSdb
->
encodeFps
[
i
];
if
(
encodeFp
==
NULL
)
continue
;
if
(
encodeFp
==
NULL
)
continue
;
mTrace
(
"
sdb write %s
, total %d rows"
,
sdbTableName
(
i
),
sdbGetSize
(
pSdb
,
i
));
mTrace
(
"
write %s to file
, total %d rows"
,
sdbTableName
(
i
),
sdbGetSize
(
pSdb
,
i
));
SHashObj
*
hash
=
pSdb
->
hashObjs
[
i
];
SHashObj
*
hash
=
pSdb
->
hashObjs
[
i
];
SRWLatch
*
pLock
=
&
pSdb
->
locks
[
i
];
SRWLatch
*
pLock
=
&
pSdb
->
locks
[
i
];
...
@@ -155,7 +269,7 @@ int32_t sdbWriteFile(SSdb *pSdb) {
...
@@ -155,7 +269,7 @@ int32_t sdbWriteFile(SSdb *pSdb) {
pRaw
->
status
=
pRow
->
status
;
pRaw
->
status
=
pRow
->
status
;
int32_t
writeLen
=
sizeof
(
SSdbRaw
)
+
pRaw
->
dataLen
;
int32_t
writeLen
=
sizeof
(
SSdbRaw
)
+
pRaw
->
dataLen
;
if
(
taosWriteFile
(
fd
,
pRaw
,
writeLen
)
!=
writeLen
)
{
if
(
taosWriteFile
(
fd
,
pRaw
,
writeLen
)
!=
writeLen
)
{
code
=
TAOS_SYSTEM_ERROR
(
t
errno
);
code
=
TAOS_SYSTEM_ERROR
(
errno
);
taosHashCancelIterate
(
hash
,
ppRow
);
taosHashCancelIterate
(
hash
,
ppRow
);
sdbFreeRaw
(
pRaw
);
sdbFreeRaw
(
pRaw
);
break
;
break
;
...
@@ -163,7 +277,7 @@ int32_t sdbWriteFile(SSdb *pSdb) {
...
@@ -163,7 +277,7 @@ int32_t sdbWriteFile(SSdb *pSdb) {
int32_t
cksum
=
taosCalcChecksum
(
0
,
(
const
uint8_t
*
)
pRaw
,
sizeof
(
SSdbRaw
)
+
pRaw
->
dataLen
);
int32_t
cksum
=
taosCalcChecksum
(
0
,
(
const
uint8_t
*
)
pRaw
,
sizeof
(
SSdbRaw
)
+
pRaw
->
dataLen
);
if
(
taosWriteFile
(
fd
,
&
cksum
,
sizeof
(
int32_t
))
!=
sizeof
(
int32_t
))
{
if
(
taosWriteFile
(
fd
,
&
cksum
,
sizeof
(
int32_t
))
!=
sizeof
(
int32_t
))
{
code
=
TAOS_SYSTEM_ERROR
(
t
errno
);
code
=
TAOS_SYSTEM_ERROR
(
errno
);
taosHashCancelIterate
(
hash
,
ppRow
);
taosHashCancelIterate
(
hash
,
ppRow
);
sdbFreeRaw
(
pRaw
);
sdbFreeRaw
(
pRaw
);
break
;
break
;
...
@@ -201,7 +315,8 @@ int32_t sdbWriteFile(SSdb *pSdb) {
...
@@ -201,7 +315,8 @@ int32_t sdbWriteFile(SSdb *pSdb) {
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
mError
(
"failed to write file:%s since %s"
,
curfile
,
tstrerror
(
code
));
mError
(
"failed to write file:%s since %s"
,
curfile
,
tstrerror
(
code
));
}
else
{
}
else
{
mDebug
(
"write file:%s successfully"
,
curfile
);
pSdb
->
lastCommitVer
=
pSdb
->
curVer
;
mDebug
(
"write file:%s successfully, ver:%"
PRId64
,
curfile
,
pSdb
->
lastCommitVer
);
}
}
terrno
=
code
;
terrno
=
code
;
...
...
source/dnode/mnode/sdb/src/sdbHash.c
浏览文件 @
f904401d
...
@@ -38,6 +38,10 @@ const char *sdbTableName(ESdbType type) {
...
@@ -38,6 +38,10 @@ const char *sdbTableName(ESdbType type) {
return
"auth"
;
return
"auth"
;
case
SDB_ACCT
:
case
SDB_ACCT
:
return
"acct"
;
return
"acct"
;
case
SDB_CONSUMER
:
return
"consumer"
;
case
SDB_CGROUP
:
return
"cgroup"
;
case
SDB_TOPIC
:
case
SDB_TOPIC
:
return
"topic"
;
return
"topic"
;
case
SDB_VGROUP
:
case
SDB_VGROUP
:
...
@@ -53,24 +57,41 @@ const char *sdbTableName(ESdbType type) {
...
@@ -53,24 +57,41 @@ const char *sdbTableName(ESdbType type) {
}
}
}
}
static
const
char
*
sdbStatusStr
(
ESdbStatus
status
)
{
switch
(
status
)
{
case
SDB_STATUS_CREATING
:
return
"creating"
;
case
SDB_STATUS_UPDATING
:
return
"updating"
;
case
SDB_STATUS_DROPPING
:
return
"dropping"
;
case
SDB_STATUS_READY
:
return
"ready"
;
case
SDB_STATUS_DROPPED
:
return
"dropped"
;
default:
return
"undefine"
;
}
}
void
sdbPrintOper
(
SSdb
*
pSdb
,
SSdbRow
*
pRow
,
const
char
*
oper
)
{
void
sdbPrintOper
(
SSdb
*
pSdb
,
SSdbRow
*
pRow
,
const
char
*
oper
)
{
EKeyType
keyType
=
pSdb
->
keyTypes
[
pRow
->
type
];
EKeyType
keyType
=
pSdb
->
keyTypes
[
pRow
->
type
];
if
(
keyType
==
SDB_KEY_BINARY
)
{
if
(
keyType
==
SDB_KEY_BINARY
)
{
mTrace
(
"%s:%s, refCount:%d oper:%s row:%p
"
,
sdbTableName
(
pRow
->
type
),
(
char
*
)
pRow
->
pObj
,
pRow
->
refCount
,
oper
,
mTrace
(
"%s:%s, refCount:%d oper:%s row:%p
status:%s"
,
sdbTableName
(
pRow
->
type
),
(
char
*
)
pRow
->
pObj
,
pRow
->
refCount
,
pRow
->
pObj
);
oper
,
pRow
->
pObj
,
sdbStatusStr
(
pRow
->
status
)
);
}
else
if
(
keyType
==
SDB_KEY_INT32
)
{
}
else
if
(
keyType
==
SDB_KEY_INT32
)
{
mTrace
(
"%s:%d, refCount:%d oper:%s row:%p
"
,
sdbTableName
(
pRow
->
type
),
*
(
int32_t
*
)
pRow
->
pObj
,
pRow
->
refCount
,
oper
,
mTrace
(
"%s:%d, refCount:%d oper:%s row:%p
status:%s"
,
sdbTableName
(
pRow
->
type
),
*
(
int32_t
*
)
pRow
->
pObj
,
pRow
->
pObj
);
pRow
->
refCount
,
oper
,
pRow
->
pObj
,
sdbStatusStr
(
pRow
->
status
)
);
}
else
if
(
keyType
==
SDB_KEY_INT64
)
{
}
else
if
(
keyType
==
SDB_KEY_INT64
)
{
mTrace
(
"%s:%"
PRId64
", refCount:%d oper:%s row:%p"
,
sdbTableName
(
pRow
->
type
),
*
(
int64_t
*
)
pRow
->
pObj
,
mTrace
(
"%s:%"
PRId64
", refCount:%d oper:%s row:%p
status:%s
"
,
sdbTableName
(
pRow
->
type
),
*
(
int64_t
*
)
pRow
->
pObj
,
pRow
->
refCount
,
oper
,
pRow
->
pObj
);
pRow
->
refCount
,
oper
,
pRow
->
pObj
,
sdbStatusStr
(
pRow
->
status
)
);
}
else
{
}
else
{
}
}
}
}
static
SHashObj
*
sdbGetHash
(
SSdb
*
pSdb
,
int32_t
type
)
{
static
SHashObj
*
sdbGetHash
(
SSdb
*
pSdb
,
int32_t
type
)
{
if
(
type
>=
SDB_MAX
||
type
<
=
SDB_START
)
{
if
(
type
>=
SDB_MAX
||
type
<
0
)
{
terrno
=
TSDB_CODE_SDB_INVALID_TABLE_TYPE
;
terrno
=
TSDB_CODE_SDB_INVALID_TABLE_TYPE
;
return
NULL
;
return
NULL
;
}
}
...
@@ -100,8 +121,6 @@ static int32_t sdbGetkeySize(SSdb *pSdb, ESdbType type, void *pKey) {
...
@@ -100,8 +121,6 @@ static int32_t sdbGetkeySize(SSdb *pSdb, ESdbType type, void *pKey) {
}
}
static
int32_t
sdbInsertRow
(
SSdb
*
pSdb
,
SHashObj
*
hash
,
SSdbRaw
*
pRaw
,
SSdbRow
*
pRow
,
int32_t
keySize
)
{
static
int32_t
sdbInsertRow
(
SSdb
*
pSdb
,
SHashObj
*
hash
,
SSdbRaw
*
pRaw
,
SSdbRow
*
pRow
,
int32_t
keySize
)
{
int32_t
code
=
0
;
SRWLatch
*
pLock
=
&
pSdb
->
locks
[
pRow
->
type
];
SRWLatch
*
pLock
=
&
pSdb
->
locks
[
pRow
->
type
];
taosWLockLatch
(
pLock
);
taosWLockLatch
(
pLock
);
...
@@ -126,10 +145,7 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
...
@@ -126,10 +145,7 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
taosWUnLockLatch
(
pLock
);
taosWUnLockLatch
(
pLock
);
if
(
pSdb
->
keyTypes
[
pRow
->
type
]
==
SDB_KEY_INT32
)
{
int32_t
code
=
0
;
pSdb
->
maxId
[
pRow
->
type
]
=
MAX
(
pSdb
->
maxId
[
pRow
->
type
],
*
((
int32_t
*
)
pRow
->
pObj
));
}
SdbInsertFp
insertFp
=
pSdb
->
insertFps
[
pRow
->
type
];
SdbInsertFp
insertFp
=
pSdb
->
insertFps
[
pRow
->
type
];
if
(
insertFp
!=
NULL
)
{
if
(
insertFp
!=
NULL
)
{
code
=
(
*
insertFp
)(
pSdb
,
pRow
->
pObj
);
code
=
(
*
insertFp
)(
pSdb
,
pRow
->
pObj
);
...
@@ -143,12 +159,18 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
...
@@ -143,12 +159,18 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
}
}
}
}
if
(
pSdb
->
keyTypes
[
pRow
->
type
]
==
SDB_KEY_INT32
)
{
pSdb
->
maxId
[
pRow
->
type
]
=
MAX
(
pSdb
->
maxId
[
pRow
->
type
],
*
((
int32_t
*
)
pRow
->
pObj
));
}
if
(
pSdb
->
keyTypes
[
pRow
->
type
]
==
SDB_KEY_INT64
)
{
pSdb
->
maxId
[
pRow
->
type
]
=
MAX
(
pSdb
->
maxId
[
pRow
->
type
],
*
((
int32_t
*
)
pRow
->
pObj
));
}
pSdb
->
tableVer
[
pRow
->
type
]
++
;
return
0
;
return
0
;
}
}
static
int32_t
sdbUpdateRow
(
SSdb
*
pSdb
,
SHashObj
*
hash
,
SSdbRaw
*
pRaw
,
SSdbRow
*
pNewRow
,
int32_t
keySize
)
{
static
int32_t
sdbUpdateRow
(
SSdb
*
pSdb
,
SHashObj
*
hash
,
SSdbRaw
*
pRaw
,
SSdbRow
*
pNewRow
,
int32_t
keySize
)
{
int32_t
code
=
0
;
SRWLatch
*
pLock
=
&
pSdb
->
locks
[
pNewRow
->
type
];
SRWLatch
*
pLock
=
&
pSdb
->
locks
[
pNewRow
->
type
];
taosRLockLatch
(
pLock
);
taosRLockLatch
(
pLock
);
...
@@ -157,23 +179,25 @@ static int32_t sdbUpdateRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
...
@@ -157,23 +179,25 @@ static int32_t sdbUpdateRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
taosRUnLockLatch
(
pLock
);
taosRUnLockLatch
(
pLock
);
return
sdbInsertRow
(
pSdb
,
hash
,
pRaw
,
pNewRow
,
keySize
);
return
sdbInsertRow
(
pSdb
,
hash
,
pRaw
,
pNewRow
,
keySize
);
}
}
SSdbRow
*
pOldRow
=
*
ppOldRow
;
SSdbRow
*
pOldRow
=
*
ppOldRow
;
pOldRow
->
status
=
pRaw
->
status
;
pOldRow
->
status
=
pRaw
->
status
;
sdbPrintOper
(
pSdb
,
pOldRow
,
"updateRow"
);
taosRUnLockLatch
(
pLock
);
taosRUnLockLatch
(
pLock
);
int32_t
code
=
0
;
SdbUpdateFp
updateFp
=
pSdb
->
updateFps
[
pNewRow
->
type
];
SdbUpdateFp
updateFp
=
pSdb
->
updateFps
[
pNewRow
->
type
];
if
(
updateFp
!=
NULL
)
{
if
(
updateFp
!=
NULL
)
{
code
=
(
*
updateFp
)(
pSdb
,
pOldRow
->
pObj
,
pNewRow
->
pObj
);
code
=
(
*
updateFp
)(
pSdb
,
pOldRow
->
pObj
,
pNewRow
->
pObj
);
}
}
sdbFreeRow
(
pSdb
,
pNewRow
);
sdbFreeRow
(
pSdb
,
pNewRow
);
pSdb
->
tableVer
[
pOldRow
->
type
]
++
;
return
code
;
return
code
;
}
}
static
int32_t
sdbDeleteRow
(
SSdb
*
pSdb
,
SHashObj
*
hash
,
SSdbRaw
*
pRaw
,
SSdbRow
*
pRow
,
int32_t
keySize
)
{
static
int32_t
sdbDeleteRow
(
SSdb
*
pSdb
,
SHashObj
*
hash
,
SSdbRaw
*
pRaw
,
SSdbRow
*
pRow
,
int32_t
keySize
)
{
int32_t
code
=
0
;
SRWLatch
*
pLock
=
&
pSdb
->
locks
[
pRow
->
type
];
SRWLatch
*
pLock
=
&
pSdb
->
locks
[
pRow
->
type
];
taosWLockLatch
(
pLock
);
taosWLockLatch
(
pLock
);
...
@@ -187,12 +211,15 @@ static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
...
@@ -187,12 +211,15 @@ static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
SSdbRow
*
pOldRow
=
*
ppOldRow
;
SSdbRow
*
pOldRow
=
*
ppOldRow
;
pOldRow
->
status
=
pRaw
->
status
;
pOldRow
->
status
=
pRaw
->
status
;
sdbPrintOper
(
pSdb
,
pOldRow
,
"deleteRow"
);
taosHashRemove
(
hash
,
pOldRow
->
pObj
,
keySize
);
taosHashRemove
(
hash
,
pOldRow
->
pObj
,
keySize
);
taosWUnLockLatch
(
pLock
);
taosWUnLockLatch
(
pLock
);
// sdbRelease(pSdb, pOldRow->pObj)
;
pSdb
->
tableVer
[
pOldRow
->
type
]
++
;
sdbFreeRow
(
pSdb
,
pRow
);
sdbFreeRow
(
pSdb
,
pRow
);
return
code
;
// sdbRelease(pSdb, pOldRow->pObj);
return
0
;
}
}
int32_t
sdbWriteNotFree
(
SSdb
*
pSdb
,
SSdbRaw
*
pRaw
)
{
int32_t
sdbWriteNotFree
(
SSdb
*
pSdb
,
SSdbRaw
*
pRaw
)
{
...
@@ -277,7 +304,7 @@ void sdbRelease(SSdb *pSdb, void *pObj) {
...
@@ -277,7 +304,7 @@ void sdbRelease(SSdb *pSdb, void *pObj) {
if
(
pObj
==
NULL
)
return
;
if
(
pObj
==
NULL
)
return
;
SSdbRow
*
pRow
=
(
SSdbRow
*
)((
char
*
)
pObj
-
sizeof
(
SSdbRow
));
SSdbRow
*
pRow
=
(
SSdbRow
*
)((
char
*
)
pObj
-
sizeof
(
SSdbRow
));
if
(
pRow
->
type
>=
SDB_MAX
||
pRow
->
type
<=
SDB_START
)
return
;
if
(
pRow
->
type
>=
SDB_MAX
)
return
;
SRWLatch
*
pLock
=
&
pSdb
->
locks
[
pRow
->
type
];
SRWLatch
*
pLock
=
&
pSdb
->
locks
[
pRow
->
type
];
taosRLockLatch
(
pLock
);
taosRLockLatch
(
pLock
);
...
...
source/libs/wal/inc/walInt.h
浏览文件 @
f904401d
...
@@ -20,6 +20,8 @@
...
@@ -20,6 +20,8 @@
#include "tchecksum.h"
#include "tchecksum.h"
#include "wal.h"
#include "wal.h"
#include "taoserror.h"
#ifdef __cplusplus
#ifdef __cplusplus
extern
"C"
{
extern
"C"
{
#endif
#endif
...
...
source/libs/wal/src/walRead.c
浏览文件 @
f904401d
...
@@ -19,8 +19,10 @@
...
@@ -19,8 +19,10 @@
SWalReadHandle
*
walOpenReadHandle
(
SWal
*
pWal
)
{
SWalReadHandle
*
walOpenReadHandle
(
SWal
*
pWal
)
{
SWalReadHandle
*
pRead
=
malloc
(
sizeof
(
SWalReadHandle
));
SWalReadHandle
*
pRead
=
malloc
(
sizeof
(
SWalReadHandle
));
if
(
pRead
==
NULL
)
{
if
(
pRead
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
return
NULL
;
}
}
pRead
->
pWal
=
pWal
;
pRead
->
pWal
=
pWal
;
pRead
->
readIdxTfd
=
-
1
;
pRead
->
readIdxTfd
=
-
1
;
pRead
->
readLogTfd
=
-
1
;
pRead
->
readLogTfd
=
-
1
;
...
...
source/libs/wal/src/walWrite.c
浏览文件 @
f904401d
...
@@ -148,7 +148,7 @@ int32_t walBeginSnapshot(SWal *pWal, int64_t ver) {
...
@@ -148,7 +148,7 @@ int32_t walBeginSnapshot(SWal *pWal, int64_t ver) {
int32_t
walEndSnapshot
(
SWal
*
pWal
)
{
int32_t
walEndSnapshot
(
SWal
*
pWal
)
{
int64_t
ver
=
pWal
->
vers
.
verInSnapshotting
;
int64_t
ver
=
pWal
->
vers
.
verInSnapshotting
;
if
(
ver
==
-
1
)
return
-
1
;
if
(
ver
==
-
1
)
return
0
;
pWal
->
vers
.
snapshotVer
=
ver
;
pWal
->
vers
.
snapshotVer
=
ver
;
int
ts
=
taosGetTimestampSec
();
int
ts
=
taosGetTimestampSec
();
...
...
source/util/src/terror.c
浏览文件 @
f904401d
...
@@ -170,6 +170,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_SDB_INVALID_STATUS_TYPE, "Invalid status type")
...
@@ -170,6 +170,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_SDB_INVALID_STATUS_TYPE, "Invalid status type")
TAOS_DEFINE_ERROR
(
TSDB_CODE_SDB_INVALID_DATA_VER
,
"Invalid raw data version"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SDB_INVALID_DATA_VER
,
"Invalid raw data version"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SDB_INVALID_DATA_LEN
,
"Invalid raw data len"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SDB_INVALID_DATA_LEN
,
"Invalid raw data len"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SDB_INVALID_DATA_CONTENT
,
"Invalid raw data content"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SDB_INVALID_DATA_CONTENT
,
"Invalid raw data content"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SDB_INVALID_WAl_VER
,
"Invalid wal version"
)
// mnode-dnode
// mnode-dnode
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_DNODE_ALREADY_EXIST
,
"Dnode already exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_DNODE_ALREADY_EXIST
,
"Dnode already exists"
)
...
...
tests/script/general/table/basic1.sim
浏览文件 @
f904401d
...
@@ -46,7 +46,6 @@ print =============== create child table
...
@@ -46,7 +46,6 @@ print =============== create child table
sql create table c1 using st tags(1)
sql create table c1 using st tags(1)
sql create table c2 using st tags(2)
sql create table c2 using st tags(2)
return
sql show tables
sql show tables
if $rows != 2 then
if $rows != 2 then
return -1
return -1
...
@@ -56,6 +55,8 @@ print $data00 $data01 $data02
...
@@ -56,6 +55,8 @@ print $data00 $data01 $data02
print $data10 $data11 $data22
print $data10 $data11 $data22
print $data20 $data11 $data22
print $data20 $data11 $data22
return
print =============== insert data
print =============== insert data
sql insert into c1 values(now+1s, 1)
sql insert into c1 values(now+1s, 1)
sql insert into c1 values(now+2s, 2)
sql insert into c1 values(now+2s, 2)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录