[td-805]
This commit is contained in:
commit
2547805ea6
|
@ -1,7 +1,6 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
PROJECT(TDengine)
|
||||
|
||||
SET(TD_SYNC FALSE)
|
||||
SET(TD_ACCOUNT FALSE)
|
||||
SET(TD_ADMIN FALSE)
|
||||
SET(TD_GRANT FALSE)
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
PROJECT(TDengine)
|
||||
|
||||
IF (TD_SYNC)
|
||||
ADD_DEFINITIONS(-D_SYNC)
|
||||
ENDIF ()
|
||||
|
||||
IF (TD_ACCOUNT)
|
||||
ADD_DEFINITIONS(-D_ACCT)
|
||||
ENDIF ()
|
||||
|
|
|
@ -9,7 +9,6 @@ SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/build/lib)
|
|||
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/build/bin)
|
||||
SET(TD_TESTS_OUTPUT_DIR ${PROJECT_BINARY_DIR}/test)
|
||||
|
||||
MESSAGE(STATUS "Operating system dependency directory: " ${TD_OS_DIR})
|
||||
MESSAGE(STATUS "Project source directory: " ${PROJECT_SOURCE_DIR})
|
||||
MESSAGE(STATUS "Project binary files output path: " ${PROJECT_BINARY_DIR})
|
||||
MESSAGE(STATUS "Project executable files output path: " ${EXECUTABLE_OUTPUT_PATH})
|
||||
|
|
|
@ -33,20 +33,23 @@ IF (${CPUTYPE} MATCHES "aarch32")
|
|||
SET(TD_PAGMODE_LITE TRUE)
|
||||
ADD_DEFINITIONS(-D_TD_ARM_)
|
||||
ADD_DEFINITIONS(-D_TD_ARM_32_)
|
||||
MESSAGE(STATUS "input cpuType: aarch32")
|
||||
ELSEIF (${CPUTYPE} MATCHES "aarch64")
|
||||
SET(TD_ARM TRUE)
|
||||
SET(TD_ARM_64 TRUE)
|
||||
ADD_DEFINITIONS(-D_TD_ARM_)
|
||||
ADD_DEFINITIONS(-D_TD_ARM_64_)
|
||||
MESSAGE(STATUS "input cpuType: aarch64")
|
||||
ELSEIF (${CPUTYPE} MATCHES "mips64")
|
||||
SET(TD_MIPS TRUE)
|
||||
SET(TD_MIPS_64 TRUE)
|
||||
ADD_DEFINITIONS(-D_TD_MIPS_)
|
||||
ADD_DEFINITIONS(-D_TD_MIPS_64_)
|
||||
MESSAGE(STATUS "input cpuType: mips64")
|
||||
ELSEIF (${CPUTYPE} MATCHES "x64")
|
||||
MESSAGE(STATUS "input cpuType: " ${CPUTYPE})
|
||||
MESSAGE(STATUS "input cpuType: x64")
|
||||
ELSEIF (${CPUTYPE} MATCHES "x86")
|
||||
MESSAGE(STATUS "input cpuType: " ${CPUTYPE})
|
||||
MESSAGE(STATUS "input cpuType: x86")
|
||||
ELSE ()
|
||||
MESSAGE(STATUS "input cpuType: " ${CPUTYPE})
|
||||
ENDIF ()
|
||||
|
@ -61,13 +64,13 @@ MESSAGE(STATUS "The current os is " ${TD_OS_INFO})
|
|||
IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
IF (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
|
||||
SET(TD_LINUX_64 TRUE)
|
||||
SET(TD_OS_DIR ${TD_COMMUNITY_DIR}/src/os/linux)
|
||||
ADD_DEFINITIONS(-D_M_X64)
|
||||
ADD_DEFINITIONS(-D_TD_LINUX_64)
|
||||
MESSAGE(STATUS "The current platform is Linux 64-bit")
|
||||
ELSEIF (${CMAKE_SIZEOF_VOID_P} MATCHES 4)
|
||||
SET(TD_LINUX_32 TRUE)
|
||||
ADD_DEFINITIONS(-D_TD_LINUX_32)
|
||||
IF (TD_ARM)
|
||||
SET(TD_LINUX_32 TRUE)
|
||||
SET(TD_OS_DIR ${TD_COMMUNITY_DIR}/src/os/linux)
|
||||
#ADD_DEFINITIONS(-D_M_IX86)
|
||||
MESSAGE(STATUS "The current platform is Linux 32-bit")
|
||||
ELSE ()
|
||||
|
@ -81,7 +84,7 @@ IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
|||
ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
IF (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
|
||||
SET(TD_DARWIN_64 TRUE)
|
||||
SET(TD_OS_DIR ${TD_COMMUNITY_DIR}/src/os/darwin)
|
||||
ADD_DEFINITIONS(-D_TD_DARWIN_64)
|
||||
MESSAGE(STATUS "The current platform is Darwin 64-bit")
|
||||
ELSE ()
|
||||
MESSAGE(FATAL_ERROR "The current platform is Darwin 32-bit, not supported yet")
|
||||
|
@ -90,10 +93,12 @@ ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
|||
ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
||||
IF (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
|
||||
SET(TD_WINDOWS_64 TRUE)
|
||||
SET(TD_OS_DIR ${TD_COMMUNITY_DIR}/src/os/windows)
|
||||
ADD_DEFINITIONS(-D_M_X64)
|
||||
ADD_DEFINITIONS(-D_TD_WINDOWS_64)
|
||||
MESSAGE(STATUS "The current platform is Windows 64-bit")
|
||||
ELSE ()
|
||||
SET(TD_WINDOWS_32 TRUE)
|
||||
ADD_DEFINITIONS(-D_TD_WINDOWS_32)
|
||||
MESSAGE(FATAL_ERROR "The current platform is Windows 32-bit, not supported yet")
|
||||
EXIT ()
|
||||
ENDIF ()
|
||||
|
|
|
@ -556,7 +556,7 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
功能说明:统计表中某列的值百分比分位数。
|
||||
返回结果数据类型: 双精度浮点数Double。
|
||||
应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
|
||||
说明:*k*值取值范围0≤*k*≤100,为0的时候等同于MIN,为100的时候等同于MAX。
|
||||
说明:*k*值取值范围0≤*P*≤100,为0的时候等同于MIN,为100的时候等同于MAX。
|
||||
|
||||
- **APERCENTILE**
|
||||
```mysql
|
||||
|
@ -565,7 +565,7 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
|
|||
功能说明:统计表中某列的值百分比分位数,与PERCENTILE函数相似,但是返回近似结果。
|
||||
返回结果数据类型: 双精度浮点数Double。
|
||||
应用字段:不能应用在timestamp、binary、nchar、bool类型字段。
|
||||
说明:*k*值取值范围0≤*k*≤100,为0的时候等同于MIN,为100的时候等同于MAX。推荐使用```APERCENTILE```函数,该函数性能远胜于```PERCENTILE```函数
|
||||
说明:*k*值取值范围0≤*P*≤100,为0的时候等同于MIN,为100的时候等同于MAX。推荐使用```APERCENTILE```函数,该函数性能远胜于```PERCENTILE```函数
|
||||
|
||||
- **LAST_ROW**
|
||||
```mysql
|
||||
|
|
|
@ -289,10 +289,10 @@ TDengine supports aggregations over numerical values, they are listed below:
|
|||
Applied to: table/STable.
|
||||
|
||||
|
||||
- **WAVG**
|
||||
- **TWA**
|
||||
|
||||
```mysql
|
||||
SELECT WAVG(field_name) FROM tb_name WHERE clause
|
||||
SELECT TWA(field_name) FROM tb_name WHERE clause
|
||||
```
|
||||
Function: return the time-weighted average value of a specific column
|
||||
Return Data Type: `double`
|
||||
|
@ -324,7 +324,7 @@ TDengine supports aggregations over numerical values, they are listed below:
|
|||
|
||||
- **LEASTSQUARES**
|
||||
```mysql
|
||||
SELECT LEASTSQUARES(field_name) FROM tb_name [WHERE clause]
|
||||
SELECT LEASTSQUARES(field_name, start_val, step_val) FROM tb_name [WHERE clause]
|
||||
```
|
||||
Function: performs a linear fit to the primary timestamp and the specified column.
|
||||
Return Data Type: return a string of the coefficient and the interception of the fitted line.
|
||||
|
@ -417,6 +417,15 @@ TDengine supports aggregations over numerical values, they are listed below:
|
|||
Applied to: table/STable.
|
||||
Note: The range of `P` is `[0, 100]`. When `P=0` , `PERCENTILE` returns the equal value as `MIN`; when `P=100`, `PERCENTILE` returns the equal value as `MAX`.
|
||||
|
||||
- **APERCENTILE**
|
||||
```mysql
|
||||
SELECT APERCENTILE(field_name, P) FROM { tb_name | stb_name } [WHERE clause]
|
||||
```
|
||||
Function: the value of the specified column below which `P` percent of the data points fall, it returns approximate value of percentile.
|
||||
Return Data Type: double.
|
||||
Applicable Data Types: all types except `timestamp`, `binary`, `nchar`, `bool`.
|
||||
Applied to: table/STable.
|
||||
Note: The range of `P` is `[0, 100]`. When `P=0` , `APERCENTILE` returns the equal value as `MIN`; when `P=100`, `APERCENTILE` returns the equal value as `MAX`. `APERCENTILE` has a much better performance than `PERCENTILE`.
|
||||
|
||||
- **LAST_ROW**
|
||||
```mysql
|
||||
|
|
|
@ -15,28 +15,15 @@
|
|||
# arbitrator arbitrator_hostname:6030
|
||||
|
||||
# the full-qualified domain name (FQDN) of dnode
|
||||
# fqdn hostname:6030
|
||||
# fqdn hostname
|
||||
|
||||
# port for MNode connect to Client, default udp[6030-6055] tcp[6030]
|
||||
# port for MNode connect to Client, default udp/tcp [6030-6040]
|
||||
# serverPort 6030
|
||||
|
||||
# http service port, default tcp[6020]
|
||||
# http service port, default tcp [6020]
|
||||
# httpPort 6020
|
||||
|
||||
# set socket type ("udp" and "tcp")
|
||||
# the server and client should have the same socket type. Otherwise, connect will fail
|
||||
# sockettype udp
|
||||
|
||||
# for the cluster version, data file's directory is configured this way
|
||||
# option mount_path tier_level
|
||||
# dataDir /mnt/disk1/taos 0
|
||||
# dataDir /mnt/disk2/taos 0
|
||||
# dataDir /mnt/disk3/taos 0
|
||||
# dataDir /mnt/disk4/taos 0
|
||||
# dataDir /mnt/disk5/taos 0
|
||||
# dataDir /mnt/disk6/taos 1
|
||||
# dataDir /mnt/disk7/taos 1
|
||||
# for the stand-alone version, data file's directory is configured this way
|
||||
# data file's directory
|
||||
# dataDir /var/lib/taos
|
||||
|
||||
# log file's directory
|
||||
|
@ -46,12 +33,12 @@
|
|||
# numOfMnodes 3
|
||||
|
||||
# optional roles for dnode. 0 - any, 1 - mnode, 2 - dnode
|
||||
# alternativeRole 0
|
||||
# role 0
|
||||
|
||||
# number of threads per CPU core
|
||||
# numOfThreadsPerCore 1.0
|
||||
|
||||
# number of vgroups per db
|
||||
# max number of vgroups per db
|
||||
# maxVgroupsPerDb 0
|
||||
|
||||
# max number of tables per vnode
|
||||
|
@ -60,9 +47,6 @@
|
|||
# the ratio of threads responsible for querying in the total thread
|
||||
# ratioOfQueryThreads 0.5
|
||||
|
||||
# interval of check load balance when the management node is in normal operation
|
||||
# balanceInterval 300
|
||||
|
||||
# interval of DNode report status to MNode, unit is Second, for cluster version only
|
||||
# statusInterval 1
|
||||
|
||||
|
@ -82,13 +66,13 @@
|
|||
# tableMetaKeepTimer 7200
|
||||
|
||||
# Minimum sliding window time
|
||||
# minSlidingTime 10
|
||||
# minSlidingTime 10
|
||||
|
||||
# Time window minimum
|
||||
# minIntervalTime 10
|
||||
# minIntervalTime 10
|
||||
|
||||
# max length of an SQL
|
||||
# maxSQLLength 65380
|
||||
# maxSQLLength 65480
|
||||
|
||||
# Support the maximum number of records allowed for super table time sorting
|
||||
# maxNumOfOrderedRes 100000
|
||||
|
@ -153,11 +137,8 @@
|
|||
# Stop writing data when the disk size of the log folder is less than this value
|
||||
# minimalDataDirGB 0.1
|
||||
|
||||
# mnode take into account while balance, for cluster version only
|
||||
# mnodeEqualVnodeNum 4
|
||||
|
||||
# number of seconds allowed for a dnode to be offline, for cluster version only
|
||||
# offlineThreshold 864000
|
||||
# offlineThreshold 8640000
|
||||
|
||||
# start http service
|
||||
# http 1
|
||||
|
@ -165,7 +146,7 @@
|
|||
# start system monitor module
|
||||
# monitor 1
|
||||
|
||||
# start http service
|
||||
# start muqq service
|
||||
# mqtt 0
|
||||
|
||||
# mqtt uri
|
||||
|
@ -201,19 +182,22 @@
|
|||
# 131: output warning and error,135: output info, warning and error to log.
|
||||
# 199: output debug, info, warning and error to both screen and file
|
||||
|
||||
# debug flag for basic utils
|
||||
# debugFlag 131
|
||||
# debug flag for all log type, take effect when non-zero value
|
||||
# debugFlag 0
|
||||
|
||||
# debug flag for meta management messages
|
||||
# mDebugFlag 135
|
||||
|
||||
# debug flag for dnode messages
|
||||
# dDebugFlag 131
|
||||
# dDebugFlag 135
|
||||
|
||||
# debug flag for TDengine SDB
|
||||
# debug flag for sync module
|
||||
# sDebugFlag 135
|
||||
|
||||
# debug flag for TDengine SDB
|
||||
# debug flag for WAL
|
||||
# wDebugFlag 135
|
||||
|
||||
# debug flag for SDB
|
||||
# sdbDebugFlag 135
|
||||
|
||||
# debug flag for RPC
|
||||
|
@ -246,6 +230,9 @@
|
|||
# debug flag for query
|
||||
# qDebugflag 131
|
||||
|
||||
# debug flag for vnode
|
||||
# vDebugflag 131
|
||||
|
||||
# debug flag for http server
|
||||
# tsdbDebugFlag 131
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@ ADD_SUBDIRECTORY(client)
|
|||
ADD_SUBDIRECTORY(query)
|
||||
ADD_SUBDIRECTORY(kit)
|
||||
ADD_SUBDIRECTORY(plugins)
|
||||
ADD_SUBDIRECTORY(sync)
|
||||
ADD_SUBDIRECTORY(balance)
|
||||
ADD_SUBDIRECTORY(mnode)
|
||||
ADD_SUBDIRECTORY(vnode)
|
||||
ADD_SUBDIRECTORY(tsdb)
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
PROJECT(TDengine)
|
||||
|
||||
IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/mnode/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/dnode/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/sdb/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_ENTERPRISE_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(inc)
|
||||
AUX_SOURCE_DIRECTORY(src SRC)
|
||||
ADD_LIBRARY(balance ${SRC})
|
||||
ENDIF ()
|
File diff suppressed because it is too large
Load Diff
|
@ -4,11 +4,11 @@ PROJECT(TDengine)
|
|||
INCLUDE_DIRECTORIES(inc)
|
||||
INCLUDE_DIRECTORIES(jni)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_ENTERPRISE_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
|
||||
AUX_SOURCE_DIRECTORY(src SRC)
|
||||
|
||||
IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
|
||||
|
|
|
@ -104,7 +104,7 @@ int tsParseTime(SSQLToken *pToken, int64_t *time, char **next, char *error, int1
|
|||
} else if (strncmp(pToken->z, "0", 1) == 0 && pToken->n == 1) {
|
||||
// do nothing
|
||||
} else if (pToken->type == TK_INTEGER) {
|
||||
useconds = str2int64(pToken->z);
|
||||
useconds = tsosStr2int64(pToken->z);
|
||||
} else {
|
||||
// strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &tm);
|
||||
if (taosParseTime(pToken->z, time, pToken->n, timePrec, tsDaylight) != TSDB_CODE_SUCCESS) {
|
||||
|
|
|
@ -358,7 +358,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
|||
}
|
||||
|
||||
case TSDB_SQL_CFG_DNODE: {
|
||||
const char* msg2 = "invalid configure options or values, such as resetlog / debugFlag 135 / balance 'vnode:1-dnode:2' / monitor 1 ";
|
||||
const char* msg2 = "invalid configure options or values, such as resetlog / debugFlag 135 / balance 'vnode:2-dnode:2' / monitor 1 ";
|
||||
const char* msg3 = "invalid dnode ep";
|
||||
|
||||
/* validate the ip address */
|
||||
|
@ -4700,10 +4700,10 @@ int32_t validateDNodeConfig(tDCLSQL* pOptions) {
|
|||
} else if ((strncasecmp(cfgOptions[tokenBalance].name, pOptionToken->z, pOptionToken->n) == 0) &&
|
||||
(cfgOptions[tokenBalance].len == pOptionToken->n)) {
|
||||
SSQLToken* pValToken = &pOptions->a[2];
|
||||
int32_t vnodeIndex = 0;
|
||||
int32_t dnodeIndex = 0;
|
||||
int32_t vnodeId = 0;
|
||||
int32_t dnodeId = 0;
|
||||
strdequote(pValToken->z);
|
||||
bool parseOk = taosCheckBalanceCfgOptions(pValToken->z, &vnodeIndex, &dnodeIndex);
|
||||
bool parseOk = taosCheckBalanceCfgOptions(pValToken->z, &vnodeId, &dnodeId);
|
||||
if (!parseOk) {
|
||||
return TSDB_CODE_TSC_INVALID_SQL; // options value is invalid
|
||||
}
|
||||
|
|
|
@ -256,11 +256,12 @@ static int tscUpdateSubscription(STscObj* pObj, SSub* pSub) {
|
|||
}
|
||||
size_t numOfTables = taosArrayGetSize(tables);
|
||||
|
||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
||||
SArray* progress = taosArrayInit(numOfTables, sizeof(SSubscriptionProgress));
|
||||
for( size_t i = 0; i < numOfTables; i++ ) {
|
||||
STidTags* tt = taosArrayGet( tables, i );
|
||||
SSubscriptionProgress p = { .uid = tt->uid };
|
||||
p.key = tscGetSubscriptionProgress(pSub, tt->uid, INT64_MIN);
|
||||
p.key = tscGetSubscriptionProgress(pSub, tt->uid, pQueryInfo->window.skey);
|
||||
taosArrayPush(progress, &p);
|
||||
}
|
||||
taosArraySort(progress, tscCompareSubscriptionProgress);
|
||||
|
|
|
@ -220,7 +220,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) {
|
|||
|
||||
if (strlen(tsLocale) == 0) { // locale does not set yet
|
||||
char* defaultLocale = setlocale(LC_CTYPE, "");
|
||||
tstrncpy(tsLocale, defaultLocale, sizeof(tsLocale));
|
||||
tstrncpy(tsLocale, defaultLocale, TSDB_LOCALE_LEN);
|
||||
}
|
||||
|
||||
// set the user specified locale
|
||||
|
@ -234,7 +234,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) {
|
|||
tscInfo("failed to set locale:%s, current locale:%s", pStr, tsLocale);
|
||||
}
|
||||
|
||||
tstrncpy(tsLocale, locale, sizeof(tsLocale));
|
||||
tstrncpy(tsLocale, locale, TSDB_LOCALE_LEN);
|
||||
|
||||
char *charset = strrchr(tsLocale, sep);
|
||||
if (charset != NULL) {
|
||||
|
@ -249,7 +249,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) {
|
|||
tscInfo("charset changed from %s to %s", tsCharset, charset);
|
||||
}
|
||||
|
||||
tstrncpy(tsCharset, charset, sizeof(tsCharset));
|
||||
tstrncpy(tsCharset, charset, TSDB_LOCALE_LEN);
|
||||
cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION;
|
||||
|
||||
} else {
|
||||
|
@ -286,7 +286,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) {
|
|||
tscInfo("charset changed from %s to %s", tsCharset, pStr);
|
||||
}
|
||||
|
||||
tstrncpy(tsCharset, pStr, sizeof(tsCharset));
|
||||
tstrncpy(tsCharset, pStr, TSDB_LOCALE_LEN);
|
||||
cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION;
|
||||
} else {
|
||||
tscInfo("charset:%s not valid", pStr);
|
||||
|
@ -304,7 +304,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) {
|
|||
assert(cfg != NULL);
|
||||
|
||||
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) {
|
||||
tstrncpy(tsTimezone, pStr, sizeof(tsTimezone));
|
||||
tstrncpy(tsTimezone, pStr, TSDB_TIMEZONE_LEN);
|
||||
tsSetTimeZone();
|
||||
cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION;
|
||||
tscDebug("timezone set:%s, input:%s by taos_options", tsTimezone, pStr);
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
PROJECT(TDengine)
|
||||
|
||||
IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
|
||||
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(inc)
|
||||
AUX_SOURCE_DIRECTORY(src SRC)
|
||||
ADD_LIBRARY(common ${SRC})
|
||||
TARGET_LINK_LIBRARIES(common tutil)
|
||||
ENDIF ()
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(inc)
|
||||
|
||||
AUX_SOURCE_DIRECTORY(src SRC)
|
||||
ADD_LIBRARY(common ${SRC})
|
||||
TARGET_LINK_LIBRARIES(common tutil)
|
||||
|
|
|
@ -43,9 +43,9 @@ extern uint32_t tsMaxTmrCtrl;
|
|||
extern float tsNumOfThreadsPerCore;
|
||||
extern float tsRatioOfQueryThreads;
|
||||
extern int8_t tsDaylight;
|
||||
extern char tsTimezone[64];
|
||||
extern char tsLocale[64];
|
||||
extern char tsCharset[64]; // default encode string
|
||||
extern char tsTimezone[];
|
||||
extern char tsLocale[];
|
||||
extern char tsCharset[]; // default encode string
|
||||
extern int32_t tsEnableCoreFile;
|
||||
extern int32_t tsCompressMsgSize;
|
||||
|
||||
|
@ -174,7 +174,7 @@ bool taosCheckGlobalCfg();
|
|||
void taosSetAllDebugFlag();
|
||||
bool taosCfgDynamicOptions(char *msg);
|
||||
int taosGetFqdnPortFromEp(const char *ep, char *fqdn, uint16_t *port);
|
||||
bool taosCheckBalanceCfgOptions(const char *option, int32_t *vnodeIndex, int32_t *dnodeIndex);
|
||||
bool taosCheckBalanceCfgOptions(const char *option, int32_t *vnodeId, int32_t *dnodeId);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ int32_t tsShellActivityTimer = 3; // second
|
|||
float tsNumOfThreadsPerCore = 1.0;
|
||||
float tsRatioOfQueryThreads = 0.5;
|
||||
int8_t tsDaylight = 0;
|
||||
char tsTimezone[64] = {0};
|
||||
char tsTimezone[TSDB_TIMEZONE_LEN] = {0};
|
||||
char tsLocale[TSDB_LOCALE_LEN] = {0};
|
||||
char tsCharset[TSDB_LOCALE_LEN] = {0}; // default encode string
|
||||
int32_t tsEnableCoreFile = 0;
|
||||
|
@ -1315,7 +1315,7 @@ int taosGetFqdnPortFromEp(const char *ep, char *fqdn, uint16_t *port) {
|
|||
* alter dnode 1 balance "vnode:1-dnode:2"
|
||||
*/
|
||||
|
||||
bool taosCheckBalanceCfgOptions(const char *option, int32_t *vnodeIndex, int32_t *dnodeIndex) {
|
||||
bool taosCheckBalanceCfgOptions(const char *option, int32_t *vnodeId, int32_t *dnodeId) {
|
||||
int len = strlen(option);
|
||||
if (strncasecmp(option, "vnode:", 6) != 0) {
|
||||
return false;
|
||||
|
@ -1331,9 +1331,9 @@ bool taosCheckBalanceCfgOptions(const char *option, int32_t *vnodeIndex, int32_t
|
|||
return false;
|
||||
}
|
||||
|
||||
*vnodeIndex = strtol(option + 6, NULL, 10);
|
||||
*dnodeIndex = strtol(option + pos + 6, NULL, 10);
|
||||
if (*vnodeIndex <= 1 || *dnodeIndex <= 0) {
|
||||
*vnodeId = strtol(option + 6, NULL, 10);
|
||||
*dnodeId = strtol(option + pos + 6, NULL, 10);
|
||||
if (*vnodeId <= 1 || *dnodeId <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
PROJECT(TDengine)
|
||||
|
||||
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc)
|
||||
INCLUDE_DIRECTORIES(inc)
|
||||
|
|
|
@ -1,17 +1,12 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
PROJECT(TDengine)
|
||||
|
||||
IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
|
||||
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc)
|
||||
INCLUDE_DIRECTORIES(../inc)
|
||||
|
||||
LIST(APPEND CQTEST_SRC ./cqtest.c)
|
||||
ADD_EXECUTABLE(cqtest ${CQTEST_SRC})
|
||||
TARGET_LINK_LIBRARIES(cqtest tcq)
|
||||
|
||||
ENDIF ()
|
||||
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/cq/inc)
|
||||
|
||||
LIST(APPEND CQTEST_SRC ./cqtest.c)
|
||||
ADD_EXECUTABLE(cqtest ${CQTEST_SRC})
|
||||
TARGET_LINK_LIBRARIES(cqtest tcq)
|
||||
|
|
|
@ -2,8 +2,8 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
|||
PROJECT(TDengine)
|
||||
|
||||
IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
|
||||
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/mnode/inc)
|
||||
|
@ -16,7 +16,7 @@ IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
|
|||
AUX_SOURCE_DIRECTORY(src SRC)
|
||||
|
||||
ADD_EXECUTABLE(taosd ${SRC})
|
||||
TARGET_LINK_LIBRARIES(taosd mnode taos_static monitor http mqtt tsdb twal vnode cJson lz4)
|
||||
TARGET_LINK_LIBRARIES(taosd mnode taos_static monitor http mqtt tsdb twal vnode cJson lz4 balance sync)
|
||||
|
||||
IF (TD_ACCOUNT)
|
||||
TARGET_LINK_LIBRARIES(taosd account)
|
||||
|
@ -26,10 +26,6 @@ IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
|
|||
TARGET_LINK_LIBRARIES(taosd grant)
|
||||
ENDIF ()
|
||||
|
||||
IF (TD_SYNC)
|
||||
TARGET_LINK_LIBRARIES(taosd balance sync)
|
||||
ENDIF ()
|
||||
|
||||
SET(PREPARE_ENV_CMD "prepare_env_cmd")
|
||||
SET(PREPARE_ENV_TARGET "prepare_env_target")
|
||||
ADD_CUSTOM_COMMAND(OUTPUT ${PREPARE_ENV_CMD}
|
||||
|
|
|
@ -492,6 +492,7 @@ static void dnodeProcessStatusRsp(SRpcMsg *pMsg) {
|
|||
pCfg->numOfVnodes = htonl(pCfg->numOfVnodes);
|
||||
pCfg->moduleStatus = htonl(pCfg->moduleStatus);
|
||||
pCfg->dnodeId = htonl(pCfg->dnodeId);
|
||||
pCfg->clusterId = htonl(pCfg->clusterId);
|
||||
|
||||
for (int32_t i = 0; i < pMnodes->nodeNum; ++i) {
|
||||
SDMMnodeInfo *pMnodeInfo = &pMnodes->nodeInfos[i];
|
||||
|
@ -697,6 +698,7 @@ static void dnodeSendStatusMsg(void *handle, void *tmrId) {
|
|||
//strcpy(pStatus->dnodeName, tsDnodeName);
|
||||
pStatus->version = htonl(tsVersion);
|
||||
pStatus->dnodeId = htonl(tsDnodeCfg.dnodeId);
|
||||
pStatus->clusterId = htonl(tsDnodeCfg.clusterId);
|
||||
strcpy(pStatus->dnodeEp, tsLocalEp);
|
||||
pStatus->lastReboot = htonl(tsRebootTime);
|
||||
pStatus->numOfCores = htons((uint16_t) tsNumOfCores);
|
||||
|
@ -767,6 +769,13 @@ static bool dnodeReadDnodeCfg() {
|
|||
}
|
||||
tsDnodeCfg.dnodeId = dnodeId->valueint;
|
||||
|
||||
cJSON* clusterId = cJSON_GetObjectItem(root, "clusterId");
|
||||
if (!clusterId || clusterId->type != cJSON_Number) {
|
||||
dError("failed to read dnodeCfg.json, clusterId not found");
|
||||
goto PARSE_CFG_OVER;
|
||||
}
|
||||
tsDnodeCfg.clusterId = clusterId->valueint;
|
||||
|
||||
ret = true;
|
||||
|
||||
dInfo("read numOfVnodes successed, dnodeId:%d", tsDnodeCfg.dnodeId);
|
||||
|
@ -790,7 +799,8 @@ static void dnodeSaveDnodeCfg() {
|
|||
char * content = calloc(1, maxLen + 1);
|
||||
|
||||
len += snprintf(content + len, maxLen - len, "{\n");
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d\n", tsDnodeCfg.dnodeId);
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d,\n", tsDnodeCfg.dnodeId);
|
||||
len += snprintf(content + len, maxLen - len, " \"clusterId\": %d\n", tsDnodeCfg.clusterId);
|
||||
len += snprintf(content + len, maxLen - len, "}\n");
|
||||
|
||||
fwrite(content, 1, len, fp);
|
||||
|
@ -803,8 +813,9 @@ static void dnodeSaveDnodeCfg() {
|
|||
|
||||
void dnodeUpdateDnodeCfg(SDMDnodeCfg *pCfg) {
|
||||
if (tsDnodeCfg.dnodeId == 0) {
|
||||
dInfo("dnodeId is set to %d", pCfg->dnodeId);
|
||||
dInfo("dnodeId is set to %d, clusterId is set to %d", pCfg->dnodeId, pCfg->clusterId);
|
||||
tsDnodeCfg.dnodeId = pCfg->dnodeId;
|
||||
tsDnodeCfg.clusterId = pCfg->clusterId;
|
||||
dnodeSaveDnodeCfg();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#include "tglobal.h"
|
||||
#include "dnodeInt.h"
|
||||
#include "dnodeMain.h"
|
||||
#include "tfile.h"
|
||||
|
||||
static void signal_handler(int32_t signum, siginfo_t *sigInfo, void *context);
|
||||
static sem_t exitSem;
|
||||
|
@ -40,7 +39,7 @@ int32_t main(int32_t argc, char *argv[]) {
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
} else if (strcmp(argv[i], "-V") == 0) {
|
||||
#ifdef _SYNC
|
||||
#ifdef _ACCT
|
||||
char *versionStr = "enterprise";
|
||||
#else
|
||||
char *versionStr = "community";
|
||||
|
|
|
@ -250,7 +250,7 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size);
|
|||
#define TSDB_STATE_LEN 20
|
||||
#define TSDB_COUNTRY_LEN 20
|
||||
#define TSDB_LOCALE_LEN 64
|
||||
#define TSDB_TIMEZONE_LEN 64
|
||||
#define TSDB_TIMEZONE_LEN 96
|
||||
#define TSDB_LABEL_LEN 8
|
||||
|
||||
#define TSDB_FQDN_LEN 128
|
||||
|
@ -377,6 +377,7 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size);
|
|||
#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
|
||||
|
|
|
@ -120,12 +120,18 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_OBJ_NOT_THERE, 0, 0x0323, "sdb object
|
|||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_INVAID_META_ROW, 0, 0x0324, "sdb invalid meta row")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_INVAID_KEY_TYPE, 0, 0x0325, "sdb invalid key type")
|
||||
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_ALREADY_EXIST, 0, 0x0330, "mnode dnode already exist")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_NOT_EXIST, 0, 0x0331, "mnode dnode not exist")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_VGROUP_NOT_EXIST, 0, 0x0332, "mnode vgroup not exist")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_NO_REMOVE_MASTER, 0, 0x0333, "mnode cant not remove master")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_NO_ENOUGH_DNODES, 0, 0x0334, "mnode no enough dnodes")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_CLUSTER_CFG_INCONSISTENT, 0, 0x0335, "mnode cluster cfg inconsistent")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_ALREADY_EXIST, 0, 0x0330, "dnode already exist")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_NOT_EXIST, 0, 0x0331, "dnode not exist")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_VGROUP_NOT_EXIST, 0, 0x0332, "vgroup not exist")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_NO_REMOVE_MASTER, 0, 0x0333, "cant not remove master")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_NO_ENOUGH_DNODES, 0, 0x0334, "no enough dnodes")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_CLUSTER_CFG_INCONSISTENT, 0, 0x0335, "cluster cfg inconsistent")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_DNODE_CFG_OPTION, 0, 0x0336, "invalid dnode cfg option")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_BALANCE_ENABLED, 0, 0x0337, "balance already enabled")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_VGROUP_NOT_IN_DNODE, 0, 0x0338, "vgroup not in dnode")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_VGROUP_ALREADY_IN_DNODE, 0, 0x0339, "vgroup already in dnode")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_NOT_FREE, 0, 0x033A, "dnode not avaliable")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_CLUSTER_ID, 0, 0x033B, "cluster id not match")
|
||||
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_ACCT_ALREADY_EXIST, 0, 0x0340, "mnode accounts already exist")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_ACCT, 0, 0x0341, "mnode invalid account")
|
||||
|
|
|
@ -139,6 +139,7 @@ enum _mgmt_table {
|
|||
TSDB_MGMT_TABLE_GRANTS,
|
||||
TSDB_MGMT_TABLE_VNODES,
|
||||
TSDB_MGMT_TABLE_STREAMTABLES,
|
||||
TSDB_MGMT_TABLE_CLUSTER,
|
||||
TSDB_MGMT_TABLE_MAX,
|
||||
};
|
||||
|
||||
|
@ -149,6 +150,7 @@ enum _mgmt_table {
|
|||
|
||||
#define TSDB_ALTER_TABLE_ADD_COLUMN 5
|
||||
#define TSDB_ALTER_TABLE_DROP_COLUMN 6
|
||||
#define TSDB_ALTER_TABLE_CHANGE_COLUMN 7
|
||||
|
||||
#define TSDB_FILL_NONE 0
|
||||
#define TSDB_FILL_NULL 1
|
||||
|
@ -545,6 +547,7 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
int32_t clusterId;
|
||||
uint32_t moduleStatus;
|
||||
uint32_t numOfVnodes;
|
||||
uint32_t reserved;
|
||||
|
@ -585,6 +588,7 @@ typedef struct {
|
|||
uint16_t openVnodes;
|
||||
uint16_t numOfCores;
|
||||
float diskAvailable; // GB
|
||||
int32_t clusterId;
|
||||
uint8_t alternativeRole;
|
||||
uint8_t reserve2[15];
|
||||
SClusterCfg clusterCfg;
|
||||
|
|
|
@ -29,7 +29,7 @@ void balanceAsyncNotify();
|
|||
void balanceSyncNotify();
|
||||
void balanceReset();
|
||||
int32_t balanceAllocVnodes(struct SVgObj *pVgroup);
|
||||
int32_t balanceCfgDnode(struct SDnodeObj *pDnode, const char *option);
|
||||
int32_t balanceAlterDnode(struct SDnodeObj *pDnode, int32_t vnodeId, int32_t dnodeId);
|
||||
int32_t balanceDropDnode(struct SDnodeObj *pDnode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -2,11 +2,11 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
|||
PROJECT(TDengine)
|
||||
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
|
||||
INCLUDE_DIRECTORIES(inc)
|
||||
|
||||
IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
|
||||
|
|
|
@ -2,9 +2,9 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
|||
PROJECT(TDengine)
|
||||
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
|
||||
INCLUDE_DIRECTORIES(inc)
|
||||
|
||||
IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
|
||||
|
|
|
@ -2,11 +2,11 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
|||
PROJECT(TDengine)
|
||||
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
|
||||
INCLUDE_DIRECTORIES(inc)
|
||||
|
||||
IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
|
||||
|
|
|
@ -545,7 +545,7 @@ int32_t taosSaveAllNormalTableToTempFile(TAOS *taosCon, char*meter, char* metric
|
|||
strcpy(tableRecord.name, meter);
|
||||
strcpy(tableRecord.metric, metric);
|
||||
|
||||
twrite(*fd, &tableRecord, sizeof(STableRecord));
|
||||
taosTWrite(*fd, &tableRecord, sizeof(STableRecord));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -600,7 +600,7 @@ int32_t taosSaveTableOfMetricToTempFile(TAOS *taosCon, char* metric, struct argu
|
|||
strncpy(tableRecord.name, (char *)row[0], fields[0].bytes);
|
||||
strcpy(tableRecord.metric, metric);
|
||||
|
||||
twrite(fd, &tableRecord, sizeof(STableRecord));
|
||||
taosTWrite(fd, &tableRecord, sizeof(STableRecord));
|
||||
|
||||
numOfTable++;
|
||||
|
||||
|
@ -1196,7 +1196,7 @@ int32_t taosDumpCreateSuperTableClause(TAOS* taosCon, char* dbName, FILE *fp)
|
|||
while ((row = taos_fetch_row(tmpResult)) != NULL) {
|
||||
memset(&tableRecord, 0, sizeof(STableRecord));
|
||||
strncpy(tableRecord.name, (char *)row[TSDB_SHOW_TABLES_NAME_INDEX], fields[TSDB_SHOW_TABLES_NAME_INDEX].bytes);
|
||||
twrite(fd, &tableRecord, sizeof(STableRecord));
|
||||
taosTWrite(fd, &tableRecord, sizeof(STableRecord));
|
||||
}
|
||||
|
||||
taos_free_result(tmpResult);
|
||||
|
@ -1282,7 +1282,7 @@ int taosDumpDb(SDbInfo *dbInfo, struct arguments *arguments, FILE *fp, TAOS *tao
|
|||
strncpy(tableRecord.name, (char *)row[TSDB_SHOW_TABLES_NAME_INDEX], fields[TSDB_SHOW_TABLES_NAME_INDEX].bytes);
|
||||
strncpy(tableRecord.metric, (char *)row[TSDB_SHOW_TABLES_METRIC_INDEX], fields[TSDB_SHOW_TABLES_METRIC_INDEX].bytes);
|
||||
|
||||
twrite(fd, &tableRecord, sizeof(STableRecord));
|
||||
taosTWrite(fd, &tableRecord, sizeof(STableRecord));
|
||||
|
||||
numOfTable++;
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
|||
PROJECT(TDengine)
|
||||
|
||||
IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
|
||||
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/mnode/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/vnode/inc)
|
||||
|
|
|
@ -2,8 +2,8 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
|||
PROJECT(TDengine)
|
||||
|
||||
IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
|
||||
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc)
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_MNODE_CLUSTER_H
|
||||
#define TDENGINE_MNODE_CLUSTER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct SClusterObj;
|
||||
|
||||
int32_t mnodeInitCluster();
|
||||
void mnodeCleanupCluster();
|
||||
int32_t mnodeGetClusterId();
|
||||
void mnodeUpdateClusterId();
|
||||
void * mnodeGetCluster(int32_t clusterId);
|
||||
void * mnodeGetNextCluster(void *pIter, struct SClusterObj **pCluster);
|
||||
void mnodeIncClusterRef(struct SClusterObj *pCluster);
|
||||
void mnodeDecClusterRef(struct SClusterObj *pCluster);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -36,6 +36,14 @@ struct define notes:
|
|||
3. The fields behind the updataEnd field can be changed;
|
||||
*/
|
||||
|
||||
typedef struct SClusterObj {
|
||||
int32_t clusterId;
|
||||
int64_t createdTime;
|
||||
int8_t reserved[36];
|
||||
int8_t updateEnd[4];
|
||||
int32_t refCount;
|
||||
} SClusterObj;
|
||||
|
||||
typedef struct SDnodeObj {
|
||||
int32_t dnodeId;
|
||||
int32_t openVnodes;
|
||||
|
|
|
@ -23,15 +23,16 @@ extern "C" {
|
|||
struct SMnodeMsg;
|
||||
|
||||
typedef enum {
|
||||
SDB_TABLE_DNODE = 0,
|
||||
SDB_TABLE_MNODE = 1,
|
||||
SDB_TABLE_ACCOUNT = 2,
|
||||
SDB_TABLE_USER = 3,
|
||||
SDB_TABLE_DB = 4,
|
||||
SDB_TABLE_VGROUP = 5,
|
||||
SDB_TABLE_STABLE = 6,
|
||||
SDB_TABLE_CTABLE = 7,
|
||||
SDB_TABLE_MAX = 8
|
||||
SDB_TABLE_CLUSTER = 0,
|
||||
SDB_TABLE_DNODE = 1,
|
||||
SDB_TABLE_MNODE = 2,
|
||||
SDB_TABLE_ACCOUNT = 3,
|
||||
SDB_TABLE_USER = 4,
|
||||
SDB_TABLE_DB = 5,
|
||||
SDB_TABLE_VGROUP = 6,
|
||||
SDB_TABLE_STABLE = 7,
|
||||
SDB_TABLE_CTABLE = 8,
|
||||
SDB_TABLE_MAX = 9
|
||||
} ESdbTable;
|
||||
|
||||
typedef enum {
|
||||
|
|
|
@ -64,7 +64,7 @@ static int32_t mnodeAcctActionUpdate(SSdbOper *pOper) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeActionActionEncode(SSdbOper *pOper) {
|
||||
static int32_t mnodeAcctActionEncode(SSdbOper *pOper) {
|
||||
SAcctObj *pAcct = pOper->pObj;
|
||||
memcpy(pOper->rowData, pAcct, tsAcctUpdateSize);
|
||||
pOper->rowSize = tsAcctUpdateSize;
|
||||
|
@ -109,7 +109,7 @@ int32_t mnodeInitAccts() {
|
|||
.insertFp = mnodeAcctActionInsert,
|
||||
.deleteFp = mnodeAcctActionDelete,
|
||||
.updateFp = mnodeAcctActionUpdate,
|
||||
.encodeFp = mnodeActionActionEncode,
|
||||
.encodeFp = mnodeAcctActionEncode,
|
||||
.decodeFp = mnodeAcctActionDecode,
|
||||
.destroyFp = mnodeAcctActionDestroy,
|
||||
.restoredFp = mnodeAcctActionRestored
|
||||
|
|
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tglobal.h"
|
||||
#include "mnodeDef.h"
|
||||
#include "mnodeInt.h"
|
||||
#include "mnodeDnode.h"
|
||||
#include "mnodeSdb.h"
|
||||
|
||||
#ifndef _SYNC
|
||||
|
||||
int32_t balanceInit() { return TSDB_CODE_SUCCESS; }
|
||||
void balanceCleanUp() {}
|
||||
void balanceAsyncNotify() {}
|
||||
void balanceSyncNotify() {}
|
||||
void balanceReset() {}
|
||||
int32_t balanceCfgDnode(struct SDnodeObj *pDnode, const char *option) { return TSDB_CODE_SYN_NOT_ENABLED; }
|
||||
|
||||
int32_t balanceAllocVnodes(SVgObj *pVgroup) {
|
||||
void * pIter = NULL;
|
||||
SDnodeObj *pDnode = NULL;
|
||||
SDnodeObj *pSelDnode = NULL;
|
||||
float vnodeUsage = 1000.0;
|
||||
|
||||
while (1) {
|
||||
pIter = mnodeGetNextDnode(pIter, &pDnode);
|
||||
if (pDnode == NULL) break;
|
||||
|
||||
if (pDnode->numOfCores > 0 && pDnode->openVnodes < TSDB_MAX_VNODES) {
|
||||
float openVnodes = pDnode->openVnodes;
|
||||
if (pDnode->isMgmt) openVnodes += tsMnodeEqualVnodeNum;
|
||||
|
||||
float usage = openVnodes / pDnode->numOfCores;
|
||||
if (usage <= vnodeUsage) {
|
||||
pSelDnode = pDnode;
|
||||
vnodeUsage = usage;
|
||||
}
|
||||
}
|
||||
mnodeDecDnodeRef(pDnode);
|
||||
}
|
||||
|
||||
sdbFreeIter(pIter);
|
||||
|
||||
if (pSelDnode == NULL) {
|
||||
mError("failed to alloc vnode to vgroup");
|
||||
return TSDB_CODE_MND_NO_ENOUGH_DNODES;
|
||||
}
|
||||
|
||||
pVgroup->vnodeGid[0].dnodeId = pSelDnode->dnodeId;
|
||||
pVgroup->vnodeGid[0].pDnode = pSelDnode;
|
||||
|
||||
mDebug("dnode:%d, alloc one vnode to vgroup, openVnodes:%d", pSelDnode->dnodeId, pSelDnode->openVnodes);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,230 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "taoserror.h"
|
||||
#include "ttime.h"
|
||||
#include "dnode.h"
|
||||
#include "mnodeDef.h"
|
||||
#include "mnodeInt.h"
|
||||
#include "mnodeCluster.h"
|
||||
#include "mnodeSdb.h"
|
||||
#include "mnodeShow.h"
|
||||
#include "tglobal.h"
|
||||
|
||||
static void * tsClusterSdb = NULL;
|
||||
static int32_t tsClusterUpdateSize;
|
||||
static int32_t tsClusterId;
|
||||
static int32_t mnodeCreateCluster();
|
||||
|
||||
static int32_t mnodeGetClusterMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
||||
static int32_t mnodeRetrieveClusters(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
||||
|
||||
static int32_t mnodeClusterActionDestroy(SSdbOper *pOper) {
|
||||
tfree(pOper->pObj);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeClusterActionInsert(SSdbOper *pOper) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeClusterActionDelete(SSdbOper *pOper) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeClusterActionUpdate(SSdbOper *pOper) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeClusterActionEncode(SSdbOper *pOper) {
|
||||
SClusterObj *pCluster = pOper->pObj;
|
||||
memcpy(pOper->rowData, pCluster, tsClusterUpdateSize);
|
||||
pOper->rowSize = tsClusterUpdateSize;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeClusterActionDecode(SSdbOper *pOper) {
|
||||
SClusterObj *pCluster = (SClusterObj *) calloc(1, sizeof(SClusterObj));
|
||||
if (pCluster == NULL) return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||
|
||||
memcpy(pCluster, pOper->rowData, tsClusterUpdateSize);
|
||||
pOper->pObj = pCluster;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mnodeClusterActionRestored() {
|
||||
int32_t numOfRows = sdbGetNumOfRows(tsClusterSdb);
|
||||
if (numOfRows <= 0 && dnodeIsFirstDeploy()) {
|
||||
mInfo("dnode first deploy, create cluster");
|
||||
int32_t code = mnodeCreateCluster();
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
mError("failed to create cluster, reason:%s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
mnodeUpdateClusterId();
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t mnodeInitCluster() {
|
||||
SClusterObj tObj;
|
||||
tsClusterUpdateSize = (int8_t *)tObj.updateEnd - (int8_t *)&tObj;
|
||||
|
||||
SSdbTableDesc tableDesc = {
|
||||
.tableId = SDB_TABLE_CLUSTER,
|
||||
.tableName = "cluster",
|
||||
.hashSessions = TSDB_DEFAULT_CLUSTER_HASH_SIZE,
|
||||
.maxRowSize = tsClusterUpdateSize,
|
||||
.refCountPos = (int8_t *)(&tObj.refCount) - (int8_t *)&tObj,
|
||||
.keyType = SDB_KEY_INT,
|
||||
.insertFp = mnodeClusterActionInsert,
|
||||
.deleteFp = mnodeClusterActionDelete,
|
||||
.updateFp = mnodeClusterActionUpdate,
|
||||
.encodeFp = mnodeClusterActionEncode,
|
||||
.decodeFp = mnodeClusterActionDecode,
|
||||
.destroyFp = mnodeClusterActionDestroy,
|
||||
.restoredFp = mnodeClusterActionRestored
|
||||
};
|
||||
|
||||
tsClusterSdb = sdbOpenTable(&tableDesc);
|
||||
if (tsClusterSdb == NULL) {
|
||||
mError("table:%s, failed to create hash", tableDesc.tableName);
|
||||
return -1;
|
||||
}
|
||||
|
||||
mnodeAddShowMetaHandle(TSDB_MGMT_TABLE_CLUSTER, mnodeGetClusterMeta);
|
||||
mnodeAddShowRetrieveHandle(TSDB_MGMT_TABLE_CLUSTER, mnodeRetrieveClusters);
|
||||
|
||||
mDebug("table:%s, hash is created", tableDesc.tableName);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void mnodeCleanupCluster() {
|
||||
sdbCloseTable(tsClusterSdb);
|
||||
tsClusterSdb = NULL;
|
||||
}
|
||||
|
||||
void *mnodeGetCluster(int32_t clusterId) {
|
||||
return sdbGetRow(tsClusterSdb, &clusterId);
|
||||
}
|
||||
|
||||
void *mnodeGetNextCluster(void *pIter, SClusterObj **pCluster) {
|
||||
return sdbFetchRow(tsClusterSdb, pIter, (void **)pCluster);
|
||||
}
|
||||
|
||||
void mnodeIncClusterRef(SClusterObj *pCluster) {
|
||||
sdbIncRef(tsClusterSdb, pCluster);
|
||||
}
|
||||
|
||||
void mnodeDecClusterRef(SClusterObj *pCluster) {
|
||||
sdbDecRef(tsClusterSdb, pCluster);
|
||||
}
|
||||
|
||||
static int32_t mnodeCreateCluster() {
|
||||
int32_t numOfClusters = sdbGetNumOfRows(tsClusterSdb);
|
||||
if (numOfClusters != 0) return TSDB_CODE_SUCCESS;
|
||||
|
||||
SClusterObj *pCluster = malloc(sizeof(SClusterObj));
|
||||
memset(pCluster, 0, sizeof(SClusterObj));
|
||||
pCluster->createdTime = taosGetTimestampMs();
|
||||
pCluster->clusterId = labs((pCluster->createdTime >> 32) & (pCluster->createdTime)) | (*(int32_t*)tsFirst);
|
||||
|
||||
SSdbOper oper = {
|
||||
.type = SDB_OPER_GLOBAL,
|
||||
.table = tsClusterSdb,
|
||||
.pObj = pCluster,
|
||||
};
|
||||
|
||||
return sdbInsertRow(&oper);
|
||||
}
|
||||
|
||||
int32_t mnodeGetClusterId() {
|
||||
return tsClusterId;
|
||||
}
|
||||
|
||||
void mnodeUpdateClusterId() {
|
||||
SClusterObj *pCluster = NULL;
|
||||
mnodeGetNextCluster(NULL, &pCluster);
|
||||
if (pCluster != NULL) {
|
||||
tsClusterId = pCluster->clusterId;
|
||||
mnodeDecClusterRef(pCluster);
|
||||
mInfo("cluster id is %d", tsClusterId);
|
||||
} else {
|
||||
//assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int32_t mnodeGetClusterMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
||||
int32_t cols = 0;
|
||||
SSchema *pSchema = pMeta->schema;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "clusterId");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
strcpy(pSchema[cols].name, "create_time");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pMeta->numOfColumns = htons(cols);
|
||||
strcpy(pMeta->tableId, "show cluster");
|
||||
pShow->numOfColumns = cols;
|
||||
|
||||
pShow->offset[0] = 0;
|
||||
for (int32_t i = 1; i < cols; ++i) {
|
||||
pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1];
|
||||
}
|
||||
|
||||
pShow->numOfRows = 1;
|
||||
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mnodeRetrieveClusters(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
|
||||
int32_t numOfRows = 0;
|
||||
int32_t cols = 0;
|
||||
char * pWrite;
|
||||
SClusterObj *pCluster = NULL;
|
||||
|
||||
while (numOfRows < rows) {
|
||||
pShow->pIter = mnodeGetNextCluster(pShow->pIter, &pCluster);
|
||||
if (pCluster == NULL) break;
|
||||
|
||||
cols = 0;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int32_t *) pWrite = pCluster->clusterId;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int32_t *) pWrite = pCluster->createdTime;
|
||||
cols++;
|
||||
|
||||
mnodeDecClusterRef(pCluster);
|
||||
numOfRows++;
|
||||
}
|
||||
|
||||
pShow->numOfReads += numOfRows;
|
||||
return numOfRows;
|
||||
}
|
|
@ -301,13 +301,6 @@ static int32_t mnodeCheckDbCfg(SDbCfg *pCfg) {
|
|||
return TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
}
|
||||
|
||||
#ifndef _SYNC
|
||||
if (pCfg->replications != 1) {
|
||||
mError("invalid db option replications:%d can only be 1 in this version", pCfg->replications);
|
||||
return TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
}
|
||||
#endif
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "mnodeVgroup.h"
|
||||
#include "mnodeWrite.h"
|
||||
#include "mnodePeer.h"
|
||||
#include "mnodeCluster.h"
|
||||
|
||||
int32_t tsAccessSquence = 0;
|
||||
static void *tsDnodeSdb = NULL;
|
||||
|
@ -78,9 +79,6 @@ static int32_t mnodeDnodeActionInsert(SSdbOper *pOper) {
|
|||
static int32_t mnodeDnodeActionDelete(SSdbOper *pOper) {
|
||||
SDnodeObj *pDnode = pOper->pObj;
|
||||
|
||||
#ifndef _SYNC
|
||||
mnodeDropAllDnodeVgroups(pDnode);
|
||||
#endif
|
||||
mnodeDropMnodeLocal(pDnode->dnodeId);
|
||||
balanceAsyncNotify();
|
||||
|
||||
|
@ -295,10 +293,19 @@ static int32_t mnodeProcessCfgDnodeMsg(SMnodeMsg *pMsg) {
|
|||
}
|
||||
|
||||
SRpcEpSet epSet = mnodeGetEpSetFromIp(pDnode->dnodeEp);
|
||||
mnodeDecDnodeRef(pDnode);
|
||||
|
||||
if (strncasecmp(pCmCfgDnode->config, "balance", 7) == 0) {
|
||||
return balanceCfgDnode(pDnode, pCmCfgDnode->config + 8);
|
||||
int32_t vnodeId = 0;
|
||||
int32_t dnodeId = 0;
|
||||
bool parseOk = taosCheckBalanceCfgOptions(pCmCfgDnode->config + 8, &vnodeId, &dnodeId);
|
||||
if (!parseOk) {
|
||||
mnodeDecDnodeRef(pDnode);
|
||||
return TSDB_CODE_MND_INVALID_DNODE_CFG_OPTION;
|
||||
}
|
||||
|
||||
int32_t code = balanceAlterDnode(pDnode, vnodeId, dnodeId);
|
||||
mnodeDecDnodeRef(pDnode);
|
||||
return code;
|
||||
} else {
|
||||
SMDCfgDnodeMsg *pMdCfgDnode = rpcMallocCont(sizeof(SMDCfgDnodeMsg));
|
||||
strcpy(pMdCfgDnode->ep, pCmCfgDnode->ep);
|
||||
|
@ -314,6 +321,7 @@ static int32_t mnodeProcessCfgDnodeMsg(SMnodeMsg *pMsg) {
|
|||
|
||||
mInfo("dnode:%s, is configured by %s", pCmCfgDnode->ep, pMsg->pUser->user);
|
||||
dnodeSendMsgToDnode(&epSet, &rpcMdCfgDnodeMsg);
|
||||
mnodeDecDnodeRef(pDnode);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -345,6 +353,7 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) {
|
|||
pStatus->moduleStatus = htonl(pStatus->moduleStatus);
|
||||
pStatus->lastReboot = htonl(pStatus->lastReboot);
|
||||
pStatus->numOfCores = htons(pStatus->numOfCores);
|
||||
pStatus->clusterId = htonl(pStatus->clusterId);
|
||||
|
||||
uint32_t version = htonl(pStatus->version);
|
||||
if (version != tsVersion) {
|
||||
|
@ -372,13 +381,19 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) {
|
|||
pDnode->diskAvailable = pStatus->diskAvailable;
|
||||
pDnode->alternativeRole = pStatus->alternativeRole;
|
||||
pDnode->moduleStatus = pStatus->moduleStatus;
|
||||
|
||||
|
||||
if (pStatus->dnodeId == 0) {
|
||||
mDebug("dnode:%d %s, first access", pDnode->dnodeId, pDnode->dnodeEp);
|
||||
mDebug("dnode:%d %s, first access, set clusterId %d", pDnode->dnodeId, pDnode->dnodeEp, mnodeGetClusterId());
|
||||
} else {
|
||||
mTrace("dnode:%d, status received, access times %d", pDnode->dnodeId, pDnode->lastAccess);
|
||||
if (pStatus->clusterId != mnodeGetClusterId()) {
|
||||
mError("dnode:%d, input clusterId %d not match with exist %d", pDnode->dnodeId, pStatus->clusterId,
|
||||
mnodeGetClusterId());
|
||||
return TSDB_CODE_MND_INVALID_CLUSTER_ID;
|
||||
} else {
|
||||
mTrace("dnode:%d, status received, access times %d", pDnode->dnodeId, pDnode->lastAccess);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int32_t openVnodes = htons(pStatus->openVnodes);
|
||||
int32_t contLen = sizeof(SDMStatusRsp) + openVnodes * sizeof(SDMVgroupAccess);
|
||||
SDMStatusRsp *pRsp = rpcMallocCont(contLen);
|
||||
|
@ -390,6 +405,7 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) {
|
|||
pRsp->dnodeCfg.dnodeId = htonl(pDnode->dnodeId);
|
||||
pRsp->dnodeCfg.moduleStatus = htonl((int32_t)pDnode->isMgmt);
|
||||
pRsp->dnodeCfg.numOfVnodes = htonl(openVnodes);
|
||||
pRsp->dnodeCfg.clusterId = htonl(mnodeGetClusterId());
|
||||
SDMVgroupAccess *pAccess = (SDMVgroupAccess *)((char *)pRsp + sizeof(SDMStatusRsp));
|
||||
|
||||
for (int32_t j = 0; j < openVnodes; ++j) {
|
||||
|
@ -533,12 +549,7 @@ static int32_t mnodeDropDnodeByEp(char *ep, SMnodeMsg *pMsg) {
|
|||
|
||||
mInfo("dnode:%d, start to drop it", pDnode->dnodeId);
|
||||
|
||||
#ifndef _SYNC
|
||||
int32_t code = mnodeDropDnode(pDnode, pMsg);
|
||||
#else
|
||||
int32_t code = balanceDropDnode(pDnode);
|
||||
#endif
|
||||
|
||||
mnodeDecDnodeRef(pDnode);
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "mnodeVgroup.h"
|
||||
#include "mnodeUser.h"
|
||||
#include "mnodeTable.h"
|
||||
#include "mnodeCluster.h"
|
||||
#include "mnodeShow.h"
|
||||
#include "mnodeProfile.h"
|
||||
|
||||
|
@ -46,6 +47,7 @@ static bool tsMgmtIsRunning = false;
|
|||
|
||||
static const SMnodeComponent tsMnodeComponents[] = {
|
||||
{"profile", mnodeInitProfile, mnodeCleanupProfile},
|
||||
{"cluster", mnodeInitCluster, mnodeCleanupCluster},
|
||||
{"accts", mnodeInitAccts, mnodeCleanupAccts},
|
||||
{"users", mnodeInitUsers, mnodeCleanupUsers},
|
||||
{"dnodes", mnodeInitDnodes, mnodeCleanupDnodes},
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "mnodeInt.h"
|
||||
#include "mnodeMnode.h"
|
||||
#include "mnodeDnode.h"
|
||||
#include "mnodeCluster.h"
|
||||
#include "mnodeSdb.h"
|
||||
|
||||
#define SDB_TABLE_LEN 12
|
||||
|
@ -214,6 +215,7 @@ void sdbUpdateMnodeRoles() {
|
|||
}
|
||||
}
|
||||
|
||||
mnodeUpdateClusterId();
|
||||
mnodeUpdateMnodeEpSet();
|
||||
}
|
||||
|
||||
|
|
|
@ -103,6 +103,8 @@ static char *mnodeGetShowType(int32_t showType) {
|
|||
case TSDB_MGMT_TABLE_SCORES: return "show scores";
|
||||
case TSDB_MGMT_TABLE_GRANTS: return "show grants";
|
||||
case TSDB_MGMT_TABLE_VNODES: return "show vnodes";
|
||||
case TSDB_MGMT_TABLE_CLUSTER: return "show clusters";
|
||||
case TSDB_MGMT_TABLE_STREAMTABLES : return "show streamtables";
|
||||
default: return "undefined";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1223,6 +1223,55 @@ static int32_t mnodeDropSuperTableColumn(SMnodeMsg *pMsg, char *colName) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t mnodeChangeSuperTableColumnCb(SMnodeMsg *pMsg, int32_t code) {
|
||||
SSuperTableObj *pStable = (SSuperTableObj *)pMsg->pTable;
|
||||
mLInfo("app:%p:%p, stable %s, change column result:%s", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId,
|
||||
tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mnodeChangeSuperTableColumn(SMnodeMsg *pMsg, char *oldName, char *newName) {
|
||||
SSuperTableObj *pStable = (SSuperTableObj *)pMsg->pTable;
|
||||
int32_t col = mnodeFindSuperTableColumnIndex(pStable, oldName);
|
||||
if (col < 0) {
|
||||
mError("app:%p:%p, stable:%s, change column, oldName: %s, newName: %s", pMsg->rpcMsg.ahandle, pMsg,
|
||||
pStable->info.tableId, oldName, newName);
|
||||
return TSDB_CODE_MND_FIELD_NOT_EXIST;
|
||||
}
|
||||
|
||||
// int32_t rowSize = 0;
|
||||
uint32_t len = strlen(newName);
|
||||
if (len >= TSDB_COL_NAME_LEN) {
|
||||
return TSDB_CODE_MND_COL_NAME_TOO_LONG;
|
||||
}
|
||||
|
||||
if (mnodeFindSuperTableColumnIndex(pStable, newName) >= 0) {
|
||||
return TSDB_CODE_MND_FIELD_ALREAY_EXIST;
|
||||
}
|
||||
|
||||
// update
|
||||
SSchema *schema = (SSchema *) (pStable->schema + col);
|
||||
tstrncpy(schema->name, newName, sizeof(schema->name));
|
||||
|
||||
mInfo("app:%p:%p, stable %s, start to modify column %s to %s", pMsg->rpcMsg.ahandle, pMsg, pStable->info.tableId,
|
||||
oldName, newName);
|
||||
|
||||
SSdbOper oper = {
|
||||
.type = SDB_OPER_GLOBAL,
|
||||
.table = tsSuperTableSdb,
|
||||
.pObj = pStable,
|
||||
.pMsg = pMsg,
|
||||
.cb = mnodeChangeSuperTableColumnCb
|
||||
};
|
||||
|
||||
int32_t code = sdbUpdateRow(&oper);
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
code = TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
// show super tables
|
||||
static int32_t mnodeGetShowSuperTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
||||
SDbObj *pDb = mnodeGetDb(pShow->db);
|
||||
|
@ -1405,6 +1454,9 @@ static int32_t mnodeSetSchemaFromSuperTable(SSchema *pSchema, SSuperTableObj *pT
|
|||
static int32_t mnodeGetSuperTableMeta(SMnodeMsg *pMsg) {
|
||||
SSuperTableObj *pTable = (SSuperTableObj *)pMsg->pTable;
|
||||
STableMetaMsg *pMeta = rpcMallocCont(sizeof(STableMetaMsg) + sizeof(SSchema) * (TSDB_MAX_TAGS + TSDB_MAX_COLUMNS + 16));
|
||||
if (pMeta == NULL) {
|
||||
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||
}
|
||||
pMeta->uid = htobe64(pTable->uid);
|
||||
pMeta->sversion = htons(pTable->sversion);
|
||||
pMeta->tversion = htons(pTable->tversion);
|
||||
|
@ -1977,6 +2029,48 @@ static int32_t mnodeDropNormalTableColumn(SMnodeMsg *pMsg, char *colName) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t mnodeChangeNormalTableColumn(SMnodeMsg *pMsg, char *oldName, char *newName) {
|
||||
SChildTableObj *pTable = (SChildTableObj *)pMsg->pTable;
|
||||
int32_t col = mnodeFindNormalTableColumnIndex(pTable, oldName);
|
||||
if (col < 0) {
|
||||
mError("app:%p:%p, ctable:%s, change column, oldName: %s, newName: %s", pMsg->rpcMsg.ahandle, pMsg,
|
||||
pTable->info.tableId, oldName, newName);
|
||||
return TSDB_CODE_MND_FIELD_NOT_EXIST;
|
||||
}
|
||||
|
||||
// int32_t rowSize = 0;
|
||||
uint32_t len = strlen(newName);
|
||||
if (len >= TSDB_COL_NAME_LEN) {
|
||||
return TSDB_CODE_MND_COL_NAME_TOO_LONG;
|
||||
}
|
||||
|
||||
if (mnodeFindNormalTableColumnIndex(pTable, newName) >= 0) {
|
||||
return TSDB_CODE_MND_FIELD_ALREAY_EXIST;
|
||||
}
|
||||
|
||||
// update
|
||||
SSchema *schema = (SSchema *) (pTable->schema + col);
|
||||
tstrncpy(schema->name, newName, sizeof(schema->name));
|
||||
|
||||
mInfo("app:%p:%p, ctable %s, start to modify column %s to %s", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId,
|
||||
oldName, newName);
|
||||
|
||||
SSdbOper oper = {
|
||||
.type = SDB_OPER_GLOBAL,
|
||||
.table = tsChildTableSdb,
|
||||
.pObj = pTable,
|
||||
.pMsg = pMsg,
|
||||
.cb = mnodeAlterNormalTableColumnCb
|
||||
};
|
||||
|
||||
int32_t code = sdbUpdateRow(&oper);
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
code = TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mnodeSetSchemaFromNormalTable(SSchema *pSchema, SChildTableObj *pTable) {
|
||||
int32_t numOfCols = pTable->numOfColumns;
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
|
@ -2596,6 +2690,8 @@ static int32_t mnodeProcessAlterTableMsg(SMnodeMsg *pMsg) {
|
|||
code = mnodeAddSuperTableColumn(pMsg, pAlter->schema, 1);
|
||||
} else if (pAlter->type == TSDB_ALTER_TABLE_DROP_COLUMN) {
|
||||
code = mnodeDropSuperTableColumn(pMsg, pAlter->schema[0].name);
|
||||
} else if (pAlter->type == TSDB_ALTER_TABLE_CHANGE_COLUMN) {
|
||||
code = mnodeChangeSuperTableColumn(pMsg, pAlter->schema[0].name, pAlter->schema[1].name);
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
|
@ -2606,6 +2702,8 @@ static int32_t mnodeProcessAlterTableMsg(SMnodeMsg *pMsg) {
|
|||
code = mnodeAddNormalTableColumn(pMsg, pAlter->schema, 1);
|
||||
} else if (pAlter->type == TSDB_ALTER_TABLE_DROP_COLUMN) {
|
||||
code = mnodeDropNormalTableColumn(pMsg, pAlter->schema[0].name);
|
||||
} else if (pAlter->type == TSDB_ALTER_TABLE_CHANGE_COLUMN) {
|
||||
code = mnodeChangeNormalTableColumn(pMsg, pAlter->schema[0].name, pAlter->schema[1].name);
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,16 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
PROJECT(TDengine)
|
||||
|
||||
ADD_SUBDIRECTORY(linux)
|
||||
ADD_SUBDIRECTORY(windows)
|
||||
ADD_SUBDIRECTORY(darwin)
|
||||
IF (TD_LINUX_64)
|
||||
ADD_SUBDIRECTORY(src/linux64)
|
||||
ELSEIF (TD_LINUX_32)
|
||||
ADD_SUBDIRECTORY(src/linux32)
|
||||
ELSEIF (TD_DARWIN_64)
|
||||
ADD_SUBDIRECTORY(src/darwin64)
|
||||
ELSEIF (TD_WINDOWS_64)
|
||||
ADD_SUBDIRECTORY(src/windows64)
|
||||
ELSEIF (TD_WINDOWS_32)
|
||||
ADD_SUBDIRECTORY(src/windows32)
|
||||
ENDIF ()
|
||||
|
||||
ADD_SUBDIRECTORY(src/detail)
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
PROJECT(TDengine)
|
||||
|
||||
IF (TD_DARWIN_64)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(inc)
|
||||
AUX_SOURCE_DIRECTORY(src SRC)
|
||||
ADD_LIBRARY(os ${SRC})
|
||||
ENDIF ()
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_OS_H
|
||||
#define TDENGINE_OS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef _TD_DARWIN_64
|
||||
#include "osDarwin64.h"
|
||||
#endif
|
||||
|
||||
#ifdef _TD_LINUX_64
|
||||
#include "osLinux64.h"
|
||||
#endif
|
||||
|
||||
#ifdef _TD_LINUX_32
|
||||
#include "osLinux32.h"
|
||||
#endif
|
||||
|
||||
#ifdef _TD_ALPINE
|
||||
#include "osAlpine.h"
|
||||
#endif
|
||||
|
||||
#ifdef _TD_WINDOWS_64
|
||||
#include "osWindows64.h"
|
||||
#endif
|
||||
|
||||
#ifdef _TD_WINDOWS_32
|
||||
#include "osWindows32.h"
|
||||
#endif
|
||||
|
||||
#include "osSpec.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_OS_LINUX64_H
|
||||
#define TDENGINE_OS_LINUX64_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <argp.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <endian.h>
|
||||
#include <errno.h>
|
||||
#include <float.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <libgen.h>
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
#include <math.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <pthread.h>
|
||||
#include <pwd.h>
|
||||
#include <regex.h>
|
||||
#include <semaphore.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/eventfd.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/sendfile.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/un.h>
|
||||
#include <syslog.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
#include <wordexp.h>
|
||||
#include <wctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/resource.h>
|
||||
#include <linux/sysctl.h>
|
||||
|
||||
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
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -201,6 +201,8 @@ int tsem_destroy(dispatch_semaphore_t *sem);
|
|||
|
||||
void osInit();
|
||||
|
||||
ssize_t tread(int fd, void *buf, size_t count);
|
||||
|
||||
ssize_t twrite(int fd, void *buf, size_t n);
|
||||
|
||||
char *taosCharsetReplace(char *charsetstr);
|
||||
|
@ -233,6 +235,8 @@ int fsendfile(FILE* out_file, FILE* in_file, int64_t* offset, int32_t count);
|
|||
|
||||
void taosSetCoreDump();
|
||||
|
||||
int tSystem(const char * cmd);
|
||||
|
||||
typedef int(*__compar_fn_t)(const void *, const void *);
|
||||
|
||||
// for send function in tsocket.c
|
||||
|
@ -255,6 +259,17 @@ typedef int(*__compar_fn_t)(const void *, const void *);
|
|||
#define BUILDIN_CLZ(val) __builtin_clz(val)
|
||||
#define BUILDIN_CTZ(val) __builtin_ctz(val)
|
||||
|
||||
#undef threadlocal
|
||||
#ifdef _ISOC11_SOURCE
|
||||
#define threadlocal _Thread_local
|
||||
#elif defined(__APPLE__)
|
||||
#define threadlocal
|
||||
#elif defined(__GNUC__) && !defined(threadlocal)
|
||||
#define threadlocal __thread
|
||||
#else
|
||||
#define threadlocal
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_OS_LINUX64_H
|
||||
#define TDENGINE_OS_LINUX64_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <argp.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <endian.h>
|
||||
#include <errno.h>
|
||||
#include <float.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <libgen.h>
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
#include <math.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <pthread.h>
|
||||
#include <pwd.h>
|
||||
#include <regex.h>
|
||||
#include <semaphore.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/eventfd.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/sendfile.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/un.h>
|
||||
#include <syslog.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
#include <wordexp.h>
|
||||
#include <wctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/resource.h>
|
||||
#include <error.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_OS_LINUX64_H
|
||||
#define TDENGINE_OS_LINUX64_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <argp.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <endian.h>
|
||||
#include <errno.h>
|
||||
#include <float.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <libgen.h>
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
#include <math.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <pthread.h>
|
||||
#include <pwd.h>
|
||||
#include <regex.h>
|
||||
#include <semaphore.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/eventfd.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/sendfile.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/un.h>
|
||||
#include <syslog.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
#include <wordexp.h>
|
||||
#include <wctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/resource.h>
|
||||
#include <error.h>
|
||||
#include <linux/sysctl.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,240 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_OS_SPEC_H
|
||||
#define TDENGINE_OS_SPEC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_FUNC_MATH
|
||||
#define SWAP(a, b, c) \
|
||||
do { \
|
||||
typeof(a) __tmp = (a); \
|
||||
(a) = (b); \
|
||||
(b) = __tmp; \
|
||||
} while (0)
|
||||
|
||||
#define MAX(a, b) \
|
||||
({ \
|
||||
typeof(a) __a = (a); \
|
||||
typeof(b) __b = (b); \
|
||||
(__a > __b) ? __a : __b; \
|
||||
})
|
||||
|
||||
#define MIN(a, b) \
|
||||
({ \
|
||||
typeof(a) __a = (a); \
|
||||
typeof(b) __b = (b); \
|
||||
(__a < __b) ? __a : __b; \
|
||||
})
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_DEF_TIME
|
||||
#define MILLISECOND_PER_SECOND ((int64_t)1000L)
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_FUNC_SEMPHONE
|
||||
#define tsem_t sem_t
|
||||
#define tsem_init sem_init
|
||||
#define tsem_wait sem_wait
|
||||
#define tsem_post sem_post
|
||||
#define tsem_destroy sem_destroy
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_FUNC_ATOMIC
|
||||
#define atomic_load_8(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
#define atomic_load_16(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
#define atomic_load_32(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
#define atomic_load_64(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
#define atomic_load_ptr(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_store_8(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_store_16(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_store_32(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_store_64(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_store_ptr(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_exchange_8(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_exchange_16(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_exchange_32(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_exchange_64(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_exchange_ptr(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_val_compare_exchange_8 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_16 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_32 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_64 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_ptr __sync_val_compare_and_swap
|
||||
|
||||
#define atomic_add_fetch_8(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_add_fetch_16(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_add_fetch_32(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_add_fetch_64(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_add_fetch_ptr(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_add_8(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_add_16(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_add_32(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_add_64(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_add_ptr(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_sub_fetch_8(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_sub_fetch_16(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_sub_fetch_32(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_sub_fetch_64(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_sub_fetch_ptr(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_sub_8(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_sub_16(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_sub_32(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_sub_64(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_sub_ptr(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_and_fetch_8(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_and_fetch_16(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_and_fetch_32(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_and_fetch_64(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_and_fetch_ptr(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_and_8(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_and_16(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_and_32(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_and_64(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_and_ptr(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_or_fetch_8(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_or_fetch_16(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_or_fetch_32(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_or_fetch_64(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_or_fetch_ptr(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_or_8(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_or_16(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_or_32(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_or_64(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_or_ptr(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_xor_fetch_8(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_xor_fetch_16(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_xor_fetch_32(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_xor_fetch_64(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_xor_fetch_ptr(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_xor_8(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_xor_16(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_xor_32(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_xor_64(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_xor_ptr(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#endif
|
||||
|
||||
ssize_t taosTReadImp(int fd, void *buf, size_t count);
|
||||
ssize_t taosTWriteImp(int fd, void *buf, size_t count);
|
||||
ssize_t taosTSendFileImp(int dfd, int sfd, off_t *offset, size_t size);
|
||||
#ifndef TAOS_OS_FUNC_FILE
|
||||
#define taosTRead(fd, buf, count) taosTReadImp(fd, buf, count)
|
||||
#define taosTWrite(fd, buf, count) taosTWriteImp(fd, buf, count)
|
||||
#define taosLSeek(fd, offset, whence) lseek(fd, offset, whence)
|
||||
#define taosTSendFile(dfd, sfd, offset, size) taosTSendFileImp(dfd, sfd, offset, size)
|
||||
#endif
|
||||
|
||||
#ifdef TAOS_RANDOM_FILE_FAIL
|
||||
void taosSetRandomFileFailFactor(int factor);
|
||||
void taosSetRandomFileFailOutput(const char *path);
|
||||
ssize_t taosReadFileRandomFail(int fd, void *buf, size_t count, const char *file, uint32_t line);
|
||||
ssize_t taosWriteFileRandomFail(int fd, void *buf, size_t count, const char *file, uint32_t line);
|
||||
off_t taosLSeekRandomFail(int fd, off_t offset, int whence, const char *file, uint32_t line);
|
||||
#define taosTRead(fd, buf, count) taosReadFileRandomFail(fd, buf, count, __FILE__, __LINE__)
|
||||
#define taosTWrite(fd, buf, count) taosWriteFileRandomFail(fd, buf, count, __FILE__, __LINE__)
|
||||
#define taosLSeek(fd, offset, whence) taosLSeekRandomFail(fd, offset, whence, __FILE__, __LINE__)
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_FUNC_NETWORK
|
||||
#define taosSend(sockfd, buf, len, flags) send(sockfd, buf, len, flags)
|
||||
#define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) sendto(sockfd, buf, len, flags, dest_addr, addrlen)
|
||||
#define taosReadSocket(fd, buf, len) read(fd, buf, len)
|
||||
#define taosWriteSocket(fd, buf, len) write(fd, buf, len)
|
||||
#define taosCloseSocket(x) \
|
||||
{ \
|
||||
if (FD_VALID(x)) { \
|
||||
close(x); \
|
||||
x = FD_INITIALIZER; \
|
||||
} \
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TAOS_RANDOM_NETWORK_FAIL
|
||||
ssize_t taosSendRandomFail(int sockfd, const void *buf, size_t len, int flags);
|
||||
ssize_t taosSendToRandomFail(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen);
|
||||
ssize_t taosReadSocketRandomFail(int fd, void *buf, size_t count);
|
||||
ssize_t taosWriteSocketRandomFail(int fd, const void *buf, size_t count);
|
||||
#define taosSend(sockfd, buf, len, flags) taosSendRandomFail(sockfd, buf, len, flags)
|
||||
#define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) taosSendToRandomFail(sockfd, buf, len, flags, dest_addr, addrlen)
|
||||
#define taosReadSocket(fd, buf, len) taosReadSocketRandomFail(fd, buf, len)
|
||||
#define taosWriteSocket(fd, buf, len) taosWriteSocketRandomFail(fd, buf, len)
|
||||
#endif
|
||||
|
||||
#ifndef TAOS_OS_FUNC_LZ4
|
||||
#define BUILDIN_CLZL(val) __builtin_clzl(val)
|
||||
#define BUILDIN_CTZL(val) __builtin_ctzl(val)
|
||||
#define BUILDIN_CLZ(val) __builtin_clz(val)
|
||||
#define BUILDIN_CTZ(val) __builtin_ctz(val)
|
||||
#endif
|
||||
|
||||
#undef threadlocal
|
||||
#ifdef _ISOC11_SOURCE
|
||||
#define threadlocal _Thread_local
|
||||
#elif defined(__APPLE__)
|
||||
#define threadlocal
|
||||
#elif defined(__GNUC__) && !defined(threadlocal)
|
||||
#define threadlocal __thread
|
||||
#else
|
||||
#define threadlocal
|
||||
#endif
|
||||
|
||||
void osInit();
|
||||
|
||||
// TAOS_OS_FUNC_PTHREAD
|
||||
bool taosCheckPthreadValid(pthread_t thread);
|
||||
int64_t taosGetPthreadId();
|
||||
|
||||
// TAOS_OS_FUNC_SOCKET
|
||||
int taosSetNonblocking(int sock, int on);
|
||||
int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optlen);
|
||||
void taosBlockSIGPIPE();
|
||||
|
||||
// TAOS_OS_FUNC_SYSINFO
|
||||
void taosGetSystemInfo();
|
||||
void taosPrintOsInfo();
|
||||
void taosKillSystem();
|
||||
int tSystem(const char * cmd) ;
|
||||
|
||||
// TAOS_OS_FUNC_CORE
|
||||
void taosSetCoreDump();
|
||||
|
||||
// TAOS_OS_FUNC_UTIL
|
||||
int64_t tsosStr2int64(char *str);
|
||||
|
||||
// TAOS_OS_FUNC_TIMER
|
||||
void taosMsleep(int mseconds);
|
||||
int taosInitTimer(void (*callback)(int), int ms);
|
||||
void taosUninitTimer();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_PLATFORM_WINDOWS32_H
|
||||
#define TDENGINE_PLATFORM_WINDOWS32_H
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <direct.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <float.h>
|
||||
#include <locale.h>
|
||||
#include <intrin.h>
|
||||
#include <io.h>
|
||||
#include <math.h>
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include <inttypes.h>
|
||||
#include "winsock2.h"
|
||||
#include <WS2tcpip.h>
|
||||
#include <winbase.h>
|
||||
#include <Winsock2.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -78,10 +78,10 @@ extern "C" {
|
|||
#define wcsncasecmp _wcsnicmp
|
||||
#define strtok_r strtok_s
|
||||
#ifdef _TD_GO_DLL_
|
||||
int64_t str2int64(char *str);
|
||||
int64_t tsosStr2int64(char *str);
|
||||
uint64_t htonll(uint64_t val);
|
||||
#else
|
||||
#define str2int64 _atoi64
|
||||
#define tsosStr2int64 _atoi64
|
||||
#endif
|
||||
|
||||
#define snprintf _snprintf
|
|
@ -1,294 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_PLATFORM_LINUX_H
|
||||
#define TDENGINE_PLATFORM_LINUX_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <argp.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <endian.h>
|
||||
#include <errno.h>
|
||||
#include <float.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <libgen.h>
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
#include <math.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <pthread.h>
|
||||
#include <pwd.h>
|
||||
#include <regex.h>
|
||||
#include <semaphore.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/eventfd.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/sendfile.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/un.h>
|
||||
#include <syslog.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
#include <wordexp.h>
|
||||
#include <wctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/resource.h>
|
||||
#include <error.h>
|
||||
|
||||
#define taosCloseSocket(x) \
|
||||
{ \
|
||||
if (FD_VALID(x)) { \
|
||||
close(x); \
|
||||
x = FD_INITIALIZER; \
|
||||
} \
|
||||
}
|
||||
|
||||
#ifdef TAOS_RANDOM_NETWORK_FAIL
|
||||
|
||||
ssize_t taos_send_random_fail(int sockfd, const void *buf, size_t len, int flags);
|
||||
|
||||
ssize_t taos_sendto_random_fail(int sockfd, const void *buf, size_t len, int flags,
|
||||
const struct sockaddr *dest_addr, socklen_t addrlen);
|
||||
ssize_t taos_read_random_fail(int fd, void *buf, size_t count);
|
||||
ssize_t taos_write_random_fail(int fd, const void *buf, size_t count);
|
||||
|
||||
#define send(sockfd, buf, len, flags) taos_send_random_fail(sockfd, buf, len, flags)
|
||||
#define sendto(sockfd, buf, len, flags, dest_addr, addrlen) \
|
||||
taos_sendto_random_fail(sockfd, buf, len, flags, dest_addr, addrlen)
|
||||
#define taosWriteSocket(fd, buf, len) taos_write_random_fail(fd, buf, len)
|
||||
#define taosReadSocket(fd, buf, len) taos_read_random_fail(fd, buf, len)
|
||||
|
||||
#else
|
||||
|
||||
#define taosWriteSocket(fd, buf, len) write(fd, buf, len)
|
||||
#define taosReadSocket(fd, buf, len) read(fd, buf, len)
|
||||
|
||||
#endif /* TAOS_RANDOM_NETWORK_FAIL */
|
||||
|
||||
#define atomic_load_8(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
#define atomic_load_16(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
#define atomic_load_32(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
#define atomic_load_64(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
#define atomic_load_ptr(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_store_8(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_store_16(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_store_32(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_store_64(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_store_ptr(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_exchange_8(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_exchange_16(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_exchange_32(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_exchange_64(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_exchange_ptr(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_val_compare_exchange_8 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_16 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_32 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_64 __sync_val_compare_and_swap
|
||||
#define atomic_val_compare_exchange_ptr __sync_val_compare_and_swap
|
||||
|
||||
#define atomic_add_fetch_8(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_add_fetch_16(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_add_fetch_32(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_add_fetch_64(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_add_fetch_ptr(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_add_8(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_add_16(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_add_32(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_add_64(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_add_ptr(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_sub_fetch_8(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_sub_fetch_16(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_sub_fetch_32(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_sub_fetch_64(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_sub_fetch_ptr(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_sub_8(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_sub_16(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_sub_32(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_sub_64(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_sub_ptr(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_and_fetch_8(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_and_fetch_16(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_and_fetch_32(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_and_fetch_64(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_and_fetch_ptr(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_and_8(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_and_16(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_and_32(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_and_64(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_and_ptr(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_or_fetch_8(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_or_fetch_16(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_or_fetch_32(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_or_fetch_64(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_or_fetch_ptr(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_or_8(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_or_16(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_or_32(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_or_64(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_or_ptr(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_xor_fetch_8(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_xor_fetch_16(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_xor_fetch_32(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_xor_fetch_64(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_xor_fetch_ptr(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define atomic_fetch_xor_8(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_xor_16(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_xor_32(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_xor_64(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
#define atomic_fetch_xor_ptr(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST)
|
||||
|
||||
#define SWAP(a, b, c) \
|
||||
do { \
|
||||
typeof(a) __tmp = (a); \
|
||||
(a) = (b); \
|
||||
(b) = __tmp; \
|
||||
} while (0)
|
||||
|
||||
#define MAX(a, b) \
|
||||
({ \
|
||||
typeof(a) __a = (a); \
|
||||
typeof(b) __b = (b); \
|
||||
(__a > __b) ? __a : __b; \
|
||||
})
|
||||
|
||||
#define MIN(a, b) \
|
||||
({ \
|
||||
typeof(a) __a = (a); \
|
||||
typeof(b) __b = (b); \
|
||||
(__a < __b) ? __a : __b; \
|
||||
})
|
||||
|
||||
#define MILLISECOND_PER_SECOND ((int64_t)1000L)
|
||||
|
||||
#define tsem_t sem_t
|
||||
#define tsem_init sem_init
|
||||
#define tsem_wait sem_wait
|
||||
#define tsem_post sem_post
|
||||
#define tsem_destroy sem_destroy
|
||||
|
||||
void osInit();
|
||||
|
||||
ssize_t tsendfile(int dfd, int sfd, off_t *offset, size_t size);
|
||||
|
||||
ssize_t twrite(int fd, void *buf, size_t n);
|
||||
|
||||
ssize_t tread(int fd, void *buf, size_t count);
|
||||
|
||||
bool taosCheckPthreadValid(pthread_t thread);
|
||||
|
||||
void taosResetPthread(pthread_t *thread);
|
||||
|
||||
int64_t taosGetPthreadId();
|
||||
|
||||
int taosSetNonblocking(int sock, int on);
|
||||
|
||||
int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optlen);
|
||||
|
||||
void taosPrintOsInfo();
|
||||
|
||||
char *taosCharsetReplace(char *charsetstr);
|
||||
|
||||
void taosGetSystemInfo();
|
||||
|
||||
void taosKillSystem();
|
||||
|
||||
bool taosSkipSocketCheck();
|
||||
|
||||
int64_t str2int64(char *str);
|
||||
|
||||
void taosSetCoreDump();
|
||||
|
||||
void taosBlockSIGPIPE();
|
||||
|
||||
int tSystem(const char * cmd) ;
|
||||
|
||||
|
||||
#ifdef _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
|
||||
|
||||
#ifndef _TD_ARM_32_
|
||||
#define BUILDIN_CLZL(val) __builtin_clzl(val)
|
||||
#define BUILDIN_CTZL(val) __builtin_ctzl(val)
|
||||
#else
|
||||
#define BUILDIN_CLZL(val) __builtin_clzll(val)
|
||||
#define BUILDIN_CTZL(val) __builtin_ctzll(val)
|
||||
#endif
|
||||
#define BUILDIN_CLZ(val) __builtin_clz(val)
|
||||
#define BUILDIN_CTZ(val) __builtin_ctz(val)
|
||||
|
||||
#undef threadlocal
|
||||
#ifdef _ISOC11_SOURCE
|
||||
#define threadlocal _Thread_local
|
||||
#elif defined(__APPLE__)
|
||||
#define threadlocal
|
||||
#elif defined(__GNUC__) && !defined(threadlocal)
|
||||
#define threadlocal __thread
|
||||
#else
|
||||
#define threadlocal
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,318 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "taosdef.h"
|
||||
#include "tglobal.h"
|
||||
#include "ttimer.h"
|
||||
#include "tulog.h"
|
||||
#include "tutil.h"
|
||||
|
||||
int64_t str2int64(char *str) {
|
||||
char *endptr = NULL;
|
||||
return strtoll(str, &endptr, 10);
|
||||
}
|
||||
|
||||
/*
|
||||
to make taosMsleep work,
|
||||
signal SIGALRM shall be blocked in the calling thread,
|
||||
|
||||
sigset_t set;
|
||||
sigemptyset(&set);
|
||||
sigaddset(&set, SIGALRM);
|
||||
pthread_sigmask(SIG_BLOCK, &set, NULL);
|
||||
*/
|
||||
void taosMsleep(int mseconds) {
|
||||
struct timeval timeout;
|
||||
int seconds, useconds;
|
||||
|
||||
seconds = mseconds / 1000;
|
||||
useconds = (mseconds % 1000) * 1000;
|
||||
timeout.tv_sec = seconds;
|
||||
timeout.tv_usec = useconds;
|
||||
|
||||
/* sigset_t set; */
|
||||
/* sigemptyset(&set); */
|
||||
/* sigaddset(&set, SIGALRM); */
|
||||
/* pthread_sigmask(SIG_BLOCK, &set, NULL); */
|
||||
|
||||
select(0, NULL, NULL, NULL, &timeout);
|
||||
|
||||
/* pthread_sigmask(SIG_UNBLOCK, &set, NULL); */
|
||||
}
|
||||
|
||||
bool taosCheckPthreadValid(pthread_t thread) { return thread != 0; }
|
||||
|
||||
int64_t taosGetPthreadId() { return (int64_t)pthread_self(); }
|
||||
|
||||
int taosSetNonblocking(int sock, int on) {
|
||||
int flags = 0;
|
||||
if ((flags = fcntl(sock, F_GETFL, 0)) < 0) {
|
||||
uError("fcntl(F_GETFL) error: %d (%s)\n", errno, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (on)
|
||||
flags |= O_NONBLOCK;
|
||||
else
|
||||
flags &= ~O_NONBLOCK;
|
||||
|
||||
if ((flags = fcntl(sock, F_SETFL, flags)) < 0) {
|
||||
uError("fcntl(F_SETFL) error: %d (%s)\n", errno, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optlen) {
|
||||
return setsockopt(socketfd, level, optname, optval, (socklen_t)optlen);
|
||||
}
|
||||
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;
|
||||
|
||||
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}};
|
||||
|
||||
#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) {
|
||||
uError("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)) {
|
||||
uError("Failed to init timer");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int signo;
|
||||
while (!stopTimer) {
|
||||
if (sigwait(&sigset, &signo)) {
|
||||
uError("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) {
|
||||
uError("failed to create timer thread");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void taosUninitTimer() {
|
||||
stopTimer = true;
|
||||
pthread_join(timerThread, NULL);
|
||||
}
|
||||
|
||||
ssize_t tread(int fd, void *buf, size_t count) {
|
||||
size_t leftbytes = count;
|
||||
ssize_t readbytes;
|
||||
char * tbuf = (char *)buf;
|
||||
|
||||
while (leftbytes > 0) {
|
||||
readbytes = read(fd, (void *)tbuf, leftbytes);
|
||||
if (readbytes < 0) {
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
} else if (readbytes == 0) {
|
||||
return (ssize_t)(count - leftbytes);
|
||||
}
|
||||
|
||||
leftbytes -= readbytes;
|
||||
tbuf += readbytes;
|
||||
}
|
||||
|
||||
return (ssize_t)count;
|
||||
}
|
||||
|
||||
ssize_t tsendfile(int dfd, int sfd, off_t *offset, size_t size) {
|
||||
size_t leftbytes = size;
|
||||
ssize_t sentbytes;
|
||||
|
||||
while (leftbytes > 0) {
|
||||
/*
|
||||
* TODO : Think to check if file is larger than 1GB
|
||||
*/
|
||||
//if (leftbytes > 1000000000) leftbytes = 1000000000;
|
||||
sentbytes = sendfile(dfd, sfd, offset, leftbytes);
|
||||
if (sentbytes == -1) {
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
} else if (sentbytes == 0) {
|
||||
return (ssize_t)(size - leftbytes);
|
||||
}
|
||||
|
||||
leftbytes -= sentbytes;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
ssize_t twrite(int fd, void *buf, size_t n) {
|
||||
size_t nleft = n;
|
||||
ssize_t nwritten = 0;
|
||||
char *tbuf = (char *)buf;
|
||||
|
||||
while (nleft > 0) {
|
||||
nwritten = write(fd, (void *)tbuf, nleft);
|
||||
if (nwritten < 0) {
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
nleft -= nwritten;
|
||||
tbuf += nwritten;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
void taosBlockSIGPIPE() {
|
||||
sigset_t signal_mask;
|
||||
sigemptyset(&signal_mask);
|
||||
sigaddset(&signal_mask, SIGPIPE);
|
||||
int rc = pthread_sigmask(SIG_BLOCK, &signal_mask, NULL);
|
||||
if (rc != 0) {
|
||||
uError("failed to block SIGPIPE");
|
||||
}
|
||||
}
|
||||
|
||||
int tSystem(const char * cmd)
|
||||
{
|
||||
FILE * fp;
|
||||
int res;
|
||||
char buf[1024];
|
||||
if (cmd == NULL) {
|
||||
uError("tSystem cmd is NULL!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((fp = popen(cmd, "r") ) == NULL) {
|
||||
uError("popen cmd:%s error: %s/n", cmd, strerror(errno));
|
||||
return -1;
|
||||
} else {
|
||||
while(fgets(buf, sizeof(buf), fp)) {
|
||||
uDebug("popen result:%s", buf);
|
||||
}
|
||||
|
||||
if ((res = pclose(fp)) == -1) {
|
||||
uError("close popen file pointer fp error!\n");
|
||||
} else {
|
||||
uDebug("popen res is :%d\n", res);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TAOS_RANDOM_NETWORK_FAIL
|
||||
|
||||
#define RANDOM_NETWORK_FAIL_FACTOR 20
|
||||
|
||||
ssize_t taos_send_random_fail(int sockfd, const void *buf, size_t len, int flags)
|
||||
{
|
||||
if (rand() % RANDOM_NETWORK_FAIL_FACTOR == 0) {
|
||||
errno = ECONNRESET;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return send(sockfd, buf, len, flags);
|
||||
}
|
||||
|
||||
ssize_t taos_sendto_random_fail(int sockfd, const void *buf, size_t len, int flags,
|
||||
const struct sockaddr *dest_addr, socklen_t addrlen)
|
||||
{
|
||||
if (rand() % RANDOM_NETWORK_FAIL_FACTOR == 0) {
|
||||
errno = ECONNRESET;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return sendto(sockfd, buf, len, flags, dest_addr, addrlen);
|
||||
}
|
||||
|
||||
ssize_t taos_read_random_fail(int fd, void *buf, size_t count)
|
||||
{
|
||||
if (rand() % RANDOM_NETWORK_FAIL_FACTOR == 0) {
|
||||
errno = ECONNRESET;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return read(fd, buf, count);
|
||||
}
|
||||
|
||||
ssize_t taos_write_random_fail(int fd, const void *buf, size_t count)
|
||||
{
|
||||
if (rand() % RANDOM_NETWORK_FAIL_FACTOR == 0) {
|
||||
errno = EINTR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return write(fd, buf, count);
|
||||
}
|
||||
|
||||
#endif /* TAOS_RANDOM_NETWORK_FAIL */
|
|
@ -0,0 +1,12 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
PROJECT(TDengine)
|
||||
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc)
|
||||
AUX_SOURCE_DIRECTORY(. SRC)
|
||||
|
||||
ADD_LIBRARY(os ${SRC})
|
||||
TARGET_LINK_LIBRARIES(os m rt)
|
||||
|
|
@ -1,16 +1,13 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
PROJECT(TDengine)
|
||||
|
||||
IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
|
||||
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
|
||||
IF (TD_DARWIN_64)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc)
|
||||
INCLUDE_DIRECTORIES(inc)
|
||||
AUX_SOURCE_DIRECTORY(src SRC)
|
||||
|
||||
ADD_LIBRARY(os ${SRC})
|
||||
TARGET_LINK_LIBRARIES(os m rt)
|
||||
ENDIF ()
|
||||
|
||||
SET_SOURCE_FILES_PROPERTIES(src/linuxSysPara.c PROPERTIES COMPILE_FLAGS -w)
|
|
@ -15,12 +15,15 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tglobal.h"
|
||||
#include "os.h"
|
||||
#include "taosdef.h"
|
||||
#include "tutil.h"
|
||||
#include "tglobal.h"
|
||||
#include "tconfig.h"
|
||||
#include "ttimer.h"
|
||||
#include "tulog.h"
|
||||
#include "tutil.h"
|
||||
|
||||
int64_t str2int64(char *str) {
|
||||
int64_t tsosStr2int64(char *str) {
|
||||
char *endptr = NULL;
|
||||
return strtoll(str, &endptr, 10);
|
||||
}
|
||||
|
@ -159,12 +162,14 @@ int taosInitTimer(void (*callback)(int), int ms) {
|
|||
tv.it_interval.tv_usec = 1000 * ms; // resolution is in msecond
|
||||
tv.it_value = tv.it_interval;
|
||||
|
||||
return setitimer(ITIMER_REAL, &tv, NULL);
|
||||
setitimer(ITIMER_REAL, &tv, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void taosUninitTimer() {
|
||||
struct itimerval tv = { 0 };
|
||||
return setitimer(ITIMER_REAL, &tv, NULL);
|
||||
setitimer(ITIMER_REAL, &tv, NULL);
|
||||
}
|
||||
|
||||
void taosGetSystemTimezone() {
|
||||
|
@ -207,7 +212,7 @@ void taosGetSystemLocale() {
|
|||
void taosPrintOsInfo() {}
|
||||
|
||||
void taosKillSystem() {
|
||||
tError("function taosKillSystem, exit!");
|
||||
uError("function taosKillSystem, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
@ -221,95 +226,75 @@ void taosGetSystemInfo() {
|
|||
}
|
||||
|
||||
void *taosInitTcpClient(char *ip, uint16_t port, char *flabel, int num, void *fp, void *shandle) {
|
||||
tError("function taosInitTcpClient is not implemented in darwin system, exit!");
|
||||
uError("function taosInitTcpClient is not implemented in darwin system, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void taosCloseTcpClientConnection(void *chandle) {
|
||||
tError("function taosCloseTcpClientConnection is not implemented in darwin system, exit!");
|
||||
uError("function taosCloseTcpClientConnection is not implemented in darwin system, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void *taosOpenTcpClientConnection(void *shandle, void *thandle, char *ip, uint16_t port) {
|
||||
tError("function taosOpenTcpClientConnection is not implemented in darwin system, exit!");
|
||||
uError("function taosOpenTcpClientConnection is not implemented in darwin system, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int taosSendTcpClientData(unsigned int ip, uint16_t port, char *data, int len, void *chandle) {
|
||||
tError("function taosSendTcpClientData is not implemented in darwin system, exit!");
|
||||
uError("function taosSendTcpClientData is not implemented in darwin system, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void taosCleanUpTcpClient(void *chandle) {
|
||||
tError("function taosCleanUpTcpClient is not implemented in darwin system, exit!");
|
||||
uError("function taosCleanUpTcpClient is not implemented in darwin system, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void taosCloseTcpServerConnection(void *chandle) {
|
||||
tError("function taosCloseTcpServerConnection is not implemented in darwin system, exit!");
|
||||
uError("function taosCloseTcpServerConnection is not implemented in darwin system, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void taosCleanUpTcpServer(void *handle) {
|
||||
tError("function taosCleanUpTcpServer is not implemented in darwin system, exit!");
|
||||
uError("function taosCleanUpTcpServer is not implemented in darwin system, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void *taosInitTcpServer(char *ip, uint16_t port, char *label, int numOfThreads, void *fp, void *shandle) {
|
||||
tError("function taosInitTcpServer is not implemented in darwin system, exit!");
|
||||
uError("function taosInitTcpServer is not implemented in darwin system, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int taosSendTcpServerData(unsigned int ip, uint16_t port, char *data, int len, void *chandle) {
|
||||
tError("function taosSendTcpServerData is not implemented in darwin system, exit!");
|
||||
uError("function taosSendTcpServerData is not implemented in darwin system, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void taosFreeMsgHdr(void *hdr) {
|
||||
tError("function taosFreeMsgHdr is not implemented in darwin system, exit!");
|
||||
uError("function taosFreeMsgHdr is not implemented in darwin system, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int taosMsgHdrSize(void *hdr) {
|
||||
tError("function taosMsgHdrSize is not implemented in darwin system, exit!");
|
||||
uError("function taosMsgHdrSize is not implemented in darwin system, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void taosSendMsgHdr(void *hdr, int fd) {
|
||||
tError("function taosSendMsgHdr is not implemented in darwin system, exit!");
|
||||
uError("function taosSendMsgHdr is not implemented in darwin system, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void taosInitMsgHdr(void **hdr, void *dest, int maxPkts) {
|
||||
tError("function taosInitMsgHdr is not implemented in darwin system, exit!");
|
||||
uError("function taosInitMsgHdr is not implemented in darwin system, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void taosSetMsgHdrData(void *hdr, char *data, int dataLen) {
|
||||
tError("function taosSetMsgHdrData is not implemented in darwin system, exit!");
|
||||
uError("function taosSetMsgHdrData is not implemented in darwin system, exit!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
ssize_t twrite(int fd, void *buf, size_t n) {
|
||||
size_t nleft = n;
|
||||
ssize_t nwritten = 0;
|
||||
char *tbuf = (char *)buf;
|
||||
|
||||
while (nleft > 0) {
|
||||
nwritten = write(fd, (void *)tbuf, nleft);
|
||||
if (nwritten < 0) {
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
nleft -= nwritten;
|
||||
tbuf += nwritten;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
bool taosSkipSocketCheck() {
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
PROJECT(TDengine)
|
||||
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc)
|
||||
INCLUDE_DIRECTORIES(.)
|
||||
AUX_SOURCE_DIRECTORY(. SRC)
|
||||
SET_SOURCE_FILES_PROPERTIES(osSysinfo.c PROPERTIES COMPILE_FLAGS -w)
|
||||
SET_SOURCE_FILES_PROPERTIES(osCoredump.c PROPERTIES COMPILE_FLAGS -w)
|
||||
|
||||
ADD_LIBRARY(osdetail ${SRC})
|
||||
TARGET_LINK_LIBRARIES(osdetail os)
|
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tconfig.h"
|
||||
#include "tglobal.h"
|
||||
#include "tulog.h"
|
||||
#include "tutil.h"
|
||||
#include "tsystem.h"
|
||||
|
||||
#ifndef TAOS_OS_FUNC_CORE
|
||||
|
||||
int _sysctl(struct __sysctl_args *args );
|
||||
|
||||
void taosSetCoreDump() {
|
||||
if (0 == tsEnableCoreFile) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. set ulimit -c unlimited
|
||||
struct rlimit rlim;
|
||||
struct rlimit rlim_new;
|
||||
if (getrlimit(RLIMIT_CORE, &rlim) == 0) {
|
||||
uInfo("the old unlimited para: rlim_cur=%" PRIu64 ", rlim_max=%" PRIu64, rlim.rlim_cur, rlim.rlim_max);
|
||||
rlim_new.rlim_cur = RLIM_INFINITY;
|
||||
rlim_new.rlim_max = RLIM_INFINITY;
|
||||
if (setrlimit(RLIMIT_CORE, &rlim_new) != 0) {
|
||||
uInfo("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) {
|
||||
uInfo("the new unlimited para: rlim_cur=%" PRIu64 ", rlim_max=%" PRIu64, rlim.rlim_cur, rlim.rlim_max);
|
||||
}
|
||||
|
||||
#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) {
|
||||
uInfo("_sysctl(kern_core_uses_pid) set fail: %s", strerror(errno));
|
||||
}
|
||||
|
||||
uInfo("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) {
|
||||
uInfo("_sysctl(kern_core_uses_pid) get fail: %s", strerror(errno));
|
||||
}
|
||||
|
||||
uInfo("The new core_uses_pid[%" PRIu64 "]: %d", old_len, old_usespid);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -13,31 +13,62 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <error.h>
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
|
||||
#define RANDOM_NETWORK_FAIL_FACTOR 20
|
||||
|
||||
#ifdef TAOS_RANDOM_NETWORK_FAIL
|
||||
|
||||
ssize_t taosSendRandomFail(int sockfd, const void *buf, size_t len, int flags) {
|
||||
if (rand() % RANDOM_NETWORK_FAIL_FACTOR == 0) {
|
||||
errno = ECONNRESET;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return send(sockfd, buf, len, flags);
|
||||
}
|
||||
|
||||
ssize_t taosSendToRandomFail(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr,
|
||||
socklen_t addrlen) {
|
||||
if (rand() % RANDOM_NETWORK_FAIL_FACTOR == 0) {
|
||||
errno = ECONNRESET;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return sendto(sockfd, buf, len, flags, dest_addr, addrlen);
|
||||
}
|
||||
|
||||
ssize_t taosReadSocketRandomFail(int fd, void *buf, size_t count) {
|
||||
if (rand() % RANDOM_NETWORK_FAIL_FACTOR == 0) {
|
||||
errno = ECONNRESET;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return read(fd, buf, count);
|
||||
}
|
||||
|
||||
ssize_t taosWriteSocketRandomFail(int fd, const void *buf, size_t count) {
|
||||
if (rand() % RANDOM_NETWORK_FAIL_FACTOR == 0) {
|
||||
errno = EINTR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return write(fd, buf, count);
|
||||
}
|
||||
|
||||
#endif //TAOS_RANDOM_NETWORK_FAIL
|
||||
|
||||
#ifdef TAOS_RANDOM_FILE_FAIL
|
||||
|
||||
static int random_file_fail_factor = 20;
|
||||
static FILE *fpRandomFileFailOutput = NULL;
|
||||
|
||||
void taosSetRandomFileFailFactor(int factor)
|
||||
{
|
||||
void taosSetRandomFileFailFactor(int factor) {
|
||||
random_file_fail_factor = factor;
|
||||
}
|
||||
|
||||
static void close_random_file_fail_output()
|
||||
{
|
||||
static void close_random_file_fail_output() {
|
||||
if (fpRandomFileFailOutput != NULL) {
|
||||
if (fpRandomFileFailOutput != stdout) {
|
||||
fclose(fpRandomFileFailOutput);
|
||||
|
@ -46,8 +77,7 @@ static void close_random_file_fail_output()
|
|||
}
|
||||
}
|
||||
|
||||
static void random_file_fail_output_sig(int sig)
|
||||
{
|
||||
static void random_file_fail_output_sig(int sig) {
|
||||
fprintf(fpRandomFileFailOutput, "signal %d received.\n", sig);
|
||||
|
||||
struct sigaction act = {0};
|
||||
|
@ -58,8 +88,7 @@ static void random_file_fail_output_sig(int sig)
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
void taosSetRandomFileFailOutput(const char *path)
|
||||
{
|
||||
void taosSetRandomFileFailOutput(const char *path) {
|
||||
if (path == NULL) {
|
||||
fpRandomFileFailOutput = stdout;
|
||||
} else if ((fpRandomFileFailOutput = fopen(path, "w")) != NULL) {
|
||||
|
@ -75,43 +104,38 @@ void taosSetRandomFileFailOutput(const char *path)
|
|||
sigaction(SIGSEGV, &act, NULL);
|
||||
sigaction(SIGILL, &act, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
ssize_t taos_tread(int fd, void *buf, size_t count, const char *file, uint32_t line)
|
||||
{
|
||||
#ifdef TAOS_RANDOM_FILE_FAIL
|
||||
ssize_t taosReadFileRandomFail(int fd, void *buf, size_t count, const char *file, uint32_t line) {
|
||||
if (random_file_fail_factor > 0) {
|
||||
if (rand() % random_file_fail_factor == 0) {
|
||||
errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return tread(fd, buf, count);
|
||||
|
||||
return taosTReadImp(fd, buf, count);
|
||||
}
|
||||
|
||||
ssize_t taos_twrite(int fd, void *buf, size_t count, const char *file, uint32_t line)
|
||||
{
|
||||
#ifdef TAOS_RANDOM_FILE_FAIL
|
||||
ssize_t taosWriteFileRandomFail(int fd, void *buf, size_t count, const char *file, uint32_t line) {
|
||||
if (random_file_fail_factor > 0) {
|
||||
if (rand() % random_file_fail_factor == 0) {
|
||||
errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return twrite(fd, buf, count);
|
||||
|
||||
return taosTWriteImp(fd, buf, count);
|
||||
}
|
||||
|
||||
off_t taos_lseek(int fd, off_t offset, int whence, const char *file, uint32_t line)
|
||||
{
|
||||
#ifdef TAOS_RANDOM_FILE_FAIL
|
||||
off_t taosLSeekRandomFail(int fd, off_t offset, int whence, const char *file, uint32_t line) {
|
||||
if (random_file_fail_factor > 0) {
|
||||
if (rand() % random_file_fail_factor == 0) {
|
||||
errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return lseek(fd, offset, whence);
|
||||
}
|
||||
|
||||
#endif //TAOS_RANDOM_FILE_FAIL
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
|
||||
ssize_t taosTReadImp(int fd, void *buf, size_t count) {
|
||||
size_t leftbytes = count;
|
||||
ssize_t readbytes;
|
||||
char * tbuf = (char *)buf;
|
||||
|
||||
while (leftbytes > 0) {
|
||||
readbytes = read(fd, (void *)tbuf, leftbytes);
|
||||
if (readbytes < 0) {
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
} else if (readbytes == 0) {
|
||||
return (ssize_t)(count - leftbytes);
|
||||
}
|
||||
|
||||
leftbytes -= readbytes;
|
||||
tbuf += readbytes;
|
||||
}
|
||||
|
||||
return (ssize_t)count;
|
||||
}
|
||||
|
||||
ssize_t taosTSendFileImp(int dfd, int sfd, off_t *offset, size_t size) {
|
||||
size_t leftbytes = size;
|
||||
ssize_t sentbytes;
|
||||
|
||||
while (leftbytes > 0) {
|
||||
/*
|
||||
* TODO : Think to check if file is larger than 1GB
|
||||
*/
|
||||
//if (leftbytes > 1000000000) leftbytes = 1000000000;
|
||||
sentbytes = sendfile(dfd, sfd, offset, leftbytes);
|
||||
if (sentbytes == -1) {
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
} else if (sentbytes == 0) {
|
||||
return (ssize_t)(size - leftbytes);
|
||||
}
|
||||
|
||||
leftbytes -= sentbytes;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
ssize_t taosTWriteImp(int fd, void *buf, size_t n) {
|
||||
size_t nleft = n;
|
||||
ssize_t nwritten = 0;
|
||||
char *tbuf = (char *)buf;
|
||||
|
||||
while (nleft > 0) {
|
||||
nwritten = write(fd, (void *)tbuf, nleft);
|
||||
if (nwritten < 0) {
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
nleft -= nwritten;
|
||||
tbuf += nwritten;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
|
||||
#ifndef TAOS_OS_FUNC_PTHREAD
|
||||
|
||||
bool taosCheckPthreadValid(pthread_t thread) { return thread != 0; }
|
||||
int64_t taosGetPthreadId() { return (int64_t)pthread_self(); }
|
||||
|
||||
#endif
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tulog.h"
|
||||
|
||||
#ifndef TAOS_OS_FUNC_SOCKET
|
||||
|
||||
int taosSetNonblocking(int sock, int on) {
|
||||
int flags = 0;
|
||||
if ((flags = fcntl(sock, F_GETFL, 0)) < 0) {
|
||||
uError("fcntl(F_GETFL) error: %d (%s)\n", errno, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (on)
|
||||
flags |= O_NONBLOCK;
|
||||
else
|
||||
flags &= ~O_NONBLOCK;
|
||||
|
||||
if ((flags = fcntl(sock, F_SETFL, flags)) < 0) {
|
||||
uError("fcntl(F_SETFL) error: %d (%s)\n", errno, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optlen) {
|
||||
return setsockopt(socketfd, level, optname, optval, (socklen_t)optlen);
|
||||
}
|
||||
|
||||
void taosBlockSIGPIPE() {
|
||||
sigset_t signal_mask;
|
||||
sigemptyset(&signal_mask);
|
||||
sigaddset(&signal_mask, SIGPIPE);
|
||||
int rc = pthread_sigmask(SIG_BLOCK, &signal_mask, NULL);
|
||||
if (rc != 0) {
|
||||
uError("failed to block SIGPIPE");
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -15,13 +15,14 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tsysctl.h"
|
||||
#include "tconfig.h"
|
||||
#include "tglobal.h"
|
||||
#include "tulog.h"
|
||||
#include "tutil.h"
|
||||
#include "tsystem.h"
|
||||
|
||||
#ifndef TAOS_OS_FUNC_SYSINFO
|
||||
|
||||
#define PROCESS_ITEM 12
|
||||
|
||||
typedef struct {
|
||||
|
@ -200,7 +201,7 @@ static void taosGetSystemTimezone() {
|
|||
* Asia/Shanghai (CST, +0800)
|
||||
* Europe/London (BST, +0100)
|
||||
*/
|
||||
sprintf(tsTimezone, "%s (%s, %s%02d00)", buf, tzname[daylight], tz >= 0 ? "+" : "-", abs(tz));
|
||||
snprintf(tsTimezone, TSDB_TIMEZONE_LEN, "%s (%s, %s%02d00)", buf, tzname[daylight], tz >= 0 ? "+" : "-", abs(tz));
|
||||
|
||||
// cfg_timezone->cfgStatus = TAOS_CFG_CSTATUS_DEFAULT;
|
||||
uInfo("timezone not configured, set to system default:%s", tsTimezone);
|
||||
|
@ -234,7 +235,7 @@ static void taosGetSystemLocale() { // get and set default locale
|
|||
uError("can't get locale from system, set it to en_US.UTF-8");
|
||||
strcpy(tsLocale, "en_US.UTF-8");
|
||||
} else {
|
||||
tstrncpy(tsLocale, locale, sizeof(tsLocale));
|
||||
tstrncpy(tsLocale, locale, TSDB_LOCALE_LEN);
|
||||
uError("locale not configured, set to system default:%s", tsLocale);
|
||||
}
|
||||
}
|
||||
|
@ -247,7 +248,7 @@ static void taosGetSystemLocale() { // get and set default locale
|
|||
str++;
|
||||
|
||||
char *revisedCharset = taosCharsetReplace(str);
|
||||
tstrncpy(tsCharset, revisedCharset, sizeof(tsCharset));
|
||||
tstrncpy(tsCharset, revisedCharset, TSDB_LOCALE_LEN);
|
||||
|
||||
free(revisedCharset);
|
||||
uWarn("charset not configured, set to system default:%s", tsCharset);
|
||||
|
@ -542,126 +543,31 @@ void taosKillSystem() {
|
|||
kill(tsProcId, 2);
|
||||
}
|
||||
|
||||
int _sysctl(struct __sysctl_args *args );
|
||||
void taosSetCoreDump() {
|
||||
if (0 == tsEnableCoreFile) {
|
||||
return;
|
||||
int tSystem(const char *cmd) {
|
||||
FILE *fp;
|
||||
int res;
|
||||
char buf[1024];
|
||||
if (cmd == NULL) {
|
||||
uError("tSystem cmd is NULL!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 1. set ulimit -c unlimited
|
||||
struct rlimit rlim;
|
||||
struct rlimit rlim_new;
|
||||
if (getrlimit(RLIMIT_CORE, &rlim) == 0) {
|
||||
uInfo("the old unlimited para: rlim_cur=%" PRIu64 ", rlim_max=%" PRIu64, rlim.rlim_cur, rlim.rlim_max);
|
||||
rlim_new.rlim_cur = RLIM_INFINITY;
|
||||
rlim_new.rlim_max = RLIM_INFINITY;
|
||||
if (setrlimit(RLIMIT_CORE, &rlim_new) != 0) {
|
||||
uInfo("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 ((fp = popen(cmd, "r")) == NULL) {
|
||||
uError("popen cmd:%s error: %s/n", cmd, strerror(errno));
|
||||
return -1;
|
||||
} else {
|
||||
while (fgets(buf, sizeof(buf), fp)) {
|
||||
uDebug("popen result:%s", buf);
|
||||
}
|
||||
}
|
||||
|
||||
if (getrlimit(RLIMIT_CORE, &rlim) == 0) {
|
||||
uInfo("the new unlimited para: rlim_cur=%" PRIu64 ", rlim_max=%" PRIu64, rlim.rlim_cur, rlim.rlim_max);
|
||||
}
|
||||
|
||||
#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) {
|
||||
uInfo("_sysctl(kern_core_uses_pid) set fail: %s", strerror(errno));
|
||||
}
|
||||
|
||||
uInfo("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) {
|
||||
uInfo("_sysctl(kern_core_uses_pid) get fail: %s", strerror(errno));
|
||||
}
|
||||
|
||||
uInfo("The new core_uses_pid[%" PRIu64 "]: %d", old_len, old_usespid);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
// 3. create the path for saving core file
|
||||
int status;
|
||||
char coredump_dir[32] = "/var/log/taosdump";
|
||||
if (opendir(coredump_dir) == NULL) {
|
||||
status = mkdir(coredump_dir, S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
if (status) {
|
||||
uInfo("mkdir fail, error: %s\n", strerror(errno));
|
||||
if ((res = pclose(fp)) == -1) {
|
||||
uError("close popen file pointer fp error!\n");
|
||||
} else {
|
||||
uDebug("popen res is :%d\n", res);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// 4. set kernel.core_pattern
|
||||
struct __sysctl_args args;
|
||||
char old_corefile[128];
|
||||
size_t old_len;
|
||||
char new_corefile[128] = "/var/log/taosdump/core-%e-%p";
|
||||
size_t new_len = sizeof(new_corefile);
|
||||
|
||||
int name[] = {CTL_KERN, KERN_CORE_PATTERN};
|
||||
|
||||
memset(&args, 0, sizeof(struct __sysctl_args));
|
||||
args.name = name;
|
||||
args.nlen = sizeof(name)/sizeof(name[0]);
|
||||
args.oldval = old_corefile;
|
||||
args.oldlenp = &old_len;
|
||||
args.newval = new_corefile;
|
||||
args.newlen = new_len;
|
||||
|
||||
old_len = sizeof(old_corefile);
|
||||
|
||||
if (syscall(SYS__sysctl, &args) == -1) {
|
||||
uInfo("_sysctl(kern_core_pattern) set fail: %s", strerror(errno));
|
||||
}
|
||||
|
||||
uInfo("The old kern_core_pattern: %*s\n", old_len, old_corefile);
|
||||
|
||||
|
||||
memset(&args, 0, sizeof(struct __sysctl_args));
|
||||
args.name = name;
|
||||
args.nlen = sizeof(name)/sizeof(name[0]);
|
||||
args.oldval = old_corefile;
|
||||
args.oldlenp = &old_len;
|
||||
|
||||
old_len = sizeof(old_corefile);
|
||||
|
||||
if (syscall(SYS__sysctl, &args) == -1) {
|
||||
uInfo("_sysctl(kern_core_pattern) get fail: %s", strerror(errno));
|
||||
}
|
||||
|
||||
uInfo("The new kern_core_pattern: %*s\n", old_len, old_corefile);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "os.h"
|
||||
#include "taosdef.h"
|
||||
#include "tglobal.h"
|
||||
#include "ttimer.h"
|
||||
#include "tulog.h"
|
||||
#include "tutil.h"
|
||||
#include <signal.h>
|
||||
|
||||
#ifndef TAOS_OS_FUNC_TIMER
|
||||
|
||||
/*
|
||||
to make taosMsleep work,
|
||||
signal SIGALRM shall be blocked in the calling thread,
|
||||
|
||||
sigset_t set;
|
||||
sigemptyset(&set);
|
||||
sigaddset(&set, SIGALRM);
|
||||
pthread_sigmask(SIG_BLOCK, &set, NULL);
|
||||
*/
|
||||
void taosMsleep(int mseconds) {
|
||||
struct timeval timeout;
|
||||
int seconds, useconds;
|
||||
|
||||
seconds = mseconds / 1000;
|
||||
useconds = (mseconds % 1000) * 1000;
|
||||
timeout.tv_sec = seconds;
|
||||
timeout.tv_usec = useconds;
|
||||
|
||||
/* sigset_t set; */
|
||||
/* sigemptyset(&set); */
|
||||
/* sigaddset(&set, SIGALRM); */
|
||||
/* pthread_sigmask(SIG_BLOCK, &set, NULL); */
|
||||
|
||||
select(0, NULL, NULL, NULL, &timeout);
|
||||
|
||||
/* pthread_sigmask(SIG_UNBLOCK, &set, NULL); */
|
||||
}
|
||||
|
||||
|
||||
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}};
|
||||
|
||||
#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) {
|
||||
uError("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)) {
|
||||
uError("Failed to init timer");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int signo;
|
||||
while (!stopTimer) {
|
||||
if (sigwait(&sigset, &signo)) {
|
||||
uError("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) {
|
||||
uError("failed to create timer thread");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void taosUninitTimer() {
|
||||
stopTimer = true;
|
||||
pthread_join(timerThread, NULL);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
|
||||
#ifndef TAOS_OS_FUNC_UTIL
|
||||
|
||||
int64_t tsosStr2int64(char *str) {
|
||||
char *endptr = NULL;
|
||||
return strtoll(str, &endptr, 10);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,12 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
PROJECT(TDengine)
|
||||
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc)
|
||||
AUX_SOURCE_DIRECTORY(. SRC)
|
||||
|
||||
ADD_LIBRARY(os ${SRC})
|
||||
TARGET_LINK_LIBRARIES(os m rt)
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "tglobal.h"
|
||||
#include "tulog.h"
|
||||
|
||||
void osInit() {
|
||||
strcpy(configDir, "/etc/taos");
|
||||
strcpy(tsVnodeDir, "");
|
||||
strcpy(tsDnodeDir, "");
|
||||
strcpy(tsMnodeDir, "");
|
||||
strcpy(tsDataDir, "/var/lib/taos");
|
||||
strcpy(tsLogDir, "/var/log/taos");
|
||||
strcpy(tsScriptDir, "/etc/taos");
|
||||
strcpy(tsOsName, "Linux");
|
||||
}
|
|
@ -398,7 +398,7 @@ char *strndup(const char *s, size_t n) {
|
|||
void taosSetCoreDump() {}
|
||||
|
||||
#ifdef _TD_GO_DLL_
|
||||
int64_t str2int64(char *str) {
|
||||
int64_t tsosStr2int64(char *str) {
|
||||
char *endptr = NULL;
|
||||
return strtoll(str, &endptr, 10);
|
||||
}
|
|
@ -3,6 +3,7 @@ PROJECT(TDengine)
|
|||
|
||||
IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc)
|
||||
|
@ -10,7 +11,6 @@ IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
|
|||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/zlib-1.2.11/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/cJson/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/lz4/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
|
||||
INCLUDE_DIRECTORIES(inc)
|
||||
AUX_SOURCE_DIRECTORY(src SRC)
|
||||
ADD_LIBRARY(http ${SRC})
|
||||
|
|
|
@ -45,7 +45,7 @@ int httpWriteBufByFd(struct HttpContext* pContext, const char* buf, int sz) {
|
|||
|
||||
do {
|
||||
if (pContext->fd > 2){
|
||||
len = (int)send(pContext->fd, buf + writeLen, (size_t)(sz - writeLen), MSG_NOSIGNAL);
|
||||
len = (int)taosSend(pContext->fd, buf + writeLen, (size_t)(sz - writeLen), MSG_NOSIGNAL);
|
||||
}
|
||||
else {
|
||||
return sz;
|
||||
|
|
|
@ -3,11 +3,11 @@ PROJECT(TDengine)
|
|||
|
||||
IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
|
||||
INCLUDE_DIRECTORIES(inc)
|
||||
AUX_SOURCE_DIRECTORY(./src SRC)
|
||||
ADD_LIBRARY(monitor ${SRC})
|
||||
|
|
|
@ -3,6 +3,7 @@ PROJECT(TDengine)
|
|||
|
||||
IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc)
|
||||
|
@ -10,7 +11,6 @@ IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
|
|||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/cJson/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/MQTT-C/include)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/MQTT-C/examples/templates)
|
||||
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
|
||||
INCLUDE_DIRECTORIES(inc)
|
||||
AUX_SOURCE_DIRECTORY(src SRC)
|
||||
ADD_LIBRARY(mqtt ${SRC})
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
PROJECT(TDengine)
|
||||
|
||||
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/tsdb/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc)
|
||||
|
|
|
@ -5901,8 +5901,10 @@ _cleanup_qinfo:
|
|||
tsdbDestroyTableGroup(pTableGroupInfo);
|
||||
|
||||
_cleanup_query:
|
||||
taosArrayDestroy(pGroupbyExpr->columnInfo);
|
||||
tfree(pGroupbyExpr);
|
||||
if (pGroupbyExpr != NULL) {
|
||||
taosArrayDestroy(pGroupbyExpr->columnInfo);
|
||||
free(pGroupbyExpr);
|
||||
}
|
||||
tfree(pTagCols);
|
||||
for (int32_t i = 0; i < numOfOutput; ++i) {
|
||||
SExprInfo* pExprInfo = &pExprs[i];
|
||||
|
|
|
@ -740,7 +740,7 @@ int32_t tsBufMerge(STSBuf* pDestBuf, const STSBuf* pSrcBuf, int32_t vnodeId) {
|
|||
int32_t size = pSrcBuf->fileSize - offset;
|
||||
|
||||
#ifdef LINUX
|
||||
ssize_t rc = tsendfile(fileno(pDestBuf->f), fileno(pSrcBuf->f), &offset, size);
|
||||
ssize_t rc = taosTSendFile(fileno(pDestBuf->f), fileno(pSrcBuf->f), &offset, size);
|
||||
#else
|
||||
ssize_t rc = fsendfile(pDestBuf->f, pSrcBuf->f, &offset, size);
|
||||
#endif
|
||||
|
|
|
@ -41,6 +41,9 @@ int32_t initWindowResInfo(SWindowResInfo *pWindowResInfo, SQueryRuntimeEnv *pRun
|
|||
pWindowResInfo->type = type;
|
||||
_hash_fn_t fn = taosGetDefaultHashFunction(type);
|
||||
pWindowResInfo->hashList = taosHashInit(threshold, fn, false);
|
||||
if (pWindowResInfo->hashList == NULL) {
|
||||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pWindowResInfo->curIndex = -1;
|
||||
pWindowResInfo->size = 0;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
PROJECT(TDengine)
|
||||
|
||||
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/cJson/inc)
|
||||
|
@ -12,10 +12,11 @@ INCLUDE_DIRECTORIES(inc)
|
|||
IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
|
||||
AUX_SOURCE_DIRECTORY(./src SRC)
|
||||
ELSEIF (TD_DARWIN_64)
|
||||
LIST(APPEND SRC ./src/thaship.c)
|
||||
LIST(APPEND SRC ./src/trpc.c)
|
||||
LIST(APPEND SRC ./src/tstring.c)
|
||||
LIST(APPEND SRC ./src/tudp.c)
|
||||
#LIST(APPEND SRC ./src/thaship.c)
|
||||
#LIST(APPEND SRC ./src/trpc.c)
|
||||
#LIST(APPEND SRC ./src/tstring.c)
|
||||
#LIST(APPEND SRC ./src/tudp.c)
|
||||
AUX_SOURCE_DIRECTORY(src SRC)
|
||||
ELSEIF (TD_WINDOWS_64)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/pthread)
|
||||
LIST(APPEND SRC ./src/thaship.c)
|
||||
|
|
|
@ -626,6 +626,7 @@ static void rpcReleaseConn(SRpcConn *pConn) {
|
|||
pConn->pReqMsg = NULL;
|
||||
pConn->reqMsgLen = 0;
|
||||
pConn->pContext = NULL;
|
||||
pConn->chandle = NULL;
|
||||
|
||||
taosFreeId(pRpc->idPool, pConn->sid);
|
||||
tDebug("%s, rpc connection is released", pConn->info);
|
||||
|
@ -656,11 +657,11 @@ static SRpcConn *rpcAllocateClientConn(SRpcInfo *pRpc) {
|
|||
pConn->sid = sid;
|
||||
pConn->tranId = (uint16_t)(random() & 0xFFFF);
|
||||
pConn->ownId = htonl(pConn->sid);
|
||||
pConn->linkUid = (uint32_t)((int64_t)pConn + (int64_t)getpid());
|
||||
pConn->linkUid = (uint32_t)((int64_t)pConn + (int64_t)getpid() + (int64_t)pConn->tranId);
|
||||
pConn->spi = pRpc->spi;
|
||||
pConn->encrypt = pRpc->encrypt;
|
||||
if (pConn->spi) memcpy(pConn->secret, pRpc->secret, TSDB_KEY_LEN);
|
||||
tDebug("%s %p client connection is allocated", pRpc->label, pConn);
|
||||
tDebug("%s %p client connection is allocated, uid:0x%x", pRpc->label, pConn, pConn->linkUid);
|
||||
}
|
||||
|
||||
return pConn;
|
||||
|
@ -721,7 +722,7 @@ static SRpcConn *rpcAllocateServerConn(SRpcInfo *pRpc, SRecvInfo *pRecv) {
|
|||
}
|
||||
|
||||
taosHashPut(pRpc->hash, hashstr, size, (char *)&pConn, POINTER_BYTES);
|
||||
tDebug("%s %p server connection is allocated", pRpc->label, pConn);
|
||||
tDebug("%s %p server connection is allocated, uid:0x%x", pRpc->label, pConn, pConn->linkUid);
|
||||
}
|
||||
|
||||
return pConn;
|
||||
|
@ -848,6 +849,16 @@ static int rpcProcessRspHead(SRpcConn *pConn, SRpcHead *pHead) {
|
|||
return TSDB_CODE_RPC_ALREADY_PROCESSED;
|
||||
}
|
||||
|
||||
if (pHead->code == TSDB_CODE_RPC_MISMATCHED_LINK_ID) {
|
||||
tDebug("%s, mismatched linkUid, link shall be restarted", pConn->info);
|
||||
pConn->secured = 0;
|
||||
((SRpcHead *)pConn->pReqMsg)->destId = 0;
|
||||
rpcSendMsgToPeer(pConn, pConn->pReqMsg, pConn->reqMsgLen);
|
||||
if (pConn->connType != RPC_CONN_TCPC)
|
||||
pConn->pTimer = taosTmrStart(rpcProcessRetryTimer, tsRpcTimer, pConn, pRpc->tmrCtrl);
|
||||
return TSDB_CODE_RPC_ALREADY_PROCESSED;
|
||||
}
|
||||
|
||||
if (pHead->code == TSDB_CODE_RPC_ACTION_IN_PROGRESS) {
|
||||
if (pConn->tretry <= tsRpcMaxRetry) {
|
||||
tDebug("%s, peer is still processing the transaction, retry:%d", pConn->info, pConn->tretry);
|
||||
|
@ -903,7 +914,7 @@ static SRpcConn *rpcProcessMsgHead(SRpcInfo *pRpc, SRecvInfo *pRecv) {
|
|||
}
|
||||
|
||||
sid = pConn->sid;
|
||||
pConn->chandle = pRecv->chandle;
|
||||
if (pConn->chandle == NULL) pConn->chandle = pRecv->chandle;
|
||||
pConn->peerIp = pRecv->ip;
|
||||
pConn->peerPort = pRecv->port;
|
||||
if (pHead->port) pConn->peerPort = htons(pHead->port);
|
||||
|
@ -1005,7 +1016,7 @@ static void *rpcProcessMsgFromPeer(SRecvInfo *pRecv) {
|
|||
if (code != 0) { // parsing error
|
||||
if (rpcIsReq(pHead->msgType)) {
|
||||
rpcSendErrorMsgToPeer(pRecv, code);
|
||||
tDebug("%s %p %p, %s is sent with error code:%x", pRpc->label, pConn, (void *)pHead->ahandle, taosMsg[pHead->msgType+1], code);
|
||||
tDebug("%s %p %p, %s is sent with error code:0x%x", pRpc->label, pConn, (void *)pHead->ahandle, taosMsg[pHead->msgType+1], code);
|
||||
}
|
||||
} else { // msg is passed to app only parsing is ok
|
||||
rpcProcessIncomingMsg(pConn, pHead);
|
||||
|
|
|
@ -242,7 +242,7 @@ int taosSendUdpData(uint32_t ip, uint16_t port, void *data, int dataLen, void *c
|
|||
destAdd.sin_addr.s_addr = ip;
|
||||
destAdd.sin_port = htons(port);
|
||||
|
||||
int ret = (int)sendto(pConn->fd, data, (size_t)dataLen, 0, (struct sockaddr *)&destAdd, sizeof(destAdd));
|
||||
int ret = (int)taosSendto(pConn->fd, data, (size_t)dataLen, 0, (struct sockaddr *)&destAdd, sizeof(destAdd));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
PROJECT(TDengine)
|
||||
|
||||
IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
|
||||
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc)
|
||||
INCLUDE_DIRECTORIES(../inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/rpc/inc)
|
||||
|
||||
IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
|
||||
LIST(APPEND CLIENT_SRC ./rclient.c)
|
||||
ADD_EXECUTABLE(rclient ${CLIENT_SRC})
|
||||
TARGET_LINK_LIBRARIES(rclient trpc)
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
PROJECT(TDengine)
|
||||
|
||||
IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc)
|
||||
INCLUDE_DIRECTORIES(${TD_ENTERPRISE_DIR}/src/inc)
|
||||
INCLUDE_DIRECTORIES(inc)
|
||||
AUX_SOURCE_DIRECTORY(src SRC)
|
||||
LIST(REMOVE_ITEM SRC ./src/tarbitrator.c)
|
||||
|
||||
ADD_LIBRARY(sync ${SRC})
|
||||
TARGET_LINK_LIBRARIES(sync tutil pthread common)
|
||||
|
||||
LIST(APPEND BIN_SRC ./src/tarbitrator.c)
|
||||
LIST(APPEND BIN_SRC ./src/taosTcpPool.c)
|
||||
ADD_EXECUTABLE(tarbitrator ${BIN_SRC})
|
||||
TARGET_LINK_LIBRARIES(tarbitrator tutil sync common)
|
||||
|
||||
ADD_SUBDIRECTORY(test)
|
||||
ENDIF ()
|
|
@ -0,0 +1,176 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_SYNCINT_H
|
||||
#define TDENGINE_SYNCINT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define sFatal(...) { if (sDebugFlag & DEBUG_FATAL) { taosPrintLog("SYN FATAL ", sDebugFlag, __VA_ARGS__); }}
|
||||
#define sError(...) { if (sDebugFlag & DEBUG_ERROR) { taosPrintLog("SYN ERROR ", sDebugFlag, __VA_ARGS__); }}
|
||||
#define sWarn(...) { if (sDebugFlag & DEBUG_WARN) { taosPrintLog("SYN WARN ", sDebugFlag, __VA_ARGS__); }}
|
||||
#define sInfo(...) { if (sDebugFlag & DEBUG_INFO) { taosPrintLog("SYN ", sDebugFlag, __VA_ARGS__); }}
|
||||
#define sDebug(...) { if (sDebugFlag & DEBUG_DEBUG) { taosPrintLog("SYN ", sDebugFlag, __VA_ARGS__); }}
|
||||
#define sTrace(...) { if (sDebugFlag & DEBUG_TRACE) { taosPrintLog("SYN ", sDebugFlag, __VA_ARGS__); }}
|
||||
|
||||
#define TAOS_SMSG_SYNC_DATA 1
|
||||
#define TAOS_SMSG_FORWARD 2
|
||||
#define TAOS_SMSG_FORWARD_RSP 3
|
||||
#define TAOS_SMSG_SYNC_REQ 4
|
||||
#define TAOS_SMSG_SYNC_RSP 5
|
||||
#define TAOS_SMSG_SYNC_MUST 6
|
||||
#define TAOS_SMSG_STATUS 7
|
||||
|
||||
#define nodeRole pNode->peerInfo[pNode->selfIndex]->role
|
||||
#define nodeVersion pNode->peerInfo[pNode->selfIndex]->version
|
||||
#define nodeSStatus pNode->peerInfo[pNode->selfIndex]->sstatus
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
typedef struct {
|
||||
char type; // msg type
|
||||
char pversion; // protocol version
|
||||
char reserved[6]; // not used
|
||||
int32_t vgId; // vg ID
|
||||
int32_t len; // content length, does not include head
|
||||
// char cont[]; // message content starts from here
|
||||
} SSyncHead;
|
||||
|
||||
typedef struct {
|
||||
SSyncHead syncHead;
|
||||
uint16_t port;
|
||||
char fqdn[TSDB_FQDN_LEN];
|
||||
int32_t sourceId; // only for arbitrator
|
||||
} SFirstPkt;
|
||||
|
||||
typedef struct {
|
||||
int8_t role;
|
||||
uint64_t version;
|
||||
} SPeerStatus;
|
||||
|
||||
typedef struct {
|
||||
int8_t role;
|
||||
int8_t ack;
|
||||
uint64_t version;
|
||||
SPeerStatus peersStatus[];
|
||||
} SPeersStatus;
|
||||
|
||||
typedef struct {
|
||||
char name[TSDB_FILENAME_LEN];
|
||||
uint32_t magic;
|
||||
uint32_t index;
|
||||
uint64_t fversion;
|
||||
int32_t size;
|
||||
} SFileInfo;
|
||||
|
||||
typedef struct {
|
||||
int8_t sync;
|
||||
} SFileAck;
|
||||
|
||||
typedef struct {
|
||||
uint64_t version;
|
||||
int32_t code;
|
||||
} SFwdRsp;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
typedef struct {
|
||||
char *buffer;
|
||||
int bufferSize;
|
||||
char *offset;
|
||||
int forwards;
|
||||
int code;
|
||||
} SRecvBuffer;
|
||||
|
||||
typedef struct {
|
||||
uint64_t version;
|
||||
void *mhandle;
|
||||
int8_t acks;
|
||||
int8_t nacks;
|
||||
int8_t confirmed;
|
||||
int32_t code;
|
||||
uint64_t time;
|
||||
} SFwdInfo;
|
||||
|
||||
typedef struct {
|
||||
int first;
|
||||
int last;
|
||||
int fwds; // number of forwards
|
||||
SFwdInfo fwdInfo[];
|
||||
} SSyncFwds;
|
||||
|
||||
typedef struct SsyncPeer {
|
||||
int32_t nodeId;
|
||||
uint32_t ip;
|
||||
uint16_t port;
|
||||
char fqdn[TSDB_FQDN_LEN]; // peer ip string
|
||||
char id[TSDB_EP_LEN+16]; // peer vgId + end point
|
||||
int8_t role;
|
||||
int8_t sstatus; // sync status
|
||||
uint64_t version;
|
||||
uint64_t sversion; // track the peer version in retrieve process
|
||||
int syncFd;
|
||||
int peerFd; // forward FD
|
||||
void *timer;
|
||||
void *pConn;
|
||||
int notifyFd;
|
||||
int watchNum;
|
||||
int *watchFd;
|
||||
int8_t refCount; // reference count
|
||||
struct SSyncNode *pSyncNode;
|
||||
} SSyncPeer;
|
||||
|
||||
typedef struct SSyncNode {
|
||||
char path[TSDB_FILENAME_LEN];
|
||||
int8_t replica;
|
||||
int8_t quorum;
|
||||
uint32_t vgId;
|
||||
void *ahandle;
|
||||
int8_t selfIndex;
|
||||
SSyncPeer *peerInfo[TAOS_SYNC_MAX_REPLICA+1]; // extra one for arbitrator
|
||||
SSyncPeer *pMaster;
|
||||
int8_t refCount;
|
||||
SRecvBuffer *pRecv;
|
||||
SSyncFwds *pSyncFwds; // saved forward info if quorum >1
|
||||
void *pFwdTimer;
|
||||
FGetFileInfo getFileInfo;
|
||||
FGetWalInfo getWalInfo;
|
||||
FWriteToCache writeToCache;
|
||||
FConfirmForward confirmForward;
|
||||
FNotifyRole notifyRole;
|
||||
FNotifyFileSynced notifyFileSynced;
|
||||
pthread_mutex_t mutex;
|
||||
} SSyncNode;
|
||||
|
||||
// sync module global
|
||||
extern int tsSyncNum;
|
||||
extern char tsNodeFqdn[TSDB_FQDN_LEN];
|
||||
|
||||
void *syncRetrieveData(void *param);
|
||||
void *syncRestoreData(void *param);
|
||||
int syncSaveIntoBuffer(SSyncPeer *pPeer, SWalHead *pHead);
|
||||
void syncRestartConnection(SSyncPeer *pPeer);
|
||||
void syncBroadcastStatus(SSyncNode *pNode);
|
||||
void syncAddPeerRef(SSyncPeer *pPeer);
|
||||
int syncDecPeerRef(SSyncPeer *pPeer);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TDENGINE_VNODEPEER_H
|
|
@ -13,18 +13,21 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_TSYSCTL_H
|
||||
#define TDENGINE_TSYSCTL_H
|
||||
#ifndef TDENGINE_PLUGINS_SYNC_H
|
||||
#define TDENGINE_PLUGINS_SYNC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _ALPINE
|
||||
#include <error.h>
|
||||
#include <sys/sysctl.h>
|
||||
#else
|
||||
#include <linux/sysctl.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
int32_t syncTest1();
|
||||
int32_t syncTest2();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_TCP_POOL_H
|
||||
#define TDENGINE_TCP_POOL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void* ttpool_h;
|
||||
typedef void* tthread_h;
|
||||
|
||||
typedef struct {
|
||||
int numOfThreads;
|
||||
uint32_t serverIp;
|
||||
short port;
|
||||
int bufferSize;
|
||||
void (*processBrokenLink)(void *ahandle);
|
||||
int (*processIncomingMsg)(void *ahandle, void *buffer);
|
||||
void (*processIncomingConn)(int fd, uint32_t ip);
|
||||
} SPoolInfo;
|
||||
|
||||
ttpool_h taosOpenTcpThreadPool(SPoolInfo *pInfo);
|
||||
void taosCloseTcpThreadPool(ttpool_h);
|
||||
void *taosAllocateTcpConn(void *, void *ahandle, int connFd);
|
||||
void taosFreeTcpConn(void *);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TDENGINE_TCP_POOL_H
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue