diff --git a/CHANGES.txt b/CHANGES.txt index c22d138a18..8f3f182fdd 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 3.0.1 + * Disable reloading of GossipingPropertyFileSnitch (CASSANDRA-9474) * Handle single-column deletions correction in materialized views when the column is part of the view primary key (CASSANDRA-10796) * Fix issue with datadir migration on upgrade (CASSANDRA-10788) diff --git a/NEWS.txt b/NEWS.txt index b3c304af61..d41384b2ba 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -146,10 +146,13 @@ Deprecation Operations ---------- - - Switching racks is no longer an allowed operation on a node which has - data. Instead, the node will need to be decommissioned and rebootstrapped. - If moving from the SimpleSnitch, make sure the rack containing all current - nodes is named "rack1". + - Switching data center or racks is no longer an allowed operation on a node + which has data. Instead, the node will need to be decommissioned and + rebootstrapped. If moving from the SimpleSnitch, make sure that the data + center and rack containing all current nodes is named "datacenter1" and + "rack1". To override this behaviour use -Dcassandra.ignore_rack=true and/or + -Dcassandra.ignore_dc=true. + - Reloading the configuration file of GossipingPropertyFileSnitch has been disabled. New features ------------ @@ -160,13 +163,6 @@ New features - Native protocol server now allows both SSL and non-SSL connections on the same port. -Operations ------------- - - Changing rack or dc of live nodes is no longer possible for PropertyFileSnitch - and YamlFileNetworkTopologySnitch. Reloading the configuration file of - GossipingPropertyFileSnitch has been disabled, CASSANDRA-10243. - - 2.2.3 ===== diff --git a/src/java/org/apache/cassandra/db/SystemKeyspace.java b/src/java/org/apache/cassandra/db/SystemKeyspace.java index 8a27c9d79a..205df8be33 100644 --- a/src/java/org/apache/cassandra/db/SystemKeyspace.java +++ b/src/java/org/apache/cassandra/db/SystemKeyspace.java @@ -1068,6 +1068,21 @@ public final class SystemKeyspace return null; } + /** + * Gets the stored data center for the local node, or null if none have been set yet. + */ + public static String getDatacenter() + { + String req = "SELECT data_center FROM system.%s WHERE key='%s'"; + UntypedResultSet result = executeInternal(String.format(req, LOCAL, LOCAL)); + + // Look up the Data center (return it if found) + if (!result.isEmpty() && result.one().has("data_center")) + return result.one().getString("data_center"); + + return null; + } + public static PaxosState loadPaxosState(DecoratedKey key, CFMetaData metadata) { String req = "SELECT * FROM system.%s WHERE row_key = ? AND cf_id = ?"; diff --git a/src/java/org/apache/cassandra/service/CassandraDaemon.java b/src/java/org/apache/cassandra/service/CassandraDaemon.java index f83152b0ab..4af926a687 100644 --- a/src/java/org/apache/cassandra/service/CassandraDaemon.java +++ b/src/java/org/apache/cassandra/service/CassandraDaemon.java @@ -241,21 +241,6 @@ public class CassandraDaemon Keyspace.setInitialized(); - if (!Boolean.getBoolean("cassandra.ignore_rack")) - { - String storedRack = SystemKeyspace.getRack(); - if (storedRack != null) - { - String currentRack = DatabaseDescriptor.getEndpointSnitch().getRack(FBUtilities.getBroadcastAddress()); - if (!storedRack.equals(currentRack)) - { - logger.error("Cannot start node if snitch's rack differs from previous rack. " + - "Please fix the snitch or decommission and rebootstrap this node."); - System.exit(100); - } - } - } - // initialize keyspaces for (String keyspaceName : Schema.instance.getKeyspaces()) { diff --git a/src/java/org/apache/cassandra/service/StartupChecks.java b/src/java/org/apache/cassandra/service/StartupChecks.java index ebe4b26259..c2c5acc35c 100644 --- a/src/java/org/apache/cassandra/service/StartupChecks.java +++ b/src/java/org/apache/cassandra/service/StartupChecks.java @@ -75,7 +75,9 @@ public class StartupChecks initSigarLibrary, checkDataDirs, checkSSTablesFormat, - checkSystemKeyspaceState); + checkSystemKeyspaceState, + checkDatacenter, + checkRack); public StartupChecks withDefaultTests() { @@ -300,4 +302,48 @@ public class StartupChecks } } }; + + public static final StartupCheck checkDatacenter = new StartupCheck() + { + public void execute() throws StartupException + { + if (!Boolean.getBoolean("cassandra.ignore_dc")) + { + String storedDc = SystemKeyspace.getDatacenter(); + if (storedDc != null) + { + String currentDc = DatabaseDescriptor.getEndpointSnitch().getDatacenter(FBUtilities.getBroadcastAddress()); + if (!storedDc.equals(currentDc)) + { + String formatMessage = "Cannot start node if snitch's data center (%s) differs from previous data center (%s). " + + "Please fix the snitch configuration, decommission and rebootstrap this node or use the flag -Dcassandra.ignore_dc=true."; + + throw new StartupException(100, String.format(formatMessage, currentDc, storedDc)); + } + } + } + } + }; + + public static final StartupCheck checkRack = new StartupCheck() + { + public void execute() throws StartupException + { + if (!Boolean.getBoolean("cassandra.ignore_rack")) + { + String storedRack = SystemKeyspace.getRack(); + if (storedRack != null) + { + String currentRack = DatabaseDescriptor.getEndpointSnitch().getRack(FBUtilities.getBroadcastAddress()); + if (!storedRack.equals(currentRack)) + { + String formatMessage = "Cannot start node if snitch's rack (%s) differs from previous rack (%s). " + + "Please fix the snitch configuration, decommission and rebootstrap this node or use the flag -Dcassandra.ignore_rack=true."; + + throw new StartupException(100, String.format(formatMessage, currentRack, storedRack)); + } + } + } + } + }; }