refactor error code

This commit is contained in:
Yihao Deng 2024-07-18 05:26:36 +00:00
parent 690c6e1cf1
commit 26663153b5
1 changed files with 33 additions and 38 deletions

View File

@ -135,8 +135,7 @@ int32_t dmReadEps(SDnodeData *pData) {
if (strlen(tsEncryptAlgorithm) > 0) { if (strlen(tsEncryptAlgorithm) > 0) {
if (strcmp(tsEncryptAlgorithm, "sm4") == 0) { if (strcmp(tsEncryptAlgorithm, "sm4") == 0) {
pData->encryptAlgorigthm = DND_CA_SM4; pData->encryptAlgorigthm = DND_CA_SM4;
} } else {
else{
terrno = TSDB_CODE_DNODE_INVALID_ENCRYPT_CONFIG; terrno = TSDB_CODE_DNODE_INVALID_ENCRYPT_CONFIG;
dError("invalid tsEncryptAlgorithm:%s", tsEncryptAlgorithm); dError("invalid tsEncryptAlgorithm:%s", tsEncryptAlgorithm);
goto _OVER; goto _OVER;
@ -316,33 +315,30 @@ int32_t dmWriteEps(SDnodeData *pData) {
snprintf(file, sizeof(file), "%s%sdnode%sdnode.json.bak", tsDataDir, TD_DIRSEP, TD_DIRSEP); 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); snprintf(realfile, sizeof(realfile), "%s%sdnode%sdnode.json", tsDataDir, TD_DIRSEP, TD_DIRSEP);
// if ((code == dmInitDndInfo(pData)) != 0) goto _OVER; // if ((code == dmInitDndInfo(pData)) != 0) goto _OVER;
TAOS_CHECK_GOTO(code = dmInitDndInfo(pData), NULL, _OVER); TAOS_CHECK_GOTO(dmInitDndInfo(pData), NULL, _OVER);
pJson = tjsonCreateObject(); pJson = tjsonCreateObject();
if (pJson == NULL) if (pJson == NULL) TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _OVER);
TAOS_CHECK_GOTO(code = TSDB_CODE_OUT_OF_MEMORY, NULL, _OVER);
pData->engineVer = tsVersion; pData->engineVer = tsVersion;
TAOS_CHECK_GOTO(code = dmEncodeEps(pJson, pData), NULL, _OVER);//dmEncodeEps(pJson, pData) != 0) goto _OVER; TAOS_CHECK_GOTO(dmEncodeEps(pJson, pData), NULL, _OVER); // dmEncodeEps(pJson, pData) != 0) goto _OVER;
buffer = tjsonToString(pJson); buffer = tjsonToString(pJson);
if (buffer == NULL) { if (buffer == NULL) {
TAOS_CHECK_GOTO(code = TSDB_CODE_OUT_OF_MEMORY, NULL, _OVER); TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _OVER);
} }
code = 0;
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); 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); int32_t len = strlen(buffer);
if (taosWriteFile(pFile, buffer, len) <= 0) goto _OVER; if (taosWriteFile(pFile, buffer, len) <= 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER);
if (taosFsyncFile(pFile) < 0) goto _OVER; if (taosFsyncFile(pFile) < 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER);
taosCloseFile(&pFile); 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; code = 0;
pData->updateTime = taosGetTimestampMs(); pData->updateTime = taosGetTimestampMs();
@ -355,7 +351,6 @@ _OVER:
if (pFile != NULL) taosCloseFile(&pFile); if (pFile != NULL) taosCloseFile(&pFile);
if (code != 0) { if (code != 0) {
// code = TAOS_SYSTEM_ERROR(errno);
dError("failed to write dnode file:%s since %s, dnodeVer:%" PRId64, realfile, tstrerror(code), pData->dnodeVer); dError("failed to write dnode file:%s since %s, dnodeVer:%" PRId64, realfile, tstrerror(code), pData->dnodeVer);
} }
return code; return code;