Class Schema
- All Implemented Interfaces:
SchemaProvider
This class should be the only entity used to query and manage schema. Internal details should not be access in production code (would be great if they were not accessed in the test code as well).
TL;DR: All modifications are made using the implementation of SchemaUpdateHandler obtained from the provided
factory. After each modification, the internally managed table metadata refs and keyspaces instances are updated and
notifications are sent to the registered listeners.
When the schema change is applied by the update handler (regardless it is initiated locally or received from outside),
the registered callback is executed which performs the remaining updates for tables metadata refs and keyspace
instances (see mergeAndUpdateVersion(SchemaTransformationResult, boolean)).
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSchema(boolean online, Keyspaces localKeyspaces, SchemaUpdateHandler updateHandler) -
Method Summary
Modifier and TypeMethodDescriptionfindUserFunction(FunctionName name, List<AbstractType<?>> argTypes) Find the function with the specified name and arguments.ReturnsColumnFamilyStoreby the table identifier.Returns the current keyspaces metadata and version synchronouly.getIndexTableMetadataRef(String keyspace, String index) getKeyspaceInstance(String keyspaceName) Get keyspace instance by namegetKeyspaceMetadata(String keyspaceName) Get metadata about keyspace by its namecom.google.common.collect.Sets.SetView<String>intgetTableMetadata(String keyspace, String table) Given a keyspace name and table name, get the table meta data.getTableMetadata(Descriptor descriptor) getTableMetadataRef(String keyspace, String table) Given a keyspace name and table/view name, get the table metadata reference.getTableMetadataRef(Descriptor descriptor) Get Table metadata by its identifiergetTablesAndViews(String keyspaceName) Get metadata about keyspace inner ColumnFamiliesgetUserFunctions(FunctionName name) Get all user-defined function overloads with the specified name.com.google.common.collect.Sets.SetView<String>Returns user keyspaces, that is all butSchemaConstants.LOCAL_SYSTEM_KEYSPACE_NAMES,SchemaConstants.REPLICATED_SYSTEM_KEYSPACE_NAMESor virtual keyspaces.Returns the current schema version.booleanisEmpty()Checks whether the current schema is empty.booleanisSameVersion(UUID schemaVersion) Checks whether the given schema version is the same as the current local schema.intCompute the largest gc grace seconds amongst all the tablesvoidLoad keyspaces definitions from local storage, seeSchemaUpdateHandler.reset(boolean).maybeAddKeyspaceInstance(String keyspaceName, Supplier<Keyspace> loadFunction) voidmergeAndUpdateVersion(SchemaTransformation.SchemaTransformationResult result, boolean dropData) Merge remote schema in form of mutations with local and mutate ks/cf metadata objects (which also involves fs operations on add/drop ks/cf)voidregisterListener(SchemaChangeListener listener) voidvoidClear all locally stored schema information and fetch schema from another node.voidtransform(SchemaTransformation transformation) transform(SchemaTransformation transformation, boolean local) voidunregisterListener(SchemaChangeListener listener) validateTable(String keyspaceName, String tableName) booleanwaitUntilReady(Duration timeout) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.cassandra.schema.SchemaProvider
getExistingTableMetadata
-
Field Details
-
instance
-
updateHandler
-
-
Constructor Details
-
Schema
-
-
Method Details
-
startSync
public void startSync() -
waitUntilReady
-
loadFromDisk
public void loadFromDisk()Load keyspaces definitions from local storage, seeSchemaUpdateHandler.reset(boolean). -
registerListener
-
unregisterListener
-
getKeyspaceInstance
Get keyspace instance by name- Specified by:
getKeyspaceInstancein interfaceSchemaProvider- Parameters:
keyspaceName- The name of the keyspace- Returns:
- Keyspace object or null if keyspace was not found
-
getColumnFamilyStoreInstance
ReturnsColumnFamilyStoreby the table identifier. Note that though, if called forTableMetadata.id, when metadata points to a secondary index table, theTableMetadata.iddenotes the identifier of the main table, not the index table. Thus, this method will return CFS of the main table rather than, probably expected, CFS for the index backing table. -
maybeAddKeyspaceInstance
- Specified by:
maybeAddKeyspaceInstancein interfaceSchemaProvider
-
distributedKeyspaces
-
largestGcgs
public int largestGcgs()Compute the largest gc grace seconds amongst all the tables- Returns:
- the largest gcgs.
-
getNumberOfTables
public int getNumberOfTables() -
getView
-
getKeyspaceMetadata
Get metadata about keyspace by its name- Specified by:
getKeyspaceMetadatain interfaceSchemaProvider- Parameters:
keyspaceName- The name of the keyspace- Returns:
- The keyspace metadata or null if it wasn't found
-
getUserKeyspaces
Returns user keyspaces, that is all butSchemaConstants.LOCAL_SYSTEM_KEYSPACE_NAMES,SchemaConstants.REPLICATED_SYSTEM_KEYSPACE_NAMESor virtual keyspaces. -
getTablesAndViews
Get metadata about keyspace inner ColumnFamilies- Parameters:
keyspaceName- The name of the keyspace- Returns:
- metadata about ColumnFamilies the belong to the given keyspace
-
getKeyspaces
- Returns:
- a set of local and distributed keyspace names; it does not include virtual keyspaces
-
getLocalKeyspaces
-
getTableMetadataRef
Given a keyspace name and table/view name, get the table metadata reference. If the keyspace name or table/view name is not present this method returns null.- Specified by:
getTableMetadataRefin interfaceSchemaProvider- Returns:
- TableMetadataRef object or null if it wasn't found
-
getIndexTableMetadataRef
-
getTableMetadataRef
Get Table metadata by its identifier- Specified by:
getTableMetadataRefin interfaceSchemaProvider- Parameters:
id- table or view identifier- Returns:
- metadata about Table or View
-
getTableMetadataRef
- Specified by:
getTableMetadataRefin interfaceSchemaProvider
-
getTableMetadata
Given a keyspace name and table name, get the table meta data. If the keyspace name or table name is not valid this function returns null.- Specified by:
getTableMetadatain interfaceSchemaProvider- Parameters:
keyspace- The keyspace nametable- The table name- Returns:
- TableMetadata object or null if it wasn't found
-
getTableMetadata
- Specified by:
getTableMetadatain interfaceSchemaProvider
-
validateTable
-
getTableMetadata
-
getUserFunctions
Get all user-defined function overloads with the specified name.- Parameters:
name- fully qualified function name- Returns:
- an empty list if the keyspace or the function name are not found;
a non-empty collection of
UserFunctionotherwise
-
findUserFunction
Find the function with the specified name and arguments. -
getVersion
Returns the current schema version. Although, if the schema is being updated while the method was called, it can return a stale version which does not correspond to the current keyspaces metadata. It is because the schema version is unknown for the partially applied changes and is updated after the entire schema change is completed.This method should be used only internally by
SchemaorSchemaUpdateHandlerimplementations. Please usegetDistributedSchemaBlocking()to get schema version consistently in other cases. -
getDistributedSchemaBlocking
Returns the current keyspaces metadata and version synchronouly. If the schema is in the middle of a multistep transformation, the method blocks until the update is completed. -
isSameVersion
Checks whether the given schema version is the same as the current local schema. Note that this method is non-blocking and may use a stale schema version for comparison - seegetVersion(). -
isEmpty
public boolean isEmpty()Checks whether the current schema is empty. Note that this method is non-blocking and may use a stale schema version for comparison - seegetVersion(). -
reloadSchemaAndAnnounceVersion
public void reloadSchemaAndAnnounceVersion() -
mergeAndUpdateVersion
public void mergeAndUpdateVersion(SchemaTransformation.SchemaTransformationResult result, boolean dropData) Merge remote schema in form of mutations with local and mutate ks/cf metadata objects (which also involves fs operations on add/drop ks/cf)- Throws:
ConfigurationException- If one of metadata attributes has invalid value
-
transform
public SchemaTransformation.SchemaTransformationResult transform(SchemaTransformation transformation) -
transform
public SchemaTransformation.SchemaTransformationResult transform(SchemaTransformation transformation, boolean local) -
resetLocalSchema
public void resetLocalSchema()Clear all locally stored schema information and fetch schema from another node. Called by user (via JMX) who wants to get rid of schema disagreement. -
getOutstandingSchemaVersions
-