diff --git a/include/libs/index/index.h b/include/libs/index/index.h index d2b157542f7449013869fbca60a812aeebcf5730..47eb97cc3a0e21b28cc0735ff5b8947ede2a77d1 100644 --- a/include/libs/index/index.h +++ b/include/libs/index/index.h @@ -76,25 +76,20 @@ void indexOptsDestroy(SIndexOpts* opts); * @param: */ -SIndexTerm* indexTermCreate(int64_t suid, - SIndexOperOnColumn operType, - uint8_t colType, - const char* colName, - int32_t nColName, - const char* colVal, - int32_t nColVal); +SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn operType, uint8_t colType, const char* colName, + int32_t nColName, const char* colVal, int32_t nColVal); void indexTermDestroy(SIndexTerm* p); /* - * init index + * init index env * */ -int32_t indexInit(); +void indexInit(); + /* - * destory index + * destory index env * */ - void indexCleanUp(); #ifdef __cplusplus diff --git a/source/dnode/vnode/meta/CMakeLists.txt b/source/dnode/vnode/meta/CMakeLists.txt index bb48d1acad50210bbca045f7d32b91e642f83a34..70418116174cfd2a4462fec00bc3f5ef684946e3 100644 --- a/source/dnode/vnode/meta/CMakeLists.txt +++ b/source/dnode/vnode/meta/CMakeLists.txt @@ -19,11 +19,13 @@ add_library(meta STATIC ${META_SRC}) target_include_directories( meta PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/vnode/meta" + PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/index" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) target_link_libraries( meta PUBLIC common + PUBLIC index ) if(${META_DB_IMPL} STREQUAL "BDB") diff --git a/source/dnode/vnode/meta/src/metaIdx.c b/source/dnode/vnode/meta/src/metaIdx.c index fe07f5ced42ec9d7d2e5a539e84dcddd711a669d..828bd120881fca49fabd2b66ce0e626e8ddc12b2 100644 --- a/source/dnode/vnode/meta/src/metaIdx.c +++ b/source/dnode/vnode/meta/src/metaIdx.c @@ -13,9 +13,13 @@ * along with this program. If not, see . */ +#include "index.h" #include "metaDef.h" struct SMetaIdx { +#ifdef USE_INVERTED_INDEX + SIndex *pIdx; +#endif /* data */ }; @@ -43,6 +47,13 @@ int metaOpenIdx(SMeta *pMeta) { rocksdb_options_destroy(options); #endif +#ifdef USE_INVERTED_INDEX + SIndexOpts opts; + if (indexOpen(&opts, pMeta->path, &pMeta->pIdx->pIdx) != 0) { + return -1; + } + +#endif return 0; } @@ -53,14 +64,47 @@ void metaCloseIdx(SMeta *pMeta) { /* TODO */ pMeta->pIdx = NULL; } #endif + +#ifdef USE_INVERTED_INDEX + SIndexOpts opts; + if (indexClose(pMeta->pIdx->pIdx) != 0) { + return -1; + } + +#endif } -int metaSaveTableToIdx(SMeta *pMeta, const STbCfg *pTbOptions) { +int metaSaveTableToIdx(SMeta *pMeta, const STbCfg *pTbCfg) { +#ifdef USE_INVERTED_INDEX + if (pTbCfgs - type == META_CHILD_TABLE) { + char buf[8] = {0}; + int16_t colId = (kvRowColIdx(pTbCfg->ctbCfg.pTag))[0].colId; + sprintf(buf, "%d", colId); // colname + + char *pTagVal = (char *)tdGetKVRowValOfCol(pTbCfg->ctbCfg.pTag, (kvRowColIdx(pTbCfg->ctbCfg.pTag))[0].colId); + + tb_uid_t suid = pTbCfg->ctbCfg.suid; // super id + tb_uid_t tuid = 0; // child table uid + SIndexMultiTerm *terms = indexMultiTermCreate(); + SIndexTerm * term = + indexTermCreate(suid, ADD_VALUE, TSDB_DATA_TYPE_BINARY, buf, strlen(buf), pTagVal, strlen(pTagVal), tuid); + indexMultiTermAdd(terms, term); + + int ret = indexPut(pMeta->pIdx->pIdx, terms); + indexMultiTermDestroy(terms); + return ret; + } else { + return DB_DONOTINDEX; + } +#endif // TODO return 0; } int metaRemoveTableFromIdx(SMeta *pMeta, tb_uid_t uid) { +#ifdef USE_INVERTED_INDEX + +#endif // TODO return 0; -} \ No newline at end of file +} diff --git a/source/dnode/vnode/meta/src/metaTbUid.c b/source/dnode/vnode/meta/src/metaTbUid.c index be85b45d950a80163488e6ebc2c1b7e0ad64b9f2..cad1eba134ca5f0f3ce3a9e63bf3711827fb5562 100644 --- a/source/dnode/vnode/meta/src/metaTbUid.c +++ b/source/dnode/vnode/meta/src/metaTbUid.c @@ -22,9 +22,10 @@ int metaOpenUidGnrt(SMeta *pMeta) { return 0; } -void metaCloseUidGnrt(SMeta *pMeta) { /* TODO */ } +void metaCloseUidGnrt(SMeta *pMeta) { /* TODO */ +} tb_uid_t metaGenerateUid(SMeta *pMeta) { // Generate a new table UID return ++(pMeta->uidGnrt.nextUid); -} \ No newline at end of file +} diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index d0b8fa4290d14f3363e3b1046b003fdc071393d2..04dac57d8f07383628bf569080c3d3bf36794807 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -30,21 +30,17 @@ void* indexQhandle = NULL; -int32_t indexInit() { +void indexInit() { + // refactor later indexQhandle = taosInitScheduler(INDEX_QUEUE_SIZE, INDEX_NUM_OF_THREADS, "index"); - return indexQhandle == NULL ? -1 : 0; - // do nothing } void indexCleanUp() { taosCleanUpScheduler(indexQhandle); } static int uidCompare(const void* a, const void* b) { + // add more version compare uint64_t u1 = *(uint64_t*)a; uint64_t u2 = *(uint64_t*)b; - if (u1 == u2) { - return 0; - } else { - return u1 < u2 ? -1 : 1; - } + return u1 - u2; } typedef struct SIdxColInfo { int colId; // generated by index internal @@ -61,7 +57,7 @@ static int indexMergeFinalResults(SArray* interResults, EIndexOperatorType oTyp static int indexGenTFile(SIndex* index, IndexCache* cache, SArray* batch); int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) { - // pthread_once(&isInit, indexInit); + pthread_once(&isInit, indexInit); SIndex* sIdx = calloc(1, sizeof(SIndex)); if (sIdx == NULL) { return -1; } diff --git a/source/libs/index/src/index_tfile.c b/source/libs/index/src/index_tfile.c index 90a730d3a938fb513e75b2220d5e2e6e7583d6d9..495c4d44770f03e5eb250b8510024a6072e2b29c 100644 --- a/source/libs/index/src/index_tfile.c +++ b/source/libs/index/src/index_tfile.c @@ -71,7 +71,10 @@ TFileCache* tfileCacheCreate(const char* path) { } TFileReader* reader = tfileReaderCreate(wc); - if (reader == NULL) { goto End; } + if (reader == NULL) { + indexInfo("skip invalid file: %s", file); + continue; + } TFileHeader* header = &reader->header; ICacheKey key = {.suid = header->suid, .colName = header->colName, .nColName = strlen(header->colName)};