update cache search

This commit is contained in:
yihaoDeng 2021-12-19 16:43:56 +08:00
parent 2375f6c944
commit d43ad3bed8
4 changed files with 31 additions and 26 deletions

View File

@ -53,7 +53,7 @@ int indexMultiTermQueryAdd(SIndexMultiTermQuery *pQuery, SIndexTerm
*/ */
int indexOpen(SIndexOpts *opt, const char *path, SIndex **index); int indexOpen(SIndexOpts *opt, const char *path, SIndex **index);
void indexClose(SIndex *index); void indexClose(SIndex *index);
int indexPut(SIndex *index, SIndexMultiTerm *terms, int uid); int indexPut(SIndex *index, SIndexMultiTerm *terms, uint64_t uid);
int indexDelete(SIndex *index, SIndexMultiTermQuery *query); int indexDelete(SIndex *index, SIndexMultiTermQuery *query);
int indexSearch(SIndex *index, SIndexMultiTermQuery *query, SArray *result); int indexSearch(SIndex *index, SIndexMultiTermQuery *query, SArray *result);
int indexRebuild(SIndex *index, SIndexOpts *opt); int indexRebuild(SIndex *index, SIndexOpts *opt);

View File

@ -16,13 +16,14 @@
#define __INDEX_CACHE_H__ #define __INDEX_CACHE_H__
#include "index.h" #include "index.h"
#include "indexInt.h"
#include "tlockfree.h" #include "tlockfree.h"
#include "tskiplist.h" #include "tskiplist.h"
// ----------------- row structure in skiplist --------------------- // ----------------- row structure in skiplist ---------------------
/* A data row, the format is like below: /* A data row, the format is like below:
* content: |<--totalLen-->|<-- fieldid-->|<--field type -->|<-- value len--->|<-- value -->|<-- uid -->|<--version--->|<-- itermType -->| * content: |<--totalLen-->|<-- fieldid-->|<--field type -->|<-- value len--->|<-- value -->|<-- uid -->|<--version--->|<-- itermType -->|
* len : |<--int32_t -->|<-- int16_t-->|<-- int16_t --->|<--- int32_t --->|<--valuelen->|<--uint64_t->|<-- int32_t-->|<-- int8_t --->| * len : |<--int32_t -->|<-- int16_t-->|<-- int8_t --->|<--- int32_t --->|<--valuelen->|<--uint64_t->|<-- int32_t-->|<-- int8_t --->|
*/ */
#ifdef __cplusplus #ifdef __cplusplus
@ -40,11 +41,10 @@ IndexCache *indexCacheCreate();
void indexCacheDestroy(void *cache); void indexCacheDestroy(void *cache);
int indexCachePut(void *cache, int16_t fieldId, int16_t fieldType, const char *fieldValue, int32_t fvLen, int indexCachePut(void *cache, SIndexTerm *term, int16_t colId, int32_t version, uint64_t uid);
uint32_t version, uint64_t uid, int8_t operType);
int indexCacheGet(void *cache, uint64_t *rst); //int indexCacheGet(void *cache, uint64_t *rst);
int indexCacheSearch(void *cache, SIndexMultiTermQuery *query, SArray *result); int indexCacheSearch(void *cache, SIndexTermQuery *query, int16_t colId, int32_t version, SArray *result);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -74,7 +74,7 @@ void indexClose(SIndex *sIdx) {
return; return;
} }
int indexPut(SIndex *index, SIndexMultiTerm * fVals, int uid) { int indexPut(SIndex *index, SIndexMultiTerm * fVals, uint64_t uid) {
#ifdef USE_LUCENE #ifdef USE_LUCENE
index_document_t *doc = index_document_create(); index_document_t *doc = index_document_create();
@ -116,7 +116,7 @@ int indexPut(SIndex *index, SIndexMultiTerm * fVals, int uid) {
assert(fi != NULL); assert(fi != NULL);
int32_t colId = fi->colId; int32_t colId = fi->colId;
int32_t version = index->cVersion; int32_t version = index->cVersion;
int ret = indexCachePut(index->cache, colId, p->colType, p->colVal, p->nColVal, version, uid, p->operType); int ret = indexCachePut(index->cache, p, colId, version, uid);
if (ret != 0) { if (ret != 0) {
return ret; return ret;
} }
@ -275,6 +275,7 @@ void indexInit() {
} }
static int indexTermSearch(SIndex *sIdx, SIndexTermQuery *term, SArray **result) { static int indexTermSearch(SIndex *sIdx, SIndexTermQuery *term, SArray **result) {
return 0;
} }
static void indexInterResultsDestroy(SArray *results) { static void indexInterResultsDestroy(SArray *results) {
if (results == NULL) { return; } if (results == NULL) { return; }
@ -288,12 +289,17 @@ 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
SArray *first = taosArrayGetP(interResults, 0);
//taosArraySort(first, getCom)
if (oType == MUST) { if (oType == MUST) {
// tag1 condition && tag2 condition
} else if (oType == SHOULD) { } else if (oType == SHOULD) {
// tag1 condistion || tag2 condition // tag1 condistion || tag2 condition
} else if (oType == NOT) { } else if (oType == NOT) {
// not use currently // not use currently
} }
return 0; return 0;

View File

@ -103,14 +103,13 @@ void indexCacheDestroy(void *cache) {
free(pCache); free(pCache);
} }
int indexCachePut(void *cache, int16_t fieldId, int16_t fieldType, const char *fieldValue, int32_t fvLen, int indexCachePut(void *cache, SIndexTerm *term, int16_t colId, int32_t version, uint64_t uid) {
uint32_t version, uint64_t uid, int8_t operType) {
if (cache == NULL) { return -1;} if (cache == NULL) { return -1;}
IndexCache *pCache = cache; IndexCache *pCache = cache;
// encode data // encode data
int32_t total = sizeof(int32_t) + sizeof(fieldId) + sizeof(fieldType) + sizeof(fvLen) + fvLen + sizeof(version) + sizeof(uid) + sizeof(operType); int32_t total = sizeof(int32_t) + sizeof(colId) + sizeof(term->colType) + sizeof(term->nColVal) + term->nColVal + sizeof(version) + sizeof(uid) + sizeof(term->operType);
char *buf = calloc(1, total); char *buf = calloc(1, total);
char *p = buf; char *p = buf;
@ -118,16 +117,16 @@ int indexCachePut(void *cache, int16_t fieldId, int16_t fieldType, const char *f
memcpy(p, &total, sizeof(total)); memcpy(p, &total, sizeof(total));
p += sizeof(total); p += sizeof(total);
memcpy(p, &fieldId, sizeof(fieldId)); memcpy(p, &colId, sizeof(colId));
p += sizeof(fieldId); p += sizeof(colId);
memcpy(p, &fieldType, sizeof(fieldType)); memcpy(p, &term->colType, sizeof(term->colType));
p += sizeof(fieldType); p += sizeof(term->colType);
memcpy(p, &fvLen, sizeof(fvLen)); memcpy(p, &term->nColVal, sizeof(term->nColVal));
p += sizeof(fvLen); p += sizeof(term->nColVal);
memcpy(p, fieldValue, fvLen); memcpy(p, term->colVal, term->nColVal);
p += fvLen; p += term->nColVal;
memcpy(p, &version, sizeof(version)); memcpy(p, &version, sizeof(version));
p += sizeof(version); p += sizeof(version);
@ -135,8 +134,8 @@ int indexCachePut(void *cache, int16_t fieldId, int16_t fieldType, const char *f
memcpy(p, &uid, sizeof(uid)); memcpy(p, &uid, sizeof(uid));
p += sizeof(uid); p += sizeof(uid);
memcpy(p, &operType, sizeof(operType)); memcpy(p, &term->operType, sizeof(term->operType));
p += sizeof(operType); p += sizeof(term->operType);
tSkipListPut(pCache->skiplist, (void *)buf); tSkipListPut(pCache->skiplist, (void *)buf);
// encode end // encode end
@ -146,7 +145,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, SIndexMultiTermQuery *query, SArray *result) { int indexCacheSearch(void *cache, SIndexTermQuery *query, int16_t colId, int32_t version, SArray *result) {
return 0;
return 0;
} }