refact
This commit is contained in:
parent
40d58ce1a2
commit
e9bf4fceb0
|
@ -22,7 +22,7 @@ extern "C" {
|
|||
|
||||
void taosRemoveDir(const char *dirname);
|
||||
bool taosDirExist(char *dirname);
|
||||
bool taosMkDir(char *dirname);
|
||||
bool taosMkDir(const char *dirname);
|
||||
void taosRemoveOldFiles(char *dirname, int32_t keepDays);
|
||||
bool taosExpandDir(char *dirname, char *outname, 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_
|
||||
#define _TD_META_DEF_H_
|
||||
|
||||
#include "metaDB.h"
|
||||
#include "metaUid.h"
|
||||
#include "tkv.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct SMeta {
|
||||
STableUidGenerator uidGenerator;
|
||||
|
||||
STkvDb* tableDb; // uid->table obj
|
||||
STkvDb* tbnameDb; // tbname --> uid
|
||||
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
|
||||
char* path; // path of current meta
|
||||
STbUidGenerator uidGenerator; // meta table UID generator
|
||||
SMetaDB* pMetaDB; // meta DB for real storage engine
|
||||
SMetaOptions options; // meta option
|
||||
};
|
||||
|
||||
#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
|
||||
|
||||
/* ------------------------ APIS EXPOSED ------------------------ */
|
||||
typedef struct STableUidGenerator STableUidGenerator;
|
||||
typedef struct STbUidGenerator {
|
||||
tb_uid_t nextUid;
|
||||
} STbUidGenerator;
|
||||
|
||||
// tb_uid_t
|
||||
#define IVLD_TB_UID 0
|
||||
tb_uid_t generateUid(STableUidGenerator *);
|
||||
tb_uid_t generateUid(STbUidGenerator *);
|
||||
|
||||
// STableUidGenerator
|
||||
void tableUidGeneratorInit(STableUidGenerator *, tb_uid_t suid);
|
||||
void tableUidGeneratorInit(STbUidGenerator *, tb_uid_t suid);
|
||||
#define tableUidGeneratorClear(ug)
|
||||
|
||||
/* ------------------------ FOR TEST AND COMPILE ONLY ------------------------ */
|
||||
struct STableUidGenerator {
|
||||
tb_uid_t nextUid;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#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/>.
|
||||
*/
|
||||
|
||||
#include "meta.h"
|
||||
#include "metaDef.h"
|
||||
#include "tcoding.h"
|
||||
|
||||
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);
|
||||
#include "meta.h"
|
||||
#include "metaDef.h"
|
||||
#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;
|
||||
|
||||
pMeta = (SMeta *)calloc(1, sizeof(*pMeta));
|
||||
if (pMeta == NULL) {
|
||||
// Set default options
|
||||
if (pMetaOptions == NULL) {
|
||||
pMetaOptions = &defaultMetaOptions;
|
||||
}
|
||||
|
||||
// Validate the options
|
||||
if (metaValidateOptions(pMetaOptions) < 0) {
|
||||
// TODO: deal with error
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// TODO: check if file exists and handle the error
|
||||
taosMkDir("meta");
|
||||
// Allocate handle
|
||||
pMeta = metaNew(path, pMetaOptions);
|
||||
if (pMeta == NULL) {
|
||||
// TODO: handle error
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Open tableDb
|
||||
STkvOpts *tableDbOpts = tkvOptsCreate();
|
||||
tkvOptsSetCreateIfMissing(tableDbOpts, 1);
|
||||
pMeta->tableDb = tkvOpen(tableDbOpts, "meta/table_db");
|
||||
tkvOptsDestroy(tableDbOpts);
|
||||
// Create META path
|
||||
taosMkDir(path);
|
||||
|
||||
// Open tbnameDb
|
||||
STkvOpts *tbnameDbOpts = tkvOptsCreate();
|
||||
tkvOptsSetCreateIfMissing(tbnameDbOpts, 1);
|
||||
pMeta->tbnameDb = tkvOpen(tbnameDbOpts, "meta/tbname_db");
|
||||
tkvOptsDestroy(tbnameDbOpts);
|
||||
// Open the DBs needed
|
||||
if (metaOpenDB(pMeta) < 0) {
|
||||
// TODO: handle error
|
||||
metaFree(pMeta);
|
||||
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;
|
||||
}
|
||||
|
||||
void metaClose(SMeta *pMeta) {
|
||||
if (pMeta) {
|
||||
tableUidGeneratorClear(&pMeta->uidGenerator);
|
||||
|
||||
tkvClose(pMeta->tagIdx);
|
||||
tkvClose(pMeta->tagDb);
|
||||
tkvClose(pMeta->schemaDb);
|
||||
tkvClose(pMeta->tbnameDb);
|
||||
tkvClose(pMeta->tableDb);
|
||||
|
||||
metaCloseDB(pMeta);
|
||||
free(pMeta);
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
int metaCreateTable(SMeta *pMeta, const STableOptions *pTableOpts) {
|
||||
size_t vallen;
|
||||
char * pUid;
|
||||
|
@ -106,8 +94,37 @@ int metaCreateTable(SMeta *pMeta, const STableOptions *pTableOpts) {
|
|||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ------------------------ 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) {
|
||||
size_t vallen;
|
||||
size_t keylen;
|
||||
|
@ -258,3 +275,5 @@ void metaTableOptsClear(STableOptions *pTableOpts) {
|
|||
}
|
||||
|
||||
void metaDestroy(const char *path) { taosRemoveDir(path); }
|
||||
|
||||
#endif
|
|
@ -26,5 +26,11 @@ void metaOptionsClear(SMetaOptions *pMetaOptions) {
|
|||
// TODO
|
||||
}
|
||||
|
||||
int metaValidateOptions(const SMetaOptions *pMetaOptions) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
void metaOptionsCopy(SMetaOptions *pDest, const SMetaOptions *pSrc) { memcpy(pDest, pSrc, sizeof(*pSrc)); }
|
||||
|
||||
/* ------------------------ STATIC METHODS ------------------------ */
|
||||
static void metaOptionsCopy(SMetaOptions *pDest, const SMetaOptions *pSrc) { memcpy(pDest, pSrc, sizeof(*pSrc)); }
|
|
@ -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"
|
||||
|
||||
tb_uid_t generateUid(STableUidGenerator *pGen) {
|
||||
tb_uid_t generateUid(STbUidGenerator *pGen) {
|
||||
// Generate a new table UID
|
||||
return ++(pGen->nextUid);
|
||||
}
|
||||
|
||||
void tableUidGeneratorInit(STableUidGenerator *pGen, tb_uid_t suid) {
|
||||
void tableUidGeneratorInit(STbUidGenerator *pGen, tb_uid_t suid) {
|
||||
// Init a generator
|
||||
pGen->nextUid = suid;
|
||||
}
|
|
@ -1,24 +1,24 @@
|
|||
add_executable(metaTest "")
|
||||
target_sources(metaTest
|
||||
PRIVATE
|
||||
"../src/metaMain.c"
|
||||
"../src/metaUid.c"
|
||||
"metaTests.cpp"
|
||||
)
|
||||
target_include_directories(metaTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/server/vnode/meta"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_link_libraries(metaTest
|
||||
os
|
||||
util
|
||||
common
|
||||
gtest_main
|
||||
tkv
|
||||
)
|
||||
enable_testing()
|
||||
add_test(
|
||||
NAME meta_test
|
||||
COMMAND metaTest
|
||||
)
|
||||
# add_executable(metaTest "")
|
||||
# target_sources(metaTest
|
||||
# PRIVATE
|
||||
# "../src/metaMain.c"
|
||||
# "../src/metaUid.c"
|
||||
# "metaTests.cpp"
|
||||
# )
|
||||
# target_include_directories(metaTest
|
||||
# PUBLIC
|
||||
# "${CMAKE_SOURCE_DIR}/include/server/vnode/meta"
|
||||
# "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
# )
|
||||
# target_link_libraries(metaTest
|
||||
# os
|
||||
# util
|
||||
# common
|
||||
# gtest_main
|
||||
# tkv
|
||||
# )
|
||||
# enable_testing()
|
||||
# add_test(
|
||||
# NAME meta_test
|
||||
# COMMAND metaTest
|
||||
# )
|
|
@ -60,7 +60,7 @@ void taosRemoveDir(const char *dirname) {
|
|||
|
||||
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);
|
||||
if (code < 0 && errno == EEXIST) {
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue