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

update index TFile write

上级 192552be
...@@ -96,7 +96,8 @@ TFileReader *tfileCacheGet(TFileCache *tcache, TFileCacheKey *key); ...@@ -96,7 +96,8 @@ TFileReader *tfileCacheGet(TFileCache *tcache, TFileCacheKey *key);
void tfileCachePut(TFileCache *tcache, TFileCacheKey *key, TFileReader *reader); void tfileCachePut(TFileCache *tcache, TFileCacheKey *key, TFileReader *reader);
TFileReader *tfileReaderCreate(WriterCtx *ctx); TFileReader *tfileReaderCreate(WriterCtx *ctx);
void TFileReaderDestroy(TFileReader *reader); void tfileReaderDestroy(TFileReader *reader);
int tfileReaderSearch(TFileReader *reader, SIndexTermQuery *query, SArray *result);
TFileWriter *tfileWriterCreate(WriterCtx *ctx, TFileHeader *header); TFileWriter *tfileWriterCreate(WriterCtx *ctx, TFileHeader *header);
void tfileWriterDestroy(TFileWriter *tw); void tfileWriterDestroy(TFileWriter *tw);
......
...@@ -117,7 +117,7 @@ TFileCache *tfileCacheCreate(const char *path) { ...@@ -117,7 +117,7 @@ TFileCache *tfileCacheCreate(const char *path) {
} }
TFileReader *reader = tfileReaderCreate(wc); TFileReader *reader = tfileReaderCreate(wc);
if (0 != tfileReadLoadHeader(reader)) { if (0 != tfileReadLoadHeader(reader)) {
TFileReaderDestroy(reader); tfileReaderDestroy(reader);
indexError("failed to load index header, index Id: %s", file); indexError("failed to load index header, index Id: %s", file);
goto End; goto End;
} }
...@@ -126,7 +126,6 @@ TFileCache *tfileCacheCreate(const char *path) { ...@@ -126,7 +126,6 @@ TFileCache *tfileCacheCreate(const char *path) {
TFileHeader * header = &reader->header; TFileHeader * header = &reader->header;
TFileCacheKey key = { TFileCacheKey key = {
.suid = header->suid, .version = header->version, .colName = header->colName, .nColName = strlen(header->colName), .colType = header->colType}; .suid = header->suid, .version = header->version, .colName = header->colName, .nColName = strlen(header->colName), .colType = header->colType};
char buf[128] = {0}; char buf[128] = {0};
tfileSerialCacheKey(&key, buf); tfileSerialCacheKey(&key, buf);
taosHashPut(tcache->tableCache, buf, strlen(buf), &reader, sizeof(void *)); taosHashPut(tcache->tableCache, buf, strlen(buf), &reader, sizeof(void *));
...@@ -147,7 +146,7 @@ void tfileCacheDestroy(TFileCache *tcache) { ...@@ -147,7 +146,7 @@ void tfileCacheDestroy(TFileCache *tcache) {
TFileReader *p = *reader; TFileReader *p = *reader;
indexInfo("drop table cache suid: %" PRIu64 ", colName: %s, colType: %d", p->header.suid, p->header.colName, p->header.colType); indexInfo("drop table cache suid: %" PRIu64 ", colName: %s, colType: %d", p->header.suid, p->header.colName, p->header.colType);
TFileReaderDestroy(p); tfileReaderDestroy(p);
reader = taosHashIterate(tcache->tableCache, reader); reader = taosHashIterate(tcache->tableCache, reader);
} }
taosHashCleanup(tcache->tableCache); taosHashCleanup(tcache->tableCache);
...@@ -175,13 +174,32 @@ TFileReader *tfileReaderCreate(WriterCtx *ctx) { ...@@ -175,13 +174,32 @@ TFileReader *tfileReaderCreate(WriterCtx *ctx) {
reader->ctx = ctx; reader->ctx = ctx;
return reader; return reader;
} }
void TFileReaderDestroy(TFileReader *reader) { void tfileReaderDestroy(TFileReader *reader) {
if (reader == NULL) { return; } if (reader == NULL) { return; }
// T_REF_INC(reader); // T_REF_INC(reader);
writerCtxDestroy(reader->ctx); writerCtxDestroy(reader->ctx);
free(reader); free(reader);
} }
int tfileReaderSearch(TFileReader *reader, SIndexTermQuery *query, SArray *result) {
SIndexTerm *term = query->term;
// refactor to callback later
if (query->qType == QUERY_TERM) {
uint64_t offset;
FstSlice key = fstSliceCreate(term->colVal, term->nColVal);
if (fstGet(reader->fst, &key, &offset)) {
//
} else {
indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, not found in tindex", term->suid, term->colName, term->colVal);
}
return 0;
} else if (query->qType == QUERY_PREFIX) {
//
//
}
return 0;
}
TFileWriter *tfileWriterCreate(WriterCtx *ctx, TFileHeader *header) { TFileWriter *tfileWriterCreate(WriterCtx *ctx, TFileHeader *header) {
// char pathBuf[128] = {0}; // char pathBuf[128] = {0};
// sprintf(pathBuf, "%s/% " PRIu64 "-%d-%d.tindex", path, suid, colId, version); // sprintf(pathBuf, "%s/% " PRIu64 "-%d-%d.tindex", path, suid, colId, version);
...@@ -196,7 +214,7 @@ TFileWriter *tfileWriterCreate(WriterCtx *ctx, TFileHeader *header) { ...@@ -196,7 +214,7 @@ TFileWriter *tfileWriterCreate(WriterCtx *ctx, TFileHeader *header) {
} }
TFileWriter *tw = calloc(1, sizeof(TFileWriter)); TFileWriter *tw = calloc(1, sizeof(TFileWriter));
if (tw == NULL) { if (tw == NULL) {
indexError("index: % " PRIu64 " failed to write header info"); indexError("index: %" PRIu64 " failed to alloc TFilerWriter", header->suid);
return NULL; return NULL;
} }
return tw; return tw;
...@@ -218,15 +236,14 @@ IndexTFile *indexTFileCreate(const char *path) { ...@@ -218,15 +236,14 @@ IndexTFile *indexTFileCreate(const char *path) {
void IndexTFileDestroy(IndexTFile *tfile) { free(tfile); } void IndexTFileDestroy(IndexTFile *tfile) { free(tfile); }
int indexTFileSearch(void *tfile, SIndexTermQuery *query, SArray *result) { int indexTFileSearch(void *tfile, SIndexTermQuery *query, SArray *result) {
if (tfile == NULL) { return -1; }
IndexTFile *pTfile = (IndexTFile *)tfile; IndexTFile *pTfile = (IndexTFile *)tfile;
if (pTfile == NULL) { return -1; }
SIndexTerm * term = query->term; SIndexTerm * term = query->term;
TFileCacheKey key = {.suid = term->suid, .colType = term->colType, .version = 0, .colName = term->colName, .nColName = term->nColName}; TFileCacheKey key = {.suid = term->suid, .colType = term->colType, .version = 0, .colName = term->colName, .nColName = term->nColName};
TFileReader *reader = tfileCacheGet(pTfile->cache, &key); TFileReader *reader = tfileCacheGet(pTfile->cache, &key);
return tfileReaderSearch(reader, query, result);
return 0;
} }
int indexTFilePut(void *tfile, SIndexTerm *term, uint64_t uid) { int indexTFilePut(void *tfile, SIndexTerm *term, uint64_t uid) {
TFileWriterOpt wOpt = {.suid = term->suid, .colType = term->colType, .colName = term->colName, .nColName = term->nColName, .version = 1}; TFileWriterOpt wOpt = {.suid = term->suid, .colType = term->colType, .colName = term->colName, .nColName = term->nColName, .version = 1};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册