more
This commit is contained in:
parent
330013c506
commit
45de6cfee0
|
@ -16,7 +16,7 @@ option(
|
||||||
option(
|
option(
|
||||||
BUILD_WITH_ROCKSDB
|
BUILD_WITH_ROCKSDB
|
||||||
"If build with rocksdb"
|
"If build with rocksdb"
|
||||||
OFF
|
ON
|
||||||
)
|
)
|
||||||
|
|
||||||
option(
|
option(
|
||||||
|
|
|
@ -17,16 +17,18 @@
|
||||||
#define _TD_META_DB_H_
|
#define _TD_META_DB_H_
|
||||||
|
|
||||||
#include "meta.h"
|
#include "meta.h"
|
||||||
#include "tkv.h"
|
// #include "tkv.h"
|
||||||
|
|
||||||
|
#include "rocksdb/c.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct SMetaDB {
|
typedef struct SMetaDB {
|
||||||
STkvDb * pDB;
|
rocksdb_t * pDB;
|
||||||
STkvDb * pIdx;
|
rocksdb_t * pIdx;
|
||||||
STkvCache *pCache;
|
rocksdb_cache_t *pCache;
|
||||||
} SMetaDB;
|
} SMetaDB;
|
||||||
|
|
||||||
int metaOpenDB(SMeta *pMeta);
|
int metaOpenDB(SMeta *pMeta);
|
||||||
|
|
|
@ -17,35 +17,57 @@
|
||||||
#include "metaDef.h"
|
#include "metaDef.h"
|
||||||
|
|
||||||
int metaOpenDB(SMeta *pMeta) {
|
int metaOpenDB(SMeta *pMeta) {
|
||||||
/* TODO */
|
char * err = NULL;
|
||||||
pMeta->metaDB.pDB = tkvOpen(NULL, "db");
|
rocksdb_options_t *pOpts;
|
||||||
|
|
||||||
|
pOpts = rocksdb_options_create();
|
||||||
|
if (pOpts == NULL) {
|
||||||
|
// TODO: handle error
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
rocksdb_options_set_row_cache(pOpts, pMeta->metaDB.pCache);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open raw data DB
|
||||||
|
pMeta->metaDB.pDB = rocksdb_open(pOpts, "db", &err);
|
||||||
if (pMeta->metaDB.pDB == NULL) {
|
if (pMeta->metaDB.pDB == NULL) {
|
||||||
// TODO
|
// TODO: handle error
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pMeta->metaDB.pIdx = tkvOpen(NULL, "index");
|
// Open index DB
|
||||||
|
pMeta->metaDB.pIdx = rocksdb_open(pOpts, "index", &err);
|
||||||
if (pMeta->metaDB.pIdx == NULL) {
|
if (pMeta->metaDB.pIdx == NULL) {
|
||||||
/* TODO */
|
// TODO: handle error
|
||||||
|
rocksdb_close(pMeta->metaDB.pDB);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
{ /* TODO: for cache*/
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void metaCloseDB(SMeta *pMeta) { /* TODO */
|
void metaCloseDB(SMeta *pMeta) { /* TODO */
|
||||||
{
|
// Close index DB
|
||||||
// TODO: clear cache
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pMeta->metaDB.pIdx) {
|
if (pMeta->metaDB.pIdx) {
|
||||||
tkvClose(pMeta->metaDB.pIdx);
|
rocksdb_close(pMeta->metaDB.pIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close raw data DB
|
||||||
if (pMeta->metaDB.pDB) {
|
if (pMeta->metaDB.pDB) {
|
||||||
tkvClose(pMeta->metaDB.pIdx);
|
rocksdb_close(pMeta->metaDB.pDB);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destroy cache
|
||||||
|
if (pMeta->metaDB.pCache) {
|
||||||
|
rocksdb_cache_destroy(pMeta->metaDB.pCache);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue