Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ea3aae75
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
ea3aae75
编写于
11月 20, 2020
作者:
S
Shengliang Guan
提交者:
GitHub
11月 20, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4298 from taosdata/feature/wal
Feature/wal
上级
84c1bac5
f323186f
变更
20
隐藏空白更改
内联
并排
Showing
20 changed file
with
1188 addition
and
1185 deletion
+1188
-1185
src/inc/tsync.h
src/inc/tsync.h
+9
-9
src/mnode/inc/mnodeSdb.h
src/mnode/inc/mnodeSdb.h
+45
-42
src/mnode/src/mnodeAcct.c
src/mnode/src/mnodeAcct.c
+35
-36
src/mnode/src/mnodeCluster.c
src/mnode/src/mnodeCluster.c
+30
-30
src/mnode/src/mnodeDb.c
src/mnode/src/mnodeDb.c
+61
-61
src/mnode/src/mnodeDnode.c
src/mnode/src/mnodeDnode.c
+45
-45
src/mnode/src/mnodeMnode.c
src/mnode/src/mnodeMnode.c
+41
-45
src/mnode/src/mnodeSdb.c
src/mnode/src/mnodeSdb.c
+413
-479
src/mnode/src/mnodeTable.c
src/mnode/src/mnodeTable.c
+191
-191
src/mnode/src/mnodeUser.c
src/mnode/src/mnodeUser.c
+52
-52
src/mnode/src/mnodeVgroup.c
src/mnode/src/mnodeVgroup.c
+73
-73
src/plugins/http/inc/httpInt.h
src/plugins/http/inc/httpInt.h
+1
-1
src/plugins/http/src/httpHandle.c
src/plugins/http/src/httpHandle.c
+2
-2
src/sync/inc/syncInt.h
src/sync/inc/syncInt.h
+20
-13
src/sync/src/syncMain.c
src/sync/src/syncMain.c
+132
-77
src/sync/src/syncRestore.c
src/sync/src/syncRestore.c
+13
-4
src/sync/src/syncRetrieve.c
src/sync/src/syncRetrieve.c
+5
-5
src/sync/src/taosTcpPool.c
src/sync/src/taosTcpPool.c
+1
-1
src/wal/src/walWrite.c
src/wal/src/walWrite.c
+2
-2
tests/script/sh/deploy.sh
tests/script/sh/deploy.sh
+17
-17
未找到文件。
src/inc/tsync.h
浏览文件 @
ea3aae75
...
@@ -24,18 +24,18 @@ extern "C" {
...
@@ -24,18 +24,18 @@ extern "C" {
#define TAOS_SYNC_MAX_INDEX 0x7FFFFFFF
#define TAOS_SYNC_MAX_INDEX 0x7FFFFFFF
typedef
enum
_TAOS_SYNC_ROLE
{
typedef
enum
_TAOS_SYNC_ROLE
{
TAOS_SYNC_ROLE_OFFLINE
,
TAOS_SYNC_ROLE_OFFLINE
=
0
,
TAOS_SYNC_ROLE_UNSYNCED
,
TAOS_SYNC_ROLE_UNSYNCED
=
1
,
TAOS_SYNC_ROLE_SYNCING
,
TAOS_SYNC_ROLE_SYNCING
=
2
,
TAOS_SYNC_ROLE_SLAVE
,
TAOS_SYNC_ROLE_SLAVE
=
3
,
TAOS_SYNC_ROLE_MASTER
,
TAOS_SYNC_ROLE_MASTER
=
4
}
ESyncRole
;
}
ESyncRole
;
typedef
enum
_TAOS_SYNC_STATUS
{
typedef
enum
_TAOS_SYNC_STATUS
{
TAOS_SYNC_STATUS_INIT
,
TAOS_SYNC_STATUS_INIT
=
0
,
TAOS_SYNC_STATUS_START
,
TAOS_SYNC_STATUS_START
=
1
,
TAOS_SYNC_STATUS_FILE
,
TAOS_SYNC_STATUS_FILE
=
2
,
TAOS_SYNC_STATUS_CACHE
,
TAOS_SYNC_STATUS_CACHE
=
3
}
ESyncStatus
;
}
ESyncStatus
;
typedef
struct
{
typedef
struct
{
...
...
src/mnode/inc/mnodeSdb.h
浏览文件 @
ea3aae75
...
@@ -20,7 +20,8 @@
...
@@ -20,7 +20,8 @@
extern
"C"
{
extern
"C"
{
#endif
#endif
struct
SMnodeMsg
;
#include "mnode.h"
#include "twal.h"
typedef
enum
{
typedef
enum
{
SDB_TABLE_CLUSTER
=
0
,
SDB_TABLE_CLUSTER
=
0
,
...
@@ -36,44 +37,46 @@ typedef enum {
...
@@ -36,44 +37,46 @@ typedef enum {
}
ESdbTable
;
}
ESdbTable
;
typedef
enum
{
typedef
enum
{
SDB_KEY_STRING
,
SDB_KEY_STRING
=
0
,
SDB_KEY_INT
,
SDB_KEY_INT
=
1
,
SDB_KEY_AUTO
,
SDB_KEY_AUTO
=
2
,
SDB_KEY_VAR_STRING
,
SDB_KEY_VAR_STRING
=
3
,
}
ESdbKey
;
}
ESdbKey
;
typedef
enum
{
typedef
enum
{
SDB_OPER_GLOBAL
,
SDB_OPER_GLOBAL
=
0
,
SDB_OPER_LOCAL
SDB_OPER_LOCAL
=
1
}
ESdbOper
;
}
ESdbOper
;
typedef
struct
SSdbOper
{
typedef
struct
SSdbRow
{
ESdbOper
type
;
ESdbOper
type
;
int32_t
rowSize
;
int32_t
processedCount
;
// for sync fwd callback
int32_t
retCode
;
// for callback in sdb queue
int32_t
code
;
// for callback in sdb queue
int32_t
processedCount
;
// for sync fwd callback
int32_t
rowSize
;
int32_t
(
*
reqFp
)(
struct
SMnodeMsg
*
pMsg
);
void
*
rowData
;
int32_t
(
*
writeCb
)(
struct
SMnodeMsg
*
pMsg
,
int32_t
code
);
void
*
pObj
;
void
*
table
;
void
*
pTable
;
void
*
pObj
;
SMnodeMsg
*
pMsg
;
void
*
rowData
;
int32_t
(
*
fpReq
)(
SMnodeMsg
*
pMsg
);
struct
SMnodeMsg
*
pMsg
;
int32_t
(
*
fpRsp
)(
SMnodeMsg
*
pMsg
,
int32_t
code
);
}
SSdbOper
;
char
reserveForSync
[
16
];
SWalHead
pHead
[];
}
SSdbRow
;
typedef
struct
{
typedef
struct
{
char
*
tableN
ame
;
char
*
n
ame
;
int32_t
hashSessions
;
int32_t
hashSessions
;
int32_t
maxRowSize
;
int32_t
maxRowSize
;
int32_t
refCountPos
;
int32_t
refCountPos
;
ESdbTable
tableI
d
;
ESdbTable
i
d
;
ESdbKey
keyType
;
ESdbKey
keyType
;
int32_t
(
*
insertFp
)(
SSdbOper
*
pOper
);
int32_t
(
*
fpInsert
)(
SSdbRow
*
pRow
);
int32_t
(
*
deleteFp
)(
SSdbOper
*
pOper
);
int32_t
(
*
fpDelete
)(
SSdbRow
*
pRow
);
int32_t
(
*
updateFp
)(
SSdbOper
*
pOper
);
int32_t
(
*
fpUpdate
)(
SSdbRow
*
pRow
);
int32_t
(
*
encodeFp
)(
SSdbOper
*
pOper
);
int32_t
(
*
fpEncode
)(
SSdbRow
*
pRow
);
int32_t
(
*
decodeFp
)(
SSdbOper
*
pDesc
);
int32_t
(
*
fpDecode
)(
SSdbRow
*
pRow
);
int32_t
(
*
destroyFp
)(
SSdbOper
*
pDesc
);
int32_t
(
*
fpDestroy
)(
SSdbRow
*
pRow
);
int32_t
(
*
restoredFp
)();
int32_t
(
*
fpRestored
)();
}
SSdbTableDesc
;
}
SSdbTableDesc
;
int32_t
sdbInit
();
int32_t
sdbInit
();
...
@@ -84,20 +87,20 @@ bool sdbIsMaster();
...
@@ -84,20 +87,20 @@ bool sdbIsMaster();
bool
sdbIsServing
();
bool
sdbIsServing
();
void
sdbUpdateMnodeRoles
();
void
sdbUpdateMnodeRoles
();
int32_t
sdbInsertRow
(
SSdb
Oper
*
pOper
);
int32_t
sdbInsertRow
(
SSdb
Row
*
pRow
);
int32_t
sdbDeleteRow
(
SSdb
Oper
*
pOper
);
int32_t
sdbDeleteRow
(
SSdb
Row
*
pRow
);
int32_t
sdbUpdateRow
(
SSdb
Oper
*
pOper
);
int32_t
sdbUpdateRow
(
SSdb
Row
*
pRow
);
int32_t
sdbInsertRow
Imp
(
SSdbOper
*
pOper
);
int32_t
sdbInsertRow
ToQueue
(
SSdbRow
*
pRow
);
void
*
sdbGetRow
(
void
*
hand
le
,
void
*
key
);
void
*
sdbGetRow
(
void
*
pTab
le
,
void
*
key
);
void
*
sdbFetchRow
(
void
*
hand
le
,
void
*
pIter
,
void
**
ppRow
);
void
*
sdbFetchRow
(
void
*
pTab
le
,
void
*
pIter
,
void
**
ppRow
);
void
sdbFreeIter
(
void
*
pIter
);
void
sdbFreeIter
(
void
*
pIter
);
void
sdbIncRef
(
void
*
thand
le
,
void
*
pRow
);
void
sdbIncRef
(
void
*
pTab
le
,
void
*
pRow
);
void
sdbDecRef
(
void
*
thand
le
,
void
*
pRow
);
void
sdbDecRef
(
void
*
pTab
le
,
void
*
pRow
);
int64_t
sdbGetNumOfRows
(
void
*
hand
le
);
int64_t
sdbGetNumOfRows
(
void
*
pTab
le
);
int32_t
sdbGetId
(
void
*
hand
le
);
int32_t
sdbGetId
(
void
*
pTab
le
);
uint64_t
sdbGetVersion
();
uint64_t
sdbGetVersion
();
bool
sdbCheckRowDeleted
(
void
*
thand
le
,
void
*
pRow
);
bool
sdbCheckRowDeleted
(
void
*
pTab
le
,
void
*
pRow
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
src/mnode/src/mnodeAcct.c
浏览文件 @
ea3aae75
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
#define _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#include "os.h"
#include "os.h"
#include "taoserror.h"
#include "taoserror.h"
#include "tglobal.h"
#include "dnode.h"
#include "dnode.h"
#include "mnodeDef.h"
#include "mnodeDef.h"
#include "mnodeInt.h"
#include "mnodeInt.h"
...
@@ -25,36 +26,34 @@
...
@@ -25,36 +26,34 @@
#include "mnodeUser.h"
#include "mnodeUser.h"
#include "mnodeVgroup.h"
#include "mnodeVgroup.h"
#include "tglobal.h"
void
*
tsAcctSdb
=
NULL
;
void
*
tsAcctSdb
=
NULL
;
static
int32_t
tsAcctUpdateSize
;
static
int32_t
tsAcctUpdateSize
;
static
int32_t
mnodeCreateRootAcct
();
static
int32_t
mnodeCreateRootAcct
();
static
int32_t
mnodeAcctActionDestroy
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeAcctActionDestroy
(
SSdb
Row
*
pRow
)
{
SAcctObj
*
pAcct
=
p
Oper
->
pObj
;
SAcctObj
*
pAcct
=
p
Row
->
pObj
;
pthread_mutex_destroy
(
&
pAcct
->
mutex
);
pthread_mutex_destroy
(
&
pAcct
->
mutex
);
tfree
(
p
Oper
->
pObj
);
tfree
(
p
Row
->
pObj
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeAcctActionInsert
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeAcctActionInsert
(
SSdb
Row
*
pRow
)
{
SAcctObj
*
pAcct
=
p
Oper
->
pObj
;
SAcctObj
*
pAcct
=
p
Row
->
pObj
;
memset
(
&
pAcct
->
acctInfo
,
0
,
sizeof
(
SAcctInfo
));
memset
(
&
pAcct
->
acctInfo
,
0
,
sizeof
(
SAcctInfo
));
pAcct
->
acctInfo
.
accessState
=
TSDB_VN_ALL_ACCCESS
;
pAcct
->
acctInfo
.
accessState
=
TSDB_VN_ALL_ACCCESS
;
pthread_mutex_init
(
&
pAcct
->
mutex
,
NULL
);
pthread_mutex_init
(
&
pAcct
->
mutex
,
NULL
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeAcctActionDelete
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeAcctActionDelete
(
SSdb
Row
*
pRow
)
{
SAcctObj
*
pAcct
=
p
Oper
->
pObj
;
SAcctObj
*
pAcct
=
p
Row
->
pObj
;
mnodeDropAllUsers
(
pAcct
);
mnodeDropAllUsers
(
pAcct
);
mnodeDropAllDbs
(
pAcct
);
mnodeDropAllDbs
(
pAcct
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeAcctActionUpdate
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeAcctActionUpdate
(
SSdb
Row
*
pRow
)
{
SAcctObj
*
pAcct
=
p
Oper
->
pObj
;
SAcctObj
*
pAcct
=
p
Row
->
pObj
;
SAcctObj
*
pSaved
=
mnodeGetAcct
(
pAcct
->
user
);
SAcctObj
*
pSaved
=
mnodeGetAcct
(
pAcct
->
user
);
if
(
pAcct
!=
pSaved
)
{
if
(
pAcct
!=
pSaved
)
{
memcpy
(
pSaved
,
pAcct
,
tsAcctUpdateSize
);
memcpy
(
pSaved
,
pAcct
,
tsAcctUpdateSize
);
...
@@ -64,19 +63,19 @@ static int32_t mnodeAcctActionUpdate(SSdbOper *pOper) {
...
@@ -64,19 +63,19 @@ static int32_t mnodeAcctActionUpdate(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeAcctActionEncode
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeAcctActionEncode
(
SSdb
Row
*
pRow
)
{
SAcctObj
*
pAcct
=
p
Oper
->
pObj
;
SAcctObj
*
pAcct
=
p
Row
->
pObj
;
memcpy
(
p
Oper
->
rowData
,
pAcct
,
tsAcctUpdateSize
);
memcpy
(
p
Row
->
rowData
,
pAcct
,
tsAcctUpdateSize
);
p
Oper
->
rowSize
=
tsAcctUpdateSize
;
p
Row
->
rowSize
=
tsAcctUpdateSize
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeAcctActionDecode
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeAcctActionDecode
(
SSdb
Row
*
pRow
)
{
SAcctObj
*
pAcct
=
(
SAcctObj
*
)
calloc
(
1
,
sizeof
(
SAcctObj
));
SAcctObj
*
pAcct
=
(
SAcctObj
*
)
calloc
(
1
,
sizeof
(
SAcctObj
));
if
(
pAcct
==
NULL
)
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
if
(
pAcct
==
NULL
)
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
memcpy
(
pAcct
,
p
Oper
->
rowData
,
tsAcctUpdateSize
);
memcpy
(
pAcct
,
p
Row
->
rowData
,
tsAcctUpdateSize
);
p
Oper
->
pObj
=
pAcct
;
p
Row
->
pObj
=
pAcct
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -99,29 +98,29 @@ int32_t mnodeInitAccts() {
...
@@ -99,29 +98,29 @@ int32_t mnodeInitAccts() {
SAcctObj
tObj
;
SAcctObj
tObj
;
tsAcctUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
;
tsAcctUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
;
SSdbTableDesc
tableD
esc
=
{
SSdbTableDesc
d
esc
=
{
.
tableId
=
SDB_TABLE_ACCOUNT
,
.
id
=
SDB_TABLE_ACCOUNT
,
.
tableName
=
"accounts"
,
.
name
=
"accounts"
,
.
hashSessions
=
TSDB_DEFAULT_ACCOUNTS_HASH_SIZE
,
.
hashSessions
=
TSDB_DEFAULT_ACCOUNTS_HASH_SIZE
,
.
maxRowSize
=
tsAcctUpdateSize
,
.
maxRowSize
=
tsAcctUpdateSize
,
.
refCountPos
=
(
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
,
.
refCountPos
=
(
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
,
.
keyType
=
SDB_KEY_STRING
,
.
keyType
=
SDB_KEY_STRING
,
.
insertFp
=
mnodeAcctActionInsert
,
.
fpInsert
=
mnodeAcctActionInsert
,
.
deleteFp
=
mnodeAcctActionDelete
,
.
fpDelete
=
mnodeAcctActionDelete
,
.
updateFp
=
mnodeAcctActionUpdate
,
.
fpUpdate
=
mnodeAcctActionUpdate
,
.
encodeFp
=
mnodeAcctActionEncode
,
.
fpEncode
=
mnodeAcctActionEncode
,
.
decodeFp
=
mnodeAcctActionDecode
,
.
fpDecode
=
mnodeAcctActionDecode
,
.
destroyFp
=
mnodeAcctActionDestroy
,
.
fpDestroy
=
mnodeAcctActionDestroy
,
.
restoredFp
=
mnodeAcctActionRestored
.
fpRestored
=
mnodeAcctActionRestored
};
};
tsAcctSdb
=
sdbOpenTable
(
&
tableD
esc
);
tsAcctSdb
=
sdbOpenTable
(
&
d
esc
);
if
(
tsAcctSdb
==
NULL
)
{
if
(
tsAcctSdb
==
NULL
)
{
mError
(
"table:%s, failed to create hash"
,
tableDesc
.
tableN
ame
);
mError
(
"table:%s, failed to create hash"
,
desc
.
n
ame
);
return
-
1
;
return
-
1
;
}
}
mDebug
(
"table:%s, hash is created"
,
tableDesc
.
tableN
ame
);
mDebug
(
"table:%s, hash is created"
,
desc
.
n
ame
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -226,13 +225,13 @@ static int32_t mnodeCreateRootAcct() {
...
@@ -226,13 +225,13 @@ static int32_t mnodeCreateRootAcct() {
pAcct
->
acctId
=
sdbGetId
(
tsAcctSdb
);
pAcct
->
acctId
=
sdbGetId
(
tsAcctSdb
);
pAcct
->
createdTime
=
taosGetTimestampMs
();
pAcct
->
createdTime
=
taosGetTimestampMs
();
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
t
able
=
tsAcctSdb
,
.
pT
able
=
tsAcctSdb
,
.
pObj
=
pAcct
,
.
pObj
=
pAcct
,
};
};
return
sdbInsertRow
(
&
oper
);
return
sdbInsertRow
(
&
row
);
}
}
#ifndef _ACCT
#ifndef _ACCT
...
...
src/mnode/src/mnodeCluster.c
浏览文件 @
ea3aae75
...
@@ -32,36 +32,36 @@ static int32_t mnodeCreateCluster();
...
@@ -32,36 +32,36 @@ static int32_t mnodeCreateCluster();
static
int32_t
mnodeGetClusterMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
mnodeGetClusterMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
mnodeRetrieveClusters
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
mnodeRetrieveClusters
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
mnodeClusterActionDestroy
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeClusterActionDestroy
(
SSdb
Row
*
pRow
)
{
tfree
(
p
Oper
->
pObj
);
tfree
(
p
Row
->
pObj
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeClusterActionInsert
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeClusterActionInsert
(
SSdb
Row
*
pRow
)
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeClusterActionDelete
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeClusterActionDelete
(
SSdb
Row
*
pRow
)
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeClusterActionUpdate
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeClusterActionUpdate
(
SSdb
Row
*
pRow
)
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeClusterActionEncode
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeClusterActionEncode
(
SSdb
Row
*
pRow
)
{
SClusterObj
*
pCluster
=
p
Oper
->
pObj
;
SClusterObj
*
pCluster
=
p
Row
->
pObj
;
memcpy
(
p
Oper
->
rowData
,
pCluster
,
tsClusterUpdateSize
);
memcpy
(
p
Row
->
rowData
,
pCluster
,
tsClusterUpdateSize
);
p
Oper
->
rowSize
=
tsClusterUpdateSize
;
p
Row
->
rowSize
=
tsClusterUpdateSize
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeClusterActionDecode
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeClusterActionDecode
(
SSdb
Row
*
pRow
)
{
SClusterObj
*
pCluster
=
(
SClusterObj
*
)
calloc
(
1
,
sizeof
(
SClusterObj
));
SClusterObj
*
pCluster
=
(
SClusterObj
*
)
calloc
(
1
,
sizeof
(
SClusterObj
));
if
(
pCluster
==
NULL
)
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
if
(
pCluster
==
NULL
)
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
memcpy
(
pCluster
,
p
Oper
->
rowData
,
tsClusterUpdateSize
);
memcpy
(
pCluster
,
p
Row
->
rowData
,
tsClusterUpdateSize
);
p
Oper
->
pObj
=
pCluster
;
p
Row
->
pObj
=
pCluster
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -84,32 +84,32 @@ int32_t mnodeInitCluster() {
...
@@ -84,32 +84,32 @@ int32_t mnodeInitCluster() {
SClusterObj
tObj
;
SClusterObj
tObj
;
tsClusterUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
;
tsClusterUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
;
SSdbTableDesc
tableD
esc
=
{
SSdbTableDesc
d
esc
=
{
.
tableId
=
SDB_TABLE_CLUSTER
,
.
id
=
SDB_TABLE_CLUSTER
,
.
tableName
=
"cluster"
,
.
name
=
"cluster"
,
.
hashSessions
=
TSDB_DEFAULT_CLUSTER_HASH_SIZE
,
.
hashSessions
=
TSDB_DEFAULT_CLUSTER_HASH_SIZE
,
.
maxRowSize
=
tsClusterUpdateSize
,
.
maxRowSize
=
tsClusterUpdateSize
,
.
refCountPos
=
(
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
,
.
refCountPos
=
(
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
,
.
keyType
=
SDB_KEY_STRING
,
.
keyType
=
SDB_KEY_STRING
,
.
insertFp
=
mnodeClusterActionInsert
,
.
fpInsert
=
mnodeClusterActionInsert
,
.
deleteFp
=
mnodeClusterActionDelete
,
.
fpDelete
=
mnodeClusterActionDelete
,
.
updateFp
=
mnodeClusterActionUpdate
,
.
fpUpdate
=
mnodeClusterActionUpdate
,
.
encodeFp
=
mnodeClusterActionEncode
,
.
fpEncode
=
mnodeClusterActionEncode
,
.
decodeFp
=
mnodeClusterActionDecode
,
.
fpDecode
=
mnodeClusterActionDecode
,
.
destroyFp
=
mnodeClusterActionDestroy
,
.
fpDestroy
=
mnodeClusterActionDestroy
,
.
restoredFp
=
mnodeClusterActionRestored
.
fpRestored
=
mnodeClusterActionRestored
};
};
tsClusterSdb
=
sdbOpenTable
(
&
tableD
esc
);
tsClusterSdb
=
sdbOpenTable
(
&
d
esc
);
if
(
tsClusterSdb
==
NULL
)
{
if
(
tsClusterSdb
==
NULL
)
{
mError
(
"table:%s, failed to create hash"
,
tableDesc
.
tableN
ame
);
mError
(
"table:%s, failed to create hash"
,
desc
.
n
ame
);
return
-
1
;
return
-
1
;
}
}
mnodeAddShowMetaHandle
(
TSDB_MGMT_TABLE_CLUSTER
,
mnodeGetClusterMeta
);
mnodeAddShowMetaHandle
(
TSDB_MGMT_TABLE_CLUSTER
,
mnodeGetClusterMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_MGMT_TABLE_CLUSTER
,
mnodeRetrieveClusters
);
mnodeAddShowRetrieveHandle
(
TSDB_MGMT_TABLE_CLUSTER
,
mnodeRetrieveClusters
);
mDebug
(
"table:%s, hash is created"
,
tableDesc
.
tableN
ame
);
mDebug
(
"table:%s, hash is created"
,
desc
.
n
ame
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -145,13 +145,13 @@ static int32_t mnodeCreateCluster() {
...
@@ -145,13 +145,13 @@ static int32_t mnodeCreateCluster() {
mDebug
(
"uid is %s"
,
pCluster
->
uid
);
mDebug
(
"uid is %s"
,
pCluster
->
uid
);
}
}
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
t
able
=
tsClusterSdb
,
.
pT
able
=
tsClusterSdb
,
.
pObj
=
pCluster
,
.
pObj
=
pCluster
,
};
};
return
sdbInsertRow
(
&
oper
);
return
sdbInsertRow
(
&
row
);
}
}
const
char
*
mnodeGetClusterId
()
{
const
char
*
mnodeGetClusterId
()
{
...
...
src/mnode/src/mnodeDb.c
浏览文件 @
ea3aae75
...
@@ -56,8 +56,8 @@ static void mnodeDestroyDb(SDbObj *pDb) {
...
@@ -56,8 +56,8 @@ static void mnodeDestroyDb(SDbObj *pDb) {
tfree
(
pDb
);
tfree
(
pDb
);
}
}
static
int32_t
mnodeDbActionDestroy
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeDbActionDestroy
(
SSdb
Row
*
pRow
)
{
mnodeDestroyDb
(
p
Oper
->
pObj
);
mnodeDestroyDb
(
p
Row
->
pObj
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -65,8 +65,8 @@ int64_t mnodeGetDbNum() {
...
@@ -65,8 +65,8 @@ int64_t mnodeGetDbNum() {
return
sdbGetNumOfRows
(
tsDbSdb
);
return
sdbGetNumOfRows
(
tsDbSdb
);
}
}
static
int32_t
mnodeDbActionInsert
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeDbActionInsert
(
SSdb
Row
*
pRow
)
{
SDbObj
*
pDb
=
p
Oper
->
pObj
;
SDbObj
*
pDb
=
p
Row
->
pObj
;
SAcctObj
*
pAcct
=
mnodeGetAcct
(
pDb
->
acct
);
SAcctObj
*
pAcct
=
mnodeGetAcct
(
pDb
->
acct
);
pthread_mutex_init
(
&
pDb
->
mutex
,
NULL
);
pthread_mutex_init
(
&
pDb
->
mutex
,
NULL
);
...
@@ -91,8 +91,8 @@ static int32_t mnodeDbActionInsert(SSdbOper *pOper) {
...
@@ -91,8 +91,8 @@ static int32_t mnodeDbActionInsert(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeDbActionDelete
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeDbActionDelete
(
SSdb
Row
*
pRow
)
{
SDbObj
*
pDb
=
p
Oper
->
pObj
;
SDbObj
*
pDb
=
p
Row
->
pObj
;
SAcctObj
*
pAcct
=
mnodeGetAcct
(
pDb
->
acct
);
SAcctObj
*
pAcct
=
mnodeGetAcct
(
pDb
->
acct
);
mnodeDropAllChildTables
(
pDb
);
mnodeDropAllChildTables
(
pDb
);
...
@@ -107,11 +107,11 @@ static int32_t mnodeDbActionDelete(SSdbOper *pOper) {
...
@@ -107,11 +107,11 @@ static int32_t mnodeDbActionDelete(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeDbActionUpdate
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeDbActionUpdate
(
SSdb
Row
*
pRow
)
{
SDbObj
*
pNew
=
p
Oper
->
pObj
;
SDbObj
*
pNew
=
p
Row
->
pObj
;
SDbObj
*
pDb
=
mnodeGetDb
(
pNew
->
name
);
SDbObj
*
pDb
=
mnodeGetDb
(
pNew
->
name
);
if
(
pDb
!=
NULL
&&
pNew
!=
pDb
)
{
if
(
pDb
!=
NULL
&&
pNew
!=
pDb
)
{
memcpy
(
pDb
,
pNew
,
p
Oper
->
rowSize
);
memcpy
(
pDb
,
pNew
,
p
Row
->
rowSize
);
free
(
pNew
->
vgList
);
free
(
pNew
->
vgList
);
free
(
pNew
);
free
(
pNew
);
}
}
...
@@ -120,19 +120,19 @@ static int32_t mnodeDbActionUpdate(SSdbOper *pOper) {
...
@@ -120,19 +120,19 @@ static int32_t mnodeDbActionUpdate(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeDbActionEncode
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeDbActionEncode
(
SSdb
Row
*
pRow
)
{
SDbObj
*
pDb
=
p
Oper
->
pObj
;
SDbObj
*
pDb
=
p
Row
->
pObj
;
memcpy
(
p
Oper
->
rowData
,
pDb
,
tsDbUpdateSize
);
memcpy
(
p
Row
->
rowData
,
pDb
,
tsDbUpdateSize
);
p
Oper
->
rowSize
=
tsDbUpdateSize
;
p
Row
->
rowSize
=
tsDbUpdateSize
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeDbActionDecode
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeDbActionDecode
(
SSdb
Row
*
pRow
)
{
SDbObj
*
pDb
=
(
SDbObj
*
)
calloc
(
1
,
sizeof
(
SDbObj
));
SDbObj
*
pDb
=
(
SDbObj
*
)
calloc
(
1
,
sizeof
(
SDbObj
));
if
(
pDb
==
NULL
)
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
if
(
pDb
==
NULL
)
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
memcpy
(
pDb
,
p
Oper
->
rowData
,
tsDbUpdateSize
);
memcpy
(
pDb
,
p
Row
->
rowData
,
tsDbUpdateSize
);
p
Oper
->
pObj
=
pDb
;
p
Row
->
pObj
=
pDb
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -144,23 +144,23 @@ int32_t mnodeInitDbs() {
...
@@ -144,23 +144,23 @@ int32_t mnodeInitDbs() {
SDbObj
tObj
;
SDbObj
tObj
;
tsDbUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
;
tsDbUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
;
SSdbTableDesc
tableD
esc
=
{
SSdbTableDesc
d
esc
=
{
.
tableId
=
SDB_TABLE_DB
,
.
id
=
SDB_TABLE_DB
,
.
tableName
=
"dbs"
,
.
name
=
"dbs"
,
.
hashSessions
=
TSDB_DEFAULT_DBS_HASH_SIZE
,
.
hashSessions
=
TSDB_DEFAULT_DBS_HASH_SIZE
,
.
maxRowSize
=
tsDbUpdateSize
,
.
maxRowSize
=
tsDbUpdateSize
,
.
refCountPos
=
(
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
,
.
refCountPos
=
(
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
,
.
keyType
=
SDB_KEY_STRING
,
.
keyType
=
SDB_KEY_STRING
,
.
insertFp
=
mnodeDbActionInsert
,
.
fpInsert
=
mnodeDbActionInsert
,
.
deleteFp
=
mnodeDbActionDelete
,
.
fpDelete
=
mnodeDbActionDelete
,
.
updateFp
=
mnodeDbActionUpdate
,
.
fpUpdate
=
mnodeDbActionUpdate
,
.
encodeFp
=
mnodeDbActionEncode
,
.
fpEncode
=
mnodeDbActionEncode
,
.
decodeFp
=
mnodeDbActionDecode
,
.
fpDecode
=
mnodeDbActionDecode
,
.
destroyFp
=
mnodeDbActionDestroy
,
.
fpDestroy
=
mnodeDbActionDestroy
,
.
restoredFp
=
mnodeDbActionRestored
.
fpRestored
=
mnodeDbActionRestored
};
};
tsDbSdb
=
sdbOpenTable
(
&
tableD
esc
);
tsDbSdb
=
sdbOpenTable
(
&
d
esc
);
if
(
tsDbSdb
==
NULL
)
{
if
(
tsDbSdb
==
NULL
)
{
mError
(
"failed to init db data"
);
mError
(
"failed to init db data"
);
return
-
1
;
return
-
1
;
...
@@ -412,16 +412,16 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCreateDbMsg *pCreate, SMnodeMsg *
...
@@ -412,16 +412,16 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCreateDbMsg *pCreate, SMnodeMsg *
pMsg
->
pDb
=
pDb
;
pMsg
->
pDb
=
pDb
;
mnodeIncDbRef
(
pDb
);
mnodeIncDbRef
(
pDb
);
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
t
able
=
tsDbSdb
,
.
pT
able
=
tsDbSdb
,
.
pObj
=
pDb
,
.
pObj
=
pDb
,
.
rowSize
=
sizeof
(
SDbObj
),
.
rowSize
=
sizeof
(
SDbObj
),
.
pMsg
=
pMsg
,
.
pMsg
=
pMsg
,
.
writeCb
=
mnodeCreateDbCb
.
fpRsp
=
mnodeCreateDbCb
};
};
code
=
sdbInsertRow
(
&
oper
);
code
=
sdbInsertRow
(
&
row
);
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
mError
(
"db:%s, failed to create, reason:%s"
,
pDb
->
name
,
tstrerror
(
code
));
mError
(
"db:%s, failed to create, reason:%s"
,
pDb
->
name
,
tstrerror
(
code
));
pMsg
->
pDb
=
NULL
;
pMsg
->
pDb
=
NULL
;
...
@@ -440,8 +440,8 @@ bool mnodeCheckIsMonitorDB(char *db, char *monitordb) {
...
@@ -440,8 +440,8 @@ bool mnodeCheckIsMonitorDB(char *db, char *monitordb) {
}
}
#if 0
#if 0
void mnodePrintVgroups(SDbObj *pDb, char *
oper
) {
void mnodePrintVgroups(SDbObj *pDb, char *
row
) {
mInfo("db:%s, vgroup link from head,
oper:%s", pDb->name, oper
);
mInfo("db:%s, vgroup link from head,
row:%s", pDb->name, row
);
SVgObj *pVgroup = pDb->pHead;
SVgObj *pVgroup = pDb->pHead;
while (pVgroup != NULL) {
while (pVgroup != NULL) {
mInfo("vgId:%d", pVgroup->vgId);
mInfo("vgId:%d", pVgroup->vgId);
...
@@ -807,13 +807,13 @@ static int32_t mnodeSetDbDropping(SDbObj *pDb) {
...
@@ -807,13 +807,13 @@ static int32_t mnodeSetDbDropping(SDbObj *pDb) {
if
(
pDb
->
status
)
return
TSDB_CODE_SUCCESS
;
if
(
pDb
->
status
)
return
TSDB_CODE_SUCCESS
;
pDb
->
status
=
true
;
pDb
->
status
=
true
;
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
t
able
=
tsDbSdb
,
.
pT
able
=
tsDbSdb
,
.
pObj
=
pDb
.
pObj
=
pDb
};
};
int32_t
code
=
sdbUpdateRow
(
&
oper
);
int32_t
code
=
sdbUpdateRow
(
&
row
);
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
mError
(
"db:%s, failed to set dropping state, reason:%s"
,
pDb
->
name
,
tstrerror
(
code
));
mError
(
"db:%s, failed to set dropping state, reason:%s"
,
pDb
->
name
,
tstrerror
(
code
));
}
}
...
@@ -1019,15 +1019,15 @@ static int32_t mnodeAlterDb(SDbObj *pDb, SAlterDbMsg *pAlter, void *pMsg) {
...
@@ -1019,15 +1019,15 @@ static int32_t mnodeAlterDb(SDbObj *pDb, SAlterDbMsg *pAlter, void *pMsg) {
if
(
memcmp
(
&
newCfg
,
&
pDb
->
cfg
,
sizeof
(
SDbCfg
))
!=
0
)
{
if
(
memcmp
(
&
newCfg
,
&
pDb
->
cfg
,
sizeof
(
SDbCfg
))
!=
0
)
{
pDb
->
cfg
=
newCfg
;
pDb
->
cfg
=
newCfg
;
pDb
->
cfgVersion
++
;
pDb
->
cfgVersion
++
;
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
table
=
tsDbSdb
,
.
pTable
=
tsDbSdb
,
.
pObj
=
pDb
,
.
pObj
=
pDb
,
.
pMsg
=
pMsg
,
.
pMsg
=
pMsg
,
.
writeCb
=
mnodeAlterDbCb
.
fpRsp
=
mnodeAlterDbCb
};
};
code
=
sdbUpdateRow
(
&
oper
);
code
=
sdbUpdateRow
(
&
row
);
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
mError
(
"db:%s, failed to alter, reason:%s"
,
pDb
->
name
,
tstrerror
(
code
));
mError
(
"db:%s, failed to alter, reason:%s"
,
pDb
->
name
,
tstrerror
(
code
));
}
}
...
@@ -1071,15 +1071,15 @@ static int32_t mnodeDropDb(SMnodeMsg *pMsg) {
...
@@ -1071,15 +1071,15 @@ static int32_t mnodeDropDb(SMnodeMsg *pMsg) {
SDbObj
*
pDb
=
pMsg
->
pDb
;
SDbObj
*
pDb
=
pMsg
->
pDb
;
mInfo
(
"db:%s, drop db from sdb"
,
pDb
->
name
);
mInfo
(
"db:%s, drop db from sdb"
,
pDb
->
name
);
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
t
able
=
tsDbSdb
,
.
pT
able
=
tsDbSdb
,
.
pObj
=
pDb
,
.
pObj
=
pDb
,
.
pMsg
=
pMsg
,
.
pMsg
=
pMsg
,
.
writeCb
=
mnodeDropDbCb
.
fpRsp
=
mnodeDropDbCb
};
};
int32_t
code
=
sdbDeleteRow
(
&
oper
);
int32_t
code
=
sdbDeleteRow
(
&
row
);
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
mError
(
"db:%s, failed to drop, reason:%s"
,
pDb
->
name
,
tstrerror
(
code
));
mError
(
"db:%s, failed to drop, reason:%s"
,
pDb
->
name
,
tstrerror
(
code
));
}
}
...
@@ -1134,13 +1134,13 @@ void mnodeDropAllDbs(SAcctObj *pAcct) {
...
@@ -1134,13 +1134,13 @@ void mnodeDropAllDbs(SAcctObj *pAcct) {
if
(
pDb
->
pAcct
==
pAcct
)
{
if
(
pDb
->
pAcct
==
pAcct
)
{
mInfo
(
"db:%s, drop db from sdb for acct:%s is dropped"
,
pDb
->
name
,
pAcct
->
user
);
mInfo
(
"db:%s, drop db from sdb for acct:%s is dropped"
,
pDb
->
name
,
pAcct
->
user
);
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_LOCAL
,
.
type
=
SDB_OPER_LOCAL
,
.
t
able
=
tsDbSdb
,
.
pT
able
=
tsDbSdb
,
.
pObj
=
pDb
.
pObj
=
pDb
};
};
sdbDeleteRow
(
&
oper
);
sdbDeleteRow
(
&
row
);
numOfDbs
++
;
numOfDbs
++
;
}
}
mnodeDecDbRef
(
pDb
);
mnodeDecDbRef
(
pDb
);
...
...
src/mnode/src/mnodeDnode.c
浏览文件 @
ea3aae75
...
@@ -87,13 +87,13 @@ static char* offlineReason[] = {
...
@@ -87,13 +87,13 @@ static char* offlineReason[] = {
"unknown"
,
"unknown"
,
};
};
static
int32_t
mnodeDnodeActionDestroy
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeDnodeActionDestroy
(
SSdb
Row
*
pRow
)
{
tfree
(
p
Oper
->
pObj
);
tfree
(
p
Row
->
pObj
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeDnodeActionInsert
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeDnodeActionInsert
(
SSdb
Row
*
pRow
)
{
SDnodeObj
*
pDnode
=
p
Oper
->
pObj
;
SDnodeObj
*
pDnode
=
p
Row
->
pObj
;
if
(
pDnode
->
status
!=
TAOS_DN_STATUS_DROPPING
)
{
if
(
pDnode
->
status
!=
TAOS_DN_STATUS_DROPPING
)
{
pDnode
->
status
=
TAOS_DN_STATUS_OFFLINE
;
pDnode
->
status
=
TAOS_DN_STATUS_OFFLINE
;
pDnode
->
lastAccess
=
tsAccessSquence
;
pDnode
->
lastAccess
=
tsAccessSquence
;
...
@@ -107,8 +107,8 @@ static int32_t mnodeDnodeActionInsert(SSdbOper *pOper) {
...
@@ -107,8 +107,8 @@ static int32_t mnodeDnodeActionInsert(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeDnodeActionDelete
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeDnodeActionDelete
(
SSdb
Row
*
pRow
)
{
SDnodeObj
*
pDnode
=
p
Oper
->
pObj
;
SDnodeObj
*
pDnode
=
p
Row
->
pObj
;
#ifndef _SYNC
#ifndef _SYNC
mnodeDropAllDnodeVgroups
(
pDnode
);
mnodeDropAllDnodeVgroups
(
pDnode
);
...
@@ -121,11 +121,11 @@ static int32_t mnodeDnodeActionDelete(SSdbOper *pOper) {
...
@@ -121,11 +121,11 @@ static int32_t mnodeDnodeActionDelete(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeDnodeActionUpdate
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeDnodeActionUpdate
(
SSdb
Row
*
pRow
)
{
SDnodeObj
*
pNew
=
p
Oper
->
pObj
;
SDnodeObj
*
pNew
=
p
Row
->
pObj
;
SDnodeObj
*
pDnode
=
mnodeGetDnode
(
pNew
->
dnodeId
);
SDnodeObj
*
pDnode
=
mnodeGetDnode
(
pNew
->
dnodeId
);
if
(
pDnode
!=
NULL
&&
pNew
!=
pDnode
)
{
if
(
pDnode
!=
NULL
&&
pNew
!=
pDnode
)
{
memcpy
(
pDnode
,
pNew
,
p
Oper
->
rowSize
);
memcpy
(
pDnode
,
pNew
,
p
Row
->
rowSize
);
free
(
pNew
);
free
(
pNew
);
}
}
mnodeDecDnodeRef
(
pDnode
);
mnodeDecDnodeRef
(
pDnode
);
...
@@ -134,19 +134,19 @@ static int32_t mnodeDnodeActionUpdate(SSdbOper *pOper) {
...
@@ -134,19 +134,19 @@ static int32_t mnodeDnodeActionUpdate(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeDnodeActionEncode
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeDnodeActionEncode
(
SSdb
Row
*
pRow
)
{
SDnodeObj
*
pDnode
=
p
Oper
->
pObj
;
SDnodeObj
*
pDnode
=
p
Row
->
pObj
;
memcpy
(
p
Oper
->
rowData
,
pDnode
,
tsDnodeUpdateSize
);
memcpy
(
p
Row
->
rowData
,
pDnode
,
tsDnodeUpdateSize
);
p
Oper
->
rowSize
=
tsDnodeUpdateSize
;
p
Row
->
rowSize
=
tsDnodeUpdateSize
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeDnodeActionDecode
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeDnodeActionDecode
(
SSdb
Row
*
pRow
)
{
SDnodeObj
*
pDnode
=
(
SDnodeObj
*
)
calloc
(
1
,
sizeof
(
SDnodeObj
));
SDnodeObj
*
pDnode
=
(
SDnodeObj
*
)
calloc
(
1
,
sizeof
(
SDnodeObj
));
if
(
pDnode
==
NULL
)
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
if
(
pDnode
==
NULL
)
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
memcpy
(
pDnode
,
p
Oper
->
rowData
,
tsDnodeUpdateSize
);
memcpy
(
pDnode
,
p
Row
->
rowData
,
tsDnodeUpdateSize
);
p
Oper
->
pObj
=
pDnode
;
p
Row
->
pObj
=
pDnode
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -171,23 +171,23 @@ int32_t mnodeInitDnodes() {
...
@@ -171,23 +171,23 @@ int32_t mnodeInitDnodes() {
tsDnodeUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
;
tsDnodeUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
;
pthread_mutex_init
(
&
tsDnodeEpsMutex
,
NULL
);
pthread_mutex_init
(
&
tsDnodeEpsMutex
,
NULL
);
SSdbTableDesc
tableD
esc
=
{
SSdbTableDesc
d
esc
=
{
.
tableId
=
SDB_TABLE_DNODE
,
.
id
=
SDB_TABLE_DNODE
,
.
tableName
=
"dnodes"
,
.
name
=
"dnodes"
,
.
hashSessions
=
TSDB_DEFAULT_DNODES_HASH_SIZE
,
.
hashSessions
=
TSDB_DEFAULT_DNODES_HASH_SIZE
,
.
maxRowSize
=
tsDnodeUpdateSize
,
.
maxRowSize
=
tsDnodeUpdateSize
,
.
refCountPos
=
(
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
,
.
refCountPos
=
(
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
,
.
keyType
=
SDB_KEY_AUTO
,
.
keyType
=
SDB_KEY_AUTO
,
.
insertFp
=
mnodeDnodeActionInsert
,
.
fpInsert
=
mnodeDnodeActionInsert
,
.
deleteFp
=
mnodeDnodeActionDelete
,
.
fpDelete
=
mnodeDnodeActionDelete
,
.
updateFp
=
mnodeDnodeActionUpdate
,
.
fpUpdate
=
mnodeDnodeActionUpdate
,
.
encodeFp
=
mnodeDnodeActionEncode
,
.
fpEncode
=
mnodeDnodeActionEncode
,
.
decodeFp
=
mnodeDnodeActionDecode
,
.
fpDecode
=
mnodeDnodeActionDecode
,
.
destroyFp
=
mnodeDnodeActionDestroy
,
.
fpDestroy
=
mnodeDnodeActionDestroy
,
.
restoredFp
=
mnodeDnodeActionRestored
.
fpRestored
=
mnodeDnodeActionRestored
};
};
tsDnodeSdb
=
sdbOpenTable
(
&
tableD
esc
);
tsDnodeSdb
=
sdbOpenTable
(
&
d
esc
);
if
(
tsDnodeSdb
==
NULL
)
{
if
(
tsDnodeSdb
==
NULL
)
{
mError
(
"failed to init dnodes data"
);
mError
(
"failed to init dnodes data"
);
return
-
1
;
return
-
1
;
...
@@ -296,13 +296,13 @@ void mnodeDecDnodeRef(SDnodeObj *pDnode) {
...
@@ -296,13 +296,13 @@ void mnodeDecDnodeRef(SDnodeObj *pDnode) {
}
}
void
mnodeUpdateDnode
(
SDnodeObj
*
pDnode
)
{
void
mnodeUpdateDnode
(
SDnodeObj
*
pDnode
)
{
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
t
able
=
tsDnodeSdb
,
.
pT
able
=
tsDnodeSdb
,
.
pObj
=
pDnode
.
pObj
=
pDnode
};
};
int32_t
code
=
sdbUpdateRow
(
&
oper
);
int32_t
code
=
sdbUpdateRow
(
&
row
);
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
mError
(
"dnodeId:%d, failed update"
,
pDnode
->
dnodeId
);
mError
(
"dnodeId:%d, failed update"
,
pDnode
->
dnodeId
);
}
}
...
@@ -644,15 +644,15 @@ static int32_t mnodeCreateDnode(char *ep, SMnodeMsg *pMsg) {
...
@@ -644,15 +644,15 @@ static int32_t mnodeCreateDnode(char *ep, SMnodeMsg *pMsg) {
tstrncpy
(
pDnode
->
dnodeEp
,
ep
,
TSDB_EP_LEN
);
tstrncpy
(
pDnode
->
dnodeEp
,
ep
,
TSDB_EP_LEN
);
taosGetFqdnPortFromEp
(
ep
,
pDnode
->
dnodeFqdn
,
&
pDnode
->
dnodePort
);
taosGetFqdnPortFromEp
(
ep
,
pDnode
->
dnodeFqdn
,
&
pDnode
->
dnodePort
);
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
table
=
tsDnodeSdb
,
.
pTable
=
tsDnodeSdb
,
.
pObj
=
pDnode
,
.
pObj
=
pDnode
,
.
rowSize
=
sizeof
(
SDnodeObj
),
.
rowSize
=
sizeof
(
SDnodeObj
),
.
pMsg
=
pMsg
.
pMsg
=
pMsg
};
};
int32_t
code
=
sdbInsertRow
(
&
oper
);
int32_t
code
=
sdbInsertRow
(
&
row
);
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
int
dnodeId
=
pDnode
->
dnodeId
;
int
dnodeId
=
pDnode
->
dnodeId
;
tfree
(
pDnode
);
tfree
(
pDnode
);
...
@@ -665,14 +665,14 @@ static int32_t mnodeCreateDnode(char *ep, SMnodeMsg *pMsg) {
...
@@ -665,14 +665,14 @@ static int32_t mnodeCreateDnode(char *ep, SMnodeMsg *pMsg) {
}
}
int32_t
mnodeDropDnode
(
SDnodeObj
*
pDnode
,
void
*
pMsg
)
{
int32_t
mnodeDropDnode
(
SDnodeObj
*
pDnode
,
void
*
pMsg
)
{
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
t
able
=
tsDnodeSdb
,
.
pT
able
=
tsDnodeSdb
,
.
pObj
=
pDnode
,
.
pObj
=
pDnode
,
.
pMsg
=
pMsg
.
pMsg
=
pMsg
};
};
int32_t
code
=
sdbDeleteRow
(
&
oper
);
int32_t
code
=
sdbDeleteRow
(
&
row
);
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
mError
(
"dnode:%d, failed to drop from cluster, result:%s"
,
pDnode
->
dnodeId
,
tstrerror
(
code
));
mError
(
"dnode:%d, failed to drop from cluster, result:%s"
,
pDnode
->
dnodeId
,
tstrerror
(
code
));
}
else
{
}
else
{
...
@@ -1141,7 +1141,7 @@ static int32_t mnodeRetrieveVnodes(SShowObj *pShow, char *data, int32_t rows, vo
...
@@ -1141,7 +1141,7 @@ static int32_t mnodeRetrieveVnodes(SShowObj *pShow, char *data, int32_t rows, vo
cols
++
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
strcpy
(
pWrite
,
mnodeGetMnodeRoleStr
(
pVgid
->
role
)
);
strcpy
(
pWrite
,
syncRole
[
pVgid
->
role
]
);
cols
++
;
cols
++
;
}
}
}
}
...
...
src/mnode/src/mnodeMnode.c
浏览文件 @
ea3aae75
...
@@ -58,13 +58,13 @@ static int32_t mnodeRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, vo
...
@@ -58,13 +58,13 @@ static int32_t mnodeRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, vo
#define mnodeMnodeDestroyLock() pthread_mutex_destroy(&tsMnodeLock)
#define mnodeMnodeDestroyLock() pthread_mutex_destroy(&tsMnodeLock)
#endif
#endif
static
int32_t
mnodeMnodeActionDestroy
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeMnodeActionDestroy
(
SSdb
Row
*
pRow
)
{
tfree
(
p
Oper
->
pObj
);
tfree
(
p
Row
->
pObj
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeMnodeActionInsert
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeMnodeActionInsert
(
SSdb
Row
*
pRow
)
{
SMnodeObj
*
pMnode
=
p
Oper
->
pObj
;
SMnodeObj
*
pMnode
=
p
Row
->
pObj
;
SDnodeObj
*
pDnode
=
mnodeGetDnode
(
pMnode
->
mnodeId
);
SDnodeObj
*
pDnode
=
mnodeGetDnode
(
pMnode
->
mnodeId
);
if
(
pDnode
==
NULL
)
return
TSDB_CODE_MND_DNODE_NOT_EXIST
;
if
(
pDnode
==
NULL
)
return
TSDB_CODE_MND_DNODE_NOT_EXIST
;
...
@@ -76,8 +76,8 @@ static int32_t mnodeMnodeActionInsert(SSdbOper *pOper) {
...
@@ -76,8 +76,8 @@ static int32_t mnodeMnodeActionInsert(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeMnodeActionDelete
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeMnodeActionDelete
(
SSdb
Row
*
pRow
)
{
SMnodeObj
*
pMnode
=
p
Oper
->
pObj
;
SMnodeObj
*
pMnode
=
p
Row
->
pObj
;
SDnodeObj
*
pDnode
=
mnodeGetDnode
(
pMnode
->
mnodeId
);
SDnodeObj
*
pDnode
=
mnodeGetDnode
(
pMnode
->
mnodeId
);
if
(
pDnode
==
NULL
)
return
TSDB_CODE_MND_DNODE_NOT_EXIST
;
if
(
pDnode
==
NULL
)
return
TSDB_CODE_MND_DNODE_NOT_EXIST
;
...
@@ -88,30 +88,30 @@ static int32_t mnodeMnodeActionDelete(SSdbOper *pOper) {
...
@@ -88,30 +88,30 @@ static int32_t mnodeMnodeActionDelete(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeMnodeActionUpdate
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeMnodeActionUpdate
(
SSdb
Row
*
pRow
)
{
SMnodeObj
*
pMnode
=
p
Oper
->
pObj
;
SMnodeObj
*
pMnode
=
p
Row
->
pObj
;
SMnodeObj
*
pSaved
=
mnodeGetMnode
(
pMnode
->
mnodeId
);
SMnodeObj
*
pSaved
=
mnodeGetMnode
(
pMnode
->
mnodeId
);
if
(
pMnode
!=
pSaved
)
{
if
(
pMnode
!=
pSaved
)
{
memcpy
(
pSaved
,
pMnode
,
p
Oper
->
rowSize
);
memcpy
(
pSaved
,
pMnode
,
p
Row
->
rowSize
);
free
(
pMnode
);
free
(
pMnode
);
}
}
mnodeDecMnodeRef
(
pSaved
);
mnodeDecMnodeRef
(
pSaved
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeMnodeActionEncode
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeMnodeActionEncode
(
SSdb
Row
*
pRow
)
{
SMnodeObj
*
pMnode
=
p
Oper
->
pObj
;
SMnodeObj
*
pMnode
=
p
Row
->
pObj
;
memcpy
(
p
Oper
->
rowData
,
pMnode
,
tsMnodeUpdateSize
);
memcpy
(
p
Row
->
rowData
,
pMnode
,
tsMnodeUpdateSize
);
p
Oper
->
rowSize
=
tsMnodeUpdateSize
;
p
Row
->
rowSize
=
tsMnodeUpdateSize
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeMnodeActionDecode
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeMnodeActionDecode
(
SSdb
Row
*
pRow
)
{
SMnodeObj
*
pMnode
=
calloc
(
1
,
sizeof
(
SMnodeObj
));
SMnodeObj
*
pMnode
=
calloc
(
1
,
sizeof
(
SMnodeObj
));
if
(
pMnode
==
NULL
)
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
if
(
pMnode
==
NULL
)
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
memcpy
(
pMnode
,
p
Oper
->
rowData
,
tsMnodeUpdateSize
);
memcpy
(
pMnode
,
p
Row
->
rowData
,
tsMnodeUpdateSize
);
p
Oper
->
pObj
=
pMnode
;
p
Row
->
pObj
=
pMnode
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -137,23 +137,23 @@ int32_t mnodeInitMnodes() {
...
@@ -137,23 +137,23 @@ int32_t mnodeInitMnodes() {
SMnodeObj
tObj
;
SMnodeObj
tObj
;
tsMnodeUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
;
tsMnodeUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
;
SSdbTableDesc
tableD
esc
=
{
SSdbTableDesc
d
esc
=
{
.
tableId
=
SDB_TABLE_MNODE
,
.
id
=
SDB_TABLE_MNODE
,
.
tableName
=
"mnodes"
,
.
name
=
"mnodes"
,
.
hashSessions
=
TSDB_DEFAULT_MNODES_HASH_SIZE
,
.
hashSessions
=
TSDB_DEFAULT_MNODES_HASH_SIZE
,
.
maxRowSize
=
tsMnodeUpdateSize
,
.
maxRowSize
=
tsMnodeUpdateSize
,
.
refCountPos
=
(
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
,
.
refCountPos
=
(
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
,
.
keyType
=
SDB_KEY_INT
,
.
keyType
=
SDB_KEY_INT
,
.
insertFp
=
mnodeMnodeActionInsert
,
.
fpInsert
=
mnodeMnodeActionInsert
,
.
deleteFp
=
mnodeMnodeActionDelete
,
.
fpDelete
=
mnodeMnodeActionDelete
,
.
updateFp
=
mnodeMnodeActionUpdate
,
.
fpUpdate
=
mnodeMnodeActionUpdate
,
.
encodeFp
=
mnodeMnodeActionEncode
,
.
fpEncode
=
mnodeMnodeActionEncode
,
.
decodeFp
=
mnodeMnodeActionDecode
,
.
fpDecode
=
mnodeMnodeActionDecode
,
.
destroyFp
=
mnodeMnodeActionDestroy
,
.
fpDestroy
=
mnodeMnodeActionDestroy
,
.
restoredFp
=
mnodeMnodeActionRestored
.
fpRestored
=
mnodeMnodeActionRestored
};
};
tsMnodeSdb
=
sdbOpenTable
(
&
tableD
esc
);
tsMnodeSdb
=
sdbOpenTable
(
&
d
esc
);
if
(
tsMnodeSdb
==
NULL
)
{
if
(
tsMnodeSdb
==
NULL
)
{
mError
(
"failed to init mnodes data"
);
mError
(
"failed to init mnodes data"
);
return
-
1
;
return
-
1
;
...
@@ -192,10 +192,6 @@ void *mnodeGetNextMnode(void *pIter, SMnodeObj **pMnode) {
...
@@ -192,10 +192,6 @@ void *mnodeGetNextMnode(void *pIter, SMnodeObj **pMnode) {
return
sdbFetchRow
(
tsMnodeSdb
,
pIter
,
(
void
**
)
pMnode
);
return
sdbFetchRow
(
tsMnodeSdb
,
pIter
,
(
void
**
)
pMnode
);
}
}
char
*
mnodeGetMnodeRoleStr
(
int32_t
role
)
{
return
syncRole
[
role
];
}
void
mnodeUpdateMnodeEpSet
()
{
void
mnodeUpdateMnodeEpSet
()
{
mInfo
(
"update mnodes epSet, numOfEps:%d "
,
mnodeGetMnodesNum
());
mInfo
(
"update mnodes epSet, numOfEps:%d "
,
mnodeGetMnodesNum
());
...
@@ -329,11 +325,11 @@ void mnodeCreateMnode(int32_t dnodeId, char *dnodeEp, bool needConfirm) {
...
@@ -329,11 +325,11 @@ void mnodeCreateMnode(int32_t dnodeId, char *dnodeEp, bool needConfirm) {
pMnode
->
mnodeId
=
dnodeId
;
pMnode
->
mnodeId
=
dnodeId
;
pMnode
->
createdTime
=
taosGetTimestampMs
();
pMnode
->
createdTime
=
taosGetTimestampMs
();
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
table
=
tsMnodeSdb
,
.
pTable
=
tsMnodeSdb
,
.
pObj
=
pMnode
,
.
pObj
=
pMnode
,
.
writeCb
=
mnodeCreateMnodeCb
.
fpRsp
=
mnodeCreateMnodeCb
};
};
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
...
@@ -346,7 +342,7 @@ void mnodeCreateMnode(int32_t dnodeId, char *dnodeEp, bool needConfirm) {
...
@@ -346,7 +342,7 @@ void mnodeCreateMnode(int32_t dnodeId, char *dnodeEp, bool needConfirm) {
return
;
return
;
}
}
code
=
sdbInsertRow
(
&
oper
);
code
=
sdbInsertRow
(
&
row
);
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
mError
(
"dnode:%d, failed to create mnode, ep:%s reason:%s"
,
dnodeId
,
dnodeEp
,
tstrerror
(
code
));
mError
(
"dnode:%d, failed to create mnode, ep:%s reason:%s"
,
dnodeId
,
dnodeEp
,
tstrerror
(
code
));
tfree
(
pMnode
);
tfree
(
pMnode
);
...
@@ -356,8 +352,8 @@ void mnodeCreateMnode(int32_t dnodeId, char *dnodeEp, bool needConfirm) {
...
@@ -356,8 +352,8 @@ void mnodeCreateMnode(int32_t dnodeId, char *dnodeEp, bool needConfirm) {
void
mnodeDropMnodeLocal
(
int32_t
dnodeId
)
{
void
mnodeDropMnodeLocal
(
int32_t
dnodeId
)
{
SMnodeObj
*
pMnode
=
mnodeGetMnode
(
dnodeId
);
SMnodeObj
*
pMnode
=
mnodeGetMnode
(
dnodeId
);
if
(
pMnode
!=
NULL
)
{
if
(
pMnode
!=
NULL
)
{
SSdb
Oper
oper
=
{.
type
=
SDB_OPER_LOCAL
,
.
t
able
=
tsMnodeSdb
,
.
pObj
=
pMnode
};
SSdb
Row
row
=
{.
type
=
SDB_OPER_LOCAL
,
.
pT
able
=
tsMnodeSdb
,
.
pObj
=
pMnode
};
sdbDeleteRow
(
&
oper
);
sdbDeleteRow
(
&
row
);
mnodeDecMnodeRef
(
pMnode
);
mnodeDecMnodeRef
(
pMnode
);
}
}
...
@@ -371,13 +367,13 @@ int32_t mnodeDropMnode(int32_t dnodeId) {
...
@@ -371,13 +367,13 @@ int32_t mnodeDropMnode(int32_t dnodeId) {
return
TSDB_CODE_MND_DNODE_NOT_EXIST
;
return
TSDB_CODE_MND_DNODE_NOT_EXIST
;
}
}
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
t
able
=
tsMnodeSdb
,
.
pT
able
=
tsMnodeSdb
,
.
pObj
=
pMnode
.
pObj
=
pMnode
};
};
int32_t
code
=
sdbDeleteRow
(
&
oper
);
int32_t
code
=
sdbDeleteRow
(
&
row
);
sdbDecRef
(
tsMnodeSdb
,
pMnode
);
sdbDecRef
(
tsMnodeSdb
,
pMnode
);
...
@@ -469,7 +465,7 @@ static int32_t mnodeRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, vo
...
@@ -469,7 +465,7 @@ static int32_t mnodeRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, vo
cols
++
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
char
*
roles
=
mnodeGetMnodeRoleStr
(
pMnode
->
role
)
;
char
*
roles
=
syncRole
[
pMnode
->
role
]
;
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
roles
,
pShow
->
bytes
[
cols
]);
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
roles
,
pShow
->
bytes
[
cols
]);
cols
++
;
cols
++
;
...
...
src/mnode/src/mnodeSdb.c
浏览文件 @
ea3aae75
...
@@ -34,23 +34,30 @@
...
@@ -34,23 +34,30 @@
#include "mnodeSdb.h"
#include "mnodeSdb.h"
#define SDB_TABLE_LEN 12
#define SDB_TABLE_LEN 12
#define
SDB_SYNC_HACK 16
#define
MAX_QUEUED_MSG_NUM 10000
typedef
enum
{
typedef
enum
{
SDB_ACTION_INSERT
,
SDB_ACTION_INSERT
=
0
,
SDB_ACTION_DELETE
,
SDB_ACTION_DELETE
=
1
,
SDB_ACTION_UPDATE
SDB_ACTION_UPDATE
=
2
}
ESdbAction
;
}
ESdbAction
;
typedef
enum
{
typedef
enum
{
SDB_STATUS_OFFLINE
,
SDB_STATUS_OFFLINE
=
0
,
SDB_STATUS_SERVING
,
SDB_STATUS_SERVING
=
1
,
SDB_STATUS_CLOSING
SDB_STATUS_CLOSING
=
2
}
ESdbStatus
;
}
ESdbStatus
;
typedef
struct
_SSdbTable
{
char
*
actStr
[]
=
{
char
tableName
[
SDB_TABLE_LEN
];
"insert"
,
ESdbTable
tableId
;
"delete"
,
"update"
,
"invalid"
};
typedef
struct
SSdbTable
{
char
name
[
SDB_TABLE_LEN
];
ESdbTable
id
;
ESdbKey
keyType
;
ESdbKey
keyType
;
int32_t
hashSessions
;
int32_t
hashSessions
;
int32_t
maxRowSize
;
int32_t
maxRowSize
;
...
@@ -58,13 +65,13 @@ typedef struct _SSdbTable {
...
@@ -58,13 +65,13 @@ typedef struct _SSdbTable {
int32_t
autoIndex
;
int32_t
autoIndex
;
int64_t
numOfRows
;
int64_t
numOfRows
;
void
*
iHandle
;
void
*
iHandle
;
int32_t
(
*
insertFp
)(
SSdbOper
*
pDesc
);
int32_t
(
*
fpInsert
)(
SSdbRow
*
pRow
);
int32_t
(
*
deleteFp
)(
SSdbOper
*
pOper
);
int32_t
(
*
fpDelete
)(
SSdbRow
*
pRow
);
int32_t
(
*
updateFp
)(
SSdbOper
*
pOper
);
int32_t
(
*
fpUpdate
)(
SSdbRow
*
pRow
);
int32_t
(
*
decodeFp
)(
SSdbOper
*
pOper
);
int32_t
(
*
fpDecode
)(
SSdbRow
*
pRow
);
int32_t
(
*
encodeFp
)(
SSdbOper
*
pOper
);
int32_t
(
*
fpEncode
)(
SSdbRow
*
pRow
);
int32_t
(
*
destroyFp
)(
SSdbOper
*
pOper
);
int32_t
(
*
fpDestroy
)(
SSdbRow
*
pRow
);
int32_t
(
*
restoredFp
)();
int32_t
(
*
fpRestored
)();
pthread_mutex_t
mutex
;
pthread_mutex_t
mutex
;
}
SSdbTable
;
}
SSdbTable
;
...
@@ -75,60 +82,60 @@ typedef struct {
...
@@ -75,60 +82,60 @@ typedef struct {
int64_t
sync
;
int64_t
sync
;
void
*
wal
;
void
*
wal
;
SSyncCfg
cfg
;
SSyncCfg
cfg
;
int32_t
queuedMsg
;
int32_t
numOfTables
;
int32_t
numOfTables
;
SSdbTable
*
tableList
[
SDB_TABLE_MAX
];
SSdbTable
*
tableList
[
SDB_TABLE_MAX
];
pthread_mutex_t
mutex
;
pthread_mutex_t
mutex
;
}
SSdb
Objec
t
;
}
SSdb
Mgm
t
;
typedef
struct
{
typedef
struct
{
pthread_t
thread
;
pthread_t
thread
;
int32_t
workerId
;
int32_t
workerId
;
}
SSdbW
riteW
orker
;
}
SSdbWorker
;
typedef
struct
{
typedef
struct
{
int32_t
num
;
int32_t
num
;
SSdbW
riteWorker
*
writeW
orker
;
SSdbW
orker
*
w
orker
;
}
SSdbW
riteW
orkerPool
;
}
SSdbWorkerPool
;
extern
void
*
tsMnodeTmr
;
extern
void
*
tsMnodeTmr
;
static
void
*
tsUpdateSyncTmr
;
static
void
*
tsSdbTmr
;
static
SSdbObject
tsSdbObj
=
{
0
};
static
SSdbMgmt
tsSdbMgmt
=
{
0
};
static
taos_qset
tsSdbWriteQset
;
static
taos_qset
tsSdbWQset
;
static
taos_qall
tsSdbWriteQall
;
static
taos_qall
tsSdbWQall
;
static
taos_queue
tsSdbWriteQueue
;
static
taos_queue
tsSdbWQueue
;
static
SSdbWriteWorkerPool
tsSdbPool
;
static
SSdbWorkerPool
tsSdbPool
;
static
int32_t
sdbWrite
(
void
*
param
,
void
*
data
,
int32_t
type
,
void
*
pMsg
);
static
int32_t
sdbProcessWrite
(
void
*
pRow
,
void
*
pHead
,
int32_t
qtype
,
void
*
unused
);
static
int32_t
sdbWriteToQueue
(
void
*
param
,
void
*
data
,
int32_t
type
,
void
*
pMsg
);
static
int32_t
sdbWriteWalToQueue
(
void
*
vparam
,
void
*
pHead
,
int32_t
qtype
,
void
*
rparam
);
static
void
*
sdbWorkerFp
(
void
*
param
);
static
int32_t
sdbWriteRowToQueue
(
SSdbRow
*
pRow
,
int32_t
action
);
static
int32_t
sdbInitWriteWorker
();
static
void
*
sdbWorkerFp
(
void
*
pWorker
);
static
void
sdbCleanupWriteWorker
();
static
int32_t
sdbInitWorker
();
static
int32_t
sdbAllocWriteQueue
();
static
void
sdbCleanupWorker
();
static
void
sdbFreeWritequeue
();
static
int32_t
sdbAllocQueue
();
static
int32_t
sdbUpdateRowImp
(
SSdbOper
*
pOper
);
static
void
sdbFreeQueue
();
static
int32_t
sdbDeleteRowImp
(
SSdbOper
*
pOper
);
static
int32_t
sdbInsertHash
(
SSdbTable
*
pTable
,
SSdbRow
*
pRow
);
static
int32_t
sdbInsertHash
(
SSdbTable
*
pTable
,
SSdbOper
*
pOper
);
static
int32_t
sdbUpdateHash
(
SSdbTable
*
pTable
,
SSdbRow
*
pRow
);
static
int32_t
sdbUpdateHash
(
SSdbTable
*
pTable
,
SSdbOper
*
pOper
);
static
int32_t
sdbDeleteHash
(
SSdbTable
*
pTable
,
SSdbRow
*
pRow
);
static
int32_t
sdbDeleteHash
(
SSdbTable
*
pTable
,
SSdbOper
*
pOper
);
int32_t
sdbGetId
(
void
*
pTable
)
{
int32_t
sdbGetId
(
void
*
handle
)
{
return
((
SSdbTable
*
)
pTable
)
->
autoIndex
;
return
((
SSdbTable
*
)
handle
)
->
autoIndex
;
}
}
int64_t
sdbGetNumOfRows
(
void
*
hand
le
)
{
int64_t
sdbGetNumOfRows
(
void
*
pTab
le
)
{
return
((
SSdbTable
*
)
hand
le
)
->
numOfRows
;
return
((
SSdbTable
*
)
pTab
le
)
->
numOfRows
;
}
}
uint64_t
sdbGetVersion
()
{
uint64_t
sdbGetVersion
()
{
return
tsSdb
Obj
.
version
;
return
tsSdb
Mgmt
.
version
;
}
}
bool
sdbIsMaster
()
{
bool
sdbIsMaster
()
{
return
tsSdb
Obj
.
role
==
TAOS_SYNC_ROLE_MASTER
;
return
tsSdb
Mgmt
.
role
==
TAOS_SYNC_ROLE_MASTER
;
}
}
bool
sdbIsServing
()
{
bool
sdbIsServing
()
{
return
tsSdb
Obj
.
status
==
SDB_STATUS_SERVING
;
return
tsSdb
Mgmt
.
status
==
SDB_STATUS_SERVING
;
}
}
static
void
*
sdbGetObjKey
(
SSdbTable
*
pTable
,
void
*
key
)
{
static
void
*
sdbGetObjKey
(
SSdbTable
*
pTable
,
void
*
key
)
{
...
@@ -139,18 +146,6 @@ static void *sdbGetObjKey(SSdbTable *pTable, void *key) {
...
@@ -139,18 +146,6 @@ static void *sdbGetObjKey(SSdbTable *pTable, void *key) {
return
key
;
return
key
;
}
}
static
char
*
sdbGetActionStr
(
int32_t
action
)
{
switch
(
action
)
{
case
SDB_ACTION_INSERT
:
return
"insert"
;
case
SDB_ACTION_DELETE
:
return
"delete"
;
case
SDB_ACTION_UPDATE
:
return
"update"
;
}
return
"invalid"
;
}
static
char
*
sdbGetKeyStr
(
SSdbTable
*
pTable
,
void
*
key
)
{
static
char
*
sdbGetKeyStr
(
SSdbTable
*
pTable
,
void
*
key
)
{
static
char
str
[
16
];
static
char
str
[
16
];
switch
(
pTable
->
keyType
)
{
switch
(
pTable
->
keyType
)
{
...
@@ -166,28 +161,28 @@ static char *sdbGetKeyStr(SSdbTable *pTable, void *key) {
...
@@ -166,28 +161,28 @@ static char *sdbGetKeyStr(SSdbTable *pTable, void *key) {
}
}
}
}
static
char
*
sdbGet
KeyStrFromObj
(
SSdbTable
*
pTable
,
void
*
key
)
{
static
char
*
sdbGet
RowStr
(
SSdbTable
*
pTable
,
void
*
key
)
{
return
sdbGetKeyStr
(
pTable
,
sdbGetObjKey
(
pTable
,
key
));
return
sdbGetKeyStr
(
pTable
,
sdbGetObjKey
(
pTable
,
key
));
}
}
static
void
*
sdbGetTableFromId
(
int32_t
tableId
)
{
static
void
*
sdbGetTableFromId
(
int32_t
tableId
)
{
return
tsSdb
Obj
.
tableList
[
tableId
];
return
tsSdb
Mgmt
.
tableList
[
tableId
];
}
}
static
int32_t
sdbInitWal
()
{
static
int32_t
sdbInitWal
()
{
SWalCfg
walCfg
=
{.
vgId
=
1
,
.
walLevel
=
TAOS_WAL_FSYNC
,
.
keep
=
TAOS_WAL_KEEP
,
.
fsyncPeriod
=
0
};
SWalCfg
walCfg
=
{.
vgId
=
1
,
.
walLevel
=
TAOS_WAL_FSYNC
,
.
keep
=
TAOS_WAL_KEEP
,
.
fsyncPeriod
=
0
};
char
temp
[
TSDB_FILENAME_LEN
]
;
char
temp
[
TSDB_FILENAME_LEN
]
=
{
0
}
;
sprintf
(
temp
,
"%s/wal"
,
tsMnodeDir
);
sprintf
(
temp
,
"%s/wal"
,
tsMnodeDir
);
tsSdb
Obj
.
wal
=
walOpen
(
temp
,
&
walCfg
);
tsSdb
Mgmt
.
wal
=
walOpen
(
temp
,
&
walCfg
);
if
(
tsSdb
Obj
.
wal
==
NULL
)
{
if
(
tsSdb
Mgmt
.
wal
==
NULL
)
{
sdbError
(
"
failed to open sdb
wal in %s"
,
tsMnodeDir
);
sdbError
(
"
vgId:1, failed to open
wal in %s"
,
tsMnodeDir
);
return
-
1
;
return
-
1
;
}
}
sdbInfo
(
"
open sdb
wal for restore"
);
sdbInfo
(
"
vgId:1, open
wal for restore"
);
int
code
=
walRestore
(
tsSdbObj
.
wal
,
NULL
,
sdb
Write
);
int
32_t
code
=
walRestore
(
tsSdbMgmt
.
wal
,
NULL
,
sdbProcess
Write
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
sdbError
(
"
failed to open wal for restore, reason:
%s"
,
tstrerror
(
code
));
sdbError
(
"
vgId:1, failed to open wal for restore since
%s"
,
tstrerror
(
code
));
return
-
1
;
return
-
1
;
}
}
return
0
;
return
0
;
...
@@ -199,31 +194,31 @@ static void sdbRestoreTables() {
...
@@ -199,31 +194,31 @@ static void sdbRestoreTables() {
for
(
int32_t
tableId
=
0
;
tableId
<
SDB_TABLE_MAX
;
++
tableId
)
{
for
(
int32_t
tableId
=
0
;
tableId
<
SDB_TABLE_MAX
;
++
tableId
)
{
SSdbTable
*
pTable
=
sdbGetTableFromId
(
tableId
);
SSdbTable
*
pTable
=
sdbGetTableFromId
(
tableId
);
if
(
pTable
==
NULL
)
continue
;
if
(
pTable
==
NULL
)
continue
;
if
(
pTable
->
restoredFp
)
{
if
(
pTable
->
fpRestored
)
{
(
*
pTable
->
restoredFp
)();
(
*
pTable
->
fpRestored
)();
}
}
totalRows
+=
pTable
->
numOfRows
;
totalRows
+=
pTable
->
numOfRows
;
numOfTables
++
;
numOfTables
++
;
sdbDebug
(
"
table:%s, is restored, numOfRows:%"
PRId64
,
pTable
->
tableN
ame
,
pTable
->
numOfRows
);
sdbDebug
(
"
vgId:1, sdb:%s is restored, rows:%"
PRId64
,
pTable
->
n
ame
,
pTable
->
numOfRows
);
}
}
sdbInfo
(
"
sdb is restored, ver:%"
PRId64
" totalRows:%d numOfTables:%d"
,
tsSdbObj
.
version
,
totalRows
,
numOfTables
);
sdbInfo
(
"
vgId:1, sdb is restored, mver:%"
PRIu64
" rows:%d tables:%d"
,
tsSdbMgmt
.
version
,
totalRows
,
numOfTables
);
}
}
void
sdbUpdateMnodeRoles
()
{
void
sdbUpdateMnodeRoles
()
{
if
(
tsSdb
Obj
.
sync
<=
0
)
return
;
if
(
tsSdb
Mgmt
.
sync
<=
0
)
return
;
SNodesRole
roles
=
{
0
};
SNodesRole
roles
=
{
0
};
syncGetNodesRole
(
tsSdb
Obj
.
sync
,
&
roles
);
syncGetNodesRole
(
tsSdb
Mgmt
.
sync
,
&
roles
);
sdbInfo
(
"
update mnodes sync roles, total:%d"
,
tsSdbObj
.
cfg
.
replica
);
sdbInfo
(
"
vgId:1, update mnodes role, replica:%d"
,
tsSdbMgmt
.
cfg
.
replica
);
for
(
int32_t
i
=
0
;
i
<
tsSdb
Obj
.
cfg
.
replica
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
tsSdb
Mgmt
.
cfg
.
replica
;
++
i
)
{
SMnodeObj
*
pMnode
=
mnodeGetMnode
(
roles
.
nodeId
[
i
]);
SMnodeObj
*
pMnode
=
mnodeGetMnode
(
roles
.
nodeId
[
i
]);
if
(
pMnode
!=
NULL
)
{
if
(
pMnode
!=
NULL
)
{
pMnode
->
role
=
roles
.
role
[
i
];
pMnode
->
role
=
roles
.
role
[
i
];
sdbInfo
(
"
mnode:%d, role:%s"
,
pMnode
->
mnodeId
,
mnodeGetMnodeRoleStr
(
pMnode
->
role
)
);
sdbInfo
(
"
vgId:1, mnode:%d, role:%s"
,
pMnode
->
mnodeId
,
syncRole
[
pMnode
->
role
]
);
if
(
pMnode
->
mnodeId
==
dnodeGetDnodeId
())
tsSdb
Obj
.
role
=
pMnode
->
role
;
if
(
pMnode
->
mnodeId
==
dnodeGetDnodeId
())
tsSdb
Mgmt
.
role
=
pMnode
->
role
;
mnodeDecMnodeRef
(
pMnode
);
mnodeDecMnodeRef
(
pMnode
);
}
}
}
}
...
@@ -238,87 +233,73 @@ static uint32_t sdbGetFileInfo(void *ahandle, char *name, uint32_t *index, uint3
...
@@ -238,87 +233,73 @@ static uint32_t sdbGetFileInfo(void *ahandle, char *name, uint32_t *index, uint3
}
}
static
int32_t
sdbGetWalInfo
(
void
*
ahandle
,
char
*
fileName
,
int64_t
*
fileId
)
{
static
int32_t
sdbGetWalInfo
(
void
*
ahandle
,
char
*
fileName
,
int64_t
*
fileId
)
{
return
walGetWalFile
(
tsSdb
Obj
.
wal
,
fileName
,
fileId
);
return
walGetWalFile
(
tsSdb
Mgmt
.
wal
,
fileName
,
fileId
);
}
}
static
void
sdbNotifyRole
(
void
*
ahandle
,
int8_t
role
)
{
static
void
sdbNotifyRole
(
void
*
ahandle
,
int8_t
role
)
{
sdbInfo
(
"
mnode role changed from %s to %s"
,
mnodeGetMnodeRoleStr
(
tsSdbObj
.
role
),
mnodeGetMnodeRoleStr
(
role
)
);
sdbInfo
(
"
vgId:1, mnode role changed from %s to %s"
,
syncRole
[
tsSdbMgmt
.
role
],
syncRole
[
role
]
);
if
(
role
==
TAOS_SYNC_ROLE_MASTER
&&
tsSdb
Obj
.
role
!=
TAOS_SYNC_ROLE_MASTER
)
{
if
(
role
==
TAOS_SYNC_ROLE_MASTER
&&
tsSdb
Mgmt
.
role
!=
TAOS_SYNC_ROLE_MASTER
)
{
balanceReset
();
balanceReset
();
}
}
tsSdb
Obj
.
role
=
role
;
tsSdb
Mgmt
.
role
=
role
;
sdbUpdateMnodeRoles
();
sdbUpdateMnodeRoles
();
}
}
FORCE_INLINE
// failed to forward, need revert insert
static
void
sdbConfirmForward
(
void
*
ahandle
,
void
*
param
,
int32_t
code
)
{
static
void
sdbHandleFailedConfirm
(
SSdbRow
*
pRow
)
{
assert
(
param
);
SWalHead
*
pHead
=
pRow
->
pHead
;
SSdbOper
*
pOper
=
param
;
int32_t
action
=
pHead
->
msgType
%
10
;
SMnodeMsg
*
pMsg
=
pOper
->
pMsg
;
if
(
code
<=
0
)
pOper
->
retCode
=
code
;
int32_t
processedCount
=
atomic_add_fetch_32
(
&
pOper
->
processedCount
,
1
);
if
(
processedCount
<=
1
)
{
if
(
pMsg
!=
NULL
)
{
sdbDebug
(
"app:%p:%p, waiting for confirm this operation, count:%d result:%s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
processedCount
,
tstrerror
(
code
));
}
return
;
}
if
(
pMsg
!=
NULL
)
{
sdbError
(
"vgId:1, row:%p:%s hver:%"
PRIu64
" action:%s, failed to foward since %s"
,
pRow
->
pObj
,
sdbDebug
(
"app:%p:%p, is confirmed and will do callback func, result:%s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
sdbGetKeyStr
(
pRow
->
pTable
,
pHead
->
cont
),
pHead
->
version
,
actStr
[
action
],
tstrerror
(
pRow
->
code
));
tstrerror
(
code
));
}
// failed to forward, need revert insert
// It's better to create a table in two stages, create it first and then set it success
if
(
pOper
->
retCode
!=
TSDB_CODE_SUCCESS
)
{
if
(
action
==
SDB_ACTION_INSERT
)
{
SWalHead
*
pHead
=
(
void
*
)
pOper
+
sizeof
(
SSdbOper
)
+
SDB_SYNC_HACK
;
SSdbRow
row
=
{.
type
=
SDB_OPER_GLOBAL
,
.
pTable
=
pRow
->
pTable
,
.
pObj
=
pRow
->
pObj
};
int32_t
action
=
pHead
->
msgType
%
10
;
sdbDeleteRow
(
&
row
);
sdbError
(
"table:%s record:%p:%s ver:%"
PRIu64
", action:%d failed to foward reason:%s"
,
((
SSdbTable
*
)
pOper
->
table
)
->
tableName
,
pOper
->
pObj
,
sdbGetKeyStr
(
pOper
->
table
,
pHead
->
cont
),
pHead
->
version
,
action
,
tstrerror
(
pOper
->
retCode
));
if
(
action
==
SDB_ACTION_INSERT
)
{
// It's better to create a table in two stages, create it first and then set it success
//sdbDeleteHash(pOper->table, pOper);
SSdbOper
oper
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
table
=
pOper
->
table
,
.
pObj
=
pOper
->
pObj
};
sdbDeleteRow
(
&
oper
);
}
}
}
}
if
(
pOper
->
writeCb
!=
NULL
)
{
FORCE_INLINE
pOper
->
retCode
=
(
*
pOper
->
writeCb
)(
pMsg
,
pOper
->
retCode
);
static
void
sdbConfirmForward
(
void
*
ahandle
,
void
*
wparam
,
int32_t
code
)
{
if
(
wparam
==
NULL
)
return
;
SSdbRow
*
pRow
=
wparam
;
SMnodeMsg
*
pMsg
=
pRow
->
pMsg
;
if
(
code
<=
0
)
pRow
->
code
=
code
;
int32_t
count
=
atomic_add_fetch_32
(
&
pRow
->
processedCount
,
1
);
if
(
count
<=
1
)
{
if
(
pMsg
!=
NULL
)
sdbTrace
(
"vgId:1, msg:%p waiting for confirm, count:%d code:%x"
,
pMsg
,
count
,
code
);
return
;
}
else
{
if
(
pMsg
!=
NULL
)
sdbTrace
(
"vgId:1, msg:%p is confirmed, code:%x"
,
pMsg
,
code
);
}
}
dnodeSendRpcMWriteRsp
(
pMsg
,
pOper
->
retCode
);
// if ahandle, means this func is called by sdb write
if
(
pRow
->
code
!=
TSDB_CODE_SUCCESS
)
sdbHandleFailedConfirm
(
pRow
);
if
(
ahandle
==
NULL
)
{
sdbDecRef
(
pOper
->
table
,
pOper
->
pObj
);
if
(
pRow
->
fpRsp
!=
NULL
)
{
pRow
->
code
=
(
*
pRow
->
fpRsp
)(
pMsg
,
pRow
->
code
);
}
}
taosFreeQitem
(
pOper
);
dnodeSendRpcMWriteRsp
(
pMsg
,
pRow
->
code
);
}
}
static
void
sdbUpdateSyncTmrFp
(
void
*
param
,
void
*
tmrId
)
{
sdbUpdateSync
(
NULL
);
}
static
void
sdbUpdateSyncTmrFp
(
void
*
param
,
void
*
tmrId
)
{
sdbUpdateSync
(
NULL
);
}
void
sdbUpdateAsync
()
{
void
sdbUpdateAsync
()
{
taosTmrReset
(
sdbUpdateSyncTmrFp
,
200
,
NULL
,
tsMnodeTmr
,
&
ts
UpdateSync
Tmr
);
taosTmrReset
(
sdbUpdateSyncTmrFp
,
200
,
NULL
,
tsMnodeTmr
,
&
ts
Sdb
Tmr
);
}
}
void
sdbUpdateSync
(
void
*
pMnodes
)
{
void
sdbUpdateSync
(
void
*
pMnodes
)
{
SMnodeInfos
*
mnodes
=
pMnodes
;
SMnodeInfos
*
mnodes
=
pMnodes
;
if
(
!
mnodeIsRunning
())
{
if
(
!
mnodeIsRunning
())
{
mDebug
(
"mnode not start yet, update sync config later"
);
mDebug
(
"
vgId:1,
mnode not start yet, update sync config later"
);
return
;
return
;
}
}
mDebug
(
"update sync config in sync module, mnodes:%p"
,
pMnodes
);
mDebug
(
"
vgId:1,
update sync config in sync module, mnodes:%p"
,
pMnodes
);
SSyncCfg
syncCfg
=
{
0
};
SSyncCfg
syncCfg
=
{
0
};
int32_t
index
=
0
;
int32_t
index
=
0
;
...
@@ -344,7 +325,7 @@ void sdbUpdateSync(void *pMnodes) {
...
@@ -344,7 +325,7 @@ void sdbUpdateSync(void *pMnodes) {
}
}
sdbFreeIter
(
pIter
);
sdbFreeIter
(
pIter
);
syncCfg
.
replica
=
index
;
syncCfg
.
replica
=
index
;
mDebug
(
"mnodes info not input, use infos in sdb, numOfMnodes:%d"
,
syncCfg
.
replica
);
mDebug
(
"
vgId:1,
mnodes info not input, use infos in sdb, numOfMnodes:%d"
,
syncCfg
.
replica
);
}
else
{
}
else
{
for
(
index
=
0
;
index
<
mnodes
->
mnodeNum
;
++
index
)
{
for
(
index
=
0
;
index
<
mnodes
->
mnodeNum
;
++
index
)
{
SMnodeInfo
*
node
=
&
mnodes
->
mnodeInfos
[
index
];
SMnodeInfo
*
node
=
&
mnodes
->
mnodeInfos
[
index
];
...
@@ -353,7 +334,7 @@ void sdbUpdateSync(void *pMnodes) {
...
@@ -353,7 +334,7 @@ void sdbUpdateSync(void *pMnodes) {
syncCfg
.
nodeInfo
[
index
].
nodePort
+=
TSDB_PORT_SYNC
;
syncCfg
.
nodeInfo
[
index
].
nodePort
+=
TSDB_PORT_SYNC
;
}
}
syncCfg
.
replica
=
index
;
syncCfg
.
replica
=
index
;
mDebug
(
"mnodes info input, numOfMnodes:%d"
,
syncCfg
.
replica
);
mDebug
(
"
vgId:1,
mnodes info input, numOfMnodes:%d"
,
syncCfg
.
replica
);
}
}
syncCfg
.
quorum
=
(
syncCfg
.
replica
==
1
)
?
1
:
2
;
syncCfg
.
quorum
=
(
syncCfg
.
replica
==
1
)
?
1
:
2
;
...
@@ -367,18 +348,19 @@ void sdbUpdateSync(void *pMnodes) {
...
@@ -367,18 +348,19 @@ void sdbUpdateSync(void *pMnodes) {
}
}
if
(
!
hasThisDnode
)
{
if
(
!
hasThisDnode
)
{
sdbDebug
(
"update sync config, this dnode not exist"
);
sdbDebug
(
"
vgId:1,
update sync config, this dnode not exist"
);
return
;
return
;
}
}
if
(
memcmp
(
&
syncCfg
,
&
tsSdb
Obj
.
cfg
,
sizeof
(
SSyncCfg
))
==
0
)
{
if
(
memcmp
(
&
syncCfg
,
&
tsSdb
Mgmt
.
cfg
,
sizeof
(
SSyncCfg
))
==
0
)
{
sdbDebug
(
"update sync config, info not changed"
);
sdbDebug
(
"
vgId:1,
update sync config, info not changed"
);
return
;
return
;
}
}
sdbInfo
(
"work as mnode, replica:%d"
,
syncCfg
.
replica
);
sdbInfo
(
"
vgId:1,
work as mnode, replica:%d"
,
syncCfg
.
replica
);
for
(
int32_t
i
=
0
;
i
<
syncCfg
.
replica
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
syncCfg
.
replica
;
++
i
)
{
sdbInfo
(
"mnode:%d, %s:%d"
,
syncCfg
.
nodeInfo
[
i
].
nodeId
,
syncCfg
.
nodeInfo
[
i
].
nodeFqdn
,
syncCfg
.
nodeInfo
[
i
].
nodePort
);
sdbInfo
(
"vgId:1, mnode:%d, %s:%d"
,
syncCfg
.
nodeInfo
[
i
].
nodeId
,
syncCfg
.
nodeInfo
[
i
].
nodeFqdn
,
syncCfg
.
nodeInfo
[
i
].
nodePort
);
}
}
SSyncInfo
syncInfo
=
{
0
};
SSyncInfo
syncInfo
=
{
0
};
...
@@ -389,23 +371,24 @@ void sdbUpdateSync(void *pMnodes) {
...
@@ -389,23 +371,24 @@ void sdbUpdateSync(void *pMnodes) {
syncInfo
.
ahandle
=
NULL
;
syncInfo
.
ahandle
=
NULL
;
syncInfo
.
getWalInfo
=
sdbGetWalInfo
;
syncInfo
.
getWalInfo
=
sdbGetWalInfo
;
syncInfo
.
getFileInfo
=
sdbGetFileInfo
;
syncInfo
.
getFileInfo
=
sdbGetFileInfo
;
syncInfo
.
writeToCache
=
sdbWriteToQueue
;
syncInfo
.
writeToCache
=
sdbWrite
Wal
ToQueue
;
syncInfo
.
confirmForward
=
sdbConfirmForward
;
syncInfo
.
confirmForward
=
sdbConfirmForward
;
syncInfo
.
notifyRole
=
sdbNotifyRole
;
syncInfo
.
notifyRole
=
sdbNotifyRole
;
tsSdb
Obj
.
cfg
=
syncCfg
;
tsSdb
Mgmt
.
cfg
=
syncCfg
;
if
(
tsSdb
Obj
.
sync
)
{
if
(
tsSdb
Mgmt
.
sync
)
{
syncReconfig
(
tsSdb
Obj
.
sync
,
&
syncCfg
);
syncReconfig
(
tsSdb
Mgmt
.
sync
,
&
syncCfg
);
}
else
{
}
else
{
tsSdb
Obj
.
sync
=
syncStart
(
&
syncInfo
);
tsSdb
Mgmt
.
sync
=
syncStart
(
&
syncInfo
);
}
}
sdbUpdateMnodeRoles
();
sdbUpdateMnodeRoles
();
}
}
int32_t
sdbInit
()
{
int32_t
sdbInit
()
{
pthread_mutex_init
(
&
tsSdb
Obj
.
mutex
,
NULL
);
pthread_mutex_init
(
&
tsSdb
Mgmt
.
mutex
,
NULL
);
if
(
sdbInitW
riteW
orker
()
!=
0
)
{
if
(
sdbInitWorker
()
!=
0
)
{
return
-
1
;
return
-
1
;
}
}
...
@@ -416,56 +399,56 @@ int32_t sdbInit() {
...
@@ -416,56 +399,56 @@ int32_t sdbInit() {
sdbRestoreTables
();
sdbRestoreTables
();
if
(
mnodeGetMnodesNum
()
==
1
)
{
if
(
mnodeGetMnodesNum
()
==
1
)
{
tsSdb
Obj
.
role
=
TAOS_SYNC_ROLE_MASTER
;
tsSdb
Mgmt
.
role
=
TAOS_SYNC_ROLE_MASTER
;
}
}
tsSdb
Obj
.
status
=
SDB_STATUS_SERVING
;
tsSdb
Mgmt
.
status
=
SDB_STATUS_SERVING
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
void
sdbCleanUp
()
{
void
sdbCleanUp
()
{
if
(
tsSdb
Obj
.
status
!=
SDB_STATUS_SERVING
)
return
;
if
(
tsSdb
Mgmt
.
status
!=
SDB_STATUS_SERVING
)
return
;
tsSdb
Obj
.
status
=
SDB_STATUS_CLOSING
;
tsSdb
Mgmt
.
status
=
SDB_STATUS_CLOSING
;
sdbCleanupW
riteW
orker
();
sdbCleanupWorker
();
sdbDebug
(
"
sdb will be closed, ver:%"
PRId64
,
tsSdbObj
.
version
);
sdbDebug
(
"
vgId:1, sdb will be closed, mver:%"
PRIu64
,
tsSdbMgmt
.
version
);
if
(
tsSdb
Obj
.
sync
)
{
if
(
tsSdb
Mgmt
.
sync
)
{
syncStop
(
tsSdb
Obj
.
sync
);
syncStop
(
tsSdb
Mgmt
.
sync
);
tsSdb
Obj
.
sync
=
-
1
;
tsSdb
Mgmt
.
sync
=
-
1
;
}
}
if
(
tsSdb
Obj
.
wal
)
{
if
(
tsSdb
Mgmt
.
wal
)
{
walClose
(
tsSdb
Obj
.
wal
);
walClose
(
tsSdb
Mgmt
.
wal
);
tsSdb
Obj
.
wal
=
NULL
;
tsSdb
Mgmt
.
wal
=
NULL
;
}
}
pthread_mutex_destroy
(
&
tsSdb
Obj
.
mutex
);
pthread_mutex_destroy
(
&
tsSdb
Mgmt
.
mutex
);
}
}
void
sdbIncRef
(
void
*
handle
,
void
*
pObj
)
{
void
sdbIncRef
(
void
*
tparam
,
void
*
pRow
)
{
if
(
p
Obj
==
NULL
||
handle
==
NULL
)
return
;
if
(
p
Row
==
NULL
||
tparam
==
NULL
)
return
;
SSdbTable
*
pTable
=
handle
;
SSdbTable
*
pTable
=
tparam
;
int32_t
*
pRefCount
=
(
int32_t
*
)(
p
Obj
+
pTable
->
refCountPos
);
int32_t
*
pRefCount
=
(
int32_t
*
)(
p
Row
+
pTable
->
refCountPos
);
int32_t
refCount
=
atomic_add_fetch_32
(
pRefCount
,
1
);
int32_t
refCount
=
atomic_add_fetch_32
(
pRefCount
,
1
);
sdbTrace
(
"
add ref to table:%s record:%p:%s:%d"
,
pTable
->
tableName
,
pObj
,
sdbGetKeyStrFromObj
(
pTable
,
pObj
),
refCount
);
sdbTrace
(
"
vgId:1, sdb:%s, inc ref to row:%p:%s:%d"
,
pTable
->
name
,
pRow
,
sdbGetRowStr
(
pTable
,
pRow
),
refCount
);
}
}
void
sdbDecRef
(
void
*
handle
,
void
*
pObj
)
{
void
sdbDecRef
(
void
*
tparam
,
void
*
pRow
)
{
if
(
p
Obj
==
NULL
||
handle
==
NULL
)
return
;
if
(
p
Row
==
NULL
||
tparam
==
NULL
)
return
;
SSdbTable
*
pTable
=
handle
;
SSdbTable
*
pTable
=
tparam
;
int32_t
*
pRefCount
=
(
int32_t
*
)(
p
Obj
+
pTable
->
refCountPos
);
int32_t
*
pRefCount
=
(
int32_t
*
)(
p
Row
+
pTable
->
refCountPos
);
int32_t
refCount
=
atomic_sub_fetch_32
(
pRefCount
,
1
);
int32_t
refCount
=
atomic_sub_fetch_32
(
pRefCount
,
1
);
sdbTrace
(
"
def ref of table:%s record:%p:%s:%d"
,
pTable
->
tableName
,
pObj
,
sdbGetKeyStrFromObj
(
pTable
,
pObj
),
refCount
);
sdbTrace
(
"
vgId:1, sdb:%s, dec ref to row:%p:%s:%d"
,
pTable
->
name
,
pRow
,
sdbGetRowStr
(
pTable
,
pRow
),
refCount
);
int32_t
*
updateEnd
=
p
Obj
+
pTable
->
refCountPos
-
4
;
int32_t
*
updateEnd
=
p
Row
+
pTable
->
refCountPos
-
4
;
if
(
refCount
<=
0
&&
*
updateEnd
)
{
if
(
refCount
<=
0
&&
*
updateEnd
)
{
sdbTrace
(
"
table:%s, record:%p:%s:%d is destroyed"
,
pTable
->
tableName
,
pObj
,
sdbGetKeyStrFromObj
(
pTable
,
pObj
),
refCount
);
sdbTrace
(
"
vgId:1, sdb:%s, row:%p:%s:%d destroyed"
,
pTable
->
name
,
pRow
,
sdbGetRowStr
(
pTable
,
pRow
),
refCount
);
SSdb
Oper
oper
=
{.
pObj
=
pObj
};
SSdb
Row
row
=
{.
pObj
=
pRow
};
(
*
pTable
->
destroyFp
)(
&
oper
);
(
*
pTable
->
fpDestroy
)(
&
row
);
}
}
}
}
...
@@ -487,12 +470,12 @@ static void *sdbGetRowMetaFromObj(SSdbTable *pTable, void *key) {
...
@@ -487,12 +470,12 @@ static void *sdbGetRowMetaFromObj(SSdbTable *pTable, void *key) {
return
sdbGetRowMeta
(
pTable
,
sdbGetObjKey
(
pTable
,
key
));
return
sdbGetRowMeta
(
pTable
,
sdbGetObjKey
(
pTable
,
key
));
}
}
void
*
sdbGetRow
(
void
*
handle
,
void
*
key
)
{
void
*
sdbGetRow
(
void
*
tparam
,
void
*
key
)
{
SSdbTable
*
pTable
=
handle
;
SSdbTable
*
pTable
=
tparam
;
pthread_mutex_lock
(
&
pTable
->
mutex
);
pthread_mutex_lock
(
&
pTable
->
mutex
);
void
*
pRow
=
sdbGetRowMeta
(
hand
le
,
key
);
void
*
pRow
=
sdbGetRowMeta
(
pTab
le
,
key
);
if
(
pRow
)
sdbIncRef
(
hand
le
,
pRow
);
if
(
pRow
)
sdbIncRef
(
pTab
le
,
pRow
);
pthread_mutex_unlock
(
&
pTable
->
mutex
);
pthread_mutex_unlock
(
&
pTable
->
mutex
);
return
pRow
;
return
pRow
;
...
@@ -502,8 +485,8 @@ static void *sdbGetRowFromObj(SSdbTable *pTable, void *key) {
...
@@ -502,8 +485,8 @@ static void *sdbGetRowFromObj(SSdbTable *pTable, void *key) {
return
sdbGetRow
(
pTable
,
sdbGetObjKey
(
pTable
,
key
));
return
sdbGetRow
(
pTable
,
sdbGetObjKey
(
pTable
,
key
));
}
}
static
int32_t
sdbInsertHash
(
SSdbTable
*
pTable
,
SSdb
Oper
*
pOper
)
{
static
int32_t
sdbInsertHash
(
SSdbTable
*
pTable
,
SSdb
Row
*
pRow
)
{
void
*
key
=
sdbGetObjKey
(
pTable
,
p
Oper
->
pObj
);
void
*
key
=
sdbGetObjKey
(
pTable
,
p
Row
->
pObj
);
int32_t
keySize
=
sizeof
(
int32_t
);
int32_t
keySize
=
sizeof
(
int32_t
);
if
(
pTable
->
keyType
==
SDB_KEY_STRING
||
pTable
->
keyType
==
SDB_KEY_VAR_STRING
)
{
if
(
pTable
->
keyType
==
SDB_KEY_STRING
||
pTable
->
keyType
==
SDB_KEY_VAR_STRING
)
{
...
@@ -511,43 +494,43 @@ static int32_t sdbInsertHash(SSdbTable *pTable, SSdbOper *pOper) {
...
@@ -511,43 +494,43 @@ static int32_t sdbInsertHash(SSdbTable *pTable, SSdbOper *pOper) {
}
}
pthread_mutex_lock
(
&
pTable
->
mutex
);
pthread_mutex_lock
(
&
pTable
->
mutex
);
taosHashPut
(
pTable
->
iHandle
,
key
,
keySize
,
&
p
Oper
->
pObj
,
sizeof
(
int64_t
));
taosHashPut
(
pTable
->
iHandle
,
key
,
keySize
,
&
p
Row
->
pObj
,
sizeof
(
int64_t
));
pthread_mutex_unlock
(
&
pTable
->
mutex
);
pthread_mutex_unlock
(
&
pTable
->
mutex
);
sdbIncRef
(
pTable
,
p
Oper
->
pObj
);
sdbIncRef
(
pTable
,
p
Row
->
pObj
);
atomic_add_fetch_32
(
&
pTable
->
numOfRows
,
1
);
atomic_add_fetch_32
(
&
pTable
->
numOfRows
,
1
);
if
(
pTable
->
keyType
==
SDB_KEY_AUTO
)
{
if
(
pTable
->
keyType
==
SDB_KEY_AUTO
)
{
pTable
->
autoIndex
=
MAX
(
pTable
->
autoIndex
,
*
((
uint32_t
*
)
p
Oper
->
pObj
));
pTable
->
autoIndex
=
MAX
(
pTable
->
autoIndex
,
*
((
uint32_t
*
)
p
Row
->
pObj
));
}
else
{
}
else
{
atomic_add_fetch_32
(
&
pTable
->
autoIndex
,
1
);
atomic_add_fetch_32
(
&
pTable
->
autoIndex
,
1
);
}
}
sdbDebug
(
"
table:%s, insert record:%s to hash, rowSize:%d numOfRows:%"
PRId64
", msg:%p"
,
pTable
->
tableN
ame
,
sdbDebug
(
"
vgId:1, sdb:%s, insert key:%s to hash, rowSize:%d rows:%"
PRId64
", msg:%p"
,
pTable
->
n
ame
,
sdbGet
KeyStrFromObj
(
pTable
,
pOper
->
pObj
),
pOper
->
rowSize
,
pTable
->
numOfRows
,
pOper
->
pMsg
);
sdbGet
RowStr
(
pTable
,
pRow
->
pObj
),
pRow
->
rowSize
,
pTable
->
numOfRows
,
pRow
->
pMsg
);
int32_t
code
=
(
*
pTable
->
insertFp
)(
pOper
);
int32_t
code
=
(
*
pTable
->
fpInsert
)(
pRow
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
sdbError
(
"
table:%s, failed to insert record:%s to hash, remove it"
,
pTable
->
tableN
ame
,
sdbError
(
"
vgId:1, sdb:%s, failed to insert key:%s to hash, remove it"
,
pTable
->
n
ame
,
sdbGet
KeyStrFromObj
(
pTable
,
pOper
->
pObj
));
sdbGet
RowStr
(
pTable
,
pRow
->
pObj
));
sdbDeleteHash
(
pTable
,
p
Oper
);
sdbDeleteHash
(
pTable
,
p
Row
);
}
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
sdbDeleteHash
(
SSdbTable
*
pTable
,
SSdb
Oper
*
pOper
)
{
static
int32_t
sdbDeleteHash
(
SSdbTable
*
pTable
,
SSdb
Row
*
pRow
)
{
int32_t
*
updateEnd
=
p
Oper
->
pObj
+
pTable
->
refCountPos
-
4
;
int32_t
*
updateEnd
=
p
Row
->
pObj
+
pTable
->
refCountPos
-
4
;
bool
set
=
atomic_val_compare_exchange_32
(
updateEnd
,
0
,
1
)
==
0
;
bool
set
=
atomic_val_compare_exchange_32
(
updateEnd
,
0
,
1
)
==
0
;
if
(
!
set
)
{
if
(
!
set
)
{
sdbError
(
"
table:%s, failed to delete record:%s from hash, for it already removed"
,
pTable
->
tableN
ame
,
sdbError
(
"
vgId:1, sdb:%s, failed to delete key:%s from hash, for it already removed"
,
pTable
->
n
ame
,
sdbGet
KeyStrFromObj
(
pTable
,
pOper
->
pObj
));
sdbGet
RowStr
(
pTable
,
pRow
->
pObj
));
return
TSDB_CODE_MND_SDB_OBJ_NOT_THERE
;
return
TSDB_CODE_MND_SDB_OBJ_NOT_THERE
;
}
}
(
*
pTable
->
deleteFp
)(
pOper
);
(
*
pTable
->
fpDelete
)(
pRow
);
void
*
key
=
sdbGetObjKey
(
pTable
,
p
Oper
->
pObj
);
void
*
key
=
sdbGetObjKey
(
pTable
,
p
Row
->
pObj
);
int32_t
keySize
=
sizeof
(
int32_t
);
int32_t
keySize
=
sizeof
(
int32_t
);
if
(
pTable
->
keyType
==
SDB_KEY_STRING
||
pTable
->
keyType
==
SDB_KEY_VAR_STRING
)
{
if
(
pTable
->
keyType
==
SDB_KEY_STRING
||
pTable
->
keyType
==
SDB_KEY_VAR_STRING
)
{
keySize
=
strlen
((
char
*
)
key
);
keySize
=
strlen
((
char
*
)
key
);
...
@@ -558,310 +541,221 @@ static int32_t sdbDeleteHash(SSdbTable *pTable, SSdbOper *pOper) {
...
@@ -558,310 +541,221 @@ static int32_t sdbDeleteHash(SSdbTable *pTable, SSdbOper *pOper) {
pthread_mutex_unlock
(
&
pTable
->
mutex
);
pthread_mutex_unlock
(
&
pTable
->
mutex
);
atomic_sub_fetch_32
(
&
pTable
->
numOfRows
,
1
);
atomic_sub_fetch_32
(
&
pTable
->
numOfRows
,
1
);
sdbDebug
(
"table:%s, delete record:%s from hash, numOfRows:%"
PRId64
", msg:%p"
,
pTable
->
tableName
,
sdbGetKeyStrFromObj
(
pTable
,
pOper
->
pObj
),
pTable
->
numOfRows
,
pOper
->
pMsg
);
sdbDecRef
(
pTable
,
pOper
->
pObj
);
sdbDebug
(
"vgId:1, sdb:%s, delete key:%s from hash, numOfRows:%"
PRId64
", msg:%p"
,
pTable
->
name
,
sdbGetRowStr
(
pTable
,
pRow
->
pObj
),
pTable
->
numOfRows
,
pRow
->
pMsg
);
sdbDecRef
(
pTable
,
pRow
->
pObj
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
sdbUpdateHash
(
SSdbTable
*
pTable
,
SSdb
Oper
*
pOper
)
{
static
int32_t
sdbUpdateHash
(
SSdbTable
*
pTable
,
SSdb
Row
*
pRow
)
{
sdbDebug
(
"
table:%s, update record:%s in hash, numOfRows:%"
PRId64
", msg:%p"
,
pTable
->
tableN
ame
,
sdbDebug
(
"
vgId:1, sdb:%s, update key:%s in hash, numOfRows:%"
PRId64
", msg:%p"
,
pTable
->
n
ame
,
sdbGet
KeyStrFromObj
(
pTable
,
pOper
->
pObj
),
pTable
->
numOfRows
,
pOper
->
pMsg
);
sdbGet
RowStr
(
pTable
,
pRow
->
pObj
),
pTable
->
numOfRows
,
pRow
->
pMsg
);
(
*
pTable
->
updateFp
)(
pOper
);
(
*
pTable
->
fpUpdate
)(
pRow
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int
sdb
Write
(
void
*
param
,
void
*
data
,
int32_t
type
,
void
*
pMsg
)
{
static
int
sdb
ProcessWrite
(
void
*
wparam
,
void
*
hparam
,
int32_t
qtype
,
void
*
unused
)
{
SSdb
Oper
*
pOper
=
param
;
SSdb
Row
*
pRow
=
w
param
;
SWalHead
*
pHead
=
data
;
SWalHead
*
pHead
=
hparam
;
int32_t
tableId
=
pHead
->
msgType
/
10
;
int32_t
tableId
=
pHead
->
msgType
/
10
;
int32_t
action
=
pHead
->
msgType
%
10
;
int32_t
action
=
pHead
->
msgType
%
10
;
SSdbTable
*
pTable
=
sdbGetTableFromId
(
tableId
);
SSdbTable
*
pTable
=
sdbGetTableFromId
(
tableId
);
assert
(
pTable
!=
NULL
);
assert
(
pTable
!=
NULL
);
pthread_mutex_lock
(
&
tsSdb
Obj
.
mutex
);
pthread_mutex_lock
(
&
tsSdb
Mgmt
.
mutex
);
if
(
pHead
->
version
==
0
)
{
if
(
pHead
->
version
==
0
)
{
// assign version
// assign version
tsSdb
Obj
.
version
++
;
tsSdb
Mgmt
.
version
++
;
pHead
->
version
=
tsSdb
Obj
.
version
;
pHead
->
version
=
tsSdb
Mgmt
.
version
;
}
else
{
}
else
{
// for data from WAL or forward, version may be smaller
// for data from WAL or forward, version may be smaller
if
(
pHead
->
version
<=
tsSdb
Obj
.
version
)
{
if
(
pHead
->
version
<=
tsSdb
Mgmt
.
version
)
{
pthread_mutex_unlock
(
&
tsSdb
Obj
.
mutex
);
pthread_mutex_unlock
(
&
tsSdb
Mgmt
.
mutex
);
sdbDebug
(
"
table:%s, failed to restore %s record:%s from source(%d), ver:%"
PRId64
" too large, sdb ver:%"
PRId
64
,
sdbDebug
(
"
vgId:1, sdb:%s, failed to restore %s key:%s from source(%d), hver:%"
PRIu64
" too large, mver:%"
PRIu
64
,
pTable
->
tableName
,
sdbGetActionStr
(
action
),
sdbGetKeyStr
(
pTable
,
pHead
->
cont
),
type
,
pHead
->
version
,
tsSdbObj
.
version
);
pTable
->
name
,
actStr
[
action
],
sdbGetKeyStr
(
pTable
,
pHead
->
cont
),
qtype
,
pHead
->
version
,
tsSdbMgmt
.
version
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
else
if
(
pHead
->
version
!=
tsSdb
Obj
.
version
+
1
)
{
}
else
if
(
pHead
->
version
!=
tsSdb
Mgmt
.
version
+
1
)
{
pthread_mutex_unlock
(
&
tsSdb
Obj
.
mutex
);
pthread_mutex_unlock
(
&
tsSdb
Mgmt
.
mutex
);
sdbError
(
"
table:%s, failed to restore %s record:%s from source(%d), ver:%"
PRId64
" too large, sdb ver:%"
PRId
64
,
sdbError
(
"
vgId:1, sdb:%s, failed to restore %s key:%s from source(%d), hver:%"
PRIu64
" too large, mver:%"
PRIu
64
,
pTable
->
tableName
,
sdbGetActionStr
(
action
),
sdbGetKeyStr
(
pTable
,
pHead
->
cont
),
type
,
pHead
->
version
,
tsSdbObj
.
version
);
pTable
->
name
,
actStr
[
action
],
sdbGetKeyStr
(
pTable
,
pHead
->
cont
),
qtype
,
pHead
->
version
,
tsSdbMgmt
.
version
);
return
TSDB_CODE_SYN_INVALID_VERSION
;
return
TSDB_CODE_SYN_INVALID_VERSION
;
}
else
{
}
else
{
tsSdb
Obj
.
version
=
pHead
->
version
;
tsSdb
Mgmt
.
version
=
pHead
->
version
;
}
}
}
}
int32_t
code
=
walWrite
(
tsSdb
Obj
.
wal
,
pHead
);
int32_t
code
=
walWrite
(
tsSdb
Mgmt
.
wal
,
pHead
);
if
(
code
<
0
)
{
if
(
code
<
0
)
{
pthread_mutex_unlock
(
&
tsSdb
Obj
.
mutex
);
pthread_mutex_unlock
(
&
tsSdb
Mgmt
.
mutex
);
return
code
;
return
code
;
}
}
pthread_mutex_unlock
(
&
tsSdb
Obj
.
mutex
);
pthread_mutex_unlock
(
&
tsSdb
Mgmt
.
mutex
);
// from app,
oper
is created
// from app,
row
is created
if
(
p
Oper
!=
NULL
)
{
if
(
p
Row
!=
NULL
)
{
// forward to peers
// forward to peers
p
Oper
->
processedCount
=
0
;
p
Row
->
processedCount
=
0
;
int32_t
syncCode
=
syncForwardToPeer
(
tsSdb
Obj
.
sync
,
pHead
,
pOper
,
TAOS_QTYPE_RPC
);
int32_t
syncCode
=
syncForwardToPeer
(
tsSdb
Mgmt
.
sync
,
pHead
,
pRow
,
TAOS_QTYPE_RPC
);
if
(
syncCode
<=
0
)
p
Oper
->
processedCount
=
1
;
if
(
syncCode
<=
0
)
p
Row
->
processedCount
=
1
;
if
(
syncCode
<
0
)
{
if
(
syncCode
<
0
)
{
sdbError
(
"
table:%s, failed to forward request, result:%s action:%s record:%s ver:%"
PRId64
", msg:%p"
,
pTable
->
tableN
ame
,
sdbError
(
"
vgId:1, sdb:%s, failed to forward req since %s action:%s key:%s hver:%"
PRIu64
", msg:%p"
,
pTable
->
n
ame
,
tstrerror
(
syncCode
),
sdbGetActionStr
(
action
),
sdbGetKeyStr
(
pTable
,
pHead
->
cont
),
pHead
->
version
,
pOper
->
pMsg
);
tstrerror
(
syncCode
),
actStr
[
action
],
sdbGetKeyStr
(
pTable
,
pHead
->
cont
),
pHead
->
version
,
pRow
->
pMsg
);
}
else
if
(
syncCode
>
0
)
{
}
else
if
(
syncCode
>
0
)
{
sdbDebug
(
"
table:%s, forward request is sent, action:%s record:%s ver:%"
PRId64
", msg:%p"
,
pTable
->
tableN
ame
,
sdbDebug
(
"
vgId:1, sdb:%s, forward req is sent, action:%s key:%s hver:%"
PRIu64
", msg:%p"
,
pTable
->
n
ame
,
sdbGetActionStr
(
action
),
sdbGetKeyStr
(
pTable
,
pHead
->
cont
),
pHead
->
version
,
pOper
->
pMsg
);
actStr
[
action
],
sdbGetKeyStr
(
pTable
,
pHead
->
cont
),
pHead
->
version
,
pRow
->
pMsg
);
}
else
{
}
else
{
sdbTrace
(
"
table:%s, no need to send fwd request, action:%s record:%s ver:%"
PRId64
", msg:%p"
,
pTable
->
tableN
ame
,
sdbTrace
(
"
vgId:1, sdb:%s, no need to send fwd req, action:%s key:%s hver:%"
PRIu64
", msg:%p"
,
pTable
->
n
ame
,
sdbGetActionStr
(
action
),
sdbGetKeyStr
(
pTable
,
pHead
->
cont
),
pHead
->
version
,
pOper
->
pMsg
);
actStr
[
action
],
sdbGetKeyStr
(
pTable
,
pHead
->
cont
),
pHead
->
version
,
pRow
->
pMsg
);
}
}
return
syncCode
;
return
syncCode
;
}
}
sdbDebug
(
"
table:%s, record from wal/fwd is disposed, action:%s record:%s ver:%"
PRId64
,
pTable
->
tableN
ame
,
sdbDebug
(
"
vgId:1, sdb:%s, record from wal/fwd is disposed, action:%s key:%s hver:%"
PRIu64
,
pTable
->
n
ame
,
sdbGetActionStr
(
action
)
,
sdbGetKeyStr
(
pTable
,
pHead
->
cont
),
pHead
->
version
);
actStr
[
action
]
,
sdbGetKeyStr
(
pTable
,
pHead
->
cont
),
pHead
->
version
);
// even it is WAL/FWD, it shall be called to update version in sync
// even it is WAL/FWD, it shall be called to update version in sync
syncForwardToPeer
(
tsSdb
Obj
.
sync
,
pHead
,
pOper
,
TAOS_QTYPE_RPC
);
syncForwardToPeer
(
tsSdb
Mgmt
.
sync
,
pHead
,
pRow
,
TAOS_QTYPE_RPC
);
// from wal or forward msg,
oper
not created, should add into hash
// from wal or forward msg,
row
not created, should add into hash
if
(
action
==
SDB_ACTION_INSERT
)
{
if
(
action
==
SDB_ACTION_INSERT
)
{
SSdb
Oper
oper
=
{.
rowSize
=
pHead
->
len
,
.
rowData
=
pHead
->
cont
,
.
t
able
=
pTable
};
SSdb
Row
row
=
{.
rowSize
=
pHead
->
len
,
.
rowData
=
pHead
->
cont
,
.
pT
able
=
pTable
};
code
=
(
*
pTable
->
decodeFp
)(
&
oper
);
code
=
(
*
pTable
->
fpDecode
)(
&
row
);
return
sdbInsertHash
(
pTable
,
&
oper
);
return
sdbInsertHash
(
pTable
,
&
row
);
}
else
if
(
action
==
SDB_ACTION_DELETE
)
{
}
else
if
(
action
==
SDB_ACTION_DELETE
)
{
void
*
p
Row
=
sdbGetRowMeta
(
pTable
,
pHead
->
cont
);
void
*
p
Obj
=
sdbGetRowMeta
(
pTable
,
pHead
->
cont
);
if
(
p
Row
==
NULL
)
{
if
(
p
Obj
==
NULL
)
{
sdbDebug
(
"
table:%s, object:%s not exist in hash, ignore delete action"
,
pTable
->
tableN
ame
,
sdbDebug
(
"
vgId:1, sdb:%s, object:%s not exist in hash, ignore delete action"
,
pTable
->
n
ame
,
sdbGetKeyStr
(
pTable
,
pHead
->
cont
));
sdbGetKeyStr
(
pTable
,
pHead
->
cont
));
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
SSdb
Oper
oper
=
{.
table
=
pTable
,
.
pObj
=
pRow
};
SSdb
Row
row
=
{.
pTable
=
pTable
,
.
pObj
=
pObj
};
return
sdbDeleteHash
(
pTable
,
&
oper
);
return
sdbDeleteHash
(
pTable
,
&
row
);
}
else
if
(
action
==
SDB_ACTION_UPDATE
)
{
}
else
if
(
action
==
SDB_ACTION_UPDATE
)
{
void
*
p
Row
=
sdbGetRowMeta
(
pTable
,
pHead
->
cont
);
void
*
p
Obj
=
sdbGetRowMeta
(
pTable
,
pHead
->
cont
);
if
(
p
Row
==
NULL
)
{
if
(
p
Obj
==
NULL
)
{
sdbDebug
(
"
table:%s, object:%s not exist in hash, ignore update action"
,
pTable
->
tableN
ame
,
sdbDebug
(
"
vgId:1, sdb:%s, object:%s not exist in hash, ignore update action"
,
pTable
->
n
ame
,
sdbGetKeyStr
(
pTable
,
pHead
->
cont
));
sdbGetKeyStr
(
pTable
,
pHead
->
cont
));
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
SSdb
Oper
oper
=
{.
rowSize
=
pHead
->
len
,
.
rowData
=
pHead
->
cont
,
.
t
able
=
pTable
};
SSdb
Row
row
=
{.
rowSize
=
pHead
->
len
,
.
rowData
=
pHead
->
cont
,
.
pT
able
=
pTable
};
code
=
(
*
pTable
->
decodeFp
)(
&
oper
);
code
=
(
*
pTable
->
fpDecode
)(
&
row
);
return
sdbUpdateHash
(
pTable
,
&
oper
);
return
sdbUpdateHash
(
pTable
,
&
row
);
}
else
{
}
else
{
return
TSDB_CODE_MND_INVALID_MSG_TYPE
;
return
TSDB_CODE_MND_INVALID_MSG_TYPE
;
}
}
}
}
int32_t
sdbInsertRow
(
SSdb
Oper
*
pOper
)
{
int32_t
sdbInsertRow
(
SSdb
Row
*
pRow
)
{
SSdbTable
*
pTable
=
(
SSdbTable
*
)
pOper
->
t
able
;
SSdbTable
*
pTable
=
pRow
->
pT
able
;
if
(
pTable
==
NULL
)
return
TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE
;
if
(
pTable
==
NULL
)
return
TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE
;
if
(
sdbGetRowFromObj
(
pTable
,
pOper
->
pObj
))
{
if
(
sdbGetRowFromObj
(
pTable
,
pRow
->
pObj
))
{
sdbError
(
"table:%s, failed to insert record:%s, already exist"
,
pTable
->
tableName
,
sdbError
(
"vgId:1, sdb:%s, failed to insert:%s since it exist"
,
pTable
->
name
,
sdbGetRowStr
(
pTable
,
pRow
->
pObj
));
sdbGetKeyStrFromObj
(
pTable
,
pOper
->
pObj
));
sdbDecRef
(
pTable
,
pRow
->
pObj
);
sdbDecRef
(
pTable
,
pOper
->
pObj
);
return
TSDB_CODE_MND_SDB_OBJ_ALREADY_THERE
;
return
TSDB_CODE_MND_SDB_OBJ_ALREADY_THERE
;
}
}
if
(
pTable
->
keyType
==
SDB_KEY_AUTO
)
{
if
(
pTable
->
keyType
==
SDB_KEY_AUTO
)
{
*
((
uint32_t
*
)
p
Oper
->
pObj
)
=
atomic_add_fetch_32
(
&
pTable
->
autoIndex
,
1
);
*
((
uint32_t
*
)
p
Row
->
pObj
)
=
atomic_add_fetch_32
(
&
pTable
->
autoIndex
,
1
);
// let vgId increase from 2
// let vgId increase from 2
if
(
pTable
->
autoIndex
==
1
&&
strcmp
(
pTable
->
tableName
,
"vgroups"
)
==
0
)
{
if
(
pTable
->
autoIndex
==
1
&&
pTable
->
id
==
SDB_TABLE_VGROUP
)
{
*
((
uint32_t
*
)
p
Oper
->
pObj
)
=
atomic_add_fetch_32
(
&
pTable
->
autoIndex
,
1
);
*
((
uint32_t
*
)
p
Row
->
pObj
)
=
atomic_add_fetch_32
(
&
pTable
->
autoIndex
,
1
);
}
}
}
}
int32_t
code
=
sdbInsertHash
(
pTable
,
p
Oper
);
int32_t
code
=
sdbInsertHash
(
pTable
,
p
Row
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
sdbError
(
"
table:%s, failed to insert into hash"
,
pTable
->
tableName
);
sdbError
(
"
vgId:1, sdb:%s, failed to insert:%s into hash"
,
pTable
->
name
,
sdbGetRowStr
(
pTable
,
pRow
->
pObj
)
);
return
code
;
return
code
;
}
}
// just insert data into memory
// just insert data into memory
if
(
p
Oper
->
type
!=
SDB_OPER_GLOBAL
)
{
if
(
p
Row
->
type
!=
SDB_OPER_GLOBAL
)
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
if
(
p
Oper
->
reqFp
)
{
if
(
p
Row
->
fpReq
)
{
return
(
*
p
Oper
->
reqFp
)(
pOper
->
pMsg
);
return
(
*
p
Row
->
fpReq
)(
pRow
->
pMsg
);
}
else
{
}
else
{
return
sdb
InsertRowImp
(
pOper
);
return
sdb
WriteRowToQueue
(
pRow
,
SDB_ACTION_INSERT
);
}
}
}
}
int32_t
sdbInsertRowImp
(
SSdbOper
*
pOper
)
{
bool
sdbCheckRowDeleted
(
void
*
tparam
,
void
*
pRow
)
{
SSdbTable
*
pTable
=
(
SSdbTable
*
)
pOper
->
table
;
SSdbTable
*
pTable
=
tparam
;
if
(
pTable
==
NULL
)
return
TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE
;
int32_t
size
=
sizeof
(
SSdbOper
)
+
sizeof
(
SWalHead
)
+
pTable
->
maxRowSize
+
SDB_SYNC_HACK
;
SSdbOper
*
pNewOper
=
taosAllocateQitem
(
size
);
SWalHead
*
pHead
=
(
void
*
)
pNewOper
+
sizeof
(
SSdbOper
)
+
SDB_SYNC_HACK
;
pHead
->
version
=
0
;
pHead
->
len
=
pOper
->
rowSize
;
pHead
->
msgType
=
pTable
->
tableId
*
10
+
SDB_ACTION_INSERT
;
pOper
->
rowData
=
pHead
->
cont
;
(
*
pTable
->
encodeFp
)(
pOper
);
pHead
->
len
=
pOper
->
rowSize
;
memcpy
(
pNewOper
,
pOper
,
sizeof
(
SSdbOper
));
if
(
pNewOper
->
pMsg
!=
NULL
)
{
sdbDebug
(
"app:%p:%p, table:%s record:%p:%s, insert action is add to sdb queue"
,
pNewOper
->
pMsg
->
rpcMsg
.
ahandle
,
pNewOper
->
pMsg
,
pTable
->
tableName
,
pOper
->
pObj
,
sdbGetKeyStrFromObj
(
pTable
,
pOper
->
pObj
));
}
sdbIncRef
(
pNewOper
->
table
,
pNewOper
->
pObj
);
taosWriteQitem
(
tsSdbWriteQueue
,
TAOS_QTYPE_RPC
,
pNewOper
);
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
bool
sdbCheckRowDeleted
(
void
*
pTableInput
,
void
*
pRow
)
{
SSdbTable
*
pTable
=
pTableInput
;
if
(
pTable
==
NULL
)
return
false
;
if
(
pTable
==
NULL
)
return
false
;
int32_t
*
updateEnd
=
pRow
+
pTable
->
refCountPos
-
4
;
int32_t
*
updateEnd
=
pRow
+
pTable
->
refCountPos
-
4
;
return
atomic_val_compare_exchange_32
(
updateEnd
,
1
,
1
)
==
1
;
return
atomic_val_compare_exchange_32
(
updateEnd
,
1
,
1
)
==
1
;
}
}
int32_t
sdbDeleteRow
(
SSdb
Oper
*
pOper
)
{
int32_t
sdbDeleteRow
(
SSdb
Row
*
pRow
)
{
SSdbTable
*
pTable
=
(
SSdbTable
*
)
pOper
->
t
able
;
SSdbTable
*
pTable
=
pRow
->
pT
able
;
if
(
pTable
==
NULL
)
return
TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE
;
if
(
pTable
==
NULL
)
return
TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE
;
void
*
p
Row
=
sdbGetRowMetaFromObj
(
pTable
,
pOper
->
pObj
);
void
*
p
Obj
=
sdbGetRowMetaFromObj
(
pTable
,
pRow
->
pObj
);
if
(
p
Row
==
NULL
)
{
if
(
p
Obj
==
NULL
)
{
sdbDebug
(
"
table:%s, record is not there, delete failed"
,
pTable
->
tableN
ame
);
sdbDebug
(
"
vgId:1, sdb:%s, record is not there, delete failed"
,
pTable
->
n
ame
);
return
TSDB_CODE_MND_SDB_OBJ_NOT_THERE
;
return
TSDB_CODE_MND_SDB_OBJ_NOT_THERE
;
}
}
sdbIncRef
(
pTable
,
pOper
->
pObj
);
int32_t
code
=
sdbDeleteHash
(
pTable
,
pRow
);
int32_t
code
=
sdbDeleteHash
(
pTable
,
pOper
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
sdbError
(
"table:%s, failed to delete from hash"
,
pTable
->
tableName
);
sdbError
(
"vgId:1, sdb:%s, failed to delete from hash"
,
pTable
->
name
);
sdbDecRef
(
pTable
,
pOper
->
pObj
);
return
code
;
return
code
;
}
}
// just delete data from memory
// just delete data from memory
if
(
pOper
->
type
!=
SDB_OPER_GLOBAL
)
{
if
(
pRow
->
type
!=
SDB_OPER_GLOBAL
)
{
sdbDecRef
(
pTable
,
pOper
->
pObj
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
if
(
p
Oper
->
reqFp
)
{
if
(
p
Row
->
fpReq
)
{
return
(
*
p
Oper
->
reqFp
)(
pOper
->
pMsg
);
return
(
*
p
Row
->
fpReq
)(
pRow
->
pMsg
);
}
else
{
}
else
{
return
sdb
DeleteRowImp
(
pOper
);
return
sdb
WriteRowToQueue
(
pRow
,
SDB_ACTION_DELETE
);
}
}
}
}
int32_t
sdb
DeleteRowImp
(
SSdbOper
*
pOper
)
{
int32_t
sdb
UpdateRow
(
SSdbRow
*
pRow
)
{
SSdbTable
*
pTable
=
(
SSdbTable
*
)
pOper
->
t
able
;
SSdbTable
*
pTable
=
pRow
->
pT
able
;
if
(
pTable
==
NULL
)
return
TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE
;
if
(
pTable
==
NULL
)
return
TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE
;
int32_t
size
=
sizeof
(
SSdbOper
)
+
sizeof
(
SWalHead
)
+
pTable
->
maxRowSize
+
SDB_SYNC_HACK
;
void
*
pObj
=
sdbGetRowMetaFromObj
(
pTable
,
pRow
->
pObj
);
SSdbOper
*
pNewOper
=
taosAllocateQitem
(
size
);
if
(
pObj
==
NULL
)
{
sdbDebug
(
"vgId:1, sdb:%s, record is not there, update failed"
,
pTable
->
name
);
SWalHead
*
pHead
=
(
void
*
)
pNewOper
+
sizeof
(
SSdbOper
)
+
SDB_SYNC_HACK
;
pHead
->
version
=
0
;
pHead
->
msgType
=
pTable
->
tableId
*
10
+
SDB_ACTION_DELETE
;
pOper
->
rowData
=
pHead
->
cont
;
(
*
pTable
->
encodeFp
)(
pOper
);
pHead
->
len
=
pOper
->
rowSize
;
memcpy
(
pNewOper
,
pOper
,
sizeof
(
SSdbOper
));
if
(
pNewOper
->
pMsg
!=
NULL
)
{
sdbDebug
(
"app:%p:%p, table:%s record:%p:%s, delete action is add to sdb queue"
,
pNewOper
->
pMsg
->
rpcMsg
.
ahandle
,
pNewOper
->
pMsg
,
pTable
->
tableName
,
pOper
->
pObj
,
sdbGetKeyStrFromObj
(
pTable
,
pOper
->
pObj
));
}
taosWriteQitem
(
tsSdbWriteQueue
,
TAOS_QTYPE_RPC
,
pNewOper
);
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
int32_t
sdbUpdateRow
(
SSdbOper
*
pOper
)
{
SSdbTable
*
pTable
=
(
SSdbTable
*
)
pOper
->
table
;
if
(
pTable
==
NULL
)
return
TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE
;
void
*
pRow
=
sdbGetRowMetaFromObj
(
pTable
,
pOper
->
pObj
);
if
(
pRow
==
NULL
)
{
sdbDebug
(
"table:%s, record is not there, update failed"
,
pTable
->
tableName
);
return
TSDB_CODE_MND_SDB_OBJ_NOT_THERE
;
return
TSDB_CODE_MND_SDB_OBJ_NOT_THERE
;
}
}
int32_t
code
=
sdbUpdateHash
(
pTable
,
p
Oper
);
int32_t
code
=
sdbUpdateHash
(
pTable
,
p
Row
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
sdbError
(
"
table:%s, failed to update hash"
,
pTable
->
tableN
ame
);
sdbError
(
"
vgId:1, sdb:%s, failed to update hash"
,
pTable
->
n
ame
);
return
code
;
return
code
;
}
}
// just update data in memory
// just update data in memory
if
(
p
Oper
->
type
!=
SDB_OPER_GLOBAL
)
{
if
(
p
Row
->
type
!=
SDB_OPER_GLOBAL
)
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
if
(
p
Oper
->
reqFp
)
{
if
(
p
Row
->
fpReq
)
{
return
(
*
p
Oper
->
reqFp
)(
pOper
->
pMsg
);
return
(
*
p
Row
->
fpReq
)(
pRow
->
pMsg
);
}
else
{
}
else
{
return
sdb
UpdateRowImp
(
pOper
);
return
sdb
WriteRowToQueue
(
pRow
,
SDB_ACTION_UPDATE
);
}
}
}
}
int32_t
sdbUpdateRowImp
(
SSdbOper
*
pOper
)
{
void
*
sdbFetchRow
(
void
*
tparam
,
void
*
pNode
,
void
**
ppRow
)
{
SSdbTable
*
pTable
=
(
SSdbTable
*
)
pOper
->
table
;
SSdbTable
*
pTable
=
tparam
;
if
(
pTable
==
NULL
)
return
TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE
;
int32_t
size
=
sizeof
(
SSdbOper
)
+
sizeof
(
SWalHead
)
+
pTable
->
maxRowSize
+
SDB_SYNC_HACK
;
SSdbOper
*
pNewOper
=
taosAllocateQitem
(
size
);
SWalHead
*
pHead
=
(
void
*
)
pNewOper
+
sizeof
(
SSdbOper
)
+
SDB_SYNC_HACK
;
pHead
->
version
=
0
;
pHead
->
msgType
=
pTable
->
tableId
*
10
+
SDB_ACTION_UPDATE
;
pOper
->
rowData
=
pHead
->
cont
;
(
*
pTable
->
encodeFp
)(
pOper
);
pHead
->
len
=
pOper
->
rowSize
;
memcpy
(
pNewOper
,
pOper
,
sizeof
(
SSdbOper
));
if
(
pNewOper
->
pMsg
!=
NULL
)
{
sdbDebug
(
"app:%p:%p, table:%s record:%p:%s, update action is add to sdb queue"
,
pNewOper
->
pMsg
->
rpcMsg
.
ahandle
,
pNewOper
->
pMsg
,
pTable
->
tableName
,
pOper
->
pObj
,
sdbGetKeyStrFromObj
(
pTable
,
pOper
->
pObj
));
}
sdbIncRef
(
pNewOper
->
table
,
pNewOper
->
pObj
);
taosWriteQitem
(
tsSdbWriteQueue
,
TAOS_QTYPE_RPC
,
pNewOper
);
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
void
*
sdbFetchRow
(
void
*
handle
,
void
*
pNode
,
void
**
ppRow
)
{
SSdbTable
*
pTable
=
(
SSdbTable
*
)
handle
;
*
ppRow
=
NULL
;
*
ppRow
=
NULL
;
if
(
pTable
==
NULL
)
return
NULL
;
if
(
pTable
==
NULL
)
return
NULL
;
...
@@ -882,7 +776,7 @@ void *sdbFetchRow(void *handle, void *pNode, void **ppRow) {
...
@@ -882,7 +776,7 @@ void *sdbFetchRow(void *handle, void *pNode, void **ppRow) {
}
}
*
ppRow
=
*
ppMetaRow
;
*
ppRow
=
*
ppMetaRow
;
sdbIncRef
(
hand
le
,
*
ppMetaRow
);
sdbIncRef
(
pTab
le
,
*
ppMetaRow
);
return
pIter
;
return
pIter
;
}
}
...
@@ -899,19 +793,19 @@ void *sdbOpenTable(SSdbTableDesc *pDesc) {
...
@@ -899,19 +793,19 @@ void *sdbOpenTable(SSdbTableDesc *pDesc) {
if
(
pTable
==
NULL
)
return
NULL
;
if
(
pTable
==
NULL
)
return
NULL
;
pthread_mutex_init
(
&
pTable
->
mutex
,
NULL
);
pthread_mutex_init
(
&
pTable
->
mutex
,
NULL
);
tstrncpy
(
pTable
->
tableName
,
pDesc
->
tableN
ame
,
SDB_TABLE_LEN
);
tstrncpy
(
pTable
->
name
,
pDesc
->
n
ame
,
SDB_TABLE_LEN
);
pTable
->
keyType
=
pDesc
->
keyType
;
pTable
->
keyType
=
pDesc
->
keyType
;
pTable
->
tableId
=
pDesc
->
tableI
d
;
pTable
->
id
=
pDesc
->
i
d
;
pTable
->
hashSessions
=
pDesc
->
hashSessions
;
pTable
->
hashSessions
=
pDesc
->
hashSessions
;
pTable
->
maxRowSize
=
pDesc
->
maxRowSize
;
pTable
->
maxRowSize
=
pDesc
->
maxRowSize
;
pTable
->
refCountPos
=
pDesc
->
refCountPos
;
pTable
->
refCountPos
=
pDesc
->
refCountPos
;
pTable
->
insertFp
=
pDesc
->
insertFp
;
pTable
->
fpInsert
=
pDesc
->
fpInsert
;
pTable
->
deleteFp
=
pDesc
->
deleteFp
;
pTable
->
fpDelete
=
pDesc
->
fpDelete
;
pTable
->
updateFp
=
pDesc
->
updateFp
;
pTable
->
fpUpdate
=
pDesc
->
fpUpdate
;
pTable
->
encodeFp
=
pDesc
->
encodeFp
;
pTable
->
fpEncode
=
pDesc
->
fpEncode
;
pTable
->
decodeFp
=
pDesc
->
decodeFp
;
pTable
->
fpDecode
=
pDesc
->
fpDecode
;
pTable
->
destroyFp
=
pDesc
->
destroyFp
;
pTable
->
fpDestroy
=
pDesc
->
fpDestroy
;
pTable
->
restoredFp
=
pDesc
->
restoredFp
;
pTable
->
fpRestored
=
pDesc
->
fpRestored
;
_hash_fn_t
hashFp
=
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
);
_hash_fn_t
hashFp
=
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
);
if
(
pTable
->
keyType
==
SDB_KEY_STRING
||
pTable
->
keyType
==
SDB_KEY_VAR_STRING
)
{
if
(
pTable
->
keyType
==
SDB_KEY_STRING
||
pTable
->
keyType
==
SDB_KEY_VAR_STRING
)
{
...
@@ -919,8 +813,8 @@ void *sdbOpenTable(SSdbTableDesc *pDesc) {
...
@@ -919,8 +813,8 @@ void *sdbOpenTable(SSdbTableDesc *pDesc) {
}
}
pTable
->
iHandle
=
taosHashInit
(
pTable
->
hashSessions
,
hashFp
,
true
,
true
);
pTable
->
iHandle
=
taosHashInit
(
pTable
->
hashSessions
,
hashFp
,
true
,
true
);
tsSdb
Obj
.
numOfTables
++
;
tsSdb
Mgmt
.
numOfTables
++
;
tsSdb
Obj
.
tableList
[
pTable
->
tableI
d
]
=
pTable
;
tsSdb
Mgmt
.
tableList
[
pTable
->
i
d
]
=
pTable
;
return
pTable
;
return
pTable
;
}
}
...
@@ -928,87 +822,87 @@ void sdbCloseTable(void *handle) {
...
@@ -928,87 +822,87 @@ void sdbCloseTable(void *handle) {
SSdbTable
*
pTable
=
(
SSdbTable
*
)
handle
;
SSdbTable
*
pTable
=
(
SSdbTable
*
)
handle
;
if
(
pTable
==
NULL
)
return
;
if
(
pTable
==
NULL
)
return
;
tsSdb
Obj
.
numOfTables
--
;
tsSdb
Mgmt
.
numOfTables
--
;
tsSdb
Obj
.
tableList
[
pTable
->
tableI
d
]
=
NULL
;
tsSdb
Mgmt
.
tableList
[
pTable
->
i
d
]
=
NULL
;
SHashMutableIterator
*
pIter
=
taosHashCreateIter
(
pTable
->
iHandle
);
SHashMutableIterator
*
pIter
=
taosHashCreateIter
(
pTable
->
iHandle
);
while
(
taosHashIterNext
(
pIter
))
{
while
(
taosHashIterNext
(
pIter
))
{
void
**
ppRow
=
taosHashIterGet
(
pIter
);
void
**
ppRow
=
taosHashIterGet
(
pIter
);
if
(
ppRow
==
NULL
)
continue
;
if
(
ppRow
==
NULL
)
continue
;
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
pObj
=
*
ppRow
,
.
pObj
=
*
ppRow
,
.
t
able
=
pTable
,
.
pT
able
=
pTable
,
};
};
(
*
pTable
->
destroyFp
)(
&
oper
);
(
*
pTable
->
fpDestroy
)(
&
row
);
}
}
taosHashDestroyIter
(
pIter
);
taosHashDestroyIter
(
pIter
);
taosHashCleanup
(
pTable
->
iHandle
);
taosHashCleanup
(
pTable
->
iHandle
);
pthread_mutex_destroy
(
&
pTable
->
mutex
);
pthread_mutex_destroy
(
&
pTable
->
mutex
);
sdbDebug
(
"
table:%s, is closed, numOfTables:%d"
,
pTable
->
tableName
,
tsSdbObj
.
numOfTables
);
sdbDebug
(
"
vgId:1, sdb:%s, is closed, numOfTables:%d"
,
pTable
->
name
,
tsSdbMgmt
.
numOfTables
);
free
(
pTable
);
free
(
pTable
);
}
}
int32_t
sdbInitWrite
Worker
()
{
static
int32_t
sdbInit
Worker
()
{
tsSdbPool
.
num
=
1
;
tsSdbPool
.
num
=
1
;
tsSdbPool
.
w
riteWorker
=
(
SSdbWriteWorker
*
)
calloc
(
sizeof
(
SSdbWrite
Worker
),
tsSdbPool
.
num
);
tsSdbPool
.
w
orker
=
calloc
(
sizeof
(
SSdb
Worker
),
tsSdbPool
.
num
);
if
(
tsSdbPool
.
w
riteW
orker
==
NULL
)
return
-
1
;
if
(
tsSdbPool
.
worker
==
NULL
)
return
-
1
;
for
(
int32_t
i
=
0
;
i
<
tsSdbPool
.
num
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
tsSdbPool
.
num
;
++
i
)
{
SSdbW
riteWorker
*
pWorker
=
tsSdbPool
.
writeW
orker
+
i
;
SSdbW
orker
*
pWorker
=
tsSdbPool
.
w
orker
+
i
;
pWorker
->
workerId
=
i
;
pWorker
->
workerId
=
i
;
}
}
sdbAlloc
Write
Queue
();
sdbAllocQueue
();
mInfo
(
"sdb write is opened"
);
mInfo
(
"
vgId:1,
sdb write is opened"
);
return
0
;
return
0
;
}
}
void
sdbCleanupWrite
Worker
()
{
static
void
sdbCleanup
Worker
()
{
for
(
int32_t
i
=
0
;
i
<
tsSdbPool
.
num
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
tsSdbPool
.
num
;
++
i
)
{
SSdbW
riteWorker
*
pWorker
=
tsSdbPool
.
writeW
orker
+
i
;
SSdbW
orker
*
pWorker
=
tsSdbPool
.
w
orker
+
i
;
if
(
pWorker
->
thread
)
{
if
(
pWorker
->
thread
)
{
taosQsetThreadResume
(
tsSdbW
rite
Qset
);
taosQsetThreadResume
(
tsSdbWQset
);
}
}
}
}
for
(
int32_t
i
=
0
;
i
<
tsSdbPool
.
num
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
tsSdbPool
.
num
;
++
i
)
{
SSdbW
riteWorker
*
pWorker
=
tsSdbPool
.
writeW
orker
+
i
;
SSdbW
orker
*
pWorker
=
tsSdbPool
.
w
orker
+
i
;
if
(
pWorker
->
thread
)
{
if
(
pWorker
->
thread
)
{
pthread_join
(
pWorker
->
thread
,
NULL
);
pthread_join
(
pWorker
->
thread
,
NULL
);
}
}
}
}
sdbFree
Writeq
ueue
();
sdbFree
Q
ueue
();
tfree
(
tsSdbPool
.
w
riteW
orker
);
tfree
(
tsSdbPool
.
worker
);
mInfo
(
"sdb write is closed"
);
mInfo
(
"
vgId:1,
sdb write is closed"
);
}
}
int32_t
sdbAllocWrite
Queue
()
{
static
int32_t
sdbAlloc
Queue
()
{
tsSdbW
rite
Queue
=
taosOpenQueue
();
tsSdbWQueue
=
taosOpenQueue
();
if
(
tsSdbW
rite
Queue
==
NULL
)
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
if
(
tsSdbWQueue
==
NULL
)
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
tsSdbW
rite
Qset
=
taosOpenQset
();
tsSdbWQset
=
taosOpenQset
();
if
(
tsSdbW
rite
Qset
==
NULL
)
{
if
(
tsSdbWQset
==
NULL
)
{
taosCloseQueue
(
tsSdbW
rite
Queue
);
taosCloseQueue
(
tsSdbWQueue
);
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
}
}
taosAddIntoQset
(
tsSdbW
riteQset
,
tsSdbWrite
Queue
,
NULL
);
taosAddIntoQset
(
tsSdbW
Qset
,
tsSdbW
Queue
,
NULL
);
tsSdbW
rite
Qall
=
taosAllocateQall
();
tsSdbWQall
=
taosAllocateQall
();
if
(
tsSdbW
rite
Qall
==
NULL
)
{
if
(
tsSdbWQall
==
NULL
)
{
taosCloseQset
(
tsSdbW
rite
Qset
);
taosCloseQset
(
tsSdbWQset
);
taosCloseQueue
(
tsSdbW
rite
Queue
);
taosCloseQueue
(
tsSdbWQueue
);
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
}
}
for
(
int32_t
i
=
0
;
i
<
tsSdbPool
.
num
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
tsSdbPool
.
num
;
++
i
)
{
SSdbW
riteWorker
*
pWorker
=
tsSdbPool
.
writeW
orker
+
i
;
SSdbW
orker
*
pWorker
=
tsSdbPool
.
w
orker
+
i
;
pWorker
->
workerId
=
i
;
pWorker
->
workerId
=
i
;
pthread_attr_t
thAttr
;
pthread_attr_t
thAttr
;
...
@@ -1017,9 +911,9 @@ int32_t sdbAllocWriteQueue() {
...
@@ -1017,9 +911,9 @@ int32_t sdbAllocWriteQueue() {
if
(
pthread_create
(
&
pWorker
->
thread
,
&
thAttr
,
sdbWorkerFp
,
pWorker
)
!=
0
)
{
if
(
pthread_create
(
&
pWorker
->
thread
,
&
thAttr
,
sdbWorkerFp
,
pWorker
)
!=
0
)
{
mError
(
"failed to create thread to process sdb write queue, reason:%s"
,
strerror
(
errno
));
mError
(
"failed to create thread to process sdb write queue, reason:%s"
,
strerror
(
errno
));
taosFreeQall
(
tsSdbW
rite
Qall
);
taosFreeQall
(
tsSdbWQall
);
taosCloseQset
(
tsSdbW
rite
Qset
);
taosCloseQset
(
tsSdbWQset
);
taosCloseQueue
(
tsSdbW
rite
Queue
);
taosCloseQueue
(
tsSdbWQueue
);
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
}
}
...
@@ -1027,86 +921,126 @@ int32_t sdbAllocWriteQueue() {
...
@@ -1027,86 +921,126 @@ int32_t sdbAllocWriteQueue() {
mDebug
(
"sdb write worker:%d is launched, total:%d"
,
pWorker
->
workerId
,
tsSdbPool
.
num
);
mDebug
(
"sdb write worker:%d is launched, total:%d"
,
pWorker
->
workerId
,
tsSdbPool
.
num
);
}
}
mDebug
(
"sdb write queue:%p is allocated"
,
tsSdbW
rite
Queue
);
mDebug
(
"sdb write queue:%p is allocated"
,
tsSdbWQueue
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
void
sdbFreeWriteq
ueue
()
{
static
void
sdbFreeQ
ueue
()
{
taosCloseQueue
(
tsSdbW
rite
Queue
);
taosCloseQueue
(
tsSdbWQueue
);
taosFreeQall
(
tsSdbW
rite
Qall
);
taosFreeQall
(
tsSdbWQall
);
taosCloseQset
(
tsSdbW
rite
Qset
);
taosCloseQset
(
tsSdbWQset
);
tsSdbW
rite
Qall
=
NULL
;
tsSdbWQall
=
NULL
;
tsSdbW
rite
Qset
=
NULL
;
tsSdbWQset
=
NULL
;
tsSdbW
rite
Queue
=
NULL
;
tsSdbWQueue
=
NULL
;
}
}
int32_t
sdbWriteToQueue
(
void
*
param
,
void
*
data
,
int32_t
qtype
,
void
*
pMsg
)
{
static
int32_t
sdbWriteToQueue
(
SSdbRow
*
pRow
,
int32_t
qtype
)
{
SWalHead
*
pHead
=
data
;
SWalHead
*
pHead
=
pRow
->
pHead
;
int32_t
size
=
sizeof
(
SWalHead
)
+
pHead
->
len
;
SWalHead
*
pWal
=
taosAllocateQitem
(
size
);
memcpy
(
pWal
,
pHead
,
size
);
taosWriteQitem
(
tsSdbWriteQueue
,
qtype
,
pWal
);
if
(
pHead
->
len
>
TSDB_MAX_WAL_SIZE
)
{
return
0
;
sdbError
(
"vgId:1, wal len:%d exceeds limit, hver:%"
PRIu64
,
pHead
->
len
,
pHead
->
version
);
taosFreeQitem
(
pRow
);
return
TSDB_CODE_WAL_SIZE_LIMIT
;
}
int32_t
queued
=
atomic_add_fetch_32
(
&
tsSdbMgmt
.
queuedMsg
,
1
);
if
(
queued
>
MAX_QUEUED_MSG_NUM
)
{
sdbDebug
(
"vgId:1, too many msg:%d in sdb queue, flow control"
,
queued
);
taosMsleep
(
1
);
}
sdbIncRef
(
pRow
->
pTable
,
pRow
->
pObj
);
sdbTrace
(
"vgId:1, msg:%p write into to sdb queue"
,
pRow
->
pMsg
);
taosWriteQitem
(
tsSdbWQueue
,
qtype
,
pRow
);
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
static
void
sdbFreeFromQueue
(
SSdbRow
*
pRow
)
{
int32_t
queued
=
atomic_sub_fetch_32
(
&
tsSdbMgmt
.
queuedMsg
,
1
);
sdbTrace
(
"vgId:1, msg:%p free from sdb queue, queued:%d"
,
pRow
->
pMsg
,
queued
);
sdbDecRef
(
pRow
->
pTable
,
pRow
->
pObj
);
taosFreeQitem
(
pRow
);
}
}
static
void
*
sdbWorkerFp
(
void
*
param
)
{
static
int32_t
sdbWriteWalToQueue
(
void
*
vparam
,
void
*
wparam
,
int32_t
qtype
,
void
*
rparam
)
{
SWalHead
*
pHead
;
SWalHead
*
pHead
=
wparam
;
SSdbOper
*
pOper
;
int32_t
type
;
int32_t
size
=
sizeof
(
SSdbRow
)
+
sizeof
(
SWalHead
)
+
pHead
->
len
;
int32_t
numOfMsgs
;
SSdbRow
*
pRow
=
taosAllocateQitem
(
size
);
void
*
item
;
if
(
pRow
==
NULL
)
{
void
*
unUsed
;
return
TSDB_CODE_VND_OUT_OF_MEMORY
;
}
return
sdbWriteToQueue
(
pRow
,
qtype
);
}
static
int32_t
sdbWriteRowToQueue
(
SSdbRow
*
pInputRow
,
int32_t
action
)
{
SSdbTable
*
pTable
=
pInputRow
->
pTable
;
if
(
pTable
==
NULL
)
return
TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE
;
int32_t
size
=
sizeof
(
SSdbRow
)
+
sizeof
(
SWalHead
)
+
pTable
->
maxRowSize
;
SSdbRow
*
pRow
=
taosAllocateQitem
(
size
);
if
(
pRow
==
NULL
)
{
return
TSDB_CODE_VND_OUT_OF_MEMORY
;
}
memcpy
(
pRow
,
pInputRow
,
sizeof
(
SSdbRow
));
pRow
->
processedCount
=
1
;
SWalHead
*
pHead
=
pRow
->
pHead
;
pRow
->
rowData
=
pHead
->
cont
;
(
*
pTable
->
fpEncode
)(
pRow
);
pHead
->
len
=
pRow
->
rowSize
;
pHead
->
version
=
0
;
pHead
->
msgType
=
pTable
->
id
*
10
+
action
;
return
sdbWriteToQueue
(
pRow
,
TAOS_QTYPE_RPC
);
}
int32_t
sdbInsertRowToQueue
(
SSdbRow
*
pRow
)
{
return
sdbWriteRowToQueue
(
pRow
,
SDB_ACTION_INSERT
);
}
static
void
*
sdbWorkerFp
(
void
*
pWorker
)
{
SSdbRow
*
pRow
;
int32_t
qtype
;
void
*
unUsed
;
while
(
1
)
{
while
(
1
)
{
numOfMsgs
=
taosReadAllQitemsFromQset
(
tsSdbWriteQset
,
tsSdbWrite
Qall
,
&
unUsed
);
int32_t
numOfMsgs
=
taosReadAllQitemsFromQset
(
tsSdbWQset
,
tsSdbW
Qall
,
&
unUsed
);
if
(
numOfMsgs
==
0
)
{
if
(
numOfMsgs
==
0
)
{
sdbDebug
(
"qset:%p, sdb got no message from qset, exiting"
,
tsSdbW
rite
Qset
);
sdbDebug
(
"qset:%p, sdb got no message from qset, exiting"
,
tsSdbWQset
);
break
;
break
;
}
}
for
(
int32_t
i
=
0
;
i
<
numOfMsgs
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfMsgs
;
++
i
)
{
taosGetQitem
(
tsSdbWriteQall
,
&
type
,
&
item
);
taosGetQitem
(
tsSdbWQall
,
&
qtype
,
(
void
**
)
&
pRow
);
if
(
type
==
TAOS_QTYPE_RPC
)
{
sdbTrace
(
"vgId:1, msg:%p, row:%p hver:%"
PRIu64
", will be processed in sdb queue"
,
pRow
->
pMsg
,
pRow
->
pObj
,
pOper
=
(
SSdbOper
*
)
item
;
pRow
->
pHead
->
version
);
pOper
->
processedCount
=
1
;
pHead
=
(
void
*
)
pOper
+
sizeof
(
SSdbOper
)
+
SDB_SYNC_HACK
;
if
(
pOper
->
pMsg
!=
NULL
)
{
sdbDebug
(
"app:%p:%p, table:%s record:%p:%s ver:%"
PRIu64
", will be processed in sdb queue"
,
pOper
->
pMsg
->
rpcMsg
.
ahandle
,
pOper
->
pMsg
,
((
SSdbTable
*
)
pOper
->
table
)
->
tableName
,
pOper
->
pObj
,
sdbGetKeyStr
(
pOper
->
table
,
pHead
->
cont
),
pHead
->
version
);
}
}
else
{
pHead
=
(
SWalHead
*
)
item
;
pOper
=
NULL
;
}
int32_t
code
=
sdbWrite
(
pOper
,
pHead
,
type
,
NULL
);
pRow
->
code
=
sdbProcessWrite
((
qtype
==
TAOS_QTYPE_RPC
)
?
pRow
:
NULL
,
pRow
->
pHead
,
qtype
,
NULL
);
if
(
code
>
0
)
code
=
0
;
if
(
pRow
->
code
>
0
)
pRow
->
code
=
0
;
if
(
pOper
)
{
pOper
->
retCode
=
code
;
sdbTrace
(
"vgId:1, msg:%p is processed in sdb queue, code:%x"
,
pRow
->
pMsg
,
pRow
->
code
);
}
else
{
pHead
->
len
=
code
;
// hackway
}
}
}
walFsync
(
tsSdb
Obj
.
wal
,
true
);
walFsync
(
tsSdb
Mgmt
.
wal
,
true
);
// browse all items, and process them one by one
// browse all items, and process them one by one
taosResetQitems
(
tsSdbW
rite
Qall
);
taosResetQitems
(
tsSdbWQall
);
for
(
int32_t
i
=
0
;
i
<
numOfMsgs
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfMsgs
;
++
i
)
{
taosGetQitem
(
tsSdbWriteQall
,
&
type
,
&
item
);
taosGetQitem
(
tsSdbWQall
,
&
qtype
,
(
void
**
)
&
pRow
);
if
(
type
==
TAOS_QTYPE_RPC
)
{
if
(
qtype
==
TAOS_QTYPE_RPC
)
{
pOper
=
(
SSdbOper
*
)
item
;
sdbConfirmForward
(
NULL
,
pRow
,
pRow
->
code
);
sdbConfirmForward
(
NULL
,
pOper
,
pOper
->
retCode
);
}
else
if
(
qtype
==
TAOS_QTYPE_FWD
)
{
}
else
if
(
type
==
TAOS_QTYPE_FWD
)
{
syncConfirmForward
(
tsSdbMgmt
.
sync
,
pRow
->
pHead
->
version
,
pRow
->
code
);
pHead
=
(
SWalHead
*
)
item
;
syncConfirmForward
(
tsSdbObj
.
sync
,
pHead
->
version
,
pHead
->
len
);
taosFreeQitem
(
item
);
}
else
{
}
else
{
taosFreeQitem
(
item
);
}
}
sdbFreeFromQueue
(
pRow
);
}
}
}
}
...
...
src/mnode/src/mnodeTable.c
浏览文件 @
ea3aae75
...
@@ -99,13 +99,13 @@ static void mnodeDestroyChildTable(SCTableObj *pTable) {
...
@@ -99,13 +99,13 @@ static void mnodeDestroyChildTable(SCTableObj *pTable) {
tfree
(
pTable
);
tfree
(
pTable
);
}
}
static
int32_t
mnodeChildTableActionDestroy
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeChildTableActionDestroy
(
SSdb
Row
*
pRow
)
{
mnodeDestroyChildTable
(
p
Oper
->
pObj
);
mnodeDestroyChildTable
(
p
Row
->
pObj
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeChildTableActionInsert
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeChildTableActionInsert
(
SSdb
Row
*
pRow
)
{
SCTableObj
*
pTable
=
p
Oper
->
pObj
;
SCTableObj
*
pTable
=
p
Row
->
pObj
;
SVgObj
*
pVgroup
=
mnodeGetVgroup
(
pTable
->
vgId
);
SVgObj
*
pVgroup
=
mnodeGetVgroup
(
pTable
->
vgId
);
if
(
pVgroup
==
NULL
)
{
if
(
pVgroup
==
NULL
)
{
...
@@ -153,8 +153,8 @@ static int32_t mnodeChildTableActionInsert(SSdbOper *pOper) {
...
@@ -153,8 +153,8 @@ static int32_t mnodeChildTableActionInsert(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeChildTableActionDelete
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeChildTableActionDelete
(
SSdb
Row
*
pRow
)
{
SCTableObj
*
pTable
=
p
Oper
->
pObj
;
SCTableObj
*
pTable
=
p
Row
->
pObj
;
if
(
pTable
->
vgId
==
0
)
{
if
(
pTable
->
vgId
==
0
)
{
return
TSDB_CODE_MND_VGROUP_NOT_EXIST
;
return
TSDB_CODE_MND_VGROUP_NOT_EXIST
;
}
}
...
@@ -189,8 +189,8 @@ static int32_t mnodeChildTableActionDelete(SSdbOper *pOper) {
...
@@ -189,8 +189,8 @@ static int32_t mnodeChildTableActionDelete(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeChildTableActionUpdate
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeChildTableActionUpdate
(
SSdb
Row
*
pRow
)
{
SCTableObj
*
pNew
=
p
Oper
->
pObj
;
SCTableObj
*
pNew
=
p
Row
->
pObj
;
SCTableObj
*
pTable
=
mnodeGetChildTable
(
pNew
->
info
.
tableId
);
SCTableObj
*
pTable
=
mnodeGetChildTable
(
pNew
->
info
.
tableId
);
if
(
pTable
!=
pNew
)
{
if
(
pTable
!=
pNew
)
{
void
*
oldTableId
=
pTable
->
info
.
tableId
;
void
*
oldTableId
=
pTable
->
info
.
tableId
;
...
@@ -216,50 +216,50 @@ static int32_t mnodeChildTableActionUpdate(SSdbOper *pOper) {
...
@@ -216,50 +216,50 @@ static int32_t mnodeChildTableActionUpdate(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeChildTableActionEncode
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeChildTableActionEncode
(
SSdb
Row
*
pRow
)
{
SCTableObj
*
pTable
=
p
Oper
->
pObj
;
SCTableObj
*
pTable
=
p
Row
->
pObj
;
assert
(
pTable
!=
NULL
&&
p
Oper
->
rowData
!=
NULL
);
assert
(
pTable
!=
NULL
&&
p
Row
->
rowData
!=
NULL
);
int32_t
len
=
strlen
(
pTable
->
info
.
tableId
);
int32_t
len
=
strlen
(
pTable
->
info
.
tableId
);
if
(
len
>=
TSDB_TABLE_FNAME_LEN
)
return
TSDB_CODE_MND_INVALID_TABLE_ID
;
if
(
len
>=
TSDB_TABLE_FNAME_LEN
)
return
TSDB_CODE_MND_INVALID_TABLE_ID
;
memcpy
(
p
Oper
->
rowData
,
pTable
->
info
.
tableId
,
len
);
memcpy
(
p
Row
->
rowData
,
pTable
->
info
.
tableId
,
len
);
memset
(
p
Oper
->
rowData
+
len
,
0
,
1
);
memset
(
p
Row
->
rowData
+
len
,
0
,
1
);
len
++
;
len
++
;
memcpy
(
p
Oper
->
rowData
+
len
,
(
char
*
)
pTable
+
sizeof
(
char
*
),
tsChildTableUpdateSize
);
memcpy
(
p
Row
->
rowData
+
len
,
(
char
*
)
pTable
+
sizeof
(
char
*
),
tsChildTableUpdateSize
);
len
+=
tsChildTableUpdateSize
;
len
+=
tsChildTableUpdateSize
;
if
(
pTable
->
info
.
type
!=
TSDB_CHILD_TABLE
)
{
if
(
pTable
->
info
.
type
!=
TSDB_CHILD_TABLE
)
{
int32_t
schemaSize
=
pTable
->
numOfColumns
*
sizeof
(
SSchema
);
int32_t
schemaSize
=
pTable
->
numOfColumns
*
sizeof
(
SSchema
);
memcpy
(
p
Oper
->
rowData
+
len
,
pTable
->
schema
,
schemaSize
);
memcpy
(
p
Row
->
rowData
+
len
,
pTable
->
schema
,
schemaSize
);
len
+=
schemaSize
;
len
+=
schemaSize
;
if
(
pTable
->
sqlLen
!=
0
)
{
if
(
pTable
->
sqlLen
!=
0
)
{
memcpy
(
p
Oper
->
rowData
+
len
,
pTable
->
sql
,
pTable
->
sqlLen
);
memcpy
(
p
Row
->
rowData
+
len
,
pTable
->
sql
,
pTable
->
sqlLen
);
len
+=
pTable
->
sqlLen
;
len
+=
pTable
->
sqlLen
;
}
}
}
}
p
Oper
->
rowSize
=
len
;
p
Row
->
rowSize
=
len
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeChildTableActionDecode
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeChildTableActionDecode
(
SSdb
Row
*
pRow
)
{
assert
(
p
Oper
->
rowData
!=
NULL
);
assert
(
p
Row
->
rowData
!=
NULL
);
SCTableObj
*
pTable
=
calloc
(
1
,
sizeof
(
SCTableObj
));
SCTableObj
*
pTable
=
calloc
(
1
,
sizeof
(
SCTableObj
));
if
(
pTable
==
NULL
)
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
if
(
pTable
==
NULL
)
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
int32_t
len
=
strlen
(
p
Oper
->
rowData
);
int32_t
len
=
strlen
(
p
Row
->
rowData
);
if
(
len
>=
TSDB_TABLE_FNAME_LEN
)
{
if
(
len
>=
TSDB_TABLE_FNAME_LEN
)
{
free
(
pTable
);
free
(
pTable
);
return
TSDB_CODE_MND_INVALID_TABLE_ID
;
return
TSDB_CODE_MND_INVALID_TABLE_ID
;
}
}
pTable
->
info
.
tableId
=
strdup
(
p
Oper
->
rowData
);
pTable
->
info
.
tableId
=
strdup
(
p
Row
->
rowData
);
len
++
;
len
++
;
memcpy
((
char
*
)
pTable
+
sizeof
(
char
*
),
p
Oper
->
rowData
+
len
,
tsChildTableUpdateSize
);
memcpy
((
char
*
)
pTable
+
sizeof
(
char
*
),
p
Row
->
rowData
+
len
,
tsChildTableUpdateSize
);
len
+=
tsChildTableUpdateSize
;
len
+=
tsChildTableUpdateSize
;
if
(
pTable
->
info
.
type
!=
TSDB_CHILD_TABLE
)
{
if
(
pTable
->
info
.
type
!=
TSDB_CHILD_TABLE
)
{
...
@@ -269,7 +269,7 @@ static int32_t mnodeChildTableActionDecode(SSdbOper *pOper) {
...
@@ -269,7 +269,7 @@ static int32_t mnodeChildTableActionDecode(SSdbOper *pOper) {
mnodeDestroyChildTable
(
pTable
);
mnodeDestroyChildTable
(
pTable
);
return
TSDB_CODE_MND_INVALID_TABLE_TYPE
;
return
TSDB_CODE_MND_INVALID_TABLE_TYPE
;
}
}
memcpy
(
pTable
->
schema
,
p
Oper
->
rowData
+
len
,
schemaSize
);
memcpy
(
pTable
->
schema
,
p
Row
->
rowData
+
len
,
schemaSize
);
len
+=
schemaSize
;
len
+=
schemaSize
;
if
(
pTable
->
sqlLen
!=
0
)
{
if
(
pTable
->
sqlLen
!=
0
)
{
...
@@ -278,11 +278,11 @@ static int32_t mnodeChildTableActionDecode(SSdbOper *pOper) {
...
@@ -278,11 +278,11 @@ static int32_t mnodeChildTableActionDecode(SSdbOper *pOper) {
mnodeDestroyChildTable
(
pTable
);
mnodeDestroyChildTable
(
pTable
);
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
}
}
memcpy
(
pTable
->
sql
,
p
Oper
->
rowData
+
len
,
pTable
->
sqlLen
);
memcpy
(
pTable
->
sql
,
p
Row
->
rowData
+
len
,
pTable
->
sqlLen
);
}
}
}
}
p
Oper
->
pObj
=
pTable
;
p
Row
->
pObj
=
pTable
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -297,7 +297,7 @@ static int32_t mnodeChildTableActionRestored() {
...
@@ -297,7 +297,7 @@ static int32_t mnodeChildTableActionRestored() {
SDbObj
*
pDb
=
mnodeGetDbByTableId
(
pTable
->
info
.
tableId
);
SDbObj
*
pDb
=
mnodeGetDbByTableId
(
pTable
->
info
.
tableId
);
if
(
pDb
==
NULL
||
pDb
->
status
!=
TSDB_DB_STATUS_READY
)
{
if
(
pDb
==
NULL
||
pDb
->
status
!=
TSDB_DB_STATUS_READY
)
{
mError
(
"ctable:%s, failed to get db or db in dropping, discard it"
,
pTable
->
info
.
tableId
);
mError
(
"ctable:%s, failed to get db or db in dropping, discard it"
,
pTable
->
info
.
tableId
);
SSdb
Oper
desc
=
{.
type
=
SDB_OPER_LOCAL
,
.
pObj
=
pTable
,
.
t
able
=
tsChildTableSdb
};
SSdb
Row
desc
=
{.
type
=
SDB_OPER_LOCAL
,
.
pObj
=
pTable
,
.
pT
able
=
tsChildTableSdb
};
sdbDeleteRow
(
&
desc
);
sdbDeleteRow
(
&
desc
);
mnodeDecTableRef
(
pTable
);
mnodeDecTableRef
(
pTable
);
mnodeDecDbRef
(
pDb
);
mnodeDecDbRef
(
pDb
);
...
@@ -309,7 +309,7 @@ static int32_t mnodeChildTableActionRestored() {
...
@@ -309,7 +309,7 @@ static int32_t mnodeChildTableActionRestored() {
if
(
pVgroup
==
NULL
)
{
if
(
pVgroup
==
NULL
)
{
mError
(
"ctable:%s, failed to get vgId:%d tid:%d, discard it"
,
pTable
->
info
.
tableId
,
pTable
->
vgId
,
pTable
->
tid
);
mError
(
"ctable:%s, failed to get vgId:%d tid:%d, discard it"
,
pTable
->
info
.
tableId
,
pTable
->
vgId
,
pTable
->
tid
);
pTable
->
vgId
=
0
;
pTable
->
vgId
=
0
;
SSdb
Oper
desc
=
{.
type
=
SDB_OPER_LOCAL
,
.
pObj
=
pTable
,
.
t
able
=
tsChildTableSdb
};
SSdb
Row
desc
=
{.
type
=
SDB_OPER_LOCAL
,
.
pObj
=
pTable
,
.
pT
able
=
tsChildTableSdb
};
sdbDeleteRow
(
&
desc
);
sdbDeleteRow
(
&
desc
);
mnodeDecTableRef
(
pTable
);
mnodeDecTableRef
(
pTable
);
continue
;
continue
;
...
@@ -320,7 +320,7 @@ static int32_t mnodeChildTableActionRestored() {
...
@@ -320,7 +320,7 @@ static int32_t mnodeChildTableActionRestored() {
mError
(
"ctable:%s, db:%s not match with vgId:%d db:%s sid:%d, discard it"
,
mError
(
"ctable:%s, db:%s not match with vgId:%d db:%s sid:%d, discard it"
,
pTable
->
info
.
tableId
,
pDb
->
name
,
pTable
->
vgId
,
pVgroup
->
dbName
,
pTable
->
tid
);
pTable
->
info
.
tableId
,
pDb
->
name
,
pTable
->
vgId
,
pVgroup
->
dbName
,
pTable
->
tid
);
pTable
->
vgId
=
0
;
pTable
->
vgId
=
0
;
SSdb
Oper
desc
=
{.
type
=
SDB_OPER_LOCAL
,
.
pObj
=
pTable
,
.
t
able
=
tsChildTableSdb
};
SSdb
Row
desc
=
{.
type
=
SDB_OPER_LOCAL
,
.
pObj
=
pTable
,
.
pT
able
=
tsChildTableSdb
};
sdbDeleteRow
(
&
desc
);
sdbDeleteRow
(
&
desc
);
mnodeDecTableRef
(
pTable
);
mnodeDecTableRef
(
pTable
);
continue
;
continue
;
...
@@ -331,7 +331,7 @@ static int32_t mnodeChildTableActionRestored() {
...
@@ -331,7 +331,7 @@ static int32_t mnodeChildTableActionRestored() {
if
(
pSuperTable
==
NULL
)
{
if
(
pSuperTable
==
NULL
)
{
mError
(
"ctable:%s, stable:%"
PRIu64
" not exist"
,
pTable
->
info
.
tableId
,
pTable
->
suid
);
mError
(
"ctable:%s, stable:%"
PRIu64
" not exist"
,
pTable
->
info
.
tableId
,
pTable
->
suid
);
pTable
->
vgId
=
0
;
pTable
->
vgId
=
0
;
SSdb
Oper
desc
=
{.
type
=
SDB_OPER_LOCAL
,
.
pObj
=
pTable
,
.
t
able
=
tsChildTableSdb
};
SSdb
Row
desc
=
{.
type
=
SDB_OPER_LOCAL
,
.
pObj
=
pTable
,
.
pT
able
=
tsChildTableSdb
};
sdbDeleteRow
(
&
desc
);
sdbDeleteRow
(
&
desc
);
mnodeDecTableRef
(
pTable
);
mnodeDecTableRef
(
pTable
);
continue
;
continue
;
...
@@ -352,19 +352,19 @@ static int32_t mnodeInitChildTables() {
...
@@ -352,19 +352,19 @@ static int32_t mnodeInitChildTables() {
tsChildTableUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
.
info
.
type
;
tsChildTableUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
.
info
.
type
;
SSdbTableDesc
tableDesc
=
{
SSdbTableDesc
tableDesc
=
{
.
tableId
=
SDB_TABLE_CTABLE
,
.
id
=
SDB_TABLE_CTABLE
,
.
tableName
=
"ctables"
,
.
name
=
"ctables"
,
.
hashSessions
=
TSDB_DEFAULT_CTABLES_HASH_SIZE
,
.
hashSessions
=
TSDB_DEFAULT_CTABLES_HASH_SIZE
,
.
maxRowSize
=
sizeof
(
SCTableObj
)
+
sizeof
(
SSchema
)
*
(
TSDB_MAX_TAGS
+
TSDB_MAX_COLUMNS
+
16
)
+
TSDB_TABLE_FNAME_LEN
+
TSDB_CQ_SQL_SIZE
,
.
maxRowSize
=
sizeof
(
SCTableObj
)
+
sizeof
(
SSchema
)
*
(
TSDB_MAX_TAGS
+
TSDB_MAX_COLUMNS
+
16
)
+
TSDB_TABLE_FNAME_LEN
+
TSDB_CQ_SQL_SIZE
,
.
refCountPos
=
(
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
,
.
refCountPos
=
(
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
,
.
keyType
=
SDB_KEY_VAR_STRING
,
.
keyType
=
SDB_KEY_VAR_STRING
,
.
insertFp
=
mnodeChildTableActionInsert
,
.
fpInsert
=
mnodeChildTableActionInsert
,
.
deleteFp
=
mnodeChildTableActionDelete
,
.
fpDelete
=
mnodeChildTableActionDelete
,
.
updateFp
=
mnodeChildTableActionUpdate
,
.
fpUpdate
=
mnodeChildTableActionUpdate
,
.
encodeFp
=
mnodeChildTableActionEncode
,
.
fpEncode
=
mnodeChildTableActionEncode
,
.
decodeFp
=
mnodeChildTableActionDecode
,
.
fpDecode
=
mnodeChildTableActionDecode
,
.
destroyFp
=
mnodeChildTableActionDestroy
,
.
fpDestroy
=
mnodeChildTableActionDestroy
,
.
restoredFp
=
mnodeChildTableActionRestored
.
fpRestored
=
mnodeChildTableActionRestored
};
};
tsChildTableSdb
=
sdbOpenTable
(
&
tableDesc
);
tsChildTableSdb
=
sdbOpenTable
(
&
tableDesc
);
...
@@ -430,13 +430,13 @@ static void mnodeDestroySuperTable(SSTableObj *pStable) {
...
@@ -430,13 +430,13 @@ static void mnodeDestroySuperTable(SSTableObj *pStable) {
tfree
(
pStable
);
tfree
(
pStable
);
}
}
static
int32_t
mnodeSuperTableActionDestroy
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeSuperTableActionDestroy
(
SSdb
Row
*
pRow
)
{
mnodeDestroySuperTable
(
p
Oper
->
pObj
);
mnodeDestroySuperTable
(
p
Row
->
pObj
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeSuperTableActionInsert
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeSuperTableActionInsert
(
SSdb
Row
*
pRow
)
{
SSTableObj
*
pStable
=
p
Oper
->
pObj
;
SSTableObj
*
pStable
=
p
Row
->
pObj
;
SDbObj
*
pDb
=
mnodeGetDbByTableId
(
pStable
->
info
.
tableId
);
SDbObj
*
pDb
=
mnodeGetDbByTableId
(
pStable
->
info
.
tableId
);
if
(
pDb
!=
NULL
&&
pDb
->
status
==
TSDB_DB_STATUS_READY
)
{
if
(
pDb
!=
NULL
&&
pDb
->
status
==
TSDB_DB_STATUS_READY
)
{
mnodeAddSuperTableIntoDb
(
pDb
);
mnodeAddSuperTableIntoDb
(
pDb
);
...
@@ -446,8 +446,8 @@ static int32_t mnodeSuperTableActionInsert(SSdbOper *pOper) {
...
@@ -446,8 +446,8 @@ static int32_t mnodeSuperTableActionInsert(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeSuperTableActionDelete
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeSuperTableActionDelete
(
SSdb
Row
*
pRow
)
{
SSTableObj
*
pStable
=
p
Oper
->
pObj
;
SSTableObj
*
pStable
=
p
Row
->
pObj
;
SDbObj
*
pDb
=
mnodeGetDbByTableId
(
pStable
->
info
.
tableId
);
SDbObj
*
pDb
=
mnodeGetDbByTableId
(
pStable
->
info
.
tableId
);
if
(
pDb
!=
NULL
)
{
if
(
pDb
!=
NULL
)
{
mnodeRemoveSuperTableFromDb
(
pDb
);
mnodeRemoveSuperTableFromDb
(
pDb
);
...
@@ -458,8 +458,8 @@ static int32_t mnodeSuperTableActionDelete(SSdbOper *pOper) {
...
@@ -458,8 +458,8 @@ static int32_t mnodeSuperTableActionDelete(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeSuperTableActionUpdate
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeSuperTableActionUpdate
(
SSdb
Row
*
pRow
)
{
SSTableObj
*
pNew
=
p
Oper
->
pObj
;
SSTableObj
*
pNew
=
p
Row
->
pObj
;
SSTableObj
*
pTable
=
mnodeGetSuperTable
(
pNew
->
info
.
tableId
);
SSTableObj
*
pTable
=
mnodeGetSuperTable
(
pNew
->
info
.
tableId
);
if
(
pTable
!=
NULL
&&
pTable
!=
pNew
)
{
if
(
pTable
!=
NULL
&&
pTable
!=
pNew
)
{
void
*
oldTableId
=
pTable
->
info
.
tableId
;
void
*
oldTableId
=
pTable
->
info
.
tableId
;
...
@@ -483,43 +483,43 @@ static int32_t mnodeSuperTableActionUpdate(SSdbOper *pOper) {
...
@@ -483,43 +483,43 @@ static int32_t mnodeSuperTableActionUpdate(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeSuperTableActionEncode
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeSuperTableActionEncode
(
SSdb
Row
*
pRow
)
{
SSTableObj
*
pStable
=
p
Oper
->
pObj
;
SSTableObj
*
pStable
=
p
Row
->
pObj
;
assert
(
p
Oper
->
pObj
!=
NULL
&&
pOper
->
rowData
!=
NULL
);
assert
(
p
Row
->
pObj
!=
NULL
&&
pRow
->
rowData
!=
NULL
);
int32_t
len
=
strlen
(
pStable
->
info
.
tableId
);
int32_t
len
=
strlen
(
pStable
->
info
.
tableId
);
if
(
len
>=
TSDB_TABLE_FNAME_LEN
)
len
=
TSDB_CODE_MND_INVALID_TABLE_ID
;
if
(
len
>=
TSDB_TABLE_FNAME_LEN
)
len
=
TSDB_CODE_MND_INVALID_TABLE_ID
;
memcpy
(
p
Oper
->
rowData
,
pStable
->
info
.
tableId
,
len
);
memcpy
(
p
Row
->
rowData
,
pStable
->
info
.
tableId
,
len
);
memset
(
p
Oper
->
rowData
+
len
,
0
,
1
);
memset
(
p
Row
->
rowData
+
len
,
0
,
1
);
len
++
;
len
++
;
memcpy
(
p
Oper
->
rowData
+
len
,
(
char
*
)
pStable
+
sizeof
(
char
*
),
tsSuperTableUpdateSize
);
memcpy
(
p
Row
->
rowData
+
len
,
(
char
*
)
pStable
+
sizeof
(
char
*
),
tsSuperTableUpdateSize
);
len
+=
tsSuperTableUpdateSize
;
len
+=
tsSuperTableUpdateSize
;
int32_t
schemaSize
=
sizeof
(
SSchema
)
*
(
pStable
->
numOfColumns
+
pStable
->
numOfTags
);
int32_t
schemaSize
=
sizeof
(
SSchema
)
*
(
pStable
->
numOfColumns
+
pStable
->
numOfTags
);
memcpy
(
p
Oper
->
rowData
+
len
,
pStable
->
schema
,
schemaSize
);
memcpy
(
p
Row
->
rowData
+
len
,
pStable
->
schema
,
schemaSize
);
len
+=
schemaSize
;
len
+=
schemaSize
;
p
Oper
->
rowSize
=
len
;
p
Row
->
rowSize
=
len
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeSuperTableActionDecode
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeSuperTableActionDecode
(
SSdb
Row
*
pRow
)
{
assert
(
p
Oper
->
rowData
!=
NULL
);
assert
(
p
Row
->
rowData
!=
NULL
);
SSTableObj
*
pStable
=
(
SSTableObj
*
)
calloc
(
1
,
sizeof
(
SSTableObj
));
SSTableObj
*
pStable
=
(
SSTableObj
*
)
calloc
(
1
,
sizeof
(
SSTableObj
));
if
(
pStable
==
NULL
)
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
if
(
pStable
==
NULL
)
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
int32_t
len
=
strlen
(
p
Oper
->
rowData
);
int32_t
len
=
strlen
(
p
Row
->
rowData
);
if
(
len
>=
TSDB_TABLE_FNAME_LEN
){
if
(
len
>=
TSDB_TABLE_FNAME_LEN
){
free
(
pStable
);
free
(
pStable
);
return
TSDB_CODE_MND_INVALID_TABLE_ID
;
return
TSDB_CODE_MND_INVALID_TABLE_ID
;
}
}
pStable
->
info
.
tableId
=
strdup
(
p
Oper
->
rowData
);
pStable
->
info
.
tableId
=
strdup
(
p
Row
->
rowData
);
len
++
;
len
++
;
memcpy
((
char
*
)
pStable
+
sizeof
(
char
*
),
p
Oper
->
rowData
+
len
,
tsSuperTableUpdateSize
);
memcpy
((
char
*
)
pStable
+
sizeof
(
char
*
),
p
Row
->
rowData
+
len
,
tsSuperTableUpdateSize
);
len
+=
tsSuperTableUpdateSize
;
len
+=
tsSuperTableUpdateSize
;
int32_t
schemaSize
=
sizeof
(
SSchema
)
*
(
pStable
->
numOfColumns
+
pStable
->
numOfTags
);
int32_t
schemaSize
=
sizeof
(
SSchema
)
*
(
pStable
->
numOfColumns
+
pStable
->
numOfTags
);
...
@@ -529,9 +529,9 @@ static int32_t mnodeSuperTableActionDecode(SSdbOper *pOper) {
...
@@ -529,9 +529,9 @@ static int32_t mnodeSuperTableActionDecode(SSdbOper *pOper) {
return
TSDB_CODE_MND_NOT_SUPER_TABLE
;
return
TSDB_CODE_MND_NOT_SUPER_TABLE
;
}
}
memcpy
(
pStable
->
schema
,
p
Oper
->
rowData
+
len
,
schemaSize
);
memcpy
(
pStable
->
schema
,
p
Row
->
rowData
+
len
,
schemaSize
);
p
Oper
->
pObj
=
pStable
;
p
Row
->
pObj
=
pStable
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -545,19 +545,19 @@ static int32_t mnodeInitSuperTables() {
...
@@ -545,19 +545,19 @@ static int32_t mnodeInitSuperTables() {
tsSuperTableUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
.
info
.
type
;
tsSuperTableUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
.
info
.
type
;
SSdbTableDesc
tableDesc
=
{
SSdbTableDesc
tableDesc
=
{
.
tableId
=
SDB_TABLE_STABLE
,
.
id
=
SDB_TABLE_STABLE
,
.
tableName
=
"stables"
,
.
name
=
"stables"
,
.
hashSessions
=
TSDB_DEFAULT_STABLES_HASH_SIZE
,
.
hashSessions
=
TSDB_DEFAULT_STABLES_HASH_SIZE
,
.
maxRowSize
=
sizeof
(
SSTableObj
)
+
sizeof
(
SSchema
)
*
(
TSDB_MAX_TAGS
+
TSDB_MAX_COLUMNS
+
16
)
+
TSDB_TABLE_FNAME_LEN
,
.
maxRowSize
=
sizeof
(
SSTableObj
)
+
sizeof
(
SSchema
)
*
(
TSDB_MAX_TAGS
+
TSDB_MAX_COLUMNS
+
16
)
+
TSDB_TABLE_FNAME_LEN
,
.
refCountPos
=
(
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
,
.
refCountPos
=
(
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
,
.
keyType
=
SDB_KEY_VAR_STRING
,
.
keyType
=
SDB_KEY_VAR_STRING
,
.
insertFp
=
mnodeSuperTableActionInsert
,
.
fpInsert
=
mnodeSuperTableActionInsert
,
.
deleteFp
=
mnodeSuperTableActionDelete
,
.
fpDelete
=
mnodeSuperTableActionDelete
,
.
updateFp
=
mnodeSuperTableActionUpdate
,
.
fpUpdate
=
mnodeSuperTableActionUpdate
,
.
encodeFp
=
mnodeSuperTableActionEncode
,
.
fpEncode
=
mnodeSuperTableActionEncode
,
.
decodeFp
=
mnodeSuperTableActionDecode
,
.
fpDecode
=
mnodeSuperTableActionDecode
,
.
destroyFp
=
mnodeSuperTableActionDestroy
,
.
fpDestroy
=
mnodeSuperTableActionDestroy
,
.
restoredFp
=
mnodeSuperTableActionRestored
.
fpRestored
=
mnodeSuperTableActionRestored
};
};
tsSuperTableSdb
=
sdbOpenTable
(
&
tableDesc
);
tsSuperTableSdb
=
sdbOpenTable
(
&
tableDesc
);
...
@@ -828,7 +828,7 @@ static int32_t mnodeCreateSuperTableCb(SMnodeMsg *pMsg, int32_t code) {
...
@@ -828,7 +828,7 @@ static int32_t mnodeCreateSuperTableCb(SMnodeMsg *pMsg, int32_t code) {
}
else
{
}
else
{
mError
(
"app:%p:%p, stable:%s, failed to create in sdb, reason:%s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pTable
->
info
.
tableId
,
mError
(
"app:%p:%p, stable:%s, failed to create in sdb, reason:%s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pTable
->
info
.
tableId
,
tstrerror
(
code
));
tstrerror
(
code
));
SSdb
Oper
desc
=
{.
type
=
SDB_OPER_GLOBAL
,
.
pObj
=
pTable
,
.
t
able
=
tsSuperTableSdb
};
SSdb
Row
desc
=
{.
type
=
SDB_OPER_GLOBAL
,
.
pObj
=
pTable
,
.
pT
able
=
tsSuperTableSdb
};
sdbDeleteRow
(
&
desc
);
sdbDeleteRow
(
&
desc
);
}
}
...
@@ -878,16 +878,16 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) {
...
@@ -878,16 +878,16 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) {
pMsg
->
pTable
=
(
STableObj
*
)
pStable
;
pMsg
->
pTable
=
(
STableObj
*
)
pStable
;
mnodeIncTableRef
(
pMsg
->
pTable
);
mnodeIncTableRef
(
pMsg
->
pTable
);
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
table
=
tsSuperTableSdb
,
.
pTable
=
tsSuperTableSdb
,
.
pObj
=
pStable
,
.
pObj
=
pStable
,
.
rowSize
=
sizeof
(
SSTableObj
)
+
schemaSize
,
.
rowSize
=
sizeof
(
SSTableObj
)
+
schemaSize
,
.
pMsg
=
pMsg
,
.
pMsg
=
pMsg
,
.
writeCb
=
mnodeCreateSuperTableCb
.
fpRsp
=
mnodeCreateSuperTableCb
};
};
int32_t
code
=
sdbInsertRow
(
&
oper
);
int32_t
code
=
sdbInsertRow
(
&
row
);
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
mnodeDestroySuperTable
(
pStable
);
mnodeDestroySuperTable
(
pStable
);
pMsg
->
pTable
=
NULL
;
pMsg
->
pTable
=
NULL
;
...
@@ -937,15 +937,15 @@ static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg) {
...
@@ -937,15 +937,15 @@ static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg) {
mnodeDropAllChildTablesInStable
(
pStable
);
mnodeDropAllChildTablesInStable
(
pStable
);
}
}
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
table
=
tsSuperTableSdb
,
.
pTable
=
tsSuperTableSdb
,
.
pObj
=
pStable
,
.
pObj
=
pStable
,
.
pMsg
=
pMsg
,
.
pMsg
=
pMsg
,
.
writeCb
=
mnodeDropSuperTableCb
.
fpRsp
=
mnodeDropSuperTableCb
};
};
int32_t
code
=
sdbDeleteRow
(
&
oper
);
int32_t
code
=
sdbDeleteRow
(
&
row
);
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
mError
(
"app:%p:%p, table:%s, failed to drop, reason:%s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pStable
->
info
.
tableId
,
mError
(
"app:%p:%p, table:%s, failed to drop, reason:%s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pStable
->
info
.
tableId
,
tstrerror
(
code
));
tstrerror
(
code
));
...
@@ -1010,15 +1010,15 @@ static int32_t mnodeAddSuperTableTag(SMnodeMsg *pMsg, SSchema schema[], int32_t
...
@@ -1010,15 +1010,15 @@ static int32_t mnodeAddSuperTableTag(SMnodeMsg *pMsg, SSchema schema[], int32_t
mInfo
(
"app:%p:%p, stable %s, start to add tag %s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pStable
->
info
.
tableId
,
mInfo
(
"app:%p:%p, stable %s, start to add tag %s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pStable
->
info
.
tableId
,
schema
[
0
].
name
);
schema
[
0
].
name
);
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
t
able
=
tsSuperTableSdb
,
.
pT
able
=
tsSuperTableSdb
,
.
pObj
=
pStable
,
.
pObj
=
pStable
,
.
pMsg
=
pMsg
,
.
pMsg
=
pMsg
,
.
writeCb
=
mnodeAddSuperTableTagCb
.
fpRsp
=
mnodeAddSuperTableTagCb
};
};
return
sdbUpdateRow
(
&
oper
);
return
sdbUpdateRow
(
&
row
);
}
}
static
int32_t
mnodeDropSuperTableTagCb
(
SMnodeMsg
*
pMsg
,
int32_t
code
)
{
static
int32_t
mnodeDropSuperTableTagCb
(
SMnodeMsg
*
pMsg
,
int32_t
code
)
{
...
@@ -1044,15 +1044,15 @@ static int32_t mnodeDropSuperTableTag(SMnodeMsg *pMsg, char *tagName) {
...
@@ -1044,15 +1044,15 @@ static int32_t mnodeDropSuperTableTag(SMnodeMsg *pMsg, char *tagName) {
mInfo
(
"app:%p:%p, stable %s, start to drop tag %s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pStable
->
info
.
tableId
,
tagName
);
mInfo
(
"app:%p:%p, stable %s, start to drop tag %s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pStable
->
info
.
tableId
,
tagName
);
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
t
able
=
tsSuperTableSdb
,
.
pT
able
=
tsSuperTableSdb
,
.
pObj
=
pStable
,
.
pObj
=
pStable
,
.
pMsg
=
pMsg
,
.
pMsg
=
pMsg
,
.
writeCb
=
mnodeDropSuperTableTagCb
.
fpRsp
=
mnodeDropSuperTableTagCb
};
};
return
sdbUpdateRow
(
&
oper
);
return
sdbUpdateRow
(
&
row
);
}
}
static
int32_t
mnodeModifySuperTableTagNameCb
(
SMnodeMsg
*
pMsg
,
int32_t
code
)
{
static
int32_t
mnodeModifySuperTableTagNameCb
(
SMnodeMsg
*
pMsg
,
int32_t
code
)
{
...
@@ -1088,15 +1088,15 @@ static int32_t mnodeModifySuperTableTagName(SMnodeMsg *pMsg, char *oldTagName, c
...
@@ -1088,15 +1088,15 @@ static int32_t mnodeModifySuperTableTagName(SMnodeMsg *pMsg, char *oldTagName, c
mInfo
(
"app:%p:%p, stable %s, start to modify tag %s to %s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pStable
->
info
.
tableId
,
mInfo
(
"app:%p:%p, stable %s, start to modify tag %s to %s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pStable
->
info
.
tableId
,
oldTagName
,
newTagName
);
oldTagName
,
newTagName
);
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
t
able
=
tsSuperTableSdb
,
.
pT
able
=
tsSuperTableSdb
,
.
pObj
=
pStable
,
.
pObj
=
pStable
,
.
pMsg
=
pMsg
,
.
pMsg
=
pMsg
,
.
writeCb
=
mnodeModifySuperTableTagNameCb
.
fpRsp
=
mnodeModifySuperTableTagNameCb
};
};
return
sdbUpdateRow
(
&
oper
);
return
sdbUpdateRow
(
&
row
);
}
}
static
int32_t
mnodeFindSuperTableColumnIndex
(
SSTableObj
*
pStable
,
char
*
colName
)
{
static
int32_t
mnodeFindSuperTableColumnIndex
(
SSTableObj
*
pStable
,
char
*
colName
)
{
...
@@ -1162,15 +1162,15 @@ static int32_t mnodeAddSuperTableColumn(SMnodeMsg *pMsg, SSchema schema[], int32
...
@@ -1162,15 +1162,15 @@ static int32_t mnodeAddSuperTableColumn(SMnodeMsg *pMsg, SSchema schema[], int32
mInfo
(
"app:%p:%p, stable %s, start to add column"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pStable
->
info
.
tableId
);
mInfo
(
"app:%p:%p, stable %s, start to add column"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pStable
->
info
.
tableId
);
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
t
able
=
tsSuperTableSdb
,
.
pT
able
=
tsSuperTableSdb
,
.
pObj
=
pStable
,
.
pObj
=
pStable
,
.
pMsg
=
pMsg
,
.
pMsg
=
pMsg
,
.
writeCb
=
mnodeAddSuperTableColumnCb
.
fpRsp
=
mnodeAddSuperTableColumnCb
};
};
return
sdbUpdateRow
(
&
oper
);
return
sdbUpdateRow
(
&
row
);
}
}
static
int32_t
mnodeDropSuperTableColumnCb
(
SMnodeMsg
*
pMsg
,
int32_t
code
)
{
static
int32_t
mnodeDropSuperTableColumnCb
(
SMnodeMsg
*
pMsg
,
int32_t
code
)
{
...
@@ -1207,15 +1207,15 @@ static int32_t mnodeDropSuperTableColumn(SMnodeMsg *pMsg, char *colName) {
...
@@ -1207,15 +1207,15 @@ static int32_t mnodeDropSuperTableColumn(SMnodeMsg *pMsg, char *colName) {
mInfo
(
"app:%p:%p, stable %s, start to delete column"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pStable
->
info
.
tableId
);
mInfo
(
"app:%p:%p, stable %s, start to delete column"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pStable
->
info
.
tableId
);
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
t
able
=
tsSuperTableSdb
,
.
pT
able
=
tsSuperTableSdb
,
.
pObj
=
pStable
,
.
pObj
=
pStable
,
.
pMsg
=
pMsg
,
.
pMsg
=
pMsg
,
.
writeCb
=
mnodeDropSuperTableColumnCb
.
fpRsp
=
mnodeDropSuperTableColumnCb
};
};
return
sdbUpdateRow
(
&
oper
);
return
sdbUpdateRow
(
&
row
);
}
}
static
int32_t
mnodeChangeSuperTableColumnCb
(
SMnodeMsg
*
pMsg
,
int32_t
code
)
{
static
int32_t
mnodeChangeSuperTableColumnCb
(
SMnodeMsg
*
pMsg
,
int32_t
code
)
{
...
@@ -1251,15 +1251,15 @@ static int32_t mnodeChangeSuperTableColumn(SMnodeMsg *pMsg, char *oldName, char
...
@@ -1251,15 +1251,15 @@ static int32_t mnodeChangeSuperTableColumn(SMnodeMsg *pMsg, char *oldName, char
mInfo
(
"app:%p:%p, stable %s, start to modify column %s to %s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pStable
->
info
.
tableId
,
mInfo
(
"app:%p:%p, stable %s, start to modify column %s to %s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pStable
->
info
.
tableId
,
oldName
,
newName
);
oldName
,
newName
);
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
t
able
=
tsSuperTableSdb
,
.
pT
able
=
tsSuperTableSdb
,
.
pObj
=
pStable
,
.
pObj
=
pStable
,
.
pMsg
=
pMsg
,
.
pMsg
=
pMsg
,
.
writeCb
=
mnodeChangeSuperTableColumnCb
.
fpRsp
=
mnodeChangeSuperTableColumnCb
};
};
return
sdbUpdateRow
(
&
oper
);
return
sdbUpdateRow
(
&
row
);
}
}
// show super tables
// show super tables
...
@@ -1417,12 +1417,12 @@ void mnodeDropAllSuperTables(SDbObj *pDropDb) {
...
@@ -1417,12 +1417,12 @@ void mnodeDropAllSuperTables(SDbObj *pDropDb) {
if
(
pTable
==
NULL
)
break
;
if
(
pTable
==
NULL
)
break
;
if
(
strncmp
(
prefix
,
pTable
->
info
.
tableId
,
prefixLen
)
==
0
)
{
if
(
strncmp
(
prefix
,
pTable
->
info
.
tableId
,
prefixLen
)
==
0
)
{
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_LOCAL
,
.
type
=
SDB_OPER_LOCAL
,
.
t
able
=
tsSuperTableSdb
,
.
pT
able
=
tsSuperTableSdb
,
.
pObj
=
pTable
,
.
pObj
=
pTable
,
};
};
sdbDeleteRow
(
&
oper
);
sdbDeleteRow
(
&
row
);
numOfTables
++
;
numOfTables
++
;
}
}
...
@@ -1694,7 +1694,7 @@ static int32_t mnodeDoCreateChildTableCb(SMnodeMsg *pMsg, int32_t code) {
...
@@ -1694,7 +1694,7 @@ static int32_t mnodeDoCreateChildTableCb(SMnodeMsg *pMsg, int32_t code) {
}
else
{
}
else
{
mError
(
"app:%p:%p, table:%s, failed to create table sid:%d, uid:%"
PRIu64
", reason:%s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
mError
(
"app:%p:%p, table:%s, failed to create table sid:%d, uid:%"
PRIu64
", reason:%s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pTable
->
info
.
tableId
,
pTable
->
tid
,
pTable
->
uid
,
tstrerror
(
code
));
pTable
->
info
.
tableId
,
pTable
->
tid
,
pTable
->
uid
,
tstrerror
(
code
));
SSdb
Oper
desc
=
{.
type
=
SDB_OPER_GLOBAL
,
.
pObj
=
pTable
,
.
t
able
=
tsChildTableSdb
};
SSdb
Row
desc
=
{.
type
=
SDB_OPER_GLOBAL
,
.
pObj
=
pTable
,
.
pT
able
=
tsChildTableSdb
};
sdbDeleteRow
(
&
desc
);
sdbDeleteRow
(
&
desc
);
return
code
;
return
code
;
}
}
...
@@ -1780,12 +1780,12 @@ static int32_t mnodeDoCreateChildTable(SMnodeMsg *pMsg, int32_t tid) {
...
@@ -1780,12 +1780,12 @@ static int32_t mnodeDoCreateChildTable(SMnodeMsg *pMsg, int32_t tid) {
pMsg
->
pTable
=
(
STableObj
*
)
pTable
;
pMsg
->
pTable
=
(
STableObj
*
)
pTable
;
mnodeIncTableRef
(
pMsg
->
pTable
);
mnodeIncTableRef
(
pMsg
->
pTable
);
SSdb
Oper
desc
=
{
SSdb
Row
desc
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
pObj
=
pTable
,
.
pObj
=
pTable
,
.
t
able
=
tsChildTableSdb
,
.
pT
able
=
tsChildTableSdb
,
.
pMsg
=
pMsg
,
.
pMsg
=
pMsg
,
.
reqFp
=
mnodeDoCreateChildTableFp
.
fpReq
=
mnodeDoCreateChildTableFp
};
};
int32_t
code
=
sdbInsertRow
(
&
desc
);
int32_t
code
=
sdbInsertRow
(
&
desc
);
...
@@ -1901,15 +1901,15 @@ static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg) {
...
@@ -1901,15 +1901,15 @@ static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg) {
return
TSDB_CODE_MND_APP_ERROR
;
return
TSDB_CODE_MND_APP_ERROR
;
}
}
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
t
able
=
tsChildTableSdb
,
.
pT
able
=
tsChildTableSdb
,
.
pObj
=
pTable
,
.
pObj
=
pTable
,
.
pMsg
=
pMsg
,
.
pMsg
=
pMsg
,
.
writeCb
=
mnodeDropChildTableCb
.
fpRsp
=
mnodeDropChildTableCb
};
};
int32_t
code
=
sdbDeleteRow
(
&
oper
);
int32_t
code
=
sdbDeleteRow
(
&
row
);
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
mError
(
"app:%p:%p, ctable:%s, failed to drop, reason:%s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pTable
->
info
.
tableId
,
mError
(
"app:%p:%p, ctable:%s, failed to drop, reason:%s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pTable
->
info
.
tableId
,
tstrerror
(
code
));
tstrerror
(
code
));
...
@@ -2005,15 +2005,15 @@ static int32_t mnodeAddNormalTableColumn(SMnodeMsg *pMsg, SSchema schema[], int3
...
@@ -2005,15 +2005,15 @@ static int32_t mnodeAddNormalTableColumn(SMnodeMsg *pMsg, SSchema schema[], int3
mInfo
(
"app:%p:%p, ctable %s, start to add column"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pTable
->
info
.
tableId
);
mInfo
(
"app:%p:%p, ctable %s, start to add column"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pTable
->
info
.
tableId
);
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
t
able
=
tsChildTableSdb
,
.
pT
able
=
tsChildTableSdb
,
.
pObj
=
pTable
,
.
pObj
=
pTable
,
.
pMsg
=
pMsg
,
.
pMsg
=
pMsg
,
.
writeCb
=
mnodeAlterNormalTableColumnCb
.
fpRsp
=
mnodeAlterNormalTableColumnCb
};
};
return
sdbUpdateRow
(
&
oper
);
return
sdbUpdateRow
(
&
row
);
}
}
static
int32_t
mnodeDropNormalTableColumn
(
SMnodeMsg
*
pMsg
,
char
*
colName
)
{
static
int32_t
mnodeDropNormalTableColumn
(
SMnodeMsg
*
pMsg
,
char
*
colName
)
{
...
@@ -2038,15 +2038,15 @@ static int32_t mnodeDropNormalTableColumn(SMnodeMsg *pMsg, char *colName) {
...
@@ -2038,15 +2038,15 @@ static int32_t mnodeDropNormalTableColumn(SMnodeMsg *pMsg, char *colName) {
mInfo
(
"app:%p:%p, ctable %s, start to drop column %s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pTable
->
info
.
tableId
,
colName
);
mInfo
(
"app:%p:%p, ctable %s, start to drop column %s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pTable
->
info
.
tableId
,
colName
);
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
t
able
=
tsChildTableSdb
,
.
pT
able
=
tsChildTableSdb
,
.
pObj
=
pTable
,
.
pObj
=
pTable
,
.
pMsg
=
pMsg
,
.
pMsg
=
pMsg
,
.
writeCb
=
mnodeAlterNormalTableColumnCb
.
fpRsp
=
mnodeAlterNormalTableColumnCb
};
};
return
sdbUpdateRow
(
&
oper
);
return
sdbUpdateRow
(
&
row
);
}
}
static
int32_t
mnodeChangeNormalTableColumn
(
SMnodeMsg
*
pMsg
,
char
*
oldName
,
char
*
newName
)
{
static
int32_t
mnodeChangeNormalTableColumn
(
SMnodeMsg
*
pMsg
,
char
*
oldName
,
char
*
newName
)
{
...
@@ -2075,15 +2075,15 @@ static int32_t mnodeChangeNormalTableColumn(SMnodeMsg *pMsg, char *oldName, char
...
@@ -2075,15 +2075,15 @@ static int32_t mnodeChangeNormalTableColumn(SMnodeMsg *pMsg, char *oldName, char
mInfo
(
"app:%p:%p, ctable %s, start to modify column %s to %s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pTable
->
info
.
tableId
,
mInfo
(
"app:%p:%p, ctable %s, start to modify column %s to %s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pTable
->
info
.
tableId
,
oldName
,
newName
);
oldName
,
newName
);
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
t
able
=
tsChildTableSdb
,
.
pT
able
=
tsChildTableSdb
,
.
pObj
=
pTable
,
.
pObj
=
pTable
,
.
pMsg
=
pMsg
,
.
pMsg
=
pMsg
,
.
writeCb
=
mnodeAlterNormalTableColumnCb
.
fpRsp
=
mnodeAlterNormalTableColumnCb
};
};
return
sdbUpdateRow
(
&
oper
);
return
sdbUpdateRow
(
&
row
);
}
}
static
int32_t
mnodeSetSchemaFromNormalTable
(
SSchema
*
pSchema
,
SCTableObj
*
pTable
)
{
static
int32_t
mnodeSetSchemaFromNormalTable
(
SSchema
*
pSchema
,
SCTableObj
*
pTable
)
{
...
@@ -2218,12 +2218,12 @@ void mnodeDropAllChildTablesInVgroups(SVgObj *pVgroup) {
...
@@ -2218,12 +2218,12 @@ void mnodeDropAllChildTablesInVgroups(SVgObj *pVgroup) {
if
(
pTable
==
NULL
)
break
;
if
(
pTable
==
NULL
)
break
;
if
(
pTable
->
vgId
==
pVgroup
->
vgId
)
{
if
(
pTable
->
vgId
==
pVgroup
->
vgId
)
{
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_LOCAL
,
.
type
=
SDB_OPER_LOCAL
,
.
t
able
=
tsChildTableSdb
,
.
pT
able
=
tsChildTableSdb
,
.
pObj
=
pTable
,
.
pObj
=
pTable
,
};
};
sdbDeleteRow
(
&
oper
);
sdbDeleteRow
(
&
row
);
numOfTables
++
;
numOfTables
++
;
}
}
mnodeDecTableRef
(
pTable
);
mnodeDecTableRef
(
pTable
);
...
@@ -2251,12 +2251,12 @@ void mnodeDropAllChildTables(SDbObj *pDropDb) {
...
@@ -2251,12 +2251,12 @@ void mnodeDropAllChildTables(SDbObj *pDropDb) {
if
(
pTable
==
NULL
)
break
;
if
(
pTable
==
NULL
)
break
;
if
(
strncmp
(
prefix
,
pTable
->
info
.
tableId
,
prefixLen
)
==
0
)
{
if
(
strncmp
(
prefix
,
pTable
->
info
.
tableId
,
prefixLen
)
==
0
)
{
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_LOCAL
,
.
type
=
SDB_OPER_LOCAL
,
.
t
able
=
tsChildTableSdb
,
.
pT
able
=
tsChildTableSdb
,
.
pObj
=
pTable
,
.
pObj
=
pTable
,
};
};
sdbDeleteRow
(
&
oper
);
sdbDeleteRow
(
&
row
);
numOfTables
++
;
numOfTables
++
;
}
}
mnodeDecTableRef
(
pTable
);
mnodeDecTableRef
(
pTable
);
...
@@ -2280,12 +2280,12 @@ static void mnodeDropAllChildTablesInStable(SSTableObj *pStable) {
...
@@ -2280,12 +2280,12 @@ static void mnodeDropAllChildTablesInStable(SSTableObj *pStable) {
if
(
pTable
==
NULL
)
break
;
if
(
pTable
==
NULL
)
break
;
if
(
pTable
->
superTable
==
pStable
)
{
if
(
pTable
->
superTable
==
pStable
)
{
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_LOCAL
,
.
type
=
SDB_OPER_LOCAL
,
.
t
able
=
tsChildTableSdb
,
.
pT
able
=
tsChildTableSdb
,
.
pObj
=
pTable
,
.
pObj
=
pTable
,
};
};
sdbDeleteRow
(
&
oper
);
sdbDeleteRow
(
&
row
);
numOfTables
++
;
numOfTables
++
;
}
}
...
@@ -2410,15 +2410,15 @@ static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg) {
...
@@ -2410,15 +2410,15 @@ static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg) {
}
}
if
(
rpcMsg
->
code
==
TSDB_CODE_SUCCESS
||
rpcMsg
->
code
==
TSDB_CODE_TDB_TABLE_ALREADY_EXIST
)
{
if
(
rpcMsg
->
code
==
TSDB_CODE_SUCCESS
||
rpcMsg
->
code
==
TSDB_CODE_TDB_TABLE_ALREADY_EXIST
)
{
SSdb
Oper
desc
=
{
SSdb
Row
desc
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
pObj
=
pTable
,
.
pObj
=
pTable
,
.
t
able
=
tsChildTableSdb
,
.
pT
able
=
tsChildTableSdb
,
.
pMsg
=
mnodeMsg
,
.
pMsg
=
mnodeMsg
,
.
writeCb
=
mnodeDoCreateChildTableCb
.
fpRsp
=
mnodeDoCreateChildTableCb
};
};
int32_t
code
=
sdbInsertRow
Imp
(
&
desc
);
int32_t
code
=
sdbInsertRow
ToQueue
(
&
desc
);
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
mnodeMsg
->
pTable
=
NULL
;
mnodeMsg
->
pTable
=
NULL
;
mnodeDestroyChildTable
(
pTable
);
mnodeDestroyChildTable
(
pTable
);
...
@@ -2440,8 +2440,8 @@ static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg) {
...
@@ -2440,8 +2440,8 @@ static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg) {
mnodeMsg
->
rpcMsg
.
ahandle
,
mnodeMsg
,
pTable
->
info
.
tableId
,
pTable
->
vgId
,
pTable
->
tid
,
pTable
->
uid
,
mnodeMsg
->
rpcMsg
.
ahandle
,
mnodeMsg
,
pTable
->
info
.
tableId
,
pTable
->
vgId
,
pTable
->
tid
,
pTable
->
uid
,
tstrerror
(
rpcMsg
->
code
),
mnodeMsg
->
rpcMsg
.
handle
,
mnodeMsg
->
incomingTs
,
sec
,
mnodeMsg
->
retry
);
tstrerror
(
rpcMsg
->
code
),
mnodeMsg
->
rpcMsg
.
handle
,
mnodeMsg
->
incomingTs
,
sec
,
mnodeMsg
->
retry
);
SSdb
Oper
oper
=
{.
type
=
SDB_OPER_GLOBAL
,
.
t
able
=
tsChildTableSdb
,
.
pObj
=
pTable
};
SSdb
Row
row
=
{.
type
=
SDB_OPER_GLOBAL
,
.
pT
able
=
tsChildTableSdb
,
.
pObj
=
pTable
};
sdbDeleteRow
(
&
oper
);
sdbDeleteRow
(
&
row
);
if
(
rpcMsg
->
code
==
TSDB_CODE_APP_NOT_READY
)
{
if
(
rpcMsg
->
code
==
TSDB_CODE_APP_NOT_READY
)
{
//Avoid retry again in client
//Avoid retry again in client
...
...
src/mnode/src/mnodeUser.c
浏览文件 @
ea3aae75
...
@@ -42,13 +42,13 @@ static int32_t mnodeProcessAlterUserMsg(SMnodeMsg *pMsg);
...
@@ -42,13 +42,13 @@ static int32_t mnodeProcessAlterUserMsg(SMnodeMsg *pMsg);
static
int32_t
mnodeProcessDropUserMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnodeProcessDropUserMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnodeProcessAuthMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnodeProcessAuthMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnodeUserActionDestroy
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeUserActionDestroy
(
SSdb
Row
*
pRow
)
{
tfree
(
p
Oper
->
pObj
);
tfree
(
p
Row
->
pObj
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeUserActionInsert
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeUserActionInsert
(
SSdb
Row
*
pRow
)
{
SUserObj
*
pUser
=
p
Oper
->
pObj
;
SUserObj
*
pUser
=
p
Row
->
pObj
;
SAcctObj
*
pAcct
=
mnodeGetAcct
(
pUser
->
acct
);
SAcctObj
*
pAcct
=
mnodeGetAcct
(
pUser
->
acct
);
if
(
pAcct
!=
NULL
)
{
if
(
pAcct
!=
NULL
)
{
...
@@ -62,8 +62,8 @@ static int32_t mnodeUserActionInsert(SSdbOper *pOper) {
...
@@ -62,8 +62,8 @@ static int32_t mnodeUserActionInsert(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeUserActionDelete
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeUserActionDelete
(
SSdb
Row
*
pRow
)
{
SUserObj
*
pUser
=
p
Oper
->
pObj
;
SUserObj
*
pUser
=
p
Row
->
pObj
;
SAcctObj
*
pAcct
=
mnodeGetAcct
(
pUser
->
acct
);
SAcctObj
*
pAcct
=
mnodeGetAcct
(
pUser
->
acct
);
if
(
pAcct
!=
NULL
)
{
if
(
pAcct
!=
NULL
)
{
...
@@ -74,8 +74,8 @@ static int32_t mnodeUserActionDelete(SSdbOper *pOper) {
...
@@ -74,8 +74,8 @@ static int32_t mnodeUserActionDelete(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeUserActionUpdate
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeUserActionUpdate
(
SSdb
Row
*
pRow
)
{
SUserObj
*
pUser
=
p
Oper
->
pObj
;
SUserObj
*
pUser
=
p
Row
->
pObj
;
SUserObj
*
pSaved
=
mnodeGetUser
(
pUser
->
user
);
SUserObj
*
pSaved
=
mnodeGetUser
(
pUser
->
user
);
if
(
pUser
!=
pSaved
)
{
if
(
pUser
!=
pSaved
)
{
memcpy
(
pSaved
,
pUser
,
tsUserUpdateSize
);
memcpy
(
pSaved
,
pUser
,
tsUserUpdateSize
);
...
@@ -85,19 +85,19 @@ static int32_t mnodeUserActionUpdate(SSdbOper *pOper) {
...
@@ -85,19 +85,19 @@ static int32_t mnodeUserActionUpdate(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeUserActionEncode
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeUserActionEncode
(
SSdb
Row
*
pRow
)
{
SUserObj
*
pUser
=
p
Oper
->
pObj
;
SUserObj
*
pUser
=
p
Row
->
pObj
;
memcpy
(
p
Oper
->
rowData
,
pUser
,
tsUserUpdateSize
);
memcpy
(
p
Row
->
rowData
,
pUser
,
tsUserUpdateSize
);
p
Oper
->
rowSize
=
tsUserUpdateSize
;
p
Row
->
rowSize
=
tsUserUpdateSize
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeUserActionDecode
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeUserActionDecode
(
SSdb
Row
*
pRow
)
{
SUserObj
*
pUser
=
(
SUserObj
*
)
calloc
(
1
,
sizeof
(
SUserObj
));
SUserObj
*
pUser
=
(
SUserObj
*
)
calloc
(
1
,
sizeof
(
SUserObj
));
if
(
pUser
==
NULL
)
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
if
(
pUser
==
NULL
)
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
memcpy
(
pUser
,
p
Oper
->
rowData
,
tsUserUpdateSize
);
memcpy
(
pUser
,
p
Row
->
rowData
,
tsUserUpdateSize
);
p
Oper
->
pObj
=
pUser
;
p
Row
->
pObj
=
pUser
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -150,25 +150,25 @@ int32_t mnodeInitUsers() {
...
@@ -150,25 +150,25 @@ int32_t mnodeInitUsers() {
SUserObj
tObj
;
SUserObj
tObj
;
tsUserUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
;
tsUserUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
;
SSdbTableDesc
tableD
esc
=
{
SSdbTableDesc
d
esc
=
{
.
tableId
=
SDB_TABLE_USER
,
.
id
=
SDB_TABLE_USER
,
.
tableName
=
"users"
,
.
name
=
"users"
,
.
hashSessions
=
TSDB_DEFAULT_USERS_HASH_SIZE
,
.
hashSessions
=
TSDB_DEFAULT_USERS_HASH_SIZE
,
.
maxRowSize
=
tsUserUpdateSize
,
.
maxRowSize
=
tsUserUpdateSize
,
.
refCountPos
=
(
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
,
.
refCountPos
=
(
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
,
.
keyType
=
SDB_KEY_STRING
,
.
keyType
=
SDB_KEY_STRING
,
.
insertFp
=
mnodeUserActionInsert
,
.
fpInsert
=
mnodeUserActionInsert
,
.
deleteFp
=
mnodeUserActionDelete
,
.
fpDelete
=
mnodeUserActionDelete
,
.
updateFp
=
mnodeUserActionUpdate
,
.
fpUpdate
=
mnodeUserActionUpdate
,
.
encodeFp
=
mnodeUserActionEncode
,
.
fpEncode
=
mnodeUserActionEncode
,
.
decodeFp
=
mnodeUserActionDecode
,
.
fpDecode
=
mnodeUserActionDecode
,
.
destroyFp
=
mnodeUserActionDestroy
,
.
fpDestroy
=
mnodeUserActionDestroy
,
.
restoredFp
=
mnodeUserActionRestored
.
fpRestored
=
mnodeUserActionRestored
};
};
tsUserSdb
=
sdbOpenTable
(
&
tableD
esc
);
tsUserSdb
=
sdbOpenTable
(
&
d
esc
);
if
(
tsUserSdb
==
NULL
)
{
if
(
tsUserSdb
==
NULL
)
{
mError
(
"table:%s, failed to create hash"
,
tableDesc
.
tableN
ame
);
mError
(
"table:%s, failed to create hash"
,
desc
.
n
ame
);
return
-
1
;
return
-
1
;
}
}
...
@@ -179,7 +179,7 @@ int32_t mnodeInitUsers() {
...
@@ -179,7 +179,7 @@ int32_t mnodeInitUsers() {
mnodeAddShowRetrieveHandle
(
TSDB_MGMT_TABLE_USER
,
mnodeRetrieveUsers
);
mnodeAddShowRetrieveHandle
(
TSDB_MGMT_TABLE_USER
,
mnodeRetrieveUsers
);
mnodeAddPeerMsgHandle
(
TSDB_MSG_TYPE_DM_AUTH
,
mnodeProcessAuthMsg
);
mnodeAddPeerMsgHandle
(
TSDB_MSG_TYPE_DM_AUTH
,
mnodeProcessAuthMsg
);
mDebug
(
"table:%s, hash is created"
,
tableDesc
.
tableN
ame
);
mDebug
(
"table:%s, hash is created"
,
desc
.
n
ame
);
return
0
;
return
0
;
}
}
...
@@ -205,14 +205,14 @@ void mnodeDecUserRef(SUserObj *pUser) {
...
@@ -205,14 +205,14 @@ void mnodeDecUserRef(SUserObj *pUser) {
}
}
static
int32_t
mnodeUpdateUser
(
SUserObj
*
pUser
,
void
*
pMsg
)
{
static
int32_t
mnodeUpdateUser
(
SUserObj
*
pUser
,
void
*
pMsg
)
{
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
t
able
=
tsUserSdb
,
.
pT
able
=
tsUserSdb
,
.
pObj
=
pUser
,
.
pObj
=
pUser
,
.
pMsg
=
pMsg
.
pMsg
=
pMsg
};
};
int32_t
code
=
sdbUpdateRow
(
&
oper
);
int32_t
code
=
sdbUpdateRow
(
&
row
);
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
mError
(
"user:%s, failed to alter by %s, reason:%s"
,
pUser
->
user
,
mnodeGetUserFromMsg
(
pMsg
),
tstrerror
(
code
));
mError
(
"user:%s, failed to alter by %s, reason:%s"
,
pUser
->
user
,
mnodeGetUserFromMsg
(
pMsg
),
tstrerror
(
code
));
}
else
{
}
else
{
...
@@ -259,15 +259,15 @@ int32_t mnodeCreateUser(SAcctObj *pAcct, char *name, char *pass, void *pMsg) {
...
@@ -259,15 +259,15 @@ int32_t mnodeCreateUser(SAcctObj *pAcct, char *name, char *pass, void *pMsg) {
pUser
->
superAuth
=
1
;
pUser
->
superAuth
=
1
;
}
}
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
t
able
=
tsUserSdb
,
.
pT
able
=
tsUserSdb
,
.
pObj
=
pUser
,
.
pObj
=
pUser
,
.
rowSize
=
sizeof
(
SUserObj
),
.
rowSize
=
sizeof
(
SUserObj
),
.
pMsg
=
pMsg
.
pMsg
=
pMsg
};
};
code
=
sdbInsertRow
(
&
oper
);
code
=
sdbInsertRow
(
&
row
);
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
mError
(
"user:%s, failed to create by %s, reason:%s"
,
pUser
->
user
,
mnodeGetUserFromMsg
(
pMsg
),
tstrerror
(
code
));
mError
(
"user:%s, failed to create by %s, reason:%s"
,
pUser
->
user
,
mnodeGetUserFromMsg
(
pMsg
),
tstrerror
(
code
));
tfree
(
pUser
);
tfree
(
pUser
);
...
@@ -279,14 +279,14 @@ int32_t mnodeCreateUser(SAcctObj *pAcct, char *name, char *pass, void *pMsg) {
...
@@ -279,14 +279,14 @@ int32_t mnodeCreateUser(SAcctObj *pAcct, char *name, char *pass, void *pMsg) {
}
}
static
int32_t
mnodeDropUser
(
SUserObj
*
pUser
,
void
*
pMsg
)
{
static
int32_t
mnodeDropUser
(
SUserObj
*
pUser
,
void
*
pMsg
)
{
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
t
able
=
tsUserSdb
,
.
pT
able
=
tsUserSdb
,
.
pObj
=
pUser
,
.
pObj
=
pUser
,
.
pMsg
=
pMsg
.
pMsg
=
pMsg
};
};
int32_t
code
=
sdbDeleteRow
(
&
oper
);
int32_t
code
=
sdbDeleteRow
(
&
row
);
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
mError
(
"user:%s, failed to drop by %s, reason:%s"
,
pUser
->
user
,
mnodeGetUserFromMsg
(
pMsg
),
tstrerror
(
code
));
mError
(
"user:%s, failed to drop by %s, reason:%s"
,
pUser
->
user
,
mnodeGetUserFromMsg
(
pMsg
),
tstrerror
(
code
));
}
else
{
}
else
{
...
@@ -562,12 +562,12 @@ void mnodeDropAllUsers(SAcctObj *pAcct) {
...
@@ -562,12 +562,12 @@ void mnodeDropAllUsers(SAcctObj *pAcct) {
if
(
pUser
==
NULL
)
break
;
if
(
pUser
==
NULL
)
break
;
if
(
strncmp
(
pUser
->
acct
,
pAcct
->
user
,
acctNameLen
)
==
0
)
{
if
(
strncmp
(
pUser
->
acct
,
pAcct
->
user
,
acctNameLen
)
==
0
)
{
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_LOCAL
,
.
type
=
SDB_OPER_LOCAL
,
.
t
able
=
tsUserSdb
,
.
pT
able
=
tsUserSdb
,
.
pObj
=
pUser
,
.
pObj
=
pUser
,
};
};
sdbDeleteRow
(
&
oper
);
sdbDeleteRow
(
&
row
);
numOfUsers
++
;
numOfUsers
++
;
}
}
...
...
src/mnode/src/mnodeVgroup.c
浏览文件 @
ea3aae75
...
@@ -72,13 +72,13 @@ static void mnodeDestroyVgroup(SVgObj *pVgroup) {
...
@@ -72,13 +72,13 @@ static void mnodeDestroyVgroup(SVgObj *pVgroup) {
tfree
(
pVgroup
);
tfree
(
pVgroup
);
}
}
static
int32_t
mnodeVgroupActionDestroy
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeVgroupActionDestroy
(
SSdb
Row
*
pRow
)
{
mnodeDestroyVgroup
(
p
Oper
->
pObj
);
mnodeDestroyVgroup
(
p
Row
->
pObj
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeVgroupActionInsert
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeVgroupActionInsert
(
SSdb
Row
*
pRow
)
{
SVgObj
*
pVgroup
=
p
Oper
->
pObj
;
SVgObj
*
pVgroup
=
p
Row
->
pObj
;
// refer to db
// refer to db
SDbObj
*
pDb
=
mnodeGetDb
(
pVgroup
->
dbName
);
SDbObj
*
pDb
=
mnodeGetDb
(
pVgroup
->
dbName
);
...
@@ -115,8 +115,8 @@ static int32_t mnodeVgroupActionInsert(SSdbOper *pOper) {
...
@@ -115,8 +115,8 @@ static int32_t mnodeVgroupActionInsert(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeVgroupActionDelete
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeVgroupActionDelete
(
SSdb
Row
*
pRow
)
{
SVgObj
*
pVgroup
=
p
Oper
->
pObj
;
SVgObj
*
pVgroup
=
p
Row
->
pObj
;
if
(
pVgroup
->
pDb
==
NULL
)
{
if
(
pVgroup
->
pDb
==
NULL
)
{
mError
(
"vgId:%d, db:%s is not exist while insert into hash"
,
pVgroup
->
vgId
,
pVgroup
->
dbName
);
mError
(
"vgId:%d, db:%s is not exist while insert into hash"
,
pVgroup
->
vgId
,
pVgroup
->
dbName
);
...
@@ -137,8 +137,8 @@ static int32_t mnodeVgroupActionDelete(SSdbOper *pOper) {
...
@@ -137,8 +137,8 @@ static int32_t mnodeVgroupActionDelete(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeVgroupActionUpdate
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeVgroupActionUpdate
(
SSdb
Row
*
pRow
)
{
SVgObj
*
pNew
=
p
Oper
->
pObj
;
SVgObj
*
pNew
=
p
Row
->
pObj
;
SVgObj
*
pVgroup
=
mnodeGetVgroup
(
pNew
->
vgId
);
SVgObj
*
pVgroup
=
mnodeGetVgroup
(
pNew
->
vgId
);
if
(
pVgroup
!=
pNew
)
{
if
(
pVgroup
!=
pNew
)
{
...
@@ -176,25 +176,25 @@ static int32_t mnodeVgroupActionUpdate(SSdbOper *pOper) {
...
@@ -176,25 +176,25 @@ static int32_t mnodeVgroupActionUpdate(SSdbOper *pOper) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeVgroupActionEncode
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeVgroupActionEncode
(
SSdb
Row
*
pRow
)
{
SVgObj
*
pVgroup
=
p
Oper
->
pObj
;
SVgObj
*
pVgroup
=
p
Row
->
pObj
;
memcpy
(
p
Oper
->
rowData
,
pVgroup
,
tsVgUpdateSize
);
memcpy
(
p
Row
->
rowData
,
pVgroup
,
tsVgUpdateSize
);
SVgObj
*
pTmpVgroup
=
p
Oper
->
rowData
;
SVgObj
*
pTmpVgroup
=
p
Row
->
rowData
;
for
(
int32_t
i
=
0
;
i
<
TSDB_MAX_REPLICA
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
TSDB_MAX_REPLICA
;
++
i
)
{
pTmpVgroup
->
vnodeGid
[
i
].
pDnode
=
NULL
;
pTmpVgroup
->
vnodeGid
[
i
].
pDnode
=
NULL
;
pTmpVgroup
->
vnodeGid
[
i
].
role
=
0
;
pTmpVgroup
->
vnodeGid
[
i
].
role
=
0
;
}
}
p
Oper
->
rowSize
=
tsVgUpdateSize
;
p
Row
->
rowSize
=
tsVgUpdateSize
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
mnodeVgroupActionDecode
(
SSdb
Oper
*
pOper
)
{
static
int32_t
mnodeVgroupActionDecode
(
SSdb
Row
*
pRow
)
{
SVgObj
*
pVgroup
=
(
SVgObj
*
)
calloc
(
1
,
sizeof
(
SVgObj
));
SVgObj
*
pVgroup
=
(
SVgObj
*
)
calloc
(
1
,
sizeof
(
SVgObj
));
if
(
pVgroup
==
NULL
)
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
if
(
pVgroup
==
NULL
)
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
memcpy
(
pVgroup
,
p
Oper
->
rowData
,
tsVgUpdateSize
);
memcpy
(
pVgroup
,
p
Row
->
rowData
,
tsVgUpdateSize
);
p
Oper
->
pObj
=
pVgroup
;
p
Row
->
pObj
=
pVgroup
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -206,23 +206,23 @@ int32_t mnodeInitVgroups() {
...
@@ -206,23 +206,23 @@ int32_t mnodeInitVgroups() {
SVgObj
tObj
;
SVgObj
tObj
;
tsVgUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
;
tsVgUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
;
SSdbTableDesc
tableD
esc
=
{
SSdbTableDesc
d
esc
=
{
.
tableId
=
SDB_TABLE_VGROUP
,
.
id
=
SDB_TABLE_VGROUP
,
.
tableName
=
"vgroups"
,
.
name
=
"vgroups"
,
.
hashSessions
=
TSDB_DEFAULT_VGROUPS_HASH_SIZE
,
.
hashSessions
=
TSDB_DEFAULT_VGROUPS_HASH_SIZE
,
.
maxRowSize
=
tsVgUpdateSize
,
.
maxRowSize
=
tsVgUpdateSize
,
.
refCountPos
=
(
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
,
.
refCountPos
=
(
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
,
.
keyType
=
SDB_KEY_AUTO
,
.
keyType
=
SDB_KEY_AUTO
,
.
insertFp
=
mnodeVgroupActionInsert
,
.
fpInsert
=
mnodeVgroupActionInsert
,
.
deleteFp
=
mnodeVgroupActionDelete
,
.
fpDelete
=
mnodeVgroupActionDelete
,
.
updateFp
=
mnodeVgroupActionUpdate
,
.
fpUpdate
=
mnodeVgroupActionUpdate
,
.
encodeFp
=
mnodeVgroupActionEncode
,
.
fpEncode
=
mnodeVgroupActionEncode
,
.
decodeFp
=
mnodeVgroupActionDecode
,
.
fpDecode
=
mnodeVgroupActionDecode
,
.
destroyFp
=
mnodeVgroupActionDestroy
,
.
fpDestroy
=
mnodeVgroupActionDestroy
,
.
restoredFp
=
mnodeVgroupActionRestored
,
.
fpRestored
=
mnodeVgroupActionRestored
,
};
};
tsVgroupSdb
=
sdbOpenTable
(
&
tableD
esc
);
tsVgroupSdb
=
sdbOpenTable
(
&
d
esc
);
if
(
tsVgroupSdb
==
NULL
)
{
if
(
tsVgroupSdb
==
NULL
)
{
mError
(
"failed to init vgroups data"
);
mError
(
"failed to init vgroups data"
);
return
-
1
;
return
-
1
;
...
@@ -253,13 +253,13 @@ SVgObj *mnodeGetVgroup(int32_t vgId) {
...
@@ -253,13 +253,13 @@ SVgObj *mnodeGetVgroup(int32_t vgId) {
}
}
void
mnodeUpdateVgroup
(
SVgObj
*
pVgroup
)
{
void
mnodeUpdateVgroup
(
SVgObj
*
pVgroup
)
{
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
t
able
=
tsVgroupSdb
,
.
pT
able
=
tsVgroupSdb
,
.
pObj
=
pVgroup
.
pObj
=
pVgroup
};
};
int32_t
code
=
sdbUpdateRow
(
&
oper
);
int32_t
code
=
sdbUpdateRow
(
&
row
);
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
mError
(
"vgId:%d, failed to update vgroup"
,
pVgroup
->
vgId
);
mError
(
"vgId:%d, failed to update vgroup"
,
pVgroup
->
vgId
);
}
}
...
@@ -519,14 +519,14 @@ static int32_t mnodeCreateVgroupCb(SMnodeMsg *pMsg, int32_t code) {
...
@@ -519,14 +519,14 @@ static int32_t mnodeCreateVgroupCb(SMnodeMsg *pMsg, int32_t code) {
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
mError
(
"app:%p:%p, vgId:%d, failed to create in sdb, reason:%s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pVgroup
->
vgId
,
mError
(
"app:%p:%p, vgId:%d, failed to create in sdb, reason:%s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pVgroup
->
vgId
,
tstrerror
(
code
));
tstrerror
(
code
));
SSdb
Oper
desc
=
{.
type
=
SDB_OPER_GLOBAL
,
.
pObj
=
pVgroup
,
.
t
able
=
tsVgroupSdb
};
SSdb
Row
desc
=
{.
type
=
SDB_OPER_GLOBAL
,
.
pObj
=
pVgroup
,
.
pT
able
=
tsVgroupSdb
};
sdbDeleteRow
(
&
desc
);
sdbDeleteRow
(
&
desc
);
return
code
;
return
code
;
}
else
{
}
else
{
mInfo
(
"app:%p:%p, vgId:%d, is created in sdb, db:%s replica:%d"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pVgroup
->
vgId
,
mInfo
(
"app:%p:%p, vgId:%d, is created in sdb, db:%s replica:%d"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pVgroup
->
vgId
,
pDb
->
name
,
pVgroup
->
numOfVnodes
);
pDb
->
name
,
pVgroup
->
numOfVnodes
);
pVgroup
->
status
=
TAOS_VG_STATUS_READY
;
pVgroup
->
status
=
TAOS_VG_STATUS_READY
;
SSdb
Oper
desc
=
{.
type
=
SDB_OPER_GLOBAL
,
.
pObj
=
pVgroup
,
.
t
able
=
tsVgroupSdb
};
SSdb
Row
desc
=
{.
type
=
SDB_OPER_GLOBAL
,
.
pObj
=
pVgroup
,
.
pT
able
=
tsVgroupSdb
};
(
void
)
sdbUpdateRow
(
&
desc
);
(
void
)
sdbUpdateRow
(
&
desc
);
dnodeReprocessMWriteMsg
(
pMsg
);
dnodeReprocessMWriteMsg
(
pMsg
);
...
@@ -535,7 +535,7 @@ static int32_t mnodeCreateVgroupCb(SMnodeMsg *pMsg, int32_t code) {
...
@@ -535,7 +535,7 @@ static int32_t mnodeCreateVgroupCb(SMnodeMsg *pMsg, int32_t code) {
// mInfo("app:%p:%p, vgId:%d, is created in sdb, db:%s replica:%d", pMsg->rpcMsg.ahandle, pMsg, pVgroup->vgId,
// mInfo("app:%p:%p, vgId:%d, is created in sdb, db:%s replica:%d", pMsg->rpcMsg.ahandle, pMsg, pVgroup->vgId,
// pDb->name, pVgroup->numOfVnodes);
// pDb->name, pVgroup->numOfVnodes);
// pVgroup->status = TAOS_VG_STATUS_READY;
// pVgroup->status = TAOS_VG_STATUS_READY;
// SSdb
Oper desc = {.type = SDB_OPER_GLOBAL, .pObj = pVgroup, .t
able = tsVgroupSdb};
// SSdb
Row desc = {.type = SDB_OPER_GLOBAL, .pObj = pVgroup, .pT
able = tsVgroupSdb};
// (void)sdbUpdateRow(&desc);
// (void)sdbUpdateRow(&desc);
// dnodeReprocessMWriteMsg(pMsg);
// dnodeReprocessMWriteMsg(pMsg);
// return TSDB_CODE_MND_ACTION_IN_PROGRESS;
// return TSDB_CODE_MND_ACTION_IN_PROGRESS;
...
@@ -571,16 +571,16 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg) {
...
@@ -571,16 +571,16 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg) {
pMsg
->
pVgroup
=
pVgroup
;
pMsg
->
pVgroup
=
pVgroup
;
mnodeIncVgroupRef
(
pVgroup
);
mnodeIncVgroupRef
(
pVgroup
);
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
t
able
=
tsVgroupSdb
,
.
pT
able
=
tsVgroupSdb
,
.
pObj
=
pVgroup
,
.
pObj
=
pVgroup
,
.
rowSize
=
sizeof
(
SVgObj
),
.
rowSize
=
sizeof
(
SVgObj
),
.
pMsg
=
pMsg
,
.
pMsg
=
pMsg
,
.
reqFp
=
mnodeCreateVgroupFp
.
fpReq
=
mnodeCreateVgroupFp
};
};
code
=
sdbInsertRow
(
&
oper
);
code
=
sdbInsertRow
(
&
row
);
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
pMsg
->
pVgroup
=
NULL
;
pMsg
->
pVgroup
=
NULL
;
mnodeDestroyVgroup
(
pVgroup
);
mnodeDestroyVgroup
(
pVgroup
);
...
@@ -595,12 +595,12 @@ void mnodeDropVgroup(SVgObj *pVgroup, void *ahandle) {
...
@@ -595,12 +595,12 @@ void mnodeDropVgroup(SVgObj *pVgroup, void *ahandle) {
}
else
{
}
else
{
mDebug
(
"vgId:%d, replica:%d is deleting from sdb"
,
pVgroup
->
vgId
,
pVgroup
->
numOfVnodes
);
mDebug
(
"vgId:%d, replica:%d is deleting from sdb"
,
pVgroup
->
vgId
,
pVgroup
->
numOfVnodes
);
mnodeSendDropVgroupMsg
(
pVgroup
,
NULL
);
mnodeSendDropVgroupMsg
(
pVgroup
,
NULL
);
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
t
able
=
tsVgroupSdb
,
.
pT
able
=
tsVgroupSdb
,
.
pObj
=
pVgroup
.
pObj
=
pVgroup
};
};
sdbDeleteRow
(
&
oper
);
sdbDeleteRow
(
&
row
);
}
}
}
}
...
@@ -770,7 +770,7 @@ static int32_t mnodeRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, v
...
@@ -770,7 +770,7 @@ static int32_t mnodeRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, v
SDnodeObj
*
pDnode
=
pVgroup
->
vnodeGid
[
i
].
pDnode
;
SDnodeObj
*
pDnode
=
pVgroup
->
vnodeGid
[
i
].
pDnode
;
const
char
*
role
=
"NULL"
;
const
char
*
role
=
"NULL"
;
if
(
pDnode
!=
NULL
)
{
if
(
pDnode
!=
NULL
)
{
role
=
mnodeGetMnodeRoleStr
(
pVgroup
->
vnodeGid
[
i
].
role
)
;
role
=
syncRole
[
pVgroup
->
vnodeGid
[
i
].
role
]
;
}
}
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
...
@@ -957,28 +957,28 @@ static void mnodeProcessCreateVnodeRsp(SRpcMsg *rpcMsg) {
...
@@ -957,28 +957,28 @@ static void mnodeProcessCreateVnodeRsp(SRpcMsg *rpcMsg) {
if
(
mnodeMsg
->
received
!=
mnodeMsg
->
expected
)
return
;
if
(
mnodeMsg
->
received
!=
mnodeMsg
->
expected
)
return
;
if
(
mnodeMsg
->
received
==
mnodeMsg
->
successed
)
{
if
(
mnodeMsg
->
received
==
mnodeMsg
->
successed
)
{
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
table
=
tsVgroupSdb
,
.
pTable
=
tsVgroupSdb
,
.
pObj
=
pVgroup
,
.
pObj
=
pVgroup
,
.
rowSize
=
sizeof
(
SVgObj
),
.
rowSize
=
sizeof
(
SVgObj
),
.
pMsg
=
mnodeMsg
,
.
pMsg
=
mnodeMsg
,
.
writeCb
=
mnodeCreateVgroupCb
.
fpRsp
=
mnodeCreateVgroupCb
};
};
int32_t
code
=
sdbInsertRow
Imp
(
&
oper
);
int32_t
code
=
sdbInsertRow
ToQueue
(
&
row
);
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
mnodeMsg
->
pVgroup
=
NULL
;
mnodeMsg
->
pVgroup
=
NULL
;
mnodeDestroyVgroup
(
pVgroup
);
mnodeDestroyVgroup
(
pVgroup
);
dnodeSendRpcMWriteRsp
(
mnodeMsg
,
code
);
dnodeSendRpcMWriteRsp
(
mnodeMsg
,
code
);
}
}
}
else
{
}
else
{
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
t
able
=
tsVgroupSdb
,
.
pT
able
=
tsVgroupSdb
,
.
pObj
=
pVgroup
.
pObj
=
pVgroup
};
};
sdbDeleteRow
(
&
oper
);
sdbDeleteRow
(
&
row
);
dnodeSendRpcMWriteRsp
(
mnodeMsg
,
mnodeMsg
->
code
);
dnodeSendRpcMWriteRsp
(
mnodeMsg
,
mnodeMsg
->
code
);
}
}
}
}
...
@@ -1031,12 +1031,12 @@ static void mnodeProcessDropVnodeRsp(SRpcMsg *rpcMsg) {
...
@@ -1031,12 +1031,12 @@ static void mnodeProcessDropVnodeRsp(SRpcMsg *rpcMsg) {
if
(
mnodeMsg
->
received
!=
mnodeMsg
->
expected
)
return
;
if
(
mnodeMsg
->
received
!=
mnodeMsg
->
expected
)
return
;
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
type
=
SDB_OPER_GLOBAL
,
.
t
able
=
tsVgroupSdb
,
.
pT
able
=
tsVgroupSdb
,
.
pObj
=
pVgroup
.
pObj
=
pVgroup
};
};
int32_t
code
=
sdbDeleteRow
(
&
oper
);
int32_t
code
=
sdbDeleteRow
(
&
row
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
code
=
TSDB_CODE_MND_SDB_ERROR
;
code
=
TSDB_CODE_MND_SDB_ERROR
;
}
}
...
@@ -1084,12 +1084,12 @@ void mnodeDropAllDnodeVgroups(SDnodeObj *pDropDnode) {
...
@@ -1084,12 +1084,12 @@ void mnodeDropAllDnodeVgroups(SDnodeObj *pDropDnode) {
if
(
pVgroup
->
vnodeGid
[
0
].
dnodeId
==
pDropDnode
->
dnodeId
)
{
if
(
pVgroup
->
vnodeGid
[
0
].
dnodeId
==
pDropDnode
->
dnodeId
)
{
mnodeDropAllChildTablesInVgroups
(
pVgroup
);
mnodeDropAllChildTablesInVgroups
(
pVgroup
);
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_LOCAL
,
.
type
=
SDB_OPER_LOCAL
,
.
t
able
=
tsVgroupSdb
,
.
pT
able
=
tsVgroupSdb
,
.
pObj
=
pVgroup
,
.
pObj
=
pVgroup
,
};
};
sdbDeleteRow
(
&
oper
);
sdbDeleteRow
(
&
row
);
numOfVgroups
++
;
numOfVgroups
++
;
}
}
mnodeDecVgroupRef
(
pVgroup
);
mnodeDecVgroupRef
(
pVgroup
);
...
@@ -1135,12 +1135,12 @@ void mnodeDropAllDbVgroups(SDbObj *pDropDb) {
...
@@ -1135,12 +1135,12 @@ void mnodeDropAllDbVgroups(SDbObj *pDropDb) {
if
(
pVgroup
==
NULL
)
break
;
if
(
pVgroup
==
NULL
)
break
;
if
(
pVgroup
->
pDb
==
pDropDb
)
{
if
(
pVgroup
->
pDb
==
pDropDb
)
{
SSdb
Oper
oper
=
{
SSdb
Row
row
=
{
.
type
=
SDB_OPER_LOCAL
,
.
type
=
SDB_OPER_LOCAL
,
.
t
able
=
tsVgroupSdb
,
.
pT
able
=
tsVgroupSdb
,
.
pObj
=
pVgroup
,
.
pObj
=
pVgroup
,
};
};
sdbDeleteRow
(
&
oper
);
sdbDeleteRow
(
&
row
);
numOfVgroups
++
;
numOfVgroups
++
;
}
}
...
...
src/plugins/http/inc/httpInt.h
浏览文件 @
ea3aae75
...
@@ -118,7 +118,7 @@ typedef struct {
...
@@ -118,7 +118,7 @@ typedef struct {
typedef
struct
{
typedef
struct
{
char
*
module
;
char
*
module
;
bool
(
*
decodeFp
)(
struct
HttpContext
*
pContext
);
bool
(
*
fpDecode
)(
struct
HttpContext
*
pContext
);
}
HttpDecodeMethod
;
}
HttpDecodeMethod
;
typedef
struct
{
typedef
struct
{
...
...
src/plugins/http/src/httpHandle.c
浏览文件 @
ea3aae75
...
@@ -21,11 +21,11 @@
...
@@ -21,11 +21,11 @@
#include "httpHandle.h"
#include "httpHandle.h"
bool
httpDecodeRequest
(
HttpContext
*
pContext
)
{
bool
httpDecodeRequest
(
HttpContext
*
pContext
)
{
if
(
pContext
->
decodeMethod
->
decodeFp
==
NULL
)
{
if
(
pContext
->
decodeMethod
->
fpDecode
==
NULL
)
{
return
false
;
return
false
;
}
}
return
(
*
pContext
->
decodeMethod
->
decodeFp
)(
pContext
);
return
(
*
pContext
->
decodeMethod
->
fpDecode
)(
pContext
);
}
}
/**
/**
...
...
src/sync/inc/syncInt.h
浏览文件 @
ea3aae75
...
@@ -27,16 +27,20 @@ extern "C" {
...
@@ -27,16 +27,20 @@ extern "C" {
#define sDebug(...) { if (sDebugFlag & DEBUG_DEBUG) { taosPrintLog("SYN ", sDebugFlag, __VA_ARGS__); }}
#define sDebug(...) { if (sDebugFlag & DEBUG_DEBUG) { taosPrintLog("SYN ", sDebugFlag, __VA_ARGS__); }}
#define sTrace(...) { if (sDebugFlag & DEBUG_TRACE) { taosPrintLog("SYN ", sDebugFlag, __VA_ARGS__); }}
#define sTrace(...) { if (sDebugFlag & DEBUG_TRACE) { taosPrintLog("SYN ", sDebugFlag, __VA_ARGS__); }}
#define TAOS_SMSG_SYNC_DATA 1
typedef
enum
{
#define TAOS_SMSG_FORWARD 2
TAOS_SMSG_SYNC_DATA
=
1
,
#define TAOS_SMSG_FORWARD_RSP 3
TAOS_SMSG_FORWARD
=
2
,
#define TAOS_SMSG_SYNC_REQ 4
TAOS_SMSG_FORWARD_RSP
=
3
,
#define TAOS_SMSG_SYNC_RSP 5
TAOS_SMSG_SYNC_REQ
=
4
,
#define TAOS_SMSG_SYNC_MUST 6
TAOS_SMSG_SYNC_RSP
=
5
,
#define TAOS_SMSG_STATUS 7
TAOS_SMSG_SYNC_MUST
=
6
,
TAOS_SMSG_STATUS
=
7
}
ESyncMsgType
;
#define SYNC_MAX_SIZE (TSDB_MAX_WAL_SIZE + sizeof(SWalHead) + sizeof(SSyncHead) + 16)
#define SYNC_MAX_SIZE (TSDB_MAX_WAL_SIZE + sizeof(SWalHead) + sizeof(SSyncHead) + 16)
#define SYNC_RECV_BUFFER_SIZE (5*1024*1024)
#define SYNC_RECV_BUFFER_SIZE (5*1024*1024)
#define SYNC_FWD_TIMER 300
#define SYNC_ROLE_TIMER 10000
#define nodeRole pNode->peerInfo[pNode->selfIndex]->role
#define nodeRole pNode->peerInfo[pNode->selfIndex]->role
#define nodeVersion pNode->peerInfo[pNode->selfIndex]->version
#define nodeVersion pNode->peerInfo[pNode->selfIndex]->version
...
@@ -68,6 +72,9 @@ typedef struct {
...
@@ -68,6 +72,9 @@ typedef struct {
typedef
struct
{
typedef
struct
{
int8_t
role
;
int8_t
role
;
int8_t
ack
;
int8_t
ack
;
int8_t
type
;
int8_t
reserved
[
3
];
uint16_t
tranId
;
uint64_t
version
;
uint64_t
version
;
SPeerStatus
peersStatus
[];
SPeerStatus
peersStatus
[];
}
SPeersStatus
;
}
SPeersStatus
;
...
@@ -120,12 +127,12 @@ typedef struct SsyncPeer {
...
@@ -120,12 +127,12 @@ typedef struct SsyncPeer {
int32_t
nodeId
;
int32_t
nodeId
;
uint32_t
ip
;
uint32_t
ip
;
uint16_t
port
;
uint16_t
port
;
int8_t
role
;
int8_t
sstatus
;
// sync status
char
fqdn
[
TSDB_FQDN_LEN
];
// peer ip string
char
fqdn
[
TSDB_FQDN_LEN
];
// peer ip string
char
id
[
TSDB_EP_LEN
+
32
];
// peer vgId + end point
char
id
[
TSDB_EP_LEN
+
32
];
// peer vgId + end point
int8_t
role
;
int8_t
sstatus
;
// sync status
uint64_t
version
;
uint64_t
version
;
uint64_t
sversion
;
// track the peer version in retrieve process
uint64_t
sversion
;
// track the peer version in retrieve process
int32_t
syncFd
;
int32_t
syncFd
;
int32_t
peerFd
;
// forward FD
int32_t
peerFd
;
// forward FD
int32_t
numOfRetrieves
;
// number of retrieves tried
int32_t
numOfRetrieves
;
// number of retrieves tried
...
@@ -135,7 +142,7 @@ typedef struct SsyncPeer {
...
@@ -135,7 +142,7 @@ typedef struct SsyncPeer {
int32_t
notifyFd
;
int32_t
notifyFd
;
int32_t
watchNum
;
int32_t
watchNum
;
int32_t
*
watchFd
;
int32_t
*
watchFd
;
int
8_t
refCount
;
// reference count
int
32_t
refCount
;
// reference count
struct
SSyncNode
*
pSyncNode
;
struct
SSyncNode
*
pSyncNode
;
}
SSyncPeer
;
}
SSyncPeer
;
...
@@ -143,16 +150,16 @@ typedef struct SSyncNode {
...
@@ -143,16 +150,16 @@ typedef struct SSyncNode {
char
path
[
TSDB_FILENAME_LEN
];
char
path
[
TSDB_FILENAME_LEN
];
int8_t
replica
;
int8_t
replica
;
int8_t
quorum
;
int8_t
quorum
;
int8_t
selfIndex
;
uint32_t
vgId
;
uint32_t
vgId
;
int64_t
rid
;
int64_t
rid
;
void
*
ahandle
;
void
*
ahandle
;
int8_t
selfIndex
;
SSyncPeer
*
peerInfo
[
TAOS_SYNC_MAX_REPLICA
+
1
];
// extra one for arbitrator
SSyncPeer
*
peerInfo
[
TAOS_SYNC_MAX_REPLICA
+
1
];
// extra one for arbitrator
SSyncPeer
*
pMaster
;
SSyncPeer
*
pMaster
;
int8_t
refCount
;
SRecvBuffer
*
pRecv
;
SRecvBuffer
*
pRecv
;
SSyncFwds
*
pSyncFwds
;
// saved forward info if quorum >1
SSyncFwds
*
pSyncFwds
;
// saved forward info if quorum >1
void
*
pFwdTimer
;
void
*
pFwdTimer
;
void
*
pRoleTimer
;
FGetFileInfo
getFileInfo
;
FGetFileInfo
getFileInfo
;
FGetWalInfo
getWalInfo
;
FGetWalInfo
getWalInfo
;
FWriteToCache
writeToCache
;
FWriteToCache
writeToCache
;
...
...
src/sync/src/syncMain.c
浏览文件 @
ea3aae75
...
@@ -50,7 +50,7 @@ static int32_t tsSyncRefId = -1;
...
@@ -50,7 +50,7 @@ static int32_t tsSyncRefId = -1;
static
void
syncProcessSyncRequest
(
char
*
pMsg
,
SSyncPeer
*
pPeer
);
static
void
syncProcessSyncRequest
(
char
*
pMsg
,
SSyncPeer
*
pPeer
);
static
void
syncRecoverFromMaster
(
SSyncPeer
*
pPeer
);
static
void
syncRecoverFromMaster
(
SSyncPeer
*
pPeer
);
static
void
syncCheckPeerConnection
(
void
*
param
,
void
*
tmrId
);
static
void
syncCheckPeerConnection
(
void
*
param
,
void
*
tmrId
);
static
void
syncSendPeersStatusMsgToPeer
(
SSyncPeer
*
pPeer
,
char
ack
);
static
void
syncSendPeersStatusMsgToPeer
(
SSyncPeer
*
pPeer
,
char
ack
,
int8_t
type
,
uint16_t
tranId
);
static
void
syncProcessBrokenLink
(
void
*
param
);
static
void
syncProcessBrokenLink
(
void
*
param
);
static
int32_t
syncProcessPeerMsg
(
void
*
param
,
void
*
buffer
);
static
int32_t
syncProcessPeerMsg
(
void
*
param
,
void
*
buffer
);
static
void
syncProcessIncommingConnection
(
int32_t
connFd
,
uint32_t
sourceIp
);
static
void
syncProcessIncommingConnection
(
int32_t
connFd
,
uint32_t
sourceIp
);
...
@@ -59,6 +59,7 @@ static void syncAddArbitrator(SSyncNode *pNode);
...
@@ -59,6 +59,7 @@ static void syncAddArbitrator(SSyncNode *pNode);
static
void
syncFreeNode
(
void
*
);
static
void
syncFreeNode
(
void
*
);
static
void
syncRemoveConfirmedFwdInfo
(
SSyncNode
*
pNode
);
static
void
syncRemoveConfirmedFwdInfo
(
SSyncNode
*
pNode
);
static
void
syncMonitorFwdInfos
(
void
*
param
,
void
*
tmrId
);
static
void
syncMonitorFwdInfos
(
void
*
param
,
void
*
tmrId
);
static
void
syncMonitorNodeRole
(
void
*
param
,
void
*
tmrId
);
static
void
syncProcessFwdAck
(
SSyncNode
*
pNode
,
SFwdInfo
*
pFwdInfo
,
int32_t
code
);
static
void
syncProcessFwdAck
(
SSyncNode
*
pNode
,
SFwdInfo
*
pFwdInfo
,
int32_t
code
);
static
void
syncSaveFwdInfo
(
SSyncNode
*
pNode
,
uint64_t
version
,
void
*
mhandle
);
static
void
syncSaveFwdInfo
(
SSyncNode
*
pNode
,
uint64_t
version
,
void
*
mhandle
);
static
void
syncRestartPeer
(
SSyncPeer
*
pPeer
);
static
void
syncRestartPeer
(
SSyncPeer
*
pPeer
);
...
@@ -73,6 +74,32 @@ char* syncRole[] = {
...
@@ -73,6 +74,32 @@ char* syncRole[] = {
"master"
"master"
};
};
typedef
enum
{
SYNC_STATUS_BROADCAST
,
SYNC_STATUS_BROADCAST_RSP
,
SYNC_STATUS_SETUP_CONN
,
SYNC_STATUS_SETUP_CONN_RSP
,
SYNC_STATUS_EXCHANGE_DATA
,
SYNC_STATUS_EXCHANGE_DATA_RSP
,
SYNC_STATUS_CHECK_ROLE
,
SYNC_STATUS_CHECK_ROLE_RSP
}
ESyncStatusType
;
char
*
statusType
[]
=
{
"broadcast"
,
"broadcast-rsp"
,
"setup-conn"
,
"setup-conn-rsp"
,
"exchange-data"
,
"exchange-data-rsp"
,
"check-role"
,
"check-role-rsp"
};
uint16_t
syncGenTranId
()
{
return
taosRand
()
&
0XFFFF
;
}
int32_t
syncInit
()
{
int32_t
syncInit
()
{
SPoolInfo
info
;
SPoolInfo
info
;
...
@@ -145,7 +172,7 @@ void syncCleanUp() {
...
@@ -145,7 +172,7 @@ void syncCleanUp() {
int64_t
syncStart
(
const
SSyncInfo
*
pInfo
)
{
int64_t
syncStart
(
const
SSyncInfo
*
pInfo
)
{
const
SSyncCfg
*
pCfg
=
&
pInfo
->
syncCfg
;
const
SSyncCfg
*
pCfg
=
&
pInfo
->
syncCfg
;
SSyncNode
*
pNode
=
(
SSyncNode
*
)
calloc
(
sizeof
(
SSyncNode
),
1
);
SSyncNode
*
pNode
=
calloc
(
sizeof
(
SSyncNode
),
1
);
if
(
pNode
==
NULL
)
{
if
(
pNode
==
NULL
)
{
sError
(
"no memory to allocate syncNode"
);
sError
(
"no memory to allocate syncNode"
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
...
@@ -180,8 +207,8 @@ int64_t syncStart(const SSyncInfo *pInfo) {
...
@@ -180,8 +207,8 @@ int64_t syncStart(const SSyncInfo *pInfo) {
const
SNodeInfo
*
pNodeInfo
=
pCfg
->
nodeInfo
+
i
;
const
SNodeInfo
*
pNodeInfo
=
pCfg
->
nodeInfo
+
i
;
pNode
->
peerInfo
[
i
]
=
syncAddPeer
(
pNode
,
pNodeInfo
);
pNode
->
peerInfo
[
i
]
=
syncAddPeer
(
pNode
,
pNodeInfo
);
if
(
pNode
->
peerInfo
[
i
]
==
NULL
)
{
if
(
pNode
->
peerInfo
[
i
]
==
NULL
)
{
sError
(
"vgId:%d, node:%d fqdn:%s port:%u is not configured, stop taosd"
,
pNode
->
vgId
,
pNodeInfo
->
nodeId
,
pNodeInfo
->
nodeFqdn
,
sError
(
"vgId:%d, node:%d fqdn:%s port:%u is not configured, stop taosd"
,
pNode
->
vgId
,
pNodeInfo
->
nodeId
,
pNodeInfo
->
nodePort
);
pNodeInfo
->
node
Fqdn
,
pNodeInfo
->
node
Port
);
syncStop
(
pNode
->
rid
);
syncStop
(
pNode
->
rid
);
exit
(
1
);
exit
(
1
);
}
}
...
@@ -211,9 +238,16 @@ int64_t syncStart(const SSyncInfo *pInfo) {
...
@@ -211,9 +238,16 @@ int64_t syncStart(const SSyncInfo *pInfo) {
return
-
1
;
return
-
1
;
}
}
pNode
->
pFwdTimer
=
taosTmrStart
(
syncMonitorFwdInfos
,
300
,
(
void
*
)
pNode
->
rid
,
tsSyncTmrCtrl
);
pNode
->
pFwdTimer
=
taosTmrStart
(
syncMonitorFwdInfos
,
SYNC_FWD_TIMER
,
(
void
*
)
pNode
->
rid
,
tsSyncTmrCtrl
);
if
(
pNode
->
pFwdTimer
==
NULL
)
{
if
(
pNode
->
pFwdTimer
==
NULL
)
{
sError
(
"vgId:%d, failed to allocate timer"
,
pNode
->
vgId
);
sError
(
"vgId:%d, failed to allocate fwd timer"
,
pNode
->
vgId
);
syncStop
(
pNode
->
rid
);
return
-
1
;
}
pNode
->
pRoleTimer
=
taosTmrStart
(
syncMonitorNodeRole
,
SYNC_ROLE_TIMER
,
(
void
*
)
pNode
->
rid
,
tsSyncTmrCtrl
);
if
(
pNode
->
pRoleTimer
==
NULL
)
{
sError
(
"vgId:%d, failed to allocate role timer"
,
pNode
->
vgId
);
syncStop
(
pNode
->
rid
);
syncStop
(
pNode
->
rid
);
return
-
1
;
return
-
1
;
}
}
...
@@ -240,6 +274,7 @@ void syncStop(int64_t rid) {
...
@@ -240,6 +274,7 @@ void syncStop(int64_t rid) {
if
(
tsVgIdHash
)
taosHashRemove
(
tsVgIdHash
,
(
const
char
*
)
&
pNode
->
vgId
,
sizeof
(
int32_t
));
if
(
tsVgIdHash
)
taosHashRemove
(
tsVgIdHash
,
(
const
char
*
)
&
pNode
->
vgId
,
sizeof
(
int32_t
));
if
(
pNode
->
pFwdTimer
)
taosTmrStop
(
pNode
->
pFwdTimer
);
if
(
pNode
->
pFwdTimer
)
taosTmrStop
(
pNode
->
pFwdTimer
);
if
(
pNode
->
pRoleTimer
)
taosTmrStop
(
pNode
->
pRoleTimer
);
for
(
int32_t
i
=
0
;
i
<
pNode
->
replica
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pNode
->
replica
;
++
i
)
{
pPeer
=
pNode
->
peerInfo
[
i
];
pPeer
=
pNode
->
peerInfo
[
i
];
...
@@ -319,12 +354,10 @@ int32_t syncReconfig(int64_t rid, const SSyncCfg *pNewCfg) {
...
@@ -319,12 +354,10 @@ int32_t syncReconfig(int64_t rid, const SSyncCfg *pNewCfg) {
pthread_mutex_unlock
(
&
(
pNode
->
mutex
));
pthread_mutex_unlock
(
&
(
pNode
->
mutex
));
sInfo
(
"vgId:%d, %d replicas are configured, quorum:%d role:%s"
,
pNode
->
vgId
,
pNode
->
replica
,
pNode
->
quorum
,
sInfo
(
"vgId:%d, %d replicas are configured, quorum:%d"
,
pNode
->
vgId
,
pNode
->
replica
,
pNode
->
quorum
);
syncRole
[
nodeRole
]);
syncBroadcastStatus
(
pNode
);
syncBroadcastStatus
(
pNode
);
taosReleaseRef
(
tsSyncRefId
,
rid
);
taosReleaseRef
(
tsSyncRefId
,
rid
);
return
0
;
return
0
;
}
}
...
@@ -356,7 +389,7 @@ void syncConfirmForward(int64_t rid, uint64_t version, int32_t code) {
...
@@ -356,7 +389,7 @@ void syncConfirmForward(int64_t rid, uint64_t version, int32_t code) {
pFwdRsp
->
code
=
code
;
pFwdRsp
->
code
=
code
;
int32_t
msgLen
=
sizeof
(
SSyncHead
)
+
sizeof
(
SFwdRsp
);
int32_t
msgLen
=
sizeof
(
SSyncHead
)
+
sizeof
(
SFwdRsp
);
int32_t
retLen
=
write
(
pPeer
->
peerFd
,
msg
,
msgLen
);
int32_t
retLen
=
taosWriteMsg
(
pPeer
->
peerFd
,
msg
,
msgLen
);
if
(
retLen
==
msgLen
)
{
if
(
retLen
==
msgLen
)
{
sDebug
(
"%s, forward-rsp is sent, code:%x hver:%"
PRIu64
,
pPeer
->
id
,
code
,
version
);
sDebug
(
"%s, forward-rsp is sent, code:%x hver:%"
PRIu64
,
pPeer
->
id
,
code
,
version
);
...
@@ -369,6 +402,7 @@ void syncConfirmForward(int64_t rid, uint64_t version, int32_t code) {
...
@@ -369,6 +402,7 @@ void syncConfirmForward(int64_t rid, uint64_t version, int32_t code) {
taosReleaseRef
(
tsSyncRefId
,
rid
);
taosReleaseRef
(
tsSyncRefId
,
rid
);
}
}
#if 0
void syncRecover(int64_t rid) {
void syncRecover(int64_t rid) {
SSyncPeer *pPeer;
SSyncPeer *pPeer;
...
@@ -385,7 +419,7 @@ void syncRecover(int64_t rid) {
...
@@ -385,7 +419,7 @@ void syncRecover(int64_t rid) {
pthread_mutex_lock(&(pNode->mutex));
pthread_mutex_lock(&(pNode->mutex));
for (int32_t i = 0; i < pNode->replica; ++i) {
for (int32_t i = 0; i < pNode->replica; ++i) {
pPeer
=
(
SSyncPeer
*
)
pNode
->
peerInfo
[
i
];
pPeer = pNode->peerInfo[i];
if (pPeer->peerFd >= 0) {
if (pPeer->peerFd >= 0) {
syncRestartConnection(pPeer);
syncRestartConnection(pPeer);
}
}
...
@@ -395,6 +429,7 @@ void syncRecover(int64_t rid) {
...
@@ -395,6 +429,7 @@ void syncRecover(int64_t rid) {
taosReleaseRef(tsSyncRefId, rid);
taosReleaseRef(tsSyncRefId, rid);
}
}
#endif
int32_t
syncGetNodesRole
(
int64_t
rid
,
SNodesRole
*
pNodesRole
)
{
int32_t
syncGetNodesRole
(
int64_t
rid
,
SNodesRole
*
pNodesRole
)
{
SSyncNode
*
pNode
=
taosAcquireRef
(
tsSyncRefId
,
rid
);
SSyncNode
*
pNode
=
taosAcquireRef
(
tsSyncRefId
,
rid
);
...
@@ -449,10 +484,10 @@ static void syncFreeNode(void *param) {
...
@@ -449,10 +484,10 @@ static void syncFreeNode(void *param) {
tfree
(
pNode
);
tfree
(
pNode
);
}
}
void
syncAddPeerRef
(
SSyncPeer
*
pPeer
)
{
atomic_add_fetch_
8
(
&
pPeer
->
refCount
,
1
);
}
void
syncAddPeerRef
(
SSyncPeer
*
pPeer
)
{
atomic_add_fetch_
32
(
&
pPeer
->
refCount
,
1
);
}
int32_t
syncDecPeerRef
(
SSyncPeer
*
pPeer
)
{
int32_t
syncDecPeerRef
(
SSyncPeer
*
pPeer
)
{
if
(
atomic_sub_fetch_
8
(
&
pPeer
->
refCount
,
1
)
==
0
)
{
if
(
atomic_sub_fetch_
32
(
&
pPeer
->
refCount
,
1
)
==
0
)
{
taosReleaseRef
(
tsSyncRefId
,
pPeer
->
pSyncNode
->
rid
);
taosReleaseRef
(
tsSyncRefId
,
pPeer
->
pSyncNode
->
rid
);
sDebug
(
"%s, resource is freed"
,
pPeer
->
id
);
sDebug
(
"%s, resource is freed"
,
pPeer
->
id
);
...
@@ -510,7 +545,7 @@ static SSyncPeer *syncAddPeer(SSyncNode *pNode, const SNodeInfo *pInfo) {
...
@@ -510,7 +545,7 @@ static SSyncPeer *syncAddPeer(SSyncNode *pNode, const SNodeInfo *pInfo) {
if
(
pPeer
->
nodeId
==
0
||
(
ret
>
0
)
||
(
ret
==
0
&&
pPeer
->
port
>
tsSyncPort
))
{
if
(
pPeer
->
nodeId
==
0
||
(
ret
>
0
)
||
(
ret
==
0
&&
pPeer
->
port
>
tsSyncPort
))
{
int32_t
checkMs
=
100
+
(
pNode
->
vgId
*
10
)
%
100
;
int32_t
checkMs
=
100
+
(
pNode
->
vgId
*
10
)
%
100
;
if
(
pNode
->
vgId
>
1
)
checkMs
=
tsStatusInterval
*
1000
+
checkMs
;
if
(
pNode
->
vgId
>
1
)
checkMs
=
tsStatusInterval
*
1000
+
checkMs
;
sDebug
(
"%s,
start to
check peer connection after %d ms"
,
pPeer
->
id
,
checkMs
);
sDebug
(
"%s, check peer connection after %d ms"
,
pPeer
->
id
,
checkMs
);
taosTmrReset
(
syncCheckPeerConnection
,
checkMs
,
pPeer
,
tsSyncTmrCtrl
,
&
pPeer
->
timer
);
taosTmrReset
(
syncCheckPeerConnection
,
checkMs
,
pPeer
,
tsSyncTmrCtrl
,
&
pPeer
->
timer
);
}
}
...
@@ -524,7 +559,7 @@ void syncBroadcastStatus(SSyncNode *pNode) {
...
@@ -524,7 +559,7 @@ void syncBroadcastStatus(SSyncNode *pNode) {
for
(
int32_t
i
=
0
;
i
<
pNode
->
replica
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pNode
->
replica
;
++
i
)
{
if
(
i
==
pNode
->
selfIndex
)
continue
;
if
(
i
==
pNode
->
selfIndex
)
continue
;
pPeer
=
pNode
->
peerInfo
[
i
];
pPeer
=
pNode
->
peerInfo
[
i
];
syncSendPeersStatusMsgToPeer
(
pPeer
,
1
);
syncSendPeersStatusMsgToPeer
(
pPeer
,
1
,
SYNC_STATUS_BROADCAST
,
syncGenTranId
()
);
}
}
}
}
...
@@ -544,8 +579,6 @@ static void syncChooseMaster(SSyncNode *pNode) {
...
@@ -544,8 +579,6 @@ static void syncChooseMaster(SSyncNode *pNode) {
int32_t
index
=
-
1
;
int32_t
index
=
-
1
;
int32_t
replica
=
pNode
->
replica
;
int32_t
replica
=
pNode
->
replica
;
sDebug
(
"vgId:%d, choose master"
,
pNode
->
vgId
);
for
(
int32_t
i
=
0
;
i
<
pNode
->
replica
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pNode
->
replica
;
++
i
)
{
if
(
pNode
->
peerInfo
[
i
]
->
role
!=
TAOS_SYNC_ROLE_OFFLINE
)
{
if
(
pNode
->
peerInfo
[
i
]
->
role
!=
TAOS_SYNC_ROLE_OFFLINE
)
{
onlineNum
++
;
onlineNum
++
;
...
@@ -611,11 +644,11 @@ static void syncChooseMaster(SSyncNode *pNode) {
...
@@ -611,11 +644,11 @@ static void syncChooseMaster(SSyncNode *pNode) {
static
SSyncPeer
*
syncCheckMaster
(
SSyncNode
*
pNode
)
{
static
SSyncPeer
*
syncCheckMaster
(
SSyncNode
*
pNode
)
{
int32_t
onlineNum
=
0
;
int32_t
onlineNum
=
0
;
int32_t
i
ndex
=
-
1
;
int32_t
masterI
ndex
=
-
1
;
int32_t
replica
=
pNode
->
replica
;
int32_t
replica
=
pNode
->
replica
;
for
(
int32_t
i
=
0
;
i
<
pNode
->
replica
;
++
i
)
{
for
(
int32_t
i
ndex
=
0
;
index
<
pNode
->
replica
;
++
index
)
{
if
(
pNode
->
peerInfo
[
i
]
->
role
!=
TAOS_SYNC_ROLE_OFFLINE
)
{
if
(
pNode
->
peerInfo
[
i
ndex
]
->
role
!=
TAOS_SYNC_ROLE_OFFLINE
)
{
onlineNum
++
;
onlineNum
++
;
}
}
}
}
...
@@ -630,18 +663,17 @@ static SSyncPeer *syncCheckMaster(SSyncNode *pNode) {
...
@@ -630,18 +663,17 @@ static SSyncPeer *syncCheckMaster(SSyncNode *pNode) {
if
(
onlineNum
<=
replica
*
0
.
5
)
{
if
(
onlineNum
<=
replica
*
0
.
5
)
{
if
(
nodeRole
!=
TAOS_SYNC_ROLE_UNSYNCED
)
{
if
(
nodeRole
!=
TAOS_SYNC_ROLE_UNSYNCED
)
{
nodeRole
=
TAOS_SYNC_ROLE_UNSYNCED
;
nodeRole
=
TAOS_SYNC_ROLE_UNSYNCED
;
// pNode->peerInfo[pNode->selfIndex]->role = nodeRole;
(
*
pNode
->
notifyRole
)(
pNode
->
ahandle
,
nodeRole
);
(
*
pNode
->
notifyRole
)(
pNode
->
ahandle
,
nodeRole
);
sInfo
(
"vgId:%d, change to unsynced state, online:%d replica:%d"
,
pNode
->
vgId
,
onlineNum
,
replica
);
sInfo
(
"vgId:%d,
self
change to unsynced state, online:%d replica:%d"
,
pNode
->
vgId
,
onlineNum
,
replica
);
}
}
}
else
{
}
else
{
for
(
int32_t
i
=
0
;
i
<
pNode
->
replica
;
++
i
)
{
for
(
int32_t
i
ndex
=
0
;
index
<
pNode
->
replica
;
++
index
)
{
SSyncPeer
*
pTemp
=
pNode
->
peerInfo
[
i
];
SSyncPeer
*
pTemp
=
pNode
->
peerInfo
[
i
ndex
];
if
(
pTemp
->
role
!=
TAOS_SYNC_ROLE_MASTER
)
continue
;
if
(
pTemp
->
role
!=
TAOS_SYNC_ROLE_MASTER
)
continue
;
if
(
i
ndex
<
0
)
{
if
(
masterI
ndex
<
0
)
{
index
=
i
;
masterIndex
=
index
;
}
else
{
// multiple masters, it shall not happen
}
else
{
// multiple masters, it shall not happen
if
(
i
==
pNode
->
selfIndex
)
{
if
(
masterIndex
==
pNode
->
selfIndex
)
{
sError
(
"%s, peer is master, work as slave instead"
,
pTemp
->
id
);
sError
(
"%s, peer is master, work as slave instead"
,
pTemp
->
id
);
nodeRole
=
TAOS_SYNC_ROLE_SLAVE
;
nodeRole
=
TAOS_SYNC_ROLE_SLAVE
;
(
*
pNode
->
notifyRole
)(
pNode
->
ahandle
,
nodeRole
);
(
*
pNode
->
notifyRole
)(
pNode
->
ahandle
,
nodeRole
);
...
@@ -650,77 +682,80 @@ static SSyncPeer *syncCheckMaster(SSyncNode *pNode) {
...
@@ -650,77 +682,80 @@ static SSyncPeer *syncCheckMaster(SSyncNode *pNode) {
}
}
}
}
SSyncPeer
*
pMaster
=
(
index
>=
0
)
?
pNode
->
peerInfo
[
i
ndex
]
:
NULL
;
SSyncPeer
*
pMaster
=
(
masterIndex
>=
0
)
?
pNode
->
peerInfo
[
masterI
ndex
]
:
NULL
;
return
pMaster
;
return
pMaster
;
}
}
static
int32_t
syncValidateMaster
(
SSyncPeer
*
pPeer
)
{
static
int32_t
syncValidateMaster
(
SSyncPeer
*
pPeer
)
{
SSyncNode
*
pNode
=
pPeer
->
pSyncNode
;
SSyncNode
*
pNode
=
pPeer
->
pSyncNode
;
int32_t
code
=
0
;
int32_t
code
=
0
;
if
(
nodeRole
==
TAOS_SYNC_ROLE_MASTER
&&
nodeVersion
<
pPeer
->
version
)
{
if
(
nodeRole
==
TAOS_SYNC_ROLE_MASTER
&&
nodeVersion
<
pPeer
->
version
)
{
sDebug
(
"%s,
slave has higher version, restart all connections!!!"
,
pPeer
->
id
);
sDebug
(
"%s,
peer has higher sver:%"
PRIu64
", restart all peer connections"
,
pPeer
->
id
,
pPeer
->
version
);
nodeRole
=
TAOS_SYNC_ROLE_UNSYNCED
;
nodeRole
=
TAOS_SYNC_ROLE_UNSYNCED
;
(
*
pNode
->
notifyRole
)(
pNode
->
ahandle
,
nodeRole
);
(
*
pNode
->
notifyRole
)(
pNode
->
ahandle
,
nodeRole
);
code
=
-
1
;
code
=
-
1
;
for
(
int32_t
i
=
0
;
i
<
pNode
->
replica
;
++
i
)
{
for
(
int32_t
i
ndex
=
0
;
index
<
pNode
->
replica
;
++
index
)
{
if
(
i
==
pNode
->
selfIndex
)
continue
;
if
(
i
ndex
==
pNode
->
selfIndex
)
continue
;
syncRestartPeer
(
pNode
->
peerInfo
[
i
]);
syncRestartPeer
(
pNode
->
peerInfo
[
i
ndex
]);
}
}
}
}
return
code
;
return
code
;
}
}
static
void
syncCheckRole
(
SSyncPeer
*
pPeer
,
SPeerStatus
peersStatus
[],
int8_t
new
Role
)
{
static
void
syncCheckRole
(
SSyncPeer
*
pPeer
,
SPeerStatus
*
peersStatus
,
int8_t
newPeer
Role
)
{
SSyncNode
*
pNode
=
pPeer
->
pSyncNode
;
SSyncNode
*
pNode
=
pPeer
->
pSyncNode
;
int8_t
peerOldRole
=
pPeer
->
role
;
int8_t
oldPeerRole
=
pPeer
->
role
;
int8_t
selfOldRole
=
nodeRole
;
int8_t
oldSelfRole
=
nodeRole
;
int8_t
i
,
syncRequired
=
0
;
int8_t
syncRequired
=
0
;
// pNode->peerInfo[pNode->selfIndex]->version = nodeVersion;
pPeer
->
role
=
newRole
;
sDebug
(
"%s, own role:%s, new peer role:%s"
,
pPeer
->
id
,
syncRole
[
nodeRole
],
syncRole
[
pPeer
->
role
]);
pPeer
->
role
=
newPeerRole
;
sDebug
(
"%s, peer role:%s change to %s"
,
pPeer
->
id
,
syncRole
[
oldPeerRole
],
syncRole
[
newPeerRole
]);
SSyncPeer
*
pMaster
=
syncCheckMaster
(
pNode
);
SSyncPeer
*
pMaster
=
syncCheckMaster
(
pNode
);
if
(
pMaster
)
{
if
(
pMaster
)
{
// master is there
// master is there
pNode
->
pMaster
=
pMaster
;
pNode
->
pMaster
=
pMaster
;
sDebug
(
"%s, it is the master, ver:%"
PRIu64
,
pMaster
->
id
,
pMaster
->
version
);
sDebug
(
"%s, it is the master,
s
ver:%"
PRIu64
,
pMaster
->
id
,
pMaster
->
version
);
if
(
syncValidateMaster
(
pPeer
)
<
0
)
return
;
if
(
syncValidateMaster
(
pPeer
)
<
0
)
return
;
if
(
nodeRole
==
TAOS_SYNC_ROLE_UNSYNCED
)
{
if
(
nodeRole
==
TAOS_SYNC_ROLE_UNSYNCED
)
{
if
(
nodeVersion
<
pMaster
->
version
)
{
if
(
nodeVersion
<
pMaster
->
version
)
{
sDebug
(
"%s, is master, sync required, self sver:%"
PRIu64
,
pMaster
->
id
,
nodeVersion
);
syncRequired
=
1
;
syncRequired
=
1
;
}
else
{
}
else
{
sInfo
(
"%s
is master, work as slave, ver:%"
PRIu64
,
pMaster
->
id
,
pMaster
->
v
ersion
);
sInfo
(
"%s
, is master, work as slave, self sver:%"
PRIu64
,
pMaster
->
id
,
nodeV
ersion
);
nodeRole
=
TAOS_SYNC_ROLE_SLAVE
;
nodeRole
=
TAOS_SYNC_ROLE_SLAVE
;
(
*
pNode
->
notifyRole
)(
pNode
->
ahandle
,
nodeRole
);
(
*
pNode
->
notifyRole
)(
pNode
->
ahandle
,
nodeRole
);
}
}
}
else
if
(
nodeRole
==
TAOS_SYNC_ROLE_SLAVE
&&
pMaster
==
pPeer
)
{
}
else
if
(
nodeRole
==
TAOS_SYNC_ROLE_SLAVE
&&
pMaster
==
pPeer
)
{
// nodeVersion = pMaster->version
;
sDebug
(
"%s, is master, continue work as slave, self sver:%"
PRIu64
,
pMaster
->
id
,
nodeVersion
)
;
}
}
}
else
{
}
else
{
// master not there, if all peer's state and version are consistent, choose the master
// master not there, if all peer's state and version are consistent, choose the master
int32_t
consistent
=
0
;
int32_t
consistent
=
0
;
if
(
peersStatus
)
{
int32_t
index
=
0
;
for
(
i
=
0
;
i
<
pNode
->
replica
;
++
i
)
{
if
(
peersStatus
!=
NULL
)
{
SSyncPeer
*
pTemp
=
pNode
->
peerInfo
[
i
];
for
(
index
=
0
;
index
<
pNode
->
replica
;
++
index
)
{
if
(
pTemp
->
role
!=
peersStatus
[
i
].
role
)
break
;
SSyncPeer
*
pTemp
=
pNode
->
peerInfo
[
index
];
if
((
pTemp
->
role
!=
TAOS_SYNC_ROLE_OFFLINE
)
&&
(
pTemp
->
version
!=
peersStatus
[
i
].
version
))
break
;
if
(
pTemp
->
role
!=
peersStatus
[
index
].
role
)
break
;
if
((
pTemp
->
role
!=
TAOS_SYNC_ROLE_OFFLINE
)
&&
(
pTemp
->
version
!=
peersStatus
[
index
].
version
))
break
;
}
}
if
(
i
>=
pNode
->
replica
)
consistent
=
1
;
if
(
i
ndex
>=
pNode
->
replica
)
consistent
=
1
;
}
else
{
}
else
{
if
(
pNode
->
replica
==
2
)
consistent
=
1
;
if
(
pNode
->
replica
==
2
)
consistent
=
1
;
}
}
if
(
consistent
)
{
if
(
consistent
)
{
sDebug
(
"vgId:%d, choose master"
,
pNode
->
vgId
);
syncChooseMaster
(
pNode
);
syncChooseMaster
(
pNode
);
}
else
{
sDebug
(
"vgId:%d, version inconsistent, cannot choose master"
,
pNode
->
vgId
);
}
}
}
}
...
@@ -728,7 +763,8 @@ static void syncCheckRole(SSyncPeer *pPeer, SPeerStatus peersStatus[], int8_t ne
...
@@ -728,7 +763,8 @@ static void syncCheckRole(SSyncPeer *pPeer, SPeerStatus peersStatus[], int8_t ne
syncRecoverFromMaster
(
pMaster
);
syncRecoverFromMaster
(
pMaster
);
}
}
if
(
peerOldRole
!=
newRole
||
nodeRole
!=
selfOldRole
)
{
if
(
oldPeerRole
!=
newPeerRole
||
nodeRole
!=
oldSelfRole
)
{
sDebug
(
"vgId:%d, roles changed, broadcast status"
,
pNode
->
vgId
);
syncBroadcastStatus
(
pNode
);
syncBroadcastStatus
(
pNode
);
}
}
...
@@ -738,7 +774,7 @@ static void syncCheckRole(SSyncPeer *pPeer, SPeerStatus peersStatus[], int8_t ne
...
@@ -738,7 +774,7 @@ static void syncCheckRole(SSyncPeer *pPeer, SPeerStatus peersStatus[], int8_t ne
}
}
static
void
syncRestartPeer
(
SSyncPeer
*
pPeer
)
{
static
void
syncRestartPeer
(
SSyncPeer
*
pPeer
)
{
sDebug
(
"%s, restart connection"
,
pPeer
->
id
);
sDebug
(
"%s, restart
peer
connection"
,
pPeer
->
id
);
syncClosePeerConn
(
pPeer
);
syncClosePeerConn
(
pPeer
);
...
@@ -746,6 +782,7 @@ static void syncRestartPeer(SSyncPeer *pPeer) {
...
@@ -746,6 +782,7 @@ static void syncRestartPeer(SSyncPeer *pPeer) {
int32_t
ret
=
strcmp
(
pPeer
->
fqdn
,
tsNodeFqdn
);
int32_t
ret
=
strcmp
(
pPeer
->
fqdn
,
tsNodeFqdn
);
if
(
ret
>
0
||
(
ret
==
0
&&
pPeer
->
port
>
tsSyncPort
))
{
if
(
ret
>
0
||
(
ret
==
0
&&
pPeer
->
port
>
tsSyncPort
))
{
sDebug
(
"%s, check peer connection in 1000 ms"
,
pPeer
->
id
);
taosTmrReset
(
syncCheckPeerConnection
,
tsSyncTimer
*
1000
,
pPeer
,
tsSyncTmrCtrl
,
&
pPeer
->
timer
);
taosTmrReset
(
syncCheckPeerConnection
,
tsSyncTimer
*
1000
,
pPeer
,
tsSyncTmrCtrl
,
&
pPeer
->
timer
);
}
}
}
}
...
@@ -840,7 +877,7 @@ static void syncRecoverFromMaster(SSyncPeer *pPeer) {
...
@@ -840,7 +877,7 @@ static void syncRecoverFromMaster(SSyncPeer *pPeer) {
firstPkt
.
port
=
tsSyncPort
;
firstPkt
.
port
=
tsSyncPort
;
taosTmrReset
(
syncNotStarted
,
tsSyncTimer
*
1000
,
pPeer
,
tsSyncTmrCtrl
,
&
pPeer
->
timer
);
taosTmrReset
(
syncNotStarted
,
tsSyncTimer
*
1000
,
pPeer
,
tsSyncTmrCtrl
,
&
pPeer
->
timer
);
if
(
write
(
pPeer
->
peerFd
,
&
firstPkt
,
sizeof
(
firstPkt
))
!=
sizeof
(
firstPkt
))
{
if
(
taosWriteMsg
(
pPeer
->
peerFd
,
&
firstPkt
,
sizeof
(
firstPkt
))
!=
sizeof
(
firstPkt
))
{
sError
(
"%s, failed to send sync-req to peer"
,
pPeer
->
id
);
sError
(
"%s, failed to send sync-req to peer"
,
pPeer
->
id
);
}
else
{
}
else
{
nodeSStatus
=
TAOS_SYNC_STATUS_START
;
nodeSStatus
=
TAOS_SYNC_STATUS_START
;
...
@@ -854,7 +891,7 @@ static void syncProcessFwdResponse(char *cont, SSyncPeer *pPeer) {
...
@@ -854,7 +891,7 @@ static void syncProcessFwdResponse(char *cont, SSyncPeer *pPeer) {
SSyncFwds
*
pSyncFwds
=
pNode
->
pSyncFwds
;
SSyncFwds
*
pSyncFwds
=
pNode
->
pSyncFwds
;
SFwdInfo
*
pFwdInfo
;
SFwdInfo
*
pFwdInfo
;
sDebug
(
"%s, forward-rsp is received, code:%x ver:%"
PRIu64
,
pPeer
->
id
,
pFwdRsp
->
code
,
pFwdRsp
->
version
);
sDebug
(
"%s, forward-rsp is received, code:%x
h
ver:%"
PRIu64
,
pPeer
->
id
,
pFwdRsp
->
code
,
pFwdRsp
->
version
);
SFwdInfo
*
pFirst
=
pSyncFwds
->
fwdInfo
+
pSyncFwds
->
first
;
SFwdInfo
*
pFirst
=
pSyncFwds
->
fwdInfo
+
pSyncFwds
->
first
;
if
(
pFirst
->
version
<=
pFwdRsp
->
version
&&
pSyncFwds
->
fwds
>
0
)
{
if
(
pFirst
->
version
<=
pFwdRsp
->
version
&&
pSyncFwds
->
fwds
>
0
)
{
...
@@ -891,14 +928,14 @@ static void syncProcessPeersStatusMsg(char *cont, SSyncPeer *pPeer) {
...
@@ -891,14 +928,14 @@ static void syncProcessPeersStatusMsg(char *cont, SSyncPeer *pPeer) {
SSyncNode
*
pNode
=
pPeer
->
pSyncNode
;
SSyncNode
*
pNode
=
pPeer
->
pSyncNode
;
SPeersStatus
*
pPeersStatus
=
(
SPeersStatus
*
)
cont
;
SPeersStatus
*
pPeersStatus
=
(
SPeersStatus
*
)
cont
;
sDebug
(
"%s, status msg is received, self:%s
ver:%"
PRIu64
" peer:%s ver:%"
PRIu64
", ack:%d
"
,
pPeer
->
id
,
sDebug
(
"%s, status msg is received, self:%s
sver:%"
PRIu64
" peer:%s sver:%"
PRIu64
", ack:%d tranId:%u type:%s
"
,
pPeer
->
id
,
syncRole
[
nodeRole
],
nodeVersion
,
syncRole
[
pPeersStatus
->
role
],
pPeersStatus
->
version
,
pPeersStatus
->
ack
);
syncRole
[
nodeRole
],
nodeVersion
,
syncRole
[
pPeersStatus
->
role
],
pPeersStatus
->
version
,
pPeersStatus
->
ack
,
pPeersStatus
->
tranId
,
statusType
[
pPeersStatus
->
type
]
);
pPeer
->
version
=
pPeersStatus
->
version
;
pPeer
->
version
=
pPeersStatus
->
version
;
syncCheckRole
(
pPeer
,
pPeersStatus
->
peersStatus
,
pPeersStatus
->
role
);
syncCheckRole
(
pPeer
,
pPeersStatus
->
peersStatus
,
pPeersStatus
->
role
);
if
(
pPeersStatus
->
ack
)
{
if
(
pPeersStatus
->
ack
)
{
syncSendPeersStatusMsgToPeer
(
pPeer
,
0
);
syncSendPeersStatusMsgToPeer
(
pPeer
,
0
,
pPeersStatus
->
type
+
1
,
pPeersStatus
->
tranId
);
}
}
}
}
...
@@ -956,7 +993,7 @@ static int32_t syncProcessPeerMsg(void *param, void *buffer) {
...
@@ -956,7 +993,7 @@ static int32_t syncProcessPeerMsg(void *param, void *buffer) {
#define statusMsgLen sizeof(SSyncHead) + sizeof(SPeersStatus) + sizeof(SPeerStatus) * TAOS_SYNC_MAX_REPLICA
#define statusMsgLen sizeof(SSyncHead) + sizeof(SPeersStatus) + sizeof(SPeerStatus) * TAOS_SYNC_MAX_REPLICA
static
void
syncSendPeersStatusMsgToPeer
(
SSyncPeer
*
pPeer
,
char
ack
)
{
static
void
syncSendPeersStatusMsgToPeer
(
SSyncPeer
*
pPeer
,
char
ack
,
int8_t
type
,
uint16_t
tranId
)
{
SSyncNode
*
pNode
=
pPeer
->
pSyncNode
;
SSyncNode
*
pNode
=
pPeer
->
pSyncNode
;
char
msg
[
statusMsgLen
]
=
{
0
};
char
msg
[
statusMsgLen
]
=
{
0
};
...
@@ -971,22 +1008,22 @@ static void syncSendPeersStatusMsgToPeer(SSyncPeer *pPeer, char ack) {
...
@@ -971,22 +1008,22 @@ static void syncSendPeersStatusMsgToPeer(SSyncPeer *pPeer, char ack) {
pPeersStatus
->
version
=
nodeVersion
;
pPeersStatus
->
version
=
nodeVersion
;
pPeersStatus
->
role
=
nodeRole
;
pPeersStatus
->
role
=
nodeRole
;
pPeersStatus
->
ack
=
ack
;
pPeersStatus
->
ack
=
ack
;
pPeersStatus
->
type
=
type
;
pPeersStatus
->
tranId
=
tranId
;
for
(
int32_t
i
=
0
;
i
<
pNode
->
replica
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pNode
->
replica
;
++
i
)
{
pPeersStatus
->
peersStatus
[
i
].
role
=
pNode
->
peerInfo
[
i
]
->
role
;
pPeersStatus
->
peersStatus
[
i
].
role
=
pNode
->
peerInfo
[
i
]
->
role
;
pPeersStatus
->
peersStatus
[
i
].
version
=
pNode
->
peerInfo
[
i
]
->
version
;
pPeersStatus
->
peersStatus
[
i
].
version
=
pNode
->
peerInfo
[
i
]
->
version
;
}
}
int32_t
retLen
=
write
(
pPeer
->
peerFd
,
msg
,
statusMsgLen
);
int32_t
retLen
=
taosWriteMsg
(
pPeer
->
peerFd
,
msg
,
statusMsgLen
);
if
(
retLen
==
statusMsgLen
)
{
if
(
retLen
==
statusMsgLen
)
{
sDebug
(
"%s, status msg is sent, self:%s
ver:%"
PRIu64
", ack:%d
"
,
pPeer
->
id
,
syncRole
[
pPeersStatus
->
role
],
sDebug
(
"%s, status msg is sent, self:%s
sver:%"
PRIu64
", ack:%d tranId:%u type:%s
"
,
pPeer
->
id
,
syncRole
[
pPeersStatus
->
role
],
pPeersStatus
->
version
,
pPeersStatus
->
ack
);
pPeersStatus
->
version
,
pPeersStatus
->
ack
,
pPeersStatus
->
tranId
,
statusType
[
pPeersStatus
->
type
]
);
}
else
{
}
else
{
sDebug
(
"%s, failed to send status msg, restart"
,
pPeer
->
id
);
sDebug
(
"%s, failed to send status msg, restart"
,
pPeer
->
id
);
syncRestartConnection
(
pPeer
);
syncRestartConnection
(
pPeer
);
}
}
return
;
}
}
static
void
syncSetupPeerConnection
(
SSyncPeer
*
pPeer
)
{
static
void
syncSetupPeerConnection
(
SSyncPeer
*
pPeer
)
{
...
@@ -995,13 +1032,13 @@ static void syncSetupPeerConnection(SSyncPeer *pPeer) {
...
@@ -995,13 +1032,13 @@ static void syncSetupPeerConnection(SSyncPeer *pPeer) {
taosTmrStopA
(
&
pPeer
->
timer
);
taosTmrStopA
(
&
pPeer
->
timer
);
if
(
pPeer
->
peerFd
>=
0
)
{
if
(
pPeer
->
peerFd
>=
0
)
{
sDebug
(
"%s, send role version to peer"
,
pPeer
->
id
);
sDebug
(
"%s, send role version to peer"
,
pPeer
->
id
);
syncSendPeersStatusMsgToPeer
(
pPeer
,
1
);
syncSendPeersStatusMsgToPeer
(
pPeer
,
1
,
SYNC_STATUS_SETUP_CONN
,
syncGenTranId
()
);
return
;
return
;
}
}
int32_t
connFd
=
taosOpenTcpClientSocket
(
pPeer
->
ip
,
pPeer
->
port
,
0
);
int32_t
connFd
=
taosOpenTcpClientSocket
(
pPeer
->
ip
,
pPeer
->
port
,
0
);
if
(
connFd
<
0
)
{
if
(
connFd
<
0
)
{
sDebug
(
"%s, failed to open tcp socket
(%s)
"
,
pPeer
->
id
,
strerror
(
errno
));
sDebug
(
"%s, failed to open tcp socket
since %s
"
,
pPeer
->
id
,
strerror
(
errno
));
taosTmrReset
(
syncCheckPeerConnection
,
tsSyncTimer
*
1000
,
pPeer
,
tsSyncTmrCtrl
,
&
pPeer
->
timer
);
taosTmrReset
(
syncCheckPeerConnection
,
tsSyncTimer
*
1000
,
pPeer
,
tsSyncTmrCtrl
,
&
pPeer
->
timer
);
return
;
return
;
}
}
...
@@ -1014,15 +1051,15 @@ static void syncSetupPeerConnection(SSyncPeer *pPeer) {
...
@@ -1014,15 +1051,15 @@ static void syncSetupPeerConnection(SSyncPeer *pPeer) {
firstPkt
.
port
=
tsSyncPort
;
firstPkt
.
port
=
tsSyncPort
;
firstPkt
.
sourceId
=
pNode
->
vgId
;
// tell arbitrator its vgId
firstPkt
.
sourceId
=
pNode
->
vgId
;
// tell arbitrator its vgId
if
(
write
(
connFd
,
&
firstPkt
,
sizeof
(
firstPkt
))
==
sizeof
(
firstPkt
))
{
if
(
taosWriteMsg
(
connFd
,
&
firstPkt
,
sizeof
(
firstPkt
))
==
sizeof
(
firstPkt
))
{
sDebug
(
"%s, connection to peer server is setup"
,
pPeer
->
id
);
sDebug
(
"%s, connection to peer server is setup"
,
pPeer
->
id
);
pPeer
->
peerFd
=
connFd
;
pPeer
->
peerFd
=
connFd
;
pPeer
->
role
=
TAOS_SYNC_ROLE_UNSYNCED
;
pPeer
->
role
=
TAOS_SYNC_ROLE_UNSYNCED
;
pPeer
->
pConn
=
taosAllocateTcpConn
(
tsTcpPool
,
pPeer
,
connFd
);
pPeer
->
pConn
=
taosAllocateTcpConn
(
tsTcpPool
,
pPeer
,
connFd
);
syncAddPeerRef
(
pPeer
);
syncAddPeerRef
(
pPeer
);
}
else
{
}
else
{
sDebug
(
"
try later"
);
sDebug
(
"
%s, failed to setup peer connection to server since %s, try later"
,
pPeer
->
id
,
strerror
(
errno
)
);
c
lose
(
connFd
);
taosC
lose
(
connFd
);
taosTmrReset
(
syncCheckPeerConnection
,
tsSyncTimer
*
1000
,
pPeer
,
tsSyncTmrCtrl
,
&
pPeer
->
timer
);
taosTmrReset
(
syncCheckPeerConnection
,
tsSyncTimer
*
1000
,
pPeer
,
tsSyncTmrCtrl
,
&
pPeer
->
timer
);
}
}
}
}
...
@@ -1108,7 +1145,7 @@ static void syncProcessIncommingConnection(int32_t connFd, uint32_t sourceIp) {
...
@@ -1108,7 +1145,7 @@ static void syncProcessIncommingConnection(int32_t connFd, uint32_t sourceIp) {
pPeer
->
pConn
=
taosAllocateTcpConn
(
tsTcpPool
,
pPeer
,
connFd
);
pPeer
->
pConn
=
taosAllocateTcpConn
(
tsTcpPool
,
pPeer
,
connFd
);
syncAddPeerRef
(
pPeer
);
syncAddPeerRef
(
pPeer
);
sDebug
(
"%s, ready to exchange data"
,
pPeer
->
id
);
sDebug
(
"%s, ready to exchange data"
,
pPeer
->
id
);
syncSendPeersStatusMsgToPeer
(
pPeer
,
1
);
syncSendPeersStatusMsgToPeer
(
pPeer
,
1
,
SYNC_STATUS_EXCHANGE_DATA
,
syncGenTranId
()
);
}
}
}
}
...
@@ -1154,7 +1191,7 @@ static void syncSaveFwdInfo(SSyncNode *pNode, uint64_t version, void *mhandle) {
...
@@ -1154,7 +1191,7 @@ static void syncSaveFwdInfo(SSyncNode *pNode, uint64_t version, void *mhandle) {
pFwdInfo
->
time
=
time
;
pFwdInfo
->
time
=
time
;
pSyncFwds
->
fwds
++
;
pSyncFwds
->
fwds
++
;
sDebug
(
"vgId:%d, fwd info is saved, ver:%"
PRIu64
" fwds:%d "
,
pNode
->
vgId
,
version
,
pSyncFwds
->
fwds
);
sDebug
(
"vgId:%d, fwd info is saved,
h
ver:%"
PRIu64
" fwds:%d "
,
pNode
->
vgId
,
version
,
pSyncFwds
->
fwds
);
}
}
static
void
syncRemoveConfirmedFwdInfo
(
SSyncNode
*
pNode
)
{
static
void
syncRemoveConfirmedFwdInfo
(
SSyncNode
*
pNode
)
{
...
@@ -1168,7 +1205,7 @@ static void syncRemoveConfirmedFwdInfo(SSyncNode *pNode) {
...
@@ -1168,7 +1205,7 @@ static void syncRemoveConfirmedFwdInfo(SSyncNode *pNode) {
pSyncFwds
->
first
=
(
pSyncFwds
->
first
+
1
)
%
tsMaxFwdInfo
;
pSyncFwds
->
first
=
(
pSyncFwds
->
first
+
1
)
%
tsMaxFwdInfo
;
pSyncFwds
->
fwds
--
;
pSyncFwds
->
fwds
--
;
if
(
pSyncFwds
->
fwds
==
0
)
pSyncFwds
->
first
=
pSyncFwds
->
last
;
if
(
pSyncFwds
->
fwds
==
0
)
pSyncFwds
->
first
=
pSyncFwds
->
last
;
// sDebug("vgId:%d, fwd info is removed, ver:%d, fwds:%d",
// sDebug("vgId:%d, fwd info is removed,
h
ver:%d, fwds:%d",
// pNode->vgId, pFwdInfo->version, pSyncFwds->fwds);
// pNode->vgId, pFwdInfo->version, pSyncFwds->fwds);
memset
(
pFwdInfo
,
0
,
sizeof
(
SFwdInfo
));
memset
(
pFwdInfo
,
0
,
sizeof
(
SFwdInfo
));
}
}
...
@@ -1191,14 +1228,32 @@ static void syncProcessFwdAck(SSyncNode *pNode, SFwdInfo *pFwdInfo, int32_t code
...
@@ -1191,14 +1228,32 @@ static void syncProcessFwdAck(SSyncNode *pNode, SFwdInfo *pFwdInfo, int32_t code
}
}
if
(
confirm
&&
pFwdInfo
->
confirmed
==
0
)
{
if
(
confirm
&&
pFwdInfo
->
confirmed
==
0
)
{
sDebug
(
"vgId:%d, forward is confirmed, ver:%"
PRIu64
" code:%x"
,
pNode
->
vgId
,
pFwdInfo
->
version
,
pFwdInfo
->
code
);
sDebug
(
"vgId:%d, forward is confirmed,
h
ver:%"
PRIu64
" code:%x"
,
pNode
->
vgId
,
pFwdInfo
->
version
,
pFwdInfo
->
code
);
(
*
pNode
->
confirmForward
)(
pNode
->
ahandle
,
pFwdInfo
->
mhandle
,
pFwdInfo
->
code
);
(
*
pNode
->
confirmForward
)(
pNode
->
ahandle
,
pFwdInfo
->
mhandle
,
pFwdInfo
->
code
);
pFwdInfo
->
confirmed
=
1
;
pFwdInfo
->
confirmed
=
1
;
}
}
}
}
static
void
syncMonitorNodeRole
(
void
*
param
,
void
*
tmrId
)
{
int64_t
rid
=
(
int64_t
)
param
;
SSyncNode
*
pNode
=
taosAcquireRef
(
tsSyncRefId
,
rid
);
if
(
pNode
==
NULL
)
return
;
for
(
int32_t
index
=
0
;
index
<
pNode
->
replica
;
index
++
)
{
if
(
index
==
pNode
->
selfIndex
)
continue
;
SSyncPeer
*
pPeer
=
pNode
->
peerInfo
[
index
];
if
(
pPeer
->
role
<=
TAOS_SYNC_ROLE_UNSYNCED
||
nodeRole
<=
TAOS_SYNC_ROLE_UNSYNCED
)
{
syncSendPeersStatusMsgToPeer
(
pPeer
,
1
,
SYNC_STATUS_CHECK_ROLE
,
syncGenTranId
());
}
}
pNode
->
pRoleTimer
=
taosTmrStart
(
syncMonitorNodeRole
,
SYNC_ROLE_TIMER
,
(
void
*
)
pNode
->
rid
,
tsSyncTmrCtrl
);
taosReleaseRef
(
tsSyncRefId
,
rid
);
}
static
void
syncMonitorFwdInfos
(
void
*
param
,
void
*
tmrId
)
{
static
void
syncMonitorFwdInfos
(
void
*
param
,
void
*
tmrId
)
{
int64_t
rid
=
(
int64_t
)
param
;
int64_t
rid
=
(
int64_t
)
param
;
SSyncNode
*
pNode
=
taosAcquireRef
(
tsSyncRefId
,
rid
);
SSyncNode
*
pNode
=
taosAcquireRef
(
tsSyncRefId
,
rid
);
if
(
pNode
==
NULL
)
return
;
if
(
pNode
==
NULL
)
return
;
...
@@ -1222,7 +1277,7 @@ static void syncMonitorFwdInfos(void *param, void *tmrId) {
...
@@ -1222,7 +1277,7 @@ static void syncMonitorFwdInfos(void *param, void *tmrId) {
pthread_mutex_unlock
(
&
(
pNode
->
mutex
));
pthread_mutex_unlock
(
&
(
pNode
->
mutex
));
}
}
pNode
->
pFwdTimer
=
taosTmrStart
(
syncMonitorFwdInfos
,
300
,
(
void
*
)
pNode
->
rid
,
tsSyncTmrCtrl
);
pNode
->
pFwdTimer
=
taosTmrStart
(
syncMonitorFwdInfos
,
SYNC_FWD_TIMER
,
(
void
*
)
pNode
->
rid
,
tsSyncTmrCtrl
);
}
}
taosReleaseRef
(
tsSyncRefId
,
rid
);
taosReleaseRef
(
tsSyncRefId
,
rid
);
...
@@ -1237,7 +1292,7 @@ static int32_t syncForwardToPeerImpl(SSyncNode *pNode, void *data, void *mhandle
...
@@ -1237,7 +1292,7 @@ static int32_t syncForwardToPeerImpl(SSyncNode *pNode, void *data, void *mhandle
if
(
pWalHead
->
version
>
nodeVersion
+
1
)
{
if
(
pWalHead
->
version
>
nodeVersion
+
1
)
{
sError
(
"vgId:%d, hver:%"
PRIu64
", inconsistent with ver:%"
PRIu64
,
pNode
->
vgId
,
pWalHead
->
version
,
nodeVersion
);
sError
(
"vgId:%d, hver:%"
PRIu64
", inconsistent with
s
ver:%"
PRIu64
,
pNode
->
vgId
,
pWalHead
->
version
,
nodeVersion
);
if
(
nodeRole
==
TAOS_SYNC_ROLE_SLAVE
)
{
if
(
nodeRole
==
TAOS_SYNC_ROLE_SLAVE
)
{
sInfo
(
"vgId:%d, restart connection"
,
pNode
->
vgId
);
sInfo
(
"vgId:%d, restart connection"
,
pNode
->
vgId
);
for
(
int32_t
i
=
0
;
i
<
pNode
->
replica
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pNode
->
replica
;
++
i
)
{
...
@@ -1280,9 +1335,9 @@ static int32_t syncForwardToPeerImpl(SSyncNode *pNode, void *data, void *mhandle
...
@@ -1280,9 +1335,9 @@ static int32_t syncForwardToPeerImpl(SSyncNode *pNode, void *data, void *mhandle
int32_t
retLen
=
write
(
pPeer
->
peerFd
,
pSyncHead
,
fwdLen
);
int32_t
retLen
=
write
(
pPeer
->
peerFd
,
pSyncHead
,
fwdLen
);
if
(
retLen
==
fwdLen
)
{
if
(
retLen
==
fwdLen
)
{
sDebug
(
"%s, forward is sent, ver:%"
PRIu64
" contLen:%d"
,
pPeer
->
id
,
pWalHead
->
version
,
pWalHead
->
len
);
sDebug
(
"%s, forward is sent,
h
ver:%"
PRIu64
" contLen:%d"
,
pPeer
->
id
,
pWalHead
->
version
,
pWalHead
->
len
);
}
else
{
}
else
{
sError
(
"%s, failed to forward, ver:%"
PRIu64
" retLen:%d"
,
pPeer
->
id
,
pWalHead
->
version
,
retLen
);
sError
(
"%s, failed to forward,
h
ver:%"
PRIu64
" retLen:%d"
,
pPeer
->
id
,
pWalHead
->
version
,
retLen
);
syncRestartConnection
(
pPeer
);
syncRestartConnection
(
pPeer
);
}
}
}
}
...
...
src/sync/src/syncRestore.c
浏览文件 @
ea3aae75
...
@@ -140,6 +140,7 @@ static int32_t syncRestoreWal(SSyncPeer *pPeer) {
...
@@ -140,6 +140,7 @@ static int32_t syncRestoreWal(SSyncPeer *pPeer) {
if
(
buffer
==
NULL
)
return
-
1
;
if
(
buffer
==
NULL
)
return
-
1
;
SWalHead
*
pHead
=
(
SWalHead
*
)
buffer
;
SWalHead
*
pHead
=
(
SWalHead
*
)
buffer
;
uint64_t
lastVer
=
0
;
while
(
1
)
{
while
(
1
)
{
ret
=
taosReadMsg
(
pPeer
->
syncFd
,
pHead
,
sizeof
(
SWalHead
));
ret
=
taosReadMsg
(
pPeer
->
syncFd
,
pHead
,
sizeof
(
SWalHead
));
...
@@ -153,7 +154,14 @@ static int32_t syncRestoreWal(SSyncPeer *pPeer) {
...
@@ -153,7 +154,14 @@ static int32_t syncRestoreWal(SSyncPeer *pPeer) {
ret
=
taosReadMsg
(
pPeer
->
syncFd
,
pHead
->
cont
,
pHead
->
len
);
ret
=
taosReadMsg
(
pPeer
->
syncFd
,
pHead
->
cont
,
pHead
->
len
);
if
(
ret
<
0
)
break
;
if
(
ret
<
0
)
break
;
sDebug
(
"%s, restore a record, qtype:wal hver:%"
PRIu64
,
pPeer
->
id
,
pHead
->
version
);
sDebug
(
"%s, restore a record, qtype:wal len:%d hver:%"
PRIu64
,
pPeer
->
id
,
pHead
->
len
,
pHead
->
version
);
if
(
lastVer
==
pHead
->
version
)
{
sError
(
"%s, failed to restore record, same hver:%"
PRIu64
", wal sync failed"
PRIu64
,
pPeer
->
id
,
lastVer
);
break
;
}
lastVer
=
pHead
->
version
;
(
*
pNode
->
writeToCache
)(
pNode
->
ahandle
,
pHead
,
TAOS_QTYPE_WAL
,
NULL
);
(
*
pNode
->
writeToCache
)(
pNode
->
ahandle
,
pHead
,
TAOS_QTYPE_WAL
,
NULL
);
}
}
...
@@ -214,7 +222,7 @@ int32_t syncSaveIntoBuffer(SSyncPeer *pPeer, SWalHead *pHead) {
...
@@ -214,7 +222,7 @@ int32_t syncSaveIntoBuffer(SSyncPeer *pPeer, SWalHead *pHead) {
memcpy
(
pRecv
->
offset
,
pHead
,
len
);
memcpy
(
pRecv
->
offset
,
pHead
,
len
);
pRecv
->
offset
+=
len
;
pRecv
->
offset
+=
len
;
pRecv
->
forwards
++
;
pRecv
->
forwards
++
;
sDebug
(
"%s, fwd is saved into queue, ver:%"
PRIu64
" fwds:%d"
,
pPeer
->
id
,
pHead
->
version
,
pRecv
->
forwards
);
sDebug
(
"%s, fwd is saved into queue,
h
ver:%"
PRIu64
" fwds:%d"
,
pPeer
->
id
,
pHead
->
version
,
pRecv
->
forwards
);
}
else
{
}
else
{
sError
(
"%s, buffer size:%d is too small"
,
pPeer
->
id
,
pRecv
->
bufferSize
);
sError
(
"%s, buffer size:%d is too small"
,
pPeer
->
id
,
pRecv
->
bufferSize
);
pRecv
->
code
=
-
1
;
// set error code
pRecv
->
code
=
-
1
;
// set error code
...
@@ -291,7 +299,7 @@ static int32_t syncRestoreDataStepByStep(SSyncPeer *pPeer) {
...
@@ -291,7 +299,7 @@ static int32_t syncRestoreDataStepByStep(SSyncPeer *pPeer) {
}
}
void
*
syncRestoreData
(
void
*
param
)
{
void
*
syncRestoreData
(
void
*
param
)
{
SSyncPeer
*
pPeer
=
(
SSyncPeer
*
)
param
;
SSyncPeer
*
pPeer
=
param
;
SSyncNode
*
pNode
=
pPeer
->
pSyncNode
;
SSyncNode
*
pNode
=
pPeer
->
pSyncNode
;
taosBlockSIGPIPE
();
taosBlockSIGPIPE
();
...
@@ -300,7 +308,8 @@ void *syncRestoreData(void *param) {
...
@@ -300,7 +308,8 @@ void *syncRestoreData(void *param) {
(
*
pNode
->
notifyRole
)(
pNode
->
ahandle
,
TAOS_SYNC_ROLE_SYNCING
);
(
*
pNode
->
notifyRole
)(
pNode
->
ahandle
,
TAOS_SYNC_ROLE_SYNCING
);
if
(
syncOpenRecvBuffer
(
pNode
)
<
0
)
{
if
(
syncOpenRecvBuffer
(
pNode
)
<
0
)
{
sError
(
"%s, failed to allocate recv buffer"
,
pPeer
->
id
);
sError
(
"%s, failed to allocate recv buffer, restart connection"
,
pPeer
->
id
);
syncRestartConnection
(
pPeer
);
}
else
{
}
else
{
if
(
syncRestoreDataStepByStep
(
pPeer
)
==
0
)
{
if
(
syncRestoreDataStepByStep
(
pPeer
)
==
0
)
{
sInfo
(
"%s, it is synced successfully"
,
pPeer
->
id
);
sInfo
(
"%s, it is synced successfully"
,
pPeer
->
id
);
...
...
src/sync/src/syncRetrieve.c
浏览文件 @
ea3aae75
...
@@ -268,7 +268,7 @@ static int32_t syncRetrieveLastWal(SSyncPeer *pPeer, char *name, uint64_t fversi
...
@@ -268,7 +268,7 @@ static int32_t syncRetrieveLastWal(SSyncPeer *pPeer, char *name, uint64_t fversi
break
;
break
;
}
}
sDebug
(
"%s, last wal is forwarded, ver:%"
PRIu64
,
pPeer
->
id
,
pHead
->
version
);
sDebug
(
"%s, last wal is forwarded,
h
ver:%"
PRIu64
,
pPeer
->
id
,
pHead
->
version
);
int32_t
ret
=
taosWriteMsg
(
pPeer
->
syncFd
,
pHead
,
wsize
);
int32_t
ret
=
taosWriteMsg
(
pPeer
->
syncFd
,
pHead
,
wsize
);
if
(
ret
!=
wsize
)
break
;
if
(
ret
!=
wsize
)
break
;
pPeer
->
sversion
=
pHead
->
version
;
pPeer
->
sversion
=
pHead
->
version
;
...
@@ -418,7 +418,7 @@ static int32_t syncRetrieveWal(SSyncPeer *pPeer) {
...
@@ -418,7 +418,7 @@ static int32_t syncRetrieveWal(SSyncPeer *pPeer) {
}
}
if
(
code
==
0
)
{
if
(
code
==
0
)
{
s
Debug
(
"%s, wal retrieve is finished"
,
pPeer
->
id
);
s
Info
(
"%s, wal retrieve is finished"
,
pPeer
->
id
);
pPeer
->
sstatus
=
TAOS_SYNC_STATUS_CACHE
;
pPeer
->
sstatus
=
TAOS_SYNC_STATUS_CACHE
;
SWalHead
walHead
;
SWalHead
walHead
;
memset
(
&
walHead
,
0
,
sizeof
(
walHead
));
memset
(
&
walHead
,
0
,
sizeof
(
walHead
));
...
@@ -447,7 +447,7 @@ static int32_t syncRetrieveDataStepByStep(SSyncPeer *pPeer) {
...
@@ -447,7 +447,7 @@ static int32_t syncRetrieveDataStepByStep(SSyncPeer *pPeer) {
pPeer
->
sversion
=
0
;
pPeer
->
sversion
=
0
;
pPeer
->
sstatus
=
TAOS_SYNC_STATUS_FILE
;
pPeer
->
sstatus
=
TAOS_SYNC_STATUS_FILE
;
s
Debug
(
"%s, start to retrieve file"
,
pPeer
->
id
);
s
Info
(
"%s, start to retrieve file"
,
pPeer
->
id
);
if
(
syncRetrieveFile
(
pPeer
)
<
0
)
{
if
(
syncRetrieveFile
(
pPeer
)
<
0
)
{
sError
(
"%s, failed to retrieve file"
,
pPeer
->
id
);
sError
(
"%s, failed to retrieve file"
,
pPeer
->
id
);
return
-
1
;
return
-
1
;
...
@@ -456,7 +456,7 @@ static int32_t syncRetrieveDataStepByStep(SSyncPeer *pPeer) {
...
@@ -456,7 +456,7 @@ static int32_t syncRetrieveDataStepByStep(SSyncPeer *pPeer) {
// if no files are synced, there must be wal to sync, sversion must be larger than one
// if no files are synced, there must be wal to sync, sversion must be larger than one
if
(
pPeer
->
sversion
==
0
)
pPeer
->
sversion
=
1
;
if
(
pPeer
->
sversion
==
0
)
pPeer
->
sversion
=
1
;
s
Debug
(
"%s, start to retrieve wal"
,
pPeer
->
id
);
s
Info
(
"%s, start to retrieve wal"
,
pPeer
->
id
);
if
(
syncRetrieveWal
(
pPeer
)
<
0
)
{
if
(
syncRetrieveWal
(
pPeer
)
<
0
)
{
sError
(
"%s, failed to retrieve wal"
,
pPeer
->
id
);
sError
(
"%s, failed to retrieve wal"
,
pPeer
->
id
);
return
-
1
;
return
-
1
;
...
@@ -478,7 +478,7 @@ void *syncRetrieveData(void *param) {
...
@@ -478,7 +478,7 @@ void *syncRetrieveData(void *param) {
sInfo
(
"%s, sync tcp is setup"
,
pPeer
->
id
);
sInfo
(
"%s, sync tcp is setup"
,
pPeer
->
id
);
if
(
syncRetrieveDataStepByStep
(
pPeer
)
==
0
)
{
if
(
syncRetrieveDataStepByStep
(
pPeer
)
==
0
)
{
s
Debug
(
"%s, sync retrieve process is successful"
,
pPeer
->
id
);
s
Info
(
"%s, sync retrieve process is successful"
,
pPeer
->
id
);
}
else
{
}
else
{
sError
(
"%s, failed to retrieve data, restart connection"
,
pPeer
->
id
);
sError
(
"%s, failed to retrieve data, restart connection"
,
pPeer
->
id
);
syncRestartConnection
(
pPeer
);
syncRestartConnection
(
pPeer
);
...
...
src/sync/src/taosTcpPool.c
浏览文件 @
ea3aae75
...
@@ -150,7 +150,7 @@ void *taosAllocateTcpConn(void *param, void *pPeer, int32_t connFd) {
...
@@ -150,7 +150,7 @@ void *taosAllocateTcpConn(void *param, void *pPeer, int32_t connFd) {
}
}
void
taosFreeTcpConn
(
void
*
param
)
{
void
taosFreeTcpConn
(
void
*
param
)
{
SConnObj
*
pConn
=
(
SConnObj
*
)
param
;
SConnObj
*
pConn
=
param
;
SThreadObj
*
pThread
=
pConn
->
pThread
;
SThreadObj
*
pThread
=
pConn
->
pThread
;
sDebug
(
"%p TCP connection will be closed, fd:%d"
,
pThread
,
pConn
->
fd
);
sDebug
(
"%p TCP connection will be closed, fd:%d"
,
pThread
,
pConn
->
fd
);
...
...
src/wal/src/walWrite.c
浏览文件 @
ea3aae75
...
@@ -144,9 +144,9 @@ void walFsync(void *handle, bool forceFsync) {
...
@@ -144,9 +144,9 @@ void walFsync(void *handle, bool forceFsync) {
if
(
pWal
==
NULL
||
pWal
->
fd
<
0
)
return
;
if
(
pWal
==
NULL
||
pWal
->
fd
<
0
)
return
;
if
(
forceFsync
||
(
pWal
->
level
==
TAOS_WAL_FSYNC
&&
pWal
->
fsyncPeriod
==
0
))
{
if
(
forceFsync
||
(
pWal
->
level
==
TAOS_WAL_FSYNC
&&
pWal
->
fsyncPeriod
==
0
))
{
wTrace
(
"vgId:%d, file
:%s, do fsync"
,
pWal
->
vgId
,
pWal
->
name
);
wTrace
(
"vgId:%d, file
Id:%"
PRId64
", do fsync"
,
pWal
->
vgId
,
pWal
->
fileId
);
if
(
fsync
(
pWal
->
fd
)
<
0
)
{
if
(
fsync
(
pWal
->
fd
)
<
0
)
{
wError
(
"vgId:%d, file
:%s, fsync failed since %s"
,
pWal
->
vgId
,
pWal
->
name
,
strerror
(
errno
));
wError
(
"vgId:%d, file
Id:%"
PRId64
", fsync failed since %s"
,
pWal
->
vgId
,
pWal
->
fileId
,
strerror
(
errno
));
}
}
}
}
}
}
...
...
tests/script/sh/deploy.sh
浏览文件 @
ea3aae75
...
@@ -111,24 +111,24 @@ echo "serverPort ${NODE}" >> $TAOS_CFG
...
@@ -111,24 +111,24 @@ echo "serverPort ${NODE}" >> $TAOS_CFG
echo
"dataDir
$DATA_DIR
"
>>
$TAOS_CFG
echo
"dataDir
$DATA_DIR
"
>>
$TAOS_CFG
echo
"logDir
$LOG_DIR
"
>>
$TAOS_CFG
echo
"logDir
$LOG_DIR
"
>>
$TAOS_CFG
echo
"debugFlag 0"
>>
$TAOS_CFG
echo
"debugFlag 0"
>>
$TAOS_CFG
echo
"mDebugFlag 1
43
"
>>
$TAOS_CFG
echo
"mDebugFlag 1
35
"
>>
$TAOS_CFG
echo
"sdbDebugFlag 1
43
"
>>
$TAOS_CFG
echo
"sdbDebugFlag 1
35
"
>>
$TAOS_CFG
echo
"dDebugFlag 1
43
"
>>
$TAOS_CFG
echo
"dDebugFlag 1
35
"
>>
$TAOS_CFG
echo
"vDebugFlag 1
43
"
>>
$TAOS_CFG
echo
"vDebugFlag 1
35
"
>>
$TAOS_CFG
echo
"tsdbDebugFlag 1
43
"
>>
$TAOS_CFG
echo
"tsdbDebugFlag 1
35
"
>>
$TAOS_CFG
echo
"cDebugFlag 1
43
"
>>
$TAOS_CFG
echo
"cDebugFlag 1
35
"
>>
$TAOS_CFG
echo
"jnidebugFlag 1
43
"
>>
$TAOS_CFG
echo
"jnidebugFlag 1
35
"
>>
$TAOS_CFG
echo
"odbcdebugFlag 1
43
"
>>
$TAOS_CFG
echo
"odbcdebugFlag 1
35
"
>>
$TAOS_CFG
echo
"httpDebugFlag 1
43
"
>>
$TAOS_CFG
echo
"httpDebugFlag 1
35
"
>>
$TAOS_CFG
echo
"monitorDebugFlag 1
43
"
>>
$TAOS_CFG
echo
"monitorDebugFlag 1
35
"
>>
$TAOS_CFG
echo
"mqttDebugFlag 1
43
"
>>
$TAOS_CFG
echo
"mqttDebugFlag 1
35
"
>>
$TAOS_CFG
echo
"qdebugFlag 1
43
"
>>
$TAOS_CFG
echo
"qdebugFlag 1
35
"
>>
$TAOS_CFG
echo
"rpcDebugFlag 1
43
"
>>
$TAOS_CFG
echo
"rpcDebugFlag 1
35
"
>>
$TAOS_CFG
echo
"tmrDebugFlag 131"
>>
$TAOS_CFG
echo
"tmrDebugFlag 131"
>>
$TAOS_CFG
echo
"udebugFlag 1
43
"
>>
$TAOS_CFG
echo
"udebugFlag 1
35
"
>>
$TAOS_CFG
echo
"sdebugFlag 1
43
"
>>
$TAOS_CFG
echo
"sdebugFlag 1
35
"
>>
$TAOS_CFG
echo
"wdebugFlag 1
43
"
>>
$TAOS_CFG
echo
"wdebugFlag 1
35
"
>>
$TAOS_CFG
echo
"cqdebugFlag 1
43
"
>>
$TAOS_CFG
echo
"cqdebugFlag 1
35
"
>>
$TAOS_CFG
echo
"monitor 0"
>>
$TAOS_CFG
echo
"monitor 0"
>>
$TAOS_CFG
echo
"monitorInterval 1"
>>
$TAOS_CFG
echo
"monitorInterval 1"
>>
$TAOS_CFG
echo
"http 0"
>>
$TAOS_CFG
echo
"http 0"
>>
$TAOS_CFG
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录