Class CassandraClusterInfoGroup
- java.lang.Object
-
- org.apache.cassandra.spark.bulkwriter.cloudstorage.coordinated.CassandraClusterInfoGroup
-
- All Implemented Interfaces:
MultiClusterSupport<ClusterInfo>,ClusterInfo,StartupValidatable
public class CassandraClusterInfoGroup extends java.lang.Object implements ClusterInfo, MultiClusterSupport<ClusterInfo>
A group of ClusterInfo. One per cluster. The class does the aggregation over all clusters for applicable operations.This class is NOT serialized and does NOT have a serialVersionUID. When broadcasting to executors, the driver extracts information from this class and creates a
BroadcastableClusterInfoGroupinstance, which is then included in theBulkWriterConfigthat gets broadcast.This class implements Serializable only because the
ClusterInfointerface requires it (for use as a field type in broadcast classes), but instances of this class are never directly serialized.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckBulkWriterIsEnabledOrThrow()java.lang.StringclusterId()ID string that can uniquely identify a clusterjava.util.Map<RingInstance,WriteAvailability>clusterWriteAvailability()static CassandraClusterInfoGroupcreateFrom(java.util.List<ClusterInfo> clusterInfos)voidforEach(java.util.function.BiConsumer<java.lang.String,ClusterInfo> action)Iterate through all valuesstatic CassandraClusterInfoGroupfrom(BroadcastableClusterInfoGroup broadcastable)Reconstruct from BroadcastableClusterInfoGroup on executor.static CassandraClusterInfoGroupfromBulkSparkConf(BulkSparkConf conf)CreatesCassandraClusterInfoGroupwith the list ofClusterInfofromBulkSparkConfand validation The validation ensures non-empty list ofClusterInfo, where all objects have non-empty and unique clusterIdstatic CassandraClusterInfoGroupfromBulkSparkConf(BulkSparkConf conf, java.util.function.Function<java.lang.String,ClusterInfo> clusterInfoFactory)Similar tofromBulkSparkConf(BulkSparkConf)but takes additional function to createClusterInfoCassandraContextgetCassandraContext()java.lang.StringgetKeyspaceSchema(boolean cached)Return the keyspace schema string of the enclosing keyspace for bulk write in the clusterjava.lang.StringgetLowestCassandraVersion()org.apache.cassandra.spark.data.partitioner.PartitionergetPartitioner()TokenRangeMapping<RingInstance>getTokenRangeMapping(boolean cached)ClusterInfogetValueOrNull(java.lang.String clusterId)Look up a value based on clusterIdvoidrefreshClusterInfo()org.apache.cassandra.spark.data.ReplicationFactorreplicationFactor()intsize()voidstartupValidate()Performs startup validation usingStartupValidatorwith currently registeredStartupValidations, throws aRuntimeExceptionif any violations are found, needs to be invoked once per execution before any actual work is startedvoidvalidateTimeSkew(com.google.common.collect.Range<java.math.BigInteger> range)Validate whether the time skew of the replicas of the range is acceptable-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.cassandra.spark.bulkwriter.ClusterInfo
close
-
Methods inherited from interface org.apache.cassandra.spark.bulkwriter.cloudstorage.coordinated.MultiClusterSupport
getValueOrThrow
-
-
-
-
Method Detail
-
fromBulkSparkConf
public static CassandraClusterInfoGroup fromBulkSparkConf(BulkSparkConf conf)
CreatesCassandraClusterInfoGroupwith the list ofClusterInfofromBulkSparkConfand validation The validation ensures non-empty list ofClusterInfo, where all objects have non-empty and unique clusterId- Parameters:
conf- bulk write conf- Returns:
- new
CassandraClusterInfoGroupinstance
-
from
public static CassandraClusterInfoGroup from(BroadcastableClusterInfoGroup broadcastable)
Reconstruct from BroadcastableClusterInfoGroup on executor. Creates CassandraClusterInfo instances for each cluster that will fetch data from Sidecar. Leverages pre-computed values (partitioner, lowestCassandraVersion) from the broadcastable to avoid re-validation and re-computation on executors.- Parameters:
broadcastable- the broadcastable cluster info group from broadcast- Returns:
- new
CassandraClusterInfoGroupinstance
-
fromBulkSparkConf
public static CassandraClusterInfoGroup fromBulkSparkConf(BulkSparkConf conf, java.util.function.Function<java.lang.String,ClusterInfo> clusterInfoFactory)
Similar tofromBulkSparkConf(BulkSparkConf)but takes additional function to createClusterInfo
-
createFrom
public static CassandraClusterInfoGroup createFrom(java.util.List<ClusterInfo> clusterInfos)
-
refreshClusterInfo
public void refreshClusterInfo()
- Specified by:
refreshClusterInfoin interfaceClusterInfo
-
getTokenRangeMapping
public TokenRangeMapping<RingInstance> getTokenRangeMapping(boolean cached)
- Specified by:
getTokenRangeMappingin interfaceClusterInfo
-
getLowestCassandraVersion
public java.lang.String getLowestCassandraVersion()
- Specified by:
getLowestCassandraVersionin interfaceClusterInfo- Returns:
- the lowest cassandra version among all clusters
-
clusterWriteAvailability
public java.util.Map<RingInstance,WriteAvailability> clusterWriteAvailability()
- Specified by:
clusterWriteAvailabilityin interfaceClusterInfo- Returns:
- WriteAvailability per RingInstance in the cluster
-
getPartitioner
public org.apache.cassandra.spark.data.partitioner.Partitioner getPartitioner()
- Specified by:
getPartitionerin interfaceClusterInfo
-
checkBulkWriterIsEnabledOrThrow
public void checkBulkWriterIsEnabledOrThrow()
- Specified by:
checkBulkWriterIsEnabledOrThrowin interfaceClusterInfo
-
validateTimeSkew
public void validateTimeSkew(com.google.common.collect.Range<java.math.BigInteger> range) throws org.apache.cassandra.spark.exception.SidecarApiCallException, org.apache.cassandra.spark.exception.TimeSkewTooLargeExceptionDescription copied from interface:ClusterInfoValidate whether the time skew of the replicas of the range is acceptable- Specified by:
validateTimeSkewin interfaceClusterInfo- Parameters:
range- token range used to look up the relevant replicas- Throws:
org.apache.cassandra.spark.exception.SidecarApiCallException- when fails to retrieve time skew informationorg.apache.cassandra.spark.exception.TimeSkewTooLargeException- when the time skew has exceeded the allowance
-
getKeyspaceSchema
public java.lang.String getKeyspaceSchema(boolean cached)
Description copied from interface:ClusterInfoReturn the keyspace schema string of the enclosing keyspace for bulk write in the cluster- Specified by:
getKeyspaceSchemain interfaceClusterInfo- Parameters:
cached- whether using the cached schema information- Returns:
- keyspace schema string
-
replicationFactor
public org.apache.cassandra.spark.data.ReplicationFactor replicationFactor()
- Specified by:
replicationFactorin interfaceClusterInfo- Returns:
- ReplicationFactor of the enclosing keyspace for bulk write in the cluster
-
getCassandraContext
public CassandraContext getCassandraContext()
- Specified by:
getCassandraContextin interfaceClusterInfo
-
startupValidate
public void startupValidate()
Description copied from interface:StartupValidatablePerforms startup validation usingStartupValidatorwith currently registeredStartupValidations, throws aRuntimeExceptionif any violations are found, needs to be invoked once per execution before any actual work is started- Specified by:
startupValidatein interfaceStartupValidatable
-
clusterId
public java.lang.String clusterId()
Description copied from interface:ClusterInfoID string that can uniquely identify a clusterImplementor note: the method is optional. When writing to a single cluster, there is no requirement of assigning an ID for bulk write to proceed. When in the coordinated write mode, i.e. writing to multiple clusters, the method must be implemented and return unique string for clusters.
- Specified by:
clusterIdin interfaceClusterInfo- Returns:
- cluster id string, null if absent
-
size
public int size()
- Specified by:
sizein interfaceMultiClusterSupport<ClusterInfo>- Returns:
- the total number of clusters
-
forEach
public void forEach(java.util.function.BiConsumer<java.lang.String,ClusterInfo> action)
Description copied from interface:MultiClusterSupportIterate through all values- Specified by:
forEachin interfaceMultiClusterSupport<ClusterInfo>- Parameters:
action- function to consume the values
-
getValueOrNull
@Nullable public ClusterInfo getValueOrNull(@NotNull java.lang.String clusterId)
Description copied from interface:MultiClusterSupportLook up a value based on clusterId- Specified by:
getValueOrNullin interfaceMultiClusterSupport<ClusterInfo>- Parameters:
clusterId- cluster id- Returns:
- the value of type T associated with the clusterId, or null if not found
-
-