Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
0fcbd2f5
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1185
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0fcbd2f5
编写于
10月 13, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '3.0' of github.com:taosdata/tdengine into 3.0
上级
3163dce0
dd9ac9bb
变更
23
隐藏空白更改
内联
并排
Showing
23 changed file
with
419 addition
and
165 deletion
+419
-165
CMakeLists.txt
CMakeLists.txt
+1
-1
include/common/schema.h
include/common/schema.h
+0
-103
include/common/tdataformat.h
include/common/tdataformat.h
+1
-1
include/common/tschema.h
include/common/tschema.h
+27
-0
include/libs/tkv/tkv.h
include/libs/tkv/tkv.h
+21
-8
include/libs/wal/wal.h
include/libs/wal/wal.h
+13
-6
include/os/osDir.h
include/os/osDir.h
+1
-1
include/server/vnode/meta/meta.h
include/server/vnode/meta/meta.h
+25
-14
source/common/src/tdataformat.c
source/common/src/tdataformat.c
+1
-1
source/common/src/ttime.c
source/common/src/ttime.c
+0
-2
source/libs/tkv/CMakeLists.txt
source/libs/tkv/CMakeLists.txt
+4
-0
source/libs/tkv/src/tkv.c
source/libs/tkv/src/tkv.c
+68
-1
source/os/src/osDir.c
source/os/src/osDir.c
+2
-2
source/os/src/osTime.c
source/os/src/osTime.c
+2
-0
source/server/vnode/inc/vnodeMain.h
source/server/vnode/inc/vnodeMain.h
+2
-1
source/server/vnode/inc/vnodeWrite.h
source/server/vnode/inc/vnodeWrite.h
+1
-1
source/server/vnode/meta/CMakeLists.txt
source/server/vnode/meta/CMakeLists.txt
+1
-1
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
+153
-18
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
+7
-1
source/server/vnode/meta/test/metaTests.cpp
source/server/vnode/meta/test/metaTests.cpp
+30
-2
source/server/vnode/tq/CMakeLists.txt
source/server/vnode/tq/CMakeLists.txt
+2
-1
未找到文件。
CMakeLists.txt
浏览文件 @
0fcbd2f5
...
...
@@ -42,7 +42,7 @@ if(${BUILD_WITH_LEVELDB})
endif
(
${
BUILD_WITH_LEVELDB
}
)
## rocksdb
option
(
BUILD_WITH_ROCKSDB
"If build with rocksdb"
O
N
)
option
(
BUILD_WITH_ROCKSDB
"If build with rocksdb"
O
FF
)
if
(
${
BUILD_WITH_ROCKSDB
}
)
cat
(
"
${
CMAKE_SUPPORT_DIR
}
/rocksdb_CMakeLists.txt.in"
${
DEPS_TMP_FILE
}
)
endif
(
${
BUILD_WITH_ROCKSDB
}
)
...
...
include/common/schema.h
已删除
100644 → 0
浏览文件 @
3163dce0
/*
* 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_COMMON_SCHEMA_H_
#define _TD_COMMON_SCHEMA_H_
#include "os.h"
#ifdef __cplusplus
extern
"C"
{
#endif
// ----------------- TSDB COLUMN DEFINITION
typedef
struct
{
int8_t
type
;
// Column type
int16_t
colId
;
// column ID
int16_t
bytes
;
// column bytes (restore to int16_t in case of misuse)
uint16_t
offset
;
// point offset in SDataRow after the header part.
}
STColumn
;
#define colType(col) ((col)->type)
#define colColId(col) ((col)->colId)
#define colBytes(col) ((col)->bytes)
#define colOffset(col) ((col)->offset)
#define colSetType(col, t) (colType(col) = (t))
#define colSetColId(col, id) (colColId(col) = (id))
#define colSetBytes(col, b) (colBytes(col) = (b))
#define colSetOffset(col, o) (colOffset(col) = (o))
// ----------------- TSDB SCHEMA DEFINITION
typedef
struct
{
int
version
;
// version
int
numOfCols
;
// Number of columns appended
int
tlen
;
// maximum length of a SDataRow without the header part (sizeof(VarDataOffsetT) + sizeof(VarDataLenT) + //
// (bytes))
uint16_t
flen
;
// First part length in a SDataRow after the header part
uint16_t
vlen
;
// pure value part length, excluded the overhead (bytes only)
STColumn
columns
[];
}
STSchema
;
#define schemaNCols(s) ((s)->numOfCols)
#define schemaVersion(s) ((s)->version)
#define schemaTLen(s) ((s)->tlen)
#define schemaFLen(s) ((s)->flen)
#define schemaVLen(s) ((s)->vlen)
#define schemaColAt(s, i) ((s)->columns + i)
#define tdFreeSchema(s) tfree((s))
STSchema
*
tdDupSchema
(
STSchema
*
pSchema
);
int
tdEncodeSchema
(
void
**
buf
,
STSchema
*
pSchema
);
void
*
tdDecodeSchema
(
void
*
buf
,
STSchema
**
pRSchema
);
static
FORCE_INLINE
int
comparColId
(
const
void
*
key1
,
const
void
*
key2
)
{
if
(
*
(
int16_t
*
)
key1
>
((
STColumn
*
)
key2
)
->
colId
)
{
return
1
;
}
else
if
(
*
(
int16_t
*
)
key1
<
((
STColumn
*
)
key2
)
->
colId
)
{
return
-
1
;
}
else
{
return
0
;
}
}
static
FORCE_INLINE
STColumn
*
tdGetColOfID
(
STSchema
*
pSchema
,
int16_t
colId
)
{
void
*
ptr
=
bsearch
(
&
colId
,
(
void
*
)
pSchema
->
columns
,
schemaNCols
(
pSchema
),
sizeof
(
STColumn
),
comparColId
);
if
(
ptr
==
NULL
)
return
NULL
;
return
(
STColumn
*
)
ptr
;
}
// ----------------- SCHEMA BUILDER DEFINITION
typedef
struct
{
int
tCols
;
int
nCols
;
int
tlen
;
uint16_t
flen
;
uint16_t
vlen
;
int
version
;
STColumn
*
columns
;
}
STSchemaBuilder
;
int
tdInitTSchemaBuilder
(
STSchemaBuilder
*
pBuilder
,
int32_t
version
);
void
tdDestroyTSchemaBuilder
(
STSchemaBuilder
*
pBuilder
);
void
tdResetTSchemaBuilder
(
STSchemaBuilder
*
pBuilder
,
int32_t
version
);
int
tdAddColToSchema
(
STSchemaBuilder
*
pBuilder
,
int8_t
type
,
int16_t
colId
,
int16_t
bytes
);
STSchema
*
tdGetSchemaFromBuilder
(
STSchemaBuilder
*
pBuilder
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_COMMON_SCHEMA_H_*/
\ No newline at end of file
include/common/tdataformat.h
浏览文件 @
0fcbd2f5
...
...
@@ -87,7 +87,7 @@ typedef struct {
#define schemaColAt(s, i) ((s)->columns + i)
#define tdFreeSchema(s) tfree((s))
STSchema
*
tdDupSchema
(
STSchema
*
pSchema
);
STSchema
*
tdDupSchema
(
const
STSchema
*
pSchema
);
int
tdEncodeSchema
(
void
**
buf
,
STSchema
*
pSchema
);
void
*
tdDecodeSchema
(
void
*
buf
,
STSchema
**
pRSchema
);
...
...
include/common/tschema.h
0 → 100644
浏览文件 @
0fcbd2f5
/*
* 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_COMMON_SCHEMA_H_
#define _TD_COMMON_SCHEMA_H_
#ifdef __cplusplus
extern
"C"
{
#endif
#ifdef __cplusplus
}
#endif
#endif
/*_TD_COMMON_SCHEMA_H_*/
\ No newline at end of file
include/libs/tkv/tkv.h
浏览文件 @
0fcbd2f5
...
...
@@ -16,30 +16,43 @@
#ifndef _TD_TKV_H_
#define _TD_TKV_H_
#include "os.h"
#ifdef __cplusplus
extern
"C"
{
#endif
// Types exported
typedef
struct
STkvDb
STkvDb
;
typedef
struct
STkvOptions
STkvOptions
;
typedef
struct
STkvCache
STkvCache
;
typedef
struct
STkvDb
STkvDb
;
typedef
struct
STkvOpts
STkvOpts
;
typedef
struct
STkvCache
STkvCache
;
typedef
struct
STkvReadOpts
STkvReadOpts
;
typedef
struct
STkvWriteOpts
STkvWriteOpts
;
// DB operations
STkvDb
*
tkvOpen
(
const
STkvOpt
ion
s
*
options
,
const
char
*
path
);
STkvDb
*
tkvOpen
(
const
STkvOpts
*
options
,
const
char
*
path
);
void
tkvClose
(
STkvDb
*
db
);
void
tkvPut
(
STkvDb
*
db
,
void
*
/*TODO*/
);
void
tkvPut
(
STkvDb
*
db
,
STkvWriteOpts
*
,
char
*
key
,
size_t
keylen
,
char
*
val
,
size_t
vallen
);
char
*
tkvGet
(
STkvDb
*
db
,
STkvReadOpts
*
,
char
*
key
,
size_t
keylen
,
size_t
*
vallen
);
// DB options
STkvOpt
ion
s
*
tkvOptionsCreate
();
void
tkvOptionsDestroy
(
STkvOption
s
*
);
void
tkvOptionsSetCache
(
STkvOption
s
*
,
STkvCache
*
);
STkvOpts
*
tkvOptionsCreate
();
void
tkvOptionsDestroy
(
STkvOpt
s
*
);
void
tkvOptionsSetCache
(
STkvOpt
s
*
,
STkvCache
*
);
// DB cache
typedef
enum
{
TKV_LRU_CACHE
=
0
,
TKV_LFU_CACHE
=
1
}
ETkvCacheType
;
STkvCache
*
tkvCacheCreate
(
size_t
capacity
,
ETkvCacheType
type
);
void
tkvCacheDestroy
(
STkvCache
*
);
// STkvReadOpts
STkvReadOpts
*
tkvReadOptsCreate
();
void
tkvReadOptsDestroy
(
STkvReadOpts
*
);
// STkvWriteOpts
STkvWriteOpts
*
tkvWriteOptsCreate
();
void
tkvWriteOptsDestroy
(
STkvWriteOpts
*
);
#ifdef __cplusplus
}
#endif
...
...
include/libs/wal/wal.h
浏览文件 @
0fcbd2f5
...
...
@@ -58,18 +58,25 @@ void walStop(twalh);
void
walClose
(
twalh
);
//write
int64_t
walWrite
(
twalh
,
int8_t
msgType
,
void
*
body
,
uint32_t
bodyLen
);
void
walFsync
(
twalh
,
bool
forceHint
);
//int32_t walCommit(twalh, int64_t ver);
//int32_t walRollback(twalh, int64_t ver);
int64_t
walWriteWithMsgType
(
twalh
,
int8_t
msgType
,
void
*
body
,
int32_t
bodyLen
);
int64_t
walWrite
(
twalh
,
void
*
body
,
int32_t
bodyLen
);
int64_t
walWriteBatch
(
twalh
,
void
*
body
,
int32_t
*
bodyLen
,
int32_t
batchSize
);
//apis for lifecycle management
void
walFsync
(
twalh
,
bool
force
);
int32_t
walCommit
(
twalh
,
int64_t
ver
);
//truncate after
int32_t
walRollback
(
twalh
,
int64_t
ver
);
//notify that previous log can be pruned safely
int32_t
walPrune
(
twalh
,
int64_t
ver
);
//read
int32_t
walRead
(
twalh
,
SWalHead
**
,
int64_t
ver
);
int32_t
walReadWithFp
(
twalh
,
FWalWrite
writeFp
,
int64_t
verStart
,
int
readNum
);
//life cycle
int32_t
walDataPersisted
(
twalh
,
int64_t
ver
);
//lifecycle check
int32_t
walFirstVer
(
twalh
);
int32_t
walPersistedVer
(
twalh
);
int32_t
walLastVer
(
twalh
);
//int32_t walDataCorrupted(twalh);
...
...
include/os/osDir.h
浏览文件 @
0fcbd2f5
...
...
@@ -20,7 +20,7 @@
extern
"C"
{
#endif
void
taosRemoveDir
(
char
*
dirname
);
void
taosRemoveDir
(
c
onst
c
har
*
dirname
);
bool
taosDirExist
(
char
*
dirname
);
bool
taosMkDir
(
char
*
dirname
);
void
taosRemoveOldFiles
(
char
*
dirname
,
int32_t
keepDays
);
...
...
include/server/vnode/meta/meta.h
浏览文件 @
0fcbd2f5
...
...
@@ -27,33 +27,44 @@ extern "C" {
typedef
uint64_t
tuid_t
;
// Types exported
typedef
struct
SMeta
SMeta
;
typedef
struct
SMetaOptions
SMetaOptions
;
typedef
struct
SMetaQueryHandle
SMetaQueryHandle
;
typedef
struct
SMetaQueryOptions
SMetaQueryOptions
;
typedef
struct
SMeta
SMeta
;
typedef
struct
SMetaOpts
SMetaOpts
;
typedef
struct
SMetaQueryHandle
SMetaQueryHandle
;
typedef
struct
SMetaQueryOpts
SMetaQueryOpts
;
typedef
struct
STableOpts
STableOpts
;
// SMeta operations
int
metaCreate
(
const
char
*
path
);
int
metaDestroy
(
const
char
*
path
);
SMeta
*
metaOpen
(
SMetaOpt
ion
s
*
);
void
metaDestroy
(
const
char
*
path
);
SMeta
*
metaOpen
(
SMetaOpts
*
);
void
metaClose
(
SMeta
*
);
int
metaCreateTable
(
SMeta
*
,
void
*
);
int
metaCreateTable
(
SMeta
*
,
STableOpts
*
);
int
metaDropTable
(
SMeta
*
,
uint64_t
tuid_t
);
int
metaAlterTable
(
SMeta
*
,
void
*
);
int
metaCommit
(
SMeta
*
);
// Options
SMetaOpt
ion
s
*
metaOptionsCreate
();
void
metaOptionsDestroy
(
SMetaOption
s
*
);
void
metaOptionsSetCache
(
SMetaOption
s
*
,
size_t
capacity
);
SMetaOpts
*
metaOptionsCreate
();
void
metaOptionsDestroy
(
SMetaOpt
s
*
);
void
metaOptionsSetCache
(
SMetaOpt
s
*
,
size_t
capacity
);
// SMetaQueryHandle
SMetaQueryHandle
*
metaQueryHandleCreate
(
SMetaQueryOpt
ion
s
*
);
SMetaQueryHandle
*
metaQueryHandleCreate
(
SMetaQueryOpts
*
);
void
metaQueryHandleDestroy
(
SMetaQueryHandle
*
);
// SMetaQueryOptions
SMetaQueryOptions
*
metaQueryOptionsCreate
();
void
metaQueryOptionsDestroy
(
SMetaQueryOptions
*
);
// SMetaQueryOpts
SMetaQueryOpts
*
metaQueryOptionsCreate
();
void
metaQueryOptionsDestroy
(
SMetaQueryOpts
*
);
// STableOpts
void
metaTableOptsInit
(
STableOpts
*
,
int8_t
type
,
const
char
*
name
,
const
STSchema
*
pSchema
);
/* -------------------------------- Hided implementations -------------------------------- */
struct
STableOpts
{
int8_t
type
;
char
*
name
;
STSchema
*
pSchema
;
};
#ifdef __cplusplus
}
...
...
source/common/src/tdataformat.c
浏览文件 @
0fcbd2f5
...
...
@@ -48,7 +48,7 @@ int tdAllocMemForCol(SDataCol *pCol, int maxPoints) {
/**
* Duplicate the schema and return a new object
*/
STSchema
*
tdDupSchema
(
STSchema
*
pSchema
)
{
STSchema
*
tdDupSchema
(
const
STSchema
*
pSchema
)
{
int
tlen
=
sizeof
(
STSchema
)
+
sizeof
(
STColumn
)
*
schemaNCols
(
pSchema
);
STSchema
*
tSchema
=
(
STSchema
*
)
malloc
(
tlen
);
...
...
source/common/src/ttime.c
浏览文件 @
0fcbd2f5
...
...
@@ -94,8 +94,6 @@ static int32_t (*parseLocaltimeFp[]) (char* timestr, int64_t* time, int32_t time
parseLocaltimeWithDst
};
int32_t
taosGetTimestampSec
()
{
return
(
int32_t
)
time
(
NULL
);
}
int32_t
taosParseTime
(
char
*
timestr
,
int64_t
*
time
,
int32_t
len
,
int32_t
timePrec
,
int8_t
day_light
)
{
/* parse datatime string in with tz */
if
(
strnchr
(
timestr
,
'T'
,
len
,
false
)
!=
NULL
)
{
...
...
source/libs/tkv/CMakeLists.txt
浏览文件 @
0fcbd2f5
...
...
@@ -4,4 +4,8 @@ target_include_directories(
tkv
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/libs/tkv"
PRIVATE
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/inc"
)
target_link_libraries
(
tkv
PUBLIC os
)
\ No newline at end of file
source/libs/tkv/src/tkv.c
浏览文件 @
0fcbd2f5
...
...
@@ -11,4 +11,71 @@
*
* 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/>.
*/
\ No newline at end of file
*/
#include "tkv.h"
struct
STkvDb
{
// TODO
};
struct
STkvOpts
{
// TODO
};
struct
STkvCache
{
// TODO
};
struct
STkvReadOpts
{
// TODO
};
struct
STkvWriteOpts
{
// TODO
};
STkvDb
*
tkvOpen
(
const
STkvOpts
*
options
,
const
char
*
path
)
{
// TODO
return
NULL
;
}
void
tkvClose
(
STkvDb
*
db
)
{
// TODO
}
void
tkvPut
(
STkvDb
*
db
,
STkvWriteOpts
*
pwopts
,
char
*
key
,
size_t
keylen
,
char
*
val
,
size_t
vallen
)
{
// TODO
}
char
*
tkvGet
(
STkvDb
*
db
,
STkvReadOpts
*
propts
,
char
*
key
,
size_t
keylen
,
size_t
*
vallen
)
{
// TODO
return
NULL
;
}
STkvOpts
*
tkvOptionsCreate
()
{
// TODO
return
NULL
;
}
void
tkvOptionsDestroy
(
STkvOpts
*
popts
)
{
// TODO
}
void
tkvOptionsSetCache
(
STkvOpts
*
popts
,
STkvCache
*
pCache
)
{
// TODO
}
STkvReadOpts
*
tkvReadOptsCreate
()
{
// TODO
return
NULL
;
}
void
tkvReadOptsDestroy
(
STkvReadOpts
*
propts
)
{
// TODO
}
STkvWriteOpts
*
tkvWriteOptsCreate
()
{
// TODO
return
NULL
;
}
void
tkvWriteOptsDestroy
(
STkvWriteOpts
*
pwopts
)
{
// TODO
}
\ No newline at end of file
source/os/src/osDir.c
浏览文件 @
0fcbd2f5
...
...
@@ -34,7 +34,7 @@
#include <unistd.h>
#include <wordexp.h>
void
taosRemoveDir
(
char
*
dirname
)
{
void
taosRemoveDir
(
c
onst
c
har
*
dirname
)
{
DIR
*
dir
=
opendir
(
dirname
);
if
(
dir
==
NULL
)
return
;
...
...
@@ -48,7 +48,7 @@ void taosRemoveDir(char *dirname) {
taosRemoveDir
(
filename
);
}
else
{
(
void
)
remove
(
filename
);
printf
(
"file:%s is removed"
,
filename
);
printf
(
"file:%s is removed
\n
"
,
filename
);
}
}
...
...
source/os/src/osTime.c
浏览文件 @
0fcbd2f5
...
...
@@ -63,4 +63,6 @@ FORCE_INLINE int32_t taosGetTimeOfDay(struct timeval *tv) {
return
gettimeofday
(
tv
,
NULL
);
}
int32_t
taosGetTimestampSec
()
{
return
(
int32_t
)
time
(
NULL
);
}
#endif
source/server/vnode/inc/vnodeMain.h
浏览文件 @
0fcbd2f5
...
...
@@ -16,10 +16,11 @@
#ifndef _TD_VNODE_MAIN_H_
#define _TD_VNODE_MAIN_H_
#include "vnodeInt.h"
#ifdef __cplusplus
extern
"C"
{
#endif
#include "vnodeInt.h"
int32_t
vnodeInitMain
();
void
vnodeCleanupMain
();
...
...
source/server/vnode/inc/vnodeWrite.h
浏览文件 @
0fcbd2f5
...
...
@@ -37,4 +37,4 @@ void vnodeWaitWriteCompleted(SVnode *pVnode);
}
#endif
#endif
/*_TD_VNODE_WRITE_H_*/
\ No newline at end of file
#endif
/*_TD_VNODE_WRITE_H_*/
source/server/vnode/meta/CMakeLists.txt
浏览文件 @
0fcbd2f5
...
...
@@ -8,8 +8,8 @@ target_include_directories(
target_link_libraries
(
meta
PUBLIC common
PUBLIC tkv
)
target_link_libraries
(
meta PUBLIC rocksdb
)
if
(
${
BUILD_TEST
}
)
add_subdirectory
(
test
)
...
...
source/server/vnode/meta/inc/metaUid.h
0 → 100644
浏览文件 @
0fcbd2f5
/*
* 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
浏览文件 @
0fcbd2f5
...
...
@@ -13,19 +13,21 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <rocksdb/c.h>
#include "tkv.h"
#include "thash.h"
#include "tlist.h"
#include "tlockfree.h"
#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
;
...
...
@@ -41,15 +43,21 @@ typedef struct STableObj {
struct
SMeta
{
pthread_rwlock_t
rwLock
;
SHashObj
*
pTableObjHash
;
// uid --> STableObj
SList
*
stbList
;
// super table list
rocksdb_t
*
tbnameDb
;
// tbname --> uid
rocksdb_t
*
tagDb
;
// uid --> tag
rocksdb_t
*
schemaDb
;
size_t
totalUsed
;
SHashObj
*
pTableObjHash
;
// uid --> STableObj
SList
*
stbList
;
// super table list
STkvDb
*
tbnameDb
;
// tbname --> uid
STkvDb
*
tagDb
;
// uid --> tag
STkvDb
*
schemaDb
;
STkvDb
*
tagIdx
;
size_t
totalUsed
;
};
SMeta
*
metaOpen
(
SMetaOptions
*
options
)
{
static
STable
*
metaTableNew
(
tb_uid_t
uid
,
const
char
*
name
,
int32_t
sver
);
static
STableObj
*
metaTableObjNew
();
/* -------------------- Methods -------------------- */
SMeta
*
metaOpen
(
SMetaOpts
*
options
)
{
SMeta
*
pMeta
=
NULL
;
char
*
err
=
NULL
;
...
...
@@ -64,21 +72,148 @@ SMeta *metaOpen(SMetaOptions *options) {
pMeta
->
stbList
=
tdListNew
(
sizeof
(
STableObj
*
));
// Options
STkvOpts
*
dbOptions
=
tkvOptionsCreate
();
taosMkDir
(
"meta"
);
// Open tbname DB
rocksdb_options_t
*
tbnameDbOptions
=
rocksdb_options_create
();
pMeta
->
tbnameDb
=
rocksdb_open
(
tbnameDbOptions
,
"tbname_uid_db"
,
&
err
);
pMeta
->
tbnameDb
=
tkvOpen
(
dbOptions
,
"meta/tbname_uid_db"
);
// Open tag DB
pMeta
->
tagDb
=
rocksdb_open
(
tbnameDbOptions
,
"uid_tag_db"
,
&
err
);
pMeta
->
tagDb
=
tkvOpen
(
dbOptions
,
"meta/uid_tag_db"
);
// Open schema DB
pMeta
->
schemaDb
=
rocksdb_open
(
tbnameDbOptions
,
"schema_db"
,
&
err
);
pMeta
->
schemaDb
=
tkvOpen
(
dbOptions
,
"meta/schema_db"
);
// Open tag index
pMeta
->
tagIdx
=
tkvOpen
(
dbOptions
,
"meta/tag_idx_db"
);
tkvOptionsDestroy
(
dbOptions
);
return
pMeta
;
}
void
metaClose
(
SMeta
*
pMeta
)
{
// TODO
if
(
pMeta
)
{
tkvClose
(
pMeta
->
tagIdx
);
tkvClose
(
pMeta
->
schemaDb
);
tkvClose
(
pMeta
->
tagDb
);
tkvClose
(
pMeta
->
tbnameDb
);
tdListFree
(
pMeta
->
stbList
);
taosHashCleanup
(
pMeta
->
pTableObjHash
);
pthread_rwlock_destroy
(
&
(
pMeta
->
rwLock
));
}
}
int
metaCreateTable
(
SMeta
*
pMeta
,
STableOpts
*
pTableOpts
)
{
size_t
vallen
;
STkvReadOpts
*
ropt
;
STableObj
*
pTableObj
=
NULL
;
STkvWriteOpts
*
wopt
;
// Check if table already exists
ropt
=
tkvReadOptsCreate
();
char
*
uidStr
=
tkvGet
(
pMeta
->
tbnameDb
,
ropt
,
pTableOpts
->
name
,
strlen
(
pTableOpts
->
name
),
&
vallen
);
if
(
uidStr
!=
NULL
)
{
// Has duplicate named table
return
-
1
;
}
tkvReadOptsDestroy
(
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
=
tkvWriteOptsCreate
();
// rocksdb_writeoptions_disable_WAL(wopt, 1);
// Add to tbname db
tkvPut
(
pMeta
->
tbnameDb
,
wopt
,
pTableOpts
->
name
,
strlen
(
pTableOpts
->
name
),
(
char
*
)
&
pTableObj
->
pTable
->
uid
,
sizeof
(
tb_uid_t
));
// Add to schema db
char
id
[
12
];
char
buf
[
256
];
void
*
pBuf
=
buf
;
*
(
tb_uid_t
*
)
id
=
pTableObj
->
pTable
->
uid
;
*
(
int32_t
*
)(
id
+
sizeof
(
tb_uid_t
))
=
schemaVersion
(
pTableOpts
->
pSchema
);
int
size
=
tdEncodeSchema
(
&
pBuf
,
pTableOpts
->
pSchema
);
tkvPut
(
pMeta
->
schemaDb
,
wopt
,
id
,
12
,
buf
,
size
);
tkvWriteOptsDestroy
(
wopt
);
pthread_rwlock_unlock
(
&
pMeta
->
rwLock
);
return
0
;
}
void
metaDestroy
(
const
char
*
path
)
{
taosRemoveDir
(
path
);
}
int
metaCommit
(
SMeta
*
meta
)
{
return
0
;
}
void
metaTableOptsInit
(
STableOpts
*
pTableOpts
,
int8_t
type
,
const
char
*
name
,
const
STSchema
*
pSchema
)
{
pTableOpts
->
type
=
type
;
pTableOpts
->
name
=
strdup
(
name
);
pTableOpts
->
pSchema
=
tdDupSchema
(
pSchema
);
}
/* -------------------- 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
;
}
int
metaCommit
(
SMeta
*
meta
)
{
return
0
;
}
\ No newline at end of file
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
浏览文件 @
0fcbd2f5
/*
* 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
浏览文件 @
0fcbd2f5
...
...
@@ -2,6 +2,7 @@ add_executable(metaTest "")
target_sources
(
metaTest
PRIVATE
"../src/meta.c"
"../src/metaUid.c"
"metaTests.cpp"
)
target_include_directories
(
metaTest
...
...
@@ -13,6 +14,11 @@ target_link_libraries(metaTest
os
util
common
rocksdb
gtest_main
tkv
)
enable_testing
()
add_test
(
NAME meta_test
COMMAND metaTest
)
\ No newline at end of file
source/server/vnode/meta/test/metaTests.cpp
浏览文件 @
0fcbd2f5
#include <gtest/gtest.h>
#include <string.h>
#include <iostream>
#include "meta.h"
TEST
(
MetaTest
,
meta_open_test
)
{
metaOpen
(
NULL
);
std
::
cout
<<
"Hello META!"
<<
std
::
endl
;
// Open Meta
SMeta
*
meta
=
metaOpen
(
NULL
);
std
::
cout
<<
"Meta is opened!"
<<
std
::
endl
;
// Create tables
STableOpts
tbOpts
;
char
tbname
[
128
];
STSchema
*
pSchema
;
STSchemaBuilder
sb
;
tdInitTSchemaBuilder
(
&
sb
,
0
);
for
(
size_t
i
=
0
;
i
<
10
;
i
++
)
{
tdAddColToSchema
(
&
sb
,
TSDB_DATA_TYPE_TIMESTAMP
,
i
,
8
);
}
pSchema
=
tdGetSchemaFromBuilder
(
&
sb
);
tdDestroyTSchemaBuilder
(
&
sb
);
for
(
size_t
i
=
0
;
i
<
1000000
;
i
++
)
{
sprintf
(
tbname
,
"tb%ld"
,
i
);
metaTableOptsInit
(
&
tbOpts
,
0
,
tbname
,
pSchema
);
metaCreateTable
(
meta
,
&
tbOpts
);
}
// Close Meta
metaClose
(
meta
);
std
::
cout
<<
"Meta is closed!"
<<
std
::
endl
;
// Destroy Meta
metaDestroy
(
"meta"
);
std
::
cout
<<
"Meta is destroyed!"
<<
std
::
endl
;
}
\ No newline at end of file
source/server/vnode/tq/CMakeLists.txt
浏览文件 @
0fcbd2f5
...
...
@@ -3,10 +3,11 @@ add_library(tq ${TQ_SRC})
target_include_directories
(
tq
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/server/vnode/tq"
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/libs/wal"
PRIVATE
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/inc"
PRIVATE
"
${
CMAKE_SOURCE_DIR
}
/include/os"
)
target_link_libraries
(
os
wal
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录