Skip to content

Commit

Permalink
update server id map for mismatched server ids between smc and healthmon
Browse files Browse the repository at this point in the history
Summary: update mismatched server ids in the server id map under a switch.

Reviewed By: lima1756

Differential Revision: D51212040

fbshipit-source-id: 7821f6571eaec28a549c0fb7ad8684a63cd9a924
  • Loading branch information
Fei Chen authored and facebook-github-bot committed Nov 29, 2023
1 parent 7efbf3a commit 26b7273
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
43 changes: 43 additions & 0 deletions katran/lib/KatranLb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2624,4 +2624,47 @@ void KatranLb::updateSvrIdRoutingFlags() {
}
}

void KatranLb::invalidateServerIds(const std::vector<int32_t>& serverIds) {
auto server_id_map_fd = bpfAdapter_->getMapFdByName("server_id_map");
for (auto serverId : serverIds) {
LOG(ERROR) << "Invalidate the server id " << serverId
<< " in server_id_map";
int res;
if (config_.enableCidV3) {
// server_id_map is of BPF_MAP_TYPE_HASH when cidv3 is enabled
res = bpfAdapter_->bpfMapDeleteElement(server_id_map_fd, &serverId);
} else {
// server_id_map is of BPF_MAP_TYPE_ARRAY when cidv3 is NOT enabled
int valueZero = 0;
res = bpfAdapter_->bpfUpdateMap(server_id_map_fd, &serverId, &valueZero);
}
if (res != 0) {
LOG(ERROR) << "can't invalidate the entry for the server id " << serverId
<< " from the server_id_map, error: "
<< folly::errnoStr(errno);
lbStats_.bpfFailedCalls++;
}
}
}

void KatranLb::revalidateServerIds(const std::vector<QuicReal>& quicReals) {
auto server_id_map_fd = bpfAdapter_->getMapFdByName("server_id_map");
for (auto [real, serverId] : quicReals) {
int realIndex = getIndexForReal(real);
if (realIndex == kError) {
LOG(ERROR) << "Can't find real " << real << " in the reals map";
continue;
}
LOG(WARNING) << "Updating server id map with server id " << serverId
<< ", real index " << realIndex;
auto res =
bpfAdapter_->bpfUpdateMap(server_id_map_fd, &serverId, &realIndex);
if (res != 0) {
LOG(ERROR) << "can't revalidate the entry for the server id " << serverId
<< " to the real " << real
<< " in server_id_map, error: " << folly::errnoStr(errno);
lbStats_.bpfFailedCalls++;
}
}
}
} // namespace katran
11 changes: 11 additions & 0 deletions katran/lib/KatranLb.h
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,17 @@ class KatranLb {
*/
void updateSvrIdRoutingFlags();

/**
* helper function to invalidate server ids from the server id map
*/
void invalidateServerIds(const std::vector<int32_t>& serverIds);

/**
* helper function to add entries for server ids which were invalidated
* in the server id map
*/
void revalidateServerIds(const std::vector<QuicReal>& quicReals);

private:
/**
* update vipmap(add or remove vip) in forwarding plane
Expand Down

0 comments on commit 26b7273

Please sign in to comment.