Skip to content

Commit 23166ae

Browse files
committed
MB-66628: SetClusterConfig CAS must be 0 [2/8]
ns_server never implemented the support for setting the control token which means that it has always provided CAS == 0. Remove support for the control token as the list of commands supporting it isn't very consistent and a new task should be scheduled to do a full scrub over all commands if we want to implement this. Change-Id: I98a507f0ddd9d7125deb14064389d71d7e6ea207 Reviewed-on: https://review.couchbase.org/c/kv_engine/+/227532 Tested-by: Build Bot <build@couchbase.com> Reviewed-by: Pavlos Georgiou <pavlos.georgiou@couchbase.com>
1 parent 72039f2 commit 23166ae

File tree

8 files changed

+30
-64
lines changed

8 files changed

+30
-64
lines changed

cluster_framework/cluster.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ ClusterImpl::ClusterImpl(std::vector<std::unique_ptr<Node>>& nod,
142142
cb::mcbp::Feature::JSON,
143143
cb::mcbp::Feature::SNAPPY});
144144
auto rsp = connection->execute(BinprotSetClusterConfigCommand{
145-
0, globalmap, epoch, revno.load(), {}});
145+
globalmap, epoch, revno.load(), {}});
146146
if (!rsp.isSuccess()) {
147147
fmt::print(stderr,
148148
"Failed to set global CCCP on node {}: {}",
@@ -268,8 +268,7 @@ void ClusterImpl::createBucketOnNode(const Node& node,
268268
}
269269

270270
rsp = connection->execute(
271-
BinprotSetClusterConfigCommand{0,
272-
bucket.getManifest().dump(2),
271+
BinprotSetClusterConfigCommand{bucket.getManifest().dump(2),
273272
epoch,
274273
revno.load(),
275274
bucket.getName()});

daemon/mcbp_validators.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ static Status set_cluster_config_validator(Cookie& cookie) {
11711171
sizeof(SetClusterConfigPayload),
11721172
ExpectedKeyLen::Any,
11731173
ExpectedValueLen::NonZero,
1174-
ExpectedCas::Any,
1174+
ExpectedCas::NotSet,
11751175
GeneratesDocKey::No,
11761176
PROTOCOL_BINARY_RAW_BYTES | PROTOCOL_BINARY_DATATYPE_JSON);
11771177

daemon/protocol/mcbp/set_cluster_config_command_context.cc

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#include "set_cluster_config_command_context.h"
1212
#include "daemon/buckets.h"
13-
#include "daemon/session_cas.h"
1413
#include "mcbp/protocol/framebuilder.h"
1514

1615
#include <cbsasl/mechanism.h>
@@ -94,15 +93,10 @@ cb::engine_errc SetClusterConfigCommandContext::doSetClusterConfig() {
9493
// session token.
9594
cb::engine_errc status;
9695
auto state = Bucket::State::None;
97-
if (!session_cas.execute(
98-
sessiontoken, [&status, &state, &configuration, this]() {
99-
auto [rv, st] = BucketManager::instance().setClusterConfig(
100-
bucketname, configuration);
101-
status = rv;
102-
state = st;
103-
})) {
104-
status = cb::engine_errc::key_already_exists;
105-
}
96+
auto [rv, st] = BucketManager::instance().setClusterConfig(bucketname,
97+
configuration);
98+
status = rv;
99+
state = st;
106100

107101
if (status == cb::engine_errc::success) {
108102
return status;

protocol/connection/client_mcbp_commands.cc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,17 +1611,12 @@ void BinprotSetClusterConfigCommand::encode(std::vector<uint8_t>& buf) const {
16111611
}
16121612

16131613
BinprotSetClusterConfigCommand::BinprotSetClusterConfigCommand(
1614-
uint64_t token_,
1615-
std::string config,
1616-
int64_t epoch,
1617-
int64_t revision,
1618-
std::string bucket)
1614+
std::string config, int64_t epoch, int64_t revision, std::string bucket)
16191615
: BinprotGenericCommand(cb::mcbp::ClientOpcode::SetClusterConfig,
16201616
std::move(bucket)),
16211617
config(std::move(config)),
16221618
epoch(epoch),
16231619
revision(revision) {
1624-
setCas(token_);
16251620
}
16261621

16271622
BinprotObserveSeqnoCommand::BinprotObserveSeqnoCommand(Vbid vbid, uint64_t uuid)

protocol/connection/client_mcbp_commands.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,8 +1028,7 @@ class BinprotSetControlTokenCommand : public BinprotGenericCommand {
10281028

10291029
class BinprotSetClusterConfigCommand : public BinprotGenericCommand {
10301030
public:
1031-
BinprotSetClusterConfigCommand(uint64_t token_,
1032-
std::string config,
1031+
BinprotSetClusterConfigCommand(std::string config,
10331032
int64_t epoch,
10341033
int64_t revision,
10351034
std::string bucket);

tests/mcbp/mcbp_test_2.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ TEST_P(SetClusterConfigValidatorTest, InvalidDatatype) {
190190
EXPECT_EQ(cb::mcbp::Status::Einval, validate());
191191
}
192192

193-
TEST_P(SetClusterConfigValidatorTest, Cas) {
193+
TEST_P(SetClusterConfigValidatorTest, InvalidCas) {
194194
req.setCas(0xff);
195-
EXPECT_EQ(cb::mcbp::Status::Success, validate());
195+
EXPECT_EQ(cb::mcbp::Status::Einval, validate());
196196
}
197197

198198
TEST_P(SetClusterConfigValidatorTest, InvalidBodylen) {

tests/testapp/testapp_cluster_config.cc

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ class ClusterConfigTest : public TestappXattrClientTest {
1616
protected:
1717
void SetUp() override {
1818
TestappXattrClientTest::SetUp();
19-
// Make sure we've specified a session token
20-
setClusterSessionToken(0xdeadbeef);
21-
2219
protocol_binary_datatype_t expected = 0;
2320
if (hasSnappySupport() == ClientSnappySupport::Everywhere) {
2421
expected |= PROTOCOL_BINARY_DATATYPE_SNAPPY;
@@ -34,11 +31,10 @@ class ClusterConfigTest : public TestappXattrClientTest {
3431
userConnection.reset();
3532
}
3633

37-
BinprotResponse setClusterConfig(uint64_t token,
38-
const std::string& config,
34+
BinprotResponse setClusterConfig(const std::string& config,
3935
int64_t revision) {
4036
return adminConnection->execute(BinprotSetClusterConfigCommand{
41-
token, config, 1, revision, bucketName});
37+
config, 1, revision, bucketName});
4238
}
4339

4440
void test_MB_17506(bool dedupe, bool client_setting);
@@ -85,7 +81,7 @@ void ClusterConfigTest::test_MB_17506(bool dedupe, bool client_setting) {
8581
const std::string clustermap{R"({"rev":100})"};
8682

8783
// Make sure we have a cluster configuration installed
88-
auto response = setClusterConfig(token, clustermap, 100);
84+
auto response = setClusterConfig(clustermap, 100);
8985
EXPECT_TRUE(response.isSuccess());
9086

9187
BinprotGetCommand command{"foo", Vbid{1}};
@@ -121,24 +117,9 @@ void ClusterConfigTest::test_MB_17506(bool dedupe, bool client_setting) {
121117
}
122118
}
123119

124-
TEST_P(ClusterConfigTest, SetClusterConfigWithIncorrectSessionToken) {
125-
auto response = setClusterConfig(0xcafebeef, R"({"rev":100})", 100);
126-
EXPECT_FALSE(response.isSuccess()) << "Should not be allowed to set "
127-
"cluster config with invalid session "
128-
"token";
129-
EXPECT_EQ(cb::mcbp::Status::KeyEexists, response.getStatus());
130-
}
131-
132-
TEST_P(ClusterConfigTest, SetClusterConfigWithCorrectToken) {
133-
auto response = setClusterConfig(token, R"({"rev":100})", 100);
134-
EXPECT_TRUE(response.isSuccess()) << "Should be allowed to set cluster "
135-
"config with the correct session "
136-
"token";
137-
}
138-
139120
TEST_P(ClusterConfigTest, GetClusterConfig) {
140121
const std::string config{R"({"rev":100})"};
141-
ASSERT_TRUE(setClusterConfig(token, config, 100).isSuccess());
122+
ASSERT_TRUE(setClusterConfig(config, 100).isSuccess());
142123

143124
BinprotGenericCommand cmd{cb::mcbp::ClientOpcode::GetClusterConfig};
144125
const auto response = userConnection->execute(cmd);
@@ -155,11 +136,10 @@ TEST_P(ClusterConfigTest, GetClusterConfig_ClusterCompat) {
155136
// version cluster.
156137
int64_t epoch = -1;
157138
const std::string config{R"({"rev":100})"};
158-
ASSERT_TRUE(
159-
adminConnection
160-
->execute(BinprotSetClusterConfigCommand{
161-
token, config, epoch, 100 /*revision */, "default"})
162-
.isSuccess());
139+
ASSERT_TRUE(adminConnection
140+
->execute(BinprotSetClusterConfigCommand{
141+
config, epoch, 100 /*revision */, "default"})
142+
.isSuccess());
163143

164144
BinprotGenericCommand cmd{cb::mcbp::ClientOpcode::GetClusterConfig};
165145
const auto response = userConnection->execute(cmd);
@@ -235,16 +215,15 @@ void ClusterConfigTest::test_CccpPushNotification(bool global, bool brief) {
235215
if (global) {
236216
adminConnection->executeInBucket(bucketName, [&global_map](auto& c) {
237217
ASSERT_TRUE(c.execute(BinprotSetClusterConfigCommand{
238-
token, global_map, 2, 532, {}})
218+
global_map, 2, 532, {}})
239219

240220
.isSuccess());
241221
});
242222
} else {
243223
adminConnection->executeInBucket(bucketName, [&bucket_map](auto& c) {
244-
ASSERT_TRUE(
245-
c.execute(BinprotSetClusterConfigCommand{
246-
token, bucket_map, 1, 666, bucketName})
247-
.isSuccess());
224+
ASSERT_TRUE(c.execute(BinprotSetClusterConfigCommand{
225+
bucket_map, 1, 666, bucketName})
226+
.isSuccess());
248227
});
249228
}
250229

@@ -315,11 +294,11 @@ TEST_P(ClusterConfigTest, ClustermapChangeNotificationBrief_Global) {
315294

316295
TEST_P(ClusterConfigTest, SetGlobalClusterConfig) {
317296
// Set one for the default bucket
318-
setClusterConfig(token, R"({"rev":1000})", 1000);
297+
setClusterConfig(R"({"rev":1000})", 1000);
319298

320299
// Set the global config
321-
auto rsp = adminConnection->execute(BinprotSetClusterConfigCommand{
322-
token, R"({"foo" : "bar"})", 1, 100, ""});
300+
auto rsp = adminConnection->execute(
301+
BinprotSetClusterConfigCommand{R"({"foo" : "bar"})", 1, 100, ""});
323302
ASSERT_TRUE(rsp.isSuccess()) << rsp.getDataView();
324303

325304
rsp = adminConnection->execute(
@@ -339,7 +318,7 @@ TEST_P(ClusterConfigTest, SetGlobalClusterConfig) {
339318
* The bucket configuration was not reset as part of bucket deletion
340319
*/
341320
TEST_P(ClusterConfigTest, MB35395) {
342-
setClusterConfig(token, R"({"rev":1000})", 1000);
321+
setClusterConfig(R"({"rev":1000})", 1000);
343322

344323
// Recreate the bucket, and the cluster config should be gone!
345324
DeleteTestBucket();
@@ -354,7 +333,7 @@ TEST_P(ClusterConfigTest, MB35395) {
354333
}
355334

356335
TEST_P(ClusterConfigTest, MB57311_RequestWithVersion) {
357-
setClusterConfig(token, R"({"rev":1000})", 1000);
336+
setClusterConfig(R"({"rev":1000})", 1000);
358337
auto validatePushedRevno = [](int64_t epoch, int64_t revno) {
359338
nlohmann::json json;
360339
userConnection->stats(

tests/testapp/testapp_stats.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,8 @@ TEST_P(StatsTest, TestTasksAllInfo) {
525525
// Set up a config only bucket too to ensure that things work with that
526526
// present
527527
const std::string config = R"({"rev":1000})";
528-
auto rsp = adminConnection->execute(BinprotSetClusterConfigCommand{
529-
token, config, 1, 1000, "cluster-config"});
528+
auto rsp = adminConnection->execute(
529+
BinprotSetClusterConfigCommand{config, 1, 1000, "cluster-config"});
530530
ASSERT_TRUE(rsp.isSuccess()) << rsp.getStatus() << std::endl
531531
<< rsp.getDataJson();
532532

0 commit comments

Comments
 (0)