提交 d9e9155f 编写于 作者: H Hongze Cheng

more

上级 32d95b8f
...@@ -65,7 +65,7 @@ void taosqsort(void *src, int64_t numOfElem, int64_t size, const void *param, __ ...@@ -65,7 +65,7 @@ void taosqsort(void *src, int64_t numOfElem, int64_t size, const void *param, __
* @param flags * @param flags
* @return * @return
*/ */
void *taosbsearch(const void *key, const void *base, int64_t nmemb, int64_t size, __compar_fn_t fn, int32_t flags); void *taosbsearch(const void *key, const void *base, int32_t nmemb, int32_t size, __compar_fn_t compar, int32_t flags);
/** /**
* adjust heap * adjust heap
...@@ -82,7 +82,7 @@ void *taosbsearch(const void *key, const void *base, int64_t nmemb, int64_t size ...@@ -82,7 +82,7 @@ void *taosbsearch(const void *key, const void *base, int64_t nmemb, int64_t size
* @return * @return
*/ */
void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const void *parcompar, void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const void *parcompar,
__ext_compar_fn_t compar, char* buf, bool maxroot); __ext_compar_fn_t compar, char *buf, bool maxroot);
/** /**
* sort heap to make sure it is a max/min root heap * sort heap to make sure it is a max/min root heap
...@@ -97,8 +97,7 @@ void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const ...@@ -97,8 +97,7 @@ void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const
* @param maxroot: if heap is max root heap * @param maxroot: if heap is max root heap
* @return * @return
*/ */
void taosheapsort(void *base, int32_t size, int32_t len, const void *parcompar, __ext_compar_fn_t compar, void taosheapsort(void *base, int32_t size, int32_t len, const void *parcompar, __ext_compar_fn_t compar, bool maxroot);
bool maxroot);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -61,8 +61,9 @@ typedef struct { ...@@ -61,8 +61,9 @@ typedef struct {
static int32_t tsdbCommitData(SCommitH *pCommith); static int32_t tsdbCommitData(SCommitH *pCommith);
static int32_t tsdbCommitDel(SCommitH *pCommith); static int32_t tsdbCommitDel(SCommitH *pCommith);
static int32_t tsdbCommitCache(SCommitH *pCommith); static int32_t tsdbCommitCache(SCommitH *pCommith);
static void tsdbStartCommit(STsdb *pRepo); static int32_t tsdbStartCommit(STsdb *pTsdb, SCommitH *pCHandle);
static void tsdbEndCommit(STsdb *pTsdb, int eno); static int32_t tsdbEndCommit(SCommitH *pCHandle, int eno);
static int tsdbInitCommitH(SCommitH *pCommith, STsdb *pRepo); static int tsdbInitCommitH(SCommitH *pCommith, STsdb *pRepo);
static void tsdbSeekCommitIter(SCommitH *pCommith, TSKEY key); static void tsdbSeekCommitIter(SCommitH *pCommith, TSKEY key);
static int tsdbNextCommitFid(SCommitH *pCommith); static int tsdbNextCommitFid(SCommitH *pCommith);
...@@ -115,9 +116,9 @@ int32_t tsdbCommit(STsdb *pTsdb) { ...@@ -115,9 +116,9 @@ int32_t tsdbCommit(STsdb *pTsdb) {
pTsdb->mem = NULL; pTsdb->mem = NULL;
// start commit // start commit
tsdbStartCommit(pTsdb); code = tsdbStartCommit(pTsdb, &commith);
if (tsdbInitCommitH(&commith, pTsdb) < 0) { if (code) {
return -1; goto _err;
} }
// commit impl // commit impl
...@@ -137,18 +138,21 @@ int32_t tsdbCommit(STsdb *pTsdb) { ...@@ -137,18 +138,21 @@ int32_t tsdbCommit(STsdb *pTsdb) {
} }
// end commit // end commit
tsdbDestroyCommitH(&commith); code = tsdbEndCommit(&commith, 0);
tsdbEndCommit(pTsdb, TSDB_CODE_SUCCESS); if (code) {
goto _err;
}
return code; return code;
_err: _err:
tsdbError("vgId:%d failed to commit since %s", TD_VID(pTsdb->pVnode), tstrerror(code));
return code; return code;
} }
static int32_t tsdbCommitData(SCommitH *pCommith) { static int32_t tsdbCommitData(SCommitH *pCommith) {
int32_t fid; int32_t fid;
SDFileSet *pSet; SDFileSet *pSet = NULL;
int32_t code = 0; int32_t code = 0;
STsdb *pTsdb = TSDB_COMMIT_REPO(pCommith); STsdb *pTsdb = TSDB_COMMIT_REPO(pCommith);
...@@ -276,19 +280,32 @@ void tsdbGetRtnSnap(STsdb *pRepo, SRtn *pRtn) { ...@@ -276,19 +280,32 @@ void tsdbGetRtnSnap(STsdb *pRepo, SRtn *pRtn) {
pRtn->minFid, pRtn->midFid, pRtn->maxFid); pRtn->minFid, pRtn->midFid, pRtn->maxFid);
} }
static void tsdbStartCommit(STsdb *pRepo) { static int32_t tsdbStartCommit(STsdb *pTsdb, SCommitH *pCHandle) {
SMemTable *pMem = pRepo->imem; int32_t code = 0;
tsdbInfo("vgId:%d, start to commit", REPO_ID(pRepo)); tsdbInfo("vgId:%d, start to commit", REPO_ID(pTsdb));
tsdbStartFSTxn(pRepo, 0, 0); if (tsdbInitCommitH(pCHandle, pTsdb) < 0) {
return -1;
}
tsdbStartFSTxn(pTsdb, 0, 0);
return code;
} }
static void tsdbEndCommit(STsdb *pTsdb, int eno) { static int32_t tsdbEndCommit(SCommitH *pCHandle, int eno) {
int32_t code = 0;
STsdb *pTsdb = TSDB_COMMIT_REPO(pCHandle);
tsdbDestroyCommitH(pCHandle);
tsdbEndFSTxn(pTsdb); tsdbEndFSTxn(pTsdb);
tsdbMemTableDestroy(pTsdb->imem); tsdbMemTableDestroy(pTsdb->imem);
pTsdb->imem = NULL; pTsdb->imem = NULL;
tsdbInfo("vgId:%d, commit over, %s", REPO_ID(pTsdb), (eno == TSDB_CODE_SUCCESS) ? "succeed" : "failed"); tsdbInfo("vgId:%d, commit over, %s", REPO_ID(pTsdb), (eno == TSDB_CODE_SUCCESS) ? "succeed" : "failed");
return code;
} }
static int tsdbInitCommitH(SCommitH *pCommith, STsdb *pRepo) { static int tsdbInitCommitH(SCommitH *pCommith, STsdb *pRepo) {
......
...@@ -158,82 +158,68 @@ void taosqsort(void *src, int64_t numOfElem, int64_t size, const void *param, __ ...@@ -158,82 +158,68 @@ void taosqsort(void *src, int64_t numOfElem, int64_t size, const void *param, __
taosMemoryFreeClear(buf); taosMemoryFreeClear(buf);
} }
void *taosbsearch(const void *key, const void *base, int64_t nmemb, int64_t size, __compar_fn_t compar, int32_t flags) { void *taosbsearch(const void *key, const void *base, int32_t nmemb, int32_t size, __compar_fn_t compar, int32_t flags) {
// TODO: need to check the correctness of this function uint8_t *p;
int32_t l = 0; int32_t lidx;
int32_t r = (int32_t)nmemb; int32_t ridx;
int32_t idx = 0; int32_t midx;
int32_t comparison; int32_t c;
if (nmemb <= 0) return NULL;
lidx = 0;
ridx = nmemb - 1;
while (lidx <= ridx) {
midx = (lidx + ridx) / 2;
p = (uint8_t *)base + size * midx;
c = compar(key, p);
if (c == 0) {
break;
} else if (c < 0) {
ridx = midx - 1;
} else {
lidx = midx + 1;
}
}
if (flags == TD_EQ) { if (flags == TD_EQ) {
return bsearch(key, base, nmemb, size, compar); if (c == 0) {
} else if (flags == TD_GE) { return p;
if (nmemb <= 0) return NULL; } else {
if ((*compar)(key, elePtrAt(base, size, 0)) <= 0) return elePtrAt(base, size, 0); return NULL;
if ((*compar)(key, elePtrAt(base, size, nmemb - 1)) > 0) return NULL;
while (l < r) {
idx = (l + r) / 2;
comparison = (*compar)(key, elePtrAt(base, size, idx));
if (comparison < 0) {
r = idx;
} else if (comparison > 0) {
l = idx + 1;
} else {
return elePtrAt(base, size, idx);
}
} }
} else if (flags == TD_GE) {
if ((*compar)(key, elePtrAt(base, size, idx)) < 0) { if (c <= 0) {
return elePtrAt(base, size, idx); return p;
} else { } else {
if (idx + 1 > nmemb - 1) { if (midx + 1 < nmemb) {
return NULL; return p + size;
} else { } else {
return elePtrAt(base, size, idx + 1); return NULL;
} }
} }
} else if (flags == TD_LE) { } else if (flags == TD_LE) {
if (nmemb <= 0) return NULL; if (c >= 0) {
if ((*compar)(key, elePtrAt(base, size, nmemb - 1)) >= 0) return elePtrAt(base, size, nmemb - 1); return p;
if ((*compar)(key, elePtrAt(base, size, 0)) < 0) return NULL;
while (l < r) {
idx = (l + r) / 2;
comparison = (*compar)(key, elePtrAt(base, size, idx));
if (comparison < 0) {
r = idx;
} else if (comparison > 0) {
l = idx + 1;
} else {
return elePtrAt(base, size, idx);
}
}
if ((*compar)(key, elePtrAt(base, size, idx)) > 0) {
return elePtrAt(base, size, idx);
} else { } else {
if (idx == 0) { if (midx > 0) {
return NULL; return p - size;
} else { } else {
return elePtrAt(base, size, idx - 1); return NULL;
} }
} }
} else { } else {
assert(0); ASSERT(0);
return NULL;
} }
return NULL;
} }
void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const void *parcompar, void taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, const void *parcompar,
__ext_compar_fn_t compar, char* buf, bool maxroot) { __ext_compar_fn_t compar, char *buf, bool maxroot) {
int32_t parent; int32_t parent;
int32_t child; int32_t child;
char* tmp = NULL; char *tmp = NULL;
if (buf == NULL) { if (buf == NULL) {
tmp = taosMemoryMalloc(size); tmp = taosMemoryMalloc(size);
} else { } else {
...@@ -288,7 +274,7 @@ void taosheapsort(void *base, int32_t size, int32_t len, const void *parcompar, ...@@ -288,7 +274,7 @@ void taosheapsort(void *base, int32_t size, int32_t len, const void *parcompar,
bool maxroot) { bool maxroot) {
int32_t i; int32_t i;
char* buf = taosMemoryCalloc(1, size); char *buf = taosMemoryCalloc(1, size);
if (buf == NULL) { if (buf == NULL) {
return; return;
} }
......
...@@ -67,4 +67,12 @@ target_link_libraries(bloomFilterTest os util gtest_main) ...@@ -67,4 +67,12 @@ target_link_libraries(bloomFilterTest os util gtest_main)
add_test( add_test(
NAME bloomFilterTest NAME bloomFilterTest
COMMAND bloomFilterTest COMMAND bloomFilterTest
)
# taosbsearchTest
add_executable(taosbsearchTest "taosbsearchTest.cpp")
target_link_libraries(taosbsearchTest os util gtest_main)
add_test(
NAME taosbsearchTest
COMMAND taosbsearchTest
) )
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册