tsdb.h 6.5 KB
Newer Older
H
refact  
Hongze Cheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * 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/>.
 */

H
refact  
Hongze Cheng 已提交
16 17
#ifndef _TD_TSDB_H_
#define _TD_TSDB_H_
H
refact  
Hongze Cheng 已提交
18

S
Shengliang Guan 已提交
19
#include "tmallocator.h"
H
more  
Hongze Cheng 已提交
20
#include "meta.h"
S
common  
Shengliang Guan 已提交
21
#include "tcommon.h"
S
Shengliang Guan 已提交
22
#include "tfs.h"
H
more  
Hongze Cheng 已提交
23

H
refact  
Hongze Cheng 已提交
24 25 26 27
#ifdef __cplusplus
extern "C" {
#endif

H
Hongze Cheng 已提交
28 29 30 31 32 33 34 35 36 37 38
typedef struct SDataStatis {
  int16_t colId;
  int64_t sum;
  int64_t max;
  int64_t min;
  int16_t maxIndex;
  int16_t minIndex;
  int16_t numOfNull;
} SDataStatis;

typedef struct STable {
H
more  
Hongze Cheng 已提交
39
  uint64_t  tid;
H
Hongze Cheng 已提交
40 41 42 43
  uint64_t  uid;
  STSchema *pSchema;
} STable;

44 45 46 47
#define BLOCK_LOAD_OFFSET_SEQ_ORDER   1
#define BLOCK_LOAD_TABLE_SEQ_ORDER    2
#define BLOCK_LOAD_TABLE_RR_ORDER     3

H
Hongze Cheng 已提交
48 49 50
#define TABLE_TID(t) (t)->tid
#define TABLE_UID(t) (t)->uid

H
refact  
Hongze Cheng 已提交
51
// TYPES EXPOSED
H
more  
Hongze Cheng 已提交
52 53 54
typedef struct STsdb STsdb;

typedef struct STsdbCfg {
H
Hongze Cheng 已提交
55
  int8_t   precision;
H
more  
Hongze Cheng 已提交
56
  uint64_t lruCacheSize;
H
Hongze Cheng 已提交
57
  int32_t  daysPerFile;
H
Hongze Cheng 已提交
58 59 60 61 62 63
  int32_t  minRowsPerFileBlock;
  int32_t  maxRowsPerFileBlock;
  int32_t  keep;
  int32_t  keep1;
  int32_t  keep2;
  int8_t   update;
H
more  
Hongze Cheng 已提交
64
  int8_t   compression;
H
more  
Hongze Cheng 已提交
65
} STsdbCfg;
H
more  
Hongze Cheng 已提交
66

67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
// query condition to build multi-table data block iterator
typedef struct STsdbQueryCond {
  STimeWindow  twindow;
  int32_t      order;             // desc|asc order to iterate the data block
  int32_t      numOfCols;
  SColumnInfo *colList;
  bool         loadExternalRows;  // load external rows or not
  int32_t      type;              // data block load type:
} STsdbQueryCond;

typedef struct {
  TSKEY    lastKey;
  uint64_t uid;
} STableKeyInfo;

H
refact  
Hongze Cheng 已提交
82
// STsdb
S
Shengliang Guan 已提交
83
STsdb *tsdbOpen(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF, SMeta *pMeta, STfs *pTfs);
H
more  
Hongze Cheng 已提交
84
void   tsdbClose(STsdb *);
H
refact  
Hongze Cheng 已提交
85
void   tsdbRemove(const char *path);
S
Shengliang Guan 已提交
86
int    tsdbInsertData(STsdb *pTsdb, SSubmitReq *pMsg, SSubmitRsp *pRsp);
H
more  
Hongze Cheng 已提交
87 88
int    tsdbPrepareCommit(STsdb *pTsdb);
int    tsdbCommit(STsdb *pTsdb);
H
more  
Hongze Cheng 已提交
89

H
refact  
Hongze Cheng 已提交
90 91 92
// STsdbCfg
int  tsdbOptionsInit(STsdbCfg *);
void tsdbOptionsClear(STsdbCfg *);
H
refact  
Hongze Cheng 已提交
93

H
Haojun Liao 已提交
94
typedef void* tsdbReaderT;
95

96 97 98 99 100 101 102 103 104 105
/**
 * Get the data block iterator, starting from position according to the query condition
 *
 * @param tsdb       tsdb handle
 * @param pCond      query condition, including time window, result set order, and basic required columns for each block
 * @param tableInfoGroup  table object list in the form of set, grouped into different sets according to the
 *                        group by condition
 * @param qinfo      query info handle from query processor
 * @return
 */
H
Haojun Liao 已提交
106
tsdbReaderT *tsdbQueryTables(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupInfo *tableInfoGroup, uint64_t qId, uint64_t taskId);
107 108 109 110 111 112 113 114 115 116 117

/**
 * Get the last row of the given query time window for all the tables in STableGroupInfo object.
 * Note that only one data block with only row will be returned while invoking retrieve data block function for
 * all tables in this group.
 *
 * @param tsdb   tsdb handle
 * @param pCond  query condition, including time window, result set order, and basic required columns for each block
 * @param tableInfo  table list.
 * @return
 */
H
Haojun Liao 已提交
118
//tsdbReaderT tsdbQueryLastRow(STsdbRepo *tsdb, STsdbQueryCond *pCond, STableGroupInfo *tableInfo, uint64_t qId,
119 120 121
//                                  SMemRef *pRef);


H
Haojun Liao 已提交
122
tsdbReaderT tsdbQueryCacheLast(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupList, uint64_t qId, void* pMemRef);
123

H
Haojun Liao 已提交
124
bool isTsdbCacheLastRow(tsdbReaderT* pTsdbReadHandle);
125

126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
/**
 *
 * @param tsdb
 * @param uid
 * @param skey
 * @param pTagCond
 * @param len
 * @param tagNameRelType
 * @param tbnameCond
 * @param pGroupInfo
 * @param pColIndex
 * @param numOfCols
 * @param reqId
 * @return
 */
H
Haojun Liao 已提交
141
int32_t tsdbQuerySTableByTagCond(void* pMeta, uint64_t uid, TSKEY skey, const char* pTagCond, size_t len,
142
                                 int16_t tagNameRelType, const char* tbnameCond, STableGroupInfo* pGroupInfo,
143
                                 SColIndex* pColIndex, int32_t numOfCols, uint64_t reqId, uint64_t taskId);
144 145 146 147 148 149 150
/**
 * get num of rows in mem table
 *
 * @param pHandle
 * @return row size
 */

H
Haojun Liao 已提交
151
int64_t tsdbGetNumOfRowsInMemTable(tsdbReaderT* pHandle);
152 153 154 155 156 157 158

/**
 * move to next block if exists
 *
 * @param pTsdbReadHandle
 * @return
 */
H
Haojun Liao 已提交
159
bool tsdbNextDataBlock(tsdbReaderT pTsdbReadHandle);
160 161 162 163 164 165 166 167

/**
 * Get current data block information
 *
 * @param pTsdbReadHandle
 * @param pBlockInfo
 * @return
 */
H
Haojun Liao 已提交
168
void tsdbRetrieveDataBlockInfo(tsdbReaderT *pTsdbReadHandle, SDataBlockInfo *pBlockInfo);
169 170 171 172 173 174 175 176 177 178 179

/**
 *
 * Get the pre-calculated information w.r.t. current data block.
 *
 * In case of data block in cache, the pBlockStatis will always be NULL.
 * If a block is not completed loaded from disk, the pBlockStatis will be NULL.

 * @pBlockStatis the pre-calculated value for current data blocks. if the block is a cache block, always return 0
 * @return
 */
H
Haojun Liao 已提交
180
int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT *pTsdbReadHandle, SDataStatis **pBlockStatis);
181 182 183 184 185 186 187 188 189 190 191

