Skip to content

Commit 266ef41

Browse files
committed
fix: privileged and unprivilegend connection behavior now the is the same
1 parent 60f86d1 commit 266ef41

File tree

3 files changed

+16
-35
lines changed

3 files changed

+16
-35
lines changed

src/server/cluster/cluster_family.cc

+1-18
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,6 @@ constexpr char kIdNotFound[] = "syncid not found";
6363
constexpr string_view kClusterDisabled =
6464
"Cluster is disabled. Enabled via passing --cluster_mode=emulated|yes";
6565

66-
ClusterShardInfos GetConfigForStats(ConnectionContext* cntx) {
67-
CHECK(!IsClusterEmulated());
68-
CHECK(ClusterConfig::Current() != nullptr);
69-
70-
auto config = ClusterConfig::Current()->GetConfig();
71-
if (cntx->conn()->IsPrivileged()) {
72-
return config;
73-
}
74-
75-
auto shards_info = config.Unwrap();
76-
for (auto& node : shards_info) {
77-
node.replicas.clear();
78-
}
79-
80-
return shards_info;
81-
}
82-
8366
} // namespace
8467

8568
ClusterFamily::ClusterFamily(ServerFamily* server_family) : server_family_(server_family) {
@@ -122,7 +105,7 @@ std::optional<ClusterShardInfos> ClusterFamily::GetShardInfos(ConnectionContext*
122105
}
123106

124107
if (ClusterConfig::Current() != nullptr) {
125-
return GetConfigForStats(cntx);
108+
return ClusterConfig::Current()->GetConfig();
126109
}
127110
return nullopt;
128111
}

src/server/cluster/cluster_family_test.cc

+8-8
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,14 @@ TEST_F(ClusterFamilyTest, ClusterConfigFull) {
224224
])json"}),
225225
"OK");
226226

227-
string cluster_info = RunPrivileged({"cluster", "info"}).GetString();
227+
string cluster_info = Run({"cluster", "info"}).GetString();
228228
EXPECT_THAT(cluster_info, HasSubstr("cluster_state:ok"));
229229
EXPECT_THAT(cluster_info, HasSubstr("cluster_slots_assigned:16384"));
230230
EXPECT_THAT(cluster_info, HasSubstr("cluster_slots_ok:16384"));
231231
EXPECT_THAT(cluster_info, HasSubstr("cluster_known_nodes:2"));
232232
EXPECT_THAT(cluster_info, HasSubstr("cluster_size:1"));
233233

