Merge pull request #26836 from taosdata/enh/TD-30987-25

enh: refactor return code
This commit is contained in:
Hongze Cheng 2024-07-29 15:52:10 +08:00 committed by GitHub
commit b5a3a56811
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 101 additions and 103 deletions

View File

@ -48,7 +48,7 @@ int32_t tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyC
int8_t rollback);
int32_t tdbTbClose(TTB *pTb);
bool tdbTbExist(const char *tbname, TDB *pEnv);
int tdbTbDropByName(const char *tbname, TDB *pEnv, TXN* pTxn);
int tdbTbDropByName(const char *tbname, TDB *pEnv, TXN *pTxn);
int32_t tdbTbDrop(TTB *pTb);
int32_t tdbTbInsert(TTB *pTb, const void *pKey, int keyLen, const void *pVal, int valLen, TXN *pTxn);
int32_t tdbTbDelete(TTB *pTb, const void *pKey, int kLen, TXN *pTxn);
@ -80,10 +80,10 @@ int32_t tdbTbcUpsert(TBC *pTbc, const void *pKey, int nKey, const void *pData, i
int32_t tdbTxnOpen(TXN *pTxn, int64_t txnid, void *(*xMalloc)(void *, size_t), void (*xFree)(void *, void *),
void *xArg, int flags);
int32_t tdbTxnCloseImpl(TXN *pTxn);
#define tdbTxnClose(pTxn) \
do { \
tdbTxnCloseImpl(pTxn); \
(pTxn) = NULL; \
#define tdbTxnClose(pTxn) \
do { \
(void)tdbTxnCloseImpl(pTxn); \
(pTxn) = NULL; \
} while (0)
// other

View File

@ -122,7 +122,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, char const *tbname, SPg
zArg.pBt = pBt;
ret = tdbPagerFetchPage(pPager, &pgno, &pPage, tdbBtreeInitPage, &zArg, txn);
if (ret < 0) {
tdbAbort(pEnv, txn);
(void)tdbAbort(pEnv, txn);
tdbOsFree(pBt);
return ret;
}
@ -130,7 +130,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, char const *tbname, SPg
ret = tdbPagerWrite(pPager, pPage);
if (ret < 0) {
tdbError("failed to write page since %s", terrstr());
tdbAbort(pEnv, txn);
(void)tdbAbort(pEnv, txn);
tdbOsFree(pBt);
return ret;
}
@ -143,7 +143,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, char const *tbname, SPg
ret = tdbTbInsert(pPager->pEnv->pMainDb, tbname, strlen(tbname) + 1, &pBt->info, sizeof(pBt->info), txn);
if (ret < 0) {
tdbAbort(pEnv, txn);
(void)tdbAbort(pEnv, txn);
tdbOsFree(pBt);
return ret;
}
@ -194,14 +194,14 @@ int tdbBtreeInsert(SBTree *pBt, const void *pKey, int kLen, const void *pVal, in
int idx;
int c;
tdbBtcOpen(&btc, pBt, pTxn);
(void)tdbBtcOpen(&btc, pBt, pTxn);
tdbTrace("tdb insert, btc: %p, pTxn: %p", &btc, pTxn);
// move to the position to insert
ret = tdbBtcMoveTo(&btc, pKey, kLen, &c);
if (ret < 0) {
tdbBtcClose(&btc);
(void)tdbBtcClose(&btc);
tdbError("tdb/btree-insert: btc move to failed with ret: %d.", ret);
return ret;
}
@ -213,7 +213,7 @@ int tdbBtreeInsert(SBTree *pBt, const void *pKey, int kLen, const void *pVal, in
btc.idx++;
} else if (c == 0) {
// dup key not allowed with insert
tdbBtcClose(&btc);
(void)tdbBtcClose(&btc);
tdbError("tdb/btree-insert: dup key. pKey: %p, kLen: %d, btc: %p, pTxn: %p", pKey, kLen, &btc, pTxn);
return TSDB_CODE_DUP_KEY;
}
@ -221,12 +221,12 @@ int tdbBtreeInsert(SBTree *pBt, const void *pKey, int kLen, const void *pVal, in
ret = tdbBtcUpsert(&btc, pKey, kLen, pVal, vLen, 1);
if (ret < 0) {
tdbBtcClose(&btc);
(void)tdbBtcClose(&btc);
tdbError("tdb/btree-insert: btc upsert failed with ret: %d.", ret);
return ret;
}
tdbBtcClose(&btc);
(void)tdbBtcClose(&btc);
return 0;
}
@ -246,20 +246,20 @@ int tdbBtreeDelete(SBTree *pBt, const void *pKey, int kLen, TXN *pTxn) {
// move the cursor
ret = tdbBtcMoveTo(&btc, pKey, kLen, &c);
if (ret < 0) {
tdbBtcClose(&btc);
(void)tdbBtcClose(&btc);
tdbError("tdb/btree-delete: btc move to failed with ret: %d.", ret);
return ret;
}
if (btc.idx < 0 || c != 0) {
tdbBtcClose(&btc);
(void)tdbBtcClose(&btc);
return TSDB_CODE_NOT_FOUND;
}
// delete the key
ret = tdbBtcDelete(&btc);
if (ret < 0) {
tdbBtcClose(&btc);
(void)tdbBtcClose(&btc);
return ret;
}
/*
@ -274,7 +274,7 @@ int tdbBtreeDelete(SBTree *pBt, const void *pKey, int kLen, TXN *pTxn) {
btc.coder.ofps = NULL;
}
*/
tdbBtcClose(&btc);
(void)tdbBtcClose(&btc);
return 0;
}
@ -343,20 +343,20 @@ int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkL
ret = tdbBtcMoveTo(&btc, pKey, kLen, &cret);
if (ret < 0) {
tdbBtcClose(&btc);
(void)tdbBtcClose(&btc);
tdbError("tdb/btree-pget: btc move to failed with ret: %d.", ret);
return ret;
}
if (btc.idx < 0 || cret) {
tdbBtcClose(&btc);
(void)tdbBtcClose(&btc);
return TSDB_CODE_NOT_FOUND;
}
pCell = tdbPageGetCell(btc.pPage, btc.idx);
ret = tdbBtreeDecodeCell(btc.pPage, pCell, &cd, btc.pTxn, pBt);
if (ret < 0) {
tdbBtcClose(&btc);
(void)tdbBtcClose(&btc);
tdbError("tdb/btree-pget: decode cell failed with ret: %d.", ret);
return ret;
}
@ -364,7 +364,7 @@ int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkL
if (ppKey) {
pTKey = tdbRealloc(*ppKey, cd.kLen);
if (pTKey == NULL) {
tdbBtcClose(&btc);
(void)tdbBtcClose(&btc);
tdbError("tdb/btree-pget: realloc pTKey failed.");
return terrno;
}
@ -376,7 +376,7 @@ int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkL
if (ppVal) {
pTVal = tdbRealloc(*ppVal, cd.vLen);
if (pTVal == NULL) {
tdbBtcClose(&btc);
(void)tdbBtcClose(&btc);
tdbError("tdb/btree-pget: realloc pTVal failed.");
return terrno;
}
@ -397,7 +397,7 @@ int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkL
tdbTrace("tdb pget end, btc decoder: %p/0x%x, local decoder:%p", &btc.coder, btc.coder.freeKV, &cd);
tdbBtcClose(&btc);
(void)tdbBtcClose(&btc);
return 0;
}
@ -512,7 +512,7 @@ static int tdbBtreeBalanceDeeper(SBTree *pBt, SPage *pRoot, SPage **ppChild, TXN
}
// Copy the root page content to the child page
tdbPageCopy(pRoot, pChild, 0);
(void)tdbPageCopy(pRoot, pChild, 0);
// Reinitialize the root page
zArg.flags = TDB_BTREE_ROOT;
@ -602,7 +602,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
if (i < nOlds - 1) {
((SPgno *)pDivCell[i])[0] = ((SIntHdr *)pOlds[i]->pData)->pgno;
((SIntHdr *)pOlds[i]->pData)->pgno = 0;
tdbPageInsertCell(pOlds[i], TDB_PAGE_TOTAL_CELLS(pOlds[i]), pDivCell[i], szDivCell[i], 1);
(void)tdbPageInsertCell(pOlds[i], TDB_PAGE_TOTAL_CELLS(pOlds[i]), pDivCell[i], szDivCell[i], 1);
}
}
rPgno = ((SIntHdr *)pOlds[nOlds - 1]->pData)->pgno;
@ -626,14 +626,14 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
}
}
tdbPageDropCell(pParent, sIdx, pTxn, pBt);
(void)tdbPageDropCell(pParent, sIdx, pTxn, pBt);
if (!childNotLeaf) {
SArray *ofps = pParent->pPager->ofps;
if (ofps) {
for (int i = 0; i < TARRAY_SIZE(ofps); ++i) {
SPage *ofp = *(SPage **)taosArrayGet(ofps, i);
tdbPagerInsertFreePage(pParent->pPager, ofp, pTxn);
(void)tdbPagerInsertFreePage(pParent->pPager, ofp, pTxn);
}
if (destroyOfps) {
@ -791,9 +791,9 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
iarg.pBt = pBt;
iarg.flags = TDB_BTREE_PAGE_GET_FLAGS(pOlds[0]);
for (int i = 0; i < nOlds; i++) {
tdbPageCreate(pOlds[0]->pageSize, &pOldsCopy[i], tdbDefaultMalloc, NULL);
tdbBtreeInitPage(pOldsCopy[i], &iarg, 0);
tdbPageCopy(pOlds[i], pOldsCopy[i], 0);
(void)tdbPageCreate(pOlds[0]->pageSize, &pOldsCopy[i], tdbDefaultMalloc, NULL);
(void)tdbBtreeInitPage(pOldsCopy[i], &iarg, 0);
(void)tdbPageCopy(pOlds[i], pOldsCopy[i], 0);
pOlds[i]->nOverflow = 0;
}
@ -818,7 +818,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
}
if (nNewCells < infoNews[iNew].cnt) {
tdbPageInsertCell(pNews[iNew], nNewCells, pCell, szCell, 0);
(void)tdbPageInsertCell(pNews[iNew], nNewCells, pCell, szCell, 0);
nNewCells++;
// insert parent page
@ -835,9 +835,9 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
int szNewCell;
SPgno pgno;
pgno = TDB_PAGE_PGNO(pNews[iNew]);
tdbBtreeEncodeCell(pParent, cd.pKey, cd.kLen, (void *)&pgno, sizeof(SPgno), pNewCell, &szNewCell, pTxn,
pBt);
tdbPageInsertCell(pParent, sIdx++, pNewCell, szNewCell, 0);
(void)tdbBtreeEncodeCell(pParent, cd.pKey, cd.kLen, (void *)&pgno, sizeof(SPgno), pNewCell, &szNewCell,
pTxn, pBt);
(void)tdbPageInsertCell(pParent, sIdx++, pNewCell, szNewCell, 0);
tdbOsFree(pNewCell);
if (TDB_CELLDECODER_FREE_VAL(&cd)) {
@ -869,7 +869,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
return TSDB_CODE_FAILED;
}
((SPgno *)pCell)[0] = TDB_PAGE_PGNO(pNews[iNew]);
tdbPageInsertCell(pParent, sIdx++, pCell, szCell, 0);
(void)tdbPageInsertCell(pParent, sIdx++, pCell, szCell, 0);
// move to next new page
iNew++;
@ -892,12 +892,12 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
pIntHdr->pgno = TDB_PAGE_PGNO(pNews[nNews - 1]);
} else {
((SPgno *)pDivCell[nOlds - 1])[0] = TDB_PAGE_PGNO(pNews[nNews - 1]);
tdbPageInsertCell(pParent, sIdx, pDivCell[nOlds - 1], szDivCell[nOlds - 1], 0);
(void)tdbPageInsertCell(pParent, sIdx, pDivCell[nOlds - 1], szDivCell[nOlds - 1], 0);
}
}
for (int i = 0; i < nOlds; i++) {
tdbPageDestroy(pOldsCopy[i], tdbDefaultFree, NULL);
(void)tdbPageDestroy(pOldsCopy[i], tdbDefaultFree, NULL);
}
}
@ -905,13 +905,13 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
i8 flags = TDB_BTREE_ROOT | TDB_BTREE_PAGE_IS_LEAF(pNews[0]);
// copy content to the parent page
tdbBtreeInitPage(pParent, &(SBtreeInitPageArg){.flags = flags, .pBt = pBt}, 0);
tdbPageCopy(pNews[0], pParent, 1);
(void)tdbPageCopy(pNews[0], pParent, 1);
if (!TDB_BTREE_PAGE_IS_LEAF(pNews[0])) {
((SIntHdr *)(pParent->pData))->pgno = ((SIntHdr *)(pNews[0]->pData))->pgno;
}
tdbPagerInsertFreePage(pBt->pPager, pNews[0], pTxn);
(void)tdbPagerInsertFreePage(pBt->pPager, pNews[0], pTxn);
}
for (int i = 0; i < 3; i++) {
@ -922,7 +922,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
for (pageIdx = 0; pageIdx < nOlds; ++pageIdx) {
if (pageIdx >= nNews) {
tdbPagerInsertFreePage(pBt->pPager, pOlds[pageIdx], pTxn);
(void)tdbPagerInsertFreePage(pBt->pPager, pOlds[pageIdx], pTxn);
}
tdbPagerReturnPage(pBt->pPager, pOlds[pageIdx], pTxn);
}
@ -1986,7 +1986,7 @@ int tdbBtcMoveToNext(SBTC *pBtc) {
return 0;
}
tdbBtcMoveUpward(pBtc);
(void)tdbBtcMoveUpward(pBtc);
pBtc->idx++;
if (TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)) {
@ -2029,7 +2029,7 @@ int tdbBtcMoveToPrev(SBTC *pBtc) {
return 0;
}
tdbBtcMoveUpward(pBtc);
(void)tdbBtcMoveUpward(pBtc);
pBtc->idx--;
if (pBtc->idx >= 0) {
break;
@ -2040,7 +2040,7 @@ int tdbBtcMoveToPrev(SBTC *pBtc) {
for (;;) {
if (TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)) break;
tdbBtcMoveDownward(pBtc);
(void)tdbBtcMoveDownward(pBtc);
if (TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)) {
pBtc->idx = TDB_PAGE_TOTAL_CELLS(pBtc->pPage) - 1;
} else {
@ -2119,7 +2119,7 @@ int tdbBtcGet(SBTC *pBtc, const void **ppKey, int *kLen, const void **ppVal, int
}
pCell = tdbPageGetCell(pBtc->pPage, pBtc->idx);
tdbBtreeDecodeCell(pBtc->pPage, pCell, &pBtc->coder, pBtc->pTxn, pBtc->pBt);
(void)tdbBtreeDecodeCell(pBtc->pPage, pCell, &pBtc->coder, pBtc->pTxn, pBtc->pBt);
if (ppKey) {
*ppKey = (void *)pBtc->coder.pKey;
@ -2165,13 +2165,13 @@ int tdbBtcDelete(SBTC *pBtc) {
destroyOfps = true;
}
tdbPageDropCell(pBtc->pPage, idx, pBtc->pTxn, pBtc->pBt);
(void)tdbPageDropCell(pBtc->pPage, idx, pBtc->pTxn, pBtc->pBt);
SArray *ofps = pBtc->pPage->pPager->ofps;
if (ofps) {
for (int i = 0; i < TARRAY_SIZE(ofps); ++i) {
SPage *ofp = *(SPage **)taosArrayGet(ofps, i);
tdbPagerInsertFreePage(pBtc->pPage->pPager, ofp, pBtc->pTxn);
(void)tdbPagerInsertFreePage(pBtc->pPage->pPager, ofp, pBtc->pTxn);
}
if (destroyOfps) {
@ -2184,7 +2184,7 @@ int tdbBtcDelete(SBTC *pBtc) {
if (idx == nCells - 1) {
if (idx) {
pBtc->idx--;
tdbBtcGet(pBtc, &pKey, &nKey, NULL, NULL);
(void)tdbBtcGet(pBtc, &pKey, &nKey, NULL, NULL);
// loop to update the interial page
pgno = TDB_PAGE_PGNO(pBtc->pPage);
@ -2202,7 +2202,7 @@ int tdbBtcDelete(SBTC *pBtc) {
// update the cell with new key
pCell = tdbOsMalloc(nKey + 9);
tdbBtreeEncodeCell(pPage, pKey, nKey, &pgno, sizeof(pgno), pCell, &szCell, pBtc->pTxn, pBtc->pBt);
(void)tdbBtreeEncodeCell(pPage, pKey, nKey, &pgno, sizeof(pgno), pCell, &szCell, pBtc->pTxn, pBtc->pBt);
ret = tdbPageUpdateCell(pPage, idx, pCell, szCell, pBtc->pTxn, pBtc->pBt);
if (ret < 0) {
@ -2429,7 +2429,7 @@ int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) {
// compare first cell
pBtc->idx = lidx;
tdbBtcGet(pBtc, &pTKey, &tkLen, NULL, NULL);
(void)tdbBtcGet(pBtc, &pTKey, &tkLen, NULL, NULL);
c = pBt->kcmpr(pKey, kLen, pTKey, tkLen);
if (c <= 0) {
ridx = lidx - 1;
@ -2439,7 +2439,7 @@ int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) {
// compare last cell
if (lidx <= ridx) {
pBtc->idx = ridx;
tdbBtcGet(pBtc, &pTKey, &tkLen, NULL, NULL);
(void)tdbBtcGet(pBtc, &pTKey, &tkLen, NULL, NULL);
c = pBt->kcmpr(pKey, kLen, pTKey, tkLen);
if (c >= 0) {
lidx = ridx + 1;
@ -2454,7 +2454,7 @@ int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) {
if (lidx > ridx) break;
pBtc->idx = (lidx + ridx) >> 1;
tdbBtcGet(pBtc, &pTKey, &tkLen, NULL, NULL);
(void)tdbBtcGet(pBtc, &pTKey, &tkLen, NULL, NULL);
c = pBt->kcmpr(pKey, kLen, pTKey, tkLen);
if (c < 0) {
// pKey < cd.pKey
@ -2476,7 +2476,7 @@ int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) {
if (c > 0) {
pBtc->idx += 1;
}
tdbBtcMoveDownward(pBtc);
(void)tdbBtcMoveDownward(pBtc);
}
}

View File

@ -101,10 +101,10 @@ int tdbClose(TDB *pDb) {
for (pPager = pDb->pgrList; pPager; pPager = pDb->pgrList) {
pDb->pgrList = pPager->pNext;
tdbPagerClose(pPager);
(void)tdbPagerClose(pPager);
}
tdbPCacheClose(pDb->pCache);
(void)tdbPCacheClose(pDb->pCache);
tdbOsFree(pDb->pgrHash);
tdbOsFree(pDb);
}

View File

@ -44,10 +44,10 @@ static void tdbPCacheAddPageToHash(SPCache *pCache, SPage *pPage);
static void tdbPCacheUnpinPage(SPCache *pCache, SPage *pPage);
static int tdbPCacheCloseImpl(SPCache *pCache);
static void tdbPCacheInitLock(SPCache *pCache) { tdbMutexInit(&(pCache->mutex), NULL); }
static void tdbPCacheDestroyLock(SPCache *pCache) { tdbMutexDestroy(&(pCache->mutex)); }
static void tdbPCacheLock(SPCache *pCache) { tdbMutexLock(&(pCache->mutex)); }
static void tdbPCacheUnlock(SPCache *pCache) { tdbMutexUnlock(&(pCache->mutex)); }
static void tdbPCacheInitLock(SPCache *pCache) { (void)tdbMutexInit(&(pCache->mutex), NULL); }
static void tdbPCacheDestroyLock(SPCache *pCache) { (void)tdbMutexDestroy(&(pCache->mutex)); }
static void tdbPCacheLock(SPCache *pCache) { (void)tdbMutexLock(&(pCache->mutex)); }
static void tdbPCacheUnlock(SPCache *pCache) { (void)tdbMutexUnlock(&(pCache->mutex)); }
int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) {
int32_t code = 0;
@ -74,7 +74,7 @@ int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) {
_exit:
if (code) {
tdbError("%s failed at %s:%d since %s", __func__, __FILE__, __LINE__, tstrerror(code));
tdbPCacheClose(pCache);
(void)tdbPCacheClose(pCache);
*ppCache = NULL;
} else {
*ppCache = pCache;
@ -84,7 +84,7 @@ _exit:
int tdbPCacheClose(SPCache *pCache) {
if (pCache) {
tdbPCacheCloseImpl(pCache);
(void)tdbPCacheCloseImpl(pCache);
tdbOsFree(pCache->aPage);
tdbOsFree(pCache);
}
@ -149,7 +149,7 @@ static int tdbPCacheAlterImpl(SPCache *pCache, int32_t nPage) {
SPage *pPage = *ppPage;
*ppPage = pPage->pFreeNext;
pCache->aPage[pPage->id] = NULL;
tdbPageDestroy(pPage, tdbDefaultFree, NULL);
(void)tdbPageDestroy(pPage, tdbDefaultFree, NULL);
pCache->nFree--;
} else {
ppPage = &(*ppPage)->pFreeNext;
@ -209,7 +209,7 @@ static void tdbPCacheFreePage(SPCache *pCache, SPage *pPage) {
tdbTrace("pcache/free2 page: %p/%d, pgno:%d, ", pPage, pPage->id, TDB_PAGE_PGNO(pPage));
tdbPCacheRemovePageFromHash(pCache, pPage);
tdbPageDestroy(pPage, tdbDefaultFree, NULL);
(void)tdbPageDestroy(pPage, tdbDefaultFree, NULL);
}
}
@ -268,7 +268,7 @@ void tdbPCacheRelease(SPCache *pCache, SPage *pPage, TXN *pTxn) {
tdbPCacheRemovePageFromHash(pCache, pPage);
}
tdbPageDestroy(pPage, pTxn->xFree, pTxn->xArg);
(void)tdbPageDestroy(pPage, pTxn->xFree, pTxn->xArg);
}
// }
}
@ -349,7 +349,7 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, TXN *pTxn)
for (int nLoops = 0;;) {
if (pPageH->pPager) break;
if (++nLoops > 1000) {
sched_yield();
(void)sched_yield();
nLoops = 0;
}
}
@ -432,7 +432,7 @@ static void tdbPCacheUnpinPage(SPCache *pCache, SPage *pPage) {
tdbTrace("pcache destroy page: %p/%d/%d", pPage, TDB_PAGE_PGNO(pPage), pPage->id);
tdbPCacheRemovePageFromHash(pCache, pPage);
tdbPageDestroy(pPage, tdbDefaultFree, NULL);
(void)tdbPageDestroy(pPage, tdbDefaultFree, NULL);
}
}
@ -518,14 +518,14 @@ static int tdbPCacheCloseImpl(SPCache *pCache) {
// free free page
for (SPage *pPage = pCache->pFree; pPage;) {
SPage *pPageT = pPage->pFreeNext;
tdbPageDestroy(pPage, tdbDefaultFree, NULL);
(void)tdbPageDestroy(pPage, tdbDefaultFree, NULL);
pPage = pPageT;
}
for (int32_t iBucket = 0; iBucket < pCache->nHash; iBucket++) {
for (SPage *pPage = pCache->pgHash[iBucket]; pPage;) {
SPage *pPageT = pPage->pHashNext;
tdbPageDestroy(pPage, tdbDefaultFree, NULL);
(void)tdbPageDestroy(pPage, tdbDefaultFree, NULL);
pPage = pPageT;
}
}

View File

@ -64,7 +64,7 @@ int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t)
memset(ptr, 0, size);
pPage = (SPage *)(ptr + pageSize);
TDB_INIT_PAGE_LOCK(pPage);
(void)TDB_INIT_PAGE_LOCK(pPage);
pPage->pageSize = pageSize;
pPage->pData = ptr;
if (pageSize < 65536) {
@ -194,7 +194,7 @@ int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl
iOvfl++;
} else {
// page must has enough space to hold the cell locally
tdbPageAllocate(pPage, szCell, &pNewCell);
(void)tdbPageAllocate(pPage, szCell, &pNewCell);
memcpy(pNewCell, pCell, szCell);
@ -220,7 +220,7 @@ int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl
}
int tdbPageUpdateCell(SPage *pPage, int idx, SCell *pCell, int szCell, TXN *pTxn, SBTree *pBt) {
tdbPageDropCell(pPage, idx, pTxn, pBt);
(void)tdbPageDropCell(pPage, idx, pTxn, pBt);
return tdbPageInsertCell(pPage, idx, pCell, szCell, 0);
}
@ -259,7 +259,7 @@ int tdbPageDropCell(SPage *pPage, int idx, TXN *pTxn, SBTree *pBt) {
lidx = idx - iOvfl;
pCell = TDB_PAGE_CELL_AT(pPage, lidx);
szCell = (*pPage->xCellSize)(pPage, pCell, 1, pTxn, pBt);
tdbPageFree(pPage, lidx, pCell, szCell);
(void)tdbPageFree(pPage, lidx, pCell, szCell);
TDB_PAGE_NCELLS_SET(pPage, nCells - 1);
for (; iOvfl < pPage->nOverflow; iOvfl++) {

View File

@ -107,7 +107,7 @@ static int hashset_add(hashset_t set, void *item) {
set->nitems = 0;
for (size_t i = 0; i < old_capacity; ++i) {
hashset_add_member(set, (void *)old_items[i]);
(void)hashset_add_member(set, (void *)old_items[i]);
}
tdbOsFree(old_items);
}
@ -223,7 +223,7 @@ int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager) {
int tdbPagerClose(SPager *pPager) {
if (pPager) {
tdbOsClose(pPager->fd);
(void)tdbOsClose(pPager->fd);
tdbOsFree(pPager);
}
return 0;
@ -236,14 +236,14 @@ int tdbPagerWrite(SPager *pPager, SPage *pPage) {
if (pPage->isDirty) return 0;
// ref page one more time so the page will not be release
tdbRefPage(pPage);
(void)tdbRefPage(pPage);
tdbTrace("pager/mdirty page %p/%d/%d", pPage, TDB_PAGE_PGNO(pPage), pPage->id);
// Set page as dirty
pPage->isDirty = 1;
tdbTrace("tdb/pager-write: put page: %p %d to dirty tree: %p", pPage, TDB_PAGE_PGNO(pPage), &pPager->rbt);
tRBTreePut(&pPager->rbt, (SRBTreeNode *)pPage);
(void)tRBTreePut(&pPager->rbt, (SRBTreeNode *)pPage);
// Write page to journal if neccessary
if (TDB_PAGE_PGNO(pPage) <= pPager->dbOrigSize &&
@ -256,7 +256,7 @@ int tdbPagerWrite(SPager *pPager, SPage *pPage) {
}
if (pPager->pActiveTxn->jPageSet) {
hashset_add(pPager->pActiveTxn->jPageSet, (void *)((long)TDB_PAGE_PGNO(pPage)));
(void)hashset_add(pPager->pActiveTxn->jPageSet, (void *)((long)TDB_PAGE_PGNO(pPage)));
}
}
@ -352,7 +352,7 @@ int tdbPagerCommit(SPager *pPager, TXN *pTxn) {
tRBTreeDrop(&pPager->rbt, (SRBTreeNode *)pPage);
if (pTxn->jPageSet) {
hashset_remove(pTxn->jPageSet, (void *)((long)TDB_PAGE_PGNO(pPage)));
(void)hashset_remove(pTxn->jPageSet, (void *)((long)TDB_PAGE_PGNO(pPage)));
}
tdbTrace("tdb/pager-commit: remove page: %p %d from dirty tree: %p", pPage, TDB_PAGE_PGNO(pPage), &pPager->rbt);
@ -590,7 +590,7 @@ int tdbPagerAbort(SPager *pPager, TXN *pTxn) {
pPage->isDirty = 0;
tRBTreeDrop(&pPager->rbt, (SRBTreeNode *)pPage);
hashset_remove(pTxn->jPageSet, (void *)((long)TDB_PAGE_PGNO(pPage)));
(void)hashset_remove(pTxn->jPageSet, (void *)((long)TDB_PAGE_PGNO(pPage)));
tdbPCacheMarkFree(pPager->pCache, pPage);
tdbPCacheRelease(pPager->pCache, pPage, pTxn);
}
@ -712,7 +712,7 @@ int tdbPagerFetchPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPa
memcpy(&pgid, pPager->fid, TDB_FILE_ID_LEN);
pgid.pgno = pgno;
while ((pPage = tdbPCacheFetch(pPager->pCache, &pgid, pTxn)) == NULL) {
tdbPagerFlushPage(pPager, pTxn);
(void)tdbPagerFlushPage(pPager, pTxn);
}
tdbTrace("tdbttl fetch pager:%p", pPage->pPager);
@ -815,7 +815,7 @@ static int tdbPagerRemoveFreePage(SPager *pPager, SPgno *pPgno, TXN *pTxn) {
code = tdbTbcMoveToFirst(pCur);
if (code) {
tdbError("tdb/remove-free-page: moveto first failed with ret: %d.", code);
tdbTbcClose(pCur);
(void)tdbTbcClose(pCur);
return 0;
}
@ -825,7 +825,7 @@ static int tdbPagerRemoveFreePage(SPager *pPager, SPgno *pPgno, TXN *pTxn) {
code = tdbTbcGet(pCur, (const void **)&pKey, &nKey, NULL, NULL);
if (code < 0) {
// tdbError("tdb/remove-free-page: tbc get failed with ret: %d.", code);
tdbTbcClose(pCur);
(void)tdbTbcClose(pCur);
return 0;
}
@ -836,10 +836,10 @@ static int tdbPagerRemoveFreePage(SPager *pPager, SPgno *pPgno, TXN *pTxn) {
code = tdbTbcDelete(pCur);
if (code < 0) {
tdbError("tdb/remove-free-page: tbc delete failed with ret: %d.", code);
tdbTbcClose(pCur);
(void)tdbTbcClose(pCur);
return 0;
}
tdbTbcClose(pCur);
(void)tdbTbcClose(pCur);
return 0;
}
@ -892,7 +892,7 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage
lcode = TDB_TRY_LOCK_PAGE(pPage);
if (lcode == P_LOCK_SUCC) {
if (TDB_PAGE_INITIALIZED(pPage)) {
TDB_UNLOCK_PAGE(pPage);
(void)TDB_UNLOCK_PAGE(pPage);
return 0;
}
@ -906,7 +906,7 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage
tdbTrace("tdb/pager:%p, pgno:%d, nRead:%" PRId64, pPager, pgno, nRead);
if (nRead < pPage->pageSize) {
tdbError("tdb/pager:%p, pgno:%d, nRead:%" PRId64 "pgSize:%" PRId32, pPager, pgno, nRead, pPage->pageSize);
TDB_UNLOCK_PAGE(pPage);
(void)TDB_UNLOCK_PAGE(pPage);
return TAOS_SYSTEM_ERROR(errno);
}
@ -953,7 +953,7 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage
if (ret < 0) {
tdbError("tdb/pager:%p, pgno:%d, nRead:%" PRId64 "pgSize:%" PRId32 " init page failed.", pPager, pgno, nRead,
pPage->pageSize);
TDB_UNLOCK_PAGE(pPage);
(void)TDB_UNLOCK_PAGE(pPage);
return ret;
}
@ -961,7 +961,7 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage
pPage->pPager = pPager;
TDB_UNLOCK_PAGE(pPage);
(void)TDB_UNLOCK_PAGE(pPage);
} else if (lcode == P_LOCK_BUSY) {
nLoops = 0;
for (;;) {
@ -1162,7 +1162,7 @@ int tdbPagerRestoreJournals(SPager *pPager) {
char *name = tdbDirEntryBaseName(tdbGetDirEntryName(pDirEntry));
if (strncmp(TDB_MAINDB_NAME "-journal", name, 16) == 0) {
int64_t txnId = -1;
sscanf(name, TDB_MAINDB_NAME "-journal.%" PRId64, &txnId);
(void)sscanf(name, TDB_MAINDB_NAME "-journal.%" PRId64, &txnId);
if (taosArrayPush(pTxnList, &txnId) == NULL) {
return TSDB_CODE_OUT_OF_MEMORY;
}
@ -1179,14 +1179,14 @@ int tdbPagerRestoreJournals(SPager *pPager) {
code = tdbPagerRestore(pPager, jname);
if (code) {
taosArrayDestroy(pTxnList);
tdbCloseDir(&pDir);
(void)tdbCloseDir(&pDir);
tdbError("failed to restore file due to %s. jFileName:%s", strerror(code), jname);
return code;
}
}
taosArrayDestroy(pTxnList);
tdbCloseDir(&pDir);
(void)tdbCloseDir(&pDir);
return 0;
}
@ -1209,7 +1209,7 @@ int tdbPagerRollback(SPager *pPager) {
jname[dirLen] = '/';
memcpy(jname + dirLen + 1, name, strlen(name));
if (tdbOsRemove(jname) < 0 && errno != ENOENT) {
tdbCloseDir(&pDir);
(void)tdbCloseDir(&pDir);
tdbError("failed to remove file due to %s. jFileName:%s", strerror(errno), name);
return terrno = TAOS_SYSTEM_ERROR(errno);
@ -1217,7 +1217,7 @@ int tdbPagerRollback(SPager *pPager) {
}
}
tdbCloseDir(&pDir);
(void)tdbCloseDir(&pDir);
return 0;
}

View File

@ -112,7 +112,7 @@ int tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprF
return ret;
}
} else {
tdbPagerRollback(pPager);
(void)tdbPagerRollback(pPager);
}
// pTb->pBt
@ -128,7 +128,7 @@ int tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprF
int tdbTbClose(TTB *pTb) {
if (pTb) {
tdbBtreeClose(pTb->pBt);
(void)tdbBtreeClose(pTb->pBt);
tdbOsFree(pTb);
}
return 0;
@ -202,7 +202,7 @@ int tdbTbInsert(TTB *pTb, const void *pKey, int keyLen, const void *pVal, int va
int tdbTbDelete(TTB *pTb, const void *pKey, int kLen, TXN *pTxn) { return tdbBtreeDelete(pTb->pBt, pKey, kLen, pTxn); }
int tdbTbUpsert(TTB *pTb, const void *pKey, int kLen, const void *pVal, int vLen, TXN *pTxn) {
tdbTbDelete(pTb, pKey, kLen, pTxn);
(void)tdbTbDelete(pTb, pKey, kLen, pTxn);
return tdbTbInsert(pTb, pKey, kLen, pVal, vLen, pTxn);
}
@ -224,7 +224,7 @@ int tdbTbcOpen(TTB *pTb, TBC **ppTbc, TXN *pTxn) {
return -1;
}
tdbBtcOpen(&pTbc->btc, pTb->pBt, pTxn);
(void)tdbBtcOpen(&pTbc->btc, pTb->pBt, pTxn);
*ppTbc = pTbc;
return 0;
@ -238,7 +238,7 @@ int32_t tdbTbTraversal(TTB *pTb, void *data,
return ret;
}
tdbTbcMoveToFirst(pCur);
(void)tdbTbcMoveToFirst(pCur);
void *pKey = NULL;
int kLen = 0;
@ -257,7 +257,7 @@ int32_t tdbTbTraversal(TTB *pTb, void *data,
}
tdbFree(pKey);
tdbFree(pValue);
tdbTbcClose(pCur);
(void)tdbTbcClose(pCur);
return 0;
}
@ -292,7 +292,7 @@ int tdbTbcUpsert(TBC *pTbc, const void *pKey, int nKey, const void *pData, int n
int tdbTbcClose(TBC *pTbc) {
if (pTbc) {
tdbBtcClose(&pTbc->btc);
(void)tdbBtcClose(&pTbc->btc);
tdbOsFree(pTbc);
}

View File

@ -13,6 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tdbInt.h"
#ifndef _TDB_UTIL_H_
#define _TDB_UTIL_H_
@ -56,8 +58,6 @@ static inline int tdbPutVarInt(u8 *p, int v) {
v >>= 7;
}
ASSERT(n < 6);
return n;
}
@ -79,8 +79,6 @@ static inline int tdbGetVarInt(const u8 *p, int *v) {
n++;
}
ASSERT(n < 6);
*v = tv;
return n;
}