Package org.apache.cassandra.schema
Class Schema
- java.lang.Object
-
- org.apache.cassandra.schema.Schema
-
- All Implemented Interfaces:
SchemaProvider
public final class Schema extends java.lang.Object implements SchemaProvider
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSchema.TransformationResult
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clear all KS/CF metadata and reset version.java.util.Optional<Function>findFunction(FunctionName name, java.util.List<AbstractType<?>> argTypes)Find the function with the specified nameColumnFamilyStoregetColumnFamilyStoreInstance(TableId id)java.util.Collection<Function>getFunctions(FunctionName name)Get all function overloads with the specified nameTableMetadataRefgetIndexTableMetadataRef(java.lang.String keyspace, java.lang.String index)KeyspacegetKeyspaceInstance(java.lang.String keyspaceName)Get keyspace instance by nameKeyspaceMetadatagetKeyspaceMetadata(java.lang.String keyspaceName)Get metadata about keyspace by its namejava.util.Set<java.lang.String>getKeyspaces()java.util.List<java.lang.String>getNonLocalStrategyKeyspaces()com.google.common.collect.ImmutableList<java.lang.String>getNonSystemKeyspaces()intgetNumberOfTables()static KeyspaceMetadatagetSystemKeyspaceMetadata()TableMetadatagetTableMetadata(java.lang.String keyspace, java.lang.String table)Given a keyspace name and table name, get the table meta data.TableMetadatagetTableMetadata(Descriptor descriptor)TableMetadatagetTableMetadata(TableId id)TableMetadataRefgetTableMetadataRef(java.lang.String keyspace, java.lang.String table)Given a keyspace name and table/view name, get the table metadata reference.TableMetadataRefgetTableMetadataRef(Descriptor descriptor)TableMetadataRefgetTableMetadataRef(TableId id)Get Table metadata by its identifierjava.lang.Iterable<TableMetadata>getTablesAndViews(java.lang.String keyspaceName)Get metadata about keyspace inner ColumnFamiliesjava.util.List<java.lang.String>getUserKeyspaces()java.util.UUIDgetVersion()ViewMetadatagetView(java.lang.String keyspaceName, java.lang.String viewName)booleanisEmpty()Checks whether the current schema is empty.booleanisSameVersion(java.util.UUID schemaVersion)Checks whether the given schema version is the same as the current local schema.voidload(KeyspaceMetadata ksm)Update (or insert) new keyspace definitionvoidloadFromDisk()load keyspace (keyspace) definitions, but do not initialize the keyspace instances.voidloadFromDisk(boolean updateVersion)Load schema definitions from disk.voidmergeAndAnnounceVersion(java.util.Collection<Mutation> mutations)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)voidreloadSchemaAndAnnounceVersion()KeyspaceremoveKeyspaceInstance(java.lang.String keyspaceName)Remove keyspace from schemavoidsaveSystemKeyspace()Add entries to system_schema.* for the hardcoded system keyspaces See CASSANDRA-16856/16996.java.util.Collection<Mutation>schemaKeyspaceAsMutations()See CASSANDRA-16856/16996.static java.lang.StringschemaVersionToString(java.util.UUID version)Converts the given schema version to a string.Keyspacessnapshot()voidstoreKeyspaceInstance(Keyspace keyspace)Store given Keyspace instance to the schemaSchema.TransformationResulttransform(SchemaTransformation transformation, boolean locally, long now)See CASSANDRA-16856/16996.voidtruncateSchemaKeyspace()See CASSANDRA-16856/16996.voidunregisterListener(SchemaChangeListener listener)voidupdateVersion()Read schema from system keyspace and calculate MD5 digest of every row, resulting digest will be converted into UUID which would act as content-based version of the schema.voidupdateVersionAndAnnounce()TableMetadatavalidateTable(java.lang.String keyspaceName, java.lang.String tableName)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.cassandra.schema.SchemaProvider
getExistingTableMetadata
-
-
-
-
Field Detail
-
instance
public static final Schema instance
-
-
Method Detail
-
saveSystemKeyspace
public void saveSystemKeyspace()
Add entries to system_schema.* for the hardcoded system keyspaces See CASSANDRA-16856/16996. Make sure schema pulls are synchronized to prevent concurrent schema pull/writes
-
truncateSchemaKeyspace
public void truncateSchemaKeyspace()
See CASSANDRA-16856/16996. Make sure schema pulls are synchronized to prevent concurrent schema pull/writes
-
schemaKeyspaceAsMutations
public java.util.Collection<Mutation> schemaKeyspaceAsMutations()
See CASSANDRA-16856/16996. Make sure schema pulls are synchronized to prevent concurrent schema pull/writes
-
getSystemKeyspaceMetadata
public static KeyspaceMetadata getSystemKeyspaceMetadata()
-
loadFromDisk
public void loadFromDisk()
load keyspace (keyspace) definitions, but do not initialize the keyspace instances. Schema version may be updated as the result.
-
loadFromDisk
public void loadFromDisk(boolean updateVersion)
Load schema definitions from disk.- Parameters:
updateVersion- true if schema version needs to be updated
-
load
public void load(KeyspaceMetadata ksm)
Update (or insert) new keyspace definition- Parameters:
ksm- The metadata about keyspace
-
registerListener
public void registerListener(SchemaChangeListener listener)
-
unregisterListener
public void unregisterListener(SchemaChangeListener listener)
-
getKeyspaceInstance
public Keyspace getKeyspaceInstance(java.lang.String keyspaceName)
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
public ColumnFamilyStore getColumnFamilyStoreInstance(TableId id)
-
storeKeyspaceInstance
public void storeKeyspaceInstance(Keyspace keyspace)
Store given Keyspace instance to the schema- Specified by:
storeKeyspaceInstancein interfaceSchemaProvider- Parameters:
keyspace- The Keyspace instance to store- Throws:
java.lang.IllegalArgumentException- if Keyspace is already stored
-
removeKeyspaceInstance
public Keyspace removeKeyspaceInstance(java.lang.String keyspaceName)
Remove keyspace from schema- Parameters:
keyspaceName- The name of the keyspace to remove- Returns:
- removed keyspace instance or null if it wasn't found
-
snapshot
public Keyspaces snapshot()
-
getNumberOfTables
public int getNumberOfTables()
-
getView
public ViewMetadata getView(java.lang.String keyspaceName, java.lang.String viewName)
-
getKeyspaceMetadata
public KeyspaceMetadata getKeyspaceMetadata(java.lang.String keyspaceName)
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
-
getNonSystemKeyspaces
public com.google.common.collect.ImmutableList<java.lang.String> getNonSystemKeyspaces()
- Returns:
- collection of the non-system keyspaces (note that this count as system only the non replicated keyspaces, so keyspace like system_traces which are replicated are actually returned. See getUserKeyspace() below if you don't want those)
-
getNonLocalStrategyKeyspaces
public java.util.List<java.lang.String> getNonLocalStrategyKeyspaces()
- Returns:
- a collection of keyspaces that do not use LocalStrategy for replication
-
getUserKeyspaces
public java.util.List<java.lang.String> getUserKeyspaces()
- Returns:
- collection of the user defined keyspaces
-
getTablesAndViews
public java.lang.Iterable<TableMetadata> getTablesAndViews(java.lang.String keyspaceName)
Get metadata about keyspace inner ColumnFamilies- Parameters:
keyspaceName- The name of the keyspace- Returns:
- metadata about ColumnFamilies the belong to the given keyspace
-
getKeyspaces
public java.util.Set<java.lang.String> getKeyspaces()
- Returns:
- collection of the all keyspace names registered in the system (system and non-system)
-
getTableMetadataRef
public TableMetadataRef getTableMetadataRef(java.lang.String keyspace, java.lang.String table)
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
public TableMetadataRef getIndexTableMetadataRef(java.lang.String keyspace, java.lang.String index)
-
getTableMetadataRef
public TableMetadataRef getTableMetadataRef(TableId id)
Get Table metadata by its identifier- Specified by:
getTableMetadataRefin interfaceSchemaProvider- Parameters:
id- table or view identifier- Returns:
- metadata about Table or View
-
getTableMetadataRef
public TableMetadataRef getTableMetadataRef(Descriptor descriptor)
- Specified by:
getTableMetadataRefin interfaceSchemaProvider
-
getTableMetadata
public TableMetadata getTableMetadata(java.lang.String keyspace, java.lang.String table)
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
public TableMetadata getTableMetadata(TableId id)
- Specified by:
getTableMetadatain interfaceSchemaProvider
-
validateTable
public TableMetadata validateTable(java.lang.String keyspaceName, java.lang.String tableName)
-
getTableMetadata
public TableMetadata getTableMetadata(Descriptor descriptor)
-
getFunctions
public java.util.Collection<Function> getFunctions(FunctionName name)
Get all 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
Functionotherwise
-
findFunction
public java.util.Optional<Function> findFunction(FunctionName name, java.util.List<AbstractType<?>> argTypes)
Find the function with the specified name- Parameters:
name- fully qualified function nameargTypes- function argument types- Returns:
- an empty
Optionalif the keyspace or the function name are not found; a non-empty optional ofFunctionotherwise
-
getVersion
public java.util.UUID getVersion()
- Returns:
- current schema version
-
isSameVersion
public boolean isSameVersion(java.util.UUID schemaVersion)
Checks whether the given schema version is the same as the current local schema.
-
isEmpty
public boolean isEmpty()
Checks whether the current schema is empty.
-
updateVersion
public void updateVersion()
Read schema from system keyspace and calculate MD5 digest of every row, resulting digest will be converted into UUID which would act as content-based version of the schema. See CASSANDRA-16856/16996. Make sure schema pulls are synchronized to prevent concurrent schema pull/writes
-
updateVersionAndAnnounce
public void updateVersionAndAnnounce()
-
clear
public void clear()
Clear all KS/CF metadata and reset version.
-
reloadSchemaAndAnnounceVersion
public void reloadSchemaAndAnnounceVersion()
-
mergeAndAnnounceVersion
public void mergeAndAnnounceVersion(java.util.Collection<Mutation> mutations)
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)- Parameters:
mutations- the schema changes to apply- Throws:
ConfigurationException- If one of metadata attributes has invalid value
-
transform
public Schema.TransformationResult transform(SchemaTransformation transformation, boolean locally, long now) throws java.net.UnknownHostException
See CASSANDRA-16856/16996. Make sure schema pulls are synchronized to prevent concurrent schema pull/writes- Throws:
java.net.UnknownHostException
-
schemaVersionToString
public static java.lang.String schemaVersionToString(java.util.UUID version)
Converts the given schema version to a string. Returnsunknown, ifversionisnullor"(empty)", ifversionrefers to anempty) schema.
-
-