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_

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

void iterateValueDestroy(IterateValue* iv, bool destroy);

dengyihao's avatar
dengyihao 已提交
109 110 111 112 113 114 115
extern void* indexQhandle;

int indexFlushCacheTFile(SIndex* sIdx, void*);

#define indexFatal(...)                                                               \
  do {                                                                                \
    if (sDebugFlag & DEBUG_FATAL) { taosPrintLog("index FATAL ", 255, __VA_ARGS__); } \
116
  } while (0)
dengyihao's avatar
dengyihao 已提交
117 118 119
#define indexError(...)                                                               \
  do {                                                                                \
    if (sDebugFlag & DEBUG_ERROR) { taosPrintLog("index ERROR ", 255, __VA_ARGS__); } \
120
  } while (0)
dengyihao's avatar
dengyihao 已提交
121 122 123
#define indexWarn(...)                                                              \
  do {                                                                              \
    if (sDebugFlag & DEBUG_WARN) { taosPrintLog("index WARN ", 255, __VA_ARGS__); } \
124
  } while (0)
dengyihao's avatar
dengyihao 已提交
125 126 127
#define indexInfo(...)                                                         \
  do {                                                                         \
    if (sDebugFlag & DEBUG_INFO) { taosPrintLog("index ", 255, __VA_ARGS__); } \
128
  } while (0)
dengyihao's avatar
dengyihao 已提交
129 130 131
#define indexDebug(...)                                                                \
  do {                                                                                 \
    if (sDebugFlag & DEBUG_DEBUG) { taosPrintLog("index ", sDebugFlag, __VA_ARGS__); } \
132
  } while (0)
dengyihao's avatar
dengyihao 已提交
133 134 135
#define indexTrace(...)                                                                \
  do {                                                                                 \
    if (sDebugFlag & DEBUG_TRACE) { taosPrintLog("index ", sDebugFlag, __VA_ARGS__); } \
136
  } while (0)
dengyihao's avatar
dengyihao 已提交
137

H
refact  
Hongze Cheng 已提交
138 139 140 141
#ifdef __cplusplus
}
#endif

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