Class Schema

    • 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
      • getKeyspaceInstance

        public Keyspace getKeyspaceInstance​(java.lang.String keyspaceName)
        Get keyspace instance by name
        Specified by:
        getKeyspaceInstance in interface SchemaProvider
        Parameters:
        keyspaceName - The name of the keyspace
        Returns:
        Keyspace object or null if keyspace was not found
      • storeKeyspaceInstance

        public void storeKeyspaceInstance​(Keyspace keyspace)
        Store given Keyspace instance to the schema
        Specified by:
        storeKeyspaceInstance in interface SchemaProvider
        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
      • 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 interface SchemaProvider
        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 interface SchemaProvider
        Returns:
        TableMetadataRef object or null if it wasn't found
      • getIndexTableMetadataRef

        public TableMetadataRef getIndexTableMetadataRef​(java.lang.String keyspace,
                                                         java.lang.String index)
      • 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 interface SchemaProvider
        Parameters:
        keyspace - The keyspace name
        table - The table name
        Returns:
        TableMetadata object or null if it wasn't found
      • validateTable

        public TableMetadata validateTable​(java.lang.String keyspaceName,
                                           java.lang.String tableName)
      • 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 name
        argTypes - function argument types
        Returns:
        an empty Optional if the keyspace or the function name are not found; a non-empty optional of Function 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. Returns unknown, if version is null or "(empty)", if version refers to an empty) schema.