/**
 *
 * The query condition with primary timestamp is passed to iterator during its constructor function,
 * the returned data block must be satisfied with the time window condition in any cases,
 * which means the SData data block is not actually the completed disk data blocks.
 *
 * @param pTsdbReadHandle      query handle
 * @param pColumnIdList     required data columns id list
 * @return
 */
H
Haojun Liao 已提交
192
SArray *tsdbRetrieveDataBlock(tsdbReaderT *pTsdbReadHandle, SArray *pColumnIdList);
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207

/**
 * destroy the created table group list, which is generated by tag query
 * @param pGroupList
 */
void tsdbDestroyTableGroup(STableGroupInfo *pGroupList);

/**
 * create the table group result including only one table, used to handle the normal table query
 *
 * @param tsdb        tsdbHandle
 * @param uid         table uid
 * @param pGroupInfo  the generated result
 * @return
 */
H
Haojun Liao 已提交
208
int32_t tsdbGetOneTableGroup(void *pMeta, uint64_t uid, TSKEY startKey, STableGroupInfo *pGroupInfo);
209 210 211 212 213 214 215 216 217 218 219 220 221 222

/**
 *
 * @param tsdb
 * @param pTableIdList
 * @param pGroupInfo
 * @return
 */
int32_t tsdbGetTableGroupFromIdList(STsdb *tsdb, SArray *pTableIdList, STableGroupInfo *pGroupInfo);

/**
 * clean up the query handle
 * @param queryHandle
 */
H
Haojun Liao 已提交
223
void tsdbCleanupReadHandle(tsdbReaderT queryHandle);
224

H
refact  
Hongze Cheng 已提交
225 226 227 228
#ifdef __cplusplus
}
#endif

D
dapan1121 已提交
229
#endif /*_TD_TSDB_H_*/