From 38b036ff36a456444019b02e03dd7b0034a9a43e Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 11 Oct 2023 17:39:58 +0800 Subject: [PATCH] fix: possible race condition --- source/dnode/vnode/src/tsdb/tsdbFS2.c | 7 +------ source/dnode/vnode/src/tsdb/tsdbFS2.h | 14 +++++++------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbFS2.c b/source/dnode/vnode/src/tsdb/tsdbFS2.c index afc9b7db3a..bb57c05e77 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS2.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS2.c @@ -793,12 +793,7 @@ int32_t tsdbCloseFS(STFileSystem **fs) { return 0; } -int64_t tsdbFSAllocEid(STFileSystem *fs) { - taosThreadRwlockRdlock(&fs->tsdb->rwLock); - int64_t cid = ++fs->neid; - taosThreadRwlockUnlock(&fs->tsdb->rwLock); - return cid; -} +int64_t tsdbFSAllocEid(STFileSystem *fs) { return atomic_add_fetch_64(&fs->neid, 1); } int32_t tsdbFSEditBegin(STFileSystem *fs, const TFileOpArray *opArray, EFEditT etype) { int32_t code = 0; diff --git a/source/dnode/vnode/src/tsdb/tsdbFS2.h b/source/dnode/vnode/src/tsdb/tsdbFS2.h index b0f42a0c48..30dde7be31 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS2.h +++ b/source/dnode/vnode/src/tsdb/tsdbFS2.h @@ -89,13 +89,13 @@ struct STFSBgTask { /* Exposed Structs */ struct STFileSystem { - STsdb *tsdb; - tsem_t canEdit; - int32_t state; - int64_t neid; - EFEditT etype; - TFileSetArray fSetArr[1]; - TFileSetArray fSetArrTmp[1]; + STsdb *tsdb; + tsem_t canEdit; + int32_t state; + volatile int64_t neid; + EFEditT etype; + TFileSetArray fSetArr[1]; + TFileSetArray fSetArrTmp[1]; // background task queue TdThreadMutex mutex[1];