indexInt.h 5.3 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"
S
Shengliang Guan 已提交
27
#include "tutil.h"
dengyihao's avatar
dengyihao 已提交
28 29 30 31 32

#ifdef USE_LUCENE
#include <lucene++/Lucene_c.h>
#endif

H
refact  
Hongze Cheng 已提交
33 34 35 36
#ifdef __cplusplus
extern "C" {
#endif

37
typedef enum { kTypeValue, kTypeDeletion } STermValueType;
dengyihao's avatar
dengyihao 已提交
38

dengyihao's avatar
dengyihao 已提交
39
typedef struct SIndexStat {
40 41 42 43 44 45
  int32_t totalAdded;    //
  int32_t totalDeled;    //
  int32_t totalUpdated;  //
  int32_t totalTerms;    //
  int32_t distinctCol;   // distinct column
} SIndexStat;
dengyihao's avatar
dengyihao 已提交
46

dengyihao's avatar
dengyihao 已提交
47
struct SIndex {
48
#ifdef USE_LUCENE
dengyihao's avatar
dengyihao 已提交
49
  index_t* index;
50
#endif
dengyihao's avatar
dengyihao 已提交
51 52 53
  void*     cache;
  void*     tindex;
  SHashObj* colObj;  // < field name, field id>
54 55 56 57

  int64_t suid;      // current super table id, -1 is normal table
  int32_t cVersion;  // current version allocated to cache

dengyihao's avatar
dengyihao 已提交
58 59
  char* path;

60 61 62
  SIndexStat      stat;
  pthread_mutex_t mtx;
};
dengyihao's avatar
dengyihao 已提交
63 64

struct SIndexOpts {
65
#ifdef USE_LUCENE
dengyihao's avatar
dengyihao 已提交
66
  void* opts;
67
#endif
dengyihao's avatar
dengyihao 已提交
68 69

#ifdef USE_INVERTED_INDEX
70
  int32_t cacheSize;  // MB
dengyihao's avatar
dengyihao 已提交
71 72
  // add cache module later
#endif
dengyihao's avatar
dengyihao 已提交
73 74
};

dengyihao's avatar
dengyihao 已提交
75
struct SIndexMultiTermQuery {
76
  EIndexOperatorType opera;
dengyihao's avatar
dengyihao 已提交
77
  SArray*            query;
dengyihao's avatar
dengyihao 已提交
78 79 80 81
};

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

typedef struct SIndexTermQuery {
dengyihao's avatar
dengyihao 已提交
92
  SIndexTerm*     term;
dengyihao's avatar
dengyihao 已提交
93
  EIndexQueryType qType;
dengyihao's avatar
dengyihao 已提交
94 95
} SIndexTermQuery;

dengyihao's avatar
dengyihao 已提交
96 97 98
typedef struct Iterate Iterate;

typedef struct IterateValue {
dengyihao's avatar
dengyihao 已提交
99 100 101
  int8_t  type;
  char*   colVal;
  SArray* val;
dengyihao's avatar
dengyihao 已提交
102 103 104 105 106 107 108
} IterateValue;

typedef struct Iterate {
  void*        iter;
  IterateValue val;
  bool (*next)(Iterate* iter);
  IterateValue* (*getValue)(Iterate* iter);
dengyihao's avatar
dengyihao 已提交
109
} Iterate;
dengyihao's avatar
dengyihao 已提交
110 111 112

void iterateValueDestroy(IterateValue* iv, bool destroy);

dengyihao's avatar
dengyihao 已提交
113 114
extern void* indexQhandle;

dengyihao's avatar
dengyihao 已提交
115 116 117 118 119 120 121
typedef struct TFileCacheKey {
  uint64_t suid;
  uint8_t  colType;
  char*    colName;
  int32_t  nColName;
} ICacheKey;

dengyihao's avatar
dengyihao 已提交
122
int indexFlushCacheToTFile(SIndex* sIdx, void*);
dengyihao's avatar
dengyihao 已提交
123

dengyihao's avatar
dengyihao 已提交
124
int32_t indexSerialCacheKey(ICacheKey* key, char* buf);
dengyihao's avatar
dengyihao 已提交
125 126
// int32_t indexSerialKey(ICacheKey* key, char* buf);
// int32_t indexSerialTermKey(SIndexTerm* itm, char* buf);
dengyihao's avatar
dengyihao 已提交
127

128 129 130 131 132
#define indexFatal(...)                                            \
  do {                                                             \
    if (sDebugFlag & DEBUG_FATAL) {                                \
      taosPrintLog("index FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); \
    }                                                              \
133
  } while (0)
134 135 136 137 138
#define indexError(...)                                            \
  do {                                                             \
    if (sDebugFlag & DEBUG_ERROR) {                                \
      taosPrintLog("index ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); \
    }                                                              \
139
  } while (0)
140 141 142 143 144
#define indexWarn(...)                                           \
  do {                                                           \
    if (sDebugFlag & DEBUG_WARN) {                               \
      taosPrintLog("index WARN ", DEBUG_WARN, 255, __VA_ARGS__); \
    }                                                            \
145
  } while (0)
146 147 148 149 150
#define indexInfo(...)                                      \
  do {                                                      \
    if (sDebugFlag & DEBUG_INFO) {                          \
      taosPrintLog("index ", DEBUG_INFO, 255, __VA_ARGS__); \
    }                                                       \
151
  } while (0)
152 153 154 155 156
#define indexDebug(...)                                             \
  do {                                                              \
    if (sDebugFlag & DEBUG_DEBUG) {                                 \
      taosPrintLog("index ", DEBUG_DEBUG, sDebugFlag, __VA_ARGS__); \
    }                                                               \
157
  } while (0)
158 159 160 161 162
#define indexTrace(...)                                             \
  do {                                                              \
    if (sDebugFlag & DEBUG_TRACE) {                                 \
      taosPrintLog("index ", DEBUG_TRACE, sDebugFlag, __VA_ARGS__); \
    }                                                               \
dengyihao's avatar
dengyihao 已提交
163 164 165 166 167 168 169 170 171
  } while (0)

#define INDEX_TYPE_CONTAIN_EXTERN_TYPE(ty, exTy) (((ty >> 4) & (exTy)) != 0)
#define INDEX_TYPE_GET_TYPE(ty) (ty & 0x0F)
#define INDEX_TYPE_ADD_EXTERN_TYPE(ty, exTy) \
  do {                                       \
    uint8_t oldTy = ty;                      \
    ty = (ty >> 4) | exTy;                   \
    ty = (ty << 4) | oldTy;                  \
172
  } while (0)
dengyihao's avatar
dengyihao 已提交
173

H
refact  
Hongze Cheng 已提交
174 175 176 177
#ifdef __cplusplus
}
#endif

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