Merge pull request #5076 from freemine/mac

taosIterateRef: shall NOT return removed node
This commit is contained in:
Shengliang Guan 2021-02-03 09:19:25 +08:00 committed by GitHub
commit bd12ad6a88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 92 additions and 75 deletions

View File

@ -280,6 +280,7 @@ void *taosIterateRef(int rsetId, int64_t rid) {
return NULL;
}
void *newP = NULL;
pSet = tsRefSetList + rsetId;
taosIncRsetCount(pSet);
if (pSet->state != TSDB_REF_STATE_ACTIVE) {
@ -289,52 +290,68 @@ void *taosIterateRef(int rsetId, int64_t rid) {
return NULL;
}
int hash = 0;
if (rid > 0) {
hash = rid % pSet->max;
taosLockList(pSet->lockedBy+hash);
pNode = pSet->nodeList[hash];
while (pNode) {
if (pNode->rid == rid) break;
pNode = pNode->next;
}
if (pNode == NULL) {
uError("rsetId:%d rid:%" PRId64 " not there, quit", rsetId, rid);
terrno = TSDB_CODE_REF_NOT_EXIST;
taosUnlockList(pSet->lockedBy+hash);
return NULL;
}
// rid is there
pNode = pNode->next;
if (pNode == NULL) {
taosUnlockList(pSet->lockedBy+hash);
hash++;
}
}
if (pNode == NULL) {
for (; hash < pSet->max; ++hash) {
do {
newP = NULL;
int hash = 0;
if (rid > 0) {
hash = rid % pSet->max;
taosLockList(pSet->lockedBy+hash);
pNode = pSet->nodeList[hash];
if (pNode) break;
taosUnlockList(pSet->lockedBy+hash);
while (pNode) {
if (pNode->rid == rid) break;
pNode = pNode->next;
}
if (pNode == NULL) {
uError("rsetId:%d rid:%" PRId64 " not there, quit", rsetId, rid);
terrno = TSDB_CODE_REF_NOT_EXIST;
taosUnlockList(pSet->lockedBy+hash);
taosDecRsetCount(pSet);
return NULL;
}
// rid is there
pNode = pNode->next;
// check first place
while (pNode) {
if (!pNode->removed) break;
pNode = pNode->next;
}
if (pNode == NULL) {
taosUnlockList(pSet->lockedBy+hash);
hash++;
}
}
}
void *newP = NULL;
if (pNode) {
pNode->count++; // acquire it
newP = pNode->p;
taosUnlockList(pSet->lockedBy+hash);
uTrace("rsetId:%d p:%p rid:%" PRId64 " is returned", rsetId, newP, rid);
} else {
uTrace("rsetId:%d the list is over", rsetId);
}
if (pNode == NULL) {
for (; hash < pSet->max; ++hash) {
taosLockList(pSet->lockedBy+hash);
pNode = pSet->nodeList[hash];
if (pNode) {
// check first place
while (pNode) {
if (!pNode->removed) break;
pNode = pNode->next;
}
if (pNode) break;
}
taosUnlockList(pSet->lockedBy+hash);
}
}
if (rid > 0) taosReleaseRef(rsetId, rid); // release the current one
if (pNode) {
pNode->count++; // acquire it
newP = pNode->p;
taosUnlockList(pSet->lockedBy+hash);
uTrace("rsetId:%d p:%p rid:%" PRId64 " is returned", rsetId, newP, rid);
} else {
uTrace("rsetId:%d the list is over", rsetId);
}
if (rid > 0) taosReleaseRef(rsetId, rid); // release the current one
if (pNode) rid = pNode->rid;
} while (newP && pNode->removed);
taosDecRsetCount(pSet);