Class CassandraClusterInfo
- java.lang.Object
-
- org.apache.cassandra.spark.bulkwriter.CassandraClusterInfo
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,ClusterInfo,StartupValidatable
public class CassandraClusterInfo extends java.lang.Object implements ClusterInfo, java.io.Closeable
Driver-only implementation ofClusterInfofor single cluster 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
BroadcastableClusterInfoinstance, 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.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<java.util.concurrent.CompletableFuture<o.a.c.sidecar.client.shaded.common.response.NodeSettings>>allNodeSettingFuturesprotected CassandraContextcassandraContextprotected java.lang.StringcassandraVersionprotected java.lang.StringclusterIdprotected BulkSparkConfconfprotected java.lang.StringkeyspaceSchemaprotected java.util.concurrent.atomic.AtomicReference<o.a.c.sidecar.client.shaded.common.response.NodeSettings>nodeSettingsprotected org.apache.cassandra.spark.data.partitioner.Partitionerpartitionerprotected org.apache.cassandra.spark.data.ReplicationFactorreplicationFactorprotected TokenRangeMapping<RingInstance>tokenRangeReplicas
-
Constructor Summary
Constructors Constructor Description CassandraClusterInfo(BroadcastableClusterInfo broadcastable)Reconstruct from BroadcastableCluster on executor.CassandraClusterInfo(BulkSparkConf conf)CassandraClusterInfo(BulkSparkConf conf, java.lang.String clusterId)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.apache.cassandra.bridge.CassandraBridgebridge()protected CassandraContextbuildCassandraContext()Gets a Cassandra ContextvoidcheckBulkWriterIsEnabledOrThrow()voidclose()java.lang.StringclusterId()ID string that can uniquely identify a clusterjava.util.Map<RingInstance,WriteAvailability>clusterWriteAvailability()protected WriteAvailabilitydetermineWriteAvailability(RingInstance instance)protected java.util.List<o.a.c.sidecar.client.shaded.common.response.NodeSettings>getAllNodeSettings()CassandraContextgetCassandraContext()protected java.lang.StringgetCurrentKeyspaceSchema()java.lang.StringgetKeyspaceSchema(boolean cached)Return the keyspace schema string of the enclosing keyspace for bulk write in the clusterjava.lang.StringgetLowestCassandraVersion()java.lang.StringgetLowestVersion(java.util.List<o.a.c.sidecar.client.shaded.common.response.NodeSettings> allNodeSettings)org.apache.cassandra.spark.data.partitioner.PartitionergetPartitioner()TokenRangeMapping<RingInstance>getTokenRangeMapping(boolean cached)java.lang.StringgetVersion()java.lang.StringgetVersionFromFeature()java.lang.StringgetVersionFromSidecar()voidrefreshClusterInfo()org.apache.cassandra.spark.data.ReplicationFactorreplicationFactor()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
-
-
-
Field Detail
-
conf
protected final BulkSparkConf conf
-
clusterId
protected final java.lang.String clusterId
-
cassandraVersion
protected java.lang.String cassandraVersion
-
partitioner
protected org.apache.cassandra.spark.data.partitioner.Partitioner partitioner
-
tokenRangeReplicas
protected volatile TokenRangeMapping<RingInstance> tokenRangeReplicas
-
keyspaceSchema
protected volatile java.lang.String keyspaceSchema
-
replicationFactor
protected volatile org.apache.cassandra.spark.data.ReplicationFactor replicationFactor
-
cassandraContext
protected volatile CassandraContext cassandraContext
-
nodeSettings
protected final java.util.concurrent.atomic.AtomicReference<o.a.c.sidecar.client.shaded.common.response.NodeSettings> nodeSettings
-
allNodeSettingFutures
protected final java.util.List<java.util.concurrent.CompletableFuture<o.a.c.sidecar.client.shaded.common.response.NodeSettings>> allNodeSettingFutures
-
-
Constructor Detail
-
CassandraClusterInfo
public CassandraClusterInfo(BulkSparkConf conf)
-
CassandraClusterInfo
public CassandraClusterInfo(BulkSparkConf conf, java.lang.String clusterId)
-
CassandraClusterInfo
public CassandraClusterInfo(BroadcastableClusterInfo broadcastable)
Reconstruct from BroadcastableCluster on executor. Reuses cassandraVersion and partitioner from broadcast, fetches other data (tokenRangeMapping, replicationFactor, keyspaceSchema, writeAvailability) fresh from Sidecar.- Parameters:
broadcastable- the broadcastable cluster info from broadcast
-
-
Method Detail
-
checkBulkWriterIsEnabledOrThrow
public void checkBulkWriterIsEnabledOrThrow()
- Specified by:
checkBulkWriterIsEnabledOrThrowin interfaceClusterInfo
-
getVersion
public java.lang.String getVersion()
-
getCassandraContext
public CassandraContext getCassandraContext()
- Specified by:
getCassandraContextin interfaceClusterInfo
-
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
-
buildCassandraContext
protected CassandraContext buildCassandraContext()
Gets a Cassandra ContextNOTE: The caller of this method is required to call `shutdown` on the returned CassandraContext instance
- Returns:
- an instance of CassandraContext based on the configuration settings
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceClusterInfo
-
getPartitioner
public org.apache.cassandra.spark.data.partitioner.Partitioner getPartitioner()
- Specified by:
getPartitionerin 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
-
refreshClusterInfo
public void refreshClusterInfo()
- Specified by:
refreshClusterInfoin interfaceClusterInfo
-
getCurrentKeyspaceSchema
protected java.lang.String getCurrentKeyspaceSchema() throws java.lang.Exception- Throws:
java.lang.Exception
-
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
-
getTokenRangeMapping
public TokenRangeMapping<RingInstance> getTokenRangeMapping(boolean cached)
- Specified by:
getTokenRangeMappingin interfaceClusterInfo
-
getLowestCassandraVersion
public java.lang.String getLowestCassandraVersion()
- Specified by:
getLowestCassandraVersionin interfaceClusterInfo
-
clusterWriteAvailability
public java.util.Map<RingInstance,WriteAvailability> clusterWriteAvailability()
- Specified by:
clusterWriteAvailabilityin interfaceClusterInfo- Returns:
- WriteAvailability per RingInstance in the cluster
-
determineWriteAvailability
protected WriteAvailability determineWriteAvailability(RingInstance instance)
-
getVersionFromFeature
public java.lang.String getVersionFromFeature()
-
getAllNodeSettings
protected java.util.List<o.a.c.sidecar.client.shaded.common.response.NodeSettings> getAllNodeSettings()
-
getVersionFromSidecar
public java.lang.String getVersionFromSidecar()
-
getLowestVersion
public java.lang.String getLowestVersion(java.util.List<o.a.c.sidecar.client.shaded.common.response.NodeSettings> allNodeSettings)
-
bridge
protected org.apache.cassandra.bridge.CassandraBridge bridge()
-
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
-
-