Merge branch '3.0' into fix/TD-30990
This commit is contained in:
commit
c9ab734b16
|
@ -12,7 +12,7 @@ extern "C" {
|
|||
#include "tarray.h"
|
||||
|
||||
void stopRsync();
|
||||
void startRsync();
|
||||
int32_t startRsync();
|
||||
int32_t uploadByRsync(const char* id, const char* path);
|
||||
int32_t downloadRsync(const char* id, const char* path);
|
||||
int32_t deleteRsync(const char* id);
|
||||
|
|
|
@ -335,7 +335,7 @@ SSchema createSchema(int8_t type, int32_t bytes, col_id_t colId, const char* nam
|
|||
|
||||
void destroyQueryExecRes(SExecResult* pRes);
|
||||
int32_t dataConverToStr(char* str, int type, void* buf, int32_t bufSize, int32_t* len);
|
||||
char* parseTagDatatoJson(void* p);
|
||||
void parseTagDatatoJson(void* p, char** jsonStr);
|
||||
int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst);
|
||||
void getColumnTypeFromMeta(STableMeta* pMeta, char* pName, ETableColumnType* pType);
|
||||
int32_t cloneDbVgInfo(SDBVgInfo* pSrc, SDBVgInfo** pDst);
|
||||
|
|
|
@ -53,7 +53,7 @@ int32_t taosGetErrSize();
|
|||
#define terrln (*taosGetErrln())
|
||||
|
||||
#define SET_ERROR_MSG(MSG, ...) \
|
||||
snprintf(terrMsg, ERR_MSG_LEN, MSG, ##__VA_ARGS__)
|
||||
(void)snprintf(terrMsg, ERR_MSG_LEN, MSG, ##__VA_ARGS__)
|
||||
|
||||
#define TSDB_CODE_SUCCESS 0
|
||||
#define TSDB_CODE_FAILED -1 // unknown or needn't tell detail error
|
||||
|
|
|
@ -885,7 +885,11 @@ void taos_init_imp(void) {
|
|||
taosSetCoreDump(true);
|
||||
#endif
|
||||
|
||||
initTaskQueue();
|
||||
if (initTaskQueue() != 0){
|
||||
tscInitRes = -1;
|
||||
tscError("failed to init task queue");
|
||||
return;
|
||||
}
|
||||
fmFuncMgtInit();
|
||||
nodesInitAllocatorSet();
|
||||
|
||||
|
|
|
@ -2007,7 +2007,8 @@ static int32_t doConvertJson(SReqResultInfo* pResultInfo, int32_t numOfCols, int
|
|||
sprintf(varDataVal(dst), "%s", TSDB_DATA_NULL_STR_L);
|
||||
varDataSetLen(dst, strlen(varDataVal(dst)));
|
||||
} else if (tTagIsJson(data)) {
|
||||
char* jsonString = parseTagDatatoJson(data);
|
||||
char* jsonString = NULL;
|
||||
parseTagDatatoJson(data, &jsonString);
|
||||
STR_TO_VARSTR(dst, jsonString);
|
||||
taosMemoryFree(jsonString);
|
||||
} else if (jsonInnerType == TSDB_DATA_TYPE_NCHAR) { // value -> "value"
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -23,11 +23,11 @@ TARGET_LINK_LIBRARIES(
|
|||
PUBLIC os util common transport parser catalog scheduler function gtest taos_static qcom geometry
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(clientMonitorTest clientMonitorTests.cpp)
|
||||
TARGET_LINK_LIBRARIES(
|
||||
clientMonitorTest
|
||||
PUBLIC os util common transport monitor parser catalog scheduler function gtest taos_static qcom executor
|
||||
)
|
||||
#ADD_EXECUTABLE(clientMonitorTest clientMonitorTests.cpp)
|
||||
#TARGET_LINK_LIBRARIES(
|
||||
# clientMonitorTest
|
||||
# PUBLIC os util common transport monitor parser catalog scheduler function gtest taos_static qcom executor
|
||||
#)
|
||||
|
||||
TARGET_INCLUDE_DIRECTORIES(
|
||||
clientTest
|
||||
|
@ -47,11 +47,11 @@ TARGET_INCLUDE_DIRECTORIES(
|
|||
PRIVATE "${TD_SOURCE_DIR}/source/client/inc"
|
||||
)
|
||||
|
||||
TARGET_INCLUDE_DIRECTORIES(
|
||||
clientMonitorTest
|
||||
PUBLIC "${TD_SOURCE_DIR}/include/client/"
|
||||
PRIVATE "${TD_SOURCE_DIR}/source/client/inc"
|
||||
)
|
||||
#TARGET_INCLUDE_DIRECTORIES(
|
||||
# clientMonitorTest
|
||||
# PUBLIC "${TD_SOURCE_DIR}/include/client/"
|
||||
# PRIVATE "${TD_SOURCE_DIR}/source/client/inc"
|
||||
#)
|
||||
|
||||
add_test(
|
||||
NAME smlTest
|
||||
|
|
|
@ -54,10 +54,11 @@ static void changeDirFromWindowsToLinux(char* from, char* to) {
|
|||
#endif
|
||||
|
||||
static int32_t generateConfigFile(char* confDir) {
|
||||
int32_t code = 0;
|
||||
TdFilePtr pFile = taosOpenFile(confDir, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pFile == NULL) {
|
||||
uError("[rsync] open conf file error, dir:%s," ERRNO_ERR_FORMAT, confDir, ERRNO_ERR_DATA);
|
||||
return -1;
|
||||
return TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
|
||||
#ifdef WINDOWS
|
||||
|
@ -92,7 +93,8 @@ static int32_t generateConfigFile(char* confDir) {
|
|||
if (taosWriteFile(pFile, confContent, strlen(confContent)) <= 0) {
|
||||
uError("[rsync] write conf file error," ERRNO_ERR_FORMAT, ERRNO_ERR_DATA);
|
||||
taosCloseFile(&pFile);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
return code;
|
||||
}
|
||||
|
||||
taosCloseFile(&pFile);
|
||||
|
@ -129,11 +131,13 @@ void stopRsync() {
|
|||
taosMsleep(500); // sleep 500 ms to wait for the completion of kill operation.
|
||||
}
|
||||
|
||||
void startRsync() {
|
||||
int32_t startRsync() {
|
||||
int32_t code = 0;
|
||||
if (taosMulMkDir(tsCheckpointBackupDir) != 0) {
|
||||
uError("[rsync] build checkpoint backup dir failed, path:%s," ERRNO_ERR_FORMAT, tsCheckpointBackupDir,
|
||||
ERRNO_ERR_DATA);
|
||||
return;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
return code;
|
||||
}
|
||||
|
||||
removeEmptyDir();
|
||||
|
@ -141,9 +145,9 @@ void startRsync() {
|
|||
char confDir[PATH_MAX] = {0};
|
||||
snprintf(confDir, PATH_MAX, "%srsync.conf", tsCheckpointBackupDir);
|
||||
|
||||
int32_t code = generateConfigFile(confDir);
|
||||
code = generateConfigFile(confDir);
|
||||
if (code != 0) {
|
||||
return;
|
||||
return code;
|
||||
}
|
||||
|
||||
char cmd[PATH_MAX] = {0};
|
||||
|
@ -152,9 +156,11 @@ void startRsync() {
|
|||
code = system(cmd);
|
||||
if (code != 0) {
|
||||
uError("[rsync] cmd:%s start server failed, code:%d," ERRNO_ERR_FORMAT, cmd, code, ERRNO_ERR_DATA);
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
} else {
|
||||
uInfo("[rsync] cmd:%s start server successful", cmd);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t uploadByRsync(const char* id, const char* path) {
|
||||
|
@ -199,6 +205,7 @@ int32_t uploadByRsync(const char* id, const char* path) {
|
|||
if (code != 0) {
|
||||
uError("[rsync] s-task:%s prepare checkpoint data in %s to %s failed, code:%d," ERRNO_ERR_FORMAT, id, path,
|
||||
tsSnodeAddress, code, ERRNO_ERR_DATA);
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
} else {
|
||||
int64_t el = (taosGetTimestampMs() - st);
|
||||
uDebug("[rsync] s-task:%s prepare checkpoint data in:%s to %s successfully, elapsed time:%" PRId64 "ms", id, path,
|
||||
|
@ -242,6 +249,7 @@ int32_t uploadByRsync(const char* id, const char* path) {
|
|||
if (code != 0) {
|
||||
uError("[rsync] s-task:%s upload checkpoint data in %s to %s failed, code:%d," ERRNO_ERR_FORMAT, id, path,
|
||||
tsSnodeAddress, code, ERRNO_ERR_DATA);
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
} else {
|
||||
int64_t el = (taosGetTimestampMs() - st);
|
||||
uDebug("[rsync] s-task:%s upload checkpoint data in:%s to %s successfully, elapsed time:%" PRId64 "ms", id, path,
|
||||
|
@ -283,13 +291,13 @@ int32_t downloadRsync(const char* id, const char* path) {
|
|||
uError("[rsync] %s download checkpoint data:%s failed, retry after 1sec, times:%d, code:%d," ERRNO_ERR_FORMAT, id,
|
||||
path, times, code, ERRNO_ERR_DATA);
|
||||
taosSsleep(1);
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
} else {
|
||||
int32_t el = taosGetTimestampMs() - st;
|
||||
uDebug("[rsync] %s download checkpoint data:%s successfully, elapsed time:%dms", id, path, el);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -298,7 +306,7 @@ int32_t deleteRsync(const char* id) {
|
|||
int32_t code = taosMkDir(tmp);
|
||||
if (code != 0) {
|
||||
uError("[rsync] make tmp dir failed. code:%d," ERRNO_ERR_FORMAT, code, ERRNO_ERR_DATA);
|
||||
return -1;
|
||||
return TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
|
||||
char command[PATH_MAX] = {0};
|
||||
|
@ -310,7 +318,7 @@ int32_t deleteRsync(const char* id) {
|
|||
taosRemoveDir(tmp);
|
||||
if (code != 0) {
|
||||
uError("[rsync] get failed code:%d," ERRNO_ERR_FORMAT, code, ERRNO_ERR_DATA);
|
||||
return -1;
|
||||
return TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
|
||||
uDebug("[rsync] delete data:%s successful", id);
|
||||
|
|
|
@ -1370,58 +1370,68 @@ static int32_t taosCheckGlobalCfg() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t cfgInitWrapper(SConfig **pCfg) {
|
||||
if (*pCfg == NULL) {
|
||||
*pCfg = cfgInit();
|
||||
if (*pCfg == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, SArray *pArgs,
|
||||
bool tsc) {
|
||||
if (tsCfg != NULL) return 0;
|
||||
tsCfg = cfgInit();
|
||||
|
||||
int32_t code = cfgInitWrapper(&tsCfg);
|
||||
|
||||
if (tsc) {
|
||||
if (taosAddClientCfg(tsCfg) != 0) return -1;
|
||||
if (taosAddClientLogCfg(tsCfg) != 0) return -1;
|
||||
if ((code = taosAddClientCfg(tsCfg)) != 0) return code;
|
||||
if ((code = taosAddClientLogCfg(tsCfg)) != 0) return code;
|
||||
} else {
|
||||
if (taosAddClientCfg(tsCfg) != 0) return -1;
|
||||
if (taosAddServerCfg(tsCfg) != 0) return -1;
|
||||
if (taosAddClientLogCfg(tsCfg) != 0) return -1;
|
||||
if (taosAddServerLogCfg(tsCfg) != 0) return -1;
|
||||
if ((code = taosAddClientCfg(tsCfg)) != 0) return code;
|
||||
if ((code = taosAddServerCfg(tsCfg)) != 0) return code;
|
||||
if ((code = taosAddClientLogCfg(tsCfg)) != 0) return code;
|
||||
if ((code = taosAddServerLogCfg(tsCfg)) != 0) return code;
|
||||
}
|
||||
|
||||
taosAddSystemCfg(tsCfg);
|
||||
code = taosAddSystemCfg(tsCfg);
|
||||
|
||||
if (taosLoadCfg(tsCfg, envCmd, cfgDir, envFile, apolloUrl) != 0) {
|
||||
uError("failed to load cfg since %s", terrstr());
|
||||
if ((code = taosLoadCfg(tsCfg, envCmd, cfgDir, envFile, apolloUrl)) != 0) {
|
||||
uError("failed to load cfg since %s", tstrerror(code));
|
||||
cfgCleanup(tsCfg);
|
||||
tsCfg = NULL;
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (cfgLoadFromArray(tsCfg, pArgs) != 0) {
|
||||
uError("failed to load cfg from array since %s", terrstr());
|
||||
if ((code = cfgLoadFromArray(tsCfg, pArgs)) != 0) {
|
||||
uError("failed to load cfg from array since %s", tstrerror(code));
|
||||
cfgCleanup(tsCfg);
|
||||
tsCfg = NULL;
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (tsc) {
|
||||
if (taosSetClientCfg(tsCfg)) return -1;
|
||||
if ((code = taosSetClientCfg(tsCfg)) != 0) return code;
|
||||
} else {
|
||||
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;
|
||||
if (taosSetS3Cfg(tsCfg) != 0) return -1;
|
||||
if ((code = taosSetClientCfg(tsCfg)) != 0) return code;
|
||||
if ((code = taosUpdateServerCfg(tsCfg)) != 0) return code;
|
||||
if ((code = taosSetServerCfg(tsCfg)) != 0) return code;
|
||||
if ((code = taosSetReleaseCfg(tsCfg)) != 0) return code;
|
||||
if ((code = taosSetTfsCfg(tsCfg)) != 0) return code;
|
||||
if ((code = taosSetS3Cfg(tsCfg)) != 0) return code;
|
||||
}
|
||||
|
||||
taosSetSystemCfg(tsCfg);
|
||||
|
||||
if (taosSetFileHandlesLimit() != 0) return -1;
|
||||
if ((code = taosSetFileHandlesLimit()) != 0) return code;
|
||||
|
||||
taosSetAllDebugFlag(tsCfg, cfgGetItem(tsCfg, "debugFlag")->i32);
|
||||
|
||||
cfgDumpCfg(tsCfg, tsc, false);
|
||||
|
||||
if (taosCheckGlobalCfg() != 0) {
|
||||
return -1;
|
||||
if ((code = taosCheckGlobalCfg()) != 0) {
|
||||
return code;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -10828,7 +10828,9 @@ int32_t tDecodeMqBatchMetaRsp(SDecoder *pDecoder, SMqBatchMetaRsp *pRsp) {
|
|||
if (tDecodeI32(pDecoder, &size) < 0) return -1;
|
||||
if (size > 0) {
|
||||
pRsp->batchMetaReq = taosArrayInit(size, POINTER_BYTES);
|
||||
if (!pRsp->batchMetaReq) return -1;
|
||||
pRsp->batchMetaLen = taosArrayInit(size, sizeof(int32_t));
|
||||
if (!pRsp->batchMetaLen) return -1;
|
||||
for (int32_t i = 0; i < size; i++) {
|
||||
void *pCreate = NULL;
|
||||
uint64_t len = 0;
|
||||
|
|
|
@ -167,23 +167,23 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
|
|||
if (i < argc - 1) {
|
||||
if (strlen(argv[++i]) >= PATH_MAX) {
|
||||
printf("config file path overflow");
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_CFG;
|
||||
}
|
||||
tstrncpy(configDir, argv[i], PATH_MAX);
|
||||
} else {
|
||||
printf("'-c' requires a parameter, default is %s\n", configDir);
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_CFG;
|
||||
}
|
||||
} else if (strcmp(argv[i], "-a") == 0) {
|
||||
if (i < argc - 1) {
|
||||
if (strlen(argv[++i]) >= PATH_MAX) {
|
||||
printf("apollo url overflow");
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_CFG;
|
||||
}
|
||||
tstrncpy(global.apolloUrl, argv[i], PATH_MAX);
|
||||
} else {
|
||||
printf("'-a' requires a parameter\n");
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_CFG;
|
||||
}
|
||||
} else if (strcmp(argv[i], "-s") == 0) {
|
||||
global.dumpSdb = true;
|
||||
|
@ -191,31 +191,31 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
|
|||
if (i < argc - 1) {
|
||||
if (strlen(argv[++i]) >= PATH_MAX) {
|
||||
printf("env file path overflow");
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_CFG;
|
||||
}
|
||||
tstrncpy(global.envFile, argv[i], PATH_MAX);
|
||||
} else {
|
||||
printf("'-E' requires a parameter\n");
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_CFG;
|
||||
}
|
||||
} else if (strcmp(argv[i], "-k") == 0) {
|
||||
global.generateGrant = true;
|
||||
} else if (strcmp(argv[i], "-y") == 0) {
|
||||
global.generateCode = true;
|
||||
if(i < argc - 1) {
|
||||
if (i < argc - 1) {
|
||||
int32_t len = strlen(argv[++i]);
|
||||
if (len < ENCRYPT_KEY_LEN_MIN) {
|
||||
printf("ERROR: Encrypt key should be at least %d characters\n", ENCRYPT_KEY_LEN_MIN);
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_CFG;
|
||||
}
|
||||
if (len > ENCRYPT_KEY_LEN) {
|
||||
printf("ERROR: Encrypt key overflow, it should be at most %d characters\n", ENCRYPT_KEY_LEN);
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_CFG;
|
||||
}
|
||||
tstrncpy(global.encryptKey, argv[i], ENCRYPT_KEY_LEN);
|
||||
} else {
|
||||
printf("'-y' requires a parameter\n");
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_CFG;
|
||||
}
|
||||
} else if (strcmp(argv[i], "-C") == 0) {
|
||||
global.dumpConfig = true;
|
||||
|
@ -310,6 +310,7 @@ static void taosCleanupArgs() {
|
|||
}
|
||||
|
||||
int main(int argc, char const *argv[]) {
|
||||
int32_t code = 0;
|
||||
#ifdef TD_JEMALLOC_ENABLED
|
||||
bool jeBackgroundThread = true;
|
||||
mallctl("background_thread", NULL, NULL, &jeBackgroundThread, sizeof(bool));
|
||||
|
@ -319,10 +320,10 @@ int main(int argc, char const *argv[]) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (dmParseArgs(argc, argv) != 0) {
|
||||
//printf("failed to start since parse args error\n");
|
||||
if ((code = dmParseArgs(argc, argv)) != 0) {
|
||||
// printf("failed to start since parse args error\n");
|
||||
taosCleanupArgs();
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
#ifdef WINDOWS
|
||||
|
@ -335,6 +336,7 @@ int main(int argc, char const *argv[]) {
|
|||
return 0;
|
||||
}
|
||||
int mainWindows(int argc, char **argv) {
|
||||
int32_t code = 0;
|
||||
#endif
|
||||
|
||||
if (global.generateGrant) {
|
||||
|
@ -357,7 +359,7 @@ int mainWindows(int argc, char **argv) {
|
|||
|
||||
#if defined(LINUX)
|
||||
if (global.memDbg) {
|
||||
int32_t code = taosMemoryDbgInit();
|
||||
code = taosMemoryDbgInit();
|
||||
if (code) {
|
||||
printf("failed to init memory dbg, error:%s\n", tstrerror(code));
|
||||
return code;
|
||||
|
@ -366,16 +368,18 @@ int mainWindows(int argc, char **argv) {
|
|||
printf("memory dbg enabled\n");
|
||||
}
|
||||
#endif
|
||||
if(global.generateCode) {
|
||||
if (global.generateCode) {
|
||||
bool toLogFile = false;
|
||||
if(taosReadDataFolder(configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs) != 0){
|
||||
encryptError("failed to generate encrypt code since dataDir can not be set from cfg file");
|
||||
return -1;
|
||||
if ((code = taosReadDataFolder(configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs)) != 0) {
|
||||
encryptError("failed to generate encrypt code since dataDir can not be set from cfg file,reason:%s",
|
||||
tstrerror(code));
|
||||
return code;
|
||||
};
|
||||
|
||||
if(dmCheckRunning(tsDataDir) == NULL) {
|
||||
encryptError("failed to generate encrypt code since taosd is running, please stop it first");
|
||||
return -1;
|
||||
TdFilePtr pFile;
|
||||
if ((code = dmCheckRunning(tsDataDir, &pFile)) != 0) {
|
||||
encryptError("failed to generate encrypt code since taosd is running, please stop it first, reason:%s",
|
||||
tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
int ret = dmUpdateEncryptKey(global.encryptKey, toLogFile);
|
||||
taosCloseLog();
|
||||
|
@ -383,30 +387,30 @@ int mainWindows(int argc, char **argv) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
if (dmInitLog() != 0) {
|
||||
if ((code = dmInitLog()) != 0) {
|
||||
printf("failed to start since init log error\n");
|
||||
taosCleanupArgs();
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
dmPrintArgs(argc, argv);
|
||||
|
||||
if (taosInitCfg(configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs, 0) != 0) {
|
||||
if ((code = taosInitCfg(configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs, 0)) != 0) {
|
||||
dError("failed to start since read config error");
|
||||
taosCloseLog();
|
||||
taosCleanupArgs();
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (taosConvInit() != 0) {
|
||||
if ((code = taosConvInit()) != 0) {
|
||||
dError("failed to init conv");
|
||||
taosCloseLog();
|
||||
taosCleanupArgs();
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (global.checkS3) {
|
||||
int32_t code = dmCheckS3();
|
||||
code = dmCheckS3();
|
||||
taosCleanupCfg();
|
||||
taosCloseLog();
|
||||
taosCleanupArgs();
|
||||
|
@ -435,31 +439,32 @@ int mainWindows(int argc, char **argv) {
|
|||
osSetProcPath(argc, (char **)argv);
|
||||
taosCleanupArgs();
|
||||
|
||||
if(dmGetEncryptKey() != 0){
|
||||
if ((code = dmGetEncryptKey()) != 0) {
|
||||
dError("failed to start since failed to get encrypt key");
|
||||
taosCloseLog();
|
||||
taosCleanupArgs();
|
||||
return -1;
|
||||
return code;
|
||||
};
|
||||
|
||||
if (dmInit() != 0) {
|
||||
if (terrno == TSDB_CODE_NOT_FOUND) {
|
||||
if ((code = dmInit()) != 0) {
|
||||
if (code == 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());
|
||||
dError("failed to init dnode since %s", tstrerror(code));
|
||||
}
|
||||
|
||||
taosCleanupCfg();
|
||||
taosCloseLog();
|
||||
taosConvDestroy();
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
dInfo("start to init service");
|
||||
dmSetSignalHandle();
|
||||
tsDndStart = taosGetTimestampMs();
|
||||
tsDndStartOsUptime = taosGetOsUptime();
|
||||
int32_t code = dmRun();
|
||||
|
||||
code = dmRun();
|
||||
dInfo("shutting down the service");
|
||||
|
||||
dmCleanup();
|
||||
|
|
|
@ -45,7 +45,7 @@ static void dmMayShouldUpdateIpWhiteList(SDnodeMgmt *pMgmt, int64_t ver) {
|
|||
|
||||
SRetrieveIpWhiteReq req = {.ipWhiteVer = oldVer};
|
||||
int32_t contLen = tSerializeRetrieveIpWhite(NULL, 0, &req);
|
||||
void * pHead = rpcMallocCont(contLen);
|
||||
void *pHead = rpcMallocCont(contLen);
|
||||
tSerializeRetrieveIpWhite(pHead, contLen, &req);
|
||||
|
||||
SRpcMsg rpcMsg = {.pCont = pHead,
|
||||
|
@ -116,7 +116,7 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) {
|
|||
req.clusterCfg.ttlChangeOnWrite = tsTtlChangeOnWrite;
|
||||
req.clusterCfg.enableWhiteList = tsEnableWhiteList ? 1 : 0;
|
||||
req.clusterCfg.encryptionKeyStat = tsEncryptionKeyStat;
|
||||
req.clusterCfg.encryptionKeyChksum = tsEncryptionKeyChksum;
|
||||
req.clusterCfg.encryptionKeyChksum = tsEncryptionKeyChksum;
|
||||
req.clusterCfg.monitorParas.tsEnableMonitor = tsEnableMonitor;
|
||||
req.clusterCfg.monitorParas.tsMonitorInterval = tsMonitorInterval;
|
||||
req.clusterCfg.monitorParas.tsSlowLogScope = tsSlowLogScope;
|
||||
|
@ -146,7 +146,7 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) {
|
|||
req.ipWhiteVer = pMgmt->pData->ipWhiteVer;
|
||||
|
||||
int32_t contLen = tSerializeSStatusReq(NULL, 0, &req);
|
||||
void * pHead = rpcMallocCont(contLen);
|
||||
void *pHead = rpcMallocCont(contLen);
|
||||
tSerializeSStatusReq(pHead, contLen, &req);
|
||||
tFreeSStatusReq(&req);
|
||||
|
||||
|
@ -207,18 +207,26 @@ int32_t dmProcessGrantRsp(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
int32_t dmProcessConfigReq(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
SDCfgDnodeReq cfgReq = {0};
|
||||
if (tDeserializeSDCfgDnodeReq(pMsg->pCont, pMsg->contLen, &cfgReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
dInfo("start to config, option:%s, value:%s", cfgReq.config, cfgReq.value);
|
||||
|
||||
SConfig *pCfg = taosGetCfg();
|
||||
cfgSetItem(pCfg, cfgReq.config, cfgReq.value, CFG_STYPE_ALTER_CMD, true);
|
||||
taosCfgDynamicOptions(pCfg, cfgReq.config, true);
|
||||
return 0;
|
||||
|
||||
code = cfgSetItem(pCfg, cfgReq.config, cfgReq.value, CFG_STYPE_ALTER_CMD, true);
|
||||
if (code != 0) {
|
||||
if (strncasecmp(cfgReq.config, "resetlog", strlen("resetlog")) == 0) {
|
||||
code = 0;
|
||||
} else {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
return taosCfgDynamicOptions(pCfg, cfgReq.config, true);
|
||||
}
|
||||
|
||||
int32_t dmProcessCreateEncryptKeyReq(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||
|
@ -251,7 +259,7 @@ static void dmGetServerRunStatus(SDnodeMgmt *pMgmt, SServerStatusRsp *pStatus) {
|
|||
pStatus->statusCode = TSDB_SRV_STATUS_SERVICE_OK;
|
||||
pStatus->details[0] = 0;
|
||||
|
||||
SMonMloadInfo minfo = {0};
|
||||
SMonMloadInfo minfo = {0};
|
||||
(*pMgmt->getMnodeLoadsFp)(&minfo);
|
||||
if (minfo.isMnode &&
|
||||
(minfo.load.syncState == TAOS_SYNC_STATE_ERROR || minfo.load.syncState == TAOS_SYNC_STATE_OFFLINE)) {
|
||||
|
@ -276,32 +284,49 @@ static void dmGetServerRunStatus(SDnodeMgmt *pMgmt, SServerStatusRsp *pStatus) {
|
|||
}
|
||||
|
||||
int32_t dmProcessServerRunStatus(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
dDebug("server run status req is received");
|
||||
SServerStatusRsp statusRsp = {0};
|
||||
dmGetServerRunStatus(pMgmt, &statusRsp);
|
||||
|
||||
pMsg->info.rsp = NULL;
|
||||
pMsg->info.rspLen = 0;
|
||||
|
||||
SRpcMsg rspMsg = {.info = pMsg->info};
|
||||
int32_t rspLen = tSerializeSServerStatusRsp(NULL, 0, &statusRsp);
|
||||
if (rspLen < 0) {
|
||||
rspMsg.code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
// rspMsg.code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
// return rspMsg.code;
|
||||
}
|
||||
|
||||
void *pRsp = rpcMallocCont(rspLen);
|
||||
if (pRsp == NULL) {
|
||||
rspMsg.code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
// rspMsg.code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
// return rspMsg.code;
|
||||
}
|
||||
|
||||
rspLen = tSerializeSServerStatusRsp(pRsp, rspLen, &statusRsp);
|
||||
if (rspLen < 0) {
|
||||
return TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
tSerializeSServerStatusRsp(pRsp, rspLen, &statusRsp);
|
||||
pMsg->info.rsp = pRsp;
|
||||
pMsg->info.rspLen = rspLen;
|
||||
return 0;
|
||||
}
|
||||
|
||||
SSDataBlock *dmBuildVariablesBlock(void) {
|
||||
SSDataBlock * pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
|
||||
size_t size = 0;
|
||||
int32_t dmBuildVariablesBlock(SSDataBlock **ppBlock) {
|
||||
int32_t code = 0;
|
||||
|
||||
SSDataBlock *pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
|
||||
if (pBlock == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
size_t size = 0;
|
||||
|
||||
const SSysTableMeta *pMeta = NULL;
|
||||
getInfosDbMeta(&pMeta, &size);
|
||||
|
||||
|
@ -314,52 +339,74 @@ SSDataBlock *dmBuildVariablesBlock(void) {
|
|||
}
|
||||
|
||||
pBlock->pDataBlock = taosArrayInit(pMeta[index].colNum, sizeof(SColumnInfoData));
|
||||
if (pBlock->pDataBlock == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pMeta[index].colNum; ++i) {
|
||||
SColumnInfoData colInfoData = {0};
|
||||
colInfoData.info.colId = i + 1;
|
||||
colInfoData.info.type = pMeta[index].schema[i].type;
|
||||
colInfoData.info.bytes = pMeta[index].schema[i].bytes;
|
||||
taosArrayPush(pBlock->pDataBlock, &colInfoData);
|
||||
if (taosArrayPush(pBlock->pDataBlock, &colInfoData) == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
}
|
||||
|
||||
pBlock->info.hasVarCol = true;
|
||||
|
||||
return pBlock;
|
||||
_exit:
|
||||
if (code != 0) {
|
||||
blockDataDestroy(pBlock);
|
||||
} else {
|
||||
*ppBlock = pBlock;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t dmAppendVariablesToBlock(SSDataBlock *pBlock, int32_t dnodeId) {
|
||||
/*int32_t code = */dumpConfToDataBlock(pBlock, 1);
|
||||
int32_t code = dumpConfToDataBlock(pBlock, 1);
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
|
||||
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, 0);
|
||||
colDataSetNItems(pColInfo, 0, (const char *)&dnodeId, pBlock->info.rows, false);
|
||||
if (pColInfo == NULL) {
|
||||
return TSDB_CODE_OUT_OF_RANGE;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
return colDataSetNItems(pColInfo, 0, (const char *)&dnodeId, pBlock->info.rows, false);
|
||||
}
|
||||
|
||||
int32_t dmProcessRetrieve(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||
int32_t size = 0;
|
||||
int32_t rowsRead = 0;
|
||||
|
||||
int32_t size = 0;
|
||||
int32_t rowsRead = 0;
|
||||
int32_t code = 0;
|
||||
SRetrieveTableReq retrieveReq = {0};
|
||||
if (tDeserializeSRetrieveTableReq(pMsg->pCont, pMsg->contLen, &retrieveReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
#if 0
|
||||
if (strcmp(retrieveReq.user, TSDB_DEFAULT_USER) != 0) {
|
||||
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
||||
return -1;
|
||||
code = TSDB_CODE_MND_NO_RIGHTS;
|
||||
return code;
|
||||
}
|
||||
#endif
|
||||
if (strcasecmp(retrieveReq.tb, TSDB_INS_TABLE_DNODE_VARIABLES)) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
SSDataBlock *pBlock = dmBuildVariablesBlock();
|
||||
SSDataBlock *pBlock = NULL;
|
||||
if ((code = dmBuildVariablesBlock(&pBlock)) != 0) {
|
||||
return code;
|
||||
}
|
||||
|
||||
dmAppendVariablesToBlock(pBlock, pMgmt->pData->dnodeId);
|
||||
code = dmAppendVariablesToBlock(pBlock, pMgmt->pData->dnodeId);
|
||||
if (code != 0) {
|
||||
blockDataDestroy(pBlock);
|
||||
return code;
|
||||
}
|
||||
|
||||
size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
|
||||
size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * numOfCols +
|
||||
|
@ -367,10 +414,10 @@ int32_t dmProcessRetrieve(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
|
||||
SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size);
|
||||
if (pRsp == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
dError("failed to retrieve data since %s", terrstr());
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
dError("failed to retrieve data since %s", tstrerror(code));
|
||||
blockDataDestroy(pBlock);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
char *pStart = pRsp->data;
|
||||
|
@ -404,7 +451,9 @@ int32_t dmProcessRetrieve(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
SArray *dmGetMsgHandles() {
|
||||
int32_t code = -1;
|
||||
SArray *pArray = taosArrayInit(16, sizeof(SMgmtHandle));
|
||||
if (pArray == NULL) goto _OVER;
|
||||
if (pArray == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Requests handled by DNODE
|
||||
if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_MNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
|
||||
|
@ -416,7 +465,7 @@ SArray *dmGetMsgHandles() {
|
|||
if (dmSetMgmtHandle(pArray, TDMT_DND_CONFIG_DNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_DND_SERVER_STATUS, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_DND_SYSTABLE_RETRIEVE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_DND_ALTER_MNODE_TYPE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_DND_ALTER_MNODE_TYPE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_ENCRYPT_KEY, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
|
||||
|
||||
// Requests handled by MNODE
|
||||
|
|
|
@ -18,22 +18,23 @@
|
|||
#include "libs/function/tudf.h"
|
||||
|
||||
static int32_t dmStartMgmt(SDnodeMgmt *pMgmt) {
|
||||
if (dmStartStatusThread(pMgmt) != 0) {
|
||||
return -1;
|
||||
int32_t code = 0;
|
||||
if ((code = dmStartStatusThread(pMgmt)) != 0) {
|
||||
return code;
|
||||
}
|
||||
#if defined(TD_ENTERPRISE)
|
||||
if (dmStartNotifyThread(pMgmt) != 0) {
|
||||
return -1;
|
||||
if ((code = dmStartNotifyThread(pMgmt)) != 0) {
|
||||
return code;
|
||||
}
|
||||
#endif
|
||||
if (dmStartMonitorThread(pMgmt) != 0) {
|
||||
return -1;
|
||||
if ((code = dmStartMonitorThread(pMgmt)) != 0) {
|
||||
return code;
|
||||
}
|
||||
if (dmStartAuditThread(pMgmt) != 0) {
|
||||
return -1;
|
||||
if ((code = dmStartAuditThread(pMgmt)) != 0) {
|
||||
return code;
|
||||
}
|
||||
if (dmStartCrashReportThread(pMgmt) != 0) {
|
||||
return -1;
|
||||
if ((code = dmStartCrashReportThread(pMgmt)) != 0) {
|
||||
return code;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -50,10 +51,10 @@ static void dmStopMgmt(SDnodeMgmt *pMgmt) {
|
|||
}
|
||||
|
||||
static int32_t dmOpenMgmt(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||
int32_t code = 0;
|
||||
SDnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SDnodeMgmt));
|
||||
if (pMgmt == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pMgmt->pData = pInput->pData;
|
||||
|
@ -70,12 +71,11 @@ static int32_t dmOpenMgmt(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
|||
pMgmt->getMnodeLoadsFp = pInput->getMnodeLoadsFp;
|
||||
pMgmt->getQnodeLoadsFp = pInput->getQnodeLoadsFp;
|
||||
|
||||
// pMgmt->pData->ipWhiteVer = 0;
|
||||
if (dmStartWorker(pMgmt) != 0) {
|
||||
return -1;
|
||||
if ((code = dmStartWorker(pMgmt)) != 0) {
|
||||
return code;
|
||||
}
|
||||
|
||||
if (udfStartUdfd(pMgmt->pData->dnodeId) != 0) {
|
||||
if ((code = udfStartUdfd(pMgmt->pData->dnodeId)) != 0) {
|
||||
dError("failed to start udfd");
|
||||
}
|
||||
|
||||
|
|
|
@ -264,12 +264,14 @@ static void *dmCrashReportThreadFp(void *param) {
|
|||
}
|
||||
|
||||
int32_t dmStartStatusThread(SDnodeMgmt *pMgmt) {
|
||||
int32_t code = 0;
|
||||
TdThreadAttr thAttr;
|
||||
taosThreadAttrInit(&thAttr);
|
||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
if (taosThreadCreate(&pMgmt->statusThread, &thAttr, dmStatusThreadFp, pMgmt) != 0) {
|
||||
dError("failed to create status thread since %s", strerror(errno));
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to create status thread since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
taosThreadAttrDestroy(&thAttr);
|
||||
|
@ -285,12 +287,14 @@ void dmStopStatusThread(SDnodeMgmt *pMgmt) {
|
|||
}
|
||||
|
||||
int32_t dmStartNotifyThread(SDnodeMgmt *pMgmt) {
|
||||
int32_t code = 0;
|
||||
TdThreadAttr thAttr;
|
||||
taosThreadAttrInit(&thAttr);
|
||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
if (taosThreadCreate(&pMgmt->notifyThread, &thAttr, dmNotifyThreadFp, pMgmt) != 0) {
|
||||
dError("failed to create notify thread since %s", strerror(errno));
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to create notify thread since %s", strerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
taosThreadAttrDestroy(&thAttr);
|
||||
|
@ -308,12 +312,14 @@ void dmStopNotifyThread(SDnodeMgmt *pMgmt) {
|
|||
}
|
||||
|
||||
int32_t dmStartMonitorThread(SDnodeMgmt *pMgmt) {
|
||||
int32_t code = 0;
|
||||
TdThreadAttr thAttr;
|
||||
taosThreadAttrInit(&thAttr);
|
||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
if (taosThreadCreate(&pMgmt->monitorThread, &thAttr, dmMonitorThreadFp, pMgmt) != 0) {
|
||||
dError("failed to create monitor thread since %s", strerror(errno));
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to create monitor thread since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
taosThreadAttrDestroy(&thAttr);
|
||||
|
@ -322,12 +328,14 @@ int32_t dmStartMonitorThread(SDnodeMgmt *pMgmt) {
|
|||
}
|
||||
|
||||
int32_t dmStartAuditThread(SDnodeMgmt *pMgmt) {
|
||||
int32_t code = 0;
|
||||
TdThreadAttr thAttr;
|
||||
taosThreadAttrInit(&thAttr);
|
||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
if (taosThreadCreate(&pMgmt->auditThread, &thAttr, dmAuditThreadFp, pMgmt) != 0) {
|
||||
dError("failed to create audit thread since %s", strerror(errno));
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to create audit thread since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
taosThreadAttrDestroy(&thAttr);
|
||||
|
@ -350,6 +358,7 @@ void dmStopAuditThread(SDnodeMgmt *pMgmt) {
|
|||
}
|
||||
|
||||
int32_t dmStartCrashReportThread(SDnodeMgmt *pMgmt) {
|
||||
int32_t code = 0;
|
||||
if (!tsEnableCrashReport) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -358,8 +367,9 @@ int32_t dmStartCrashReportThread(SDnodeMgmt *pMgmt) {
|
|||
taosThreadAttrInit(&thAttr);
|
||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
if (taosThreadCreate(&pMgmt->crashReportThread, &thAttr, dmCrashReportThreadFp, pMgmt) != 0) {
|
||||
dError("failed to create crashReport thread since %s", strerror(errno));
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to create crashReport thread since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
taosThreadAttrDestroy(&thAttr);
|
||||
|
@ -431,8 +441,8 @@ static void dmProcessMgmtQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
|||
code = dmProcessCreateEncryptKeyReq(pMgmt, pMsg);
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
dGError("msg:%p, not processed in mgmt queue", pMsg);
|
||||
code = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
dGError("msg:%p, not processed in mgmt queue, reason:%s", pMsg, tstrerror(code));
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,11 +21,11 @@ static int32_t mmDecodeOption(SJson *pJson, SMnodeOpt *pOption) {
|
|||
int32_t code = 0;
|
||||
|
||||
tjsonGetInt32ValueFromDouble(pJson, "deployed", pOption->deploy, code);
|
||||
if (code < 0) return -1;
|
||||
if (code < 0) return code;
|
||||
tjsonGetInt32ValueFromDouble(pJson, "selfIndex", pOption->selfIndex, code);
|
||||
if (code < 0) return 0;
|
||||
if (code < 0) return code;
|
||||
tjsonGetInt32ValueFromDouble(pJson, "lastIndex", pOption->lastIndex, code);
|
||||
if (code < 0) return 0;
|
||||
if (code < 0) return code;
|
||||
|
||||
SJson *replicas = tjsonGetObjectItem(pJson, "replicas");
|
||||
if (replicas == NULL) return 0;
|
||||
|
@ -35,17 +35,17 @@ static int32_t mmDecodeOption(SJson *pJson, SMnodeOpt *pOption) {
|
|||
|
||||
for (int32_t i = 0; i < pOption->numOfTotalReplicas; ++i) {
|
||||
SJson *replica = tjsonGetArrayItem(replicas, i);
|
||||
if (replica == NULL) return -1;
|
||||
if (replica == NULL) return TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
|
||||
SReplica *pReplica = pOption->replicas + i;
|
||||
tjsonGetInt32ValueFromDouble(replica, "id", pReplica->id, code);
|
||||
if (code < 0) return -1;
|
||||
if (code < 0) return code;
|
||||
code = tjsonGetStringValue(replica, "fqdn", pReplica->fqdn);
|
||||
if (code < 0) return -1;
|
||||
if (code < 0) return code;
|
||||
tjsonGetUInt16ValueFromDouble(replica, "port", pReplica->port, code);
|
||||
if (code < 0) return -1;
|
||||
if (code < 0) return code;
|
||||
tjsonGetInt32ValueFromDouble(replica, "role", pOption->nodeRoles[i], code);
|
||||
if (code < 0) return -1;
|
||||
if (code < 0) return code;
|
||||
if (pOption->nodeRoles[i] == TAOS_SYNC_ROLE_VOTER) {
|
||||
pOption->numOfReplicas++;
|
||||
}
|
||||
|
@ -63,36 +63,41 @@ int32_t mmReadFile(const char *path, SMnodeOpt *pOption) {
|
|||
char *pData = NULL;
|
||||
SJson *pJson = NULL;
|
||||
char file[PATH_MAX] = {0};
|
||||
snprintf(file, sizeof(file), "%s%smnode.json", path, TD_DIRSEP);
|
||||
|
||||
int32_t nBytes = snprintf(file, sizeof(file), "%s%smnode.json", path, TD_DIRSEP);
|
||||
if (nBytes <= 0 || nBytes >= sizeof(file)) {
|
||||
code = TSDB_CODE_OUT_OF_BUFFER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
||||
dInfo("mnode file:%s not exist", file);
|
||||
dInfo("mnode file:%s not exist, reason:%s", file, tstrerror(TAOS_SYSTEM_ERROR(errno)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to open mnode file:%s since %s", file, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to open mnode file:%s since %s", file, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
int64_t size = 0;
|
||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to fstat mnode file:%s since %s", file, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to fstat mnode file:%s since %s", file, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pData = taosMemoryMalloc(size + 1);
|
||||
if (pData == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (taosReadFile(pFile, pData, size) != size) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to read mnode file:%s since %s", file, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to read mnode file:%s since %s", file, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -100,12 +105,11 @@ int32_t mmReadFile(const char *path, SMnodeOpt *pOption) {
|
|||
|
||||
pJson = tjsonParse(pData);
|
||||
if (pJson == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (mmDecodeOption(pJson, pOption) < 0) {
|
||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
if ((code = mmDecodeOption(pJson, pOption)) < 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -118,37 +122,42 @@ _OVER:
|
|||
if (pFile != NULL) taosCloseFile(&pFile);
|
||||
|
||||
if (code != 0) {
|
||||
dError("failed to read mnode file:%s since %s", file, terrstr());
|
||||
dError("failed to read mnode file:%s since %s", file, tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mmEncodeOption(SJson *pJson, const SMnodeOpt *pOption) {
|
||||
int32_t code = 0;
|
||||
if (pOption->deploy && pOption->numOfTotalReplicas > 0) {
|
||||
if (tjsonAddDoubleToObject(pJson, "selfIndex", pOption->selfIndex) < 0) return -1;
|
||||
if ((code = tjsonAddDoubleToObject(pJson, "selfIndex", pOption->selfIndex)) < 0) return code;
|
||||
|
||||
SJson *replicas = tjsonCreateArray();
|
||||
if (replicas == NULL) return -1;
|
||||
if (tjsonAddItemToObject(pJson, "replicas", replicas) < 0) return -1;
|
||||
if (replicas == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
if ((code = tjsonAddItemToObject(pJson, "replicas", replicas)) < 0) return code;
|
||||
|
||||
for (int32_t i = 0; i < pOption->numOfTotalReplicas; ++i) {
|
||||
SJson *replica = tjsonCreateObject();
|
||||
if (replica == NULL) return -1;
|
||||
if (replica == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
const SReplica *pReplica = pOption->replicas + i;
|
||||
if (tjsonAddDoubleToObject(replica, "id", pReplica->id) < 0) return -1;
|
||||
if (tjsonAddStringToObject(replica, "fqdn", pReplica->fqdn) < 0) return -1;
|
||||
if (tjsonAddDoubleToObject(replica, "port", pReplica->port) < 0) return -1;
|
||||
if (tjsonAddDoubleToObject(replica, "role", pOption->nodeRoles[i]) < 0) return -1;
|
||||
if (tjsonAddItemToArray(replicas, replica) < 0) return -1;
|
||||
if ((code = tjsonAddDoubleToObject(replica, "id", pReplica->id)) < 0) return code;
|
||||
if ((code = tjsonAddStringToObject(replica, "fqdn", pReplica->fqdn)) < 0) return code;
|
||||
if ((code = tjsonAddDoubleToObject(replica, "port", pReplica->port)) < 0) return code;
|
||||
if ((code = tjsonAddDoubleToObject(replica, "role", pOption->nodeRoles[i])) < 0) return code;
|
||||
if ((code = tjsonAddItemToArray(replicas, replica)) < 0) return code;
|
||||
}
|
||||
}
|
||||
|
||||
if (tjsonAddDoubleToObject(pJson, "lastIndex", pOption->lastIndex) < 0) return -1;
|
||||
if ((code = tjsonAddDoubleToObject(pJson, "lastIndex", pOption->lastIndex)) < 0) return code;
|
||||
|
||||
if (tjsonAddDoubleToObject(pJson, "deployed", pOption->deploy) < 0) return -1;
|
||||
if ((code = tjsonAddDoubleToObject(pJson, "deployed", pOption->deploy)) < 0) return code;
|
||||
|
||||
return 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) {
|
||||
|
@ -158,28 +167,59 @@ int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) {
|
|||
TdFilePtr pFile = NULL;
|
||||
char file[PATH_MAX] = {0};
|
||||
char realfile[PATH_MAX] = {0};
|
||||
snprintf(file, sizeof(file), "%s%smnode.json.bak", path, TD_DIRSEP);
|
||||
snprintf(realfile, sizeof(realfile), "%s%smnode.json", path, TD_DIRSEP);
|
||||
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
int32_t nBytes = snprintf(file, sizeof(file), "%s%smnode.json.bak", path, TD_DIRSEP);
|
||||
if (nBytes <= 0 || nBytes >= sizeof(file)) {
|
||||
code = TSDB_CODE_OUT_OF_BUFFER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
nBytes = snprintf(realfile, sizeof(realfile), "%s%smnode.json", path, TD_DIRSEP);
|
||||
if (nBytes <= 0 || nBytes >= sizeof(realfile)) {
|
||||
code = TSDB_CODE_OUT_OF_BUFFER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
// terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
pJson = tjsonCreateObject();
|
||||
if (pJson == NULL) goto _OVER;
|
||||
if (mmEncodeOption(pJson, pOption) != 0) goto _OVER;
|
||||
if (pJson == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
TAOS_CHECK_GOTO(mmEncodeOption(pJson, pOption), NULL, _OVER);
|
||||
|
||||
buffer = tjsonToString(pJson);
|
||||
if (buffer == NULL) goto _OVER;
|
||||
terrno = 0;
|
||||
if (buffer == NULL) {
|
||||
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||
if (pFile == NULL) goto _OVER;
|
||||
if (pFile == NULL) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
int32_t len = strlen(buffer);
|
||||
if (taosWriteFile(pFile, buffer, len) <= 0) goto _OVER;
|
||||
if (taosFsyncFile(pFile) < 0) goto _OVER;
|
||||
if (taosWriteFile(pFile, buffer, len) <= 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
if (taosFsyncFile(pFile) < 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
taosCloseFile(&pFile);
|
||||
if (taosRenameFile(file, realfile) != 0) goto _OVER;
|
||||
if (taosCloseFile(&pFile) < 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
if (taosRenameFile(file, realfile) != 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
code = 0;
|
||||
dInfo("succeed to write mnode file:%s, deloyed:%d", realfile, pOption->deploy);
|
||||
|
||||
_OVER:
|
||||
|
@ -188,8 +228,7 @@ _OVER:
|
|||
if (pFile != NULL) taosCloseFile(&pFile);
|
||||
|
||||
if (code != 0) {
|
||||
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to write mnode file:%s since %s, deloyed:%d", realfile, terrstr(), pOption->deploy);
|
||||
dError("failed to write mnode file:%s since %s, deloyed:%d", realfile, tstrerror(code), pOption->deploy);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -26,11 +26,12 @@ void mmGetMnodeLoads(SMnodeMgmt *pMgmt, SMonMloadInfo *pInfo) {
|
|||
}
|
||||
|
||||
int32_t mmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
const STraceId *trace = &pMsg->info.traceId;
|
||||
SDCreateMnodeReq createReq = {0};
|
||||
if (tDeserializeSDCreateMnodeReq(pMsg->pCont, pMsg->contLen, &createReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
return code;
|
||||
}
|
||||
|
||||
SMnodeOpt option = {.deploy = true,
|
||||
|
@ -56,43 +57,45 @@ int32_t mmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
if (option.selfIndex == -1) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dGError("failed to create mnode since %s, selfIndex is -1", terrstr());
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_OPTION;
|
||||
dGError("failed to create mnode since %s, selfIndex is -1", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
if (mmWriteFile(pInput->path, &option) != 0) {
|
||||
dGError("failed to write mnode file since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = mmWriteFile(pInput->path, &option)) != 0) {
|
||||
dGError("failed to write mnode file since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mmProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
|
||||
const STraceId *trace = &pMsg->info.traceId;
|
||||
SDDropMnodeReq dropReq = {0};
|
||||
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &dropReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (pInput->pData->dnodeId != 0 && dropReq.dnodeId != pInput->pData->dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dGError("failed to drop mnode since %s", terrstr());
|
||||
code = TSDB_CODE_INVALID_OPTION;
|
||||
dGError("failed to drop mnode since %s", tstrerror(code));
|
||||
tFreeSMCreateQnodeReq(&dropReq);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
SMnodeOpt option = {.deploy = false};
|
||||
if (mmWriteFile(pInput->path, &option) != 0) {
|
||||
dGError("failed to write mnode file since %s", terrstr());
|
||||
if ((code = mmWriteFile(pInput->path, &option)) != 0) {
|
||||
dGError("failed to write mnode file since %s", tstrerror(code));
|
||||
tFreeSMCreateQnodeReq(&dropReq);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
tFreeSMCreateQnodeReq(&dropReq);
|
||||
return 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
SArray *mmGetMsgHandles() {
|
||||
|
|
|
@ -25,9 +25,10 @@ static bool mmDeployRequired(const SMgmtInputOpt *pInput) {
|
|||
}
|
||||
|
||||
static int32_t mmRequire(const SMgmtInputOpt *pInput, bool *required) {
|
||||
int32_t code = 0;
|
||||
SMnodeOpt option = {0};
|
||||
if (mmReadFile(pInput->path, &option) != 0) {
|
||||
return -1;
|
||||
if ((code = mmReadFile(pInput->path, &option)) != 0) {
|
||||
return code;
|
||||
}
|
||||
|
||||
if (!option.deploy) {
|
||||
|
@ -41,7 +42,7 @@ static int32_t mmRequire(const SMgmtInputOpt *pInput, bool *required) {
|
|||
dInfo("deploy mnode required. option deploy:%d", option.deploy);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
static void mmBuildOptionForDeploy(SMnodeMgmt *pMgmt, const SMgmtInputOpt *pInput, SMnodeOpt *pOption) {
|
||||
|
@ -73,22 +74,31 @@ static void mmClose(SMnodeMgmt *pMgmt) {
|
|||
|
||||
taosMemoryFree(pMgmt);
|
||||
}
|
||||
|
||||
static int32_t mndOpenWrapper(const char *path, SMnodeOpt *opt, SMnode **pMnode) {
|
||||
int32_t code = 0;
|
||||
*pMnode = mndOpen(path, opt);
|
||||
if (*pMnode == NULL) {
|
||||
code = terrno;
|
||||
}
|
||||
///*pMnode = pNode;
|
||||
return code;
|
||||
}
|
||||
static int32_t mmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||
if (walInit() != 0) {
|
||||
dError("failed to init wal since %s", terrstr());
|
||||
return -1;
|
||||
int32_t code = 0;
|
||||
if ((code = walInit()) != 0) {
|
||||
dError("failed to init wal since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
if (syncInit() != 0) {
|
||||
dError("failed to init sync since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = syncInit()) != 0) {
|
||||
dError("failed to init sync since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
SMnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SMnodeMgmt));
|
||||
if (pMgmt == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return code;
|
||||
}
|
||||
|
||||
pMgmt->pData = pInput->pData;
|
||||
|
@ -100,10 +110,10 @@ static int32_t mmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
|||
taosThreadRwlockInit(&pMgmt->lock, NULL);
|
||||
|
||||
SMnodeOpt option = {0};
|
||||
if (mmReadFile(pMgmt->path, &option) != 0) {
|
||||
dError("failed to read file since %s", terrstr());
|
||||
if ((code = mmReadFile(pMgmt->path, &option)) != 0) {
|
||||
dError("failed to read file since %s", tstrerror(code));
|
||||
mmClose(pMgmt);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (!option.deploy) {
|
||||
|
@ -115,18 +125,18 @@ static int32_t mmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
|||
mmBuildOptionForOpen(pMgmt, &option);
|
||||
}
|
||||
|
||||
pMgmt->pMnode = mndOpen(pMgmt->path, &option);
|
||||
if (pMgmt->pMnode == NULL) {
|
||||
dError("failed to open mnode since %s", terrstr());
|
||||
code = mndOpenWrapper(pMgmt->path, &option, &pMgmt->pMnode);
|
||||
if (code != 0) {
|
||||
dError("failed to open mnode since %s", tstrerror(code));
|
||||
mmClose(pMgmt);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
tmsgReportStartup("mnode-impl", "initialized");
|
||||
|
||||
if (mmStartWorker(pMgmt) != 0) {
|
||||
dError("failed to start mnode worker since %s", terrstr());
|
||||
if ((code = mmStartWorker(pMgmt)) != 0) {
|
||||
dError("failed to start mnode worker since %s", tstrerror(code));
|
||||
mmClose(pMgmt);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
tmsgReportStartup("mnode-worker", "initialized");
|
||||
|
||||
|
@ -134,9 +144,9 @@ static int32_t mmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
|||
option.deploy = true;
|
||||
option.numOfReplicas = 0;
|
||||
option.numOfTotalReplicas = 0;
|
||||
if (mmWriteFile(pMgmt->path, &option) != 0) {
|
||||
dError("failed to write mnode file since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = mmWriteFile(pMgmt->path, &option)) != 0) {
|
||||
dError("failed to write mnode file since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -160,13 +170,9 @@ static void mmStop(SMnodeMgmt *pMgmt) {
|
|||
mndStop(pMgmt->pMnode);
|
||||
}
|
||||
|
||||
static int32_t mmSyncIsCatchUp(SMnodeMgmt *pMgmt) {
|
||||
return mndIsCatchUp(pMgmt->pMnode);
|
||||
}
|
||||
static int32_t mmSyncIsCatchUp(SMnodeMgmt *pMgmt) { return mndIsCatchUp(pMgmt->pMnode); }
|
||||
|
||||
static ESyncRole mmSyncGetRole(SMnodeMgmt *pMgmt) {
|
||||
return mndGetRole(pMgmt->pMnode);
|
||||
}
|
||||
static ESyncRole mmSyncGetRole(SMnodeMgmt *pMgmt) { return mndGetRole(pMgmt->pMnode); }
|
||||
|
||||
SMgmtFunc mmGetMgmtFunc() {
|
||||
SMgmtFunc mgmtFunc = {0};
|
||||
|
|
|
@ -179,13 +179,15 @@ int32_t mmPutMsgToQueue(SMnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
|||
pWorker = &pMgmt->syncRdWorker;
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
code = TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
||||
if (pWorker == NULL) return -1;
|
||||
if (pWorker == NULL) return code;
|
||||
|
||||
SRpcMsg *pMsg;
|
||||
code = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM, pRpc->contLen, (void **)&pMsg);
|
||||
if (code) return code;
|
||||
|
||||
memcpy(pMsg, pRpc, sizeof(SRpcMsg));
|
||||
pRpc->pCont = NULL;
|
||||
|
||||
|
@ -201,6 +203,7 @@ int32_t mmPutMsgToQueue(SMnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
|||
}
|
||||
|
||||
int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
||||
int32_t code = 0;
|
||||
SSingleWorkerCfg qCfg = {
|
||||
.min = tsNumOfMnodeQueryThreads,
|
||||
.max = tsNumOfMnodeQueryThreads,
|
||||
|
@ -209,9 +212,9 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
|||
.param = pMgmt,
|
||||
.poolType = QUERY_AUTO_QWORKER_POOL,
|
||||
};
|
||||
if (tSingleWorkerInit(&pMgmt->queryWorker, &qCfg) != 0) {
|
||||
dError("failed to start mnode-query worker since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = tSingleWorkerInit(&pMgmt->queryWorker, &qCfg)) != 0) {
|
||||
dError("failed to start mnode-query worker since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
SSingleWorkerCfg fCfg = {
|
||||
|
@ -221,9 +224,9 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
|||
.fp = (FItem)mmProcessRpcMsg,
|
||||
.param = pMgmt,
|
||||
};
|
||||
if (tSingleWorkerInit(&pMgmt->fetchWorker, &fCfg) != 0) {
|
||||
dError("failed to start mnode-fetch worker since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = tSingleWorkerInit(&pMgmt->fetchWorker, &fCfg)) != 0) {
|
||||
dError("failed to start mnode-fetch worker since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
SSingleWorkerCfg rCfg = {
|
||||
|
@ -233,9 +236,9 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
|||
.fp = (FItem)mmProcessRpcMsg,
|
||||
.param = pMgmt,
|
||||
};
|
||||
if (tSingleWorkerInit(&pMgmt->readWorker, &rCfg) != 0) {
|
||||
dError("failed to start mnode-read worker since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = tSingleWorkerInit(&pMgmt->readWorker, &rCfg)) != 0) {
|
||||
dError("failed to start mnode-read worker since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
SSingleWorkerCfg wCfg = {
|
||||
|
@ -245,9 +248,9 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
|||
.fp = (FItem)mmProcessRpcMsg,
|
||||
.param = pMgmt,
|
||||
};
|
||||
if (tSingleWorkerInit(&pMgmt->writeWorker, &wCfg) != 0) {
|
||||
dError("failed to start mnode-write worker since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = tSingleWorkerInit(&pMgmt->writeWorker, &wCfg)) != 0) {
|
||||
dError("failed to start mnode-write worker since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
SSingleWorkerCfg sCfg = {
|
||||
|
@ -257,9 +260,9 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
|||
.fp = (FItem)mmProcessSyncMsg,
|
||||
.param = pMgmt,
|
||||
};
|
||||
if (tSingleWorkerInit(&pMgmt->syncWorker, &sCfg) != 0) {
|
||||
dError("failed to start mnode mnode-sync worker since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = tSingleWorkerInit(&pMgmt->syncWorker, &sCfg)) != 0) {
|
||||
dError("failed to start mnode mnode-sync worker since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
SSingleWorkerCfg scCfg = {
|
||||
|
@ -269,9 +272,9 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
|||
.fp = (FItem)mmProcessSyncMsg,
|
||||
.param = pMgmt,
|
||||
};
|
||||
if (tSingleWorkerInit(&pMgmt->syncRdWorker, &scCfg) != 0) {
|
||||
dError("failed to start mnode mnode-sync-rd worker since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = tSingleWorkerInit(&pMgmt->syncRdWorker, &scCfg)) != 0) {
|
||||
dError("failed to start mnode mnode-sync-rd worker since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
SSingleWorkerCfg arbCfg = {
|
||||
|
@ -281,13 +284,13 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
|||
.fp = (FItem)mmProcessRpcMsg,
|
||||
.param = pMgmt,
|
||||
};
|
||||
if (tSingleWorkerInit(&pMgmt->arbWorker, &arbCfg) != 0) {
|
||||
dError("failed to start mnode mnode-arb worker since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = tSingleWorkerInit(&pMgmt->arbWorker, &arbCfg)) != 0) {
|
||||
dError("failed to start mnode mnode-arb worker since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
dDebug("mnode workers are initialized");
|
||||
return 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
void mmStopWorker(SMnodeMgmt *pMgmt) {
|
||||
|
|
|
@ -30,24 +30,25 @@ void qmGetQnodeLoads(SQnodeMgmt *pMgmt, SQnodeLoad *pInfo) {
|
|||
}
|
||||
|
||||
int32_t qmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
SDCreateQnodeReq createReq = {0};
|
||||
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &createReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (pInput->pData->dnodeId != 0 && createReq.dnodeId != pInput->pData->dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to create qnode since %s", terrstr());
|
||||
code = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to create qnode since %s", tstrerror(code));
|
||||
tFreeSMCreateQnodeReq(&createReq);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
bool deployed = true;
|
||||
if (dmWriteFile(pInput->path, pInput->name, deployed) != 0) {
|
||||
dError("failed to write qnode file since %s", terrstr());
|
||||
if ((code = dmWriteFile(pInput->path, pInput->name, deployed)) != 0) {
|
||||
dError("failed to write qnode file since %s", tstrerror(code));
|
||||
tFreeSMCreateQnodeReq(&createReq);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
tFreeSMCreateQnodeReq(&createReq);
|
||||
|
@ -55,24 +56,25 @@ int32_t qmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
int32_t qmProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
SDDropQnodeReq dropReq = {0};
|
||||
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &dropReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (pInput->pData->dnodeId != 0 && dropReq.dnodeId != pInput->pData->dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to drop qnode since %s", terrstr());
|
||||
code = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to drop qnode since %s", tstrerror(code));
|
||||
tFreeSMCreateQnodeReq(&dropReq);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
bool deployed = false;
|
||||
if (dmWriteFile(pInput->path, pInput->name, deployed) != 0) {
|
||||
dError("failed to write qnode file since %s", terrstr());
|
||||
if ((code = dmWriteFile(pInput->path, pInput->name, deployed)) != 0) {
|
||||
dError("failed to write qnode file since %s", tstrerror(code));
|
||||
tFreeSMCreateQnodeReq(&dropReq);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
tFreeSMCreateQnodeReq(&dropReq);
|
||||
|
|
|
@ -33,11 +33,18 @@ static void qmClose(SQnodeMgmt *pMgmt) {
|
|||
taosMemoryFree(pMgmt);
|
||||
}
|
||||
|
||||
static int32_t qndOpenWrapper(SQnodeOpt *pOption, SQnode **pQnode) {
|
||||
*pQnode = qndOpen(pOption);
|
||||
if (*pQnode == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static int32_t qmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||
int32_t code = 0;
|
||||
SQnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SQnodeMgmt));
|
||||
if (pMgmt == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pMgmt->pData = pInput->pData;
|
||||
|
@ -50,29 +57,30 @@ static int32_t qmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
|||
|
||||
SQnodeOpt option = {0};
|
||||
qmInitOption(pMgmt, &option);
|
||||
pMgmt->pQnode = qndOpen(&option);
|
||||
if (pMgmt->pQnode == NULL) {
|
||||
dError("failed to open qnode since %s", terrstr());
|
||||
|
||||
code = qndOpenWrapper(&option, &pMgmt->pQnode);
|
||||
if (code != 0) {
|
||||
dError("failed to open qnode since %s", tstrerror(code));
|
||||
qmClose(pMgmt);
|
||||
return -1;
|
||||
}
|
||||
tmsgReportStartup("qnode-impl", "initialized");
|
||||
|
||||
if (udfcOpen() != 0) {
|
||||
if ((code = udfcOpen()) != 0) {
|
||||
dError("qnode can not open udfc");
|
||||
qmClose(pMgmt);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (qmStartWorker(pMgmt) != 0) {
|
||||
dError("failed to start qnode worker since %s", terrstr());
|
||||
if ((code = qmStartWorker(pMgmt)) != 0) {
|
||||
dError("failed to start qnode worker since %s", tstrerror(code));
|
||||
qmClose(pMgmt);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
tmsgReportStartup("qnode-worker", "initialized");
|
||||
|
||||
pOutput->pMgmt = pMgmt;
|
||||
return 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
SMgmtFunc qmGetMgmtFunc() {
|
||||
|
|
|
@ -102,6 +102,8 @@ int32_t qmGetQueueSize(SQnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
|
|||
}
|
||||
|
||||
int32_t qmStartWorker(SQnodeMgmt *pMgmt) {
|
||||
int32_t code = 0;
|
||||
|
||||
SSingleWorkerCfg queryCfg = {
|
||||
.min = tsNumOfVnodeQueryThreads,
|
||||
.max = tsNumOfVnodeQueryThreads,
|
||||
|
@ -111,9 +113,9 @@ int32_t qmStartWorker(SQnodeMgmt *pMgmt) {
|
|||
.poolType = QUERY_AUTO_QWORKER_POOL,
|
||||
};
|
||||
|
||||
if (tSingleWorkerInit(&pMgmt->queryWorker, &queryCfg) != 0) {
|
||||
dError("failed to start qnode-query worker since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = tSingleWorkerInit(&pMgmt->queryWorker, &queryCfg)) != 0) {
|
||||
dError("failed to start qnode-query worker since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
SSingleWorkerCfg fetchCfg = {
|
||||
|
@ -124,13 +126,13 @@ int32_t qmStartWorker(SQnodeMgmt *pMgmt) {
|
|||
.param = pMgmt,
|
||||
};
|
||||
|
||||
if (tSingleWorkerInit(&pMgmt->fetchWorker, &fetchCfg) != 0) {
|
||||
dError("failed to start qnode-fetch worker since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = tSingleWorkerInit(&pMgmt->fetchWorker, &fetchCfg)) != 0) {
|
||||
dError("failed to start qnode-fetch worker since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
dDebug("qnode workers are initialized");
|
||||
return 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
void qmStopWorker(SQnodeMgmt *pMgmt) {
|
||||
|
|
|
@ -19,24 +19,25 @@
|
|||
void smGetMonitorInfo(SSnodeMgmt *pMgmt, SMonSmInfo *smInfo) {}
|
||||
|
||||
int32_t smProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
SDCreateSnodeReq createReq = {0};
|
||||
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &createReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (pInput->pData->dnodeId != 0 && createReq.dnodeId != pInput->pData->dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to create snode since %s", terrstr());
|
||||
code = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to create snode since %s", tstrerror(code));
|
||||
tFreeSMCreateQnodeReq(&createReq);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
bool deployed = true;
|
||||
if (dmWriteFile(pInput->path, pInput->name, deployed) != 0) {
|
||||
dError("failed to write snode file since %s", terrstr());
|
||||
if ((code = dmWriteFile(pInput->path, pInput->name, deployed)) != 0) {
|
||||
dError("failed to write snode file since %s", tstrerror(code));
|
||||
tFreeSMCreateQnodeReq(&createReq);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
tFreeSMCreateQnodeReq(&createReq);
|
||||
|
@ -44,24 +45,26 @@ int32_t smProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
int32_t smProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
SDDropSnodeReq dropReq = {0};
|
||||
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &dropReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
if (pInput->pData->dnodeId != 0 && dropReq.dnodeId != pInput->pData->dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to drop snode since %s", terrstr());
|
||||
code = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to drop snode since %s", tstrerror(code));
|
||||
tFreeSMCreateQnodeReq(&dropReq);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
bool deployed = false;
|
||||
if (dmWriteFile(pInput->path, pInput->name, deployed) != 0) {
|
||||
dError("failed to write snode file since %s", terrstr());
|
||||
if ((code = dmWriteFile(pInput->path, pInput->name, deployed)) != 0) {
|
||||
dError("failed to write snode file since %s", tstrerror(code));
|
||||
tFreeSMCreateQnodeReq(&dropReq);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
tFreeSMCreateQnodeReq(&dropReq);
|
||||
|
|
|
@ -33,12 +33,19 @@ static void smClose(SSnodeMgmt *pMgmt) {
|
|||
|
||||
taosMemoryFree(pMgmt);
|
||||
}
|
||||
|
||||
int32_t sndOpenWrapper(const char *path, SSnodeOpt *pOption, SSnode **pNode) {
|
||||
*pNode = sndOpen(path, pOption);
|
||||
if (*pNode == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int32_t smOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||
int32_t code = 0;
|
||||
SSnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SSnodeMgmt));
|
||||
if (pMgmt == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return code;
|
||||
}
|
||||
|
||||
pMgmt->pData = pInput->pData;
|
||||
|
@ -50,35 +57,34 @@ int32_t smOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
|||
|
||||
SSnodeOpt option = {0};
|
||||
smInitOption(pMgmt, &option);
|
||||
pMgmt->pSnode = sndOpen(pMgmt->path, &option);
|
||||
if (pMgmt->pSnode == NULL) {
|
||||
dError("failed to open snode since %s", terrstr());
|
||||
|
||||
code = sndOpenWrapper(pMgmt->path, &option, &pMgmt->pSnode);
|
||||
if (code != 0) {
|
||||
dError("failed to open snode since %s", tstrerror(code));
|
||||
smClose(pMgmt);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
tmsgReportStartup("snode-impl", "initialized");
|
||||
|
||||
if (smStartWorker(pMgmt) != 0) {
|
||||
dError("failed to start snode worker since %s", terrstr());
|
||||
if ((code = smStartWorker(pMgmt)) != 0) {
|
||||
dError("failed to start snode worker since %s", tstrerror(code));
|
||||
smClose(pMgmt);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
tmsgReportStartup("snode-worker", "initialized");
|
||||
|
||||
if (udfcOpen() != 0) {
|
||||
dError("failed to open udfc in snode");
|
||||
if ((code = udfcOpen()) != 0) {
|
||||
dError("failed to open udfc in snode since:%s", tstrerror(code));
|
||||
smClose(pMgmt);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
pOutput->pMgmt = pMgmt;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t smStartSnodes(SSnodeMgmt *pMgmt) {
|
||||
return sndInit(pMgmt->pSnode);
|
||||
}
|
||||
static int32_t smStartSnodes(SSnodeMgmt *pMgmt) { return sndInit(pMgmt->pSnode); }
|
||||
|
||||
SMgmtFunc smGetMgmtFunc() {
|
||||
SMgmtFunc mgmtFunc = {0};
|
||||
|
|
|
@ -68,17 +68,18 @@ static void smProcessStreamQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
int32_t smStartWorker(SSnodeMgmt *pMgmt) {
|
||||
int32_t code = 0;
|
||||
pMgmt->writeWroker = taosArrayInit(0, sizeof(SMultiWorker *));
|
||||
if (pMgmt->writeWroker == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return code;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < tsNumOfSnodeWriteThreads; i++) {
|
||||
SMultiWorker *pWriteWorker = taosMemoryMalloc(sizeof(SMultiWorker));
|
||||
if (pWriteWorker == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return code;
|
||||
}
|
||||
|
||||
SMultiWorkerCfg cfg = {
|
||||
|
@ -87,13 +88,13 @@ int32_t smStartWorker(SSnodeMgmt *pMgmt) {
|
|||
.fp = smProcessWriteQueue,
|
||||
.param = pMgmt,
|
||||
};
|
||||
if (tMultiWorkerInit(pWriteWorker, &cfg) != 0) {
|
||||
dError("failed to start snode-unique worker since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = tMultiWorkerInit(pWriteWorker, &cfg)) != 0) {
|
||||
dError("failed to start snode-unique worker since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
if (taosArrayPush(pMgmt->writeWroker, &pWriteWorker) == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,13 +106,13 @@ int32_t smStartWorker(SSnodeMgmt *pMgmt) {
|
|||
.param = pMgmt,
|
||||
};
|
||||
|
||||
if (tSingleWorkerInit(&pMgmt->streamWorker, &cfg)) {
|
||||
dError("failed to start snode shared-worker since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = tSingleWorkerInit(&pMgmt->streamWorker, &cfg)) != 0) {
|
||||
dError("failed to start snode shared-worker since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
dDebug("snode workers are initialized");
|
||||
return 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
void smStopWorker(SSnodeMgmt *pMgmt) {
|
||||
|
@ -133,17 +134,18 @@ int32_t smPutMsgToQueue(SSnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
|||
if (code) {
|
||||
rpcFreeCont(pRpc->pCont);
|
||||
pRpc->pCont = NULL;
|
||||
return -1;
|
||||
return code = terrno;
|
||||
}
|
||||
|
||||
SSnode *pSnode = pMgmt->pSnode;
|
||||
if (pSnode == NULL) {
|
||||
dError("msg:%p failed to put into snode queue since %s, type:%s qtype:%d len:%d", pMsg, terrstr(),
|
||||
code = terrno;
|
||||
dError("msg:%p failed to put into snode queue since %s, type:%s qtype:%d len:%d", pMsg, tstrerror(code),
|
||||
TMSG_INFO(pMsg->msgType), qtype, pRpc->contLen);
|
||||
taosFreeQitem(pMsg);
|
||||
rpcFreeCont(pRpc->pCont);
|
||||
pRpc->pCont = NULL;
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
SMsgHead *pHead = pRpc->pCont;
|
||||
|
@ -154,48 +156,44 @@ int32_t smPutMsgToQueue(SSnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
|||
|
||||
switch (qtype) {
|
||||
case STREAM_QUEUE:
|
||||
smPutNodeMsgToStreamQueue(pMgmt, pMsg);
|
||||
code = smPutNodeMsgToStreamQueue(pMgmt, pMsg);
|
||||
break;
|
||||
case WRITE_QUEUE:
|
||||
smPutNodeMsgToWriteQueue(pMgmt, pMsg);
|
||||
code = smPutNodeMsgToWriteQueue(pMgmt, pMsg);
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
code = TSDB_CODE_INVALID_PARA;
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
return 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t smPutNodeMsgToMgmtQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
SMultiWorker *pWorker = taosArrayGetP(pMgmt->writeWroker, 0);
|
||||
if (pWorker == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
|
||||
taosWriteQitem(pWorker->queue, pMsg);
|
||||
return 0;
|
||||
return taosWriteQitem(pWorker->queue, pMsg);
|
||||
}
|
||||
|
||||
int32_t smPutNodeMsgToWriteQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||
SMultiWorker *pWorker = taosArrayGetP(pMgmt->writeWroker, 0);
|
||||
if (pWorker == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
|
||||
taosWriteQitem(pWorker->queue, pMsg);
|
||||
return 0;
|
||||
return taosWriteQitem(pWorker->queue, pMsg);
|
||||
}
|
||||
|
||||
int32_t smPutNodeMsgToStreamQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||
SSingleWorker *pWorker = &pMgmt->streamWorker;
|
||||
|
||||
dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
|
||||
taosWriteQitem(pWorker->queue, pMsg);
|
||||
return 0;
|
||||
return taosWriteQitem(pWorker->queue, pMsg);
|
||||
}
|
||||
|
|
|
@ -54,24 +54,24 @@ typedef struct {
|
|||
} SWrapperCfg;
|
||||
|
||||
typedef struct {
|
||||
int32_t vgId;
|
||||
int32_t vgVersion;
|
||||
int32_t refCount;
|
||||
int8_t dropped;
|
||||
int8_t failed;
|
||||
int8_t disable;
|
||||
int32_t diskPrimary;
|
||||
int32_t toVgId;
|
||||
char *path;
|
||||
SVnode *pImpl;
|
||||
SMultiWorker pWriteW;
|
||||
SMultiWorker pSyncW;
|
||||
SMultiWorker pSyncRdW;
|
||||
SMultiWorker pApplyW;
|
||||
STaosQueue *pQueryQ;
|
||||
STaosQueue *pStreamQ;
|
||||
STaosQueue *pFetchQ;
|
||||
STaosQueue *pMultiMgmQ;
|
||||
int32_t vgId;
|
||||
int32_t vgVersion;
|
||||
int32_t refCount;
|
||||
int8_t dropped;
|
||||
int8_t failed;
|
||||
int8_t disable;
|
||||
int32_t diskPrimary;
|
||||
int32_t toVgId;
|
||||
char *path;
|
||||
SVnode *pImpl;
|
||||
SMultiWorker pWriteW;
|
||||
SMultiWorker pSyncW;
|
||||
SMultiWorker pSyncRdW;
|
||||
SMultiWorker pApplyW;
|
||||
STaosQueue *pQueryQ;
|
||||
STaosQueue *pStreamQ;
|
||||
STaosQueue *pFetchQ;
|
||||
STaosQueue *pMultiMgmQ;
|
||||
} SVnodeObj;
|
||||
|
||||
typedef struct {
|
||||
|
@ -107,9 +107,9 @@ int32_t vmProcessCheckLearnCatchupReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
|||
int32_t vmProcessArbHeartBeatReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||
|
||||
// vmFile.c
|
||||
int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t *numOfVnodes);
|
||||
int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt);
|
||||
SVnodeObj **vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes);
|
||||
int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t *numOfVnodes);
|
||||
int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt);
|
||||
int32_t vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes, SVnodeObj ***ppVnodes);
|
||||
|
||||
// vmWorker.c
|
||||
int32_t vmStartWorker(SVnodeMgmt *pMgmt);
|
||||
|
|
|
@ -19,12 +19,16 @@
|
|||
|
||||
#define MAX_CONTENT_LEN 2 * 1024 * 1024
|
||||
|
||||
SVnodeObj **vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes) {
|
||||
int32_t vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes, SVnodeObj ***ppVnodes) {
|
||||
taosThreadRwlockRdlock(&pMgmt->lock);
|
||||
|
||||
int32_t num = 0;
|
||||
int32_t size = taosHashGetSize(pMgmt->hash);
|
||||
SVnodeObj **pVnodes = taosMemoryCalloc(size, sizeof(SVnodeObj *));
|
||||
if (pVnodes == NULL) {
|
||||
taosThreadRwlockUnlock(&pMgmt->lock);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
void *pIter = taosHashIterate(pMgmt->hash, NULL);
|
||||
while (pIter) {
|
||||
|
@ -42,8 +46,9 @@ SVnodeObj **vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes) {
|
|||
|
||||
taosThreadRwlockUnlock(&pMgmt->lock);
|
||||
*numOfVnodes = num;
|
||||
*ppVnodes = pVnodes;
|
||||
|
||||
return pVnodes;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t vmDecodeVnodeList(SJson *pJson, SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t *numOfVnodes) {
|
||||
|
@ -52,29 +57,32 @@ static int32_t vmDecodeVnodeList(SJson *pJson, SVnodeMgmt *pMgmt, SWrapperCfg **
|
|||
*ppCfgs = NULL;
|
||||
|
||||
SJson *vnodes = tjsonGetObjectItem(pJson, "vnodes");
|
||||
if (vnodes == NULL) return -1;
|
||||
if (vnodes == NULL) return TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
|
||||
int32_t vnodesNum = cJSON_GetArraySize(vnodes);
|
||||
if (vnodesNum > 0) {
|
||||
pCfgs = taosMemoryCalloc(vnodesNum, sizeof(SWrapperCfg));
|
||||
if (pCfgs == NULL) return -1;
|
||||
if (pCfgs == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < vnodesNum; ++i) {
|
||||
SJson *vnode = tjsonGetArrayItem(vnodes, i);
|
||||
if (vnode == NULL) goto _OVER;
|
||||
if (vnode == NULL) {
|
||||
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
SWrapperCfg *pCfg = &pCfgs[i];
|
||||
tjsonGetInt32ValueFromDouble(vnode, "vgId", pCfg->vgId, code);
|
||||
if (code < 0) goto _OVER;
|
||||
if (code != 0) goto _OVER;
|
||||
tjsonGetInt32ValueFromDouble(vnode, "dropped", pCfg->dropped, code);
|
||||
if (code < 0) goto _OVER;
|
||||
if (code != 0) goto _OVER;
|
||||
tjsonGetInt32ValueFromDouble(vnode, "vgVersion", pCfg->vgVersion, code);
|
||||
if (code < 0) goto _OVER;
|
||||
if (code != 0) goto _OVER;
|
||||
tjsonGetInt32ValueFromDouble(vnode, "diskPrimary", pCfg->diskPrimary, code);
|
||||
if (code < 0) goto _OVER;
|
||||
if (code != 0) goto _OVER;
|
||||
tjsonGetInt32ValueFromDouble(vnode, "toVgId", pCfg->toVgId, code);
|
||||
if (code < 0) goto _OVER;
|
||||
if (code != 0) goto _OVER;
|
||||
|
||||
snprintf(pCfg->path, sizeof(pCfg->path), "%s%svnode%d", pMgmt->path, TD_DIRSEP, pCfg->vgId);
|
||||
}
|
||||
|
@ -98,33 +106,35 @@ int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t
|
|||
snprintf(file, sizeof(file), "%s%svnodes.json", pMgmt->path, TD_DIRSEP);
|
||||
|
||||
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
||||
dInfo("vnode file:%s not exist", file);
|
||||
return 0;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dInfo("vnode file:%s not exist, reason:%s", file, tstrerror(code));
|
||||
code = 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to open vnode file:%s since %s", file, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to open vnode file:%s since %s", file, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
int64_t size = 0;
|
||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to fstat mnode file:%s since %s", file, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to fstat mnode file:%s since %s", file, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pData = taosMemoryMalloc(size + 1);
|
||||
if (pData == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (taosReadFile(pFile, pData, size) != size) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to read vnode file:%s since %s", file, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to read vnode file:%s since %s", file, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -132,12 +142,12 @@ int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t
|
|||
|
||||
pJson = tjsonParse(pData);
|
||||
if (pJson == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (vmDecodeVnodeList(pJson, pMgmt, ppCfgs, numOfVnodes) < 0) {
|
||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -150,28 +160,36 @@ _OVER:
|
|||
if (pFile != NULL) taosCloseFile(&pFile);
|
||||
|
||||
if (code != 0) {
|
||||
dError("failed to read vnode file:%s since %s", file, terrstr());
|
||||
dError("failed to read vnode file:%s since %s", file, tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t vmEncodeVnodeList(SJson *pJson, SVnodeObj **ppVnodes, int32_t numOfVnodes) {
|
||||
SJson *vnodes = tjsonCreateArray();
|
||||
if (vnodes == NULL) return -1;
|
||||
if (tjsonAddItemToObject(pJson, "vnodes", vnodes) < 0) return -1;
|
||||
int32_t code = 0;
|
||||
SJson *vnodes = tjsonCreateArray();
|
||||
if (vnodes == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
if ((code = tjsonAddItemToObject(pJson, "vnodes", vnodes)) < 0) {
|
||||
tjsonDelete(vnodes);
|
||||
return code;
|
||||
};
|
||||
|
||||
for (int32_t i = 0; i < numOfVnodes; ++i) {
|
||||
SVnodeObj *pVnode = ppVnodes[i];
|
||||
if (pVnode == NULL) continue;
|
||||
|
||||
SJson *vnode = tjsonCreateObject();
|
||||
if (vnode == NULL) return -1;
|
||||
if (tjsonAddDoubleToObject(vnode, "vgId", pVnode->vgId) < 0) return -1;
|
||||
if (tjsonAddDoubleToObject(vnode, "dropped", pVnode->dropped) < 0) return -1;
|
||||
if (tjsonAddDoubleToObject(vnode, "vgVersion", pVnode->vgVersion) < 0) return -1;
|
||||
if (tjsonAddDoubleToObject(vnode, "diskPrimary", pVnode->diskPrimary) < 0) return -1;
|
||||
if (pVnode->toVgId && tjsonAddDoubleToObject(vnode, "toVgId", pVnode->toVgId) < 0) return -1;
|
||||
if (tjsonAddItemToArray(vnodes, vnode) < 0) return -1;
|
||||
if (vnode == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||
if ((code = tjsonAddDoubleToObject(vnode, "vgId", pVnode->vgId)) < 0) return code;
|
||||
if ((code = tjsonAddDoubleToObject(vnode, "dropped", pVnode->dropped)) < 0) return code;
|
||||
if ((code = tjsonAddDoubleToObject(vnode, "vgVersion", pVnode->vgVersion)) < 0) return code;
|
||||
if ((code = tjsonAddDoubleToObject(vnode, "diskPrimary", pVnode->diskPrimary)) < 0) return code;
|
||||
if (pVnode->toVgId) {
|
||||
if ((code = tjsonAddDoubleToObject(vnode, "toVgId", pVnode->toVgId)) < 0) return code;
|
||||
}
|
||||
if ((code = tjsonAddItemToArray(vnodes, vnode)) < 0) return code;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -185,30 +203,60 @@ int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt) {
|
|||
SVnodeObj **ppVnodes = NULL;
|
||||
char file[PATH_MAX] = {0};
|
||||
char realfile[PATH_MAX] = {0};
|
||||
snprintf(file, sizeof(file), "%s%svnodes_tmp.json", pMgmt->path, TD_DIRSEP);
|
||||
snprintf(realfile, sizeof(realfile), "%s%svnodes.json", pMgmt->path, TD_DIRSEP);
|
||||
|
||||
int32_t nBytes = snprintf(file, sizeof(file), "%s%svnodes_tmp.json", pMgmt->path, TD_DIRSEP);
|
||||
if (nBytes <= 0 || nBytes >= sizeof(file)) {
|
||||
return TSDB_CODE_OUT_OF_RANGE;
|
||||
}
|
||||
|
||||
nBytes = snprintf(realfile, sizeof(realfile), "%s%svnodes.json", pMgmt->path, TD_DIRSEP);
|
||||
if (nBytes <= 0 || nBytes >= sizeof(realfile)) {
|
||||
return TSDB_CODE_OUT_OF_RANGE;
|
||||
}
|
||||
|
||||
int32_t numOfVnodes = 0;
|
||||
ppVnodes = vmGetVnodeListFromHash(pMgmt, &numOfVnodes);
|
||||
if (ppVnodes == NULL) goto _OVER;
|
||||
code = vmGetVnodeListFromHash(pMgmt, &numOfVnodes, &ppVnodes);
|
||||
if (code) goto _OVER;
|
||||
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
// terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
pJson = tjsonCreateObject();
|
||||
if (pJson == NULL) goto _OVER;
|
||||
if (vmEncodeVnodeList(pJson, ppVnodes, numOfVnodes) != 0) goto _OVER;
|
||||
if (pJson == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
if ((code = vmEncodeVnodeList(pJson, ppVnodes, numOfVnodes)) != 0) goto _OVER;
|
||||
|
||||
buffer = tjsonToString(pJson);
|
||||
if (buffer == NULL) goto _OVER;
|
||||
terrno = 0;
|
||||
if (buffer == NULL) {
|
||||
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||
if (pFile == NULL) goto _OVER;
|
||||
if (pFile == NULL) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
int32_t len = strlen(buffer);
|
||||
if (taosWriteFile(pFile, buffer, len) <= 0) goto _OVER;
|
||||
if (taosFsyncFile(pFile) < 0) goto _OVER;
|
||||
if (taosWriteFile(pFile, buffer, len) <= 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
if (taosFsyncFile(pFile) < 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
taosCloseFile(&pFile);
|
||||
if (taosRenameFile(file, realfile) != 0) goto _OVER;
|
||||
code = taosCloseFile(&pFile);
|
||||
if (code != 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
if (taosRenameFile(file, realfile) != 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
code = 0;
|
||||
dInfo("succeed to write vnodes file:%s, vnodes:%d", realfile, numOfVnodes);
|
||||
|
@ -228,8 +276,7 @@ _OVER:
|
|||
}
|
||||
|
||||
if (code != 0) {
|
||||
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to write vnodes file:%s since %s, vnodes:%d", realfile, terrstr(), numOfVnodes);
|
||||
dError("failed to write vnodes file:%s since %s, vnodes:%d", realfile, tstrerror(code), numOfVnodes);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -256,8 +256,7 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
char path[TSDB_FILENAME_LEN] = {0};
|
||||
|
||||
if (tDeserializeSCreateVnodeReq(pMsg->pCont, pMsg->contLen, &req) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
if (req.learnerReplica == 0) {
|
||||
|
@ -298,25 +297,24 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
}
|
||||
if (pReplica->id != pMgmt->pData->dnodeId || pReplica->port != tsServerPort ||
|
||||
strcmp(pReplica->fqdn, tsLocalFqdn) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
dError("vgId:%d, dnodeId:%d ep:%s:%u not matched with local dnode", req.vgId, pReplica->id, pReplica->fqdn,
|
||||
pReplica->port);
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
dError("vgId:%d, dnodeId:%d ep:%s:%u not matched with local dnode, reason:%s", req.vgId, pReplica->id,
|
||||
pReplica->fqdn, pReplica->port, tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
if (req.encryptAlgorithm == DND_CA_SM4) {
|
||||
if (strlen(tsEncryptKey) == 0) {
|
||||
terrno = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY;
|
||||
dError("vgId:%d, failed to create vnode since encrypt key is empty", req.vgId);
|
||||
return -1;
|
||||
code = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY;
|
||||
dError("vgId:%d, failed to create vnode since encrypt key is empty, reason:%s", req.vgId, tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
vmGenerateVnodeCfg(&req, &vnodeCfg);
|
||||
|
||||
if (vmTsmaAdjustDays(&vnodeCfg, &req) < 0) {
|
||||
dError("vgId:%d, failed to adjust tsma days since %s", req.vgId, terrstr());
|
||||
code = terrno != 0 ? terrno : -1;
|
||||
if ((code = vmTsmaAdjustDays(&vnodeCfg, &req)) < 0) {
|
||||
dError("vgId:%d, failed to adjust tsma days since %s", req.vgId, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -327,8 +325,7 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
dError("vgId:%d, already exist", req.vgId);
|
||||
tFreeSCreateVnodeReq(&req);
|
||||
vmReleaseVnode(pMgmt, pVnode);
|
||||
terrno = TSDB_CODE_VND_ALREADY_EXIST;
|
||||
code = terrno;
|
||||
code = TSDB_CODE_VND_ALREADY_EXIST;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ int32_t vmGetPrimaryDisk(SVnodeMgmt *pMgmt, int32_t vgId) {
|
|||
}
|
||||
|
||||
int32_t vmAllocPrimaryDisk(SVnodeMgmt *pMgmt, int32_t vgId) {
|
||||
int32_t code = 0;
|
||||
STfs *pTfs = pMgmt->pTfs;
|
||||
int32_t diskId = 0;
|
||||
if (!pTfs) {
|
||||
|
@ -59,7 +60,12 @@ int32_t vmAllocPrimaryDisk(SVnodeMgmt *pMgmt, int32_t vgId) {
|
|||
// alloc
|
||||
int32_t disks[TFS_MAX_DISKS_PER_TIER] = {0};
|
||||
int32_t numOfVnodes = 0;
|
||||
SVnodeObj **ppVnodes = vmGetVnodeListFromHash(pMgmt, &numOfVnodes);
|
||||
SVnodeObj **ppVnodes = NULL;
|
||||
|
||||
code = vmGetVnodeListFromHash(pMgmt, &numOfVnodes, &ppVnodes);
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
for (int32_t v = 0; v < numOfVnodes; v++) {
|
||||
SVnodeObj *pVnode = ppVnodes[v];
|
||||
disks[pVnode->diskPrimary] += 1;
|
||||
|
@ -436,6 +442,7 @@ static void *vmCloseVnodeInThread(void *param) {
|
|||
}
|
||||
|
||||
static void vmCloseVnodes(SVnodeMgmt *pMgmt) {
|
||||
int32_t code = 0;
|
||||
dInfo("start to close all vnodes");
|
||||
tSingleWorkerCleanup(&pMgmt->mgmtWorker);
|
||||
dInfo("vnodes mgmt worker is stopped");
|
||||
|
@ -443,7 +450,12 @@ static void vmCloseVnodes(SVnodeMgmt *pMgmt) {
|
|||
dInfo("vnodes multiple mgmt worker is stopped");
|
||||
|
||||
int32_t numOfVnodes = 0;
|
||||
SVnodeObj **ppVnodes = vmGetVnodeListFromHash(pMgmt, &numOfVnodes);
|
||||
SVnodeObj **ppVnodes = NULL;
|
||||
code = vmGetVnodeListFromHash(pMgmt, &numOfVnodes, &ppVnodes);
|
||||
if (code != 0) {
|
||||
dError("failed to get vnode list since %s", tstrerror(code));
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t threadNum = tsNumOfCores / 2;
|
||||
if (threadNum < 1) threadNum = 1;
|
||||
|
@ -513,8 +525,14 @@ static void vmCleanup(SVnodeMgmt *pMgmt) {
|
|||
}
|
||||
|
||||
static void vmCheckSyncTimeout(SVnodeMgmt *pMgmt) {
|
||||
int32_t code = 0;
|
||||
int32_t numOfVnodes = 0;
|
||||
SVnodeObj **ppVnodes = vmGetVnodeListFromHash(pMgmt, &numOfVnodes);
|
||||
SVnodeObj **ppVnodes = NULL;
|
||||
code = vmGetVnodeListFromHash(pMgmt, &numOfVnodes, &ppVnodes);
|
||||
if (code != 0) {
|
||||
dError("failed to get vnode list since %s", tstrerror(code));
|
||||
return;
|
||||
}
|
||||
|
||||
if (ppVnodes != NULL) {
|
||||
for (int32_t i = 0; i < numOfVnodes; ++i) {
|
||||
|
@ -549,12 +567,14 @@ static void *vmThreadFp(void *param) {
|
|||
}
|
||||
|
||||
static int32_t vmInitTimer(SVnodeMgmt *pMgmt) {
|
||||
int32_t code = 0;
|
||||
TdThreadAttr thAttr;
|
||||
taosThreadAttrInit(&thAttr);
|
||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
if (taosThreadCreate(&pMgmt->thread, &thAttr, vmThreadFp, pMgmt) != 0) {
|
||||
dError("failed to create vnode timer thread since %s", strerror(errno));
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to create vnode timer thread since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
taosThreadAttrDestroy(&thAttr);
|
||||
|
@ -573,7 +593,10 @@ static int32_t vmInit(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
|||
int32_t code = -1;
|
||||
|
||||
SVnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SVnodeMgmt));
|
||||
if (pMgmt == NULL) goto _OVER;
|
||||
if (pMgmt == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pMgmt->pData = pInput->pData;
|
||||
pMgmt->path = pInput->path;
|
||||
|
@ -582,8 +605,18 @@ static int32_t vmInit(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
|||
pMgmt->msgCb.putToQueueFp = (PutToQueueFp)vmPutRpcMsgToQueue;
|
||||
pMgmt->msgCb.qsizeFp = (GetQueueSizeFp)vmGetQueueSize;
|
||||
pMgmt->msgCb.mgmt = pMgmt;
|
||||
taosThreadRwlockInit(&pMgmt->lock, NULL);
|
||||
taosThreadMutexInit(&pMgmt->createLock, NULL);
|
||||
|
||||
code = taosThreadRwlockInit(&pMgmt->lock, NULL);
|
||||
if (code != 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
code = taosThreadMutexInit(&pMgmt->createLock, NULL);
|
||||
if (code != 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pMgmt->pTfs = pInput->pTfs;
|
||||
if (pMgmt->pTfs == NULL) {
|
||||
|
@ -592,38 +625,39 @@ static int32_t vmInit(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
|||
}
|
||||
tmsgReportStartup("vnode-tfs", "initialized");
|
||||
|
||||
if (walInit() != 0) {
|
||||
dError("failed to init wal since %s", terrstr());
|
||||
if ((code = walInit()) != 0) {
|
||||
dError("failed to init wal since %s", tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
tmsgReportStartup("vnode-wal", "initialized");
|
||||
|
||||
if (syncInit() != 0) {
|
||||
dError("failed to open sync since %s", terrstr());
|
||||
if ((code = syncInit()) != 0) {
|
||||
dError("failed to open sync since %s", tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
tmsgReportStartup("vnode-sync", "initialized");
|
||||
|
||||
if (vnodeInit(tsNumOfCommitThreads) != 0) {
|
||||
dError("failed to init vnode since %s", terrstr());
|
||||
if ((code = vnodeInit(tsNumOfCommitThreads)) != 0) {
|
||||
dError("failed to init vnode since %s", tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
tmsgReportStartup("vnode-commit", "initialized");
|
||||
|
||||
if (vmStartWorker(pMgmt) != 0) {
|
||||
dError("failed to init workers since %s", terrstr());
|
||||
if ((code = vmStartWorker(pMgmt)) != 0) {
|
||||
dError("failed to init workers since %s", tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
tmsgReportStartup("vnode-worker", "initialized");
|
||||
|
||||
if (vmOpenVnodes(pMgmt) != 0) {
|
||||
dError("failed to open all vnodes since %s", terrstr());
|
||||
if ((code = vmOpenVnodes(pMgmt)) != 0) {
|
||||
dError("failed to open all vnodes since %s", tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
tmsgReportStartup("vnode-vnodes", "initialized");
|
||||
|
||||
if (udfcOpen() != 0) {
|
||||
dError("failed to open udfc in vnode");
|
||||
if ((code = udfcOpen()) != 0) {
|
||||
dError("failed to open udfc in vnode since %s", tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -633,7 +667,7 @@ _OVER:
|
|||
if (code == 0) {
|
||||
pOutput->pMgmt = pMgmt;
|
||||
} else {
|
||||
dError("failed to init vnodes-mgmt since %s", terrstr());
|
||||
dError("failed to init vnodes-mgmt since %s", tstrerror(code));
|
||||
vmCleanup(pMgmt);
|
||||
}
|
||||
|
||||
|
@ -683,18 +717,32 @@ static void *vmRestoreVnodeInThread(void *param) {
|
|||
}
|
||||
|
||||
static int32_t vmStartVnodes(SVnodeMgmt *pMgmt) {
|
||||
int32_t code = 0;
|
||||
int32_t numOfVnodes = 0;
|
||||
SVnodeObj **ppVnodes = vmGetVnodeListFromHash(pMgmt, &numOfVnodes);
|
||||
SVnodeObj **ppVnodes = NULL;
|
||||
code = vmGetVnodeListFromHash(pMgmt, &numOfVnodes, &ppVnodes);
|
||||
if (code != 0) {
|
||||
dError("failed to get vnode list since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t threadNum = tsNumOfCores / 2;
|
||||
if (threadNum < 1) threadNum = 1;
|
||||
int32_t vnodesPerThread = numOfVnodes / threadNum + 1;
|
||||
|
||||
SVnodeThread *threads = taosMemoryCalloc(threadNum, sizeof(SVnodeThread));
|
||||
if (threads == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
for (int32_t t = 0; t < threadNum; ++t) {
|
||||
threads[t].threadIndex = t;
|
||||
threads[t].pMgmt = pMgmt;
|
||||
threads[t].ppVnodes = taosMemoryCalloc(vnodesPerThread, sizeof(SVnode *));
|
||||
if (threads[t].ppVnodes == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t v = 0; v < numOfVnodes; ++v) {
|
||||
|
@ -717,6 +765,7 @@ static int32_t vmStartVnodes(SVnodeMgmt *pMgmt) {
|
|||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
if (taosThreadCreate(&pThread->thread, &thAttr, vmRestoreVnodeInThread, pThread) != 0) {
|
||||
dError("thread:%d, failed to create thread to restore vnode since %s", pThread->threadIndex, strerror(errno));
|
||||
ASSERT(errno == 0);
|
||||
}
|
||||
|
||||
taosThreadAttrDestroy(&thAttr);
|
||||
|
@ -742,6 +791,14 @@ static int32_t vmStartVnodes(SVnodeMgmt *pMgmt) {
|
|||
}
|
||||
|
||||
return vmInitTimer(pMgmt);
|
||||
|
||||
_exit:
|
||||
for (int32_t t = 0; t < threadNum; ++t) {
|
||||
SVnodeThread *pThread = &threads[t];
|
||||
taosMemoryFree(pThread->ppVnodes);
|
||||
}
|
||||
taosMemoryFree(threads);
|
||||
return code;
|
||||
}
|
||||
|
||||
static void vmStop(SVnodeMgmt *pMgmt) { vmCleanupTimer(pMgmt); }
|
||||
|
|
|
@ -200,26 +200,33 @@ static bool vmDataSpaceSufficient(SVnodeObj *pVnode) {
|
|||
}
|
||||
}
|
||||
|
||||
static int32_t vmAcquireVnodeWrapper(SVnodeMgmt *pMgt, int32_t vgId, SVnodeObj **pNode) {
|
||||
*pNode = vmAcquireVnode(pMgt, vgId);
|
||||
if (*pNode == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
|
||||
int32_t code = 0;
|
||||
const STraceId *trace = &pMsg->info.traceId;
|
||||
if (pMsg->contLen < sizeof(SMsgHead)) {
|
||||
dGError("invalid rpc msg with no msg head at pCont. pMsg:%p, type:%s, contLen:%d", pMsg, TMSG_INFO(pMsg->msgType),
|
||||
pMsg->contLen);
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
SMsgHead *pHead = pMsg->pCont;
|
||||
int32_t code = 0;
|
||||
|
||||
pHead->contLen = ntohl(pHead->contLen);
|
||||
pHead->vgId = ntohl(pHead->vgId);
|
||||
|
||||
SVnodeObj *pVnode = vmAcquireVnode(pMgmt, pHead->vgId);
|
||||
if (pVnode == NULL) {
|
||||
SVnodeObj *pVnode = NULL;
|
||||
code = vmAcquireVnodeWrapper(pMgmt, pHead->vgId, &pVnode);
|
||||
if (code != 0) {
|
||||
dGDebug("vgId:%d, msg:%p failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg,
|
||||
terrstr(), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
|
||||
terrno = (terrno != 0) ? terrno : -1;
|
||||
return terrno;
|
||||
tstrerror(code), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
|
||||
return code;
|
||||
}
|
||||
|
||||
switch (qtype) {
|
||||
|
@ -234,49 +241,45 @@ static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtyp
|
|||
break;
|
||||
case STREAM_QUEUE:
|
||||
dGTrace("vgId:%d, msg:%p put into vnode-stream queue", pVnode->vgId, pMsg);
|
||||
taosWriteQitem(pVnode->pStreamQ, pMsg);
|
||||
code = taosWriteQitem(pVnode->pStreamQ, pMsg);
|
||||
break;
|
||||
case FETCH_QUEUE:
|
||||
dGTrace("vgId:%d, msg:%p put into vnode-fetch queue", pVnode->vgId, pMsg);
|
||||
taosWriteQitem(pVnode->pFetchQ, pMsg);
|
||||
code = taosWriteQitem(pVnode->pFetchQ, pMsg);
|
||||
break;
|
||||
case WRITE_QUEUE:
|
||||
if (!vmDataSpaceSufficient(pVnode)) {
|
||||
terrno = TSDB_CODE_NO_ENOUGH_DISKSPACE;
|
||||
code = terrno;
|
||||
code = TSDB_CODE_NO_ENOUGH_DISKSPACE;
|
||||
dError("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, tstrerror(code));
|
||||
break;
|
||||
}
|
||||
if (pMsg->msgType == TDMT_VND_SUBMIT && (grantCheck(TSDB_GRANT_STORAGE) != TSDB_CODE_SUCCESS)) {
|
||||
terrno = TSDB_CODE_VND_NO_WRITE_AUTH;
|
||||
code = terrno;
|
||||
code = TSDB_CODE_VND_NO_WRITE_AUTH;
|
||||
dDebug("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, tstrerror(code));
|
||||
break;
|
||||
}
|
||||
if (pMsg->msgType != TDMT_VND_ALTER_CONFIRM && pVnode->disable) {
|
||||
dDebug("vgId:%d, msg:%p put into vnode-write queue failed since its disable", pVnode->vgId, pMsg);
|
||||
terrno = TSDB_CODE_VND_STOPPED;
|
||||
code = terrno;
|
||||
code = TSDB_CODE_VND_STOPPED;
|
||||
break;
|
||||
}
|
||||
dGTrace("vgId:%d, msg:%p put into vnode-write queue", pVnode->vgId, pMsg);
|
||||
taosWriteQitem(pVnode->pWriteW.queue, pMsg);
|
||||
code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
|
||||
break;
|
||||
case SYNC_QUEUE:
|
||||
dGTrace("vgId:%d, msg:%p put into vnode-sync queue", pVnode->vgId, pMsg);
|
||||
taosWriteQitem(pVnode->pSyncW.queue, pMsg);
|
||||
code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
|
||||
break;
|
||||
case SYNC_RD_QUEUE:
|
||||
dGTrace("vgId:%d, msg:%p put into vnode-sync-rd queue", pVnode->vgId, pMsg);
|
||||
taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
|
||||
code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
|
||||
break;
|
||||
case APPLY_QUEUE:
|
||||
dGTrace("vgId:%d, msg:%p put into vnode-apply queue", pVnode->vgId, pMsg);
|
||||
taosWriteQitem(pVnode->pApplyW.queue, pMsg);
|
||||
code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
|
||||
break;
|
||||
default:
|
||||
code = -1;
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -299,15 +302,13 @@ int32_t vmPutMsgToStreamQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMs
|
|||
int32_t vmPutMsgToMultiMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||
const STraceId *trace = &pMsg->info.traceId;
|
||||
dGTrace("msg:%p, put into vnode-multi-mgmt queue", pMsg);
|
||||
taosWriteQitem(pMgmt->mgmtMultiWorker.queue, pMsg);
|
||||
return 0;
|
||||
return taosWriteQitem(pMgmt->mgmtMultiWorker.queue, pMsg);
|
||||
}
|
||||
|
||||
int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||
const STraceId *trace = &pMsg->info.traceId;
|
||||
dGTrace("msg:%p, put into vnode-mgmt queue", pMsg);
|
||||
taosWriteQitem(pMgmt->mgmtWorker.queue, pMsg);
|
||||
return 0;
|
||||
return taosWriteQitem(pMgmt->mgmtWorker.queue, pMsg);
|
||||
}
|
||||
|
||||
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
||||
|
@ -317,7 +318,7 @@ int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
|||
pRpc->contLen);
|
||||
rpcFreeCont(pRpc->pCont);
|
||||
pRpc->pCont = NULL;
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
EQItype itype = APPLY_QUEUE == qtype ? DEF_QITEM : RPC_QITEM;
|
||||
|
@ -326,7 +327,7 @@ int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
|||
if (code) {
|
||||
rpcFreeCont(pRpc->pCont);
|
||||
pRpc->pCont = NULL;
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
SMsgHead *pHead = pRpc->pCont;
|
||||
|
@ -383,6 +384,7 @@ int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
|
|||
}
|
||||
|
||||
int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
||||
int32_t code = 0;
|
||||
SMultiWorkerCfg wcfg = {.max = 1, .name = "vnode-write", .fp = (FItems)vnodeProposeWriteMsg, .param = pVnode->pImpl};
|
||||
SMultiWorkerCfg scfg = {.max = 1, .name = "vnode-sync", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
|
||||
SMultiWorkerCfg sccfg = {.max = 1, .name = "vnode-sync-rd", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
|
||||
|
@ -398,8 +400,7 @@ int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
|||
|
||||
if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
|
||||
pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pStreamQ == NULL || pVnode->pFetchQ == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
dInfo("vgId:%d, write-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pWriteW.queue,
|
||||
|
@ -428,26 +429,27 @@ void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
|||
}
|
||||
|
||||
int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
|
||||
int32_t code = 0;
|
||||
SQueryAutoQWorkerPool *pQPool = &pMgmt->queryPool;
|
||||
pQPool->name = "vnode-query";
|
||||
pQPool->min = tsNumOfVnodeQueryThreads;
|
||||
pQPool->max = tsNumOfVnodeQueryThreads;
|
||||
if (tQueryAutoQWorkerInit(pQPool) != 0) return -1;
|
||||
if ((code = tQueryAutoQWorkerInit(pQPool)) != 0) return code;
|
||||
|
||||
SAutoQWorkerPool *pStreamPool = &pMgmt->streamPool;
|
||||
pStreamPool->name = "vnode-stream";
|
||||
pStreamPool->ratio = tsRatioOfVnodeStreamThreads;
|
||||
if (tAutoQWorkerInit(pStreamPool) != 0) return -1;
|
||||
if ((code = tAutoQWorkerInit(pStreamPool)) != 0) return code;
|
||||
|
||||
SWWorkerPool *pFPool = &pMgmt->fetchPool;
|
||||
pFPool->name = "vnode-fetch";
|
||||
pFPool->max = tsNumOfVnodeFetchThreads;
|
||||
if (tWWorkerInit(pFPool) != 0) return -1;
|
||||
if ((code = tWWorkerInit(pFPool)) != 0) return code;
|
||||
|
||||
SSingleWorkerCfg mgmtCfg = {
|
||||
.min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt};
|
||||
|
||||
if (tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg) != 0) return -1;
|
||||
if ((code = tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg)) != 0) return code;
|
||||
|
||||
int32_t threadNum = 0;
|
||||
if (tsNumOfCores == 1) {
|
||||
|
@ -461,7 +463,7 @@ int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
|
|||
.fp = (FItem)vmProcessMultiMgmtQueue,
|
||||
.param = pMgmt};
|
||||
|
||||
if (tSingleWorkerInit(&pMgmt->mgmtMultiWorker, &multiMgmtCfg) != 0) return -1;
|
||||
if ((code = tSingleWorkerInit(&pMgmt->mgmtMultiWorker, &multiMgmtCfg)) != 0) return code;
|
||||
|
||||
dDebug("vnode workers are initialized");
|
||||
return 0;
|
||||
|
|
|
@ -98,6 +98,7 @@ SMgmtWrapper *dmAcquireWrapper(SDnode *pDnode, EDndNodeType nType);
|
|||
int32_t dmMarkWrapper(SMgmtWrapper *pWrapper);
|
||||
void dmReleaseWrapper(SMgmtWrapper *pWrapper);
|
||||
int32_t dmInitVars(SDnode *pDnode);
|
||||
int32_t dmInitVarsWrapper(SDnode *pDnode);
|
||||
void dmClearVars(SDnode *pDnode);
|
||||
int32_t dmInitModule(SDnode *pDnode);
|
||||
SMgmtInputOpt dmBuildMgmtInputOpt(SMgmtWrapper *pWrapper);
|
||||
|
|
|
@ -14,20 +14,22 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
// clang-format off
|
||||
#include "dmMgmt.h"
|
||||
#include "audit.h"
|
||||
#include "libs/function/tudf.h"
|
||||
#include "tgrant.h"
|
||||
#include "tcompare.h"
|
||||
// clang-format on
|
||||
|
||||
#define DM_INIT_AUDIT() \
|
||||
do { \
|
||||
auditCfg.port = tsMonitorPort; \
|
||||
auditCfg.server = tsMonitorFqdn; \
|
||||
auditCfg.comp = tsMonitorComp; \
|
||||
if (auditInit(&auditCfg) != 0) { \
|
||||
return -1; \
|
||||
} \
|
||||
#define DM_INIT_AUDIT() \
|
||||
do { \
|
||||
auditCfg.port = tsMonitorPort; \
|
||||
auditCfg.server = tsMonitorFqdn; \
|
||||
auditCfg.comp = tsMonitorComp; \
|
||||
if ((code = auditInit(&auditCfg)) != 0) { \
|
||||
return code; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static SDnode globalDnode = {0};
|
||||
|
@ -35,10 +37,11 @@ static SDnode globalDnode = {0};
|
|||
SDnode *dmInstance() { return &globalDnode; }
|
||||
|
||||
static int32_t dmCheckRepeatInit(SDnode *pDnode) {
|
||||
int32_t code = 0;
|
||||
if (atomic_val_compare_exchange_8(&pDnode->once, DND_ENV_INIT, DND_ENV_READY) != DND_ENV_INIT) {
|
||||
dError("env is already initialized");
|
||||
terrno = TSDB_CODE_REPEAT_INIT;
|
||||
return -1;
|
||||
code = TSDB_CODE_REPEAT_INIT;
|
||||
return code;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -58,18 +61,15 @@ static int32_t dmInitMonitor() {
|
|||
monCfg.port = tsMonitorPort;
|
||||
monCfg.server = tsMonitorFqdn;
|
||||
monCfg.comp = tsMonitorComp;
|
||||
if (monInit(&monCfg) != 0) {
|
||||
if (terrno != 0) code = terrno;
|
||||
goto _exit;
|
||||
if ((code = monInit(&monCfg)) != 0) {
|
||||
dError("failed to init monitor since %s", tstrerror(code));
|
||||
}
|
||||
|
||||
_exit:
|
||||
if (code) terrno = code;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t dmInitAudit() {
|
||||
SAuditCfg auditCfg = {0};
|
||||
int32_t code = 0;
|
||||
|
||||
DM_INIT_AUDIT();
|
||||
|
||||
|
@ -88,27 +88,34 @@ static bool dmDataSpaceAvailable() {
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool dmCheckDiskSpace() {
|
||||
static int32_t dmCheckDiskSpace() {
|
||||
osUpdate();
|
||||
// availability
|
||||
bool ret = true;
|
||||
int32_t code = 0;
|
||||
if (!dmDataSpaceAvailable()) {
|
||||
terrno = TSDB_CODE_NO_DISKSPACE;
|
||||
ret = false;
|
||||
code = TSDB_CODE_NO_DISKSPACE;
|
||||
return code;
|
||||
}
|
||||
if (!osLogSpaceAvailable()) {
|
||||
dError("log disk space unavailable, i.e. %s", tsLogDir);
|
||||
terrno = TSDB_CODE_NO_DISKSPACE;
|
||||
ret = false;
|
||||
code = TSDB_CODE_NO_DISKSPACE;
|
||||
return code;
|
||||
}
|
||||
if (!osTempSpaceAvailable()) {
|
||||
dError("temp disk space unavailable, i.e. %s", tsTempDir);
|
||||
terrno = TSDB_CODE_NO_DISKSPACE;
|
||||
ret = false;
|
||||
code = TSDB_CODE_NO_DISKSPACE;
|
||||
return code;
|
||||
}
|
||||
return ret;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tfsOpenWrapper(SDiskCfg *pCfg, int32_t ndisk, STfs **tfs) {
|
||||
*tfs = tfsOpen(pCfg, ndisk);
|
||||
if (*tfs == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int32_t dmDiskInit() {
|
||||
SDnode *pDnode = dmInstance();
|
||||
SDiskCfg dCfg = {.level = 0, .primary = 1, .disable = 0};
|
||||
|
@ -120,10 +127,10 @@ int32_t dmDiskInit() {
|
|||
numOfDisks = 1;
|
||||
}
|
||||
|
||||
pDnode->pTfs = tfsOpen(pDisks, numOfDisks);
|
||||
if (pDnode->pTfs == NULL) {
|
||||
dError("failed to init tfs since %s", terrstr());
|
||||
return -1;
|
||||
int32_t code = tfsOpenWrapper(pDisks, numOfDisks, &pDnode->pTfs);
|
||||
if (code != 0) {
|
||||
dError("failed to init tfs since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -146,6 +153,12 @@ static bool dmCheckDataDirVersion() {
|
|||
return true;
|
||||
}
|
||||
|
||||
static int32_t dmCheckDataDirVersionWrapper() {
|
||||
if (!dmCheckDataDirVersion()) {
|
||||
return TSDB_CODE_INVALID_DATA_FMT;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#if defined(USE_S3)
|
||||
|
||||
extern int32_t s3Begin();
|
||||
|
@ -156,17 +169,21 @@ extern int8_t tsS3Enabled;
|
|||
|
||||
int32_t dmInit() {
|
||||
dInfo("start to init dnode env");
|
||||
if (dmDiskInit() != 0) return -1;
|
||||
if (!dmCheckDataDirVersion()) return -1;
|
||||
if (!dmCheckDiskSpace()) return -1;
|
||||
if (dmCheckRepeatInit(dmInstance()) != 0) return -1;
|
||||
if (dmInitSystem() != 0) return -1;
|
||||
if (dmInitMonitor() != 0) return -1;
|
||||
if (dmInitAudit() != 0) return -1;
|
||||
if (dmInitDnode(dmInstance()) != 0) return -1;
|
||||
if (InitRegexCache() != 0) return -1;
|
||||
int32_t code = 0;
|
||||
if ((code = dmDiskInit()) != 0) return code;
|
||||
if (!dmCheckDataDirVersion()) {
|
||||
code = TSDB_CODE_INVALID_DATA_FMT;
|
||||
return code;
|
||||
}
|
||||
if ((code = dmCheckDiskSpace()) != 0) return code;
|
||||
if ((code = dmCheckRepeatInit(dmInstance())) != 0) return code;
|
||||
if ((code = dmInitSystem()) != 0) return code;
|
||||
if ((code = dmInitMonitor()) != 0) return code;
|
||||
if ((code = dmInitAudit()) != 0) return code;
|
||||
if ((code = dmInitDnode(dmInstance())) != 0) return code;
|
||||
if ((code = InitRegexCache() != 0)) return code;
|
||||
#if defined(USE_S3)
|
||||
if (s3Begin() != 0) return -1;
|
||||
if ((code = s3Begin()) != 0) return code;
|
||||
#endif
|
||||
|
||||
dInfo("dnode env is initialized");
|
||||
|
@ -217,6 +234,7 @@ int32_t dmRun() {
|
|||
}
|
||||
|
||||
static int32_t dmProcessCreateNodeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
SDnode *pDnode = dmInstance();
|
||||
|
||||
SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, ntype);
|
||||
|
@ -224,19 +242,19 @@ static int32_t dmProcessCreateNodeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
|||
dmReleaseWrapper(pWrapper);
|
||||
switch (ntype) {
|
||||
case MNODE:
|
||||
terrno = TSDB_CODE_MNODE_ALREADY_DEPLOYED;
|
||||
code = TSDB_CODE_MNODE_ALREADY_DEPLOYED;
|
||||
break;
|
||||
case QNODE:
|
||||
terrno = TSDB_CODE_QNODE_ALREADY_DEPLOYED;
|
||||
code = TSDB_CODE_QNODE_ALREADY_DEPLOYED;
|
||||
break;
|
||||
case SNODE:
|
||||
terrno = TSDB_CODE_SNODE_ALREADY_DEPLOYED;
|
||||
code = TSDB_CODE_SNODE_ALREADY_DEPLOYED;
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_APP_ERROR;
|
||||
code = TSDB_CODE_APP_ERROR;
|
||||
}
|
||||
dError("failed to create node since %s", terrstr());
|
||||
return -1;
|
||||
dError("failed to create node since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
dInfo("start to process create-node-request");
|
||||
|
@ -244,18 +262,18 @@ static int32_t dmProcessCreateNodeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
|||
pWrapper = &pDnode->wrappers[ntype];
|
||||
if (taosMkDir(pWrapper->path) != 0) {
|
||||
dmReleaseWrapper(pWrapper);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to create dir:%s since %s", pWrapper->path, terrstr());
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to create dir:%s since %s", pWrapper->path, tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
taosThreadMutexLock(&pDnode->mutex);
|
||||
SMgmtInputOpt input = dmBuildMgmtInputOpt(pWrapper);
|
||||
|
||||
dInfo("node:%s, start to create", pWrapper->name);
|
||||
int32_t code = (*pWrapper->func.createFp)(&input, pMsg);
|
||||
code = (*pWrapper->func.createFp)(&input, pMsg);
|
||||
if (code != 0) {
|
||||
dError("node:%s, failed to create since %s", pWrapper->name, terrstr());
|
||||
dError("node:%s, failed to create since %s", pWrapper->name, tstrerror(code));
|
||||
} else {
|
||||
dInfo("node:%s, has been created", pWrapper->name);
|
||||
code = dmOpenNode(pWrapper);
|
||||
|
@ -271,12 +289,13 @@ static int32_t dmProcessCreateNodeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
static int32_t dmProcessAlterNodeTypeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
SDnode *pDnode = dmInstance();
|
||||
|
||||
SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, ntype);
|
||||
if (pWrapper == NULL) {
|
||||
dError("fail to process alter node type since node not exist");
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
dmReleaseWrapper(pWrapper);
|
||||
|
||||
|
@ -289,16 +308,16 @@ static int32_t dmProcessAlterNodeTypeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
|||
dInfo("node:%s, checking node role:%d", pWrapper->name, role);
|
||||
if (role == TAOS_SYNC_ROLE_VOTER) {
|
||||
dError("node:%s, failed to alter node type since node already is role:%d", pWrapper->name, role);
|
||||
terrno = TSDB_CODE_MNODE_ALREADY_IS_VOTER;
|
||||
return -1;
|
||||
code = TSDB_CODE_MNODE_ALREADY_IS_VOTER;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
if (pWrapper->func.isCatchUpFp != NULL) {
|
||||
dInfo("node:%s, checking node catch up", pWrapper->name);
|
||||
if ((*pWrapper->func.isCatchUpFp)(pWrapper->pMgmt) != 1) {
|
||||
terrno = TSDB_CODE_MNODE_NOT_CATCH_UP;
|
||||
return -1;
|
||||
code = TSDB_CODE_MNODE_NOT_CATCH_UP;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -314,17 +333,17 @@ static int32_t dmProcessAlterNodeTypeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
|||
pWrapper = &pDnode->wrappers[ntype];
|
||||
if (taosMkDir(pWrapper->path) != 0) {
|
||||
taosThreadMutexUnlock(&pDnode->mutex);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to create dir:%s since %s", pWrapper->path, terrstr());
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to create dir:%s since %s", pWrapper->path, tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
SMgmtInputOpt input = dmBuildMgmtInputOpt(pWrapper);
|
||||
|
||||
dInfo("node:%s, start to create", pWrapper->name);
|
||||
int32_t code = (*pWrapper->func.createFp)(&input, pMsg);
|
||||
code = (*pWrapper->func.createFp)(&input, pMsg);
|
||||
if (code != 0) {
|
||||
dError("node:%s, failed to create since %s", pWrapper->name, terrstr());
|
||||
dError("node:%s, failed to create since %s", pWrapper->name, tstrerror(code));
|
||||
} else {
|
||||
dInfo("node:%s, has been created", pWrapper->name);
|
||||
code = dmOpenNode(pWrapper);
|
||||
|
@ -340,35 +359,36 @@ static int32_t dmProcessAlterNodeTypeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
static int32_t dmProcessDropNodeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
SDnode *pDnode = dmInstance();
|
||||
|
||||
SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, ntype);
|
||||
if (pWrapper == NULL) {
|
||||
switch (ntype) {
|
||||
case MNODE:
|
||||
terrno = TSDB_CODE_MNODE_NOT_DEPLOYED;
|
||||
code = TSDB_CODE_MNODE_NOT_DEPLOYED;
|
||||
break;
|
||||
case QNODE:
|
||||
terrno = TSDB_CODE_QNODE_NOT_DEPLOYED;
|
||||
code = TSDB_CODE_QNODE_NOT_DEPLOYED;
|
||||
break;
|
||||
case SNODE:
|
||||
terrno = TSDB_CODE_SNODE_NOT_DEPLOYED;
|
||||
code = TSDB_CODE_SNODE_NOT_DEPLOYED;
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_APP_ERROR;
|
||||
code = TSDB_CODE_APP_ERROR;
|
||||
}
|
||||
|
||||
dError("failed to drop node since %s", terrstr());
|
||||
return -1;
|
||||
dError("failed to drop node since %s", tstrerror(code));
|
||||
return terrno = code;
|
||||
}
|
||||
|
||||
taosThreadMutexLock(&pDnode->mutex);
|
||||
SMgmtInputOpt input = dmBuildMgmtInputOpt(pWrapper);
|
||||
|
||||
dInfo("node:%s, start to drop", pWrapper->name);
|
||||
int32_t code = (*pWrapper->func.dropFp)(&input, pMsg);
|
||||
code = (*pWrapper->func.dropFp)(&input, pMsg);
|
||||
if (code != 0) {
|
||||
dError("node:%s, failed to drop since %s", pWrapper->name, terrstr());
|
||||
dError("node:%s, failed to drop since %s", pWrapper->name, tstrerror(code));
|
||||
} else {
|
||||
dInfo("node:%s, has been dropped", pWrapper->name);
|
||||
pWrapper->required = false;
|
||||
|
@ -416,6 +436,4 @@ void dmReportStartup(const char *pName, const char *pDesc) {
|
|||
|
||||
int64_t dmGetClusterId() { return globalDnode.data.clusterId; }
|
||||
|
||||
bool dmReadyForTest() {
|
||||
return dmInstance()->data.dnodeVer > 0;
|
||||
}
|
||||
bool dmReadyForTest() { return dmInstance()->data.dnodeVer > 0; }
|
||||
|
|
|
@ -42,7 +42,7 @@ int32_t dmInitDnode(SDnode *pDnode) {
|
|||
int32_t code = -1;
|
||||
char path[PATH_MAX + 100] = {0};
|
||||
|
||||
if (dmInitVars(pDnode) != 0) {
|
||||
if ((code = dmInitVarsWrapper(pDnode)) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -65,26 +65,31 @@ int32_t dmInitDnode(SDnode *pDnode) {
|
|||
snprintf(path, sizeof(path), "%s%s%s", tsDataDir, TD_DIRSEP, pWrapper->name);
|
||||
pWrapper->path = taosStrdup(path);
|
||||
if (pWrapper->path == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pWrapper->required = dmRequireNode(pDnode, pWrapper);
|
||||
}
|
||||
|
||||
pDnode->lockfile = dmCheckRunning(tsDataDir);
|
||||
if (pDnode->lockfile == NULL) {
|
||||
code = dmCheckRunning(tsDataDir, &pDnode->lockfile);
|
||||
if (code != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
if (dmInitModule(pDnode) != 0) {
|
||||
|
||||
if ((code = dmInitModule(pDnode)) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
indexInit(tsNumOfCommitThreads);
|
||||
streamMetaInit();
|
||||
|
||||
dmInitStatusClient(pDnode);
|
||||
dmInitSyncClient(pDnode);
|
||||
if ((code = dmInitStatusClient(pDnode)) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
if ((code = dmInitSyncClient(pDnode)) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
dmReportStartup("dnode-transport", "initialized");
|
||||
dDebug("dnode is created, ptr:%p", pDnode);
|
||||
|
@ -94,7 +99,7 @@ _OVER:
|
|||
if (code != 0 && pDnode != NULL) {
|
||||
dmClearVars(pDnode);
|
||||
pDnode = NULL;
|
||||
dError("failed to create dnode since %s", terrstr());
|
||||
dError("failed to create dnode since %s", tstrerror(code));
|
||||
}
|
||||
|
||||
return code;
|
||||
|
@ -122,7 +127,15 @@ void dmCleanupDnode(SDnode *pDnode) {
|
|||
dDebug("dnode is closed, ptr:%p", pDnode);
|
||||
}
|
||||
|
||||
int32_t dmInitVarsWrapper(SDnode *pDnode) {
|
||||
int32_t code = dmInitVars(pDnode);
|
||||
if (code == -1) {
|
||||
return terrno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int32_t dmInitVars(SDnode *pDnode) {
|
||||
int32_t code = 0;
|
||||
SDnodeData *pData = &pDnode->data;
|
||||
pData->dnodeId = 0;
|
||||
pData->clusterId = 0;
|
||||
|
@ -138,21 +151,21 @@ int32_t dmInitVars(SDnode *pDnode) {
|
|||
taosMemoryFreeClear(machineId);
|
||||
} else {
|
||||
#if defined(TD_ENTERPRISE) && !defined(GRANTS_CFG)
|
||||
terrno = TSDB_CODE_DNODE_NO_MACHINE_CODE;
|
||||
return -1;
|
||||
code = TSDB_CODE_DNODE_NO_MACHINE_CODE;
|
||||
return terrno = code;
|
||||
#endif
|
||||
}
|
||||
|
||||
pData->dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
|
||||
if (pData->dnodeHash == NULL) {
|
||||
dError("failed to init dnode hash");
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno = code;
|
||||
}
|
||||
|
||||
if (dmReadEps(pData) != 0) {
|
||||
dError("failed to read file since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = dmReadEps(pData)) != 0) {
|
||||
dError("failed to read file since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
#if defined(TD_ENTERPRISE)
|
||||
|
@ -274,22 +287,21 @@ int32_t dmMarkWrapper(SMgmtWrapper *pWrapper) {
|
|||
} else {
|
||||
switch (pWrapper->ntype) {
|
||||
case MNODE:
|
||||
terrno = TSDB_CODE_MNODE_NOT_FOUND;
|
||||
code = TSDB_CODE_MNODE_NOT_FOUND;
|
||||
break;
|
||||
case QNODE:
|
||||
terrno = TSDB_CODE_QNODE_NOT_FOUND;
|
||||
code = TSDB_CODE_QNODE_NOT_FOUND;
|
||||
break;
|
||||
case SNODE:
|
||||
terrno = TSDB_CODE_SNODE_NOT_FOUND;
|
||||
code = TSDB_CODE_SNODE_NOT_FOUND;
|
||||
break;
|
||||
case VNODE:
|
||||
terrno = TSDB_CODE_VND_STOPPED;
|
||||
code = TSDB_CODE_VND_STOPPED;
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_APP_IS_STOPPING;
|
||||
code = TSDB_CODE_APP_IS_STOPPING;
|
||||
break;
|
||||
}
|
||||
code = -1;
|
||||
}
|
||||
taosThreadRwlockUnlock(&pWrapper->lock);
|
||||
|
||||
|
|
|
@ -17,12 +17,13 @@
|
|||
#include "dmMgmt.h"
|
||||
|
||||
int32_t dmOpenNode(SMgmtWrapper *pWrapper) {
|
||||
int32_t code = 0;
|
||||
SDnode *pDnode = pWrapper->pDnode;
|
||||
|
||||
if (taosMkDir(pWrapper->path) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("node:%s, failed to create dir:%s since %s", pWrapper->name, pWrapper->path, terrstr());
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("node:%s, failed to create dir:%s since %s", pWrapper->name, pWrapper->path, tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
SMgmtOutputOpt output = {0};
|
||||
|
@ -30,9 +31,9 @@ int32_t dmOpenNode(SMgmtWrapper *pWrapper) {
|
|||
|
||||
dInfo("node:%s, start to open", pWrapper->name);
|
||||
tmsgSetDefault(&input.msgCb);
|
||||
if ((*pWrapper->func.openFp)(&input, &output) != 0) {
|
||||
dError("node:%s, failed to open since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
if ((code = (*pWrapper->func.openFp)(&input, &output)) != 0) {
|
||||
dError("node:%s, failed to open since %s", pWrapper->name, tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
dInfo("node:%s, has been opened", pWrapper->name);
|
||||
pWrapper->deployed = true;
|
||||
|
@ -46,11 +47,12 @@ int32_t dmOpenNode(SMgmtWrapper *pWrapper) {
|
|||
}
|
||||
|
||||
int32_t dmStartNode(SMgmtWrapper *pWrapper) {
|
||||
int32_t code = 0;
|
||||
if (pWrapper->func.startFp != NULL) {
|
||||
dDebug("node:%s, start to start", pWrapper->name);
|
||||
if ((*pWrapper->func.startFp)(pWrapper->pMgmt) != 0) {
|
||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
if ((code = (*pWrapper->func.startFp)(pWrapper->pMgmt)) != 0) {
|
||||
dError("node:%s, failed to start since %s", pWrapper->name, tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
dDebug("node:%s, has been started", pWrapper->name);
|
||||
}
|
||||
|
@ -86,12 +88,13 @@ void dmCloseNode(SMgmtWrapper *pWrapper) {
|
|||
}
|
||||
|
||||
static int32_t dmOpenNodes(SDnode *pDnode) {
|
||||
int32_t code = 0;
|
||||
for (EDndNodeType ntype = DNODE; ntype < NODE_END; ++ntype) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype];
|
||||
if (!pWrapper->required) continue;
|
||||
if (dmOpenNode(pWrapper) != 0) {
|
||||
dError("node:%s, failed to open since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
if ((code = dmOpenNode(pWrapper)) != 0) {
|
||||
dError("node:%s, failed to open since %s", pWrapper->name, tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,12 +103,13 @@ static int32_t dmOpenNodes(SDnode *pDnode) {
|
|||
}
|
||||
|
||||
static int32_t dmStartNodes(SDnode *pDnode) {
|
||||
int32_t code = 0;
|
||||
for (EDndNodeType ntype = DNODE; ntype < NODE_END; ++ntype) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype];
|
||||
if (!pWrapper->required) continue;
|
||||
if (dmStartNode(pWrapper) != 0) {
|
||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
if ((code = dmStartNode(pWrapper)) != 0) {
|
||||
dError("node:%s, failed to start since %s", pWrapper->name, tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,19 +133,20 @@ static void dmCloseNodes(SDnode *pDnode) {
|
|||
}
|
||||
|
||||
int32_t dmRunDnode(SDnode *pDnode) {
|
||||
int32_t code = 0;
|
||||
int32_t count = 0;
|
||||
if (dmOpenNodes(pDnode) != 0) {
|
||||
dError("failed to open nodes since %s", terrstr());
|
||||
if ((code = dmOpenNodes(pDnode)) != 0) {
|
||||
dError("failed to open nodes since %s", tstrerror(code));
|
||||
dmCloseNodes(pDnode);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (dmStartNodes(pDnode) != 0) {
|
||||
dError("failed to start nodes since %s", terrstr());
|
||||
if ((code = dmStartNodes(pDnode)) != 0) {
|
||||
dError("failed to start nodes since %s", tstrerror(code));
|
||||
dmSetStatus(pDnode, DND_STAT_STOPPED);
|
||||
dmStopNodes(pDnode);
|
||||
dmCloseNodes(pDnode);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
|
|
|
@ -39,9 +39,9 @@ int32_t dmProcessNodeMsg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg) {
|
|||
|
||||
NodeMsgFp msgFp = pWrapper->msgFps[TMSG_INDEX(pMsg->msgType)];
|
||||
if (msgFp == NULL) {
|
||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
// terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
dGError("msg:%p, not processed since no handler, type:%s", pMsg, TMSG_INFO(pMsg->msgType));
|
||||
return -1;
|
||||
return TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
}
|
||||
|
||||
dGTrace("msg:%p, will be processed by %s", pMsg, pWrapper->name);
|
||||
|
@ -54,14 +54,15 @@ static bool dmFailFastFp(tmsg_t msgType) {
|
|||
return msgType == TDMT_SYNC_HEARTBEAT || msgType == TDMT_SYNC_APPEND_ENTRIES;
|
||||
}
|
||||
|
||||
static void dmConvertErrCode(tmsg_t msgType) {
|
||||
if (terrno != TSDB_CODE_APP_IS_STOPPING) {
|
||||
return;
|
||||
static int32_t dmConvertErrCode(tmsg_t msgType, int32_t code) {
|
||||
if (code != TSDB_CODE_APP_IS_STOPPING) {
|
||||
return code;
|
||||
}
|
||||
if ((msgType > TDMT_VND_MSG_MIN && msgType < TDMT_VND_MSG_MAX) ||
|
||||
(msgType > TDMT_SCH_MSG_MIN && msgType < TDMT_SCH_MSG_MAX)) {
|
||||
terrno = TSDB_CODE_VND_STOPPED;
|
||||
code = TSDB_CODE_VND_STOPPED;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
static void dmUpdateRpcIpWhite(SDnodeData *pData, void *pTrans, SRpcMsg *pRpc) {
|
||||
SUpdateIpWhite ipWhite = {0}; // aosMemoryCalloc(1, sizeof(SUpdateIpWhite));
|
||||
|
@ -99,14 +100,14 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
|||
|
||||
int32_t svrVer = 0;
|
||||
taosVersionStrToInt(version, &svrVer);
|
||||
if (0 != taosCheckVersionCompatible(pRpc->info.cliVer, svrVer, 3)) {
|
||||
if ((code = taosCheckVersionCompatible(pRpc->info.cliVer, svrVer, 3)) != 0) {
|
||||
dError("Version not compatible, cli ver: %d, svr ver: %d", pRpc->info.cliVer, svrVer);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
bool isForbidden = dmIsForbiddenIp(pRpc->info.forbiddenIp, pRpc->info.conn.user, pRpc->info.conn.clientIp);
|
||||
if (isForbidden) {
|
||||
terrno = TSDB_CODE_IP_NOT_IN_WHITE_LIST;
|
||||
code = TSDB_CODE_IP_NOT_IN_WHITE_LIST;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -119,7 +120,7 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
|||
case TDMT_SCH_FETCH_RSP:
|
||||
case TDMT_SCH_MERGE_FETCH_RSP:
|
||||
case TDMT_VND_SUBMIT_RSP:
|
||||
qWorkerProcessRspMsg(NULL, NULL, pRpc, 0);
|
||||
code = qWorkerProcessRspMsg(NULL, NULL, pRpc, 0);
|
||||
return;
|
||||
case TDMT_MND_STATUS_RSP:
|
||||
if (pEpSet != NULL) {
|
||||
|
@ -148,32 +149,32 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
|||
return;
|
||||
} else {
|
||||
if (pDnode->status == DND_STAT_INIT) {
|
||||
terrno = TSDB_CODE_APP_IS_STARTING;
|
||||
code = TSDB_CODE_APP_IS_STARTING;
|
||||
} else {
|
||||
terrno = TSDB_CODE_APP_IS_STOPPING;
|
||||
code = TSDB_CODE_APP_IS_STOPPING;
|
||||
}
|
||||
goto _OVER;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
terrno = TSDB_CODE_APP_IS_STARTING;
|
||||
code = TSDB_CODE_APP_IS_STARTING;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (pRpc->pCont == NULL && (IsReq(pRpc) || pRpc->contLen != 0)) {
|
||||
dGError("msg:%p, type:%s pCont is NULL", pRpc, TMSG_INFO(pRpc->msgType));
|
||||
terrno = TSDB_CODE_INVALID_MSG_LEN;
|
||||
code = TSDB_CODE_INVALID_MSG_LEN;
|
||||
goto _OVER;
|
||||
} else if ((pRpc->code == TSDB_CODE_RPC_NETWORK_UNAVAIL || pRpc->code == TSDB_CODE_RPC_BROKEN_LINK) &&
|
||||
(!IsReq(pRpc)) && (pRpc->pCont == NULL)) {
|
||||
dGError("msg:%p, type:%s pCont is NULL, err: %s", pRpc, TMSG_INFO(pRpc->msgType), tstrerror(pRpc->code));
|
||||
terrno = pRpc->code;
|
||||
code = pRpc->code;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (pHandle->defaultNtype == NODE_END) {
|
||||
dGError("msg:%p, type:%s not processed since no handle", pRpc, TMSG_INFO(pRpc->msgType));
|
||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
code = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -197,12 +198,12 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
|||
}
|
||||
} else {
|
||||
dGError("msg:%p, type:%s contLen is 0", pRpc, TMSG_INFO(pRpc->msgType));
|
||||
terrno = TSDB_CODE_INVALID_MSG_LEN;
|
||||
code = TSDB_CODE_INVALID_MSG_LEN;
|
||||
goto _OVER;
|
||||
}
|
||||
}
|
||||
|
||||
if (dmMarkWrapper(pWrapper) != 0) {
|
||||
if ((code = dmMarkWrapper(pWrapper)) != 0) {
|
||||
pWrapper = NULL;
|
||||
goto _OVER;
|
||||
}
|
||||
|
@ -221,12 +222,11 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
|||
|
||||
_OVER:
|
||||
if (code != 0) {
|
||||
dmConvertErrCode(pRpc->msgType);
|
||||
if (terrno != 0) code = terrno;
|
||||
code = dmConvertErrCode(pRpc->msgType, code);
|
||||
if (pMsg) {
|
||||
dGTrace("msg:%p, failed to process %s since %s", pMsg, TMSG_INFO(pMsg->msgType), terrstr());
|
||||
dGTrace("msg:%p, failed to process %s since %s", pMsg, TMSG_INFO(pMsg->msgType), tstrerror(code));
|
||||
} else {
|
||||
dGTrace("msg:%p, failed to process empty msg since %s", pMsg, terrstr());
|
||||
dGTrace("msg:%p, failed to process empty msg since %s", pMsg, tstrerror(code));
|
||||
}
|
||||
|
||||
if (IsReq(pRpc)) {
|
||||
|
@ -280,17 +280,19 @@ int32_t dmInitMsgHandle(SDnode *pDnode) {
|
|||
}
|
||||
|
||||
static inline int32_t dmSendReq(const SEpSet *pEpSet, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
SDnode *pDnode = dmInstance();
|
||||
if (pDnode->status != DND_STAT_RUNNING && pMsg->msgType < TDMT_SYNC_MSG_MIN) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
pMsg->pCont = NULL;
|
||||
if (pDnode->status == DND_STAT_INIT) {
|
||||
terrno = TSDB_CODE_APP_IS_STARTING;
|
||||
code = TSDB_CODE_APP_IS_STARTING;
|
||||
} else {
|
||||
terrno = TSDB_CODE_APP_IS_STOPPING;
|
||||
code = TSDB_CODE_APP_IS_STOPPING;
|
||||
}
|
||||
dError("failed to send rpc msg:%s since %s, handle:%p", TMSG_INFO(pMsg->msgType), terrstr(), pMsg->info.handle);
|
||||
return -1;
|
||||
dError("failed to send rpc msg:%s since %s, handle:%p", TMSG_INFO(pMsg->msgType), tstrerror(code),
|
||||
pMsg->info.handle);
|
||||
return code;
|
||||
} else {
|
||||
pMsg->info.handle = 0;
|
||||
rpcSendRequest(pDnode->trans.clientRpc, pEpSet, pMsg, NULL);
|
||||
|
@ -298,17 +300,19 @@ static inline int32_t dmSendReq(const SEpSet *pEpSet, SRpcMsg *pMsg) {
|
|||
}
|
||||
}
|
||||
static inline int32_t dmSendSyncReq(const SEpSet *pEpSet, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
SDnode *pDnode = dmInstance();
|
||||
if (pDnode->status != DND_STAT_RUNNING && pMsg->msgType < TDMT_SYNC_MSG_MIN) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
pMsg->pCont = NULL;
|
||||
if (pDnode->status == DND_STAT_INIT) {
|
||||
terrno = TSDB_CODE_APP_IS_STARTING;
|
||||
code = TSDB_CODE_APP_IS_STARTING;
|
||||
} else {
|
||||
terrno = TSDB_CODE_APP_IS_STOPPING;
|
||||
code = TSDB_CODE_APP_IS_STOPPING;
|
||||
}
|
||||
dError("failed to send rpc msg:%s since %s, handle:%p", TMSG_INFO(pMsg->msgType), terrstr(), pMsg->info.handle);
|
||||
return -1;
|
||||
dError("failed to send rpc msg:%s since %s, handle:%p", TMSG_INFO(pMsg->msgType), tstrerror(code),
|
||||
pMsg->info.handle);
|
||||
return code;
|
||||
} else {
|
||||
rpcSendRequest(pDnode->trans.syncRpc, pEpSet, pMsg, NULL);
|
||||
return 0;
|
||||
|
@ -426,7 +430,7 @@ int32_t dmInitStatusClient(SDnode *pDnode) {
|
|||
pTrans->statusRpc = rpcOpen(&rpcInit);
|
||||
if (pTrans->statusRpc == NULL) {
|
||||
dError("failed to init dnode rpc status client");
|
||||
return -1;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
dDebug("dnode rpc status client is initialized");
|
||||
|
@ -471,7 +475,7 @@ int32_t dmInitSyncClient(SDnode *pDnode) {
|
|||
pTrans->syncRpc = rpcOpen(&rpcInit);
|
||||
if (pTrans->syncRpc == NULL) {
|
||||
dError("failed to init dnode rpc sync client");
|
||||
return -1;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
dDebug("dnode rpc sync client is initialized");
|
||||
|
@ -521,7 +525,7 @@ int32_t dmInitServer(SDnode *pDnode) {
|
|||
pTrans->serverRpc = rpcOpen(&rpcInit);
|
||||
if (pTrans->serverRpc == NULL) {
|
||||
dError("failed to init dnode rpc server");
|
||||
return -1;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
dDebug("dnode rpc server is initialized");
|
||||
|
|
|
@ -145,20 +145,20 @@ typedef struct {
|
|||
} SDnodeData;
|
||||
|
||||
typedef struct {
|
||||
const char *path;
|
||||
const char *name;
|
||||
STfs *pTfs;
|
||||
SDnodeData *pData;
|
||||
SMsgCb msgCb;
|
||||
ProcessCreateNodeFp processCreateNodeFp;
|
||||
const char *path;
|
||||
const char *name;
|
||||
STfs *pTfs;
|
||||
SDnodeData *pData;
|
||||
SMsgCb msgCb;
|
||||
ProcessCreateNodeFp processCreateNodeFp;
|
||||
ProcessAlterNodeTypeFp processAlterNodeTypeFp;
|
||||
ProcessDropNodeFp processDropNodeFp;
|
||||
SendMonitorReportFp sendMonitorReportFp;
|
||||
SendAuditRecordsFp sendAuditRecordFp;
|
||||
GetVnodeLoadsFp getVnodeLoadsFp;
|
||||
GetVnodeLoadsFp getVnodeLoadsLiteFp;
|
||||
GetMnodeLoadsFp getMnodeLoadsFp;
|
||||
GetQnodeLoadsFp getQnodeLoadsFp;
|
||||
ProcessDropNodeFp processDropNodeFp;
|
||||
SendMonitorReportFp sendMonitorReportFp;
|
||||
SendAuditRecordsFp sendAuditRecordFp;
|
||||
GetVnodeLoadsFp getVnodeLoadsFp;
|
||||
GetVnodeLoadsFp getVnodeLoadsLiteFp;
|
||||
GetMnodeLoadsFp getMnodeLoadsFp;
|
||||
GetQnodeLoadsFp getQnodeLoadsFp;
|
||||
} SMgmtInputOpt;
|
||||
|
||||
typedef struct {
|
||||
|
@ -203,9 +203,10 @@ void *dmSetMgmtHandle(SArray *pArray, tmsg_t msgType, void *nodeMsgFp, boo
|
|||
void dmGetMonitorSystemInfo(SMonSysInfo *pInfo);
|
||||
|
||||
// dmFile.c
|
||||
int32_t dmReadFile(const char *path, const char *name, bool *pDeployed);
|
||||
int32_t dmWriteFile(const char *path, const char *name, bool deployed);
|
||||
TdFilePtr dmCheckRunning(const char *dataDir);
|
||||
int32_t dmReadFile(const char *path, const char *name, bool *pDeployed);
|
||||
int32_t dmWriteFile(const char *path, const char *name, bool deployed);
|
||||
int32_t dmCheckRunning(const char *dataDir, TdFilePtr *pFile);
|
||||
//int32_t dmCheckRunningWrapper(const char *dataDir, TdFilePtr *pFile);
|
||||
|
||||
// dmodule.c
|
||||
int32_t dmInitDndInfo(SDnodeData *pData);
|
||||
|
|
|
@ -95,18 +95,18 @@ static int32_t dmDecodeEps(SJson *pJson, SDnodeData *pData) {
|
|||
}
|
||||
|
||||
int dmOccurrences(char *str, char *toSearch) {
|
||||
int count = 0;
|
||||
char *ptr = str;
|
||||
while ((ptr = strstr(ptr, toSearch)) != NULL) {
|
||||
count++;
|
||||
ptr++;
|
||||
}
|
||||
return count;
|
||||
int count = 0;
|
||||
char *ptr = str;
|
||||
while ((ptr = strstr(ptr, toSearch)) != NULL) {
|
||||
count++;
|
||||
ptr++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void dmSplitStr(char** arr, char* str, const char* del) {
|
||||
void dmSplitStr(char **arr, char *str, const char *del) {
|
||||
char *lasts;
|
||||
char* s = strsep(&str, del);
|
||||
char *s = strsep(&str, del);
|
||||
while (s != NULL) {
|
||||
*arr++ = s;
|
||||
s = strsep(&str, del);
|
||||
|
@ -132,11 +132,10 @@ int32_t dmReadEps(SDnodeData *pData) {
|
|||
dInfo("dnode file:%s not exist", file);
|
||||
|
||||
#ifdef TD_ENTERPRISE
|
||||
if(strlen(tsEncryptAlgorithm) > 0){
|
||||
if(strcmp(tsEncryptAlgorithm, "sm4") == 0) {
|
||||
if (strlen(tsEncryptAlgorithm) > 0) {
|
||||
if (strcmp(tsEncryptAlgorithm, "sm4") == 0) {
|
||||
pData->encryptAlgorigthm = DND_CA_SM4;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
terrno = TSDB_CODE_DNODE_INVALID_ENCRYPT_CONFIG;
|
||||
dError("invalid tsEncryptAlgorithm:%s", tsEncryptAlgorithm);
|
||||
goto _OVER;
|
||||
|
@ -144,45 +143,45 @@ int32_t dmReadEps(SDnodeData *pData) {
|
|||
|
||||
dInfo("start to parse encryptScope:%s", tsEncryptScope);
|
||||
int32_t scopeLen = strlen(tsEncryptScope);
|
||||
if(scopeLen == 0){
|
||||
if (scopeLen == 0) {
|
||||
terrno = TSDB_CODE_DNODE_INVALID_ENCRYPT_CONFIG;
|
||||
dError("invalid tsEncryptScope:%s", tsEncryptScope);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
char* tmp = taosMemoryMalloc(scopeLen + 1);
|
||||
char *tmp = taosMemoryMalloc(scopeLen + 1);
|
||||
memset(tmp, 0, scopeLen + 1);
|
||||
memcpy(tmp, tsEncryptScope, scopeLen);
|
||||
|
||||
int32_t count = dmOccurrences(tmp, ",");
|
||||
|
||||
char** array = taosMemoryMalloc(sizeof(char*) * (count + 1));
|
||||
memset(array, 0, sizeof(char*) * (count + 1));
|
||||
char **array = taosMemoryMalloc(sizeof(char *) * (count + 1));
|
||||
memset(array, 0, sizeof(char *) * (count + 1));
|
||||
dmSplitStr(array, tmp, ",");
|
||||
|
||||
for(int32_t i = 0; i < count + 1; i++){
|
||||
char* str = *(array + i);
|
||||
for (int32_t i = 0; i < count + 1; i++) {
|
||||
char *str = *(array + i);
|
||||
|
||||
bool success = false;
|
||||
|
||||
if(strcasecmp(str, "tsdb") == 0 || strcasecmp(str, "all") == 0){
|
||||
if (strcasecmp(str, "tsdb") == 0 || strcasecmp(str, "all") == 0) {
|
||||
pData->encryptScope |= DND_CS_TSDB;
|
||||
success = true;
|
||||
}
|
||||
if(strcasecmp(str, "vnode_wal") == 0 || strcasecmp(str, "all") == 0){
|
||||
if (strcasecmp(str, "vnode_wal") == 0 || strcasecmp(str, "all") == 0) {
|
||||
pData->encryptScope |= DND_CS_VNODE_WAL;
|
||||
success = true;
|
||||
}
|
||||
if(strcasecmp(str, "sdb") == 0 || strcasecmp(str, "all") == 0){
|
||||
if (strcasecmp(str, "sdb") == 0 || strcasecmp(str, "all") == 0) {
|
||||
pData->encryptScope |= DND_CS_SDB;
|
||||
success = true;
|
||||
}
|
||||
if(strcasecmp(str, "mnode_wal") == 0 || strcasecmp(str, "all") == 0){
|
||||
if (strcasecmp(str, "mnode_wal") == 0 || strcasecmp(str, "all") == 0) {
|
||||
pData->encryptScope |= DND_CS_MNODE_WAL;
|
||||
success = true;
|
||||
}
|
||||
|
||||
if(!success){
|
||||
if (!success) {
|
||||
terrno = TSDB_CODE_DNODE_INVALID_ENCRYPT_CONFIG;
|
||||
taosMemoryFree(tmp);
|
||||
taosMemoryFree(array);
|
||||
|
@ -196,7 +195,7 @@ int32_t dmReadEps(SDnodeData *pData) {
|
|||
|
||||
dInfo("set tsCryptAlgorithm:%s, tsCryptScope:%s from cfg", tsEncryptAlgorithm, tsEncryptScope);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
code = 0;
|
||||
goto _OVER;
|
||||
|
@ -204,26 +203,26 @@ int32_t dmReadEps(SDnodeData *pData) {
|
|||
|
||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to open dnode file:%s since %s", file, terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
int64_t size = 0;
|
||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to fstat dnode file:%s since %s", file, terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
content = taosMemoryMalloc(size + 1);
|
||||
if (content == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (taosReadFile(pFile, content, size) != size) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to read dnode file:%s since %s", file, terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
@ -232,12 +231,11 @@ int32_t dmReadEps(SDnodeData *pData) {
|
|||
|
||||
pJson = tjsonParse(content);
|
||||
if (pJson == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (dmDecodeEps(pJson, pData) < 0) {
|
||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
if ((code = dmDecodeEps(pJson, pData)) < 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -251,7 +249,7 @@ _OVER:
|
|||
|
||||
if (code != 0) {
|
||||
dError("failed to read dnode file:%s since %s", file, terrstr());
|
||||
return code;
|
||||
return terrno = code;
|
||||
}
|
||||
|
||||
if (taosArrayGetSize(pData->dnodeEps) == 0) {
|
||||
|
@ -261,8 +259,8 @@ _OVER:
|
|||
taosArrayPush(pData->dnodeEps, &dnodeEp);
|
||||
}
|
||||
|
||||
if (dmReadDnodePairs(pData) != 0) {
|
||||
return -1;
|
||||
if ((code = dmReadDnodePairs(pData)) != 0) {
|
||||
return terrno = code;
|
||||
}
|
||||
|
||||
dDebug("reset dnode list on startup");
|
||||
|
@ -270,8 +268,8 @@ _OVER:
|
|||
|
||||
if (pData->oldDnodeEps == NULL && dmIsEpChanged(pData, pData->dnodeId, tsLocalEp)) {
|
||||
dError("localEp %s different with %s and need to be reconfigured", tsLocalEp, file);
|
||||
terrno = TSDB_CODE_INVALID_CFG;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_CFG;
|
||||
return terrno = code;
|
||||
}
|
||||
|
||||
return code;
|
||||
|
@ -308,7 +306,7 @@ static int32_t dmEncodeEps(SJson *pJson, SDnodeData *pData) {
|
|||
}
|
||||
|
||||
int32_t dmWriteEps(SDnodeData *pData) {
|
||||
int32_t code = -1;
|
||||
int32_t code = 0;
|
||||
char *buffer = NULL;
|
||||
SJson *pJson = NULL;
|
||||
TdFilePtr pFile = NULL;
|
||||
|
@ -317,26 +315,30 @@ int32_t dmWriteEps(SDnodeData *pData) {
|
|||
snprintf(file, sizeof(file), "%s%sdnode%sdnode.json.bak", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
||||
snprintf(realfile, sizeof(realfile), "%s%sdnode%sdnode.json", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
||||
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
// if ((code == dmInitDndInfo(pData)) != 0) goto _OVER;
|
||||
TAOS_CHECK_GOTO(dmInitDndInfo(pData), NULL, _OVER);
|
||||
|
||||
if ((code == dmInitDndInfo(pData)) != 0) goto _OVER;
|
||||
pJson = tjsonCreateObject();
|
||||
if (pJson == NULL) goto _OVER;
|
||||
if (pJson == NULL) TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _OVER);
|
||||
|
||||
pData->engineVer = tsVersion;
|
||||
if (dmEncodeEps(pJson, pData) != 0) goto _OVER;
|
||||
|
||||
TAOS_CHECK_GOTO(dmEncodeEps(pJson, pData), NULL, _OVER); // dmEncodeEps(pJson, pData) != 0) goto _OVER;
|
||||
|
||||
buffer = tjsonToString(pJson);
|
||||
if (buffer == NULL) goto _OVER;
|
||||
terrno = 0;
|
||||
if (buffer == NULL) {
|
||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _OVER);
|
||||
}
|
||||
|
||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||
if (pFile == NULL) goto _OVER;
|
||||
if (pFile == NULL) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER);
|
||||
|
||||
int32_t len = strlen(buffer);
|
||||
if (taosWriteFile(pFile, buffer, len) <= 0) goto _OVER;
|
||||
if (taosFsyncFile(pFile) < 0) goto _OVER;
|
||||
if (taosWriteFile(pFile, buffer, len) <= 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER);
|
||||
if (taosFsyncFile(pFile) < 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER);
|
||||
|
||||
taosCloseFile(&pFile);
|
||||
if (taosRenameFile(file, realfile) != 0) goto _OVER;
|
||||
if (taosRenameFile(file, realfile) != 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER);
|
||||
|
||||
code = 0;
|
||||
pData->updateTime = taosGetTimestampMs();
|
||||
|
@ -349,8 +351,7 @@ _OVER:
|
|||
if (pFile != NULL) taosCloseFile(&pFile);
|
||||
|
||||
if (code != 0) {
|
||||
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to write dnode file:%s since %s, dnodeVer:%" PRId64, realfile, terrstr(), pData->dnodeVer);
|
||||
dError("failed to write dnode file:%s since %s, dnodeVer:%" PRId64, realfile, tstrerror(code), pData->dnodeVer);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -592,28 +593,29 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) {
|
|||
snprintf(file, sizeof(file), "%s%sdnode%sep.json", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
||||
|
||||
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
||||
dDebug("dnode file:%s not exist", file);
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dDebug("dnode file:%s not exist, reason:%s", file, tstrerror(code));
|
||||
code = 0;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to open dnode file:%s since %s", file, terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
int64_t size = 0;
|
||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to fstat dnode file:%s since %s", file, terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
content = taosMemoryMalloc(size + 1);
|
||||
if (content == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -627,12 +629,13 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) {
|
|||
|
||||
pJson = tjsonParse(content);
|
||||
if (pJson == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pData->oldDnodeEps = taosArrayInit(1, sizeof(SDnodeEpPair));
|
||||
if (pData->oldDnodeEps == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
dError("failed to calloc dnodeEp array since %s", strerror(errno));
|
||||
goto _OVER;
|
||||
}
|
||||
|
@ -640,7 +643,8 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) {
|
|||
if (dmDecodeEpPairs(pJson, pData) < 0) {
|
||||
taosArrayDestroy(pData->oldDnodeEps);
|
||||
pData->oldDnodeEps = NULL;
|
||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
|
||||
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -653,7 +657,7 @@ _OVER:
|
|||
if (pFile != NULL) taosCloseFile(&pFile);
|
||||
|
||||
if (code != 0) {
|
||||
dError("failed to read dnode file:%s since %s", file, terrstr());
|
||||
dError("failed to read dnode file:%s since %s", file, tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -680,8 +684,8 @@ _OVER:
|
|||
pair->oldPort, pair->newFqdn, pair->newPort, pDnodeEp->id);
|
||||
taosArrayDestroy(pData->oldDnodeEps);
|
||||
pData->oldDnodeEps = NULL;
|
||||
terrno = TSDB_CODE_INVALID_CFG;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_CFG;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,23 +14,23 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dmUtil.h"
|
||||
#include "tjson.h"
|
||||
#include "tgrant.h"
|
||||
#include "crypt.h"
|
||||
#include "dmUtil.h"
|
||||
#include "tchecksum.h"
|
||||
#include "tgrant.h"
|
||||
#include "tjson.h"
|
||||
|
||||
#define MAXLEN 1024
|
||||
#define DM_KEY_INDICATOR "this indicator!"
|
||||
#define DM_ENCRYPT_CODE_FILE "encryptCode.cfg"
|
||||
#define DM_CHECK_CODE_FILE "checkCode.bin"
|
||||
#define MAXLEN 1024
|
||||
#define DM_KEY_INDICATOR "this indicator!"
|
||||
#define DM_ENCRYPT_CODE_FILE "encryptCode.cfg"
|
||||
#define DM_CHECK_CODE_FILE "checkCode.bin"
|
||||
|
||||
static int32_t dmDecodeFile(SJson *pJson, bool *deployed) {
|
||||
int32_t code = 0;
|
||||
int32_t value = 0;
|
||||
|
||||
tjsonGetInt32ValueFromDouble(pJson, "deployed", value, code);
|
||||
if (code < 0) return -1;
|
||||
if (code < 0) return code;
|
||||
|
||||
*deployed = (value != 0);
|
||||
return code;
|
||||
|
@ -42,7 +42,11 @@ int32_t dmReadFile(const char *path, const char *name, bool *pDeployed) {
|
|||
char *content = NULL;
|
||||
SJson *pJson = NULL;
|
||||
char file[PATH_MAX] = {0};
|
||||
snprintf(file, sizeof(file), "%s%s%s.json", path, TD_DIRSEP, name);
|
||||
int32_t nBytes = snprintf(file, sizeof(file), "%s%s%s.json", path, TD_DIRSEP, name);
|
||||
if (nBytes <= 0 || nBytes >= PATH_MAX) {
|
||||
code = TSDB_CODE_OUT_OF_BUFFER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
||||
dInfo("file:%s not exist", file);
|
||||
|
@ -52,27 +56,27 @@ int32_t dmReadFile(const char *path, const char *name, bool *pDeployed) {
|
|||
|
||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to open file:%s since %s", file, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to open file:%s since %s", file, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
int64_t size = 0;
|
||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to fstat file:%s since %s", file, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to fstat file:%s since %s", file, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
content = taosMemoryMalloc(size + 1);
|
||||
if (content == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (taosReadFile(pFile, content, size) != size) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to read file:%s since %s", file, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to read file:%s since %s", file, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -80,12 +84,12 @@ int32_t dmReadFile(const char *path, const char *name, bool *pDeployed) {
|
|||
|
||||
pJson = tjsonParse(content);
|
||||
if (pJson == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (dmDecodeFile(pJson, pDeployed) < 0) {
|
||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -98,13 +102,13 @@ _OVER:
|
|||
if (pFile != NULL) taosCloseFile(&pFile);
|
||||
|
||||
if (code != 0) {
|
||||
dError("failed to read dnode file:%s since %s", file, terrstr());
|
||||
dError("failed to read dnode file:%s since %s", file, tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t dmEncodeFile(SJson *pJson, bool deployed) {
|
||||
if (tjsonAddDoubleToObject(pJson, "deployed", deployed) < 0) return -1;
|
||||
if (tjsonAddDoubleToObject(pJson, "deployed", deployed) < 0) return TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -115,26 +119,57 @@ int32_t dmWriteFile(const char *path, const char *name, bool deployed) {
|
|||
TdFilePtr pFile = NULL;
|
||||
char file[PATH_MAX] = {0};
|
||||
char realfile[PATH_MAX] = {0};
|
||||
snprintf(file, sizeof(file), "%s%s%s.json", path, TD_DIRSEP, name);
|
||||
snprintf(realfile, sizeof(realfile), "%s%s%s.json", path, TD_DIRSEP, name);
|
||||
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
int32_t nBytes = snprintf(file, sizeof(file), "%s%s%s.json", path, TD_DIRSEP, name);
|
||||
if (nBytes <= 0 || nBytes >= PATH_MAX) {
|
||||
code = TSDB_CODE_OUT_OF_BUFFER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
nBytes = snprintf(realfile, sizeof(realfile), "%s%s%s.json", path, TD_DIRSEP, name);
|
||||
if (nBytes <= 0 || nBytes >= PATH_MAX) {
|
||||
code = TSDB_CODE_OUT_OF_BUFFER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pJson = tjsonCreateObject();
|
||||
if (pJson == NULL) goto _OVER;
|
||||
if (dmEncodeFile(pJson, deployed) != 0) goto _OVER;
|
||||
if (pJson == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if ((code = dmEncodeFile(pJson, deployed)) != 0) goto _OVER;
|
||||
|
||||
buffer = tjsonToString(pJson);
|
||||
if (buffer == NULL) goto _OVER;
|
||||
terrno = 0;
|
||||
if (buffer == NULL) {
|
||||
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||
if (pFile == NULL) goto _OVER;
|
||||
if (pFile == NULL) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
int32_t len = strlen(buffer);
|
||||
if (taosWriteFile(pFile, buffer, len) <= 0) goto _OVER;
|
||||
if (taosFsyncFile(pFile) < 0) goto _OVER;
|
||||
if (taosWriteFile(pFile, buffer, len) <= 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
if (taosFsyncFile(pFile) < 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
taosCloseFile(&pFile);
|
||||
if (taosRenameFile(file, realfile) != 0) goto _OVER;
|
||||
if (taosCloseFile(&pFile) != 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
if (taosRenameFile(file, realfile) != 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
code = 0;
|
||||
dInfo("succeed to write file:%s, deloyed:%d", realfile, deployed);
|
||||
|
@ -145,54 +180,58 @@ _OVER:
|
|||
if (pFile != NULL) taosCloseFile(&pFile);
|
||||
|
||||
if (code != 0) {
|
||||
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to write file:%s since %s, deloyed:%d", realfile, terrstr(), deployed);
|
||||
dError("failed to write file:%s since %s, deloyed:%d", realfile, tstrerror(code), deployed);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
TdFilePtr dmCheckRunning(const char *dataDir) {
|
||||
char filepath[PATH_MAX] = {0};
|
||||
int32_t dmCheckRunning(const char *dataDir, TdFilePtr *pFile) {
|
||||
int32_t code = 0;
|
||||
char filepath[PATH_MAX] = {0};
|
||||
snprintf(filepath, sizeof(filepath), "%s%s.running", dataDir, TD_DIRSEP);
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_CLOEXEC);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to open file:%s since %s", filepath, terrstr());
|
||||
return NULL;
|
||||
*pFile = taosOpenFile(filepath, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_CLOEXEC);
|
||||
if (*pFile == NULL) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to open file:%s since %s", filepath, tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t retryTimes = 0;
|
||||
int32_t ret = 0;
|
||||
do {
|
||||
ret = taosLockFile(pFile);
|
||||
ret = taosLockFile(*pFile);
|
||||
if (ret == 0) break;
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
taosMsleep(1000);
|
||||
retryTimes++;
|
||||
dError("failed to lock file:%s since %s, retryTimes:%d", filepath, terrstr(), retryTimes);
|
||||
dError("failed to lock file:%s since %s, retryTimes:%d", filepath, tstrerror(code), retryTimes);
|
||||
} while (retryTimes < 12);
|
||||
|
||||
if (ret < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
taosCloseFile(&pFile);
|
||||
return NULL;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
taosCloseFile(pFile);
|
||||
*pFile = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
terrno = 0;
|
||||
dDebug("lock file:%s to prevent repeated starts", filepath);
|
||||
return pFile;
|
||||
return code;
|
||||
}
|
||||
|
||||
extern int32_t generateEncryptCode(const char *key, const char *machineId, char **encryptCode);
|
||||
|
||||
static int32_t dmWriteCheckCodeFile(char* file, char* realfile, char* key, bool toLogFile){
|
||||
static int32_t dmWriteCheckCodeFile(char *file, char *realfile, char *key, bool toLogFile) {
|
||||
TdFilePtr pFile = NULL;
|
||||
char *result = NULL;
|
||||
int32_t code = -1;
|
||||
|
||||
int32_t len = ENCRYPTED_LEN(sizeof(DM_KEY_INDICATOR));
|
||||
result = taosMemoryMalloc(len);
|
||||
if (result == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SCryptOpts opts;
|
||||
strncpy(opts.key, key, ENCRYPT_KEY_LEN);
|
||||
|
@ -203,48 +242,81 @@ static int32_t dmWriteCheckCodeFile(char* file, char* realfile, char* key, bool
|
|||
CBC_Encrypt(&opts);
|
||||
|
||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||
if (pFile == NULL) goto _OVER;
|
||||
if (pFile == NULL) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (taosWriteFile(pFile, opts.result, len) <= 0) goto _OVER;
|
||||
if (taosFsyncFile(pFile) < 0) goto _OVER;
|
||||
if (taosWriteFile(pFile, opts.result, len) <= 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
taosCloseFile(&pFile);
|
||||
if (taosRenameFile(file, realfile) != 0) goto _OVER;
|
||||
if (taosFsyncFile(pFile) < 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (taosCloseFile(&pFile) != 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (taosRenameFile(file, realfile) != 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
encryptDebug("succeed to write checkCode file:%s", realfile);
|
||||
|
||||
code = 0;
|
||||
_OVER:
|
||||
if(pFile != NULL) taosCloseFile(&pFile);
|
||||
if(result != NULL) taosMemoryFree(result);
|
||||
if (pFile != NULL) taosCloseFile(&pFile);
|
||||
if (result != NULL) taosMemoryFree(result);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t dmWriteEncryptCodeFile(char* file, char* realfile, char* encryptCode, bool toLogFile){
|
||||
static int32_t dmWriteEncryptCodeFile(char *file, char *realfile, char *encryptCode, bool toLogFile) {
|
||||
TdFilePtr pFile = NULL;
|
||||
int32_t code = -1;
|
||||
|
||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||
if (pFile == NULL) goto _OVER;
|
||||
if (pFile == NULL) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
int32_t len = strlen(encryptCode);
|
||||
if (taosWriteFile(pFile, encryptCode, len) <= 0) goto _OVER;
|
||||
if (taosFsyncFile(pFile) < 0) goto _OVER;
|
||||
if (taosWriteFile(pFile, encryptCode, len) <= 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
if (taosFsyncFile(pFile) < 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
taosCloseFile(&pFile);
|
||||
if (taosRenameFile(file, realfile) != 0) goto _OVER;
|
||||
if (taosCloseFile(&pFile) != 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (taosRenameFile(file, realfile) != 0) {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
encryptDebug("succeed to write encryptCode file:%s", realfile);
|
||||
|
||||
code = 0;
|
||||
_OVER:
|
||||
if(pFile != NULL) taosCloseFile(&pFile);
|
||||
if (pFile != NULL) taosCloseFile(&pFile);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t dmCompareEncryptKey(char* file, char* key, bool toLogFile){
|
||||
static int32_t dmCompareEncryptKey(char *file, char *key, bool toLogFile) {
|
||||
char *content = NULL;
|
||||
int64_t size = 0;
|
||||
TdFilePtr pFile = NULL;
|
||||
|
@ -253,31 +325,31 @@ static int32_t dmCompareEncryptKey(char* file, char* key, bool toLogFile){
|
|||
|
||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
encryptError("failed to open dnode file:%s since %s", file, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
encryptError("failed to open dnode file:%s since %s", file, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
encryptError("failed to fstat dnode file:%s since %s", file, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
encryptError("failed to fstat dnode file:%s since %s", file, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
content = taosMemoryMalloc(size);
|
||||
if (content == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (taosReadFile(pFile, content, size) != size) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
encryptError("failed to read dnode file:%s since %s", file, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
encryptError("failed to read dnode file:%s since %s", file, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
encryptDebug("succeed to read checkCode file:%s", file);
|
||||
|
||||
|
||||
int len = ENCRYPTED_LEN(size);
|
||||
result = taosMemoryMalloc(len);
|
||||
|
||||
|
@ -289,8 +361,8 @@ static int32_t dmCompareEncryptKey(char* file, char* key, bool toLogFile){
|
|||
opts.unitLen = 16;
|
||||
CBC_Decrypt(&opts);
|
||||
|
||||
if(strcmp(opts.result, DM_KEY_INDICATOR) != 0) {
|
||||
terrno = TSDB_CODE_DNODE_ENCRYPTKEY_CHANGED;
|
||||
if (strcmp(opts.result, DM_KEY_INDICATOR) != 0) {
|
||||
code = TSDB_CODE_DNODE_ENCRYPTKEY_CHANGED;
|
||||
encryptError("failed to compare decrypted result");
|
||||
goto _OVER;
|
||||
}
|
||||
|
@ -298,9 +370,9 @@ static int32_t dmCompareEncryptKey(char* file, char* key, bool toLogFile){
|
|||
encryptDebug("succeed to compare checkCode file:%s", file);
|
||||
code = 0;
|
||||
_OVER:
|
||||
if(result != NULL) taosMemoryFree(result);
|
||||
if(content != NULL) taosMemoryFree(content);
|
||||
if(pFile != NULL) taosCloseFile(&pFile);
|
||||
if (result != NULL) taosMemoryFree(result);
|
||||
if (content != NULL) taosMemoryFree(content);
|
||||
if (pFile != NULL) taosCloseFile(&pFile);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -319,40 +391,57 @@ int32_t dmUpdateEncryptKey(char *key, bool toLogFile) {
|
|||
char checkFile[PATH_MAX] = {0};
|
||||
char realCheckFile[PATH_MAX] = {0};
|
||||
|
||||
snprintf(folder, sizeof(folder), "%s%sdnode", tsDataDir, TD_DIRSEP);
|
||||
snprintf(encryptFile, sizeof(realEncryptFile), "%s%s%s.bak", folder, TD_DIRSEP, DM_ENCRYPT_CODE_FILE);
|
||||
snprintf(realEncryptFile, sizeof(realEncryptFile), "%s%s%s", folder, TD_DIRSEP, DM_ENCRYPT_CODE_FILE);
|
||||
snprintf(checkFile, sizeof(checkFile), "%s%s%s.bak", folder, TD_DIRSEP, DM_CHECK_CODE_FILE);
|
||||
snprintf(realCheckFile, sizeof(realCheckFile), "%s%s%s", folder, TD_DIRSEP, DM_CHECK_CODE_FILE);
|
||||
int32_t nBytes = snprintf(folder, sizeof(folder), "%s%sdnode", tsDataDir, TD_DIRSEP);
|
||||
if (nBytes <= 0 || nBytes >= PATH_MAX) {
|
||||
return TSDB_CODE_OUT_OF_BUFFER;
|
||||
}
|
||||
|
||||
terrno = 0;
|
||||
nBytes = snprintf(encryptFile, sizeof(realEncryptFile), "%s%s%s.bak", folder, TD_DIRSEP, DM_ENCRYPT_CODE_FILE);
|
||||
if (nBytes <= 0 || nBytes >= PATH_MAX) {
|
||||
return TSDB_CODE_OUT_OF_BUFFER;
|
||||
}
|
||||
|
||||
nBytes = snprintf(realEncryptFile, sizeof(realEncryptFile), "%s%s%s", folder, TD_DIRSEP, DM_ENCRYPT_CODE_FILE);
|
||||
if (nBytes <= 0 || nBytes >= PATH_MAX) {
|
||||
return TSDB_CODE_OUT_OF_BUFFER;
|
||||
}
|
||||
|
||||
nBytes = snprintf(checkFile, sizeof(checkFile), "%s%s%s.bak", folder, TD_DIRSEP, DM_CHECK_CODE_FILE);
|
||||
if (nBytes <= 0 || nBytes >= PATH_MAX) {
|
||||
return TSDB_CODE_OUT_OF_BUFFER;
|
||||
}
|
||||
|
||||
snprintf(realCheckFile, sizeof(realCheckFile), "%s%s%s", folder, TD_DIRSEP, DM_CHECK_CODE_FILE);
|
||||
if (nBytes <= 0 || nBytes >= PATH_MAX) {
|
||||
return TSDB_CODE_OUT_OF_BUFFER;
|
||||
}
|
||||
|
||||
if (taosMkDir(folder) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
encryptError("failed to create dir:%s since %s", folder, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
encryptError("failed to create dir:%s since %s", folder, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if(taosCheckExistFile(realCheckFile)){
|
||||
if(dmCompareEncryptKey(realCheckFile, key, toLogFile) != 0){
|
||||
if (taosCheckExistFile(realCheckFile)) {
|
||||
if ((code = dmCompareEncryptKey(realCheckFile, key, toLogFile)) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!(machineId = tGetMachineId())) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (generateEncryptCode(key, machineId, &encryptCode) != 0) {
|
||||
if ((code = generateEncryptCode(key, machineId, &encryptCode)) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if(dmWriteEncryptCodeFile(encryptFile, realEncryptFile, encryptCode, toLogFile) != 0){
|
||||
if ((code = dmWriteEncryptCodeFile(encryptFile, realEncryptFile, encryptCode, toLogFile)) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if(dmWriteCheckCodeFile(checkFile, realCheckFile, key, toLogFile) != 0){
|
||||
if ((code = dmWriteCheckCodeFile(checkFile, realCheckFile, key, toLogFile)) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -363,8 +452,7 @@ _OVER:
|
|||
taosMemoryFree(encryptCode);
|
||||
taosMemoryFree(machineId);
|
||||
if (code != 0) {
|
||||
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
encryptError("failed to update encrypt key since %s", terrstr());
|
||||
encryptError("failed to update encrypt key since %s", tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
#else
|
||||
|
@ -374,89 +462,102 @@ _OVER:
|
|||
|
||||
extern int32_t checkAndGetCryptKey(const char *encryptCode, const char *machineId, char **key);
|
||||
|
||||
static int32_t dmReadEncryptCodeFile(char* file, char** output){
|
||||
static int32_t dmReadEncryptCodeFile(char *file, char **output) {
|
||||
TdFilePtr pFile = NULL;
|
||||
int32_t code = -1;
|
||||
char *content = NULL;
|
||||
|
||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to open dnode file:%s since %s", file, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to open dnode file:%s since %s", file, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
int64_t size = 0;
|
||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to fstat dnode file:%s since %s", file, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to fstat dnode file:%s since %s", file, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
content = taosMemoryMalloc(size + 1);
|
||||
if (content == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (taosReadFile(pFile, content, size) != size) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to read dnode file:%s since %s", file, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to read dnode file:%s since %s", file, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
content[size] = '\0';
|
||||
|
||||
*output = content;
|
||||
content = NULL;
|
||||
|
||||
dInfo("succeed to read encryptCode file:%s", file);
|
||||
code = 0;
|
||||
_OVER:
|
||||
if(pFile != NULL) taosCloseFile(&pFile);
|
||||
if (pFile != NULL) taosCloseFile(&pFile);
|
||||
taosMemoryFree(content);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t dmGetEncryptKey(){
|
||||
int32_t dmGetEncryptKey() {
|
||||
#ifdef TD_ENTERPRISE
|
||||
int32_t code = -1;
|
||||
char encryptFile[PATH_MAX] = {0};
|
||||
char checkFile[PATH_MAX] = {0};
|
||||
char *machineId = NULL;
|
||||
char *encryptKey = NULL;
|
||||
char *content = NULL;
|
||||
int32_t code = -1;
|
||||
char encryptFile[PATH_MAX] = {0};
|
||||
char checkFile[PATH_MAX] = {0};
|
||||
char *machineId = NULL;
|
||||
char *encryptKey = NULL;
|
||||
char *content = NULL;
|
||||
|
||||
snprintf(encryptFile, sizeof(encryptFile), "%s%sdnode%s%s", tsDataDir, TD_DIRSEP, TD_DIRSEP, DM_ENCRYPT_CODE_FILE);
|
||||
snprintf(checkFile, sizeof(checkFile), "%s%sdnode%s%s", tsDataDir, TD_DIRSEP, TD_DIRSEP, DM_CHECK_CODE_FILE);
|
||||
int32_t nBytes = snprintf(encryptFile, sizeof(encryptFile), "%s%sdnode%s%s", tsDataDir, TD_DIRSEP, TD_DIRSEP,
|
||||
DM_ENCRYPT_CODE_FILE);
|
||||
if (nBytes <= 0 || nBytes >= sizeof(encryptFile)) {
|
||||
code = TSDB_CODE_OUT_OF_BUFFER;
|
||||
return code;
|
||||
}
|
||||
|
||||
if(!taosCheckExistFile(encryptFile)){
|
||||
nBytes = snprintf(checkFile, sizeof(checkFile), "%s%sdnode%s%s", tsDataDir, TD_DIRSEP, TD_DIRSEP, DM_CHECK_CODE_FILE);
|
||||
if (nBytes <= 0 || nBytes >= sizeof(checkFile)) {
|
||||
code = TSDB_CODE_OUT_OF_BUFFER;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (!taosCheckExistFile(encryptFile)) {
|
||||
code = TSDB_CODE_DNODE_INVALID_ENCRYPT_CONFIG;
|
||||
dInfo("no exist, checkCode file:%s", encryptFile);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(dmReadEncryptCodeFile(encryptFile, &content) != 0){
|
||||
if ((code = dmReadEncryptCodeFile(encryptFile, &content)) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (!(machineId = tGetMachineId())) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if(checkAndGetCryptKey(content, machineId, &encryptKey) != 0){
|
||||
if ((code = checkAndGetCryptKey(content, machineId, &encryptKey)) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
taosMemoryFreeClear(machineId);
|
||||
taosMemoryFreeClear(content);
|
||||
|
||||
if(encryptKey[0] == '\0'){
|
||||
terrno = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY;
|
||||
dError("failed to read key since %s", terrstr());
|
||||
if (encryptKey[0] == '\0') {
|
||||
code = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY;
|
||||
dError("failed to read key since %s", tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if(dmCompareEncryptKey(checkFile, encryptKey, true) != 0){
|
||||
if ((code = dmCompareEncryptKey(checkFile, encryptKey, true)) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -471,8 +572,7 @@ _OVER:
|
|||
if (encryptKey != NULL) taosMemoryFree(encryptKey);
|
||||
if (machineId != NULL) taosMemoryFree(machineId);
|
||||
if (code != 0) {
|
||||
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to get encrypt key since %s", terrstr());
|
||||
dError("failed to get encrypt key since %s", tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
#else
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -464,26 +464,23 @@ static int32_t mndCreateDir(SMnode *pMnode, const char *path) {
|
|||
static int32_t mndInitWal(SMnode *pMnode) {
|
||||
char path[PATH_MAX + 20] = {0};
|
||||
snprintf(path, sizeof(path), "%s%swal", pMnode->path, TD_DIRSEP);
|
||||
SWalCfg cfg = {
|
||||
.vgId = 1,
|
||||
.fsyncPeriod = 0,
|
||||
.rollPeriod = -1,
|
||||
.segSize = -1,
|
||||
.retentionPeriod = 0,
|
||||
.retentionSize = 0,
|
||||
.level = TAOS_WAL_FSYNC,
|
||||
.encryptAlgorithm = 0,
|
||||
.encryptKey = {0}
|
||||
};
|
||||
SWalCfg cfg = {.vgId = 1,
|
||||
.fsyncPeriod = 0,
|
||||
.rollPeriod = -1,
|
||||
.segSize = -1,
|
||||
.retentionPeriod = 0,
|
||||
.retentionSize = 0,
|
||||
.level = TAOS_WAL_FSYNC,
|
||||
.encryptAlgorithm = 0,
|
||||
.encryptKey = {0}};
|
||||
|
||||
#if defined(TD_ENTERPRISE)
|
||||
if(tsiEncryptAlgorithm == DND_CA_SM4 && (tsiEncryptScope & DND_CS_MNODE_WAL) == DND_CS_MNODE_WAL){
|
||||
cfg.encryptAlgorithm = (tsiEncryptScope & DND_CS_MNODE_WAL)? tsiEncryptAlgorithm : 0;
|
||||
if(tsEncryptKey[0] == '\0'){
|
||||
if (tsiEncryptAlgorithm == DND_CA_SM4 && (tsiEncryptScope & DND_CS_MNODE_WAL) == DND_CS_MNODE_WAL) {
|
||||
cfg.encryptAlgorithm = (tsiEncryptScope & DND_CS_MNODE_WAL) ? tsiEncryptAlgorithm : 0;
|
||||
if (tsEncryptKey[0] == '\0') {
|
||||
terrno = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY;
|
||||
return -1;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
strncpy(cfg.encryptKey, tsEncryptKey, ENCRYPT_KEY_LEN);
|
||||
}
|
||||
}
|
||||
|
@ -856,7 +853,7 @@ _OVER:
|
|||
return -1;
|
||||
}
|
||||
|
||||
int32_t mndProcessRpcMsg(SRpcMsg *pMsg, SQueueInfo* pQueueInfo) {
|
||||
int32_t mndProcessRpcMsg(SRpcMsg *pMsg, SQueueInfo *pQueueInfo) {
|
||||
SMnode *pMnode = pMsg->info.node;
|
||||
const STraceId *trace = &pMsg->info.traceId;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
|
|
@ -69,6 +69,7 @@ int32_t mndInitMnode(SMnode *pMnode) {
|
|||
void mndCleanupMnode(SMnode *pMnode) {}
|
||||
|
||||
SMnodeObj *mndAcquireMnode(SMnode *pMnode, int32_t mnodeId) {
|
||||
terrno = 0;
|
||||
SMnodeObj *pObj = sdbAcquire(pMnode->pSdb, SDB_MNODE, &mnodeId);
|
||||
if (pObj == NULL && terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) {
|
||||
terrno = TSDB_CODE_MND_MNODE_NOT_EXIST;
|
||||
|
@ -82,13 +83,18 @@ void mndReleaseMnode(SMnode *pMnode, SMnodeObj *pObj) {
|
|||
}
|
||||
|
||||
static int32_t mndCreateDefaultMnode(SMnode *pMnode) {
|
||||
int32_t code = 0;
|
||||
SMnodeObj mnodeObj = {0};
|
||||
mnodeObj.id = 1;
|
||||
mnodeObj.createdTime = taosGetTimestampMs();
|
||||
mnodeObj.updateTime = mnodeObj.createdTime;
|
||||
|
||||
SSdbRaw *pRaw = mndMnodeActionEncode(&mnodeObj);
|
||||
if (pRaw == NULL) return -1;
|
||||
if (pRaw == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
return -1;
|
||||
}
|
||||
(void)sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
|
||||
mInfo("mnode:%d, will be created when deploying, raw:%p", mnodeObj.id, pRaw);
|
||||
|
@ -97,25 +103,27 @@ static int32_t mndCreateDefaultMnode(SMnode *pMnode) {
|
|||
if (pTrans == NULL) {
|
||||
sdbFreeRaw(pRaw);
|
||||
mError("mnode:%d, failed to create since %s", mnodeObj.id, terrstr());
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
return -1;
|
||||
}
|
||||
mInfo("trans:%d, used to create mnode:%d", pTrans->id, mnodeObj.id);
|
||||
|
||||
if (mndTransAppendCommitlog(pTrans, pRaw) != 0) {
|
||||
if ((code = mndTransAppendCommitlog(pTrans, pRaw)) != 0) {
|
||||
mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
(void)sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
if ((code = mndTransPrepare(pMnode, pTrans)) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
|
||||
mndTransDrop(pTrans);
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static SSdbRaw *mndMnodeActionEncode(SMnodeObj *pObj) {
|
||||
|
@ -188,16 +196,19 @@ _OVER:
|
|||
}
|
||||
|
||||
static int32_t mndMnodeActionInsert(SSdb *pSdb, SMnodeObj *pObj) {
|
||||
int32_t code = 0;
|
||||
mTrace("mnode:%d, perform insert action, row:%p", pObj->id, pObj);
|
||||
pObj->pDnode = sdbAcquireNotReadyObj(pSdb, SDB_DNODE, &pObj->id);
|
||||
if (pObj->pDnode == NULL) {
|
||||
mError("mnode:%d, failed to perform insert action since %s", pObj->id, terrstr());
|
||||
return -1;
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
int32_t code = 0;
|
||||
}
|
||||
|
||||
pObj->syncState = TAOS_SYNC_STATE_OFFLINE;
|
||||
mndReloadSyncConfig(pSdb->pMnode);
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndMnodeActionDelete(SSdb *pSdb, SMnodeObj *pObj) {
|
||||
|
@ -271,38 +282,59 @@ void mndGetMnodeEpSet(SMnode *pMnode, SEpSet *pEpSet) {
|
|||
}
|
||||
|
||||
static int32_t mndSetCreateMnodeRedoLogs(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pRedoRaw = mndMnodeActionEncode(pObj);
|
||||
if (pRedoRaw == NULL) return -1;
|
||||
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING) != 0) return -1;
|
||||
return 0;
|
||||
if (pRedoRaw == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
TAOS_CHECK_RETURN(mndTransAppendRedolog(pTrans, pRedoRaw));
|
||||
TAOS_CHECK_RETURN(sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t mndSetRestoreCreateMnodeRedoLogs(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pRedoRaw = mndMnodeActionEncode(pObj);
|
||||
if (pRedoRaw == NULL) return -1;
|
||||
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY) != 0) return -1;
|
||||
return 0;
|
||||
if (pRedoRaw == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
TAOS_CHECK_RETURN(mndTransAppendRedolog(pTrans, pRedoRaw));
|
||||
TAOS_CHECK_RETURN(sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndSetCreateMnodeUndoLogs(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pUndoRaw = mndMnodeActionEncode(pObj);
|
||||
if (pUndoRaw == NULL) return -1;
|
||||
if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
||||
return 0;
|
||||
if (pUndoRaw == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
TAOS_CHECK_RETURN(mndTransAppendUndolog(pTrans, pUndoRaw));
|
||||
TAOS_CHECK_RETURN(sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t mndSetCreateMnodeCommitLogs(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pCommitRaw = mndMnodeActionEncode(pObj);
|
||||
if (pCommitRaw == NULL) return -1;
|
||||
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1;
|
||||
return 0;
|
||||
if (pCommitRaw == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
TAOS_CHECK_RETURN(mndTransAppendCommitlog(pTrans, pCommitRaw));
|
||||
TAOS_CHECK_RETURN(sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndBuildCreateMnodeRedoAction(STrans *pTrans, SDCreateMnodeReq *pCreateReq, SEpSet *pCreateEpSet) {
|
||||
int32_t code = 0;
|
||||
int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, pCreateReq);
|
||||
void *pReq = taosMemoryMalloc(contLen);
|
||||
tSerializeSDCreateMnodeReq(pReq, contLen, pCreateReq);
|
||||
|
@ -315,15 +347,16 @@ static int32_t mndBuildCreateMnodeRedoAction(STrans *pTrans, SDCreateMnodeReq *p
|
|||
.acceptableCode = TSDB_CODE_MNODE_ALREADY_DEPLOYED,
|
||||
};
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndBuildAlterMnodeTypeRedoAction(STrans *pTrans, SDAlterMnodeTypeReq *pAlterMnodeTypeReq,
|
||||
SEpSet *pAlterMnodeTypeEpSet) {
|
||||
int32_t code = 0;
|
||||
int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, pAlterMnodeTypeReq);
|
||||
void *pReq = taosMemoryMalloc(contLen);
|
||||
tSerializeSDCreateMnodeReq(pReq, contLen, pAlterMnodeTypeReq);
|
||||
|
@ -337,14 +370,15 @@ static int32_t mndBuildAlterMnodeTypeRedoAction(STrans *pTrans, SDAlterMnodeType
|
|||
.acceptableCode = TSDB_CODE_MNODE_ALREADY_IS_VOTER,
|
||||
};
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndBuildAlterMnodeRedoAction(STrans *pTrans, SDCreateMnodeReq *pAlterReq, SEpSet *pAlterEpSet) {
|
||||
int32_t code = 0;
|
||||
int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, pAlterReq);
|
||||
void *pReq = taosMemoryMalloc(contLen);
|
||||
tSerializeSDCreateMnodeReq(pReq, contLen, pAlterReq);
|
||||
|
@ -357,15 +391,16 @@ static int32_t mndBuildAlterMnodeRedoAction(STrans *pTrans, SDCreateMnodeReq *pA
|
|||
.acceptableCode = 0,
|
||||
};
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndBuildDropMnodeRedoAction(STrans *pTrans, SDDropMnodeReq *pDropReq, SEpSet *pDroprEpSet) {
|
||||
int32_t code = 0;
|
||||
int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, pDropReq);
|
||||
void *pReq = taosMemoryMalloc(contLen);
|
||||
tSerializeSCreateDropMQSNodeReq(pReq, contLen, pDropReq);
|
||||
|
@ -378,11 +413,11 @@ static int32_t mndBuildDropMnodeRedoAction(STrans *pTrans, SDDropMnodeReq *pDrop
|
|||
.acceptableCode = TSDB_CODE_MNODE_NOT_DEPLOYED,
|
||||
};
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnodeObj *pDnode, SMnodeObj *pObj) {
|
||||
|
@ -426,9 +461,9 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
|
|||
createEpset.eps[0].port = pDnode->port;
|
||||
memcpy(createEpset.eps[0].fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
|
||||
|
||||
if (mndBuildCreateMnodeRedoAction(pTrans, &createReq, &createEpset) != 0) return -1;
|
||||
TAOS_CHECK_RETURN(mndBuildCreateMnodeRedoAction(pTrans, &createReq, &createEpset));
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(0);
|
||||
}
|
||||
|
||||
int32_t mndSetRestoreCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnodeObj *pDnode, SMnodeObj *pObj) {
|
||||
|
@ -474,9 +509,9 @@ int32_t mndSetRestoreCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
|
|||
createEpset.eps[0].port = pDnode->port;
|
||||
memcpy(createEpset.eps[0].fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
|
||||
|
||||
if (mndBuildCreateMnodeRedoAction(pTrans, &createReq, &createEpset) != 0) return -1;
|
||||
TAOS_CHECK_RETURN(mndBuildCreateMnodeRedoAction(pTrans, &createReq, &createEpset));
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(0);
|
||||
}
|
||||
|
||||
static int32_t mndSetAlterMnodeTypeRedoActions(SMnode *pMnode, STrans *pTrans, SDnodeObj *pDnode, SMnodeObj *pObj) {
|
||||
|
@ -517,9 +552,9 @@ static int32_t mndSetAlterMnodeTypeRedoActions(SMnode *pMnode, STrans *pTrans, S
|
|||
createEpset.eps[0].port = pDnode->port;
|
||||
memcpy(createEpset.eps[0].fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
|
||||
|
||||
if (mndBuildAlterMnodeTypeRedoAction(pTrans, &alterReq, &createEpset) != 0) return -1;
|
||||
TAOS_CHECK_RETURN(mndBuildAlterMnodeTypeRedoAction(pTrans, &alterReq, &createEpset));
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(0);
|
||||
}
|
||||
|
||||
int32_t mndSetRestoreAlterMnodeTypeRedoActions(SMnode *pMnode, STrans *pTrans, SDnodeObj *pDnode, SMnodeObj *pObj) {
|
||||
|
@ -565,19 +600,23 @@ int32_t mndSetRestoreAlterMnodeTypeRedoActions(SMnode *pMnode, STrans *pTrans, S
|
|||
createEpset.eps[0].port = pDnode->port;
|
||||
memcpy(createEpset.eps[0].fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
|
||||
|
||||
if (mndBuildAlterMnodeTypeRedoAction(pTrans, &alterReq, &createEpset) != 0) return -1;
|
||||
TAOS_CHECK_RETURN(mndBuildAlterMnodeTypeRedoAction(pTrans, &alterReq, &createEpset));
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(0);
|
||||
}
|
||||
|
||||
static int32_t mndCreateMnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SMCreateMnodeReq *pCreate) {
|
||||
int32_t code = -1;
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq, "create-mnode");
|
||||
if (pTrans == NULL) goto _OVER;
|
||||
if (pTrans == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
goto _OVER;
|
||||
}
|
||||
mndTransSetSerial(pTrans);
|
||||
mInfo("trans:%d, used to create mnode:%d", pTrans->id, pCreate->dnodeId);
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
TAOS_CHECK_GOTO(mndTransCheckConflict(pMnode, pTrans), NULL, _OVER);
|
||||
|
||||
SMnodeObj mnodeObj = {0};
|
||||
mnodeObj.id = pDnode->id;
|
||||
|
@ -586,8 +625,8 @@ static int32_t mndCreateMnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode,
|
|||
mnodeObj.role = TAOS_SYNC_ROLE_LEARNER;
|
||||
mnodeObj.lastIndex = pMnode->applied;
|
||||
|
||||
if (mndSetCreateMnodeRedoActions(pMnode, pTrans, pDnode, &mnodeObj) != 0) goto _OVER;
|
||||
if (mndSetCreateMnodeRedoLogs(pMnode, pTrans, &mnodeObj) != 0) goto _OVER;
|
||||
TAOS_CHECK_GOTO(mndSetCreateMnodeRedoActions(pMnode, pTrans, pDnode, &mnodeObj), NULL, _OVER);
|
||||
TAOS_CHECK_GOTO(mndSetCreateMnodeRedoLogs(pMnode, pTrans, &mnodeObj), NULL, _OVER);
|
||||
|
||||
SMnodeObj mnodeLeaderObj = {0};
|
||||
mnodeLeaderObj.id = pDnode->id;
|
||||
|
@ -596,15 +635,15 @@ static int32_t mndCreateMnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode,
|
|||
mnodeLeaderObj.role = TAOS_SYNC_ROLE_VOTER;
|
||||
mnodeLeaderObj.lastIndex = pMnode->applied + 1;
|
||||
|
||||
if (mndSetAlterMnodeTypeRedoActions(pMnode, pTrans, pDnode, &mnodeLeaderObj) != 0) goto _OVER;
|
||||
if (mndSetCreateMnodeCommitLogs(pMnode, pTrans, &mnodeLeaderObj) != 0) goto _OVER;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
TAOS_CHECK_GOTO(mndSetAlterMnodeTypeRedoActions(pMnode, pTrans, pDnode, &mnodeLeaderObj), NULL, _OVER);
|
||||
TAOS_CHECK_GOTO(mndSetCreateMnodeCommitLogs(pMnode, pTrans, &mnodeLeaderObj), NULL, _OVER);
|
||||
TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
|
||||
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
mndTransDrop(pTrans);
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndProcessCreateMnodeReq(SRpcMsg *pReq) {
|
||||
|
@ -614,19 +653,14 @@ static int32_t mndProcessCreateMnodeReq(SRpcMsg *pReq) {
|
|||
SDnodeObj *pDnode = NULL;
|
||||
SMCreateMnodeReq createReq = {0};
|
||||
|
||||
if (tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &createReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
goto _OVER;
|
||||
}
|
||||
TAOS_CHECK_GOTO(tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &createReq), NULL, _OVER);
|
||||
|
||||
mInfo("mnode:%d, start to create", createReq.dnodeId);
|
||||
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CREATE_MNODE) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
TAOS_CHECK_GOTO(mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CREATE_MNODE), NULL, _OVER);
|
||||
|
||||
pObj = mndAcquireMnode(pMnode, createReq.dnodeId);
|
||||
if (pObj != NULL) {
|
||||
terrno = TSDB_CODE_MND_MNODE_ALREADY_EXIST;
|
||||
code = TSDB_CODE_MND_MNODE_ALREADY_EXIST;
|
||||
goto _OVER;
|
||||
} else if (terrno != TSDB_CODE_MND_MNODE_NOT_EXIST) {
|
||||
goto _OVER;
|
||||
|
@ -634,17 +668,17 @@ static int32_t mndProcessCreateMnodeReq(SRpcMsg *pReq) {
|
|||
|
||||
pDnode = mndAcquireDnode(pMnode, createReq.dnodeId);
|
||||
if (pDnode == NULL) {
|
||||
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||
code = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (sdbGetSize(pMnode->pSdb, SDB_MNODE) >= 3) {
|
||||
terrno = TSDB_CODE_MND_TOO_MANY_MNODES;
|
||||
code = TSDB_CODE_MND_TOO_MANY_MNODES;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (!mndIsDnodeOnline(pDnode, taosGetTimestampMs())) {
|
||||
terrno = TSDB_CODE_DNODE_OFFLINE;
|
||||
code = TSDB_CODE_DNODE_OFFLINE;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -665,27 +699,38 @@ _OVER:
|
|||
mndReleaseDnode(pMnode, pDnode);
|
||||
tFreeSMCreateQnodeReq(&createReq);
|
||||
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndSetDropMnodeRedoLogs(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pRedoRaw = mndMnodeActionEncode(pObj);
|
||||
if (pRedoRaw == NULL) return -1;
|
||||
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1;
|
||||
return 0;
|
||||
if (pRedoRaw == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
TAOS_CHECK_RETURN(mndTransAppendRedolog(pTrans, pRedoRaw));
|
||||
TAOS_CHECK_RETURN(sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndSetDropMnodeCommitLogs(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pCommitRaw = mndMnodeActionEncode(pObj);
|
||||
if (pCommitRaw == NULL) return -1;
|
||||
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
||||
return 0;
|
||||
if (pCommitRaw == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
TAOS_CHECK_RETURN(mndTransAppendCommitlog(pTrans, pCommitRaw));
|
||||
TAOS_CHECK_RETURN(sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnodeObj *pDnode, SMnodeObj *pObj,
|
||||
bool force) {
|
||||
int32_t code = 0;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
void *pIter = NULL;
|
||||
SDDropMnodeReq dropReq = {0};
|
||||
|
@ -700,32 +745,32 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
|
|||
if (totalMnodes == 2) {
|
||||
if (force) {
|
||||
mError("cant't force drop dnode, since a mnode on it and replica is 2");
|
||||
terrno = TSDB_CODE_MNODE_ONLY_TWO_MNODE;
|
||||
return -1;
|
||||
code = TSDB_CODE_MNODE_ONLY_TWO_MNODE;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
mInfo("vgId:1, has %d mnodes, exec redo log first", totalMnodes);
|
||||
if (mndSetDropMnodeRedoLogs(pMnode, pTrans, pObj) != 0) return -1;
|
||||
TAOS_CHECK_RETURN(mndSetDropMnodeRedoLogs(pMnode, pTrans, pObj));
|
||||
if (!force) {
|
||||
if (mndBuildDropMnodeRedoAction(pTrans, &dropReq, &dropEpSet) != 0) return -1;
|
||||
TAOS_CHECK_RETURN(mndBuildDropMnodeRedoAction(pTrans, &dropReq, &dropEpSet));
|
||||
}
|
||||
} else if (totalMnodes == 3) {
|
||||
mInfo("vgId:1, has %d mnodes, exec redo action first", totalMnodes);
|
||||
if (!force) {
|
||||
if (mndBuildDropMnodeRedoAction(pTrans, &dropReq, &dropEpSet) != 0) return -1;
|
||||
TAOS_CHECK_RETURN(mndBuildDropMnodeRedoAction(pTrans, &dropReq, &dropEpSet));
|
||||
}
|
||||
if (mndSetDropMnodeRedoLogs(pMnode, pTrans, pObj) != 0) return -1;
|
||||
TAOS_CHECK_RETURN(mndSetDropMnodeRedoLogs(pMnode, pTrans, pObj));
|
||||
} else {
|
||||
return -1;
|
||||
TAOS_RETURN(-1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t mndSetDropMnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj, bool force) {
|
||||
if (pObj == NULL) return 0;
|
||||
pObj->lastIndex = pMnode->applied;
|
||||
if (mndSetDropMnodeRedoActions(pMnode, pTrans, pObj->pDnode, pObj, force) != 0) return -1;
|
||||
if (mndSetDropMnodeCommitLogs(pMnode, pTrans, pObj) != 0) return -1;
|
||||
TAOS_CHECK_RETURN(mndSetDropMnodeRedoActions(pMnode, pTrans, pObj->pDnode, pObj, force));
|
||||
TAOS_CHECK_RETURN(mndSetDropMnodeCommitLogs(pMnode, pTrans, pObj));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -734,19 +779,23 @@ static int32_t mndDropMnode(SMnode *pMnode, SRpcMsg *pReq, SMnodeObj *pObj) {
|
|||
STrans *pTrans = NULL;
|
||||
|
||||
pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq, "drop-mnode");
|
||||
if (pTrans == NULL) goto _OVER;
|
||||
if (pTrans == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
goto _OVER;
|
||||
}
|
||||
mndTransSetSerial(pTrans);
|
||||
mInfo("trans:%d, used to drop mnode:%d", pTrans->id, pObj->id);
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
TAOS_CHECK_GOTO(mndTransCheckConflict(pMnode, pTrans), NULL, _OVER);
|
||||
|
||||
if (mndSetDropMnodeInfoToTrans(pMnode, pTrans, pObj, false) != 0) goto _OVER;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
TAOS_CHECK_GOTO(mndSetDropMnodeInfoToTrans(pMnode, pTrans, pObj, false), NULL, _OVER);
|
||||
TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
|
||||
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
mndTransDrop(pTrans);
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndProcessDropMnodeReq(SRpcMsg *pReq) {
|
||||
|
@ -755,38 +804,35 @@ static int32_t mndProcessDropMnodeReq(SRpcMsg *pReq) {
|
|||
SMnodeObj *pObj = NULL;
|
||||
SMDropMnodeReq dropReq = {0};
|
||||
|
||||
if (tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
goto _OVER;
|
||||
}
|
||||
TAOS_CHECK_GOTO(tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &dropReq), NULL, _OVER);
|
||||
|
||||
mInfo("mnode:%d, start to drop", dropReq.dnodeId);
|
||||
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_MNODE) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
TAOS_CHECK_GOTO(mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_MNODE), NULL, _OVER);
|
||||
|
||||
if (dropReq.dnodeId <= 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pObj = mndAcquireMnode(pMnode, dropReq.dnodeId);
|
||||
if (pObj == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (pMnode->selfDnodeId == dropReq.dnodeId) {
|
||||
terrno = TSDB_CODE_MND_CANT_DROP_LEADER;
|
||||
code = TSDB_CODE_MND_CANT_DROP_LEADER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (sdbGetSize(pMnode->pSdb, SDB_MNODE) <= 1) {
|
||||
terrno = TSDB_CODE_MND_TOO_FEW_MNODES;
|
||||
code = TSDB_CODE_MND_TOO_FEW_MNODES;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (!mndIsDnodeOnline(pObj->pDnode, taosGetTimestampMs())) {
|
||||
terrno = TSDB_CODE_DNODE_OFFLINE;
|
||||
code = TSDB_CODE_DNODE_OFFLINE;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -805,7 +851,7 @@ _OVER:
|
|||
|
||||
mndReleaseMnode(pMnode, pObj);
|
||||
tFreeSMCreateQnodeReq(&dropReq);
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndRetrieveMnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
||||
|
@ -892,13 +938,11 @@ static int32_t mndProcessAlterMnodeReq(SRpcMsg *pReq) {
|
|||
#if 1
|
||||
return 0;
|
||||
#else
|
||||
int32_t code = 0;
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
SDAlterMnodeReq alterReq = {0};
|
||||
|
||||
if (tDeserializeSDCreateMnodeReq(pReq->pCont, pReq->contLen, &alterReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
TAOS_CHECK_RETURN(tDeserializeSDCreateMnodeReq(pReq->pCont, pReq->contLen, &alterReq));
|
||||
|
||||
SMnodeOpt option = {.deploy = true, .numOfReplicas = alterReq.replica, .selfIndex = -1};
|
||||
memcpy(option.replicas, alterReq.replicas, sizeof(alterReq.replicas));
|
||||
|
@ -913,9 +957,9 @@ static int32_t mndProcessAlterMnodeReq(SRpcMsg *pReq) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (mndWriteFile(pMnode->path, &option) != 0) {
|
||||
if ((code = mndWriteFile(pMnode->path, &option)) != 0) {
|
||||
mError("failed to write mnode file since %s", terrstr());
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
SSyncCfg cfg = {.replicaNum = alterReq.replica, .myIndex = -1};
|
||||
|
@ -939,14 +983,14 @@ static int32_t mndProcessAlterMnodeReq(SRpcMsg *pReq) {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t code = syncReconfig(pMnode->syncMgmt.sync, &cfg);
|
||||
code = syncReconfig(pMnode->syncMgmt.sync, &cfg);
|
||||
if (code != 0) {
|
||||
mError("failed to sync reconfig since %s", terrstr());
|
||||
} else {
|
||||
mInfo("alter mnode sync success");
|
||||
}
|
||||
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -19,10 +19,11 @@
|
|||
|
||||
// connection/application/
|
||||
int32_t mndInitPerfsTableSchema(const SSysDbTableSchema *pSrc, int32_t colNum, SSchema **pDst) {
|
||||
int32_t code = 0;
|
||||
SSchema *schema = taosMemoryCalloc(colNum, sizeof(SSchema));
|
||||
if (NULL == schema) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < colNum; ++i) {
|
||||
|
@ -34,10 +35,11 @@ int32_t mndInitPerfsTableSchema(const SSysDbTableSchema *pSrc, int32_t colNum, S
|
|||
}
|
||||
|
||||
*pDst = schema;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t mndPerfsInitMeta(SHashObj *hash) {
|
||||
int32_t code = 0;
|
||||
STableMetaRsp meta = {0};
|
||||
|
||||
tstrncpy(meta.dbFName, TSDB_INFORMATION_SCHEMA_DB, sizeof(meta.dbFName));
|
||||
|
@ -53,56 +55,56 @@ int32_t mndPerfsInitMeta(SHashObj *hash) {
|
|||
tstrncpy(meta.tbName, pSysDbTableMeta[i].name, sizeof(meta.tbName));
|
||||
meta.numOfColumns = pSysDbTableMeta[i].colNum;
|
||||
|
||||
if (mndInitPerfsTableSchema(pSysDbTableMeta[i].schema, pSysDbTableMeta[i].colNum, &meta.pSchemas)) {
|
||||
return -1;
|
||||
}
|
||||
TAOS_CHECK_RETURN(mndInitPerfsTableSchema(pSysDbTableMeta[i].schema, pSysDbTableMeta[i].colNum, &meta.pSchemas));
|
||||
|
||||
if (taosHashPut(hash, meta.tbName, strlen(meta.tbName), &meta, sizeof(meta))) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t mndBuildPerfsTableSchema(SMnode *pMnode, const char *dbFName, const char *tbName, STableMetaRsp *pRsp) {
|
||||
int32_t code = 0;
|
||||
if (NULL == pMnode->perfsMeta) {
|
||||
terrno = TSDB_CODE_APP_ERROR;
|
||||
return -1;
|
||||
code = TSDB_CODE_APP_ERROR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
STableMetaRsp *meta = (STableMetaRsp *)taosHashGet(pMnode->perfsMeta, tbName, strlen(tbName));
|
||||
if (NULL == meta) {
|
||||
mError("invalid performance schema table name:%s", tbName);
|
||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*pRsp = *meta;
|
||||
|
||||
pRsp->pSchemas = taosMemoryCalloc(meta->numOfColumns, sizeof(SSchema));
|
||||
if (pRsp->pSchemas == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
pRsp->pSchemas = NULL;
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
memcpy(pRsp->pSchemas, meta->pSchemas, meta->numOfColumns * sizeof(SSchema));
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t mndBuildPerfsTableCfg(SMnode *pMnode, const char *dbFName, const char *tbName, STableCfgRsp *pRsp) {
|
||||
int32_t code = 0;
|
||||
if (NULL == pMnode->perfsMeta) {
|
||||
terrno = TSDB_CODE_APP_ERROR;
|
||||
return -1;
|
||||
code = TSDB_CODE_APP_ERROR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
STableMetaRsp *pMeta = taosHashGet(pMnode->perfsMeta, tbName, strlen(tbName));
|
||||
if (NULL == pMeta) {
|
||||
mError("invalid performance schema table name:%s", tbName);
|
||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
strcpy(pRsp->tbName, pMeta->tbName);
|
||||
|
@ -114,20 +116,21 @@ int32_t mndBuildPerfsTableCfg(SMnode *pMnode, const char *dbFName, const char *t
|
|||
|
||||
pRsp->pSchemas = taosMemoryCalloc(pMeta->numOfColumns, sizeof(SSchema));
|
||||
if (pRsp->pSchemas == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
pRsp->pSchemas = NULL;
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
memcpy(pRsp->pSchemas, pMeta->pSchemas, pMeta->numOfColumns * sizeof(SSchema));
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t mndInitPerfs(SMnode *pMnode) {
|
||||
int32_t code = 0;
|
||||
pMnode->perfsMeta = taosHashInit(20, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
|
||||
if (pMnode->perfsMeta == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return mndPerfsInitMeta(pMnode->perfsMeta);
|
||||
|
|
|
@ -85,22 +85,23 @@ static void mndCancelGetNextApp(SMnode *pMnode, void *pIter);
|
|||
static int32_t mndProcessSvrVerReq(SRpcMsg *pReq);
|
||||
|
||||
int32_t mndInitProfile(SMnode *pMnode) {
|
||||
int32_t code = 0;
|
||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||
|
||||
// in ms
|
||||
int32_t checkTime = tsShellActivityTimer * 2 * 1000;
|
||||
pMgmt->connCache = taosCacheInit(TSDB_DATA_TYPE_UINT, checkTime, false, (__cache_free_fn_t)mndFreeConn, "conn");
|
||||
if (pMgmt->connCache == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("failed to alloc profile cache since %s", terrstr());
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
pMgmt->appCache = taosCacheInit(TSDB_DATA_TYPE_BIGINT, checkTime, true, (__cache_free_fn_t)mndFreeApp, "app");
|
||||
if (pMgmt->appCache == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("failed to alloc profile cache since %s", terrstr());
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_HEARTBEAT, mndProcessHeartBeatReq);
|
||||
|
@ -116,7 +117,7 @@ int32_t mndInitProfile(SMnode *pMnode) {
|
|||
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_APPS, mndRetrieveApps);
|
||||
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_APPS, mndCancelGetNextApp);
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
void mndCleanupProfile(SMnode *pMnode) {
|
||||
|
@ -384,6 +385,7 @@ static SAppObj *mndCreateApp(SMnode *pMnode, uint32_t clientIp, SAppHbReq *pReq)
|
|||
static void mndFreeApp(SAppObj *pApp) { mTrace("app %" PRIx64 " is destroyed", pApp->appId); }
|
||||
|
||||
static SAppObj *mndAcquireApp(SMnode *pMnode, int64_t appId) {
|
||||
terrno = 0;
|
||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||
|
||||
SAppObj *pApp = taosCacheAcquireByKey(pMgmt->appCache, &appId, sizeof(appId));
|
||||
|
@ -431,13 +433,16 @@ static SClientHbRsp *mndMqHbBuildRsp(SMnode *pMnode, SClientHbReq *pReq) {
|
|||
}
|
||||
|
||||
static int32_t mndUpdateAppInfo(SMnode *pMnode, SClientHbReq *pHbReq, SRpcConnInfo *connInfo) {
|
||||
int32_t code = 0;
|
||||
SAppHbReq *pReq = &pHbReq->app;
|
||||
SAppObj *pApp = mndAcquireApp(pMnode, pReq->appId);
|
||||
if (pApp == NULL) {
|
||||
pApp = mndCreateApp(pMnode, connInfo->clientIp, pReq);
|
||||
if (pApp == NULL) {
|
||||
mError("failed to create new app %" PRIx64 " since %s", pReq->appId, terrstr());
|
||||
return -1;
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
} else {
|
||||
mDebug("a new app %" PRIx64 " is created", pReq->appId);
|
||||
mndReleaseApp(pMnode, pApp);
|
||||
|
@ -475,6 +480,7 @@ static int32_t mndGetOnlineDnodeNum(SMnode *pMnode, int32_t *num) {
|
|||
|
||||
static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHbReq *pHbReq,
|
||||
SClientHbBatchRsp *pBatchRsp, SConnPreparedObj *pObj) {
|
||||
int32_t code = 0;
|
||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||
SClientHbRsp hbRsp = {.connKey = pHbReq->connKey, .status = 0, .info = NULL, .query = NULL};
|
||||
SRpcConnInfo connInfo = pMsg->info.conn;
|
||||
|
@ -492,7 +498,9 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb
|
|||
pHbReq->app.pid, pHbReq->app.name, 0);
|
||||
if (pConn == NULL) {
|
||||
mError("user:%s, conn:%u is freed and failed to create new since %s", connInfo.user, pBasic->connId, terrstr());
|
||||
return -1;
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
} else {
|
||||
mDebug("user:%s, conn:%u is freed, will create a new conn:%u", connInfo.user, pBasic->connId, pConn->id);
|
||||
}
|
||||
|
@ -501,9 +509,9 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb
|
|||
SQueryHbRspBasic *rspBasic = taosMemoryCalloc(1, sizeof(SQueryHbRspBasic));
|
||||
if (rspBasic == NULL) {
|
||||
mndReleaseConn(pMnode, pConn, true);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("user:%s, conn:%u failed to process hb while since %s", pConn->user, pBasic->connId, terrstr());
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
mndSaveQueryList(pConn, pBasic);
|
||||
|
@ -539,9 +547,9 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb
|
|||
hbRsp.info = taosArrayInit(kvNum, sizeof(SKv));
|
||||
if (NULL == hbRsp.info) {
|
||||
mError("taosArrayInit %d rsp kv failed", kvNum);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
tFreeClientHbRsp(&hbRsp);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
#ifdef TD_ENTERPRISE
|
||||
|
@ -554,8 +562,8 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb
|
|||
mTrace("recv view dyn ver, bootTs:%" PRId64 ", ver:%" PRIu64, pDynViewVer->svrBootTs, pDynViewVer->dynViewVer);
|
||||
|
||||
SDynViewVersion *pRspVer = NULL;
|
||||
if (0 != mndValidateDynViewVersion(pMnode, pDynViewVer, &needCheck, &pRspVer)) {
|
||||
return -1;
|
||||
if (0 != (code = mndValidateDynViewVersion(pMnode, pDynViewVer, &needCheck, &pRspVer))) {
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (needCheck) {
|
||||
|
@ -647,13 +655,14 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb
|
|||
}
|
||||
|
||||
static int32_t mndProcessHeartBeatReq(SRpcMsg *pReq) {
|
||||
int32_t code = 0;
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
|
||||
SClientHbBatchReq batchReq = {0};
|
||||
if (tDeserializeSClientHbBatchReq(pReq->pCont, pReq->contLen, &batchReq) != 0) {
|
||||
taosArrayDestroyEx(batchReq.reqs, tFreeClientHbReq);
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
SConnPreparedObj obj = {0};
|
||||
|
@ -699,31 +708,27 @@ static int32_t mndProcessHeartBeatReq(SRpcMsg *pReq) {
|
|||
|
||||
taosArrayDestroy(obj.pQnodeList);
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndProcessKillQueryReq(SRpcMsg *pReq) {
|
||||
int32_t code = 0;
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||
|
||||
SKillQueryReq killReq = {0};
|
||||
if (tDeserializeSKillQueryReq(pReq->pCont, pReq->contLen, &killReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
TAOS_CHECK_RETURN(tDeserializeSKillQueryReq(pReq->pCont, pReq->contLen, &killReq));
|
||||
|
||||
mInfo("kill query msg is received, queryId:%s", killReq.queryStrId);
|
||||
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_KILL_QUERY) != 0) {
|
||||
return -1;
|
||||
}
|
||||
TAOS_CHECK_RETURN(mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_KILL_QUERY));
|
||||
|
||||
int32_t connId = 0;
|
||||
uint64_t queryId = 0;
|
||||
char *p = strchr(killReq.queryStrId, ':');
|
||||
if (NULL == p) {
|
||||
mError("invalid query id %s", killReq.queryStrId);
|
||||
terrno = TSDB_CODE_MND_INVALID_QUERY_ID;
|
||||
return -1;
|
||||
code = TSDB_CODE_MND_INVALID_QUERY_ID;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
*p = 0;
|
||||
connId = taosStr2Int32(killReq.queryStrId, NULL, 16);
|
||||
|
@ -732,40 +737,36 @@ static int32_t mndProcessKillQueryReq(SRpcMsg *pReq) {
|
|||
SConnObj *pConn = taosCacheAcquireByKey(pMgmt->connCache, &connId, sizeof(int32_t));
|
||||
if (pConn == NULL) {
|
||||
mError("connId:%x, failed to kill queryId:%" PRIx64 ", conn not exist", connId, queryId);
|
||||
terrno = TSDB_CODE_MND_INVALID_CONN_ID;
|
||||
return -1;
|
||||
code = TSDB_CODE_MND_INVALID_CONN_ID;
|
||||
TAOS_RETURN(code);
|
||||
} else {
|
||||
mInfo("connId:%x, queryId:%" PRIx64 " is killed by user:%s", connId, queryId, pReq->info.conn.user);
|
||||
pConn->killId = queryId;
|
||||
taosCacheRelease(pMgmt->connCache, (void **)&pConn, false);
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t mndProcessKillConnReq(SRpcMsg *pReq) {
|
||||
int32_t code = 0;
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||
|
||||
SKillConnReq killReq = {0};
|
||||
if (tDeserializeSKillConnReq(pReq->pCont, pReq->contLen, &killReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
TAOS_CHECK_RETURN(tDeserializeSKillConnReq(pReq->pCont, pReq->contLen, &killReq));
|
||||
|
||||
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_KILL_CONN) != 0) {
|
||||
return -1;
|
||||
}
|
||||
TAOS_CHECK_RETURN(mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_KILL_CONN));
|
||||
|
||||
SConnObj *pConn = taosCacheAcquireByKey(pMgmt->connCache, &killReq.connId, sizeof(uint32_t));
|
||||
if (pConn == NULL) {
|
||||
mError("connId:%u, failed to kill connection, conn not exist", killReq.connId);
|
||||
terrno = TSDB_CODE_MND_INVALID_CONN_ID;
|
||||
return -1;
|
||||
code = TSDB_CODE_MND_INVALID_CONN_ID;
|
||||
TAOS_RETURN(code);
|
||||
} else {
|
||||
mInfo("connId:%u, is killed by user:%s", killReq.connId, pReq->info.conn.user);
|
||||
pConn->killed = 1;
|
||||
taosCacheRelease(pMgmt->connCache, (void **)&pConn, false);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -138,15 +138,16 @@ _OVER:
|
|||
}
|
||||
|
||||
static int32_t mndQnodeActionInsert(SSdb *pSdb, SQnodeObj *pObj) {
|
||||
int32_t code = 0;
|
||||
mTrace("qnode:%d, perform insert action, row:%p", pObj->id, pObj);
|
||||
pObj->pDnode = sdbAcquire(pSdb, SDB_DNODE, &pObj->id);
|
||||
if (pObj->pDnode == NULL) {
|
||||
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||
code = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||
mError("qnode:%d, failed to perform insert action since %s", pObj->id, terrstr());
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndQnodeActionDelete(SSdb *pSdb, SQnodeObj *pObj) {
|
||||
|
@ -166,27 +167,42 @@ static int32_t mndQnodeActionUpdate(SSdb *pSdb, SQnodeObj *pOld, SQnodeObj *pNew
|
|||
}
|
||||
|
||||
static int32_t mndSetCreateQnodeRedoLogs(STrans *pTrans, SQnodeObj *pObj) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pRedoRaw = mndQnodeActionEncode(pObj);
|
||||
if (pRedoRaw == NULL) return -1;
|
||||
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING) != 0) return -1;
|
||||
return 0;
|
||||
if (pRedoRaw == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
TAOS_CHECK_RETURN(mndTransAppendRedolog(pTrans, pRedoRaw));
|
||||
TAOS_CHECK_RETURN(sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndSetCreateQnodeUndoLogs(STrans *pTrans, SQnodeObj *pObj) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pUndoRaw = mndQnodeActionEncode(pObj);
|
||||
if (pUndoRaw == NULL) return -1;
|
||||
if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
||||
return 0;
|
||||
if (pUndoRaw == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
TAOS_CHECK_RETURN(mndTransAppendUndolog(pTrans, pUndoRaw));
|
||||
TAOS_CHECK_RETURN(sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t mndSetCreateQnodeCommitLogs(STrans *pTrans, SQnodeObj *pObj) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pCommitRaw = mndQnodeActionEncode(pObj);
|
||||
if (pCommitRaw == NULL) return -1;
|
||||
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1;
|
||||
return 0;
|
||||
if (pCommitRaw == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
TAOS_CHECK_RETURN(mndTransAppendCommitlog(pTrans, pCommitRaw));
|
||||
TAOS_CHECK_RETURN(sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
bool mndQnodeInDnode(SQnodeObj *pQnode, int32_t dnodeId) {
|
||||
|
@ -194,6 +210,7 @@ bool mndQnodeInDnode(SQnodeObj *pQnode, int32_t dnodeId) {
|
|||
}
|
||||
|
||||
int32_t mndSetCreateQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) {
|
||||
int32_t code = 0;
|
||||
SDCreateQnodeReq createReq = {0};
|
||||
createReq.dnodeId = pDnode->id;
|
||||
|
||||
|
@ -212,23 +229,24 @@ int32_t mndSetCreateQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeOb
|
|||
action.msgType = TDMT_DND_CREATE_QNODE;
|
||||
action.acceptableCode = TSDB_CODE_QNODE_ALREADY_DEPLOYED;
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndSetCreateQnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) {
|
||||
int32_t code = 0;
|
||||
SDDropQnodeReq dropReq = {0};
|
||||
dropReq.dnodeId = pDnode->id;
|
||||
|
||||
int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
|
||||
void *pReq = taosMemoryMalloc(contLen);
|
||||
if (pReq == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
|
||||
|
||||
|
@ -239,12 +257,12 @@ static int32_t mndSetCreateQnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, S
|
|||
action.msgType = TDMT_DND_DROP_QNODE;
|
||||
action.acceptableCode = TSDB_CODE_QNODE_NOT_DEPLOYED;
|
||||
|
||||
if (mndTransAppendUndoAction(pTrans, &action) != 0) {
|
||||
if ((code = mndTransAppendUndoAction(pTrans, &action)) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndCreateQnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SMCreateQnodeReq *pCreate) {
|
||||
|
@ -256,22 +274,26 @@ static int32_t mndCreateQnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode,
|
|||
qnodeObj.updateTime = qnodeObj.createdTime;
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pReq, "create-qnode");
|
||||
if (pTrans == NULL) goto _OVER;
|
||||
if (pTrans == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
goto _OVER;
|
||||
}
|
||||
mndTransSetSerial(pTrans);
|
||||
|
||||
mInfo("trans:%d, used to create qnode:%d", pTrans->id, pCreate->dnodeId);
|
||||
if (mndSetCreateQnodeRedoLogs(pTrans, &qnodeObj) != 0) goto _OVER;
|
||||
if (mndSetCreateQnodeUndoLogs(pTrans, &qnodeObj) != 0) goto _OVER;
|
||||
if (mndSetCreateQnodeCommitLogs(pTrans, &qnodeObj) != 0) goto _OVER;
|
||||
if (mndSetCreateQnodeRedoActions(pTrans, pDnode, &qnodeObj) != 0) goto _OVER;
|
||||
if (mndSetCreateQnodeUndoActions(pTrans, pDnode, &qnodeObj) != 0) goto _OVER;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
TAOS_CHECK_GOTO(mndSetCreateQnodeRedoLogs(pTrans, &qnodeObj), NULL, _OVER);
|
||||
TAOS_CHECK_GOTO(mndSetCreateQnodeUndoLogs(pTrans, &qnodeObj), NULL, _OVER);
|
||||
TAOS_CHECK_GOTO(mndSetCreateQnodeCommitLogs(pTrans, &qnodeObj), NULL, _OVER);
|
||||
TAOS_CHECK_GOTO(mndSetCreateQnodeRedoActions(pTrans, pDnode, &qnodeObj), NULL, _OVER);
|
||||
TAOS_CHECK_GOTO(mndSetCreateQnodeUndoActions(pTrans, pDnode, &qnodeObj), NULL, _OVER);
|
||||
TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
|
||||
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
mndTransDrop(pTrans);
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndProcessCreateQnodeReq(SRpcMsg *pReq) {
|
||||
|
@ -281,19 +303,14 @@ static int32_t mndProcessCreateQnodeReq(SRpcMsg *pReq) {
|
|||
SDnodeObj *pDnode = NULL;
|
||||
SMCreateQnodeReq createReq = {0};
|
||||
|
||||
if (tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &createReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
goto _OVER;
|
||||
}
|
||||
TAOS_CHECK_GOTO(tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &createReq), NULL, _OVER);
|
||||
|
||||
mInfo("qnode:%d, start to create", createReq.dnodeId);
|
||||
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CREATE_QNODE) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
TAOS_CHECK_GOTO(mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CREATE_QNODE), NULL, _OVER);
|
||||
|
||||
pObj = mndAcquireQnode(pMnode, createReq.dnodeId);
|
||||
if (pObj != NULL) {
|
||||
terrno = TSDB_CODE_MND_QNODE_ALREADY_EXIST;
|
||||
code = TSDB_CODE_MND_QNODE_ALREADY_EXIST;
|
||||
goto _OVER;
|
||||
} else if (terrno != TSDB_CODE_MND_QNODE_NOT_EXIST) {
|
||||
goto _OVER;
|
||||
|
@ -301,7 +318,7 @@ static int32_t mndProcessCreateQnodeReq(SRpcMsg *pReq) {
|
|||
|
||||
pDnode = mndAcquireDnode(pMnode, createReq.dnodeId);
|
||||
if (pDnode == NULL) {
|
||||
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||
code = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -320,34 +337,47 @@ _OVER:
|
|||
mndReleaseQnode(pMnode, pObj);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
tFreeSMCreateQnodeReq(&createReq);
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndSetDropQnodeRedoLogs(STrans *pTrans, SQnodeObj *pObj) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pRedoRaw = mndQnodeActionEncode(pObj);
|
||||
if (pRedoRaw == NULL) return -1;
|
||||
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1;
|
||||
return 0;
|
||||
if (pRedoRaw == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
TAOS_CHECK_RETURN(mndTransAppendRedolog(pTrans, pRedoRaw));
|
||||
TAOS_CHECK_RETURN(sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndSetDropQnodeCommitLogs(STrans *pTrans, SQnodeObj *pObj) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pCommitRaw = mndQnodeActionEncode(pObj);
|
||||
if (pCommitRaw == NULL) return -1;
|
||||
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
||||
return 0;
|
||||
if (pCommitRaw == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (mndTransAppendCommitlog(pTrans, pCommitRaw))
|
||||
;
|
||||
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED))
|
||||
;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndSetDropQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) {
|
||||
int32_t code = 0;
|
||||
SDDropQnodeReq dropReq = {0};
|
||||
dropReq.dnodeId = pDnode->id;
|
||||
|
||||
int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, &dropReq);
|
||||
void *pReq = taosMemoryMalloc(contLen);
|
||||
if (pReq == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
|
||||
|
||||
|
@ -358,20 +388,20 @@ static int32_t mndSetDropQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQn
|
|||
action.msgType = TDMT_DND_DROP_QNODE;
|
||||
action.acceptableCode = TSDB_CODE_QNODE_NOT_DEPLOYED;
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
if ((code = mndTransAppendRedoAction(pTrans, &action)) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t mndSetDropQnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SQnodeObj *pObj, bool force) {
|
||||
if (pObj == NULL) return 0;
|
||||
if (mndSetDropQnodeRedoLogs(pTrans, pObj) != 0) return -1;
|
||||
if (mndSetDropQnodeCommitLogs(pTrans, pObj) != 0) return -1;
|
||||
TAOS_CHECK_RETURN(mndSetDropQnodeRedoLogs(pTrans, pObj));
|
||||
TAOS_CHECK_RETURN(mndSetDropQnodeCommitLogs(pTrans, pObj));
|
||||
if (!force) {
|
||||
if (mndSetDropQnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) return -1;
|
||||
TAOS_CHECK_RETURN(mndSetDropQnodeRedoActions(pTrans, pObj->pDnode, pObj));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -380,18 +410,22 @@ static int32_t mndDropQnode(SMnode *pMnode, SRpcMsg *pReq, SQnodeObj *pObj) {
|
|||
int32_t code = -1;
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, pReq, "drop-qnode");
|
||||
if (pTrans == NULL) goto _OVER;
|
||||
if (pTrans == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
goto _OVER;
|
||||
}
|
||||
mndTransSetSerial(pTrans);
|
||||
|
||||
mInfo("trans:%d, used to drop qnode:%d", pTrans->id, pObj->id);
|
||||
if (mndSetDropQnodeInfoToTrans(pMnode, pTrans, pObj, false) != 0) goto _OVER;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
TAOS_CHECK_GOTO(mndSetDropQnodeInfoToTrans(pMnode, pTrans, pObj, false), NULL, _OVER);
|
||||
TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
|
||||
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
mndTransDrop(pTrans);
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndProcessDropQnodeReq(SRpcMsg *pReq) {
|
||||
|
@ -400,23 +434,20 @@ static int32_t mndProcessDropQnodeReq(SRpcMsg *pReq) {
|
|||
SQnodeObj *pObj = NULL;
|
||||
SMDropQnodeReq dropReq = {0};
|
||||
|
||||
if (tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
goto _OVER;
|
||||
}
|
||||
TAOS_CHECK_GOTO(tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &dropReq), NULL, _OVER);
|
||||
|
||||
mInfo("qnode:%d, start to drop", dropReq.dnodeId);
|
||||
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_QNODE) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
TAOS_CHECK_GOTO(mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_QNODE), NULL, _OVER);
|
||||
|
||||
if (dropReq.dnodeId <= 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pObj = mndAcquireQnode(pMnode, dropReq.dnodeId);
|
||||
if (pObj == NULL) {
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -435,10 +466,11 @@ _OVER:
|
|||
|
||||
mndReleaseQnode(pMnode, pObj);
|
||||
tFreeSDDropQnodeReq(&dropReq);
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t mndCreateQnodeList(SMnode *pMnode, SArray **pList, int32_t limit) {
|
||||
int32_t code = 0;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
void *pIter = NULL;
|
||||
SQnodeObj *pObj = NULL;
|
||||
|
@ -447,8 +479,8 @@ int32_t mndCreateQnodeList(SMnode *pMnode, SArray **pList, int32_t limit) {
|
|||
SArray *qnodeList = taosArrayInit(5, sizeof(SQueryNodeLoad));
|
||||
if (NULL == qnodeList) {
|
||||
mError("failed to alloc epSet while process qnode list req");
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
|
@ -484,20 +516,14 @@ static int32_t mndProcessQnodeListReq(SRpcMsg *pReq) {
|
|||
SQnodeListReq qlistReq = {0};
|
||||
SQnodeListRsp qlistRsp = {0};
|
||||
|
||||
if (tDeserializeSQnodeListReq(pReq->pCont, pReq->contLen, &qlistReq) != 0) {
|
||||
mError("failed to parse qnode list req");
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
goto _OVER;
|
||||
}
|
||||
TAOS_CHECK_GOTO(tDeserializeSQnodeListReq(pReq->pCont, pReq->contLen, &qlistReq), NULL, _OVER);
|
||||
|
||||
if (mndCreateQnodeList(pMnode, &qlistRsp.qnodeList, qlistReq.rowNum) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
TAOS_CHECK_GOTO(mndCreateQnodeList(pMnode, &qlistRsp.qnodeList, qlistReq.rowNum), NULL, _OVER);
|
||||
|
||||
int32_t rspLen = tSerializeSQnodeListRsp(NULL, 0, &qlistRsp);
|
||||
void *pRsp = rpcMallocCont(rspLen);
|
||||
if (pRsp == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -509,7 +535,7 @@ static int32_t mndProcessQnodeListReq(SRpcMsg *pReq) {
|
|||
|
||||
_OVER:
|
||||
tFreeSQnodeListRsp(&qlistRsp);
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndRetrieveQnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
||||
|
|
|
@ -88,7 +88,7 @@ int32_t mndProcessBatchMetaMsg(SRpcMsg *pMsg) {
|
|||
void *pRsp = NULL;
|
||||
SMnode *pMnode = pMsg->info.node;
|
||||
|
||||
if (tDeserializeSBatchReq(pMsg->pCont, pMsg->contLen, &batchReq)) {
|
||||
if ((code = tDeserializeSBatchReq(pMsg->pCont, pMsg->contLen, &batchReq)) != 0) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("tDeserializeSBatchReq failed");
|
||||
goto _exit;
|
||||
|
@ -119,7 +119,7 @@ int32_t mndProcessBatchMetaMsg(SRpcMsg *pMsg) {
|
|||
MndMsgFp fp = pMnode->msgFp[TMSG_INDEX(req->msgType)];
|
||||
if (fp == NULL) {
|
||||
mError("msg:%p, failed to get msg handle, app:%p type:%s", pMsg, pMsg->info.ahandle, TMSG_INFO(pMsg->msgType));
|
||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
code = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
taosArrayDestroy(batchRsp.pRsps);
|
||||
return -1;
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ _exit:
|
|||
taosArrayDestroyEx(batchReq.pMsgs, tFreeSBatchReqMsg);
|
||||
taosArrayDestroyEx(batchRsp.pRsps, mnodeFreeSBatchRspMsg);
|
||||
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t mndInitQuery(SMnode *pMnode) {
|
||||
|
|
|
@ -50,17 +50,17 @@ static bool isCountWindowStreamTask(SSubplan* pPlan) {
|
|||
|
||||
int32_t mndConvertRsmaTask(char** pDst, int32_t* pDstLen, const char* ast, int64_t uid, int8_t triggerType,
|
||||
int64_t watermark, int64_t deleteMark) {
|
||||
int32_t code = 0;
|
||||
SNode* pAst = NULL;
|
||||
SQueryPlan* pPlan = NULL;
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
|
||||
if (nodesStringToNode(ast, &pAst) < 0) {
|
||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
code = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
goto END;
|
||||
}
|
||||
|
||||
if (qSetSTableIdForRsma(pAst, uid) < 0) {
|
||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
code = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
goto END;
|
||||
}
|
||||
|
||||
|
@ -75,33 +75,33 @@ int32_t mndConvertRsmaTask(char** pDst, int32_t* pDstLen, const char* ast, int64
|
|||
};
|
||||
|
||||
if (qCreateQueryPlan(&cxt, &pPlan, NULL) < 0) {
|
||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
code = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
goto END;
|
||||
}
|
||||
|
||||
int32_t levelNum = LIST_LENGTH(pPlan->pSubplans);
|
||||
if (levelNum != 1) {
|
||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
code = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
goto END;
|
||||
}
|
||||
SNodeListNode* inner = (SNodeListNode*)nodesListGetNode(pPlan->pSubplans, 0);
|
||||
|
||||
int32_t opNum = LIST_LENGTH(inner->pNodeList);
|
||||
if (opNum != 1) {
|
||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
code = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
goto END;
|
||||
}
|
||||
|
||||
SSubplan* plan = (SSubplan*)nodesListGetNode(inner->pNodeList, 0);
|
||||
if (qSubPlanToString(plan, pDst, pDstLen) < 0) {
|
||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
code = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
goto END;
|
||||
}
|
||||
|
||||
END:
|
||||
if (pAst) nodesDestroyNode(pAst);
|
||||
if (pPlan) nodesDestroyNode((SNode*)pPlan);
|
||||
return terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t mndSetSinkTaskInfo(SStreamObj* pStream, SStreamTask* pTask) {
|
||||
|
@ -127,6 +127,7 @@ int32_t mndSetSinkTaskInfo(SStreamObj* pStream, SStreamTask* pTask) {
|
|||
|
||||
int32_t mndAddDispatcherForInternalTask(SMnode* pMnode, SStreamObj* pStream, SArray* pSinkNodeList,
|
||||
SStreamTask* pTask) {
|
||||
int32_t code = 0;
|
||||
bool isShuffle = false;
|
||||
|
||||
if (pStream->fixedSinkVgId == 0) {
|
||||
|
@ -135,9 +136,7 @@ int32_t mndAddDispatcherForInternalTask(SMnode* pMnode, SStreamObj* pStream, SAr
|
|||
isShuffle = true;
|
||||
pTask->outputInfo.type = TASK_OUTPUT__SHUFFLE_DISPATCH;
|
||||
pTask->msgInfo.msgType = TDMT_STREAM_TASK_DISPATCH;
|
||||
if (mndExtractDbInfo(pMnode, pDb, &pTask->outputInfo.shuffleDispatcher.dbInfo, NULL) < 0) {
|
||||
return -1;
|
||||
}
|
||||
TAOS_CHECK_RETURN(mndExtractDbInfo(pMnode, pDb, &pTask->outputInfo.shuffleDispatcher.dbInfo, NULL));
|
||||
}
|
||||
|
||||
sdbRelease(pMnode->pSdb, pDb);
|
||||
|
@ -166,7 +165,7 @@ int32_t mndAddDispatcherForInternalTask(SMnode* pMnode, SStreamObj* pStream, SAr
|
|||
streamTaskSetFixedDownstreamInfo(pTask, pOneSinkTask);
|
||||
}
|
||||
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t mndAssignStreamTaskToVgroup(SMnode* pMnode, SStreamTask* pTask, SSubplan* plan, const SVgObj* pVgroup) {
|
||||
|
@ -639,14 +638,15 @@ static void bindTwoLevel(SArray* tasks, int32_t begin, int32_t end) {
|
|||
|
||||
static int32_t doScheduleStream(SStreamObj* pStream, SMnode* pMnode, SQueryPlan* pPlan, SEpSet* pEpset, int64_t skey,
|
||||
SArray* pVerList) {
|
||||
int32_t code = 0;
|
||||
SSdb* pSdb = pMnode->pSdb;
|
||||
int32_t numOfPlanLevel = LIST_LENGTH(pPlan->pSubplans);
|
||||
bool hasExtraSink = false;
|
||||
bool externalTargetDB = strcmp(pStream->sourceDb, pStream->targetDb) != 0;
|
||||
SDbObj* pDbObj = mndAcquireDb(pMnode, pStream->targetDb);
|
||||
if (pDbObj == NULL) {
|
||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
return -1;
|
||||
code = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
bool multiTarget = (pDbObj->cfg.numOfVgroups > 1);
|
||||
|
@ -670,9 +670,11 @@ static int32_t doScheduleStream(SStreamObj* pStream, SMnode* pMnode, SQueryPlan*
|
|||
|
||||
SSubplan* plan = getScanSubPlan(pPlan); // source plan
|
||||
if (plan == NULL) {
|
||||
return terrno;
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
int32_t code = addSourceTask(pMnode, plan, pStream, pEpset, skey, pVerList, numOfPlanLevel == 1);
|
||||
code = addSourceTask(pMnode, plan, pStream, pEpset, skey, pVerList, numOfPlanLevel == 1);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
@ -688,7 +690,9 @@ static int32_t doScheduleStream(SStreamObj* pStream, SMnode* pMnode, SQueryPlan*
|
|||
if (numOfPlanLevel == 3) {
|
||||
plan = getAggSubPlan(pPlan, 1); // middle agg plan
|
||||
if (plan == NULL) {
|
||||
return terrno;
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
do {
|
||||
SArray** list = taosArrayGetLast(pStream->tasks);
|
||||
|
@ -715,7 +719,9 @@ static int32_t doScheduleStream(SStreamObj* pStream, SMnode* pMnode, SQueryPlan*
|
|||
|
||||
plan = getAggSubPlan(pPlan, 0);
|
||||
if (plan == NULL) {
|
||||
return terrno;
|
||||
code = TSDB_CODE_MND_RETURN_VALUE_NULL;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
mDebug("doScheduleStream add final agg");
|
||||
|
@ -724,7 +730,7 @@ static int32_t doScheduleStream(SStreamObj* pStream, SMnode* pMnode, SQueryPlan*
|
|||
addNewTaskList(pStream);
|
||||
code = addAggTask(pStream, pMnode, plan, pEpset, true);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
bindTwoLevel(pStream->tasks, 0, size);
|
||||
if (pStream->conf.fillHistory) {
|
||||
|
@ -735,26 +741,28 @@ static int32_t doScheduleStream(SStreamObj* pStream, SMnode* pMnode, SQueryPlan*
|
|||
if (pStream->conf.fillHistory) {
|
||||
bindAggSink(pStream, pMnode, pStream->pHTasksList);
|
||||
}
|
||||
return TDB_CODE_SUCCESS;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t mndScheduleStream(SMnode* pMnode, SStreamObj* pStream, int64_t skey, SArray* pVgVerList) {
|
||||
int32_t code = 0;
|
||||
SQueryPlan* pPlan = qStringToQueryPlan(pStream->physicalPlan);
|
||||
if (pPlan == NULL) {
|
||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
return -1;
|
||||
code = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
SEpSet mnodeEpset = {0};
|
||||
mndGetMnodeEpSet(pMnode, &mnodeEpset);
|
||||
|
||||
int32_t code = doScheduleStream(pStream, pMnode, pPlan, &mnodeEpset, skey, pVgVerList);
|
||||
code = doScheduleStream(pStream, pMnode, pPlan, &mnodeEpset, skey, pVgVerList);
|
||||
qDestroyQueryPlan(pPlan);
|
||||
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscribeObj* pSub) {
|
||||
int32_t code = 0;
|
||||
SSdb* pSdb = pMnode->pSdb;
|
||||
SVgObj* pVgroup = NULL;
|
||||
SQueryPlan* pPlan = NULL;
|
||||
|
@ -763,21 +771,21 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
|
|||
if (pTopic->subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||
pPlan = qStringToQueryPlan(pTopic->physicalPlan);
|
||||
if (pPlan == NULL) {
|
||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
return -1;
|
||||
code = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
} else if (pTopic->subType == TOPIC_SUB_TYPE__TABLE && pTopic->ast != NULL) {
|
||||
SNode* pAst = NULL;
|
||||
if (nodesStringToNode(pTopic->ast, &pAst) != 0) {
|
||||
if ((code = nodesStringToNode(pTopic->ast, &pAst)) != 0) {
|
||||
mError("topic:%s, failed to create since %s", pTopic->name, terrstr());
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
SPlanContext cxt = {.pAstRoot = pAst, .topicQuery = true};
|
||||
if (qCreateQueryPlan(&cxt, &pPlan, NULL) != 0) {
|
||||
if ((code = qCreateQueryPlan(&cxt, &pPlan, NULL)) != 0) {
|
||||
mError("failed to create topic:%s since %s", pTopic->name, terrstr());
|
||||
nodesDestroyNode(pAst);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
nodesDestroyNode(pAst);
|
||||
}
|
||||
|
@ -786,8 +794,8 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
|
|||
int32_t levelNum = LIST_LENGTH(pPlan->pSubplans);
|
||||
if (levelNum != 1) {
|
||||
qDestroyQueryPlan(pPlan);
|
||||
terrno = TSDB_CODE_MND_INVALID_TOPIC_QUERY;
|
||||
return -1;
|
||||
code = TSDB_CODE_MND_INVALID_TOPIC_QUERY;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
SNodeListNode* pNodeListNode = (SNodeListNode*)nodesListGetNode(pPlan->pSubplans, 0);
|
||||
|
@ -795,8 +803,8 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
|
|||
int32_t opNum = LIST_LENGTH(pNodeListNode->pNodeList);
|
||||
if (opNum != 1) {
|
||||
qDestroyQueryPlan(pPlan);
|
||||
terrno = TSDB_CODE_MND_INVALID_TOPIC_QUERY;
|
||||
return -1;
|
||||
code = TSDB_CODE_MND_INVALID_TOPIC_QUERY;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
pSubplan = (SSubplan*)nodesListGetNode(pNodeListNode->pNodeList, 0);
|
||||
|
@ -831,13 +839,13 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
|
|||
|
||||
if (qSubPlanToString(pSubplan, &pSub->qmsg, &msgLen) < 0) {
|
||||
qDestroyQueryPlan(pPlan);
|
||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
return -1;
|
||||
code = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
} else {
|
||||
pSub->qmsg = taosStrdup("");
|
||||
}
|
||||
|
||||
qDestroyQueryPlan(pPlan);
|
||||
return 0;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
|
|
@ -61,6 +61,7 @@ int32_t sndBuildStreamTask(SSnode *pSnode, SStreamTask *pTask, int64_t nextProce
|
|||
}
|
||||
|
||||
SSnode *sndOpen(const char *path, const SSnodeOpt *pOption) {
|
||||
int32_t code = 0;
|
||||
SSnode *pSnode = taosMemoryCalloc(1, sizeof(SSnode));
|
||||
if (pSnode == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -68,12 +69,17 @@ SSnode *sndOpen(const char *path, const SSnodeOpt *pOption) {
|
|||
}
|
||||
|
||||
stopRsync();
|
||||
startRsync();
|
||||
code = startRsync();
|
||||
if (code != 0) {
|
||||
terrno = code;
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
pSnode->msgCb = pOption->msgCb;
|
||||
int32_t code = streamMetaOpen(path, pSnode, (FTaskBuild *)sndBuildStreamTask, tqExpandStreamTask, SNODE_HANDLE,
|
||||
taosGetTimestampMs(), tqStartTaskCompleteCallback, &pSnode->pMeta);
|
||||
code = streamMetaOpen(path, pSnode, (FTaskBuild *)sndBuildStreamTask, tqExpandStreamTask, SNODE_HANDLE,
|
||||
taosGetTimestampMs(), tqStartTaskCompleteCallback, &pSnode->pMeta);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
terrno = code;
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
|
|
|
@ -103,33 +103,31 @@ int32_t tqMetaSaveInfo(STQ* pTq, TTB* ttb, const void* key, int32_t kLen, const
|
|||
int32_t code = TDB_CODE_SUCCESS;
|
||||
TXN* txn = NULL;
|
||||
|
||||
TQ_ERR_RETURN(
|
||||
tdbBegin(pTq->pMetaDB, &txn, tdbDefaultMalloc, tdbDefaultFree, NULL, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED));
|
||||
TQ_ERR_RETURN(tdbTbUpsert(ttb, key, kLen, value, vLen, txn));
|
||||
TQ_ERR_RETURN(tdbCommit(pTq->pMetaDB, txn));
|
||||
TQ_ERR_RETURN(tdbPostCommit(pTq->pMetaDB, txn));
|
||||
TQ_ERR_GO_TO_END(tdbBegin(pTq->pMetaDB, &txn, tdbDefaultMalloc, tdbDefaultFree, NULL, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED));
|
||||
TQ_ERR_GO_TO_END(tdbTbUpsert(ttb, key, kLen, value, vLen, txn));
|
||||
TQ_ERR_GO_TO_END(tdbCommit(pTq->pMetaDB, txn));
|
||||
TQ_ERR_GO_TO_END(tdbPostCommit(pTq->pMetaDB, txn));
|
||||
|
||||
return 0;
|
||||
|
||||
END:
|
||||
tdbAbort(pTq->pMetaDB, txn);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tqMetaDeleteInfo(STQ* pTq, TTB* ttb, const void* key, int32_t kLen) {
|
||||
int32_t code = TDB_CODE_SUCCESS;
|
||||
TXN* txn = NULL;
|
||||
|
||||
TQ_ERR_RETURN(
|
||||
tdbBegin(pTq->pMetaDB, &txn, tdbDefaultMalloc, tdbDefaultFree, NULL, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED));
|
||||
TQ_ERR_RETURN(tdbTbDelete(ttb, key, kLen, txn));
|
||||
TQ_ERR_RETURN(tdbCommit(pTq->pMetaDB, txn));
|
||||
TQ_ERR_RETURN(tdbPostCommit(pTq->pMetaDB, txn));
|
||||
TQ_ERR_GO_TO_END(tdbBegin(pTq->pMetaDB, &txn, tdbDefaultMalloc, tdbDefaultFree, NULL, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED));
|
||||
TQ_ERR_GO_TO_END(tdbTbDelete(ttb, key, kLen, txn));
|
||||
TQ_ERR_GO_TO_END(tdbCommit(pTq->pMetaDB, txn));
|
||||
TQ_ERR_GO_TO_END(tdbPostCommit(pTq->pMetaDB, txn));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tqMetaTransformOffsetInfo(STQ* pTq, char* path) {
|
||||
int32_t code = TDB_CODE_SUCCESS;
|
||||
TQ_ERR_RETURN(tqOffsetRestoreFromFile(pTq, path));
|
||||
|
||||
END:
|
||||
tdbAbort(pTq->pMetaDB, txn);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -415,7 +413,8 @@ END:
|
|||
}
|
||||
|
||||
int32_t tqMetaOpen(STQ* pTq) {
|
||||
char* maindb = NULL;
|
||||
char* maindb = NULL;
|
||||
char* offsetNew = NULL;
|
||||
int32_t code = TDB_CODE_SUCCESS;
|
||||
TQ_ERR_GO_TO_END(tqBuildFName(&maindb, pTq->path, TDB_MAINDB_NAME));
|
||||
if (!taosCheckExistFile(maindb)) {
|
||||
|
@ -423,12 +422,20 @@ int32_t tqMetaOpen(STQ* pTq) {
|
|||
TQ_ERR_GO_TO_END(tqMetaOpenTdb(pTq));
|
||||
} else {
|
||||
TQ_ERR_GO_TO_END(tqMetaTransform(pTq));
|
||||
taosRemoveFile(maindb);
|
||||
(void)taosRemoveFile(maindb);
|
||||
}
|
||||
|
||||
TQ_ERR_GO_TO_END(tqBuildFName(&offsetNew, pTq->path, TQ_OFFSET_NAME));
|
||||
if(taosCheckExistFile(offsetNew)){
|
||||
TQ_ERR_GO_TO_END(tqOffsetRestoreFromFile(pTq, offsetNew));
|
||||
(void)taosRemoveFile(offsetNew);
|
||||
}
|
||||
|
||||
TQ_ERR_GO_TO_END(tqMetaRestoreCheckInfo(pTq));
|
||||
|
||||
END:
|
||||
taosMemoryFree(maindb);
|
||||
taosMemoryFree(offsetNew);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -452,13 +459,14 @@ int32_t tqMetaTransform(STQ* pTq) {
|
|||
TQ_ERR_GO_TO_END(tqMetaTransformInfo(pTq->pMetaDB, pCheckStore, pTq->pCheckStore));
|
||||
|
||||
TQ_ERR_GO_TO_END(tqBuildFName(&offsetNew, pTq->path, TQ_OFFSET_NAME));
|
||||
if (taosCheckExistFile(offset) && taosCopyFile(offset, offsetNew) < 0) {
|
||||
tqError("copy offset file error");
|
||||
}
|
||||
|
||||
TQ_ERR_GO_TO_END(tqMetaTransformOffsetInfo(pTq, offsetNew));
|
||||
(void)taosRemoveFile(offset);
|
||||
(void)taosRemoveFile(offsetNew);
|
||||
if(taosCheckExistFile(offset)) {
|
||||
if (taosCopyFile(offset, offsetNew) < 0) {
|
||||
tqError("copy offset file error");
|
||||
} else {
|
||||
(void)taosRemoveFile(offset);
|
||||
}
|
||||
}
|
||||
|
||||
END:
|
||||
taosMemoryFree(offset);
|
||||
|
|
|
@ -73,6 +73,7 @@ int32_t tqOffsetRestoreFromFile(STQ* pTq, char* name) {
|
|||
}
|
||||
TQ_ERR_GO_TO_END(tqMetaSaveInfo(pTq, pTq->pOffsetStore, offset.subKey, strlen(offset.subKey), pMemBuf, size));
|
||||
|
||||
tqInfo("tq: offset restore from file to tdb, subkey:%s", offset.subKey);
|
||||
taosMemoryFree(pMemBuf);
|
||||
pMemBuf = NULL;
|
||||
}
|
||||
|
|
|
@ -446,7 +446,8 @@ int32_t ctgGetTbTag(SCatalog* pCtg, SRequestConnInfo* pConn, SName* pTableName,
|
|||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
char* pJson = parseTagDatatoJson(pTag);
|
||||
char* pJson = NULL;
|
||||
parseTagDatatoJson(pTag, &pJson);
|
||||
STagVal tagVal;
|
||||
tagVal.cid = 0;
|
||||
tagVal.type = TSDB_DATA_TYPE_JSON;
|
||||
|
|
|
@ -2079,7 +2079,8 @@ int32_t ctgHandleGetTbTagRsp(SCtgTaskReq* tReq, int32_t reqType, const SDataBuf*
|
|||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
char* pJson = parseTagDatatoJson(pTag);
|
||||
char* pJson = NULL;
|
||||
parseTagDatatoJson(pTag, &pJson);
|
||||
STagVal tagVal;
|
||||
tagVal.cid = 0;
|
||||
tagVal.type = TSDB_DATA_TYPE_JSON;
|
||||
|
|
|
@ -23,6 +23,15 @@
|
|||
#include "tglobal.h"
|
||||
#include "tgrant.h"
|
||||
|
||||
#define COL_DATA_SET_VAL_AND_CHECK(pCol, rows, buf, isNull) \
|
||||
do { \
|
||||
int _code = colDataSetVal(pCol, rows, buf, isNull);\
|
||||
if (TSDB_CODE_SUCCESS != _code) { \
|
||||
terrno = _code; \
|
||||
return _code; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
extern SConfig* tsCfg;
|
||||
|
||||
static int32_t buildRetrieveTableRsp(SSDataBlock* pBlock, int32_t numOfCols, SRetrieveTableRsp** pRsp) {
|
||||
|
@ -100,7 +109,7 @@ static int32_t buildDescResultDataBlock(SSDataBlock** pOutput) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pOutput = pBlock;
|
||||
} else {
|
||||
blockDataDestroy(pBlock);
|
||||
(void)blockDataDestroy(pBlock);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -108,7 +117,7 @@ static int32_t buildDescResultDataBlock(SSDataBlock** pOutput) {
|
|||
static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock, int32_t numOfRows, STableMeta* pMeta,
|
||||
int8_t biMode) {
|
||||
int32_t blockCap = (biMode != 0) ? numOfRows + 1 : numOfRows;
|
||||
blockDataEnsureCapacity(pBlock, blockCap);
|
||||
QRY_ERR_RET(blockDataEnsureCapacity(pBlock, blockCap));
|
||||
pBlock->info.rows = 0;
|
||||
|
||||
// field
|
||||
|
@ -138,11 +147,12 @@ static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock,
|
|||
continue;
|
||||
}
|
||||
STR_TO_VARSTR(buf, pMeta->schema[i].name);
|
||||
colDataSetVal(pCol1, pBlock->info.rows, buf, false);
|
||||
COL_DATA_SET_VAL_AND_CHECK(pCol1, pBlock->info.rows, buf, false);
|
||||
|
||||
STR_TO_VARSTR(buf, tDataTypes[pMeta->schema[i].type].name);
|
||||
colDataSetVal(pCol2, pBlock->info.rows, buf, false);
|
||||
COL_DATA_SET_VAL_AND_CHECK(pCol2, pBlock->info.rows, buf, false);
|
||||
int32_t bytes = getSchemaBytes(pMeta->schema + i);
|
||||
colDataSetVal(pCol3, pBlock->info.rows, (const char*)&bytes, false);
|
||||
COL_DATA_SET_VAL_AND_CHECK(pCol3, pBlock->info.rows, (const char*)&bytes, false);
|
||||
if (TSDB_VIEW_TABLE != pMeta->tableType) {
|
||||
if (i >= pMeta->tableInfo.numOfColumns) {
|
||||
STR_TO_VARSTR(buf, "TAG");
|
||||
|
@ -155,22 +165,22 @@ static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock,
|
|||
} else {
|
||||
STR_TO_VARSTR(buf, "VIEW COL");
|
||||
}
|
||||
colDataSetVal(pCol4, pBlock->info.rows, buf, false);
|
||||
COL_DATA_SET_VAL_AND_CHECK(pCol4, pBlock->info.rows, buf, false);
|
||||
if (useCompress(pMeta->tableType) && pMeta->schemaExt) {
|
||||
if (i < pMeta->tableInfo.numOfColumns) {
|
||||
STR_TO_VARSTR(buf, columnEncodeStr(COMPRESS_L1_TYPE_U32(pMeta->schemaExt[i].compress)));
|
||||
colDataSetVal(pCol5, pBlock->info.rows, buf, false);
|
||||
COL_DATA_SET_VAL_AND_CHECK(pCol5, pBlock->info.rows, buf, false);
|
||||
STR_TO_VARSTR(buf, columnCompressStr(COMPRESS_L2_TYPE_U32(pMeta->schemaExt[i].compress)));
|
||||
colDataSetVal(pCol6, pBlock->info.rows, buf, false);
|
||||
COL_DATA_SET_VAL_AND_CHECK(pCol6, pBlock->info.rows, buf, false);
|
||||
STR_TO_VARSTR(buf, columnLevelStr(COMPRESS_L2_TYPE_LEVEL_U32(pMeta->schemaExt[i].compress)));
|
||||
colDataSetVal(pCol7, pBlock->info.rows, buf, false);
|
||||
COL_DATA_SET_VAL_AND_CHECK(pCol7, pBlock->info.rows, buf, false);
|
||||
} else {
|
||||
STR_TO_VARSTR(buf, fillTagCol == 0 ? "" : "disabled");
|
||||
colDataSetVal(pCol5, pBlock->info.rows, buf, false);
|
||||
COL_DATA_SET_VAL_AND_CHECK(pCol5, pBlock->info.rows, buf, false);
|
||||
STR_TO_VARSTR(buf, fillTagCol == 0 ? "" : "disabled");
|
||||
colDataSetVal(pCol6, pBlock->info.rows, buf, false);
|
||||
COL_DATA_SET_VAL_AND_CHECK(pCol6, pBlock->info.rows, buf, false);
|
||||
STR_TO_VARSTR(buf, fillTagCol == 0 ? "" : "disabled");
|
||||
colDataSetVal(pCol7, pBlock->info.rows, buf, false);
|
||||
COL_DATA_SET_VAL_AND_CHECK(pCol7, pBlock->info.rows, buf, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -180,13 +190,13 @@ static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock,
|
|||
}
|
||||
if (pMeta->tableType == TSDB_SUPER_TABLE && biMode != 0) {
|
||||
STR_TO_VARSTR(buf, "tbname");
|
||||
colDataSetVal(pCol1, pBlock->info.rows, buf, false);
|
||||
COL_DATA_SET_VAL_AND_CHECK(pCol1, pBlock->info.rows, buf, false);
|
||||
STR_TO_VARSTR(buf, "VARCHAR");
|
||||
colDataSetVal(pCol2, pBlock->info.rows, buf, false);
|
||||
COL_DATA_SET_VAL_AND_CHECK(pCol2, pBlock->info.rows, buf, false);
|
||||
int32_t bytes = TSDB_TABLE_NAME_LEN - 1;
|
||||
colDataSetVal(pCol3, pBlock->info.rows, (const char*)&bytes, false);
|
||||
COL_DATA_SET_VAL_AND_CHECK(pCol3, pBlock->info.rows, (const char*)&bytes, false);
|
||||
STR_TO_VARSTR(buf, "TAG");
|
||||
colDataSetVal(pCol4, pBlock->info.rows, buf, false);
|
||||
COL_DATA_SET_VAL_AND_CHECK(pCol4, pBlock->info.rows, buf, false);
|
||||
++(pBlock->info.rows);
|
||||
}
|
||||
if (pBlock->info.rows <= 0) {
|
||||
|
@ -212,7 +222,7 @@ static int32_t execDescribe(bool sysInfoUser, SNode* pStmt, SRetrieveTableRsp**
|
|||
code = buildRetrieveTableRsp(pBlock, DESCRIBE_RESULT_COLS, pRsp);
|
||||
}
|
||||
}
|
||||
blockDataDestroy(pBlock);
|
||||
(void)blockDataDestroy(pBlock);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -234,7 +244,7 @@ static int32_t buildCreateDBResultDataBlock(SSDataBlock** pOutput) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pOutput = pBlock;
|
||||
} else {
|
||||
blockDataDestroy(pBlock);
|
||||
(void)blockDataDestroy(pBlock);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -264,13 +274,17 @@ int64_t getValOfDiffPrecision(int8_t unit, int64_t val) {
|
|||
return v;
|
||||
}
|
||||
|
||||
static char* buildRetension(SArray* pRetension) {
|
||||
static int32_t buildRetension(SArray* pRetension, char **ppRetentions ) {
|
||||
size_t size = taosArrayGetSize(pRetension);
|
||||
if (size == 0) {
|
||||
return NULL;
|
||||
*ppRetentions = NULL;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
char* p1 = taosMemoryCalloc(1, 100);
|
||||
if(NULL == p1) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
int32_t len = 0;
|
||||
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
|
@ -288,7 +302,8 @@ static char* buildRetension(SArray* pRetension) {
|
|||
}
|
||||
}
|
||||
|
||||
return p1;
|
||||
*ppRetentions = p1;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static const char* cacheModelStr(int8_t cacheModel) {
|
||||
|
@ -319,14 +334,14 @@ static const char* encryptAlgorithmStr(int8_t encryptAlgorithm) {
|
|||
return TSDB_CACHE_MODEL_NONE_STR;
|
||||
}
|
||||
|
||||
static void setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName, char* dbFName, SDbCfgInfo* pCfg) {
|
||||
blockDataEnsureCapacity(pBlock, 1);
|
||||
static int32_t setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName, char* dbFName, SDbCfgInfo* pCfg) {
|
||||
QRY_ERR_RET(blockDataEnsureCapacity(pBlock, 1));
|
||||
pBlock->info.rows = 1;
|
||||
|
||||
SColumnInfoData* pCol1 = taosArrayGet(pBlock->pDataBlock, 0);
|
||||
char buf1[SHOW_CREATE_DB_RESULT_FIELD1_LEN] = {0};
|
||||
STR_TO_VARSTR(buf1, dbName);
|
||||
colDataSetVal(pCol1, 0, buf1, false);
|
||||
COL_DATA_SET_VAL_AND_CHECK(pCol1, 0, buf1, false);
|
||||
|
||||
SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1);
|
||||
char buf2[SHOW_CREATE_DB_RESULT_FIELD2_LEN] = {0};
|
||||
|
@ -347,7 +362,8 @@ static void setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName, ch
|
|||
break;
|
||||
}
|
||||
|
||||
char* retentions = buildRetension(pCfg->pRetensions);
|
||||
char* pRetentions = NULL;
|
||||
QRY_ERR_RET(buildRetension(pCfg->pRetensions, &pRetentions));
|
||||
int32_t dbFNameLen = strlen(dbFName);
|
||||
int32_t hashPrefix = 0;
|
||||
if (pCfg->hashPrefix > 0) {
|
||||
|
@ -374,28 +390,30 @@ static void setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName, ch
|
|||
pCfg->keepTimeOffset, encryptAlgorithmStr(pCfg->encryptAlgorithm), pCfg->s3ChunkSize,
|
||||
pCfg->s3KeepLocal, pCfg->s3Compact);
|
||||
|
||||
if (retentions) {
|
||||
len += sprintf(buf2 + VARSTR_HEADER_SIZE + len, " RETENTIONS %s", retentions);
|
||||
if (pRetentions) {
|
||||
len += sprintf(buf2 + VARSTR_HEADER_SIZE + len, " RETENTIONS %s", pRetentions);
|
||||
}
|
||||
}
|
||||
|
||||
taosMemoryFree(retentions);
|
||||
taosMemoryFree(pRetentions);
|
||||
|
||||
(varDataLen(buf2)) = len;
|
||||
|
||||
colDataSetVal(pCol2, 0, buf2, false);
|
||||
COL_DATA_SET_VAL_AND_CHECK(pCol2, 0, buf2, false);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t execShowCreateDatabase(SShowCreateDatabaseStmt* pStmt, SRetrieveTableRsp** pRsp) {
|
||||
SSDataBlock* pBlock = NULL;
|
||||
int32_t code = buildCreateDBResultDataBlock(&pBlock);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
setCreateDBResultIntoDataBlock(pBlock, pStmt->dbName, pStmt->dbFName, pStmt->pCfg);
|
||||
code = setCreateDBResultIntoDataBlock(pBlock, pStmt->dbName, pStmt->dbFName, pStmt->pCfg);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = buildRetrieveTableRsp(pBlock, SHOW_CREATE_DB_RESULT_COLS, pRsp);
|
||||
}
|
||||
blockDataDestroy(pBlock);
|
||||
(void)blockDataDestroy(pBlock);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -415,7 +433,7 @@ static int32_t buildCreateTbResultDataBlock(SSDataBlock** pOutput) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pOutput = pBlock;
|
||||
} else {
|
||||
blockDataDestroy(pBlock);
|
||||
(void)blockDataDestroy(pBlock);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -436,7 +454,7 @@ static int32_t buildCreateViewResultDataBlock(SSDataBlock** pOutput) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pOutput = pBlock;
|
||||
} else {
|
||||
blockDataDestroy(pBlock);
|
||||
(void)blockDataDestroy(pBlock);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -494,6 +512,7 @@ void appendTagNameFields(char* buf, int32_t* len, STableCfg* pCfg) {
|
|||
}
|
||||
|
||||
int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SArray* pTagVals = NULL;
|
||||
STag* pTag = (STag*)pCfg->pTags;
|
||||
|
||||
|
@ -503,20 +522,15 @@ int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) {
|
|||
}
|
||||
|
||||
if (tTagIsJson(pTag)) {
|
||||
char* pJson = parseTagDatatoJson(pTag);
|
||||
if (pJson) {
|
||||
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "%s", pJson);
|
||||
taosMemoryFree(pJson);
|
||||
}
|
||||
char* pJson = NULL;
|
||||
parseTagDatatoJson(pTag, &pJson);
|
||||
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "%s", pJson);
|
||||
taosMemoryFree(pJson);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t code = tTagToValArray((const STag*)pCfg->pTags, &pTagVals);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
QRY_ERR_RET(tTagToValArray((const STag*)pCfg->pTags, &pTagVals));
|
||||
int16_t valueNum = taosArrayGetSize(pTagVals);
|
||||
int32_t num = 0;
|
||||
int32_t j = 0;
|
||||
|
@ -534,16 +548,18 @@ int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) {
|
|||
STagVal* pTagVal = (STagVal*)taosArrayGet(pTagVals, j);
|
||||
if (pSchema->colId > pTagVal->cid) {
|
||||
qError("tag value and column mismatch, schemaId:%d, valId:%d", pSchema->colId, pTagVal->cid);
|
||||
taosArrayDestroy(pTagVals);
|
||||
return TSDB_CODE_APP_ERROR;
|
||||
code = TSDB_CODE_APP_ERROR;
|
||||
TAOS_CHECK_ERRNO(code);
|
||||
} else if (pSchema->colId == pTagVal->cid) {
|
||||
char type = pTagVal->type;
|
||||
int32_t tlen = 0;
|
||||
|
||||
if (IS_VAR_DATA_TYPE(type)) {
|
||||
dataConverToStr(buf + VARSTR_HEADER_SIZE + *len, type, pTagVal->pData, pTagVal->nData, &tlen);
|
||||
code = dataConverToStr(buf + VARSTR_HEADER_SIZE + *len, type, pTagVal->pData, pTagVal->nData, &tlen);
|
||||
TAOS_CHECK_ERRNO(code);
|
||||
} else {
|
||||
dataConverToStr(buf + VARSTR_HEADER_SIZE + *len, type, &pTagVal->i64, tDataTypes[type].bytes, &tlen);
|
||||
code = dataConverToStr(buf + VARSTR_HEADER_SIZE + *len, type, &pTagVal->i64, tDataTypes[type].bytes, &tlen);
|
||||
TAOS_CHECK_ERRNO(code);
|
||||
}
|
||||
*len += tlen;
|
||||
j++;
|
||||
|
@ -580,9 +596,10 @@ int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) {
|
|||
*/
|
||||
}
|
||||
|
||||
_exit:
|
||||
taosArrayDestroy(pTagVals);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
return code;
|
||||
}
|
||||
|
||||
void appendTableOptions(char* buf, int32_t* len, SDbCfgInfo* pDbCfg, STableCfg* pCfg) {
|
||||
|
@ -647,20 +664,19 @@ void appendTableOptions(char* buf, int32_t* len, SDbCfgInfo* pDbCfg, STableCfg*
|
|||
}
|
||||
|
||||
static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, SDbCfgInfo* pDbCfg, char* tbName, STableCfg* pCfg) {
|
||||
int32_t code = 0;
|
||||
blockDataEnsureCapacity(pBlock, 1);
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
QRY_ERR_RET(blockDataEnsureCapacity(pBlock, 1));
|
||||
pBlock->info.rows = 1;
|
||||
|
||||
SColumnInfoData* pCol1 = taosArrayGet(pBlock->pDataBlock, 0);
|
||||
char buf1[SHOW_CREATE_TB_RESULT_FIELD1_LEN] = {0};
|
||||
STR_TO_VARSTR(buf1, tbName);
|
||||
colDataSetVal(pCol1, 0, buf1, false);
|
||||
QRY_ERR_RET(colDataSetVal(pCol1, 0, buf1, false));
|
||||
|
||||
SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1);
|
||||
char* buf2 = taosMemoryMalloc(SHOW_CREATE_TB_RESULT_FIELD2_LEN);
|
||||
if (NULL == buf2) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
QRY_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
int32_t len = 0;
|
||||
|
@ -677,10 +693,7 @@ static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, SDbCfgInfo* p
|
|||
appendTagNameFields(buf2, &len, pCfg);
|
||||
len += sprintf(buf2 + VARSTR_HEADER_SIZE + len, ") TAGS (");
|
||||
code = appendTagValues(buf2, &len, pCfg);
|
||||
if (code) {
|
||||
taosMemoryFree(buf2);
|
||||
return code;
|
||||
}
|
||||
TAOS_CHECK_ERRNO(code);
|
||||
len += sprintf(buf2 + VARSTR_HEADER_SIZE + len, ")");
|
||||
appendTableOptions(buf2, &len, pDbCfg, pCfg);
|
||||
} else {
|
||||
|
@ -692,29 +705,30 @@ static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, SDbCfgInfo* p
|
|||
|
||||
varDataLen(buf2) = (len > 65535) ? 65535 : len;
|
||||
|
||||
colDataSetVal(pCol2, 0, buf2, false);
|
||||
code = colDataSetVal(pCol2, 0, buf2, false);
|
||||
TAOS_CHECK_ERRNO(code);
|
||||
|
||||
_exit:
|
||||
taosMemoryFree(buf2);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t setCreateViewResultIntoDataBlock(SSDataBlock* pBlock, SShowCreateViewStmt* pStmt) {
|
||||
int32_t code = 0;
|
||||
blockDataEnsureCapacity(pBlock, 1);
|
||||
QRY_ERR_RET(blockDataEnsureCapacity(pBlock, 1));
|
||||
pBlock->info.rows = 1;
|
||||
|
||||
SColumnInfoData* pCol1 = taosArrayGet(pBlock->pDataBlock, 0);
|
||||
char buf1[SHOW_CREATE_VIEW_RESULT_FIELD1_LEN + 1] = {0};
|
||||
snprintf(varDataVal(buf1), TSDB_VIEW_FNAME_LEN + 4, "`%s`.`%s`", pStmt->dbName, pStmt->viewName);
|
||||
varDataSetLen(buf1, strlen(varDataVal(buf1)));
|
||||
colDataSetVal(pCol1, 0, buf1, false);
|
||||
QRY_ERR_RET(colDataSetVal(pCol1, 0, buf1, false));
|
||||
|
||||
SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1);
|
||||
char* buf2 = taosMemoryMalloc(SHOW_CREATE_VIEW_RESULT_FIELD2_LEN);
|
||||
if (NULL == buf2) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
QRY_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
SViewMeta* pMeta = pStmt->pViewMeta;
|
||||
|
@ -723,11 +737,10 @@ static int32_t setCreateViewResultIntoDataBlock(SSDataBlock* pBlock, SShowCreate
|
|||
pStmt->dbName, pStmt->viewName, pMeta->querySql);
|
||||
int32_t len = strlen(varDataVal(buf2));
|
||||
varDataLen(buf2) = (len > 65535) ? 65535 : len;
|
||||
colDataSetVal(pCol2, 0, buf2, false);
|
||||
|
||||
code = colDataSetVal(pCol2, 0, buf2, false);
|
||||
taosMemoryFree(buf2);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t execShowCreateTable(SShowCreateTableStmt* pStmt, SRetrieveTableRsp** pRsp) {
|
||||
|
@ -739,7 +752,7 @@ static int32_t execShowCreateTable(SShowCreateTableStmt* pStmt, SRetrieveTableRs
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = buildRetrieveTableRsp(pBlock, SHOW_CREATE_TB_RESULT_COLS, pRsp);
|
||||
}
|
||||
blockDataDestroy(pBlock);
|
||||
(void)blockDataDestroy(pBlock);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -832,23 +845,39 @@ static int32_t buildLocalVariablesResultDataBlock(SSDataBlock** pOutput) {
|
|||
pBlock->info.hasVarCol = true;
|
||||
|
||||
pBlock->pDataBlock = taosArrayInit(SHOW_LOCAL_VARIABLES_RESULT_COLS, sizeof(SColumnInfoData));
|
||||
if (NULL == pBlock->pDataBlock) {
|
||||
taosMemoryFree(pBlock);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SColumnInfoData infoData = {0};
|
||||
|
||||
infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
|
||||
infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD1_LEN;
|
||||
taosArrayPush(pBlock->pDataBlock, &infoData);
|
||||
if(taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) {
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
|
||||
infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD2_LEN;
|
||||
taosArrayPush(pBlock->pDataBlock, &infoData);
|
||||
if(taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) {
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
|
||||
infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD3_LEN;
|
||||
taosArrayPush(pBlock->pDataBlock, &infoData);
|
||||
if(taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) {
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
*pOutput = pBlock;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
_exit:
|
||||
if(terrno != TSDB_CODE_SUCCESS) {
|
||||
taosMemoryFree(pBlock);
|
||||
taosArrayDestroy(pBlock->pDataBlock);
|
||||
}
|
||||
return terrno;
|
||||
}
|
||||
|
||||
static int32_t execShowLocalVariables(SRetrieveTableRsp** pRsp) {
|
||||
|
@ -860,7 +889,7 @@ static int32_t execShowLocalVariables(SRetrieveTableRsp** pRsp) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = buildRetrieveTableRsp(pBlock, SHOW_LOCAL_VARIABLES_RESULT_COLS, pRsp);
|
||||
}
|
||||
blockDataDestroy(pBlock);
|
||||
(void)blockDataDestroy(pBlock);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -881,14 +910,14 @@ static int32_t createSelectResultDataBlock(SNodeList* pProjects, SSDataBlock** p
|
|||
infoData.info.type = pExpr->resType.type;
|
||||
infoData.info.bytes = pExpr->resType.bytes;
|
||||
}
|
||||
blockDataAppendColInfo(pBlock, &infoData);
|
||||
QRY_ERR_RET(blockDataAppendColInfo(pBlock, &infoData));
|
||||
}
|
||||
*pOutput = pBlock;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t buildSelectResultDataBlock(SNodeList* pProjects, SSDataBlock* pBlock) {
|
||||
blockDataEnsureCapacity(pBlock, 1);
|
||||
QRY_ERR_RET(blockDataEnsureCapacity(pBlock, 1));
|
||||
|
||||
int32_t index = 0;
|
||||
SNode* pProj = NULL;
|
||||
|
@ -897,9 +926,9 @@ int32_t buildSelectResultDataBlock(SNodeList* pProjects, SSDataBlock* pBlock) {
|
|||
return TSDB_CODE_PAR_INVALID_SELECTED_EXPR;
|
||||
} else {
|
||||
if (((SValueNode*)pProj)->isNull) {
|
||||
colDataSetVal(taosArrayGet(pBlock->pDataBlock, index++), 0, NULL, true);
|
||||
QRY_ERR_RET(colDataSetVal(taosArrayGet(pBlock->pDataBlock, index++), 0, NULL, true));
|
||||
} else {
|
||||
colDataSetVal(taosArrayGet(pBlock->pDataBlock, index++), 0, nodesGetValueFromNode((SValueNode*)pProj), false);
|
||||
QRY_ERR_RET(colDataSetVal(taosArrayGet(pBlock->pDataBlock, index++), 0, nodesGetValueFromNode((SValueNode*)pProj), false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -917,7 +946,7 @@ static int32_t execSelectWithoutFrom(SSelectStmt* pSelect, SRetrieveTableRsp** p
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = buildRetrieveTableRsp(pBlock, LIST_LENGTH(pSelect->pProjectionList), pRsp);
|
||||
}
|
||||
blockDataDestroy(pBlock);
|
||||
(void)blockDataDestroy(pBlock);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -930,7 +959,7 @@ static int32_t execShowCreateView(SShowCreateViewStmt* pStmt, SRetrieveTableRsp*
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = buildRetrieveTableRsp(pBlock, SHOW_CREATE_VIEW_RESULT_COLS, pRsp);
|
||||
}
|
||||
blockDataDestroy(pBlock);
|
||||
(void)blockDataDestroy(pBlock);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
|
|
@ -199,7 +199,7 @@ int32_t qExplainGenerateResNodeExecInfo(SPhysiNode *pNode, SArray **pExecInfo, S
|
|||
return TSDB_CODE_APP_ERROR;
|
||||
}
|
||||
|
||||
taosArrayPush(*pExecInfo, rsp->subplanInfo + group->physiPlanExecIdx);
|
||||
if(taosArrayPush(*pExecInfo, rsp->subplanInfo + group->physiPlanExecIdx) == NULL) return terrno;
|
||||
} else {
|
||||
for (int32_t i = 0; i < group->nodeNum; ++i) {
|
||||
rsp = taosArrayGet(group->nodeExecInfo, i);
|
||||
|
@ -208,7 +208,7 @@ int32_t qExplainGenerateResNodeExecInfo(SPhysiNode *pNode, SArray **pExecInfo, S
|
|||
return TSDB_CODE_APP_ERROR;
|
||||
}
|
||||
|
||||
taosArrayPush(*pExecInfo, rsp->subplanInfo + group->physiPlanExecIdx);
|
||||
if(taosArrayPush(*pExecInfo, rsp->subplanInfo + group->physiPlanExecIdx) == NULL) return terrno;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1920,6 +1920,7 @@ _return:
|
|||
}
|
||||
|
||||
int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) {
|
||||
int32_t code = 0;
|
||||
SExplainCtx *pCtx = (SExplainCtx *)ctx;
|
||||
int32_t rowNum = taosArrayGetSize(pCtx->rows);
|
||||
if (rowNum <= 0) {
|
||||
|
@ -1929,14 +1930,14 @@ int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) {
|
|||
|
||||
SSDataBlock *pBlock = createDataBlock();
|
||||
SColumnInfoData infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, TSDB_EXPLAIN_RESULT_ROW_SIZE, 1);
|
||||
blockDataAppendColInfo(pBlock, &infoData);
|
||||
blockDataEnsureCapacity(pBlock, rowNum);
|
||||
QRY_ERR_JRET(blockDataAppendColInfo(pBlock, &infoData));
|
||||
QRY_ERR_JRET(blockDataEnsureCapacity(pBlock, rowNum));
|
||||
|
||||
SColumnInfoData *pInfoData = taosArrayGet(pBlock->pDataBlock, 0);
|
||||
|
||||
for (int32_t i = 0; i < rowNum; ++i) {
|
||||
SQueryExplainRowInfo *row = taosArrayGet(pCtx->rows, i);
|
||||
colDataSetVal(pInfoData, i, row->buf, false);
|
||||
QRY_ERR_JRET(colDataSetVal(pInfoData, i, row->buf, false));
|
||||
}
|
||||
|
||||
pBlock->info.rows = rowNum;
|
||||
|
@ -1946,8 +1947,7 @@ int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) {
|
|||
SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)taosMemoryCalloc(1, rspSize);
|
||||
if (NULL == rsp) {
|
||||
qError("malloc SRetrieveTableRsp failed, size:%d", rspSize);
|
||||
blockDataDestroy(pBlock);
|
||||
QRY_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
QRY_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
rsp->completed = 1;
|
||||
|
@ -1961,10 +1961,11 @@ int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) {
|
|||
|
||||
SET_PAYLOAD_LEN(rsp->data, len, len);
|
||||
|
||||
_return:
|
||||
blockDataDestroy(pBlock);
|
||||
|
||||
*pRsp = rsp;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
QRY_RET(code);
|
||||
}
|
||||
|
||||
int32_t qExplainPrepareCtx(SQueryPlan *pDag, SExplainCtx **pCtx) {
|
||||
|
@ -2099,32 +2100,30 @@ int32_t qExplainUpdateExecInfo(SExplainCtx *pCtx, SExplainRsp *pRspMsg, int32_t
|
|||
group->nodeExecInfo = taosArrayInit(group->nodeNum, sizeof(SExplainRsp));
|
||||
if (NULL == group->nodeExecInfo) {
|
||||
qError("taosArrayInit %d explainExecInfo failed", group->nodeNum);
|
||||
tFreeSExplainRsp(pRspMsg);
|
||||
taosWUnLockLatch(&group->lock);
|
||||
|
||||
QRY_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TAOS_CHECK_ERRNO(code);
|
||||
}
|
||||
|
||||
group->physiPlanExecNum = pRspMsg->numOfPlans;
|
||||
} else if (taosArrayGetSize(group->nodeExecInfo) >= group->nodeNum) {
|
||||
qError("group execInfo already full, size:%d, nodeNum:%d", (int32_t)taosArrayGetSize(group->nodeExecInfo),
|
||||
group->nodeNum);
|
||||
tFreeSExplainRsp(pRspMsg);
|
||||
taosWUnLockLatch(&group->lock);
|
||||
|
||||
QRY_ERR_RET(TSDB_CODE_APP_ERROR);
|
||||
code = TSDB_CODE_APP_ERROR;
|
||||
TAOS_CHECK_ERRNO(code);
|
||||
}
|
||||
|
||||
if (group->physiPlanExecNum != pRspMsg->numOfPlans) {
|
||||
qError("physiPlanExecNum %d mismatch with others %d in group %d", pRspMsg->numOfPlans, group->physiPlanExecNum,
|
||||
groupId);
|
||||
tFreeSExplainRsp(pRspMsg);
|
||||
taosWUnLockLatch(&group->lock);
|
||||
|
||||
QRY_ERR_RET(TSDB_CODE_APP_ERROR);
|
||||
code = TSDB_CODE_APP_ERROR;
|
||||
TAOS_CHECK_ERRNO(code);
|
||||
}
|
||||
|
||||
taosArrayPush(group->nodeExecInfo, pRspMsg);
|
||||
if(taosArrayPush(group->nodeExecInfo, pRspMsg) == NULL)
|
||||
{
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TAOS_CHECK_ERRNO(code);
|
||||
}
|
||||
|
||||
groupDone = (taosArrayGetSize(group->nodeExecInfo) >= group->nodeNum);
|
||||
|
||||
|
@ -2140,6 +2139,11 @@ int32_t qExplainUpdateExecInfo(SExplainCtx *pCtx, SExplainRsp *pRspMsg, int32_t
|
|||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
_exit:
|
||||
tFreeSExplainRsp(pRspMsg);
|
||||
taosWUnLockLatch(&group->lock);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t qExecStaticExplain(SQueryPlan *pDag, SRetrieveTableRsp **pRsp) {
|
||||
|
|
|
@ -966,7 +966,8 @@ static int32_t sysTableUserTagsFillOneTableTags(const SSysTableScanInfo* pInfo,
|
|||
char* tagVarChar = NULL;
|
||||
if (tagData != NULL) {
|
||||
if (tagType == TSDB_DATA_TYPE_JSON) {
|
||||
char* tagJson = parseTagDatatoJson(tagData);
|
||||
char* tagJson = NULL;
|
||||
parseTagDatatoJson(tagData, &tagJson);
|
||||
tagVarChar = taosMemoryMalloc(strlen(tagJson) + VARSTR_HEADER_SIZE);
|
||||
memcpy(varDataVal(tagVarChar), tagJson, strlen(tagJson));
|
||||
varDataSetLen(tagVarChar, strlen(tagJson));
|
||||
|
|
|
@ -417,7 +417,7 @@ int32_t dataConverToStr(char* str, int type, void* buf, int32_t bufSize, int32_t
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
char* parseTagDatatoJson(void* p) {
|
||||
void parseTagDatatoJson(void* p, char** jsonStr) {
|
||||
char* string = NULL;
|
||||
SArray* pTagVals = NULL;
|
||||
cJSON* json = NULL;
|
||||
|
@ -436,6 +436,9 @@ char* parseTagDatatoJson(void* p) {
|
|||
}
|
||||
for (int j = 0; j < nCols; ++j) {
|
||||
STagVal* pTagVal = (STagVal*)taosArrayGet(pTagVals, j);
|
||||
if (pTagVal == NULL) {
|
||||
continue;
|
||||
}
|
||||
// json key encode by binary
|
||||
tstrncpy(tagJsonKey, pTagVal->pKey, sizeof(tagJsonKey));
|
||||
// json value
|
||||
|
@ -445,11 +448,16 @@ char* parseTagDatatoJson(void* p) {
|
|||
if (value == NULL) {
|
||||
goto end;
|
||||
}
|
||||
cJSON_AddItemToObject(json, tagJsonKey, value);
|
||||
if(!cJSON_AddItemToObject(json, tagJsonKey, value)){
|
||||
goto end;
|
||||
}
|
||||
} else if (type == TSDB_DATA_TYPE_NCHAR) {
|
||||
cJSON* value = NULL;
|
||||
if (pTagVal->nData > 0) {
|
||||
char* tagJsonValue = taosMemoryCalloc(pTagVal->nData, 1);
|
||||
if (tagJsonValue == NULL) {
|
||||
goto end;
|
||||
}
|
||||
int32_t length = taosUcs4ToMbs((TdUcs4*)pTagVal->pData, pTagVal->nData, tagJsonValue);
|
||||
if (length < 0) {
|
||||
qError("charset:%s to %s. val:%s convert json value failed.", DEFAULT_UNICODE_ENCODEC, tsCharset,
|
||||
|
@ -464,25 +472,34 @@ char* parseTagDatatoJson(void* p) {
|
|||
}
|
||||
} else if (pTagVal->nData == 0) {
|
||||
value = cJSON_CreateString("");
|
||||
if (value == NULL) {
|
||||
goto end;
|
||||
}
|
||||
} else {
|
||||
goto end;
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(json, tagJsonKey, value);
|
||||
if(!cJSON_AddItemToObject(json, tagJsonKey, value)){
|
||||
goto end;
|
||||
}
|
||||
} else if (type == TSDB_DATA_TYPE_DOUBLE) {
|
||||
double jsonVd = *(double*)(&pTagVal->i64);
|
||||
cJSON* value = cJSON_CreateNumber(jsonVd);
|
||||
if (value == NULL) {
|
||||
goto end;
|
||||
}
|
||||
cJSON_AddItemToObject(json, tagJsonKey, value);
|
||||
if(!cJSON_AddItemToObject(json, tagJsonKey, value)){
|
||||
goto end;
|
||||
}
|
||||
} else if (type == TSDB_DATA_TYPE_BOOL) {
|
||||
char jsonVd = *(char*)(&pTagVal->i64);
|
||||
cJSON* value = cJSON_CreateBool(jsonVd);
|
||||
if (value == NULL) {
|
||||
goto end;
|
||||
}
|
||||
cJSON_AddItemToObject(json, tagJsonKey, value);
|
||||
if(!cJSON_AddItemToObject(json, tagJsonKey, value)){
|
||||
goto end;
|
||||
}
|
||||
} else {
|
||||
goto end;
|
||||
}
|
||||
|
@ -494,7 +511,7 @@ end:
|
|||
if (string == NULL) {
|
||||
string = taosStrdup(TSDB_DATA_NULL_STR_L);
|
||||
}
|
||||
return string;
|
||||
*jsonStr = string;
|
||||
}
|
||||
|
||||
int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst) {
|
||||
|
|
|
@ -85,7 +85,10 @@ int32_t queryBuildTableMetaReqMsg(void *input, char **msg, int32_t msgSize, int3
|
|||
|
||||
int32_t bufLen = tSerializeSTableInfoReq(NULL, 0, &infoReq);
|
||||
void *pBuf = (*mallcFp)(bufLen);
|
||||
tSerializeSTableInfoReq(pBuf, bufLen, &infoReq);
|
||||
if(tSerializeSTableInfoReq(pBuf, bufLen, &infoReq) < 0)
|
||||
{
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
}
|
||||
|
||||
*msg = pBuf;
|
||||
*msgLen = bufLen;
|
||||
|
@ -109,7 +112,10 @@ int32_t queryBuildUseDbMsg(void *input, char **msg, int32_t msgSize, int32_t *ms
|
|||
|
||||
int32_t bufLen = tSerializeSUseDbReq(NULL, 0, &usedbReq);
|
||||
void *pBuf = (*mallcFp)(bufLen);
|
||||
tSerializeSUseDbReq(pBuf, bufLen, &usedbReq);
|
||||
if(tSerializeSUseDbReq(pBuf, bufLen, &usedbReq) < 0)
|
||||
{
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
}
|
||||
|
||||
*msg = pBuf;
|
||||
*msgLen = bufLen;
|
||||
|
@ -127,7 +133,10 @@ int32_t queryBuildQnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t
|
|||
|
||||
int32_t bufLen = tSerializeSQnodeListReq(NULL, 0, &qnodeListReq);
|
||||
void *pBuf = (*mallcFp)(bufLen);
|
||||
tSerializeSQnodeListReq(pBuf, bufLen, &qnodeListReq);
|
||||
if(tSerializeSQnodeListReq(pBuf, bufLen, &qnodeListReq) < 0)
|
||||
{
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
}
|
||||
|
||||
*msg = pBuf;
|
||||
*msgLen = bufLen;
|
||||
|
@ -145,7 +154,10 @@ int32_t queryBuildDnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t
|
|||
|
||||
int32_t bufLen = tSerializeSDnodeListReq(NULL, 0, &dnodeListReq);
|
||||
void *pBuf = (*mallcFp)(bufLen);
|
||||
tSerializeSDnodeListReq(pBuf, bufLen, &dnodeListReq);
|
||||
if(tSerializeSDnodeListReq(pBuf, bufLen, &dnodeListReq) < 0)
|
||||
{
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
}
|
||||
|
||||
*msg = pBuf;
|
||||
*msgLen = bufLen;
|
||||
|
@ -162,7 +174,10 @@ int32_t queryBuildGetSerVerMsg(void *input, char **msg, int32_t msgSize, int32_t
|
|||
|
||||
int32_t bufLen = tSerializeSServerVerReq(NULL, 0, &req);
|
||||
void *pBuf = (*mallcFp)(bufLen);
|
||||
tSerializeSServerVerReq(pBuf, bufLen, &req);
|
||||
if(tSerializeSServerVerReq(pBuf, bufLen, &req) < 0)
|
||||
{
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
}
|
||||
|
||||
*msg = pBuf;
|
||||
*msgLen = bufLen;
|
||||
|
@ -180,7 +195,10 @@ int32_t queryBuildGetDBCfgMsg(void *input, char **msg, int32_t msgSize, int32_t
|
|||
|
||||
int32_t bufLen = tSerializeSDbCfgReq(NULL, 0, &dbCfgReq);
|
||||
void *pBuf = (*mallcFp)(bufLen);
|
||||
tSerializeSDbCfgReq(pBuf, bufLen, &dbCfgReq);
|
||||
if(tSerializeSDbCfgReq(pBuf, bufLen, &dbCfgReq) < 0)
|
||||
{
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
}
|
||||
|
||||
*msg = pBuf;
|
||||
*msgLen = bufLen;
|
||||
|
@ -198,7 +216,10 @@ int32_t queryBuildGetIndexMsg(void *input, char **msg, int32_t msgSize, int32_t
|
|||
|
||||
int32_t bufLen = tSerializeSUserIndexReq(NULL, 0, &indexReq);
|
||||
void *pBuf = (*mallcFp)(bufLen);
|
||||
tSerializeSUserIndexReq(pBuf, bufLen, &indexReq);
|
||||
if(tSerializeSUserIndexReq(pBuf, bufLen, &indexReq) < 0)
|
||||
{
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
}
|
||||
|
||||
*msg = pBuf;
|
||||
*msgLen = bufLen;
|
||||
|
@ -216,11 +237,20 @@ int32_t queryBuildRetrieveFuncMsg(void *input, char **msg, int32_t msgSize, int3
|
|||
funcReq.numOfFuncs = 1;
|
||||
funcReq.ignoreCodeComment = true;
|
||||
funcReq.pFuncNames = taosArrayInit(1, strlen(input) + 1);
|
||||
taosArrayPush(funcReq.pFuncNames, input);
|
||||
if (NULL == funcReq.pFuncNames) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
if (taosArrayPush(funcReq.pFuncNames, input) == NULL) {
|
||||
taosArrayDestroy(funcReq.pFuncNames);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
int32_t bufLen = tSerializeSRetrieveFuncReq(NULL, 0, &funcReq);
|
||||
void *pBuf = (*mallcFp)(bufLen);
|
||||
tSerializeSRetrieveFuncReq(pBuf, bufLen, &funcReq);
|
||||
if(tSerializeSRetrieveFuncReq(pBuf, bufLen, &funcReq) < 0)
|
||||
{
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
}
|
||||
|
||||
taosArrayDestroy(funcReq.pFuncNames);
|
||||
|
||||
|
@ -240,7 +270,9 @@ int32_t queryBuildGetUserAuthMsg(void *input, char **msg, int32_t msgSize, int32
|
|||
|
||||
int32_t bufLen = tSerializeSGetUserAuthReq(NULL, 0, &req);
|
||||
void *pBuf = (*mallcFp)(bufLen);
|
||||
tSerializeSGetUserAuthReq(pBuf, bufLen, &req);
|
||||
if (tSerializeSGetUserAuthReq(pBuf, bufLen, &req) < 0) {
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
}
|
||||
|
||||
*msg = pBuf;
|
||||
*msgLen = bufLen;
|
||||
|
@ -258,7 +290,10 @@ int32_t queryBuildGetTbIndexMsg(void *input, char **msg, int32_t msgSize, int32_
|
|||
|
||||
int32_t bufLen = tSerializeSTableIndexReq(NULL, 0, &indexReq);
|
||||
void *pBuf = (*mallcFp)(bufLen);
|
||||
tSerializeSTableIndexReq(pBuf, bufLen, &indexReq);
|
||||
if(tSerializeSTableIndexReq(pBuf, bufLen, &indexReq) < 0)
|
||||
{
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
}
|
||||
|
||||
*msg = pBuf;
|
||||
*msgLen = bufLen;
|
||||
|
@ -279,7 +314,10 @@ int32_t queryBuildGetTbCfgMsg(void *input, char **msg, int32_t msgSize, int32_t
|
|||
|
||||
int32_t bufLen = tSerializeSTableCfgReq(NULL, 0, &cfgReq);
|
||||
void *pBuf = (*mallcFp)(bufLen);
|
||||
tSerializeSTableCfgReq(pBuf, bufLen, &cfgReq);
|
||||
if(tSerializeSTableCfgReq(pBuf, bufLen, &cfgReq) < 0)
|
||||
{
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
}
|
||||
|
||||
*msg = pBuf;
|
||||
*msgLen = bufLen;
|
||||
|
@ -297,7 +335,10 @@ int32_t queryBuildGetViewMetaMsg(void *input, char **msg, int32_t msgSize, int32
|
|||
|
||||
int32_t bufLen = tSerializeSViewMetaReq(NULL, 0, &req);
|
||||
void *pBuf = (*mallcFp)(bufLen);
|
||||
tSerializeSViewMetaReq(pBuf, bufLen, &req);
|
||||
if(tSerializeSViewMetaReq(pBuf, bufLen, &req) < 0)
|
||||
{
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
}
|
||||
|
||||
*msg = pBuf;
|
||||
*msgLen = bufLen;
|
||||
|
@ -316,7 +357,10 @@ int32_t queryBuildGetTableTSMAMsg(void *input, char **msg, int32_t msgSize, int3
|
|||
|
||||
int32_t bufLen = tSerializeTableTSMAInfoReq(NULL, 0, &req);
|
||||
void * pBuf = (*mallcFp)(bufLen);
|
||||
tSerializeTableTSMAInfoReq(pBuf, bufLen, &req);
|
||||
if(tSerializeTableTSMAInfoReq(pBuf, bufLen, &req) < 0)
|
||||
{
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
}
|
||||
|
||||
*msg = pBuf;
|
||||
*msgLen = bufLen;
|
||||
|
@ -335,7 +379,10 @@ int32_t queryBuildGetTSMAMsg(void *input, char **msg, int32_t msgSize, int32_t *
|
|||
|
||||
int32_t bufLen = tSerializeTableTSMAInfoReq(NULL, 0, &req);
|
||||
void * pBuf = (*mallcFp)(bufLen);
|
||||
tSerializeTableTSMAInfoReq(pBuf, bufLen, &req);
|
||||
if(tSerializeTableTSMAInfoReq(pBuf, bufLen, &req) < 0)
|
||||
{
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
}
|
||||
|
||||
*msg = pBuf;
|
||||
*msgLen = bufLen;
|
||||
|
@ -350,7 +397,10 @@ int32_t queryBuildGetStreamProgressMsg(void* input, char** msg, int32_t msgSize,
|
|||
int32_t len = tSerializeStreamProgressReq(NULL, 0, input);
|
||||
void* pBuf = (*mallcFp)(len);
|
||||
|
||||
tSerializeStreamProgressReq(pBuf, len, input);
|
||||
if(tSerializeStreamProgressReq(pBuf, len, input) < 0)
|
||||
{
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
}
|
||||
|
||||
*msg = pBuf;
|
||||
*msgLen = len;
|
||||
|
@ -713,6 +763,9 @@ int32_t queryProcessGetTbCfgRsp(void *output, char *msg, int32_t msgSize) {
|
|||
}
|
||||
|
||||
STableCfgRsp *out = taosMemoryCalloc(1, sizeof(STableCfgRsp));
|
||||
if(out == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
if (tDeserializeSTableCfgRsp(msg, msgSize, out) != 0) {
|
||||
qError("tDeserializeSTableCfgRsp failed, msgSize:%d", msgSize);
|
||||
tFreeSTableCfgRsp(out);
|
||||
|
@ -731,6 +784,9 @@ int32_t queryProcessGetViewMetaRsp(void *output, char *msg, int32_t msgSize) {
|
|||
}
|
||||
|
||||
SViewMetaRsp *out = taosMemoryCalloc(1, sizeof(SViewMetaRsp));
|
||||
if (out == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
if (tDeserializeSViewMetaRsp(msg, msgSize, out) != 0) {
|
||||
qError("tDeserializeSViewMetaRsp failed, msgSize:%d", msgSize);
|
||||
tFreeSViewMetaRsp(out);
|
||||
|
|
|
@ -214,7 +214,6 @@ void schedulerDestroy(void) {
|
|||
}
|
||||
SCH_UNLOCK(SCH_WRITE, &schMgmt.hbLock);
|
||||
|
||||
taosTmrCleanUp(schMgmt.timer);
|
||||
qWorkerDestroy(&schMgmt.queryMgmt);
|
||||
schMgmt.queryMgmt = NULL;
|
||||
}
|
||||
|
|
|
@ -102,21 +102,21 @@ int32_t tasoUcs4Compare(TdUcs4 *f1_ucs4, TdUcs4 *f2_ucs4, int32_t bytes) {
|
|||
|
||||
return 0;
|
||||
|
||||
//#if 0
|
||||
// int32_t ucs4_max_len = bytes + 4;
|
||||
// char *f1_mbs = taosMemoryCalloc(bytes, 1);
|
||||
// char *f2_mbs = taosMemoryCalloc(bytes, 1);
|
||||
// if (taosUcs4ToMbs(f1_ucs4, ucs4_max_len, f1_mbs) < 0) {
|
||||
// return -1;
|
||||
// }
|
||||
// if (taosUcs4ToMbs(f2_ucs4, ucs4_max_len, f2_mbs) < 0) {
|
||||
// return -1;
|
||||
// }
|
||||
// int32_t ret = strcmp(f1_mbs, f2_mbs);
|
||||
// taosMemoryFree(f1_mbs);
|
||||
// taosMemoryFree(f2_mbs);
|
||||
// return ret;
|
||||
//#endif
|
||||
//#if 0
|
||||
// int32_t ucs4_max_len = bytes + 4;
|
||||
// char *f1_mbs = taosMemoryCalloc(bytes, 1);
|
||||
// char *f2_mbs = taosMemoryCalloc(bytes, 1);
|
||||
// if (taosUcs4ToMbs(f1_ucs4, ucs4_max_len, f1_mbs) < 0) {
|
||||
// return -1;
|
||||
// }
|
||||
// if (taosUcs4ToMbs(f2_ucs4, ucs4_max_len, f2_mbs) < 0) {
|
||||
// return -1;
|
||||
// }
|
||||
// int32_t ret = strcmp(f1_mbs, f2_mbs);
|
||||
// taosMemoryFree(f1_mbs);
|
||||
// taosMemoryFree(f2_mbs);
|
||||
// return ret;
|
||||
//#endif
|
||||
}
|
||||
|
||||
TdUcs4 *tasoUcs4Copy(TdUcs4 *target_ucs4, TdUcs4 *source_ucs4, int32_t len_ucs4) {
|
||||
|
@ -142,17 +142,22 @@ int32_t taosConvInit(void) {
|
|||
|
||||
gConv[M2C] = taosMemoryCalloc(gConvMaxNum[M2C], sizeof(SConv));
|
||||
gConv[1 - M2C] = taosMemoryCalloc(gConvMaxNum[1 - M2C], sizeof(SConv));
|
||||
if (gConv[M2C] == NULL || gConv[1 - M2C] == NULL) {
|
||||
taosMemoryFree(gConv[M2C]);
|
||||
taosMemoryFree(gConv[1 - M2C]);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < gConvMaxNum[M2C]; ++i) {
|
||||
gConv[M2C][i].conv = iconv_open(DEFAULT_UNICODE_ENCODEC, tsCharset);
|
||||
if ((iconv_t)-1 == gConv[M2C][i].conv || (iconv_t)0 == gConv[M2C][i].conv) {
|
||||
return -1;
|
||||
return TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
}
|
||||
for (int32_t i = 0; i < gConvMaxNum[1 - M2C]; ++i) {
|
||||
gConv[1 - M2C][i].conv = iconv_open(tsCharset, DEFAULT_UNICODE_ENCODEC);
|
||||
if ((iconv_t)-1 == gConv[1 - M2C][i].conv || (iconv_t)0 == gConv[1 - M2C][i].conv) {
|
||||
return -1;
|
||||
return TAOS_SYSTEM_ERROR(errno);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -491,17 +496,17 @@ float taosStr2Float(const char *str, char **pEnd) {
|
|||
return tmp;
|
||||
}
|
||||
|
||||
#define HEX_PREFIX_LEN 2 // \x
|
||||
bool isHex(const char* z, uint32_t n){
|
||||
if(n < HEX_PREFIX_LEN) return false;
|
||||
if(z[0] == '\\' && z[1] == 'x') return true;
|
||||
#define HEX_PREFIX_LEN 2 // \x
|
||||
bool isHex(const char *z, uint32_t n) {
|
||||
if (n < HEX_PREFIX_LEN) return false;
|
||||
if (z[0] == '\\' && z[1] == 'x') return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isValidateHex(const char* z, uint32_t n){
|
||||
if((n & 1) != 0) return false;
|
||||
for(size_t i = HEX_PREFIX_LEN; i < n; i++){
|
||||
if(isxdigit(z[i]) == 0){
|
||||
bool isValidateHex(const char *z, uint32_t n) {
|
||||
if ((n & 1) != 0) return false;
|
||||
for (size_t i = HEX_PREFIX_LEN; i < n; i++) {
|
||||
if (isxdigit(z[i]) == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -540,70 +545,83 @@ int32_t taosHex2Ascii(const char *z, uint32_t n, void **data, uint32_t *size) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
//int32_t taosBin2Ascii(const char *z, uint32_t n, void** data, uint32_t* size){
|
||||
// int32_t taosBin2Ascii(const char *z, uint32_t n, void** data, uint32_t* size){
|
||||
//
|
||||
// for (i = 2; isdigit(z[i]) || (z[i] >= 'a' && z[i] <= 'f') || (z[i] >= 'A' && z[i] <= 'F'); ++i) {
|
||||
// }
|
||||
// for (i = 2; isdigit(z[i]) || (z[i] >= 'a' && z[i] <= 'f') || (z[i] >= 'A' && z[i] <= 'F'); ++i) {
|
||||
// }
|
||||
//
|
||||
// n -= 2; // remove 0b
|
||||
// z += 2;
|
||||
// *size = n%8 == 0 ? n/8 : n/8 + 1;
|
||||
// uint8_t* tmp = (uint8_t*)taosMemoryCalloc(*size, 1);
|
||||
// if(tmp == NULL) return -1;
|
||||
// int8_t num = 0;
|
||||
// uint8_t *byte = tmp + *size - 1;
|
||||
// n -= 2; // remove 0b
|
||||
// z += 2;
|
||||
// *size = n%8 == 0 ? n/8 : n/8 + 1;
|
||||
// uint8_t* tmp = (uint8_t*)taosMemoryCalloc(*size, 1);
|
||||
// if(tmp == NULL) return -1;
|
||||
// int8_t num = 0;
|
||||
// uint8_t *byte = tmp + *size - 1;
|
||||
//
|
||||
// for (int i = n - 1; i >= 0; i--) {
|
||||
// *byte |= ((uint8_t)(z[i] - '0') << num);
|
||||
// if (num == 7) {
|
||||
// byte--;
|
||||
// num = 0;
|
||||
// } else {
|
||||
// num++;
|
||||
// }
|
||||
// }
|
||||
// *data = tmp;
|
||||
// return 0;
|
||||
//}
|
||||
// for (int i = n - 1; i >= 0; i--) {
|
||||
// *byte |= ((uint8_t)(z[i] - '0') << num);
|
||||
// if (num == 7) {
|
||||
// byte--;
|
||||
// num = 0;
|
||||
// } else {
|
||||
// num++;
|
||||
// }
|
||||
// }
|
||||
// *data = tmp;
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
static char valueOf(uint8_t symbol)
|
||||
{
|
||||
switch(symbol)
|
||||
{
|
||||
case 0: return '0';
|
||||
case 1: return '1';
|
||||
case 2: return '2';
|
||||
case 3: return '3';
|
||||
case 4: return '4';
|
||||
case 5: return '5';
|
||||
case 6: return '6';
|
||||
case 7: return '7';
|
||||
case 8: return '8';
|
||||
case 9: return '9';
|
||||
case 10: return 'A';
|
||||
case 11: return 'B';
|
||||
case 12: return 'C';
|
||||
case 13: return 'D';
|
||||
case 14: return 'E';
|
||||
case 15: return 'F';
|
||||
default:
|
||||
{
|
||||
static char valueOf(uint8_t symbol) {
|
||||
switch (symbol) {
|
||||
case 0:
|
||||
return '0';
|
||||
case 1:
|
||||
return '1';
|
||||
case 2:
|
||||
return '2';
|
||||
case 3:
|
||||
return '3';
|
||||
case 4:
|
||||
return '4';
|
||||
case 5:
|
||||
return '5';
|
||||
case 6:
|
||||
return '6';
|
||||
case 7:
|
||||
return '7';
|
||||
case 8:
|
||||
return '8';
|
||||
case 9:
|
||||
return '9';
|
||||
case 10:
|
||||
return 'A';
|
||||
case 11:
|
||||
return 'B';
|
||||
case 12:
|
||||
return 'C';
|
||||
case 13:
|
||||
return 'D';
|
||||
case 14:
|
||||
return 'E';
|
||||
case 15:
|
||||
return 'F';
|
||||
default: {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t taosAscii2Hex(const char *z, uint32_t n, void** data, uint32_t* size){
|
||||
int32_t taosAscii2Hex(const char *z, uint32_t n, void **data, uint32_t *size) {
|
||||
*size = n * 2 + HEX_PREFIX_LEN;
|
||||
uint8_t* tmp = (uint8_t*)taosMemoryCalloc(*size + 1, 1);
|
||||
if(tmp == NULL) return -1;
|
||||
uint8_t *tmp = (uint8_t *)taosMemoryCalloc(*size + 1, 1);
|
||||
if (tmp == NULL) return -1;
|
||||
*data = tmp;
|
||||
*(tmp++) = '\\';
|
||||
*(tmp++) = 'x';
|
||||
for(int i = 0; i < n; i ++){
|
||||
for (int i = 0; i < n; i++) {
|
||||
uint8_t val = z[i];
|
||||
tmp[i*2] = valueOf(val >> 4);
|
||||
tmp[i*2 + 1] = valueOf(val & 0x0F);
|
||||
tmp[i * 2] = valueOf(val >> 4);
|
||||
tmp[i * 2 + 1] = valueOf(val & 0x0F);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -83,15 +83,13 @@ int32_t taosCheckVersionCompatible(int32_t clientVer, int32_t serverVer, int32_t
|
|||
serverVer /= 1000000;
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_INVALID_VERSION_NUMBER;
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_VERSION_NUMBER;
|
||||
}
|
||||
|
||||
if (clientVer == serverVer) {
|
||||
return 0;
|
||||
} else {
|
||||
terrno = TSDB_CODE_VERSION_NOT_COMPATIBLE;
|
||||
return -1;
|
||||
return TSDB_CODE_VERSION_NOT_COMPATIBLE;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -171,7 +171,7 @@ int32_t init_env() {
|
|||
}
|
||||
|
||||
// pass NULL return last error code describe
|
||||
const char* err = taos_errstr(NULL);
|
||||
const char* err = tmq_err2str(error_code);
|
||||
printf("write_raw_block return code =0x%x err=%s\n", error_code, err);
|
||||
if(strcmp(err, "success") == 0) {
|
||||
printf("expect failed , but error string is success! err=%s\n", err);
|
||||
|
@ -185,7 +185,7 @@ int32_t init_env() {
|
|||
goto END;
|
||||
}
|
||||
|
||||
err = taos_errstr(NULL);
|
||||
err = tmq_err2str(error_code);
|
||||
printf("write_raw_block no exist table return code =0x%x err=%s\n", error_code, err);
|
||||
if(strcmp(err, "success") == 0) {
|
||||
printf("expect failed write no exist table, but error string is success! err=%s\n", err);
|
||||
|
|
Loading…
Reference in New Issue