Merge pull request #9681 from taosdata/feature/index_complete
index integrated into vnode meta
This commit is contained in:
commit
f7a446f239
|
@ -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
|
||||
*
|
||||
*/
|
||||
int32_t indexInit();
|
||||
/*
|
||||
* destory index
|
||||
* init index env
|
||||
*
|
||||
*/
|
||||
void indexInit();
|
||||
|
||||
/*
|
||||
* destory index env
|
||||
*
|
||||
*/
|
||||
void indexCleanUp();
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -13,9 +13,13 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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; }
|
||||
|
||||
|
|
|
@ -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)};
|
||||
|
||||
|
|
Loading…
Reference in New Issue