Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print error code #2800

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 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 char* MdsErrCodeToName(int code) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
inline char* MdsErrCodeToName(int code) {
inline const 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;
Expand Down Expand Up @@ -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
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::TopoErrCodeToName;

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;
<< TopoErrCodeToName(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;
<< TopoErrCodeToName(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::TopoErrCodeToName;

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: "
<< TopoErrCodeToName(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::TopoErrCodeToName(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::TopoErrCodeToName;

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: "
<< TopoErrCodeToName(updateCode);
return;
}
}
Expand Down
20 changes: 11 additions & 9 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 = " << MdsErrCodeToName(ret)
<< ", inodeid = " << fileInfo.id()
<< ", filename = " << fileInfo.filename()
<< ", correctSn = " << correctSn;
progress->SetStatus(TaskStatus::FAILED);
return StatusCode::kSnapshotFileDeleteError;
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()
Expand Down
35 changes: 16 additions & 19 deletions src/mds/nameserver2/curvefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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<FileInfo> snapShotFileInfos;
StatusCode ret = ListSnapShotFile(fileName, &snapShotFileInfos);
if (ret != StatusCode::kOK) {
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions src/mds/nameserver2/namespace_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down