[TD-10430] adjust os module
This commit is contained in:
parent
e889008732
commit
c0a171b144
|
@ -42,6 +42,8 @@ execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
|
||||||
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
|
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
|
||||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/deps/deps-download")
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/deps/deps-download")
|
||||||
|
|
||||||
|
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -gdwarf-2 -msse4.2 -mfma")
|
||||||
|
|
||||||
# deps
|
# deps
|
||||||
add_subdirectory(deps)
|
add_subdirectory(deps)
|
||||||
|
|
||||||
|
|
|
@ -31,21 +31,23 @@ typedef void TAOS_SUB;
|
||||||
typedef void **TAOS_ROW;
|
typedef void **TAOS_ROW;
|
||||||
|
|
||||||
// Data type definition
|
// Data type definition
|
||||||
#define TSDB_DATA_TYPE_NULL 0 // 1 bytes
|
#ifndef TSDB_DATA_TYPE_NULL
|
||||||
#define TSDB_DATA_TYPE_BOOL 1 // 1 bytes
|
#define TSDB_DATA_TYPE_NULL 0 // 1 bytes
|
||||||
#define TSDB_DATA_TYPE_TINYINT 2 // 1 byte
|
#define TSDB_DATA_TYPE_BOOL 1 // 1 bytes
|
||||||
#define TSDB_DATA_TYPE_SMALLINT 3 // 2 bytes
|
#define TSDB_DATA_TYPE_TINYINT 2 // 1 byte
|
||||||
#define TSDB_DATA_TYPE_INT 4 // 4 bytes
|
#define TSDB_DATA_TYPE_SMALLINT 3 // 2 bytes
|
||||||
#define TSDB_DATA_TYPE_BIGINT 5 // 8 bytes
|
#define TSDB_DATA_TYPE_INT 4 // 4 bytes
|
||||||
#define TSDB_DATA_TYPE_FLOAT 6 // 4 bytes
|
#define TSDB_DATA_TYPE_BIGINT 5 // 8 bytes
|
||||||
#define TSDB_DATA_TYPE_DOUBLE 7 // 8 bytes
|
#define TSDB_DATA_TYPE_FLOAT 6 // 4 bytes
|
||||||
#define TSDB_DATA_TYPE_BINARY 8 // string
|
#define TSDB_DATA_TYPE_DOUBLE 7 // 8 bytes
|
||||||
#define TSDB_DATA_TYPE_TIMESTAMP 9 // 8 bytes
|
#define TSDB_DATA_TYPE_BINARY 8 // string
|
||||||
#define TSDB_DATA_TYPE_NCHAR 10 // unicode string
|
#define TSDB_DATA_TYPE_TIMESTAMP 9 // 8 bytes
|
||||||
#define TSDB_DATA_TYPE_UTINYINT 11 // 1 byte
|
#define TSDB_DATA_TYPE_NCHAR 10 // unicode string
|
||||||
#define TSDB_DATA_TYPE_USMALLINT 12 // 2 bytes
|
#define TSDB_DATA_TYPE_UTINYINT 11 // 1 byte
|
||||||
#define TSDB_DATA_TYPE_UINT 13 // 4 bytes
|
#define TSDB_DATA_TYPE_USMALLINT 12 // 2 bytes
|
||||||
#define TSDB_DATA_TYPE_UBIGINT 14 // 8 bytes
|
#define TSDB_DATA_TYPE_UINT 13 // 4 bytes
|
||||||
|
#define TSDB_DATA_TYPE_UBIGINT 14 // 8 bytes
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
TSDB_OPTION_LOCALE,
|
TSDB_OPTION_LOCALE,
|
||||||
|
|
|
@ -13,389 +13,20 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TDENGINE_TAOS_DEF_H
|
#ifndef _TD_COMMON_TAOS_DEF_H
|
||||||
#define TDENGINE_TAOS_DEF_H
|
#define _TD_COMMON_TAOS_DEF_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include "tdef.h"
|
||||||
#include <stdbool.h>
|
|
||||||
#include "taos.h"
|
#include "taos.h"
|
||||||
|
|
||||||
#define TSDB__packed
|
|
||||||
|
|
||||||
#ifdef TSKEY32
|
|
||||||
#define TSKEY int32_t;
|
|
||||||
#else
|
|
||||||
#define TSKEY int64_t
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define TSWINDOW_INITIALIZER ((STimeWindow) {INT64_MIN, INT64_MAX})
|
#define TSWINDOW_INITIALIZER ((STimeWindow) {INT64_MIN, INT64_MAX})
|
||||||
#define TSWINDOW_DESC_INITIALIZER ((STimeWindow) {INT64_MAX, INT64_MIN})
|
#define TSWINDOW_DESC_INITIALIZER ((STimeWindow) {INT64_MAX, INT64_MIN})
|
||||||
#define IS_TSWINDOW_SPECIFIED(win) (((win).skey != INT64_MIN) || ((win).ekey != INT64_MAX))
|
#define IS_TSWINDOW_SPECIFIED(win) (((win).skey != INT64_MIN) || ((win).ekey != INT64_MAX))
|
||||||
|
|
||||||
#define TSKEY_INITIAL_VAL INT64_MIN
|
|
||||||
|
|
||||||
// Bytes for each type.
|
|
||||||
extern const int32_t TYPE_BYTES[15];
|
|
||||||
|
|
||||||
#define TSDB_KEYSIZE sizeof(TSKEY)
|
|
||||||
|
|
||||||
#if LINUX
|
|
||||||
#define TSDB_NCHAR_SIZE sizeof(wchar_t)
|
|
||||||
#else
|
|
||||||
#define TSDB_NCHAR_SIZE sizeof(int32_t)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// NULL definition
|
|
||||||
#define TSDB_DATA_BOOL_NULL 0x02
|
|
||||||
#define TSDB_DATA_TINYINT_NULL 0x80
|
|
||||||
#define TSDB_DATA_SMALLINT_NULL 0x8000
|
|
||||||
#define TSDB_DATA_INT_NULL 0x80000000L
|
|
||||||
#define TSDB_DATA_BIGINT_NULL 0x8000000000000000L
|
|
||||||
#define TSDB_DATA_TIMESTAMP_NULL TSDB_DATA_BIGINT_NULL
|
|
||||||
|
|
||||||
#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
|
|
||||||
|
|
||||||
#define TSDB_DATA_UTINYINT_NULL 0xFF
|
|
||||||
#define TSDB_DATA_USMALLINT_NULL 0xFFFF
|
|
||||||
#define TSDB_DATA_UINT_NULL 0xFFFFFFFF
|
|
||||||
#define TSDB_DATA_UBIGINT_NULL 0xFFFFFFFFFFFFFFFFL
|
|
||||||
|
|
||||||
#define TSDB_DATA_NULL_STR "NULL"
|
|
||||||
#define TSDB_DATA_NULL_STR_L "null"
|
|
||||||
|
|
||||||
#define TSDB_DEFAULT_USER "root"
|
|
||||||
#ifdef _TD_POWER_
|
|
||||||
#define TSDB_DEFAULT_PASS "powerdb"
|
|
||||||
#elif (_TD_TQ_ == true)
|
|
||||||
#define TSDB_DEFAULT_PASS "tqueue"
|
|
||||||
#elif (_TD_PRO_ == true)
|
|
||||||
#define TSDB_DEFAULT_PASS "prodb"
|
|
||||||
#else
|
|
||||||
#define TSDB_DEFAULT_PASS "taosdata"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define SHELL_MAX_PASSWORD_LEN 20
|
|
||||||
|
|
||||||
#define TSDB_TRUE 1
|
|
||||||
#define TSDB_FALSE 0
|
|
||||||
#define TSDB_OK 0
|
|
||||||
#define TSDB_ERR -1
|
|
||||||
|
|
||||||
#define TS_PATH_DELIMITER "."
|
|
||||||
|
|
||||||
#define TSDB_TIME_PRECISION_MILLI 0
|
|
||||||
#define TSDB_TIME_PRECISION_MICRO 1
|
|
||||||
#define TSDB_TIME_PRECISION_NANO 2
|
|
||||||
|
|
||||||
#define TSDB_TIME_PRECISION_MILLI_STR "ms"
|
|
||||||
#define TSDB_TIME_PRECISION_MICRO_STR "us"
|
|
||||||
#define TSDB_TIME_PRECISION_NANO_STR "ns"
|
|
||||||
|
|
||||||
#define TSDB_TICK_PER_SECOND(precision) ((int64_t)((precision)==TSDB_TIME_PRECISION_MILLI ? 1e3L : ((precision)==TSDB_TIME_PRECISION_MICRO ? 1e6L : 1e9L)))
|
|
||||||
|
|
||||||
#define T_MEMBER_SIZE(type, member) sizeof(((type *)0)->member)
|
|
||||||
#define T_APPEND_MEMBER(dst, ptr, type, member) \
|
|
||||||
do {\
|
|
||||||
memcpy((void *)(dst), (void *)(&((ptr)->member)), T_MEMBER_SIZE(type, member));\
|
|
||||||
dst = (void *)((char *)(dst) + T_MEMBER_SIZE(type, member));\
|
|
||||||
} while(0)
|
|
||||||
#define T_READ_MEMBER(src, type, target) \
|
|
||||||
do { \
|
|
||||||
(target) = *(type *)(src); \
|
|
||||||
(src) = (void *)((char *)src + sizeof(type));\
|
|
||||||
} while(0)
|
|
||||||
|
|
||||||
#define GET_INT8_VAL(x) (*(int8_t *)(x))
|
|
||||||
#define GET_INT16_VAL(x) (*(int16_t *)(x))
|
|
||||||
#define GET_INT32_VAL(x) (*(int32_t *)(x))
|
|
||||||
#define GET_INT64_VAL(x) (*(int64_t *)(x))
|
|
||||||
#define GET_UINT8_VAL(x) (*(uint8_t*) (x))
|
|
||||||
#define GET_UINT16_VAL(x) (*(uint16_t *)(x))
|
|
||||||
#define GET_UINT32_VAL(x) (*(uint32_t *)(x))
|
|
||||||
#define GET_UINT64_VAL(x) (*(uint64_t *)(x))
|
|
||||||
|
|
||||||
#ifdef _TD_ARM_32
|
|
||||||
float taos_align_get_float(const char* pBuf);
|
|
||||||
double taos_align_get_double(const char* pBuf);
|
|
||||||
|
|
||||||
#define GET_FLOAT_VAL(x) taos_align_get_float(x)
|
|
||||||
#define GET_DOUBLE_VAL(x) taos_align_get_double(x)
|
|
||||||
#define SET_FLOAT_VAL(x, y) { float z = (float)(y); (*(int32_t*) x = *(int32_t*)(&z)); }
|
|
||||||
#define SET_DOUBLE_VAL(x, y) { double z = (double)(y); (*(int64_t*) x = *(int64_t*)(&z)); }
|
|
||||||
#define SET_FLOAT_PTR(x, y) { (*(int32_t*) x = *(int32_t*)y); }
|
|
||||||
#define SET_DOUBLE_PTR(x, y) { (*(int64_t*) x = *(int64_t*)y); }
|
|
||||||
#else
|
|
||||||
#define GET_FLOAT_VAL(x) (*(float *)(x))
|
|
||||||
#define GET_DOUBLE_VAL(x) (*(double *)(x))
|
|
||||||
#define SET_FLOAT_VAL(x, y) { (*(float *)(x)) = (float)(y); }
|
|
||||||
#define SET_DOUBLE_VAL(x, y) { (*(double *)(x)) = (double)(y); }
|
|
||||||
#define SET_FLOAT_PTR(x, y) { (*(float *)(x)) = (*(float *)(y)); }
|
|
||||||
#define SET_DOUBLE_PTR(x, y) { (*(double *)(x)) = (*(double *)(y)); }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// TODO: check if below is necessary
|
|
||||||
#define TSDB_RELATION_INVALID 0
|
|
||||||
#define TSDB_RELATION_LESS 1
|
|
||||||
#define TSDB_RELATION_GREATER 2
|
|
||||||
#define TSDB_RELATION_EQUAL 3
|
|
||||||
#define TSDB_RELATION_LESS_EQUAL 4
|
|
||||||
#define TSDB_RELATION_GREATER_EQUAL 5
|
|
||||||
#define TSDB_RELATION_NOT_EQUAL 6
|
|
||||||
#define TSDB_RELATION_LIKE 7
|
|
||||||
#define TSDB_RELATION_ISNULL 8
|
|
||||||
#define TSDB_RELATION_NOTNULL 9
|
|
||||||
#define TSDB_RELATION_IN 10
|
|
||||||
|
|
||||||
#define TSDB_RELATION_AND 11
|
|
||||||
#define TSDB_RELATION_OR 12
|
|
||||||
#define TSDB_RELATION_NOT 13
|
|
||||||
|
|
||||||
#define TSDB_RELATION_MATCH 14
|
|
||||||
#define TSDB_RELATION_NMATCH 15
|
|
||||||
|
|
||||||
#define TSDB_BINARY_OP_ADD 30
|
|
||||||
#define TSDB_BINARY_OP_SUBTRACT 31
|
|
||||||
#define TSDB_BINARY_OP_MULTIPLY 32
|
|
||||||
#define TSDB_BINARY_OP_DIVIDE 33
|
|
||||||
#define TSDB_BINARY_OP_REMAINDER 34
|
|
||||||
|
|
||||||
|
|
||||||
#define IS_RELATION_OPTR(op) (((op) >= TSDB_RELATION_LESS) && ((op) < TSDB_RELATION_IN))
|
|
||||||
#define IS_ARITHMETIC_OPTR(op) (((op) >= TSDB_BINARY_OP_ADD) && ((op) <= TSDB_BINARY_OP_REMAINDER))
|
|
||||||
|
|
||||||
#define TS_PATH_DELIMITER_LEN 1
|
|
||||||
|
|
||||||
#define TSDB_UNI_LEN 24
|
|
||||||
#define TSDB_USER_LEN TSDB_UNI_LEN
|
|
||||||
|
|
||||||
// ACCOUNT is a 32 bit positive integer
|
|
||||||
// this is the length of its string representation, including the terminator zero
|
|
||||||
#define TSDB_ACCT_ID_LEN 11
|
|
||||||
|
|
||||||
#define TSDB_MAX_COLUMNS 4096
|
|
||||||
#define TSDB_MIN_COLUMNS 2 //PRIMARY COLUMN(timestamp) + other columns
|
|
||||||
|
|
||||||
#define TSDB_NODE_NAME_LEN 64
|
|
||||||
#define TSDB_TABLE_NAME_LEN 193 // it is a null-terminated string
|
|
||||||
#define TSDB_DB_NAME_LEN 33
|
|
||||||
#define TSDB_FUNC_NAME_LEN 65
|
|
||||||
#define TSDB_FUNC_CODE_LEN (65535 - 512)
|
|
||||||
#define TSDB_FUNC_BUF_SIZE 512
|
|
||||||
#define TSDB_TYPE_STR_MAX_LEN 32
|
|
||||||
#define TSDB_TABLE_FNAME_LEN (TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN + TSDB_TABLE_NAME_LEN)
|
|
||||||
#define TSDB_COL_NAME_LEN 65
|
|
||||||
#define TSDB_MAX_SAVED_SQL_LEN TSDB_MAX_COLUMNS * 64
|
|
||||||
#define TSDB_MAX_SQL_LEN TSDB_PAYLOAD_SIZE
|
|
||||||
#define TSDB_MAX_SQL_SHOW_LEN 512
|
|
||||||
#define TSDB_MAX_ALLOWED_SQL_LEN (1*1024*1024u) // sql length should be less than 1mb
|
|
||||||
|
|
||||||
#define TSDB_APPNAME_LEN TSDB_UNI_LEN
|
|
||||||
|
|
||||||
/**
|
|
||||||
* In some scenarios uint16_t (0~65535) is used to store the row len.
|
|
||||||
* - Firstly, we use 65531(65535 - 4), as the SDataRow/SKVRow contains 4 bits header.
|
|
||||||
* - Secondly, if all cols are VarDataT type except primary key, we need 4 bits to store the offset, thus
|
|
||||||
* the final value is 65531-(4096-1)*4 = 49151.
|
|
||||||
*/
|
|
||||||
#define TSDB_MAX_BYTES_PER_ROW 49151
|
|
||||||
#define TSDB_MAX_TAGS_LEN 16384
|
|
||||||
#define TSDB_MAX_TAGS 128
|
|
||||||
#define TSDB_MAX_TAG_CONDITIONS 1024
|
|
||||||
|
|
||||||
#define TSDB_AUTH_LEN 16
|
|
||||||
#define TSDB_KEY_LEN 16
|
|
||||||
#define TSDB_VERSION_LEN 12
|
|
||||||
#define TSDB_LOCALE_LEN 64
|
|
||||||
#define TSDB_TIMEZONE_LEN 96
|
|
||||||
#define TSDB_LABEL_LEN 8
|
|
||||||
|
|
||||||
#define TSDB_CLUSTER_ID_LEN 40
|
|
||||||
#define TSDB_FQDN_LEN 128
|
|
||||||
#define TSDB_EP_LEN (TSDB_FQDN_LEN+6)
|
|
||||||
#define TSDB_IPv4ADDR_LEN 16
|
|
||||||
#define TSDB_FILENAME_LEN 128
|
|
||||||
#define TSDB_SHOW_SQL_LEN 512
|
|
||||||
#define TSDB_SHOW_SUBQUERY_LEN 1000
|
|
||||||
#define TSDB_SLOW_QUERY_SQL_LEN 512
|
|
||||||
|
|
||||||
#define TSDB_STEP_NAME_LEN 32
|
|
||||||
#define TSDB_STEP_DESC_LEN 128
|
|
||||||
|
|
||||||
#define TSDB_MQTT_HOSTNAME_LEN 64
|
|
||||||
#define TSDB_MQTT_PORT_LEN 8
|
|
||||||
#define TSDB_MQTT_USER_LEN 24
|
|
||||||
#define TSDB_MQTT_PASS_LEN 24
|
|
||||||
#define TSDB_MQTT_TOPIC_LEN 64
|
|
||||||
#define TSDB_MQTT_CLIENT_ID_LEN 32
|
|
||||||
|
|
||||||
#define TSDB_DB_TYPE_DEFAULT 0
|
|
||||||
#define TSDB_DB_TYPE_TOPIC 1
|
|
||||||
|
|
||||||
#define TSDB_DEFAULT_PKT_SIZE 65480 //same as RPC_MAX_UDP_SIZE
|
|
||||||
|
|
||||||
#define TSDB_PAYLOAD_SIZE TSDB_DEFAULT_PKT_SIZE
|
|
||||||
#define TSDB_DEFAULT_PAYLOAD_SIZE 5120 // default payload size, greater than PATH_MAX value
|
|
||||||
#define TSDB_EXTRA_PAYLOAD_SIZE 128 // extra bytes for auth
|
|
||||||
#define TSDB_CQ_SQL_SIZE 1024
|
|
||||||
#define TSDB_MIN_VNODES 64
|
|
||||||
#define TSDB_MAX_VNODES 2048
|
|
||||||
#define TSDB_MIN_VNODES_PER_DB 2
|
|
||||||
#define TSDB_MAX_VNODES_PER_DB 64
|
|
||||||
|
|
||||||
#define TSDB_DNODE_ROLE_ANY 0
|
|
||||||
#define TSDB_DNODE_ROLE_MGMT 1
|
|
||||||
#define TSDB_DNODE_ROLE_VNODE 2
|
|
||||||
|
|
||||||
#define TSDB_MAX_REPLICA 5
|
|
||||||
|
|
||||||
#define TSDB_TBNAME_COLUMN_INDEX (-1)
|
|
||||||
#define TSDB_UD_COLUMN_INDEX (-1000)
|
|
||||||
#define TSDB_RES_COL_ID (-5000)
|
|
||||||
|
|
||||||
#define TSDB_MULTI_TABLEMETA_MAX_NUM 100000 // maximum batch size allowed to load table meta
|
|
||||||
|
|
||||||
#define TSDB_MIN_CACHE_BLOCK_SIZE 1
|
|
||||||
#define TSDB_MAX_CACHE_BLOCK_SIZE 128 // 128MB for each vnode
|
|
||||||
#define TSDB_DEFAULT_CACHE_BLOCK_SIZE 16
|
|
||||||
|
|
||||||
#define TSDB_MIN_TOTAL_BLOCKS 3
|
|
||||||
#define TSDB_MAX_TOTAL_BLOCKS 10000
|
|
||||||
#define TSDB_DEFAULT_TOTAL_BLOCKS 6
|
|
||||||
|
|
||||||
#define TSDB_MIN_TABLES 4
|
|
||||||
#define TSDB_MAX_TABLES 10000000
|
|
||||||
#define TSDB_DEFAULT_TABLES 1000000
|
|
||||||
#define TSDB_TABLES_STEP 1000
|
|
||||||
#define TSDB_META_COMPACT_RATIO 0 // disable tsdb meta compact by default
|
|
||||||
|
|
||||||
#define TSDB_MIN_DAYS_PER_FILE 1
|
|
||||||
#define TSDB_MAX_DAYS_PER_FILE 3650
|
|
||||||
#define TSDB_DEFAULT_DAYS_PER_FILE 10
|
|
||||||
|
|
||||||
#define TSDB_MIN_KEEP 1 // data in db to be reserved.
|
|
||||||
#define TSDB_MAX_KEEP 365000 // data in db to be reserved.
|
|
||||||
#define TSDB_DEFAULT_KEEP 3650 // ten years
|
|
||||||
|
|
||||||
#define TSDB_DEFAULT_MIN_ROW_FBLOCK 100
|
|
||||||
#define TSDB_MIN_MIN_ROW_FBLOCK 10
|
|
||||||
#define TSDB_MAX_MIN_ROW_FBLOCK 1000
|
|
||||||
|
|
||||||
#define TSDB_DEFAULT_MAX_ROW_FBLOCK 4096
|
|
||||||
#define TSDB_MIN_MAX_ROW_FBLOCK 200
|
|
||||||
#define TSDB_MAX_MAX_ROW_FBLOCK 10000
|
|
||||||
|
|
||||||
#define TSDB_MIN_COMMIT_TIME 30
|
|
||||||
#define TSDB_MAX_COMMIT_TIME 40960
|
|
||||||
#define TSDB_DEFAULT_COMMIT_TIME 3600
|
|
||||||
|
|
||||||
#define TSDB_MIN_PRECISION TSDB_TIME_PRECISION_MILLI
|
|
||||||
#define TSDB_MAX_PRECISION TSDB_TIME_PRECISION_NANO
|
|
||||||
#define TSDB_DEFAULT_PRECISION TSDB_TIME_PRECISION_MILLI
|
|
||||||
|
|
||||||
#define TSDB_MIN_COMP_LEVEL 0
|
|
||||||
#define TSDB_MAX_COMP_LEVEL 2
|
|
||||||
#define TSDB_DEFAULT_COMP_LEVEL 2
|
|
||||||
|
|
||||||
#define TSDB_MIN_WAL_LEVEL 0
|
|
||||||
#define TSDB_MAX_WAL_LEVEL 2
|
|
||||||
#define TSDB_DEFAULT_WAL_LEVEL 1
|
|
||||||
|
|
||||||
#define TSDB_MIN_DB_UPDATE 0
|
|
||||||
#define TSDB_MAX_DB_UPDATE 2
|
|
||||||
#define TSDB_DEFAULT_DB_UPDATE_OPTION 0
|
|
||||||
|
|
||||||
#define TSDB_MIN_DB_CACHE_LAST_ROW 0
|
|
||||||
#define TSDB_MAX_DB_CACHE_LAST_ROW 3
|
|
||||||
#define TSDB_DEFAULT_CACHE_LAST_ROW 0
|
|
||||||
|
|
||||||
#define TSDB_MIN_FSYNC_PERIOD 0
|
|
||||||
#define TSDB_MAX_FSYNC_PERIOD 180000 // millisecond
|
|
||||||
#define TSDB_DEFAULT_FSYNC_PERIOD 3000 // three second
|
|
||||||
|
|
||||||
#define TSDB_MIN_DB_REPLICA_OPTION 1
|
|
||||||
#define TSDB_MAX_DB_REPLICA_OPTION 3
|
|
||||||
#define TSDB_DEFAULT_DB_REPLICA_OPTION 1
|
|
||||||
|
|
||||||
#define TSDB_MIN_DB_PARTITON_OPTION 0
|
|
||||||
#define TSDB_MAX_DB_PARTITON_OPTION 1000
|
|
||||||
#define TSDB_DEFAULT_DB_PARTITON_OPTION 4
|
|
||||||
|
|
||||||
#define TSDB_MIN_DB_QUORUM_OPTION 1
|
|
||||||
#define TSDB_MAX_DB_QUORUM_OPTION 2
|
|
||||||
#define TSDB_DEFAULT_DB_QUORUM_OPTION 1
|
|
||||||
|
|
||||||
#define TSDB_MAX_JOIN_TABLE_NUM 10
|
|
||||||
#define TSDB_MAX_UNION_CLAUSE 5
|
|
||||||
|
|
||||||
#define TSDB_MAX_FIELD_LEN 16384
|
|
||||||
#define TSDB_MAX_BINARY_LEN (TSDB_MAX_FIELD_LEN-TSDB_KEYSIZE) // keep 16384
|
|
||||||
#define TSDB_MAX_NCHAR_LEN (TSDB_MAX_FIELD_LEN-TSDB_KEYSIZE) // keep 16384
|
|
||||||
#define PRIMARYKEY_TIMESTAMP_COL_INDEX 0
|
|
||||||
|
|
||||||
#define TSDB_MAX_RPC_THREADS 5
|
|
||||||
|
|
||||||
#define TSDB_QUERY_TYPE_NON_TYPE 0x00u // none type
|
|
||||||
#define TSDB_QUERY_TYPE_FREE_RESOURCE 0x01u // free qhandle at vnode
|
|
||||||
|
|
||||||
#define TSDB_UDF_TYPE_SCALAR 1
|
|
||||||
#define TSDB_UDF_TYPE_AGGREGATE 2
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 1. ordinary sub query for select * from super_table
|
|
||||||
* 2. all sqlobj generated by createSubqueryObj with this flag
|
|
||||||
*/
|
|
||||||
#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
|
|
||||||
|
|
||||||
#define TSDB_QUERY_TYPE_TAG_FILTER_QUERY 0x400u
|
|
||||||
#define TSDB_QUERY_TYPE_INSERT 0x100u // insert type
|
|
||||||
#define TSDB_QUERY_TYPE_MULTITABLE_QUERY 0x200u
|
|
||||||
#define TSDB_QUERY_TYPE_FILE_INSERT 0x400u // insert data from file
|
|
||||||
#define TSDB_QUERY_TYPE_STMT_INSERT 0x800u // stmt insert type
|
|
||||||
#define TSDB_QUERY_TYPE_NEST_SUBQUERY 0x1000u // nested sub query
|
|
||||||
|
|
||||||
#define TSDB_QUERY_HAS_TYPE(x, _type) (((x) & (_type)) != 0)
|
|
||||||
#define TSDB_QUERY_SET_TYPE(x, _type) ((x) |= (_type))
|
|
||||||
#define TSDB_QUERY_CLEAR_TYPE(x, _type) ((x) &= (~_type))
|
|
||||||
#define TSDB_QUERY_RESET_TYPE(x) ((x) = TSDB_QUERY_TYPE_NON_TYPE)
|
|
||||||
|
|
||||||
#define TSDB_ORDER_ASC 1
|
|
||||||
#define TSDB_ORDER_DESC 2
|
|
||||||
|
|
||||||
#define TSDB_DEFAULT_CLUSTER_HASH_SIZE 1
|
|
||||||
#define TSDB_DEFAULT_MNODES_HASH_SIZE 5
|
|
||||||
#define TSDB_DEFAULT_DNODES_HASH_SIZE 10
|
|
||||||
#define TSDB_DEFAULT_ACCOUNTS_HASH_SIZE 10
|
|
||||||
#define TSDB_DEFAULT_USERS_HASH_SIZE 20
|
|
||||||
#define TSDB_DEFAULT_DBS_HASH_SIZE 100
|
|
||||||
#define TSDB_DEFAULT_VGROUPS_HASH_SIZE 100
|
|
||||||
#define TSDB_DEFAULT_STABLES_HASH_SIZE 100
|
|
||||||
#define TSDB_DEFAULT_CTABLES_HASH_SIZE 20000
|
|
||||||
|
|
||||||
#define TSDB_PORT_DNODESHELL 0
|
|
||||||
#define TSDB_PORT_DNODEDNODE 5
|
|
||||||
#define TSDB_PORT_SYNC 10
|
|
||||||
#define TSDB_PORT_HTTP 11
|
|
||||||
#define TSDB_PORT_ARBITRATOR 12
|
|
||||||
|
|
||||||
#define TSDB_MAX_WAL_SIZE (1024*1024*3)
|
|
||||||
|
|
||||||
#define TSDB_ARB_DUMMY_TIME 4765104000000 // 2121-01-01 00:00:00.000, :P
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
TAOS_QTYPE_RPC = 0,
|
TAOS_QTYPE_RPC = 0,
|
||||||
TAOS_QTYPE_FWD = 1,
|
TAOS_QTYPE_FWD = 1,
|
||||||
|
@ -404,10 +35,6 @@ typedef enum {
|
||||||
TAOS_QTYPE_QUERY = 4
|
TAOS_QTYPE_QUERY = 4
|
||||||
} EQType;
|
} EQType;
|
||||||
|
|
||||||
#define TSDB_MAX_TIERS 3
|
|
||||||
#define TSDB_MAX_DISKS_PER_TIER 16
|
|
||||||
#define TSDB_MAX_DISKS (TSDB_MAX_TIERS * TSDB_MAX_DISKS_PER_TIER)
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
TSDB_SUPER_TABLE = 0, // super table
|
TSDB_SUPER_TABLE = 0, // super table
|
||||||
TSDB_CHILD_TABLE = 1, // table created from super table
|
TSDB_CHILD_TABLE = 1, // table created from super table
|
||||||
|
@ -449,4 +76,4 @@ extern char *qtypeStr[];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif /*_TD_COMMON_TAOS_DEF_H*/
|
||||||
|
|
|
@ -13,10 +13,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TDENGINE_COMMON_GLOBAL_H
|
#ifndef _TD_COMMON_GLOBAL_H
|
||||||
#define TDENGINE_COMMON_GLOBAL_H
|
#define _TD_COMMON_GLOBAL_H
|
||||||
|
|
||||||
#include "taosdef.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -52,9 +50,6 @@ extern float tsNumOfThreadsPerCore;
|
||||||
extern int32_t tsNumOfCommitThreads;
|
extern int32_t tsNumOfCommitThreads;
|
||||||
extern float tsRatioOfQueryCores;
|
extern float tsRatioOfQueryCores;
|
||||||
extern int8_t tsDaylight;
|
extern int8_t tsDaylight;
|
||||||
extern char tsTimezone[];
|
|
||||||
extern char tsLocale[];
|
|
||||||
extern char tsCharset[]; // default encode string
|
|
||||||
extern int8_t tsEnableCoreFile;
|
extern int8_t tsEnableCoreFile;
|
||||||
extern int32_t tsCompressMsgSize;
|
extern int32_t tsCompressMsgSize;
|
||||||
extern int32_t tsCompressColData;
|
extern int32_t tsCompressColData;
|
||||||
|
@ -151,24 +146,14 @@ extern int8_t tsEnableStream;
|
||||||
// internal
|
// internal
|
||||||
extern int8_t tsPrintAuth;
|
extern int8_t tsPrintAuth;
|
||||||
extern int8_t tscEmbedded;
|
extern int8_t tscEmbedded;
|
||||||
extern char configDir[];
|
|
||||||
extern char tsVnodeDir[];
|
extern char tsVnodeDir[];
|
||||||
extern char tsDnodeDir[];
|
|
||||||
extern char tsMnodeDir[];
|
extern char tsMnodeDir[];
|
||||||
extern char tsMnodeBakDir[];
|
extern char tsMnodeBakDir[];
|
||||||
extern char tsMnodeTmpDir[];
|
extern char tsMnodeTmpDir[];
|
||||||
extern char tsDataDir[];
|
|
||||||
extern char tsLogDir[];
|
|
||||||
extern char tsScriptDir[];
|
|
||||||
extern int64_t tsTickPerDay[3];
|
extern int64_t tsTickPerDay[3];
|
||||||
extern int32_t tsTopicBianryLen;
|
extern int32_t tsTopicBianryLen;
|
||||||
|
|
||||||
// system info
|
// system info
|
||||||
extern char tsOsName[];
|
|
||||||
extern int64_t tsPageSize;
|
|
||||||
extern int64_t tsOpenMax;
|
|
||||||
extern int64_t tsStreamMax;
|
|
||||||
extern int32_t tsNumOfCores;
|
|
||||||
extern float tsTotalLogDirGB;
|
extern float tsTotalLogDirGB;
|
||||||
extern float tsTotalTmpDirGB;
|
extern float tsTotalTmpDirGB;
|
||||||
extern float tsTotalDataDirGB;
|
extern float tsTotalDataDirGB;
|
||||||
|
@ -179,7 +164,6 @@ extern float tsUsedDataDirGB;
|
||||||
extern float tsMinimalLogDirGB;
|
extern float tsMinimalLogDirGB;
|
||||||
extern float tsReservedTmpDirectorySpace;
|
extern float tsReservedTmpDirectorySpace;
|
||||||
extern float tsMinimalDataDirGB;
|
extern float tsMinimalDataDirGB;
|
||||||
extern int32_t tsTotalMemoryMB;
|
|
||||||
extern uint32_t tsVersion;
|
extern uint32_t tsVersion;
|
||||||
|
|
||||||
// build info
|
// build info
|
||||||
|
@ -189,28 +173,6 @@ extern char gitinfo[];
|
||||||
extern char gitinfoOfInternal[];
|
extern char gitinfoOfInternal[];
|
||||||
extern char buildinfo[];
|
extern char buildinfo[];
|
||||||
|
|
||||||
// log
|
|
||||||
extern int8_t tsAsyncLog;
|
|
||||||
extern int32_t tsNumOfLogLines;
|
|
||||||
extern int32_t tsLogKeepDays;
|
|
||||||
extern int32_t dDebugFlag;
|
|
||||||
extern int32_t vDebugFlag;
|
|
||||||
extern int32_t mDebugFlag;
|
|
||||||
extern uint32_t cDebugFlag;
|
|
||||||
extern int32_t jniDebugFlag;
|
|
||||||
extern int32_t tmrDebugFlag;
|
|
||||||
extern int32_t sdbDebugFlag;
|
|
||||||
extern int32_t httpDebugFlag;
|
|
||||||
extern int32_t mqttDebugFlag;
|
|
||||||
extern int32_t monDebugFlag;
|
|
||||||
extern int32_t uDebugFlag;
|
|
||||||
extern int32_t rpcDebugFlag;
|
|
||||||
extern int32_t odbcDebugFlag;
|
|
||||||
extern uint32_t qDebugFlag;
|
|
||||||
extern int32_t wDebugFlag;
|
|
||||||
extern int32_t cqDebugFlag;
|
|
||||||
extern int32_t debugFlag;
|
|
||||||
|
|
||||||
#ifdef TD_TSZ
|
#ifdef TD_TSZ
|
||||||
// lossy
|
// lossy
|
||||||
extern char lossyColumns[];
|
extern char lossyColumns[];
|
||||||
|
@ -224,7 +186,7 @@ extern char Compressor[];
|
||||||
extern int8_t tsDeadLockKillQuery;
|
extern int8_t tsDeadLockKillQuery;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char dir[TSDB_FILENAME_LEN];
|
char dir[128];
|
||||||
int level;
|
int level;
|
||||||
int primary;
|
int primary;
|
||||||
} SDiskCfg;
|
} SDiskCfg;
|
||||||
|
@ -235,7 +197,6 @@ extern SDiskCfg tsDiskCfg[];
|
||||||
|
|
||||||
void taosInitGlobalCfg();
|
void taosInitGlobalCfg();
|
||||||
int32_t taosCheckGlobalCfg();
|
int32_t taosCheckGlobalCfg();
|
||||||
void taosSetAllDebugFlag();
|
|
||||||
bool taosCfgDynamicOptions(char *msg);
|
bool taosCfgDynamicOptions(char *msg);
|
||||||
int taosGetFqdnPortFromEp(const char *ep, char *fqdn, uint16_t *port);
|
int taosGetFqdnPortFromEp(const char *ep, char *fqdn, uint16_t *port);
|
||||||
bool taosCheckBalanceCfgOptions(const char *option, int32_t *vnodeId, int32_t *dnodeId);
|
bool taosCheckBalanceCfgOptions(const char *option, int32_t *vnodeId, int32_t *dnodeId);
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* 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_COMMON_TIME_H_
|
||||||
|
#define _TD_COMMON_TIME_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "taosdef.h"
|
||||||
|
#include "taosmsg.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @return timestamp decided by global conf variable, tsTimePrecision
|
||||||
|
* if precision == TSDB_TIME_PRECISION_MICRO, it returns timestamp in microsecond.
|
||||||
|
* precision == TSDB_TIME_PRECISION_MILLI, it returns timestamp in millisecond.
|
||||||
|
*/
|
||||||
|
static FORCE_INLINE int64_t taosGetTimestamp(int32_t precision) {
|
||||||
|
if (precision == TSDB_TIME_PRECISION_MICRO) {
|
||||||
|
return taosGetTimestampUs();
|
||||||
|
} else if (precision == TSDB_TIME_PRECISION_NANO) {
|
||||||
|
return taosGetTimestampNs();
|
||||||
|
}else {
|
||||||
|
return taosGetTimestampMs();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision);
|
||||||
|
int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precision);
|
||||||
|
int32_t taosTimeCountInterval(int64_t skey, int64_t ekey, int64_t interval, char unit, int32_t precision);
|
||||||
|
|
||||||
|
int32_t parseAbsoluteDuration(char* token, int32_t tokenlen, int64_t* ts, char* unit, int32_t timePrecision);
|
||||||
|
int32_t parseNatualDuration(const char* token, int32_t tokenLen, int64_t* duration, char* unit, int32_t timePrecision);
|
||||||
|
|
||||||
|
int32_t taosParseTime(char* timestr, int64_t* time, int32_t len, int32_t timePrec, int8_t dayligth);
|
||||||
|
void deltaToUtcInitOnce();
|
||||||
|
|
||||||
|
int64_t convertTimePrecision(int64_t time, int32_t fromPrecision, int32_t toPrecision);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /*_TD_COMMON_TIME_H_*/
|
|
@ -9,43 +9,6 @@ extern "C" {
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
|
|
||||||
// ----------------- For variable data types such as TSDB_DATA_TYPE_BINARY and TSDB_DATA_TYPE_NCHAR
|
|
||||||
typedef int32_t VarDataOffsetT;
|
|
||||||
typedef int16_t VarDataLenT; // maxVarDataLen: 32767
|
|
||||||
typedef uint16_t TDRowLenT; // not including overhead: 0 ~ 65535
|
|
||||||
typedef uint32_t TDRowTLenT; // total length, including overhead
|
|
||||||
|
|
||||||
typedef struct tstr {
|
|
||||||
VarDataLenT len;
|
|
||||||
char data[];
|
|
||||||
} tstr;
|
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
|
||||||
typedef struct {
|
|
||||||
VarDataLenT len;
|
|
||||||
uint8_t data;
|
|
||||||
} SBinaryNullT;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
VarDataLenT len;
|
|
||||||
uint32_t data;
|
|
||||||
} SNCharNullT;
|
|
||||||
#pragma pack(pop)
|
|
||||||
|
|
||||||
#define VARSTR_HEADER_SIZE sizeof(VarDataLenT)
|
|
||||||
|
|
||||||
#define varDataLen(v) ((VarDataLenT *)(v))[0]
|
|
||||||
#define varDataTLen(v) (sizeof(VarDataLenT) + varDataLen(v))
|
|
||||||
#define varDataVal(v) ((void *)((char *)v + VARSTR_HEADER_SIZE))
|
|
||||||
#define varDataCopy(dst, v) memcpy((dst), (void*) (v), varDataTLen(v))
|
|
||||||
#define varDataLenByData(v) (*(VarDataLenT *)(((char*)(v)) - VARSTR_HEADER_SIZE))
|
|
||||||
#define varDataSetLen(v, _len) (((VarDataLenT *)(v))[0] = (VarDataLenT) (_len))
|
|
||||||
#define IS_VAR_DATA_TYPE(t) (((t) == TSDB_DATA_TYPE_BINARY) || ((t) == TSDB_DATA_TYPE_NCHAR))
|
|
||||||
|
|
||||||
#define varDataNetLen(v) (htons(((VarDataLenT *)(v))[0]))
|
|
||||||
#define varDataNetTLen(v) (sizeof(VarDataLenT) + varDataNetLen(v))
|
|
||||||
|
|
||||||
|
|
||||||
// this data type is internally used only in 'in' query to hold the values
|
// this data type is internally used only in 'in' query to hold the values
|
||||||
#define TSDB_DATA_TYPE_POINTER_ARRAY (1000)
|
#define TSDB_DATA_TYPE_POINTER_ARRAY (1000)
|
||||||
#define TSDB_DATA_TYPE_VALUE_ARRAY (1001)
|
#define TSDB_DATA_TYPE_VALUE_ARRAY (1001)
|
||||||
|
|
|
@ -27,20 +27,26 @@ extern "C" {
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <setjmp.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <wctype.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
#include "osAtomic.h"
|
#include "osAtomic.h"
|
||||||
#include "osDef.h"
|
#include "osDef.h"
|
||||||
#include "osDir.h"
|
#include "osDir.h"
|
||||||
#include "osEndian.h"
|
#include "osEndian.h"
|
||||||
|
#include "osEnv.h"
|
||||||
#include "osFile.h"
|
#include "osFile.h"
|
||||||
|
#include "osLz4.h"
|
||||||
#include "osMath.h"
|
#include "osMath.h"
|
||||||
#include "osMemory.h"
|
#include "osMemory.h"
|
||||||
#include "osRand.h"
|
#include "osRand.h"
|
||||||
|
@ -49,10 +55,14 @@ extern "C" {
|
||||||
#include "osSleep.h"
|
#include "osSleep.h"
|
||||||
#include "osSocket.h"
|
#include "osSocket.h"
|
||||||
#include "osString.h"
|
#include "osString.h"
|
||||||
|
#include "osSysinfo.h"
|
||||||
|
#include "osSystem.h"
|
||||||
#include "osThread.h"
|
#include "osThread.h"
|
||||||
#include "osTime.h"
|
#include "osTime.h"
|
||||||
#include "osTimer.h"
|
#include "osTimer.h"
|
||||||
|
|
||||||
|
void osInit();
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -20,14 +20,154 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(_TD_DARWIN_64)
|
||||||
|
// specific
|
||||||
|
typedef int(*__compar_fn_t)(const void *, const void *);
|
||||||
|
|
||||||
|
// for send function in tsocket.c
|
||||||
|
#if defined(MSG_NOSIGNAL)
|
||||||
|
#undef MSG_NOSIGNAL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define MSG_NOSIGNAL 0
|
||||||
|
|
||||||
|
#define SO_NO_CHECK 0x1234
|
||||||
|
#define SOL_TCP 0x1234
|
||||||
|
#define TCP_KEEPIDLE 0x1234
|
||||||
|
|
||||||
|
#ifndef PTHREAD_MUTEX_RECURSIVE_NP
|
||||||
|
#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_ALPINE)
|
||||||
|
typedef int(*__compar_fn_t)(const void *, const void *);
|
||||||
|
void error (int, int, const char *);
|
||||||
|
#ifndef PTHREAD_MUTEX_RECURSIVE_NP
|
||||||
|
#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||||
|
char *stpcpy (char *dest, const char *src);
|
||||||
|
char *stpncpy (char *dest, const char *src, size_t n);
|
||||||
|
|
||||||
|
// specific
|
||||||
|
typedef int (*__compar_fn_t)(const void *, const void *);
|
||||||
|
#define ssize_t int
|
||||||
|
#define bzero(ptr, size) memset((ptr), 0, (size))
|
||||||
|
#define strcasecmp _stricmp
|
||||||
|
#define strncasecmp _strnicmp
|
||||||
|
#define wcsncasecmp _wcsnicmp
|
||||||
|
#define strtok_r strtok_s
|
||||||
|
#define snprintf _snprintf
|
||||||
|
#define in_addr_t unsigned long
|
||||||
|
#define socklen_t int
|
||||||
|
|
||||||
|
struct tm *localtime_r(const time_t *timep, struct tm *result);
|
||||||
|
char * strptime(const char *buf, const char *fmt, struct tm *tm);
|
||||||
|
char * strsep(char **stringp, const char *delim);
|
||||||
|
char * getpass(const char *prefix);
|
||||||
|
char * strndup(const char *s, size_t n);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define POINTER_SHIFT(p, b) ((void *)((char *)(p) + (b)))
|
||||||
|
#define POINTER_DISTANCE(p1, p2) ((char *)(p1) - (char *)(p2))
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
#define ASSERT(x) assert(x)
|
||||||
|
#else
|
||||||
|
#define ASSERT(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef UNUSED
|
||||||
|
#define UNUSED(x) ((void)(x))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef UNUSED_FUNC
|
||||||
|
#undefine UNUSED_FUNC
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef UNUSED_PARAM
|
||||||
|
#undef UNUSED_PARAM
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
#define UNUSED_PARAM(x) _UNUSED##x __attribute__((unused))
|
||||||
|
#define UNUSED_FUNC __attribute__((unused))
|
||||||
|
#else
|
||||||
|
#define UNUSED_PARAM(x) x
|
||||||
|
#define UNUSED_FUNC
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// TODO: replace and remove code below
|
||||||
|
#define CHAR_BYTES sizeof(char)
|
||||||
|
#define SHORT_BYTES sizeof(int16_t)
|
||||||
|
#define INT_BYTES sizeof(int32_t)
|
||||||
|
#define LONG_BYTES sizeof(int64_t)
|
||||||
|
#define FLOAT_BYTES sizeof(float)
|
||||||
|
#define DOUBLE_BYTES sizeof(double)
|
||||||
|
#define POINTER_BYTES sizeof(void *) // 8 by default assert(sizeof(ptrdiff_t) == sizseof(void*)
|
||||||
|
|
||||||
|
#ifdef tListLen
|
||||||
|
#undefine tListLen
|
||||||
|
#endif
|
||||||
|
#define tListLen(x) (sizeof(x) / sizeof((x)[0]))
|
||||||
|
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__)
|
||||||
#define FORCE_INLINE inline __attribute__((always_inline))
|
#define FORCE_INLINE inline __attribute__((always_inline))
|
||||||
#else
|
#else
|
||||||
#define FORCE_INLINE
|
#define FORCE_INLINE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define POINTER_SHIFT(p, b) ((void *)((char *)(p) + (b)))
|
#define DEFAULT_UNICODE_ENCODEC "UCS-4LE"
|
||||||
#define POINTER_DISTANCE(p1, p2) ((char *)(p1) - (char *)(p2))
|
|
||||||
|
#define DEFAULT_COMP(x, y) \
|
||||||
|
do { \
|
||||||
|
if ((x) == (y)) { \
|
||||||
|
return 0; \
|
||||||
|
} else { \
|
||||||
|
return (x) < (y) ? -1 : 1; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define DEFAULT_DOUBLE_COMP(x, y) \
|
||||||
|
do { \
|
||||||
|
if (isnan(x) && isnan(y)) { return 0; } \
|
||||||
|
if (isnan(x)) { return -1; } \
|
||||||
|
if (isnan(y)) { return 1; } \
|
||||||
|
if ((x) == (y)) { \
|
||||||
|
return 0; \
|
||||||
|
} else { \
|
||||||
|
return (x) < (y) ? -1 : 1; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define DEFAULT_FLOAT_COMP(x, y) DEFAULT_DOUBLE_COMP(x, y)
|
||||||
|
|
||||||
|
#define ALIGN_NUM(n, align) (((n) + ((align)-1)) & (~((align)-1)))
|
||||||
|
|
||||||
|
// align to 8bytes
|
||||||
|
#define ALIGN8(n) ALIGN_NUM(n, 8)
|
||||||
|
|
||||||
|
#undef threadlocal
|
||||||
|
#ifdef _ISOC11_SOURCE
|
||||||
|
#define threadlocal _Thread_local
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
#define threadlocal __thread
|
||||||
|
#elif defined(__GNUC__) && !defined(threadlocal)
|
||||||
|
#define threadlocal __thread
|
||||||
|
#else
|
||||||
|
#define threadlocal __declspec( thread )
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||||
|
#define PRIzu "ld"
|
||||||
|
#else
|
||||||
|
#define PRIzu "zu"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(_TD_LINUX_64) || defined(_TD_LINUX_32) || defined(_TD_MIPS_64) || defined(_TD_ARM_32) || defined(_TD_ARM_64) || defined(_TD_DARWIN_64)
|
#if defined(_TD_LINUX_64) || defined(_TD_LINUX_32) || defined(_TD_MIPS_64) || defined(_TD_ARM_32) || defined(_TD_ARM_64) || defined(_TD_DARWIN_64)
|
||||||
#if defined(_TD_DARWIN_64)
|
#if defined(_TD_DARWIN_64)
|
||||||
|
@ -47,17 +187,6 @@ extern "C" {
|
||||||
#define setThreadName(name)
|
#define setThreadName(name)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: replace and remove code below
|
|
||||||
#define CHAR_BYTES sizeof(char)
|
|
||||||
#define SHORT_BYTES sizeof(int16_t)
|
|
||||||
#define INT_BYTES sizeof(int32_t)
|
|
||||||
#define LONG_BYTES sizeof(int64_t)
|
|
||||||
#define FLOAT_BYTES sizeof(float)
|
|
||||||
#define DOUBLE_BYTES sizeof(double)
|
|
||||||
#define POINTER_BYTES sizeof(void *) // 8 by default assert(sizeof(ptrdiff_t) == sizseof(void*)
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -20,12 +20,12 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void taosRemoveDir(char *rootDir);
|
void taosRemoveDir(char *dirname);
|
||||||
bool taosDirExist(const char* dirname);
|
bool taosDirExist(char *dirname);
|
||||||
int32_t taosMkDir(const char *pathname, mode_t mode);
|
bool taosMkDir(char *dirname, mode_t mode);
|
||||||
void taosRemoveOldLogFiles(char *rootDir, int32_t keepDays);
|
void taosRemoveOldFiles(char *dirname, int32_t keepDays);
|
||||||
int32_t taosRename(char *oldName, char *newName);
|
bool taosExpandDir(char *dirname, char *outname, int32_t maxlen);
|
||||||
int32_t taosCompressFile(char *srcFileName, char *destFileName);
|
bool taosRealPath(char *dirname, int32_t maxlen);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,18 +13,22 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TDENGINE_OS_TIMER_H
|
#ifndef _TD_OS_ENV_H_
|
||||||
#define TDENGINE_OS_TIMER_H
|
#define _TD_OS_ENV_H_
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int taosInitTimer(void (*callback)(int), int ms);
|
extern char tsOsName[];
|
||||||
void taosUninitTimer();
|
extern char tsDnodeDir[];
|
||||||
|
extern char tsDataDir[];
|
||||||
|
extern char tsLogDir[];
|
||||||
|
extern char tsScriptDir[];
|
||||||
|
extern char configDir[];
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif /*_TD_OS_ENV_H_*/
|
|
@ -13,8 +13,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TDENGINE_OS_LZ4_H
|
#ifndef _TD_OS_LZ4_H_
|
||||||
#define TDENGINE_OS_LZ4_H
|
#define _TD_OS_LZ4_H_
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -46,4 +46,4 @@ extern "C" {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif /*_TD_OS_LZ4_H_*/
|
|
@ -20,8 +20,34 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int32_t taosInitTimer(void (*callback)(int32_t), int32_t ms);
|
#ifndef SIGALRM
|
||||||
void taosUninitTimer();
|
#define SIGALRM 1234
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef SIGHUP
|
||||||
|
#define SIGHUP 1230
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef SIGCHLD
|
||||||
|
#define SIGCHLD 1234
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef SIGUSR1
|
||||||
|
#define SIGUSR1 1234
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef SIGUSR2
|
||||||
|
#define SIGUSR2 1234
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef SIGBREAK
|
||||||
|
#define SIGBREAK 1234
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef void (*FSignalHandler)(int32_t signum, void *sigInfo, void *context);
|
||||||
|
void taosSetSignal(int32_t signum, FSignalHandler sigfp);
|
||||||
|
void taosIgnSignal(int32_t signum);
|
||||||
|
void taosDflSignal(int32_t signum);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TDENGINE_OS_SLEEP_H
|
#ifndef _TD_OS_SLEEP_H_
|
||||||
#define TDENGINE_OS_SLEEP_H
|
#define _TD_OS_SLEEP_H_
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -26,4 +26,4 @@ void taosMsleep(int32_t ms);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif /*_TD_OS_SLEEP_H_*/
|
|
@ -13,8 +13,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TDENGINE_OS_SOCKET_H
|
#ifndef _TD_OS_SOCKET_H_
|
||||||
#define TDENGINE_OS_SOCKET_H
|
#define _TD_OS_SOCKET_H_
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -89,4 +89,4 @@ const char *taosInetNtoa(struct in_addr ipInt);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif /*_TD_OS_SOCKET_H_*/
|
||||||
|
|
|
@ -43,7 +43,7 @@ int64_t taosStr2int64(char *str);
|
||||||
// USE_LIBICONV
|
// USE_LIBICONV
|
||||||
int32_t taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs);
|
int32_t taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs);
|
||||||
bool taosMbsToUcs4(char *mbs, size_t mbs_len, char *ucs4, int32_t ucs4_max_len, int32_t *len);
|
bool taosMbsToUcs4(char *mbs, size_t mbs_len, char *ucs4, int32_t ucs4_max_len, int32_t *len);
|
||||||
int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes);
|
int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes, int8_t ncharSize);
|
||||||
bool taosValidateEncodec(const char *encodec);
|
bool taosValidateEncodec(const char *encodec);
|
||||||
char * taosCharsetReplace(char *charsetstr);
|
char * taosCharsetReplace(char *charsetstr);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
/*
|
||||||
|
* 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_OS_SYSINFO_H_
|
||||||
|
#define _TD_OS_SYSINFO_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define TSDB_LOCALE_LEN 64
|
||||||
|
#define TSDB_TIMEZONE_LEN 96
|
||||||
|
|
||||||
|
extern int64_t tsPageSize;
|
||||||
|
extern int64_t tsOpenMax;
|
||||||
|
extern int64_t tsStreamMax;
|
||||||
|
extern int32_t tsNumOfCores;
|
||||||
|
extern int32_t tsTotalMemoryMB;
|
||||||
|
extern char tsTimezone[];
|
||||||
|
extern char tsLocale[];
|
||||||
|
extern char tsCharset[]; // default encode string
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int64_t tsize;
|
||||||
|
int64_t used;
|
||||||
|
int64_t avail;
|
||||||
|
} SysDiskSize;
|
||||||
|
|
||||||
|
int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize);
|
||||||
|
int32_t taosGetCpuCores();
|
||||||
|
void taosGetSystemInfo();
|
||||||
|
bool taosReadProcIO(int64_t *rchars, int64_t *wchars);
|
||||||
|
bool taosGetProcIO(float *readKB, float *writeKB);
|
||||||
|
bool taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes);
|
||||||
|
bool taosGetBandSpeed(float *bandSpeedKb);
|
||||||
|
void taosGetDisk();
|
||||||
|
bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage);
|
||||||
|
bool taosGetProcMemory(float *memoryUsedMB);
|
||||||
|
bool taosGetSysMemory(float *memoryUsedMB);
|
||||||
|
void taosPrintOsInfo();
|
||||||
|
int taosSystem(const char *cmd);
|
||||||
|
void taosKillSystem();
|
||||||
|
bool taosGetSystemUid(char *uid, int32_t uidlen);
|
||||||
|
char * taosGetCmdlineByPID(int pid);
|
||||||
|
void taosSetCoreDump(bool enable);
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const char *sysname;
|
||||||
|
const char *nodename;
|
||||||
|
const char *release;
|
||||||
|
const char *version;
|
||||||
|
const char *machine;
|
||||||
|
} SysNameInfo;
|
||||||
|
|
||||||
|
SysNameInfo taosGetSysNameInfo();
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
|
@ -13,21 +13,21 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TDENGINE_OS_SYSTEM_H
|
#ifndef _TD_OS_SYSTEM_H_
|
||||||
#define TDENGINE_OS_SYSTEM_H
|
#define _TD_OS_SYSTEM_H_
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void* taosLoadDll(const char *filename);
|
void* taosLoadDll(const char* filename);
|
||||||
void* taosLoadSym(void* handle, char* name);
|
void* taosLoadSym(void* handle, char* name);
|
||||||
void taosCloseDll(void *handle);
|
void taosCloseDll(void* handle);
|
||||||
|
|
||||||
int taosSetConsoleEcho(bool on);
|
int32_t taosSetConsoleEcho(bool on);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif /*_TD_OS_SYSTEM_H_*/
|
|
@ -20,6 +20,21 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||||
|
#ifdef _TD_GO_DLL_
|
||||||
|
#define MILLISECOND_PER_SECOND (1000LL)
|
||||||
|
#else
|
||||||
|
#define MILLISECOND_PER_SECOND (1000i64)
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define MILLISECOND_PER_SECOND ((int64_t)1000L)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define MILLISECOND_PER_MINUTE (MILLISECOND_PER_SECOND * 60)
|
||||||
|
#define MILLISECOND_PER_HOUR (MILLISECOND_PER_MINUTE * 60)
|
||||||
|
#define MILLISECOND_PER_DAY (MILLISECOND_PER_HOUR * 24)
|
||||||
|
#define MILLISECOND_PER_WEEK (MILLISECOND_PER_DAY * 7)
|
||||||
|
|
||||||
int32_t taosGetTimeOfDay(struct timeval *tv);
|
int32_t taosGetTimeOfDay(struct timeval *tv);
|
||||||
|
|
||||||
//@return timestamp in second
|
//@return timestamp in second
|
||||||
|
@ -46,11 +61,6 @@ static FORCE_INLINE int64_t taosGetTimestampNs() {
|
||||||
return (int64_t)systemTime.tv_sec * 1000000000L + (int64_t)systemTime.tv_nsec;
|
return (int64_t)systemTime.tv_sec * 1000000000L + (int64_t)systemTime.tv_nsec;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosParseTime(char* timestr, int64_t* time, int32_t len, int32_t timePrec, int8_t dayligth);
|
|
||||||
void deltaToUtcInitOnce();
|
|
||||||
|
|
||||||
int64_t convertTimePrecision(int64_t time, int32_t fromPrecision, int32_t toPrecision);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define MSECONDS_PER_TICK 5
|
||||||
|
|
||||||
int32_t taosInitTimer(void (*callback)(int32_t), int32_t ms);
|
int32_t taosInitTimer(void (*callback)(int32_t), int32_t ms);
|
||||||
void taosUninitTimer();
|
void taosUninitTimer();
|
||||||
|
|
||||||
|
|
|
@ -13,13 +13,10 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TDENGINE_EXCEPTION_H
|
#ifndef _TD_UTIL_EXCEPTION_H
|
||||||
#define TDENGINE_EXCEPTION_H
|
#define _TD_UTIL_EXCEPTION_H
|
||||||
|
|
||||||
#include <setjmp.h>
|
#include "os.h"
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -125,4 +122,4 @@ void exceptionThrow( int32_t code );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif /*_TD_UTIL_EXCEPTION_H*/
|
|
@ -13,8 +13,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TDENGINE_HASH_H
|
#ifndef _TD_UTIL_HASH_H
|
||||||
#define TDENGINE_HASH_H
|
#define _TD_UTIL_HASH_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -178,4 +178,4 @@ uint32_t taosHashGetDataKeyLen(SHashObj *pHashObj, void *data);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // TDENGINE_HASH_H
|
#endif /*_TD_UTIL_HASH_H*/
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TDENGINE_HASHUTIL_H
|
#ifndef _TD_UTIL_HASH_FUNC_H
|
||||||
#define TDENGINE_HASHUTIL_H
|
#define _TD_UTIL_HASH_FUNC_H
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
|
@ -48,4 +48,4 @@ _hash_fn_t taosGetDefaultHashFunction(int32_t type);
|
||||||
|
|
||||||
_equal_fn_t taosGetDefaultEqualFunction(int32_t type);
|
_equal_fn_t taosGetDefaultEqualFunction(int32_t type);
|
||||||
|
|
||||||
#endif //TDENGINE_HASHUTIL_H
|
#endif /*_TD_UTIL_HASH_FUNC_H*/
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TDENGINE_TALGO_H
|
#ifndef _TD_UTIL_TALGO_H
|
||||||
#define TDENGINE_TALGO_H
|
#define _TD_UTIL_TALGO_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -95,4 +95,4 @@ void taosheapsort(void *base, int32_t size, int32_t len, const void *parcompar,
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif // TDENGINE_TALGO_H
|
#endif /*_TD_UTIL_TALGO_H*/
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TDENGINE_TAOSARRAY_H
|
#ifndef _TD_UTIL_ARRAY_H
|
||||||
#define TDENGINE_TAOSARRAY_H
|
#define _TD_UTIL_ARRAY_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -228,6 +228,4 @@ void taosArraySortPWithExt(SArray* pArray, __ext_compar_fn_t fn, const void *par
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif /*_TD_UTIL_ARRAY_H*/
|
||||||
|
|
||||||
#endif // TDENGINE_TAOSARRAY_H
|
|
||||||
|
|
|
@ -13,11 +13,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TDENGINE_TBUFFER_H
|
#ifndef _TD_UTIL_BUFFER_H
|
||||||
#define TDENGINE_TBUFFER_H
|
#define _TD_UTIL_BUFFER_H
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -175,4 +172,4 @@ void tbufWriteDoubleAt( SBufferWriter* buf, size_t pos, double data );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif /*_TD_UTIL_BUFFER_H*/
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TDENGINE_TCACHE_H
|
#ifndef _TD_UTIL_CACHE_H
|
||||||
#define TDENGINE_TCACHE_H
|
#define _TD_UTIL_CACHE_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -188,4 +188,4 @@ void taosStopCacheRefreshWorker();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // TDENGINE_TCACHE_H
|
#endif /*_TD_UTIL_CACHE_H*/
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
* 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/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#ifndef _TD_CODING_H_
|
#ifndef _TD_UTIL_CODING_H
|
||||||
#define _TD_CODING_H_
|
#define _TD_UTIL_CODING_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -361,4 +361,4 @@ static FORCE_INLINE void *taosDecodeString(void *buf, char **value) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif /*_TD_UTIL_CODING_H*/
|
|
@ -13,8 +13,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TDENGINE_CFG_H
|
#ifndef _TD_UTIL_CONFIG_H
|
||||||
#define TDENGINE_CFG_H
|
#define _TD_UTIL_CONFIG_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -89,10 +89,9 @@ void taosDumpGlobalCfg();
|
||||||
|
|
||||||
void taosInitConfigOption(SGlobalCfg cfg);
|
void taosInitConfigOption(SGlobalCfg cfg);
|
||||||
SGlobalCfg * taosGetConfigOption(const char *option);
|
SGlobalCfg * taosGetConfigOption(const char *option);
|
||||||
bool taosReadConfigOption(const char *option, char *value, char *value2, char *value3, int8_t cfgStatus, int8_t sourceType);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // TDENGINE_TGLOBALCFG_H
|
#endif /*_TD_UTIL_CONFIG_H*/
|
||||||
|
|
|
@ -18,10 +18,8 @@
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TDENGINE_TCRC32C_H
|
#ifndef _TD_UTIL_CRC32_H
|
||||||
#define TDENGINE_TCRC32C_H
|
#define _TD_UTIL_CRC32_H
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -41,4 +39,4 @@ void taosResolveCRC();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // TDENGINE_TCRC32C_H
|
#endif /*_TD_UTIL_CRC32_H*/
|
||||||
|
|
|
@ -0,0 +1,451 @@
|
||||||
|
/*
|
||||||
|
* 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_UTIL_DEF_H
|
||||||
|
#define _TD_UTIL_DEF_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define TSDB__packed
|
||||||
|
|
||||||
|
#ifdef TSKEY32
|
||||||
|
#define TSKEY int32_t;
|
||||||
|
#else
|
||||||
|
#define TSKEY int64_t
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define TSKEY_INITIAL_VAL INT64_MIN
|
||||||
|
|
||||||
|
// Bytes for each type.
|
||||||
|
extern const int32_t TYPE_BYTES[15];
|
||||||
|
|
||||||
|
#define TSDB_KEYSIZE sizeof(TSKEY)
|
||||||
|
|
||||||
|
#if LINUX
|
||||||
|
#define TSDB_NCHAR_SIZE sizeof(wchar_t)
|
||||||
|
#else
|
||||||
|
#define TSDB_NCHAR_SIZE sizeof(int32_t)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// NULL definition
|
||||||
|
#define TSDB_DATA_BOOL_NULL 0x02
|
||||||
|
#define TSDB_DATA_TINYINT_NULL 0x80
|
||||||
|
#define TSDB_DATA_SMALLINT_NULL 0x8000
|
||||||
|
#define TSDB_DATA_INT_NULL 0x80000000L
|
||||||
|
#define TSDB_DATA_BIGINT_NULL 0x8000000000000000L
|
||||||
|
#define TSDB_DATA_TIMESTAMP_NULL TSDB_DATA_BIGINT_NULL
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
|
#define TSDB_DATA_UTINYINT_NULL 0xFF
|
||||||
|
#define TSDB_DATA_USMALLINT_NULL 0xFFFF
|
||||||
|
#define TSDB_DATA_UINT_NULL 0xFFFFFFFF
|
||||||
|
#define TSDB_DATA_UBIGINT_NULL 0xFFFFFFFFFFFFFFFFL
|
||||||
|
|
||||||
|
#define TSDB_DATA_NULL_STR "NULL"
|
||||||
|
#define TSDB_DATA_NULL_STR_L "null"
|
||||||
|
|
||||||
|
#define TSDB_DEFAULT_USER "root"
|
||||||
|
#ifdef _TD_POWER_
|
||||||
|
#define TSDB_DEFAULT_PASS "powerdb"
|
||||||
|
#elif (_TD_TQ_ == true)
|
||||||
|
#define TSDB_DEFAULT_PASS "tqueue"
|
||||||
|
#elif (_TD_PRO_ == true)
|
||||||
|
#define TSDB_DEFAULT_PASS "prodb"
|
||||||
|
#else
|
||||||
|
#define TSDB_DEFAULT_PASS "taosdata"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define SHELL_MAX_PASSWORD_LEN 20
|
||||||
|
|
||||||
|
#define TSDB_TRUE 1
|
||||||
|
#define TSDB_FALSE 0
|
||||||
|
#define TSDB_OK 0
|
||||||
|
#define TSDB_ERR -1
|
||||||
|
|
||||||
|
#define TS_PATH_DELIMITER "."
|
||||||
|
|
||||||
|
#define TSDB_TIME_PRECISION_MILLI 0
|
||||||
|
#define TSDB_TIME_PRECISION_MICRO 1
|
||||||
|
#define TSDB_TIME_PRECISION_NANO 2
|
||||||
|
|
||||||
|
#define TSDB_TIME_PRECISION_MILLI_STR "ms"
|
||||||
|
#define TSDB_TIME_PRECISION_MICRO_STR "us"
|
||||||
|
#define TSDB_TIME_PRECISION_NANO_STR "ns"
|
||||||
|
|
||||||
|
#define TSDB_TICK_PER_SECOND(precision) ((int64_t)((precision)==TSDB_TIME_PRECISION_MILLI ? 1e3L : ((precision)==TSDB_TIME_PRECISION_MICRO ? 1e6L : 1e9L)))
|
||||||
|
|
||||||
|
#define T_MEMBER_SIZE(type, member) sizeof(((type *)0)->member)
|
||||||
|
#define T_APPEND_MEMBER(dst, ptr, type, member) \
|
||||||
|
do {\
|
||||||
|
memcpy((void *)(dst), (void *)(&((ptr)->member)), T_MEMBER_SIZE(type, member));\
|
||||||
|
dst = (void *)((char *)(dst) + T_MEMBER_SIZE(type, member));\
|
||||||
|
} while(0)
|
||||||
|
#define T_READ_MEMBER(src, type, target) \
|
||||||
|
do { \
|
||||||
|
(target) = *(type *)(src); \
|
||||||
|
(src) = (void *)((char *)src + sizeof(type));\
|
||||||
|
} while(0)
|
||||||
|
|
||||||
|
#define GET_INT8_VAL(x) (*(int8_t *)(x))
|
||||||
|
#define GET_INT16_VAL(x) (*(int16_t *)(x))
|
||||||
|
#define GET_INT32_VAL(x) (*(int32_t *)(x))
|
||||||
|
#define GET_INT64_VAL(x) (*(int64_t *)(x))
|
||||||
|
#define GET_UINT8_VAL(x) (*(uint8_t*) (x))
|
||||||
|
#define GET_UINT16_VAL(x) (*(uint16_t *)(x))
|
||||||
|
#define GET_UINT32_VAL(x) (*(uint32_t *)(x))
|
||||||
|
#define GET_UINT64_VAL(x) (*(uint64_t *)(x))
|
||||||
|
|
||||||
|
#ifdef _TD_ARM_32
|
||||||
|
float taos_align_get_float(const char* pBuf);
|
||||||
|
double taos_align_get_double(const char* pBuf);
|
||||||
|
|
||||||
|
#define GET_FLOAT_VAL(x) taos_align_get_float(x)
|
||||||
|
#define GET_DOUBLE_VAL(x) taos_align_get_double(x)
|
||||||
|
#define SET_FLOAT_VAL(x, y) { float z = (float)(y); (*(int32_t*) x = *(int32_t*)(&z)); }
|
||||||
|
#define SET_DOUBLE_VAL(x, y) { double z = (double)(y); (*(int64_t*) x = *(int64_t*)(&z)); }
|
||||||
|
#define SET_FLOAT_PTR(x, y) { (*(int32_t*) x = *(int32_t*)y); }
|
||||||
|
#define SET_DOUBLE_PTR(x, y) { (*(int64_t*) x = *(int64_t*)y); }
|
||||||
|
#else
|
||||||
|
#define GET_FLOAT_VAL(x) (*(float *)(x))
|
||||||
|
#define GET_DOUBLE_VAL(x) (*(double *)(x))
|
||||||
|
#define SET_FLOAT_VAL(x, y) { (*(float *)(x)) = (float)(y); }
|
||||||
|
#define SET_DOUBLE_VAL(x, y) { (*(double *)(x)) = (double)(y); }
|
||||||
|
#define SET_FLOAT_PTR(x, y) { (*(float *)(x)) = (*(float *)(y)); }
|
||||||
|
#define SET_DOUBLE_PTR(x, y) { (*(double *)(x)) = (*(double *)(y)); }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// TODO: check if below is necessary
|
||||||
|
#define TSDB_RELATION_INVALID 0
|
||||||
|
#define TSDB_RELATION_LESS 1
|
||||||
|
#define TSDB_RELATION_GREATER 2
|
||||||
|
#define TSDB_RELATION_EQUAL 3
|
||||||
|
#define TSDB_RELATION_LESS_EQUAL 4
|
||||||
|
#define TSDB_RELATION_GREATER_EQUAL 5
|
||||||
|
#define TSDB_RELATION_NOT_EQUAL 6
|
||||||
|
#define TSDB_RELATION_LIKE 7
|
||||||
|
#define TSDB_RELATION_ISNULL 8
|
||||||
|
#define TSDB_RELATION_NOTNULL 9
|
||||||
|
#define TSDB_RELATION_IN 10
|
||||||
|
|
||||||
|
#define TSDB_RELATION_AND 11
|
||||||
|
#define TSDB_RELATION_OR 12
|
||||||
|
#define TSDB_RELATION_NOT 13
|
||||||
|
|
||||||
|
#define TSDB_RELATION_MATCH 14
|
||||||
|
#define TSDB_RELATION_NMATCH 15
|
||||||
|
|
||||||
|
#define TSDB_BINARY_OP_ADD 30
|
||||||
|
#define TSDB_BINARY_OP_SUBTRACT 31
|
||||||
|
#define TSDB_BINARY_OP_MULTIPLY 32
|
||||||
|
#define TSDB_BINARY_OP_DIVIDE 33
|
||||||
|
#define TSDB_BINARY_OP_REMAINDER 34
|
||||||
|
|
||||||
|
|
||||||
|
#define IS_RELATION_OPTR(op) (((op) >= TSDB_RELATION_LESS) && ((op) < TSDB_RELATION_IN))
|
||||||
|
#define IS_ARITHMETIC_OPTR(op) (((op) >= TSDB_BINARY_OP_ADD) && ((op) <= TSDB_BINARY_OP_REMAINDER))
|
||||||
|
|
||||||
|
#define TS_PATH_DELIMITER_LEN 1
|
||||||
|
|
||||||
|
#define TSDB_UNI_LEN 24
|
||||||
|
#define TSDB_USER_LEN TSDB_UNI_LEN
|
||||||
|
|
||||||
|
// ACCOUNT is a 32 bit positive integer
|
||||||
|
// this is the length of its string representation, including the terminator zero
|
||||||
|
#define TSDB_ACCT_ID_LEN 11
|
||||||
|
|
||||||
|
#define TSDB_MAX_COLUMNS 4096
|
||||||
|
#define TSDB_MIN_COLUMNS 2 //PRIMARY COLUMN(timestamp) + other columns
|
||||||
|
|
||||||
|
#define TSDB_NODE_NAME_LEN 64
|
||||||
|
#define TSDB_TABLE_NAME_LEN 193 // it is a null-terminated string
|
||||||
|
#define TSDB_DB_NAME_LEN 33
|
||||||
|
#define TSDB_FUNC_NAME_LEN 65
|
||||||
|
#define TSDB_FUNC_CODE_LEN (65535 - 512)
|
||||||
|
#define TSDB_FUNC_BUF_SIZE 512
|
||||||
|
#define TSDB_TYPE_STR_MAX_LEN 32
|
||||||
|
#define TSDB_TABLE_FNAME_LEN (TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN + TSDB_TABLE_NAME_LEN)
|
||||||
|
#define TSDB_COL_NAME_LEN 65
|
||||||
|
#define TSDB_MAX_SAVED_SQL_LEN TSDB_MAX_COLUMNS * 64
|
||||||
|
#define TSDB_MAX_SQL_LEN TSDB_PAYLOAD_SIZE
|
||||||
|
#define TSDB_MAX_SQL_SHOW_LEN 512
|
||||||
|
#define TSDB_MAX_ALLOWED_SQL_LEN (1*1024*1024u) // sql length should be less than 1mb
|
||||||
|
|
||||||
|
#define TSDB_APPNAME_LEN TSDB_UNI_LEN
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In some scenarios uint16_t (0~65535) is used to store the row len.
|
||||||
|
* - Firstly, we use 65531(65535 - 4), as the SDataRow/SKVRow contains 4 bits header.
|
||||||
|
* - Secondly, if all cols are VarDataT type except primary key, we need 4 bits to store the offset, thus
|
||||||
|
* the final value is 65531-(4096-1)*4 = 49151.
|
||||||
|
*/
|
||||||
|
#define TSDB_MAX_BYTES_PER_ROW 49151
|
||||||
|
#define TSDB_MAX_TAGS_LEN 16384
|
||||||
|
#define TSDB_MAX_TAGS 128
|
||||||
|
#define TSDB_MAX_TAG_CONDITIONS 1024
|
||||||
|
|
||||||
|
#define TSDB_AUTH_LEN 16
|
||||||
|
#define TSDB_KEY_LEN 16
|
||||||
|
#define TSDB_VERSION_LEN 12
|
||||||
|
#define TSDB_LABEL_LEN 8
|
||||||
|
|
||||||
|
#define TSDB_CLUSTER_ID_LEN 40
|
||||||
|
#define TSDB_FQDN_LEN 128
|
||||||
|
#define TSDB_EP_LEN (TSDB_FQDN_LEN+6)
|
||||||
|
#define TSDB_IPv4ADDR_LEN 16
|
||||||
|
#define TSDB_FILENAME_LEN 128
|
||||||
|
#define TSDB_SHOW_SQL_LEN 512
|
||||||
|
#define TSDB_SHOW_SUBQUERY_LEN 1000
|
||||||
|
#define TSDB_SLOW_QUERY_SQL_LEN 512
|
||||||
|
|
||||||
|
#define TSDB_STEP_NAME_LEN 32
|
||||||
|
#define TSDB_STEP_DESC_LEN 128
|
||||||
|
|
||||||
|
#define TSDB_MQTT_HOSTNAME_LEN 64
|
||||||
|
#define TSDB_MQTT_PORT_LEN 8
|
||||||
|
#define TSDB_MQTT_USER_LEN 24
|
||||||
|
#define TSDB_MQTT_PASS_LEN 24
|
||||||
|
#define TSDB_MQTT_TOPIC_LEN 64
|
||||||
|
#define TSDB_MQTT_CLIENT_ID_LEN 32
|
||||||
|
|
||||||
|
#define TSDB_DB_TYPE_DEFAULT 0
|
||||||
|
#define TSDB_DB_TYPE_TOPIC 1
|
||||||
|
|
||||||
|
#define TSDB_DEFAULT_PKT_SIZE 65480 //same as RPC_MAX_UDP_SIZE
|
||||||
|
|
||||||
|
#define TSDB_PAYLOAD_SIZE TSDB_DEFAULT_PKT_SIZE
|
||||||
|
#define TSDB_DEFAULT_PAYLOAD_SIZE 5120 // default payload size, greater than PATH_MAX value
|
||||||
|
#define TSDB_EXTRA_PAYLOAD_SIZE 128 // extra bytes for auth
|
||||||
|
#define TSDB_CQ_SQL_SIZE 1024
|
||||||
|
#define TSDB_MIN_VNODES 64
|
||||||
|
#define TSDB_MAX_VNODES 2048
|
||||||
|
#define TSDB_MIN_VNODES_PER_DB 2
|
||||||
|
#define TSDB_MAX_VNODES_PER_DB 64
|
||||||
|
|
||||||
|
#define TSDB_DNODE_ROLE_ANY 0
|
||||||
|
#define TSDB_DNODE_ROLE_MGMT 1
|
||||||
|
#define TSDB_DNODE_ROLE_VNODE 2
|
||||||
|
|
||||||
|
#define TSDB_MAX_REPLICA 5
|
||||||
|
|
||||||
|
#define TSDB_TBNAME_COLUMN_INDEX (-1)
|
||||||
|
#define TSDB_UD_COLUMN_INDEX (-1000)
|
||||||
|
#define TSDB_RES_COL_ID (-5000)
|
||||||
|
|
||||||
|
#define TSDB_MULTI_TABLEMETA_MAX_NUM 100000 // maximum batch size allowed to load table meta
|
||||||
|
|
||||||
|
#define TSDB_MIN_CACHE_BLOCK_SIZE 1
|
||||||
|
#define TSDB_MAX_CACHE_BLOCK_SIZE 128 // 128MB for each vnode
|
||||||
|
#define TSDB_DEFAULT_CACHE_BLOCK_SIZE 16
|
||||||
|
|
||||||
|
#define TSDB_MIN_TOTAL_BLOCKS 3
|
||||||
|
#define TSDB_MAX_TOTAL_BLOCKS 10000
|
||||||
|
#define TSDB_DEFAULT_TOTAL_BLOCKS 6
|
||||||
|
|
||||||
|
#define TSDB_MIN_TABLES 4
|
||||||
|
#define TSDB_MAX_TABLES 10000000
|
||||||
|
#define TSDB_DEFAULT_TABLES 1000000
|
||||||
|
#define TSDB_TABLES_STEP 1000
|
||||||
|
#define TSDB_META_COMPACT_RATIO 0 // disable tsdb meta compact by default
|
||||||
|
|
||||||
|
#define TSDB_MIN_DAYS_PER_FILE 1
|
||||||
|
#define TSDB_MAX_DAYS_PER_FILE 3650
|
||||||
|
#define TSDB_DEFAULT_DAYS_PER_FILE 10
|
||||||
|
|
||||||
|
#define TSDB_MIN_KEEP 1 // data in db to be reserved.
|
||||||
|
#define TSDB_MAX_KEEP 365000 // data in db to be reserved.
|
||||||
|
#define TSDB_DEFAULT_KEEP 3650 // ten years
|
||||||
|
|
||||||
|
#define TSDB_DEFAULT_MIN_ROW_FBLOCK 100
|
||||||
|
#define TSDB_MIN_MIN_ROW_FBLOCK 10
|
||||||
|
#define TSDB_MAX_MIN_ROW_FBLOCK 1000
|
||||||
|
|
||||||
|
#define TSDB_DEFAULT_MAX_ROW_FBLOCK 4096
|
||||||
|
#define TSDB_MIN_MAX_ROW_FBLOCK 200
|
||||||
|
#define TSDB_MAX_MAX_ROW_FBLOCK 10000
|
||||||
|
|
||||||
|
#define TSDB_MIN_COMMIT_TIME 30
|
||||||
|
#define TSDB_MAX_COMMIT_TIME 40960
|
||||||
|
#define TSDB_DEFAULT_COMMIT_TIME 3600
|
||||||
|
|
||||||
|
#define TSDB_MIN_PRECISION TSDB_TIME_PRECISION_MILLI
|
||||||
|
#define TSDB_MAX_PRECISION TSDB_TIME_PRECISION_NANO
|
||||||
|
#define TSDB_DEFAULT_PRECISION TSDB_TIME_PRECISION_MILLI
|
||||||
|
|
||||||
|
#define TSDB_MIN_COMP_LEVEL 0
|
||||||
|
#define TSDB_MAX_COMP_LEVEL 2
|
||||||
|
#define TSDB_DEFAULT_COMP_LEVEL 2
|
||||||
|
|
||||||
|
#define TSDB_MIN_WAL_LEVEL 0
|
||||||
|
#define TSDB_MAX_WAL_LEVEL 2
|
||||||
|
#define TSDB_DEFAULT_WAL_LEVEL 1
|
||||||
|
|
||||||
|
#define TSDB_MIN_DB_UPDATE 0
|
||||||
|
#define TSDB_MAX_DB_UPDATE 2
|
||||||
|
#define TSDB_DEFAULT_DB_UPDATE_OPTION 0
|
||||||
|
|
||||||
|
#define TSDB_MIN_DB_CACHE_LAST_ROW 0
|
||||||
|
#define TSDB_MAX_DB_CACHE_LAST_ROW 3
|
||||||
|
#define TSDB_DEFAULT_CACHE_LAST_ROW 0
|
||||||
|
|
||||||
|
#define TSDB_MIN_FSYNC_PERIOD 0
|
||||||
|
#define TSDB_MAX_FSYNC_PERIOD 180000 // millisecond
|
||||||
|
#define TSDB_DEFAULT_FSYNC_PERIOD 3000 // three second
|
||||||
|
|
||||||
|
#define TSDB_MIN_DB_REPLICA_OPTION 1
|
||||||
|
#define TSDB_MAX_DB_REPLICA_OPTION 3
|
||||||
|
#define TSDB_DEFAULT_DB_REPLICA_OPTION 1
|
||||||
|
|
||||||
|
#define TSDB_MIN_DB_PARTITON_OPTION 0
|
||||||
|
#define TSDB_MAX_DB_PARTITON_OPTION 1000
|
||||||
|
#define TSDB_DEFAULT_DB_PARTITON_OPTION 4
|
||||||
|
|
||||||
|
#define TSDB_MIN_DB_QUORUM_OPTION 1
|
||||||
|
#define TSDB_MAX_DB_QUORUM_OPTION 2
|
||||||
|
#define TSDB_DEFAULT_DB_QUORUM_OPTION 1
|
||||||
|
|
||||||
|
#define TSDB_MAX_JOIN_TABLE_NUM 10
|
||||||
|
#define TSDB_MAX_UNION_CLAUSE 5
|
||||||
|
|
||||||
|
#define TSDB_MAX_FIELD_LEN 16384
|
||||||
|
#define TSDB_MAX_BINARY_LEN (TSDB_MAX_FIELD_LEN-TSDB_KEYSIZE) // keep 16384
|
||||||
|
#define TSDB_MAX_NCHAR_LEN (TSDB_MAX_FIELD_LEN-TSDB_KEYSIZE) // keep 16384
|
||||||
|
#define PRIMARYKEY_TIMESTAMP_COL_INDEX 0
|
||||||
|
|
||||||
|
#define TSDB_MAX_RPC_THREADS 5
|
||||||
|
|
||||||
|
#define TSDB_QUERY_TYPE_NON_TYPE 0x00u // none type
|
||||||
|
#define TSDB_QUERY_TYPE_FREE_RESOURCE 0x01u // free qhandle at vnode
|
||||||
|
|
||||||
|
#define TSDB_UDF_TYPE_SCALAR 1
|
||||||
|
#define TSDB_UDF_TYPE_AGGREGATE 2
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 1. ordinary sub query for select * from super_table
|
||||||
|
* 2. all sqlobj generated by createSubqueryObj with this flag
|
||||||
|
*/
|
||||||
|
#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
|
||||||
|
|
||||||
|
#define TSDB_QUERY_TYPE_TAG_FILTER_QUERY 0x400u
|
||||||
|
#define TSDB_QUERY_TYPE_INSERT 0x100u // insert type
|
||||||
|
#define TSDB_QUERY_TYPE_MULTITABLE_QUERY 0x200u
|
||||||
|
#define TSDB_QUERY_TYPE_FILE_INSERT 0x400u // insert data from file
|
||||||
|
#define TSDB_QUERY_TYPE_STMT_INSERT 0x800u // stmt insert type
|
||||||
|
#define TSDB_QUERY_TYPE_NEST_SUBQUERY 0x1000u // nested sub query
|
||||||
|
|
||||||
|
#define TSDB_QUERY_HAS_TYPE(x, _type) (((x) & (_type)) != 0)
|
||||||
|
#define TSDB_QUERY_SET_TYPE(x, _type) ((x) |= (_type))
|
||||||
|
#define TSDB_QUERY_CLEAR_TYPE(x, _type) ((x) &= (~_type))
|
||||||
|
#define TSDB_QUERY_RESET_TYPE(x) ((x) = TSDB_QUERY_TYPE_NON_TYPE)
|
||||||
|
|
||||||
|
#define TSDB_ORDER_ASC 1
|
||||||
|
#define TSDB_ORDER_DESC 2
|
||||||
|
|
||||||
|
#define TSDB_DEFAULT_CLUSTER_HASH_SIZE 1
|
||||||
|
#define TSDB_DEFAULT_MNODES_HASH_SIZE 5
|
||||||
|
#define TSDB_DEFAULT_DNODES_HASH_SIZE 10
|
||||||
|
#define TSDB_DEFAULT_ACCOUNTS_HASH_SIZE 10
|
||||||
|
#define TSDB_DEFAULT_USERS_HASH_SIZE 20
|
||||||
|
#define TSDB_DEFAULT_DBS_HASH_SIZE 100
|
||||||
|
#define TSDB_DEFAULT_VGROUPS_HASH_SIZE 100
|
||||||
|
#define TSDB_DEFAULT_STABLES_HASH_SIZE 100
|
||||||
|
#define TSDB_DEFAULT_CTABLES_HASH_SIZE 20000
|
||||||
|
|
||||||
|
#define TSDB_PORT_DNODESHELL 0
|
||||||
|
#define TSDB_PORT_DNODEDNODE 5
|
||||||
|
#define TSDB_PORT_SYNC 10
|
||||||
|
#define TSDB_PORT_HTTP 11
|
||||||
|
#define TSDB_PORT_ARBITRATOR 12
|
||||||
|
|
||||||
|
#define TSDB_MAX_WAL_SIZE (1024*1024*3)
|
||||||
|
|
||||||
|
#define TSDB_ARB_DUMMY_TIME 4765104000000 // 2121-01-01 00:00:00.000, :P
|
||||||
|
|
||||||
|
#define TSDB_MAX_TIERS 3
|
||||||
|
#define TSDB_MAX_DISKS_PER_TIER 16
|
||||||
|
#define TSDB_MAX_DISKS (TSDB_MAX_TIERS * TSDB_MAX_DISKS_PER_TIER)
|
||||||
|
|
||||||
|
#define TSDB_DATA_TYPE_NULL 0 // 1 bytes
|
||||||
|
#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
|
||||||
|
#define TSDB_DATA_TYPE_UTINYINT 11 // 1 byte
|
||||||
|
#define TSDB_DATA_TYPE_USMALLINT 12 // 2 bytes
|
||||||
|
#define TSDB_DATA_TYPE_UINT 13 // 4 bytes
|
||||||
|
#define TSDB_DATA_TYPE_UBIGINT 14 // 8 bytes
|
||||||
|
|
||||||
|
// ----------------- For variable data types such as TSDB_DATA_TYPE_BINARY and TSDB_DATA_TYPE_NCHAR
|
||||||
|
|
||||||
|
typedef int32_t VarDataOffsetT;
|
||||||
|
typedef int16_t VarDataLenT; // maxVarDataLen: 32767
|
||||||
|
typedef uint16_t TDRowLenT; // not including overhead: 0 ~ 65535
|
||||||
|
typedef uint32_t TDRowTLenT; // total length, including overhead
|
||||||
|
|
||||||
|
typedef struct tstr {
|
||||||
|
VarDataLenT len;
|
||||||
|
char data[];
|
||||||
|
} tstr;
|
||||||
|
|
||||||
|
#pragma pack(push, 1)
|
||||||
|
typedef struct {
|
||||||
|
VarDataLenT len;
|
||||||
|
uint8_t data;
|
||||||
|
} SBinaryNullT;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
VarDataLenT len;
|
||||||
|
uint32_t data;
|
||||||
|
} SNCharNullT;
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
#define VARSTR_HEADER_SIZE sizeof(VarDataLenT)
|
||||||
|
|
||||||
|
#define varDataLen(v) ((VarDataLenT *)(v))[0]
|
||||||
|
#define varDataTLen(v) (sizeof(VarDataLenT) + varDataLen(v))
|
||||||
|
#define varDataVal(v) ((void *)((char *)v + VARSTR_HEADER_SIZE))
|
||||||
|
#define varDataCopy(dst, v) memcpy((dst), (void*) (v), varDataTLen(v))
|
||||||
|
#define varDataLenByData(v) (*(VarDataLenT *)(((char*)(v)) - VARSTR_HEADER_SIZE))
|
||||||
|
#define varDataSetLen(v, _len) (((VarDataLenT *)(v))[0] = (VarDataLenT) (_len))
|
||||||
|
#define IS_VAR_DATA_TYPE(t) (((t) == TSDB_DATA_TYPE_BINARY) || ((t) == TSDB_DATA_TYPE_NCHAR))
|
||||||
|
|
||||||
|
#define varDataNetLen(v) (htons(((VarDataLenT *)(v))[0]))
|
||||||
|
#define varDataNetTLen(v) (sizeof(VarDataLenT) + varDataNetLen(v))
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
|
@ -12,8 +12,8 @@
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
* 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/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#ifndef _TD_LIST_
|
#ifndef _TD_UTIL_LIST_H
|
||||||
#define _TD_LIST_
|
#define _TD_UTIL_LIST_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -69,4 +69,4 @@ SListNode *tdListNext(SListIter *pIter);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif /*_TD_UTIL_LIST_H*/
|
|
@ -12,8 +12,8 @@
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
* 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/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#ifndef __TD_LOCK_FREE_H__
|
#ifndef _TD_UTIL_LOCK_FREE_H
|
||||||
#define __TD_LOCK_FREE_H__
|
#define _TD_UTIL_LOCK_FREE_H
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// reference counting
|
// reference counting
|
||||||
typedef void (*_ref_fn_t)(const void* pObj);
|
typedef void (*_ref_fn_t)(const void* pObj);
|
||||||
|
|
||||||
|
@ -106,9 +105,8 @@ void taosRUnLockLatch(SRWLatch *pLatch);
|
||||||
break; \
|
break; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif /*_TD_UTIL_LOCK_FREE_H*/
|
||||||
|
|
|
@ -13,13 +13,38 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TDENGINE_TLOG_H
|
#ifndef _TD_UTIL_LOG_H
|
||||||
#define TDENGINE_TLOG_H
|
#define _TD_UTIL_LOG_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// log
|
||||||
|
extern int8_t tsAsyncLog;
|
||||||
|
extern int32_t tsNumOfLogLines;
|
||||||
|
extern int32_t tsLogKeepDays;
|
||||||
|
extern int32_t dDebugFlag;
|
||||||
|
extern int32_t vDebugFlag;
|
||||||
|
extern int32_t mDebugFlag;
|
||||||
|
extern int32_t cDebugFlag;
|
||||||
|
extern int32_t jniDebugFlag;
|
||||||
|
extern int32_t tmrDebugFlag;
|
||||||
|
extern int32_t sdbDebugFlag;
|
||||||
|
extern int32_t httpDebugFlag;
|
||||||
|
extern int32_t mqttDebugFlag;
|
||||||
|
extern int32_t monDebugFlag;
|
||||||
|
extern int32_t uDebugFlag;
|
||||||
|
extern int32_t rpcDebugFlag;
|
||||||
|
extern int32_t odbcDebugFlag;
|
||||||
|
extern int32_t qDebugFlag;
|
||||||
|
extern int32_t wDebugFlag;
|
||||||
|
extern int32_t sDebugFlag;
|
||||||
|
extern int32_t tsdbDebugFlag;
|
||||||
|
extern int32_t cqDebugFlag;
|
||||||
|
extern int32_t debugFlag;
|
||||||
|
|
||||||
#define DEBUG_FATAL 1U
|
#define DEBUG_FATAL 1U
|
||||||
#define DEBUG_ERROR DEBUG_FATAL
|
#define DEBUG_ERROR DEBUG_FATAL
|
||||||
#define DEBUG_WARN 2U
|
#define DEBUG_WARN 2U
|
||||||
|
@ -53,4 +78,4 @@ void taosDumpData(unsigned char *msg, int32_t len);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif /*_TD_UTIL_LOG_H*/
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "taosdef.h"
|
#include "tdef.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
|
|
||||||
#define COMP_OVERFLOW_BYTES 2
|
#define COMP_OVERFLOW_BYTES 2
|
||||||
|
|
|
@ -53,11 +53,6 @@ static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, size_t inLen, char *tar
|
||||||
memcpy(target, context.digest, keylen);
|
memcpy(target, context.digest, keylen);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef tListLen
|
|
||||||
#undefine tListLen
|
|
||||||
#endif
|
|
||||||
#define tListLen(x) (sizeof(x) / sizeof((x)[0]))
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,4 +4,9 @@ target_include_directories(
|
||||||
common
|
common
|
||||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/common"
|
PUBLIC "${CMAKE_SOURCE_DIR}/include/common"
|
||||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||||
|
)
|
||||||
|
target_link_libraries(
|
||||||
|
common
|
||||||
|
PUBLIC os
|
||||||
|
PUBLIC util
|
||||||
)
|
)
|
|
@ -18,14 +18,14 @@
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
#include "taoserror.h"
|
#include "taoserror.h"
|
||||||
#include "tulog.h"
|
#include "tulog.h"
|
||||||
|
#include "tlog.h"
|
||||||
#include "tconfig.h"
|
#include "tconfig.h"
|
||||||
#include "tglobal.h"
|
#include "tglobal.h"
|
||||||
#include "monitor.h"
|
|
||||||
#include "tsocket.h"
|
#include "tsocket.h"
|
||||||
#include "tutil.h"
|
|
||||||
#include "tlocale.h"
|
|
||||||
#include "ttimezone.h"
|
|
||||||
#include "tcompare.h"
|
#include "tcompare.h"
|
||||||
|
#include "tutil.h"
|
||||||
|
#include "ttimezone.h"
|
||||||
|
#include "tlocale.h"
|
||||||
|
|
||||||
// cluster
|
// cluster
|
||||||
char tsFirst[TSDB_EP_LEN] = {0};
|
char tsFirst[TSDB_EP_LEN] = {0};
|
||||||
|
@ -59,9 +59,6 @@ float tsNumOfThreadsPerCore = 1.0f;
|
||||||
int32_t tsNumOfCommitThreads = 4;
|
int32_t tsNumOfCommitThreads = 4;
|
||||||
float tsRatioOfQueryCores = 1.0f;
|
float tsRatioOfQueryCores = 1.0f;
|
||||||
int8_t tsDaylight = 0;
|
int8_t tsDaylight = 0;
|
||||||
char tsTimezone[TSDB_TIMEZONE_LEN] = {0};
|
|
||||||
char tsLocale[TSDB_LOCALE_LEN] = {0};
|
|
||||||
char tsCharset[TSDB_LOCALE_LEN] = {0}; // default encode string
|
|
||||||
int8_t tsEnableCoreFile = 0;
|
int8_t tsEnableCoreFile = 0;
|
||||||
int32_t tsMaxBinaryDisplayWidth = 30;
|
int32_t tsMaxBinaryDisplayWidth = 30;
|
||||||
|
|
||||||
|
@ -201,15 +198,11 @@ int8_t tsEnableStream = 1;
|
||||||
int8_t tsCompactMnodeWal = 0;
|
int8_t tsCompactMnodeWal = 0;
|
||||||
int8_t tsPrintAuth = 0;
|
int8_t tsPrintAuth = 0;
|
||||||
int8_t tscEmbedded = 0;
|
int8_t tscEmbedded = 0;
|
||||||
char configDir[PATH_MAX] = {0};
|
|
||||||
char tsVnodeDir[PATH_MAX] = {0};
|
char tsVnodeDir[PATH_MAX] = {0};
|
||||||
char tsDnodeDir[PATH_MAX] = {0};
|
char tsDnodeDir[PATH_MAX] = {0};
|
||||||
char tsMnodeDir[PATH_MAX] = {0};
|
char tsMnodeDir[PATH_MAX] = {0};
|
||||||
char tsMnodeTmpDir[PATH_MAX] = {0};
|
char tsMnodeTmpDir[PATH_MAX] = {0};
|
||||||
char tsMnodeBakDir[PATH_MAX] = {0};
|
char tsMnodeBakDir[PATH_MAX] = {0};
|
||||||
char tsDataDir[PATH_MAX] = {0};
|
|
||||||
char tsScriptDir[PATH_MAX] = {0};
|
|
||||||
char tsTempDir[PATH_MAX] = "/tmp/";
|
|
||||||
|
|
||||||
int32_t tsDiskCfgNum = 0;
|
int32_t tsDiskCfgNum = 0;
|
||||||
int32_t tsTopicBianryLen = 16000;
|
int32_t tsTopicBianryLen = 16000;
|
||||||
|
@ -229,11 +222,6 @@ SDiskCfg tsDiskCfg[TSDB_MAX_DISKS];
|
||||||
int64_t tsTickPerDay[] = {86400000L, 86400000000L, 86400000000000L};
|
int64_t tsTickPerDay[] = {86400000L, 86400000000L, 86400000000000L};
|
||||||
|
|
||||||
// system info
|
// system info
|
||||||
char tsOsName[10] = "Linux";
|
|
||||||
int64_t tsPageSize;
|
|
||||||
int64_t tsOpenMax;
|
|
||||||
int64_t tsStreamMax;
|
|
||||||
int32_t tsNumOfCores = 1;
|
|
||||||
float tsTotalTmpDirGB = 0;
|
float tsTotalTmpDirGB = 0;
|
||||||
float tsTotalDataDirGB = 0;
|
float tsTotalDataDirGB = 0;
|
||||||
float tsAvailTmpDirectorySpace = 0;
|
float tsAvailTmpDirectorySpace = 0;
|
||||||
|
@ -244,28 +232,6 @@ float tsMinimalDataDirGB = 2.0f;
|
||||||
int32_t tsTotalMemoryMB = 0;
|
int32_t tsTotalMemoryMB = 0;
|
||||||
uint32_t tsVersion = 0;
|
uint32_t tsVersion = 0;
|
||||||
|
|
||||||
// log
|
|
||||||
int32_t tsNumOfLogLines = 10000000;
|
|
||||||
int32_t mDebugFlag = 131;
|
|
||||||
int32_t sdbDebugFlag = 131;
|
|
||||||
int32_t dDebugFlag = 135;
|
|
||||||
int32_t vDebugFlag = 135;
|
|
||||||
uint32_t cDebugFlag = 131;
|
|
||||||
int32_t jniDebugFlag = 131;
|
|
||||||
int32_t odbcDebugFlag = 131;
|
|
||||||
int32_t httpDebugFlag = 131;
|
|
||||||
int32_t mqttDebugFlag = 131;
|
|
||||||
int32_t monDebugFlag = 131;
|
|
||||||
uint32_t qDebugFlag = 131;
|
|
||||||
int32_t rpcDebugFlag = 131;
|
|
||||||
int32_t uDebugFlag = 131;
|
|
||||||
int32_t debugFlag = 0;
|
|
||||||
int32_t sDebugFlag = 135;
|
|
||||||
int32_t wDebugFlag = 135;
|
|
||||||
int32_t tsdbDebugFlag = 131;
|
|
||||||
int32_t cqDebugFlag = 131;
|
|
||||||
int32_t fsDebugFlag = 135;
|
|
||||||
|
|
||||||
#ifdef TD_TSZ
|
#ifdef TD_TSZ
|
||||||
//
|
//
|
||||||
// lossy compress 6
|
// lossy compress 6
|
||||||
|
@ -420,6 +386,7 @@ static void taosCheckDataDirCfg() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t taosCheckTmpDir(void) {
|
static int32_t taosCheckTmpDir(void) {
|
||||||
|
#if 0
|
||||||
if (strlen(tsTempDir) <= 0){
|
if (strlen(tsTempDir) <= 0){
|
||||||
uError("tempDir is not set");
|
uError("tempDir is not set");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -432,10 +399,11 @@ static int32_t taosCheckTmpDir(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void doInitGlobalConfig(void) {
|
static void doInitGlobalConfig(void) {
|
||||||
osInit();
|
osInit();
|
||||||
srand(taosSafeRand());
|
srand(taosSafeRand());
|
||||||
|
@ -1096,7 +1064,7 @@ static void doInitGlobalConfig(void) {
|
||||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
|
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
|
||||||
cfg.minValue = 0;
|
cfg.minValue = 0;
|
||||||
cfg.maxValue = 0;
|
cfg.maxValue = 0;
|
||||||
cfg.ptrLength = tListLen(tsTimezone);
|
cfg.ptrLength = TSDB_TIMEZONE_LEN;
|
||||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||||
taosInitConfigOption(cfg);
|
taosInitConfigOption(cfg);
|
||||||
|
|
||||||
|
@ -1106,7 +1074,7 @@ static void doInitGlobalConfig(void) {
|
||||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
|
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
|
||||||
cfg.minValue = 0;
|
cfg.minValue = 0;
|
||||||
cfg.maxValue = 0;
|
cfg.maxValue = 0;
|
||||||
cfg.ptrLength = tListLen(tsLocale);
|
cfg.ptrLength = TSDB_LOCALE_LEN;
|
||||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||||
taosInitConfigOption(cfg);
|
taosInitConfigOption(cfg);
|
||||||
|
|
||||||
|
@ -1116,7 +1084,7 @@ static void doInitGlobalConfig(void) {
|
||||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
|
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
|
||||||
cfg.minValue = 0;
|
cfg.minValue = 0;
|
||||||
cfg.maxValue = 0;
|
cfg.maxValue = 0;
|
||||||
cfg.ptrLength = tListLen(tsCharset);
|
cfg.ptrLength = TSDB_LOCALE_LEN;
|
||||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||||
taosInitConfigOption(cfg);
|
taosInitConfigOption(cfg);
|
||||||
|
|
||||||
|
@ -1612,7 +1580,7 @@ static void doInitGlobalConfig(void) {
|
||||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT;
|
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT;
|
||||||
cfg.minValue = 0;
|
cfg.minValue = 0;
|
||||||
cfg.maxValue = 0;
|
cfg.maxValue = 0;
|
||||||
cfg.ptrLength = tListLen(tsTempDir);
|
cfg.ptrLength = PATH_MAX;
|
||||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||||
taosInitConfigOption(cfg);
|
taosInitConfigOption(cfg);
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
|
#include "ttime.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
|
|
||||||
/*
|
/*
|
|
@ -14,6 +14,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
#include "taosdef.h"
|
||||||
#include "tglobal.h"
|
#include "tglobal.h"
|
||||||
#include "tmempool.h"
|
#include "tmempool.h"
|
||||||
#include "ttimer.h"
|
#include "ttimer.h"
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/
|
|
|
@ -13,13 +13,9 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "taosdef.h"
|
|
||||||
#include "tglobal.h"
|
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||||
#include "ttimer.h"
|
|
||||||
#include "tulog.h"
|
|
||||||
#include "tutil.h"
|
|
||||||
|
|
||||||
// add
|
// add
|
||||||
char interlocked_add_fetch_8(char volatile* ptr, char val) {
|
char interlocked_add_fetch_8(char volatile* ptr, char val) {
|
||||||
|
@ -162,3 +158,42 @@ __int64 interlocked_fetch_xor_64(__int64 volatile* ptr, __int64 val) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _TD_NINGSI_60
|
||||||
|
void* atomic_exchange_ptr_impl(void** ptr, void* val ) {
|
||||||
|
void *old;
|
||||||
|
do {
|
||||||
|
old = *ptr;
|
||||||
|
} while( !__sync_bool_compare_and_swap(ptr, old, val) );
|
||||||
|
return old;
|
||||||
|
}
|
||||||
|
int8_t atomic_exchange_8_impl(int8_t* ptr, int8_t val ) {
|
||||||
|
int8_t old;
|
||||||
|
do {
|
||||||
|
old = *ptr;
|
||||||
|
} while( !__sync_bool_compare_and_swap(ptr, old, val) );
|
||||||
|
return old;
|
||||||
|
}
|
||||||
|
int16_t atomic_exchange_16_impl(int16_t* ptr, int16_t val ) {
|
||||||
|
int16_t old;
|
||||||
|
do {
|
||||||
|
old = *ptr;
|
||||||
|
} while( !__sync_bool_compare_and_swap(ptr, old, val) );
|
||||||
|
return old;
|
||||||
|
}
|
||||||
|
int32_t atomic_exchange_32_impl(int32_t* ptr, int32_t val ) {
|
||||||
|
int32_t old;
|
||||||
|
do {
|
||||||
|
old = *ptr;
|
||||||
|
} while( !__sync_bool_compare_and_swap(ptr, old, val) );
|
||||||
|
return old;
|
||||||
|
}
|
||||||
|
int64_t atomic_exchange_64_impl(int64_t* ptr, int64_t val ) {
|
||||||
|
int64_t old;
|
||||||
|
do {
|
||||||
|
old = *ptr;
|
||||||
|
} while( !__sync_bool_compare_and_swap(ptr, old, val) );
|
||||||
|
return old;
|
||||||
|
}
|
||||||
|
#endif
|
|
@ -13,16 +13,29 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "tglobal.h"
|
#include "osString.h"
|
||||||
#include "tulog.h"
|
|
||||||
#include "zlib.h"
|
|
||||||
|
|
||||||
#define COMPRESS_STEP_SIZE 163840
|
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||||
|
/*
|
||||||
|
* windows implementation
|
||||||
|
*/
|
||||||
|
|
||||||
void taosRemoveDir(char *rootDir) {
|
// todo
|
||||||
DIR *dir = opendir(rootDir);
|
|
||||||
|
#else
|
||||||
|
/*
|
||||||
|
* linux implementation
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <wordexp.h>
|
||||||
|
|
||||||
|
void taosRemoveDir(char *dirname) {
|
||||||
|
DIR *dir = opendir(dirname);
|
||||||
if (dir == NULL) return;
|
if (dir == NULL) return;
|
||||||
|
|
||||||
struct dirent *de = NULL;
|
struct dirent *de = NULL;
|
||||||
|
@ -30,33 +43,34 @@ void taosRemoveDir(char *rootDir) {
|
||||||
if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue;
|
if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue;
|
||||||
|
|
||||||
char filename[1024];
|
char filename[1024];
|
||||||
snprintf(filename, 1023, "%s/%s", rootDir, de->d_name);
|
snprintf(filename, sizeof(filename), "%s/%s", dirname, de->d_name);
|
||||||
if (de->d_type & DT_DIR) {
|
if (de->d_type & DT_DIR) {
|
||||||
taosRemoveDir(filename);
|
taosRemoveDir(filename);
|
||||||
} else {
|
} else {
|
||||||
(void)remove(filename);
|
(void)remove(filename);
|
||||||
uInfo("file:%s is removed", filename);
|
printf("file:%s is removed", filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
rmdir(rootDir);
|
rmdir(dirname);
|
||||||
|
|
||||||
uInfo("dir:%s is removed", rootDir);
|
printf("dir:%s is removed", dirname);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool taosDirExist(const char* dirname) {
|
bool taosDirExist(char *dirname) { return access(dirname, F_OK) == 0; }
|
||||||
return access(dirname, F_OK) == 0;
|
|
||||||
|
bool taosMkDir(char *dirname, mode_t mode) {
|
||||||
|
int32_t code = mkdir(dirname, 0755);
|
||||||
|
if (code < 0 && errno == EEXIST) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return code == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int taosMkDir(const char *path, mode_t mode) {
|
void taosRemoveOldFiles(char *dirname, int32_t keepDays) {
|
||||||
int code = mkdir(path, 0755);
|
DIR *dir = opendir(dirname);
|
||||||
if (code < 0 && errno == EEXIST) code = 0;
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
void taosRemoveOldLogFiles(char *rootDir, int32_t keepDays) {
|
|
||||||
DIR *dir = opendir(rootDir);
|
|
||||||
if (dir == NULL) return;
|
if (dir == NULL) return;
|
||||||
|
|
||||||
int64_t sec = taosGetTimestampSec();
|
int64_t sec = taosGetTimestampSec();
|
||||||
|
@ -66,7 +80,7 @@ void taosRemoveOldLogFiles(char *rootDir, int32_t keepDays) {
|
||||||
if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue;
|
if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue;
|
||||||
|
|
||||||
char filename[1024];
|
char filename[1024];
|
||||||
snprintf(filename, 1023, "%s/%s", rootDir, de->d_name);
|
snprintf(filename, sizeof(filename), "%s/%s", dirname, de->d_name);
|
||||||
if (de->d_type & DT_DIR) {
|
if (de->d_type & DT_DIR) {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
|
@ -76,7 +90,7 @@ void taosRemoveOldLogFiles(char *rootDir, int32_t keepDays) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t fileSec = 0;
|
int64_t fileSec = 0;
|
||||||
for (int i = len - 1; i >= 0; i--) {
|
for (int32_t i = len - 1; i >= 0; i--) {
|
||||||
if (filename[i] == '.') {
|
if (filename[i] == '.') {
|
||||||
fileSec = atoll(filename + i + 1);
|
fileSec = atoll(filename + i + 1);
|
||||||
break;
|
break;
|
||||||
|
@ -87,56 +101,41 @@ void taosRemoveOldLogFiles(char *rootDir, int32_t keepDays) {
|
||||||
int32_t days = (int32_t)(ABS(sec - fileSec) / 86400 + 1);
|
int32_t days = (int32_t)(ABS(sec - fileSec) / 86400 + 1);
|
||||||
if (days > keepDays) {
|
if (days > keepDays) {
|
||||||
(void)remove(filename);
|
(void)remove(filename);
|
||||||
uInfo("file:%s is removed, days:%d keepDays:%d", filename, days, keepDays);
|
printf("file:%s is removed, days:%d keepDays:%d", filename, days, keepDays);
|
||||||
} else {
|
} else {
|
||||||
uTrace("file:%s won't be removed, days:%d keepDays:%d", filename, days, keepDays);
|
printf("file:%s won't be removed, days:%d keepDays:%d", filename, days, keepDays);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
rmdir(rootDir);
|
rmdir(dirname);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosCompressFile(char *srcFileName, char *destFileName) {
|
bool taosExpandDir(char *dirname, char *outname, int32_t maxlen) {
|
||||||
int32_t ret = 0;
|
wordexp_t full_path;
|
||||||
int32_t len = 0;
|
if (0 != wordexp(dirname, &full_path, 0)) {
|
||||||
char * data = malloc(COMPRESS_STEP_SIZE);
|
printf("failed to expand path:%s since %s", dirname, strerror(errno));
|
||||||
FILE * srcFp = NULL;
|
wordfree(&full_path);
|
||||||
gzFile dstFp = NULL;
|
return false;
|
||||||
|
|
||||||
srcFp = fopen(srcFileName, "r");
|
|
||||||
if (srcFp == NULL) {
|
|
||||||
ret = -1;
|
|
||||||
goto cmp_end;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t fd = open(destFileName, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRWXU | S_IRWXG | S_IRWXO);
|
if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) {
|
||||||
if (fd < 0) {
|
strncpy(outname, full_path.we_wordv[0], maxlen);
|
||||||
ret = -2;
|
|
||||||
goto cmp_end;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dstFp = gzdopen(fd, "wb6f");
|
wordfree(&full_path);
|
||||||
if (dstFp == NULL) {
|
|
||||||
ret = -3;
|
|
||||||
close(fd);
|
|
||||||
goto cmp_end;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!feof(srcFp)) {
|
return true;
|
||||||
len = (int32_t)fread(data, 1, COMPRESS_STEP_SIZE, srcFp);
|
|
||||||
(void)gzwrite(dstFp, data, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
cmp_end:
|
|
||||||
if (srcFp) {
|
|
||||||
fclose(srcFp);
|
|
||||||
}
|
|
||||||
if (dstFp) {
|
|
||||||
gzclose(dstFp);
|
|
||||||
}
|
|
||||||
free(data);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool taosRealPath(char *dirname, int32_t maxlen) {
|
||||||
|
char tmp[PATH_MAX] = {0};
|
||||||
|
if (realpath(dirname, tmp) != NULL) {
|
||||||
|
strncpy(dirname, tmp, maxlen);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,66 @@
|
||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
|
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||||
|
|
||||||
|
char tsOsName[10] = "Windows";
|
||||||
|
char configDir[PATH_MAX] = "C:/TDengine/cfg";
|
||||||
|
char tsDataDir[PATH_MAX] = "C:/TDengine/data";
|
||||||
|
char tsLogDir[PATH_MAX] = "C:/TDengine/log";
|
||||||
|
char tsScriptDir[PATH_MAX] = "C:/TDengine/script";
|
||||||
|
char tsTempDir[PATH_MAX] = "C:\\Windows\\Temp";
|
||||||
|
|
||||||
|
extern taosWinSocketInit();
|
||||||
|
|
||||||
|
void osInit() {
|
||||||
|
taosWinSocketInit();
|
||||||
|
|
||||||
|
const char *tmpDir = getenv("tmp");
|
||||||
|
if (tmpDir == NULL) {
|
||||||
|
tmpDir = getenv("temp");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tmpDir != NULL) {
|
||||||
|
strcpy(tsTempDir, tmpDir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(_TD_DARWIN_64)
|
||||||
|
|
||||||
|
char tsOsName[10] = "Darwin";
|
||||||
|
char configDir[PATH_MAX] = "/usr/local/etc/taos";
|
||||||
|
char tsDataDir[PATH_MAX] = "/usr/local/var/lib/taos";
|
||||||
|
char tsLogDir[PATH_MAX] = "/usr/local/var/log/taos";
|
||||||
|
char tsScriptDir[PATH_MAX] = "/usr/local/etc/taos";
|
||||||
|
char tsTempDir[PATH_MAX] = "/tmp/taosd";
|
||||||
|
|
||||||
|
void osInit() {}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
char tsOsName[10] = "Linux";
|
||||||
|
char configDir[PATH_MAX] = "/etc/taos";
|
||||||
|
char tsDataDir[PATH_MAX] = "/var/lib/taos";
|
||||||
|
char tsLogDir[PATH_MAX] = "/var/log/taos";
|
||||||
|
char tsScriptDir[PATH_MAX] = "/etc/taos";
|
||||||
|
char tsTempDir[PATH_MAX] = "/tmp/";
|
||||||
|
|
||||||
|
void osInit() {}
|
||||||
|
|
||||||
|
#endif
|
|
@ -402,7 +402,6 @@ int32_t taosRenameFile(char *oldName, char *newName) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t taosLockFile(int32_t fd) {
|
int32_t taosLockFile(int32_t fd) {
|
||||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -15,11 +15,12 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "taosdef.h"
|
|
||||||
#include "tglobal.h"
|
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||||
#include "ttimer.h"
|
|
||||||
#include "tulog.h"
|
/*
|
||||||
#include "tutil.h"
|
* windows implementation
|
||||||
|
*/
|
||||||
|
|
||||||
unsigned char _MyBitScanForward64(unsigned long *ret, uint64_t x) {
|
unsigned char _MyBitScanForward64(unsigned long *ret, uint64_t x) {
|
||||||
unsigned long x0 = (unsigned long)x, top, bottom;
|
unsigned long x0 = (unsigned long)x, top, bottom;
|
||||||
|
@ -67,4 +68,6 @@ int32_t BUILDIN_CTZ(uint32_t val) {
|
||||||
unsigned long r = 0;
|
unsigned long r = 0;
|
||||||
_BitScanForward(&r, val);
|
_BitScanForward(&r, val);
|
||||||
return (int)(r >> 3);
|
return (int)(r >> 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -15,6 +15,10 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||||
|
#else
|
||||||
|
#include <sys/file.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
uint32_t taosRand(void) { return rand(); }
|
uint32_t taosRand(void) { return rand(); }
|
||||||
|
|
|
@ -13,13 +13,66 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// fail-fast or let-it-crash philosophy
|
|
||||||
// https://en.wikipedia.org/wiki/Fail-fast
|
|
||||||
// https://stackoverflow.com/questions/4393197/erlangs-let-it-crash-philosophy-applicable-elsewhere
|
|
||||||
// experimentally, we follow log-and-crash here
|
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
|
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* windows implementation
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
bool taosCheckPthreadValid(pthread_t thread) { return thread.p != NULL; }
|
||||||
|
|
||||||
|
void taosResetPthread(pthread_t* thread) { thread->p = 0; }
|
||||||
|
|
||||||
|
int64_t taosGetPthreadId(pthread_t thread) {
|
||||||
|
#ifdef PTW32_VERSION
|
||||||
|
return pthread_getw32threadid_np(thread);
|
||||||
|
#else
|
||||||
|
return (int64_t)thread;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t taosGetSelfPthreadId() { return GetCurrentThreadId(); }
|
||||||
|
|
||||||
|
bool taosComparePthread(pthread_t first, pthread_t second) { return first.p == second.p; }
|
||||||
|
|
||||||
|
int32_t taosGetPId() { return GetCurrentProcessId(); }
|
||||||
|
|
||||||
|
int32_t taosGetCurrentAPPName(char* name, int32_t* len) {
|
||||||
|
char filepath[1024] = {0};
|
||||||
|
|
||||||
|
GetModuleFileName(NULL, filepath, MAX_PATH);
|
||||||
|
char* sub = strrchr(filepath, '.');
|
||||||
|
if (sub != NULL) {
|
||||||
|
*sub = '\0';
|
||||||
|
}
|
||||||
|
strcpy(name, filepath);
|
||||||
|
|
||||||
|
if (len != NULL) {
|
||||||
|
*len = (int32_t)strlen(filepath);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tsem_wait(tsem_t* sem) {
|
||||||
|
int ret = 0;
|
||||||
|
do {
|
||||||
|
ret = sem_wait(sem);
|
||||||
|
} while (ret != 0 && errno == EINTR);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(_TD_DARWIN_64)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* darwin implementation
|
||||||
|
*/
|
||||||
|
|
||||||
#include <libproc.h>
|
#include <libproc.h>
|
||||||
|
|
||||||
// #define SEM_USE_PTHREAD
|
// #define SEM_USE_PTHREAD
|
||||||
|
@ -27,19 +80,19 @@
|
||||||
#define SEM_USE_SEM
|
#define SEM_USE_SEM
|
||||||
|
|
||||||
#ifdef SEM_USE_SEM
|
#ifdef SEM_USE_SEM
|
||||||
#include <mach/mach_init.h>
|
|
||||||
#include <mach/mach_error.h>
|
#include <mach/mach_error.h>
|
||||||
|
#include <mach/mach_init.h>
|
||||||
#include <mach/semaphore.h>
|
#include <mach/semaphore.h>
|
||||||
#include <mach/task.h>
|
#include <mach/task.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
static pthread_t sem_thread;
|
static pthread_t sem_thread;
|
||||||
static pthread_once_t sem_once;
|
static pthread_once_t sem_once;
|
||||||
static task_t sem_port;
|
static task_t sem_port;
|
||||||
static volatile int sem_inited = 0;
|
static volatile int sem_inited = 0;
|
||||||
static semaphore_t sem_exit;
|
static semaphore_t sem_exit;
|
||||||
|
|
||||||
static void* sem_thread_routine(void *arg) {
|
static void *sem_thread_routine(void *arg) {
|
||||||
(void)arg;
|
(void)arg;
|
||||||
setThreadName("sem_thrd");
|
setThreadName("sem_thrd");
|
||||||
|
|
||||||
|
@ -62,7 +115,7 @@ static void once_init(void) {
|
||||||
fprintf(stderr, "==%s[%d]%s()==failed to create thread\n", basename(__FILE__), __LINE__, __func__);
|
fprintf(stderr, "==%s[%d]%s()==failed to create thread\n", basename(__FILE__), __LINE__, __func__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (sem_inited==0) {
|
while (sem_inited == 0) {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,19 +123,19 @@ static void once_init(void) {
|
||||||
|
|
||||||
struct tsem_s {
|
struct tsem_s {
|
||||||
#ifdef SEM_USE_PTHREAD
|
#ifdef SEM_USE_PTHREAD
|
||||||
pthread_mutex_t lock;
|
pthread_mutex_t lock;
|
||||||
pthread_cond_t cond;
|
pthread_cond_t cond;
|
||||||
volatile int64_t val;
|
volatile int64_t val;
|
||||||
#elif defined(SEM_USE_POSIX)
|
#elif defined(SEM_USE_POSIX)
|
||||||
size_t id;
|
size_t id;
|
||||||
sem_t *sem;
|
sem_t * sem;
|
||||||
#elif defined(SEM_USE_SEM)
|
#elif defined(SEM_USE_SEM)
|
||||||
semaphore_t sem;
|
semaphore_t sem;
|
||||||
#else // SEM_USE_PTHREAD
|
#else // SEM_USE_PTHREAD
|
||||||
dispatch_semaphore_t sem;
|
dispatch_semaphore_t sem;
|
||||||
#endif // SEM_USE_PTHREAD
|
#endif // SEM_USE_PTHREAD
|
||||||
|
|
||||||
volatile unsigned int valid:1;
|
volatile unsigned int valid : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
int tsem_init(tsem_t *sem, int pshared, unsigned int value) {
|
int tsem_init(tsem_t *sem, int pshared, unsigned int value) {
|
||||||
|
@ -91,7 +144,7 @@ int tsem_init(tsem_t *sem, int pshared, unsigned int value) {
|
||||||
fprintf(stderr, "==%s[%d]%s():[%p]==already initialized\n", basename(__FILE__), __LINE__, __func__, sem);
|
fprintf(stderr, "==%s[%d]%s():[%p]==already initialized\n", basename(__FILE__), __LINE__, __func__, sem);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
struct tsem_s *p = (struct tsem_s*)calloc(1, sizeof(*p));
|
struct tsem_s *p = (struct tsem_s *)calloc(1, sizeof(*p));
|
||||||
if (!p) {
|
if (!p) {
|
||||||
fprintf(stderr, "==%s[%d]%s():[%p]==out of memory\n", basename(__FILE__), __LINE__, __func__, sem);
|
fprintf(stderr, "==%s[%d]%s():[%p]==out of memory\n", basename(__FILE__), __LINE__, __func__, sem);
|
||||||
abort();
|
abort();
|
||||||
|
@ -116,24 +169,25 @@ int tsem_init(tsem_t *sem, int pshared, unsigned int value) {
|
||||||
static size_t tick = 0;
|
static size_t tick = 0;
|
||||||
do {
|
do {
|
||||||
size_t id = atomic_add_fetch_64(&tick, 1);
|
size_t id = atomic_add_fetch_64(&tick, 1);
|
||||||
if (id==SEM_VALUE_MAX) {
|
if (id == SEM_VALUE_MAX) {
|
||||||
atomic_store_64(&tick, 0);
|
atomic_store_64(&tick, 0);
|
||||||
id = 0;
|
id = 0;
|
||||||
}
|
}
|
||||||
char name[NAME_MAX-4];
|
char name[NAME_MAX - 4];
|
||||||
snprintf(name, sizeof(name), "/t%ld", id);
|
snprintf(name, sizeof(name), "/t%ld", id);
|
||||||
p->sem = sem_open(name, O_CREAT|O_EXCL, pshared, value);
|
p->sem = sem_open(name, O_CREAT | O_EXCL, pshared, value);
|
||||||
p->id = id;
|
p->id = id;
|
||||||
if (p->sem!=SEM_FAILED) break;
|
if (p->sem != SEM_FAILED) break;
|
||||||
int e = errno;
|
int e = errno;
|
||||||
if (e==EEXIST) continue;
|
if (e == EEXIST) continue;
|
||||||
if (e==EINTR) continue;
|
if (e == EINTR) continue;
|
||||||
fprintf(stderr, "==%s[%d]%s():[%p]==not created[%d]%s\n", basename(__FILE__), __LINE__, __func__, sem, e, strerror(e));
|
fprintf(stderr, "==%s[%d]%s():[%p]==not created[%d]%s\n", basename(__FILE__), __LINE__, __func__, sem, e,
|
||||||
|
strerror(e));
|
||||||
abort();
|
abort();
|
||||||
} while (p->sem==SEM_FAILED);
|
} while (p->sem == SEM_FAILED);
|
||||||
#elif defined(SEM_USE_SEM)
|
#elif defined(SEM_USE_SEM)
|
||||||
pthread_once(&sem_once, once_init);
|
pthread_once(&sem_once, once_init);
|
||||||
if (sem_inited!=1) {
|
if (sem_inited != 1) {
|
||||||
fprintf(stderr, "==%s[%d]%s():[%p]==internal resource init failed\n", basename(__FILE__), __LINE__, __func__, sem);
|
fprintf(stderr, "==%s[%d]%s():[%p]==internal resource init failed\n", basename(__FILE__), __LINE__, __func__, sem);
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -144,13 +198,13 @@ int tsem_init(tsem_t *sem, int pshared, unsigned int value) {
|
||||||
// we fail-fast here, because we have less-doc about semaphore_create for the moment
|
// we fail-fast here, because we have less-doc about semaphore_create for the moment
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
#else // SEM_USE_PTHREAD
|
#else // SEM_USE_PTHREAD
|
||||||
p->sem = dispatch_semaphore_create(value);
|
p->sem = dispatch_semaphore_create(value);
|
||||||
if (p->sem == NULL) {
|
if (p->sem == NULL) {
|
||||||
fprintf(stderr, "==%s[%d]%s():[%p]==not created\n", basename(__FILE__), __LINE__, __func__, sem);
|
fprintf(stderr, "==%s[%d]%s():[%p]==not created\n", basename(__FILE__), __LINE__, __func__, sem);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
#endif // SEM_USE_PTHREAD
|
#endif // SEM_USE_PTHREAD
|
||||||
|
|
||||||
p->valid = 1;
|
p->valid = 1;
|
||||||
|
|
||||||
|
@ -190,9 +244,9 @@ int tsem_wait(tsem_t *sem) {
|
||||||
return sem_wait(p->sem);
|
return sem_wait(p->sem);
|
||||||
#elif defined(SEM_USE_SEM)
|
#elif defined(SEM_USE_SEM)
|
||||||
return semaphore_wait(p->sem);
|
return semaphore_wait(p->sem);
|
||||||
#else // SEM_USE_PTHREAD
|
#else // SEM_USE_PTHREAD
|
||||||
return dispatch_semaphore_wait(p->sem, DISPATCH_TIME_FOREVER);
|
return dispatch_semaphore_wait(p->sem, DISPATCH_TIME_FOREVER);
|
||||||
#endif // SEM_USE_PTHREAD
|
#endif // SEM_USE_PTHREAD
|
||||||
}
|
}
|
||||||
|
|
||||||
int tsem_post(tsem_t *sem) {
|
int tsem_post(tsem_t *sem) {
|
||||||
|
@ -226,9 +280,9 @@ int tsem_post(tsem_t *sem) {
|
||||||
return sem_post(p->sem);
|
return sem_post(p->sem);
|
||||||
#elif defined(SEM_USE_SEM)
|
#elif defined(SEM_USE_SEM)
|
||||||
return semaphore_signal(p->sem);
|
return semaphore_signal(p->sem);
|
||||||
#else // SEM_USE_PTHREAD
|
#else // SEM_USE_PTHREAD
|
||||||
return dispatch_semaphore_signal(p->sem);
|
return dispatch_semaphore_signal(p->sem);
|
||||||
#endif // SEM_USE_PTHREAD
|
#endif // SEM_USE_PTHREAD
|
||||||
}
|
}
|
||||||
|
|
||||||
int tsem_destroy(tsem_t *sem) {
|
int tsem_destroy(tsem_t *sem) {
|
||||||
|
@ -263,18 +317,19 @@ int tsem_destroy(tsem_t *sem) {
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
#elif defined(SEM_USE_POSIX)
|
#elif defined(SEM_USE_POSIX)
|
||||||
char name[NAME_MAX-4];
|
char name[NAME_MAX - 4];
|
||||||
snprintf(name, sizeof(name), "/t%ld", p->id);
|
snprintf(name, sizeof(name), "/t%ld", p->id);
|
||||||
int r = sem_unlink(name);
|
int r = sem_unlink(name);
|
||||||
if (r) {
|
if (r) {
|
||||||
int e = errno;
|
int e = errno;
|
||||||
fprintf(stderr, "==%s[%d]%s():[%p]==unlink failed[%d]%s\n", basename(__FILE__), __LINE__, __func__, sem, e, strerror(e));
|
fprintf(stderr, "==%s[%d]%s():[%p]==unlink failed[%d]%s\n", basename(__FILE__), __LINE__, __func__, sem, e,
|
||||||
|
strerror(e));
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
#elif defined(SEM_USE_SEM)
|
#elif defined(SEM_USE_SEM)
|
||||||
semaphore_destroy(sem_port, p->sem);
|
semaphore_destroy(sem_port, p->sem);
|
||||||
#else // SEM_USE_PTHREAD
|
#else // SEM_USE_PTHREAD
|
||||||
#endif // SEM_USE_PTHREAD
|
#endif // SEM_USE_PTHREAD
|
||||||
|
|
||||||
p->valid = 0;
|
p->valid = 0;
|
||||||
free(p);
|
free(p);
|
||||||
|
@ -285,36 +340,28 @@ int tsem_destroy(tsem_t *sem) {
|
||||||
|
|
||||||
bool taosCheckPthreadValid(pthread_t thread) {
|
bool taosCheckPthreadValid(pthread_t thread) {
|
||||||
uint64_t id = 0;
|
uint64_t id = 0;
|
||||||
int r = pthread_threadid_np(thread, &id);
|
int r = pthread_threadid_np(thread, &id);
|
||||||
return r ? false : true;
|
return r ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t taosGetSelfPthreadId() {
|
int64_t taosGetSelfPthreadId() {
|
||||||
uint64_t id;
|
uint64_t id;
|
||||||
pthread_threadid_np(0, &id);
|
pthread_threadid_np(0, &id);
|
||||||
return (int64_t) id;
|
return (int64_t)id;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t taosGetPthreadId(pthread_t thread) {
|
int64_t taosGetPthreadId(pthread_t thread) { return (int64_t)thread; }
|
||||||
return (int64_t)thread;
|
|
||||||
}
|
|
||||||
|
|
||||||
void taosResetPthread(pthread_t* thread) {
|
void taosResetPthread(pthread_t *thread) { *thread = NULL; }
|
||||||
*thread = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool taosComparePthread(pthread_t first, pthread_t second) {
|
bool taosComparePthread(pthread_t first, pthread_t second) { return pthread_equal(first, second) ? true : false; }
|
||||||
return pthread_equal(first, second) ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t taosGetPId() {
|
int32_t taosGetPId() { return (int32_t)getpid(); }
|
||||||
return (int32_t)getpid();
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t taosGetCurrentAPPName(char* name, int32_t* len) {
|
int32_t taosGetCurrentAPPName(char *name, int32_t *len) {
|
||||||
char buf[PATH_MAX+1];
|
char buf[PATH_MAX + 1];
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
proc_name(getpid(), buf, sizeof(buf)-1);
|
proc_name(getpid(), buf, sizeof(buf) - 1);
|
||||||
buf[PATH_MAX] = '\0';
|
buf[PATH_MAX] = '\0';
|
||||||
size_t n = strlen(buf);
|
size_t n = strlen(buf);
|
||||||
if (len) *len = n;
|
if (len) *len = n;
|
||||||
|
@ -322,4 +369,59 @@ int32_t taosGetCurrentAPPName(char* name, int32_t* len) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
/*
|
||||||
|
* linux implementation
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/syscall.h>
|
||||||
|
|
||||||
|
bool taosCheckPthreadValid(pthread_t thread) { return thread != 0; }
|
||||||
|
|
||||||
|
int64_t taosGetSelfPthreadId() {
|
||||||
|
static __thread int id = 0;
|
||||||
|
if (id != 0) return id;
|
||||||
|
id = syscall(SYS_gettid);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t taosGetPthreadId(pthread_t thread) { return (int64_t)thread; }
|
||||||
|
void taosResetPthread(pthread_t* thread) { *thread = 0; }
|
||||||
|
bool taosComparePthread(pthread_t first, pthread_t second) { return first == second; }
|
||||||
|
int32_t taosGetPId() { return getpid(); }
|
||||||
|
|
||||||
|
int32_t taosGetCurrentAPPName(char* name, int32_t* len) {
|
||||||
|
const char* self = "/proc/self/exe";
|
||||||
|
char path[PATH_MAX] = {0};
|
||||||
|
|
||||||
|
if (readlink(self, path, PATH_MAX) <= 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
path[PATH_MAX - 1] = 0;
|
||||||
|
char* end = strrchr(path, '/');
|
||||||
|
if (end == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
++end;
|
||||||
|
|
||||||
|
strcpy(name, end);
|
||||||
|
|
||||||
|
if (len != NULL) {
|
||||||
|
*len = strlen(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tsem_wait(tsem_t* sem) {
|
||||||
|
int ret = 0;
|
||||||
|
do {
|
||||||
|
ret = sem_wait(sem);
|
||||||
|
} while (ret != 0 && errno == EINTR);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -15,7 +15,13 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include <signal.h>
|
|
||||||
|
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* windows implementation
|
||||||
|
*/
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
typedef void (*FWinSignalHandler)(int32_t signum);
|
typedef void (*FWinSignalHandler)(int32_t signum);
|
||||||
|
@ -27,7 +33,7 @@ void taosSetSignal(int32_t signum, FSignalHandler sigfp) {
|
||||||
if (signum == SIGHUP) {
|
if (signum == SIGHUP) {
|
||||||
SetConsoleCtrlHandler((PHANDLER_ROUTINE)sigfp, TRUE);
|
SetConsoleCtrlHandler((PHANDLER_ROUTINE)sigfp, TRUE);
|
||||||
} else {
|
} else {
|
||||||
signal(signum, (FWinSignalHandler)sigfp);
|
signal(signum, (FWinSignalHandler)sigfp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,3 +46,29 @@ void taosDflSignal(int32_t signum) {
|
||||||
if (signum == SIGUSR1 || signum == SIGHUP) return;
|
if (signum == SIGUSR1 || signum == SIGHUP) return;
|
||||||
signal(signum, SIG_DFL);
|
signal(signum, SIG_DFL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
/*
|
||||||
|
* linux and darwin implementation
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef void (*FLinuxSignalHandler)(int32_t signum, siginfo_t *sigInfo, void *context);
|
||||||
|
|
||||||
|
void taosSetSignal(int32_t signum, FSignalHandler sigfp) {
|
||||||
|
struct sigaction act;
|
||||||
|
memset(&act, 0, sizeof(act));
|
||||||
|
#if 1
|
||||||
|
act.sa_flags = SA_SIGINFO;
|
||||||
|
act.sa_sigaction = (FLinuxSignalHandler)sigfp;
|
||||||
|
#else
|
||||||
|
act.sa_handler = sigfp;
|
||||||
|
#endif
|
||||||
|
sigaction(signum, &act, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void taosIgnSignal(int32_t signum) { signal(signum, SIG_IGN); }
|
||||||
|
|
||||||
|
void taosDflSignal(int32_t signum) { signal(signum, SIG_DFL); }
|
||||||
|
|
||||||
|
#endif
|
|
@ -16,6 +16,19 @@
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
|
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||||
|
#else
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <netinet/ip.h>
|
||||||
|
#include <netinet/tcp.h>
|
||||||
|
#include <netinet/udp.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
void taosShutDownSocketRD(SOCKET fd) {
|
void taosShutDownSocketRD(SOCKET fd) {
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
closesocket(fd);
|
closesocket(fd);
|
||||||
|
@ -41,7 +54,7 @@ void taosShutDownSocketWR(SOCKET fd) {
|
||||||
int32_t taosSetNonblocking(SOCKET sock, int32_t on) {
|
int32_t taosSetNonblocking(SOCKET sock, int32_t on) {
|
||||||
int32_t flags = 0;
|
int32_t flags = 0;
|
||||||
if ((flags = fcntl(sock, F_GETFL, 0)) < 0) {
|
if ((flags = fcntl(sock, F_GETFL, 0)) < 0) {
|
||||||
uError("fcntl(F_GETFL) error: %d (%s)\n", errno, strerror(errno));
|
printf("fcntl(F_GETFL) error: %d (%s)\n", errno, strerror(errno));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,16 +64,14 @@ int32_t taosSetNonblocking(SOCKET sock, int32_t on) {
|
||||||
flags &= ~O_NONBLOCK;
|
flags &= ~O_NONBLOCK;
|
||||||
|
|
||||||
if ((flags = fcntl(sock, F_SETFL, flags)) < 0) {
|
if ((flags = fcntl(sock, F_SETFL, flags)) < 0) {
|
||||||
uError("fcntl(F_SETFL) error: %d (%s)\n", errno, strerror(errno));
|
printf("fcntl(F_SETFL) error: %d (%s)\n", errno, strerror(errno));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosIgnSIGPIPE() {
|
void taosIgnSIGPIPE() { signal(SIGPIPE, SIG_IGN); }
|
||||||
signal(SIGPIPE, SIG_IGN);
|
|
||||||
}
|
|
||||||
|
|
||||||
void taosBlockSIGPIPE() {
|
void taosBlockSIGPIPE() {
|
||||||
sigset_t signal_mask;
|
sigset_t signal_mask;
|
||||||
|
@ -68,7 +79,7 @@ void taosBlockSIGPIPE() {
|
||||||
sigaddset(&signal_mask, SIGPIPE);
|
sigaddset(&signal_mask, SIGPIPE);
|
||||||
int32_t rc = pthread_sigmask(SIG_BLOCK, &signal_mask, NULL);
|
int32_t rc = pthread_sigmask(SIG_BLOCK, &signal_mask, NULL);
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
uError("failed to block SIGPIPE");
|
printf("failed to block SIGPIPE");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +89,7 @@ void taosSetMaskSIGPIPE() {
|
||||||
sigaddset(&signal_mask, SIGPIPE);
|
sigaddset(&signal_mask, SIGPIPE);
|
||||||
int32_t rc = pthread_sigmask(SIG_SETMASK, &signal_mask, NULL);
|
int32_t rc = pthread_sigmask(SIG_SETMASK, &signal_mask, NULL);
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
uError("failed to setmask SIGPIPE");
|
printf("failed to setmask SIGPIPE");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,35 +101,127 @@ int32_t taosSetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *op
|
||||||
return setsockopt(socketfd, level, optname, optval, (socklen_t)optlen);
|
return setsockopt(socketfd, level, optname, optval, (socklen_t)optlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosGetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *optval, int32_t* optlen) {
|
int32_t taosGetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *optval, int32_t *optlen) {
|
||||||
return getsockopt(socketfd, level, optname, optval, (socklen_t *)optlen);
|
return getsockopt(socketfd, level, optname, optval, (socklen_t *)optlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !( (defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)) && defined(_MSC_VER) )
|
#if !((defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)) && defined(_MSC_VER))
|
||||||
|
|
||||||
|
uint32_t taosInetAddr(char *ipAddr) { return inet_addr(ipAddr); }
|
||||||
|
|
||||||
|
const char *taosInetNtoa(struct in_addr ipInt) { return inet_ntoa(ipInt); }
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_TD_DARWIN_64)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* darwin implementation
|
||||||
|
*/
|
||||||
|
|
||||||
|
int taosSetSockOpt(SOCKET socketfd, int level, int optname, void *optval, int optlen) {
|
||||||
|
if (level == SOL_SOCKET && optname == SO_SNDBUF) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (level == SOL_SOCKET && optname == SO_RCVBUF) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return setsockopt(socketfd, level, optname, optval, (socklen_t)optlen);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* windows implementation
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <IPHlpApi.h>
|
||||||
|
#include <WS2tcpip.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <tchar.h>
|
||||||
|
#include <winsock2.h>
|
||||||
|
#include <ws2def.h>
|
||||||
|
|
||||||
|
void taosWinSocketInit() {
|
||||||
|
static char flag = 0;
|
||||||
|
if (flag == 0) {
|
||||||
|
WORD wVersionRequested;
|
||||||
|
WSADATA wsaData;
|
||||||
|
wVersionRequested = MAKEWORD(1, 1);
|
||||||
|
if (WSAStartup(wVersionRequested, &wsaData) == 0) {
|
||||||
|
flag = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t taosSetNonblocking(SOCKET sock, int32_t on) {
|
||||||
|
u_long mode;
|
||||||
|
if (on) {
|
||||||
|
mode = 1;
|
||||||
|
ioctlsocket(sock, FIONBIO, &mode);
|
||||||
|
} else {
|
||||||
|
mode = 0;
|
||||||
|
ioctlsocket(sock, FIONBIO, &mode);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void taosIgnSIGPIPE() {}
|
||||||
|
void taosBlockSIGPIPE() {}
|
||||||
|
void taosSetMaskSIGPIPE() {}
|
||||||
|
|
||||||
|
int32_t taosSetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *optval, int32_t optlen) {
|
||||||
|
if (level == SOL_SOCKET && optname == TCP_KEEPCNT) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (level == SOL_TCP && optname == TCP_KEEPIDLE) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (level == SOL_TCP && optname == TCP_KEEPINTVL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (level == SOL_TCP && optname == TCP_KEEPCNT) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return setsockopt(socketfd, level, optname, optval, optlen);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
//#if _MSC_VER >= 1900
|
||||||
|
|
||||||
uint32_t taosInetAddr(char *ipAddr) {
|
uint32_t taosInetAddr(char *ipAddr) {
|
||||||
return inet_addr(ipAddr);
|
uint32_t value;
|
||||||
|
int32_t ret = inet_pton(AF_INET, ipAddr, &value);
|
||||||
|
if (ret <= 0) {
|
||||||
|
return INADDR_NONE;
|
||||||
|
} else {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *taosInetNtoa(struct in_addr ipInt) {
|
|
||||||
return inet_ntoa(ipInt);
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
const char *taosInetNtoa(struct in_addr ipInt) {
|
const char *taosInetNtoa(struct in_addr ipInt) {
|
||||||
// not thread safe, only for debug usage while print log
|
// not thread safe, only for debug usage while print log
|
||||||
static char tmpDstStr[16];
|
static char tmpDstStr[16];
|
||||||
return inet_ntop(AF_INET, &ipInt, tmpDstStr, INET6_ADDRSTRLEN);
|
return inet_ntop(AF_INET, &ipInt, tmpDstStr, INET6_ADDRSTRLEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if defined(_TD_GO_DLL_)
|
#if defined(_TD_GO_DLL_)
|
||||||
|
|
||||||
uint64_t htonll(uint64_t val) { return (((uint64_t)htonl(val)) << 32) + htonl(val >> 32); }
|
uint64_t htonll(uint64_t val) { return (((uint64_t)htonl(val)) << 32) + htonl(val >> 32); }
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -0,0 +1,382 @@
|
||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "os.h"
|
||||||
|
#include <wchar.h>
|
||||||
|
#include <wctype.h>
|
||||||
|
|
||||||
|
typedef struct CharsetPair {
|
||||||
|
char *oldCharset;
|
||||||
|
char *newCharset;
|
||||||
|
} CharsetPair;
|
||||||
|
|
||||||
|
char *taosCharsetReplace(char *charsetstr) {
|
||||||
|
CharsetPair charsetRep[] = {
|
||||||
|
{ "utf8", "UTF-8" }, { "936", "CP936" },
|
||||||
|
};
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < tListLen(charsetRep); ++i) {
|
||||||
|
if (strcasecmp(charsetRep[i].oldCharset, charsetstr) == 0) {
|
||||||
|
return strdup(charsetRep[i].newCharset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return strdup(charsetstr);
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t taosStr2int64(char *str) {
|
||||||
|
char *endptr = NULL;
|
||||||
|
return strtoll(str, &endptr, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef USE_LIBICONV
|
||||||
|
#include "iconv.h"
|
||||||
|
|
||||||
|
int32_t taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs) {
|
||||||
|
iconv_t cd = iconv_open(tsCharset, DEFAULT_UNICODE_ENCODEC);
|
||||||
|
size_t ucs4_input_len = ucs4_max_len;
|
||||||
|
size_t outLen = ucs4_max_len;
|
||||||
|
if (iconv(cd, (char **)&ucs4, &ucs4_input_len, &mbs, &outLen) == -1) {
|
||||||
|
iconv_close(cd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
iconv_close(cd);
|
||||||
|
return (int32_t)(ucs4_max_len - outLen);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool taosMbsToUcs4(char *mbs, size_t mbsLength, char *ucs4, int32_t ucs4_max_len, int32_t *len) {
|
||||||
|
memset(ucs4, 0, ucs4_max_len);
|
||||||
|
iconv_t cd = iconv_open(DEFAULT_UNICODE_ENCODEC, tsCharset);
|
||||||
|
size_t ucs4_input_len = mbsLength;
|
||||||
|
size_t outLeft = ucs4_max_len;
|
||||||
|
if (iconv(cd, &mbs, &ucs4_input_len, &ucs4, &outLeft) == -1) {
|
||||||
|
iconv_close(cd);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
iconv_close(cd);
|
||||||
|
if (len != NULL) {
|
||||||
|
*len = (int32_t)(ucs4_max_len - outLeft);
|
||||||
|
if (*len < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool taosValidateEncodec(const char *encodec) {
|
||||||
|
iconv_t cd = iconv_open(encodec, DEFAULT_UNICODE_ENCODEC);
|
||||||
|
if (cd == (iconv_t)(-1)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
iconv_close(cd);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
int32_t taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs) {
|
||||||
|
mbstate_t state = {0};
|
||||||
|
int32_t len = (int32_t)wcsnrtombs(NULL, (const wchar_t **)&ucs4, ucs4_max_len / 4, 0, &state);
|
||||||
|
if (len < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(&state, 0, sizeof(state));
|
||||||
|
len = wcsnrtombs(mbs, (const wchar_t **)&ucs4, ucs4_max_len / 4, (size_t)len, &state);
|
||||||
|
if (len < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool taosMbsToUcs4(char *mbs, size_t mbsLength, char *ucs4, int32_t ucs4_max_len, int32_t *len) {
|
||||||
|
memset(ucs4, 0, ucs4_max_len);
|
||||||
|
mbstate_t state = {0};
|
||||||
|
int32_t retlen = mbsnrtowcs((wchar_t *)ucs4, (const char **)&mbs, mbsLength, ucs4_max_len / 4, &state);
|
||||||
|
*len = retlen;
|
||||||
|
|
||||||
|
return retlen >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool taosValidateEncodec(const char *encodec) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* windows implementation
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#if STDC_HEADERS
|
||||||
|
#include <stdlib.h>
|
||||||
|
#else
|
||||||
|
char *malloc(), *realloc();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Always add at least this many bytes when extending the buffer. */
|
||||||
|
#define MIN_CHUNK 64
|
||||||
|
|
||||||
|
/* Read up to (and including) a TERMINATOR from STREAM into *LINEPTR
|
||||||
|
+ OFFSET (and null-terminate it). *LINEPTR is a pointer returned from
|
||||||
|
malloc (or NULL), pointing to *N characters of space. It is realloc'd
|
||||||
|
as necessary. Return the number of characters read (not including the
|
||||||
|
null terminator), or -1 on error or EOF. On a -1 return, the caller
|
||||||
|
should check feof(), if not then errno has been set to indicate
|
||||||
|
the error. */
|
||||||
|
|
||||||
|
int32_t getstr(char **lineptr, size_t *n, FILE *stream, char terminator, int32_t offset) {
|
||||||
|
int32_t nchars_avail; /* Allocated but unused chars in *LINEPTR. */
|
||||||
|
char * read_pos; /* Where we're reading into *LINEPTR. */
|
||||||
|
int32_t ret;
|
||||||
|
|
||||||
|
if (!lineptr || !n || !stream) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!*lineptr) {
|
||||||
|
*n = MIN_CHUNK;
|
||||||
|
*lineptr = malloc(*n);
|
||||||
|
if (!*lineptr) {
|
||||||
|
errno = ENOMEM;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nchars_avail = (int32_t)(*n - offset);
|
||||||
|
read_pos = *lineptr + offset;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
int32_t save_errno;
|
||||||
|
register int32_t c = getc(stream);
|
||||||
|
|
||||||
|
save_errno = errno;
|
||||||
|
|
||||||
|
/* We always want at least one char left in the buffer, since we
|
||||||
|
always (unless we get an error while reading the first char)
|
||||||
|
NUL-terminate the line buffer. */
|
||||||
|
|
||||||
|
assert((*lineptr + *n) == (read_pos + nchars_avail));
|
||||||
|
if (nchars_avail < 2) {
|
||||||
|
if (*n > MIN_CHUNK)
|
||||||
|
*n *= 2;
|
||||||
|
else
|
||||||
|
*n += MIN_CHUNK;
|
||||||
|
|
||||||
|
nchars_avail = (int32_t)(*n + *lineptr - read_pos);
|
||||||
|
char* lineptr1 = realloc(*lineptr, *n);
|
||||||
|
if (!lineptr1) {
|
||||||
|
errno = ENOMEM;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*lineptr = lineptr1;
|
||||||
|
|
||||||
|
read_pos = *n - nchars_avail + *lineptr;
|
||||||
|
assert((*lineptr + *n) == (read_pos + nchars_avail));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ferror(stream)) {
|
||||||
|
/* Might like to return partial line, but there is no
|
||||||
|
place for us to store errno. And we don't want to just
|
||||||
|
lose errno. */
|
||||||
|
errno = save_errno;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c == EOF) {
|
||||||
|
/* Return partial line, if any. */
|
||||||
|
if (read_pos == *lineptr)
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
*read_pos++ = c;
|
||||||
|
nchars_avail--;
|
||||||
|
|
||||||
|
if (c == terminator) /* Return the line. */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Done - NUL terminate and return the number of chars read. */
|
||||||
|
*read_pos = '\0';
|
||||||
|
|
||||||
|
ret = (int32_t)(read_pos - (*lineptr + offset));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tgetline(char **lineptr, size_t *n, FILE *stream) { return getstr(lineptr, n, stream, '\n', 0); }
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get next token from string *stringp, where tokens are possibly-empty
|
||||||
|
* strings separated by characters from delim.
|
||||||
|
*
|
||||||
|
* Writes NULs into the string at *stringp to end tokens.
|
||||||
|
* delim need not remain constant from call to call.
|
||||||
|
* On return, *stringp points past the last NUL written (if there might
|
||||||
|
* be further tokens), or is NULL (if there are definitely no moretokens).
|
||||||
|
*
|
||||||
|
* If *stringp is NULL, strsep returns NULL.
|
||||||
|
*/
|
||||||
|
char *strsep(char **stringp, const char *delim) {
|
||||||
|
char * s;
|
||||||
|
const char *spanp;
|
||||||
|
int32_t c, sc;
|
||||||
|
char *tok;
|
||||||
|
if ((s = *stringp) == NULL)
|
||||||
|
return (NULL);
|
||||||
|
for (tok = s;;) {
|
||||||
|
c = *s++;
|
||||||
|
spanp = delim;
|
||||||
|
do {
|
||||||
|
if ((sc = *spanp++) == c) {
|
||||||
|
if (c == 0)
|
||||||
|
s = NULL;
|
||||||
|
else
|
||||||
|
s[-1] = 0;
|
||||||
|
*stringp = s;
|
||||||
|
return (tok);
|
||||||
|
}
|
||||||
|
} while (sc != 0);
|
||||||
|
}
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
|
||||||
|
char *getpass(const char *prefix) {
|
||||||
|
static char passwd[TSDB_KEY_LEN] = {0};
|
||||||
|
memset(passwd, 0, TSDB_KEY_LEN);
|
||||||
|
printf("%s", prefix);
|
||||||
|
|
||||||
|
int32_t index = 0;
|
||||||
|
char ch;
|
||||||
|
while (index < TSDB_KEY_LEN) {
|
||||||
|
ch = getch();
|
||||||
|
if (ch == '\n' || ch == '\r') {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
passwd[index++] = ch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return passwd;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t twcslen(const wchar_t *wcs) {
|
||||||
|
int32_t *wstr = (int32_t *)wcs;
|
||||||
|
if (NULL == wstr) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t n = 0;
|
||||||
|
while (1) {
|
||||||
|
if (0 == *wstr++) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes) {
|
||||||
|
for (int32_t i = 0; i < bytes; ++i) {
|
||||||
|
int32_t f1 = *(int32_t *)((char *)f1_ucs4 + i * 4);
|
||||||
|
int32_t f2 = *(int32_t *)((char *)f2_ucs4 + i * 4);
|
||||||
|
|
||||||
|
if ((f1 == 0 && f2 != 0) || (f1 != 0 && f2 == 0)) {
|
||||||
|
return f1 - f2;
|
||||||
|
} else if (f1 == 0 && f2 == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (f1 != f2) {
|
||||||
|
return f1 - f2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
int32_t ucs4_max_len = bytes + 4;
|
||||||
|
char *f1_mbs = calloc(bytes, 1);
|
||||||
|
char *f2_mbs = calloc(bytes, 1);
|
||||||
|
if (taosUcs4ToMbs(f1_ucs4, ucs4_max_len, f1_mbs) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (taosUcs4ToMbs(f2_ucs4, ucs4_max_len, f2_mbs) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
int32_t ret = strcmp(f1_mbs, f2_mbs);
|
||||||
|
free(f1_mbs);
|
||||||
|
free(f2_mbs);
|
||||||
|
return ret;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Copy memory to memory until the specified number of bytes
|
||||||
|
has been copied, return pointer to following byte.
|
||||||
|
Overlap is NOT handled correctly. */
|
||||||
|
void *mempcpy(void *dest, const void *src, size_t len) {
|
||||||
|
return (char*)memcpy(dest, src, len) + len;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Copy SRC to DEST, returning the address of the terminating '\0' in DEST. */
|
||||||
|
char *stpcpy (char *dest, const char *src) {
|
||||||
|
size_t len = strlen (src);
|
||||||
|
return (char*)memcpy(dest, src, len + 1) + len;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Copy no more than N characters of SRC to DEST, returning the address of
|
||||||
|
the terminating '\0' in DEST, if any, or else DEST + N. */
|
||||||
|
char *stpncpy (char *dest, const char *src, size_t n) {
|
||||||
|
size_t size = strnlen (src, n);
|
||||||
|
memcpy (dest, src, size);
|
||||||
|
dest += size;
|
||||||
|
if (size == n)
|
||||||
|
return dest;
|
||||||
|
return memset (dest, '\0', n - size);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
/*
|
||||||
|
* linux and darwin implementation
|
||||||
|
*/
|
||||||
|
|
||||||
|
int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes, int8_t ncharSize) {
|
||||||
|
return wcsncmp((wchar_t *)f1_ucs4, (wchar_t *)f2_ucs4, bytes / ncharSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -37,6 +37,9 @@
|
||||||
*/
|
*/
|
||||||
//
|
//
|
||||||
//#include "lukemftp.h"
|
//#include "lukemftp.h"
|
||||||
|
|
||||||
|
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -395,4 +398,6 @@ conv_num(const char **buf, int *dest, int llim, int ulim)
|
||||||
|
|
||||||
*dest = result;
|
*dest = result;
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,143 @@
|
||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
|
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* windows implementation
|
||||||
|
*/
|
||||||
|
|
||||||
|
void* taosLoadDll(const char* filename) { return NULL; }
|
||||||
|
void* taosLoadSym(void* handle, char* name) { return NULL; }
|
||||||
|
void taosCloseDll(void* handle) {}
|
||||||
|
|
||||||
|
int taosSetConsoleEcho(bool on) {
|
||||||
|
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
|
||||||
|
DWORD mode = 0;
|
||||||
|
GetConsoleMode(hStdin, &mode);
|
||||||
|
if (on) {
|
||||||
|
mode |= ENABLE_ECHO_INPUT;
|
||||||
|
} else {
|
||||||
|
mode &= ~ENABLE_ECHO_INPUT;
|
||||||
|
}
|
||||||
|
SetConsoleMode(hStdin, mode);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(_TD_DARWIN_64)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* darwin implementation
|
||||||
|
*/
|
||||||
|
|
||||||
|
void* taosLoadDll(const char* filename) { return NULL; }
|
||||||
|
void* taosLoadSym(void* handle, char* name) { return NULL; }
|
||||||
|
void taosCloseDll(void* handle) {}
|
||||||
|
|
||||||
|
int taosSetConsoleEcho(bool on) {
|
||||||
|
#define ECHOFLAGS (ECHO | ECHOE | ECHOK | ECHONL)
|
||||||
|
int err;
|
||||||
|
struct termios term;
|
||||||
|
|
||||||
|
if (tcgetattr(STDIN_FILENO, &term) == -1) {
|
||||||
|
perror("Cannot get the attribution of the terminal");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (on)
|
||||||
|
term.c_lflag |= ECHOFLAGS;
|
||||||
|
else
|
||||||
|
term.c_lflag &= ~ECHOFLAGS;
|
||||||
|
|
||||||
|
err = tcsetattr(STDIN_FILENO, TCSAFLUSH, &term);
|
||||||
|
if (err == -1 && err == EINTR) {
|
||||||
|
perror("Cannot set the attribution of the terminal");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
/*
|
||||||
|
* linux implementation
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#include <termios.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
void* taosLoadDll(const char* filename) {
|
||||||
|
void* handle = dlopen(filename, RTLD_LAZY);
|
||||||
|
if (!handle) {
|
||||||
|
printf("load dll:%s failed, error:%s", filename, dlerror());
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("dll %s loaded", filename);
|
||||||
|
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* taosLoadSym(void* handle, char* name) {
|
||||||
|
void* sym = dlsym(handle, name);
|
||||||
|
char* error = NULL;
|
||||||
|
|
||||||
|
if ((error = dlerror()) != NULL) {
|
||||||
|
printf("load sym:%s failed, error:%s", name, dlerror());
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("sym %s loaded", name);
|
||||||
|
|
||||||
|
return sym;
|
||||||
|
}
|
||||||
|
|
||||||
|
void taosCloseDll(void* handle) {
|
||||||
|
if (handle) {
|
||||||
|
dlclose(handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int taosSetConsoleEcho(bool on) {
|
||||||
|
#define ECHOFLAGS (ECHO | ECHOE | ECHOK | ECHONL)
|
||||||
|
int err;
|
||||||
|
struct termios term;
|
||||||
|
|
||||||
|
if (tcgetattr(STDIN_FILENO, &term) == -1) {
|
||||||
|
perror("Cannot get the attribution of the terminal");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (on)
|
||||||
|
term.c_lflag |= ECHOFLAGS;
|
||||||
|
else
|
||||||
|
term.c_lflag &= ~ECHOFLAGS;
|
||||||
|
|
||||||
|
err = tcsetattr(STDIN_FILENO, TCSAFLUSH, &term);
|
||||||
|
if (err == -1 || err == EINTR) {
|
||||||
|
printf("Cannot set the attribution of the terminal");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -13,16 +13,28 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define _BSD_SOURCE
|
||||||
|
|
||||||
|
#ifdef DARWIN
|
||||||
|
#define _XOPEN_SOURCE
|
||||||
|
#else
|
||||||
|
#define _XOPEN_SOURCE 500
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||||
#include <winsock2.h>
|
/*
|
||||||
#else
|
* windows implementation
|
||||||
#endif
|
*/
|
||||||
|
|
||||||
FORCE_INLINE int32_t taosGetTimeOfDay(struct timeval *tv) {
|
#include <time.h>
|
||||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
#include <winsock2.h>
|
||||||
time_t t;
|
|
||||||
|
int taosGetTimeOfDay(struct timeval *tv, struct timezone *tz) {
|
||||||
|
time_t t;
|
||||||
t = time(NULL);
|
t = time(NULL);
|
||||||
SYSTEMTIME st;
|
SYSTEMTIME st;
|
||||||
GetLocalTime(&st);
|
GetLocalTime(&st);
|
||||||
|
@ -31,7 +43,23 @@ FORCE_INLINE int32_t taosGetTimeOfDay(struct timeval *tv) {
|
||||||
tv->tv_usec = st.wMilliseconds * 1000;
|
tv->tv_usec = st.wMilliseconds * 1000;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct tm *localtime_r(const time_t *timep, struct tm *result) {
|
||||||
|
localtime_s(result, timep);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
/*
|
||||||
|
* linux and darwin implementation
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
FORCE_INLINE int32_t taosGetTimeOfDay(struct timeval *tv) {
|
||||||
return gettimeofday(tv, NULL);
|
return gettimeofday(tv, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
|
|
@ -0,0 +1,225 @@
|
||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
|
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* windows implementation
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <Windows.h>
|
||||||
|
#include <Mmsystem.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#pragma warning( disable : 4244 )
|
||||||
|
|
||||||
|
typedef void (*win_timer_f)(int signo);
|
||||||
|
|
||||||
|
void WINAPI taosWinOnTimer(UINT wTimerID, UINT msg, DWORD_PTR dwUser, DWORD_PTR dwl, DWORD_PTR dw2) {
|
||||||
|
win_timer_f callback = *((win_timer_f *)&dwUser);
|
||||||
|
if (callback != NULL) {
|
||||||
|
callback(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static MMRESULT timerId;
|
||||||
|
int taosInitTimer(win_timer_f callback, int ms) {
|
||||||
|
DWORD_PTR param = *((int64_t *) & callback);
|
||||||
|
|
||||||
|
timerId = timeSetEvent(ms, 1, (LPTIMECALLBACK)taosWinOnTimer, param, TIME_PERIODIC);
|
||||||
|
if (timerId == 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void taosUninitTimer() {
|
||||||
|
timeKillEvent(timerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(_TD_DARWIN_64)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* darwin implementation
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/syscall.h>
|
||||||
|
#include <sys/event.h>
|
||||||
|
|
||||||
|
static void (*timer_callback)(int);
|
||||||
|
static int timer_ms = 0;
|
||||||
|
static pthread_t timer_thread;
|
||||||
|
static int timer_kq = -1;
|
||||||
|
static volatile int timer_stop = 0;
|
||||||
|
|
||||||
|
static void* timer_routine(void *arg) {
|
||||||
|
(void)arg;
|
||||||
|
setThreadName("timer");
|
||||||
|
|
||||||
|
int r = 0;
|
||||||
|
struct timespec to = {0};
|
||||||
|
to.tv_sec = timer_ms / 1000;
|
||||||
|
to.tv_nsec = (timer_ms % 1000) * 1000000;
|
||||||
|
while (!timer_stop) {
|
||||||
|
struct kevent64_s kev[10] = {0};
|
||||||
|
r = kevent64(timer_kq, NULL, 0, kev, sizeof(kev)/sizeof(kev[0]), 0, &to);
|
||||||
|
if (r!=0) {
|
||||||
|
fprintf(stderr, "==%s[%d]%s()==kevent64 failed\n", basename(__FILE__), __LINE__, __func__);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
timer_callback(SIGALRM); // just mock
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int taosInitTimer(void (*callback)(int), int ms) {
|
||||||
|
int r = 0;
|
||||||
|
timer_ms = ms;
|
||||||
|
timer_callback = callback;
|
||||||
|
|
||||||
|
timer_kq = kqueue();
|
||||||
|
if (timer_kq==-1) {
|
||||||
|
fprintf(stderr, "==%s[%d]%s()==failed to create timer kq\n", basename(__FILE__), __LINE__, __func__);
|
||||||
|
// since no caller of this func checks the return value for the moment
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
r = pthread_create(&timer_thread, NULL, timer_routine, NULL);
|
||||||
|
if (r) {
|
||||||
|
fprintf(stderr, "==%s[%d]%s()==failed to create timer thread\n", basename(__FILE__), __LINE__, __func__);
|
||||||
|
// since no caller of this func checks the return value for the moment
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void taosUninitTimer() {
|
||||||
|
int r = 0;
|
||||||
|
timer_stop = 1;
|
||||||
|
r = pthread_join(timer_thread, NULL);
|
||||||
|
if (r) {
|
||||||
|
fprintf(stderr, "==%s[%d]%s()==failed to join timer thread\n", basename(__FILE__), __LINE__, __func__);
|
||||||
|
// since no caller of this func checks the return value for the moment
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
close(timer_kq);
|
||||||
|
timer_kq = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void taos_block_sigalrm(void) {
|
||||||
|
// we don't know if there's any specific API for SIGALRM to deliver to specific thread
|
||||||
|
// this implementation relies on kqueue rather than SIGALRM
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
/*
|
||||||
|
* linux implementation
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/syscall.h>
|
||||||
|
|
||||||
|
static void taosDeleteTimer(void *tharg) {
|
||||||
|
timer_t *pTimer = tharg;
|
||||||
|
timer_delete(*pTimer);
|
||||||
|
}
|
||||||
|
|
||||||
|
static pthread_t timerThread;
|
||||||
|
static timer_t timerId;
|
||||||
|
static volatile bool stopTimer = false;
|
||||||
|
static void *taosProcessAlarmSignal(void *tharg) {
|
||||||
|
// Block the signal
|
||||||
|
sigset_t sigset;
|
||||||
|
sigemptyset(&sigset);
|
||||||
|
sigaddset(&sigset, SIGALRM);
|
||||||
|
sigprocmask(SIG_BLOCK, &sigset, NULL);
|
||||||
|
void (*callback)(int) = tharg;
|
||||||
|
|
||||||
|
struct sigevent sevent = {{0}};
|
||||||
|
|
||||||
|
setThreadName("tmr");
|
||||||
|
|
||||||
|
#ifdef _ALPINE
|
||||||
|
sevent.sigev_notify = SIGEV_THREAD;
|
||||||
|
sevent.sigev_value.sival_int = syscall(__NR_gettid);
|
||||||
|
#else
|
||||||
|
sevent.sigev_notify = SIGEV_THREAD_ID;
|
||||||
|
sevent._sigev_un._tid = syscall(__NR_gettid);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
sevent.sigev_signo = SIGALRM;
|
||||||
|
|
||||||
|
if (timer_create(CLOCK_REALTIME, &sevent, &timerId) == -1) {
|
||||||
|
printf("Failed to create timer");
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_cleanup_push(taosDeleteTimer, &timerId);
|
||||||
|
|
||||||
|
struct itimerspec ts;
|
||||||
|
ts.it_value.tv_sec = 0;
|
||||||
|
ts.it_value.tv_nsec = 1000000 * MSECONDS_PER_TICK;
|
||||||
|
ts.it_interval.tv_sec = 0;
|
||||||
|
ts.it_interval.tv_nsec = 1000000 * MSECONDS_PER_TICK;
|
||||||
|
|
||||||
|
if (timer_settime(timerId, 0, &ts, NULL)) {
|
||||||
|
printf("Failed to init timer");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int signo;
|
||||||
|
while (!stopTimer) {
|
||||||
|
if (sigwait(&sigset, &signo)) {
|
||||||
|
printf("Failed to wait signal: number %d", signo);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
/* printf("Signal handling: number %d ......\n", signo); */
|
||||||
|
|
||||||
|
callback(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_cleanup_pop(1);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int taosInitTimer(void (*callback)(int), int ms) {
|
||||||
|
pthread_attr_t tattr;
|
||||||
|
pthread_attr_init(&tattr);
|
||||||
|
int code = pthread_create(&timerThread, &tattr, taosProcessAlarmSignal, callback);
|
||||||
|
pthread_attr_destroy(&tattr);
|
||||||
|
if (code != 0) {
|
||||||
|
printf("failed to create timer thread");
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
printf("timer thread:0x%08" PRIx64 " is created", taosGetPthreadId(timerThread));
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void taosUninitTimer() {
|
||||||
|
stopTimer = true;
|
||||||
|
|
||||||
|
printf("join timer thread:0x%08" PRIx64, taosGetPthreadId(timerThread));
|
||||||
|
pthread_join(timerThread, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -28,7 +28,7 @@
|
||||||
#include "mnode.h"
|
#include "mnode.h"
|
||||||
|
|
||||||
static int32_t dnodeCreateDir(const char *dir) {
|
static int32_t dnodeCreateDir(const char *dir) {
|
||||||
if (taosMkDir(dir, 0755) != 0 && errno != EEXIST) {
|
if (!taosMkDir(dir, 0755) && errno != EEXIST) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +55,14 @@ static void dnodeCheckDataDirOpenned(char *dir) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dnodePrintDiskInfo() {
|
||||||
|
dInfo("==================================");
|
||||||
|
dInfo(" os totalDisk: %f(GB)", tsTotalDataDirGB);
|
||||||
|
dInfo(" os usedDisk: %f(GB)", tsUsedDataDirGB);
|
||||||
|
dInfo(" os availDisk: %f(GB)", tsAvailDataDirGB);
|
||||||
|
dInfo("==================================");
|
||||||
|
}
|
||||||
|
|
||||||
int32_t dnodeInitMain(Dnode *dnode, DnMain **out) {
|
int32_t dnodeInitMain(Dnode *dnode, DnMain **out) {
|
||||||
DnMain* main = calloc(1, sizeof(DnMain));
|
DnMain* main = calloc(1, sizeof(DnMain));
|
||||||
if (main == NULL) return -1;
|
if (main == NULL) return -1;
|
||||||
|
@ -76,7 +84,7 @@ int32_t dnodeInitMain(Dnode *dnode, DnMain **out) {
|
||||||
taosInitGlobalCfg();
|
taosInitGlobalCfg();
|
||||||
taosReadGlobalLogCfg();
|
taosReadGlobalLogCfg();
|
||||||
#if 0
|
#if 0
|
||||||
taosSetCoreDump();
|
taosSetCoreDump(tsEnableCoreFile);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (dnodeCreateDir(tsLogDir) < 0) {
|
if (dnodeCreateDir(tsLogDir) < 0) {
|
||||||
|
@ -182,7 +190,7 @@ int32_t dnodeInitStorage(Dnode *dnode, void **m) {
|
||||||
dnodeCheckDataDirOpenned(tsDnodeDir);
|
dnodeCheckDataDirOpenned(tsDnodeDir);
|
||||||
|
|
||||||
taosGetDisk();
|
taosGetDisk();
|
||||||
taosPrintDiskInfo();
|
dnodePrintDiskInfo();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
dInfo("dnode storage is initialized at %s", tsDnodeDir);
|
dInfo("dnode storage is initialized at %s", tsDnodeDir);
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
#include "ttime.h"
|
||||||
#include "ttimer.h"
|
#include "ttimer.h"
|
||||||
#include "tglobal.h"
|
#include "tglobal.h"
|
||||||
#include "dnodeCfg.h"
|
#include "dnodeCfg.h"
|
||||||
|
|
|
@ -8,4 +8,6 @@ target_include_directories(
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
util
|
util
|
||||||
PRIVATE os
|
PRIVATE os
|
||||||
)
|
PUBLIC zlib
|
||||||
|
PUBLIC lz4_static
|
||||||
|
)
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
#include "tulog.h"
|
#include "tulog.h"
|
||||||
// #include "taosdef.h"
|
|
||||||
|
|
||||||
#define EXT_SIZE 1024
|
#define EXT_SIZE 1024
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
#include "talgo.h"
|
#include "talgo.h"
|
||||||
|
|
||||||
#define doswap(__left, __right, __size, __buf) do {\
|
#define doswap(__left, __right, __size, __buf) do {\
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
#include "regex.h"
|
#include "regex.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "ttype.h"
|
#include "tdef.h"
|
||||||
|
|
||||||
int32_t setCompareBytes1(const void *pLeft, const void *pRight) {
|
int32_t setCompareBytes1(const void *pLeft, const void *pRight) {
|
||||||
return NULL != taosHashGet((SHashObj *)pRight, pLeft, 1) ? 1 : 0;
|
return NULL != taosHashGet((SHashObj *)pRight, pLeft, 1) ? 1 : 0;
|
|
@ -52,11 +52,8 @@
|
||||||
#ifdef TD_TSZ
|
#ifdef TD_TSZ
|
||||||
#include "td_sz.h"
|
#include "td_sz.h"
|
||||||
#endif
|
#endif
|
||||||
#include "taosdef.h"
|
|
||||||
#include "tscompression.h"
|
#include "tscompression.h"
|
||||||
#include "tulog.h"
|
#include "tulog.h"
|
||||||
#include "tglobal.h"
|
|
||||||
|
|
||||||
|
|
||||||
static const int TEST_NUMBER = 1;
|
static const int TEST_NUMBER = 1;
|
||||||
#define is_bigendian() ((*(char *)&TEST_NUMBER) == 0)
|
#define is_bigendian() ((*(char *)&TEST_NUMBER) == 0)
|
|
@ -15,10 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "taosdef.h"
|
|
||||||
#include "taoserror.h"
|
|
||||||
#include "tconfig.h"
|
#include "tconfig.h"
|
||||||
#include "tglobal.h"
|
|
||||||
#include "tulog.h"
|
#include "tulog.h"
|
||||||
#include "tsocket.h"
|
#include "tsocket.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
|
@ -78,7 +75,6 @@ static void taosReadDoubleConfig(SGlobalCfg *cfg, char *input_value) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void taosReadInt32Config(SGlobalCfg *cfg, char *input_value) {
|
static void taosReadInt32Config(SGlobalCfg *cfg, char *input_value) {
|
||||||
int32_t value = atoi(input_value);
|
int32_t value = atoi(input_value);
|
||||||
int32_t *option = (int32_t *)cfg->ptr;
|
int32_t *option = (int32_t *)cfg->ptr;
|
||||||
|
@ -156,27 +152,10 @@ static bool taosReadDirectoryConfig(SGlobalCfg *cfg, char *input_value) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
|
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
|
||||||
wordexp_t full_path;
|
taosExpandDir(input_value, option, cfg->ptrLength);
|
||||||
if (0 != wordexp(input_value, &full_path, 0)) {
|
taosRealPath(option, cfg->ptrLength);
|
||||||
printf("\nconfig dir: %s wordexp fail! reason:%s\n", input_value, strerror(errno));
|
|
||||||
wordfree(&full_path);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) {
|
if (!taosMkDir(option, 0755)) {
|
||||||
strcpy(option, full_path.we_wordv[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
wordfree(&full_path);
|
|
||||||
|
|
||||||
char tmp[PATH_MAX] = {0};
|
|
||||||
if (realpath(option, tmp) != NULL) {
|
|
||||||
strcpy(option, tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
int code = taosMkDir(option, 0755);
|
|
||||||
if (code != 0) {
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
uError("config option:%s, input value:%s, directory not exist, create fail:%s", cfg->option, input_value,
|
uError("config option:%s, input value:%s, directory not exist, create fail:%s", cfg->option, input_value,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
return false;
|
return false;
|
||||||
|
@ -234,9 +213,9 @@ static void taosReadLogOption(char *option, char *value) {
|
||||||
switch (cfg->valType) {
|
switch (cfg->valType) {
|
||||||
case TAOS_CFG_VTYPE_INT32:
|
case TAOS_CFG_VTYPE_INT32:
|
||||||
taosReadInt32Config(cfg, value);
|
taosReadInt32Config(cfg, value);
|
||||||
if (strcasecmp(cfg->option, "debugFlag") == 0) {
|
// if (strcasecmp(cfg->option, "debugFlag") == 0) {
|
||||||
taosSetAllDebugFlag();
|
// taosSetAllDebugFlag();
|
||||||
}
|
// }
|
||||||
break;
|
break;
|
||||||
case TAOS_CFG_VTYPE_DIRECTORY:
|
case TAOS_CFG_VTYPE_DIRECTORY:
|
||||||
taosReadDirectoryConfig(cfg, value);
|
taosReadDirectoryConfig(cfg, value);
|
||||||
|
@ -249,7 +228,6 @@ static void taosReadLogOption(char *option, char *value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SGlobalCfg *taosGetConfigOption(const char *option) {
|
SGlobalCfg *taosGetConfigOption(const char *option) {
|
||||||
taosInitGlobalCfg();
|
|
||||||
for (int i = 0; i < tsGlobalConfigNum; ++i) {
|
for (int i = 0; i < tsGlobalConfigNum; ++i) {
|
||||||
SGlobalCfg *cfg = tsGlobalConfig + i;
|
SGlobalCfg *cfg = tsGlobalConfig + i;
|
||||||
if (strcasecmp(cfg->option, option) != 0) continue;
|
if (strcasecmp(cfg->option, option) != 0) continue;
|
||||||
|
@ -294,7 +272,7 @@ static void taosReadConfigOption(const char *option, char *value, char *value2,
|
||||||
break;
|
break;
|
||||||
case TAOS_CFG_VTYPE_DATA_DIRCTORY:
|
case TAOS_CFG_VTYPE_DATA_DIRCTORY:
|
||||||
if (taosReadDirectoryConfig(cfg, value)) {
|
if (taosReadDirectoryConfig(cfg, value)) {
|
||||||
taosReadDataDirCfg(value, value2, value3);
|
// taosReadDataDirCfg(value, value2, value3);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -315,34 +293,7 @@ void taosReadGlobalLogCfg() {
|
||||||
int olen, vlen;
|
int olen, vlen;
|
||||||
char fileName[PATH_MAX] = {0};
|
char fileName[PATH_MAX] = {0};
|
||||||
|
|
||||||
wordexp_t full_path;
|
taosExpandDir(configDir, configDir, PATH_MAX);
|
||||||
if ( 0 != wordexp(configDir, &full_path, 0)) {
|
|
||||||
printf("\nconfig file: %s wordexp fail! reason:%s\n", configDir, strerror(errno));
|
|
||||||
wordfree(&full_path);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) {
|
|
||||||
if (strlen(full_path.we_wordv[0]) >= TSDB_FILENAME_LEN) {
|
|
||||||
printf("\nconfig file: %s path overflow max len %d, all variables are set to default\n", full_path.we_wordv[0], TSDB_FILENAME_LEN - 1);
|
|
||||||
wordfree(&full_path);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
strcpy(configDir, full_path.we_wordv[0]);
|
|
||||||
} else {
|
|
||||||
#ifdef _TD_POWER_
|
|
||||||
printf("configDir:%s not there, use default value: /etc/power", configDir);
|
|
||||||
strcpy(configDir, "/etc/power");
|
|
||||||
#elif (_TD_TQ_ == true)
|
|
||||||
printf("configDir:%s not there, use default value: /etc/tq", configDir);
|
|
||||||
strcpy(configDir, "/etc/tq");
|
|
||||||
#else
|
|
||||||
printf("configDir:%s not there, use default value: /etc/taos", configDir);
|
|
||||||
strcpy(configDir, "/etc/taos");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
wordfree(&full_path);
|
|
||||||
|
|
||||||
taosReadLogOption("logDir", tsLogDir);
|
taosReadLogOption("logDir", tsLogDir);
|
||||||
|
|
||||||
sprintf(fileName, "%s/taos.cfg", configDir);
|
sprintf(fileName, "%s/taos.cfg", configDir);
|
||||||
|
@ -391,13 +342,8 @@ bool taosReadGlobalCfg() {
|
||||||
char fileName[PATH_MAX] = {0};
|
char fileName[PATH_MAX] = {0};
|
||||||
|
|
||||||
sprintf(fileName, "%s/taos.cfg", configDir);
|
sprintf(fileName, "%s/taos.cfg", configDir);
|
||||||
FILE* fp = fopen(fileName, "r");
|
FILE *fp = fopen(fileName, "r");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
struct stat s;
|
|
||||||
if (stat(configDir, &s) != 0 || (!S_ISREG(s.st_mode) && !S_ISLNK(s.st_mode))) {
|
|
||||||
//return true to follow behavior before file support
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
fp = fopen(configDir, "r");
|
fp = fopen(configDir, "r");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -444,9 +390,9 @@ bool taosReadGlobalCfg() {
|
||||||
|
|
||||||
tfree(line);
|
tfree(line);
|
||||||
|
|
||||||
if (debugFlag & DEBUG_TRACE || debugFlag & DEBUG_DEBUG || debugFlag & DEBUG_DUMP) {
|
// if (debugFlag & DEBUG_TRACE || debugFlag & DEBUG_DEBUG || debugFlag & DEBUG_DUMP) {
|
||||||
taosSetAllDebugFlag();
|
// taosSetAllDebugFlag();
|
||||||
}
|
// }
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -498,7 +444,7 @@ void taosPrintGlobalCfg() {
|
||||||
}
|
}
|
||||||
|
|
||||||
taosPrintOsInfo();
|
taosPrintOsInfo();
|
||||||
taosPrintDataDirCfg();
|
// taosPrintDataDirCfg();
|
||||||
uInfo("==================================");
|
uInfo("==================================");
|
||||||
}
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue