From c8f23a801de2141c4c6ffbd4b15b30dc125f1074 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 6 Dec 2021 15:35:39 +0800 Subject: [PATCH] more --- source/dnode/vnode/meta/src/metaBDBImpl.c | 30 ++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/source/dnode/vnode/meta/src/metaBDBImpl.c b/source/dnode/vnode/meta/src/metaBDBImpl.c index 1cc197820b..e0c21dba64 100644 --- a/source/dnode/vnode/meta/src/metaBDBImpl.c +++ b/source/dnode/vnode/meta/src/metaBDBImpl.c @@ -24,8 +24,7 @@ struct SMetaDB { }; int metaOpenDB(SMeta *pMeta) { - int ret; - char dbname[128]; + int ret; pMeta->pDB = (SMetaDB *)calloc(1, sizeof(SMetaDB)); if (pMeta->pDB == NULL) { @@ -34,6 +33,17 @@ int metaOpenDB(SMeta *pMeta) { } // TODO: create the env + ret = db_env_create(&(pMeta->pDB->pEvn), 0); + if (ret != 0) { + // TODO: handle error + return -1; + } + + ret = pMeta->pDB->pEvn->open(pMeta->pDB->pEvn, pMeta->path, DB_CREATE | DB_INIT_MPOOL, 0); + if (ret != 0) { + // TODO: handle error + return -1; + } ret = db_create(&(pMeta->pDB->pDB), pMeta->pDB->pEvn, 0); if (ret != 0) { @@ -77,7 +87,21 @@ int metaOpenDB(SMeta *pMeta) { void metaCloseDB(SMeta *pMeta) { if (pMeta->pDB) { - /* TODO */ + if (pMeta->pDB->pIdx) { + pMeta->pDB->pIdx->close(pMeta->pDB->pIdx, 0); + pMeta->pDB->pIdx = NULL; + } + + if (pMeta->pDB->pDB) { + pMeta->pDB->pDB->close(pMeta->pDB->pDB, 0); + pMeta->pDB->pDB = NULL; + } + + if (pMeta->pDB->pEvn) { + pMeta->pDB->pEvn->close(pMeta->pDB->pEvn, 0); + pMeta->pDB->pEvn = NULL; + } + free(pMeta->pDB); } }