refactor(sync): add entries cache

This commit is contained in:
Minghao Li 2022-06-27 16:56:36 +08:00
parent 49ff32cda5
commit 5e7b7cb449
1 changed files with 4 additions and 0 deletions

View File

@ -308,6 +308,7 @@ int32_t raftCacheGetEntryP(struct SRaftEntryCache* pCache, SyncIndex index, SSyn
int32_t raftCacheDelEntry(struct SRaftEntryCache* pCache, SyncIndex index) { int32_t raftCacheDelEntry(struct SRaftEntryCache* pCache, SyncIndex index) {
taosThreadMutexLock(&(pCache->mutex)); taosThreadMutexLock(&(pCache->mutex));
taosHashRemove(pCache->pEntryHash, &index, sizeof(index)); taosHashRemove(pCache->pEntryHash, &index, sizeof(index));
--(pCache->currentCount);
taosThreadMutexUnlock(&(pCache->mutex)); taosThreadMutexUnlock(&(pCache->mutex));
return 0; return 0;
} }
@ -334,6 +335,8 @@ int32_t raftCacheGetAndDel(struct SRaftEntryCache* pCache, SyncIndex index, SSyn
} while (0); } while (0);
taosHashRemove(pCache->pEntryHash, &index, sizeof(index)); taosHashRemove(pCache->pEntryHash, &index, sizeof(index));
--(pCache->currentCount);
taosThreadMutexUnlock(&(pCache->mutex)); taosThreadMutexUnlock(&(pCache->mutex));
return 0; return 0;
} }
@ -346,6 +349,7 @@ int32_t raftCacheGetAndDel(struct SRaftEntryCache* pCache, SyncIndex index, SSyn
int32_t raftCacheClear(struct SRaftEntryCache* pCache) { int32_t raftCacheClear(struct SRaftEntryCache* pCache) {
taosThreadMutexLock(&(pCache->mutex)); taosThreadMutexLock(&(pCache->mutex));
taosHashClear(pCache->pEntryHash); taosHashClear(pCache->pEntryHash);
pCache->currentCount = 0;
taosThreadMutexUnlock(&(pCache->mutex)); taosThreadMutexUnlock(&(pCache->mutex));
return 0; return 0;
} }