org.apache.cassandra.db
Class DefsTable
java.lang.Object
org.apache.cassandra.db.DefsTable
public class DefsTable
- extends java.lang.Object
SCHEMA_{KEYSPACES, COLUMNFAMILIES, COLUMNS}_CF are used to store Keyspace/ColumnFamily attributes to make schema
load/distribution easy, it replaces old mechanism when local migrations where serialized, stored in system.Migrations
and used for schema distribution.
SCHEMA_KEYSPACES_CF layout:
ascii => json_serialized_value
...
Where is a name of keyspace e.g. "ks".
SCHEMA_COLUMNFAMILIES_CF layout:
composite(ascii, ascii) => json_serialized_value
Where is a name of keyspace e.g. "ks"., first component of the column name is name of the ColumnFamily, last
component is the name of the ColumnFamily attribute.
SCHEMA_COLUMNS_CF layout:
composite(ascii, ascii, ascii) => json_serialized value
Where is a name of keyspace e.g. "ks".
Column names where made composite to support 3-level nesting which represents following structure:
"ColumnFamily name":"column name":"column attribute" => "value"
Example of schema (using CLI):
schema_keyspaces
----------------
RowKey: ks
=> (column=durable_writes, value=true, timestamp=1327061028312185000)
=> (column=name, value="ks", timestamp=1327061028312185000)
=> (column=replication_factor, value=0, timestamp=1327061028312185000)
=> (column=strategy_class, value="org.apache.cassandra.locator.NetworkTopologyStrategy", timestamp=1327061028312185000)
=> (column=strategy_options, value={"datacenter1":"1"}, timestamp=1327061028312185000)
schema_columnfamilies
---------------------
RowKey: ks
=> (column=cf:bloom_filter_fp_chance, value=0.0, timestamp=1327061105833119000)
=> (column=cf:caching, value="NONE", timestamp=1327061105833119000)
=> (column=cf:column_type, value="Standard", timestamp=1327061105833119000)
=> (column=cf:comment, value="ColumnFamily", timestamp=1327061105833119000)
=> (column=cf:default_validation_class, value="org.apache.cassandra.db.marshal.BytesType", timestamp=1327061105833119000)
=> (column=cf:gc_grace_seconds, value=864000, timestamp=1327061105833119000)
=> (column=cf:id, value=1000, timestamp=1327061105833119000)
=> (column=cf:key_alias, value="S0VZ", timestamp=1327061105833119000)
... part of the output omitted.
schema_columns
--------------
RowKey: ks
=> (column=cf:c:index_name, value=null, timestamp=1327061105833119000)
=> (column=cf:c:index_options, value=null, timestamp=1327061105833119000)
=> (column=cf:c:index_type, value=null, timestamp=1327061105833119000)
=> (column=cf:c:name, value="aGVsbG8=", timestamp=1327061105833119000)
=> (column=cf:c:validation_class, value="org.apache.cassandra.db.marshal.AsciiType", timestamp=1327061105833119000)
Method Summary |
static
<T extends org.apache.avro.specific.SpecificRecord>
T |
|
deserializeAvro(org.apache.avro.Schema writer,
java.nio.ByteBuffer bytes,
T ob)
Deserialize a single object based on the given Schema. |
static void |
fixSchemaNanoTimestamps()
|
static java.util.Collection<KSMetaData> |
loadFromStorage(java.util.UUID version)
Loads a version of keyspace definitions from storage (using old SCHEMA_CF as a data source)
Note: If definitions where found in SCHEMA_CF this method would load them into new schema handling table KEYSPACE_CF |
static java.util.Collection<KSMetaData> |
loadFromTable()
Load keyspace definitions for the system keyspace (system.SCHEMA_KEYSPACES_CF) |
static void |
mergeSchema(java.util.Collection<RowMutation> mutations)
Merge remote schema in form of row mutations with local and mutate ks/cf metadata objects
(which also involves fs operations on add/drop ks/cf) |
static void |
save(java.util.Collection<KSMetaData> keyspaces)
|
static java.nio.ByteBuffer |
searchComposite(java.lang.String name,
boolean start)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DEFINITION_SCHEMA_COLUMN_NAME
public static final java.nio.ByteBuffer DEFINITION_SCHEMA_COLUMN_NAME
OLD_MIGRATIONS_CF
public static final java.lang.String OLD_MIGRATIONS_CF
- See Also:
- Constant Field Values
OLD_SCHEMA_CF
public static final java.lang.String OLD_SCHEMA_CF
- See Also:
- Constant Field Values
DefsTable
public DefsTable()
save
public static void save(java.util.Collection<KSMetaData> keyspaces)
loadFromTable
public static java.util.Collection<KSMetaData> loadFromTable()
- Load keyspace definitions for the system keyspace (system.SCHEMA_KEYSPACES_CF)
- Returns:
- Collection of found keyspace definitions
fixSchemaNanoTimestamps
public static void fixSchemaNanoTimestamps()
searchComposite
public static java.nio.ByteBuffer searchComposite(java.lang.String name,
boolean start)
loadFromStorage
public static java.util.Collection<KSMetaData> loadFromStorage(java.util.UUID version)
throws java.io.IOException
- Loads a version of keyspace definitions from storage (using old SCHEMA_CF as a data source)
Note: If definitions where found in SCHEMA_CF this method would load them into new schema handling table KEYSPACE_CF
- Parameters:
version
- The version of the latest migration.
- Returns:
- Collection of found keyspace definitions
- Throws:
java.io.IOException
- if failed to read SCHEMA_CF or failed to deserialize Avro schema
mergeSchema
public static void mergeSchema(java.util.Collection<RowMutation> mutations)
throws ConfigurationException,
java.io.IOException
- Merge remote schema in form of row 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
java.io.IOException
- If data was corrupted during transportation or failed to apply fs operations
deserializeAvro
public static <T extends org.apache.avro.specific.SpecificRecord> T deserializeAvro(org.apache.avro.Schema writer,
java.nio.ByteBuffer bytes,
T ob)
throws java.io.IOException
- Deserialize a single object based on the given Schema.
- Parameters:
writer
- writer's schemabytes
- Array to deserialize fromob
- An empty object to deserialize into (must not be null).
- Returns:
- serialized Avro object
- Throws:
java.io.IOException
- if deserialization failed
Copyright © 2012 The Apache Software Foundation