Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
dc272910
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
未验证
提交
dc272910
编写于
5月 17, 2022
作者:
H
Hongze Cheng
提交者:
GitHub
5月 17, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #12555 from taosdata/feat/alter_table
feat: alter table
上级
44b75e6d
a98d86d4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
122 addition
and
7 deletion
+122
-7
source/dnode/vnode/inc/vnode.h
source/dnode/vnode/inc/vnode.h
+2
-0
source/dnode/vnode/src/meta/metaTable.c
source/dnode/vnode/src/meta/metaTable.c
+102
-1
source/dnode/vnode/src/vnd/vnodeSvr.c
source/dnode/vnode/src/vnd/vnodeSvr.c
+18
-6
未找到文件。
source/dnode/vnode/inc/vnode.h
浏览文件 @
dc272910
...
...
@@ -196,6 +196,8 @@ struct SMetaEntry {
STSma
*
tsma
;
}
smaEntry
;
};
uint8_t
*
pBuf
;
};
struct
SMetaReader
{
...
...
source/dnode/vnode/src/meta/metaTable.c
浏览文件 @
dc272910
...
...
@@ -498,6 +498,18 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
entry
.
version
=
version
;
// do actual write
metaWLock
(
pMeta
);
// save to table db
metaSaveToTbDb
(
pMeta
,
&
entry
);
tdbDbcUpsert
(
pUidIdxc
,
&
entry
.
uid
,
sizeof
(
tb_uid_t
),
&
version
,
sizeof
(
version
),
0
);
metaSaveToSkmDb
(
pMeta
,
&
entry
);
metaULock
(
pMeta
);
tDecoderClear
(
&
dc
);
tdbDbcClose
(
pTbDbc
);
tdbDbcClose
(
pUidIdxc
);
...
...
@@ -511,8 +523,97 @@ _err:
}
static
int
metaUpdateTableTagVal
(
SMeta
*
pMeta
,
int64_t
version
,
SVAlterTbReq
*
pAlterTbReq
)
{
// TODO
SMetaEntry
ctbEntry
=
{
0
};
SMetaEntry
stbEntry
=
{
0
};
void
*
pVal
=
NULL
;
int
nVal
=
0
;
int
ret
;
int
c
;
tb_uid_t
uid
;
int64_t
oversion
;
const
void
*
pData
=
NULL
;
int
nData
=
0
;
// search name index
ret
=
tdbDbGet
(
pMeta
->
pNameIdx
,
pAlterTbReq
->
tbName
,
strlen
(
pAlterTbReq
->
tbName
)
+
1
,
&
pVal
,
&
nVal
);
if
(
ret
<
0
)
{
terrno
=
TSDB_CODE_VND_TABLE_NOT_EXIST
;
return
-
1
;
}
uid
=
*
(
tb_uid_t
*
)
pVal
;
tdbFree
(
pVal
);
pVal
=
NULL
;
// search uid index
TDBC
*
pUidIdxc
=
NULL
;
tdbDbcOpen
(
pMeta
->
pUidIdx
,
&
pUidIdxc
,
&
pMeta
->
txn
);
tdbDbcMoveTo
(
pUidIdxc
,
&
uid
,
sizeof
(
uid
),
&
c
);
ASSERT
(
c
==
0
);
tdbDbcGet
(
pUidIdxc
,
NULL
,
NULL
,
&
pData
,
&
nData
);
oversion
=
*
(
int64_t
*
)
pData
;
// search table.db
TDBC
*
pTbDbc
=
NULL
;
SDecoder
dc
=
{
0
};
/* get ctbEntry */
tdbDbcOpen
(
pMeta
->
pTbDb
,
&
pTbDbc
,
&
pMeta
->
txn
);
tdbDbcMoveTo
(
pTbDbc
,
&
((
STbDbKey
){.
uid
=
uid
,
.
version
=
oversion
}),
sizeof
(
STbDbKey
),
&
c
);
ASSERT
(
c
==
0
);
tdbDbcGet
(
pTbDbc
,
NULL
,
NULL
,
&
pData
,
&
nData
);
ctbEntry
.
pBuf
=
taosMemoryMalloc
(
nData
);
memcpy
(
ctbEntry
.
pBuf
,
pData
,
nData
);
tDecoderInit
(
&
dc
,
ctbEntry
.
pBuf
,
nData
);
metaDecodeEntry
(
&
dc
,
&
ctbEntry
);
tDecoderClear
(
&
dc
);
/* get stbEntry*/
tdbDbGet
(
pMeta
->
pUidIdx
,
&
ctbEntry
.
ctbEntry
.
suid
,
sizeof
(
tb_uid_t
),
&
pVal
,
&
nVal
);
tdbDbGet
(
pMeta
->
pTbDb
,
&
((
STbDbKey
){.
uid
=
ctbEntry
.
ctbEntry
.
suid
,
.
version
=
*
(
int64_t
*
)
pVal
}),
sizeof
(
STbDbKey
),
(
void
**
)
&
stbEntry
.
pBuf
,
&
nVal
);
tdbFree
(
pVal
);
tDecoderInit
(
&
dc
,
stbEntry
.
pBuf
,
nVal
);
metaDecodeEntry
(
&
dc
,
&
stbEntry
);
tDecoderClear
(
&
dc
);
SSchemaWrapper
*
pTagSchema
=
&
stbEntry
.
stbEntry
.
schemaTag
;
SSchema
*
pColumn
=
NULL
;
int32_t
iCol
=
0
;
for
(;;)
{
pColumn
=
NULL
;
if
(
iCol
>=
pTagSchema
->
nCols
)
break
;
pColumn
=
&
pTagSchema
->
pSchema
[
iCol
];
if
(
strcmp
(
pColumn
->
name
,
pAlterTbReq
->
tagName
)
==
0
)
break
;
iCol
++
;
}
if
(
pColumn
==
NULL
)
{
terrno
=
TSDB_CODE_VND_TABLE_COL_NOT_EXISTS
;
goto
_err
;
}
{
// TODO:
}
if
(
ctbEntry
.
pBuf
)
taosMemoryFree
(
ctbEntry
.
pBuf
);
if
(
stbEntry
.
pBuf
)
tdbFree
(
stbEntry
.
pBuf
);
tdbDbcClose
(
pTbDbc
);
tdbDbcClose
(
pUidIdxc
);
return
0
;
_err:
if
(
ctbEntry
.
pBuf
)
taosMemoryFree
(
ctbEntry
.
pBuf
);
if
(
stbEntry
.
pBuf
)
tdbFree
(
stbEntry
.
pBuf
);
tdbDbcClose
(
pTbDbc
);
tdbDbcClose
(
pUidIdxc
);
return
-
1
;
}
static
int
metaUpdateTableOptions
(
SMeta
*
pMeta
,
int64_t
version
,
SVAlterTbReq
*
pAlterTbReq
)
{
...
...
source/dnode/vnode/src/vnd/vnodeSvr.c
浏览文件 @
dc272910
...
...
@@ -204,7 +204,7 @@ void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) {
int
vnodeProcessSyncReq
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
pRsp
)
{
int32_t
ret
=
TAOS_SYNC_PROPOSE_OTHER_ERROR
;
if
(
syncEnvIsStart
())
{
SSyncNode
*
pSyncNode
=
syncNodeAcquire
(
pVnode
->
sync
);
assert
(
pSyncNode
!=
NULL
);
...
...
@@ -467,7 +467,11 @@ _exit:
static
int
vnodeProcessAlterTbReq
(
SVnode
*
pVnode
,
int64_t
version
,
void
*
pReq
,
int32_t
len
,
SRpcMsg
*
pRsp
)
{
SVAlterTbReq
vAlterTbReq
=
{
0
};
SVAlterTbRsp
vAlterTbRsp
=
{
0
};
SDecoder
dc
=
{
0
};
int
rcode
=
0
;
int
ret
;
SEncoder
ec
=
{
0
};
pRsp
->
msgType
=
TDMT_VND_ALTER_TABLE_RSP
;
pRsp
->
pCont
=
NULL
;
...
...
@@ -478,19 +482,27 @@ static int vnodeProcessAlterTbReq(SVnode *pVnode, int64_t version, void *pReq, i
// decode
if
(
tDecodeSVAlterTbReq
(
&
dc
,
&
vAlterTbReq
)
<
0
)
{
pRsp
->
code
=
TSDB_CODE_INVALID_MSG
;
vAlterTbRsp
.
code
=
TSDB_CODE_INVALID_MSG
;
tDecoderClear
(
&
dc
);
return
-
1
;
rcode
=
-
1
;
goto
_exit
;
}
// process
if
(
metaAlterTable
(
pVnode
->
pMeta
,
version
,
&
vAlterTbReq
)
<
0
)
{
pRsp
->
code
=
terrno
;
vAlterTbRsp
.
code
=
TSDB_CODE_INVALID_MSG
;
tDecoderClear
(
&
dc
);
return
-
1
;
rcode
=
-
1
;
goto
_exit
;
}
tDecoderClear
(
&
dc
);
_exit:
tEncodeSize
(
tEncodeSVAlterTbRsp
,
&
vAlterTbRsp
,
pRsp
->
contLen
,
ret
);
pRsp
->
pCont
=
rpcMallocCont
(
pRsp
->
contLen
);
tEncoderInit
(
&
ec
,
pRsp
->
pCont
,
pRsp
->
contLen
);
tEncodeSVAlterTbRsp
(
&
ec
,
&
vAlterTbRsp
);
tEncoderClear
(
&
ec
);
return
0
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录