public class Schema extends java.lang.Object implements 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)
).
Modifier and Type | Field and Description |
---|---|
static Schema |
instance |
SchemaUpdateHandler |
updateHandler |
Constructor and Description |
---|
Schema(boolean online,
Keyspaces localKeyspaces,
SchemaUpdateHandler updateHandler) |
Modifier and Type | Method and Description |
---|---|
Keyspaces |
distributedKeyspaces() |
java.util.Optional<Function> |
findFunction(FunctionName name,
java.util.List<AbstractType<?>> argTypes)
Find the function with the specified name
|
ColumnFamilyStore |
getColumnFamilyStoreInstance(TableId id) |
DistributedSchema |
getDistributedSchemaBlocking()
Returns the current keyspaces metadata and version synchronouly.
|
java.util.Collection<Function> |
getFunctions(FunctionName name)
Get all function overloads with the specified name
|
TableMetadataRef |
getIndexTableMetadataRef(java.lang.String keyspace,
java.lang.String index) |
Keyspace |
getKeyspaceInstance(java.lang.String keyspaceName)
Get keyspace instance by name
|
KeyspaceMetadata |
getKeyspaceMetadata(java.lang.String keyspaceName)
Get metadata about keyspace by its name
|
com.google.common.collect.Sets.SetView<java.lang.String> |
getKeyspaces() |
Keyspaces |
getLocalKeyspaces() |
int |
getNumberOfTables() |
java.util.Map<java.util.UUID,java.util.Set<InetAddressAndPort>> |
getOutstandingSchemaVersions() |
TableMetadata |
getTableMetadata(Descriptor descriptor) |
TableMetadata |
getTableMetadata(java.lang.String keyspace,
java.lang.String table)
Given a keyspace name and table name, get the table
meta data.
|
TableMetadata |
getTableMetadata(TableId id) |
TableMetadataRef |
getTableMetadataRef(Descriptor descriptor) |
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(TableId id)
Get Table metadata by its identifier
|
java.lang.Iterable<TableMetadata> |
getTablesAndViews(java.lang.String keyspaceName)
Get metadata about keyspace inner ColumnFamilies
|
com.google.common.collect.Sets.SetView<java.lang.String> |
getUserKeyspaces()
Returns user keyspaces, that is all but
SchemaConstants.LOCAL_SYSTEM_KEYSPACE_NAMES ,
SchemaConstants.REPLICATED_SYSTEM_KEYSPACE_NAMES or virtual keyspaces. |
java.util.UUID |
getVersion()
Returns the current schema version.
|
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.
|
int |
largestGcgs()
Compute the largest gc grace seconds amongst all the tables
|
void |
loadFromDisk()
Load keyspaces definitions from local storage, see
SchemaUpdateHandler.reset(boolean) . |
Keyspace |
maybeAddKeyspaceInstance(java.lang.String keyspaceName,
java.util.function.Supplier<Keyspace> loadFunction) |
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)
|
void |
registerListener(SchemaChangeListener listener) |
void |
reloadSchemaAndAnnounceVersion() |
void |
resetLocalSchema()
Clear all locally stored schema information and fetch schema from another node.
|
void |
startSync() |
SchemaTransformation.SchemaTransformationResult |
transform(SchemaTransformation transformation) |
SchemaTransformation.SchemaTransformationResult |
transform(SchemaTransformation transformation,
boolean local) |
void |
unregisterListener(SchemaChangeListener listener) |
TableMetadata |
validateTable(java.lang.String keyspaceName,
java.lang.String tableName) |
boolean |
waitUntilReady(java.time.Duration timeout) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getExistingTableMetadata
public static final Schema instance
public final SchemaUpdateHandler updateHandler
public Schema(boolean online, Keyspaces localKeyspaces, SchemaUpdateHandler updateHandler)
public void startSync()
public boolean waitUntilReady(java.time.Duration timeout)
public void loadFromDisk()
SchemaUpdateHandler.reset(boolean)
.public void registerListener(SchemaChangeListener listener)
public void unregisterListener(SchemaChangeListener listener)
public Keyspace getKeyspaceInstance(java.lang.String keyspaceName)
getKeyspaceInstance
in interface SchemaProvider
keyspaceName
- The name of the keyspacepublic ColumnFamilyStore getColumnFamilyStoreInstance(TableId id)
public Keyspace maybeAddKeyspaceInstance(java.lang.String keyspaceName, java.util.function.Supplier<Keyspace> loadFunction)
maybeAddKeyspaceInstance
in interface SchemaProvider
public Keyspaces distributedKeyspaces()
public int largestGcgs()
public int getNumberOfTables()
public ViewMetadata getView(java.lang.String keyspaceName, java.lang.String viewName)
public KeyspaceMetadata getKeyspaceMetadata(java.lang.String keyspaceName)
getKeyspaceMetadata
in interface SchemaProvider
keyspaceName
- The name of the keyspacepublic com.google.common.collect.Sets.SetView<java.lang.String> getUserKeyspaces()
SchemaConstants.LOCAL_SYSTEM_KEYSPACE_NAMES
,
SchemaConstants.REPLICATED_SYSTEM_KEYSPACE_NAMES
or virtual keyspaces.public java.lang.Iterable<TableMetadata> getTablesAndViews(java.lang.String keyspaceName)
keyspaceName
- The name of the keyspacepublic com.google.common.collect.Sets.SetView<java.lang.String> getKeyspaces()
public Keyspaces getLocalKeyspaces()
public TableMetadataRef getTableMetadataRef(java.lang.String keyspace, java.lang.String table)
getTableMetadataRef
in interface SchemaProvider
public TableMetadataRef getIndexTableMetadataRef(java.lang.String keyspace, java.lang.String index)
public TableMetadataRef getTableMetadataRef(TableId id)
getTableMetadataRef
in interface SchemaProvider
id
- table or view identifierpublic TableMetadataRef getTableMetadataRef(Descriptor descriptor)
getTableMetadataRef
in interface SchemaProvider
public TableMetadata getTableMetadata(java.lang.String keyspace, java.lang.String table)
getTableMetadata
in interface SchemaProvider
keyspace
- The keyspace nametable
- The table namepublic TableMetadata getTableMetadata(TableId id)
getTableMetadata
in interface SchemaProvider
public TableMetadata validateTable(java.lang.String keyspaceName, java.lang.String tableName)
public TableMetadata getTableMetadata(Descriptor descriptor)
public java.util.Collection<Function> getFunctions(FunctionName name)
name
- fully qualified function nameFunction
otherwisepublic java.util.Optional<Function> findFunction(FunctionName name, java.util.List<AbstractType<?>> argTypes)
name
- fully qualified function nameargTypes
- function argument typesOptional
if the keyspace or the function name are not found;
a non-empty optional of Function
otherwisepublic java.util.UUID getVersion()
This method should be used only internally by Schema
or SchemaUpdateHandler
implementations.
Please use getDistributedSchemaBlocking()
to get schema version consistently in other cases.
public DistributedSchema getDistributedSchemaBlocking()
public boolean isSameVersion(java.util.UUID schemaVersion)
getVersion()
.public boolean isEmpty()
getVersion()
.public void reloadSchemaAndAnnounceVersion()
public void mergeAndUpdateVersion(SchemaTransformation.SchemaTransformationResult result, boolean dropData)
ConfigurationException
- If one of metadata attributes has invalid valuepublic SchemaTransformation.SchemaTransformationResult transform(SchemaTransformation transformation)
public SchemaTransformation.SchemaTransformationResult transform(SchemaTransformation transformation, boolean local)
public void resetLocalSchema()
public java.util.Map<java.util.UUID,java.util.Set<InetAddressAndPort>> getOutstandingSchemaVersions()
Copyright © 2009- The Apache Software Foundation