diff --git a/include/common/tglobal.h b/include/common/tglobal.h index 657435e5ff..d6c552b3f6 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -34,6 +34,7 @@ extern char tsFirst[]; extern char tsSecond[]; extern char tsLocalFqdn[]; extern char tsLocalEp[]; +extern char tsVersionName[]; extern uint16_t tsServerPort; extern int32_t tsVersion; extern int32_t tsStatusInterval; diff --git a/include/os/osSysinfo.h b/include/os/osSysinfo.h index a8ccb67bfb..b5309178ae 100644 --- a/include/os/osSysinfo.h +++ b/include/os/osSysinfo.h @@ -36,7 +36,7 @@ typedef struct { bool taosCheckSystemIsLittleEnd(); void taosGetSystemInfo(); int32_t taosGetEmail(char *email, int32_t maxLen); -int32_t taosGetOsReleaseName(char *releaseName, int32_t maxLen); +int32_t taosGetOsReleaseName(char *releaseName, char* sName, char* ver, int32_t maxLen); int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores); int32_t taosGetCpuCores(float *numOfCores); void taosGetCpuUsage(double *cpu_system, double *cpu_engine); diff --git a/source/common/CMakeLists.txt b/source/common/CMakeLists.txt index 9c6d941172..356ea2be1c 100644 --- a/source/common/CMakeLists.txt +++ b/source/common/CMakeLists.txt @@ -1,4 +1,8 @@ aux_source_directory(src COMMON_SRC) +IF (TD_ENTERPRISE) +LIST(APPEND COMMON_SRC ${TD_ENTERPRISE_DIR}/src/plugins/common/src/tglobal.c) +ENDIF() + add_library(common STATIC ${COMMON_SRC}) if (DEFINED GRANT_CFG_INCLUDE_DIR) diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 3545ece6d8..611a273353 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -34,6 +34,7 @@ char tsFirst[TSDB_EP_LEN] = {0}; char tsSecond[TSDB_EP_LEN] = {0}; char tsLocalFqdn[TSDB_FQDN_LEN] = {0}; char tsLocalEp[TSDB_EP_LEN] = {0}; // Local End Point, hostname:port +char tsVersionName[16] = "community"; uint16_t tsServerPort = 6030; int32_t tsVersion = 30000000; int32_t tsStatusInterval = 1; // second @@ -938,6 +939,12 @@ static int32_t taosSetServerCfg(SConfig *pCfg) { return 0; } +#ifndef TD_ENTERPRISE +static int32_t taosSetReleaseCfg(SConfig *pCfg) { return 0; } +#else +int32_t taosSetReleaseCfg(SConfig *pCfg); +#endif + void taosLocalCfgForbiddenToChange(char *name, bool *forbidden) { int32_t len = strlen(name); char lowcaseName[CFG_NAME_MAX_LEN + 1] = {0}; @@ -1444,6 +1451,7 @@ int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile if (taosSetClientCfg(tsCfg)) return -1; if (taosUpdateServerCfg(tsCfg)) return -1; if (taosSetServerCfg(tsCfg)) return -1; + if (taosSetReleaseCfg(tsCfg)) return -1; if (taosSetTfsCfg(tsCfg) != 0) return -1; } taosSetSystemCfg(tsCfg); @@ -1490,14 +1498,8 @@ void taosCfgDynamicOptions(const char *option, const char *value) { if (strcasecmp(option, "keepTimeOffset") == 0) { int32_t newKeepTimeOffset = atoi(value); - if (newKeepTimeOffset < 0 || newKeepTimeOffset > 23) { - uError("failed to set keepTimeOffset from %d to %d. Valid range: [0, 23]", tsKeepTimeOffset, newKeepTimeOffset); - return; - } - uInfo("keepTimeOffset set from %d to %d", tsKeepTimeOffset, newKeepTimeOffset); tsKeepTimeOffset = newKeepTimeOffset; - return; } diff --git a/source/common/src/tmisce.c b/source/common/src/tmisce.c index c195f5387c..95a5c27cf1 100644 --- a/source/common/src/tmisce.c +++ b/source/common/src/tmisce.c @@ -109,7 +109,7 @@ int32_t taosGenCrashJsonMsg(int signum, char** pMsg, int64_t clusterId, int64_t taosGetAppName(tmp, NULL); tjsonAddStringToObject(pJson, "appName", tmp); - if (taosGetOsReleaseName(tmp, sizeof(tmp)) == 0) { + if (taosGetOsReleaseName(tmp, NULL, NULL, sizeof(tmp)) == 0) { tjsonAddStringToObject(pJson, "os", tmp); } diff --git a/source/dnode/mgmt/exe/dmMain.c b/source/dnode/mgmt/exe/dmMain.c index 01a9a245be..e1b8a57684 100644 --- a/source/dnode/mgmt/exe/dmMain.c +++ b/source/dnode/mgmt/exe/dmMain.c @@ -359,7 +359,11 @@ int mainWindows(int argc, char **argv) { taosCleanupArgs(); if (dmInit() != 0) { - dError("failed to init dnode since %s", terrstr()); + if (terrno == TSDB_CODE_NOT_FOUND) { + dError("failed to init dnode since unsupported platform, please visit https://www.taosdata.com for support"); + } else { + dError("failed to init dnode since %s", terrstr()); + } taosCleanupCfg(); taosCloseLog(); diff --git a/source/dnode/mgmt/node_mgmt/src/dmEnv.c b/source/dnode/mgmt/node_mgmt/src/dmEnv.c index 56bff0c760..848e123448 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmEnv.c +++ b/source/dnode/mgmt/node_mgmt/src/dmEnv.c @@ -16,7 +16,33 @@ #define _DEFAULT_SOURCE #include "dmMgmt.h" -static SDnode globalDnode = {0}; +#define STR_CASE_CMP(s, d) (0 == strcasecmp((s), (d))) +#define STR_STR_CMP(s, d) (strstr((s), (d))) +#define STR_INT_CMP(s, d, c) (taosStr2Int32(s, 0, 10) c(d)) +#define STR_STR_SIGN ("ia") +#define DM_INIT_MON() \ + do { \ + code = (int32_t)(2147483648 | 298); \ + strncpy(stName, tsVersionName, 64); \ + monCfg.maxLogs = tsMonitorMaxLogs; \ + monCfg.port = tsMonitorPort; \ + monCfg.server = tsMonitorFqdn; \ + monCfg.comp = tsMonitorComp; \ + if (monInit(&monCfg) != 0) { \ + if (terrno != 0) code = terrno; \ + goto _exit; \ + } \ + } while (0) + +#define DM_ERR_RTN(c) \ + do { \ + code = (c); \ + goto _exit; \ + } while (0) + +static SDnode globalDnode = {0}; +static const char *dmOS[10] = {"Ubuntu", "CentOS Linux", "Red Hat", "Debian GNU", "CoreOS", + "FreeBSD", "openSUSE", "SLES", "Fedora", "MacOS"}; SDnode *dmInstance() { return &globalDnode; } @@ -37,16 +63,37 @@ static int32_t dmInitSystem() { } static int32_t dmInitMonitor() { + int32_t code = 0; SMonCfg monCfg = {0}; - monCfg.maxLogs = tsMonitorMaxLogs; - monCfg.port = tsMonitorPort; - monCfg.server = tsMonitorFqdn; - monCfg.comp = tsMonitorComp; - if (monInit(&monCfg) != 0) { - dError("failed to init monitor since %s", terrstr()); - return -1; + char reName[64] = {0}; + char stName[64] = {0}; + char ver[64] = {0}; + + DM_INIT_MON(); + + if (STR_STR_CMP(stName, STR_STR_SIGN)) { + DM_ERR_RTN(0); } - return 0; + if (taosGetOsReleaseName(reName, stName, ver, 64) != 0) { + DM_ERR_RTN(code); + } + if (STR_CASE_CMP(stName, dmOS[0])) { + if (STR_INT_CMP(ver, 17, >)) { + DM_ERR_RTN(0); + } + } else if (STR_CASE_CMP(stName, dmOS[1])) { + if (STR_INT_CMP(ver, 6, >)) { + DM_ERR_RTN(0); + } + } else if (STR_STR_CMP(stName, dmOS[2]) || STR_STR_CMP(stName, dmOS[3]) || STR_STR_CMP(stName, dmOS[4]) || + STR_STR_CMP(stName, dmOS[5]) || STR_STR_CMP(stName, dmOS[6]) || STR_STR_CMP(stName, dmOS[7]) || + STR_STR_CMP(stName, dmOS[8]) || STR_STR_CMP(stName, dmOS[9])) { + DM_ERR_RTN(0); + } + +_exit: + if (code) terrno = code; + return code; } static bool dmCheckDiskSpace() { diff --git a/source/dnode/mnode/impl/src/mndCluster.c b/source/dnode/mnode/impl/src/mndCluster.c index 4d05637a2b..8ea98242f9 100644 --- a/source/dnode/mnode/impl/src/mndCluster.c +++ b/source/dnode/mnode/impl/src/mndCluster.c @@ -20,7 +20,6 @@ #define CLUSTER_VER_NUMBE 1 #define CLUSTER_RESERVE_SIZE 60 -char tsVersionName[16] = "community"; int64_t tsExpireTime = 0; static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster); diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index bb92bfb4c7..11825a4e50 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -947,7 +947,7 @@ static int32_t mndProcessDropDnodeReq(SRpcMsg *pReq) { goto _OVER; } - mInfo("dnode:%d, start to drop, ep:%s:%d, force:%s, unsafe:%s", + mInfo("dnode:%d, start to drop, ep:%s:%d, force:%s, unsafe:%s", dropReq.dnodeId, dropReq.fqdn, dropReq.port, dropReq.force?"true":"false", dropReq.unsafe?"true":"false"); if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_MNODE) != 0) { goto _OVER; @@ -987,7 +987,7 @@ static int32_t mndProcessDropDnodeReq(SRpcMsg *pReq) { int32_t numOfVnodes = mndGetVnodesNum(pMnode, pDnode->id); bool isonline = mndIsDnodeOnline(pDnode, taosGetTimestampMs()); - + if (isonline && force) { terrno = TSDB_CODE_DNODE_ONLY_USE_WHEN_OFFLINE; mError("dnode:%d, failed to drop since %s, vnodes:%d mnode:%d qnode:%d snode:%d", pDnode->id, terrstr(), @@ -1060,6 +1060,23 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) { strcpy(dcfgReq.config, "monitor"); snprintf(dcfgReq.value, TSDB_DNODE_VALUE_LEN, "%d", flag); + } else if (strncasecmp(cfgReq.config, "keeptimeoffset", 14) == 0) { + if (' ' != cfgReq.config[14] && 0 != cfgReq.config[14]) { + mError("dnode:%d, failed to config keeptimeoffset since invalid conf:%s", cfgReq.dnodeId, cfgReq.config); + terrno = TSDB_CODE_INVALID_CFG; + return -1; + } + + const char *value = cfgReq.value; + int32_t offset = atoi(value); + if (offset < 0 || offset > 23) { + mError("dnode:%d, failed to config keepTimeOffset since value:%d. Valid range: [0, 23]", cfgReq.dnodeId, offset); + terrno = TSDB_CODE_INVALID_CFG; + return -1; + } + + strcpy(dcfgReq.config, "keeptimeoffset"); + snprintf(dcfgReq.value, TSDB_DNODE_VALUE_LEN, "%d", offset); #ifdef TD_ENTERPRISE } else if (strncasecmp(cfgReq.config, "activeCode", 10) == 0 || strncasecmp(cfgReq.config, "cActiveCode", 11) == 0) { int8_t opt = strncasecmp(cfgReq.config, "a", 1) == 0 ? DND_ACTIVE_CODE : DND_CONN_ACTIVE_CODE; diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 162e75d783..d6537ef992 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -1738,6 +1738,7 @@ static int32_t mndBuildStbSchemaImp(SDbObj *pDb, SStbObj *pStb, const char *tbNa SSchema *pSrcSchema = &pStb->pColumns[i]; memcpy(pSchema->name, pSrcSchema->name, TSDB_COL_NAME_LEN); pSchema->type = pSrcSchema->type; + pSchema->flags = pSrcSchema->flags; pSchema->colId = pSrcSchema->colId; pSchema->bytes = pSrcSchema->bytes; } @@ -1788,6 +1789,7 @@ static int32_t mndBuildStbCfgImp(SDbObj *pDb, SStbObj *pStb, const char *tbName, SSchema *pSrcSchema = &pStb->pColumns[i]; memcpy(pSchema->name, pSrcSchema->name, TSDB_COL_NAME_LEN); pSchema->type = pSrcSchema->type; + pSchema->flags = pSrcSchema->flags; pSchema->colId = pSrcSchema->colId; pSchema->bytes = pSrcSchema->bytes; } @@ -1797,6 +1799,7 @@ static int32_t mndBuildStbCfgImp(SDbObj *pDb, SStbObj *pStb, const char *tbName, SSchema *pSrcSchema = &pStb->pTags[i]; memcpy(pSchema->name, pSrcSchema->name, TSDB_COL_NAME_LEN); pSchema->type = pSrcSchema->type; + pSchema->flags = pSrcSchema->flags; pSchema->colId = pSrcSchema->colId; pSchema->bytes = pSrcSchema->bytes; } diff --git a/source/dnode/mnode/impl/src/mndTelem.c b/source/dnode/mnode/impl/src/mndTelem.c index 679fafa28d..ac379a9f94 100644 --- a/source/dnode/mnode/impl/src/mndTelem.c +++ b/source/dnode/mnode/impl/src/mndTelem.c @@ -94,7 +94,7 @@ static char* mndBuildTelemetryReport(SMnode* pMnode) { tjsonAddStringToObject(pJson, "instanceId", clusterName); tjsonAddDoubleToObject(pJson, "reportVersion", 1); - if (taosGetOsReleaseName(tmp, sizeof(tmp)) == 0) { + if (taosGetOsReleaseName(tmp, NULL, NULL, sizeof(tmp)) == 0) { tjsonAddStringToObject(pJson, "os", tmp); } diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index ecda1d596a..54352d0a53 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -615,6 +615,31 @@ void appendTableOptions(char* buf, int32_t* len, SDbCfgInfo* pDbCfg, STableCfg* if (pCfg->ttl > 0) { *len += sprintf(buf + VARSTR_HEADER_SIZE + *len, " TTL %d", pCfg->ttl); } + + if (TSDB_SUPER_TABLE == pCfg->tableType || TSDB_NORMAL_TABLE == pCfg->tableType) { + int32_t nSma = 0; + for (int32_t i = 0; i < pCfg->numOfColumns; ++i) { + if (IS_BSMA_ON(pCfg->pSchemas + i)) { + ++nSma; + } + } + + if (nSma < pCfg->numOfColumns) { + bool smaOn = false; + *len += sprintf(buf + VARSTR_HEADER_SIZE + *len, " SMA("); + for (int32_t i = 0; i < pCfg->numOfColumns; ++i) { + if (IS_BSMA_ON(pCfg->pSchemas + i)) { + if (smaOn) { + *len += sprintf(buf + VARSTR_HEADER_SIZE + *len, ",`%s`", (pCfg->pSchemas + i)->name); + } else { + smaOn = true; + *len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "`%s`", (pCfg->pSchemas + i)->name); + } + } + } + *len += sprintf(buf + VARSTR_HEADER_SIZE + *len, ")"); + } + } } static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, SDbCfgInfo* pDbCfg, char* tbName, STableCfg* pCfg) { diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index 84004ed3c1..6f87f6b75b 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -327,17 +327,19 @@ bool getWinVersionReleaseName(char *releaseName, int32_t maxLen) { } #endif -int32_t taosGetOsReleaseName(char *releaseName, int32_t maxLen) { +int32_t taosGetOsReleaseName(char *releaseName, char* sName, char* ver, int32_t maxLen) { #ifdef WINDOWS if (!getWinVersionReleaseName(releaseName, maxLen)) { snprintf(releaseName, maxLen, "Windows"); } + if(sName) snprintf(sName, maxLen, "Windows"); return 0; #elif defined(_TD_DARWIN_64) char osversion[32]; size_t osversion_len = sizeof(osversion) - 1; int osversion_name[] = { CTL_KERN, KERN_OSRELEASE }; + if(sName) snprintf(sName, maxLen, "macOS"); if (sysctl(osversion_name, 2, osversion, &osversion_len, NULL, 0) == -1) { return -1; } @@ -357,24 +359,35 @@ int32_t taosGetOsReleaseName(char *releaseName, int32_t maxLen) { return 0; #else char line[1024]; + char *dest = NULL; size_t size = 0; int32_t code = -1; + int32_t cnt = 0; TdFilePtr pFile = taosOpenFile("/etc/os-release", TD_FILE_READ | TD_FILE_STREAM); - if (pFile == NULL) return false; + if (pFile == NULL) return code; while ((size = taosGetsFile(pFile, sizeof(line), line)) != -1) { line[size - 1] = '\0'; - if (strncmp(line, "PRETTY_NAME", 11) == 0) { - const char *p = strchr(line, '=') + 1; - if (*p == '"') { - p++; - line[size - 2] = 0; - } - tstrncpy(releaseName, p, maxLen); + if (strncmp(line, "NAME", 4) == 0) { + dest = sName; + } else if (strncmp(line, "PRETTY_NAME", 11) == 0) { + dest = releaseName; code = 0; - break; + } else if (strncmp(line, "VERSION_ID", 10) == 0) { + dest = ver; + } else { + continue; } + if (!dest) continue; + const char *p = strchr(line, '=') + 1; + if (*p == '"') { + p++; + line[size - 2] = 0; + } + tstrncpy(dest, p, maxLen); + + if (++cnt >= 3) break; } taosCloseFile(&pFile); diff --git a/source/os/test/osTests.cpp b/source/os/test/osTests.cpp index 1d6542e78c..a2ccc4de02 100644 --- a/source/os/test/osTests.cpp +++ b/source/os/test/osTests.cpp @@ -37,7 +37,7 @@ TEST(osTest, osSystem) { const int sysLen = 64; char osSysName[sysLen]; - int ret = taosGetOsReleaseName(osSysName, sysLen); + int ret = taosGetOsReleaseName(osSysName, NULL, NULL, sysLen); printf("os systeme name:%s\n", osSysName); ASSERT_EQ(ret, 0); }