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

update index TFile write

上级 489179b9
......@@ -76,7 +76,7 @@ struct SIndexMultiTermQuery {
// field and key;
typedef struct SIndexTerm {
int64_t suid;
int64_t suid;
SIndexOperOnColumn operType; // oper type, add/del/update
uint8_t colType; // term data type, str/interger/json
char *colName;
......
......@@ -19,31 +19,76 @@
#include "indexInt.h"
#include "tlockfree.h"
#include "index_tfile.h"
#include "index_fst_counting_writer.h"
#include "index_fst.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct TFileCacheKey {
uint64_t suid;
uint8_t colType;
int32_t version;
const char *colName;
int32_t nColName;
} TFileCacheKey;
// table cache
// refactor to LRU cache later
typedef struct TFileCache {
SHashObj *tableCache;
int16_t capacity;
// add more param
} TFileCache;
typedef struct TFileWriter {
FstBuilder *fb;
WriterCtx *wc;
} TFileWriter;
typedef struct TFileReader {
T_REF_DECLARE()
Fst *fst;
} TFileReader;
typedef struct IndexTFile {
T_REF_DECLARE()
char *path;
TFileReader *tb;
TFileWriter *tw;
} IndexTFile;
typedef struct TFileWriterOpt {
uint64_t suid;
int8_t colType;
char *colName;
int32_t nColName;
int32_t version;
} TFileWriterOpt;
typedef struct TFileReaderOpt {
uint64_t suid;
char *colName;
int32_t nColName;
} TFileReaderOpt;
// tfile cache
TFileCache *tfileCacheCreate();
void tfileCacheDestroy(TFileCache *tcache);
TFileReader* tfileCacheGet(TFileCache *tcache, TFileCacheKey *key);
void tfileCachePut(TFileCache *tcache, TFileCacheKey *key, TFileReader *reader);
TFileWriter *tfileWriterCreate(const char *suid, const char *colName);
IndexTFile *indexTFileCreate();
int indexTFilePut(void *tfile, SIndexTerm *term, uint64_t uid);
int indexTFilePut(void *tfile, SIndexTerm *term, uint64_t uid);
int indexTFileSearch(void *tfile, SIndexTermQuery *query, SArray *result);
......
......@@ -16,9 +16,67 @@
#include "index_tfile.h"
#include "index_fst.h"
#define SERIALIZE_TO_BUF(buf, key, mem) \
do { \
memcpy(buf, &key->mem, sizeof(key->mem)); \
buf += sizeof(key->mem); \
} while (0)
#define SERIALIZE_STR_TO_BUF(buf, key, mem, len) \
do { \
memcpy(buf, key->mem, len); \
buf += len; \
} while (0)
#define SERIALIZE_DELIMITER_TO_BUF(buf, delim) \
do { \
char c = delim; \
memcpy(buf, &c, sizeof(c)); \
buf += sizeof(c); \
} while (0)
static void tfileSerialCacheKey(TFileCacheKey *key, char *buf) {
SERIALIZE_TO_BUF(buf, key, suid);
SERIALIZE_DELIMITER_TO_BUF(buf, '_');
SERIALIZE_TO_BUF(buf, key, colType);
SERIALIZE_DELIMITER_TO_BUF(buf, '_');
SERIALIZE_TO_BUF(buf, key, version);
SERIALIZE_DELIMITER_TO_BUF(buf, '_');
SERIALIZE_STR_TO_BUF(buf, key, colName, key->nColName);
}
TFileCache *tfileCacheCreate() {
TFileCache *tcache = calloc(1, sizeof(TFileCache));
if (tcache == NULL) { return NULL; }
tcache->tableCache = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
tcache->capacity = 64;
return tcache;
}
void tfileCacheDestroy(TFileCache *tcache) {
}
TFileReader *tfileCacheGet(TFileCache *tcache, TFileCacheKey *key) {
char buf[128] = {0};
tfileSerialCacheKey(key, buf);
TFileReader *reader = taosHashGet(tcache->tableCache, buf, strlen(buf));
return reader;
}
void tfileCachePut(TFileCache *tcache, TFileCacheKey *key, TFileReader *reader) {
char buf[128] = {0};
tfileSerialCacheKey(key, buf);
taosHashPut(tcache->tableCache, buf, strlen(buf), &reader, sizeof(void *));
return;
}
IndexTFile *indexTFileCreate() {
IndexTFile *tfile = calloc(1, sizeof(IndexTFile));
return tfile;
}
void IndexTFileDestroy(IndexTFile *tfile) {
......@@ -28,10 +86,20 @@ void IndexTFileDestroy(IndexTFile *tfile) {
int indexTFileSearch(void *tfile, SIndexTermQuery *query, SArray *result) {
IndexTFile *ptfile = (IndexTFile *)tfile;
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};
return 0;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册