index_tfile.h 2.9 KB
Newer Older
dengyihao's avatar
dengyihao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * 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"
dengyihao's avatar
dengyihao 已提交
20
#include "index_fst.h"
21 22 23
#include "index_fst_counting_writer.h"
#include "index_tfile.h"
#include "tlockfree.h"
dengyihao's avatar
dengyihao 已提交
24 25 26 27 28

#ifdef __cplusplus
extern "C" {
#endif

dengyihao's avatar
dengyihao 已提交
29 30 31
// tfile header
// |<---suid--->|<---version--->|<--colLen-->|<-colName->|<---type-->|
// |<-uint64_t->|<---int32_t--->|<--int32_t->|<-colLen-->|<-uint8_t->|
32

dengyihao's avatar
dengyihao 已提交
33 34 35
typedef struct TFileReadHeader {
  uint64_t suid;
  int32_t  version;
36 37
  char     colName[128];  //
  uint8_t  colType;
dengyihao's avatar
dengyihao 已提交
38 39
} TFileReadHeader;

40
#define TFILE_HEADER_SIZE (sizeof(TFILE_HEADER_SIZE) + sizeof(uint32_t));
dengyihao's avatar
dengyihao 已提交
41
#define TFILE_HADER_PRE_SIZE (sizeof(uint64_t) + sizeof(int32_t) + sizeof(int32_t))
dengyihao's avatar
dengyihao 已提交
42 43

typedef struct TFileCacheKey {
44 45 46
  uint64_t    suid;
  uint8_t     colType;
  int32_t     version;
dengyihao's avatar
dengyihao 已提交
47
  const char *colName;
48 49
  int32_t     nColName;
} TFileCacheKey;
dengyihao's avatar
dengyihao 已提交
50 51 52 53

// table cache
// refactor to LRU cache later
typedef struct TFileCache {
54 55 56
  SHashObj *tableCache;
  int16_t   capacity;
  // add more param
dengyihao's avatar
dengyihao 已提交
57 58
} TFileCache;

dengyihao's avatar
dengyihao 已提交
59 60
typedef struct TFileWriter {
  FstBuilder *fb;
61
  WriterCtx * ctx;
dengyihao's avatar
dengyihao 已提交
62 63 64
} TFileWriter;

typedef struct TFileReader {
65 66 67 68 69
  T_REF_DECLARE()
  Fst *           fst;
  WriterCtx *     ctx;
  TFileReadHeader header;
} TFileReader;
dengyihao's avatar
dengyihao 已提交
70

dengyihao's avatar
dengyihao 已提交
71
typedef struct IndexTFile {
72 73 74
  char *       path;
  TFileCache * cache;
  TFileWriter *tw;
dengyihao's avatar
dengyihao 已提交
75 76
} IndexTFile;

dengyihao's avatar
dengyihao 已提交
77 78 79
typedef struct TFileWriterOpt {
  uint64_t suid;
  int8_t   colType;
80 81
  char *   colName;
  int32_t  nColName;
dengyihao's avatar
dengyihao 已提交
82
  int32_t  version;
83
} TFileWriterOpt;
dengyihao's avatar
dengyihao 已提交
84 85

typedef struct TFileReaderOpt {
86 87 88
  uint64_t suid;
  char *   colName;
  int32_t  nColName;
dengyihao's avatar
dengyihao 已提交
89 90
} TFileReaderOpt;

91 92 93 94 95
// tfile cache, manage tindex reader
TFileCache * tfileCacheCreate(const char *path);
void         tfileCacheDestroy(TFileCache *tcache);
TFileReader *tfileCacheGet(TFileCache *tcache, TFileCacheKey *key);
void         tfileCachePut(TFileCache *tcache, TFileCacheKey *key, TFileReader *reader);
dengyihao's avatar
dengyihao 已提交
96

97 98
TFileReader *tfileReaderCreate();
void         TFileReaderDestroy(TFileReader *reader);
dengyihao's avatar
dengyihao 已提交
99

dengyihao's avatar
dengyihao 已提交
100
TFileWriter *tfileWriterCreate(const char *suid, const char *colName);
101
void         tfileWriterDestroy(TFileWriter *tw);
dengyihao's avatar
dengyihao 已提交
102

103
//
dengyihao's avatar
dengyihao 已提交
104
IndexTFile *indexTFileCreate(const char *path);
105 106
int         indexTFilePut(void *tfile, SIndexTerm *term, uint64_t uid);
int         indexTFileSearch(void *tfile, SIndexTermQuery *query, SArray *result);
dengyihao's avatar
dengyihao 已提交
107

dengyihao's avatar
dengyihao 已提交
108 109 110 111 112 113
#ifdef __cplusplus
}

#endif

#endif