Class 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 of ClusterInfo for 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 BroadcastableClusterInfo instance, which is then included in the BulkWriterConfig that gets broadcast.

    This class implements Serializable only because the ClusterInfo interface requires it (for use as a field type in broadcast classes), but instances of this class are never directly serialized.

    • Field Detail

      • clusterId

        protected final java.lang.String clusterId
      • cassandraVersion

        protected java.lang.String cassandraVersion
      • partitioner

        protected org.apache.cassandra.spark.data.partitioner.Partitioner partitioner
      • keyspaceSchema

        protected volatile java.lang.String keyspaceSchema
      • replicationFactor

        protected volatile org.apache.cassandra.spark.data.ReplicationFactor replicationFactor
      • 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

      • getVersion

        public java.lang.String getVersion()
      • clusterId

        public java.lang.String clusterId()
        Description copied from interface: ClusterInfo
        ID string that can uniquely identify a cluster

        Implementor 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:
        clusterId in interface ClusterInfo
        Returns:
        cluster id string, null if absent
      • buildCassandraContext

        protected CassandraContext buildCassandraContext()
        Gets a Cassandra Context

        NOTE: 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:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in interface ClusterInfo
      • getPartitioner

        public org.apache.cassandra.spark.data.partitioner.Partitioner getPartitioner()
        Specified by:
        getPartitioner in interface ClusterInfo
      • 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.TimeSkewTooLargeException
        Description copied from interface: ClusterInfo
        Validate whether the time skew of the replicas of the range is acceptable
        Specified by:
        validateTimeSkew in interface ClusterInfo
        Parameters:
        range - token range used to look up the relevant replicas
        Throws:
        org.apache.cassandra.spark.exception.SidecarApiCallException - when fails to retrieve time skew information
        org.apache.cassandra.spark.exception.TimeSkewTooLargeException - when the time skew has exceeded the allowance
      • 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: ClusterInfo
        Return the keyspace schema string of the enclosing keyspace for bulk write in the cluster
        Specified by:
        getKeyspaceSchema in interface ClusterInfo
        Parameters:
        cached - whether using the cached schema information
        Returns:
        keyspace schema string
      • replicationFactor

        public org.apache.cassandra.spark.data.ReplicationFactor replicationFactor()
        Specified by:
        replicationFactor in interface ClusterInfo
        Returns:
        ReplicationFactor of the enclosing keyspace for bulk write in the cluster
      • 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: StartupValidatable
        Performs startup validation using StartupValidator with currently registered StartupValidations, throws a RuntimeException if any violations are found, needs to be invoked once per execution before any actual work is started
        Specified by:
        startupValidate in interface StartupValidatable