diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h index ac9fabf05248fc4bf58f4e271ca161681f327eca..f229b3b12748d4f0bdab9205e2bbc3f3b6cfc946 100644 --- a/source/dnode/vnode/src/inc/vnodeInt.h +++ b/source/dnode/vnode/src/inc/vnodeInt.h @@ -142,7 +142,7 @@ typedef struct SMetaInfo { int64_t version; int32_t skmVer; } SMetaInfo; -int32_t metaGetInfo(SMeta* pMeta, int64_t uid, SMetaInfo* pInfo); +int32_t metaGetInfo(SMeta* pMeta, int64_t uid, SMetaInfo* pInfo, SMetaReader* pReader); typedef struct { int64_t uid; diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index 89eb0525ea378ae7e8535c7955b3e1606d2b6fab..f58b97eeb8362fa48f7b8be83c01401d3a0841c8 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -165,8 +165,9 @@ int metaGetTableEntryByUid(SMetaReader *pReader, tb_uid_t uid) { version1 = ((SUidIdxVal *)pReader->pBuf)[0].version; return metaGetTableEntryByVersion(pReader, version1, uid); */ + SMetaInfo info; - if (metaGetInfo(pMeta, uid, &info) == TSDB_CODE_NOT_FOUND) { + if (metaGetInfo(pMeta, uid, &info, pReader) == TSDB_CODE_NOT_FOUND) { terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST; return -1; } @@ -623,7 +624,7 @@ int32_t metaGetTbTSchemaEx(SMeta *pMeta, tb_uid_t suid, tb_uid_t uid, int32_t sv SSkmDbKey skmDbKey; if (sver <= 0) { SMetaInfo info; - if (metaGetInfo(pMeta, suid ? suid : uid, &info) == 0) { + if (metaGetInfo(pMeta, suid ? suid : uid, &info, NULL) == 0) { sver = info.skmVer; } else { TBC *pSkmDbC = NULL; @@ -1388,10 +1389,11 @@ int32_t metaGetTableTags(SMeta *pMeta, uint64_t suid, SArray *uidList, SHashObj int32_t metaCacheGet(SMeta *pMeta, int64_t uid, SMetaInfo *pInfo); -int32_t metaGetInfo(SMeta *pMeta, int64_t uid, SMetaInfo *pInfo) { +int32_t metaGetInfo(SMeta *pMeta, int64_t uid, SMetaInfo *pInfo, SMetaReader *pReader) { int32_t code = 0; void *pData = NULL; int nData = 0; + int lock = 0; metaRLock(pMeta); @@ -1416,11 +1418,22 @@ int32_t metaGetInfo(SMeta *pMeta, int64_t uid, SMetaInfo *pInfo) { pInfo->version = ((SUidIdxVal *)pData)->version; pInfo->skmVer = ((SUidIdxVal *)pData)->skmVer; + if (pReader != NULL) { + lock = !(pReader->flags & META_READER_NOLOCK); + if (lock) { + metaULock(pReader->pMeta); + // metaReaderReleaseLock(pReader); + } + } // upsert the cache metaWLock(pMeta); metaCacheUpsert(pMeta, pInfo); metaULock(pMeta); + if (lock) { + metaRLock(pReader->pMeta); + } + _exit: tdbFree(pData); return code; diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 6dadce80ca459ce371cf13311b643974e6f1cd07..bb0cfe183dbe540a14e0a2b0d8a4688e7d965262 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -207,7 +207,7 @@ int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { tb_uid_t uid = *(tb_uid_t *)pData; tdbFree(pData); SMetaInfo info; - metaGetInfo(pMeta, uid, &info); + metaGetInfo(pMeta, uid, &info, NULL); if (info.uid == info.suid) { return 0; } else { diff --git a/source/dnode/vnode/src/tsdb/tsdbMemTable.c b/source/dnode/vnode/src/tsdb/tsdbMemTable.c index c663e2b5268eec7aa0ad8313110fb403dd483979..ca3c283d05d290eeddebb6b6d1f7bab69eec1d70 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMemTable.c +++ b/source/dnode/vnode/src/tsdb/tsdbMemTable.c @@ -104,7 +104,7 @@ int32_t tsdbInsertTableData(STsdb *pTsdb, int64_t version, SSubmitMsgIter *pMsgI tb_uid_t uid = pMsgIter->uid; SMetaInfo info; - code = metaGetInfo(pTsdb->pVnode->pMeta, uid, &info); + code = metaGetInfo(pTsdb->pVnode->pMeta, uid, &info, NULL); if (code) { code = TSDB_CODE_TDB_TABLE_NOT_EXIST; goto _err; @@ -114,7 +114,7 @@ int32_t tsdbInsertTableData(STsdb *pTsdb, int64_t version, SSubmitMsgIter *pMsgI goto _err; } if (info.suid) { - metaGetInfo(pTsdb->pVnode->pMeta, info.suid, &info); + metaGetInfo(pTsdb->pVnode->pMeta, info.suid, &info, NULL); } if (pMsgIter->sversion != info.skmVer) { tsdbError("vgId:%d, req sver:%d, skmVer:%d suid:%" PRId64 " uid:%" PRId64, TD_VID(pTsdb->pVnode), @@ -153,7 +153,7 @@ int32_t tsdbDeleteTableData(STsdb *pTsdb, int64_t version, tb_uid_t suid, tb_uid // check if table exists SMetaInfo info; - code = metaGetInfo(pTsdb->pVnode->pMeta, uid, &info); + code = metaGetInfo(pTsdb->pVnode->pMeta, uid, &info, NULL); if (code) { code = TSDB_CODE_TDB_TABLE_NOT_EXIST; goto _err;