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 class
Schema.TransformationResult
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
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 nameColumnFamilyStore
getColumnFamilyStoreInstance(TableId id)
java.util.Collection<Function>
getFunctions(FunctionName name)
Get all function overloads with the specified nameTableMetadataRef
getIndexTableMetadataRef(java.lang.String keyspace, java.lang.String index)
Keyspace
getKeyspaceInstance(java.lang.String keyspaceName)
Get keyspace instance by nameKeyspaceMetadata
getKeyspaceMetadata(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()
int
getNumberOfTables()
static KeyspaceMetadata
getSystemKeyspaceMetadata()
TableMetadata
getTableMetadata(java.lang.String keyspace, java.lang.String table)
Given a keyspace name and table name, get the table meta data.TableMetadata
getTableMetadata(Descriptor descriptor)
TableMetadata
getTableMetadata(TableId id)
TableMetadataRef
getTableMetadataRef(java.lang.String keyspace, java.lang.String table)
Given a keyspace name and table/view name, get the table metadata reference.TableMetadataRef
getTableMetadataRef(Descriptor descriptor)
TableMetadataRef
getTableMetadataRef(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.UUID
getVersion()
ViewMetadata
getView(java.lang.String keyspaceName, java.lang.String viewName)
boolean
isEmpty()
Checks whether the current schema is empty.boolean
isSameVersion(java.util.UUID schemaVersion)
Checks whether the given schema version is the same as the current local schema.void
load(KeyspaceMetadata ksm)
Update (or insert) new keyspace definitionvoid
loadFromDisk()
load keyspace (keyspace) definitions, but do not initialize the keyspace instances.void
loadFromDisk(boolean updateVersion)
Load schema definitions from disk.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)void
registerListener(SchemaChangeListener listener)
void
reloadSchemaAndAnnounceVersion()
Keyspace
removeKeyspaceInstance(java.lang.String keyspaceName)
Remove keyspace from schemavoid
saveSystemKeyspace()
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.String
schemaVersionToString(java.util.UUID version)
Converts the given schema version to a string.Keyspaces
snapshot()
void
storeKeyspaceInstance(Keyspace keyspace)
Store given Keyspace instance to the schemaSchema.TransformationResult
transform(SchemaTransformation transformation, boolean locally, long now)
See CASSANDRA-16856/16996.void
truncateSchemaKeyspace()
See CASSANDRA-16856/16996.void
unregisterListener(SchemaChangeListener listener)
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.void
updateVersionAndAnnounce()
TableMetadata
validateTable(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:
getKeyspaceInstance
in 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:
storeKeyspaceInstance
in 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:
getKeyspaceMetadata
in 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:
getTableMetadataRef
in 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:
getTableMetadataRef
in interfaceSchemaProvider
- Parameters:
id
- table or view identifier- Returns:
- metadata about Table or View
-
getTableMetadataRef
public TableMetadataRef getTableMetadataRef(Descriptor descriptor)
- Specified by:
getTableMetadataRef
in 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:
getTableMetadata
in 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:
getTableMetadata
in 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
Function
otherwise
-
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
Optional
if the keyspace or the function name are not found; a non-empty optional ofFunction
otherwise
-
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
, ifversion
isnull
or"(empty)"
, ifversion
refers to anempty) schema.
-
-