enh: trigger vnode commit at exit if meta changed, for dbs of single replica

This commit is contained in:
Benguang Zhao 2023-11-22 15:23:00 +08:00
parent 421a154d2a
commit f7f9546d1e
4 changed files with 16 additions and 3 deletions

View File

@ -79,6 +79,7 @@ struct SMeta {
char* path; char* path;
SVnode* pVnode; SVnode* pVnode;
bool changed;
TDB* pEnv; TDB* pEnv;
TXN* txn; TXN* txn;
TTB* pTbDb; TTB* pTbDb;

View File

@ -56,7 +56,7 @@ int metaPrepareAsyncCommit(SMeta *pMeta) {
code = ttlMgrFlush(pMeta->pTtlMgr, pMeta->txn); code = ttlMgrFlush(pMeta->pTtlMgr, pMeta->txn);
metaULock(pMeta); metaULock(pMeta);
code = tdbCommit(pMeta->pEnv, pMeta->txn); code = tdbCommit(pMeta->pEnv, pMeta->txn);
pMeta->changed = false;
return code; return code;
} }

View File

@ -251,6 +251,7 @@ int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
++pMeta->pVnode->config.vndStats.numOfSTables; ++pMeta->pVnode->config.vndStats.numOfSTables;
pMeta->changed = true;
metaDebug("vgId:%d, stb:%s is created, suid:%" PRId64, TD_VID(pMeta->pVnode), pReq->name, pReq->suid); metaDebug("vgId:%d, stb:%s is created, suid:%" PRId64, TD_VID(pMeta->pVnode), pReq->name, pReq->suid);
return 0; return 0;
@ -325,6 +326,8 @@ _drop_super_table:
metaUpdTimeSeriesNum(pMeta); metaUpdTimeSeriesNum(pMeta);
pMeta->changed = true;
_exit: _exit:
tdbFree(pKey); tdbFree(pKey);
tdbFree(pData); tdbFree(pData);
@ -424,6 +427,8 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
metaTimeSeriesNotifyCheck(pMeta); metaTimeSeriesNotifyCheck(pMeta);
} }
pMeta->changed = true;
_exit: _exit:
if (oStbEntry.pBuf) taosMemoryFree(oStbEntry.pBuf); if (oStbEntry.pBuf) taosMemoryFree(oStbEntry.pBuf);
tDecoderClear(&dc); tDecoderClear(&dc);
@ -847,6 +852,7 @@ int metaCreateTable(SMeta *pMeta, int64_t ver, SVCreateTbReq *pReq, STableMetaRs
} }
} }
pMeta->changed = true;
metaDebug("vgId:%d, table:%s uid %" PRId64 " is created, type:%" PRId8, TD_VID(pMeta->pVnode), pReq->name, pReq->uid, metaDebug("vgId:%d, table:%s uid %" PRId64 " is created, type:%" PRId8, TD_VID(pMeta->pVnode), pReq->name, pReq->uid,
pReq->type); pReq->type);
return 0; return 0;
@ -895,6 +901,7 @@ int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUi
*tbUid = uid; *tbUid = uid;
} }
pMeta->changed = true;
_exit: _exit:
tdbFree(pData); tdbFree(pData);
return rc; return rc;
@ -938,6 +945,8 @@ void metaDropTables(SMeta *pMeta, SArray *tbUids) {
} }
} }
tSimpleHashCleanup(suidHash); tSimpleHashCleanup(suidHash);
pMeta->changed = true;
} }
static int32_t metaFilterTableByHash(SMeta *pMeta, SArray *uidList) { static int32_t metaFilterTableByHash(SMeta *pMeta, SArray *uidList) {
@ -1970,6 +1979,7 @@ _err:
} }
int metaAlterTable(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq, STableMetaRsp *pMetaRsp) { int metaAlterTable(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq, STableMetaRsp *pMetaRsp) {
pMeta->changed = true;
switch (pReq->action) { switch (pReq->action) {
case TSDB_ALTER_TABLE_ADD_COLUMN: case TSDB_ALTER_TABLE_ADD_COLUMN:
case TSDB_ALTER_TABLE_DROP_COLUMN: case TSDB_ALTER_TABLE_DROP_COLUMN:

View File

@ -13,9 +13,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "meta.h"
#include "sync.h"
#include "vnd.h" #include "vnd.h"
#include "vnodeInt.h" #include "vnodeInt.h"
#include "sync.h"
extern int32_t tsdbPreCommit(STsdb *pTsdb); extern int32_t tsdbPreCommit(STsdb *pTsdb);
extern int32_t tsdbCommitBegin(STsdb *pTsdb, SCommitInfo *pInfo); extern int32_t tsdbCommitBegin(STsdb *pTsdb, SCommitInfo *pInfo);
@ -155,7 +156,8 @@ int vnodeShouldCommit(SVnode *pVnode, bool atExit) {
taosThreadMutexLock(&pVnode->mutex); taosThreadMutexLock(&pVnode->mutex);
if (pVnode->inUse && diskAvail) { if (pVnode->inUse && diskAvail) {
needCommit = (pVnode->inUse->size > pVnode->inUse->node.size) || (pVnode->inUse->size > 0 && atExit); needCommit = (pVnode->inUse->size > pVnode->inUse->node.size) ||
(atExit && (pVnode->inUse->size > 0 || pVnode->pMeta->changed));
} }
taosThreadMutexUnlock(&pVnode->mutex); taosThreadMutexUnlock(&pVnode->mutex);
return needCommit; return needCommit;