diff --git a/src/mds/common/mds_define.h b/src/mds/common/mds_define.h index 8dd0655476..7c000a5276 100644 --- a/src/mds/common/mds_define.h +++ b/src/mds/common/mds_define.h @@ -47,6 +47,27 @@ const int kCsClientReturnFail = -5; // error code: chunkserver offline const int kCsClientCSOffline = -6; +inline char* MdsErrCodeToName(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; @@ -104,6 +125,59 @@ const int kTopoErrCodePoolsetNotFound = -20; const int kTopoErrCodeCannotDeleteDefaultPoolset = -21; const int kTopoErrCodeConflictBlockSizeAndChunkSize = -22; +inline const char* TopoErrCodeToName(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 diff --git a/src/mds/heartbeat/chunkserver_healthy_checker.cpp b/src/mds/heartbeat/chunkserver_healthy_checker.cpp index ce4225bd1d..aea9bf02c8 100644 --- a/src/mds/heartbeat/chunkserver_healthy_checker.cpp +++ b/src/mds/heartbeat/chunkserver_healthy_checker.cpp @@ -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::TopoErrCodeToName; using std::chrono::milliseconds; @@ -127,7 +128,7 @@ void ChunkserverHealthyChecker::UpdateChunkServerOnlineState( if (kTopoErrCodeSuccess != errCode) { LOG(WARNING) << "heartbeatManager update chunkserver get error code: " - << errCode; + << TopoErrCodeToName(errCode); } } @@ -168,7 +169,7 @@ bool ChunkserverHealthyChecker::TrySetChunkServerRetiredIfNeed( ChunkServerStatus::RETIRED, info.csId); if (kTopoErrCodeSuccess != updateErrCode) { LOG(WARNING) << "heartbeatManager update chunkserver get error code: " - << updateErrCode; + << TopoErrCodeToName(updateErrCode); return false; } diff --git a/src/mds/heartbeat/copyset_conf_generator.cpp b/src/mds/heartbeat/copyset_conf_generator.cpp index 9139275e4e..36431a062a 100644 --- a/src/mds/heartbeat/copyset_conf_generator.cpp +++ b/src/mds/heartbeat/copyset_conf_generator.cpp @@ -27,6 +27,7 @@ using std::chrono::milliseconds; using ::curve::mds::heartbeat::ConfigChangeInfo; +using ::curve::mds::topology::TopoErrCodeToName; namespace curve { namespace mds { @@ -65,7 +66,8 @@ bool CopysetConfGenerator::GenCopysetConf( LOG(WARNING) << "topoUpdater update copyset(" << reportCopySetInfo.GetLogicalPoolId() << "," << reportCopySetInfo.GetId() - << ") got error code: " << updateCode; + << ") got error code: " + << TopoErrCodeToName(updateCode); return false; } else { // update to memory successfully diff --git a/src/mds/heartbeat/heartbeat_manager.cpp b/src/mds/heartbeat/heartbeat_manager.cpp index 188ee03112..bac8fea22d 100644 --- a/src/mds/heartbeat/heartbeat_manager.cpp +++ b/src/mds/heartbeat/heartbeat_manager.cpp @@ -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::TopoErrCodeToName(ret); } } diff --git a/src/mds/heartbeat/topo_updater.cpp b/src/mds/heartbeat/topo_updater.cpp index 154bbcb67e..eee42fd871 100644 --- a/src/mds/heartbeat/topo_updater.cpp +++ b/src/mds/heartbeat/topo_updater.cpp @@ -23,6 +23,8 @@ #include #include "src/mds/heartbeat/topo_updater.h" +using curve::mds::topology::TopoErrCodeToName; + namespace curve { namespace mds { namespace heartbeat { @@ -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: " + << TopoErrCodeToName(updateCode); return; } } diff --git a/src/mds/nameserver2/clean_core.cpp b/src/mds/nameserver2/clean_core.cpp index 54f743c300..20a4ed1ea1 100644 --- a/src/mds/nameserver2/clean_core.cpp +++ b/src/mds/nameserver2/clean_core.cpp @@ -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 = " << MdsErrCodeToName(ret) + << ", inodeid = " << fileInfo.id() + << ", filename = " << fileInfo.filename() + << ", correctSn = " << correctSn; progress->SetStatus(TaskStatus::FAILED); return StatusCode::kSnapshotFileDeleteError; } @@ -123,7 +123,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 = " << MdsErrCodeToName(ret) << ", inodeid = " << commonFile.id() << ", filename = " << commonFile.filename() << ", sequenceNum = " << commonFile.seqnum(); @@ -153,7 +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, retCode = " << ret; + LOG(INFO) << "delete common file error, retDesc = " << ret; progress->SetStatus(TaskStatus::FAILED); return StatusCode::kCommonFileDeleteError; } else { @@ -185,7 +185,8 @@ StatusCode CleanCore::CleanDiscardSegment( int ret = DeleteChunksInSegment(segment, seq); if (ret != 0) { LOG(ERROR) << "CleanDiscardSegment failed, DeleteChunk Error, ret = " - << ret << ", filename = " << fileInfo.filename() + << MdsErrCodeToName(ret) + << ", filename = " << fileInfo.filename() << ", inodeid = " << fileInfo.id() << ", segment offset = " << segment.startoffset(); progress->SetStatus(TaskStatus::FAILED); @@ -229,7 +230,8 @@ int CleanCore::DeleteChunksInSegment(const PageFileSegment& segment, seq); if (ret != 0) { - LOG(ERROR) << "DeleteChunk failed, ret = " << ret + LOG(ERROR) << "DeleteChunk failed, ret = " + << MdsErrCodeToName(ret) << ", logicalpoolid = " << logicalPoolId << ", copysetid = " << segment.chunks()[i].copysetid() << ", chunkid = " << segment.chunks()[i].chunkid() diff --git a/src/mds/nameserver2/curvefs.cpp b/src/mds/nameserver2/curvefs.cpp index 5d5af4d75f..d4243841f0 100644 --- a/src/mds/nameserver2/curvefs.cpp +++ b/src/mds/nameserver2/curvefs.cpp @@ -679,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 = " << ret; + << ", filename = " << filename << ", ret = " << ret; return StatusCode::kStorageError; } @@ -728,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 = " << ret1; + << ", filename = " << filename << ", ret = " << ret1; return StatusCode::kStorageError; } LOG(INFO) << "file delete to recyclebin, fileName = " << filename @@ -877,7 +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 = " << ret1; + LOG(ERROR) << "storage_ recoverfile error, error = " << ret; return StatusCode::kStorageError; } return StatusCode::kOK; @@ -1122,9 +1120,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 = " << ret1; return StatusCode::kStorageError; } @@ -1385,8 +1383,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 = " << storeRet; return StatusCode::kStorageError; } @@ -1513,8 +1511,9 @@ StatusCode CurveFS::ListSnapShotFile(const std::string & fileName, } } -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 snapShotFileInfos; StatusCode ret = ListSnapShotFile(fileName, &snapShotFileInfos); if (ret != StatusCode::kOK) { @@ -1703,17 +1702,15 @@ StatusCode CurveFS::GetSnapShotFileSegment( return StatusCode::kSegmentNotAllocated; } else { LOG(ERROR) << "get segment fail, KInternalError, ret = " << storeRet - << ", fileInfo.id() = " - << fileInfo.id() - << ", offset = " << offset; + << ", 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; diff --git a/src/mds/nameserver2/namespace_storage.h b/src/mds/nameserver2/namespace_storage.h index df4e1fe0dd..52a94d1f02 100644 --- a/src/mds/nameserver2/namespace_storage.h +++ b/src/mds/nameserver2/namespace_storage.h @@ -50,15 +50,13 @@ enum class StoreStatus { InternalError, }; std::ostream& operator << (std::ostream & os, StoreStatus &s); - // 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