refact
This commit is contained in:
parent
40d58ce1a2
commit
e9bf4fceb0
|
@ -22,7 +22,7 @@ extern "C" {
|
||||||
|
|
||||||
void taosRemoveDir(const char *dirname);
|
void taosRemoveDir(const char *dirname);
|
||||||
bool taosDirExist(char *dirname);
|
bool taosDirExist(char *dirname);
|
||||||
bool taosMkDir(char *dirname);
|
bool taosMkDir(const char *dirname);
|
||||||
void taosRemoveOldFiles(char *dirname, int32_t keepDays);
|
void taosRemoveOldFiles(char *dirname, int32_t keepDays);
|
||||||
bool taosExpandDir(char *dirname, char *outname, int32_t maxlen);
|
bool taosExpandDir(char *dirname, char *outname, int32_t maxlen);
|
||||||
bool taosRealPath(char *dirname, int32_t maxlen);
|
bool taosRealPath(char *dirname, int32_t maxlen);
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* 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_DB_H_
|
||||||
|
#define _TD_META_DB_H_
|
||||||
|
|
||||||
|
#include "meta.h"
|
||||||
|
#include "tkv.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct SMetaDB {
|
||||||
|
STkvDb * pDB;
|
||||||
|
STkvDb * pIdx;
|
||||||
|
STkvCache *pCache;
|
||||||
|
} SMetaDB;
|
||||||
|
|
||||||
|
int metaOpenDB(SMeta *pMeta);
|
||||||
|
void metaCloseDB(SMeta *pMeta);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /*_TD_META_DB_H_*/
|
|
@ -16,22 +16,18 @@
|
||||||
#ifndef _TD_META_DEF_H_
|
#ifndef _TD_META_DEF_H_
|
||||||
#define _TD_META_DEF_H_
|
#define _TD_META_DEF_H_
|
||||||
|
|
||||||
|
#include "metaDB.h"
|
||||||
#include "metaUid.h"
|
#include "metaUid.h"
|
||||||
#include "tkv.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct SMeta {
|
struct SMeta {
|
||||||
STableUidGenerator uidGenerator;
|
char* path; // path of current meta
|
||||||
|
STbUidGenerator uidGenerator; // meta table UID generator
|
||||||
STkvDb* tableDb; // uid->table obj
|
SMetaDB* pMetaDB; // meta DB for real storage engine
|
||||||
STkvDb* tbnameDb; // tbname --> uid
|
SMetaOptions options; // meta option
|
||||||
STkvDb* schemaDb; // uid+version --> schema
|
|
||||||
STkvDb* tagDb; // uid --> tag
|
|
||||||
STkvDb* tagIdx; // TODO: need to integrate lucene or our own
|
|
||||||
// STkvCache* metaCache; // TODO: add a global cache here
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* 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_OPTIONS_H_
|
||||||
|
#define _TD_META_OPTIONS_H_
|
||||||
|
|
||||||
|
#include "meta.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern const SMetaOptions defaultMetaOptions;
|
||||||
|
|
||||||
|
int metaValidateOptions(const SMetaOptions *);
|
||||||
|
void metaOptionsCopy(SMetaOptions *pDest, const SMetaOptions *pSrc);
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /*_TD_META_OPTIONS_H_*/
|
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* 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_TABLE_OPTIONS_H_
|
||||||
|
#define _TD_META_TABLE_OPTIONS_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /*_TD_META_TABLE_OPTIONS_H_*/
|
|
@ -23,21 +23,18 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* ------------------------ APIS EXPOSED ------------------------ */
|
/* ------------------------ APIS EXPOSED ------------------------ */
|
||||||
typedef struct STableUidGenerator STableUidGenerator;
|
typedef struct STbUidGenerator {
|
||||||
|
tb_uid_t nextUid;
|
||||||
|
} STbUidGenerator;
|
||||||
|
|
||||||
// tb_uid_t
|
// tb_uid_t
|
||||||
#define IVLD_TB_UID 0
|
#define IVLD_TB_UID 0
|
||||||
tb_uid_t generateUid(STableUidGenerator *);
|
tb_uid_t generateUid(STbUidGenerator *);
|
||||||
|
|
||||||
// STableUidGenerator
|
// STableUidGenerator
|
||||||
void tableUidGeneratorInit(STableUidGenerator *, tb_uid_t suid);
|
void tableUidGeneratorInit(STbUidGenerator *, tb_uid_t suid);
|
||||||
#define tableUidGeneratorClear(ug)
|
#define tableUidGeneratorClear(ug)
|
||||||
|
|
||||||
/* ------------------------ FOR TEST AND COMPILE ONLY ------------------------ */
|
|
||||||
struct STableUidGenerator {
|
|
||||||
tb_uid_t nextUid;
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
|
@ -13,74 +13,62 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "meta.h"
|
|
||||||
#include "metaDef.h"
|
|
||||||
#include "tcoding.h"
|
#include "tcoding.h"
|
||||||
|
|
||||||
static int metaCreateSuperTable(SMeta *pMeta, const char *tbname, const SSuperTableOpts *pSuperTableOpts);
|
#include "meta.h"
|
||||||
static int metaCreateChildTable(SMeta *pMeta, const char *tbname, const SChildTableOpts *pChildTableOpts);
|
#include "metaDef.h"
|
||||||
static int metaCreateNormalTable(SMeta *pMeta, const char *tbname, const SNormalTableOpts *pNormalTableOpts);
|
#include "metaOptions.h"
|
||||||
|
#include "metaDB.h"
|
||||||
|
|
||||||
SMeta *metaOpen(const char *path, const SMetaOptions *pMetaOpts) {
|
static SMeta *metaNew(const char *path, const SMetaOptions *pMetaOptions);
|
||||||
|
static void metaFree(SMeta *pMeta);
|
||||||
|
static int metaCreateSuperTable(SMeta *pMeta, const char *tbname, const SSuperTableOpts *pSuperTableOpts);
|
||||||
|
static int metaCreateChildTable(SMeta *pMeta, const char *tbname, const SChildTableOpts *pChildTableOpts);
|
||||||
|
static int metaCreateNormalTable(SMeta *pMeta, const char *tbname, const SNormalTableOpts *pNormalTableOpts);
|
||||||
|
|
||||||
|
SMeta *metaOpen(const char *path, const SMetaOptions *pMetaOptions) {
|
||||||
SMeta *pMeta = NULL;
|
SMeta *pMeta = NULL;
|
||||||
|
|
||||||
pMeta = (SMeta *)calloc(1, sizeof(*pMeta));
|
// Set default options
|
||||||
if (pMeta == NULL) {
|
if (pMetaOptions == NULL) {
|
||||||
|
pMetaOptions = &defaultMetaOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate the options
|
||||||
|
if (metaValidateOptions(pMetaOptions) < 0) {
|
||||||
|
// TODO: deal with error
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: check if file exists and handle the error
|
// Allocate handle
|
||||||
taosMkDir("meta");
|
pMeta = metaNew(path, pMetaOptions);
|
||||||
|
if (pMeta == NULL) {
|
||||||
|
// TODO: handle error
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// Open tableDb
|
// Create META path
|
||||||
STkvOpts *tableDbOpts = tkvOptsCreate();
|
taosMkDir(path);
|
||||||
tkvOptsSetCreateIfMissing(tableDbOpts, 1);
|
|
||||||
pMeta->tableDb = tkvOpen(tableDbOpts, "meta/table_db");
|
|
||||||
tkvOptsDestroy(tableDbOpts);
|
|
||||||
|
|
||||||
// Open tbnameDb
|
// Open the DBs needed
|
||||||
STkvOpts *tbnameDbOpts = tkvOptsCreate();
|
if (metaOpenDB(pMeta) < 0) {
|
||||||
tkvOptsSetCreateIfMissing(tbnameDbOpts, 1);
|
// TODO: handle error
|
||||||
pMeta->tbnameDb = tkvOpen(tbnameDbOpts, "meta/tbname_db");
|
metaFree(pMeta);
|
||||||
tkvOptsDestroy(tbnameDbOpts);
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// Open schemaDb
|
|
||||||
STkvOpts *schemaDbOpts = tkvOptsCreate();
|
|
||||||
tkvOptsSetCreateIfMissing(schemaDbOpts, 1);
|
|
||||||
pMeta->schemaDb = tkvOpen(schemaDbOpts, "meta/schema_db");
|
|
||||||
tkvOptsDestroy(schemaDbOpts);
|
|
||||||
|
|
||||||
// Open tagDb
|
|
||||||
STkvOpts *tagDbOpts = tkvOptsCreate();
|
|
||||||
tkvOptsSetCreateIfMissing(tagDbOpts, 1);
|
|
||||||
pMeta->tagDb = tkvOpen(tagDbOpts, "meta/tag_db");
|
|
||||||
tkvOptsDestroy(tagDbOpts);
|
|
||||||
|
|
||||||
// Open tagIdx
|
|
||||||
STkvOpts *tagIdxDbOpts = tkvOptsCreate();
|
|
||||||
tkvOptsSetCreateIfMissing(tagIdxDbOpts, 1);
|
|
||||||
pMeta->tagIdx = tkvOpen(tagIdxDbOpts, "meta/tag_idx_db");
|
|
||||||
tkvOptsDestroy(tagIdxDbOpts);
|
|
||||||
|
|
||||||
// TODO: need to figure out how to persist the START UID
|
|
||||||
tableUidGeneratorInit(&(pMeta->uidGenerator), IVLD_TB_UID);
|
|
||||||
return pMeta;
|
return pMeta;
|
||||||
}
|
}
|
||||||
|
|
||||||
void metaClose(SMeta *pMeta) {
|
void metaClose(SMeta *pMeta) {
|
||||||
if (pMeta) {
|
if (pMeta) {
|
||||||
tableUidGeneratorClear(&pMeta->uidGenerator);
|
tableUidGeneratorClear(&pMeta->uidGenerator);
|
||||||
|
metaCloseDB(pMeta);
|
||||||
tkvClose(pMeta->tagIdx);
|
|
||||||
tkvClose(pMeta->tagDb);
|
|
||||||
tkvClose(pMeta->schemaDb);
|
|
||||||
tkvClose(pMeta->tbnameDb);
|
|
||||||
tkvClose(pMeta->tableDb);
|
|
||||||
|
|
||||||
free(pMeta);
|
free(pMeta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
int metaCreateTable(SMeta *pMeta, const STableOptions *pTableOpts) {
|
int metaCreateTable(SMeta *pMeta, const STableOptions *pTableOpts) {
|
||||||
size_t vallen;
|
size_t vallen;
|
||||||
char * pUid;
|
char * pUid;
|
||||||
|
@ -106,8 +94,37 @@ int metaCreateTable(SMeta *pMeta, const STableOptions *pTableOpts) {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* ------------------------ STATIC METHODS ------------------------ */
|
/* ------------------------ STATIC METHODS ------------------------ */
|
||||||
|
static SMeta *metaNew(const char *path, const SMetaOptions *pMetaOptions) {
|
||||||
|
SMeta *pMeta;
|
||||||
|
size_t psize = strlen(path);
|
||||||
|
|
||||||
|
pMeta = (SMeta *)calloc(1, sizeof(*pMeta));
|
||||||
|
if (pMeta == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
pMeta->path = strdup(path);
|
||||||
|
if (pMeta->path == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
metaOptionsCopy(&(pMeta->options), pMetaOptions);
|
||||||
|
|
||||||
|
return pMeta;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void metaFree(SMeta *pMeta) {
|
||||||
|
if (pMeta) {
|
||||||
|
tfree(pMeta->path);
|
||||||
|
free(pMeta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OLD -------------------------------------------------------------------
|
||||||
|
#if 0
|
||||||
static int metaCreateSuperTable(SMeta *pMeta, const char *tbname, const SSuperTableOpts *pSuperTableOpts) {
|
static int metaCreateSuperTable(SMeta *pMeta, const char *tbname, const SSuperTableOpts *pSuperTableOpts) {
|
||||||
size_t vallen;
|
size_t vallen;
|
||||||
size_t keylen;
|
size_t keylen;
|
||||||
|
@ -258,3 +275,5 @@ void metaTableOptsClear(STableOptions *pTableOpts) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void metaDestroy(const char *path) { taosRemoveDir(path); }
|
void metaDestroy(const char *path) { taosRemoveDir(path); }
|
||||||
|
|
||||||
|
#endif
|
|
@ -26,5 +26,11 @@ void metaOptionsClear(SMetaOptions *pMetaOptions) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------ STATIC METHODS ------------------------ */
|
int metaValidateOptions(const SMetaOptions *pMetaOptions) {
|
||||||
static void metaOptionsCopy(SMetaOptions *pDest, const SMetaOptions *pSrc) { memcpy(pDest, pSrc, sizeof(*pSrc)); }
|
// TODO
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void metaOptionsCopy(SMetaOptions *pDest, const SMetaOptions *pSrc) { memcpy(pDest, pSrc, sizeof(*pSrc)); }
|
||||||
|
|
||||||
|
/* ------------------------ STATIC METHODS ------------------------ */
|
|
@ -0,0 +1,14 @@
|
||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
|
@ -15,12 +15,12 @@
|
||||||
|
|
||||||
#include "metaUid.h"
|
#include "metaUid.h"
|
||||||
|
|
||||||
tb_uid_t generateUid(STableUidGenerator *pGen) {
|
tb_uid_t generateUid(STbUidGenerator *pGen) {
|
||||||
// Generate a new table UID
|
// Generate a new table UID
|
||||||
return ++(pGen->nextUid);
|
return ++(pGen->nextUid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tableUidGeneratorInit(STableUidGenerator *pGen, tb_uid_t suid) {
|
void tableUidGeneratorInit(STbUidGenerator *pGen, tb_uid_t suid) {
|
||||||
// Init a generator
|
// Init a generator
|
||||||
pGen->nextUid = suid;
|
pGen->nextUid = suid;
|
||||||
}
|
}
|
|
@ -1,24 +1,24 @@
|
||||||
add_executable(metaTest "")
|
# add_executable(metaTest "")
|
||||||
target_sources(metaTest
|
# target_sources(metaTest
|
||||||
PRIVATE
|
# PRIVATE
|
||||||
"../src/metaMain.c"
|
# "../src/metaMain.c"
|
||||||
"../src/metaUid.c"
|
# "../src/metaUid.c"
|
||||||
"metaTests.cpp"
|
# "metaTests.cpp"
|
||||||
)
|
# )
|
||||||
target_include_directories(metaTest
|
# target_include_directories(metaTest
|
||||||
PUBLIC
|
# PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/server/vnode/meta"
|
# "${CMAKE_SOURCE_DIR}/include/server/vnode/meta"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
# "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
# )
|
||||||
target_link_libraries(metaTest
|
# target_link_libraries(metaTest
|
||||||
os
|
# os
|
||||||
util
|
# util
|
||||||
common
|
# common
|
||||||
gtest_main
|
# gtest_main
|
||||||
tkv
|
# tkv
|
||||||
)
|
# )
|
||||||
enable_testing()
|
# enable_testing()
|
||||||
add_test(
|
# add_test(
|
||||||
NAME meta_test
|
# NAME meta_test
|
||||||
COMMAND metaTest
|
# COMMAND metaTest
|
||||||
)
|
# )
|
|
@ -60,7 +60,7 @@ void taosRemoveDir(const char *dirname) {
|
||||||
|
|
||||||
bool taosDirExist(char *dirname) { return access(dirname, F_OK) == 0; }
|
bool taosDirExist(char *dirname) { return access(dirname, F_OK) == 0; }
|
||||||
|
|
||||||
bool taosMkDir(char *dirname) {
|
bool taosMkDir(const char *dirname) {
|
||||||
int32_t code = mkdir(dirname, 0755);
|
int32_t code = mkdir(dirname, 0755);
|
||||||
if (code < 0 && errno == EEXIST) {
|
if (code < 0 && errno == EEXIST) {
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue