提交 bad68656 编写于 作者: dengyihao's avatar dengyihao

fix: avoid invalid read/write

上级 fb4982f8
......@@ -31,7 +31,7 @@ if (${BUILD_WITH_INVERTEDINDEX})
endif(${BUILD_WITH_INVERTEDINDEX})
if (${BUILD_TEST})
add_subdirectory(test)
endif(${BUILD_TEST})
#if (${BUILD_TEST})
# add_subdirectory(test)
#endif(${BUILD_TEST})
......@@ -58,6 +58,7 @@ struct SIndex {
SIndexStat stat;
TdThreadMutex mtx;
tsem_t sem;
bool quit;
};
......@@ -70,6 +71,7 @@ struct SIndexOpts {
int32_t cacheSize; // MB
// add cache module later
#endif
int32_t cacheOpt; // MB
};
struct SIndexMultiTermQuery {
......
......@@ -90,6 +90,15 @@ static void indexMergeCacheAndTFile(SArray* result, IterateValue* icache, Iterat
// static int32_t indexSerialTermKey(SIndexTerm* itm, char* buf);
// int32_t indexSerialKey(ICacheKey* key, char* buf);
static void indexPost(void* idx) {
SIndex* pIdx = idx;
tsem_post(&pIdx->sem);
}
static void indexWait(void* idx) {
SIndex* pIdx = idx;
tsem_wait(&pIdx->sem);
}
int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) {
taosThreadOnce(&isInit, indexInit);
SIndex* sIdx = taosMemoryCalloc(1, sizeof(SIndex));
......@@ -107,6 +116,8 @@ int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) {
sIdx->cVersion = 1;
sIdx->path = tstrdup(path);
taosThreadMutexInit(&sIdx->mtx, NULL);
tsem_init(&sIdx->sem, 0, 0);
// taosThreadCondInit(&sIdx->finished, NULL);
sIdx->refId = indexAddRef(sIdx);
indexAcquireRef(sIdx->refId);
......@@ -125,6 +136,7 @@ END:
void indexDestroy(void* handle) {
SIndex* sIdx = handle;
taosThreadMutexDestroy(&sIdx->mtx);
tsem_destroy(&sIdx->sem);
indexTFileDestroy(sIdx->tindex);
taosMemoryFree(sIdx->path);
taosMemoryFree(sIdx);
......@@ -138,7 +150,7 @@ void indexClose(SIndex* sIdx) {
while (iter) {
IndexCache** pCache = iter;
indexCacheForceToMerge((void*)(*pCache));
indexCacheWait((void*)(*pCache));
indexWait((void*)(sIdx));
iter = taosHashIterate(sIdx->colObj, iter);
indexCacheUnRef(*pCache);
}
......@@ -461,7 +473,8 @@ int indexFlushCacheToTFile(SIndex* sIdx, void* cache) {
indexCacheDestroyImm(pCache);
tfileReaderUnRef(pReader);
if (sIdx->quit) {
indexCacheBroadcast(pCache);
indexPost(sIdx);
// indexCacheBroadcast(pCache);
}
indexReleaseRef(sIdx->refId);
return 0;
......@@ -509,9 +522,6 @@ int indexFlushCacheToTFile(SIndex* sIdx, void* cache) {
indexDestroyFinalResult(result);
indexCacheDestroyImm(pCache);
if (sIdx->quit) {
indexCacheBroadcast(pCache);
}
indexCacheIteratorDestroy(cacheIter);
tfileIteratorDestroy(tfileIter);
......@@ -525,6 +535,9 @@ int indexFlushCacheToTFile(SIndex* sIdx, void* cache) {
} else {
indexInfo("success to merge , time cost: %" PRId64 "ms", cost / 1000);
}
if (sIdx->quit) {
indexPost(sIdx);
}
indexReleaseRef(sIdx->refId);
return ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册