Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c448c156
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
c448c156
编写于
12月 07, 2021
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more work
上级
9048c77e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
160 addition
and
1 deletion
+160
-1
source/dnode/vnode/meta/src/metaBDBImpl.c
source/dnode/vnode/meta/src/metaBDBImpl.c
+160
-1
未找到文件。
source/dnode/vnode/meta/src/metaBDBImpl.c
浏览文件 @
c448c156
...
...
@@ -17,8 +17,14 @@
#include "metaDef.h"
#include "tcoding.h"
#include "thash.h"
typedef
struct
{
tb_uid_t
uid
;
int32_t
sver
;
}
SSchemaKey
;
struct
SMetaDB
{
// DB
DB
*
pStbDB
;
...
...
@@ -39,9 +45,18 @@ static SMetaDB *metaNewDB();
static
void
metaFreeDB
(
SMetaDB
*
pDB
);
static
int
metaCreateDBEnv
(
SMetaDB
*
pDB
,
const
char
*
path
);
static
void
metaDestroyDBEnv
(
SMetaDB
*
pDB
);
static
int
metaEncodeSchemaKey
(
void
**
buf
,
SSchemaKey
*
pSchemaKey
);
static
void
*
metaDecodeSchemaKey
(
void
*
buf
,
SSchemaKey
*
pSchemaKey
);
static
int
metaNameIdxCb
(
DB
*
sdbp
,
const
DBT
*
pKey
,
const
DBT
*
pValue
,
DBT
*
pSKey
);
static
int
metaUidIdxCb
(
DB
*
sdbp
,
const
DBT
*
pKey
,
const
DBT
*
pValue
,
DBT
*
pSKey
);
static
void
metaPutSchema
(
SMeta
*
pMeta
,
tb_uid_t
uid
,
STSchema
*
pSchema
);
static
int
metaEncodeTbInfo
(
void
**
buf
,
STbCfg
*
pTbCfg
);
static
void
*
metaDecodeTbInfo
(
void
*
buf
,
STbCfg
*
pTbCfg
);
static
int
metaSaveTbInfo
(
DB
*
pDB
,
tb_uid_t
uid
,
STbCfg
*
pTbCfg
);
#define META_OPEN_DB(pDB, pEnv, fName) \
do { \
int ret; \
ret = db_create(&((pDB)), (pEnv), 0); \
if (ret != 0) { \
P_ERROR("Failed to create META DB", ret); \
...
...
@@ -59,6 +74,15 @@ static void metaDestroyDBEnv(SMetaDB *pDB);
#define META_CLOSE_DB(pDB)
#define META_ASSOCIATE_IDX(pDB, pNameIdx, cbf) \
do { \
int ret = (pDB)->associate((pDB), NULL, (pNameIdx), (cbf), 0); \
if (ret != 0) { \
P_ERROR("Failed to associate META DB", ret); \
metaCloseDB(pMeta); \
} \
} while (0)
int
metaOpenDB
(
SMeta
*
pMeta
)
{
int
ret
;
SMetaDB
*
pDB
;
...
...
@@ -89,6 +113,17 @@ int metaOpenDB(SMeta *pMeta) {
META_OPEN_DB
(
pDB
->
pUidIdx
,
pDB
->
pEvn
,
"index.db"
);
// Associate name index
META_ASSOCIATE_IDX
(
pDB
->
pStbDB
,
pDB
->
pNameIdx
,
metaNameIdxCb
);
META_ASSOCIATE_IDX
(
pDB
->
pStbDB
,
pDB
->
pUidIdx
,
metaUidIdxCb
);
META_ASSOCIATE_IDX
(
pDB
->
pNtbDB
,
pDB
->
pNameIdx
,
metaNameIdxCb
);
META_ASSOCIATE_IDX
(
pDB
->
pNtbDB
,
pDB
->
pUidIdx
,
metaUidIdxCb
);
for
(;;)
{
// Loop to associate each super table db
break
;
}
{
// TODO: Loop to open index DB for each super table
// and create the association between main DB and index
...
...
@@ -106,7 +141,56 @@ void metaCloseDB(SMeta *pMeta) {
}
int
metaSaveTableToDB
(
SMeta
*
pMeta
,
STbCfg
*
pTbCfg
)
{
// TODO
char
buf
[
512
];
void
*
pBuf
;
DBT
key
=
{
0
};
DBT
value
=
{
0
};
SSchemaKey
schemaKey
;
tb_uid_t
uid
;
if
(
pTbCfg
->
type
==
META_SUPER_TABLE
)
{
// Handle SUPER table
uid
=
pTbCfg
->
stbCfg
.
suid
;
// Same table info
metaSaveTbInfo
(
pMeta
->
pDB
->
pStbDB
,
uid
,
pTbCfg
);
// save schema
metaPutSchema
(
pMeta
,
uid
,
pTbCfg
->
stbCfg
.
pSchema
);
{
// Create a super table DB and corresponding index DB
DB
*
pStbDB
;
DB
*
pStbIdxDB
;
META_OPEN_DB
(
pStbDB
,
pMeta
->
pDB
->
pEvn
,
"meta.db"
);
META_OPEN_DB
(
pStbIdxDB
,
pMeta
->
pDB
->
pEvn
,
"index.db"
);
// TODO META_ASSOCIATE_IDX();
}
}
else
if
(
pTbCfg
->
type
==
META_CHILD_TABLE
)
{
// Handle CHILD table
uid
=
metaGenerateUid
(
pMeta
);
DB
*
pCTbDB
=
taosHashGet
(
pMeta
->
pDB
->
pCtbMap
,
&
(
pTbCfg
->
ctbCfg
.
suid
),
sizeof
(
pTbCfg
->
ctbCfg
.
suid
));
if
(
pCTbDB
==
NULL
)
{
ASSERT
(
0
);
}
metaSaveTbInfo
(
pCTbDB
,
uid
,
pTbCfg
);
}
else
if
(
pTbCfg
->
type
==
META_NORMAL_TABLE
)
{
// Handle NORMAL table
uid
=
metaGenerateUid
(
pMeta
);
metaSaveTbInfo
(
pMeta
->
pDB
->
pNtbDB
,
uid
,
pTbCfg
);
metaPutSchema
(
pMeta
,
uid
,
pTbCfg
->
stbCfg
.
pSchema
);
}
else
{
ASSERT
(
0
);
}
return
0
;
}
...
...
@@ -175,4 +259,79 @@ static void metaDestroyDBEnv(SMetaDB *pDB) {
if
(
pDB
->
pEvn
)
{
pDB
->
pEvn
->
close
(
pDB
->
pEvn
,
0
);
}
}
static
int
metaEncodeSchemaKey
(
void
**
buf
,
SSchemaKey
*
pSchemaKey
)
{
int
tsize
=
0
;
tsize
+=
taosEncodeFixedU64
(
buf
,
pSchemaKey
->
uid
);
tsize
+=
taosEncodeFixedI32
(
buf
,
pSchemaKey
->
sver
);
return
tsize
;
}
static
void
*
metaDecodeSchemaKey
(
void
*
buf
,
SSchemaKey
*
pSchemaKey
)
{
buf
=
taosDecodeFixedU64
(
buf
,
&
(
pSchemaKey
->
uid
));
buf
=
taosDecodeFixedI32
(
buf
,
&
(
pSchemaKey
->
sver
));
return
buf
;
}
static
int
metaNameIdxCb
(
DB
*
sdbp
,
const
DBT
*
pKey
,
const
DBT
*
pValue
,
DBT
*
pSKey
)
{
// TODO
return
0
;
}
static
int
metaUidIdxCb
(
DB
*
sdbp
,
const
DBT
*
pKey
,
const
DBT
*
pValue
,
DBT
*
pSKey
)
{
// TODO
return
0
;
}
static
void
metaPutSchema
(
SMeta
*
pMeta
,
tb_uid_t
uid
,
STSchema
*
pSchema
)
{
SSchemaKey
skey
;
char
buf
[
256
];
void
*
pBuf
=
buf
;
DBT
key
=
{
0
};
DBT
value
=
{
0
};
skey
.
uid
=
uid
;
skey
.
sver
=
schemaVersion
(
pSchema
);
key
.
data
=
&
skey
;
key
.
size
=
sizeof
(
skey
);
tdEncodeSchema
(
&
pBuf
,
pSchema
);
value
.
data
=
buf
;
value
.
size
=
POINTER_DISTANCE
(
pBuf
,
buf
);
pMeta
->
pDB
->
pSchemaDB
->
put
(
pMeta
->
pDB
->
pSchemaDB
,
NULL
,
&
key
,
&
value
,
0
);
}
static
int
metaEncodeTbInfo
(
void
**
buf
,
STbCfg
*
pTbCfg
)
{
// TODO
return
0
;
}
static
void
*
metaDecodeTbInfo
(
void
*
buf
,
STbCfg
*
pTbCfg
)
{
// TODO
return
NULL
;
}
static
int
metaSaveTbInfo
(
DB
*
pDB
,
tb_uid_t
uid
,
STbCfg
*
pTbCfg
)
{
DBT
key
=
{
0
};
DBT
value
=
{
0
};
char
buf
[
512
];
void
*
pBuf
=
buf
;
key
.
data
=
&
uid
;
key
.
size
=
sizeof
(
uid
);
metaEncodeTbInfo
(
&
pBuf
,
pTbCfg
);
value
.
data
=
buf
;
value
.
size
=
POINTER_DISTANCE
(
pBuf
,
buf
);
pDB
->
put
(
pDB
,
NULL
,
&
key
,
&
value
,
0
);
return
0
;
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录