Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
d7fe6bb9
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
d7fe6bb9
编写于
2月 27, 2023
作者:
K
kailixu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh: suuport create child/normal table by specified uid/tid
上级
7427a37f
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
102 addition
and
37 deletion
+102
-37
src/common/src/tglobal.c
src/common/src/tglobal.c
+1
-1
src/inc/taoserror.h
src/inc/taoserror.h
+2
-0
src/mnode/src/mnodeTable.c
src/mnode/src/mnodeTable.c
+54
-30
src/mnode/src/mnodeVgroup.c
src/mnode/src/mnodeVgroup.c
+10
-6
src/util/inc/tidpool.h
src/util/inc/tidpool.h
+2
-0
src/util/src/terror.c
src/util/src/terror.c
+3
-0
src/util/src/tidpool.c
src/util/src/tidpool.c
+30
-0
未找到文件。
src/common/src/tglobal.c
浏览文件 @
d7fe6bb9
...
@@ -232,7 +232,7 @@ int32_t tsKeepTimeOffset = 0;
...
@@ -232,7 +232,7 @@ int32_t tsKeepTimeOffset = 0;
int32_t
tsDiskCfgNum
=
0
;
int32_t
tsDiskCfgNum
=
0
;
int32_t
tsTopicBianryLen
=
16000
;
int32_t
tsTopicBianryLen
=
16000
;
int32_t
tsMetaSyncOption
=
1
;
int32_t
tsMetaSyncOption
=
0
;
#ifndef _STORAGE
#ifndef _STORAGE
SDiskCfg
tsDiskCfg
[
1
];
SDiskCfg
tsDiskCfg
[
1
];
...
...
src/inc/taoserror.h
浏览文件 @
d7fe6bb9
...
@@ -223,6 +223,8 @@ int32_t* taosGetErrno();
...
@@ -223,6 +223,8 @@ int32_t* taosGetErrno();
#define TSDB_CODE_MND_TOPIC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0395) //"Topic already exists)
#define TSDB_CODE_MND_TOPIC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0395) //"Topic already exists)
#define TSDB_CODE_MND_INVALID_FORMAT TAOS_DEF_ERROR_CODE(0, 0x0396) //"Invalid format)
#define TSDB_CODE_MND_INVALID_FORMAT TAOS_DEF_ERROR_CODE(0, 0x0396) //"Invalid format)
#define TSDB_CODE_MND_DUP_TID TAOS_DEF_ERROR_CODE(0, 0x0397) //"Duplicated tid)
#define TSDB_CODE_MND_ID_POOL_IS_FULL TAOS_DEF_ERROR_CODE(0, 0x0398) //"Id pool is full)
// dnode
// dnode
#define TSDB_CODE_DND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0400) //"Message not processed"
#define TSDB_CODE_DND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0400) //"Message not processed"
...
...
src/mnode/src/mnodeTable.c
浏览文件 @
d7fe6bb9
...
@@ -64,6 +64,13 @@ static SHashObj *tsSTableUidHash;
...
@@ -64,6 +64,13 @@ static SHashObj *tsSTableUidHash;
static
int32_t
tsChildTableUpdateSize
;
static
int32_t
tsChildTableUpdateSize
;
static
int32_t
tsSuperTableUpdateSize
;
static
int32_t
tsSuperTableUpdateSize
;
typedef
struct
{
int32_t
vgId
;
int32_t
tid
;
uint64_t
uid
;
uint64_t
suid
;
}
SMetaInfo
;
static
void
*
mnodeGetChildTable
(
char
*
tableId
);
static
void
*
mnodeGetChildTable
(
char
*
tableId
);
static
void
*
mnodeGetSuperTable
(
char
*
tableId
);
static
void
*
mnodeGetSuperTable
(
char
*
tableId
);
static
void
*
mnodeGetSuperTableByUid
(
uint64_t
uid
);
static
void
*
mnodeGetSuperTableByUid
(
uint64_t
uid
);
...
@@ -82,7 +89,7 @@ static int32_t mnodeProcessCreateTableMsg(SMnodeMsg *pMsg);
...
@@ -82,7 +89,7 @@ static int32_t mnodeProcessCreateTableMsg(SMnodeMsg *pMsg);
static
int32_t
mnodeProcessCreateSuperTableMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnodeProcessCreateSuperTableMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnodeProcessCreateChildTableMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnodeProcessCreateChildTableMsg
(
SMnodeMsg
*
pMsg
);
static
void
mnodeProcessCreateChildTableRsp
(
SRpcMsg
*
rpcMsg
);
static
void
mnodeProcessCreateChildTableRsp
(
SRpcMsg
*
rpcMsg
);
static
int32_t
mnodeProcessMetaSyncCreateChildTableMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnodeProcessMetaSyncCreateChildTableMsg
(
SMnodeMsg
*
pMsg
,
SMetaInfo
*
pInf
);
static
int32_t
mnodeProcessDropTableMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnodeProcessDropTableMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnodeProcessDropSuperTableMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnodeProcessDropSuperTableMsg
(
SMnodeMsg
*
pMsg
);
...
@@ -2164,7 +2171,7 @@ static int32_t mnodeDoCreateChildTableCb(SMnodeMsg *pMsg, int32_t code) {
...
@@ -2164,7 +2171,7 @@ static int32_t mnodeDoCreateChildTableCb(SMnodeMsg *pMsg, int32_t code) {
}
}
}
}
static
int32_t
mnodeDoCreateChildTable
(
SMnodeMsg
*
pMsg
,
int32_t
tid
)
{
static
int32_t
mnodeDoCreateChildTable
(
SMnodeMsg
*
pMsg
,
SMetaInfo
*
pInf
)
{
SVgObj
*
pVgroup
=
pMsg
->
pVgroup
;
SVgObj
*
pVgroup
=
pMsg
->
pVgroup
;
SCMCreateTableMsg
*
p1
=
pMsg
->
rpcMsg
.
pCont
;
SCMCreateTableMsg
*
p1
=
pMsg
->
rpcMsg
.
pCont
;
...
@@ -2179,7 +2186,7 @@ static int32_t mnodeDoCreateChildTable(SMnodeMsg *pMsg, int32_t tid) {
...
@@ -2179,7 +2186,7 @@ static int32_t mnodeDoCreateChildTable(SMnodeMsg *pMsg, int32_t tid) {
pTable
->
info
.
type
=
(
pCreate
->
numOfColumns
==
0
)
?
TSDB_CHILD_TABLE
:
TSDB_NORMAL_TABLE
;
pTable
->
info
.
type
=
(
pCreate
->
numOfColumns
==
0
)
?
TSDB_CHILD_TABLE
:
TSDB_NORMAL_TABLE
;
pTable
->
info
.
tableId
=
strdup
(
pCreate
->
tableName
);
pTable
->
info
.
tableId
=
strdup
(
pCreate
->
tableName
);
pTable
->
createdTime
=
taosGetTimestampMs
();
pTable
->
createdTime
=
taosGetTimestampMs
();
pTable
->
tid
=
tid
;
pTable
->
tid
=
pInf
->
tid
;
pTable
->
vgId
=
pVgroup
->
vgId
;
pTable
->
vgId
=
pVgroup
->
vgId
;
if
(
pTable
->
info
.
type
==
TSDB_CHILD_TABLE
)
{
if
(
pTable
->
info
.
type
==
TSDB_CHILD_TABLE
)
{
...
@@ -2207,13 +2214,21 @@ static int32_t mnodeDoCreateChildTable(SMnodeMsg *pMsg, int32_t tid) {
...
@@ -2207,13 +2214,21 @@ static int32_t mnodeDoCreateChildTable(SMnodeMsg *pMsg, int32_t tid) {
}
}
pTable
->
suid
=
pMsg
->
pSTable
->
uid
;
pTable
->
suid
=
pMsg
->
pSTable
->
uid
;
pTable
->
uid
=
mnodeCreateTableUid
(
pTable
->
vgId
,
pTable
->
tid
);
if
(
tsMetaSyncOption
&&
pInf
->
uid
!=
(
uint64_t
)
-
1
)
{
pTable
->
uid
=
pInf
->
uid
;
}
else
{
pTable
->
uid
=
mnodeCreateTableUid
(
pTable
->
vgId
,
pTable
->
tid
);
}
pTable
->
superTable
=
pMsg
->
pSTable
;
pTable
->
superTable
=
pMsg
->
pSTable
;
}
else
{
}
else
{
if
(
pTable
->
info
.
type
==
TSDB_SUPER_TABLE
)
{
if
(
pTable
->
info
.
type
==
TSDB_SUPER_TABLE
)
{
pTable
->
uid
=
mnodeCreateSuperTableUid
();
pTable
->
uid
=
mnodeCreateSuperTableUid
();
}
else
{
}
else
{
pTable
->
uid
=
mnodeCreateTableUid
(
pTable
->
vgId
,
pTable
->
tid
);
if
(
tsMetaSyncOption
&&
pInf
->
uid
!=
(
uint64_t
)
-
1
)
{
pTable
->
uid
=
pInf
->
uid
;
}
else
{
pTable
->
uid
=
mnodeCreateTableUid
(
pTable
->
vgId
,
pTable
->
tid
);
}
}
}
pTable
->
sversion
=
0
;
pTable
->
sversion
=
0
;
...
@@ -2266,57 +2281,69 @@ static int32_t mnodeDoCreateChildTable(SMnodeMsg *pMsg, int32_t tid) {
...
@@ -2266,57 +2281,69 @@ static int32_t mnodeDoCreateChildTable(SMnodeMsg *pMsg, int32_t tid) {
mError
(
"msg:%p, app:%p table:%s, failed to create, reason:%s"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
tableName
,
mError
(
"msg:%p, app:%p table:%s, failed to create, reason:%s"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
tableName
,
tstrerror
(
code
));
tstrerror
(
code
));
}
else
{
}
else
{
m
Debug
(
"msg:%p, app:%p table:%s, allocated in vgroup, vgId:%d sid:%d uid:%"
PRIu64
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
m
Info
(
"msg:%p, app:%p table:%s, allocated in vgroup, vgId:%d sid:%d uid:%"
PRIu64
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pTable
->
info
.
tableId
,
pVgroup
->
vgId
,
pTable
->
tid
,
pTable
->
uid
);
pTable
->
info
.
tableId
,
pVgroup
->
vgId
,
pTable
->
tid
,
pTable
->
uid
);
}
}
return
code
;
return
code
;
}
}
static
int32_t
mnodeProcessMetaSyncCreateChildTableMsg
(
SMnodeMsg
*
pMsg
,
int32_t
*
tid
,
int32_t
*
vgId
,
uint64_t
*
uid
,
static
int32_t
mnodeProcessMetaSyncCreateChildTableMsg
(
SMnodeMsg
*
pMsg
,
SMetaInfo
*
pInf
)
{
uint64_t
*
suid
)
{
SCreateTableMsg
*
pCreate
=
(
SCreateTableMsg
*
)((
char
*
)
pMsg
->
rpcMsg
.
pCont
+
sizeof
(
SCMCreateTableMsg
));
SCreateTableMsg
*
pCreate
=
(
SCreateTableMsg
*
)((
char
*
)
pMsg
->
rpcMsg
.
pCont
+
sizeof
(
SCMCreateTableMsg
));
int32_t
code
=
0
;
int32_t
code
=
0
;
// 0.db0._taos_meta_sync_cret_mndtb_taos_vgId.suid.uid.tid
// 0.db0._taos_meta_sync_cret_mndtb_taos_vgId.suid.uid.tid
.tbName
if
(
strstr
(
pCreate
->
tableName
,
META_SYNC_CRET_MNDTB
))
{
if
(
strstr
(
pCreate
->
tableName
,
META_SYNC_CRET_MNDTB
))
{
code
=
TSDB_CODE_MND_INVALID_FORMAT
;
char
realName
[
TSDB_TABLE_FNAME_LEN
]
=
{
0
};
char
*
pTbName
=
strchr
(
pCreate
->
tableName
,
'.'
);
char
*
pTbName
=
strchr
(
pCreate
->
tableName
,
'.'
);
if
(
pTbName
&&
(
pTbName
=
strchr
(
pTbName
+
1
,
'.'
)))
{
if
(
pTbName
&&
(
pTbName
=
strchr
(
pTbName
+
1
,
'.'
)))
{
if
(
0
==
strncmp
(
META_SYNC_CRET_MNDTB
,
++
pTbName
,
META_SYNC_TABLE_NAME_LEN
))
{
if
(
0
==
strncmp
(
META_SYNC_CRET_MNDTB
,
++
pTbName
,
META_SYNC_TABLE_NAME_LEN
))
{
strncpy
(
realName
,
pCreate
->
tableName
,
POINTER_DISTANCE
(
pTbName
,
pCreate
->
tableName
));
pTbName
+=
META_SYNC_TABLE_NAME_LEN
;
pTbName
+=
META_SYNC_TABLE_NAME_LEN
;
*
vgId
=
atoi
(
pTbName
);
pInf
->
vgId
=
atoi
(
pTbName
);
if
((
pTbName
=
strchr
(
pTbName
,
'.'
)))
{
if
((
pTbName
=
strchr
(
pTbName
,
'.'
)))
{
*
suid
=
strtoull
(
++
pTbName
,
NULL
,
10
);
pInf
->
suid
=
strtoull
(
++
pTbName
,
NULL
,
10
);
if
((
pTbName
=
strchr
(
pTbName
,
'.'
)))
{
if
((
pTbName
=
strchr
(
pTbName
,
'.'
)))
{
*
uid
=
strtoull
(
++
pTbName
,
NULL
,
10
);
pInf
->
uid
=
strtoull
(
++
pTbName
,
NULL
,
10
);
if
((
pTbName
=
strchr
(
pTbName
,
'.'
)))
{
if
((
pTbName
=
strchr
(
pTbName
,
'.'
)))
{
*
tid
=
atoi
(
++
pTbName
);
pInf
->
tid
=
atoi
(
++
pTbName
);
if
((
pTbName
=
strchr
(
pTbName
,
'.'
)))
{
int32_t
len
=
strlen
(
realName
);
strncpy
(
realName
+
len
,
pTbName
+
1
,
TSDB_TABLE_FNAME_LEN
-
len
-
1
);
code
=
0
;
}
}
}
}
}
}
}
}
}
}
}
if
(
*
tid
<=
0
||
*
uid
==
(
uint64_t
)
-
1
||
*
vgId
<=
0
)
{
if
(
code
!=
0
||
pInf
->
tid
<
1
||
pInf
->
uid
==
(
uint64_t
)
-
1
||
pInf
->
vgId
<
2
)
{
code
=
TSDB_CODE_MND_INVALID_FORMAT
;
code
=
TSDB_CODE_MND_INVALID_FORMAT
;
mError
(
"
msg:%p, app:%p table:%s, failed to create table, reason:%s"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
mError
(
"
%s:%d msg:%p, app:%p table:%s, failed to create table, reason:%s"
,
__func__
,
__LINE__
,
pMsg
,
pCreate
->
tableName
,
tstrerror
(
code
));
p
Msg
->
rpcMsg
.
ahandle
,
p
Create
->
tableName
,
tstrerror
(
code
));
return
code
;
return
code
;
}
}
mInfo
(
"msg:%p, app:%p table:%s, start to create table, vgId:%d suid:%"
PRIu64
" uid:%"
PRIu64
" tid:%d"
,
pMsg
,
mInfo
(
"%s:%d msg:%p, app:%p table:%s, start to create table, vgId:%d suid:%"
PRIu64
" uid:%"
PRIu64
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
tableName
,
*
vgId
,
*
suid
,
*
uid
,
*
tid
);
" tid:%d realName:%s"
,
__func__
,
__LINE__
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
tableName
,
pInf
->
vgId
,
pInf
->
suid
,
pInf
->
uid
,
pInf
->
tid
,
realName
);
strncpy
(
pCreate
->
tableName
,
realName
,
TSDB_TABLE_FNAME_LEN
);
}
else
if
(
strstr
(
pCreate
->
tableName
,
META_SYNC_TABLE_NAME
))
{
}
else
if
(
strstr
(
pCreate
->
tableName
,
META_SYNC_TABLE_NAME
))
{
char
*
pTbName
=
strchr
(
pCreate
->
tableName
,
'.'
);
char
*
pTbName
=
strchr
(
pCreate
->
tableName
,
'.'
);
if
(
pTbName
&&
(
pTbName
=
strchr
(
pTbName
+
1
,
'.'
)))
{
if
(
pTbName
&&
(
pTbName
=
strchr
(
pTbName
+
1
,
'.'
)))
{
if
(
0
==
strncmp
(
META_SYNC_TABLE_NAME
,
++
pTbName
,
META_SYNC_TABLE_NAME_LEN
))
{
if
(
0
==
strncmp
(
META_SYNC_TABLE_NAME
,
++
pTbName
,
META_SYNC_TABLE_NAME_LEN
))
{
*
vgId
=
atoi
(
pTbName
+
META_SYNC_TABLE_NAME_LEN
);
pInf
->
vgId
=
atoi
(
pTbName
+
META_SYNC_TABLE_NAME_LEN
);
}
}
}
}
if
(
*
vgId
<=
0
)
{
if
(
pInf
->
vgId
<
2
)
{
code
=
TSDB_CODE_MND_INVALID_FORMAT
;
code
=
TSDB_CODE_MND_INVALID_FORMAT
;
mError
(
"
msg:%p, app:%p table:%s, failed to create table, reason:%s"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
mError
(
"
%s:%d msg:%p, app:%p table:%s, failed to create table, reason:%s"
,
__func__
,
__LINE__
,
pMsg
,
pCreate
->
tableName
,
tstrerror
(
code
));
p
Msg
->
rpcMsg
.
ahandle
,
p
Create
->
tableName
,
tstrerror
(
code
));
return
code
;
return
code
;
}
}
mInfo
(
"%s:%d msg:%p, app:%p table:%s, start to create table, vgId:%d"
,
__func__
,
__LINE__
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
tableName
,
pInf
->
vgId
);
}
}
return
code
;
return
code
;
...
@@ -2335,17 +2362,14 @@ static int32_t mnodeProcessCreateChildTableMsg(SMnodeMsg *pMsg) {
...
@@ -2335,17 +2362,14 @@ static int32_t mnodeProcessCreateChildTableMsg(SMnodeMsg *pMsg) {
if
(
pMsg
->
retry
==
0
)
{
if
(
pMsg
->
retry
==
0
)
{
if
(
pMsg
->
pTable
==
NULL
)
{
if
(
pMsg
->
pTable
==
NULL
)
{
SVgObj
*
pVgroup
=
NULL
;
SVgObj
*
pVgroup
=
NULL
;
int32_t
tid
=
0
;
SMetaInfo
metaInfo
=
{.
tid
=
0
,
.
vgId
=
0
,
.
uid
=
-
1
,
.
suid
=
-
1
};
int32_t
vgId
=
0
;
uint64_t
uid
=
-
1
;
uint64_t
suid
=
-
1
;
if
(
tsMetaSyncOption
)
{
if
(
tsMetaSyncOption
)
{
code
=
mnodeProcessMetaSyncCreateChildTableMsg
(
pMsg
,
&
tid
,
&
vgId
,
&
uid
,
&
suid
);
code
=
mnodeProcessMetaSyncCreateChildTableMsg
(
pMsg
,
&
metaInfo
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
return
code
;
if
(
code
!=
TSDB_CODE_SUCCESS
)
return
code
;
}
}
code
=
mnodeGetAvailableVgroup
(
pMsg
,
&
pVgroup
,
&
tid
,
vgId
);
code
=
mnodeGetAvailableVgroup
(
pMsg
,
&
pVgroup
,
&
metaInfo
.
tid
,
metaInfo
.
vgId
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
mInfo
(
"msg:%p, app:%p table:%s, failed to get available vgroup, reason:%s"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
mInfo
(
"msg:%p, app:%p table:%s, failed to get available vgroup, reason:%s"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pCreate
->
tableName
,
tstrerror
(
code
));
pCreate
->
tableName
,
tstrerror
(
code
));
...
@@ -2359,7 +2383,7 @@ static int32_t mnodeProcessCreateChildTableMsg(SMnodeMsg *pMsg) {
...
@@ -2359,7 +2383,7 @@ static int32_t mnodeProcessCreateChildTableMsg(SMnodeMsg *pMsg) {
pMsg
->
pVgroup
=
pVgroup
;
pMsg
->
pVgroup
=
pVgroup
;
mnodeIncVgroupRef
(
pVgroup
);
mnodeIncVgroupRef
(
pVgroup
);
return
mnodeDoCreateChildTable
(
pMsg
,
tid
);
return
mnodeDoCreateChildTable
(
pMsg
,
&
metaInfo
);
}
}
}
else
{
}
else
{
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
mnodeGetTable
(
pCreate
->
tableName
);
if
(
pMsg
->
pTable
==
NULL
)
pMsg
->
pTable
=
mnodeGetTable
(
pCreate
->
tableName
);
...
...
src/mnode/src/mnodeVgroup.c
浏览文件 @
d7fe6bb9
...
@@ -459,9 +459,8 @@ int32_t mnodeGetAvailableVgroup(SMnodeMsg *pMsg, SVgObj **ppVgroup, int32_t *pSi
...
@@ -459,9 +459,8 @@ int32_t mnodeGetAvailableVgroup(SMnodeMsg *pMsg, SVgObj **ppVgroup, int32_t *pSi
continue
;
continue
;
}
}
int32_t
sid
=
0
;
if
(
*
pSid
<=
0
)
{
if
(
*
pSid
<=
0
)
{
sid
=
taosAllocateId
(
pVgroup
->
idPool
);
int32_t
sid
=
taosAllocateId
(
pVgroup
->
idPool
);
if
(
sid
<=
0
)
{
if
(
sid
<=
0
)
{
int
curMaxId
=
taosIdPoolMaxSize
(
pVgroup
->
idPool
);
int
curMaxId
=
taosIdPoolMaxSize
(
pVgroup
->
idPool
);
if
((
taosUpdateIdPool
(
pVgroup
->
idPool
,
curMaxId
+
1
)
<
0
)
||
((
sid
=
taosAllocateId
(
pVgroup
->
idPool
))
<=
0
))
{
if
((
taosUpdateIdPool
(
pVgroup
->
idPool
,
curMaxId
+
1
)
<
0
)
||
((
sid
=
taosAllocateId
(
pVgroup
->
idPool
))
<=
0
))
{
...
@@ -471,14 +470,19 @@ int32_t mnodeGetAvailableVgroup(SMnodeMsg *pMsg, SVgObj **ppVgroup, int32_t *pSi
...
@@ -471,14 +470,19 @@ int32_t mnodeGetAvailableVgroup(SMnodeMsg *pMsg, SVgObj **ppVgroup, int32_t *pSi
return
TSDB_CODE_MND_APP_ERROR
;
return
TSDB_CODE_MND_APP_ERROR
;
}
}
}
}
*
pSid
=
sid
;
// assignment
}
else
{
}
else
{
int32_t
code
=
taosAssignId
(
pVgroup
->
idPool
,
*
pSid
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
mError
(
"msg:%p, app:%p db:%s, failed to assign tid:%d in vgId:%d since %s"
,
pMsg
,
pMsg
->
rpcMsg
.
ahandle
,
pDb
->
name
,
*
pSid
,
pVgroup
->
vgId
,
tstrerror
(
code
));
pthread_mutex_unlock
(
&
pDb
->
mutex
);
return
code
;
}
}
}
mDebug
(
"vgId:%d, alloc tid:%d"
,
pVgroup
->
vgId
,
s
id
);
mDebug
(
"vgId:%d, alloc tid:%d"
,
pVgroup
->
vgId
,
*
pS
id
);
*
pSid
=
sid
;
*
ppVgroup
=
pVgroup
;
*
ppVgroup
=
pVgroup
;
pDb
->
vgListIndex
=
v
;
pDb
->
vgListIndex
=
v
;
...
...
src/util/inc/tidpool.h
浏览文件 @
d7fe6bb9
...
@@ -28,6 +28,8 @@ int taosIdPoolMaxSize(void *handle);
...
@@ -28,6 +28,8 @@ int taosIdPoolMaxSize(void *handle);
int
taosAllocateId
(
void
*
handle
);
int
taosAllocateId
(
void
*
handle
);
int
taosAssignId
(
void
*
handle
,
int
id
);
void
taosFreeId
(
void
*
handle
,
int
id
);
void
taosFreeId
(
void
*
handle
,
int
id
);
void
taosIdPoolCleanUp
(
void
*
handle
);
void
taosIdPoolCleanUp
(
void
*
handle
);
...
...
src/util/src/terror.c
浏览文件 @
d7fe6bb9
...
@@ -230,6 +230,9 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_TOPIC_PARTITONS, "Invalid topic partito
...
@@ -230,6 +230,9 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_TOPIC_PARTITONS, "Invalid topic partito
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_TOPIC_ALREADY_EXIST
,
"Topic already exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_TOPIC_ALREADY_EXIST
,
"Topic already exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_FORMAT
,
"Invalid format"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_FORMAT
,
"Invalid format"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_DUP_TID
,
"Duplicated tid"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_ID_POOL_IS_FULL
,
"Id pool is full"
)
// dnode
// dnode
TAOS_DEFINE_ERROR
(
TSDB_CODE_DND_MSG_NOT_PROCESSED
,
"Message not processed"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_DND_MSG_NOT_PROCESSED
,
"Message not processed"
)
...
...
src/util/src/tidpool.c
浏览文件 @
d7fe6bb9
...
@@ -14,8 +14,10 @@
...
@@ -14,8 +14,10 @@
*/
*/
#include "os.h"
#include "os.h"
#include "taoserror.h"
#include "tulog.h"
#include "tulog.h"
typedef
struct
{
typedef
struct
{
int
maxId
;
int
maxId
;
int
numOfFree
;
int
numOfFree
;
...
@@ -70,6 +72,34 @@ int taosAllocateId(void *handle) {
...
@@ -70,6 +72,34 @@ int taosAllocateId(void *handle) {
return
slot
+
1
;
return
slot
+
1
;
}
}
int
taosAssignId
(
void
*
handle
,
int
id
)
{
id_pool_t
*
pIdPool
=
handle
;
if
(
handle
==
NULL
)
{
return
TSDB_CODE_MND_APP_ERROR
;
}
int32_t
code
=
0
;
pthread_mutex_lock
(
&
pIdPool
->
mutex
);
if
(
pIdPool
->
numOfFree
>
0
)
{
if
(
id
>
0
&&
id
<
pIdPool
->
maxId
)
{
if
(
false
==
pIdPool
->
freeList
[
id
-
1
])
{
pIdPool
->
freeList
[
id
-
1
]
=
true
;
pIdPool
->
numOfFree
--
;
}
else
{
code
=
TSDB_CODE_MND_DUP_TID
;
}
}
else
{
code
=
TSDB_CODE_MND_INVALID_FORMAT
;
}
}
else
{
code
=
TSDB_CODE_MND_ID_POOL_IS_FULL
;
}
pthread_mutex_unlock
(
&
pIdPool
->
mutex
);
return
code
;
}
void
taosFreeId
(
void
*
handle
,
int
id
)
{
void
taosFreeId
(
void
*
handle
,
int
id
)
{
id_pool_t
*
pIdPool
=
handle
;
id_pool_t
*
pIdPool
=
handle
;
if
(
handle
==
NULL
)
return
;
if
(
handle
==
NULL
)
return
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录