diff --git a/CMakeLists.txt b/CMakeLists.txt
index e16c93c1f1394969c945aba55188c262dfb4b961..95e1cad2fe93a9a0e78f4e3cb83dac361d043fd7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -42,6 +42,8 @@ execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/deps/deps-download")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -gdwarf-2 -msse4.2 -mfma")
+
# deps
add_subdirectory(deps)
diff --git a/include/client/taos.h b/include/client/taos.h
index edb1552b811a2ff4b8c78c19523cc6f2ad82ba74..635ca3c7747e6c11d2f66cc53c0e9c7cda6e7f7c 100644
--- a/include/client/taos.h
+++ b/include/client/taos.h
@@ -31,21 +31,23 @@ typedef void TAOS_SUB;
typedef void **TAOS_ROW;
// Data type definition
-#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
+#ifndef TSDB_DATA_TYPE_NULL
+ #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
+#endif
typedef enum {
TSDB_OPTION_LOCALE,
diff --git a/include/common/taosdef.h b/include/common/taosdef.h
index 0bcd693f5e0881f61915e5599c772b8db8033ce0..dd7dfd9518adf0381505a2d53a770e1dd5a3a54e 100644
--- a/include/common/taosdef.h
+++ b/include/common/taosdef.h
@@ -13,389 +13,20 @@
* along with this program. If not, see .
*/
-#ifndef TDENGINE_TAOS_DEF_H
-#define TDENGINE_TAOS_DEF_H
+#ifndef _TD_COMMON_TAOS_DEF_H
+#define _TD_COMMON_TAOS_DEF_H
#ifdef __cplusplus
extern "C" {
#endif
-#include
-#include
+#include "tdef.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_DESC_INITIALIZER ((STimeWindow) {INT64_MAX, INT64_MIN})
#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 {
TAOS_QTYPE_RPC = 0,
TAOS_QTYPE_FWD = 1,
@@ -404,10 +35,6 @@ typedef enum {
TAOS_QTYPE_QUERY = 4
} 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 {
TSDB_SUPER_TABLE = 0, // super table
TSDB_CHILD_TABLE = 1, // table created from super table
@@ -449,4 +76,4 @@ extern char *qtypeStr[];
}
#endif
-#endif
+#endif /*_TD_COMMON_TAOS_DEF_H*/
diff --git a/src/common/inc/tarithoperator.h b/include/common/tarithoperator.h
similarity index 100%
rename from src/common/inc/tarithoperator.h
rename to include/common/tarithoperator.h
diff --git a/src/common/inc/tcmdtype.h b/include/common/tcmdtype.h
similarity index 100%
rename from src/common/inc/tcmdtype.h
rename to include/common/tcmdtype.h
diff --git a/src/common/inc/texpr.h b/include/common/texpr.h
similarity index 100%
rename from src/common/inc/texpr.h
rename to include/common/texpr.h
diff --git a/include/common/tglobal.h b/include/common/tglobal.h
index a5f8005e9cd90214c5ec3f1c387d18c772794e43..867d4ae2dddff7dd114aa72684a1bf5a83d0b465 100644
--- a/include/common/tglobal.h
+++ b/include/common/tglobal.h
@@ -13,10 +13,8 @@
* along with this program. If not, see .
*/
-#ifndef TDENGINE_COMMON_GLOBAL_H
-#define TDENGINE_COMMON_GLOBAL_H
-
-#include "taosdef.h"
+#ifndef _TD_COMMON_GLOBAL_H
+#define _TD_COMMON_GLOBAL_H
#ifdef __cplusplus
extern "C" {
@@ -52,9 +50,6 @@ extern float tsNumOfThreadsPerCore;
extern int32_t tsNumOfCommitThreads;
extern float tsRatioOfQueryCores;
extern int8_t tsDaylight;
-extern char tsTimezone[];
-extern char tsLocale[];
-extern char tsCharset[]; // default encode string
extern int8_t tsEnableCoreFile;
extern int32_t tsCompressMsgSize;
extern int32_t tsCompressColData;
@@ -151,24 +146,14 @@ extern int8_t tsEnableStream;
// internal
extern int8_t tsPrintAuth;
extern int8_t tscEmbedded;
-extern char configDir[];
extern char tsVnodeDir[];
-extern char tsDnodeDir[];
extern char tsMnodeDir[];
extern char tsMnodeBakDir[];
extern char tsMnodeTmpDir[];
-extern char tsDataDir[];
-extern char tsLogDir[];
-extern char tsScriptDir[];
extern int64_t tsTickPerDay[3];
extern int32_t tsTopicBianryLen;
// 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 tsTotalTmpDirGB;
extern float tsTotalDataDirGB;
@@ -179,7 +164,6 @@ extern float tsUsedDataDirGB;
extern float tsMinimalLogDirGB;
extern float tsReservedTmpDirectorySpace;
extern float tsMinimalDataDirGB;
-extern int32_t tsTotalMemoryMB;
extern uint32_t tsVersion;
// build info
@@ -189,28 +173,6 @@ extern char gitinfo[];
extern char gitinfoOfInternal[];
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
// lossy
extern char lossyColumns[];
@@ -224,7 +186,7 @@ extern char Compressor[];
extern int8_t tsDeadLockKillQuery;
typedef struct {
- char dir[TSDB_FILENAME_LEN];
+ char dir[128];
int level;
int primary;
} SDiskCfg;
@@ -235,7 +197,6 @@ extern SDiskCfg tsDiskCfg[];
void taosInitGlobalCfg();
int32_t taosCheckGlobalCfg();
-void taosSetAllDebugFlag();
bool taosCfgDynamicOptions(char *msg);
int taosGetFqdnPortFromEp(const char *ep, char *fqdn, uint16_t *port);
bool taosCheckBalanceCfgOptions(const char *option, int32_t *vnodeId, int32_t *dnodeId);
diff --git a/src/common/inc/tlocale.h b/include/common/tlocale.h
similarity index 100%
rename from src/common/inc/tlocale.h
rename to include/common/tlocale.h
diff --git a/src/common/inc/tname.h b/include/common/tname.h
similarity index 100%
rename from src/common/inc/tname.h
rename to include/common/tname.h
diff --git a/include/common/ttime.h b/include/common/ttime.h
new file mode 100644
index 0000000000000000000000000000000000000000..0d9b89b6f9c22e484917a2af2d26a56f40094b1b
--- /dev/null
+++ b/include/common/ttime.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * 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 .
+ */
+
+#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_*/
diff --git a/src/common/inc/ttimezone.h b/include/common/ttimezone.h
similarity index 100%
rename from src/common/inc/ttimezone.h
rename to include/common/ttimezone.h
diff --git a/include/common/ttype.h b/include/common/ttype.h
index 3f1606e957564f0a86988a389071957d2204d391..42296f80ba3199b463452513adf126a03945bd10 100644
--- a/include/common/ttype.h
+++ b/include/common/ttype.h
@@ -9,43 +9,6 @@ extern "C" {
#include
#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
#define TSDB_DATA_TYPE_POINTER_ARRAY (1000)
#define TSDB_DATA_TYPE_VALUE_ARRAY (1001)
diff --git a/src/common/inc/tvariant.h b/include/common/tvariant.h
similarity index 100%
rename from src/common/inc/tvariant.h
rename to include/common/tvariant.h
diff --git a/include/os/os.h b/include/os/os.h
index d450ff620f57293716fe7fcbbc8768e8c35fb0e3..447df9d65c135b30e2f83ec1a212c21458be437d 100644
--- a/include/os/os.h
+++ b/include/os/os.h
@@ -27,20 +27,26 @@ extern "C" {
#include
#include
#include
+#include
#include
#include
#include
+#include
#include
#include
#include
#include
#include
+#include
+#include
#include "osAtomic.h"
#include "osDef.h"
#include "osDir.h"
#include "osEndian.h"
+#include "osEnv.h"
#include "osFile.h"
+#include "osLz4.h"
#include "osMath.h"
#include "osMemory.h"
#include "osRand.h"
@@ -49,10 +55,14 @@ extern "C" {
#include "osSleep.h"
#include "osSocket.h"
#include "osString.h"
+#include "osSysinfo.h"
+#include "osSystem.h"
#include "osThread.h"
#include "osTime.h"
#include "osTimer.h"
+void osInit();
+
#ifdef __cplusplus
}
#endif
diff --git a/include/os/osDef.h b/include/os/osDef.h
index 053bf42ece7fe814d762a93a0b7972ffb34c9de3..8db9c6584f71827c6f2bd89853a88a98112435ce 100644
--- a/include/os/osDef.h
+++ b/include/os/osDef.h
@@ -20,14 +20,154 @@
extern "C" {
#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__)
#define FORCE_INLINE inline __attribute__((always_inline))
#else
#define FORCE_INLINE
#endif
-#define POINTER_SHIFT(p, b) ((void *)((char *)(p) + (b)))
-#define POINTER_DISTANCE(p1, p2) ((char *)(p1) - (char *)(p2))
+#define DEFAULT_UNICODE_ENCODEC "UCS-4LE"
+
+#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_DARWIN_64)
@@ -47,17 +187,6 @@ extern "C" {
#define setThreadName(name)
#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
}
#endif
diff --git a/include/os/osDir.h b/include/os/osDir.h
index dfd814d70b49a993fba53ec6ec20610ac0e619f9..74286edbe80ac1212aead2a5fe0b7d1fd80a05f0 100644
--- a/include/os/osDir.h
+++ b/include/os/osDir.h
@@ -20,12 +20,12 @@
extern "C" {
#endif
-void taosRemoveDir(char *rootDir);
-bool taosDirExist(const char* dirname);
-int32_t taosMkDir(const char *pathname, mode_t mode);
-void taosRemoveOldLogFiles(char *rootDir, int32_t keepDays);
-int32_t taosRename(char *oldName, char *newName);
-int32_t taosCompressFile(char *srcFileName, char *destFileName);
+void taosRemoveDir(char *dirname);
+bool taosDirExist(char *dirname);
+bool taosMkDir(char *dirname, mode_t mode);
+void taosRemoveOldFiles(char *dirname, int32_t keepDays);
+bool taosExpandDir(char *dirname, char *outname, int32_t maxlen);
+bool taosRealPath(char *dirname, int32_t maxlen);
#ifdef __cplusplus
}
diff --git a/src/os/inc/osRand.h b/include/os/osEnv.h
similarity index 76%
rename from src/os/inc/osRand.h
rename to include/os/osEnv.h
index e08768c2cc6b379877fb8be7d3541c13bc431f98..b857670214699c52975fff1020e548f6b40242a6 100644
--- a/src/os/inc/osRand.h
+++ b/include/os/osEnv.h
@@ -13,19 +13,22 @@
* along with this program. If not, see .
*/
-#ifndef TDENGINE_OS_RAND_H
-#define TDENGINE_OS_RAND_H
+#ifndef _TD_OS_ENV_H_
+#define _TD_OS_ENV_H_
#ifdef __cplusplus
extern "C" {
#endif
-uint32_t taosRand(void);
-void taosRandStr(char* str, int32_t size);
-uint32_t taosSafeRand(void);
+extern char tsOsName[];
+extern char tsDnodeDir[];
+extern char tsDataDir[];
+extern char tsLogDir[];
+extern char tsScriptDir[];
+extern char configDir[];
#ifdef __cplusplus
}
#endif
-#endif
+#endif /*_TD_OS_ENV_H_*/
\ No newline at end of file
diff --git a/src/os/inc/osLz4.h b/include/os/osLz4.h
similarity index 95%
rename from src/os/inc/osLz4.h
rename to include/os/osLz4.h
index 8363861e0348141243c49c9df72b4aac7b6c199d..09aaa553acc66fe71bd4e34576cf6911799ecbd4 100644
--- a/src/os/inc/osLz4.h
+++ b/include/os/osLz4.h
@@ -13,8 +13,8 @@
* along with this program. If not, see .
*/
-#ifndef TDENGINE_OS_LZ4_H
-#define TDENGINE_OS_LZ4_H
+#ifndef _TD_OS_LZ4_H_
+#define _TD_OS_LZ4_H_
#ifdef __cplusplus
extern "C" {
@@ -46,4 +46,4 @@ extern "C" {
}
#endif
-#endif
+#endif /*_TD_OS_LZ4_H_*/
diff --git a/include/os/osSignal.h b/include/os/osSignal.h
index ce133e62b7bd2c4eb81e689309c82aa4de9f25d5..ab4b6fa242cce2a7250ec6e7f3c669d62dd0ac21 100644
--- a/include/os/osSignal.h
+++ b/include/os/osSignal.h
@@ -20,8 +20,34 @@
extern "C" {
#endif
-int32_t taosInitTimer(void (*callback)(int32_t), int32_t ms);
-void taosUninitTimer();
+#ifndef SIGALRM
+ #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
}
diff --git a/include/os/osSleep.h b/include/os/osSleep.h
index e42da8d5a64bbc484b15beea19433a710578ff3f..686bdd292e376f55182caea52189a678bfdc3b14 100644
--- a/include/os/osSleep.h
+++ b/include/os/osSleep.h
@@ -13,8 +13,8 @@
* along with this program. If not, see .
*/
-#ifndef TDENGINE_OS_SLEEP_H
-#define TDENGINE_OS_SLEEP_H
+#ifndef _TD_OS_SLEEP_H_
+#define _TD_OS_SLEEP_H_
#ifdef __cplusplus
extern "C" {
@@ -26,4 +26,4 @@ void taosMsleep(int32_t ms);
}
#endif
-#endif
\ No newline at end of file
+#endif /*_TD_OS_SLEEP_H_*/
\ No newline at end of file
diff --git a/include/os/osSocket.h b/include/os/osSocket.h
index 719c69376513fe351a8feb8c05ae1a48603297b0..11a6486ff6fe08ea020f14aa352f8c4ec4420db3 100644
--- a/include/os/osSocket.h
+++ b/include/os/osSocket.h
@@ -13,8 +13,8 @@
* along with this program. If not, see .
*/
-#ifndef TDENGINE_OS_SOCKET_H
-#define TDENGINE_OS_SOCKET_H
+#ifndef _TD_OS_SOCKET_H_
+#define _TD_OS_SOCKET_H_
#ifdef __cplusplus
extern "C" {
@@ -89,4 +89,4 @@ const char *taosInetNtoa(struct in_addr ipInt);
}
#endif
-#endif
+#endif /*_TD_OS_SOCKET_H_*/
diff --git a/include/os/osString.h b/include/os/osString.h
index 3adee83c84ca979bd3f80921560fc8e0ad750367..358324075fab292657a207c37c3d1292a137b0d9 100644
--- a/include/os/osString.h
+++ b/include/os/osString.h
@@ -43,7 +43,7 @@ int64_t taosStr2int64(char *str);
// USE_LIBICONV
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);
-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);
char * taosCharsetReplace(char *charsetstr);
diff --git a/include/os/osSysinfo.h b/include/os/osSysinfo.h
new file mode 100644
index 0000000000000000000000000000000000000000..62b52827d68b33ac2ee84e884772dbf416e2ef64
--- /dev/null
+++ b/include/os/osSysinfo.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * 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 .
+ */
+
+#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
diff --git a/src/os/inc/osSystem.h b/include/os/osSystem.h
similarity index 79%
rename from src/os/inc/osSystem.h
rename to include/os/osSystem.h
index 4b7925074075b7eef04d2281d3ba7649740bae1e..8554c4ad12f8737aac63a1815b63acf9cf0f69ff 100644
--- a/src/os/inc/osSystem.h
+++ b/include/os/osSystem.h
@@ -13,21 +13,21 @@
* along with this program. If not, see .
*/
-#ifndef TDENGINE_OS_SYSTEM_H
-#define TDENGINE_OS_SYSTEM_H
+#ifndef _TD_OS_SYSTEM_H_
+#define _TD_OS_SYSTEM_H_
#ifdef __cplusplus
extern "C" {
#endif
-void* taosLoadDll(const char *filename);
+void* taosLoadDll(const char* filename);
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
}
#endif
-#endif
+#endif /*_TD_OS_SYSTEM_H_*/
diff --git a/include/os/osTime.h b/include/os/osTime.h
index d076d502766505ae5d44e3b126a411453eb81383..62ecd5477f4d27c0214140f014aa95fc8b5ef605 100644
--- a/include/os/osTime.h
+++ b/include/os/osTime.h
@@ -20,6 +20,21 @@
extern "C" {
#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);
//@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;
}
-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
diff --git a/include/os/osTimer.h b/include/os/osTimer.h
index 623d2da20a3285e67adc12f5c9fccb1756e55e4b..2afe018c433eee13e05de70305f344c81f7c7b9c 100644
--- a/include/os/osTimer.h
+++ b/include/os/osTimer.h
@@ -20,6 +20,8 @@
extern "C" {
#endif
+#define MSECONDS_PER_TICK 5
+
int32_t taosInitTimer(void (*callback)(int32_t), int32_t ms);
void taosUninitTimer();
diff --git a/src/util/inc/exception.h b/include/util/exception.h
similarity index 96%
rename from src/util/inc/exception.h
rename to include/util/exception.h
index 38f94bfe283e41e4418ed6ab1673efb82acc44a0..8012e3431591099a645373092fb34ac0fb66ea77 100644
--- a/src/util/inc/exception.h
+++ b/include/util/exception.h
@@ -13,13 +13,10 @@
* along with this program. If not, see .
*/
-#ifndef TDENGINE_EXCEPTION_H
-#define TDENGINE_EXCEPTION_H
+#ifndef _TD_UTIL_EXCEPTION_H
+#define _TD_UTIL_EXCEPTION_H
-#include
-#include
-#include
-#include
+#include "os.h"
#ifdef __cplusplus
extern "C" {
@@ -125,4 +122,4 @@ void exceptionThrow( int32_t code );
}
#endif
-#endif
+#endif /*_TD_UTIL_EXCEPTION_H*/
diff --git a/include/util/hash.h b/include/util/hash.h
index 7a93745dc800df3d6395e756cc8433cf4062af8a..5c723be1060ea8b28737b3554cae1c58c54b562c 100644
--- a/include/util/hash.h
+++ b/include/util/hash.h
@@ -13,8 +13,8 @@
* along with this program. If not, see .
*/
-#ifndef TDENGINE_HASH_H
-#define TDENGINE_HASH_H
+#ifndef _TD_UTIL_HASH_H
+#define _TD_UTIL_HASH_H
#ifdef __cplusplus
extern "C" {
@@ -178,4 +178,4 @@ uint32_t taosHashGetDataKeyLen(SHashObj *pHashObj, void *data);
}
#endif
-#endif // TDENGINE_HASH_H
+#endif /*_TD_UTIL_HASH_H*/
diff --git a/include/util/hashfunc.h b/include/util/hashfunc.h
index a9563d03941496a42e71a91fc7b7aab014ff4f50..04c2d1fcf0546737a397ccb5499a7477e26c6465 100644
--- a/include/util/hashfunc.h
+++ b/include/util/hashfunc.h
@@ -13,8 +13,8 @@
* along with this program. If not, see .
*/
-#ifndef TDENGINE_HASHUTIL_H
-#define TDENGINE_HASHUTIL_H
+#ifndef _TD_UTIL_HASH_FUNC_H
+#define _TD_UTIL_HASH_FUNC_H
#include "os.h"
@@ -48,4 +48,4 @@ _hash_fn_t taosGetDefaultHashFunction(int32_t type);
_equal_fn_t taosGetDefaultEqualFunction(int32_t type);
-#endif //TDENGINE_HASHUTIL_H
+#endif /*_TD_UTIL_HASH_FUNC_H*/
diff --git a/include/util/talgo.h b/include/util/talgo.h
index 4aa54306052bfe224d81ac90f8310de7ac85f8eb..575f98b486f90b2eb4a830d0bb39868fcdc0c137 100644
--- a/include/util/talgo.h
+++ b/include/util/talgo.h
@@ -13,8 +13,8 @@
* along with this program. If not, see .
*/
-#ifndef TDENGINE_TALGO_H
-#define TDENGINE_TALGO_H
+#ifndef _TD_UTIL_TALGO_H
+#define _TD_UTIL_TALGO_H
#ifdef __cplusplus
extern "C" {
@@ -95,4 +95,4 @@ void taosheapsort(void *base, int32_t size, int32_t len, const void *parcompar,
#ifdef __cplusplus
}
#endif
-#endif // TDENGINE_TALGO_H
+#endif /*_TD_UTIL_TALGO_H*/
diff --git a/include/util/tarray.h b/include/util/tarray.h
index 2da74eac820e28206cb3e2b7cb6f2c4fb9f481b8..5807c980e0692449e2159973416762cff5e213c9 100644
--- a/include/util/tarray.h
+++ b/include/util/tarray.h
@@ -13,8 +13,8 @@
* along with this program. If not, see .
*/
-#ifndef TDENGINE_TAOSARRAY_H
-#define TDENGINE_TAOSARRAY_H
+#ifndef _TD_UTIL_ARRAY_H
+#define _TD_UTIL_ARRAY_H
#ifdef __cplusplus
extern "C" {
@@ -228,6 +228,4 @@ void taosArraySortPWithExt(SArray* pArray, __ext_compar_fn_t fn, const void *par
}
#endif
-
-
-#endif // TDENGINE_TAOSARRAY_H
+#endif /*_TD_UTIL_ARRAY_H*/
diff --git a/include/util/tbuffer.h b/include/util/tbuffer.h
index b19984b4be047108fd9848a2a7eddbac2c0b78a4..d1d403e996cb9add581255d0544dfa9ef6c450d9 100644
--- a/include/util/tbuffer.h
+++ b/include/util/tbuffer.h
@@ -13,11 +13,8 @@
* along with this program. If not, see .
*/
-#ifndef TDENGINE_TBUFFER_H
-#define TDENGINE_TBUFFER_H
-
-#include
-#include
+#ifndef _TD_UTIL_BUFFER_H
+#define _TD_UTIL_BUFFER_H
#ifdef __cplusplus
extern "C" {
@@ -175,4 +172,4 @@ void tbufWriteDoubleAt( SBufferWriter* buf, size_t pos, double data );
}
#endif
-#endif
+#endif /*_TD_UTIL_BUFFER_H*/
diff --git a/include/util/tcache.h b/include/util/tcache.h
index 40069d7d273caa14ce3b80467b25d68ea476fb75..f0bf78cd929bf4c3b8d437c79d6c79d413e6d581 100644
--- a/include/util/tcache.h
+++ b/include/util/tcache.h
@@ -13,8 +13,8 @@
* along with this program. If not, see .
*/
-#ifndef TDENGINE_TCACHE_H
-#define TDENGINE_TCACHE_H
+#ifndef _TD_UTIL_CACHE_H
+#define _TD_UTIL_CACHE_H
#ifdef __cplusplus
extern "C" {
@@ -188,4 +188,4 @@ void taosStopCacheRefreshWorker();
}
#endif
-#endif // TDENGINE_TCACHE_H
+#endif /*_TD_UTIL_CACHE_H*/
diff --git a/src/util/inc/tchecksum.h b/include/util/tchecksum.h
similarity index 100%
rename from src/util/inc/tchecksum.h
rename to include/util/tchecksum.h
diff --git a/include/util/tcoding.h b/include/util/tcoding.h
index 3ccf51c2dd774581693e0fc90fe7ffed217636d7..ccc3c26124da1fbf5a8b9e3c4627d7b69a6520d8 100644
--- a/include/util/tcoding.h
+++ b/include/util/tcoding.h
@@ -12,8 +12,8 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
-#ifndef _TD_CODING_H_
-#define _TD_CODING_H_
+#ifndef _TD_UTIL_CODING_H
+#define _TD_UTIL_CODING_H
#ifdef __cplusplus
extern "C" {
@@ -361,4 +361,4 @@ static FORCE_INLINE void *taosDecodeString(void *buf, char **value) {
}
#endif
-#endif
\ No newline at end of file
+#endif /*_TD_UTIL_CODING_H*/
\ No newline at end of file
diff --git a/src/util/inc/tcompare.h b/include/util/tcompare.h
similarity index 100%
rename from src/util/inc/tcompare.h
rename to include/util/tcompare.h
diff --git a/include/util/tconfig.h b/include/util/tconfig.h
index 2c632d4a17f5394dc28df72414948855b89bc001..68fa4128ae6a7ceccb877219d2d886bd42e346a7 100644
--- a/include/util/tconfig.h
+++ b/include/util/tconfig.h
@@ -13,8 +13,8 @@
* along with this program. If not, see .
*/
-#ifndef TDENGINE_CFG_H
-#define TDENGINE_CFG_H
+#ifndef _TD_UTIL_CONFIG_H
+#define _TD_UTIL_CONFIG_H
#ifdef __cplusplus
extern "C" {
@@ -89,10 +89,9 @@ void taosDumpGlobalCfg();
void taosInitConfigOption(SGlobalCfg cfg);
SGlobalCfg * taosGetConfigOption(const char *option);
-bool taosReadConfigOption(const char *option, char *value, char *value2, char *value3, int8_t cfgStatus, int8_t sourceType);
#ifdef __cplusplus
}
#endif
-#endif // TDENGINE_TGLOBALCFG_H
+#endif /*_TD_UTIL_CONFIG_H*/
diff --git a/include/util/tcrc32c.h b/include/util/tcrc32c.h
index 78e52e226fc212e43c65e4f0dd7a9d4cd4d12757..200103b173d44d73d0c640588e521ba9ae6f0ca0 100644
--- a/include/util/tcrc32c.h
+++ b/include/util/tcrc32c.h
@@ -18,10 +18,8 @@
3. This notice may not be removed or altered from any source distribution.
*/
-#ifndef TDENGINE_TCRC32C_H
-#define TDENGINE_TCRC32C_H
-
-#include
+#ifndef _TD_UTIL_CRC32_H
+#define _TD_UTIL_CRC32_H
#ifdef __cplusplus
extern "C" {
@@ -41,4 +39,4 @@ void taosResolveCRC();
}
#endif
-#endif // TDENGINE_TCRC32C_H
+#endif /*_TD_UTIL_CRC32_H*/
diff --git a/include/util/tdef.h b/include/util/tdef.h
new file mode 100644
index 0000000000000000000000000000000000000000..b09f39fc327c743bd388e5f04769849257f6a75b
--- /dev/null
+++ b/include/util/tdef.h
@@ -0,0 +1,451 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * 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 .
+ */
+
+#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
diff --git a/src/util/inc/tfile.h b/include/util/tfile.h
similarity index 100%
rename from src/util/inc/tfile.h
rename to include/util/tfile.h
diff --git a/src/util/inc/tfunctional.h b/include/util/tfunctional.h
similarity index 100%
rename from src/util/inc/tfunctional.h
rename to include/util/tfunctional.h
diff --git a/include/util/tlist.h b/include/util/tlist.h
index 758190454030a7287c3ca95418e7a8fea3618cc5..8246205e9b46fab0f6a363d61c19dfd59bdb8bc5 100644
--- a/include/util/tlist.h
+++ b/include/util/tlist.h
@@ -12,8 +12,8 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
-#ifndef _TD_LIST_
-#define _TD_LIST_
+#ifndef _TD_UTIL_LIST_H
+#define _TD_UTIL_LIST_H
#ifdef __cplusplus
extern "C" {
@@ -69,4 +69,4 @@ SListNode *tdListNext(SListIter *pIter);
}
#endif
-#endif
\ No newline at end of file
+#endif /*_TD_UTIL_LIST_H*/
\ No newline at end of file
diff --git a/include/util/tlockfree.h b/include/util/tlockfree.h
index e960b601caf6322938f4b0da3953e0b3ba454ce3..82c9607ff440d3746ffff760466fa1599807825a 100644
--- a/include/util/tlockfree.h
+++ b/include/util/tlockfree.h
@@ -12,8 +12,8 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
-#ifndef __TD_LOCK_FREE_H__
-#define __TD_LOCK_FREE_H__
+#ifndef _TD_UTIL_LOCK_FREE_H
+#define _TD_UTIL_LOCK_FREE_H
#include "os.h"
@@ -21,7 +21,6 @@
extern "C" {
#endif
-
// reference counting
typedef void (*_ref_fn_t)(const void* pObj);
@@ -106,9 +105,8 @@ void taosRUnLockLatch(SRWLatch *pLatch);
break; \
}
-
#ifdef __cplusplus
}
#endif
-#endif
+#endif /*_TD_UTIL_LOCK_FREE_H*/
diff --git a/include/util/tlog.h b/include/util/tlog.h
index 50bc45e7dd5b7d9aa5bba75d270718175d9e328f..a99085923e7e2316ab80aac9e08c4c02ef861aae 100644
--- a/include/util/tlog.h
+++ b/include/util/tlog.h
@@ -13,13 +13,38 @@
* along with this program. If not, see .
*/
-#ifndef TDENGINE_TLOG_H
-#define TDENGINE_TLOG_H
+#ifndef _TD_UTIL_LOG_H
+#define _TD_UTIL_LOG_H
#ifdef __cplusplus
extern "C" {
#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_ERROR DEBUG_FATAL
#define DEBUG_WARN 2U
@@ -53,4 +78,4 @@ void taosDumpData(unsigned char *msg, int32_t len);
}
#endif
-#endif
+#endif /*_TD_UTIL_LOG_H*/
diff --git a/src/util/inc/tlosertree.h b/include/util/tlosertree.h
similarity index 100%
rename from src/util/inc/tlosertree.h
rename to include/util/tlosertree.h
diff --git a/src/util/inc/tnettest.h b/include/util/tnettest.h
similarity index 100%
rename from src/util/inc/tnettest.h
rename to include/util/tnettest.h
diff --git a/src/util/inc/tqueue.h b/include/util/tqueue.h
similarity index 100%
rename from src/util/inc/tqueue.h
rename to include/util/tqueue.h
diff --git a/src/util/inc/tsched.h b/include/util/tsched.h
similarity index 100%
rename from src/util/inc/tsched.h
rename to include/util/tsched.h
diff --git a/include/util/tscompression.h b/include/util/tscompression.h
index 3f2160bbf26da0ff6eb839ddb4c303d221bce7c2..6f722533ac599d20450419f060160eb160d6d2a0 100644
--- a/include/util/tscompression.h
+++ b/include/util/tscompression.h
@@ -20,7 +20,7 @@
extern "C" {
#endif
-#include "taosdef.h"
+#include "tdef.h"
#include "tutil.h"
#define COMP_OVERFLOW_BYTES 2
diff --git a/src/util/inc/tskiplist.h b/include/util/tskiplist.h
similarity index 100%
rename from src/util/inc/tskiplist.h
rename to include/util/tskiplist.h
diff --git a/src/util/inc/tstrbuild.h b/include/util/tstrbuild.h
similarity index 100%
rename from src/util/inc/tstrbuild.h
rename to include/util/tstrbuild.h
diff --git a/src/util/inc/tthread.h b/include/util/tthread.h
similarity index 100%
rename from src/util/inc/tthread.h
rename to include/util/tthread.h
diff --git a/src/util/inc/ttoken.h b/include/util/ttoken.h
similarity index 100%
rename from src/util/inc/ttoken.h
rename to include/util/ttoken.h
diff --git a/source/util/inc/tulog.h b/include/util/tulog.h
similarity index 100%
rename from source/util/inc/tulog.h
rename to include/util/tulog.h
diff --git a/include/util/tutil.h b/include/util/tutil.h
index 16e5af1aded99ceef3fa6183574504249b0f8b3c..ba48fcdc049fb26314366b2cf2e2db6e2f2f2831 100644
--- a/include/util/tutil.h
+++ b/include/util/tutil.h
@@ -53,11 +53,6 @@ static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, size_t inLen, char *tar
memcpy(target, context.digest, keylen);
}
-#ifdef tListLen
-#undefine tListLen
-#endif
-#define tListLen(x) (sizeof(x) / sizeof((x)[0]))
-
#ifdef __cplusplus
}
#endif
diff --git a/src/util/inc/tworker.h b/include/util/tworker.h
similarity index 100%
rename from src/util/inc/tworker.h
rename to include/util/tworker.h
diff --git a/source/common/CMakeLists.txt b/source/common/CMakeLists.txt
index 1273a61c02c84e649d787c07674372b5f068129a..4a8dffb433eeb3532009cf996a5cd994f4f80506 100644
--- a/source/common/CMakeLists.txt
+++ b/source/common/CMakeLists.txt
@@ -4,4 +4,9 @@ target_include_directories(
common
PUBLIC "${CMAKE_SOURCE_DIR}/include/common"
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
+)
+target_link_libraries(
+ common
+ PUBLIC os
+ PUBLIC util
)
\ No newline at end of file
diff --git a/src/common/src/sqlcmdstr.c b/source/common/src/sqlcmdstr.c
similarity index 100%
rename from src/common/src/sqlcmdstr.c
rename to source/common/src/sqlcmdstr.c
diff --git a/src/common/src/tarithoperator.c b/source/common/src/tarithoperator.c
similarity index 100%
rename from src/common/src/tarithoperator.c
rename to source/common/src/tarithoperator.c
diff --git a/src/common/src/tdataformat.c b/source/common/src/tdataformat.c
similarity index 100%
rename from src/common/src/tdataformat.c
rename to source/common/src/tdataformat.c
diff --git a/src/util/src/terror.c b/source/common/src/terror.c
similarity index 100%
rename from src/util/src/terror.c
rename to source/common/src/terror.c
diff --git a/src/common/src/texpr.c b/source/common/src/texpr.c
similarity index 100%
rename from src/common/src/texpr.c
rename to source/common/src/texpr.c
diff --git a/src/common/src/tglobal.c b/source/common/src/tglobal.c
similarity index 97%
rename from src/common/src/tglobal.c
rename to source/common/src/tglobal.c
index 339fa35bb3009db96c9c6e0cabea6b60881f05c5..fbf8926fb47b3d50e2b9965487eab4a554253c04 100644
--- a/src/common/src/tglobal.c
+++ b/source/common/src/tglobal.c
@@ -18,14 +18,14 @@
#include "taosdef.h"
#include "taoserror.h"
#include "tulog.h"
+#include "tlog.h"
#include "tconfig.h"
#include "tglobal.h"
-#include "monitor.h"
#include "tsocket.h"
+#include "tcompare.h"
#include "tutil.h"
-#include "tlocale.h"
#include "ttimezone.h"
-#include "tcompare.h"
+#include "tlocale.h"
// cluster
char tsFirst[TSDB_EP_LEN] = {0};
@@ -59,9 +59,6 @@ float tsNumOfThreadsPerCore = 1.0f;
int32_t tsNumOfCommitThreads = 4;
float tsRatioOfQueryCores = 1.0f;
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;
int32_t tsMaxBinaryDisplayWidth = 30;
@@ -201,15 +198,11 @@ int8_t tsEnableStream = 1;
int8_t tsCompactMnodeWal = 0;
int8_t tsPrintAuth = 0;
int8_t tscEmbedded = 0;
-char configDir[PATH_MAX] = {0};
char tsVnodeDir[PATH_MAX] = {0};
char tsDnodeDir[PATH_MAX] = {0};
char tsMnodeDir[PATH_MAX] = {0};
char tsMnodeTmpDir[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 tsTopicBianryLen = 16000;
@@ -229,11 +222,6 @@ SDiskCfg tsDiskCfg[TSDB_MAX_DISKS];
int64_t tsTickPerDay[] = {86400000L, 86400000000L, 86400000000000L};
// system info
-char tsOsName[10] = "Linux";
-int64_t tsPageSize;
-int64_t tsOpenMax;
-int64_t tsStreamMax;
-int32_t tsNumOfCores = 1;
float tsTotalTmpDirGB = 0;
float tsTotalDataDirGB = 0;
float tsAvailTmpDirectorySpace = 0;
@@ -244,28 +232,6 @@ float tsMinimalDataDirGB = 2.0f;
int32_t tsTotalMemoryMB = 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
//
// lossy compress 6
@@ -420,6 +386,7 @@ static void taosCheckDataDirCfg() {
}
static int32_t taosCheckTmpDir(void) {
+#if 0
if (strlen(tsTempDir) <= 0){
uError("tempDir is not set");
return -1;
@@ -432,10 +399,11 @@ static int32_t taosCheckTmpDir(void) {
}
closedir(dir);
-
+#endif
return 0;
}
+
static void doInitGlobalConfig(void) {
osInit();
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.minValue = 0;
cfg.maxValue = 0;
- cfg.ptrLength = tListLen(tsTimezone);
+ cfg.ptrLength = TSDB_TIMEZONE_LEN;
cfg.unitType = TAOS_CFG_UTYPE_NONE;
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.minValue = 0;
cfg.maxValue = 0;
- cfg.ptrLength = tListLen(tsLocale);
+ cfg.ptrLength = TSDB_LOCALE_LEN;
cfg.unitType = TAOS_CFG_UTYPE_NONE;
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.minValue = 0;
cfg.maxValue = 0;
- cfg.ptrLength = tListLen(tsCharset);
+ cfg.ptrLength = TSDB_LOCALE_LEN;
cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg);
@@ -1612,7 +1580,7 @@ static void doInitGlobalConfig(void) {
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT;
cfg.minValue = 0;
cfg.maxValue = 0;
- cfg.ptrLength = tListLen(tsTempDir);
+ cfg.ptrLength = PATH_MAX;
cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg);
diff --git a/src/common/src/tlocale.c b/source/common/src/tlocale.c
similarity index 100%
rename from src/common/src/tlocale.c
rename to source/common/src/tlocale.c
diff --git a/src/common/src/tmessage.c b/source/common/src/tmessage.c
similarity index 100%
rename from src/common/src/tmessage.c
rename to source/common/src/tmessage.c
diff --git a/src/common/src/tname.c b/source/common/src/tname.c
similarity index 100%
rename from src/common/src/tname.c
rename to source/common/src/tname.c
diff --git a/src/os/src/detail/osTime.c b/source/common/src/ttime.c
similarity index 99%
rename from src/os/src/detail/osTime.c
rename to source/common/src/ttime.c
index 5b2a01edc3e04ae5b9bb8e9df9c222368aac5c1b..0f15dcc13bb4d6465fc61ef4a15b08d04ae08677 100644
--- a/src/os/src/detail/osTime.c
+++ b/source/common/src/ttime.c
@@ -25,6 +25,7 @@
#include "os.h"
#include "taosdef.h"
+#include "ttime.h"
#include "tutil.h"
/*
diff --git a/src/common/src/ttimezone.c b/source/common/src/ttimezone.c
similarity index 100%
rename from src/common/src/ttimezone.c
rename to source/common/src/ttimezone.c
diff --git a/src/common/src/ttypes.c b/source/common/src/ttypes.c
similarity index 100%
rename from src/common/src/ttypes.c
rename to source/common/src/ttypes.c
diff --git a/src/common/src/tvariant.c b/source/common/src/tvariant.c
similarity index 100%
rename from src/common/src/tvariant.c
rename to source/common/src/tvariant.c
diff --git a/source/libs/transport/src/rpcCache.c b/source/libs/transport/src/rpcCache.c
index 60a12c26b78626ed81cbc182d76c836c6ee74498..7de7aa341b90ed753b63d20b29979f7f72b53734 100644
--- a/source/libs/transport/src/rpcCache.c
+++ b/source/libs/transport/src/rpcCache.c
@@ -14,6 +14,7 @@
*/
#include "os.h"
+#include "taosdef.h"
#include "tglobal.h"
#include "tmempool.h"
#include "ttimer.h"
diff --git a/source/os/src/os.c b/source/os/src/os.c
deleted file mode 100644
index 6dea4a4e57392be988126c579648f39a8270b9bf..0000000000000000000000000000000000000000
--- a/source/os/src/os.c
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * 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 .
- */
\ No newline at end of file
diff --git a/src/os/src/windows/wAtomic.c b/source/os/src/osAtomic.c
similarity index 81%
rename from src/os/src/windows/wAtomic.c
rename to source/os/src/osAtomic.c
index b645893030b852428bff13744050b1f6f8ef1c42..6429cdc9d3d5dea6d1418994aadabcf2db3dfeb0 100644
--- a/src/os/src/windows/wAtomic.c
+++ b/source/os/src/osAtomic.c
@@ -13,13 +13,9 @@
* along with this program. If not, see .
*/
-#define _DEFAULT_SOURCE
#include "os.h"
-#include "taosdef.h"
-#include "tglobal.h"
-#include "ttimer.h"
-#include "tulog.h"
-#include "tutil.h"
+
+#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
// add
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
+
+#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
diff --git a/src/os/src/detail/osDir.c b/source/os/src/osDir.c
similarity index 52%
rename from src/os/src/detail/osDir.c
rename to source/os/src/osDir.c
index c467c64872d4b660af5cebb19b017f1528b55055..9bca1e6c2e88aaa4d11407f4dc7ce28481468c43 100644
--- a/src/os/src/detail/osDir.c
+++ b/source/os/src/osDir.c
@@ -13,16 +13,29 @@
* along with this program. If not, see .
*/
-#define _DEFAULT_SOURCE
#include "os.h"
-#include "tglobal.h"
-#include "tulog.h"
-#include "zlib.h"
+#include "osString.h"
-#define COMPRESS_STEP_SIZE 163840
+#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
+/*
+ * windows implementation
+ */
+
+// todo
+
+#else
+/*
+ * linux implementation
+ */
-void taosRemoveDir(char *rootDir) {
- DIR *dir = opendir(rootDir);
+#include
+#include
+#include
+#include
+#include
+
+void taosRemoveDir(char *dirname) {
+ DIR *dir = opendir(dirname);
if (dir == NULL) return;
struct dirent *de = NULL;
@@ -30,33 +43,34 @@ void taosRemoveDir(char *rootDir) {
if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue;
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) {
taosRemoveDir(filename);
} else {
(void)remove(filename);
- uInfo("file:%s is removed", filename);
+ printf("file:%s is removed", filename);
}
}
closedir(dir);
- rmdir(rootDir);
+ rmdir(dirname);
- uInfo("dir:%s is removed", rootDir);
+ printf("dir:%s is removed", dirname);
}
-bool taosDirExist(const char* dirname) {
- return access(dirname, F_OK) == 0;
-}
+bool taosDirExist(char *dirname) { return access(dirname, F_OK) == 0; }
-int taosMkDir(const char *path, mode_t mode) {
- int code = mkdir(path, 0755);
- if (code < 0 && errno == EEXIST) code = 0;
- return code;
+bool taosMkDir(char *dirname, mode_t mode) {
+ int32_t code = mkdir(dirname, 0755);
+ if (code < 0 && errno == EEXIST) {
+ return true;
+ }
+
+ return code == 0;
}
-void taosRemoveOldLogFiles(char *rootDir, int32_t keepDays) {
- DIR *dir = opendir(rootDir);
+void taosRemoveOldFiles(char *dirname, int32_t keepDays) {
+ DIR *dir = opendir(dirname);
if (dir == NULL) return;
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;
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) {
continue;
} else {
@@ -76,7 +90,7 @@ void taosRemoveOldLogFiles(char *rootDir, int32_t keepDays) {
}
int64_t fileSec = 0;
- for (int i = len - 1; i >= 0; i--) {
+ for (int32_t i = len - 1; i >= 0; i--) {
if (filename[i] == '.') {
fileSec = atoll(filename + i + 1);
break;
@@ -87,56 +101,41 @@ void taosRemoveOldLogFiles(char *rootDir, int32_t keepDays) {
int32_t days = (int32_t)(ABS(sec - fileSec) / 86400 + 1);
if (days > keepDays) {
(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 {
- 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);
- rmdir(rootDir);
+ rmdir(dirname);
}
-int32_t taosCompressFile(char *srcFileName, char *destFileName) {
- int32_t ret = 0;
- int32_t len = 0;
- char * data = malloc(COMPRESS_STEP_SIZE);
- FILE * srcFp = NULL;
- gzFile dstFp = NULL;
-
- srcFp = fopen(srcFileName, "r");
- if (srcFp == NULL) {
- ret = -1;
- goto cmp_end;
+bool taosExpandDir(char *dirname, char *outname, int32_t maxlen) {
+ wordexp_t full_path;
+ if (0 != wordexp(dirname, &full_path, 0)) {
+ printf("failed to expand path:%s since %s", dirname, strerror(errno));
+ wordfree(&full_path);
+ return false;
}
- int32_t fd = open(destFileName, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRWXU | S_IRWXG | S_IRWXO);
- if (fd < 0) {
- ret = -2;
- goto cmp_end;
+ if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) {
+ strncpy(outname, full_path.we_wordv[0], maxlen);
}
- dstFp = gzdopen(fd, "wb6f");
- if (dstFp == NULL) {
- ret = -3;
- close(fd);
- goto cmp_end;
- }
+ wordfree(&full_path);
- while (!feof(srcFp)) {
- len = (int32_t)fread(data, 1, COMPRESS_STEP_SIZE, srcFp);
- (void)gzwrite(dstFp, data, len);
- }
+ return true;
+}
-cmp_end:
- if (srcFp) {
- fclose(srcFp);
- }
- if (dstFp) {
- gzclose(dstFp);
+bool taosRealPath(char *dirname, int32_t maxlen) {
+ char tmp[PATH_MAX] = {0};
+ if (realpath(dirname, tmp) != NULL) {
+ strncpy(dirname, tmp, maxlen);
}
- free(data);
- return ret;
+ return true;
}
+
+#endif
\ No newline at end of file
diff --git a/source/os/src/osEnv.c b/source/os/src/osEnv.c
new file mode 100644
index 0000000000000000000000000000000000000000..7bc5e0a7fcfa759444d0d6d445a9b2eb1175f8e1
--- /dev/null
+++ b/source/os/src/osEnv.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * 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 .
+ */
+
+
+#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
diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c
index 5acbfd6fa729f70e296eb3adc28961e4a5131421..3726830635df727fedcdcf761e72c682a289922e 100644
--- a/source/os/src/osFile.c
+++ b/source/os/src/osFile.c
@@ -402,7 +402,6 @@ int32_t taosRenameFile(char *oldName, char *newName) {
#endif
}
-
int32_t taosLockFile(int32_t fd) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
return 0;
diff --git a/src/os/src/windows/wLz4.c b/source/os/src/osLz4.c
similarity index 94%
rename from src/os/src/windows/wLz4.c
rename to source/os/src/osLz4.c
index 631a22e5727695499febffd0ff212532f88413e1..29d219f37b879abe675508af5b26acec0abadddd 100644
--- a/src/os/src/windows/wLz4.c
+++ b/source/os/src/osLz4.c
@@ -15,11 +15,12 @@
#define _DEFAULT_SOURCE
#include "os.h"
-#include "taosdef.h"
-#include "tglobal.h"
-#include "ttimer.h"
-#include "tulog.h"
-#include "tutil.h"
+
+#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
+
+/*
+ * windows implementation
+ */
unsigned char _MyBitScanForward64(unsigned long *ret, uint64_t x) {
unsigned long x0 = (unsigned long)x, top, bottom;
@@ -67,4 +68,6 @@ int32_t BUILDIN_CTZ(uint32_t val) {
unsigned long r = 0;
_BitScanForward(&r, val);
return (int)(r >> 3);
-}
\ No newline at end of file
+}
+
+#endif
diff --git a/src/os/src/detail/osRand.c b/source/os/src/osRand.c
similarity index 92%
rename from src/os/src/detail/osRand.c
rename to source/os/src/osRand.c
index 0dda908bb35c68513dba150e8380846c36aa2893..247097f9ce33ac687f87ad5e9e51eb02f3bbc591 100644
--- a/src/os/src/detail/osRand.c
+++ b/source/os/src/osRand.c
@@ -15,6 +15,10 @@
#define _DEFAULT_SOURCE
#include "os.h"
+#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
+#else
+#include
+#endif
uint32_t taosRand(void) { return rand(); }
diff --git a/src/os/src/darwin/dwSemaphore.c b/source/os/src/osSemaphore.c
similarity index 67%
rename from src/os/src/darwin/dwSemaphore.c
rename to source/os/src/osSemaphore.c
index 25cb28cff1b6f9c83cab43faf68641717450c0ea..c9533c8b8a7f907a41997fdb53f829dc731dace8 100644
--- a/src/os/src/darwin/dwSemaphore.c
+++ b/source/os/src/osSemaphore.c
@@ -13,13 +13,66 @@
* along with this program. If not, see .
*/
-// 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
#include "os.h"
+
+#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
+
+/*
+ * windows implementation
+ */
+
+#include
+
+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
// #define SEM_USE_PTHREAD
@@ -27,19 +80,19 @@
#define SEM_USE_SEM
#ifdef SEM_USE_SEM
-#include
#include
+#include
#include
#include
#include
-static pthread_t sem_thread;
-static pthread_once_t sem_once;
-static task_t sem_port;
-static volatile int sem_inited = 0;
-static semaphore_t sem_exit;
+static pthread_t sem_thread;
+static pthread_once_t sem_once;
+static task_t sem_port;
+static volatile int sem_inited = 0;
+static semaphore_t sem_exit;
-static void* sem_thread_routine(void *arg) {
+static void *sem_thread_routine(void *arg) {
(void)arg;
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__);
return;
}
- while (sem_inited==0) {
+ while (sem_inited == 0) {
;
}
}
@@ -70,19 +123,19 @@ static void once_init(void) {
struct tsem_s {
#ifdef SEM_USE_PTHREAD
- pthread_mutex_t lock;
- pthread_cond_t cond;
- volatile int64_t val;
+ pthread_mutex_t lock;
+ pthread_cond_t cond;
+ volatile int64_t val;
#elif defined(SEM_USE_POSIX)
- size_t id;
- sem_t *sem;
+ size_t id;
+ sem_t * sem;
#elif defined(SEM_USE_SEM)
- semaphore_t sem;
-#else // SEM_USE_PTHREAD
- dispatch_semaphore_t sem;
-#endif // SEM_USE_PTHREAD
+ semaphore_t sem;
+#else // SEM_USE_PTHREAD
+ dispatch_semaphore_t sem;
+#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) {
@@ -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);
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) {
fprintf(stderr, "==%s[%d]%s():[%p]==out of memory\n", basename(__FILE__), __LINE__, __func__, sem);
abort();
@@ -116,24 +169,25 @@ int tsem_init(tsem_t *sem, int pshared, unsigned int value) {
static size_t tick = 0;
do {
size_t id = atomic_add_fetch_64(&tick, 1);
- if (id==SEM_VALUE_MAX) {
+ if (id == SEM_VALUE_MAX) {
atomic_store_64(&tick, 0);
id = 0;
}
- char name[NAME_MAX-4];
+ char name[NAME_MAX - 4];
snprintf(name, sizeof(name), "/t%ld", id);
- p->sem = sem_open(name, O_CREAT|O_EXCL, pshared, value);
- p->id = id;
- if (p->sem!=SEM_FAILED) break;
+ p->sem = sem_open(name, O_CREAT | O_EXCL, pshared, value);
+ p->id = id;
+ if (p->sem != SEM_FAILED) break;
int e = errno;
- if (e==EEXIST) continue;
- if (e==EINTR) continue;
- fprintf(stderr, "==%s[%d]%s():[%p]==not created[%d]%s\n", basename(__FILE__), __LINE__, __func__, sem, e, strerror(e));
+ if (e == EEXIST) continue;
+ if (e == EINTR) continue;
+ fprintf(stderr, "==%s[%d]%s():[%p]==not created[%d]%s\n", basename(__FILE__), __LINE__, __func__, sem, e,
+ strerror(e));
abort();
- } while (p->sem==SEM_FAILED);
+ } while (p->sem == SEM_FAILED);
#elif defined(SEM_USE_SEM)
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);
errno = ENOMEM;
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
abort();
}
-#else // SEM_USE_PTHREAD
+#else // SEM_USE_PTHREAD
p->sem = dispatch_semaphore_create(value);
if (p->sem == NULL) {
fprintf(stderr, "==%s[%d]%s():[%p]==not created\n", basename(__FILE__), __LINE__, __func__, sem);
abort();
}
-#endif // SEM_USE_PTHREAD
+#endif // SEM_USE_PTHREAD
p->valid = 1;
@@ -190,9 +244,9 @@ int tsem_wait(tsem_t *sem) {
return sem_wait(p->sem);
#elif defined(SEM_USE_SEM)
return semaphore_wait(p->sem);
-#else // SEM_USE_PTHREAD
+#else // SEM_USE_PTHREAD
return dispatch_semaphore_wait(p->sem, DISPATCH_TIME_FOREVER);
-#endif // SEM_USE_PTHREAD
+#endif // SEM_USE_PTHREAD
}
int tsem_post(tsem_t *sem) {
@@ -226,9 +280,9 @@ int tsem_post(tsem_t *sem) {
return sem_post(p->sem);
#elif defined(SEM_USE_SEM)
return semaphore_signal(p->sem);
-#else // SEM_USE_PTHREAD
+#else // SEM_USE_PTHREAD
return dispatch_semaphore_signal(p->sem);
-#endif // SEM_USE_PTHREAD
+#endif // SEM_USE_PTHREAD
}
int tsem_destroy(tsem_t *sem) {
@@ -263,18 +317,19 @@ int tsem_destroy(tsem_t *sem) {
abort();
}
#elif defined(SEM_USE_POSIX)
- char name[NAME_MAX-4];
+ char name[NAME_MAX - 4];
snprintf(name, sizeof(name), "/t%ld", p->id);
int r = sem_unlink(name);
if (r) {
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();
}
#elif defined(SEM_USE_SEM)
semaphore_destroy(sem_port, p->sem);
-#else // SEM_USE_PTHREAD
-#endif // SEM_USE_PTHREAD
+#else // SEM_USE_PTHREAD
+#endif // SEM_USE_PTHREAD
p->valid = 0;
free(p);
@@ -285,36 +340,28 @@ int tsem_destroy(tsem_t *sem) {
bool taosCheckPthreadValid(pthread_t thread) {
uint64_t id = 0;
- int r = pthread_threadid_np(thread, &id);
+ int r = pthread_threadid_np(thread, &id);
return r ? false : true;
}
int64_t taosGetSelfPthreadId() {
uint64_t id;
pthread_threadid_np(0, &id);
- return (int64_t) id;
+ return (int64_t)id;
}
-int64_t taosGetPthreadId(pthread_t thread) {
- return (int64_t)thread;
-}
+int64_t taosGetPthreadId(pthread_t thread) { return (int64_t)thread; }
-void taosResetPthread(pthread_t* thread) {
- *thread = NULL;
-}
+void taosResetPthread(pthread_t *thread) { *thread = NULL; }
-bool taosComparePthread(pthread_t first, pthread_t second) {
- return pthread_equal(first, second) ? true : false;
-}
+bool taosComparePthread(pthread_t first, pthread_t second) { return pthread_equal(first, second) ? true : false; }
-int32_t taosGetPId() {
- return (int32_t)getpid();
-}
+int32_t taosGetPId() { return (int32_t)getpid(); }
-int32_t taosGetCurrentAPPName(char* name, int32_t* len) {
- char buf[PATH_MAX+1];
+int32_t taosGetCurrentAPPName(char *name, int32_t *len) {
+ char buf[PATH_MAX + 1];
buf[0] = '\0';
- proc_name(getpid(), buf, sizeof(buf)-1);
+ proc_name(getpid(), buf, sizeof(buf) - 1);
buf[PATH_MAX] = '\0';
size_t n = strlen(buf);
if (len) *len = n;
@@ -322,4 +369,59 @@ int32_t taosGetCurrentAPPName(char* name, int32_t* len) {
return 0;
}
+#else
+
+/*
+ * linux implementation
+ */
+
+#include
+
+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
diff --git a/src/os/src/windows/wSignal.c b/source/os/src/osSignal.c
similarity index 64%
rename from src/os/src/windows/wSignal.c
rename to source/os/src/osSignal.c
index 9de6b5f3434dc792c40b330ec37c7edd180b999e..12721a17f55a3f716c4a65f41121280d6c56cbe3 100644
--- a/src/os/src/windows/wSignal.c
+++ b/source/os/src/osSignal.c
@@ -15,7 +15,13 @@
#define _DEFAULT_SOURCE
#include "os.h"
-#include
+
+#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
+
+/*
+ * windows implementation
+ */
+
#include
typedef void (*FWinSignalHandler)(int32_t signum);
@@ -27,7 +33,7 @@ void taosSetSignal(int32_t signum, FSignalHandler sigfp) {
if (signum == SIGHUP) {
SetConsoleCtrlHandler((PHANDLER_ROUTINE)sigfp, TRUE);
} else {
- signal(signum, (FWinSignalHandler)sigfp);
+ signal(signum, (FWinSignalHandler)sigfp);
}
}
@@ -40,3 +46,29 @@ void taosDflSignal(int32_t signum) {
if (signum == SIGUSR1 || signum == SIGHUP) return;
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
diff --git a/src/os/src/detail/osSleep.c b/source/os/src/osSleep.c
similarity index 100%
rename from src/os/src/detail/osSleep.c
rename to source/os/src/osSleep.c
diff --git a/source/os/src/osSocket.c b/source/os/src/osSocket.c
index 7964482db66e250035b81ed5db34fd0ec06d442a..d2f3c120db80c778a74b53eed4d9d7c9e5027707 100644
--- a/source/os/src/osSocket.c
+++ b/source/os/src/osSocket.c
@@ -16,6 +16,19 @@
#define _DEFAULT_SOURCE
#include "os.h"
+#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
+#else
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#endif
+
void taosShutDownSocketRD(SOCKET fd) {
#ifdef WINDOWS
closesocket(fd);
@@ -41,7 +54,7 @@ void taosShutDownSocketWR(SOCKET fd) {
int32_t taosSetNonblocking(SOCKET sock, int32_t on) {
int32_t flags = 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;
}
@@ -51,16 +64,14 @@ int32_t taosSetNonblocking(SOCKET sock, int32_t on) {
flags &= ~O_NONBLOCK;
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 0;
}
-void taosIgnSIGPIPE() {
- signal(SIGPIPE, SIG_IGN);
-}
+void taosIgnSIGPIPE() { signal(SIGPIPE, SIG_IGN); }
void taosBlockSIGPIPE() {
sigset_t signal_mask;
@@ -68,7 +79,7 @@ void taosBlockSIGPIPE() {
sigaddset(&signal_mask, SIGPIPE);
int32_t rc = pthread_sigmask(SIG_BLOCK, &signal_mask, NULL);
if (rc != 0) {
- uError("failed to block SIGPIPE");
+ printf("failed to block SIGPIPE");
}
}
@@ -78,7 +89,7 @@ void taosSetMaskSIGPIPE() {
sigaddset(&signal_mask, SIGPIPE);
int32_t rc = pthread_sigmask(SIG_SETMASK, &signal_mask, NULL);
if (rc != 0) {
- uError("failed to setmask SIGPIPE");
+ printf("failed to setmask SIGPIPE");
}
}
@@ -90,23 +101,113 @@ int32_t taosSetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *op
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);
-}
+}
#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);
+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
-const char *taosInetNtoa(struct in_addr ipInt) {
- return inet_ntoa(ipInt);
+#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
+
+/*
+ * windows implementation
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+void taosWinSocketInit() {
+ static char flag = 0;
+ if (flag == 0) {
+ WORD wVersionRequested;
+ WSADATA wsaData;
+ wVersionRequested = MAKEWORD(1, 1);
+ if (WSAStartup(wVersionRequested, &wsaData) == 0) {
+ flag = 1;
+ }
+ }
}
-#else
+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 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) {
// not thread safe, only for debug usage while print log
@@ -114,11 +215,13 @@ const char *taosInetNtoa(struct in_addr ipInt) {
return inet_ntop(AF_INET, &ipInt, tmpDstStr, INET6_ADDRSTRLEN);
}
+//#endif
#endif
-
#if defined(_TD_GO_DLL_)
uint64_t htonll(uint64_t val) { return (((uint64_t)htonl(val)) << 32) + htonl(val >> 32); }
+#endif
+
#endif
\ No newline at end of file
diff --git a/source/os/src/osString.c b/source/os/src/osString.c
new file mode 100644
index 0000000000000000000000000000000000000000..10606a3d7bc3823e2d504fe38409ad1b861fe6c2
--- /dev/null
+++ b/source/os/src/osString.c
@@ -0,0 +1,382 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * 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 .
+ */
+
+#define _DEFAULT_SOURCE
+#include "os.h"
+#include
+#include
+
+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
+#endif
+
+#include
+#include
+#include
+#include
+#include
+
+#if STDC_HEADERS
+#include
+#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
\ No newline at end of file
diff --git a/src/os/src/windows/wStrptime.c b/source/os/src/osStrptime.c
similarity index 99%
rename from src/os/src/windows/wStrptime.c
rename to source/os/src/osStrptime.c
index 24018182740edee5debdccfb6e36864266fc5061..e8c873bc492ee33f1833ca38bcd7111bd6838d1b 100644
--- a/src/os/src/windows/wStrptime.c
+++ b/source/os/src/osStrptime.c
@@ -37,6 +37,9 @@
*/
//
//#include "lukemftp.h"
+
+#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
+
#include
#include
#include
@@ -395,4 +398,6 @@ conv_num(const char **buf, int *dest, int llim, int ulim)
*dest = result;
return (1);
-}
\ No newline at end of file
+}
+
+#endif
\ No newline at end of file
diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c
new file mode 100644
index 0000000000000000000000000000000000000000..54af2ab4ade1fd7852d07aa12d08096a12533dd3
--- /dev/null
+++ b/source/os/src/osSysinfo.c
@@ -0,0 +1,1130 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * 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 .
+ */
+
+#define _DEFAULT_SOURCE
+#include "os.h"
+
+int32_t tsTotalMemoryMB = 0;
+int64_t tsPageSize = 0;
+int64_t tsOpenMax = 0;
+int64_t tsStreamMax = 0;
+int32_t tsNumOfCores = 1;
+char tsTimezone[TSDB_TIMEZONE_LEN] = {0};
+char tsLocale[TSDB_LOCALE_LEN] = {0};
+char tsCharset[TSDB_LOCALE_LEN] = {0}; // default encode string
+
+#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
+
+/*
+ * windows implementation
+ */
+
+#if (_WIN64)
+#include
+#include
+#include
+#include
+#include
+#include
+#pragma comment(lib, "Mswsock.lib ")
+#endif
+
+#include
+
+#pragma warning(push)
+#pragma warning(disable : 4091)
+#include
+#pragma warning(pop)
+
+static int32_t taosGetTotalMemory() {
+ MEMORYSTATUSEX memsStat;
+ memsStat.dwLength = sizeof(memsStat);
+ if (!GlobalMemoryStatusEx(&memsStat)) {
+ return 0;
+ }
+
+ float nMemTotal = memsStat.ullTotalPhys / (1024.0f * 1024.0f);
+ return (int32_t)nMemTotal;
+}
+
+bool taosGetSysMemory(float *memoryUsedMB) {
+ MEMORYSTATUSEX memsStat;
+ memsStat.dwLength = sizeof(memsStat);
+ if (!GlobalMemoryStatusEx(&memsStat)) {
+ return false;
+ }
+
+ float nMemFree = memsStat.ullAvailPhys / (1024.0f * 1024.0f);
+ float nMemTotal = memsStat.ullTotalPhys / (1024.0f * 1024.0f);
+
+ *memoryUsedMB = nMemTotal - nMemFree;
+ return true;
+}
+
+bool taosGetProcMemory(float *memoryUsedMB) {
+ unsigned bytes_used = 0;
+
+#if defined(_WIN64) && defined(_MSC_VER)
+ PROCESS_MEMORY_COUNTERS pmc;
+ HANDLE cur_proc = GetCurrentProcess();
+
+ if (GetProcessMemoryInfo(cur_proc, &pmc, sizeof(pmc))) {
+ bytes_used = (unsigned)(pmc.WorkingSetSize + pmc.PagefileUsage);
+ }
+#endif
+
+ *memoryUsedMB = (float)bytes_used / 1024 / 1024;
+ return true;
+}
+
+static void taosGetSystemTimezone() {
+ // get and set default timezone
+ char *tz = getenv("TZ");
+ if (tz == NULL || strlen(tz) == 0) {
+ strcpy(tsTimezone, "not configured");
+ } else {
+ strcpy(tsTimezone, tz);
+ }
+}
+
+static void taosGetSystemLocale() {
+ // get and set default locale
+ char *locale = setlocale(LC_CTYPE, "chs");
+ if (locale != NULL) {
+ tstrncpy(tsLocale, locale, TSDB_LOCALE_LEN);
+ }
+
+ strcpy(tsCharset, "cp936");
+}
+
+int32_t taosGetCpuCores() {
+ SYSTEM_INFO info;
+ GetSystemInfo(&info);
+ return (int32_t)info.dwNumberOfProcessors;
+}
+
+bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) {
+ *sysCpuUsage = 0;
+ *procCpuUsage = 0;
+ return true;
+}
+
+int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize) {
+ unsigned _int64 i64FreeBytesToCaller;
+ unsigned _int64 i64TotalBytes;
+ unsigned _int64 i64FreeBytes;
+
+ BOOL fResult = GetDiskFreeSpaceExA(dataDir, (PULARGE_INTEGER)&i64FreeBytesToCaller, (PULARGE_INTEGER)&i64TotalBytes,
+ (PULARGE_INTEGER)&i64FreeBytes);
+ if (fResult) {
+ diskSize->tsize = (int64_t)(i64TotalBytes);
+ diskSize->avail = (int64_t)(i64FreeBytesToCaller);
+ diskSize->used = (int64_t)(i64TotalBytes - i64FreeBytes);
+ return 0;
+ } else {
+ printf("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno));
+ terrno = TAOS_SYSTEM_ERROR(errno);
+ return -1;
+ }
+}
+
+bool taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes) {
+ if (bytes) *bytes = 0;
+ if (rbytes) *rbytes = 0;
+ if (tbytes) *tbytes = 0;
+ return true;
+}
+
+bool taosGetBandSpeed(float *bandSpeedKb) {
+ *bandSpeedKb = 0;
+ return true;
+}
+
+bool taosReadProcIO(int64_t *readbyte, int64_t *writebyte) {
+ IO_COUNTERS io_counter;
+ if (GetProcessIoCounters(GetCurrentProcess(), &io_counter)) {
+ if (readbyte) *readbyte = io_counter.ReadTransferCount;
+ if (writebyte) *writebyte = io_counter.WriteTransferCount;
+ return true;
+ }
+ return false;
+}
+
+bool taosGetProcIO(float *readKB, float *writeKB) {
+ static int64_t lastReadbyte = -1;
+ static int64_t lastWritebyte = -1;
+
+ int64_t curReadbyte = 0;
+ int64_t curWritebyte = 0;
+
+ if (!taosReadProcIO(&curReadbyte, &curWritebyte)) {
+ return false;
+ }
+
+ if (lastReadbyte == -1 || lastWritebyte == -1) {
+ lastReadbyte = curReadbyte;
+ lastWritebyte = curWritebyte;
+ return false;
+ }
+
+ *readKB = (float)((double)(curReadbyte - lastReadbyte) / 1024);
+ *writeKB = (float)((double)(curWritebyte - lastWritebyte) / 1024);
+ if (*readKB < 0) *readKB = 0;
+ if (*writeKB < 0) *writeKB = 0;
+
+ lastReadbyte = curReadbyte;
+ lastWritebyte = curWritebyte;
+
+ return true;
+}
+
+void taosGetSystemInfo() {
+ tsNumOfCores = taosGetCpuCores();
+ tsTotalMemoryMB = taosGetTotalMemory();
+
+ float tmp1, tmp2;
+ // taosGetDisk();
+ taosGetBandSpeed(&tmp1);
+ taosGetCpuUsage(&tmp1, &tmp2);
+ taosGetProcIO(&tmp1, &tmp2);
+
+ taosGetSystemTimezone();
+ taosGetSystemLocale();
+}
+
+void taosKillSystem() {
+ printf("function taosKillSystem, exit!");
+ exit(0);
+}
+
+int taosSystem(const char *cmd) {
+ printf("taosSystem not support");
+ return -1;
+}
+
+LONG WINAPI FlCrashDump(PEXCEPTION_POINTERS ep) {
+ typedef BOOL(WINAPI * FxMiniDumpWriteDump)(IN HANDLE hProcess, IN DWORD ProcessId, IN HANDLE hFile,
+ IN MINIDUMP_TYPE DumpType,
+ IN CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
+ IN CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
+ IN CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
+
+ HMODULE dll = LoadLibrary("dbghelp.dll");
+ if (dll == NULL) return EXCEPTION_CONTINUE_SEARCH;
+ FxMiniDumpWriteDump mdwd = (FxMiniDumpWriteDump)(GetProcAddress(dll, "MiniDumpWriteDump"));
+ if (mdwd == NULL) {
+ FreeLibrary(dll);
+ return EXCEPTION_CONTINUE_SEARCH;
+ }
+
+ TCHAR path[MAX_PATH];
+ DWORD len = GetModuleFileName(NULL, path, _countof(path));
+ path[len - 3] = 'd';
+ path[len - 2] = 'm';
+ path[len - 1] = 'p';
+
+ HANDLE file = CreateFile(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+
+ MINIDUMP_EXCEPTION_INFORMATION mei;
+ mei.ThreadId = GetCurrentThreadId();
+ mei.ExceptionPointers = ep;
+ mei.ClientPointers = FALSE;
+
+ (*mdwd)(GetCurrentProcess(), GetCurrentProcessId(), file, MiniDumpWithHandleData, &mei, NULL, NULL);
+
+ CloseHandle(file);
+ FreeLibrary(dll);
+
+ return EXCEPTION_CONTINUE_SEARCH;
+}
+
+void taosSetCoreDump() { SetUnhandledExceptionFilter(&FlCrashDump); }
+
+bool taosGetSystemUid(char *uid) {
+ GUID guid;
+ CoCreateGuid(&guid);
+
+ sprintf(uid, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", guid.Data1, guid.Data2, guid.Data3, guid.Data4[0],
+ guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
+
+ return true;
+}
+
+char *taosGetCmdlineByPID(int pid) { return ""; }
+
+#elif defined(_TD_DARWIN_64)
+
+/*
+ * darwin implementation
+ */
+
+#include
+#include
+
+static void taosGetSystemTimezone() {
+ /* load time zone string from /etc/localtime */
+ char buf[4096];
+ char *tz = NULL;
+ {
+ int n = readlink("/etc/localtime", buf, sizeof(buf));
+ if (n < 0) {
+ printf("read /etc/localtime error, reason:%s", strerror(errno));
+ return;
+ }
+ buf[n] = '\0';
+ for (int i = n - 1; i >= 0; --i) {
+ if (buf[i] == '/') {
+ if (tz) {
+ tz = buf + i + 1;
+ break;
+ }
+ tz = buf + i + 1;
+ }
+ }
+ if (!tz || 0 == strchr(tz, '/')) {
+ printf("parsing /etc/localtime failed");
+ return;
+ }
+
+ setenv("TZ", tz, 1);
+ tzset();
+ }
+
+ /*
+ * NOTE: do not remove it.
+ * Enforce set the correct daylight saving time(DST) flag according
+ * to current time
+ */
+ time_t tx1 = time(NULL);
+ struct tm tm1;
+ localtime_r(&tx1, &tm1);
+
+ /*
+ * format example:
+ *
+ * Asia/Shanghai (CST, +0800)
+ * Europe/London (BST, +0100)
+ */
+ snprintf(tsTimezone, TSDB_TIMEZONE_LEN, "%s (%s, %+03ld00)", tz, tm1.tm_isdst ? tzname[daylight] : tzname[0],
+ -timezone / 3600);
+
+ // cfg_timezone->cfgStatus = TAOS_CFG_CSTATUS_DEFAULT;
+ printf("timezone not configured, set to system default:%s", tsTimezone);
+}
+
+/*
+ * originally from src/os/src/detail/osSysinfo.c
+ * POSIX format locale string:
+ * (Language Strings)_(Country/Region Strings).(code_page)
+ *
+ * example: en_US.UTF-8, zh_CN.GB18030, zh_CN.UTF-8,
+ *
+ * if user does not specify the locale in taos.cfg the program use default LC_CTYPE as system locale.
+ *
+ * In case of some CentOS systems, their default locale is "en_US.utf8", which is not valid code_page
+ * for libiconv that is employed to convert string in this system. This program will automatically use
+ * UTF-8 instead as the charset.
+ *
+ * In case of windows client, the locale string is not valid POSIX format, user needs to set the
+ * correct code_page for libiconv. Usually, the code_page of windows system with simple chinese is
+ * CP936, CP437 for English charset.
+ *
+ */
+static void taosGetSystemLocale() { // get and set default locale
+ char sep = '.';
+ char *locale = NULL;
+
+ locale = setlocale(LC_CTYPE, "");
+ if (locale == NULL) {
+ printf("can't get locale from system, set it to en_US.UTF-8 since error:%d:%s", errno, strerror(errno));
+ strcpy(tsLocale, "en_US.UTF-8");
+ } else {
+ tstrncpy(tsLocale, locale, TSDB_LOCALE_LEN);
+ printf("locale not configured, set to system default:%s", tsLocale);
+ }
+
+ /* if user does not specify the charset, extract it from locale */
+ char *str = strrchr(tsLocale, sep);
+ if (str != NULL) {
+ str++;
+
+ char *revisedCharset = taosCharsetReplace(str);
+ tstrncpy(tsCharset, revisedCharset, TSDB_LOCALE_LEN);
+
+ free(revisedCharset);
+ printf("charset not configured, set to system default:%s", tsCharset);
+ } else {
+ strcpy(tsCharset, "UTF-8");
+ printf("can't get locale and charset from system, set it to UTF-8");
+ }
+}
+
+void taosKillSystem() {
+ printf("function taosKillSystem, exit!");
+ exit(0);
+}
+
+int32_t taosGetCpuCores() { return sysconf(_SC_NPROCESSORS_ONLN); }
+
+void taosGetSystemInfo() {
+ // taosGetProcInfos();
+
+ tsNumOfCores = sysconf(_SC_NPROCESSORS_ONLN);
+ long physical_pages = sysconf(_SC_PHYS_PAGES);
+ long page_size = sysconf(_SC_PAGESIZE);
+ tsTotalMemoryMB = physical_pages * page_size / (1024 * 1024);
+ tsPageSize = page_size;
+
+ taosGetSystemTimezone();
+ taosGetSystemLocale();
+}
+
+bool taosReadProcIO(int64_t *rchars, int64_t *wchars) {
+ if (rchars) *rchars = 0;
+ if (wchars) *wchars = 0;
+ return true;
+}
+
+bool taosGetProcIO(float *readKB, float *writeKB) {
+ *readKB = 0;
+ *writeKB = 0;
+ return true;
+}
+
+bool taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes) {
+ if (bytes) *bytes = 0;
+ if (rbytes) *rbytes = 0;
+ if (tbytes) *tbytes = 0;
+ return true;
+}
+
+bool taosGetBandSpeed(float *bandSpeedKb) {
+ *bandSpeedKb = 0;
+ return true;
+}
+
+bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) {
+ *sysCpuUsage = 0;
+ *procCpuUsage = 0;
+ return true;
+}
+
+bool taosGetProcMemory(float *memoryUsedMB) {
+ *memoryUsedMB = 0;
+ return true;
+}
+
+bool taosGetSysMemory(float *memoryUsedMB) {
+ *memoryUsedMB = 0;
+ return true;
+}
+
+int taosSystem(const char *cmd) {
+ printf("un support funtion");
+ return -1;
+}
+
+void taosSetCoreDump() {}
+
+int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize) {
+ struct statvfs info;
+ if (statvfs(dataDir, &info)) {
+ printf("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno));
+ terrno = TAOS_SYSTEM_ERROR(errno);
+ return -1;
+ } else {
+ diskSize->tsize = info.f_blocks * info.f_frsize;
+ diskSize->avail = info.f_bavail * info.f_frsize;
+ diskSize->used = (info.f_blocks - info.f_bfree) * info.f_frsize;
+ return 0;
+ }
+}
+
+bool taosGetSystemUid(char *uid) {
+ uuid_t uuid = {0};
+ uuid_generate(uuid);
+ // it's caller's responsibility to make enough space for `uid`, that's 36-char + 1-null
+ uuid_unparse_lower(uuid, uid);
+ return true;
+}
+
+char *taosGetCmdlineByPID(int pid) {
+ static char cmdline[1024];
+ errno = 0;
+
+ if (proc_pidpath(pid, cmdline, sizeof(cmdline)) <= 0) {
+ fprintf(stderr, "PID is %d, %s", pid, strerror(errno));
+ return strerror(errno);
+ }
+
+ return cmdline;
+}
+
+#else
+
+/*
+ * linux implementation
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#define PROCESS_ITEM 12
+
+typedef struct {
+ uint64_t user;
+ uint64_t nice;
+ uint64_t system;
+ uint64_t idle;
+} SysCpuInfo;
+
+typedef struct {
+ uint64_t utime; // user time
+ uint64_t stime; // kernel time
+ uint64_t cutime; // all user time
+ uint64_t cstime; // all dead time
+} ProcCpuInfo;
+
+static pid_t tsProcId;
+static char tsSysNetFile[] = "/proc/net/dev";
+static char tsSysCpuFile[] = "/proc/stat";
+static char tsProcCpuFile[25] = {0};
+static char tsProcMemFile[25] = {0};
+static char tsProcIOFile[25] = {0};
+static float tsPageSizeKB = 0;
+
+static void taosGetProcInfos() {
+ tsPageSize = sysconf(_SC_PAGESIZE);
+ tsOpenMax = sysconf(_SC_OPEN_MAX);
+ tsStreamMax = sysconf(_SC_STREAM_MAX);
+
+ tsProcId = (pid_t)syscall(SYS_gettid);
+ tsPageSizeKB = (float)(sysconf(_SC_PAGESIZE)) / 1024;
+
+ snprintf(tsProcMemFile, 25, "/proc/%d/status", tsProcId);
+ snprintf(tsProcCpuFile, 25, "/proc/%d/stat", tsProcId);
+ snprintf(tsProcIOFile, 25, "/proc/%d/io", tsProcId);
+}
+
+static int32_t taosGetTotalMemory() { return (int32_t)((float)sysconf(_SC_PHYS_PAGES) * tsPageSizeKB / 1024); }
+
+bool taosGetSysMemory(float *memoryUsedMB) {
+ float memoryAvailMB = (float)sysconf(_SC_AVPHYS_PAGES) * tsPageSizeKB / 1024;
+ *memoryUsedMB = (float)tsTotalMemoryMB - memoryAvailMB;
+ return true;
+}
+
+bool taosGetProcMemory(float *memoryUsedMB) {
+ FILE *fp = fopen(tsProcMemFile, "r");
+ if (fp == NULL) {
+ printf("open file:%s failed", tsProcMemFile);
+ return false;
+ }
+
+ ssize_t _bytes = 0;
+ size_t len;
+ char * line = NULL;
+ while (!feof(fp)) {
+ tfree(line);
+ len = 0;
+ _bytes = getline(&line, &len, fp);
+ if ((_bytes < 0) || (line == NULL)) {
+ break;
+ }
+ if (strstr(line, "VmRSS:") != NULL) {
+ break;
+ }
+ }
+
+ if (line == NULL) {
+ printf("read file:%s failed", tsProcMemFile);
+ fclose(fp);
+ return false;
+ }
+
+ int64_t memKB = 0;
+ char tmp[10];
+ sscanf(line, "%s %" PRId64, tmp, &memKB);
+ *memoryUsedMB = (float)((double)memKB / 1024);
+
+ tfree(line);
+ fclose(fp);
+ return true;
+}
+
+static bool taosGetSysCpuInfo(SysCpuInfo *cpuInfo) {
+ FILE *fp = fopen(tsSysCpuFile, "r");
+ if (fp == NULL) {
+ printf("open file:%s failed", tsSysCpuFile);
+ return false;
+ }
+
+ size_t len;
+ char * line = NULL;
+ ssize_t _bytes = getline(&line, &len, fp);
+ if ((_bytes < 0) || (line == NULL)) {
+ printf("read file:%s failed", tsSysCpuFile);
+ fclose(fp);
+ return false;
+ }
+
+ char cpu[10] = {0};
+ sscanf(line, "%s %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64, cpu, &cpuInfo->user, &cpuInfo->nice, &cpuInfo->system,
+ &cpuInfo->idle);
+
+ tfree(line);
+ fclose(fp);
+ return true;
+}
+
+static bool taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
+ FILE *fp = fopen(tsProcCpuFile, "r");
+ if (fp == NULL) {
+ printf("open file:%s failed", tsProcCpuFile);
+ return false;
+ }
+
+ size_t len = 0;
+ char * line = NULL;
+ ssize_t _bytes = getline(&line, &len, fp);
+ if ((_bytes < 0) || (line == NULL)) {
+ printf("read file:%s failed", tsProcCpuFile);
+ fclose(fp);
+ return false;
+ }
+
+ for (int i = 0, blank = 0; line[i] != 0; ++i) {
+ if (line[i] == ' ') blank++;
+ if (blank == PROCESS_ITEM) {
+ sscanf(line + i + 1, "%" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64, &cpuInfo->utime, &cpuInfo->stime,
+ &cpuInfo->cutime, &cpuInfo->cstime);
+ break;
+ }
+ }
+
+ tfree(line);
+ fclose(fp);
+ return true;
+}
+
+static void taosGetSystemTimezone() {
+ /*
+ * NOTE: do not remove it.
+ * Enforce set the correct daylight saving time(DST) flag according
+ * to current time
+ */
+ time_t tx1 = time(NULL);
+ struct tm tm1;
+ localtime_r(&tx1, &tm1);
+
+ /* load time zone string from /etc/timezone */
+ FILE *f = fopen("/etc/timezone", "r");
+ char buf[68] = {0};
+ if (f != NULL) {
+ int len = fread(buf, 64, 1, f);
+ if (len < 64 && ferror(f)) {
+ fclose(f);
+ printf("read /etc/timezone error, reason:%s", strerror(errno));
+ return;
+ }
+
+ fclose(f);
+
+ buf[sizeof(buf) - 1] = 0;
+ char *lineEnd = strstr(buf, "\n");
+ if (lineEnd != NULL) {
+ *lineEnd = 0;
+ }
+
+ // for CentOS system, /etc/timezone does not exist. Ignore the TZ environment variables
+ if (strlen(buf) > 0) {
+ setenv("TZ", buf, 1);
+ }
+ }
+ // get and set default timezone
+ tzset();
+
+ /*
+ * get CURRENT time zone.
+ * system current time zone is affected by daylight saving time(DST)
+ *
+ * e.g., the local time zone of London in DST is GMT+01:00,
+ * otherwise is GMT+00:00
+ */
+ int32_t tz = (-timezone * MILLISECOND_PER_SECOND) / MILLISECOND_PER_HOUR;
+ tz += daylight;
+
+ /*
+ * format example:
+ *
+ * Asia/Shanghai (CST, +0800)
+ * Europe/London (BST, +0100)
+ */
+ snprintf(tsTimezone, TSDB_TIMEZONE_LEN, "%s (%s, %s%02d00)", buf, tzname[daylight], tz >= 0 ? "+" : "-", abs(tz));
+
+ // cfg_timezone->cfgStatus = TAOS_CFG_CSTATUS_DEFAULT;
+ printf("timezone not configured, set to system default:%s", tsTimezone);
+}
+
+/*
+ * POSIX format locale string:
+ * (Language Strings)_(Country/Region Strings).(code_page)
+ *
+ * example: en_US.UTF-8, zh_CN.GB18030, zh_CN.UTF-8,
+ *
+ * if user does not specify the locale in taos.cfg the program use default LC_CTYPE as system locale.
+ *
+ * In case of some CentOS systems, their default locale is "en_US.utf8", which is not valid code_page
+ * for libiconv that is employed to convert string in this system. This program will automatically use
+ * UTF-8 instead as the charset.
+ *
+ * In case of windows client, the locale string is not valid POSIX format, user needs to set the
+ * correct code_page for libiconv. Usually, the code_page of windows system with simple chinese is
+ * CP936, CP437 for English charset.
+ *
+ */
+static void taosGetSystemLocale() { // get and set default locale
+ char sep = '.';
+ char *locale = NULL;
+
+ locale = setlocale(LC_CTYPE, "");
+ if (locale == NULL) {
+ printf("can't get locale from system, set it to en_US.UTF-8 since error:%d:%s", errno, strerror(errno));
+ strcpy(tsLocale, "en_US.UTF-8");
+ } else {
+ tstrncpy(tsLocale, locale, TSDB_LOCALE_LEN);
+ printf("locale not configured, set to system default:%s", tsLocale);
+ }
+
+ /* if user does not specify the charset, extract it from locale */
+ char *str = strrchr(tsLocale, sep);
+ if (str != NULL) {
+ str++;
+
+ char *revisedCharset = taosCharsetReplace(str);
+ tstrncpy(tsCharset, revisedCharset, TSDB_LOCALE_LEN);
+
+ free(revisedCharset);
+ printf("charset not configured, set to system default:%s", tsCharset);
+ } else {
+ strcpy(tsCharset, "UTF-8");
+ printf("can't get locale and charset from system, set it to UTF-8");
+ }
+}
+
+int32_t taosGetCpuCores() { return (int32_t)sysconf(_SC_NPROCESSORS_ONLN); }
+
+bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) {
+ static uint64_t lastSysUsed = 0;
+ static uint64_t lastSysTotal = 0;
+ static uint64_t lastProcTotal = 0;
+
+ SysCpuInfo sysCpu;
+ ProcCpuInfo procCpu;
+ if (!taosGetSysCpuInfo(&sysCpu)) {
+ return false;
+ }
+ if (!taosGetProcCpuInfo(&procCpu)) {
+ return false;
+ }
+
+ uint64_t curSysUsed = sysCpu.user + sysCpu.nice + sysCpu.system;
+ uint64_t curSysTotal = curSysUsed + sysCpu.idle;
+ uint64_t curProcTotal = procCpu.utime + procCpu.stime + procCpu.cutime + procCpu.cstime;
+
+ if (lastSysUsed == 0 || lastSysTotal == 0 || lastProcTotal == 0) {
+ lastSysUsed = curSysUsed > 1 ? curSysUsed : 1;
+ lastSysTotal = curSysTotal > 1 ? curSysTotal : 1;
+ lastProcTotal = curProcTotal > 1 ? curProcTotal : 1;
+ return false;
+ }
+
+ if (curSysTotal == lastSysTotal) {
+ return false;
+ }
+
+ *sysCpuUsage = (float)((double)(curSysUsed - lastSysUsed) / (double)(curSysTotal - lastSysTotal) * 100);
+ *procCpuUsage = (float)((double)(curProcTotal - lastProcTotal) / (double)(curSysTotal - lastSysTotal) * 100);
+
+ lastSysUsed = curSysUsed;
+ lastSysTotal = curSysTotal;
+ lastProcTotal = curProcTotal;
+
+ return true;
+}
+
+int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize) {
+ struct statvfs info;
+ if (statvfs(dataDir, &info)) {
+ printf("failed to get disk size, dataDir:%s errno:%s", dataDir, strerror(errno));
+ return -1;
+ } else {
+ diskSize->tsize = info.f_blocks * info.f_frsize;
+ diskSize->avail = info.f_bavail * info.f_frsize;
+ diskSize->used = (info.f_blocks - info.f_bfree) * info.f_frsize;
+ return 0;
+ }
+}
+
+bool taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes) {
+ *bytes = 0;
+ FILE *fp = fopen(tsSysNetFile, "r");
+ if (fp == NULL) {
+ printf("open file:%s failed", tsSysNetFile);
+ return false;
+ }
+
+ ssize_t _bytes = 0;
+ size_t len = 2048;
+ char * line = calloc(1, len);
+
+ while (!feof(fp)) {
+ memset(line, 0, len);
+
+ int64_t o_rbytes = 0;
+ int64_t rpackts = 0;
+ int64_t o_tbytes = 0;
+ int64_t tpackets = 0;
+ int64_t nouse1 = 0;
+ int64_t nouse2 = 0;
+ int64_t nouse3 = 0;
+ int64_t nouse4 = 0;
+ int64_t nouse5 = 0;
+ int64_t nouse6 = 0;
+ char nouse0[200] = {0};
+
+ _bytes = getline(&line, &len, fp);
+ if (_bytes < 0) {
+ break;
+ }
+
+ line[len - 1] = 0;
+
+ if (strstr(line, "lo:") != NULL) {
+ continue;
+ }
+
+ sscanf(line,
+ "%s %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64
+ " %" PRId64,
+ nouse0, &o_rbytes, &rpackts, &nouse1, &nouse2, &nouse3, &nouse4, &nouse5, &nouse6, &o_tbytes, &tpackets);
+ if (rbytes) *rbytes = o_rbytes;
+ if (tbytes) *tbytes = o_tbytes;
+ *bytes += (o_rbytes + o_tbytes);
+ }
+
+ tfree(line);
+ fclose(fp);
+
+ return true;
+}
+
+bool taosGetBandSpeed(float *bandSpeedKb) {
+ static int64_t lastBytes = 0;
+ static time_t lastTime = 0;
+ int64_t curBytes = 0;
+ time_t curTime = time(NULL);
+
+ if (!taosGetCardInfo(&curBytes, NULL, NULL)) {
+ return false;
+ }
+
+ if (lastTime == 0 || lastBytes == 0) {
+ lastTime = curTime;
+ lastBytes = curBytes;
+ *bandSpeedKb = 0;
+ return true;
+ }
+
+ if (lastTime >= curTime || lastBytes > curBytes) {
+ lastTime = curTime;
+ lastBytes = curBytes;
+ *bandSpeedKb = 0;
+ return true;
+ }
+
+ double totalBytes = (double)(curBytes - lastBytes) / 1024 * 8; // Kb
+ *bandSpeedKb = (float)(totalBytes / (double)(curTime - lastTime));
+
+ // printf("bandwidth lastBytes:%ld, lastTime:%ld, curBytes:%ld, curTime:%ld,
+ // speed:%f", lastBytes, lastTime, curBytes, curTime, *bandSpeed);
+
+ lastTime = curTime;
+ lastBytes = curBytes;
+
+ return true;
+}
+
+bool taosReadProcIO(int64_t *rchars, int64_t *wchars) {
+ FILE *fp = fopen(tsProcIOFile, "r");
+ if (fp == NULL) {
+ printf("open file:%s failed", tsProcIOFile);
+ return false;
+ }
+
+ ssize_t _bytes = 0;
+ size_t len;
+ char * line = NULL;
+ char tmp[10];
+ int readIndex = 0;
+
+ while (!feof(fp)) {
+ tfree(line);
+ len = 0;
+ _bytes = getline(&line, &len, fp);
+ if ((_bytes < 0) || (line == NULL)) {
+ break;
+ }
+ if (strstr(line, "rchar:") != NULL) {
+ sscanf(line, "%s %" PRId64, tmp, rchars);
+ readIndex++;
+ } else if (strstr(line, "wchar:") != NULL) {
+ sscanf(line, "%s %" PRId64, tmp, wchars);
+ readIndex++;
+ } else {
+ }
+
+ if (readIndex >= 2) break;
+ }
+
+ tfree(line);
+ fclose(fp);
+
+ if (readIndex < 2) {
+ printf("read file:%s failed", tsProcIOFile);
+ return false;
+ }
+
+ return true;
+}
+
+bool taosGetProcIO(float *readKB, float *writeKB) {
+ static int64_t lastReadbyte = -1;
+ static int64_t lastWritebyte = -1;
+
+ int64_t curReadbyte = 0;
+ int64_t curWritebyte = 0;
+
+ if (!taosReadProcIO(&curReadbyte, &curWritebyte)) {
+ return false;
+ }
+
+ if (lastReadbyte == -1 || lastWritebyte == -1) {
+ lastReadbyte = curReadbyte;
+ lastWritebyte = curWritebyte;
+ return false;
+ }
+
+ *readKB = (float)((double)(curReadbyte - lastReadbyte) / 1024);
+ *writeKB = (float)((double)(curWritebyte - lastWritebyte) / 1024);
+ if (*readKB < 0) *readKB = 0;
+ if (*writeKB < 0) *writeKB = 0;
+
+ lastReadbyte = curReadbyte;
+ lastWritebyte = curWritebyte;
+
+ return true;
+}
+
+void taosGetSystemInfo() {
+ taosGetProcInfos();
+
+ tsNumOfCores = taosGetCpuCores();
+ tsTotalMemoryMB = taosGetTotalMemory();
+
+ float tmp1, tmp2;
+ taosGetSysMemory(&tmp1);
+ taosGetProcMemory(&tmp2);
+ // taosGetDisk();
+ taosGetBandSpeed(&tmp1);
+ taosGetCpuUsage(&tmp1, &tmp2);
+ taosGetProcIO(&tmp1, &tmp2);
+
+ taosGetSystemTimezone();
+ taosGetSystemLocale();
+}
+
+void taosKillSystem() {
+ // SIGINT
+ printf("taosd will shut down soon");
+ kill(tsProcId, 2);
+}
+
+int taosSystem(const char *cmd) {
+ FILE *fp;
+ int res;
+ char buf[1024];
+ if (cmd == NULL) {
+ printf("taosSystem cmd is NULL!");
+ return -1;
+ }
+
+ if ((fp = popen(cmd, "r")) == NULL) {
+ printf("popen cmd:%s error: %s", cmd, strerror(errno));
+ return -1;
+ } else {
+ while (fgets(buf, sizeof(buf), fp)) {
+ printf("popen result:%s", buf);
+ }
+
+ if ((res = pclose(fp)) == -1) {
+ printf("close popen file pointer fp error!");
+ } else {
+ printf("popen res is :%d", res);
+ }
+
+ return res;
+ }
+}
+
+void taosSetCoreDump(bool enable) {
+ if (!enable) return;
+
+ // 1. set ulimit -c unlimited
+ struct rlimit rlim;
+ struct rlimit rlim_new;
+ if (getrlimit(RLIMIT_CORE, &rlim) == 0) {
+#ifndef _ALPINE
+ printf("the old unlimited para: rlim_cur=%" PRIu64 ", rlim_max=%" PRIu64, rlim.rlim_cur, rlim.rlim_max);
+#else
+ printf("the old unlimited para: rlim_cur=%llu, rlim_max=%llu", rlim.rlim_cur, rlim.rlim_max);
+#endif
+ rlim_new.rlim_cur = RLIM_INFINITY;
+ rlim_new.rlim_max = RLIM_INFINITY;
+ if (setrlimit(RLIMIT_CORE, &rlim_new) != 0) {
+ printf("set unlimited fail, error: %s", strerror(errno));
+ rlim_new.rlim_cur = rlim.rlim_max;
+ rlim_new.rlim_max = rlim.rlim_max;
+ (void)setrlimit(RLIMIT_CORE, &rlim_new);
+ }
+ }
+
+ if (getrlimit(RLIMIT_CORE, &rlim) == 0) {
+#ifndef _ALPINE
+ printf("the new unlimited para: rlim_cur=%" PRIu64 ", rlim_max=%" PRIu64, rlim.rlim_cur, rlim.rlim_max);
+#else
+ printf("the new unlimited para: rlim_cur=%llu, rlim_max=%llu", rlim.rlim_cur, rlim.rlim_max);
+#endif
+ }
+
+#ifndef _TD_ARM_
+ // 2. set the path for saving core file
+ struct __sysctl_args args;
+
+ int old_usespid = 0;
+ size_t old_len = 0;
+ int new_usespid = 1;
+ size_t new_len = sizeof(new_usespid);
+
+ int name[] = {CTL_KERN, KERN_CORE_USES_PID};
+
+ memset(&args, 0, sizeof(struct __sysctl_args));
+ args.name = name;
+ args.nlen = sizeof(name) / sizeof(name[0]);
+ args.oldval = &old_usespid;
+ args.oldlenp = &old_len;
+ args.newval = &new_usespid;
+ args.newlen = new_len;
+
+ old_len = sizeof(old_usespid);
+
+ if (syscall(SYS__sysctl, &args) == -1) {
+ printf("_sysctl(kern_core_uses_pid) set fail: %s", strerror(errno));
+ }
+
+ printf("The old core_uses_pid[%" PRIu64 "]: %d", old_len, old_usespid);
+
+ old_usespid = 0;
+ old_len = 0;
+ memset(&args, 0, sizeof(struct __sysctl_args));
+ args.name = name;
+ args.nlen = sizeof(name) / sizeof(name[0]);
+ args.oldval = &old_usespid;
+ args.oldlenp = &old_len;
+
+ old_len = sizeof(old_usespid);
+
+ if (syscall(SYS__sysctl, &args) == -1) {
+ printf("_sysctl(kern_core_uses_pid) get fail: %s", strerror(errno));
+ }
+
+ printf("The new core_uses_pid[%" PRIu64 "]: %d", old_len, old_usespid);
+#endif
+}
+
+bool taosGetSystemUid(char *uid, int32_t uidlen) {
+ int fd;
+ int len = 0;
+
+ fd = open("/proc/sys/kernel/random/uuid", 0);
+ if (fd < 0) {
+ return false;
+ } else {
+ len = read(fd, uid, uidlen);
+ close(fd);
+ }
+
+ if (len >= 36) {
+ uid[36] = 0;
+ return true;
+ }
+ return false;
+}
+
+char *taosGetCmdlineByPID(int pid) {
+ static char cmdline[1024];
+ sprintf(cmdline, "/proc/%d/cmdline", pid);
+
+ int fd = open(cmdline, O_RDONLY);
+ if (fd >= 0) {
+ int n = read(fd, cmdline, sizeof(cmdline) - 1);
+ if (n < 0) n = 0;
+
+ if (n > 0 && cmdline[n - 1] == '\n') --n;
+
+ cmdline[n] = 0;
+
+ close(fd);
+ } else {
+ cmdline[0] = 0;
+ }
+
+ return cmdline;
+}
+
+#endif
+
+#if !(defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32))
+
+SysNameInfo taosGetSysNameInfo() {
+ SysNameInfo info = {0};
+
+ struct utsname buf;
+ if (!uname(&buf)) {
+ info.sysname = buf.sysname;
+ info.sysname == buf.nodename;
+ info.sysname = buf.release;
+ info.sysname = buf.version;
+ info.sysname = buf.machine;
+ }
+
+ return info;
+}
+#endif
\ No newline at end of file
diff --git a/source/os/src/osSystem.c b/source/os/src/osSystem.c
new file mode 100644
index 0000000000000000000000000000000000000000..1a57e88c58c78ee5b0b9743346b1cec445848237
--- /dev/null
+++ b/source/os/src/osSystem.c
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * 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 .
+ */
+
+#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
+#include
+#include
+
+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
diff --git a/source/os/src/osTime.c b/source/os/src/osTime.c
index 27d046d4c91ca31d669415922c3a7a50b91e1825..2deac7e216f117577967341a56c7ce22f8cde655 100644
--- a/source/os/src/osTime.c
+++ b/source/os/src/osTime.c
@@ -13,16 +13,28 @@
* along with this program. If not, see .
*/
-#include "os.h"
+#define _BSD_SOURCE
-#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
-#include
+#ifdef DARWIN
+#define _XOPEN_SOURCE
#else
+#define _XOPEN_SOURCE 500
#endif
-FORCE_INLINE int32_t taosGetTimeOfDay(struct timeval *tv) {
+#define _DEFAULT_SOURCE
+
+#include "os.h"
+
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
- time_t t;
+/*
+ * windows implementation
+ */
+
+#include
+#include
+
+int taosGetTimeOfDay(struct timeval *tv, struct timezone *tz) {
+ time_t t;
t = time(NULL);
SYSTEMTIME st;
GetLocalTime(&st);
@@ -31,7 +43,23 @@ FORCE_INLINE int32_t taosGetTimeOfDay(struct timeval *tv) {
tv->tv_usec = st.wMilliseconds * 1000;
return 0;
+}
+
+struct tm *localtime_r(const time_t *timep, struct tm *result) {
+ localtime_s(result, timep);
+ return result;
+}
+
#else
+
+/*
+ * linux and darwin implementation
+ */
+
+#include
+
+FORCE_INLINE int32_t taosGetTimeOfDay(struct timeval *tv) {
return gettimeofday(tv, NULL);
+}
+
#endif
-}
\ No newline at end of file
diff --git a/source/os/src/osTimer.c b/source/os/src/osTimer.c
new file mode 100644
index 0000000000000000000000000000000000000000..d0114044f3d25e2682eb8b162774ee095af2a1f4
--- /dev/null
+++ b/source/os/src/osTimer.c
@@ -0,0 +1,225 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc.
+ *
+ * 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 .
+ */
+
+#define _DEFAULT_SOURCE
+#include "os.h"
+
+#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
+
+/*
+ * windows implementation
+ */
+
+
+#include
+#include
+#include
+#include
+
+#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
+#include
+
+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
+
+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
diff --git a/source/server/dnode/src/dnodeMain.c b/source/server/dnode/src/dnodeMain.c
index 715c27a9e08ec4999fc190941762b60d70b2c778..668b844f6cdad8f590ade78f93f3a049f60aec38 100644
--- a/source/server/dnode/src/dnodeMain.c
+++ b/source/server/dnode/src/dnodeMain.c
@@ -28,7 +28,7 @@
#include "mnode.h"
static int32_t dnodeCreateDir(const char *dir) {
- if (taosMkDir(dir, 0755) != 0 && errno != EEXIST) {
+ if (!taosMkDir(dir, 0755) && errno != EEXIST) {
return -1;
}
@@ -55,6 +55,14 @@ static void dnodeCheckDataDirOpenned(char *dir) {
#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) {
DnMain* main = calloc(1, sizeof(DnMain));
if (main == NULL) return -1;
@@ -76,7 +84,7 @@ int32_t dnodeInitMain(Dnode *dnode, DnMain **out) {
taosInitGlobalCfg();
taosReadGlobalLogCfg();
#if 0
- taosSetCoreDump();
+ taosSetCoreDump(tsEnableCoreFile);
#endif
if (dnodeCreateDir(tsLogDir) < 0) {
@@ -182,7 +190,7 @@ int32_t dnodeInitStorage(Dnode *dnode, void **m) {
dnodeCheckDataDirOpenned(tsDnodeDir);
taosGetDisk();
- taosPrintDiskInfo();
+ dnodePrintDiskInfo();
#endif
dInfo("dnode storage is initialized at %s", tsDnodeDir);
diff --git a/source/server/dnode/src/dnodeStatus.c b/source/server/dnode/src/dnodeStatus.c
index 4408cc8b87056c2eabfef6585d1d1405426471cd..58effb5b44df71ecc5b6cb20ee7e0a6b9ae314e3 100644
--- a/source/server/dnode/src/dnodeStatus.c
+++ b/source/server/dnode/src/dnodeStatus.c
@@ -15,6 +15,7 @@
#define _DEFAULT_SOURCE
#include "os.h"
+#include "ttime.h"
#include "ttimer.h"
#include "tglobal.h"
#include "dnodeCfg.h"
diff --git a/source/util/CMakeLists.txt b/source/util/CMakeLists.txt
index cec2554b52c0fc59cb0f0eaec592a27ca0c178b6..df7efb3380c2fa13a2862699dfb08721099f4d89 100644
--- a/source/util/CMakeLists.txt
+++ b/source/util/CMakeLists.txt
@@ -8,4 +8,6 @@ target_include_directories(
target_link_libraries(
util
PRIVATE os
-)
\ No newline at end of file
+ PUBLIC zlib
+ PUBLIC lz4_static
+)
diff --git a/src/util/src/exception.c b/source/util/src/exception.c
similarity index 100%
rename from src/util/src/exception.c
rename to source/util/src/exception.c
diff --git a/source/util/src/hash.c b/source/util/src/hash.c
index 21e835a6bf19ce95b71818af3ab2fc14924d45d2..2d48a7c3bf1acf024b6a807c5fe3a55375c40417 100644
--- a/source/util/src/hash.c
+++ b/source/util/src/hash.c
@@ -16,7 +16,6 @@
#include "os.h"
#include "hash.h"
#include "tulog.h"
-// #include "taosdef.h"
#define EXT_SIZE 1024
diff --git a/source/util/src/talgo.c b/source/util/src/talgo.c
index b9aabd7c4ae210dd3ab1c0136220bd0df4dcf6a1..f8520b0742951cb6f63b6fc626326578282791e3 100644
--- a/source/util/src/talgo.c
+++ b/source/util/src/talgo.c
@@ -14,7 +14,6 @@
*/
#include "os.h"
-
#include "talgo.h"
#define doswap(__left, __right, __size, __buf) do {\
diff --git a/src/util/src/tbase64.c b/source/util/src/tbase64.c
similarity index 100%
rename from src/util/src/tbase64.c
rename to source/util/src/tbase64.c
diff --git a/src/util/src/tbuffer.c b/source/util/src/tbuffer.c
similarity index 100%
rename from src/util/src/tbuffer.c
rename to source/util/src/tbuffer.c
diff --git a/src/util/src/tcache.c b/source/util/src/tcache.c
similarity index 100%
rename from src/util/src/tcache.c
rename to source/util/src/tcache.c
diff --git a/src/util/src/tcompare.c b/source/util/src/tcompare.c
similarity index 99%
rename from src/util/src/tcompare.c
rename to source/util/src/tcompare.c
index 482dd8a6a15d1c7bf6aca76159b95b71ef244dd2..e31fbaaff1af6353417c96fe671628f2556b3924 100644
--- a/src/util/src/tcompare.c
+++ b/source/util/src/tcompare.c
@@ -22,7 +22,7 @@
#include "hash.h"
#include "regex.h"
#include "os.h"
-#include "ttype.h"
+#include "tdef.h"
int32_t setCompareBytes1(const void *pLeft, const void *pRight) {
return NULL != taosHashGet((SHashObj *)pRight, pLeft, 1) ? 1 : 0;
diff --git a/src/util/src/tcompression.c b/source/util/src/tcompression.c
similarity index 99%
rename from src/util/src/tcompression.c
rename to source/util/src/tcompression.c
index 48bba75926415752cfd777242a55ef71c5c96c2c..990008a8401fbb0b619e367235f1859350c8b98c 100644
--- a/src/util/src/tcompression.c
+++ b/source/util/src/tcompression.c
@@ -52,11 +52,8 @@
#ifdef TD_TSZ
#include "td_sz.h"
#endif
-#include "taosdef.h"
#include "tscompression.h"
#include "tulog.h"
-#include "tglobal.h"
-
static const int TEST_NUMBER = 1;
#define is_bigendian() ((*(char *)&TEST_NUMBER) == 0)
diff --git a/src/util/src/tconfig.c b/source/util/src/tconfig.c
similarity index 87%
rename from src/util/src/tconfig.c
rename to source/util/src/tconfig.c
index 5a3dc3f9bcdee41f974e48f22b27beb2a1eb5a35..e7c0758b6193709826fc7a3e761a8663de828caa 100644
--- a/src/util/src/tconfig.c
+++ b/source/util/src/tconfig.c
@@ -15,10 +15,7 @@
#define _DEFAULT_SOURCE
#include "os.h"
-#include "taosdef.h"
-#include "taoserror.h"
#include "tconfig.h"
-#include "tglobal.h"
#include "tulog.h"
#include "tsocket.h"
#include "tutil.h"
@@ -78,7 +75,6 @@ static void taosReadDoubleConfig(SGlobalCfg *cfg, char *input_value) {
}
}
-
static void taosReadInt32Config(SGlobalCfg *cfg, char *input_value) {
int32_t value = atoi(input_value);
int32_t *option = (int32_t *)cfg->ptr;
@@ -156,27 +152,10 @@ static bool taosReadDirectoryConfig(SGlobalCfg *cfg, char *input_value) {
return false;
} else {
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
- wordexp_t full_path;
- if (0 != wordexp(input_value, &full_path, 0)) {
- 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) {
- strcpy(option, full_path.we_wordv[0]);
- }
+ taosExpandDir(input_value, option, cfg->ptrLength);
+ taosRealPath(option, cfg->ptrLength);
- 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);
+ if (!taosMkDir(option, 0755)) {
uError("config option:%s, input value:%s, directory not exist, create fail:%s", cfg->option, input_value,
strerror(errno));
return false;
@@ -234,9 +213,9 @@ static void taosReadLogOption(char *option, char *value) {
switch (cfg->valType) {
case TAOS_CFG_VTYPE_INT32:
taosReadInt32Config(cfg, value);
- if (strcasecmp(cfg->option, "debugFlag") == 0) {
- taosSetAllDebugFlag();
- }
+ // if (strcasecmp(cfg->option, "debugFlag") == 0) {
+ // taosSetAllDebugFlag();
+ // }
break;
case TAOS_CFG_VTYPE_DIRECTORY:
taosReadDirectoryConfig(cfg, value);
@@ -249,7 +228,6 @@ static void taosReadLogOption(char *option, char *value) {
}
SGlobalCfg *taosGetConfigOption(const char *option) {
- taosInitGlobalCfg();
for (int i = 0; i < tsGlobalConfigNum; ++i) {
SGlobalCfg *cfg = tsGlobalConfig + i;
if (strcasecmp(cfg->option, option) != 0) continue;
@@ -294,7 +272,7 @@ static void taosReadConfigOption(const char *option, char *value, char *value2,
break;
case TAOS_CFG_VTYPE_DATA_DIRCTORY:
if (taosReadDirectoryConfig(cfg, value)) {
- taosReadDataDirCfg(value, value2, value3);
+ // taosReadDataDirCfg(value, value2, value3);
}
break;
default:
@@ -315,34 +293,7 @@ void taosReadGlobalLogCfg() {
int olen, vlen;
char fileName[PATH_MAX] = {0};
- wordexp_t full_path;
- 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);
-
+ taosExpandDir(configDir, configDir, PATH_MAX);
taosReadLogOption("logDir", tsLogDir);
sprintf(fileName, "%s/taos.cfg", configDir);
@@ -391,13 +342,8 @@ bool taosReadGlobalCfg() {
char fileName[PATH_MAX] = {0};
sprintf(fileName, "%s/taos.cfg", configDir);
- FILE* fp = fopen(fileName, "r");
+ FILE *fp = fopen(fileName, "r");
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");
if (fp == NULL) {
return false;
@@ -444,9 +390,9 @@ bool taosReadGlobalCfg() {
tfree(line);
- if (debugFlag & DEBUG_TRACE || debugFlag & DEBUG_DEBUG || debugFlag & DEBUG_DUMP) {
- taosSetAllDebugFlag();
- }
+ // if (debugFlag & DEBUG_TRACE || debugFlag & DEBUG_DEBUG || debugFlag & DEBUG_DUMP) {
+ // taosSetAllDebugFlag();
+ // }
return true;
}
@@ -498,7 +444,7 @@ void taosPrintGlobalCfg() {
}
taosPrintOsInfo();
- taosPrintDataDirCfg();
+ // taosPrintDataDirCfg();
uInfo("==================================");
}
diff --git a/src/util/src/tcrc32c.c b/source/util/src/tcrc32c.c
similarity index 99%
rename from src/util/src/tcrc32c.c
rename to source/util/src/tcrc32c.c
index d2b63eb9ee7dd9a3119866bcf2d61b893192b14b..73bba4480e99f45a41ce937e9ea99bcd9077e995 100644
--- a/src/util/src/tcrc32c.c
+++ b/source/util/src/tcrc32c.c
@@ -18,14 +18,15 @@
3. This notice may not be removed or altered from any source distribution.
*/
+#include "os.h"
+#include "tcrc32c.h"
+#include "tdef.h"
+
#if !defined(_TD_ARM_) && !defined(_TD_MIPS_)
#include
#endif
-#include
-#include
-#include "tcrc32c.h"
#define POLY 0x82f63b78
#define LONG_SHIFT 8192
diff --git a/src/util/src/tdes.c b/source/util/src/tdes.c
similarity index 100%
rename from src/util/src/tdes.c
rename to source/util/src/tdes.c
diff --git a/src/util/src/tfile.c b/source/util/src/tfile.c
similarity index 100%
rename from src/util/src/tfile.c
rename to source/util/src/tfile.c
diff --git a/src/util/src/tfunctional.c b/source/util/src/tfunctional.c
similarity index 100%
rename from src/util/src/tfunctional.c
rename to source/util/src/tfunctional.c
diff --git a/src/util/src/thashutil.c b/source/util/src/thashutil.c
similarity index 100%
rename from src/util/src/thashutil.c
rename to source/util/src/thashutil.c
diff --git a/src/util/src/tidpool.c b/source/util/src/tidpool.c
similarity index 100%
rename from src/util/src/tidpool.c
rename to source/util/src/tidpool.c
diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c
index 1906ea1629e3aa85b1f087837a4d1fd31980ece4..63dd1ef606f2839636c19476280330e3a90ff2ff 100644
--- a/source/util/src/tlog.c
+++ b/source/util/src/tlog.c
@@ -19,6 +19,7 @@
#include "tlog.h"
#include "tnote.h"
#include "tutil.h"
+#include "zlib.h"
#define MAX_LOGLINE_SIZE (1000)
#define MAX_LOGLINE_BUFFER_SIZE (MAX_LOGLINE_SIZE + 10)
@@ -75,22 +76,34 @@ float tsMinimalLogDirGB = 1.0f;
int64_t asyncLogLostLines = 0;
int32_t writeInterval = DEFAULT_LOG_INTERVAL;
+// log
+int32_t tsNumOfLogLines = 10000000;
+int32_t mDebugFlag = 131;
+int32_t sdbDebugFlag = 131;
+int32_t dDebugFlag = 135;
+int32_t vDebugFlag = 135;
+int32_t cDebugFlag = 131;
+int32_t jniDebugFlag = 131;
+int32_t odbcDebugFlag = 131;
+int32_t httpDebugFlag = 131;
+int32_t mqttDebugFlag = 131;
+int32_t monDebugFlag = 131;
+int32_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;
+
int64_t dbgEmptyW = 0;
int64_t dbgWN = 0;
int64_t dbgSmallWN = 0;
int64_t dbgBigWN = 0;
int64_t dbgWSize = 0;
-#ifdef _TD_POWER_
-char tsLogDir[TSDB_FILENAME_LEN] = "/var/log/power";
-#elif (_TD_TQ_ == true)
-char tsLogDir[TSDB_FILENAME_LEN] = "/var/log/tq";
-#elif (_TD_PRO_ == true)
-char tsLogDir[TSDB_FILENAME_LEN] = "/var/log/ProDB";
-#else
-char tsLogDir[PATH_MAX] = "/var/log/taos";
-#endif
-
static SLogObj tsLogObj = { .fileNum = 1 };
static void * taosAsyncOutputLog(void *param);
static int32_t taosPushLogBuffer(SLogBuff *tLogBuff, char *msg, int32_t msgLen);
@@ -98,6 +111,7 @@ static SLogBuff *taosLogBuffNew(int32_t bufSize);
static void taosCloseLogByFd(int32_t oldFd);
static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum);
extern void taosPrintGlobalCfg();
+static int32_t taosCompressFile(char *srcFileName, char *destFileName);
static int32_t taosStartLog() {
pthread_attr_t threadAttr;
@@ -164,7 +178,7 @@ static void taosKeepOldLog(char *oldName) {
char fileName[LOG_FILE_NAME_LEN + 20];
snprintf(fileName, LOG_FILE_NAME_LEN + 20, "%s.%" PRId64, tsLogObj.logName, fileSec);
- taosRename(oldName, fileName);
+ taosRenameFile(oldName, fileName);
if (tsLogKeepDays < 0) {
char compressFileName[LOG_FILE_NAME_LEN + 20];
snprintf(compressFileName, LOG_FILE_NAME_LEN + 20, "%s.%" PRId64 ".gz", tsLogObj.logName, fileSec);
@@ -173,7 +187,7 @@ static void taosKeepOldLog(char *oldName) {
}
}
- taosRemoveOldLogFiles(tsLogDir, ABS(tsLogKeepDays));
+ taosRemoveOldFiles(tsLogDir, ABS(tsLogKeepDays));
}
static void *taosThreadToOpenNewFile(void *param) {
@@ -702,3 +716,62 @@ static void *taosAsyncOutputLog(void *param) {
return NULL;
}
+
+int32_t taosCompressFile(char *srcFileName, char *destFileName) {
+ int32_t compressSize = 163840;
+ int32_t ret = 0;
+ int32_t len = 0;
+ char * data = malloc(compressSize);
+ FILE * srcFp = NULL;
+ gzFile dstFp = NULL;
+
+ srcFp = fopen(srcFileName, "r");
+ if (srcFp == NULL) {
+ ret = -1;
+ goto cmp_end;
+ }
+
+ int32_t fd = taosOpenFileTruncCreateWrite(destFileName);
+ if (fd < 0) {
+ ret = -2;
+ goto cmp_end;
+ }
+
+ dstFp = gzdopen(fd, "wb6f");
+ if (dstFp == NULL) {
+ ret = -3;
+ close(fd);
+ goto cmp_end;
+ }
+
+ while (!feof(srcFp)) {
+ len = (int32_t)fread(data, 1, compressSize, srcFp);
+ (void)gzwrite(dstFp, data, len);
+ }
+
+cmp_end:
+ if (srcFp) {
+ fclose(srcFp);
+ }
+ if (dstFp) {
+ gzclose(dstFp);
+ }
+ free(data);
+
+ return ret;
+}
+
+void taosPrintOsInfo() {
+ SysNameInfo info = taosGetSysNameInfo();
+
+ uInfo(" os pageSize: %" PRId64 "(KB)", tsPageSize);
+ uInfo(" os openMax: %" PRId64, tsOpenMax);
+ uInfo(" os streamMax: %" PRId64, tsStreamMax);
+ uInfo(" os numOfCores: %d", tsNumOfCores);
+ uInfo(" os totalMemory: %d(MB)", tsTotalMemoryMB);
+ uInfo(" os sysname: %s", info.sysname);
+ uInfo(" os nodename: %s", info.nodename);
+ uInfo(" os release: %s", info.release);
+ uInfo(" os version: %s", info.version);
+ uInfo(" os machine: %s", info.machine);
+}
diff --git a/src/util/src/tlosertree.c b/source/util/src/tlosertree.c
similarity index 100%
rename from src/util/src/tlosertree.c
rename to source/util/src/tlosertree.c
diff --git a/src/util/src/tmd5.c b/source/util/src/tmd5.c
similarity index 100%
rename from src/util/src/tmd5.c
rename to source/util/src/tmd5.c
diff --git a/src/util/src/tmempool.c b/source/util/src/tmempool.c
similarity index 100%
rename from src/util/src/tmempool.c
rename to source/util/src/tmempool.c
diff --git a/src/util/src/tnettest.c b/source/util/src/tnettest.c
similarity index 100%
rename from src/util/src/tnettest.c
rename to source/util/src/tnettest.c
diff --git a/src/util/src/tnote.c b/source/util/src/tnote.c
similarity index 100%
rename from src/util/src/tnote.c
rename to source/util/src/tnote.c
diff --git a/src/util/src/tqueue.c b/source/util/src/tqueue.c
similarity index 100%
rename from src/util/src/tqueue.c
rename to source/util/src/tqueue.c
diff --git a/src/util/src/tref.c b/source/util/src/tref.c
similarity index 100%
rename from src/util/src/tref.c
rename to source/util/src/tref.c
diff --git a/src/util/src/tsched.c b/source/util/src/tsched.c
similarity index 100%
rename from src/util/src/tsched.c
rename to source/util/src/tsched.c
diff --git a/src/util/src/tskiplist.c b/source/util/src/tskiplist.c
similarity index 100%
rename from src/util/src/tskiplist.c
rename to source/util/src/tskiplist.c
diff --git a/src/util/src/tsocket.c b/source/util/src/tsocket.c
similarity index 100%
rename from src/util/src/tsocket.c
rename to source/util/src/tsocket.c
diff --git a/src/util/src/tstrbuild.c b/source/util/src/tstrbuild.c
similarity index 100%
rename from src/util/src/tstrbuild.c
rename to source/util/src/tstrbuild.c
diff --git a/src/util/src/tthread.c b/source/util/src/tthread.c
similarity index 100%
rename from src/util/src/tthread.c
rename to source/util/src/tthread.c
diff --git a/src/util/src/ttimer.c b/source/util/src/ttimer.c
similarity index 100%
rename from src/util/src/ttimer.c
rename to source/util/src/ttimer.c
diff --git a/src/util/src/ttokenizer.c b/source/util/src/ttokenizer.c
similarity index 100%
rename from src/util/src/ttokenizer.c
rename to source/util/src/ttokenizer.c
diff --git a/src/util/src/tutil.c b/source/util/src/tutil.c
similarity index 100%
rename from src/util/src/tutil.c
rename to source/util/src/tutil.c
diff --git a/src/util/src/tworker.c b/source/util/src/tworker.c
similarity index 100%
rename from src/util/src/tworker.c
rename to source/util/src/tworker.c
diff --git a/src/util/src/version.c.in b/source/util/src/version.c.in
similarity index 100%
rename from src/util/src/version.c.in
rename to source/util/src/version.c.in
diff --git a/src/util/tests/CMakeLists.txt b/source/util/test/CMakeLists.txt
similarity index 100%
rename from src/util/tests/CMakeLists.txt
rename to source/util/test/CMakeLists.txt
diff --git a/src/util/tests/arrayTest.cpp b/source/util/test/arrayTest.cpp
similarity index 100%
rename from src/util/tests/arrayTest.cpp
rename to source/util/test/arrayTest.cpp
diff --git a/src/util/tests/cacheTest.cpp b/source/util/test/cacheTest.cpp
similarity index 100%
rename from src/util/tests/cacheTest.cpp
rename to source/util/test/cacheTest.cpp
diff --git a/src/util/tests/codingTests.cpp b/source/util/test/codingTests.cpp
similarity index 100%
rename from src/util/tests/codingTests.cpp
rename to source/util/test/codingTests.cpp
diff --git a/src/util/tests/hashTest.cpp b/source/util/test/hashTest.cpp
similarity index 100%
rename from src/util/tests/hashTest.cpp
rename to source/util/test/hashTest.cpp
diff --git a/src/util/tests/skiplistTest.cpp b/source/util/test/skiplistTest.cpp
similarity index 100%
rename from src/util/tests/skiplistTest.cpp
rename to source/util/test/skiplistTest.cpp
diff --git a/src/util/tests/stringTest.cpp b/source/util/test/stringTest.cpp
similarity index 100%
rename from src/util/tests/stringTest.cpp
rename to source/util/test/stringTest.cpp
diff --git a/src/util/tests/taosbsearchTest.cpp b/source/util/test/taosbsearchTest.cpp
similarity index 100%
rename from src/util/tests/taosbsearchTest.cpp
rename to source/util/test/taosbsearchTest.cpp
diff --git a/src/util/tests/trefTest.c b/source/util/test/trefTest.c
similarity index 100%
rename from src/util/tests/trefTest.c
rename to source/util/test/trefTest.c
diff --git a/src/client/src/tscSub.c b/src/client/src/tscSub.c
index 52ba424fa5adcd43ac5b624b7f486c06df71f2c4..2d2ce3829969d07d58d972b02cbc8717273da60d 100644
--- a/src/client/src/tscSub.c
+++ b/src/client/src/tscSub.c
@@ -371,7 +371,7 @@ void tscSaveSubscriptionProgress(void* sub) {
char path[256];
sprintf(path, "%s/subscribe", tsDataDir);
- if (taosMkDir(path, 0777) != 0) {
+ if (!taosMkDir(path, 0777)) {
tscError("failed to create subscribe dir: %s", path);
}
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
deleted file mode 100644
index 57d4890f49ecc58b28cfaabddc14dc1c3f4e0c06..0000000000000000000000000000000000000000
--- a/src/common/CMakeLists.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-aux_source_directory(source COMMON_SRC)
-add_library(common ${COMMON_SRC})
-target_include_directories(
- common
- PUBLIC "${CMAKE_SOURCE_DIR}/include/common"
- PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include"
-)
-target_include_directories(
- common
- PRIVATE util
-)
\ No newline at end of file
diff --git a/src/common/inc/tulog.h b/src/common/inc/tulog.h
deleted file mode 100644
index 566da40a10e078b9789e2e1b76a8d82fe89aef46..0000000000000000000000000000000000000000
--- a/src/common/inc/tulog.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * 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 .
- */
-
-#ifndef TDENGINE_COMMON_ULOG_H
-#define TDENGINE_COMMON_ULOG_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "tlog.h"
-
-extern int32_t uDebugFlag;
-extern int8_t tscEmbedded;
-
-#define uFatal(...) { if (uDebugFlag & DEBUG_FATAL) { taosPrintLog("UTL FATAL", tscEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
-#define uError(...) { if (uDebugFlag & DEBUG_ERROR) { taosPrintLog("UTL ERROR ", tscEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
-#define uWarn(...) { if (uDebugFlag & DEBUG_WARN) { taosPrintLog("UTL WARN ", tscEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
-#define uInfo(...) { if (uDebugFlag & DEBUG_INFO) { taosPrintLog("UTL ", tscEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
-#define uDebug(...) { if (uDebugFlag & DEBUG_DEBUG) { taosPrintLog("UTL ", uDebugFlag, __VA_ARGS__); }}
-#define uTrace(...) { if (uDebugFlag & DEBUG_TRACE) { taosPrintLog("UTL ", uDebugFlag, __VA_ARGS__); }}
-
-#define pError(...) { taosPrintLog("APP ERROR ", 255, __VA_ARGS__); }
-#define pPrint(...) { taosPrintLog("APP ", 255, __VA_ARGS__); }
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/common/source/common.c b/src/common/source/common.c
deleted file mode 100644
index 6dea4a4e57392be988126c579648f39a8270b9bf..0000000000000000000000000000000000000000
--- a/src/common/source/common.c
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * 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 .
- */
\ No newline at end of file
diff --git a/src/os/CMakeLists.txt b/src/os/CMakeLists.txt
deleted file mode 100644
index 4d3bf4d7dc5b04844863851b321a14c7423ca26b..0000000000000000000000000000000000000000
--- a/src/os/CMakeLists.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-aux_source_directory(source OS_SRC)
-add_library(os ${OS_SRC})
-target_include_directories(
- os
- PUBLIC "${CMAKE_SOURCE_DIR}/include/os"
- PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include"
-)
\ No newline at end of file
diff --git a/src/os/inc/osArm32.h b/src/os/inc/osArm32.h
deleted file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000
diff --git a/src/os/inc/osArm64.h b/src/os/inc/osArm64.h
deleted file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000
diff --git a/src/os/inc/osEok.h b/src/os/inc/osEok.h
deleted file mode 100644
index 3ca476f840c1fc35bc796ecb4de67f6e0a156ca9..0000000000000000000000000000000000000000
--- a/src/os/inc/osEok.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * 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 .
- */
-
-#ifndef TDENGINE_OS_EOK_H
-#define TDENGINE_OS_EOK_H
-
-#include
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifdef __APPLE__
-
-enum EPOLL_EVENTS
- {
- EPOLLIN = 0x001,
-#define EPOLLIN EPOLLIN
- EPOLLPRI = 0x002,
-#define EPOLLPRI EPOLLPRI
- EPOLLOUT = 0x004,
-#define EPOLLOUT EPOLLOUT
- EPOLLRDNORM = 0x040,
-#define EPOLLRDNORM EPOLLRDNORM
- EPOLLRDBAND = 0x080,
-#define EPOLLRDBAND EPOLLRDBAND
- EPOLLWRNORM = 0x100,
-#define EPOLLWRNORM EPOLLWRNORM
- EPOLLWRBAND = 0x200,
-#define EPOLLWRBAND EPOLLWRBAND
- EPOLLMSG = 0x400,
-#define EPOLLMSG EPOLLMSG
- EPOLLERR = 0x008,
-#define EPOLLERR EPOLLERR
- EPOLLHUP = 0x010,
-#define EPOLLHUP EPOLLHUP
- EPOLLRDHUP = 0x2000,
-#define EPOLLRDHUP EPOLLRDHUP
- EPOLLEXCLUSIVE = 1u << 28,
-#define EPOLLEXCLUSIVE EPOLLEXCLUSIVE
- EPOLLWAKEUP = 1u << 29,
-#define EPOLLWAKEUP EPOLLWAKEUP
- EPOLLONESHOT = 1u << 30,
-#define EPOLLONESHOT EPOLLONESHOT
- EPOLLET = 1u << 31
-#define EPOLLET EPOLLET
- };
-
-/* Valid opcodes ( "op" parameter ) to issue to epoll_ctl(). */
-#define EPOLL_CTL_ADD 1 /* Add a file descriptor to the interface. */
-#define EPOLL_CTL_DEL 2 /* Remove a file descriptor from the interface. */
-#define EPOLL_CTL_MOD 3 /* Change file descriptor epoll_event structure. */
-
-
-typedef union epoll_data
-{
- void *ptr;
- int fd;
- uint32_t u32;
- uint64_t u64;
-} epoll_data_t;
-
-struct epoll_event
-{
- uint32_t events; /* Epoll events */
- epoll_data_t data; /* User data variable */
-};
-
-int epoll_create(int size);
-int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event);
-int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout);
-int epoll_close(int epfd);
-
-#endif // __APPLE__
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // _eok_h_fd274616_996c_400e_9023_ae70be881fa3_
-
diff --git a/src/os/inc/osInc.h b/src/os/inc/osInc.h
deleted file mode 100644
index 9b78110833e73274f82d051cbaa6fd35c90f2a08..0000000000000000000000000000000000000000
--- a/src/os/inc/osInc.h
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * 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 .
- */
-
-#ifndef TDENGINE_OS_INC_H
-#define TDENGINE_OS_INC_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#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)
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
-
- #if defined(_TD_DARWIN_64)
- #include
- #include "osEok.h"
- #else
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
-
- #if !(defined(_ALPINE))
- #include
- #endif
- #endif
-#endif
-
-#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
- #include
- #include
- #include "winsock2.h"
- #include
- #include
- #include
- #include
- #include
- #include "msvcProcess.h"
- #include "msvcDirect.h"
- #include "msvcFcntl.h"
- #include "msvcLibgen.h"
- #include "msvcStdio.h"
- #include "msvcUnistd.h"
- #include "msvcLibgen.h"
- #include "sys/msvcStat.h"
- #include "sys/msvcTypes.h"
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/os/inc/osLinux32.h b/src/os/inc/osLinux32.h
deleted file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000
diff --git a/src/os/inc/osLinux64.h b/src/os/inc/osLinux64.h
deleted file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000
diff --git a/src/os/inc/osMemory.h b/src/os/inc/osMemory.h
deleted file mode 100644
index 793992c197a475b68046296b6683b5b2843b9d68..0000000000000000000000000000000000000000
--- a/src/os/inc/osMemory.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * 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 .
- */
-
-#ifndef TDENGINE_OS_MEMORY_H
-#define TDENGINE_OS_MEMORY_H
-
-#include "osString.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifdef TD_JEMALLOC_ENABLED
-#include
-#endif
-
-typedef enum {
- TAOS_ALLOC_MODE_DEFAULT = 0,
- TAOS_ALLOC_MODE_RANDOM_FAIL = 1,
- TAOS_ALLOC_MODE_DETECT_LEAK = 2
-} ETaosMemoryAllocMode;
-
-void taosSetAllocMode(int mode, const char *path, bool autoDump);
-void taosDumpMemoryLeak();
-
-// used in tsdb module
-void * taosTMalloc(size_t size);
-void * taosTCalloc(size_t nmemb, size_t size);
-void * taosTRealloc(void *ptr, size_t size);
-void * taosTZfree(void *ptr);
-size_t taosTSizeof(void *ptr);
-void taosTMemset(void *ptr, int c);
-
-// used in other module
-#define tmalloc(size) malloc(size)
-#define tcalloc(num, size) calloc(num, size)
-#define trealloc(ptr, size) realloc(ptr, size)
-#define tfree(x) \
- do { \
- if (x) { \
- free((void *)(x)); \
- x = 0; \
- } \
- } while (0)
-
-#ifdef TAOS_MEM_CHECK
- #ifdef TAOS_MEM_CHECK_TEST
- void * taosMallocMem(size_t size, const char *file, uint32_t line);
- void * taosCallocMem(size_t num, size_t size, const char *file, uint32_t line);
- void * taosReallocMem(void *ptr, size_t size, const char *file, uint32_t line);
- void taosFreeMem(void *ptr, const char *file, uint32_t line);
- char * taosStrdupMem(const char *str, const char *file, uint32_t line);
- char * taosStrndupMem(const char *str, size_t size, const char *file, uint32_t line);
- ssize_t taosGetlineMem(char **lineptr, size_t *n, FILE *stream, const char *file, uint32_t line);
- #undef tmalloc
- #undef tcalloc
- #undef trealloc
- #undef tfree
- #define tmalloc(size) taosMallocMem(size, __FILE__, __LINE__)
- #define tcalloc(num, size) taosCallocMem(num, size, __FILE__, __LINE__)
- #define trealloc(ptr, size) taosReallocMem(ptr, size, __FILE__, __LINE__)
- #define tfree(ptr) taosFreeMem(ptr, __FILE__, __LINE__)
- #endif
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/os/inc/osMips64.h b/src/os/inc/osMips64.h
deleted file mode 100644
index ed7b08a31116d20a8eaaaacfa3a9a64ea75dbcee..0000000000000000000000000000000000000000
--- a/src/os/inc/osMips64.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * 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 .
- */
-
-#ifndef TDENGINE_OS_MIPS64_H
-#define TDENGINE_OS_MIPS64_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/os/inc/osSignal.h b/src/os/inc/osSignal.h
deleted file mode 100644
index eca1d3b3f6b78a773822e5f2acb652493b5d262f..0000000000000000000000000000000000000000
--- a/src/os/inc/osSignal.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * 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 .
- */
-
-#ifndef TDENGINE_OS_SIGNAL_H
-#define TDENGINE_OS_SIGNAL_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include
-
-#ifndef SIGALRM
- #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
-}
-#endif
-
-#endif // TDENGINE_OS_SIGNAL_H
diff --git a/src/os/inc/osSleep.h b/src/os/inc/osSleep.h
deleted file mode 100644
index e42da8d5a64bbc484b15beea19433a710578ff3f..0000000000000000000000000000000000000000
--- a/src/os/inc/osSleep.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * 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 .
- */
-
-#ifndef TDENGINE_OS_SLEEP_H
-#define TDENGINE_OS_SLEEP_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void taosMsleep(int32_t ms);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
\ No newline at end of file
diff --git a/src/os/inc/osSysinfo.h b/src/os/inc/osSysinfo.h
deleted file mode 100644
index 0320ab0f7fe5f72e70fd6d12d8d2b0a27dec3754..0000000000000000000000000000000000000000
--- a/src/os/inc/osSysinfo.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * 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 .
- */
-
-#ifndef TDENGINE_OS_SYSINFO_H
-#define TDENGINE_OS_SYSINFO_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-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();
-void taosPrintDiskInfo();
-int taosSystem(const char * cmd) ;
-void taosKillSystem();
-bool taosGetSystemUid(char *uid);
-char *taosGetCmdlineByPID(int pid);
-
-void taosSetCoreDump();
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/os/inc/osTimer.h b/src/os/inc/osTimer.h
deleted file mode 100644
index 72da19cd899a708dc36c91ac25159995fe0da51c..0000000000000000000000000000000000000000
--- a/src/os/inc/osTimer.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * 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 .
- */
-
-#ifndef TDENGINE_OS_TIMER_H
-#define TDENGINE_OS_TIMER_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int taosInitTimer(void (*callback)(int), int ms);
-void taosUninitTimer();
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/os/source/os.c b/src/os/source/os.c
deleted file mode 100644
index 6dea4a4e57392be988126c579648f39a8270b9bf..0000000000000000000000000000000000000000
--- a/src/os/source/os.c
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc.
- *
- * 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