indexInt.h 4.2 KB
Newer Older
H
refact  
Hongze Cheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * 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 _TD_INDEX_INT_H_
#define _TD_INDEX_INT_H_

S
Shengliang Guan 已提交
19 20
#include "os.h"

dengyihao's avatar
dengyihao 已提交
21
#include "index.h"
dengyihao's avatar
dengyihao 已提交
22
#include "taos.h"
S
Shengliang Guan 已提交
23
#include "tarray.h"
dengyihao's avatar
dengyihao 已提交
24
#include "tchecksum.h"
25 26
#include "thash.h"
#include "tlog.h"
dengyihao's avatar
dengyihao 已提交
27
#include "tlrucache.h"
S
Shengliang Guan 已提交
28
#include "tutil.h"
dengyihao's avatar
dengyihao 已提交
29

H
refact  
Hongze Cheng 已提交
30 31 32 33
#ifdef __cplusplus
extern "C" {
#endif

dengyihao's avatar
dengyihao 已提交
34
// clang-format off
dengyihao's avatar
dengyihao 已提交
35 36 37 38 39 40
#define indexFatal(...) do { if (idxDebugFlag & DEBUG_FATAL) {  taosPrintLog("IDX FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while (0)
#define indexError(...) do { if (idxDebugFlag & DEBUG_ERROR) {  taosPrintLog("IDX ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while (0)
#define indexWarn(...)  do { if (idxDebugFlag & DEBUG_WARN)  {  taosPrintLog("IDX WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while (0)
#define indexInfo(...)  do { if (idxDebugFlag & DEBUG_INFO)  { taosPrintLog("IDX ", DEBUG_INFO, 255, __VA_ARGS__); } } while (0)
#define indexDebug(...) do { if (idxDebugFlag & DEBUG_DEBUG) { taosPrintLog("IDX ", DEBUG_DEBUG, idxDebugFlag, __VA_ARGS__);} } while (0)
#define indexTrace(...) do { if (idxDebugFlag & DEBUG_TRACE) { taosPrintLog("IDX", DEBUG_TRACE, idxDebugFlag, __VA_ARGS__);} } while (0)
dengyihao's avatar
dengyihao 已提交
41 42
// clang-format on

dengyihao's avatar
dengyihao 已提交
43 44
extern void* indexQhandle;

dengyihao's avatar
dengyihao 已提交
45
typedef enum { LT, LE, GT, GE, CONTAINS, EQ } RangeType;
46
typedef enum { kTypeValue, kTypeDeletion } STermValueType;
dengyihao's avatar
dengyihao 已提交
47
typedef enum { kRebuild, kFinished } SIdxStatus;
dengyihao's avatar
dengyihao 已提交
48

dengyihao's avatar
dengyihao 已提交
49
typedef struct SIndexStat {
dengyihao's avatar
dengyihao 已提交
50 51 52 53 54 55
  int32_t total;
  int32_t add;      //
  int32_t del;      //
  int32_t update;   //
  int32_t terms;    //
  int32_t distCol;  // distinct column
56
} SIndexStat;
dengyihao's avatar
dengyihao 已提交
57

dengyihao's avatar
dengyihao 已提交
58
struct SIndex {
dengyihao's avatar
dengyihao 已提交
59 60
  SIndexOpts opts;

dengyihao's avatar
dengyihao 已提交
61
  int64_t   refId;
dengyihao's avatar
dengyihao 已提交
62 63 64
  void*     cache;
  void*     tindex;
  SHashObj* colObj;  // < field name, field id>
65

dengyihao's avatar
dengyihao 已提交
66 67
  int64_t    suid;     // current super table id, -1 is normal table
  int32_t    version;  // current version allocated to cache
dengyihao's avatar
dengyihao 已提交
68 69
  SLRUCache* lru;
  char*      path;
dengyihao's avatar
dengyihao 已提交
70

dengyihao's avatar
dengyihao 已提交
71
  int8_t        status;
dengyihao's avatar
dengyihao 已提交
72
  SIndexStat    stat;
wafwerar's avatar
wafwerar 已提交
73
  TdThreadMutex mtx;
dengyihao's avatar
dengyihao 已提交
74
  tsem_t        sem;
dengyihao's avatar
dengyihao 已提交
75
  bool          quit;
dengyihao's avatar
dengyihao 已提交
76 77
};

dengyihao's avatar
dengyihao 已提交
78
struct SIndexMultiTermQuery {
79
  EIndexOperatorType opera;
dengyihao's avatar
dengyihao 已提交
80
  SArray*            query;
dengyihao's avatar
dengyihao 已提交
81 82 83 84
};

// field and key;
typedef struct SIndexTerm {
85 86 87
  int64_t            suid;
  SIndexOperOnColumn operType;  // oper type, add/del/update
  uint8_t            colType;   // term data type, str/interger/json
dengyihao's avatar
dengyihao 已提交
88
  char*              colName;
89
  int32_t            nColName;
dengyihao's avatar
dengyihao 已提交
90
  char*              colVal;
91
  int32_t            nColVal;
dengyihao's avatar
dengyihao 已提交
92 93 94
} SIndexTerm;

typedef struct SIndexTermQuery {
dengyihao's avatar
dengyihao 已提交
95
  SIndexTerm*     term;
dengyihao's avatar
dengyihao 已提交
96
  EIndexQueryType qType;
dengyihao's avatar
dengyihao 已提交
97 98
} SIndexTermQuery;

dengyihao's avatar
dengyihao 已提交
99 100 101
typedef struct Iterate Iterate;

typedef struct IterateValue {
dengyihao's avatar
dengyihao 已提交
102 103 104 105
  int8_t   type;  // opera type, ADD_VALUE/DELETE_VALUE
  uint64_t ver;   // data ver, tfile data version is 0
  char*    colVal;

dengyihao's avatar
dengyihao 已提交
106
  SArray* val;
dengyihao's avatar
dengyihao 已提交
107 108 109 110 111 112 113
} IterateValue;

typedef struct Iterate {
  void*        iter;
  IterateValue val;
  bool (*next)(Iterate* iter);
  IterateValue* (*getValue)(Iterate* iter);
dengyihao's avatar
dengyihao 已提交
114
} Iterate;
dengyihao's avatar
dengyihao 已提交
115 116 117

void iterateValueDestroy(IterateValue* iv, bool destroy);

dengyihao's avatar
dengyihao 已提交
118 119 120 121 122 123
typedef struct TFileCacheKey {
  uint64_t suid;
  uint8_t  colType;
  char*    colName;
  int32_t  nColName;
} ICacheKey;
dengyihao's avatar
dengyihao 已提交
124 125 126

int32_t idxSerialCacheKey(ICacheKey* key, char* buf);

dengyihao's avatar
dengyihao 已提交
127
int idxFlushCacheToTFile(SIndex* sIdx, void*, bool quit);
dengyihao's avatar
dengyihao 已提交
128

dengyihao's avatar
dengyihao 已提交
129 130 131 132
int64_t idxAddRef(void* p);
int32_t idxRemoveRef(int64_t ref);
void    idxAcquireRef(int64_t ref);
void    idxReleaseRef(int64_t ref);
dengyihao's avatar
dengyihao 已提交
133

dengyihao's avatar
dengyihao 已提交
134
#define IDX_TYPE_CONTAIN_EXTERN_TYPE(ty, exTy) (((ty >> 4) & (exTy)) != 0)
dengyihao's avatar
dengyihao 已提交
135

dengyihao's avatar
dengyihao 已提交
136
#define IDX_TYPE_GET_TYPE(ty) (ty & 0x0F)
dengyihao's avatar
dengyihao 已提交
137

dengyihao's avatar
dengyihao 已提交
138 139 140 141 142
#define IDX_TYPE_ADD_EXTERN_TYPE(ty, exTy) \
  do {                                     \
    uint8_t oldTy = ty;                    \
    ty = (ty >> 4) | exTy;                 \
    ty = (ty << 4) | oldTy;                \
143
  } while (0)
dengyihao's avatar
dengyihao 已提交
144

H
refact  
Hongze Cheng 已提交
145 146 147 148
#ifdef __cplusplus
}
#endif

dengyihao's avatar
dengyihao 已提交
149
#endif /*_TD_INDEX_INT_H_*/