update index TFile write
This commit is contained in:
parent
489179b980
commit
a0864b1c14
|
@ -76,7 +76,7 @@ struct SIndexMultiTermQuery {
|
||||||
|
|
||||||
// field and key;
|
// field and key;
|
||||||
typedef struct SIndexTerm {
|
typedef struct SIndexTerm {
|
||||||
int64_t suid;
|
int64_t suid;
|
||||||
SIndexOperOnColumn operType; // oper type, add/del/update
|
SIndexOperOnColumn operType; // oper type, add/del/update
|
||||||
uint8_t colType; // term data type, str/interger/json
|
uint8_t colType; // term data type, str/interger/json
|
||||||
char *colName;
|
char *colName;
|
||||||
|
|
|
@ -19,31 +19,76 @@
|
||||||
#include "indexInt.h"
|
#include "indexInt.h"
|
||||||
#include "tlockfree.h"
|
#include "tlockfree.h"
|
||||||
#include "index_tfile.h"
|
#include "index_tfile.h"
|
||||||
|
#include "index_fst_counting_writer.h"
|
||||||
#include "index_fst.h"
|
#include "index_fst.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#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 {
|
typedef struct TFileWriter {
|
||||||
FstBuilder *fb;
|
FstBuilder *fb;
|
||||||
|
WriterCtx *wc;
|
||||||
} TFileWriter;
|
} TFileWriter;
|
||||||
|
|
||||||
typedef struct TFileReader {
|
typedef struct TFileReader {
|
||||||
T_REF_DECLARE()
|
T_REF_DECLARE()
|
||||||
Fst *fst;
|
Fst *fst;
|
||||||
|
|
||||||
} TFileReader;
|
} TFileReader;
|
||||||
|
|
||||||
typedef struct IndexTFile {
|
typedef struct IndexTFile {
|
||||||
T_REF_DECLARE()
|
char *path;
|
||||||
TFileReader *tb;
|
TFileReader *tb;
|
||||||
TFileWriter *tw;
|
TFileWriter *tw;
|
||||||
} IndexTFile;
|
} 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();
|
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);
|
int indexTFileSearch(void *tfile, SIndexTermQuery *query, SArray *result);
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,67 @@
|
||||||
#include "index_tfile.h"
|
#include "index_tfile.h"
|
||||||
#include "index_fst.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 *indexTFileCreate() {
|
||||||
IndexTFile *tfile = calloc(1, sizeof(IndexTFile));
|
IndexTFile *tfile = calloc(1, sizeof(IndexTFile));
|
||||||
|
|
||||||
return tfile;
|
return tfile;
|
||||||
}
|
}
|
||||||
void IndexTFileDestroy(IndexTFile *tfile) {
|
void IndexTFileDestroy(IndexTFile *tfile) {
|
||||||
|
@ -28,10 +86,20 @@ void IndexTFileDestroy(IndexTFile *tfile) {
|
||||||
|
|
||||||
int indexTFileSearch(void *tfile, SIndexTermQuery *query, SArray *result) {
|
int indexTFileSearch(void *tfile, SIndexTermQuery *query, SArray *result) {
|
||||||
IndexTFile *ptfile = (IndexTFile *)tfile;
|
IndexTFile *ptfile = (IndexTFile *)tfile;
|
||||||
|
|
||||||
return 0;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue