提交 b8753573 编写于 作者: H Haojun Liao

refactor:do some internal refactor.

上级 a23f5f59
...@@ -26,7 +26,7 @@ typedef struct SLHashBucket { ...@@ -26,7 +26,7 @@ typedef struct SLHashBucket {
int32_t size; // the number of element in this entry int32_t size; // the number of element in this entry
} SLHashBucket; } SLHashBucket;
typedef struct SLHashObj { struct SLHashObj {
SDiskbasedBuf *pBuf; SDiskbasedBuf *pBuf;
_hash_fn_t hashFn; _hash_fn_t hashFn;
SLHashBucket **pBucket; // entry list SLHashBucket **pBucket; // entry list
...@@ -35,7 +35,7 @@ typedef struct SLHashObj { ...@@ -35,7 +35,7 @@ typedef struct SLHashObj {
int32_t bits; // the number of bits used in hash int32_t bits; // the number of bits used in hash
int32_t numOfBuckets; // the number of buckets int32_t numOfBuckets; // the number of buckets
int64_t size; // the number of total items int64_t size; // the number of total items
} SLHashObj; };
/** /**
* the data struct for each hash node * the data struct for each hash node
...@@ -99,7 +99,7 @@ static int32_t doAddToBucket(SLHashObj* pHashObj, SLHashBucket* pBucket, int32_t ...@@ -99,7 +99,7 @@ static int32_t doAddToBucket(SLHashObj* pHashObj, SLHashBucket* pBucket, int32_t
int32_t newPageId = -1; int32_t newPageId = -1;
SFilePage* pNewPage = getNewBufPage(pHashObj->pBuf, 0, &newPageId); SFilePage* pNewPage = getNewBufPage(pHashObj->pBuf, 0, &newPageId);
if (pNewPage == NULL) { if (pNewPage == NULL) {
return TSDB_CODE_OUT_OF_MEMORY; return terrno;
} }
taosArrayPush(pBucket->pPageIdList, &newPageId); taosArrayPush(pBucket->pPageIdList, &newPageId);
...@@ -138,7 +138,6 @@ static void doRemoveFromBucket(SFilePage* pPage, SLHashNode* pNode, SLHashBucket ...@@ -138,7 +138,6 @@ static void doRemoveFromBucket(SFilePage* pPage, SLHashNode* pNode, SLHashBucket
} }
setBufPageDirty(pPage, true); setBufPageDirty(pPage, true);
pBucket->size -= 1; pBucket->size -= 1;
} }
...@@ -229,6 +228,10 @@ static int32_t doAddNewBucket(SLHashObj* pHashObj) { ...@@ -229,6 +228,10 @@ static int32_t doAddNewBucket(SLHashObj* pHashObj) {
int32_t pageId = -1; int32_t pageId = -1;
SFilePage* p = getNewBufPage(pHashObj->pBuf, 0, &pageId); SFilePage* p = getNewBufPage(pHashObj->pBuf, 0, &pageId);
if (p == NULL) {
return terrno;
}
p->num = sizeof(SFilePage); p->num = sizeof(SFilePage);
setBufPageDirty(p, true); setBufPageDirty(p, true);
...@@ -252,7 +255,8 @@ SLHashObj* tHashInit(int32_t inMemPages, int32_t pageSize, _hash_fn_t fn, int32_ ...@@ -252,7 +255,8 @@ SLHashObj* tHashInit(int32_t inMemPages, int32_t pageSize, _hash_fn_t fn, int32_
printf("tHash Init failed since %s", terrstr(terrno)); printf("tHash Init failed since %s", terrstr(terrno));
return NULL; return NULL;
} }
int32_t code = createDiskbasedBuf(&pHashObj->pBuf, pageSize, inMemPages * pageSize, 0, tsTempDir);
int32_t code = createDiskbasedBuf(&pHashObj->pBuf, pageSize, inMemPages * pageSize, "", tsTempDir);
if (code != 0) { if (code != 0) {
terrno = code; terrno = code;
return NULL; return NULL;
...@@ -389,7 +393,9 @@ char* tHashGet(SLHashObj* pHashObj, const void *key, size_t keyLen) { ...@@ -389,7 +393,9 @@ char* tHashGet(SLHashObj* pHashObj, const void *key, size_t keyLen) {
} }
SLHashBucket* pBucket = pHashObj->pBucket[bucketId]; SLHashBucket* pBucket = pHashObj->pBucket[bucketId];
for (int32_t i = 0; i < taosArrayGetSize(pBucket->pPageIdList); ++i) { int32_t num = taosArrayGetSize(pBucket->pPageIdList);
for (int32_t i = 0; i < num; ++i) {
int32_t pageId = *(int32_t*)taosArrayGet(pBucket->pPageIdList, i); int32_t pageId = *(int32_t*)taosArrayGet(pBucket->pPageIdList, i);
SFilePage* p = getBufPage(pHashObj->pBuf, pageId); SFilePage* p = getBufPage(pHashObj->pBuf, pageId);
......
...@@ -309,6 +309,7 @@ static SListNode* getEldestUnrefedPage(SDiskbasedBuf* pBuf) { ...@@ -309,6 +309,7 @@ static SListNode* getEldestUnrefedPage(SDiskbasedBuf* pBuf) {
static char* evacOneDataPage(SDiskbasedBuf* pBuf) { static char* evacOneDataPage(SDiskbasedBuf* pBuf) {
char* bufPage = NULL; char* bufPage = NULL;
SListNode* pn = getEldestUnrefedPage(pBuf); SListNode* pn = getEldestUnrefedPage(pBuf);
terrno = 0;
// all pages are referenced by user, try to allocate new space // all pages are referenced by user, try to allocate new space
if (pn == NULL) { if (pn == NULL) {
...@@ -332,6 +333,7 @@ static char* evacOneDataPage(SDiskbasedBuf* pBuf) { ...@@ -332,6 +333,7 @@ static char* evacOneDataPage(SDiskbasedBuf* pBuf) {
bufPage = flushPageToDisk(pBuf, d); bufPage = flushPageToDisk(pBuf, d);
} }
ASSERT((bufPage != NULL) || terrno != TSDB_CODE_SUCCESS);
return bufPage; return bufPage;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册