Skip to content

Commit

Permalink
[refactor]mds: print the error code
Browse files Browse the repository at this point in the history
Signed-off-by: NopeDl <[email protected]>
  • Loading branch information
NopeDl committed Oct 13, 2023
1 parent 92f1e1a commit 91ad4ad
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 31 deletions.
21 changes: 21 additions & 0 deletions src/mds/common/mds_define.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,27 @@ const int kCsClientReturnFail = -5;
// error code: chunkserver offline
const int kCsClientCSOffline = -6;

inline const char* PrintMdsDescByErrorCode(int code) {
switch (code) {
case kMdsSuccess:
return "MDS execution succeeded";
case kMdsFail:
return "MDS execution failed";
case kCsClientInternalError:
return "chunkserverclient internal error";
case kCsClientNotLeader:
return "chunkserverclient request is not from the leader";
case kRpcChannelInitFail:
return "brpc channel init fail";
case kRpcFail:
return "RPC fail or Chunkserverclient request return fail";
case kCsClientCSOffline:
return "chunkserver offline";
default:
return "undefied code";
}
}

// kStaledRequestTimeIntervalUs indicates the expiration time of the request
// to prevent the request from being intercepted and played back
const uint64_t kStaledRequestTimeIntervalUs = 15 * 1000 * 1000u;
Expand Down
24 changes: 14 additions & 10 deletions src/mds/nameserver2/clean_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ StatusCode CleanCore::CleanSnapShotFile(const FileInfo & fileInfo,
correctSn);
if (ret != 0) {
LOG(ERROR) << "CleanSnapShotFile Error: "
<< "DeleteChunkSnapshotOrCorrectSn Error"
<< ", ret = " << ret
<< ", inodeid = " << fileInfo.id()
<< ", filename = " << fileInfo.filename()
<< ", correctSn = " << correctSn;
<< "DeleteChunkSnapshotOrCorrectSn Error"
<< ", ret = " << PrintMdsDescByErrorCode(ret)
<< ", inodeid = " << fileInfo.id()
<< ", filename = " << fileInfo.filename()
<< ", correctSn = " << correctSn;
progress->SetStatus(TaskStatus::FAILED);
return StatusCode::kSnapshotFileDeleteError;
}
Expand All @@ -81,7 +81,8 @@ StatusCode CleanCore::CleanSnapShotFile(const FileInfo & fileInfo,
StoreStatus ret = storage_->DeleteSnapshotFile(fileInfo.parentid(),
fileInfo.filename());
if (ret != StoreStatus::OK) {
LOG(INFO) << "delete snapshotfile error, retCode = " << ret;
LOG(INFO) << "delete snapshotfile error, retCode = "
<< PrintStoreStatusByErrorCode(ret);
progress->SetStatus(TaskStatus::FAILED);
return StatusCode::kSnapshotFileDeleteError;
} else {
Expand Down Expand Up @@ -123,7 +124,7 @@ StatusCode CleanCore::CleanFile(const FileInfo & commonFile,
int ret = DeleteChunksInSegment(segment, commonFile.seqnum());
if (ret != 0) {
LOG(ERROR) << "Clean common File Error: "
<< ", ret = " << ret
<< ", ret = " << PrintMdsDescByErrorCode(ret)
<< ", inodeid = " << commonFile.id()
<< ", filename = " << commonFile.filename()
<< ", sequenceNum = " << commonFile.seqnum();
Expand Down Expand Up @@ -153,7 +154,8 @@ StatusCode CleanCore::CleanFile(const FileInfo & commonFile,
StoreStatus ret = storage_->DeleteFile(commonFile.parentid(),
commonFile.filename());
if (ret != StoreStatus::OK) {
LOG(INFO) << "delete common file error, retCode = " << ret;
LOG(INFO) << "delete common file error, retDesc = "
<< PrintStoreStatusByErrorCode(ret);
progress->SetStatus(TaskStatus::FAILED);
return StatusCode::kCommonFileDeleteError;
} else {
Expand Down Expand Up @@ -185,7 +187,8 @@ StatusCode CleanCore::CleanDiscardSegment(
int ret = DeleteChunksInSegment(segment, seq);
if (ret != 0) {
LOG(ERROR) << "CleanDiscardSegment failed, DeleteChunk Error, ret = "
<< ret << ", filename = " << fileInfo.filename()
<< PrintMdsDescByErrorCode(ret)
<< ", filename = " << fileInfo.filename()
<< ", inodeid = " << fileInfo.id()
<< ", segment offset = " << segment.startoffset();
progress->SetStatus(TaskStatus::FAILED);
Expand Down Expand Up @@ -229,7 +232,8 @@ int CleanCore::DeleteChunksInSegment(const PageFileSegment& segment,
seq);

if (ret != 0) {
LOG(ERROR) << "DeleteChunk failed, ret = " << ret
LOG(ERROR) << "DeleteChunk failed, ret = "
<< PrintMdsDescByErrorCode(ret)
<< ", logicalpoolid = " << logicalPoolId
<< ", copysetid = " << segment.chunks()[i].copysetid()
<< ", chunkid = " << segment.chunks()[i].chunkid()
Expand Down
6 changes: 4 additions & 2 deletions src/mds/nameserver2/clean_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ bool CleanManager::RecoverCleanTasks(void) {
std::vector<FileInfo> snapShotFiles;
StoreStatus ret = storage_->LoadSnapShotFile(&snapShotFiles);
if (ret != StoreStatus::OK) {
LOG(ERROR) << "Load SnapShotFile error, ret = " << ret;
LOG(ERROR) << "Load SnapShotFile error, ret = "
<< PrintStoreStatusByErrorCode(ret);
return false;
}

Expand All @@ -104,7 +105,8 @@ bool CleanManager::RecoverCleanTasks(void) {
StoreStatus ret1 = storage_->ListFile(RECYCLEBININODEID,
RECYCLEBININODEID + 1, &commonFiles);
if (ret1 != StoreStatus::OK) {
LOG(ERROR) << "Load recylce bin file error, ret = " << ret1;
LOG(ERROR) << "Load recylce bin file error, ret = "
<< PrintStoreStatusByErrorCode(ret1);
return false;
}

Expand Down
44 changes: 25 additions & 19 deletions src/mds/nameserver2/curvefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ bool CurveFS::InitRecycleBinDir() {
return true;
} else {
// internal error
LOG(INFO) << "InitRecycleBinDir error ,ret = " << ret;
LOG(INFO) << "InitRecycleBinDir error ,ret = "
<< PrintStoreStatusByErrorCode(ret);
return false;
}
}
Expand Down Expand Up @@ -206,7 +207,8 @@ StatusCode CurveFS::WalkPath(const std::string &fileName,
} else if (ret == StoreStatus::KeyNotExist) {
return StatusCode::kFileNotExists;
} else {
LOG(ERROR) << "GetFile error, errcode = " << ret;
LOG(ERROR) << "GetFile error, errcode = "
<< PrintStoreStatusByErrorCode(ret);
return StatusCode::kStorageError;
}
// assert(fileInfo->parentid() != parentID);
Expand Down Expand Up @@ -680,7 +682,7 @@ StatusCode CurveFS::DeleteFile(const std::string & filename, uint64_t fileId,
if (ret != StoreStatus::OK) {
LOG(ERROR) << "delete file, file is directory and delete fail"
<< ", filename = " << filename
<< ", ret = " << ret;
<< ", ret = " << PrintStoreStatusByErrorCode(ret);
return StatusCode::kStorageError;
}

Expand Down Expand Up @@ -728,8 +730,8 @@ StatusCode CurveFS::DeleteFile(const std::string & filename, uint64_t fileId,
storage_->MoveFileToRecycle(fileInfo, recycleFileInfo);
if (ret1 != StoreStatus::OK) {
LOG(ERROR) << "delete file, move file to recycle fail"
<< ", filename = " << filename
<< ", ret = " << ret1;
<< ", filename = " << filename
<< ", ret = " << PrintStoreStatusByErrorCode(ret1);
return StatusCode::kStorageError;
}
LOG(INFO) << "file delete to recyclebin, fileName = " << filename
Expand Down Expand Up @@ -877,7 +879,8 @@ StatusCode CurveFS::RecoverFile(const std::string & originFileName,

auto ret1 = storage_->RenameFile(recycleFileInfo, recoverFileInfo);
if ( ret1 != StoreStatus::OK ) {
LOG(ERROR) << "storage_ recoverfile error, error = " << ret1;
LOG(ERROR) << "storage_ recoverfile error, error = "
<< PrintStoreStatusByErrorCode(ret1);
return StatusCode::kStorageError;
}
return StatusCode::kOK;
Expand Down Expand Up @@ -1122,9 +1125,9 @@ StatusCode CurveFS::RenameFile(const std::string & sourceFileName,
recycleFileInfo);
if (ret1 != StoreStatus::OK) {
LOG(ERROR) << "storage_ ReplaceFileAndRecycleOldFile error"
<< ", sourceFileName = " << sourceFileName
<< ", destFileName = " << destFileName
<< ", ret = " << ret1;
<< ", sourceFileName = " << sourceFileName
<< ", destFileName = " << destFileName
<< ", ret = " << PrintStoreStatusByErrorCode(ret1);

return StatusCode::kStorageError;
}
Expand All @@ -1138,7 +1141,8 @@ StatusCode CurveFS::RenameFile(const std::string & sourceFileName,

auto ret = storage_->RenameFile(sourceFileInfo, destFileInfo);
if ( ret != StoreStatus::OK ) {
LOG(ERROR) << "storage_ renamefile error, error = " << ret;
LOG(ERROR) << "storage_ renamefile error, error = "
<< PrintStoreStatusByErrorCode(ret);
return StatusCode::kStorageError;
}
return StatusCode::kOK;
Expand Down Expand Up @@ -1385,8 +1389,8 @@ StatusCode CurveFS::DeAllocateSegment(const std::string& fileName,
storeRet = storage_->DiscardSegment(fileInfo, segment);
if (storeRet != StoreStatus::OK) {
LOG(WARNING) << "Storage CleanSegment return error, filename = "
<< fileName << ", offset = " << offset
<< ", error = " << storeRet;
<< fileName << ", offset = " << offset
<< ", error = " << PrintStoreStatusByErrorCode(storeRet);
return StatusCode::kStorageError;
}

Expand Down Expand Up @@ -1508,7 +1512,8 @@ StatusCode CurveFS::ListSnapShotFile(const std::string & fileName,
storeStatus == StoreStatus::OK) {
return StatusCode::kOK;
} else {
LOG(ERROR) << fileName << ", storage ListFile return = " << storeStatus;
LOG(ERROR) << fileName << ", storage ListFile return = "
<< PrintStoreStatusByErrorCode(storeStatus);
return StatusCode::kStorageError;
}
}
Expand Down Expand Up @@ -1702,10 +1707,10 @@ StatusCode CurveFS::GetSnapShotFileSegment(
<< ", offset = " << offset;
return StatusCode::kSegmentNotAllocated;
} else {
LOG(ERROR) << "get segment fail, KInternalError, ret = " << storeRet
<< ", fileInfo.id() = "
<< fileInfo.id()
<< ", offset = " << offset;
LOG(ERROR) << "get segment fail, KInternalError, ret = "
<< PrintStoreStatusByErrorCode(storeRet)
<< ", fileInfo.id() = " << fileInfo.id()
<< ", offset = " << offset;
return StatusCode::KInternalError;
}
}
Expand Down Expand Up @@ -2038,7 +2043,8 @@ StatusCode CurveFS::CheckPathOwnerInternal(const std::string &filename,
LOG(WARNING) << paths[i] << " not exist";
return StatusCode::kFileNotExists;
} else {
LOG(ERROR) << "GetFile " << paths[i] << " error, errcode = " << ret;
LOG(ERROR) << "GetFile " << paths[i] << " error, errcode = "
<< PrintStoreStatusByErrorCode(ret);
return StatusCode::kStorageError;
}
tempParentID = fileInfo.id();
Expand Down Expand Up @@ -2393,7 +2399,7 @@ StatusCode CurveFS::ListCloneSourceFileSegments(
"filename = "
<< fileInfo->filename()
<< ", source file name = " << fileInfo->clonesource()
<< ", ret = " << status;
<< ", ret = " << PrintStoreStatusByErrorCode(status);
return StatusCode::kStorageError;
}

Expand Down
12 changes: 12 additions & 0 deletions src/mds/nameserver2/namespace_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ enum class StoreStatus {
};
std::ostream& operator << (std::ostream & os, StoreStatus &s);

inline const char* PrintStoreStatusByErrorCode(StoreStatus status) {
switch (status) {
case StoreStatus::OK:
return "OK";
case StoreStatus::KeyNotExist:
return "KeyNotExist";
case StoreStatus::InternalError:
return "InternalError";
default:
return "unknown status";
}
}
// TODO(hzsunjianliang): may be storage need high level abstraction
// put the encoding internal, not external

Expand Down

0 comments on commit 91ad4ad

Please sign in to comment.