more refact

This commit is contained in:
Hongze Cheng 2022-05-07 13:16:07 +00:00
parent 3cad99a178
commit 16897f17dc
1 changed files with 11 additions and 14 deletions

View File

@ -199,12 +199,15 @@ int32_t tsdbInsertData2(SMemTable *pMemTb, int64_t version, const SVSubmitBlk *p
// ASSERT(c); // ASSERT(c);
// encode row // encode row
int8_t level = tsdbMemSkipListRandLevel(&pMemData->sl); int8_t level = tsdbMemSkipListRandLevel(&pMemData->sl);
int32_t tsize = SL_NODE_SIZE(level) + sizeof(version) + (0 /*todo*/);
SMemSkipListNode *pNode = vnodeBufPoolMalloc(pPool, tsize);
if (pNode == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
// int8_t level = tsdbMemSkipListRandLevel(&pMemData->sl); pNode->level = level;
// int32_t tsize = SL_NODE_SIZE(level) + sizeof(version) + (p - pt);
// pSlNode = vnodeBufPoolMalloc(pPool, tsize);
// pSlNode->level = level;
// uint8_t *pData = SL_NODE_DATA(pSlNode); // uint8_t *pData = SL_NODE_DATA(pSlNode);
// *(int64_t *)pData = version; // *(int64_t *)pData = version;
@ -235,20 +238,14 @@ int32_t tsdbInsertData2(SMemTable *pMemTb, int64_t version, const SVSubmitBlk *p
static int8_t tsdbMemSkipListRandLevel(SMemSkipList *pSl) { static int8_t tsdbMemSkipListRandLevel(SMemSkipList *pSl) {
int8_t level = 1; int8_t level = 1;
int8_t tlevel;
const uint32_t factor = 4; const uint32_t factor = 4;
if (pSl->size) { if (pSl->size) {
while ((taosRandR(&pSl->seed) % factor) == 0 && level < pSl->maxLevel) { tlevel = TMIN(pSl->maxLevel, pSl->level + 1);
while ((taosRandR(&pSl->seed) % factor) == 0 && level < tlevel) {
level++; level++;
} }
if (level > pSl->level) {
if (pSl->level < pSl->maxLevel) {
level = pSl->level + 1;
} else {
level = pSl->level;
}
}
} }
return level; return level;