You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "frankgh (via GitHub)" <gi...@apache.org> on 2025/03/19 21:34:53 UTC
[PR] Casssidecar 232 [cassandra-sidecar]
frankgh opened a new pull request, #211:
URL: https://github.com/apache/cassandra-sidecar/pull/211
(no comment)
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSSIDECAR-232: Enhance the Cluster Lease Claim task feature [cassandra-sidecar]
Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on code in PR #211:
URL: https://github.com/apache/cassandra-sidecar/pull/211#discussion_r2004396323
##########
conf/sidecar.yaml:
##########
@@ -121,20 +121,37 @@ sidecar:
replication_strategy: SimpleStrategy
replication_factor: 1
# The TTL in seconds used to insert entries into the sidecar_lease schema
- lease_schema_ttl: 2m
+ lease_schema_ttl: 5m
coordination:
# Captures configuration parameters for the task that performs the cluster lease claim process
cluster_lease_claim:
+ # The name of the strategy used to determine the electorate membership
+ # Out of the box Sidecar provides the MostReplicatedKeyspaceTokenZeroElectorateMembership, and
+ # SidecarInternalTokenZeroElectorateMembership implementations.
+ # - MostReplicatedKeyspaceTokenZeroElectorateMembership the current Sidecar will be determined to be part
+ # of the electorate iff one of the Cassandra instances it
+ # manages owns token 0 for the user keyspace that has the
+ # highest replication factor. If multiple keyspaces have
+ # the highest replication factor, the keyspace to be used
+ # is decided by the keyspace with the name that sorts
+ # first in the lexicographic sort order. If no user
+ # keyspaces are created, the internal sidecar keyspace will
+ # be used.
+ # - SidecarInternalTokenZeroElectorateMembership the current Sidecar will be determined to be part of the
+ # electorate iff one of the Cassandra instances it manages
+ # owns token {@code 0} for the {@code sidecar_internal}
+ # keyspace.
+ electorate_membership_strategy: MostReplicatedKeyspaceTokenZeroElectorateMembership
Review Comment:
good question, let me write a quick test . It should default to `MostReplicatedKeyspaceTokenZeroElectorateMembership`
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSSIDECAR-232: Enhance the Cluster Lease Claim task feature [cassandra-sidecar]
Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on code in PR #211:
URL: https://github.com/apache/cassandra-sidecar/pull/211#discussion_r2004420972
##########
server/src/main/java/org/apache/cassandra/sidecar/modules/CoordinationModule.java:
##########
@@ -70,6 +72,18 @@ ElectorateMembership electorateMembership(InstanceMetadataFetcher instanceMetada
CQLSessionProvider cqlSessionProvider,
SidecarConfiguration configuration)
{
- return new MostReplicatedKeyspaceTokenZeroElectorateMembership(instanceMetadataFetcher, cqlSessionProvider, configuration);
+ String strategy = configuration.serviceConfiguration()
+ .coordinationConfiguration()
+ .clusterLeaseClaimConfiguration()
+ .electorateMembershipStrategy();
+ switch (strategy)
+ {
+ case "MostReplicatedKeyspaceTokenZeroElectorateMembership":
+ return new MostReplicatedKeyspaceTokenZeroElectorateMembership(instanceMetadataFetcher, cqlSessionProvider, configuration);
+ case "SidecarInternalTokenZeroElectorateMembership":
+ return new SidecarInternalTokenZeroElectorateMembership(instanceMetadataFetcher, configuration);
+ default:
+ throw new ConfigurationException("Invalid electorate membership strategy value '" + strategy + "'");
+ }
Review Comment:
done
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSSIDECAR-232: Enhance the Cluster Lease Claim task feature [cassandra-sidecar]
Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on code in PR #211:
URL: https://github.com/apache/cassandra-sidecar/pull/211#discussion_r2004420771
##########
server/src/main/java/org/apache/cassandra/sidecar/coordination/ClusterLeaseClaimTask.java:
##########
@@ -144,7 +147,13 @@ public ScheduleDecision scheduleDecision()
@Override
public DurationSpec initialDelay()
{
- return periodicTaskConfiguration.initialDelay();
+ // Return a randomized delay to introduce jitter among all the instances participating
+ // in the lease claim process
+ MillisecondBoundConfiguration initialDelay = periodicTaskConfiguration.initialDelay();
+ long millis = initialDelay.toMillis();
+ return millis <= 0
+ ? initialDelay
+ : new MillisecondBoundConfiguration(ThreadLocalRandom.current().nextLong(millis), TimeUnit.MILLISECONDS);
Review Comment:
it cannot be negative, it's restricted by `DurationSpec` however `ThreadLocalRandom.current().nextLong` throws when you provide it a value that is 0
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSSIDECAR-232: Enhance the Cluster Lease Claim task feature [cassandra-sidecar]
Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on code in PR #211:
URL: https://github.com/apache/cassandra-sidecar/pull/211#discussion_r2004402350
##########
server/src/test/integration/org/apache/cassandra/sidecar/coordination/MostReplicatedKeyspaceTokenZeroElectorateMembershipIntegrationTest.java:
##########
@@ -107,12 +109,17 @@ void test(TestVersion version) throws IOException
private void runTestScenario(AbstractCluster<?> cluster)
{
- List<MostReplicatedKeyspaceTokenZeroElectorateMembership> memberships = buildElectorateMembershipPerCassandraInstance(cluster);
+ var pair = buildElectorateMembershipPerCassandraInstance(cluster);
Review Comment:
using var here, not sure if this is something we should discourage
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSSIDECAR-232: Enhance the Cluster Lease Claim task feature [cassandra-sidecar]
Posted by "yifan-c (via GitHub)" <gi...@apache.org>.
yifan-c commented on code in PR #211:
URL: https://github.com/apache/cassandra-sidecar/pull/211#discussion_r2004457733
##########
server/src/test/integration/org/apache/cassandra/sidecar/coordination/MostReplicatedKeyspaceTokenZeroElectorateMembershipIntegrationTest.java:
##########
@@ -107,12 +109,17 @@ void test(TestVersion version) throws IOException
private void runTestScenario(AbstractCluster<?> cluster)
{
- List<MostReplicatedKeyspaceTokenZeroElectorateMembership> memberships = buildElectorateMembershipPerCassandraInstance(cluster);
+ var pair = buildElectorateMembershipPerCassandraInstance(cluster);
Review Comment:
can we avoid using `var`?
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSSIDECAR-232: Enhance the Cluster Lease Claim task feature [cassandra-sidecar]
Posted by "yifan-c (via GitHub)" <gi...@apache.org>.
yifan-c commented on code in PR #211:
URL: https://github.com/apache/cassandra-sidecar/pull/211#discussion_r2004522493
##########
server/src/main/java/org/apache/cassandra/sidecar/coordination/ClusterLeaseClaimTask.java:
##########
@@ -144,7 +146,16 @@ public ScheduleDecision scheduleDecision()
@Override
public DurationSpec initialDelay()
{
- return periodicTaskConfiguration.initialDelay();
+ // Return a randomized delay to introduce jitter among all the instances participating
+ // in the lease claim process
+ long randomDeltaDelayMillis = configuration.randomDeltaDelayMillis();
+ if (randomDeltaDelayMillis == 0)
+ {
+ // no jitter
+ return configuration.initialDelay();
+ }
+ long initialDelayMillis = configuration.initialDelay().toMillis() + randomDeltaDelayMillis;
+ return new MillisecondBoundConfiguration(initialDelayMillis, TimeUnit.MILLISECONDS);
Review Comment:
👍
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSSIDECAR-232: Enhance the Cluster Lease Claim task feature [cassandra-sidecar]
Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on code in PR #211:
URL: https://github.com/apache/cassandra-sidecar/pull/211#discussion_r2004399014
##########
conf/sidecar.yaml:
##########
@@ -121,20 +121,37 @@ sidecar:
replication_strategy: SimpleStrategy
replication_factor: 1
# The TTL in seconds used to insert entries into the sidecar_lease schema
- lease_schema_ttl: 2m
+ lease_schema_ttl: 5m
coordination:
# Captures configuration parameters for the task that performs the cluster lease claim process
cluster_lease_claim:
+ # The name of the strategy used to determine the electorate membership
+ # Out of the box Sidecar provides the MostReplicatedKeyspaceTokenZeroElectorateMembership, and
+ # SidecarInternalTokenZeroElectorateMembership implementations.
+ # - MostReplicatedKeyspaceTokenZeroElectorateMembership the current Sidecar will be determined to be part
+ # of the electorate iff one of the Cassandra instances it
+ # manages owns token 0 for the user keyspace that has the
+ # highest replication factor. If multiple keyspaces have
+ # the highest replication factor, the keyspace to be used
+ # is decided by the keyspace with the name that sorts
+ # first in the lexicographic sort order. If no user
+ # keyspaces are created, the internal sidecar keyspace will
+ # be used.
+ # - SidecarInternalTokenZeroElectorateMembership the current Sidecar will be determined to be part of the
+ # electorate iff one of the Cassandra instances it manages
+ # owns token {@code 0} for the {@code sidecar_internal}
+ # keyspace.
+ electorate_membership_strategy: MostReplicatedKeyspaceTokenZeroElectorateMembership
# Whether the process is enabled
enabled: true
# The initial delay for the first execution of the cluster lease claim process task after being
# scheduled or rescheduled.
# The minimum value for the initial delay is 0ms.
- initial_delay: 1s
Review Comment:
yeah, I think that's fine. If you have a single sidecar instance there will be no contention. i.e using the default configuration values for the sidecar_internal keyspace and `SidecarInternalTokenZeroElectorateMembership`
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSSIDECAR-232: Enhance the Cluster Lease Claim task feature [cassandra-sidecar]
Posted by "yifan-c (via GitHub)" <gi...@apache.org>.
yifan-c commented on code in PR #211:
URL: https://github.com/apache/cassandra-sidecar/pull/211#discussion_r2004374489
##########
conf/sidecar.yaml:
##########
@@ -121,20 +121,37 @@ sidecar:
replication_strategy: SimpleStrategy
replication_factor: 1
# The TTL in seconds used to insert entries into the sidecar_lease schema
- lease_schema_ttl: 2m
+ lease_schema_ttl: 5m
coordination:
# Captures configuration parameters for the task that performs the cluster lease claim process
cluster_lease_claim:
+ # The name of the strategy used to determine the electorate membership
+ # Out of the box Sidecar provides the MostReplicatedKeyspaceTokenZeroElectorateMembership, and
+ # SidecarInternalTokenZeroElectorateMembership implementations.
+ # - MostReplicatedKeyspaceTokenZeroElectorateMembership the current Sidecar will be determined to be part
+ # of the electorate iff one of the Cassandra instances it
+ # manages owns token 0 for the user keyspace that has the
+ # highest replication factor. If multiple keyspaces have
+ # the highest replication factor, the keyspace to be used
+ # is decided by the keyspace with the name that sorts
+ # first in the lexicographic sort order. If no user
+ # keyspaces are created, the internal sidecar keyspace will
+ # be used.
+ # - SidecarInternalTokenZeroElectorateMembership the current Sidecar will be determined to be part of the
+ # electorate iff one of the Cassandra instances it manages
+ # owns token {@code 0} for the {@code sidecar_internal}
+ # keyspace.
+ electorate_membership_strategy: MostReplicatedKeyspaceTokenZeroElectorateMembership
Review Comment:
What is the default value if the new field `electorate_membership_strategy` is not configured?
##########
examples/conf/sidecar-ccm.yaml:
##########
@@ -277,6 +307,19 @@ access_control:
#
# other options are, io.vertx.ext.auth.mtls.impl.SpiffeIdentityExtractor.
certificate_identity_extractor: org.apache.cassandra.sidecar.acl.authentication.CassandraIdentityExtractor
+ # JwtAuthenticationHandlerFactory adds support to authenticate users with their JWT tokens. It also includes
+ # supports for OpenID discovery.
+ - class_name: org.apache.cassandra.sidecar.acl.authentication.JwtAuthenticationHandlerFactory
+ parameters:
+ # To selectively enable or disable JWT authentication
+ enabled: false
+ # Site for sidecar to dynamically retrieve the configuration information of an OpenID provider, without
+ # having to manually configure settings like issuer etc.
+ site: https://authorization.com
Review Comment:
Thanks for adding them back. It is easy to forgot update this file. We should think of "copying" from `conf/sidecar.yaml` in the future.
##########
conf/sidecar.yaml:
##########
@@ -121,20 +121,37 @@ sidecar:
replication_strategy: SimpleStrategy
replication_factor: 1
# The TTL in seconds used to insert entries into the sidecar_lease schema
- lease_schema_ttl: 2m
+ lease_schema_ttl: 5m
coordination:
# Captures configuration parameters for the task that performs the cluster lease claim process
cluster_lease_claim:
+ # The name of the strategy used to determine the electorate membership
+ # Out of the box Sidecar provides the MostReplicatedKeyspaceTokenZeroElectorateMembership, and
+ # SidecarInternalTokenZeroElectorateMembership implementations.
+ # - MostReplicatedKeyspaceTokenZeroElectorateMembership the current Sidecar will be determined to be part
+ # of the electorate iff one of the Cassandra instances it
+ # manages owns token 0 for the user keyspace that has the
+ # highest replication factor. If multiple keyspaces have
+ # the highest replication factor, the keyspace to be used
+ # is decided by the keyspace with the name that sorts
+ # first in the lexicographic sort order. If no user
+ # keyspaces are created, the internal sidecar keyspace will
+ # be used.
+ # - SidecarInternalTokenZeroElectorateMembership the current Sidecar will be determined to be part of the
+ # electorate iff one of the Cassandra instances it manages
+ # owns token {@code 0} for the {@code sidecar_internal}
+ # keyspace.
+ electorate_membership_strategy: MostReplicatedKeyspaceTokenZeroElectorateMembership
# Whether the process is enabled
enabled: true
# The initial delay for the first execution of the cluster lease claim process task after being
# scheduled or rescheduled.
# The minimum value for the initial delay is 0ms.
- initial_delay: 1s
Review Comment:
> The minimum value for the initial delay is 0ms.
Is it true? Should the minimum be 0? It will cause a lot of cas contention.
##########
server/src/main/java/org/apache/cassandra/sidecar/coordination/AbstractTokenZeroOfKeyspaceElectorateMembership.java:
##########
@@ -0,0 +1,149 @@
+/*
+ * 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.sidecar.coordination;
+
+import java.math.BigInteger;
+import java.net.InetSocketAddress;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.cassandra.sidecar.cluster.CassandraAdapterDelegate;
+import org.apache.cassandra.sidecar.cluster.instance.InstanceMetadata;
+import org.apache.cassandra.sidecar.common.response.NodeSettings;
+import org.apache.cassandra.sidecar.common.response.TokenRangeReplicasResponse;
+import org.apache.cassandra.sidecar.common.server.StorageOperations;
+import org.apache.cassandra.sidecar.common.server.data.Name;
+import org.apache.cassandra.sidecar.common.server.utils.StringUtils;
+import org.apache.cassandra.sidecar.exceptions.CassandraUnavailableException;
+import org.apache.cassandra.sidecar.utils.InstanceMetadataFetcher;
+
+/**
+ * Provides common functionality for {@link ElectorateMembership} implementations
+ * that rely on token zero replication of a keyspace to determine eligibility.
+ */
+public abstract class AbstractTokenZeroOfKeyspaceElectorateMembership implements ElectorateMembership
+{
+ private static final Logger LOGGER = LoggerFactory.getLogger(AbstractTokenZeroOfKeyspaceElectorateMembership.class);
+ protected final InstanceMetadataFetcher instanceMetadataFetcher;
+
+ public AbstractTokenZeroOfKeyspaceElectorateMembership(InstanceMetadataFetcher instanceMetadataFetcher)
+ {
+ this.instanceMetadataFetcher = instanceMetadataFetcher;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isMember()
+ {
+ Set<String> localInstancesHostsAndPorts = collectLocalInstancesHostsAndPorts();
+ if (localInstancesHostsAndPorts.isEmpty())
+ {
+ // Unable to retrieve local instances, maybe all Cassandra connections are down?
+ return false;
+ }
+
+ String keyspace = keyspaceToDetermineElectorateMembership();
+ if (keyspace == null)
+ {
+ // pre-checks failed
+ return false;
+ }
+ LOGGER.debug("Using keyspace={} to determine electorate membership", keyspace);
+
+ TokenRangeReplicasResponse tokenRangeReplicas = instanceMetadataFetcher.callOnFirstAvailableInstance(instance -> {
+ CassandraAdapterDelegate delegate = instance.delegate();
+ StorageOperations operations = delegate.storageOperations();
+ NodeSettings nodeSettings = delegate.nodeSettings();
+ return operations.tokenRangeReplicas(new Name(keyspace), nodeSettings.partitioner());
+ });
+
+ return anyInstanceOwnsTokenZero(tokenRangeReplicas, localInstancesHostsAndPorts);
+ }
+
+ /**
+ * @return the name of the keyspace that will be used to determine the electorate membership
+ */
+ protected abstract String keyspaceToDetermineElectorateMembership();
+
+ Set<String> collectLocalInstancesHostsAndPorts()
+ {
+ Set<String> result = new HashSet<>();
+ for (InstanceMetadata instance : instanceMetadataFetcher.allLocalInstances())
+ {
+ try
+ {
+ InetSocketAddress address = instance.delegate().localStorageBroadcastAddress();
+ result.add(StringUtils.cassandraFormattedHostAndPort(address));
+ }
+ catch (CassandraUnavailableException exception)
+ {
+ // Log a warning message and continue
+ LOGGER.warn("Unable to determine local storage broadcast address for instance. instance={}", instance, exception);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * @param tokenRangeReplicas the token range replicas for a keyspace
+ * @param localInstancesHostAndPorts local instance(s) IP(s) and port(s)
+ * @return {@code true} if any of the local instances is a replica of token zero for a single keyspace,
+ * {@code false} otherwise
+ */
+ boolean anyInstanceOwnsTokenZero(TokenRangeReplicasResponse tokenRangeReplicas, Set<String> localInstancesHostAndPorts)
Review Comment:
curious, why not `protected` for this and for `collectLocalInstancesHostsAndPorts` and `replicaOwnsTokenZero`?
##########
server/src/main/java/org/apache/cassandra/sidecar/db/SidecarLeaseDatabaseAccessor.java:
##########
@@ -76,20 +78,22 @@ public LeaseClaimResult extendLease(String currentOwner)
*/
public static class LeaseClaimResult
{
- public final boolean leaseAcquired;
public final String currentOwner;
- LeaseClaimResult(boolean leaseAcquired, String currentOwner)
+ LeaseClaimResult(String currentOwner)
{
- this.leaseAcquired = leaseAcquired;
this.currentOwner = currentOwner;
}
static LeaseClaimResult from(ResultSet resultSet, String newOwner)
{
return resultSet.wasApplied()
- ? new LeaseClaimResult(true, newOwner)
- : new LeaseClaimResult(false, resultSet.one().getString("owner"));
+ ? new LeaseClaimResult(newOwner)
+ // In some rare cases, the resultSet will not contain the owner information
+ // even though the resultSet was not applied. This will translate into an
+ // IllegalArgumentException being thrown when trying to retrieve the non-existing
+ // owner string. This exception is left to be handled by the caller method
+ : new LeaseClaimResult(resultSet.one().getString("owner"));
Review Comment:
It is unclear to me what is the proper handling at the caller. Maybe handle exception here and set a new state, say "unknown". Caller can react on the "unknown" state, for example, query retry.
##########
server/src/main/java/org/apache/cassandra/sidecar/modules/CoordinationModule.java:
##########
@@ -70,6 +72,18 @@ ElectorateMembership electorateMembership(InstanceMetadataFetcher instanceMetada
CQLSessionProvider cqlSessionProvider,
SidecarConfiguration configuration)
{
- return new MostReplicatedKeyspaceTokenZeroElectorateMembership(instanceMetadataFetcher, cqlSessionProvider, configuration);
+ String strategy = configuration.serviceConfiguration()
+ .coordinationConfiguration()
+ .clusterLeaseClaimConfiguration()
+ .electorateMembershipStrategy();
+ switch (strategy)
+ {
+ case "MostReplicatedKeyspaceTokenZeroElectorateMembership":
+ return new MostReplicatedKeyspaceTokenZeroElectorateMembership(instanceMetadataFetcher, cqlSessionProvider, configuration);
+ case "SidecarInternalTokenZeroElectorateMembership":
+ return new SidecarInternalTokenZeroElectorateMembership(instanceMetadataFetcher, configuration);
+ default:
+ throw new ConfigurationException("Invalid electorate membership strategy value '" + strategy + "'");
+ }
Review Comment:
can we move this code to a factory class? Module code is hard to testable, and complex code should be tested.
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSSIDECAR-232: Enhance the Cluster Lease Claim task feature [cassandra-sidecar]
Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on code in PR #211:
URL: https://github.com/apache/cassandra-sidecar/pull/211#discussion_r2004459240
##########
server/src/test/integration/org/apache/cassandra/sidecar/coordination/MostReplicatedKeyspaceTokenZeroElectorateMembershipIntegrationTest.java:
##########
@@ -107,12 +109,17 @@ void test(TestVersion version) throws IOException
private void runTestScenario(AbstractCluster<?> cluster)
{
- List<MostReplicatedKeyspaceTokenZeroElectorateMembership> memberships = buildElectorateMembershipPerCassandraInstance(cluster);
+ var pair = buildElectorateMembershipPerCassandraInstance(cluster);
Review Comment:
I used it for convenience in the test, otherwise the line was huge! I'd prefer to keep it here, but I also am wary of introducing var because other contributors will start using it and I think we should lean on discouraging its use.
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSSIDECAR-232: Enhance the Cluster Lease Claim task feature [cassandra-sidecar]
Posted by "yifan-c (via GitHub)" <gi...@apache.org>.
yifan-c commented on code in PR #211:
URL: https://github.com/apache/cassandra-sidecar/pull/211#discussion_r2004462373
##########
server/src/main/java/org/apache/cassandra/sidecar/coordination/ClusterLeaseClaimTask.java:
##########
@@ -144,7 +147,13 @@ public ScheduleDecision scheduleDecision()
@Override
public DurationSpec initialDelay()
{
- return periodicTaskConfiguration.initialDelay();
+ // Return a randomized delay to introduce jitter among all the instances participating
+ // in the lease claim process
+ MillisecondBoundConfiguration initialDelay = periodicTaskConfiguration.initialDelay();
+ long millis = initialDelay.toMillis();
+ return millis <= 0
+ ? initialDelay
+ : new MillisecondBoundConfiguration(ThreadLocalRandom.current().nextLong(millis), TimeUnit.MILLISECONDS);
Review Comment:
Thinking it more. I think the current `RAND(initialDelay)` changes the semantics of the initial delay. It is almost guaranteed that the actual value is not the `initialDelay`. It could cause surprise.
Would it make sense to split it into 2 parts, `minInitialDelay` and `maxInitialDelay`? The actual value is randomly picked that in the value range.
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSSIDECAR-232: Enhance the Cluster Lease Claim task feature [cassandra-sidecar]
Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on code in PR #211:
URL: https://github.com/apache/cassandra-sidecar/pull/211#discussion_r2004400355
##########
server/src/main/java/org/apache/cassandra/sidecar/coordination/AbstractTokenZeroOfKeyspaceElectorateMembership.java:
##########
@@ -0,0 +1,149 @@
+/*
+ * 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.sidecar.coordination;
+
+import java.math.BigInteger;
+import java.net.InetSocketAddress;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.cassandra.sidecar.cluster.CassandraAdapterDelegate;
+import org.apache.cassandra.sidecar.cluster.instance.InstanceMetadata;
+import org.apache.cassandra.sidecar.common.response.NodeSettings;
+import org.apache.cassandra.sidecar.common.response.TokenRangeReplicasResponse;
+import org.apache.cassandra.sidecar.common.server.StorageOperations;
+import org.apache.cassandra.sidecar.common.server.data.Name;
+import org.apache.cassandra.sidecar.common.server.utils.StringUtils;
+import org.apache.cassandra.sidecar.exceptions.CassandraUnavailableException;
+import org.apache.cassandra.sidecar.utils.InstanceMetadataFetcher;
+
+/**
+ * Provides common functionality for {@link ElectorateMembership} implementations
+ * that rely on token zero replication of a keyspace to determine eligibility.
+ */
+public abstract class AbstractTokenZeroOfKeyspaceElectorateMembership implements ElectorateMembership
+{
+ private static final Logger LOGGER = LoggerFactory.getLogger(AbstractTokenZeroOfKeyspaceElectorateMembership.class);
+ protected final InstanceMetadataFetcher instanceMetadataFetcher;
+
+ public AbstractTokenZeroOfKeyspaceElectorateMembership(InstanceMetadataFetcher instanceMetadataFetcher)
+ {
+ this.instanceMetadataFetcher = instanceMetadataFetcher;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isMember()
+ {
+ Set<String> localInstancesHostsAndPorts = collectLocalInstancesHostsAndPorts();
+ if (localInstancesHostsAndPorts.isEmpty())
+ {
+ // Unable to retrieve local instances, maybe all Cassandra connections are down?
+ return false;
+ }
+
+ String keyspace = keyspaceToDetermineElectorateMembership();
+ if (keyspace == null)
+ {
+ // pre-checks failed
+ return false;
+ }
+ LOGGER.debug("Using keyspace={} to determine electorate membership", keyspace);
+
+ TokenRangeReplicasResponse tokenRangeReplicas = instanceMetadataFetcher.callOnFirstAvailableInstance(instance -> {
+ CassandraAdapterDelegate delegate = instance.delegate();
+ StorageOperations operations = delegate.storageOperations();
+ NodeSettings nodeSettings = delegate.nodeSettings();
+ return operations.tokenRangeReplicas(new Name(keyspace), nodeSettings.partitioner());
+ });
+
+ return anyInstanceOwnsTokenZero(tokenRangeReplicas, localInstancesHostsAndPorts);
+ }
+
+ /**
+ * @return the name of the keyspace that will be used to determine the electorate membership
+ */
+ protected abstract String keyspaceToDetermineElectorateMembership();
+
+ Set<String> collectLocalInstancesHostsAndPorts()
+ {
+ Set<String> result = new HashSet<>();
+ for (InstanceMetadata instance : instanceMetadataFetcher.allLocalInstances())
+ {
+ try
+ {
+ InetSocketAddress address = instance.delegate().localStorageBroadcastAddress();
+ result.add(StringUtils.cassandraFormattedHostAndPort(address));
+ }
+ catch (CassandraUnavailableException exception)
+ {
+ // Log a warning message and continue
+ LOGGER.warn("Unable to determine local storage broadcast address for instance. instance={}", instance, exception);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * @param tokenRangeReplicas the token range replicas for a keyspace
+ * @param localInstancesHostAndPorts local instance(s) IP(s) and port(s)
+ * @return {@code true} if any of the local instances is a replica of token zero for a single keyspace,
+ * {@code false} otherwise
+ */
+ boolean anyInstanceOwnsTokenZero(TokenRangeReplicasResponse tokenRangeReplicas, Set<String> localInstancesHostAndPorts)
Review Comment:
good point! this is just copy paste error. This code originally lived in the `MostReplicatedKeyspaceTokenZeroElectorateMembership` class, and it has now been moved to `AbstractTokenZeroOfKeyspaceElectorateMembership`
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSSIDECAR-232: Enhance the Cluster Lease Claim task feature [cassandra-sidecar]
Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on code in PR #211:
URL: https://github.com/apache/cassandra-sidecar/pull/211#discussion_r2004421415
##########
server/src/main/java/org/apache/cassandra/sidecar/coordination/ClusterLeaseClaimTask.java:
##########
@@ -144,7 +147,13 @@ public ScheduleDecision scheduleDecision()
@Override
public DurationSpec initialDelay()
{
- return periodicTaskConfiguration.initialDelay();
+ // Return a randomized delay to introduce jitter among all the instances participating
+ // in the lease claim process
+ MillisecondBoundConfiguration initialDelay = periodicTaskConfiguration.initialDelay();
+ long millis = initialDelay.toMillis();
+ return millis <= 0
+ ? initialDelay
+ : new MillisecondBoundConfiguration(ThreadLocalRandom.current().nextLong(millis), TimeUnit.MILLISECONDS);
Review Comment:
I could have done `==` but I think it's fine to leave a `<=` what do you think?
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSSIDECAR-232: Enhance the Cluster Lease Claim task feature [cassandra-sidecar]
Posted by "yifan-c (via GitHub)" <gi...@apache.org>.
yifan-c commented on code in PR #211:
URL: https://github.com/apache/cassandra-sidecar/pull/211#discussion_r2004456719
##########
server/src/main/java/org/apache/cassandra/sidecar/db/SidecarLeaseDatabaseAccessor.java:
##########
@@ -76,20 +78,22 @@ public LeaseClaimResult extendLease(String currentOwner)
*/
public static class LeaseClaimResult
{
- public final boolean leaseAcquired;
public final String currentOwner;
- LeaseClaimResult(boolean leaseAcquired, String currentOwner)
+ LeaseClaimResult(String currentOwner)
{
- this.leaseAcquired = leaseAcquired;
this.currentOwner = currentOwner;
}
static LeaseClaimResult from(ResultSet resultSet, String newOwner)
{
return resultSet.wasApplied()
- ? new LeaseClaimResult(true, newOwner)
- : new LeaseClaimResult(false, resultSet.one().getString("owner"));
+ ? new LeaseClaimResult(newOwner)
+ // In some rare cases, the resultSet will not contain the owner information
+ // even though the resultSet was not applied. This will translate into an
+ // IllegalArgumentException being thrown when trying to retrieve the non-existing
+ // owner string. This exception is left to be handled by the caller method
+ : new LeaseClaimResult(resultSet.one().getString("owner"));
Review Comment:
my thinking was also unclear. Disregard it :p
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSSIDECAR-232: Enhance the Cluster Lease Claim task feature [cassandra-sidecar]
Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on code in PR #211:
URL: https://github.com/apache/cassandra-sidecar/pull/211#discussion_r2004403463
##########
server/src/test/resources/config/sidecar_coordination.yaml:
##########
Review Comment:
inlined this to a yaml string so we avoid having to add new files every time
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSSIDECAR-232: Enhance the Cluster Lease Claim task feature [cassandra-sidecar]
Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on code in PR #211:
URL: https://github.com/apache/cassandra-sidecar/pull/211#discussion_r2004467955
##########
server/src/test/integration/org/apache/cassandra/sidecar/coordination/MostReplicatedKeyspaceTokenZeroElectorateMembershipIntegrationTest.java:
##########
@@ -107,12 +109,17 @@ void test(TestVersion version) throws IOException
private void runTestScenario(AbstractCluster<?> cluster)
{
- List<MostReplicatedKeyspaceTokenZeroElectorateMembership> memberships = buildElectorateMembershipPerCassandraInstance(cluster);
+ var pair = buildElectorateMembershipPerCassandraInstance(cluster);
Review Comment:
ok, I'm no longer using var, I think that's better
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSSIDECAR-232: Enhance the Cluster Lease Claim task feature [cassandra-sidecar]
Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on code in PR #211:
URL: https://github.com/apache/cassandra-sidecar/pull/211#discussion_r2004397807
##########
conf/sidecar.yaml:
##########
@@ -121,20 +121,37 @@ sidecar:
replication_strategy: SimpleStrategy
replication_factor: 1
# The TTL in seconds used to insert entries into the sidecar_lease schema
- lease_schema_ttl: 2m
+ lease_schema_ttl: 5m
coordination:
# Captures configuration parameters for the task that performs the cluster lease claim process
cluster_lease_claim:
+ # The name of the strategy used to determine the electorate membership
+ # Out of the box Sidecar provides the MostReplicatedKeyspaceTokenZeroElectorateMembership, and
+ # SidecarInternalTokenZeroElectorateMembership implementations.
+ # - MostReplicatedKeyspaceTokenZeroElectorateMembership the current Sidecar will be determined to be part
+ # of the electorate iff one of the Cassandra instances it
+ # manages owns token 0 for the user keyspace that has the
+ # highest replication factor. If multiple keyspaces have
+ # the highest replication factor, the keyspace to be used
+ # is decided by the keyspace with the name that sorts
+ # first in the lexicographic sort order. If no user
+ # keyspaces are created, the internal sidecar keyspace will
+ # be used.
+ # - SidecarInternalTokenZeroElectorateMembership the current Sidecar will be determined to be part of the
+ # electorate iff one of the Cassandra instances it manages
+ # owns token {@code 0} for the {@code sidecar_internal}
+ # keyspace.
+ electorate_membership_strategy: MostReplicatedKeyspaceTokenZeroElectorateMembership
Review Comment:
pushed the test
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSSIDECAR-232: Enhance the Cluster Lease Claim task feature [cassandra-sidecar]
Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on code in PR #211:
URL: https://github.com/apache/cassandra-sidecar/pull/211#discussion_r2004467742
##########
server/src/main/java/org/apache/cassandra/sidecar/coordination/ClusterLeaseClaimTask.java:
##########
@@ -144,7 +147,13 @@ public ScheduleDecision scheduleDecision()
@Override
public DurationSpec initialDelay()
{
- return periodicTaskConfiguration.initialDelay();
+ // Return a randomized delay to introduce jitter among all the instances participating
+ // in the lease claim process
+ MillisecondBoundConfiguration initialDelay = periodicTaskConfiguration.initialDelay();
+ long millis = initialDelay.toMillis();
+ return millis <= 0
+ ? initialDelay
+ : new MillisecondBoundConfiguration(ThreadLocalRandom.current().nextLong(millis), TimeUnit.MILLISECONDS);
Review Comment:
I think that's fine, but I would probably like to address it as part of a different effort. What do you think ? In that case we'd also need to address the randomized initial delay in `org.apache.cassandra.sidecar.datahub.SchemaReportingTask#initialDelay`
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSSIDECAR-232: Enhance the Cluster Lease Claim task feature [cassandra-sidecar]
Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh merged PR #211:
URL: https://github.com/apache/cassandra-sidecar/pull/211
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSSIDECAR-232: Enhance the Cluster Lease Claim task feature [cassandra-sidecar]
Posted by "yifan-c (via GitHub)" <gi...@apache.org>.
yifan-c commented on code in PR #211:
URL: https://github.com/apache/cassandra-sidecar/pull/211#discussion_r2004396091
##########
server/src/main/java/org/apache/cassandra/sidecar/coordination/ClusterLeaseClaimTask.java:
##########
@@ -144,7 +147,13 @@ public ScheduleDecision scheduleDecision()
@Override
public DurationSpec initialDelay()
{
- return periodicTaskConfiguration.initialDelay();
+ // Return a randomized delay to introduce jitter among all the instances participating
+ // in the lease claim process
+ MillisecondBoundConfiguration initialDelay = periodicTaskConfiguration.initialDelay();
+ long millis = initialDelay.toMillis();
+ return millis <= 0
+ ? initialDelay
+ : new MillisecondBoundConfiguration(ThreadLocalRandom.current().nextLong(millis), TimeUnit.MILLISECONDS);
Review Comment:
How can `initialDelay` be configured negative?
How about adding a lower bound to the randomized delay? I am thinking of 1 second.
--
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: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org