more
This commit is contained in:
parent
27f465a884
commit
15b8a7f55a
|
@ -18,9 +18,20 @@
|
|||
|
||||
int metaOpenCache(SMeta *pMeta) {
|
||||
// TODO
|
||||
if (pMeta->options.lruCacheSize) {
|
||||
pMeta->pCache = rocksdb_cache_create_lru(pMeta->options.lruCacheSize);
|
||||
if (pMeta->pCache == NULL) {
|
||||
// TODO: handle error
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void metaCloseCache(SMeta *pMeta) {
|
||||
// TODO
|
||||
if (pMeta->pCache) {
|
||||
rocksdb_cache_destroy(pMeta->pCache);
|
||||
pMeta->pCache = NULL;
|
||||
}
|
||||
}
|
|
@ -17,78 +17,10 @@
|
|||
#include "metaDef.h"
|
||||
|
||||
int metaOpenDB(SMeta *pMeta) {
|
||||
#if 0
|
||||
char * err = NULL;
|
||||
rocksdb_options_t *dbOptions;
|
||||
rocksdb_options_t *idxOptions;
|
||||
/* TODO */
|
||||
|
||||
// Create LRU cache
|
||||
if (pMeta->options.lruCacheSize) {
|
||||
pMeta->metaDB.pCache = rocksdb_cache_create_lru(pMeta->options.lruCacheSize);
|
||||
if (pMeta->metaDB.pCache == NULL) {
|
||||
// TODO: handle error
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Open raw data DB ---------------------------
|
||||
dbOptions = rocksdb_options_create();
|
||||
if (dbOptions == NULL) {
|
||||
// TODO: handle error
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pMeta->metaDB.pCache) {
|
||||
rocksdb_options_set_row_cache(dbOptions, pMeta->metaDB.pCache);
|
||||
}
|
||||
|
||||
pMeta->metaDB.pDB = rocksdb_open(dbOptions, "db", &err);
|
||||
if (pMeta->metaDB.pDB == NULL) {
|
||||
// TODO: handle error
|
||||
return -1;
|
||||
}
|
||||
|
||||
rocksdb_options_destroy(dbOptions);
|
||||
|
||||
// Open index DB ---------------------------
|
||||
idxOptions = rocksdb_options_create();
|
||||
if (idxOptions == NULL) {
|
||||
// TODO: handle error
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pMeta->metaDB.pCache) {
|
||||
rocksdb_options_set_row_cache(dbOptions, pMeta->metaDB.pCache);
|
||||
}
|
||||
|
||||
pMeta->metaDB.pIdx = rocksdb_open(idxOptions, "index", &err);
|
||||
if (pMeta->metaDB.pIdx == NULL) {
|
||||
// TODO: handle error
|
||||
rocksdb_close(pMeta->metaDB.pDB);
|
||||
return -1;
|
||||
}
|
||||
|
||||
rocksdb_options_destroy(idxOptions);
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
void metaCloseDB(SMeta *pMeta) { /* TODO */
|
||||
#if 0
|
||||
// Close index DB
|
||||
if (pMeta->metaDB.pIdx) {
|
||||
rocksdb_close(pMeta->metaDB.pIdx);
|
||||
}
|
||||
|
||||
// Close raw data DB
|
||||
if (pMeta->metaDB.pDB) {
|
||||
rocksdb_close(pMeta->metaDB.pDB);
|
||||
}
|
||||
|
||||
// Destroy cache
|
||||
if (pMeta->metaDB.pCache) {
|
||||
rocksdb_cache_destroy(pMeta->metaDB.pCache);
|
||||
}
|
||||
#endif
|
||||
}
|
|
@ -13,11 +13,36 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "metaIdx.h"
|
||||
#include "meta.h"
|
||||
#include "metaDef.h"
|
||||
|
||||
int metaOpenIdx(SMeta *pMeta) {
|
||||
/* TODO */
|
||||
char idxDir[128]; // TODO
|
||||
char * err = NULL;
|
||||
rocksdb_options_t *options = rocksdb_options_create();
|
||||
|
||||
// TODO
|
||||
sprintf(idxDir, "%s/index", pMeta->path);
|
||||
|
||||
if (pMeta->pCache) {
|
||||
rocksdb_options_set_row_cache(options, pMeta->pCache);
|
||||
}
|
||||
|
||||
pMeta->pIdx = rocksdb_open(options, idxDir, &err);
|
||||
if (pMeta->pIdx == NULL) {
|
||||
// TODO: handle error
|
||||
rocksdb_options_destroy(options);
|
||||
return -1;
|
||||
}
|
||||
|
||||
rocksdb_options_destroy(options);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void metaCloseIdx(SMeta *pMeta) { /* TODO */ }
|
||||
void metaCloseIdx(SMeta *pMeta) { /* TODO */
|
||||
if (pMeta->pIdx) {
|
||||
rocksdb_close(pMeta->pIdx);
|
||||
pMeta->pIdx = NULL;
|
||||
}
|
||||
}
|
|
@ -22,6 +22,8 @@
|
|||
|
||||
static SMeta *metaNew(const char *path, const SMetaOptions *pMetaOptions);
|
||||
static void metaFree(SMeta *pMeta);
|
||||
static int metaOpenImpl(SMeta *pMeta);
|
||||
static void metaCloseImpl(SMeta *pMeta);
|
||||
|
||||
SMeta *metaOpen(const char *path, const SMetaOptions *pMetaOptions) {
|
||||
SMeta *pMeta = NULL;
|
||||
|
@ -47,26 +49,9 @@ SMeta *metaOpen(const char *path, const SMetaOptions *pMetaOptions) {
|
|||
// Create META path (TODO)
|
||||
taosMkDir(path);
|
||||
|
||||
// Open meta cache
|
||||
if (metaOpenCache(pMeta) < 0) {
|
||||
// TODO: handle error
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Open meta db
|
||||
if (metaOpenDB(pMeta) < 0) {
|
||||
// TODO: handle error
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Open meta index
|
||||
if (metaOpenIdx(pMeta) < 0) {
|
||||
// TODO: handle error
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Open meta table uid generator
|
||||
if (metaOpenUidGnrt(pMeta) < 0) {
|
||||
// Open meta
|
||||
if (metaOpenImpl(pMeta) < 0) {
|
||||
metaFree(pMeta);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -75,10 +60,7 @@ SMeta *metaOpen(const char *path, const SMetaOptions *pMetaOptions) {
|
|||
|
||||
void metaClose(SMeta *pMeta) {
|
||||
if (pMeta) {
|
||||
metaCloseUidGnrt(pMeta);
|
||||
metaCloseIdx(pMeta);
|
||||
metaCloseDB(pMeta);
|
||||
metaCloseCache(pMeta);
|
||||
metaCloseImpl(pMeta);
|
||||
metaFree(pMeta);
|
||||
}
|
||||
}
|
||||
|
@ -113,6 +95,45 @@ static void metaFree(SMeta *pMeta) {
|
|||
}
|
||||
}
|
||||
|
||||
static int metaOpenImpl(SMeta *pMeta) {
|
||||
// Open meta cache
|
||||
if (metaOpenCache(pMeta) < 0) {
|
||||
// TODO: handle error
|
||||
metaCloseImpl(pMeta);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Open meta db
|
||||
if (metaOpenDB(pMeta) < 0) {
|
||||
// TODO: handle error
|
||||
metaCloseImpl(pMeta);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Open meta index
|
||||
if (metaOpenIdx(pMeta) < 0) {
|
||||
// TODO: handle error
|
||||
metaCloseImpl(pMeta);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Open meta table uid generator
|
||||
if (metaOpenUidGnrt(pMeta) < 0) {
|
||||
// TODO: handle error
|
||||
metaCloseImpl(pMeta);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void metaCloseImpl(SMeta *pMeta) {
|
||||
metaCloseUidGnrt(pMeta);
|
||||
metaCloseIdx(pMeta);
|
||||
metaCloseDB(pMeta);
|
||||
metaCloseCache(pMeta);
|
||||
}
|
||||
|
||||
// OLD -------------------------------------------------------------------
|
||||
#if 0
|
||||
static int metaCreateSuperTable(SMeta *pMeta, const char *tbname, const SSuperTableOpts *pSuperTableOpts);
|
||||
|
|
Loading…
Reference in New Issue