enh: clear tdb asserts

This commit is contained in:
Hongze Cheng 2024-08-21 15:28:25 +08:00
parent 456f0d888a
commit 0f82052392
8 changed files with 37 additions and 53 deletions

View File

@ -152,6 +152,7 @@ int32_t taosGetErrSize();
#define TSDB_CODE_FAILED_TO_CONNECT_S3 TAOS_DEF_ERROR_CODE(0, 0x0135)
#define TSDB_CODE_MSG_PREPROCESSED TAOS_DEF_ERROR_CODE(0, 0x0136) // internal
#define TSDB_CODE_OUT_OF_BUFFER TAOS_DEF_ERROR_CODE(0, 0x0137)
#define TSDB_CODE_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x0138)
//client
#define TSDB_CODE_TSC_INVALID_OPERATION TAOS_DEF_ERROR_CODE(0, 0x0200)

View File

@ -161,7 +161,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, char const *tbname, SPg
if (pgno == 0) {
tdbError("tdb/btree-open: pgno cannot be zero.");
tdbOsFree(pBt);
ASSERT(0);
return TSDB_CODE_INTERNAL_ERROR;
}
pBt->root = pgno;
/*
@ -418,10 +418,6 @@ static int tdbDefaultKeyCmprFn(const void *pKey1, int keyLen1, const void *pKey2
int mlen;
int cret;
if (ASSERT(keyLen1 > 0 && keyLen2 > 0 && pKey1 != NULL && pKey2 != NULL)) {
// -1 is less than
}
mlen = keyLen1 < keyLen2 ? keyLen1 : keyLen2;
cret = memcmp(pKey1, pKey2, mlen);
if (cret == 0) {
@ -571,14 +567,14 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
nOlds = 3;
}
for (int i = 0; i < nOlds; i++) {
if (ASSERT(sIdx + i <= nCells)) {
if (!(sIdx + i <= nCells)) {
return TSDB_CODE_FAILED;
}
SPgno pgno;
if (sIdx + i == nCells) {
if (ASSERT(!TDB_BTREE_PAGE_IS_LEAF(pParent))) {
return TSDB_CODE_FAILED;
if (TDB_BTREE_PAGE_IS_LEAF(pParent)) {
return TSDB_CODE_INTERNAL_ERROR;
}
pgno = ((SIntHdr *)(pParent->pData))->pgno;
} else {
@ -685,8 +681,6 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
// page is full, use a new page
nNews++;
ASSERT(infoNews[nNews].size + cellBytes <= TDB_PAGE_USABLE_SIZE(pPage));
if (childNotLeaf) {
// for non-child page, this cell is used as the right-most child,
// the divider cell to parent as well
@ -732,7 +726,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
szRCell = tdbBtreeCellSize(pPage, pCell, 0, NULL, NULL);
}
if (ASSERT(infoNews[iNew - 1].cnt > 0)) {
if (!(infoNews[iNew - 1].cnt > 0)) {
return TSDB_CODE_FAILED;
}
@ -822,10 +816,10 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
pCell = tdbPageGetCell(pPage, oIdx);
szCell = tdbBtreeCellSize(pPage, pCell, 0, NULL, NULL);
if (ASSERT(nNewCells <= infoNews[iNew].cnt)) {
if (!(nNewCells <= infoNews[iNew].cnt)) {
return TSDB_CODE_FAILED;
}
if (ASSERT(iNew < nNews)) {
if (!(iNew < nNews)) {
return TSDB_CODE_FAILED;
}
@ -866,10 +860,10 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
}
}
} else {
if (ASSERT(childNotLeaf)) {
if (!(childNotLeaf)) {
return TSDB_CODE_FAILED;
}
if (ASSERT(iNew < nNews - 1)) {
if (!(iNew < nNews - 1)) {
return TSDB_CODE_FAILED;
}
@ -877,7 +871,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
((SIntHdr *)pNews[iNew]->pData)->pgno = ((SPgno *)pCell)[0];
// insert to parent as divider cell
if (ASSERT(iNew < nNews - 1)) {
if (!(iNew < nNews - 1)) {
return TSDB_CODE_FAILED;
}
((SPgno *)pCell)[0] = TDB_PAGE_PGNO(pNews[iNew]);
@ -894,7 +888,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
}
if (childNotLeaf) {
if (ASSERT(TDB_PAGE_TOTAL_CELLS(pNews[nNews - 1]) == infoNews[nNews - 1].cnt)) {
if (!(TDB_PAGE_TOTAL_CELLS(pNews[nNews - 1]) == infoNews[nNews - 1].cnt)) {
return TSDB_CODE_FAILED;
}
((SIntHdr *)(pNews[nNews - 1]->pData))->pgno = rPgno;
@ -1091,7 +1085,7 @@ static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const
nLeft -= kLen;
// pack partial val to local if any space left
if (nLocal > nHeader + kLen + sizeof(SPgno)) {
if (ASSERT(pVal != NULL && vLen != 0)) {
if (!(pVal != NULL && vLen != 0)) {
tdbFree(pBuf);
return TSDB_CODE_FAILED;
}
@ -1259,14 +1253,14 @@ static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const vo
int nPayload;
int ret;
if (ASSERT(pPage->kLen == TDB_VARIANT_LEN || pPage->kLen == kLen)) {
return TSDB_CODE_FAILED;
if (!(pPage->kLen == TDB_VARIANT_LEN || pPage->kLen == kLen)) {
return TSDB_CODE_INVALID_PARA;
}
if (ASSERT(pPage->vLen == TDB_VARIANT_LEN || pPage->vLen == vLen)) {
return TSDB_CODE_FAILED;
if (!(pPage->vLen == TDB_VARIANT_LEN || pPage->vLen == vLen)) {
return TSDB_CODE_INVALID_PARA;
}
if (ASSERT(pKey != NULL && kLen > 0)) {
return TSDB_CODE_FAILED;
if (!(pKey != NULL && kLen > 0)) {
return TSDB_CODE_INVALID_PARA;
}
nPayload = 0;
@ -1645,7 +1639,6 @@ static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell, int dropOfp, TXN *
SArray *ofps = pPage->pPager->ofps;
if (ofps) {
if (taosArrayPush(ofps, &ofp) == NULL) {
ASSERT(0);
return terrno;
}
}
@ -2438,7 +2431,10 @@ int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) {
lidx = 0;
ridx = nCells - 1;
ASSERT(nCells > 0);
if (nCells <= 0) {
tdbError("tdb/btc-move-to: empty page.");
return TSDB_CODE_FAILED;
}
// compare first cell
pBtc->idx = lidx;

View File

@ -522,7 +522,9 @@ static int tdbPageDefragment(SPage *pPage) {
SCell *pCell = TDB_PAGE_CELL_AT(pPage, aCellIdx[iCell].iCell);
int32_t szCell = pPage->xCellSize(pPage, pCell, 0, NULL, NULL);
ASSERT(pNextCell - szCell >= pCell);
if (pNextCell - szCell < pCell) {
return TSDB_CODE_INTERNAL_ERROR;
}
pNextCell -= szCell;
if (pNextCell > pCell) {
@ -535,7 +537,11 @@ static int tdbPageDefragment(SPage *pPage) {
TDB_PAGE_FCELL_SET(pPage, 0);
tdbOsFree(aCellIdx);
ASSERT(pPage->pFreeEnd - pPage->pFreeStart == nFree);
if (pPage->pFreeEnd - pPage->pFreeStart != nFree) {
tdbError("tdb/page-defragment: nFree: %d, pFreeStart: %p, pFreeEnd: %p.", nFree, pPage->pFreeStart,
pPage->pFreeEnd);
return TSDB_CODE_INTERNAL_ERROR;
}
return 0;
}

View File

@ -16,19 +16,7 @@
#include "crypt.h"
#include "tdbInt.h"
#include "tglobal.h"
/*
#pragma pack(push, 1)
typedef struct {
u8 hdrString[16];
u16 pageSize;
SPgno freePage;
u32 nFreePages;
u8 reserved[102];
} SFileHdr;
#pragma pack(pop)
TDB_STATIC_ASSERT(sizeof(SFileHdr) == 128, "Size of file header is not correct");
*/
struct hashset_st {
size_t nbits;
size_t mask;
@ -450,7 +438,6 @@ static char *tdbEncryptPage(SPager *pPager, char *pPageData, int32_t pageSize, c
if (encryptAlgorithm == DND_CA_SM4) {
// tdbInfo("CBC_Encrypt key:%d %s %s", encryptAlgorithm, encryptKey, __FUNCTION__);
// ASSERT(strlen(encryptKey) > 0);
// tdbInfo("CBC tdb offset:%" PRId64 ", flag:%d before Encrypt", offset, pPage->pData[0]);
@ -915,7 +902,6 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage
if (encryptAlgorithm == DND_CA_SM4) {
// tdbInfo("CBC_Decrypt key:%d %s %s", encryptAlgorithm, encryptKey, __FUNCTION__);
// ASSERT(strlen(encryptKey) > 0);
// uint8_t flags = pPage->pData[0];
// tdbInfo("CBC tdb offset:%" PRId64 ", flag:%d before Decrypt", ((i64)pPage->pageSize) * (pgno - 1), flags);

View File

@ -40,7 +40,6 @@ int tdbTxnCloseImpl(TXN *pTxn) {
if (pTxn->jfd) {
TAOS_UNUSED(tdbOsClose(pTxn->jfd));
ASSERT(pTxn->jfd == NULL);
}
tdbOsFree(pTxn);

View File

@ -319,7 +319,6 @@ static inline int tdbTryLockPage(tdb_spinlock_t *pLock) {
} else if (ret == EBUSY) {
return P_LOCK_BUSY;
} else {
ASSERT(0);
return P_LOCK_FAIL;
}
}
@ -354,7 +353,10 @@ static inline SCell *tdbPageGetCell(SPage *pPage, int idx) {
int iOvfl;
int lidx;
ASSERT(idx >= 0 && idx < TDB_PAGE_TOTAL_CELLS(pPage));
if (idx < 0 || idx >= TDB_PAGE_TOTAL_CELLS(pPage)) {
terrno = TSDB_CODE_INVALID_PARA;
return NULL;
}
iOvfl = 0;
for (; iOvfl < pPage->nOverflow; iOvfl++) {
@ -367,7 +369,6 @@ static inline SCell *tdbPageGetCell(SPage *pPage, int idx) {
}
lidx = idx - iOvfl;
ASSERT(lidx >= 0 && lidx < pPage->pPageMethods->getCellNum(pPage));
pCell = pPage->pData + pPage->pPageMethods->getCellOffset(pPage, lidx);
return pCell;

View File

@ -22,12 +22,6 @@
extern "C" {
#endif
#if __STDC_VERSION__ >= 201112LL
#define TDB_STATIC_ASSERT(op, info) static_assert(op, info)
#else
#define TDB_STATIC_ASSERT(op, info)
#endif
#define TDB_ROUND8(x) (((x) + 7) & ~7)
int tdbGnrtFileID(tdb_fd_t fd, uint8_t *fileid, bool unique);

View File

@ -111,6 +111,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_IP_NOT_IN_WHITE_LIST, "Not allowed to connec
TAOS_DEFINE_ERROR(TSDB_CODE_FAILED_TO_CONNECT_S3, "Failed to connect to s3 server")
TAOS_DEFINE_ERROR(TSDB_CODE_MSG_PREPROCESSED, "Message has been processed in preprocess")
TAOS_DEFINE_ERROR(TSDB_CODE_OUT_OF_BUFFER, "Out of buffer")
TAOS_DEFINE_ERROR(TSDB_CODE_INTERNAL_ERROR, "Internal error")
//client
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_OPERATION, "Invalid operation")