From f04e00d5fb0d01b603df0e96c65572cd637ba972 Mon Sep 17 00:00:00 2001 From: Nivras <12605142+Nivras@users.noreply.github.com> Date: Tue, 7 Dec 2021 10:26:31 +0800 Subject: [PATCH] add comments --- src/common/utils/MetaKeyUtils.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/common/utils/MetaKeyUtils.cpp b/src/common/utils/MetaKeyUtils.cpp index b9fffa0360e..63535c5c958 100644 --- a/src/common/utils/MetaKeyUtils.cpp +++ b/src/common/utils/MetaKeyUtils.cpp @@ -1152,26 +1152,34 @@ GraphSpaceID MetaKeyUtils::parseLocalIdSpace(folly::StringPiece rawData) { return *reinterpret_cast(rawData.data() + offset); } +/** + * diskPartsKey = kDiskPartsTable + serializeHostAddr(HostAddr) + SpaceId + diskPath + * kDiskPartsTable = "__disk_parts__" + * HostAddr : see serializeHostAddr(), HostAddr = len(host.ip) + host.ip + host.port + * SpaceId: int32_t + * diskPath: string like "/data/storage/1/nebula/part_1" + */ + HostAddr MetaKeyUtils::parseDiskPartsHost(const folly::StringPiece& rawData) { auto offset = kDiskPartsTable.size(); - size_t len = *reinterpret_cast(rawData.begin() + offset); - std::string hostStr; - hostStr.reserve(sizeof(size_t) + len + sizeof(Port)); - hostStr.append(rawData.begin() + offset, sizeof(size_t) + len + sizeof(Port)); - return deserializeHostAddr(hostStr); + size_t hostIpLen = *reinterpret_cast(rawData.begin() + offset); + std::string hostAddrStr; + hostAddrStr.reserve(sizeof(size_t) + hostIpLen + sizeof(Port)); + hostAddrStr.append(rawData.begin() + offset, sizeof(size_t) + hostIpLen + sizeof(Port)); + return deserializeHostAddr(hostAddrStr); } GraphSpaceID MetaKeyUtils::parseDiskPartsSpace(const folly::StringPiece& rawData) { auto offset = kDiskPartsTable.size(); - size_t len = *reinterpret_cast(rawData.begin() + offset); - offset += sizeof(size_t) + len + sizeof(Port); + size_t hostIpLen = *reinterpret_cast(rawData.begin() + offset); + offset += sizeof(size_t) + hostIpLen + sizeof(Port); return *reinterpret_cast(rawData.begin() + offset); } std::string MetaKeyUtils::parseDiskPartsPath(const folly::StringPiece& rawData) { auto offset = kDiskPartsTable.size(); - size_t len = *reinterpret_cast(rawData.begin() + offset); - offset += sizeof(size_t) + len + sizeof(Port) + sizeof(GraphSpaceID); + size_t hostIpLen = *reinterpret_cast(rawData.begin() + offset); + offset += sizeof(size_t) + hostIpLen + sizeof(Port) + sizeof(GraphSpaceID); std::string path; path.reserve(rawData.size() - offset); path.append(rawData.begin() + offset, rawData.size() - offset);