Package org.apache.cassandra.db
Class SystemKeyspace
- java.lang.Object
-
- org.apache.cassandra.db.SystemKeyspace
-
public final class SystemKeyspace extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SystemKeyspace.AvailableRanges
static class
SystemKeyspace.BootstrapState
static interface
SystemKeyspace.TriFunction<A,B,C,D>
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
AVAILABLE_RANGES_V2
static TableMetadata
Batches
static java.lang.String
BATCHES
static java.lang.String
BUILT_INDEXES
static java.lang.String
BUILT_VIEWS
static java.lang.String
COMPACTION_HISTORY
static CassandraVersion
CURRENT_VERSION
static java.lang.String
LEGACY_AVAILABLE_RANGES
Deprecated.static java.lang.String
LEGACY_PEER_EVENTS
Deprecated.static java.lang.String
LEGACY_PEERS
Deprecated.static java.lang.String
LEGACY_SIZE_ESTIMATES
Deprecated.static java.lang.String
LEGACY_TRANSFERRED_RANGES
Deprecated.static java.lang.String
LOCAL
static CassandraVersion
NULL_VERSION
static java.lang.String
PAXOS
static java.lang.String
PEER_EVENTS_V2
static java.lang.String
PEERS_V2
static java.lang.String
PREPARED_STATEMENTS
static java.lang.String
REPAIRS
static java.lang.String
SSTABLE_ACTIVITY
static java.lang.String
TABLE_ESTIMATES
static java.lang.String
TABLE_ESTIMATES_TYPE_LOCAL_PRIMARY
static java.lang.String
TABLE_ESTIMATES_TYPE_PRIMARY
static 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.static java.lang.String
TRANSFERRED_RANGES_V2
static CassandraVersion
UNREADABLE_VERSION
static java.lang.String
VIEW_BUILDS_IN_PROGRESS
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
bootstrapComplete()
static boolean
bootstrapInProgress()
static void
checkHealth()
One of three things will happen if you try to read the system keyspace: 1.static void
clearAllEstimates()
truncates size_estimates and table_estimates tablesstatic void
clearEstimates(java.lang.String keyspace, java.lang.String table)
Clears size estimates for a table (on table drop)static void
clearSSTableReadMeter(java.lang.String keyspace, java.lang.String table, int generation)
Clears persisted read rates from system.sstable_activity for SSTables that have been deleted.static void
finishStartup()
static void
finishViewBuildStatus(java.lang.String ksname, java.lang.String viewName)
static void
forceBlockingFlush(java.lang.String... cfnames)
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.static SystemKeyspace.BootstrapState
getBootstrapState()
static java.util.List<java.lang.String>
getBuiltIndexes(java.lang.String keyspaceName, java.util.Set<java.lang.String> indexNames)
static javax.management.openmbean.TabularData
getCompactionHistory()
static java.lang.String
getDatacenter()
Gets the stored data center for the local node, or null if none have been set yet.static java.util.UUID
getLocalHostId()
Read the host ID from the system keyspace.static java.util.UUID
getOrInitializeLocalHostId()
Read the host ID from the system keyspace, creating (and storing) one if none exists.static InetAddressAndPort
getPreferredIP(InetAddressAndPort ep)
Get preferred IP for given endpoint if it is known.static java.lang.String
getRack()
Gets the stored rack for the local node, or null if none have been set yet.static CassandraVersion
getReleaseVersion(InetAddressAndPort ep)
Get release version for given endpoint.static java.util.Collection<Token>
getSavedTokens()
static RestorableMeter
getSSTableReadMeter(java.lang.String keyspace, java.lang.String table, int generation)
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.static java.util.Map<InetAddressAndPort,java.util.Set<Range<Token>>>
getTransferredRanges(java.lang.String description, java.lang.String keyspace, IPartitioner partitioner)
static long
getTruncatedAt(TableId id)
static CommitLogPosition
getTruncatedPosition(TableId id)
static java.util.Map<Range<Token>,Pair<Token,java.lang.Long>>
getViewBuildStatus(java.lang.String ksname, java.lang.String viewName)
static int
incrementAndGetGeneration()
static boolean
isIndexBuilt(java.lang.String keyspaceName, java.lang.String indexName)
static boolean
isViewBuilt(java.lang.String keyspaceName, java.lang.String viewName)
static boolean
isViewStatusReplicated(java.lang.String keyspaceName, java.lang.String viewName)
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 infostatic java.util.Map<InetAddressAndPort,java.util.UUID>
loadHostIds()
Return a map of store host_ids to IP addressesstatic PaxosState
loadPaxosState(DecoratedKey key, TableMetadata metadata, int nowInSec)
static int
loadPreparedStatement(MD5Digest digest, SystemKeyspace.TriFunction<MD5Digest,java.lang.String,java.lang.String,java.lang.Boolean> onLoaded)
static int
loadPreparedStatements(SystemKeyspace.TriFunction<MD5Digest,java.lang.String,java.lang.String,java.lang.Boolean> onLoaded)
static com.google.common.collect.SetMultimap<InetAddressAndPort,Token>
loadTokens()
Return a map of stored tokens to IP addressesstatic KeyspaceMetadata
metadata()
static int
paxosTtlSec(TableMetadata metadata)
static void
persistLocalMetadata()
static void
persistSSTableReadMeter(java.lang.String keyspace, java.lang.String table, int generation, RestorableMeter meter)
Writes the current read rates for a given SSTable to system.sstable_activitystatic java.util.Set<Range<Token>>
rawRangesToRangeSet(java.util.Set<java.nio.ByteBuffer> rawRanges, IPartitioner partitioner)
static void
removeEndpoint(InetAddressAndPort ep)
Remove stored tokens being used by another nodestatic void
removePreparedStatement(MD5Digest key)
static void
removeTruncationRecord(TableId id)
This method is used to remove information about truncation time for specified column familystatic void
resetAvailableRanges()
static void
resetPreparedStatements()
static void
savePaxosCommit(Commit commit)
static void
savePaxosPromise(Commit promise)
static void
savePaxosProposal(Commit proposal)
static void
saveTruncationRecord(ColumnFamilyStore cfs, long truncatedAt, CommitLogPosition position)
static void
setBootstrapState(SystemKeyspace.BootstrapState state)
static void
setIndexBuilt(java.lang.String keyspaceName, java.lang.String indexName)
static void
setIndexRemoved(java.lang.String keyspaceName, java.lang.String indexName)
static java.util.UUID
setLocalHostId(java.util.UUID hostId)
Sets the local host ID explicitly.static void
setViewBuilt(java.lang.String keyspaceName, java.lang.String viewName, boolean replicated)
static void
setViewBuiltReplicated(java.lang.String ksname, java.lang.String viewName)
static void
setViewRemoved(java.lang.String keyspaceName, java.lang.String viewName)
static void
snapshotOnVersionChange()
Compare the release version in the system.local table with the one included in the distro.static void
updateAvailableRanges(java.lang.String keyspace, java.util.Collection<Range<Token>> completedFullRanges, java.util.Collection<Range<Token>> completedTransientRanges)
static void
updateCompactionHistory(java.lang.String ksname, java.lang.String cfname, long compactedAt, long bytesIn, long bytesOut, java.util.Map<java.lang.Integer,java.lang.Long> rowsMerged)
static void
updateHintsDropped(InetAddressAndPort ep, java.util.UUID timePeriod, int value)
static void
updatePeerInfo(InetAddressAndPort ep, java.lang.String columnName, java.lang.Object value)
static void
updatePeerNativeAddress(InetAddressAndPort ep, InetAddressAndPort address)
static boolean
updatePreferredIP(InetAddressAndPort ep, InetAddressAndPort preferred_ip)
static void
updateSchemaVersion(java.util.UUID version)
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_CFstatic 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_estimatesstatic void
updateTokens(java.util.Collection<Token> tokens)
This method is used to update the System Keyspace with the new tokens for this nodestatic void
updateTokens(InetAddressAndPort ep, java.util.Collection<Token> tokens)
Record tokens being used by another nodestatic void
updateTransferredRanges(StreamOperation streamOperation, InetAddressAndPort peer, java.lang.String keyspace, java.util.Collection<Range<Token>> streamedRanges)
static void
updateViewBuildStatus(java.lang.String ksname, java.lang.String viewName, Range<Token> range, Token lastToken, long keysBuilt)
static boolean
wasDecommissioned()
static void
writePreparedStatement(java.lang.String loggedKeyspace, MD5Digest key, java.lang.String cql)
-
-
-
Field Detail
-
UNREADABLE_VERSION
public static final CassandraVersion UNREADABLE_VERSION
-
NULL_VERSION
public static final CassandraVersion NULL_VERSION
-
CURRENT_VERSION
public static final CassandraVersion CURRENT_VERSION
-
BATCHES
public static final java.lang.String BATCHES
- See Also:
- Constant Field Values
-
PAXOS
public static final java.lang.String PAXOS
- See Also:
- Constant Field Values
-
BUILT_INDEXES
public static final java.lang.String BUILT_INDEXES
- See Also:
- Constant Field Values
-
LOCAL
public static final java.lang.String LOCAL
- See Also:
- Constant Field Values
-
PEERS_V2
public static final java.lang.String PEERS_V2
- See Also:
- Constant Field Values
-
PEER_EVENTS_V2
public static final java.lang.String PEER_EVENTS_V2
- See Also:
- Constant Field Values
-
COMPACTION_HISTORY
public static final java.lang.String COMPACTION_HISTORY
- See Also:
- Constant Field Values
-
SSTABLE_ACTIVITY
public static final java.lang.String SSTABLE_ACTIVITY
- See Also:
- Constant Field Values
-
TABLE_ESTIMATES
public static final java.lang.String TABLE_ESTIMATES
- 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
-
BUILT_VIEWS
public static final java.lang.String BUILT_VIEWS
- See Also:
- Constant Field Values
-
PREPARED_STATEMENTS
public static final java.lang.String PREPARED_STATEMENTS
- See Also:
- Constant Field Values
-
REPAIRS
public static final java.lang.String REPAIRS
- 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 public static final java.lang.String LEGACY_PEERS
Deprecated.- See Also:
- Constant Field Values
-
LEGACY_PEER_EVENTS
@Deprecated public static final java.lang.String LEGACY_PEER_EVENTS
Deprecated.- See Also:
- Constant Field Values
-
LEGACY_TRANSFERRED_RANGES
@Deprecated public static final java.lang.String LEGACY_TRANSFERRED_RANGES
Deprecated.- See Also:
- Constant Field Values
-
LEGACY_AVAILABLE_RANGES
@Deprecated public static final java.lang.String LEGACY_AVAILABLE_RANGES
Deprecated.- See Also:
- Constant Field Values
-
LEGACY_SIZE_ESTIMATES
@Deprecated public static final java.lang.String LEGACY_SIZE_ESTIMATES
Deprecated.- See Also:
- Constant Field Values
-
Batches
public static final TableMetadata Batches
-
-
Method Detail
-
metadata
public static KeyspaceMetadata metadata()
-
finishStartup
public static void finishStartup()
-
persistLocalMetadata
public static void persistLocalMetadata()
-
updateCompactionHistory
public static void updateCompactionHistory(java.lang.String ksname, java.lang.String cfname, long compactedAt, long bytesIn, long bytesOut, java.util.Map<java.lang.Integer,java.lang.Long> rowsMerged)
-
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)
-
saveTruncationRecord
public static void saveTruncationRecord(ColumnFamilyStore cfs, long truncatedAt, CommitLogPosition position)
-
removeTruncationRecord
public static void removeTruncationRecord(TableId id)
This method is used to remove information about truncation time for specified column family
-
getTruncatedPosition
public static CommitLogPosition getTruncatedPosition(TableId id)
-
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
-
updatePreferredIP
public static boolean updatePreferredIP(InetAddressAndPort ep, InetAddressAndPort preferred_ip)
-
updatePeerInfo
public static void updatePeerInfo(InetAddressAndPort ep, java.lang.String columnName, java.lang.Object value)
-
updatePeerNativeAddress
public static void updatePeerNativeAddress(InetAddressAndPort ep, InetAddressAndPort address)
-
updateHintsDropped
public static void updateHintsDropped(InetAddressAndPort ep, java.util.UUID timePeriod, int value)
-
updateSchemaVersion
public static void updateSchemaVersion(java.util.UUID version)
-
removeEndpoint
public static void removeEndpoint(InetAddressAndPort 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()
-
getBootstrapState
public static SystemKeyspace.BootstrapState getBootstrapState()
-
bootstrapComplete
public static boolean bootstrapComplete()
-
bootstrapInProgress
public static boolean bootstrapInProgress()
-
wasDecommissioned
public static boolean wasDecommissioned()
-
setBootstrapState
public static void setBootstrapState(SystemKeyspace.BootstrapState state)
-
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.
-
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 loadPaxosState(DecoratedKey key, TableMetadata metadata, int nowInSec)
-
savePaxosPromise
public static void savePaxosPromise(Commit promise)
-
savePaxosProposal
public static void savePaxosProposal(Commit proposal)
-
paxosTtlSec
public static int paxosTtlSec(TableMetadata metadata)
-
savePaxosCommit
public static void savePaxosCommit(Commit commit)
-
getSSTableReadMeter
public static RestorableMeter getSSTableReadMeter(java.lang.String keyspace, java.lang.String table, int generation)
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 totable
- the table the sstable belongs togeneration
- the generation number for the sstable
-
persistSSTableReadMeter
public static void persistSSTableReadMeter(java.lang.String keyspace, java.lang.String table, int generation, 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, int generation)
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.
-
resetAvailableRanges
public static void resetAvailableRanges()
-
updateTransferredRanges
public static void updateTransferredRanges(StreamOperation streamOperation, InetAddressAndPort peer, java.lang.String keyspace, java.util.Collection<Range<Token>> streamedRanges)
-
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)
-
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)
-
loadPreparedStatement
public static int loadPreparedStatement(MD5Digest digest, SystemKeyspace.TriFunction<MD5Digest,java.lang.String,java.lang.String,java.lang.Boolean> onLoaded)
-
-