You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by sa...@apache.org on 2023/07/24 12:02:46 UTC
[cassandra] branch cep-21-tcm updated (090f7c3fb4 -> 12e38feec9)
This is an automated email from the ASF dual-hosted git repository.
samt pushed a change to branch cep-21-tcm
in repository https://gitbox.apache.org/repos/asf/cassandra.git
from 090f7c3fb4 [CEP-21] Implement multi-dc placement simulator for NTS
new 55bdbcde6e [CEP-21] During startup request replay from CMS asynchronously
new cd4f484fa0 [CEP-21] Ensure that SchemaTransformation impls correctly set TableMetadata epoch
new 633b40766b [CEP-21] During startup, don't open SSTables until local metadata log replay is complete
new d1fbca392a [CEP-21] Rewrite o.a.c.distributed.test.SchemaTest
new 50d186fc52 [CEP-21] Ensure that ClusterMetadata::forceEpoch keeps component epochs consistent
new 6af8a5a397 [CEP-21] Avoid NPE when getting dc/rack for not yet registered endpoints
new 96e6a32566 [CEP-21] Fix tools tests
new 12e38feec9 [CEP-21] Reinstate client notifications for joining/leaving/moving nodes
The 8 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../statements/schema/AlterTableStatement.java | 4 +-
.../org/apache/cassandra/db/ColumnFamilyStore.java | 18 +-
src/java/org/apache/cassandra/db/ReadCommand.java | 9 +-
.../cassandra/locator/AlibabaCloudSnitch.java | 6 +
.../apache/cassandra/locator/CloudstackSnitch.java | 7 +-
.../org/apache/cassandra/locator/Ec2Snitch.java | 6 +
.../cassandra/locator/GoogleCloudSnitch.java | 6 +
.../locator/GossipingPropertyFileSnitch.java | 19 +-
.../apache/cassandra/locator/ReplicaLayout.java | 5 +-
.../apache/cassandra/schema/DistributedSchema.java | 6 +-
.../org/apache/cassandra/schema/TableMetadata.java | 7 +-
.../apache/cassandra/service/CassandraDaemon.java | 4 +-
.../apache/cassandra/service/StorageService.java | 18 ++
.../org/apache/cassandra/tcm/ClusterMetadata.java | 43 +++-
.../cassandra/tcm/ClusterMetadataService.java | 2 +-
.../org/apache/cassandra/tcm/RemoteProcessor.java | 2 +-
src/java/org/apache/cassandra/tcm/Startup.java | 79 ++++----
.../tcm/listeners/ClientNotificationListener.java | 126 ++++++++++++
.../cassandra/tcm/listeners/SchemaListener.java | 21 +-
.../org/apache/cassandra/tcm/log/LocalLog.java | 15 +-
.../cassandra/tcm/transformations/AlterSchema.java | 49 ++++-
.../cassandra/distributed/impl/Instance.java | 1 +
.../distributed/impl/TestChangeListener.java | 119 +++++++++++
.../cassandra/distributed/shared/ClusterUtils.java | 134 +++++++++++++
.../cassandra/distributed/test/SchemaTest.java | 148 +++++++++-----
.../distributed/test/log/ConsistentLeaveTest.java | 19 +-
.../distributed/test/log/ConsistentMoveTest.java | 22 +--
.../distributed/test/log/FailedLeaveTest.java | 2 +
.../distributed/test/log/FuzzTestBase.java | 66 -------
.../log/InProgressSequenceCoordinationTest.java | 1 +
.../distributed/test/log/ResumableStartupTest.java | 1 +
.../test/ring/ConsistentBootstrapTest.java | 29 ++-
.../distributed/test/schema/SchemaTest.java | 55 ------
.../org/apache/cassandra/db/ReadCommandTest.java | 10 +-
.../org/apache/cassandra/schema/SchemaTest.java | 219 +++++++++++++++------
.../listeners/ClientNotificationListenerTest.java | 63 ++++++
36 files changed, 985 insertions(+), 356 deletions(-)
create mode 100644 src/java/org/apache/cassandra/tcm/listeners/ClientNotificationListener.java
create mode 100644 test/distributed/org/apache/cassandra/distributed/impl/TestChangeListener.java
delete mode 100644 test/distributed/org/apache/cassandra/distributed/test/schema/SchemaTest.java
create mode 100644 test/unit/org/apache/cassandra/tcm/listeners/ClientNotificationListenerTest.java
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org
[cassandra] 07/08: [CEP-21] Fix tools tests
Posted by sa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
samt pushed a commit to branch cep-21-tcm
in repository https://gitbox.apache.org/repos/asf/cassandra.git
commit 96e6a32566f22625d747afb18e607edc46ac707c
Author: Marcus Eriksson <ma...@apache.org>
AuthorDate: Tue Apr 4 17:07:58 2023 +0200
[CEP-21] Fix tools tests
patch by Marcus Eriksson; reviewed by Alex Petrov and Sam Tunnicliffe
for CASSANDRA-18462
---
src/java/org/apache/cassandra/tcm/ClusterMetadataService.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/java/org/apache/cassandra/tcm/ClusterMetadataService.java b/src/java/org/apache/cassandra/tcm/ClusterMetadataService.java
index 7978a58741..09db32ac13 100644
--- a/src/java/org/apache/cassandra/tcm/ClusterMetadataService.java
+++ b/src/java/org/apache/cassandra/tcm/ClusterMetadataService.java
@@ -191,7 +191,7 @@ public class ClusterMetadataService
ClusterMetadata emptyFromSystemTables = emptyWithSchemaFromSystemTables();
emptyFromSystemTables.schema.initializeKeyspaceInstances(DistributedSchema.empty(), loadSSTables);
emptyFromSystemTables = emptyFromSystemTables.forceEpoch(Epoch.EMPTY);
- LocalLog log = LocalLog.sync(emptyFromSystemTables, new AtomicLongBackedProcessor.InMemoryStorage(), true);
+ LocalLog log = LocalLog.sync(emptyFromSystemTables, new AtomicLongBackedProcessor.InMemoryStorage(), false);
ClusterMetadataService cms = new ClusterMetadataService(new UniformRangePlacement(),
MetadataSnapshots.NO_OP,
log,
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org
[cassandra] 01/08: [CEP-21] During startup request replay from CMS asynchronously
Posted by sa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
samt pushed a commit to branch cep-21-tcm
in repository https://gitbox.apache.org/repos/asf/cassandra.git
commit 55bdbcde6e3d75cfb6371ead0733b3ce8a376797
Author: Marcus Eriksson <ma...@apache.org>
AuthorDate: Fri Mar 31 16:03:47 2023 +0200
[CEP-21] During startup request replay from CMS asynchronously
patch by Marcus Eriksson; reviewed by Alex Petrov and Sam Tunnicliffe
for CASSANDRA-18456
---
src/java/org/apache/cassandra/locator/ReplicaLayout.java | 5 +----
src/java/org/apache/cassandra/schema/TableMetadata.java | 7 +------
src/java/org/apache/cassandra/service/CassandraDaemon.java | 4 ++--
src/java/org/apache/cassandra/tcm/RemoteProcessor.java | 2 +-
4 files changed, 5 insertions(+), 13 deletions(-)
diff --git a/src/java/org/apache/cassandra/locator/ReplicaLayout.java b/src/java/org/apache/cassandra/locator/ReplicaLayout.java
index 4d4d6fc363..82d9dd31f5 100644
--- a/src/java/org/apache/cassandra/locator/ReplicaLayout.java
+++ b/src/java/org/apache/cassandra/locator/ReplicaLayout.java
@@ -27,7 +27,6 @@ import org.apache.cassandra.dht.Token;
import org.apache.cassandra.gms.FailureDetector;
import org.apache.cassandra.tcm.Epoch;
import org.apache.cassandra.schema.KeyspaceMetadata;
-import org.apache.cassandra.tcm.ownership.TokenMap;
import org.apache.cassandra.tcm.ClusterMetadata;
import org.apache.cassandra.utils.FBUtilities;
@@ -401,9 +400,7 @@ public abstract class ReplicaLayout<E extends Endpoints<E>>
static EndpointsForRange forNonLocalStategyRangeRead(ClusterMetadata metadata, KeyspaceMetadata keyspace, AbstractBounds<PartitionPosition> range)
{
- TokenMap tokenMap = metadata.tokenMap;
- Token token = tokenMap.nextToken(tokenMap.tokens(), range.right.getToken());
- return metadata.placements.get(keyspace.params.replication).reads.forRange(token);
+ return metadata.placements.get(keyspace.params.replication).reads.forRange(range.right.getToken());
}
static EndpointsForToken forNonLocalStrategyTokenRead(ClusterMetadata metadata, KeyspaceMetadata keyspace, Token token)
diff --git a/src/java/org/apache/cassandra/schema/TableMetadata.java b/src/java/org/apache/cassandra/schema/TableMetadata.java
index 031fa829b6..dda2c519b1 100644
--- a/src/java/org/apache/cassandra/schema/TableMetadata.java
+++ b/src/java/org/apache/cassandra/schema/TableMetadata.java
@@ -823,12 +823,7 @@ public class TableMetadata implements SchemaElement
partitioner = DatabaseDescriptor.getPartitioner();
if (id == null)
- {
- // make sure vtables use determiniestic ids so they can be referenced in calls cross-nodes
- // see CASSANDRA-17295
- if (DatabaseDescriptor.useDeterministicTableID() || kind == Kind.VIRTUAL) id = TableId.unsafeDeterministic(keyspace, name);
- else id = TableId.generate();
- }
+ id = TableId.unsafeDeterministic(keyspace, name);
if (Flag.isCQLTable(flags))
return new TableMetadata(this);
diff --git a/src/java/org/apache/cassandra/service/CassandraDaemon.java b/src/java/org/apache/cassandra/service/CassandraDaemon.java
index aa8921109e..18e5ac5163 100644
--- a/src/java/org/apache/cassandra/service/CassandraDaemon.java
+++ b/src/java/org/apache/cassandra/service/CassandraDaemon.java
@@ -428,7 +428,7 @@ public class CassandraDaemon
exitOrFail(1, "Fatal configuration error", e);
}
- ClusterMetadataService.instance().replayAndWait();
+ ScheduledExecutors.nonPeriodicTasks.execute(() -> ClusterMetadataService.instance().replayAndWait());
// TODO: (TM/alexp), this can be made time-dependent
// Because we are writing to the system_distributed keyspace, this should happen after that is created, which
@@ -732,7 +732,7 @@ public class CassandraDaemon
// jsvc takes care of taking the rest down
logger.info("Cassandra shutting down...");
destroyClientTransports();
- //StorageService.instance.setRpcReady(false);
+ StorageService.instance.setRpcReady(false);
if (jmxServer != null)
{
diff --git a/src/java/org/apache/cassandra/tcm/RemoteProcessor.java b/src/java/org/apache/cassandra/tcm/RemoteProcessor.java
index db0310d1a1..6b70918f37 100644
--- a/src/java/org/apache/cassandra/tcm/RemoteProcessor.java
+++ b/src/java/org/apache/cassandra/tcm/RemoteProcessor.java
@@ -186,7 +186,7 @@ public final class RemoteProcessor implements Processor
else
{
candidates.timeout(from);
- logger.error("Got error from {}: {} when sending {}, retrying on {}", from, reason, verb, candidates);
+ logger.warn("Got error from {}: {} when sending {}, retrying on {}", from, reason, verb, candidates);
}
promise.tryFailure(null);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org
[cassandra] 05/08: [CEP-21] Ensure that ClusterMetadata::forceEpoch keeps component epochs consistent
Posted by sa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
samt pushed a commit to branch cep-21-tcm
in repository https://gitbox.apache.org/repos/asf/cassandra.git
commit 50d186fc5207a942417cb960506fabe2f3ab71df
Author: Sam Tunnicliffe <sa...@apache.org>
AuthorDate: Thu Mar 30 15:36:21 2023 +0100
[CEP-21] Ensure that ClusterMetadata::forceEpoch keeps component epochs consistent
patch by Sam Tunnicliffe; reviewed by Marcus Eriksson and Alex Petrov
for CASSANDRA-18460
---
.../org/apache/cassandra/tcm/ClusterMetadata.java | 43 ++++++++++++++++++----
1 file changed, 36 insertions(+), 7 deletions(-)
diff --git a/src/java/org/apache/cassandra/tcm/ClusterMetadata.java b/src/java/org/apache/cassandra/tcm/ClusterMetadata.java
index ab412cfd05..a5467e3756 100644
--- a/src/java/org/apache/cassandra/tcm/ClusterMetadata.java
+++ b/src/java/org/apache/cassandra/tcm/ClusterMetadata.java
@@ -176,17 +176,46 @@ public class ClusterMetadata
public ClusterMetadata forceEpoch(Epoch epoch)
{
+ // In certain circumstances, the last modified epoch of the individual
+ // components may have been updated beyond the epoch we're specifying here.
+ // An example is the execution of an UnsafeJoin transformation, where the
+ // sub-steps (Start/Mid/Finish) are executed in series, each updating a
+ // single ClusterMetadata and its individual components. At the end of that
+ // sequence, the CM epoch is then set forcibly to ensure the UnsafeJoin only
+ // increments the published epoch by one. As each component has its own last
+ // modified epoch, we may also need to coerce those, but only if they are
+ // greater than the epoch we're forcing here.
return new ClusterMetadata(epoch,
period,
lastInPeriod,
partitioner,
- schema,
- directory,
- tokenMap,
- placements,
- lockedRanges,
- inProgressSequences,
- extensions);
+ capLastModified(schema, epoch),
+ capLastModified(directory, epoch),
+ capLastModified(tokenMap, epoch),
+ capLastModified(placements, epoch),
+ capLastModified(lockedRanges, epoch),
+ capLastModified(inProgressSequences, epoch),
+ capLastModified(extensions, epoch));
+ }
+
+ private static Map<ExtensionKey<?,?>, ExtensionValue<?>> capLastModified(Map<ExtensionKey<?,?>, ExtensionValue<?>> original, Epoch maxEpoch)
+ {
+ Map<ExtensionKey<?, ?>, ExtensionValue<?>> updated = new HashMap<>();
+ original.forEach((key, value) -> {
+ ExtensionValue<?> newValue = value == null || value.lastModified().isEqualOrBefore(maxEpoch)
+ ? value
+ : (ExtensionValue<?>)value.withLastModified(maxEpoch);
+ updated.put(key, newValue);
+ });
+ return updated;
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <V> V capLastModified(MetadataValue<V> value, Epoch maxEpoch)
+ {
+ return value == null || value.lastModified().isEqualOrBefore(maxEpoch)
+ ? (V)value
+ : value.withLastModified(maxEpoch);
}
public Epoch nextEpoch()
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org
[cassandra] 08/08: [CEP-21] Reinstate client notifications for joining/leaving/moving nodes
Posted by sa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
samt pushed a commit to branch cep-21-tcm
in repository https://gitbox.apache.org/repos/asf/cassandra.git
commit 12e38feec94e59d516ff751af992d631aac5c685
Author: Marcus Eriksson <ma...@apache.org>
AuthorDate: Mon Apr 17 09:07:46 2023 +0200
[CEP-21] Reinstate client notifications for joining/leaving/moving nodes
patch by Marcus Eriksson; reviewed by Alex Petrov and Sam Tunnicliffe
for CASSANDRA-18463
---
.../apache/cassandra/service/StorageService.java | 18 +++
.../tcm/listeners/ClientNotificationListener.java | 126 +++++++++++++++++++++
.../org/apache/cassandra/tcm/log/LocalLog.java | 2 +
.../listeners/ClientNotificationListenerTest.java | 63 +++++++++++
4 files changed, 209 insertions(+)
diff --git a/src/java/org/apache/cassandra/service/StorageService.java b/src/java/org/apache/cassandra/service/StorageService.java
index b1e4e3093d..b6bd7edc52 100644
--- a/src/java/org/apache/cassandra/service/StorageService.java
+++ b/src/java/org/apache/cassandra/service/StorageService.java
@@ -2133,6 +2133,24 @@ public class StorageService extends NotificationBroadcasterSupport implements IE
subscriber.onDown(endpoint);
}
+ public void notifyJoined(InetAddressAndPort endpoint)
+ {
+ for (IEndpointLifecycleSubscriber subscriber : lifecycleSubscribers)
+ subscriber.onJoinCluster(endpoint);
+ }
+
+ public void notifyMoved(InetAddressAndPort endpoint)
+ {
+ for (IEndpointLifecycleSubscriber subscriber : lifecycleSubscribers)
+ subscriber.onMove(endpoint);
+ }
+
+ public void notifyLeft(InetAddressAndPort endpoint)
+ {
+ for (IEndpointLifecycleSubscriber subscriber : lifecycleSubscribers)
+ subscriber.onLeaveCluster(endpoint);
+ }
+
public boolean isRpcReady(InetAddressAndPort endpoint)
{
EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
diff --git a/src/java/org/apache/cassandra/tcm/listeners/ClientNotificationListener.java b/src/java/org/apache/cassandra/tcm/listeners/ClientNotificationListener.java
new file mode 100644
index 0000000000..58dbb4409c
--- /dev/null
+++ b/src/java/org/apache/cassandra/tcm/listeners/ClientNotificationListener.java
@@ -0,0 +1,126 @@
+/*
+ * 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.listeners;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.cassandra.locator.InetAddressAndPort;
+import org.apache.cassandra.service.StorageService;
+import org.apache.cassandra.tcm.ClusterMetadata;
+import org.apache.cassandra.tcm.membership.Directory;
+import org.apache.cassandra.tcm.membership.NodeId;
+import org.apache.cassandra.tcm.membership.NodeState;
+import org.apache.cassandra.utils.Pair;
+
+import static org.apache.cassandra.tcm.listeners.ClientNotificationListener.ChangeType.LEAVE;
+import static org.apache.cassandra.tcm.membership.NodeState.BOOTSTRAPPING;
+import static org.apache.cassandra.tcm.membership.NodeState.MOVING;
+import static org.apache.cassandra.tcm.membership.NodeState.REGISTERED;
+
+public class ClientNotificationListener implements ChangeListener
+{
+ private static final Logger logger = LoggerFactory.getLogger(ClientNotificationListener.class);
+
+ /**
+ * notify clients when node JOIN/MOVE/LEAVE
+ *
+ * note that we don't register any listeners in StorageService until starting the native protocol
+ * so we won't send any notifications during startup replay (todo: should we start native before doing the background catchup?)
+ */
+ public void notifyPostCommit(ClusterMetadata prev, ClusterMetadata next)
+ {
+ List<Pair<NodeId, ChangeType>> diff = diff(prev.directory, next.directory);
+ logger.debug("Maybe notify listeners about {}", diff);
+
+ for (Pair<NodeId, ChangeType> change : diff)
+ {
+ InetAddressAndPort endpoint = next.directory.endpoint(change.left);
+ switch (change.right)
+ {
+ case JOIN:
+ StorageService.instance.notifyJoined(endpoint);
+ break;
+ case MOVE:
+ StorageService.instance.notifyMoved(endpoint);
+ break;
+ case LEAVE:
+ StorageService.instance.notifyLeft(endpoint);
+ break;
+ }
+ }
+ }
+
+ enum ChangeType
+ {
+ MOVE,
+ JOIN,
+ LEAVE
+ }
+
+ private static List<Pair<NodeId, ChangeType>> diff(Directory prev, Directory next)
+ {
+ if (!prev.lastModified().equals(next.lastModified()))
+ {
+ List<Pair<NodeId, ChangeType>> changes = new ArrayList<>();
+ for (NodeId node : next.peerIds())
+ {
+ NodeState prevState = prev.peerState(node);
+ NodeState nextState = next.peerState(node);
+ ChangeType ct = fromNodeStateTransition(prevState, nextState);
+ if (ct != null)
+ changes.add(Pair.create(node, ct));
+ }
+ return changes;
+ }
+ return Collections.emptyList();
+ }
+
+ static ChangeType fromNodeStateTransition(NodeState prev, NodeState next)
+ {
+ if (next == null)
+ return LEAVE;
+ if (prev == next)
+ return null;
+ switch (next)
+ {
+ case MOVING:
+ case LEAVING:
+ // if we see this NodeState but the previous state was null, it means we must have missed the JOINED state
+ if (prev == null || prev == BOOTSTRAPPING || prev == REGISTERED)
+ return ChangeType.JOIN;
+ return null;
+ case JOINED:
+ if (prev == MOVING)
+ return ChangeType.MOVE;
+ return ChangeType.JOIN;
+ case LEFT:
+ return LEAVE;
+ case BOOTSTRAPPING:
+ case REGISTERED:
+ return null;
+ default:
+ throw new IllegalStateException("Unknown NodeState: " + next);
+ }
+ }
+}
diff --git a/src/java/org/apache/cassandra/tcm/log/LocalLog.java b/src/java/org/apache/cassandra/tcm/log/LocalLog.java
index 931e581c63..1259d55008 100644
--- a/src/java/org/apache/cassandra/tcm/log/LocalLog.java
+++ b/src/java/org/apache/cassandra/tcm/log/LocalLog.java
@@ -44,6 +44,7 @@ import org.apache.cassandra.tcm.ClusterMetadataService;
import org.apache.cassandra.tcm.Epoch;
import org.apache.cassandra.tcm.Transformation;
import org.apache.cassandra.tcm.listeners.ChangeListener;
+import org.apache.cassandra.tcm.listeners.ClientNotificationListener;
import org.apache.cassandra.tcm.listeners.InitializationListener;
import org.apache.cassandra.tcm.listeners.LegacyStateListener;
import org.apache.cassandra.tcm.listeners.LogListener;
@@ -572,6 +573,7 @@ public abstract class LocalLog implements Closeable
addListener(new PlacementsChangeListener());
addListener(new MetadataSnapshotListener());
addListener(new PaxosRepairListener());
+ addListener(new ClientNotificationListener());
}
private LogListener snapshotListener()
diff --git a/test/unit/org/apache/cassandra/tcm/listeners/ClientNotificationListenerTest.java b/test/unit/org/apache/cassandra/tcm/listeners/ClientNotificationListenerTest.java
new file mode 100644
index 0000000000..fde53deca9
--- /dev/null
+++ b/test/unit/org/apache/cassandra/tcm/listeners/ClientNotificationListenerTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.listeners;
+
+import org.junit.Test;
+
+import org.apache.cassandra.tcm.membership.NodeState;
+
+import static org.apache.cassandra.tcm.listeners.ClientNotificationListener.ChangeType.*;
+import static org.apache.cassandra.tcm.listeners.ClientNotificationListener.fromNodeStateTransition;
+import static org.apache.cassandra.tcm.membership.NodeState.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+public class ClientNotificationListenerTest
+{
+ @Test
+ public void testTransitions()
+ {
+ assertEquals(fromNodeStateTransition(null, JOINED), JOIN);
+ assertEquals(fromNodeStateTransition(REGISTERED, JOINED), JOIN);
+ assertEquals(fromNodeStateTransition(BOOTSTRAPPING, JOINED), JOIN);
+
+ for (NodeState ns : NodeState.values())
+ {
+ if (ns == LEFT)
+ continue;
+ assertEquals(ns.toString(), fromNodeStateTransition(ns, LEFT), LEAVE);
+ }
+
+ assertEquals(fromNodeStateTransition(null, LEFT), LEAVE);
+
+ // no client notifications when leaving/moving start:
+ assertNull(fromNodeStateTransition(JOINED, LEAVING));
+ assertNull(fromNodeStateTransition(JOINED, MOVING));
+
+ // no client notifications until JOINED
+ assertNull(fromNodeStateTransition(null, BOOTSTRAPPING));
+ assertNull(fromNodeStateTransition(null, REGISTERED));
+
+ // if LEAVING/MOVING is the first state we see for a node, assume it was JOINED before;
+ assertEquals(fromNodeStateTransition(null, LEAVING), JOIN);
+ assertEquals(fromNodeStateTransition(null, MOVING), JOIN);
+
+ assertEquals(fromNodeStateTransition(MOVING, JOINED), MOVE);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org
[cassandra] 04/08: [CEP-21] Rewrite o.a.c.distributed.test.SchemaTest
Posted by sa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
samt pushed a commit to branch cep-21-tcm
in repository https://gitbox.apache.org/repos/asf/cassandra.git
commit d1fbca392aa5b2232f82970a0c87cad3e6eacab8
Author: Sam Tunnicliffe <sa...@apache.org>
AuthorDate: Thu Mar 30 16:54:36 2023 +0100
[CEP-21] Rewrite o.a.c.distributed.test.SchemaTest
patch by Sam Tunnicliffe; reviewed by Marcus Eriksson and Alex Petrov
for CASSANDRA-18459
---
.../cassandra/distributed/impl/Instance.java | 1 +
.../distributed/impl/TestChangeListener.java | 119 +++++++++++++++++
.../cassandra/distributed/shared/ClusterUtils.java | 134 +++++++++++++++++++
.../cassandra/distributed/test/SchemaTest.java | 148 ++++++++++++++-------
.../distributed/test/log/ConsistentLeaveTest.java | 19 ++-
.../distributed/test/log/ConsistentMoveTest.java | 22 ++-
.../distributed/test/log/FailedLeaveTest.java | 2 +
.../distributed/test/log/FuzzTestBase.java | 66 ---------
.../log/InProgressSequenceCoordinationTest.java | 1 +
.../distributed/test/log/ResumableStartupTest.java | 1 +
.../test/ring/ConsistentBootstrapTest.java | 29 ++--
.../distributed/test/schema/SchemaTest.java | 55 --------
12 files changed, 389 insertions(+), 208 deletions(-)
diff --git a/test/distributed/org/apache/cassandra/distributed/impl/Instance.java b/test/distributed/org/apache/cassandra/distributed/impl/Instance.java
index 40451380ea..9468692790 100644
--- a/test/distributed/org/apache/cassandra/distributed/impl/Instance.java
+++ b/test/distributed/org/apache/cassandra/distributed/impl/Instance.java
@@ -696,6 +696,7 @@ public class Instance extends IsolatedExecutor implements IInvokableInstance
registerOutboundFilter(cluster);
});
QueryProcessor.registerStatementInvalidatingListener();
+ TestChangeListener.register();
// We need to persist this as soon as possible after startup checks.
// This should be the first write to SystemKeyspace (CASSANDRA-11742)
diff --git a/test/distributed/org/apache/cassandra/distributed/impl/TestChangeListener.java b/test/distributed/org/apache/cassandra/distributed/impl/TestChangeListener.java
new file mode 100644
index 0000000000..b73e9a9b8f
--- /dev/null
+++ b/test/distributed/org/apache/cassandra/distributed/impl/TestChangeListener.java
@@ -0,0 +1,119 @@
+/*
+ * 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.distributed.impl;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.function.Predicate;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.cassandra.tcm.ClusterMetadata;
+import org.apache.cassandra.tcm.ClusterMetadataService;
+import org.apache.cassandra.tcm.Epoch;
+import org.apache.cassandra.tcm.listeners.ChangeListener;
+import org.apache.cassandra.utils.concurrent.WaitQueue;
+
+public class TestChangeListener implements ChangeListener
+{
+ private static final Logger logger = LoggerFactory.getLogger(TestChangeListener.class);
+ public static final TestChangeListener instance = new TestChangeListener();
+
+ public static void register()
+ {
+ logger.debug("Registered TestChangeListener");
+ ClusterMetadataService.instance().log().addListener(instance);
+ }
+
+ private final List<Predicate<Epoch>> preCommitPredicates = new ArrayList<>();
+ private final List<Predicate<Epoch>> postCommitPredicates = new ArrayList<>();
+ private final WaitQueue waiters = WaitQueue.newWaitQueue();
+
+ @Override
+ public void notifyPreCommit(ClusterMetadata prev, ClusterMetadata next)
+ {
+ Iterator<Predicate<Epoch>> iter = preCommitPredicates.iterator();
+ while (iter.hasNext())
+ {
+ if (iter.next().test(next.epoch))
+ {
+ logger.debug("Epoch matches pre-commit predicate, pausing");
+ pause();
+ iter.remove();
+ }
+ }
+ }
+
+ @Override
+ public void notifyPostCommit(ClusterMetadata prev, ClusterMetadata next)
+ {
+ Iterator<Predicate<Epoch>> iter = postCommitPredicates.iterator();
+ while (iter.hasNext())
+ {
+ if (iter.next().test(next.epoch))
+ {
+ logger.debug("Epoch matches post-commit predicate, pausing");
+ pause();
+ iter.remove();
+ }
+ }
+ }
+
+ public void pauseBefore(Epoch epoch, Runnable onMatch)
+ {
+ logger.debug("Requesting pause before enacting {}", epoch);
+ preCommitPredicates.add((e) -> {
+ if (e.is(epoch))
+ {
+ onMatch.run();
+ return true;
+ }
+ return false;
+ });
+ }
+
+ public void pauseAfter(Epoch epoch, Runnable onMatch)
+ {
+ logger.debug("Requesting pause after enacting {}", epoch);
+ postCommitPredicates.add((e) -> {
+ if (e.is(epoch))
+ {
+ onMatch.run();
+ return true;
+ }
+ return false;
+ });
+ }
+
+ public void pause()
+ {
+ WaitQueue.Signal signal = waiters.register();
+ logger.debug("Log follower is paused, waiting...");
+ signal.awaitUninterruptibly();
+ logger.debug("Resumed log follower...");
+ }
+
+ public void unpause()
+ {
+ logger.debug("Unpausing log follower");
+ waiters.signalAll();
+ }
+}
diff --git a/test/distributed/org/apache/cassandra/distributed/shared/ClusterUtils.java b/test/distributed/org/apache/cassandra/distributed/shared/ClusterUtils.java
index b28fe90685..a1a23ea211 100644
--- a/test/distributed/org/apache/cassandra/distributed/shared/ClusterUtils.java
+++ b/test/distributed/org/apache/cassandra/distributed/shared/ClusterUtils.java
@@ -18,6 +18,7 @@
package org.apache.cassandra.distributed.shared;
+import java.io.Serializable;
import java.lang.reflect.Field;
import java.net.InetSocketAddress;
import java.security.Permission;
@@ -31,10 +32,12 @@ import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
+import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.BiConsumer;
+import java.util.function.BiPredicate;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.regex.Matcher;
@@ -61,6 +64,8 @@ import org.apache.cassandra.distributed.impl.AbstractCluster;
import org.apache.cassandra.distributed.impl.InstanceConfig;
import org.apache.cassandra.gms.ApplicationState;
import org.apache.cassandra.gms.VersionedValue;
+import org.apache.cassandra.distributed.impl.TestChangeListener;
+import org.apache.cassandra.distributed.test.log.TestProcessor;
import org.apache.cassandra.io.util.File;
import org.apache.cassandra.locator.InetAddressAndPort;
import org.apache.cassandra.net.Message;
@@ -72,11 +77,14 @@ import org.apache.cassandra.schema.KeyspaceMetadata;
import org.apache.cassandra.service.StorageService;
import org.apache.cassandra.tcm.ClusterMetadata;
import org.apache.cassandra.tcm.ClusterMetadataService;
+import org.apache.cassandra.tcm.Commit;
import org.apache.cassandra.tcm.Epoch;
+import org.apache.cassandra.tcm.Transformation;
import org.apache.cassandra.tcm.membership.NodeId;
import org.apache.cassandra.tcm.ownership.PlacementForRange;
import org.apache.cassandra.tools.SystemExitException;
import org.apache.cassandra.utils.Isolated;
+import org.apache.cassandra.utils.concurrent.AsyncPromise;
import org.apache.cassandra.utils.concurrent.CountDownLatch;
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
@@ -413,6 +421,132 @@ public class ClusterUtils
ClusterUtils.waitForCMSToQuiesce(cluster, getClusterMetadataVersion(leader), ignored);
}
+ public static Callable<Void> pauseBeforeEnacting(IInvokableInstance instance, Epoch epoch)
+ {
+ return pauseBeforeEnacting(instance, epoch, 10, TimeUnit.SECONDS);
+ }
+
+ protected static Callable<Void> pauseBeforeEnacting(IInvokableInstance instance,
+ Epoch epoch,
+ long wait,
+ TimeUnit waitUnit)
+ {
+ return instance.callOnInstance(() -> {
+ TestChangeListener listener = TestChangeListener.instance;
+ AsyncPromise<?> promise = new AsyncPromise<>();
+ listener.pauseBefore(epoch, () -> promise.setSuccess(null));
+ return () -> {
+ try
+ {
+ promise.get(wait, waitUnit);
+ return null;
+ }
+ catch (Throwable e)
+ {
+ throw new RuntimeException(e);
+ }
+ };
+ });
+ }
+
+ public static Callable<Void> pauseAfterEnacting(IInvokableInstance instance, Epoch epoch)
+ {
+ return pauseAfterEnacting(instance, epoch, 10, TimeUnit.SECONDS);
+ }
+
+ protected static Callable<Void> pauseAfterEnacting(IInvokableInstance instance,
+ Epoch epoch,
+ long wait,
+ TimeUnit waitUnit)
+ {
+ return instance.callOnInstance(() -> {
+ TestChangeListener listener = TestChangeListener.instance;
+ AsyncPromise<?> promise = new AsyncPromise<>();
+ listener.pauseAfter(epoch, () -> promise.setSuccess(null));
+ return () -> {
+ try
+ {
+ promise.get(wait, waitUnit);
+ return null;
+ }
+ catch (Throwable e)
+ {
+ throw new RuntimeException(e);
+ }
+ };
+ });
+ }
+
+ public static Callable<Epoch> pauseBeforeCommit(IInvokableInstance cmsInstance, SerializablePredicate<Transformation> predicate)
+ {
+ Callable<Long> remoteCallable = cmsInstance.callOnInstance(() -> {
+ TestProcessor processor = (TestProcessor) ((ClusterMetadataService.SwitchableProcessor) ClusterMetadataService.instance().processor()).delegate();
+ AsyncPromise<Epoch> promise = new AsyncPromise<>();
+ processor.pauseIf(predicate, () -> promise.setSuccess(ClusterMetadata.current().epoch));
+ return () -> {
+ try
+ {
+ return promise.get(30, TimeUnit.SECONDS).getEpoch();
+ }
+ catch (Throwable e)
+ {
+ throw new RuntimeException(e);
+ }
+ };
+ });
+ return () -> Epoch.create(remoteCallable.call());
+
+ }
+
+ public static Callable<Epoch> getSequenceAfterCommit(IInvokableInstance cmsInstance,
+ SerializableBiPredicate<Transformation, Commit.Result> predicate)
+ {
+ Callable<Long> remoteCallable = cmsInstance.callOnInstance(() -> {
+ TestProcessor processor = (TestProcessor) ((ClusterMetadataService.SwitchableProcessor) ClusterMetadataService.instance().processor()).delegate();
+
+ AsyncPromise<Epoch> promise = new AsyncPromise<>();
+ processor.registerCommitPredicate((event, result) -> {
+ if (predicate.test(event, result))
+ {
+ promise.setSuccess(result.success().replication.latestEpoch());
+ return true;
+ }
+
+ return false;
+ });
+ return () -> {
+ try
+ {
+ return promise.get(30, TimeUnit.SECONDS).getEpoch();
+ }
+ catch (Throwable e)
+ {
+ throw new RuntimeException(e);
+ }
+ };
+ });
+
+ return () -> Epoch.create(remoteCallable.call());
+ }
+
+ public static void unpauseCommits(IInvokableInstance instance)
+ {
+ instance.runOnInstance(() -> {
+ TestProcessor processor = (TestProcessor) ((ClusterMetadataService.SwitchableProcessor) ClusterMetadataService.instance().processor()).delegate();
+ processor.unpause();
+ });
+ }
+
+ public static void unpauseEnactment(IInvokableInstance instance)
+ {
+ instance.runOnInstance(() -> TestChangeListener.instance.unpause());
+ }
+
+ public static interface SerializablePredicate<T> extends Predicate<T>, Serializable
+ {}
+
+ public static interface SerializableBiPredicate<T1, T2> extends BiPredicate<T1, T2>, Serializable {}
+
private static class ClusterMetadataVersion
{
public final int node;
diff --git a/test/distributed/org/apache/cassandra/distributed/test/SchemaTest.java b/test/distributed/org/apache/cassandra/distributed/test/SchemaTest.java
index 3d54e53712..4104ea7f02 100644
--- a/test/distributed/org/apache/cassandra/distributed/test/SchemaTest.java
+++ b/test/distributed/org/apache/cassandra/distributed/test/SchemaTest.java
@@ -18,6 +18,8 @@
package org.apache.cassandra.distributed.test;
+import java.util.concurrent.Callable;
+
import org.junit.Test;
import org.apache.cassandra.config.CassandraRelevantProperties;
@@ -27,10 +29,17 @@ import org.apache.cassandra.distributed.api.Feature;
import org.apache.cassandra.distributed.api.IInvokableInstance;
import org.apache.cassandra.gms.Gossiper;
import org.apache.cassandra.schema.Schema;
+import org.apache.cassandra.tcm.Epoch;
+import org.apache.cassandra.tcm.transformations.AlterSchema;
import org.awaitility.Awaitility;
import org.awaitility.core.ConditionFactory;
import static java.time.Duration.ofSeconds;
+import static org.apache.cassandra.distributed.shared.ClusterUtils.pauseAfterEnacting;
+import static org.apache.cassandra.distributed.shared.ClusterUtils.pauseBeforeCommit;
+import static org.apache.cassandra.distributed.shared.ClusterUtils.pauseBeforeEnacting;
+import static org.apache.cassandra.distributed.shared.ClusterUtils.unpauseCommits;
+import static org.apache.cassandra.distributed.shared.ClusterUtils.unpauseEnactment;
import static org.apache.cassandra.utils.FBUtilities.getBroadcastAddressAndPort;
import static org.junit.Assert.assertTrue;
@@ -46,15 +55,40 @@ public class SchemaTest extends TestBaseImpl
{
cluster.schemaChange("CREATE TABLE " + KEYSPACE + ".tbl (pk int, ck int, v1 int, v2 int, primary key (pk, ck))");
String name = "aaa";
- cluster.get(1).schemaChangeInternal("ALTER TABLE " + KEYSPACE + ".tbl ADD " + name + " list<int>");
- cluster.get(1).executeInternal("INSERT INTO " + KEYSPACE + ".tbl (pk, ck, v1, v2) values (?,1,1,1)", 1);
- selectSilent(cluster, name);
+ // have the CMS node pause directly before committing the ALTER TABLE so we can infer the next epoch
+ Callable<Epoch> beforeCommit = pauseBeforeCommit(cluster.get(1), (e) -> e instanceof AlterSchema);
+ new Thread(() -> {
+ cluster.get(1).schemaChangeInternal("ALTER TABLE " + KEYSPACE + ".tbl ADD " + name + " list<int>");
+ cluster.get(1).executeInternal("INSERT INTO " + KEYSPACE + ".tbl (pk, ck, v1, v2) values (?,1,1,1)", 1);
+ }).start();
+
+ Epoch targetEpoch = beforeCommit.call().nextEpoch();
+ // pause the replica immediately before and after enacting the ALTER TABLE stmt
+ Callable<?> beforeEnactedOnReplica = pauseBeforeEnacting(cluster.get(2), targetEpoch);
+ Callable<?> afterEnactedOnReplica = pauseAfterEnacting(cluster.get(2), targetEpoch);
+ // unpause the CMS node and allow it to commit and replicate the ALTER TABLE
+ unpauseCommits(cluster.get(1));
+
+ // Wait for the replica to signal that it has paused before enacting the schema change
+ // then execute the query and assert that a schema disagreement error was triggered
+ beforeEnactedOnReplica.call();
+ selectExpectingError(cluster, name);
+
+ // unpause the replica and wait until it notifies that it has enacted the schema change
+ unpauseEnactment(cluster.get(2));
+ afterEnactedOnReplica.call();
+ unpauseEnactment(cluster.get(2));
cluster.get(2).flush(KEYSPACE);
- cluster.get(2).schemaChangeInternal("ALTER TABLE " + KEYSPACE + ".tbl ADD " + name + " list<int>");
+ // now that the replica has enacted the alter table, an attempt to repeat it should be rejected
+ alterTableExpectingError(cluster.get(2), name);
+ // bouncing the replica should be safe as SSTables aren't loaded until the log replay is complete
+ // and the schema is in it's most up to date state
cluster.get(2).shutdown().get();
cluster.get(2).startup();
+ cluster.coordinator(1).execute(withKeyspace("SELECT * FROM %s.tbl WHERE pk = ?"), ConsistencyLevel.ALL, 1);
cluster.get(2).forceCompact(KEYSPACE, "tbl");
+ cluster.coordinator(1).execute(withKeyspace("SELECT * FROM %s.tbl WHERE pk = ?"), ConsistencyLevel.ALL, 1);
}
}
@@ -65,21 +99,50 @@ public class SchemaTest extends TestBaseImpl
{
cluster.schemaChange("CREATE TABLE " + KEYSPACE + ".tbl (pk int, ck int, v1 int, v2 int, primary key (pk, ck))");
String name = "v10";
- cluster.get(1).schemaChangeInternal("ALTER TABLE " + KEYSPACE + ".tbl ADD " + name + " list<int>");
- cluster.get(1).executeInternal("INSERT INTO " + KEYSPACE + ".tbl (pk, ck, v1, v2) values (?,1,1,1)", 1);
- selectSilent(cluster, name);
+
+ // have the CMS node pause directly before committing the ALTER TABLE so we can infer the next epoch
+ Callable<Epoch> beforeCommit = pauseBeforeCommit(cluster.get(1), (e) -> e instanceof AlterSchema);
+ new Thread(() -> {
+ cluster.get(1).schemaChangeInternal("ALTER TABLE " + KEYSPACE + ".tbl ADD " + name + " list<int>");
+ cluster.get(1).executeInternal("INSERT INTO " + KEYSPACE + ".tbl (pk, ck, v1, v2) values (?,1,1,1)", 1);
+ }).start();
+ Epoch targetEpoch = beforeCommit.call().nextEpoch();
+
+ // pause the replica immediately before and after enacting the ALTER TABLE stmt
+ Callable<?> beforeEnactedOnReplica = pauseBeforeEnacting(cluster.get(2), targetEpoch);
+ Callable<?> afterEnactedOnReplica = pauseAfterEnacting(cluster.get(2), targetEpoch);
+ // unpause the CMS node and allow it to commit and replicate the ALTER TABLE
+ unpauseCommits(cluster.get(1));
+
+ // Wait for the replica to signal that it has paused before enacting the schema change
+ // then execute the query and assert that a schema disagreement error was triggered
+ beforeEnactedOnReplica.call();
+ selectExpectingError(cluster, name);
+
+ // unpause the replica and wait until it notifies that it has enacted the schema change
+ unpauseEnactment(cluster.get(2));
+ afterEnactedOnReplica.call();
+ unpauseEnactment(cluster.get(2));
+
cluster.get(2).flush(KEYSPACE);
- cluster.get(2).schemaChangeInternal("ALTER TABLE " + KEYSPACE + ".tbl ADD " + name + " list<int>");
+ // now that the replica has enacted the alter table, an attempt to repeat it should be rejected
+ alterTableExpectingError(cluster.get(2), name);
cluster.get(2).executeInternal("INSERT INTO " + KEYSPACE + ".tbl (pk, ck, v1, v2, " + name + ") values (?,1,1,1,[1])", 1);
cluster.get(2).flush(KEYSPACE);
cluster.get(2).forceCompact(KEYSPACE, "tbl");
+
+ // bouncing the replica should be safe as SSTables aren't loaded until the log replay is complete
+ // and the schema is in it's most up to date state
cluster.get(2).shutdown().get();
cluster.get(2).startup();
+
+ cluster.coordinator(1).execute(withKeyspace("SELECT * FROM %s.tbl WHERE pk = ?"), ConsistencyLevel.ALL, 1);
cluster.get(2).forceCompact(KEYSPACE, "tbl");
+ cluster.coordinator(1).execute(withKeyspace("SELECT * FROM %s.tbl WHERE pk = ?"), ConsistencyLevel.ALL, 1);
}
}
- private void selectSilent(Cluster cluster, String name)
+ private void selectExpectingError(Cluster cluster, String name)
{
try
{
@@ -99,26 +162,42 @@ public class SchemaTest extends TestBaseImpl
}
}
+ private void alterTableExpectingError(IInvokableInstance instance, String name)
+ {
+ try
+ {
+ instance.schemaChangeInternal("ALTER TABLE " + KEYSPACE + ".tbl ADD " + name + " list<int>");
+ }
+ catch (Exception e)
+ {
+ boolean causeIsColumnExists = false;
+ Throwable cause = e;
+ while (cause != null)
+ {
+ if (cause.getMessage() != null && cause.getMessage().contains("Column with name '" + name + "' already exists"))
+ causeIsColumnExists = true;
+ cause = cause.getCause();
+ }
+ assertTrue(causeIsColumnExists);
+ }
+ }
+
/**
- * The purpose of this test is to verify manual schema reset functinality.
+ * The original purpose of this test was to verify manual schema reset functionality, but with schema updates being
+ * serialized in the cluster metadata log local schema reset no longer makes sense so the assertions have been
+ * modified to verify that schema changes are correctly propagated to down nodes once they come back up.
* <p>
* There is a 2-node cluster and a TABLE_ONE created. The schema version is agreed on both nodes. Then the 2nd node
* is shutdown. We introduce a disagreement by dropping TABLE_ONE and creating TABLE_TWO on the 1st node. Therefore,
* the 1st node has a newer schema version with TABLE_TWO, while the shutdown 2nd node has older schema version with
* TABLE_ONE.
* <p>
- * At this point, if we just started the 2nd node, it would sync its schema by getting fresh mutations from the 1st
- * node which would result in both nodes having only the definition of TABLE_TWO.
- * <p>
- * However, before starting the 2nd node the schema is reset on the 1st node, so the 1st node will discard its local
- * schema whenever it manages to fetch a schema definition from some other node (the 2nd node in this case).
- * It is expected to end up with both nodes having only the definition of TABLE_ONE.
+ * At this point, if we just start the 2nd node, it would sync its schema by getting the transformations that it
+ * missed while down, which would result in both nodes having only the definition of TABLE_TWO.
* <p>
- * In the second phase of the test we simply break the schema on the 1st node and call reset to fetch the schema
- * definition it from the 2nd node.
*/
@Test
- public void schemaReset() throws Throwable
+ public void schemaPropagationToDownNode() throws Throwable
{
CassandraRelevantProperties.MIGRATION_DELAY.setLong(10000);
CassandraRelevantProperties.SCHEMA_PULL_INTERVAL_MS.setLong(10000);
@@ -137,43 +216,16 @@ public class SchemaTest extends TestBaseImpl
.allMatch(e -> e.equals(getBroadcastAddressAndPort()));
}));
- // when there is no node to fetch the schema from, reset local schema should immediately fail
-// Assertions.assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> {
-// cluster.get(1).runOnInstance(() -> Schema.instance.resetLocalSchema());
-// }).withMessageContaining("Cannot reset local schema when there are no other live nodes");
-
// now, let's make a disagreement, the shutdown node 2 has a definition of TABLE_ONE, while the running
// node 1 will have a definition of TABLE_TWO
cluster.coordinator(1).execute(String.format("DROP TABLE %s.%s", KEYSPACE, TABLE_ONE), ConsistencyLevel.ONE);
cluster.coordinator(1).execute(String.format("CREATE TABLE %s.%s (pk INT PRIMARY KEY, v TEXT)", KEYSPACE, TABLE_TWO), ConsistencyLevel.ONE);
await(30).until(() -> checkTablesPropagated(cluster.get(1), false, true));
- // Schema.resetLocalSchema is guarded by some conditions which would not let us reset schema if there is no
- // live node in the cluster, therefore we simply call SchemaUpdateHandler.clear (this is the only real thing
- // being done by Schema.resetLocalSchema under the hood)
-// SerializableCallable<Boolean> clear = () -> Schema.instance.updateHandler.clear().awaitUninterruptibly(1, TimeUnit.MINUTES);
-// Future<Boolean> clear1 = cluster.get(1).asyncCallsOnInstance(clear).call();
-// assertFalse(clear1.isDone());
-
// when the 2nd node is started, schema should be back in sync
cluster.get(2).startup();
-// await(30).until(() -> clear1.isDone() && clear1.get());
-
- // this proves that reset schema works on the 1st node - the most recent change should be discarded because
- // it receives the schema from the 2nd node and applies it on empty schema
- await(60).until(() -> checkTablesPropagated(cluster.get(1), true, false));
-
- // now let's break schema locally and let it be reset
-// cluster.get(1).runOnInstance(() -> Schema.instance.getLocalKeyspaces()
-// .get(SchemaConstants.SCHEMA_KEYSPACE_NAME)
-// .get().tables.forEach(t -> ColumnFamilyStore.getIfExists(t.keyspace, t.name).truncateBlockingWithoutSnapshot()));
-
- // when schema is removed and there is a node to fetch it from, the 1st node should immediately restore it
-// cluster.get(1).runOnInstance(() -> Schema.instance.resetLocalSchema());
- // note that we should not wait for this to be true because resetLocalSchema is blocking
- // and after successfully completing it, the schema should be already back in sync
- assertTrue(checkTablesPropagated(cluster.get(1), true, false));
- assertTrue(checkTablesPropagated(cluster.get(2), true, false));
+ assertTrue(checkTablesPropagated(cluster.get(1), false, true));
+ assertTrue(checkTablesPropagated(cluster.get(2), false, true));
}
}
diff --git a/test/distributed/org/apache/cassandra/distributed/test/log/ConsistentLeaveTest.java b/test/distributed/org/apache/cassandra/distributed/test/log/ConsistentLeaveTest.java
index b502fbbb48..0dd2c887fc 100644
--- a/test/distributed/org/apache/cassandra/distributed/test/log/ConsistentLeaveTest.java
+++ b/test/distributed/org/apache/cassandra/distributed/test/log/ConsistentLeaveTest.java
@@ -38,18 +38,20 @@ import org.apache.cassandra.distributed.api.TokenSupplier;
import org.apache.cassandra.distributed.fuzz.HarryHelper;
import org.apache.cassandra.distributed.fuzz.InJVMTokenAwareVisitorExecutor;
import org.apache.cassandra.distributed.fuzz.InJvmSut;
-import org.apache.cassandra.distributed.shared.ClusterUtils;
import org.apache.cassandra.distributed.shared.NetworkTopology;
import org.apache.cassandra.gms.ApplicationState;
import org.apache.cassandra.gms.Gossiper;
import org.apache.cassandra.locator.InetAddressAndPort;
import org.apache.cassandra.locator.ReplicationFactor;
import org.apache.cassandra.service.StorageService;
-import org.apache.cassandra.tcm.ClusterMetadataService;
import org.apache.cassandra.tcm.Epoch;
import org.apache.cassandra.tcm.transformations.PrepareLeave;
import static org.apache.cassandra.distributed.shared.ClusterUtils.getClusterMetadataVersion;
+import static org.apache.cassandra.distributed.shared.ClusterUtils.getSequenceAfterCommit;
+import static org.apache.cassandra.distributed.shared.ClusterUtils.pauseBeforeCommit;
+import static org.apache.cassandra.distributed.shared.ClusterUtils.unpauseCommits;
+import static org.apache.cassandra.distributed.shared.ClusterUtils.waitForCMSToQuiesce;
import static org.junit.Assert.assertFalse;
public class ConsistentLeaveTest extends FuzzTestBase
@@ -70,7 +72,7 @@ public class ConsistentLeaveTest extends FuzzTestBase
{
IInvokableInstance cmsInstance = cluster.get(1);
IInvokableInstance leavingInstance = cluster.get(2);
- ClusterUtils.waitForCMSToQuiesce(cluster, cmsInstance);
+ waitForCMSToQuiesce(cluster, cmsInstance);
configBuilder.setSUT(() -> new InJvmSut(cluster));
Run run = configBuilder.build().createRun();
@@ -79,7 +81,7 @@ public class ConsistentLeaveTest extends FuzzTestBase
" WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 2};",
ConsistencyLevel.ALL);
cluster.coordinator(1).execute(run.schemaSpec.compile().cql(), ConsistencyLevel.ALL);
- ClusterUtils.waitForCMSToQuiesce(cluster, cmsInstance);
+ waitForCMSToQuiesce(cluster, cmsInstance);
QuiescentLocalStateChecker model = new QuiescentLocalStateChecker(run, ReplicationFactor.fullOnly(2));
Visitor visitor = new LoggingVisitor(run, MutatingRowVisitor::new);
@@ -103,20 +105,17 @@ public class ConsistentLeaveTest extends FuzzTestBase
model.validateAll();
// Make sure there can be only one FinishLeave in flight
- ClusterUtils.waitForCMSToQuiesce(cluster, cmsInstance);
+ waitForCMSToQuiesce(cluster, cmsInstance);
// set expectation of finish leave & retrieve the sequence when it gets committed
Epoch currentEpoch = getClusterMetadataVersion(cmsInstance);
Callable<Epoch> finishedLeaving = getSequenceAfterCommit(cmsInstance, (e, r) -> e instanceof PrepareLeave.FinishLeave && r.isSuccess());
- cmsInstance.runOnInstance(() -> {
- TestProcessor processor = (TestProcessor) ((ClusterMetadataService.SwitchableProcessor) ClusterMetadataService.instance().processor()).delegate();
- processor.unpause();
- });
+ unpauseCommits(cmsInstance);
Epoch nextEpoch = finishedLeaving.call();
Assert.assertEquals(String.format("Epoch %s should have immediately superseded epoch %s.", nextEpoch, currentEpoch),
nextEpoch.getEpoch(), currentEpoch.getEpoch() + 1);
// wait for the cluster to all witness the finish join event
- ClusterUtils.waitForCMSToQuiesce(cluster, nextEpoch);
+ waitForCMSToQuiesce(cluster, nextEpoch);
assertGossipStatus(cluster, leavingInstance.config().num(), "LEFT");
diff --git a/test/distributed/org/apache/cassandra/distributed/test/log/ConsistentMoveTest.java b/test/distributed/org/apache/cassandra/distributed/test/log/ConsistentMoveTest.java
index 425cd7a62c..d046fc5021 100644
--- a/test/distributed/org/apache/cassandra/distributed/test/log/ConsistentMoveTest.java
+++ b/test/distributed/org/apache/cassandra/distributed/test/log/ConsistentMoveTest.java
@@ -41,17 +41,19 @@ import org.apache.cassandra.distributed.api.TokenSupplier;
import org.apache.cassandra.distributed.fuzz.HarryHelper;
import org.apache.cassandra.distributed.fuzz.InJVMTokenAwareVisitorExecutor;
import org.apache.cassandra.distributed.fuzz.InJvmSut;
-import org.apache.cassandra.distributed.shared.ClusterUtils;
import org.apache.cassandra.distributed.shared.NetworkTopology;
import org.apache.cassandra.gms.ApplicationState;
import org.apache.cassandra.gms.Gossiper;
import org.apache.cassandra.locator.InetAddressAndPort;
import org.apache.cassandra.locator.ReplicationFactor;
import org.apache.cassandra.service.StorageService;
-import org.apache.cassandra.tcm.ClusterMetadataService;
import org.apache.cassandra.tcm.Epoch;
import org.apache.cassandra.tcm.transformations.PrepareMove;
+import static org.apache.cassandra.distributed.shared.ClusterUtils.getSequenceAfterCommit;
+import static org.apache.cassandra.distributed.shared.ClusterUtils.pauseBeforeCommit;
+import static org.apache.cassandra.distributed.shared.ClusterUtils.unpauseCommits;
+import static org.apache.cassandra.distributed.shared.ClusterUtils.waitForCMSToQuiesce;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -73,7 +75,7 @@ public class ConsistentMoveTest extends FuzzTestBase
{
IInvokableInstance cmsInstance = cluster.get(1);
IInvokableInstance movingInstance = cluster.get(2);
- ClusterUtils.waitForCMSToQuiesce(cluster, cmsInstance);
+ waitForCMSToQuiesce(cluster, cmsInstance);
configBuilder.setSUT(() -> new InJvmSut(cluster));
Run run = configBuilder.build().createRun();
@@ -82,7 +84,7 @@ public class ConsistentMoveTest extends FuzzTestBase
" WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 2};",
ConsistencyLevel.ALL);
cluster.coordinator(1).execute(run.schemaSpec.compile().cql(), ConsistencyLevel.ALL);
- ClusterUtils.waitForCMSToQuiesce(cluster, cmsInstance);
+ waitForCMSToQuiesce(cluster, cmsInstance);
FuzzTestBase.QuiescentLocalStateChecker model = new FuzzTestBase.QuiescentLocalStateChecker(run, ReplicationFactor.fullOnly(2));
Visitor visitor = new LoggingVisitor(run, MutatingRowVisitor::new);
@@ -92,7 +94,7 @@ public class ConsistentMoveTest extends FuzzTestBase
model.validateAll();
// Make sure there can be only one FinishLeave in flight
- ClusterUtils.waitForCMSToQuiesce(cluster, cmsInstance);
+ waitForCMSToQuiesce(cluster, cmsInstance);
Callable<?> pending = pauseBeforeCommit(cmsInstance, (e) -> e instanceof PrepareMove.FinishMove);
new Thread(() -> {
@@ -103,15 +105,11 @@ public class ConsistentMoveTest extends FuzzTestBase
assertGossipStatus(cluster, movingInstance.config().num(), "MOVING");
+ // wait for the cluster to all witness the finish join event
Callable<Epoch> finishedMoving = getSequenceAfterCommit(cmsInstance, (e, r) -> e instanceof PrepareMove.FinishMove && r.isSuccess());
- cmsInstance.runOnInstance(() -> {
- TestProcessor processor = (TestProcessor) ((ClusterMetadataService.SwitchableProcessor) ClusterMetadataService.instance().processor()).delegate();
- processor.unpause();
- });
-
+ unpauseCommits(cmsInstance);
Epoch nextEpoch = finishedMoving.call();
- // wait for the cluster to all witness the finish join event
- ClusterUtils.waitForCMSToQuiesce(cluster, nextEpoch);
+ waitForCMSToQuiesce(cluster, nextEpoch);
// Streaming for unbootstrap has finished, any rows from the first batch should have been transferred
// from the leaving node to the new replicas. Continue to write at ONE, replication of these rows will
diff --git a/test/distributed/org/apache/cassandra/distributed/test/log/FailedLeaveTest.java b/test/distributed/org/apache/cassandra/distributed/test/log/FailedLeaveTest.java
index b7509ff40f..a22eb09167 100644
--- a/test/distributed/org/apache/cassandra/distributed/test/log/FailedLeaveTest.java
+++ b/test/distributed/org/apache/cassandra/distributed/test/log/FailedLeaveTest.java
@@ -45,6 +45,7 @@ import org.apache.cassandra.distributed.fuzz.HarryHelper;
import org.apache.cassandra.distributed.fuzz.InJVMTokenAwareVisitorExecutor;
import org.apache.cassandra.distributed.fuzz.InJvmSut;
import org.apache.cassandra.distributed.shared.ClusterUtils;
+import org.apache.cassandra.distributed.shared.ClusterUtils.SerializableBiPredicate;
import org.apache.cassandra.locator.ReplicationFactor;
import org.apache.cassandra.tcm.Commit;
import org.apache.cassandra.tcm.Epoch;
@@ -58,6 +59,7 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.cassandra.distributed.shared.ClusterUtils.cancelInProgressSequences;
import static org.apache.cassandra.distributed.shared.ClusterUtils.decommission;
import static org.apache.cassandra.distributed.shared.ClusterUtils.getClusterMetadataVersion;
+import static org.apache.cassandra.distributed.shared.ClusterUtils.getSequenceAfterCommit;
public class FailedLeaveTest extends FuzzTestBase
{
diff --git a/test/distributed/org/apache/cassandra/distributed/test/log/FuzzTestBase.java b/test/distributed/org/apache/cassandra/distributed/test/log/FuzzTestBase.java
index f86b800ae7..02f6b3eb91 100644
--- a/test/distributed/org/apache/cassandra/distributed/test/log/FuzzTestBase.java
+++ b/test/distributed/org/apache/cassandra/distributed/test/log/FuzzTestBase.java
@@ -19,14 +19,10 @@
package org.apache.cassandra.distributed.test.log;
-import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
-import java.util.function.BiPredicate;
-import java.util.function.Predicate;
import org.junit.BeforeClass;
@@ -38,19 +34,12 @@ import harry.model.sut.SystemUnderTest;
import harry.operations.CompiledStatement;
import harry.operations.Query;
import org.apache.cassandra.distributed.Cluster;
-import org.apache.cassandra.distributed.api.IInvokableInstance;
import org.apache.cassandra.distributed.api.IIsolatedExecutor;
import org.apache.cassandra.distributed.fuzz.HarryHelper;
import org.apache.cassandra.distributed.fuzz.InJvmSut;
-import org.apache.cassandra.distributed.shared.ClusterUtils;
import org.apache.cassandra.distributed.test.ExecUtil;
import org.apache.cassandra.distributed.test.TestBaseImpl;
import org.apache.cassandra.locator.ReplicationFactor;
-import org.apache.cassandra.tcm.Commit;
-import org.apache.cassandra.tcm.Transformation;
-import org.apache.cassandra.tcm.ClusterMetadataService;
-import org.apache.cassandra.tcm.Epoch;
-import org.apache.cassandra.utils.concurrent.AsyncPromise;
import static harry.model.SelectHelper.resultSetToRow;
import static org.apache.cassandra.distributed.api.Feature.GOSSIP;
@@ -74,58 +63,6 @@ public class FuzzTestBase extends TestBaseImpl
.set("request_timeout", String.format("%dms", TimeUnit.MINUTES.toMillis(10))));
}
- protected static Callable<Void> pauseBeforeCommit(IInvokableInstance cmsInstance, SerializablePredicate<Transformation> predicate)
- {
- return cmsInstance.callOnInstance(() -> {
- TestProcessor processor = (TestProcessor) ((ClusterMetadataService.SwitchableProcessor) ClusterMetadataService.instance().processor()).delegate();
- AsyncPromise<?> promise = new AsyncPromise<>();
- processor.pauseIf(predicate, () -> promise.setSuccess(null));
- return () -> {
- try
- {
- promise.get(30, TimeUnit.SECONDS);
- return null;
- }
- catch (Throwable e)
- {
- throw new RuntimeException(e);
- }
- };
- });
- }
-
- // todo; assumes period = 1
- protected static Callable<Epoch> getSequenceAfterCommit(IInvokableInstance cmsInstance,
- SerializableBiPredicate<Transformation, Commit.Result> predicate)
- {
- Callable<Long> remoteCallable = cmsInstance.callOnInstance(() -> {
- TestProcessor processor = (TestProcessor) ((ClusterMetadataService.SwitchableProcessor) ClusterMetadataService.instance().processor()).delegate();
-
- AsyncPromise<Epoch> promise = new AsyncPromise<>();
- processor.registerCommitPredicate((event, result) -> {
- if (predicate.test(event, result))
- {
- promise.setSuccess(result.success().replication.latestEpoch());
- return true;
- }
-
- return false;
- });
- return () -> {
- try
- {
- return ClusterUtils.encode(promise.get(30, TimeUnit.SECONDS));
- }
- catch (Throwable e)
- {
- throw new RuntimeException(e);
- }
- };
- });
-
- return () -> ClusterUtils.decode(remoteCallable.call());
- }
-
public static IIsolatedExecutor.SerializableRunnable toRunnable(ExecUtil.ThrowingSerializableRunnable runnable)
{
return () -> {
@@ -202,7 +139,4 @@ public class FuzzTestBase extends TestBaseImpl
}
}
}
-
- public static interface SerializablePredicate<T> extends Predicate<T>, Serializable {}
- public static interface SerializableBiPredicate<T1, T2> extends BiPredicate<T1, T2>, Serializable {}
}
diff --git a/test/distributed/org/apache/cassandra/distributed/test/log/InProgressSequenceCoordinationTest.java b/test/distributed/org/apache/cassandra/distributed/test/log/InProgressSequenceCoordinationTest.java
index 0cd3046d57..3d1b4c0102 100644
--- a/test/distributed/org/apache/cassandra/distributed/test/log/InProgressSequenceCoordinationTest.java
+++ b/test/distributed/org/apache/cassandra/distributed/test/log/InProgressSequenceCoordinationTest.java
@@ -46,6 +46,7 @@ import static org.apache.cassandra.config.CassandraRelevantProperties.PROGRESS_B
import static org.apache.cassandra.distributed.Constants.KEY_DTEST_API_STARTUP_FAILURE_AS_SHUTDOWN;
import static org.apache.cassandra.distributed.Constants.KEY_DTEST_FULL_STARTUP;
import static org.apache.cassandra.distributed.shared.ClusterUtils.addInstance;
+import static org.apache.cassandra.distributed.shared.ClusterUtils.getSequenceAfterCommit;
import static org.apache.cassandra.net.Verb.TCM_REPLICATION;
import static org.apache.cassandra.tcm.sequences.InProgressSequences.SequenceState.BLOCKED;
import static org.apache.cassandra.tcm.sequences.InProgressSequences.SequenceState.CONTINUING;
diff --git a/test/distributed/org/apache/cassandra/distributed/test/log/ResumableStartupTest.java b/test/distributed/org/apache/cassandra/distributed/test/log/ResumableStartupTest.java
index 83f8d77c89..c1a31776b5 100644
--- a/test/distributed/org/apache/cassandra/distributed/test/log/ResumableStartupTest.java
+++ b/test/distributed/org/apache/cassandra/distributed/test/log/ResumableStartupTest.java
@@ -43,6 +43,7 @@ import org.apache.cassandra.service.StorageService;
import static org.apache.cassandra.distributed.action.GossipHelper.withProperty;
import static org.apache.cassandra.distributed.shared.ClusterUtils.getClusterMetadataVersion;
+import static org.apache.cassandra.distributed.shared.ClusterUtils.getSequenceAfterCommit;
public class ResumableStartupTest extends FuzzTestBase
{
diff --git a/test/distributed/org/apache/cassandra/distributed/test/ring/ConsistentBootstrapTest.java b/test/distributed/org/apache/cassandra/distributed/test/ring/ConsistentBootstrapTest.java
index 8f11c02553..d523a32ce5 100644
--- a/test/distributed/org/apache/cassandra/distributed/test/ring/ConsistentBootstrapTest.java
+++ b/test/distributed/org/apache/cassandra/distributed/test/ring/ConsistentBootstrapTest.java
@@ -37,14 +37,16 @@ import org.apache.cassandra.distributed.api.IInvokableInstance;
import org.apache.cassandra.distributed.api.TokenSupplier;
import org.apache.cassandra.distributed.fuzz.HarryHelper;
import org.apache.cassandra.distributed.fuzz.InJvmSut;
-import org.apache.cassandra.distributed.shared.ClusterUtils;
import org.apache.cassandra.distributed.shared.NetworkTopology;
import org.apache.cassandra.distributed.test.log.FuzzTestBase;
-import org.apache.cassandra.distributed.test.log.TestProcessor;
-import org.apache.cassandra.tcm.ClusterMetadataService;
import org.apache.cassandra.tcm.Epoch;
import org.apache.cassandra.tcm.transformations.PrepareJoin;
+import static org.apache.cassandra.distributed.shared.ClusterUtils.getSequenceAfterCommit;
+import static org.apache.cassandra.distributed.shared.ClusterUtils.pauseBeforeCommit;
+import static org.apache.cassandra.distributed.shared.ClusterUtils.unpauseCommits;
+import static org.apache.cassandra.distributed.shared.ClusterUtils.waitForCMSToQuiesce;
+
public class ConsistentBootstrapTest extends FuzzTestBase
{
private static int WRITES = 2000;
@@ -63,7 +65,7 @@ public class ConsistentBootstrapTest extends FuzzTestBase
.start())
{
IInvokableInstance cmsInstance = cluster.get(1);
- ClusterUtils.waitForCMSToQuiesce(cluster, cmsInstance);
+ waitForCMSToQuiesce(cluster, cmsInstance);
configBuilder.setSUT(() -> new InJvmSut(cluster));
Run run = configBuilder.build().createRun();
@@ -71,7 +73,7 @@ public class ConsistentBootstrapTest extends FuzzTestBase
" WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 3};",
ConsistencyLevel.ALL);
cluster.coordinator(1).execute(run.schemaSpec.compile().cql(), ConsistencyLevel.ALL);
- ClusterUtils.waitForCMSToQuiesce(cluster, cluster.get(1));
+ waitForCMSToQuiesce(cluster, cluster.get(1));
Visitor visitor = new LoggingVisitor(run, MutatingRowVisitor::new);
QuiescentLocalStateChecker model = new QuiescentLocalStateChecker(run);
System.out.println("Starting write phase...");
@@ -86,7 +88,7 @@ public class ConsistentBootstrapTest extends FuzzTestBase
.set(Constants.KEY_DTEST_FULL_STARTUP, true);
IInvokableInstance newInstance = cluster.bootstrap(config);
- // Prime the DPS node to pause before the finish join event is committed
+ // Prime the CMS node to pause before the finish join event is committed
Callable<?> pending = pauseBeforeCommit(cmsInstance, (e) -> e instanceof PrepareJoin.FinishJoin);
new Thread(() -> newInstance.startup()).start();
pending.call();
@@ -102,25 +104,18 @@ public class ConsistentBootstrapTest extends FuzzTestBase
catch (Throwable t)
{
// Unpause, since otherwise validation exception will prevent graceful shutdown
- cmsInstance.runOnInstance(() -> {
- TestProcessor processor = (TestProcessor) ((ClusterMetadataService.SwitchableProcessor) ClusterMetadataService.instance().processor()).delegate();
- processor.unpause();
- });
+ unpauseCommits(cmsInstance);
throw t;
}
// Make sure there can be only one FinishJoin in flight
- ClusterUtils.waitForCMSToQuiesce(cluster, cmsInstance);
+ waitForCMSToQuiesce(cluster, cmsInstance);
// set expectation of finish join & retrieve the sequence when it gets committed
Callable<Epoch> bootstrapVisible = getSequenceAfterCommit(cmsInstance, (e, r) -> e instanceof PrepareJoin.FinishJoin && r.isSuccess());
- cmsInstance.runOnInstance(() -> {
- TestProcessor processor = (TestProcessor) ((ClusterMetadataService.SwitchableProcessor) ClusterMetadataService.instance().processor()).delegate();
- processor.unpause();
- });
-
// wait for the cluster to all witness the finish join event
- ClusterUtils.waitForCMSToQuiesce(cluster, bootstrapVisible.call());
+ unpauseCommits(cmsInstance);
+ waitForCMSToQuiesce(cluster, bootstrapVisible.call());
for (int i = 0; i < WRITES; i++)
visitor.visit();
diff --git a/test/distributed/org/apache/cassandra/distributed/test/schema/SchemaTest.java b/test/distributed/org/apache/cassandra/distributed/test/schema/SchemaTest.java
deleted file mode 100644
index 0661537e72..0000000000
--- a/test/distributed/org/apache/cassandra/distributed/test/schema/SchemaTest.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.distributed.test.schema;
-
-import org.junit.Test;
-
-import org.apache.cassandra.distributed.Cluster;
-import org.apache.cassandra.distributed.api.ConsistencyLevel;
-import org.apache.cassandra.distributed.test.TestBaseImpl;
-
-import static org.apache.cassandra.distributed.api.Feature.GOSSIP;
-import static org.apache.cassandra.distributed.api.Feature.NETWORK;
-
-public class SchemaTest extends TestBaseImpl
-{
- @Test
- public void bootstrapTest() throws Throwable
- {
- try (Cluster cluster = builder().withNodes(3)
- .withConfig(config -> config.with(NETWORK, GOSSIP))
- .start())
- {
- System.out.println("ABOUT TO CREATE KEYSPACE");
- // TODO: consistency level will become irrelevant
- cluster.coordinator(2).execute("CREATE KEYSPACE " + KEYSPACE + " WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 3};",
- ConsistencyLevel.ALL);
-
- cluster.coordinator(2).execute("CREATE TABLE " + KEYSPACE + ".tbl (pk int PRIMARY KEY, v int);",
- ConsistencyLevel.ALL);
-
- System.out.println("STARTING READING");
- for (int i = 1; i <= 3; i++)
- {
- cluster.coordinator(i).execute("SELECT * FROM " + KEYSPACE + ".tbl;",
- ConsistencyLevel.ALL);
- }
- }
- }
-}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org
[cassandra] 02/08: [CEP-21] Ensure that SchemaTransformation impls correctly set TableMetadata epoch
Posted by sa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
samt pushed a commit to branch cep-21-tcm
in repository https://gitbox.apache.org/repos/asf/cassandra.git
commit cd4f484fa0696f7faecf6cfb752cfb37ed391035
Author: Sam Tunnicliffe <sa...@apache.org>
AuthorDate: Thu Mar 30 16:49:47 2023 +0100
[CEP-21] Ensure that SchemaTransformation impls correctly set TableMetadata epoch
patch by Sam Tunnicliffe; reviewed by Marcus Eriksson and Alex Petrov
for CASSANDRA-18457
---
.../statements/schema/AlterTableStatement.java | 4 +-
src/java/org/apache/cassandra/db/ReadCommand.java | 9 +-
.../cassandra/tcm/transformations/AlterSchema.java | 49 ++++-
.../org/apache/cassandra/db/ReadCommandTest.java | 10 +-
.../org/apache/cassandra/schema/SchemaTest.java | 219 +++++++++++++++------
5 files changed, 226 insertions(+), 65 deletions(-)
diff --git a/src/java/org/apache/cassandra/cql3/statements/schema/AlterTableStatement.java b/src/java/org/apache/cassandra/cql3/statements/schema/AlterTableStatement.java
index c0f85afa31..7d3ddbeb39 100644
--- a/src/java/org/apache/cassandra/cql3/statements/schema/AlterTableStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/schema/AlterTableStatement.java
@@ -378,7 +378,7 @@ public abstract class AlterTableStatement extends AlterSchemaStatement
public KeyspaceMetadata apply(Epoch epoch, KeyspaceMetadata keyspace, TableMetadata table)
{
Guardrails.alterTableEnabled.ensureEnabled("ALTER TABLE changing columns", state);
- TableMetadata.Builder builder = table.unbuild().epoch(epoch);
+ TableMetadata.Builder builder = table.unbuild();
removedColumns.forEach(c -> dropColumn(keyspace, table, c, ifColumnExists, builder));
return keyspace.withSwapped(keyspace.tables.withSwapped(builder.build()));
}
@@ -583,7 +583,7 @@ public abstract class AlterTableStatement extends AlterSchemaStatement
? ImmutableSet.of(Flag.COMPOUND, Flag.COUNTER)
: ImmutableSet.of(Flag.COMPOUND);
- return keyspace.withSwapped(keyspace.tables.withSwapped(table.unbuild().epoch(epoch).flags(flags).build()));
+ return keyspace.withSwapped(keyspace.tables.withSwapped(table.unbuild().flags(flags).build()));
}
/**
diff --git a/src/java/org/apache/cassandra/db/ReadCommand.java b/src/java/org/apache/cassandra/db/ReadCommand.java
index de218d9b67..691b6dc30b 100644
--- a/src/java/org/apache/cassandra/db/ReadCommand.java
+++ b/src/java/org/apache/cassandra/db/ReadCommand.java
@@ -70,6 +70,7 @@ import org.apache.cassandra.service.ClientWarn;
import org.apache.cassandra.tcm.Epoch;
import org.apache.cassandra.tracing.Tracing;
import org.apache.cassandra.utils.FBUtilities;
+import org.apache.cassandra.utils.NoSpamLogger;
import org.apache.cassandra.utils.ObjectSizes;
import org.apache.cassandra.utils.TimeUUID;
@@ -1008,6 +1009,11 @@ public abstract class ReadCommand extends AbstractReadQuery
@VisibleForTesting
public static class Serializer implements IVersionedSerializer<ReadCommand>
{
+ private static final NoSpamLogger noSpamLogger = NoSpamLogger.getLogger(logger, 10L, TimeUnit.SECONDS);
+ private static final NoSpamLogger.NoSpamLogStatement schemaMismatchStmt =
+ noSpamLogger.getStatement("Schema epoch mismatch during read command deserialization. " +
+ "TableId: {}, remote epoch: {}, local epoch: {}", 10L, TimeUnit.SECONDS);
+
private final SchemaProvider schema;
public Serializer()
@@ -1104,7 +1110,8 @@ public abstract class ReadCommand extends AbstractReadQuery
Epoch schemaVersion = null;
if (version >= MessagingService.VERSION_50)
schemaVersion = Epoch.serializer.deserialize(in);
- assert schemaVersion == null || metadata.epoch.equals(schemaVersion) : metadata.epoch + " " + schemaVersion; // TODO: handle etc
+ if (schemaVersion != null && !(metadata.epoch.equals(schemaVersion)))
+ schemaMismatchStmt.info(metadata.id, schemaVersion.getEpoch(), metadata.epoch.getEpoch());
int nowInSec = in.readInt();
ColumnFilter columnFilter = ColumnFilter.serializer.deserialize(in, version, metadata);
RowFilter rowFilter = RowFilter.serializer.deserialize(in, version, metadata);
diff --git a/src/java/org/apache/cassandra/tcm/transformations/AlterSchema.java b/src/java/org/apache/cassandra/tcm/transformations/AlterSchema.java
index 0e0dec2bf0..667d5410a6 100644
--- a/src/java/org/apache/cassandra/tcm/transformations/AlterSchema.java
+++ b/src/java/org/apache/cassandra/tcm/transformations/AlterSchema.java
@@ -19,18 +19,24 @@
package org.apache.cassandra.tcm.transformations;
import java.io.IOException;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.io.util.DataInputPlus;
import org.apache.cassandra.io.util.DataOutputPlus;
import org.apache.cassandra.schema.DistributedSchema;
+import org.apache.cassandra.schema.KeyspaceMetadata;
import org.apache.cassandra.schema.Keyspaces;
import org.apache.cassandra.schema.Schema;
import org.apache.cassandra.schema.SchemaProvider;
import org.apache.cassandra.schema.SchemaTransformation;
+import org.apache.cassandra.schema.TableMetadata;
+import org.apache.cassandra.schema.Tables;
import org.apache.cassandra.tcm.ClusterMetadata;
import org.apache.cassandra.tcm.ClusterMetadataService;
+import org.apache.cassandra.tcm.Epoch;
import org.apache.cassandra.tcm.Transformation;
import org.apache.cassandra.tcm.ownership.DataPlacements;
import org.apache.cassandra.tcm.sequences.LockedRanges;
@@ -41,7 +47,7 @@ public class AlterSchema implements Transformation
{
public static final Serializer serializer = new Serializer();
- protected final SchemaTransformation schemaTransformation;
+ public final SchemaTransformation schemaTransformation;
protected final SchemaProvider schemaProvider;
public AlterSchema(SchemaTransformation schemaTransformation,
@@ -65,16 +71,46 @@ public class AlterSchema implements Transformation
return new Rejected("Can't have schema changes during ring movements: " + prev.lockedRanges.locked);
Keyspaces newKeyspaces;
-
try
{
newKeyspaces = schemaTransformation.apply(prev, prev.schema.getKeyspaces());
+ newKeyspaces.forEach(ksm -> {
+ ksm.tables.forEach(tm -> {
+ if (tm.epoch.isAfter(prev.nextEpoch()))
+ throw new InvalidRequestException(String.format("Invalid schema transformation. " +
+ "Resultant epoch for table metadata of %s.%s (%d) " +
+ "is greater than for cluster metadata (%d)",
+ ksm.name, tm.name, tm.epoch.getEpoch(),
+ prev.nextEpoch().getEpoch()));
+ });
+ });
}
catch (ConfigurationException | InvalidRequestException t)
{
return new Rejected(t.getMessage());
}
+ // Ensure that any new or modified TableMetadata has the correct epoch
+ Epoch nextEpoch = prev.nextEpoch();
+ Keyspaces.KeyspacesDiff diff = Keyspaces.diff(prev.schema.getKeyspaces(), newKeyspaces);
+
+ for (KeyspaceMetadata newKSM : diff.created)
+ {
+ Tables tables = Tables.of(normaliseEpochs(nextEpoch, newKSM.tables.stream()));
+ newKeyspaces = newKeyspaces.withAddedOrUpdated(newKSM.withSwapped(tables));
+ }
+
+ for (KeyspaceMetadata.KeyspaceDiff alteredKSM : diff.altered)
+ {
+ Tables tables = Tables.of(alteredKSM.after.tables);
+ for (TableMetadata created : normaliseEpochs(nextEpoch, alteredKSM.tables.created.stream()))
+ tables = tables.withSwapped(created);
+
+ for (TableMetadata altered : normaliseEpochs(nextEpoch, alteredKSM.tables.altered.stream().map(altered -> altered.after)))
+ tables = tables.withSwapped(altered);
+ newKeyspaces = newKeyspaces.withAddedOrUpdated(alteredKSM.after.withSwapped(tables));
+ }
+
DistributedSchema snapshotAfter = new DistributedSchema(newKeyspaces);
// state.schema is a DistributedSchema, so doesn't include local keyspaces. If we don't explicitly include those
@@ -90,6 +126,15 @@ public class AlterSchema implements Transformation
return success(next, LockedRanges.AffectedRanges.EMPTY);
}
+ private static Iterable<TableMetadata> normaliseEpochs(Epoch nextEpoch, Stream<TableMetadata> tables)
+ {
+ return tables.map(tm -> tm.epoch.is(nextEpoch)
+ ? tm
+ : tm.unbuild().epoch(nextEpoch).build())
+ .collect(Collectors.toList());
+ }
+
+
static class Serializer implements AsymmetricMetadataSerializer<Transformation, AlterSchema>
{
@Override
diff --git a/test/unit/org/apache/cassandra/db/ReadCommandTest.java b/test/unit/org/apache/cassandra/db/ReadCommandTest.java
index bf272b87cf..fde5650108 100644
--- a/test/unit/org/apache/cassandra/db/ReadCommandTest.java
+++ b/test/unit/org/apache/cassandra/db/ReadCommandTest.java
@@ -78,6 +78,7 @@ import org.apache.cassandra.schema.TableMetadata;
import org.apache.cassandra.schema.TableParams;
import org.apache.cassandra.service.ActiveRepairService;
import org.apache.cassandra.streaming.PreviewKind;
+import org.apache.cassandra.tcm.Epoch;
import org.apache.cassandra.tracing.Tracing;
import org.apache.cassandra.utils.ByteBufferUtil;
import org.apache.cassandra.utils.FBUtilities;
@@ -931,7 +932,14 @@ public class ReadCommandTest
{
TableParams newParams = cfs.metadata().params.unbuild().gcGraceSeconds(gcGrace).build();
KeyspaceMetadata keyspaceMetadata = Schema.instance.getKeyspaceMetadata(cfs.metadata().keyspace);
- SchemaTestUtil.addOrUpdateKeyspace(keyspaceMetadata.withSwapped(keyspaceMetadata.tables.withSwapped(cfs.metadata().withSwapped(newParams))), true);
+ // Because addOrUpdateKeyspace uses an anonymous SchemaTransformation, we need to supply an epoch
+ // to be used when updating the TableMetadata params. This would usually be the responsibility of
+ // the SchemaTransformation impl (i.e. a subclass of AlterSchemaStatement).
+ Epoch nextEpoch = cfs.metadata().epoch.nextEpoch();
+ SchemaTestUtil.addOrUpdateKeyspace(
+ keyspaceMetadata.withSwapped(
+ keyspaceMetadata.tables.withSwapped(
+ cfs.metadata().withSwapped(newParams))), true);
}
private long getAndResetOverreadCount(ColumnFamilyStore cfs)
diff --git a/test/unit/org/apache/cassandra/schema/SchemaTest.java b/test/unit/org/apache/cassandra/schema/SchemaTest.java
index 5b22211653..c35b42debc 100644
--- a/test/unit/org/apache/cassandra/schema/SchemaTest.java
+++ b/test/unit/org/apache/cassandra/schema/SchemaTest.java
@@ -18,26 +18,29 @@
*/
package org.apache.cassandra.schema;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collection;
+import java.util.function.Predicate;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.apache.cassandra.ServerTestUtils;
import org.apache.cassandra.config.DatabaseDescriptor;
-import org.apache.cassandra.db.Keyspace;
-import org.apache.cassandra.db.Mutation;
-import org.apache.cassandra.gms.Gossiper;
-import org.apache.cassandra.utils.FBUtilities;
+import org.apache.cassandra.cql3.QueryProcessor;
+import org.apache.cassandra.cql3.statements.schema.AlterSchemaStatement;
+import org.apache.cassandra.service.ClientState;
+import org.apache.cassandra.tcm.ClusterMetadata;
+import org.apache.cassandra.tcm.Epoch;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
public class SchemaTest
{
+ private static final String KS_PREFIX = "schema_test_ks_";
+ private static final String KS_ONE = KS_PREFIX + "1";
+ private static final String KS_TWO = KS_PREFIX + "2";
+
@BeforeClass
public static void setup()
{
@@ -45,69 +48,167 @@ public class SchemaTest
ServerTestUtils.prepareServer();
}
+ @Before
+ public void clearSchema()
+ {
+ SchemaTestUtil.dropKeyspaceIfExist(KS_ONE, true);
+ SchemaTestUtil.dropKeyspaceIfExist(KS_TWO, true);
+ }
+
@Test
- public void testTransKsMigration() throws IOException
+ public void tablesInNewKeyspaceHaveCorrectEpoch()
{
- assertEquals(0, Schema.instance.distributedKeyspaces().size());
+ Tables tables = Tables.of(TableMetadata.minimal(KS_ONE, "modified1"),
+ TableMetadata.minimal(KS_ONE, "modified2"));
+ KeyspaceMetadata ksm = KeyspaceMetadata.create(KS_ONE, KeyspaceParams.simple(1), tables);
+ applyAndAssertTableMetadata((metadata, schema) -> schema.withAddedOrUpdated(ksm), true);
+ }
- Gossiper.instance.start((int) (System.currentTimeMillis() / 1000));
- try
- {
- // add a few.
- saveKeyspaces();
-// Schema.instance.reloadSchema();
+ @Test
+ public void newTablesInExistingKeyspaceHaveCorrectEpoch()
+ {
+ // Create an empty keyspace
+ KeyspaceMetadata ksm = KeyspaceMetadata.create(KS_ONE, KeyspaceParams.simple(1));
+ Schema.instance.submit((metadata, schema) -> schema.withAddedOrUpdated(ksm));
+
+ // Add two tables and verify that the resultant table metadata has the correct epoch
+ Tables tables = Tables.of(TableMetadata.minimal(KS_ONE, "modified1"), TableMetadata.minimal(KS_ONE, "modified2"));
+ KeyspaceMetadata updated = ksm.withSwapped(tables);
+ applyAndAssertTableMetadata((metadata, schema) -> schema.withAddedOrUpdated(updated), true);
+ }
- assertNotNull(Schema.instance.getKeyspaceMetadata("ks0"));
- assertNotNull(Schema.instance.getKeyspaceMetadata("ks1"));
+ @Test
+ public void newTablesInNonEmptyKeyspaceHaveCorrectEpoch()
+ {
+ Tables tables = Tables.of(TableMetadata.minimal(KS_ONE, "unmodified"));
+ KeyspaceMetadata ksm = KeyspaceMetadata.create(KS_ONE, KeyspaceParams.simple(1), tables);
+ Schema.instance.submit((metadata, schema) -> schema.withAddedOrUpdated(ksm));
+
+ // Add a second table and assert that its table metadata has the latest epoch, but that the
+ // metadata of the other table stays unmodified
+ KeyspaceMetadata updated = ksm.withSwapped(tables.with(TableMetadata.minimal(KS_ONE, "modified1")));
+ applyAndAssertTableMetadata((metadata, schema) -> schema.withAddedOrUpdated(updated));
+ }
- Schema.instance.submit((metadata, schema) -> schema.without(Arrays.asList("ks0", "ks1")));
+ @Test
+ public void createTableCQLSetsCorrectEpoch()
+ {
+ Tables tables = Tables.of(TableMetadata.minimal(KS_ONE, "unmodified"));
+ KeyspaceMetadata ksm = KeyspaceMetadata.create(KS_ONE, KeyspaceParams.simple(1), tables);
+ Schema.instance.submit((metadata, schema) -> schema.withAddedOrUpdated(ksm));
- assertNull(Schema.instance.getKeyspaceMetadata("ks0"));
- assertNull(Schema.instance.getKeyspaceMetadata("ks1"));
+ applyAndAssertTableMetadata(cql(KS_ONE, "CREATE TABLE %s.modified (k int PRIMARY KEY)"));
+ }
- saveKeyspaces();
-// Schema.instance.reloadSchema(); // TODO .reloadSchemaAndAnnounceVersion();
+ @Test
+ public void createTablesInMultipleKeyspaces()
+ {
+ KeyspaceMetadata ksm1 = KeyspaceMetadata.create(KS_ONE, KeyspaceParams.simple(1));
+ KeyspaceMetadata ksm2 = KeyspaceMetadata.create(KS_TWO, KeyspaceParams.simple(1));
+ Schema.instance.submit((metadata, schema) -> schema.withAddedOrUpdated(ksm1).withAddedOrUpdated(ksm2));
+
+ // Add two tables in each ks and verify that the resultant table metadata has the correct epoch
+ Tables tables1 = Tables.of(TableMetadata.minimal(KS_ONE, "modified1"), TableMetadata.minimal(KS_ONE, "modified2"));
+ KeyspaceMetadata updated1 = ksm1.withSwapped(tables1);
+ Tables tables2 = Tables.of(TableMetadata.minimal(KS_TWO, "modified1"), TableMetadata.minimal(KS_TWO, "modified2"));
+ KeyspaceMetadata updated2 = ksm2.withSwapped(tables2);
+ applyAndAssertTableMetadata((metadata, schema) -> schema.withAddedOrUpdated(updated1)
+ .withAddedOrUpdated(updated2),
+ true);
+ }
+
+
+ @Test
+ public void createTablesInMultipleNonEmptyKeyspaces()
+ {
+ KeyspaceMetadata ksm1 = KeyspaceMetadata.create(KS_ONE, KeyspaceParams.simple(1));
+ KeyspaceMetadata ksm2 = KeyspaceMetadata.create(KS_TWO, KeyspaceParams.simple(1));
+ Schema.instance.submit((metadata, schema) -> schema.withAddedOrUpdated(ksm1).withAddedOrUpdated(ksm2));
+
+ // Add two tables in each ks and verify that the resultant table metadata has the correct epoch
+ Tables tables1 = Tables.of(TableMetadata.minimal(KS_ONE, "unmodified1"), TableMetadata.minimal(KS_ONE, "unmodified2"));
+ KeyspaceMetadata updated1 = ksm1.withSwapped(tables1);
+ Tables tables2 = Tables.of(TableMetadata.minimal(KS_TWO, "unmodified1"), TableMetadata.minimal(KS_TWO, "unmodified2"));
+ KeyspaceMetadata updated2 = ksm2.withSwapped(tables2);
+ Schema.instance.submit((metadata, schema) -> schema.withAddedOrUpdated(updated1).withAddedOrUpdated(updated2));
+
+ // Add a third table in one ks and assert that its table metadata has the latest epoch, but that the
+ // metadata of the all other tables stays unmodified
+ applyAndAssertTableMetadata(cql(KS_ONE, "CREATE TABLE %s.modified (k int PRIMARY KEY)"));
+ }
- assertNotNull(Schema.instance.getKeyspaceMetadata("ks0"));
- assertNotNull(Schema.instance.getKeyspaceMetadata("ks1"));
- }
- finally
- {
- Gossiper.instance.stop();
- }
+ @Test
+ public void alterTableAndVerifyEpoch()
+ {
+ SchemaTestUtil.addOrUpdateKeyspace(KeyspaceMetadata.create(KS_ONE, KeyspaceParams.simple(1)), true);
+ Schema.instance.submit(cql(KS_ONE, "CREATE TABLE %s.unmodified (k int PRIMARY KEY)"));
+ Schema.instance.submit(cql(KS_ONE, "CREATE TABLE %s.modified ( " +
+ "k int, " +
+ "c1 int, " +
+ "v1 text, " +
+ "v2 text, " +
+ "v3 text, " +
+ "v4 text," +
+ "PRIMARY KEY(k,c1))"));
+
+ applyAndAssertTableMetadata(cql(KS_ONE, "ALTER TABLE %s.modified DROP v4"));
+ applyAndAssertTableMetadata(cql(KS_ONE, "ALTER TABLE %s.modified ADD v5 text"));
+ applyAndAssertTableMetadata(cql(KS_ONE, "ALTER TABLE %s.modified RENAME c1 TO c2"));
+ applyAndAssertTableMetadata(cql(KS_ONE, "ALTER TABLE %s.modified WITH comment = 'altered'"));
}
@Test
- public void testKeyspaceCreationWhenNotInitialized() {
- Keyspace.unsetInitialized();
- try
- {
- SchemaTestUtil.addOrUpdateKeyspace(KeyspaceMetadata.create("test", KeyspaceParams.simple(1)), true);
- assertNotNull(Schema.instance.getKeyspaceMetadata("test"));
- assertNull(Schema.instance.getKeyspaceInstance("test"));
-
- SchemaTestUtil.dropKeyspaceIfExist("test", true);
- assertNull(Schema.instance.getKeyspaceMetadata("test"));
- assertNull(Schema.instance.getKeyspaceInstance("test"));
- }
- finally
- {
- Keyspace.setInitialized();
- }
-
- SchemaTestUtil.addOrUpdateKeyspace(KeyspaceMetadata.create("test", KeyspaceParams.simple(1)), true);
- assertNotNull(Schema.instance.getKeyspaceMetadata("test"));
- assertNotNull(Schema.instance.getKeyspaceInstance("test"));
-
- SchemaTestUtil.dropKeyspaceIfExist("test", true);
- assertNull(Schema.instance.getKeyspaceMetadata("test"));
- assertNull(Schema.instance.getKeyspaceInstance("test"));
+ public void alterTableMultipleKeyspacesAndVerifyEpoch()
+ {
+ SchemaTestUtil.addOrUpdateKeyspace(KeyspaceMetadata.create(KS_ONE, KeyspaceParams.simple(1)), true);
+ SchemaTestUtil.addOrUpdateKeyspace(KeyspaceMetadata.create(KS_TWO, KeyspaceParams.simple(1)), true);
+ Schema.instance.submit(cql(KS_ONE, "CREATE TABLE %s.unmodified (k int PRIMARY KEY)"));
+ Schema.instance.submit(cql(KS_TWO, "CREATE TABLE %s.unmodified (k int PRIMARY KEY)"));
+ Schema.instance.submit(cql(KS_ONE, "CREATE TABLE %s.modified ( " +
+ "k int, " +
+ "c1 int, " +
+ "v1 text, " +
+ "v2 text, " +
+ "v3 text, " +
+ "v4 text," +
+ "PRIMARY KEY(k, c1))"));
+
+ applyAndAssertTableMetadata(cql(KS_ONE, "ALTER TABLE %s.modified DROP v4"));
+ applyAndAssertTableMetadata(cql(KS_ONE, "ALTER TABLE %s.modified ADD v5 text"));
+ applyAndAssertTableMetadata(cql(KS_ONE, "ALTER TABLE %s.modified RENAME c1 TO c2"));
+ applyAndAssertTableMetadata(cql(KS_ONE, "ALTER TABLE %s.modified WITH comment = 'altered'"));
+ }
+
+ private void applyAndAssertTableMetadata(SchemaTransformation transformation)
+ {
+ applyAndAssertTableMetadata(transformation, false);
+ }
+
+ private void applyAndAssertTableMetadata(SchemaTransformation transformation, boolean onlyModified)
+ {
+ Epoch before = ClusterMetadata.current().epoch;
+ Schema.instance.submit(transformation);
+ Epoch after = ClusterMetadata.current().epoch;
+ assertTrue(after.isDirectlyAfter(before));
+ DistributedSchema schema = ClusterMetadata.current().schema;
+ Predicate<TableMetadata> modified = (tm) -> tm.name.startsWith("modified") && tm.epoch.is(after);
+ Predicate<TableMetadata> predicate = onlyModified
+ ? modified
+ : modified.or((tm) -> tm.name.startsWith("unmodified") && tm.epoch.isBefore(after));
+
+ schema.getKeyspaces().forEach(keyspace -> {
+ if (keyspace.name.startsWith(KS_PREFIX))
+ {
+ boolean containsUnmodified = keyspace.tables.stream().anyMatch(tm -> tm.name.startsWith("unmodified"));
+ assertEquals("Expected an unmodified table metadata but none found in " + keyspace.name, !onlyModified, containsUnmodified);
+ assertTrue(keyspace.tables.stream().allMatch(predicate));
+ }
+ });
}
- private void saveKeyspaces()
+ private static AlterSchemaStatement cql(String keyspace, String cql)
{
- Collection<Mutation> mutations = Arrays.asList(SchemaKeyspace.makeCreateKeyspaceMutation(KeyspaceMetadata.create("ks0", KeyspaceParams.simple(3)), FBUtilities.timestampMicros()).build(),
- SchemaKeyspace.makeCreateKeyspaceMutation(KeyspaceMetadata.create("ks1", KeyspaceParams.simple(3)), FBUtilities.timestampMicros()).build());
- SchemaKeyspace.applyChanges(mutations);
+ return (AlterSchemaStatement) QueryProcessor.parseStatement(String.format(cql, keyspace))
+ .prepare(ClientState.forInternalCalls());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org
[cassandra] 03/08: [CEP-21] During startup, don't open SSTables until local metadata log replay is complete
Posted by sa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
samt pushed a commit to branch cep-21-tcm
in repository https://gitbox.apache.org/repos/asf/cassandra.git
commit 633b40766b046cd852f312e51c4b6dbc60e49add
Author: Sam Tunnicliffe <sa...@apache.org>
AuthorDate: Thu Mar 30 16:52:13 2023 +0100
[CEP-21] During startup, don't open SSTables until local metadata log replay is complete
patch by Sam Tunnicliffe; reviewed by Marcus Eriksson and Alex Petrov
for CASSANDRA-18458
---
.../org/apache/cassandra/db/ColumnFamilyStore.java | 18 ++++-
.../apache/cassandra/schema/DistributedSchema.java | 6 +-
src/java/org/apache/cassandra/tcm/Startup.java | 79 ++++++++++++----------
.../cassandra/tcm/listeners/SchemaListener.java | 21 +++++-
.../org/apache/cassandra/tcm/log/LocalLog.java | 13 ++--
5 files changed, 91 insertions(+), 46 deletions(-)
diff --git a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
index 99e0bcde68..da85799a7a 100644
--- a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
+++ b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
@@ -506,6 +506,7 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean, Memtable.Owner
initialMemtable = createMemtable(new AtomicReference<>(CommitLog.instance.getCurrentPosition()));
memtableMetrics = memtableFactory.createMemtableMetrics(metadata);
}
+ metric = new TableMetrics(this, memtableMetrics);
data = new Tracker(this, initialMemtable, loadSSTables);
// Note that this needs to happen before we load the first sstables, or the global sstable tracker will not
@@ -537,8 +538,6 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean, Memtable.Owner
indexManager.addIndex(info, true);
}
- metric = new TableMetrics(this, memtableMetrics);
-
if (data.loadsstables)
{
data.updateInitialSSTableSize(sstables);
@@ -570,6 +569,21 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean, Memtable.Owner
topPartitions = new TopPartitionTracker(initMetadata);
}
+ public void loadInitialSSTables()
+ {
+ if (data.loadsstables)
+ {
+ logger.info("Attempted to load initial SSTables for {}.{} but this was done during construction, ignoring",
+ keyspace.getName(), name);
+ return;
+ }
+ Collection<SSTableReader> sstables;
+ Directories.SSTableLister sstableFiles = directories.sstableLister(Directories.OnTxnErr.IGNORE).skipTemporary(true);
+ sstables = SSTableReader.openAll(this, sstableFiles.list().entrySet(), metadata);
+ data.addInitialSSTablesWithoutUpdatingSize(sstables, this);
+ data.updateInitialSSTableSize(sstables);
+ }
+
public static String getTableMBeanName(String ks, String name, boolean isIndex)
{
return String.format("org.apache.cassandra.db:type=%s,keyspace=%s,table=%s",
diff --git a/src/java/org/apache/cassandra/schema/DistributedSchema.java b/src/java/org/apache/cassandra/schema/DistributedSchema.java
index f2e2356f9d..3ce318dd59 100644
--- a/src/java/org/apache/cassandra/schema/DistributedSchema.java
+++ b/src/java/org/apache/cassandra/schema/DistributedSchema.java
@@ -146,7 +146,7 @@ public class DistributedSchema implements MetadataValue<DistributedSchema>
delta.tables.dropped.forEach(t -> dropTable(keyspace, t, true));
// add tables and views
- delta.tables.created.forEach(t -> createTable(keyspace, t));
+ delta.tables.created.forEach(t -> createTable(keyspace, t, loadSSTables));
delta.views.created.forEach(v -> createView(keyspace, v));
// update tables and views
@@ -238,10 +238,10 @@ public class DistributedSchema implements MetadataValue<DistributedSchema>
SchemaDiagnostics.tableDropped(Schema.instance, metadata);
}
- private void createTable(Keyspace keyspace, TableMetadata table)
+ private void createTable(Keyspace keyspace, TableMetadata table, boolean loadSSTables)
{
SchemaDiagnostics.tableCreating(Schema.instance, table);
- keyspace.initCf(table, true);
+ keyspace.initCf(table, loadSSTables);
SchemaDiagnostics.tableCreated(Schema.instance, table);
}
diff --git a/src/java/org/apache/cassandra/tcm/Startup.java b/src/java/org/apache/cassandra/tcm/Startup.java
index a49a3d088e..5600dd12d3 100644
--- a/src/java/org/apache/cassandra/tcm/Startup.java
+++ b/src/java/org/apache/cassandra/tcm/Startup.java
@@ -18,37 +18,40 @@
package org.apache.cassandra.tcm;
- import java.io.IOException;
- import java.util.Collections;
- import java.util.Map;
- import java.util.Set;
- import java.util.concurrent.ExecutionException;
- import java.util.concurrent.TimeUnit;
- import java.util.function.Function;
-
- import com.google.common.util.concurrent.Uninterruptibles;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
-
- import org.apache.cassandra.config.DatabaseDescriptor;
- import org.apache.cassandra.db.SystemKeyspace;
- import org.apache.cassandra.db.commitlog.CommitLog;
- import org.apache.cassandra.gms.EndpointState;
- import org.apache.cassandra.gms.Gossiper;
- import org.apache.cassandra.gms.NewGossiper;
- import org.apache.cassandra.locator.InetAddressAndPort;
- import org.apache.cassandra.net.MessagingService;
- import org.apache.cassandra.schema.DistributedSchema;
- import org.apache.cassandra.tcm.compatibility.GossipHelper;
- import org.apache.cassandra.tcm.log.SystemKeyspaceStorage;
- import org.apache.cassandra.tcm.migration.Election;
- import org.apache.cassandra.tcm.ownership.UniformRangePlacement;
- import org.apache.cassandra.tcm.transformations.cms.Initialize;
- import org.apache.cassandra.utils.FBUtilities;
-
- import static org.apache.cassandra.tcm.ClusterMetadataService.State.LOCAL;
- import static org.apache.cassandra.tcm.compatibility.GossipHelper.emptyWithSchemaFromSystemTables;
- import static org.apache.cassandra.tcm.compatibility.GossipHelper.fromEndpointStates;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+
+import com.google.common.util.concurrent.Uninterruptibles;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.db.ColumnFamilyStore;
+import org.apache.cassandra.db.Keyspace;
+import org.apache.cassandra.db.SystemKeyspace;
+import org.apache.cassandra.db.commitlog.CommitLog;
+import org.apache.cassandra.gms.EndpointState;
+import org.apache.cassandra.gms.Gossiper;
+import org.apache.cassandra.gms.NewGossiper;
+import org.apache.cassandra.locator.InetAddressAndPort;
+import org.apache.cassandra.net.MessagingService;
+import org.apache.cassandra.schema.DistributedSchema;
+import org.apache.cassandra.tcm.compatibility.GossipHelper;
+import org.apache.cassandra.tcm.listeners.SchemaListener;
+import org.apache.cassandra.tcm.log.SystemKeyspaceStorage;
+import org.apache.cassandra.tcm.migration.Election;
+import org.apache.cassandra.tcm.ownership.UniformRangePlacement;
+import org.apache.cassandra.tcm.transformations.cms.Initialize;
+import org.apache.cassandra.utils.FBUtilities;
+
+import static org.apache.cassandra.tcm.ClusterMetadataService.State.LOCAL;
+import static org.apache.cassandra.tcm.compatibility.GossipHelper.emptyWithSchemaFromSystemTables;
+import static org.apache.cassandra.tcm.compatibility.GossipHelper.fromEndpointStates;
public class Startup
{
@@ -103,7 +106,6 @@ package org.apache.cassandra.tcm;
{
ClusterMetadataService.instance().log().bootstrap(FBUtilities.getBroadcastAddressAndPort());
assert ClusterMetadataService.state() == LOCAL : String.format("Can't initialize as node hasn't transitioned to CMS state. State: %s.\n%s", ClusterMetadataService.state(), ClusterMetadata.current());
-
Initialize initialize = new Initialize(ClusterMetadata.current());
ClusterMetadataService.instance().commit(initialize);
}
@@ -116,23 +118,28 @@ package org.apache.cassandra.tcm;
initial,
wrapProcessor,
ClusterMetadataService::state));
-
ClusterMetadataService.instance().initRecentlySealedPeriodsIndex();
ClusterMetadataService.instance().log().replayPersisted();
+ ClusterMetadataService.instance().log().removeListener(SchemaListener.INSTANCE_FOR_STARTUP);
+ DistributedSchema schema = ClusterMetadata.current().schema;
+ schema.getKeyspaces().forEach(ksm -> {
+ Keyspace ks = schema.getKeyspace(ksm.name);
+ ks.getColumnFamilyStores().forEach(cfs -> {
+ cfs.concatWithIndexes().forEach(ColumnFamilyStore::loadInitialSSTables);
+ });
+ });
+ ClusterMetadataService.instance().log().addListener(new SchemaListener());
}
public static void initializeForDiscovery(Runnable initMessaging)
{
initMessaging.run();
-
logger.debug("Discovering other nodes in the system");
Discovery.DiscoveredNodes candidates = Discovery.instance.discover();
-
if (candidates.kind() == Discovery.DiscoveredNodes.Kind.KNOWN_PEERS)
{
logger.debug("Got candidates: " + candidates);
InetAddressAndPort min = candidates.nodes().stream().min(InetAddressAndPort::compareTo).get();
-
// identify if you need to start the vote
if (min.equals(FBUtilities.getBroadcastAddressAndPort()) || FBUtilities.getBroadcastAddressAndPort().compareTo(min) < 0)
{
diff --git a/src/java/org/apache/cassandra/tcm/listeners/SchemaListener.java b/src/java/org/apache/cassandra/tcm/listeners/SchemaListener.java
index d3320b1568..38c5ef572c 100644
--- a/src/java/org/apache/cassandra/tcm/listeners/SchemaListener.java
+++ b/src/java/org/apache/cassandra/tcm/listeners/SchemaListener.java
@@ -29,11 +29,30 @@ import org.apache.cassandra.tcm.ClusterMetadata;
public class SchemaListener implements ChangeListener
{
+ // Special instance used during startup to ensure that SSTable files are not opened until
+ // replay of the locally persisted metadata log is complete. Failure to do this can result
+ // in deserialization errors if an SSTables written with schema at epoch X are opened before
+ // the log replay has replayed X. After replay is complete, this instance is replaced with
+ // a standard SchemaListener.
+ public static final SchemaListener INSTANCE_FOR_STARTUP = new SchemaListener()
+ {
+ @Override
+ public void notifyPreCommit(ClusterMetadata prev, ClusterMetadata next)
+ {
+ notifyInternal(prev, next, false);
+ }
+ };
+
@Override
public void notifyPreCommit(ClusterMetadata prev, ClusterMetadata next)
+ {
+ notifyInternal(prev, next, true);
+ }
+
+ protected void notifyInternal(ClusterMetadata prev, ClusterMetadata next, boolean loadSSTables)
{
if (!next.schema.lastModified().equals(prev.schema.lastModified()))
- next.schema.initializeKeyspaceInstances(prev.schema);
+ next.schema.initializeKeyspaceInstances(prev.schema, loadSSTables);
}
@Override
diff --git a/src/java/org/apache/cassandra/tcm/log/LocalLog.java b/src/java/org/apache/cassandra/tcm/log/LocalLog.java
index 25942368c8..931e581c63 100644
--- a/src/java/org/apache/cassandra/tcm/log/LocalLog.java
+++ b/src/java/org/apache/cassandra/tcm/log/LocalLog.java
@@ -272,10 +272,10 @@ public abstract class LocalLog implements Closeable
assert transformed.isSuccess();
ClusterMetadata next = transformed.success().metadata;
assert pendingEntry.epoch.is(next.epoch) :
- String.format("Entry epoch %s does not match metadata epoch %s", pendingEntry.epoch, next.epoch);
+ String.format("Entry epoch %s does not match metadata epoch %s", pendingEntry.epoch, next.epoch);
assert next.epoch.isDirectlyAfter(prev.epoch) || pendingEntry.transform.kind() == Transformation.Kind.FORCE_SNAPSHOT || pendingEntry.transform.kind() == Transformation.Kind.PRE_INITIALIZE_CMS :
- String.format("Epoch %s for %s can either force snapshot, or immediately follow %s",
- next.epoch, pendingEntry.transform, prev.epoch);
+ String.format("Epoch %s for %s can either force snapshot, or immediately follow %s",
+ next.epoch, pendingEntry.transform, prev.epoch);
persistence.append(transformed.success().metadata.period, pendingEntry.maybeUnwrapExecuted());
@@ -353,6 +353,11 @@ public abstract class LocalLog implements Closeable
this.cmListeners.add(listener);
}
+ public void removeListener(ChangeListener listener)
+ {
+ this.cmListeners.remove(listener);
+ }
+
private static class Async extends LocalLog
{
private final AsyncRunnable runnable;
@@ -562,7 +567,7 @@ public abstract class LocalLog implements Closeable
{
addListener(snapshotListener());
addListener(new InitializationListener());
- addListener(new SchemaListener());
+ addListener(SchemaListener.INSTANCE_FOR_STARTUP);
addListener(new LegacyStateListener());
addListener(new PlacementsChangeListener());
addListener(new MetadataSnapshotListener());
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org
[cassandra] 06/08: [CEP-21] Avoid NPE when getting dc/rack for not yet registered endpoints
Posted by sa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
samt pushed a commit to branch cep-21-tcm
in repository https://gitbox.apache.org/repos/asf/cassandra.git
commit 6af8a5a397dd91f9bf3b14c82aaf6d3e354e796d
Author: Marcus Eriksson <ma...@apache.org>
AuthorDate: Mon Apr 3 15:41:42 2023 +0200
[CEP-21] Avoid NPE when getting dc/rack for not yet registered endpoints
patch by Marcus Eriksson; reviewed by Alex Petrov and Sam Tunnicliffe
for CASSANDRA-18461
---
.../apache/cassandra/locator/AlibabaCloudSnitch.java | 6 ++++++
.../apache/cassandra/locator/CloudstackSnitch.java | 7 ++++++-
src/java/org/apache/cassandra/locator/Ec2Snitch.java | 6 ++++++
.../apache/cassandra/locator/GoogleCloudSnitch.java | 6 ++++++
.../locator/GossipingPropertyFileSnitch.java | 19 ++++---------------
5 files changed, 28 insertions(+), 16 deletions(-)
diff --git a/src/java/org/apache/cassandra/locator/AlibabaCloudSnitch.java b/src/java/org/apache/cassandra/locator/AlibabaCloudSnitch.java
index 45d7fcd857..574a1d4974 100644
--- a/src/java/org/apache/cassandra/locator/AlibabaCloudSnitch.java
+++ b/src/java/org/apache/cassandra/locator/AlibabaCloudSnitch.java
@@ -45,6 +45,8 @@ public class AlibabaCloudSnitch extends AbstractNetworkTopologySnitch
{
protected static final Logger logger = LoggerFactory.getLogger(AlibabaCloudSnitch.class);
protected static final String ZONE_NAME_QUERY_URL = "http://100.100.100.200/latest/meta-data/zone-id";
+ private static final String DEFAULT_DC = "UNKNOWN-DC";
+ private static final String DEFAULT_RACK = "UNKNOWN-RACK";
protected String ecsZone;
protected String ecsRegion;
@@ -110,6 +112,8 @@ public class AlibabaCloudSnitch extends AbstractNetworkTopologySnitch
ClusterMetadata metadata = ClusterMetadata.current();
NodeId nodeId = metadata.directory.peerId(endpoint);
+ if (nodeId == null)
+ return DEFAULT_RACK;
return metadata.directory.location(nodeId).rack;
}
@@ -120,6 +124,8 @@ public class AlibabaCloudSnitch extends AbstractNetworkTopologySnitch
return ecsRegion;
ClusterMetadata metadata = ClusterMetadata.current();
NodeId nodeId = metadata.directory.peerId(endpoint);
+ if (nodeId == null)
+ return DEFAULT_DC;
return metadata.directory.location(nodeId).datacenter;
}
diff --git a/src/java/org/apache/cassandra/locator/CloudstackSnitch.java b/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
index a4535d6374..8475fc64d8 100644
--- a/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
+++ b/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
@@ -52,7 +52,8 @@ public class CloudstackSnitch extends AbstractNetworkTopologySnitch
{
protected static final Logger logger = LoggerFactory.getLogger(CloudstackSnitch.class);
protected static final String ZONE_NAME_QUERY_URI = "/latest/meta-data/availability-zone";
-
+ private static final String DEFAULT_DC = "UNKNOWN-DC";
+ private static final String DEFAULT_RACK = "UNKNOWN-RACK";
private static final String[] LEASE_FILES =
{
"file:///var/lib/dhcp/dhclient.eth0.leases",
@@ -83,6 +84,8 @@ public class CloudstackSnitch extends AbstractNetworkTopologySnitch
ClusterMetadata metadata = ClusterMetadata.current();
NodeId nodeId = metadata.directory.peerId(endpoint);
+ if (nodeId == null)
+ return DEFAULT_RACK;
return metadata.directory.location(nodeId).rack;
}
@@ -93,6 +96,8 @@ public class CloudstackSnitch extends AbstractNetworkTopologySnitch
ClusterMetadata metadata = ClusterMetadata.current();
NodeId nodeId = metadata.directory.peerId(endpoint);
+ if (nodeId == null)
+ return DEFAULT_DC;
return metadata.directory.location(nodeId).datacenter;
}
diff --git a/src/java/org/apache/cassandra/locator/Ec2Snitch.java b/src/java/org/apache/cassandra/locator/Ec2Snitch.java
index 09134959eb..f9275affda 100644
--- a/src/java/org/apache/cassandra/locator/Ec2Snitch.java
+++ b/src/java/org/apache/cassandra/locator/Ec2Snitch.java
@@ -49,6 +49,8 @@ public class Ec2Snitch extends AbstractNetworkTopologySnitch
private static final String EC2_NAMING_STANDARD = "standard";
private static final String ZONE_NAME_QUERY_URL = "http://169.254.169.254/latest/meta-data/placement/availability-zone";
+ private static final String DEFAULT_DC = "UNKNOWN-DC";
+ private static final String DEFAULT_RACK = "UNKNOWN-RACK";
final String ec2region;
private final String ec2zone;
@@ -130,6 +132,8 @@ public class Ec2Snitch extends AbstractNetworkTopologySnitch
ClusterMetadata metadata = ClusterMetadata.current();
NodeId nodeId = metadata.directory.peerId(endpoint);
+ if (nodeId == null)
+ return DEFAULT_RACK;
return metadata.directory.location(nodeId).rack;
}
@@ -140,6 +144,8 @@ public class Ec2Snitch extends AbstractNetworkTopologySnitch
ClusterMetadata metadata = ClusterMetadata.current();
NodeId nodeId = metadata.directory.peerId(endpoint);
+ if (nodeId == null)
+ return DEFAULT_DC;
return metadata.directory.location(nodeId).datacenter;
}
diff --git a/src/java/org/apache/cassandra/locator/GoogleCloudSnitch.java b/src/java/org/apache/cassandra/locator/GoogleCloudSnitch.java
index d2ff6ee4e4..aa247936e4 100644
--- a/src/java/org/apache/cassandra/locator/GoogleCloudSnitch.java
+++ b/src/java/org/apache/cassandra/locator/GoogleCloudSnitch.java
@@ -41,6 +41,8 @@ public class GoogleCloudSnitch extends AbstractNetworkTopologySnitch
{
protected static final Logger logger = LoggerFactory.getLogger(GoogleCloudSnitch.class);
protected static final String ZONE_NAME_QUERY_URL = "http://metadata.google.internal/computeMetadata/v1/instance/zone";
+ private static final String DEFAULT_DC = "UNKNOWN-DC";
+ private static final String DEFAULT_RACK = "UNKNOWN-RACK";
protected String gceZone;
protected String gceRegion;
@@ -95,6 +97,8 @@ public class GoogleCloudSnitch extends AbstractNetworkTopologySnitch
ClusterMetadata metadata = ClusterMetadata.current();
NodeId nodeId = metadata.directory.peerId(endpoint);
+ if (nodeId == null)
+ return DEFAULT_RACK;
return metadata.directory.location(nodeId).rack;
}
@@ -105,6 +109,8 @@ public class GoogleCloudSnitch extends AbstractNetworkTopologySnitch
ClusterMetadata metadata = ClusterMetadata.current();
NodeId nodeId = metadata.directory.peerId(endpoint);
+ if (nodeId == null)
+ return DEFAULT_DC;
return metadata.directory.location(nodeId).rack;
}
}
diff --git a/src/java/org/apache/cassandra/locator/GossipingPropertyFileSnitch.java b/src/java/org/apache/cassandra/locator/GossipingPropertyFileSnitch.java
index f320f7f03c..3516550c05 100644
--- a/src/java/org/apache/cassandra/locator/GossipingPropertyFileSnitch.java
+++ b/src/java/org/apache/cassandra/locator/GossipingPropertyFileSnitch.java
@@ -19,7 +19,6 @@
package org.apache.cassandra.locator;
import java.util.concurrent.atomic.AtomicReference;
-import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -37,14 +36,10 @@ public class GossipingPropertyFileSnitch extends AbstractNetworkTopologySnitch//
{
private static final Logger logger = LoggerFactory.getLogger(GossipingPropertyFileSnitch.class);
- private PropertyFileSnitch psnitch;
-
private final String myDC;
private final String myRack;
private final boolean preferLocal;
private final AtomicReference<ReconnectableSnitchHelper> snitchHelperReference;
-
- private Map<InetAddressAndPort, Map<String, String>> savedEndpoints;
private static final String DEFAULT_DC = "UNKNOWN_DC";
private static final String DEFAULT_RACK = "UNKNOWN_RACK";
@@ -56,16 +51,6 @@ public class GossipingPropertyFileSnitch extends AbstractNetworkTopologySnitch//
myRack = properties.get("rack", DEFAULT_RACK).trim();
preferLocal = Boolean.parseBoolean(properties.get("prefer_local", "false"));
snitchHelperReference = new AtomicReference<>();
-
- try
- {
- psnitch = new PropertyFileSnitch();
- logger.info("Loaded {} for compatibility", PropertyFileSnitch.SNITCH_PROPERTIES_FILENAME);
- }
- catch (ConfigurationException e)
- {
- logger.info("Unable to load {}; compatibility mode disabled", PropertyFileSnitch.SNITCH_PROPERTIES_FILENAME);
- }
}
private static SnitchProperties loadConfiguration() throws ConfigurationException
@@ -90,6 +75,8 @@ public class GossipingPropertyFileSnitch extends AbstractNetworkTopologySnitch//
ClusterMetadata metadata = ClusterMetadata.current();
NodeId nodeId = metadata.directory.peerId(endpoint);
+ if (nodeId == null)
+ return DEFAULT_DC;
return metadata.directory.location(nodeId).rack;
}
@@ -106,6 +93,8 @@ public class GossipingPropertyFileSnitch extends AbstractNetworkTopologySnitch//
ClusterMetadata metadata = ClusterMetadata.current();
NodeId nodeId = metadata.directory.peerId(endpoint);
+ if (nodeId == null)
+ return DEFAULT_RACK;
return metadata.directory.location(nodeId).rack;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org