add index TFile

This commit is contained in:
yihaoDeng 2021-12-20 09:34:28 +08:00
parent 21d6ba86c0
commit 76f70feb49
6 changed files with 128 additions and 9 deletions

View File

@ -31,6 +31,8 @@
extern "C" { extern "C" {
#endif #endif
typedef enum {kTypeValue, kTypeDeletion} STermValueType ;
typedef struct SIndexStat { typedef struct SIndexStat {
int32_t totalAdded; // int32_t totalAdded; //
int32_t totalDeled; // int32_t totalDeled; //

View File

@ -44,7 +44,7 @@ void indexCacheDestroy(void *cache);
int indexCachePut(void *cache, SIndexTerm *term, int16_t colId, int32_t version, uint64_t uid); int indexCachePut(void *cache, SIndexTerm *term, int16_t colId, int32_t version, uint64_t uid);
//int indexCacheGet(void *cache, uint64_t *rst); //int indexCacheGet(void *cache, uint64_t *rst);
int indexCacheSearch(void *cache, SIndexTermQuery *query, int16_t colId, int32_t version, SArray *result); int indexCacheSearch(void *cache, SIndexTermQuery *query, int16_t colId, int32_t version, SArray *result, STermValueType *s);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __INDEX_TFILE_H__
#define __INDEX_TFILE_H__
#include "index.h"
#include "indexInt.h"
#include "tlockfree.h"
#include "tskiplist.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct IndexTFile {
T_REF_DECLARE()
} IndexTFile;
IndexTFile *indexTFileCreate();
int indexTFileSearch(void *tfile, SIndexTermQuery *query, SArray *result);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -16,13 +16,19 @@
#include "index.h" #include "index.h"
#include "indexInt.h" #include "indexInt.h"
#include "index_cache.h" #include "index_cache.h"
#include "index_tfile.h"
#include "tdef.h" #include "tdef.h"
#ifdef USE_LUCENE #ifdef USE_LUCENE
#include "lucene++/Lucene_c.h" #include "lucene++/Lucene_c.h"
#endif #endif
static int uidCompare(const void *a, const void *b) {
uint64_t u1 = *(uint64_t *)a;
uint64_t u2 = *(uint64_t *)b;
if (u1 == u2) { return 0; }
else { return u1 < u2 ? -1 : 1; }
}
typedef struct SIdxColInfo { typedef struct SIdxColInfo {
int colId; // generated by index internal int colId; // generated by index internal
int cVersion; int cVersion;
@ -273,9 +279,44 @@ void indexMultiTermDestroy(SIndexMultiTerm *terms) {
void indexInit() { void indexInit() {
//do nothing //do nothing
} }
static int indexTermSearch(SIndex *sIdx, SIndexTermQuery *term, SArray **result) { static int indexTermSearch(SIndex *sIdx, SIndexTermQuery *query, SArray **result) {
int32_t version = -1;
int16_t colId = -1;
SIdxColInfo *colInfo = NULL;
SIndexTerm *term = query->term;
const char *colName = term->colName;
int32_t nColName = term->nColName;
pthread_mutex_lock(&sIdx->mtx);
colInfo = taosHashGet(sIdx->colObj, colName, nColName);
if (colInfo == NULL) {
pthread_mutex_unlock(&sIdx->mtx);
return -1;
}
colId = colInfo->colId;
version = colInfo->cVersion;
pthread_mutex_unlock(&sIdx->mtx);
return 0; *result = taosArrayInit(4, sizeof(uint64_t));
//TODO: iterator mem and tidex
STermValueType s;
if (0 == indexCacheSearch(sIdx->cache, query, colId, version, *result, &s)) {
if (s == kTypeDeletion) {
indexInfo("col: %s already drop by other opera", term->colName);
// coloum already drop by other oper, no need to query tindex
return 0;
} else {
if (0 != indexTFileSearch(sIdx->tindex, query, *result)) {
indexError("corrupt at index(TFile) col:%s val: %s", term->colName, term->colVal);
return -1;
}
}
} else {
indexError("corrupt at index(cache) col:%s val: %s", term->colName, term->colVal);
return -1;
}
return 0;
} }
static void indexInterResultsDestroy(SArray *results) { static void indexInterResultsDestroy(SArray *results) {
if (results == NULL) { return; } if (results == NULL) { return; }
@ -291,8 +332,7 @@ static void indexInterResultsDestroy(SArray *results) {
static int indexMergeFinalResults(SArray *interResults, EIndexOperatorType oType, SArray *fResults) { static int indexMergeFinalResults(SArray *interResults, EIndexOperatorType oType, SArray *fResults) {
//refactor, merge interResults into fResults by oType //refactor, merge interResults into fResults by oType
SArray *first = taosArrayGetP(interResults, 0); SArray *first = taosArrayGetP(interResults, 0);
taosArraySort(first, uidCompare);
//taosArraySort(first, getCom)
if (oType == MUST) { if (oType == MUST) {
} else if (oType == SHOULD) { } else if (oType == SHOULD) {

View File

@ -46,7 +46,7 @@ static int32_t compareKey(const void *l, const void *r) {
rp += sizeof(rf); rp += sizeof(rf);
// compare field type // compare field type
int16_t lft, rft; int8_t lft, rft;
memcpy(&lft, lp, sizeof(lft)); memcpy(&lft, lp, sizeof(lft));
memcpy(&rft, rp, sizeof(rft)); memcpy(&rft, rp, sizeof(rft));
lp += sizeof(lft); lp += sizeof(lft);
@ -149,7 +149,7 @@ int indexCacheDel(void *cache, int32_t fieldId, const char *fieldValue, int32_t
IndexCache *pCache = cache; IndexCache *pCache = cache;
return 0; return 0;
} }
int indexCacheSearch(void *cache, SIndexTermQuery *query, int16_t colId, int32_t version, SArray *result) { int indexCacheSearch(void *cache, SIndexTermQuery *query, int16_t colId, int32_t version, SArray *result, STermValueType *s) {
if (cache == NULL) { return -1; } if (cache == NULL) { return -1; }
IndexCache *pCache = cache; IndexCache *pCache = cache;
SIndexTerm *term = query->term; SIndexTerm *term = query->term;
@ -159,7 +159,7 @@ int indexCacheSearch(void *cache, SIndexTermQuery *query, int16_t colId, int32_t
char *buf = calloc(1, keyLen); char *buf = calloc(1, keyLen);
if (qtype == QUERY_TERM) { if (qtype == QUERY_TERM) {
} else if (qtype == QUERY_PREFIX) { } else if (qtype == QUERY_PREFIX) {
} else if (qtype == QUERY_SUFFIX) { } else if (qtype == QUERY_SUFFIX) {

View File

@ -0,0 +1,31 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "index_tfile.h"
IndexTFile *indexTFileCreate() {
IndexTFile *tfile = calloc(1, sizeof(IndexTFile));
return tfile;
}
void IndexTFileDestroy(IndexTFile *tfile) {
free(tfile);
}
int indexTFileSearch(void *tfile, SIndexTermQuery *query, SArray *result) {
IndexTFile *ptfile = (IndexTFile *)tfile;
return 0;
}