more
This commit is contained in:
parent
e7ea5a0e90
commit
9048c77eca
|
@ -40,6 +40,25 @@ static void metaFreeDB(SMetaDB *pDB);
|
||||||
static int metaCreateDBEnv(SMetaDB *pDB, const char *path);
|
static int metaCreateDBEnv(SMetaDB *pDB, const char *path);
|
||||||
static void metaDestroyDBEnv(SMetaDB *pDB);
|
static void metaDestroyDBEnv(SMetaDB *pDB);
|
||||||
|
|
||||||
|
#define META_OPEN_DB(pDB, pEnv, fName) \
|
||||||
|
do { \
|
||||||
|
ret = db_create(&((pDB)), (pEnv), 0); \
|
||||||
|
if (ret != 0) { \
|
||||||
|
P_ERROR("Failed to create META DB", ret); \
|
||||||
|
metaCloseDB(pMeta); \
|
||||||
|
return -1; \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
ret = (pDB)->open((pDB), NULL, (fName), NULL, DB_BTREE, DB_CREATE, 0); \
|
||||||
|
if (ret != 0) { \
|
||||||
|
P_ERROR("Failed to open META DB", ret); \
|
||||||
|
metaCloseDB(pMeta); \
|
||||||
|
return -1; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define META_CLOSE_DB(pDB)
|
||||||
|
|
||||||
int metaOpenDB(SMeta *pMeta) {
|
int metaOpenDB(SMeta *pMeta) {
|
||||||
int ret;
|
int ret;
|
||||||
SMetaDB *pDB;
|
SMetaDB *pDB;
|
||||||
|
@ -56,86 +75,25 @@ int metaOpenDB(SMeta *pMeta) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ret = db_create(&(pDB->pStbDB), pDB->pEvn, 0);
|
META_OPEN_DB(pDB->pStbDB, pDB->pEvn, "meta.db");
|
||||||
// if (ret != 0) {
|
|
||||||
// P_ERROR("failed to create META super table DB", ret);
|
|
||||||
// metaCloseDB(pMeta);
|
|
||||||
// return -1;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// ret = pDB->pStbDB->open(pDB->pStbDB, NULL, "meta.db", NULL, DB_BTREE, DB_CREATE, 0);
|
META_OPEN_DB(pDB->pNtbDB, pDB->pEvn, "meta.db");
|
||||||
// if (ret != 0) {
|
|
||||||
// P_ERROR("failed to create META super table DB", ret);
|
|
||||||
// metaCloseDB(pMeta);
|
|
||||||
// return -1;
|
|
||||||
// }
|
|
||||||
|
|
||||||
#if 0
|
META_OPEN_DB(pDB->pSchemaDB, pDB->pEvn, "meta.db");
|
||||||
ret = db_create(&(pMeta->pDB->pDB), pMeta->pDB->pEvn, 0);
|
|
||||||
if (ret != 0) {
|
{
|
||||||
// TODO: handle error
|
// TODO: Loop to open each super table db
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = db_create(&(pMeta->pDB->pSchemaDB), pMeta->pDB->pEvn, 0);
|
META_OPEN_DB(pDB->pNameIdx, pDB->pEvn, "index.db");
|
||||||
if (ret != 0) {
|
|
||||||
// TODO: handle error
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = db_create(&(pMeta->pDB->pIdx), pMeta->pDB->pEvn, 0);
|
META_OPEN_DB(pDB->pUidIdx, pDB->pEvn, "index.db");
|
||||||
if (ret != 0) {
|
|
||||||
// TODO: handle error
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = pMeta->pDB->pDB->open(pMeta->pDB->pDB, /* DB structure pointer */
|
{
|
||||||
NULL, /* Transaction pointer */
|
// TODO: Loop to open index DB for each super table
|
||||||
"meta.db", /* On-disk file that holds the database */
|
// and create the association between main DB and index
|
||||||
NULL, /* Optional logical database name */
|
|
||||||
DB_BTREE, /* Database access method */
|
|
||||||
DB_CREATE, /* Open flags */
|
|
||||||
0); /* File mode */
|
|
||||||
if (ret != 0) {
|
|
||||||
// TODO: handle error
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = pMeta->pDB->pSchemaDB->open(pMeta->pDB->pSchemaDB, /* DB structure pointer */
|
|
||||||
NULL, /* Transaction pointer */
|
|
||||||
"meta.db", /* On-disk file that holds the database */
|
|
||||||
NULL, /* Optional logical database name */
|
|
||||||
DB_BTREE, /* Database access method */
|
|
||||||
DB_CREATE, /* Open flags */
|
|
||||||
0); /* File mode */
|
|
||||||
if (ret != 0) {
|
|
||||||
// TODO: handle error
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = pMeta->pDB->pIdx->open(pMeta->pDB->pIdx, /* DB structure pointer */
|
|
||||||
NULL, /* Transaction pointer */
|
|
||||||
"index.db", /* On-disk file that holds the database */
|
|
||||||
NULL, /* Optional logical database name */
|
|
||||||
DB_BTREE, /* Database access method */
|
|
||||||
DB_CREATE, /* Open flags */
|
|
||||||
0); /* File mode */
|
|
||||||
if (ret != 0) {
|
|
||||||
// TODO: handle error
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = pMeta->pDB->pDB->associate(pMeta->pDB->pDB, /* Primary database */
|
|
||||||
NULL, /* TXN id */
|
|
||||||
pMeta->pDB->pIdx, /* Secondary database */
|
|
||||||
metaIdxCallback, /* Callback used for key creation */
|
|
||||||
0); /* Flags */
|
|
||||||
if (ret != 0) {
|
|
||||||
// TODO: handle error
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,30 +106,7 @@ void metaCloseDB(SMeta *pMeta) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) {
|
int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) {
|
||||||
#if 0
|
// TODO
|
||||||
tb_uid_t uid;
|
|
||||||
DBT key = {0};
|
|
||||||
DBT value = {0};
|
|
||||||
char buf[256];
|
|
||||||
void * pBuf;
|
|
||||||
int bsize;
|
|
||||||
|
|
||||||
if (pTbCfg->type == META_SUPER_TABLE) {
|
|
||||||
uid = pTbCfg->stbCfg.suid;
|
|
||||||
} else {
|
|
||||||
uid = metaGenerateUid(pMeta);
|
|
||||||
}
|
|
||||||
|
|
||||||
key.size = sizeof(uid);
|
|
||||||
key.data = &uid;
|
|
||||||
|
|
||||||
pBuf = buf;
|
|
||||||
value.size = metaEncodeTbCfg(&pBuf, pTbCfg);
|
|
||||||
value.data = buf;
|
|
||||||
|
|
||||||
pMeta->pDB->pDB->put(pMeta->pDB->pDB, NULL, &key, &value, 0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue