From 930359101012bcbc8aa1bc636dd3d6e3c6cc4b04 Mon Sep 17 00:00:00 2001 From: Borys Date: Mon, 23 Sep 2024 12:59:13 +0300 Subject: [PATCH] fix: mark pubusb commands as unsupported for cluster (#3767) --- src/server/cluster/cluster_family_test.cc | 13 +++++++++++++ src/server/main_service.cc | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/server/cluster/cluster_family_test.cc b/src/server/cluster/cluster_family_test.cc index 173409745..074ba2f5a 100644 --- a/src/server/cluster/cluster_family_test.cc +++ b/src/server/cluster/cluster_family_test.cc @@ -589,6 +589,19 @@ TEST_F(ClusterFamilyTest, ClusterModeSelectNotAllowed) { EXPECT_EQ(Run({"select", "0"}), "OK"); } +TEST_F(ClusterFamilyTest, ClusterModePubSubNotAllowed) { + EXPECT_THAT(Run({"PUBLISH", "ch", "message"}), + ErrArg("PUBLISH is not supported in cluster mode yet")); + EXPECT_THAT(Run({"SUBSCRIBE", "ch"}), ErrArg("SUBSCRIBE is not supported in cluster mode yet")); + EXPECT_THAT(Run({"UNSUBSCRIBE", "ch"}), + ErrArg("UNSUBSCRIBE is not supported in cluster mode yet")); + EXPECT_THAT(Run({"PSUBSCRIBE", "ch?"}), + ErrArg("PSUBSCRIBE is not supported in cluster mode yet")); + EXPECT_THAT(Run({"PUNSUBSCRIBE", "ch?"}), + ErrArg("PUNSUBSCRIBE is not supported in cluster mode yet")); + EXPECT_THAT(Run({"PUBSUB", "CHANNELS"}), ErrArg("PUBSUB is not supported in cluster mode yet")); +} + TEST_F(ClusterFamilyTest, ClusterFirstConfigCallDropsEntriesNotOwnedByNode) { InitWithDbFilename(); diff --git a/src/server/main_service.cc b/src/server/main_service.cc index 11cf2bc0f..3e4724c45 100644 --- a/src/server/main_service.cc +++ b/src/server/main_service.cc @@ -2354,6 +2354,9 @@ void Service::Exec(CmdArgList args, ConnectionContext* cntx) { } void Service::Publish(CmdArgList args, ConnectionContext* cntx) { + if (cluster::IsClusterEnabled()) { + return cntx->SendError("PUBLISH is not supported in cluster mode yet"); + } string_view channel = ArgS(args, 0); string_view messages[] = {ArgS(args, 1)}; @@ -2362,10 +2365,16 @@ void Service::Publish(CmdArgList args, ConnectionContext* cntx) { } void Service::Subscribe(CmdArgList args, ConnectionContext* cntx) { + if (cluster::IsClusterEnabled()) { + return cntx->SendError("SUBSCRIBE is not supported in cluster mode yet"); + } cntx->ChangeSubscription(true /*add*/, true /* reply*/, std::move(args)); } void Service::Unsubscribe(CmdArgList args, ConnectionContext* cntx) { + if (cluster::IsClusterEnabled()) { + return cntx->SendError("UNSUBSCRIBE is not supported in cluster mode yet"); + } if (args.size() == 0) { cntx->UnsubscribeAll(true); } else { @@ -2374,10 +2383,16 @@ void Service::Unsubscribe(CmdArgList args, ConnectionContext* cntx) { } void Service::PSubscribe(CmdArgList args, ConnectionContext* cntx) { + if (cluster::IsClusterEnabled()) { + return cntx->SendError("PSUBSCRIBE is not supported in cluster mode yet"); + } cntx->ChangePSubscription(true, true, args); } void Service::PUnsubscribe(CmdArgList args, ConnectionContext* cntx) { + if (cluster::IsClusterEnabled()) { + return cntx->SendError("PUNSUBSCRIBE is not supported in cluster mode yet"); + } if (args.size() == 0) { cntx->PUnsubscribeAll(true); } else { @@ -2429,6 +2444,9 @@ void Service::Monitor(CmdArgList args, ConnectionContext* cntx) { } void Service::Pubsub(CmdArgList args, ConnectionContext* cntx) { + if (cluster::IsClusterEnabled()) { + return cntx->SendError("PUBSUB is not supported in cluster mode yet"); + } if (args.size() < 1) { cntx->SendError(WrongNumArgsError(cntx->cid->name())); return;