Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class RailMonitor {
// conf: optional Config pointer; when non-null, overrides the default
// error_threshold / error_window_secs / cooldown_secs values via
// kCfgErrorThreshold / kCfgErrorWindowSecs / kCfgCooldownSecs.
// A later call with the same NIC/memory layout only refreshes the pins
// (segment COW snapshots); it does not rebuild rail_states_ or reprint
// the config banner.
Status load(std::shared_ptr<const Topology> local,
std::shared_ptr<const Topology> remote,
const std::string &rail_topo_json = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,58 @@
namespace mooncake {
namespace tent {

namespace {

bool sameNicLayout(const Topology::NicEntry& a, const Topology::NicEntry& b) {
return a.name == b.name && a.pci_bus_id == b.pci_bus_id &&
a.type == b.type && a.numa_node == b.numa_node;
}

bool sameMemLayout(const Topology::MemEntry& a, const Topology::MemEntry& b) {
if (a.name != b.name || a.pci_bus_id != b.pci_bus_id || a.type != b.type ||
a.numa_node != b.numa_node)
return false;
for (size_t rank = 0; rank < Topology::DevicePriorityRanks; ++rank) {
if (a.device_list[rank] != b.device_list[rank]) return false;
}
return true;
}

// True when two snapshots describe the same NIC/memory wiring. Segment
// metadata is copy-on-write, so a buffer register publishes a new Topology*
// even when the rail map is unchanged. Comparing layout (not pointer
// identity) lets load() refresh pins without rebuilding rail_states_.
bool sameRailLayout(const Topology* a, const Topology* b) {
if (a == b) return true;
if (!a || !b) return false;
const size_t nic_count = a->getNicCount();
const size_t mem_count = a->getMemCount();
if (nic_count != b->getNicCount() || mem_count != b->getMemCount())
return false;
for (size_t i = 0; i < nic_count; ++i) {
auto* ea = a->getNicEntry(static_cast<int>(i));
auto* eb = b->getNicEntry(static_cast<int>(i));
if (!ea || !eb || !sameNicLayout(*ea, *eb)) return false;
}
for (size_t i = 0; i < mem_count; ++i) {
auto* ea = a->getMemEntry(static_cast<int>(i));
auto* eb = b->getMemEntry(static_cast<int>(i));
if (!ea || !eb || !sameMemLayout(*ea, *eb)) return false;
}
return true;
}

} // namespace

Status RailMonitor::load(std::shared_ptr<const Topology> local,
std::shared_ptr<const Topology> remote,
const std::string& rail_topo_json,
const Config* conf) {
const bool first_load = !ready_;
const bool same_layout = ready_ &&
sameRailLayout(local_.get(), local.get()) &&
sameRailLayout(remote_.get(), remote.get());

local_ = std::move(local);
remote_ = std::move(remote);
if (conf) {
Expand All @@ -29,10 +77,15 @@ Status RailMonitor::load(std::shared_ptr<const Topology> local,
conf->get(kCfgErrorWindowSecs, (int)error_window_.count()));
cooldown_ = std::chrono::seconds(
conf->get(kCfgCooldownSecs, (int)cooldown_.count()));
LOG(INFO) << "RailMonitor: error_threshold=" << error_threshold_
<< " error_window=" << error_window_.count() << "s"
<< " cooldown=" << cooldown_.count() << "s";
// Config is identical on every COW snapshot refresh. Log once per
// monitor so PD/e2e does not reprint the banner per slice/worker.
if (first_load) {
LOG(INFO) << "RailMonitor: error_threshold=" << error_threshold_
<< " error_window=" << error_window_.count() << "s"
<< " cooldown=" << cooldown_.count() << "s";
}
}
if (same_layout) return Status::OK();
if (!rail_topo_json.empty()) {
auto status = loadFromJson(rail_topo_json);
if (status.ok()) return status;
Expand Down
37 changes: 37 additions & 0 deletions mooncake-transfer-engine/tent/tests/rail_monitor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,43 @@ TEST(RailMonitorRecoverTest, FindBestAfterRecovery) {
// pause would expire in ~2s.
// ---------------------------------------------------------------------------

// Segment metadata is copy-on-write: a new Topology object with the same
// NIC/memory wiring must not rebuild rail_states_ (that would reset
// error_count) and must not treat the reload as a first-time config log.
TEST(RailMonitorLoadTest, SameLayoutReloadPreservesErrorCount) {
auto local1 = makeSingleNicTopology("mlx5_0");
auto remote1 = makeSingleNicTopology("mlx5_1");
auto local2 = makeSingleNicTopology("mlx5_0");
auto remote2 = makeSingleNicTopology("mlx5_1");
Config cfg;
RailMonitor rail;
ASSERT_TRUE(rail.load(local1, remote1, "", &cfg).ok());

rail.markFailed(0, 0);
rail.markFailed(0, 0);
EXPECT_TRUE(rail.available(0, 0))
<< "Two failures are below the default threshold of 3";

ASSERT_TRUE(rail.load(local2, remote2, "", &cfg).ok());
rail.markFailed(0, 0);
EXPECT_FALSE(rail.available(0, 0))
<< "COW snapshot refresh must not reset rail error_count";
}

TEST(RailMonitorLoadTest, DifferentLayoutRebuildsMapping) {
auto local = makeSingleNicTopology("mlx5_0");
auto remote_old = makeSingleNicTopology("mlx5_1");
auto remote_new = makeSingleNicTopology("mlx5_2");
RailMonitor rail;
ASSERT_TRUE(rail.load(local, remote_old).ok());
for (int i = 0; i < 3; ++i) rail.markFailed(0, 0);
EXPECT_FALSE(rail.available(0, 0));

ASSERT_TRUE(rail.load(local, remote_new).ok());
EXPECT_TRUE(rail.available(0, 0))
<< "A real topology change must rebuild rails from a clean state";
}

TEST(RailMonitorRecoverTest, CooldownDoesNotCarryOverAfterRecovery) {
auto local = makeSingleNicTopology("mlx5_0");
auto remote = makeSingleNicTopology("mlx5_1");
Expand Down
Loading