Skip to content

Commit

Permalink
[refactor]mds: print the error code
Browse files Browse the repository at this point in the history
add topology support and remove storage status

Signed-off-by: NopeDl <[email protected]>
  • Loading branch information
NopeDl committed Oct 24, 2023
1 parent 91ad4ad commit 3f71912
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 56 deletions.
55 changes: 54 additions & 1 deletion src/mds/common/mds_define.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const int kCsClientReturnFail = -5;
// error code: chunkserver offline
const int kCsClientCSOffline = -6;

inline const char* PrintMdsDescByErrorCode(int code) {
const char* PrintMdsDescByErrorCode(int code) {
switch (code) {
case kMdsSuccess:
return "MDS execution succeeded";
Expand Down Expand Up @@ -125,6 +125,59 @@ const int kTopoErrCodePoolsetNotFound = -20;
const int kTopoErrCodeCannotDeleteDefaultPoolset = -21;
const int kTopoErrCodeConflictBlockSizeAndChunkSize = -22;

const char* PrintTopoErrCodeDescription(int code) {
switch (code) {
case kTopoErrCodeSuccess:
return "kTopoErrCodeSuccess";
case kTopoErrCodeInternalError:
return "kTopoErrCodeInternalError";
case kTopoErrCodeInvalidParam:
return "kTopoErrCodeInvalidParam";
case kTopoErrCodeInitFail:
return "kTopoErrCodeInitFail";
case kTopoErrCodeStorgeFail:
return "kTopoErrCodeStorgeFail";
case kTopoErrCodeIdDuplicated:
return "kTopoErrCodeIdDuplicated";
case kTopoErrCodeChunkServerNotFound:
return "kTopoErrCodeChunkServerNotFound";
case kTopoErrCodeServerNotFound:
return "kTopoErrCodeServerNotFound";
case kTopoErrCodeZoneNotFound:
return "kTopoErrCodeZoneNotFound";
case kTopoErrCodePhysicalPoolNotFound:
return "kTopoErrCodePhysicalPoolNotFound";
case kTopoErrCodeLogicalPoolNotFound:
return "kTopoErrCodeLogicalPoolNotFound";
case kTopoErrCodeCopySetNotFound:
return "kTopoErrCodeCopySetNotFound";
case kTopoErrCodeGenCopysetErr:
return "kTopoErrCodeGenCopysetErr";
case kTopoErrCodeAllocateIdFail:
return "kTopoErrCodeAllocateIdFail";
case kTopoErrCodeCannotRemoveWhenNotEmpty:
return "kTopoErrCodeCannotRemoveWhenNotEmpty";
case kTopoErrCodeIpPortDuplicated:
return "kTopoErrCodeIpPortDuplicated";
case kTopoErrCodeNameDuplicated:
return "kTopoErrCodeNameDuplicated";
case kTopoErrCodeCreateCopysetNodeOnChunkServerFail:
return "kTopoErrCodeCreateCopysetNodeOnChunkServerFail";
case kTopoErrCodeCannotRemoveNotRetired:
return "kTopoErrCodeCannotRemoveNotRetired";
case kTopoErrCodeLogicalPoolExist:
return "kTopoErrCodeLogicalPoolExist";
case kTopoErrCodePoolsetNotFound:
return "kTopoErrCodePoolsetNotFound";
case kTopoErrCodeCannotDeleteDefaultPoolset:
return "kTopoErrCodeCannotDeleteDefaultPoolset";
case kTopoErrCodeConflictBlockSizeAndChunkSize:
return "kTopoErrCodeConflictBlockSizeAndChunkSize";
default:
return "undefined status";
}
}

} // namespace topology
} // namespace mds
} // namespace curve
Expand Down
5 changes: 3 additions & 2 deletions src/mds/heartbeat/chunkserver_healthy_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ using ::curve::mds::topology::ChunkServerState;
using ::curve::mds::topology::ChunkServerStatus;
using ::curve::mds::topology::ChunkServer;
using ::curve::mds::topology::kTopoErrCodeSuccess;
using ::curve::mds::topology::PrintTopoErrCodeDescription;

using std::chrono::milliseconds;

