make decrypt return code
This commit is contained in:
parent
4f594dcec7
commit
e22c0ed3fb
|
@ -166,7 +166,7 @@ int32_t walMetaSerialize(SWal* pWal, char** serialized);
|
|||
int32_t walMetaDeserialize(SWal* pWal, const char* bytes);
|
||||
// meta section end
|
||||
|
||||
void decryptBody(SWalCfg* cfg, SWalCkHead* pHead, int32_t plainBodyLen, const char* func);
|
||||
int32_t decryptBody(SWalCfg* cfg, SWalCkHead* pHead, int32_t plainBodyLen, const char* func);
|
||||
|
||||
int64_t walGetSeq();
|
||||
|
||||
|
|
|
@ -140,7 +140,7 @@ static FORCE_INLINE int32_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx, in
|
|||
|
||||
logContent = (SWalCkHead*)(buf + pos);
|
||||
if (walValidHeadCksum(logContent) != 0) {
|
||||
terrno = TSDB_CODE_WAL_CHKSUM_MISMATCH;
|
||||
code = TSDB_CODE_WAL_CHKSUM_MISMATCH;
|
||||
wWarn("vgId:%d, failed to validate checksum of wal entry header. offset:%" PRId64 ", file:%s", pWal->cfg.vgId,
|
||||
offset + pos, fnameStr);
|
||||
haystack = buf + pos + 1;
|
||||
|
@ -171,21 +171,25 @@ static FORCE_INLINE int32_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx, in
|
|||
if (ret < 0) {
|
||||
wError("vgId:%d, failed to lseek file due to %s. offset:%" PRId64 "", pWal->cfg.vgId, strerror(errno),
|
||||
offset);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
break;
|
||||
}
|
||||
if (extraSize != taosReadFile(pFile, buf + readSize, extraSize)) {
|
||||
wError("vgId:%d, failed to read file due to %s. offset:%" PRId64 ", extraSize:%" PRId64 ", file:%s",
|
||||
pWal->cfg.vgId, strerror(errno), offset + readSize, extraSize, fnameStr);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
logContent = (SWalCkHead*)(buf + pos);
|
||||
decryptBody(&pWal->cfg, logContent, logContent->head.bodyLen, __FUNCTION__);
|
||||
code = decryptBody(&pWal->cfg, logContent, logContent->head.bodyLen, __FUNCTION__);
|
||||
if (code) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (walValidBodyCksum(logContent) != 0) {
|
||||
terrno = TSDB_CODE_WAL_CHKSUM_MISMATCH;
|
||||
code = TSDB_CODE_WAL_CHKSUM_MISMATCH;
|
||||
wWarn("vgId:%d, failed to validate checksum of wal entry body. offset:%" PRId64 ", file:%s", pWal->cfg.vgId,
|
||||
offset + pos, fnameStr);
|
||||
haystack = buf + pos + 1;
|
||||
|
@ -715,8 +719,7 @@ int32_t walRollFileInfo(SWal* pWal) {
|
|||
// TODO: change to emplace back
|
||||
SWalFileInfo* pNewInfo = taosMemoryMalloc(sizeof(SWalFileInfo));
|
||||
if (pNewInfo == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
pNewInfo->firstVer = pWal->vers.lastVer + 1;
|
||||
pNewInfo->lastVer = -1;
|
||||
|
|
|
@ -362,7 +362,7 @@ int32_t walFetchBody(SWalReader *pRead) {
|
|||
TAOS_RETURN(TSDB_CODE_WAL_FILE_CORRUPTED);
|
||||
}
|
||||
|
||||
decryptBody(&pRead->pWal->cfg, pRead->pHead, plainBodyLen, __FUNCTION__);
|
||||
TAOS_CHECK_RETURN(decryptBody(&pRead->pWal->cfg, pRead->pHead, plainBodyLen, __FUNCTION__));
|
||||
|
||||
if (walValidBodyCksum(pRead->pHead) != 0) {
|
||||
wError("vgId:%d, wal fetch body error, index:%" PRId64 ", since body checksum not passed, 0x%" PRIx64, vgId, ver,
|
||||
|
@ -482,7 +482,12 @@ int32_t walReadVer(SWalReader *pReader, int64_t ver) {
|
|||
TAOS_RETURN(TSDB_CODE_WAL_FILE_CORRUPTED);
|
||||
}
|
||||
|
||||
decryptBody(&pReader->pWal->cfg, pReader->pHead, plainBodyLen, __FUNCTION__);
|
||||
code = decryptBody(&pReader->pWal->cfg, pReader->pHead, plainBodyLen, __FUNCTION__);
|
||||
if (code) {
|
||||
taosThreadMutexUnlock(&pReader->mutex);
|
||||
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
code = walValidBodyCksum(pReader->pHead);
|
||||
if (code != 0) {
|
||||
|
@ -504,11 +509,14 @@ int32_t walReadVer(SWalReader *pReader, int64_t ver) {
|
|||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
void decryptBody(SWalCfg *cfg, SWalCkHead *pHead, int32_t plainBodyLen, const char *func) {
|
||||
int32_t decryptBody(SWalCfg *cfg, SWalCkHead *pHead, int32_t plainBodyLen, const char *func) {
|
||||
// TODO: dmchen emun
|
||||
if (cfg->encryptAlgorithm == 1) {
|
||||
int32_t cryptedBodyLen = ENCRYPTED_LEN(plainBodyLen);
|
||||
char *newBody = taosMemoryMalloc(cryptedBodyLen);
|
||||
if (!newBody) {
|
||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
SCryptOpts opts;
|
||||
opts.len = cryptedBodyLen;
|
||||
|
@ -525,6 +533,8 @@ void decryptBody(SWalCfg *cfg, SWalCkHead *pHead, int32_t plainBodyLen, const ch
|
|||
|
||||
taosMemoryFree(newBody);
|
||||
}
|
||||
|
||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
void walReadReset(SWalReader *pReader) {
|
||||
|
|
Loading…
Reference in New Issue