indexInt.h 4.4 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_

dengyihao's avatar
dengyihao 已提交
19
#include "index.h"
dengyihao's avatar
dengyihao 已提交
20 21
#include "index_fst.h"
#include "taos.h"
dengyihao's avatar
dengyihao 已提交
22
#include "tchecksum.h"
23 24
#include "thash.h"
#include "tlog.h"
dengyihao's avatar
dengyihao 已提交
25 26 27 28 29

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

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

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

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

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

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

dengyihao's avatar
dengyihao 已提交
55 56
  char* path;

57 58 59
  SIndexStat      stat;
  pthread_mutex_t mtx;
};
dengyihao's avatar
dengyihao 已提交
60 61

struct SIndexOpts {
62
#ifdef USE_LUCENE
dengyihao's avatar
dengyihao 已提交
63
  void* opts;
64
#endif
dengyihao's avatar
dengyihao 已提交
65 66

#ifdef USE_INVERTED_INDEX
67
  int32_t cacheSize;  // MB
dengyihao's avatar
dengyihao 已提交
68 69
  // add cache module later
#endif
dengyihao's avatar
dengyihao 已提交
70 71
};

dengyihao's avatar
dengyihao 已提交
72
struct SIndexMultiTermQuery {
73
  EIndexOperatorType opera;
dengyihao's avatar
dengyihao 已提交
74
  SArray*            query;
dengyihao's avatar
dengyihao 已提交
75 76 77 78
};

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

typedef struct SIndexTermQuery {
dengyihao's avatar
dengyihao 已提交
89
  SIndexTerm*     term;
dengyihao's avatar
dengyihao 已提交
90
  EIndexQueryType qType;
dengyihao's avatar
dengyihao 已提交
91 92
} SIndexTermQuery;

dengyihao's avatar
dengyihao 已提交
93 94 95
typedef struct Iterate Iterate;

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

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

void iterateValueDestroy(IterateValue* iv, bool destroy);

dengyihao's avatar
dengyihao 已提交
110 111
extern void* indexQhandle;

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

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

dengyihao's avatar
dengyihao 已提交
121 122
int32_t indexSerialCacheKey(ICacheKey* key, char* buf);

dengyihao's avatar
dengyihao 已提交
123 124 125
#define indexFatal(...)                                                               \
  do {                                                                                \
    if (sDebugFlag & DEBUG_FATAL) { taosPrintLog("index FATAL ", 255, __VA_ARGS__); } \
126
  } while (0)
dengyihao's avatar
dengyihao 已提交
127 128 129
#define indexError(...)                                                               \
  do {                                                                                \
    if (sDebugFlag & DEBUG_ERROR) { taosPrintLog("index ERROR ", 255, __VA_ARGS__); } \
130
  } while (0)
dengyihao's avatar
dengyihao 已提交
131 132 133
#define indexWarn(...)                                                              \
  do {                                                                              \
    if (sDebugFlag & DEBUG_WARN) { taosPrintLog("index WARN ", 255, __VA_ARGS__); } \
134
  } while (0)
dengyihao's avatar
dengyihao 已提交
135 136 137
#define indexInfo(...)                                                         \
  do {                                                                         \
    if (sDebugFlag & DEBUG_INFO) { taosPrintLog("index ", 255, __VA_ARGS__); } \
138
  } while (0)
dengyihao's avatar
dengyihao 已提交
139 140 141
#define indexDebug(...)                                                                \
  do {                                                                                 \
    if (sDebugFlag & DEBUG_DEBUG) { taosPrintLog("index ", sDebugFlag, __VA_ARGS__); } \
142
  } while (0)
dengyihao's avatar
dengyihao 已提交
143 144 145
#define indexTrace(...)                                                                \
  do {                                                                                 \
    if (sDebugFlag & DEBUG_TRACE) { taosPrintLog("index ", sDebugFlag, __VA_ARGS__); } \
146
  } while (0)
dengyihao's avatar
dengyihao 已提交
147

H
refact  
Hongze Cheng 已提交
148 149 150 151
#ifdef __cplusplus
}
#endif

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