Expand Down Expand Up @@ -127,7 +128,7 @@ void ChunkserverHealthyChecker::UpdateChunkServerOnlineState(

if (kTopoErrCodeSuccess != errCode) {
LOG(WARNING) << "heartbeatManager update chunkserver get error code: "
<< errCode;
<< PrintTopoErrCodeDescription(errCode);
}
}

Expand Down Expand Up @@ -168,7 +169,7 @@ bool ChunkserverHealthyChecker::TrySetChunkServerRetiredIfNeed(
ChunkServerStatus::RETIRED, info.csId);
if (kTopoErrCodeSuccess != updateErrCode) {
LOG(WARNING) << "heartbeatManager update chunkserver get error code: "
<< updateErrCode;
<< PrintTopoErrCodeDescription(updateErrCode);
return false;
}

Expand Down
4 changes: 3 additions & 1 deletion src/mds/heartbeat/copyset_conf_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

using std::chrono::milliseconds;
using ::curve::mds::heartbeat::ConfigChangeInfo;
using ::curve::mds::topology::PrintTopoErrCodeDescription;

namespace curve {
namespace mds {
Expand Down Expand Up @@ -65,7 +66,8 @@ bool CopysetConfGenerator::GenCopysetConf(
LOG(WARNING) << "topoUpdater update copyset("
<< reportCopySetInfo.GetLogicalPoolId()
<< "," << reportCopySetInfo.GetId()
<< ") got error code: " << updateCode;
<< ") got error code: "
<< PrintTopoErrCodeDescription(updateCode);
return false;
} else {
// update to memory successfully
Expand Down
2 changes: 1 addition & 1 deletion src/mds/heartbeat/heartbeat_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void HeartbeatManager::UpdateChunkServerDiskStatus(
request.chunkserverid());
if (ret != curve::mds::topology::kTopoErrCodeSuccess) {
LOG(ERROR) << "heartbeat UpdateDiskStatus get an error, ret ="
<< ret;
<< curve::mds::topology::PrintTopoErrCodeDescription(ret);
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/mds/heartbeat/topo_updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <glog/logging.h>
#include "src/mds/heartbeat/topo_updater.h"

using curve::mds::topology::PrintTopoErrCodeDescription;

namespace curve {
namespace mds {
namespace heartbeat {
Expand Down Expand Up @@ -178,7 +180,8 @@ void TopoUpdater::UpdateTopo(const CopySetInfo &reportCopySetInfo) {
LOG(ERROR) << "topoUpdater update copyset("
<< reportCopySetInfo.GetLogicalPoolId()
<< "," << reportCopySetInfo.GetId()
<< ") got error code: " << updateCode;
<< ") got error code: "
<< PrintTopoErrCodeDescription(updateCode);
return;
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/mds/nameserver2/clean_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ StatusCode CleanCore::CleanSnapShotFile(const FileInfo & fileInfo,
StoreStatus ret = storage_->DeleteSnapshotFile(fileInfo.parentid(),
fileInfo.filename());
if (ret != StoreStatus::OK) {
LOG(INFO) << "delete snapshotfile error, retCode = "
<< PrintStoreStatusByErrorCode(ret);
LOG(INFO) << "delete snapshotfile error, retCode = " << ret;
progress->SetStatus(TaskStatus::FAILED);
return StatusCode::kSnapshotFileDeleteError;
} else {
Expand Down Expand Up @@ -154,8 +153,7 @@ StatusCode CleanCore::CleanFile(const FileInfo & commonFile,
StoreStatus ret = storage_->DeleteFile(commonFile.parentid(),
commonFile.filename());
if (ret != StoreStatus::OK) {
LOG(INFO) << "delete common file error, retDesc = "
<< PrintStoreStatusByErrorCode(ret);
LOG(INFO) << "delete common file error, retDesc = " << ret;
progress->SetStatus(TaskStatus::FAILED);
return StatusCode::kCommonFileDeleteError;
} else {
Expand Down
6 changes: 2 additions & 4 deletions src/mds/nameserver2/clean_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ bool CleanManager::RecoverCleanTasks(void) {
std::vector<FileInfo> snapShotFiles;
StoreStatus ret = storage_->LoadSnapShotFile(&snapShotFiles);
if (ret != StoreStatus::OK) {
LOG(ERROR) << "Load SnapShotFile error, ret = "
<< PrintStoreStatusByErrorCode(ret);
LOG(ERROR) << "Load SnapShotFile error, ret = " << ret;
return false;
}

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

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

Expand Down Expand Up @@ -730,8 +727,7 @@ 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 = " << PrintStoreStatusByErrorCode(ret1);
<< ", filename = " << filename << ", ret = " << ret1;
return StatusCode::kStorageError;
}
LOG(INFO) << "file delete to recyclebin, fileName = " << filename
Expand Down Expand Up @@ -879,8 +875,7 @@ StatusCode CurveFS::RecoverFile(const std::string & originFileName,

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

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

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

Expand Down Expand Up @@ -1512,14 +1506,14 @@ StatusCode CurveFS::ListSnapShotFile(const std::string & fileName,
storeStatus == StoreStatus::OK) {
return StatusCode::kOK;
} else {
LOG(ERROR) << fileName << ", storage ListFile return = "
<< PrintStoreStatusByErrorCode(storeStatus);
LOG(ERROR) << fileName << ", storage ListFile return = " << storeStatus;
return StatusCode::kStorageError;
}
}

StatusCode CurveFS::GetSnapShotFileInfo(const std::string &fileName,
FileSeqType seq, FileInfo *snapshotFileInfo) const {
StatusCode CurveFS::GetSnapShotFileInfo(const std::string& fileName,
FileSeqType seq,
FileInfo* snapshotFileInfo) const {
std::vector<FileInfo> snapShotFileInfos;
StatusCode ret = ListSnapShotFile(fileName, &snapShotFileInfos);
if (ret != StatusCode::kOK) {
Expand Down Expand Up @@ -1707,18 +1701,16 @@ StatusCode CurveFS::GetSnapShotFileSegment(
<< ", offset = " << offset;
return StatusCode::kSegmentNotAllocated;
} else {
LOG(ERROR) << "get segment fail, KInternalError, ret = "
<< PrintStoreStatusByErrorCode(storeRet)
LOG(ERROR) << "get segment fail, KInternalError, ret = " << storeRet
<< ", fileInfo.id() = " << fileInfo.id()
<< ", offset = " << offset;
return StatusCode::KInternalError;
}
}

StatusCode CurveFS::OpenFile(const std::string &fileName,
const std::string &clientIP,
ProtoSession *protoSession,
FileInfo *fileInfo,
StatusCode CurveFS::OpenFile(const std::string& fileName,
const std::string& clientIP,
ProtoSession* protoSession, FileInfo* fileInfo,
CloneSourceSegment* cloneSourceSegment) {
// check the existence of the file
StatusCode ret;
Expand Down Expand Up @@ -2043,8 +2035,7 @@ StatusCode CurveFS::CheckPathOwnerInternal(const std::string &filename,
LOG(WARNING) << paths[i] << " not exist";
return StatusCode::kFileNotExists;
} else {
LOG(ERROR) << "GetFile " << paths[i] << " error, errcode = "
<< PrintStoreStatusByErrorCode(ret);
LOG(ERROR) << "GetFile " << paths[i] << " error, errcode = " << ret;
return StatusCode::kStorageError;
}
tempParentID = fileInfo.id();
Expand Down Expand Up @@ -2399,7 +2390,7 @@ StatusCode CurveFS::ListCloneSourceFileSegments(
"filename = "
<< fileInfo->filename()
<< ", source file name = " << fileInfo->clonesource()
<< ", ret = " << PrintStoreStatusByErrorCode(status);
<< ", ret = " << status;
return StatusCode::kStorageError;
}

Expand Down
16 changes: 1 addition & 15 deletions src/mds/nameserver2/namespace_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,13 @@ enum class StoreStatus {
InternalError,
};
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


// kv value storage for namespace and segment
class NameServerStorage {
public:
virtual ~NameServerStorage(void) {}
virtual ~NameServerStorage(void) {}

/**
* @brief PutFile Store fileInfo
Expand Down

0 comments on commit 3f71912

Please sign in to comment.