Skip to content

Commit c689f03

Browse files
committed
fix(store): validate client HA backend availability
1 parent 7db4eb1 commit c689f03

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

mooncake-store/src/client_service.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ tl::expected<std::optional<ha::HABackendSpec>, ErrorCode> ParseHABackendSpec(
241241
return tl::make_unexpected(ErrorCode::INVALID_PARAMS);
242242
}
243243

244+
auto availability = ha::ValidateHABackendAvailability(backend_type.value());
245+
if (availability != ErrorCode::OK) {
246+
return tl::make_unexpected(availability);
247+
}
248+
244249
return std::optional<ha::HABackendSpec>{ha::HABackendSpec{
245250
.type = backend_type.value(),
246251
.connstring = master_server_entry.substr(delimiter_pos + 3),

mooncake-store/tests/ha/leadership/ha_backend_availability_test.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
#include "ha/ha_types.h"
22

33
#include <gtest/gtest.h>
4+
#include <ylt/util/tl/expected.hpp>
45

56
namespace mooncake {
7+
8+
tl::expected<std::optional<ha::HABackendSpec>, ErrorCode> ParseHABackendSpec(
9+
const std::string& master_server_entry);
10+
611
namespace ha {
712
namespace {
813

@@ -36,6 +41,13 @@ TEST(HABackendAvailabilityTest, K8sLeaseIsRejectedUntilCoordinatorExists) {
3641
ValidateHABackendAvailability(HABackendType::K8S));
3742
}
3843

44+
TEST(HABackendAvailabilityTest,
45+
ClientSpecParsingRejectsUnavailableBackendBeforeCoordinatorCreation) {
46+
auto spec = ParseHABackendSpec("k8s://default/master");
47+
ASSERT_FALSE(spec.has_value());
48+
EXPECT_EQ(ErrorCode::UNAVAILABLE_IN_CURRENT_MODE, spec.error());
49+
}
50+
3951
} // namespace
4052
} // namespace ha
4153
} // namespace mooncake

0 commit comments

Comments
 (0)