diff --git a/src/server/cluster/cluster_defs.cc b/src/server/cluster/cluster_defs.cc index d5ae508fa..36e77b52c 100644 --- a/src/server/cluster/cluster_defs.cc +++ b/src/server/cluster/cluster_defs.cc @@ -116,16 +116,17 @@ bool IsClusterShardedByTag() { return IsClusterEnabledOrEmulated() || LockTagOptions::instance().enabled; } -std::optional SlotOwnershipErrorStr(SlotId slot_id) { +facade::ErrorReply SlotOwnershipError(SlotId slot_id) { const cluster::ClusterConfig* cluster_config = ClusterFamily::cluster_config(); if (!cluster_config) - return facade::kClusterNotConfigured; + return facade::ErrorReply{facade::kClusterNotConfigured}; if (!cluster_config->IsMySlot(slot_id)) { // See more details here: https://redis.io/docs/reference/cluster-spec/#moved-redirection cluster::ClusterNodeInfo master = cluster_config->GetMasterNodeForSlot(slot_id); - return absl::StrCat("-MOVED ", slot_id, " ", master.ip, ":", master.port); + return facade::ErrorReply{absl::StrCat("-MOVED ", slot_id, " ", master.ip, ":", master.port), + "MOVED"}; } - return std::nullopt; + return facade::ErrorReply{facade::OpStatus::OK}; } } // namespace dfly::cluster diff --git a/src/server/cluster/cluster_defs.h b/src/server/cluster/cluster_defs.h index 1e0c820fe..7ef509d49 100644 --- a/src/server/cluster/cluster_defs.h +++ b/src/server/cluster/cluster_defs.h @@ -10,6 +10,8 @@ #include #include +#include "facade/facade_types.h" + namespace dfly::cluster { using SlotId = uint16_t; @@ -170,7 +172,7 @@ enum class MigrationState : uint8_t { SlotId KeySlot(std::string_view key); // return error message if slot doesn't belong to this node -std::optional SlotOwnershipErrorStr(SlotId slot_id); +facade::ErrorReply SlotOwnershipError(SlotId slot_id); void InitializeCluster(); bool IsClusterEnabled(); diff --git a/src/server/list_family.cc b/src/server/list_family.cc index d6780b645..d23c72202 100644 --- a/src/server/list_family.cc +++ b/src/server/list_family.cc @@ -1118,9 +1118,9 @@ void BPopGeneric(ListDir dir, CmdArgList args, Transaction* tx, SinkReplyBuilder case OpStatus::TIMED_OUT: return rb->SendNullArray(); case OpStatus::KEY_MOVED: { - auto error = cluster::SlotOwnershipErrorStr(*tx->GetUniqueSlotId()); - CHECK(error.has_value()); - return builder->SendError(std::move(*error)); + auto error = cluster::SlotOwnershipError(*tx->GetUniqueSlotId()); + CHECK(!error.status.has_value() || error.status.value() != facade::OpStatus::OK); + return builder->SendError(std::move(error)); } default: LOG(ERROR) << "Unexpected error " << popped_key.status(); diff --git a/src/server/main_service.cc b/src/server/main_service.cc index 6fa009ef0..e4f08c25b 100644 --- a/src/server/main_service.cc +++ b/src/server/main_service.cc @@ -940,8 +940,9 @@ optional Service::CheckKeysOwnership(const CommandId* cid, CmdArgLis } if (keys_slot.has_value()) { - if (auto error_str = cluster::SlotOwnershipErrorStr(*keys_slot); error_str) { - return ErrorReply{std::move(*error_str)}; + if (auto error = cluster::SlotOwnershipError(*keys_slot); + !error.status.has_value() || error.status.value() != facade::OpStatus::OK) { + return ErrorReply{std::move(error)}; } } diff --git a/src/server/zset_family.cc b/src/server/zset_family.cc index 7d942d228..fecf99b93 100644 --- a/src/server/zset_family.cc +++ b/src/server/zset_family.cc @@ -1279,9 +1279,9 @@ void BZPopMinMax(CmdArgList args, Transaction* tx, SinkReplyBuilder* builder, case OpStatus::TIMED_OUT: return rb->SendNullArray(); case OpStatus::KEY_MOVED: { - auto error = cluster::SlotOwnershipErrorStr(*tx->GetUniqueSlotId()); - CHECK(error.has_value()); - return builder->SendError(std::move(*error)); + auto error = cluster::SlotOwnershipError(*tx->GetUniqueSlotId()); + CHECK(!error.status.has_value() || error.status.value() != facade::OpStatus::OK); + return builder->SendError(std::move(error)); } default: LOG(ERROR) << "Unexpected error " << popped_key.status();