clohfink commented on a change in pull request #1376:
URL: https://github.com/apache/cassandra/pull/1376#discussion_r793003967
##########
File path: src/java/org/apache/cassandra/config/DatabaseDescriptor.java
##########
@@ -1042,6 +1059,52 @@ public static void applySslContext()
}
}
+ public static void applyStartupConnectivityChecker()
+ {
+ applyStartupConnectivityChecker(conf);
+ }
+
+ @VisibleForTesting
+ static void applyStartupConnectivityChecker(Config conf)
+ {
+ StartupConnectivityChecker startupConnectivityChecker;
+
+ /* Startup cluster connectivity checker backend, implementing
StartupClusterConnectivityChecker */
+ if (conf.startup_connectivity_checker != null)
+ {
+ // A ConfigurationException is thrown if the class is not found
+ startupConnectivityChecker =
FBUtilities.newStartupConnectivityChecker(conf.startup_connectivity_checker);
+ }
+ else
+ {
+ startupConnectivityChecker = new
StrictStartupConnectivityChecker();
+ }
+
+ // the configuration option block_for_peers_in_remote_dcs is only
guaranteed
+ // to work with StrictStartupClusterConnectivityChecker, so log a
message if
+ // some other startup cluster connectivity checker is in use and the
non-default
+ // value is detected
+ if (!(startupConnectivityChecker instanceof
StrictStartupConnectivityChecker)
Review comment:
instead of tying this logic in DD, can add a `validate` method to
`StartupConnectivityChecker` with the config allowing it to log warnings or
fail. This also means any custom implementation can have checks.
##########
File path:
src/java/org/apache/cassandra/net/ConsistencyLevelStartupConnectivityChecker.java
##########
@@ -0,0 +1,442 @@
+/*
+ * 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.net;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.ToIntFunction;
+import java.util.stream.Stream;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
+
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.db.ConsistencyLevel;
+import org.apache.cassandra.dht.Token;
+import org.apache.cassandra.locator.InetAddressAndPort;
+import org.apache.cassandra.locator.NetworkTopologyStrategy;
+import org.apache.cassandra.schema.Schema;
+import org.apache.cassandra.service.StorageService;
+import org.apache.cassandra.utils.concurrent.CountDownLatch;
+
+import static java.util.stream.Collectors.groupingBy;
+import static
org.apache.cassandra.utils.concurrent.CountDownLatch.newCountDownLatch;
+
+
+/**
+ * A {@link StartupConnectivityChecker} implementation that based on the
configured {@link ConsistencyLevel} to
+ * determine how many peers in the local datacenter or all datacenters to wait
for before it is ready to advertise to clients.
+ * The lowest non-zero replication factor among all user keyspaces is used to
determine the quorum.
+ *
+ * <p>The checker breaks the check into 2 phases.
+ * 1. In phase one, it checks if the primary set of peers has connected.
+ * 2. In phase two, it sends additional ping messages to the rest of the peers
and check if the connected peers can satisfy
+ * the specified consistency level at the end.
+ *
+ * <p>Supported values for {@code blockForPeersConsistencyLevel} are:
+ * <ul>
+ * <li>ALL
+ * <li>QUORUM
+ * <li>LOCAL_QUORUM
+ * <li>EACH_QUORUM
+ * </ul>
+ *
+ * <p>The checker only supports the {@link NetworkTopologyStrategy}. The
checker is not suitable when using vnodes.
+ */
+public class ConsistencyLevelStartupConnectivityChecker
+extends AbstractStartupConnectivityChecker
+{
Review comment:
At a high level, I think a lot of this logic is replicated in the
ReplicaPlan stuff that is used by the Read/Writes already. (hence will
accurately reflect if they will throw UnavailableExceptions). Can we use this
directly and cut almost all this logic? ie:
``` while (System.currentTimeMillis() < timeout)
{
boolean allGood = true;
// different RFs
for (Keyspace keyspace : Keyspace.all())
{
for (TableMetadata table : keyspace.getMetadata().tables)
{
allGood &=
RangeCommands.sufficientLiveNodesForSelectStar(table, consistencyLevel);
}
}
if (allGood) break;
sleep(1000);
}
##########
File path:
src/java/org/apache/cassandra/net/ConsistencyLevelStartupConnectivityChecker.java
##########
@@ -0,0 +1,442 @@
+/*
+ * 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.net;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.ToIntFunction;
+import java.util.stream.Stream;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
+
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.db.ConsistencyLevel;
+import org.apache.cassandra.dht.Token;
+import org.apache.cassandra.locator.InetAddressAndPort;
+import org.apache.cassandra.locator.NetworkTopologyStrategy;
+import org.apache.cassandra.schema.Schema;
+import org.apache.cassandra.service.StorageService;
+import org.apache.cassandra.utils.concurrent.CountDownLatch;
+
+import static java.util.stream.Collectors.groupingBy;
+import static
org.apache.cassandra.utils.concurrent.CountDownLatch.newCountDownLatch;
+
+
+/**
+ * A {@link StartupConnectivityChecker} implementation that based on the
configured {@link ConsistencyLevel} to
+ * determine how many peers in the local datacenter or all datacenters to wait
for before it is ready to advertise to clients.
+ * The lowest non-zero replication factor among all user keyspaces is used to
determine the quorum.
+ *
+ * <p>The checker breaks the check into 2 phases.
+ * 1. In phase one, it checks if the primary set of peers has connected.
+ * 2. In phase two, it sends additional ping messages to the rest of the peers
and check if the connected peers can satisfy
+ * the specified consistency level at the end.
+ *
+ * <p>Supported values for {@code blockForPeersConsistencyLevel} are:
+ * <ul>
+ * <li>ALL
+ * <li>QUORUM
+ * <li>LOCAL_QUORUM
+ * <li>EACH_QUORUM
+ * </ul>
+ *
+ * <p>The checker only supports the {@link NetworkTopologyStrategy}. The
checker is not suitable when using vnodes.
+ */
+public class ConsistencyLevelStartupConnectivityChecker
+extends AbstractStartupConnectivityChecker
Review comment:
NP: dont place implements/extends on new lines
##########
File path: src/java/org/apache/cassandra/config/DatabaseDescriptor.java
##########
@@ -18,9 +18,21 @@
package org.apache.cassandra.config;
import java.io.IOException;
-import java.net.*;
+import java.net.Inet4Address;
Review comment:
NP: maybe dont explode these out, next persons pr might fold them back
up.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]