Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
a1e281b7
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
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看板
提交
a1e281b7
编写于
12月 08, 2021
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement index callback function
上级
fc267502
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
71 addition
and
131 deletion
+71
-131
source/dnode/vnode/meta/src/metaBDBImpl.c
source/dnode/vnode/meta/src/metaBDBImpl.c
+71
-131
未找到文件。
source/dnode/vnode/meta/src/metaBDBImpl.c
浏览文件 @
a1e281b7
...
...
@@ -20,6 +20,11 @@
#include "tcoding.h"
#include "thash.h"
typedef
struct
{
tb_uid_t
uid
;
int32_t
sver
;
}
SSchemaKey
;
struct
SMetaDB
{
// DB
DB
*
pTbDB
;
...
...
@@ -47,6 +52,9 @@ static int metaNameIdxCb(DB *pIdx, const DBT *pKey, const DBT *pValue, DBT
static
int
metaStbIdxCb
(
DB
*
pIdx
,
const
DBT
*
pKey
,
const
DBT
*
pValue
,
DBT
*
pSKey
);
static
int
metaNtbIdxCb
(
DB
*
pIdx
,
const
DBT
*
pKey
,
const
DBT
*
pValue
,
DBT
*
pSKey
);
static
int
metaCtbIdxCb
(
DB
*
pIdx
,
const
DBT
*
pKey
,
const
DBT
*
pValue
,
DBT
*
pSKey
);
static
int
metaEncodeTbInfo
(
void
**
buf
,
STbCfg
*
pTbCfg
);
static
void
*
metaDecodeTbInfo
(
void
*
buf
,
STbCfg
*
pTbCfg
);
static
void
metaClearTbCfg
(
STbCfg
*
pTbCfg
);
#define BDB_PERR(info, code) fprintf(stderr, info " reason: %s", db_strerror(code))
...
...
@@ -118,6 +126,9 @@ void metaCloseDB(SMeta *pMeta) {
int
metaSaveTableToDB
(
SMeta
*
pMeta
,
STbCfg
*
pTbCfg
)
{
tb_uid_t
uid
;
char
buf
[
512
];
void
*
pBuf
;
DBT
key
,
value
;
STSchema
*
pSchema
=
NULL
;
if
(
pTbCfg
->
type
==
META_SUPER_TABLE
)
{
...
...
@@ -128,15 +139,14 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) {
{
// save table info
char
buf
[
512
];
void
*
pBuf
=
buf
;
DBT
key
=
{
0
};
DBT
value
=
{
0
};
pBuf
=
buf
;
memset
(
&
key
,
0
,
sizeof
(
key
));
memset
(
&
value
,
0
,
sizeof
(
key
));
key
.
data
=
&
uid
;
key
.
size
=
sizeof
(
uid
);
//
metaEncodeTbInfo(&pBuf, pTbCfg);
metaEncodeTbInfo
(
&
pBuf
,
pTbCfg
);
value
.
data
=
buf
;
value
.
size
=
POINTER_DISTANCE
(
pBuf
,
buf
);
...
...
@@ -152,14 +162,13 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) {
}
if
(
pSchema
)
{
char
buf
[
512
]
;
void
*
pBuf
=
buf
;
DBT
key
=
{
0
}
;
DBT
value
=
{
0
};
pBuf
=
buf
;
memset
(
&
key
,
0
,
sizeof
(
key
))
;
memset
(
&
value
,
0
,
sizeof
(
key
))
;
SSchemaKey
schemaKey
=
{
uid
,
schemaVersion
(
pSchema
)
};
// TODO
key
.
data
=
NULL
;
key
.
size
=
0
;
key
.
data
=
&
schemaKey
;
key
.
size
=
sizeof
(
schemaKey
);
tdEncodeSchema
(
&
pBuf
,
pSchema
);
...
...
@@ -274,129 +283,70 @@ static void metaCloseBDBIdx(DB *pIdx) {
}
static
int
metaNameIdxCb
(
DB
*
pIdx
,
const
DBT
*
pKey
,
const
DBT
*
pValue
,
DBT
*
pSKey
)
{
// TODO
return
0
;
}
char
*
name
;
static
int
metaStbIdxCb
(
DB
*
pIdx
,
const
DBT
*
pKey
,
const
DBT
*
pValue
,
DBT
*
pSKey
)
{
// TODO
return
0
;
}
memset
(
pSKey
,
0
,
sizeof
(
*
pSKey
));
taosDecodeString
(
pValue
->
data
,
&
name
);
static
int
metaNtbIdxCb
(
DB
*
pIdx
,
const
DBT
*
pKey
,
const
DBT
*
pValue
,
DBT
*
pSKey
)
{
// TODO
return
0
;
}
pSKey
->
data
=
name
;
pSKey
->
size
=
strlen
(
name
);
pSKey
->
flags
=
DB_DBT_APPMALLOC
;
static
int
metaCtbIdxCb
(
DB
*
pIdx
,
const
DBT
*
pKey
,
const
DBT
*
pValue
,
DBT
*
pSKey
)
{
// TODO
return
0
;
}
#if 0
int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) {
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);
}
static
int
metaStbIdxCb
(
DB
*
pIdx
,
const
DBT
*
pKey
,
const
DBT
*
pValue
,
DBT
*
pSKey
)
{
STbCfg
tbCfg
=
{
0
};
metaSaveTbInfo(pCTbDB, uid, pTbCfg);
metaDecodeTbInfo
(
pValue
->
data
,
&
tbCfg
);
if
(
tbCfg
.
type
==
META_SUPER_TABLE
)
{
memset
(
pSKey
,
0
,
sizeof
(
*
pSKey
));
} else if (pTbCfg->type == META_NORMAL_TABLE) {
// Handle NORMAL table
uid = metaGenerateUid(pMeta);
pSKey
->
data
=
pKey
->
data
;
pSKey
->
size
=
pKey
->
size
;
meta
SaveTbInfo(pMeta->pDB->pNtbDB, uid, pT
bCfg);
meta
ClearTbCfg
(
&
t
bCfg
);
metaPutSchema(pMeta, uid, pTbCfg->stbCfg.pSchema)
;
return
0
;
}
else
{
ASSERT(0)
;
return
DB_DONOTINDEX
;
}
return 0;
}
int metaRemoveTableFromDb(SMeta *pMeta, tb_uid_t uid) {
// TODO
}
/* ------------------------ STATIC METHODS ------------------------ */
static int metaEncodeSchemaKey(void **buf, SSchemaKey *pSchemaKey) {
int tsize = 0;
tsize += taosEncodeFixedU64(buf, pSchemaKey->uid);
tsize += taosEncodeFixedI32(buf, pSchemaKey->sver);
return tsize;
}
static
int
metaNtbIdxCb
(
DB
*
pIdx
,
const
DBT
*
pKey
,
const
DBT
*
pValue
,
DBT
*
pSKey
)
{
STbCfg
tbCfg
=
{
0
};
static void *metaDecodeSchemaKey(void *buf, SSchemaKey *pSchemaKey) {
buf = taosDecodeFixedU64(buf, &(pSchemaKey->uid));
buf = taosDecodeFixedI32(buf, &(pSchemaKey->sver
));
metaDecodeTbInfo
(
pValue
->
data
,
&
tbCfg
);
if
(
tbCfg
.
type
==
META_NORMAL_TABLE
)
{
memset
(
pSKey
,
0
,
sizeof
(
*
pSKey
));
return buf
;
}
pSKey
->
data
=
pKey
->
data
;
pSKey
->
size
=
pKey
->
size
;
static int metaNameIdxCb(DB *sdbp, const DBT *pKey, const DBT *pValue, DBT *pSKey) {
// TODO
return 0;
}
metaClearTbCfg
(
&
tbCfg
);
static int metaUidIdxCb(DB *sdbp, const DBT *pKey, const DBT *pValue, DBT *pSKey) {
// TODO
return 0;
return
0
;
}
else
{
return
DB_DONOTINDEX
;
}
}
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};
static
int
metaCtbIdxCb
(
DB
*
pIdx
,
const
DBT
*
pKey
,
const
DBT
*
pValue
,
DBT
*
pSKey
)
{
STbCfg
tbCfg
=
{
0
};
skey.uid = uid;
skey.sver = schemaVersion(pSchema);
metaDecodeTbInfo
(
pValue
->
data
,
&
tbCfg
);
if
(
tbCfg
.
type
==
META_CHILD_TABLE
)
{
memset
(
pSKey
,
0
,
sizeof
(
*
pSKey
));
key.data = &skey
;
key.size = sizeof(skey)
;
pSKey
->
data
=
pKey
->
data
;
pSKey
->
size
=
pKey
->
size
;
tdEncodeSchema(&pBuf, pSchema);
value.data = buf;
value.size = POINTER_DISTANCE(pBuf, buf);
metaClearTbCfg
(
&
tbCfg
);
pMeta->pDB->pSchemaDB->put(pMeta->pDB->pSchemaDB, NULL, &key, &value, 0);
return
0
;
}
else
{
return
DB_DONOTINDEX
;
}
}
static
int
metaEncodeTbInfo
(
void
**
buf
,
STbCfg
*
pTbCfg
)
{
...
...
@@ -405,6 +355,7 @@ static int metaEncodeTbInfo(void **buf, STbCfg *pTbCfg) {
tsize
+=
taosEncodeString
(
buf
,
pTbCfg
->
name
);
tsize
+=
taosEncodeFixedU32
(
buf
,
pTbCfg
->
ttl
);
tsize
+=
taosEncodeFixedU32
(
buf
,
pTbCfg
->
keep
);
tsize
+=
taosEncodeFixedU8
(
buf
,
pTbCfg
->
type
);
if
(
pTbCfg
->
type
==
META_SUPER_TABLE
)
{
tsize
+=
tdEncodeSchema
(
buf
,
pTbCfg
->
stbCfg
.
pTagSchema
);
...
...
@@ -420,10 +371,10 @@ static int metaEncodeTbInfo(void **buf, STbCfg *pTbCfg) {
}
static
void
*
metaDecodeTbInfo
(
void
*
buf
,
STbCfg
*
pTbCfg
)
{
// TODO
buf
=
taosDecodeString
(
buf
,
&
(
pTbCfg
->
name
));
buf
=
taosDecodeFixedU32
(
buf
,
&
(
pTbCfg
->
ttl
));
buf
=
taosDecodeFixedU32
(
buf
,
&
(
pTbCfg
->
keep
));
buf
=
taosDecodeFixedU8
(
buf
,
&
(
pTbCfg
->
type
));
if
(
pTbCfg
->
type
==
META_SUPER_TABLE
)
{
buf
=
tdDecodeSchema
(
buf
,
&
(
pTbCfg
->
stbCfg
.
pTagSchema
));
...
...
@@ -437,22 +388,11 @@ static void *metaDecodeTbInfo(void *buf, STbCfg *pTbCfg) {
return
buf
;
}
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;
}
#endif
\ No newline at end of file
static
void
metaClearTbCfg
(
STbCfg
*
pTbCfg
)
{
tfree
(
pTbCfg
->
name
);
if
(
pTbCfg
->
type
==
META_SUPER_TABLE
)
{
tdFreeSchema
(
pTbCfg
->
stbCfg
.
pTagSchema
);
}
else
if
(
pTbCfg
->
type
==
META_CHILD_TABLE
)
{
tfree
(
pTbCfg
->
ctbCfg
.
pTag
);
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录