From ae509e874e9a009f37b24477b1344fb91f83b9f8 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 11 May 2022 14:20:14 +0000 Subject: [PATCH] fix: concurrent r/w meta --- source/dnode/vnode/src/meta/metaQuery.c | 4 ++++ source/dnode/vnode/src/meta/metaTable.c | 21 ++++++++++++++------- source/dnode/vnode/src/tsdb/tsdbRead.c | 2 ++ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index 39c3a6c42d..1f5d6c60e4 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -19,9 +19,13 @@ void metaReaderInit(SMetaReader *pReader, SMeta *pMeta, int32_t flags) { memset(pReader, 0, sizeof(*pReader)); pReader->flags = flags; pReader->pMeta = pMeta; + metaRLock(pMeta); } void metaReaderClear(SMetaReader *pReader) { + if (pReader->pMeta) { + metaULock(pReader->pMeta); + } tDecoderClear(&pReader->coder); tdbFree(pReader->pBuf); } diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 7663047429..20248f39fb 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -439,29 +439,36 @@ _exit: } static int metaHandleEntry(SMeta *pMeta, const SMetaEntry *pME) { + metaWLock(pMeta); + // save to table.db - if (metaSaveToTbDb(pMeta, pME) < 0) return -1; + if (metaSaveToTbDb(pMeta, pME) < 0) goto _err; // update uid.idx - if (metaUpdateUidIdx(pMeta, pME) < 0) return -1; + if (metaUpdateUidIdx(pMeta, pME) < 0) goto _err; // update name.idx - if (metaUpdateNameIdx(pMeta, pME) < 0) return -1; + if (metaUpdateNameIdx(pMeta, pME) < 0) goto _err; if (pME->type == TSDB_CHILD_TABLE) { // update ctb.idx - if (metaUpdateCtbIdx(pMeta, pME) < 0) return -1; + if (metaUpdateCtbIdx(pMeta, pME) < 0) goto _err; // update tag.idx - if (metaUpdateTagIdx(pMeta, pME) < 0) return -1; + if (metaUpdateTagIdx(pMeta, pME) < 0) goto _err; } else { // update schema.db - if (metaSaveToSkmDb(pMeta, pME) < 0) return -1; + if (metaSaveToSkmDb(pMeta, pME) < 0) goto _err; } if (pME->type != TSDB_SUPER_TABLE) { - if (metaUpdateTtlIdx(pMeta, pME) < 0) return -1; + if (metaUpdateTtlIdx(pMeta, pME) < 0) goto _err; } + metaULock(pMeta); return 0; + +_err: + metaULock(pMeta); + return -1; } \ No newline at end of file diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index 4638066935..2511e3a570 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -3870,6 +3870,7 @@ int32_t tsdbQuerySTableByTagCond(void* pMeta, uint64_t uid, TSKEY skey, const ch if (metaGetTableEntryByUid(&mr, uid) < 0) { tsdbError("%p failed to get stable, uid:%" PRIu64 ", TID:0x%" PRIx64 " QID:0x%" PRIx64, pMeta, uid, taskId, reqId); + metaReaderClear(&mr); terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST; goto _error; } else { @@ -3880,6 +3881,7 @@ int32_t tsdbQuerySTableByTagCond(void* pMeta, uint64_t uid, TSKEY skey, const ch tsdbError("%p query normal tag not allowed, uid:%" PRIu64 ", TID:0x%" PRIx64 " QID:0x%" PRIx64, pMeta, uid, taskId, reqId); terrno = TSDB_CODE_OPS_NOT_SUPPORT; // basically, this error is caused by invalid sql issued by client + metaReaderClear(&mr); goto _error; } -- GitLab