index_tfile.h 3.1 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
// tfile header content
dengyihao's avatar
dengyihao 已提交
30 31
// |<---suid--->|<---version--->|<--colLen-->|<-colName->|<---type-->|
// |<-uint64_t->|<---int32_t--->|<--int32_t->|<-colLen-->|<-uint8_t->|
32

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

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 {
dengyihao's avatar
dengyihao 已提交
44 45 46 47 48
  uint64_t suid;
  uint8_t  colType;
  int32_t  version;
  char *   colName;
  int32_t  nColName;
49
} 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
  TFileHeader header;
dengyihao's avatar
dengyihao 已提交
63 64 65
} TFileWriter;

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

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

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

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

92 93 94 95 96
// 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 已提交
97

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

dengyihao's avatar
dengyihao 已提交
101
TFileWriter *tfileWriterCreate(WriterCtx *ctx, TFileHeader *header);
102
void         tfileWriterDestroy(TFileWriter *tw);
dengyihao's avatar
dengyihao 已提交
103 104
int          tfileWriterPut(TFileWriter *tw, const char *key, int32_t nKey, const char *val, int32_t nVal);
int          tfileWriterFinish(TFileWriter *tw);
dengyihao's avatar
dengyihao 已提交
105

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

dengyihao's avatar
dengyihao 已提交
111 112 113 114 115 116
#ifdef __cplusplus
}

#endif

#endif