tsdb.h 8.4 KB
Newer Older
H
hzcheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/*
 * 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 _tsdb_global_header_
#define _tsdb_global_header_

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>
#include "tglobalcfg.h"

#define TSDB__packed

#ifdef TSKEY32
#define TSKEY int32_t;
#else
#define TSKEY int64_t
#endif

S
slguan 已提交
34 35 36 37
#define TSDB_TRUE 1
#define TSDB_FALSE 0
#define TSDB_OK 0
#define TSDB_ERR -1
H
hzcheng 已提交
38 39 40 41 42 43 44 45 46

#define TS_PATH_DELIMITER "."

#define TSDB_TIME_PRECISION_MILLI 0
#define TSDB_TIME_PRECISION_MICRO 1

#define TSDB_TIME_PRECISION_MILLI_STR "ms"
#define TSDB_TIME_PRECISION_MICRO_STR "us"

S
slguan 已提交
47 48 49 50 51 52 53 54
  enum _vnode_status {
  TSDB_VNODE_STATUS_OFFLINE,
  TSDB_VNODE_STATUS_CREATING,
  TSDB_VNODE_STATUS_UNSYNCED,
  TSDB_VNODE_STATUS_SLAVE,
  TSDB_VNODE_STATUS_MASTER,
  TSDB_VNODE_STATUS_CLOSING,
  TSDB_VNODE_STATUS_DELETING,
H
hzcheng 已提交
55 56
};

S
slguan 已提交
57
enum _vnode_sync_status {
H
hzcheng 已提交
58 59 60 61 62 63
  STDB_SSTATUS_INIT,
  TSDB_SSTATUS_SYNCING,
  TSDB_SSTATUS_SYNC_CACHE,
  TSDB_SSTATUS_SYNC_FILE,
};

S
slguan 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
enum _dnode_status {
    TSDB_DNODE_STATUS_OFFLINE,
    TSDB_DNODE_STATUS_READY
};

enum _dnode_balance_status {
    LB_DNODE_STATE_BALANCED,
    LB_DNODE_STATE_BALANCING,
    LB_DNODE_STATE_OFFLINE_REMOVING,
    LB_DNODE_STATE_SHELL_REMOVING
};

enum _vgroup_status {
    LB_VGROUP_STATE_READY,
    LB_VGROUP_STATE_UPDATE
};

S
slguan 已提交
81 82 83 84 85 86 87 88 89 90
#define TSDB_DATA_TYPE_BOOL       1     // 1 bytes
#define TSDB_DATA_TYPE_TINYINT    2     // 1 byte
#define TSDB_DATA_TYPE_SMALLINT   3     // 2 bytes
#define TSDB_DATA_TYPE_INT        4     // 4 bytes
#define TSDB_DATA_TYPE_BIGINT     5     // 8 bytes
#define TSDB_DATA_TYPE_FLOAT      6     // 4 bytes
#define TSDB_DATA_TYPE_DOUBLE     7     // 8 bytes
#define TSDB_DATA_TYPE_BINARY     8     // string
#define TSDB_DATA_TYPE_TIMESTAMP  9     // 8 bytes
#define TSDB_DATA_TYPE_NCHAR      10    // unicode string
H
hzcheng 已提交
91 92

#define TSDB_KEYSIZE              sizeof(TSKEY)
S
slguan 已提交
93

S
slguan 已提交
94 95 96 97 98
#if LINUX
  #define TSDB_NCHAR_SIZE         sizeof(wchar_t)
#else
  #define TSDB_NCHAR_SIZE         4
#endif
S
slguan 已提交
99
//#define TSDB_CHAR_TERMINATED_SPACE 1
H
hzcheng 已提交
100

101
#define TSDB_RELATION_INVALID     0
H
hzcheng 已提交
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
#define TSDB_RELATION_LESS        1
#define TSDB_RELATION_LARGE       2
#define TSDB_RELATION_EQUAL       3
#define TSDB_RELATION_LESS_EQUAL  4
#define TSDB_RELATION_LARGE_EQUAL 5
#define TSDB_RELATION_NOT_EQUAL   6
#define TSDB_RELATION_LIKE        7

#define TSDB_RELATION_AND         8
#define TSDB_RELATION_OR          9
#define TSDB_RELATION_NOT         10

#define TSDB_BINARY_OP_ADD        11
#define TSDB_BINARY_OP_SUBTRACT   12
#define TSDB_BINARY_OP_MULTIPLY   13
#define TSDB_BINARY_OP_DIVIDE     14
#define TSDB_BINARY_OP_REMAINDER  15
#define TSDB_USERID_LEN           9
#define TS_PATH_DELIMITER_LEN     1

S
slguan 已提交
122 123
#define TSDB_METER_ID_LEN_MARGIN  10
#define TSDB_METER_ID_LEN         (TSDB_DB_NAME_LEN+TSDB_METER_NAME_LEN+2*TS_PATH_DELIMITER_LEN+TSDB_USERID_LEN+TSDB_METER_ID_LEN_MARGIN) //TSDB_DB_NAME_LEN+TSDB_METER_NAME_LEN+2*strlen(TS_PATH_DELIMITER)+strlen(USERID)
H
hzcheng 已提交
124 125 126 127 128 129
#define TSDB_UNI_LEN              24
#define TSDB_USER_LEN             TSDB_UNI_LEN
#define TSDB_ACCT_LEN             TSDB_UNI_LEN
#define TSDB_PASSWORD_LEN         TSDB_UNI_LEN

#define TSDB_MAX_COLUMNS          256
S
slguan 已提交
130
#define TSDB_MIN_COLUMNS          2       //PRIMARY COLUMN(timestamp) + other columns
H
hzcheng 已提交
131 132 133 134

#define TSDB_METER_NAME_LEN       64
#define TSDB_DB_NAME_LEN          32
#define TSDB_COL_NAME_LEN         64
S
slguan 已提交
135 136
#define TSDB_MAX_SAVED_SQL_LEN    TSDB_MAX_COLUMNS * 16
#define TSDB_MAX_SQL_LEN          TSDB_PAYLOAD_SIZE
H
hzcheng 已提交
137

S
slguan 已提交
138
#define TSDB_MAX_BYTES_PER_ROW    TSDB_MAX_COLUMNS * 16
H
hzcheng 已提交
139
#define TSDB_MAX_TAGS_LEN         512
S
slguan 已提交
140
#define TSDB_MAX_TAGS             32
H
hzcheng 已提交
141 142 143 144 145 146 147 148 149 150 151 152 153

#define TSDB_AUTH_LEN             16
#define TSDB_KEY_LEN              16
#define TSDB_VERSION_LEN          12
#define TSDB_STREET_LEN           64
#define TSDB_CITY_LEN             20
#define TSDB_STATE_LEN            20
#define TSDB_COUNTRY_LEN          20
#define TSDB_VNODES_SUPPORT       6
#define TSDB_MGMT_SUPPORT         4
#define TSDB_LOCALE_LEN           64
#define TSDB_TIMEZONE_LEN         64

S
slguan 已提交
154
#define TSDB_IPv4ADDR_LEN      	  16
H
hzcheng 已提交
155 156 157 158 159 160 161 162 163 164 165
#define TSDB_FILENAME_LEN         128
#define TSDB_METER_VNODE_BITS     20
#define TSDB_METER_SID_MASK       0xFFFFF
#define TSDB_SHELL_VNODE_BITS     24
#define TSDB_SHELL_SID_MASK       0xFF
#define TSDB_HTTP_TOKEN_LEN       20
#define TSDB_SHOW_SQL_LEN         32

#define TSDB_METER_STATE_OFFLINE  0
#define TSDB_METER_STATE_ONLLINE  1

S
slguan 已提交
166
#define TSDB_DEFAULT_PKT_SIZE     65480  //same as RPC_MAX_UDP_SIZE
H
hzcheng 已提交
167

S
slguan 已提交
168 169 170
#define TSDB_PAYLOAD_SIZE         (TSDB_DEFAULT_PKT_SIZE - 100)
#define TSDB_DEFAULT_PAYLOAD_SIZE 1024   // default payload size
#define TSDB_EXTRA_PAYLOAD_SIZE   128    // extra bytes for auth
H
hzcheng 已提交
171 172 173 174 175 176 177 178 179 180
#define TSDB_SQLCMD_SIZE          1024
#define TSDB_MAX_VNODES           256
#define TSDB_MIN_VNODES           50
#define TSDB_INVALID_VNODE_NUM    0

#define TSDB_DNODE_ROLE_ANY       0
#define TSDB_DNODE_ROLE_MGMT      1
#define TSDB_DNODE_ROLE_VNODE     2

#define TSDB_MAX_MPEERS           5
S
slguan 已提交
181 182 183 184 185 186 187
#define TSDB_MAX_MGMT_IPS         (TSDB_MAX_MPEERS+1)

//#define TSDB_REPLICA_MAX_NUM    3
#define TSDB_REPLICA_MIN_NUM      1

#define TSDB_TBNAME_COLUMN_INDEX       (-1)
#define TSDB_MULTI_METERMETA_MAX_NUM    100000  // maximum batch size allowed to load metermeta
H
hzcheng 已提交
188

S
slguan 已提交
189 190 191
//default value == 10
#define TSDB_FILE_MIN_PARTITION_RANGE   1         //minimum partition range of vnode file in days
#define TSDB_FILE_MAX_PARTITION_RANGE   3650      //max partition range of vnode file in days
H
hzcheng 已提交
192

S
slguan 已提交
193 194
#define TSDB_DATA_MIN_RESERVE_DAY       1        // data in db to be reserved.
#define TSDB_DATA_DEFAULT_RESERVE_DAY   3650     // ten years
H
hzcheng 已提交
195

S
slguan 已提交
196 197
#define TSDB_MIN_COMPRESSION_LEVEL      0
#define TSDB_MAX_COMPRESSION_LEVEL      2
H
hzcheng 已提交
198

S
slguan 已提交
199 200
#define TSDB_MIN_CACHE_BLOCKS_PER_METER 32
#define TSDB_MAX_CACHE_BLOCKS_PER_METER 40960
H
hzcheng 已提交
201

S
slguan 已提交
202 203
#define TSDB_MIN_COMMIT_TIME_INTERVAL   30
#define TSDB_MAX_COMMIT_TIME_INTERVAL   40960
H
hzcheng 已提交
204

S
slguan 已提交
205 206
#define TSDB_MIN_ROWS_IN_FILEBLOCK      200
#define TSDB_MAX_ROWS_IN_FILEBLOCK      500000
H
hzcheng 已提交
207

S
slguan 已提交
208 209
#define TSDB_MIN_CACHE_BLOCK_SIZE       100
#define TSDB_MAX_CACHE_BLOCK_SIZE       104857600
H
hzcheng 已提交
210

S
slguan 已提交
211 212
#define TSDB_MIN_CACHE_BLOCKS           100
#define TSDB_MAX_CACHE_BLOCKS           409600
H
hzcheng 已提交
213

S
slguan 已提交
214
#define TSDB_MAX_AVG_BLOCKS             2048
H
hzcheng 已提交
215

S
slguan 已提交
216 217
#define TSDB_MIN_TABLES_PER_VNODE       1
#define TSDB_MAX_TABLES_PER_VNODE       220000
H
hzcheng 已提交
218

S
slguan 已提交
219
#define TSDB_MAX_JOIN_TABLE_NUM         5
H
hzcheng 已提交
220

S
slguan 已提交
221 222 223
#define TSDB_MAX_BINARY_LEN            (TSDB_MAX_BYTES_PER_ROW-TSDB_KEYSIZE)
#define TSDB_MAX_NCHAR_LEN             (TSDB_MAX_BYTES_PER_ROW-TSDB_KEYSIZE)
#define PRIMARYKEY_TIMESTAMP_COL_INDEX  0
H
hzcheng 已提交
224

S
slguan 已提交
225 226 227 228 229
#define TSDB_DATA_BOOL_NULL             0x02
#define TSDB_DATA_TINYINT_NULL          0x80
#define TSDB_DATA_SMALLINT_NULL         0x8000
#define TSDB_DATA_INT_NULL              0x80000000
#define TSDB_DATA_BIGINT_NULL           0x8000000000000000L
H
hzcheng 已提交
230

S
slguan 已提交
231 232 233 234
#define TSDB_DATA_FLOAT_NULL            0x7FF00000              // it is an NAN
#define TSDB_DATA_DOUBLE_NULL           0x7FFFFF0000000000L     // an NAN
#define TSDB_DATA_NCHAR_NULL            0xFFFFFFFF
#define TSDB_DATA_BINARY_NULL           0xFF
H
hzcheng 已提交
235

S
slguan 已提交
236 237
#define TSDB_DATA_NULL_STR              "NULL"
#define TSDB_DATA_NULL_STR_L            "null"
H
hzcheng 已提交
238

S
slguan 已提交
239 240 241
#define TSDB_MAX_RPC_THREADS            5

#define TSDB_QUERY_TYPE_QUERY                            0     // normal query
242
#define TSDB_QUERY_TYPE_FREE_RESOURCE                  0x01U     // free qhandle at vnode
S
slguan 已提交
243 244 245 246 247

/*
 * 1. ordinary sub query for select * from super_table
 * 2. all sqlobj generated by createSubqueryObj with this flag
 */
248 249 250 251 252 253 254 255
#define TSDB_QUERY_TYPE_SUBQUERY                       0x02U
#define TSDB_QUERY_TYPE_STABLE_SUBQUERY                0x04U     // two-stage subquery for super table

#define TSDB_QUERY_TYPE_TABLE_QUERY                    0x08U     // query ordinary table; below only apply to client side
#define TSDB_QUERY_TYPE_STABLE_QUERY                   0x10U    // query on super table
#define TSDB_QUERY_TYPE_JOIN_QUERY                     0x20U    // join query
#define TSDB_QUERY_TYPE_PROJECTION_QUERY               0x40U    // select *,columns... query
#define TSDB_QUERY_TYPE_JOIN_SEC_STAGE                 0x80U    // join sub query at the second stage
H
hzcheng 已提交
256 257 258 259 260 261

#ifdef __cplusplus
}
#endif

#endif