-
Notifications
You must be signed in to change notification settings - Fork 3.8k
CASSANDRA-21174: Prevent log-incompatible upgrades #4614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aparna0522
wants to merge
4
commits into
apache:trunk
Choose a base branch
from
aparna0522:anaik-163631557
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+330
−25
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
test/unit/org/apache/cassandra/tcm/transformations/RegisterTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.cassandra.tcm.transformations; | ||
|
|
||
| import java.net.UnknownHostException; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| import org.apache.cassandra.dht.Murmur3Partitioner; | ||
| import org.apache.cassandra.distributed.test.log.ClusterMetadataTestHelper; | ||
| import org.apache.cassandra.exceptions.ExceptionCode; | ||
| import org.apache.cassandra.locator.InetAddressAndPort; | ||
| import org.apache.cassandra.tcm.ClusterMetadata; | ||
| import org.apache.cassandra.tcm.Transformation; | ||
| import org.apache.cassandra.tcm.membership.Directory; | ||
| import org.apache.cassandra.tcm.membership.Location; | ||
| import org.apache.cassandra.tcm.membership.NodeAddresses; | ||
| import org.apache.cassandra.tcm.membership.NodeId; | ||
| import org.apache.cassandra.tcm.membership.NodeState; | ||
| import org.apache.cassandra.tcm.membership.NodeVersion; | ||
| import org.apache.cassandra.tcm.serialization.Version; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| public class RegisterTest | ||
| { | ||
| private static final Location LOCATION = new Location("dc", "rack"); | ||
|
|
||
| /** | ||
| * Tests that registering a new node with a serialization version lower than the cluster's | ||
| * commonSerializationVersion is rejected. | ||
| */ | ||
| @Test | ||
| public void rejectsLowerSerializationVersion() throws UnknownHostException | ||
| { | ||
| NodeId existingNode = new NodeId(1); | ||
|
|
||
| Directory directory = Directory.EMPTY | ||
| .unsafeWithNodeForTesting(existingNode, | ||
| new NodeAddresses(InetAddressAndPort.getByName("127.0.0.1")), | ||
| LOCATION, | ||
| NodeVersion.CURRENT) | ||
| .withNodeState(existingNode, NodeState.JOINED); | ||
|
|
||
| ClusterMetadata metadata = ClusterMetadataTestHelper.minimalForTesting(Murmur3Partitioner.instance) | ||
| .transformer() | ||
| .with(directory) | ||
| .build().metadata; | ||
|
|
||
| assertEquals("commonSerializationVersion should be CURRENT_METADATA_VERSION", NodeVersion.CURRENT_METADATA_VERSION, metadata.directory.commonSerializationVersion); | ||
|
|
||
| // Try to register a new node with V3 (lower than cluster's current version) | ||
| NodeVersion lowerVersion = new NodeVersion(NodeVersion.CURRENT.cassandraVersion, Version.V3); | ||
| Register register = new Register( | ||
| new NodeAddresses(InetAddressAndPort.getByName("127.0.0.2")), | ||
| LOCATION, | ||
| lowerVersion | ||
| ); | ||
|
|
||
| Transformation.Result result = register.execute(metadata); | ||
|
|
||
| assertTrue("Registration should be rejected for node with lower serialization version", result.isRejected()); | ||
| assertEquals(ExceptionCode.INVALID, result.rejected().code); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that registering nodes with serialization version equal to or higher than | ||
| * the cluster's commonSerializationVersion is allowed. | ||
| */ | ||
| @Test | ||
| public void allowsEqualOrHigherSerializationVersion() throws UnknownHostException | ||
| { | ||
| NodeId existingNode = new NodeId(1); | ||
| NodeVersion v3 = new NodeVersion(NodeVersion.CURRENT.cassandraVersion, Version.V3); | ||
|
|
||
| Directory directory = Directory.EMPTY | ||
| .unsafeWithNodeForTesting(existingNode, | ||
| new NodeAddresses(InetAddressAndPort.getByName("127.0.0.1")), | ||
| LOCATION, | ||
| v3) | ||
| .withNodeState(existingNode, NodeState.JOINED); | ||
|
|
||
| ClusterMetadata metadata = ClusterMetadataTestHelper.minimalForTesting(Murmur3Partitioner.instance) | ||
| .transformer() | ||
| .with(directory) | ||
| .build().metadata; | ||
|
|
||
| assertEquals("commonSerializationVersion should be V3", Version.V3, metadata.directory.commonSerializationVersion); | ||
|
|
||
| // Register a node with higher version - should succeed | ||
| Register registerHigher = new Register( | ||
| new NodeAddresses(InetAddressAndPort.getByName("127.0.0.2")), | ||
| LOCATION, | ||
| NodeVersion.CURRENT | ||
| ); | ||
|
|
||
| Transformation.Result resultHigher = registerHigher.execute(metadata); | ||
| assertTrue("Registration should succeed for node with higher serialization version", resultHigher.isSuccess()); | ||
|
|
||
| // Register a node with equal version - should succeed | ||
| Register registerEqual = new Register( | ||
| new NodeAddresses(InetAddressAndPort.getByName("127.0.0.3")), | ||
| LOCATION, | ||
| v3 | ||
| ); | ||
|
|
||
| Transformation.Result resultEqual = registerEqual.execute(metadata); | ||
| assertTrue("Registration should succeed for node with equal serialization version", resultEqual.isSuccess()); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that the first node in an empty cluster can register with any version | ||
| * (bypasses version check because directory is empty). | ||
| */ | ||
| @Test | ||
| public void allowsAnyVersionForFirstNode() throws UnknownHostException | ||
| { | ||
| ClusterMetadata metadata = ClusterMetadataTestHelper.minimalForTesting(Murmur3Partitioner.instance); | ||
|
|
||
| assertTrue("Directory should be empty", metadata.directory.isEmpty()); | ||
|
|
||
| // Register first node with V0 - should succeed because directory is empty | ||
| NodeVersion v0 = new NodeVersion(NodeVersion.CURRENT.cassandraVersion, Version.V0); | ||
| Register register = new Register( | ||
| new NodeAddresses(InetAddressAndPort.getByName("127.0.0.1")), | ||
| LOCATION, | ||
| v0 | ||
| ); | ||
|
|
||
| Transformation.Result result = register.execute(metadata); | ||
| assertTrue("First node registration should succeed with any version", result.isSuccess()); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How to recover from this situation? Would it be possible to include the recovery strategy in this message or a log message?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The recovery strategy here is to upgrade the joining node to a cassandra version that supports the required metadata serialization version, so usually you can think of it as
Node Cassandra version >= minimum serialization version.I felt this was reasonably implied by the error message, but I'm open to adding extra level details or hints if you feel it would helpful. What level of detail do you have in mind?