234-
EXPECT_THAT(RunPrivileged({"cluster", "shards"}),
234+
EXPECT_THAT(Run({"cluster", "shards"}),
235235
RespArray(ElementsAre("slots", //
236236
RespArray(ElementsAre(IntArg(0), IntArg(16'383))), //
237237
"nodes", //
@@ -253,7 +253,7 @@ TEST_F(ClusterFamilyTest, ClusterConfigFull) {
253253
"replication-offset", IntArg(0), //
254254
"health", "online")))))));
255255

256-
EXPECT_THAT(RunPrivileged({"cluster", "slots"}),
256+
EXPECT_THAT(Run({"cluster", "slots"}),
257257
RespArray(ElementsAre(IntArg(0), //
258258
IntArg(16'383), //
259259
RespArray(ElementsAre( //
@@ -265,7 +265,7 @@ TEST_F(ClusterFamilyTest, ClusterConfigFull) {
265265
IntArg(8'000), //
266266
"wxyz")))));
267267

268-
EXPECT_EQ(RunPrivileged({"cluster", "nodes"}),
268+
EXPECT_EQ(Run({"cluster", "nodes"}),
269269
"abcd1234 10.0.0.1:7000@7000 master - 0 0 0 connected 0-16383\n"
270270
"wxyz 10.0.0.10:8000@8000 slave abcd1234 0 0 0 connected\n");
271271
}
@@ -338,14 +338,14 @@ TEST_F(ClusterFamilyTest, ClusterConfigFullMultipleInstances) {
338338
])json"}),
339339
"OK");
340340

341-
string cluster_info = RunPrivileged({"cluster", "info"}).GetString();
341+
string cluster_info = Run({"cluster", "info"}).GetString();
342342
EXPECT_THAT(cluster_info, HasSubstr("cluster_state:ok"));
343343
EXPECT_THAT(cluster_info, HasSubstr("cluster_slots_assigned:16384"));
344344
EXPECT_THAT(cluster_info, HasSubstr("cluster_slots_ok:16384"));
345345
EXPECT_THAT(cluster_info, HasSubstr("cluster_known_nodes:7"));
346346
EXPECT_THAT(cluster_info, HasSubstr("cluster_size:2"));
347347

348-
EXPECT_THAT(RunPrivileged({"cluster", "shards"}),
348+
EXPECT_THAT(Run({"cluster", "shards"}),
349349
RespArray(ElementsAre(
350350
RespArray(ElementsAre("slots", //
351351
RespArray(ElementsAre(IntArg(0), IntArg(10'000))), //
@@ -404,7 +404,7 @@ TEST_F(ClusterFamilyTest, ClusterConfigFullMultipleInstances) {
404404
"replication-offset", IntArg(0), //
405405
"health", "fail")))))))));
406406

407-
EXPECT_THAT(RunPrivileged({"cluster", "slots"}),
407+
EXPECT_THAT(Run({"cluster", "slots"}),
408408
RespArray(ElementsAre( //
409409
RespArray(ElementsAre(IntArg(0), //
410410
IntArg(10'000), //
@@ -427,7 +427,7 @@ TEST_F(ClusterFamilyTest, ClusterConfigFullMultipleInstances) {
427427
IntArg(8'001), //
428428
"qwerty")))))));
429429

430-
EXPECT_THAT(RunPrivileged({"cluster", "nodes"}),
430+
EXPECT_THAT(Run({"cluster", "nodes"}),
431431
"abcd1234 10.0.0.1:7000@7000 master - 0 0 0 disconnected 0-10000\n"
432432
"wxyz 10.0.0.10:8000@8000 slave abcd1234 0 0 0 connected\n"
433433
"efgh7890 10.0.0.2:7001@7001 master - 0 0 0 connected 10001-16383\n"

tests/dragonfly/cluster_test.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,7 @@ async def test_cluster_managed_service_info(df_factory):
459459
replica_id,
460460
]
461461
)
462-
# managed_service_info is ignored for cluster because we have "hidden" health for replica
463-
assert await c_master.execute_command("CLUSTER SLOTS") == expected_hidden_cluster_slots
462+
assert await c_master.execute_command("CLUSTER SLOTS") == expected_full_cluster_slots
464463
assert await c_master_admin.execute_command("CLUSTER SLOTS") == expected_full_cluster_slots
465464

466465
expected_hidden_cluster_nodes = {
@@ -490,8 +489,7 @@ async def test_cluster_managed_service_info(df_factory):
490489
"node_id": replica_id,
491490
"slots": [],
492491
}
493-
# managed_service_info is ignored for cluster because we have "hidden" health for replica
494-
assert await c_master.execute_command("CLUSTER NODES") == expected_hidden_cluster_nodes
492+
assert await c_master.execute_command("CLUSTER NODES") == expected_full_cluster_nodes
495493
assert await c_master_admin.execute_command("CLUSTER NODES") == expected_full_cluster_nodes
496494

497495
expected_hidden_cluster_shards = [
@@ -538,19 +536,19 @@ async def test_cluster_managed_service_info(df_factory):
538536
"online",
539537
]
540538
)
541-
# managed_service_info is ignored for cluster because we have "hidden" health for replica
542-
assert await c_master.execute_command("CLUSTER SHARDS") == expected_hidden_cluster_shards
539+
assert await c_master.execute_command("CLUSTER SHARDS") == expected_full_cluster_shards
543540
assert await c_master_admin.execute_command("CLUSTER SHARDS") == expected_full_cluster_shards
544541

542+
# this flag doesn't affect cluster anymore so the results will be the same
545543
await c_master.execute_command("config set managed_service_info true")
546544

547-
assert await c_master.execute_command("CLUSTER SLOTS") == expected_hidden_cluster_slots
545+
assert await c_master.execute_command("CLUSTER SLOTS") == expected_full_cluster_slots
548546
assert await c_master_admin.execute_command("CLUSTER SLOTS") == expected_full_cluster_slots
549547

550-
assert await c_master.execute_command("CLUSTER NODES") == expected_hidden_cluster_nodes
548+
assert await c_master.execute_command("CLUSTER NODES") == expected_full_cluster_nodes
551549
assert await c_master_admin.execute_command("CLUSTER NODES") == expected_full_cluster_nodes
552550

553-
assert await c_master.execute_command("CLUSTER SHARDS") == expected_hidden_cluster_shards
551+
assert await c_master.execute_command("CLUSTER SHARDS") == expected_full_cluster_shards
554552
assert await c_master_admin.execute_command("CLUSTER SHARDS") == expected_full_cluster_shards
555553

556554

0 commit comments

Comments
 (0)