Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Nivras committed Dec 7, 2021
1 parent 9941a85 commit f04e00d
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/common/utils/MetaKeyUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1152,26 +1152,34 @@ GraphSpaceID MetaKeyUtils::parseLocalIdSpace(folly::StringPiece rawData) {
return *reinterpret_cast<const GraphSpaceID*>(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<const size_t*>(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<const size_t*>(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<const size_t*>(rawData.begin() + offset);
offset += sizeof(size_t) + len + sizeof(Port);
size_t hostIpLen = *reinterpret_cast<const size_t*>(rawData.begin() + offset);
offset += sizeof(size_t) + hostIpLen + sizeof(Port);
return *reinterpret_cast<const GraphSpaceID*>(rawData.begin() + offset);
}

std::string MetaKeyUtils::parseDiskPartsPath(const folly::StringPiece& rawData) {
auto offset = kDiskPartsTable.size();
size_t len = *reinterpret_cast<const size_t*>(rawData.begin() + offset);
offset += sizeof(size_t) + len + sizeof(Port) + sizeof(GraphSpaceID);
size_t hostIpLen = *reinterpret_cast<const size_t*>(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);
Expand Down

1 comment on commit f04e00d

@wenhaocs
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you. Well done.

Please sign in to comment.