fix(tdb): subtract payload size with cell header size
This commit is contained in:
parent
de3e886188
commit
4a64803278
|
@ -1003,14 +1003,14 @@ static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const
|
||||||
int nLeft = nPayload;
|
int nLeft = nPayload;
|
||||||
int bytes;
|
int bytes;
|
||||||
int lastPage = 0;
|
int lastPage = 0;
|
||||||
if (nLocal >= kLen + 4) {
|
if (nLocal >= nHeader + kLen + sizeof(SPgno)) {
|
||||||
// pack key to local
|
// pack key to local
|
||||||
memcpy(pCell + nHeader, pKey, kLen);
|
memcpy(pCell + nHeader, pKey, kLen);
|
||||||
nLeft -= kLen;
|
nLeft -= kLen;
|
||||||
// pack partial val to local if any space left
|
// pack partial val to local if any space left
|
||||||
if (nLocal > kLen + 4) {
|
if (nLocal > nHeader + kLen + sizeof(SPgno)) {
|
||||||
memcpy(pCell + nHeader + kLen, pVal, nLocal - kLen - sizeof(SPgno));
|
memcpy(pCell + nHeader + kLen, pVal, nLocal - nHeader - kLen - sizeof(SPgno));
|
||||||
nLeft -= nLocal - kLen - sizeof(SPgno);
|
nLeft -= nLocal - nHeader - kLen - sizeof(SPgno);
|
||||||
}
|
}
|
||||||
|
|
||||||
// pack nextPgno
|
// pack nextPgno
|
||||||
|
@ -1150,9 +1150,7 @@ static int tdbBtreeEncodePayload(SPage *pPage, SCell *pCell, int nHeader, const
|
||||||
// free local buffer
|
// free local buffer
|
||||||
tdbFree(pBuf);
|
tdbFree(pBuf);
|
||||||
|
|
||||||
*szPayload = nLocal;
|
*szPayload = nLocal - nHeader;
|
||||||
|
|
||||||
// ASSERT(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1246,10 +1244,10 @@ static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader,
|
||||||
int bytes;
|
int bytes;
|
||||||
int lastPage = 0;
|
int lastPage = 0;
|
||||||
|
|
||||||
if (nLocal >= pDecoder->kLen + 4) {
|
if (nLocal >= pDecoder->kLen + nHeader + sizeof(SPgno)) {
|
||||||
pDecoder->pKey = (SCell *)pCell + nHeader;
|
pDecoder->pKey = (SCell *)pCell + nHeader;
|
||||||
nLeft -= kLen;
|
nLeft -= kLen;
|
||||||
if (nLocal > kLen + 4) {
|
if (nLocal > kLen + nHeader + sizeof(SPgno)) {
|
||||||
// read partial val to local
|
// read partial val to local
|
||||||
pDecoder->pVal = tdbRealloc(pDecoder->pVal, vLen);
|
pDecoder->pVal = tdbRealloc(pDecoder->pVal, vLen);
|
||||||
if (pDecoder->pVal == NULL) {
|
if (pDecoder->pVal == NULL) {
|
||||||
|
@ -1259,9 +1257,9 @@ static int tdbBtreeDecodePayload(SPage *pPage, const SCell *pCell, int nHeader,
|
||||||
|
|
||||||
tdbDebug("tdb btc decoder: %p/0x%x pVal: %p ", pDecoder, pDecoder->freeKV, pDecoder->pVal);
|
tdbDebug("tdb btc decoder: %p/0x%x pVal: %p ", pDecoder, pDecoder->freeKV, pDecoder->pVal);
|
||||||
|
|
||||||
memcpy(pDecoder->pVal, pCell + nHeader + kLen, nLocal - kLen - sizeof(SPgno));
|
memcpy(pDecoder->pVal, pCell + nHeader + kLen, nLocal - nHeader - kLen - sizeof(SPgno));
|
||||||
|
|
||||||
nLeft -= nLocal - kLen - sizeof(SPgno);
|
nLeft -= nLocal - nHeader - kLen - sizeof(SPgno);
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&pgno, pCell + nHeader + nPayload - nLeft, sizeof(pgno));
|
memcpy(&pgno, pCell + nHeader + nPayload - nLeft, sizeof(pgno));
|
||||||
|
@ -1474,7 +1472,7 @@ static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell, int dropOfp, TXN *
|
||||||
|
|
||||||
int nPayload = kLen + vLen;
|
int nPayload = kLen + vLen;
|
||||||
if (nHeader + nPayload <= pPage->maxLocal) {
|
if (nHeader + nPayload <= pPage->maxLocal) {
|
||||||
return nHeader + kLen + vLen;
|
return nHeader + nPayload;
|
||||||
} else {
|
} else {
|
||||||
int maxLocal = pPage->maxLocal;
|
int maxLocal = pPage->maxLocal;
|
||||||
|
|
||||||
|
@ -1486,7 +1484,7 @@ static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell, int dropOfp, TXN *
|
||||||
// free ofp pages' cells
|
// free ofp pages' cells
|
||||||
if (dropOfp) {
|
if (dropOfp) {
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
SPgno pgno = *(SPgno *)(pCell + nHeader + nLocal - sizeof(SPgno));
|
SPgno pgno = *(SPgno *)(pCell + nLocal - sizeof(SPgno));
|
||||||
int nLeft = nPayload - nLocal + sizeof(SPgno);
|
int nLeft = nPayload - nLocal + sizeof(SPgno);
|
||||||
SPage *ofp;
|
SPage *ofp;
|
||||||
int bytes;
|
int bytes;
|
||||||
|
@ -1513,7 +1511,7 @@ static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell, int dropOfp, TXN *
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nHeader + nLocal;
|
return nLocal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TDB_BTREE_CELL
|
// TDB_BTREE_CELL
|
||||||
|
|
Loading…
Reference in New Issue