Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
b45884c1
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看板
提交
b45884c1
编写于
10月 12, 2021
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more
上级
512ad36e
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
164 addition
and
10 deletion
+164
-10
include/server/vnode/meta/meta.h
include/server/vnode/meta/meta.h
+10
-0
source/server/vnode/meta/inc/metaUid.h
source/server/vnode/meta/inc/metaUid.h
+34
-0
source/server/vnode/meta/src/meta.c
source/server/vnode/meta/src/meta.c
+96
-10
source/server/vnode/meta/src/metaUid.c
source/server/vnode/meta/src/metaUid.c
+23
-0
source/server/vnode/meta/test/CMakeLists.txt
source/server/vnode/meta/test/CMakeLists.txt
+1
-0
未找到文件。
include/server/vnode/meta/meta.h
浏览文件 @
b45884c1
...
...
@@ -56,6 +56,16 @@ void metaQueryHandleDestroy(SMetaQueryHandle *);
SMetaQueryOpts
*
metaQueryOptionsCreate
();
void
metaQueryOptionsDestroy
(
SMetaQueryOpts
*
);
// STableOpts
void
metaTableOptsInit
(
int8_t
type
,
const
char
*
name
,
const
STSchema
*
pSchema
);
/* -------------------------------- Hided implementations -------------------------------- */
struct
STableOpts
{
int8_t
type
;
char
*
name
;
STSchema
*
pSchema
;
};
#ifdef __cplusplus
}
#endif
...
...
source/server/vnode/meta/inc/metaUid.h
0 → 100644
浏览文件 @
b45884c1
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_META_UID_H_
#define _TD_META_UID_H_
#include "os.h"
#ifdef __cplusplus
extern
"C"
{
#endif
typedef
uint64_t
tb_uid_t
;
tb_uid_t
metaGenerateUid
();
#define IVLD_TB_UID 0
#ifdef __cplusplus
}
#endif
#endif
/*_TD_META_UID_H_*/
\ No newline at end of file
source/server/vnode/meta/src/meta.c
浏览文件 @
b45884c1
...
...
@@ -21,12 +21,14 @@
#include "ttypes.h"
#include "meta.h"
#include "metaUid.h"
/* -------------------- Structures -------------------- */
typedef
struct
STable
{
uint64
_t
uid
;
tst
r
*
name
;
uint64
_t
suid
;
tb_uid
_t
uid
;
cha
r
*
name
;
tb_uid
_t
suid
;
SArray
*
schema
;
}
STable
;
...
...
@@ -51,11 +53,8 @@ struct SMeta {
size_t
totalUsed
;
};
struct
STableOpts
{
int8_t
type
;
char
*
name
;
STSchema
*
pSchema
;
};
static
STable
*
metaTableNew
(
tb_uid_t
uid
,
const
char
*
name
,
int32_t
sver
);
static
STableObj
*
metaTableObjNew
();
/* -------------------- Methods -------------------- */
...
...
@@ -111,10 +110,97 @@ void metaClose(SMeta *pMeta) {
}
int
metaCreateTable
(
SMeta
*
pMeta
,
STableOpts
*
pTableOpts
)
{
// TODO
size_t
vallen
;
char
*
err
=
NULL
;
rocksdb_readoptions_t
*
ropt
;
STableObj
*
pTableObj
=
NULL
;
rocksdb_writeoptions_t
*
wopt
;
// Check if table already exists
ropt
=
rocksdb_readoptions_create
();
char
*
uidStr
=
rocksdb_get
(
pMeta
->
tbnameDb
,
ropt
,
pTableOpts
->
name
,
strlen
(
pTableOpts
->
name
),
&
vallen
,
&
err
);
if
(
uidStr
!=
NULL
)
{
// Has duplicate named table
return
-
1
;
}
rocksdb_readoptions_destroy
(
ropt
);
// Create table obj
pTableObj
=
metaTableObjNew
();
if
(
pTableObj
==
NULL
)
{
// TODO
return
-
1
;
}
// Create table object
pTableObj
->
pTable
=
metaTableNew
(
metaGenerateUid
(),
pTableOpts
->
name
,
schemaVersion
(
pTableOpts
->
pSchema
));
if
(
pTableObj
->
pTable
==
NULL
)
{
// TODO
}
pthread_rwlock_rdlock
(
&
pMeta
->
rwLock
);
taosHashPut
(
pMeta
->
pTableObjHash
,
&
(
pTableObj
->
pTable
->
uid
),
sizeof
(
tb_uid_t
),
&
pTableObj
,
sizeof
(
pTableObj
));
wopt
=
rocksdb_writeoptions_create
();
rocksdb_put
(
pMeta
->
tbnameDb
,
wopt
,
pTableOpts
->
name
,
strlen
(
pTableOpts
->
name
),
&
pTableObj
->
pTable
->
uid
,
sizeof
(
tb_uid_t
),
&
err
);
rocksdb_put
(
pMeta
->
schemaDb
,
wopt
,
pTableOpts
->
name
,
strlen
(
pTableOpts
->
name
),
&
pTableObj
->
pTable
->
uid
,
sizeof
(
tb_uid_t
),
&
err
);
rocksdb_writeoptions_destroy
(
wopt
);
pthread_rwlock_unlock
(
&
pMeta
->
rwLock
);
return
0
;
}
void
metaDestroy
(
const
char
*
path
)
{
taosRemoveDir
(
path
);
}
int
metaCommit
(
SMeta
*
meta
)
{
return
0
;
}
\ No newline at end of file
int
metaCommit
(
SMeta
*
meta
)
{
return
0
;
}
/* -------------------- Static Methods -------------------- */
static
STable
*
metaTableNew
(
tb_uid_t
uid
,
const
char
*
name
,
int32_t
sver
)
{
STable
*
pTable
=
NULL
;
pTable
=
(
STable
*
)
malloc
(
sizeof
(
*
pTable
));
if
(
pTable
==
NULL
)
{
// TODO
return
NULL
;
}
pTable
->
schema
=
taosArrayInit
(
0
,
sizeof
(
int32_t
));
if
(
pTable
->
schema
==
NULL
)
{
// TODO
return
NULL
;
}
pTable
->
uid
=
uid
;
pTable
->
name
=
strdup
(
name
);
pTable
->
suid
=
IVLD_TB_UID
;
taosArrayPush
(
pTable
->
schema
,
&
sver
);
return
pTable
;
}
static
STableObj
*
metaTableObjNew
()
{
STableObj
*
pTableObj
=
NULL
;
pTableObj
=
(
STableObj
*
)
malloc
(
sizeof
(
*
pTableObj
));
if
(
pTableObj
==
NULL
)
{
return
NULL
;
}
pTableObj
->
pin
=
true
;
pTableObj
->
ref
=
1
;
taosInitRWLatch
(
&
(
pTableObj
->
latch
));
pTableObj
->
offset
=
UINT64_MAX
;
pTableObj
->
ctbList
=
NULL
;
pTableObj
->
pTable
=
NULL
;
return
pTableObj
;
}
\ No newline at end of file
source/server/vnode/meta/src/metaUid.c
0 → 100644
浏览文件 @
b45884c1
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "metaUid.h"
static
tb_uid_t
nuid
=
IVLD_TB_UID
;
tb_uid_t
metaGenerateUid
()
{
// TODO: need a more complex UID generator
return
++
nuid
;
}
\ No newline at end of file
source/server/vnode/meta/test/CMakeLists.txt
浏览文件 @
b45884c1
...
...
@@ -2,6 +2,7 @@ add_executable(metaTest "")
target_sources
(
metaTest
PRIVATE
"../src/meta.c"
"../src/metaUid.c"
"metaTests.cpp"
)
target_include_directories
(
metaTest
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录