Class SystemKeyspace


  • public final class SystemKeyspace
    extends java.lang.Object
    • Field Detail

      • PAXOS_REPAIR_HISTORY

        public static final java.lang.String PAXOS_REPAIR_HISTORY
        See Also:
        Constant Field Values
      • PAXOS_REPAIR_STATE

        public static final java.lang.String PAXOS_REPAIR_STATE
        See Also:
        Constant Field Values
      • COMPACTION_HISTORY

        public static final java.lang.String COMPACTION_HISTORY
        See Also:
        Constant Field Values
      • SSTABLE_ACTIVITY_V2

        public static final java.lang.String SSTABLE_ACTIVITY_V2
        See Also:
        Constant Field Values
      • TABLE_ESTIMATES_TYPE_PRIMARY

        public static final java.lang.String TABLE_ESTIMATES_TYPE_PRIMARY
        See Also:
        Constant Field Values
      • TABLE_ESTIMATES_TYPE_LOCAL_PRIMARY

        public static final java.lang.String TABLE_ESTIMATES_TYPE_LOCAL_PRIMARY
        See Also:
        Constant Field Values
      • AVAILABLE_RANGES_V2

        public static final java.lang.String AVAILABLE_RANGES_V2
        See Also:
        Constant Field Values
      • TRANSFERRED_RANGES_V2

        public static final java.lang.String TRANSFERRED_RANGES_V2
        See Also:
        Constant Field Values
      • VIEW_BUILDS_IN_PROGRESS

        public static final java.lang.String VIEW_BUILDS_IN_PROGRESS
        See Also:
        Constant Field Values
      • PREPARED_STATEMENTS

        public static final java.lang.String PREPARED_STATEMENTS
        See Also:
        Constant Field Values
      • TABLES_SPLIT_ACROSS_MULTIPLE_DISKS

        public static final java.util.Set<java.lang.String> TABLES_SPLIT_ACROSS_MULTIPLE_DISKS
        By default the system keyspace tables should be stored in a single data directory to allow the server to handle more gracefully disk failures. Some tables through can be split accross multiple directories as the server can continue operating even if those tables lost some data.
      • LEGACY_PEERS

        @Deprecated(since="4.0")
        public static final java.lang.String LEGACY_PEERS
        Deprecated.
        See CASSANDRA-7544
        See Also:
        Constant Field Values
      • LEGACY_PEER_EVENTS

        @Deprecated(since="4.0")
        public static final java.lang.String LEGACY_PEER_EVENTS
        Deprecated.
        See CASSANDRA-7544
        See Also:
        Constant Field Values
      • LEGACY_TRANSFERRED_RANGES

        @Deprecated(since="4.0")
        public static final java.lang.String LEGACY_TRANSFERRED_RANGES
        Deprecated.
        See CASSANDRA-7544
        See Also:
        Constant Field Values
      • LEGACY_AVAILABLE_RANGES

        @Deprecated(since="4.0")
        public static final java.lang.String LEGACY_AVAILABLE_RANGES
        Deprecated.
        See CASSANDRA-14404
        See Also:
        Constant Field Values
      • LEGACY_SIZE_ESTIMATES

        @Deprecated(since="4.0")
        public static final java.lang.String LEGACY_SIZE_ESTIMATES
        Deprecated.
        See CASSANDRA-15637
        See Also:
        Constant Field Values
      • LEGACY_SSTABLE_ACTIVITY

        @Deprecated(since="4.1")
        public static final java.lang.String LEGACY_SSTABLE_ACTIVITY
        Deprecated.
        See CASSANDRA-17048
        See Also:
        Constant Field Values
      • ALL_TABLE_NAMES

        public static final java.util.Set<java.lang.String> ALL_TABLE_NAMES
      • TABLE_NAMES

        public static final java.util.Set<java.lang.String> TABLE_NAMES
    • Method Detail

      • persistLocalMetadata

        public static void persistLocalMetadata()
      • persistLocalMetadata

        public static void persistLocalMetadata​(java.util.function.Supplier<java.util.UUID> nodeIdSupplier)
      • updateCompactionHistory

        public static void updateCompactionHistory​(TimeUUID taskId,
                                                   java.lang.String ksname,
                                                   java.lang.String cfname,
                                                   long compactedAt,
                                                   long bytesIn,
                                                   long bytesOut,
                                                   java.util.Map<java.lang.Integer,​java.lang.Long> rowsMerged,
                                                   java.util.Map<java.lang.String,​java.lang.String> compactionProperties)
      • getCompactionHistory

        public static javax.management.openmbean.TabularData getCompactionHistory()
                                                                           throws javax.management.openmbean.OpenDataException
        Throws:
        javax.management.openmbean.OpenDataException
      • isViewBuilt

        public static boolean isViewBuilt​(java.lang.String keyspaceName,
                                          java.lang.String viewName)
      • isViewStatusReplicated

        public static boolean isViewStatusReplicated​(java.lang.String keyspaceName,
                                                     java.lang.String viewName)
      • setViewBuilt

        public static void setViewBuilt​(java.lang.String keyspaceName,
                                        java.lang.String viewName,
                                        boolean replicated)
      • setViewRemoved

        public static void setViewRemoved​(java.lang.String keyspaceName,
                                          java.lang.String viewName)
      • finishViewBuildStatus

        public static void finishViewBuildStatus​(java.lang.String ksname,
                                                 java.lang.String viewName)
      • setViewBuiltReplicated

        public static void setViewBuiltReplicated​(java.lang.String ksname,
                                                  java.lang.String viewName)
      • updateViewBuildStatus

        public static void updateViewBuildStatus​(java.lang.String ksname,
                                                 java.lang.String viewName,
                                                 Range<Token> range,
                                                 Token lastToken,
                                                 long keysBuilt)
      • getViewBuildStatus

        public static java.util.Map<Range<Token>,​Pair<Token,​java.lang.Long>> getViewBuildStatus​(java.lang.String ksname,
                                                                                                            java.lang.String viewName)
      • removeTruncationRecord

        public static void removeTruncationRecord​(TableId id)
        This method is used to remove information about truncation time for specified column family
      • getTruncatedAt

        public static long getTruncatedAt​(TableId id)
      • updateTokens

        public static void updateTokens​(InetAddressAndPort ep,
                                        java.util.Collection<Token> tokens)
        Record tokens being used by another node
      • updatePeerInfo

        public static void updatePeerInfo​(InetAddressAndPort ep,
                                          java.lang.String columnName,
                                          java.lang.Object value)
      • updateSchemaVersion

        public static void updateSchemaVersion​(java.util.UUID version)
      • removeEndpoint

        public static void removeEndpoint​(java.net.InetSocketAddress ep)
        Remove stored tokens being used by another node
      • updateTokens

        public static void updateTokens​(java.util.Collection<Token> tokens)
        This method is used to update the System Keyspace with the new tokens for this node
      • forceBlockingFlush

        public static void forceBlockingFlush​(java.lang.String... cfnames)
      • loadTokens

        public static com.google.common.collect.SetMultimap<InetAddressAndPort,​Token> loadTokens()
        Return a map of stored tokens to IP addresses
      • loadHostIds

        public static java.util.Map<InetAddressAndPort,​java.util.UUID> loadHostIds()
        Return a map of store host_ids to IP addresses
      • getPreferredIP

        public static InetAddressAndPort getPreferredIP​(InetAddressAndPort ep)
        Get preferred IP for given endpoint if it is known. Otherwise this returns given endpoint itself.
        Parameters:
        ep - endpoint address to check
        Returns:
        Preferred IP for given endpoint if present, otherwise returns given ep
      • loadDcRackInfo

        public static java.util.Map<InetAddressAndPort,​java.util.Map<java.lang.String,​java.lang.String>> loadDcRackInfo()
        Return a map of IP addresses containing a map of dc and rack info
      • getReleaseVersion

        public static CassandraVersion getReleaseVersion​(InetAddressAndPort ep)
        Get release version for given endpoint. If release version is unknown, then this returns null.
        Parameters:
        ep - endpoint address to check
        Returns:
        Release version or null if version is unknown.
      • checkHealth

        public static void checkHealth()
                                throws ConfigurationException
        One of three things will happen if you try to read the system keyspace: 1. files are present and you can read them: great 2. no files are there: great (new node is assumed) 3. files are present but you can't read them: bad
        Throws:
        ConfigurationException
      • getSavedTokens

        public static java.util.Collection<Token> getSavedTokens()
      • incrementAndGetGeneration

        public static int incrementAndGetGeneration()
      • bootstrapComplete

        public static boolean bootstrapComplete()
      • bootstrapInProgress

        public static boolean bootstrapInProgress()
      • wasDecommissioned

        public static boolean wasDecommissioned()
      • isIndexBuilt

        public static boolean isIndexBuilt​(java.lang.String keyspaceName,
                                           java.lang.String indexName)
      • setIndexBuilt

        public static void setIndexBuilt​(java.lang.String keyspaceName,
                                         java.lang.String indexName)
      • setIndexRemoved

        public static void setIndexRemoved​(java.lang.String keyspaceName,
                                           java.lang.String indexName)
      • getBuiltIndexes

        public static java.util.List<java.lang.String> getBuiltIndexes​(java.lang.String keyspaceName,
                                                                       java.util.Set<java.lang.String> indexNames)
      • getLocalHostId

        public static java.util.UUID getLocalHostId()
        Read the host ID from the system keyspace.
      • getOrInitializeLocalHostId

        public static java.util.UUID getOrInitializeLocalHostId()
        Read the host ID from the system keyspace, creating (and storing) one if none exists.
      • setLocalHostId

        public static java.util.UUID setLocalHostId​(java.util.UUID hostId)
        Sets the local host ID explicitly. Should only be called outside of SystemTable when replacing a node.
      • getSchemaVersion

        public static java.util.UUID getSchemaVersion()
        Gets the schema version or null if missing
      • getRack

        public static java.lang.String getRack()
        Gets the stored rack for the local node, or null if none have been set yet.
      • getDatacenter

        public static java.lang.String getDatacenter()
        Gets the stored data center for the local node, or null if none have been set yet.
      • loadPaxosState

        public static PaxosState.Snapshot loadPaxosState​(DecoratedKey partitionKey,
                                                         TableMetadata metadata,
                                                         long nowInSec)
        Load the current paxos state for the table and key NOTE: nowInSec is typically provided as zero, and should not be assumed to be definitive, as the cache may apply different nowInSec filters
      • legacyPaxosTtlSec

        public static int legacyPaxosTtlSec​(TableMetadata metadata)
      • savePaxosProposal

        public static void savePaxosProposal​(Commit proposal)
      • savePaxosCommit

        public static void savePaxosCommit​(Commit commit)
      • savePaxosRepairHistory

        public static void savePaxosRepairHistory​(java.lang.String keyspace,
                                                  java.lang.String table,
                                                  PaxosRepairHistory history,
                                                  boolean flush)
      • flushPaxosRepairHistory

        public static void flushPaxosRepairHistory()
      • loadPaxosRepairHistory

        public static PaxosRepairHistory loadPaxosRepairHistory​(java.lang.String keyspace,
                                                                java.lang.String table)
      • getSSTableReadMeter

        public static RestorableMeter getSSTableReadMeter​(java.lang.String keyspace,
                                                          java.lang.String table,
                                                          SSTableId id)
        Returns a RestorableMeter tracking the average read rate of a particular SSTable, restoring the last-seen rate from values in system.sstable_activity if present.
        Parameters:
        keyspace - the keyspace the sstable belongs to
        table - the table the sstable belongs to
        id - the generation id for the sstable
      • readSSTableActivity

        public static UntypedResultSet readSSTableActivity​(java.lang.String keyspace,
                                                           java.lang.String table,
                                                           SSTableId id)
      • persistSSTableReadMeter

        public static void persistSSTableReadMeter​(java.lang.String keyspace,
                                                   java.lang.String table,
                                                   SSTableId id,
                                                   RestorableMeter meter)
        Writes the current read rates for a given SSTable to system.sstable_activity
      • clearSSTableReadMeter

        public static void clearSSTableReadMeter​(java.lang.String keyspace,
                                                 java.lang.String table,
                                                 SSTableId id)
        Clears persisted read rates from system.sstable_activity for SSTables that have been deleted.
      • updateSizeEstimates

        public static void updateSizeEstimates​(java.lang.String keyspace,
                                               java.lang.String table,
                                               java.util.Map<Range<Token>,​Pair<java.lang.Long,​java.lang.Long>> estimates)
        Writes the current partition count and size estimates into SIZE_ESTIMATES_CF
      • updateTableEstimates

        public static void updateTableEstimates​(java.lang.String keyspace,
                                                java.lang.String table,
                                                java.lang.String type,
                                                java.util.Map<Range<Token>,​Pair<java.lang.Long,​java.lang.Long>> estimates)
        Writes the current partition count and size estimates into table_estimates
      • clearEstimates

        public static void clearEstimates​(java.lang.String keyspace,
                                          java.lang.String table)
        Clears size estimates for a table (on table drop)
      • clearAllEstimates

        public static void clearAllEstimates()
        truncates size_estimates and table_estimates tables
      • updateAvailableRanges

        public static void updateAvailableRanges​(java.lang.String keyspace,
                                                 java.util.Collection<Range<Token>> completedFullRanges,
                                                 java.util.Collection<Range<Token>> completedTransientRanges)
      • getAvailableRanges

        public static SystemKeyspace.AvailableRanges getAvailableRanges​(java.lang.String keyspace,
                                                                        IPartitioner partitioner)
        List of the streamed ranges, where transientness is encoded based on the source, where range was streamed from.
      • resetAvailableStreamedRanges

        public static void resetAvailableStreamedRanges()
      • resetAvailableStreamedRangesForKeyspace

        public static void resetAvailableStreamedRangesForKeyspace​(java.lang.String keyspace)
      • getTransferredRanges

        public static java.util.Map<InetAddressAndPort,​java.util.Set<Range<Token>>> getTransferredRanges​(java.lang.String description,
                                                                                                               java.lang.String keyspace,
                                                                                                               IPartitioner partitioner)
      • snapshotOnVersionChange

        public static void snapshotOnVersionChange()
                                            throws java.io.IOException
        Compare the release version in the system.local table with the one included in the distro. If they don't match, snapshot all tables in the system and schema keyspaces. This is intended to be called at startup to create a backup of the system tables during an upgrade
        Throws:
        java.io.IOException
      • rawRangesToRangeSet

        public static java.util.Set<Range<Token>> rawRangesToRangeSet​(java.util.Set<java.nio.ByteBuffer> rawRanges,
                                                                      IPartitioner partitioner)
      • rangeToBytes

        public static java.nio.ByteBuffer rangeToBytes​(Range<Token> range)
      • writePreparedStatement

        public static void writePreparedStatement​(java.lang.String loggedKeyspace,
                                                  MD5Digest key,
                                                  java.lang.String cql)
      • removePreparedStatement

        public static void removePreparedStatement​(MD5Digest key)
      • resetPreparedStatements

        public static void resetPreparedStatements()
      • loadPreparedStatements

        public static int loadPreparedStatements​(SystemKeyspace.TriFunction<MD5Digest,​java.lang.String,​java.lang.String,​java.lang.Boolean> onLoaded)