org.apache.cassandra.db.migration
Class Migration

java.lang.Object
  extended by org.apache.cassandra.db.migration.Migration
Direct Known Subclasses:
AddColumnFamily, AddKeyspace, DropColumnFamily, DropKeyspace, RenameColumnFamily, RenameKeyspace

public abstract class Migration
extends java.lang.Object

A migration represents a single metadata mutation (cf dropped, added, etc.). Migrations can be applied locally, or serialized and sent to another machine where it can be applied there. Each migration has a version represented by a TimeUUID that can be used to look up both the Migration itself (see getLocalMigrations) as well as a serialization of the Keyspace definition that was modified. There are three parts to a migration (think of it as a schema update): 1. data is written to the schema cf. 2. the migration is serialized to the migrations cf. 3. updated models are applied to the cassandra instance. Since steps 1, 2 and 3 are not committed atomically, care should be taken to ensure that a node/cluster is reasonably quiescent with regard to the keyspace or columnfamily whose schema is being modified. Each class that extends Migration is required to implement a no arg constructor, which will be used to inflate the object from it's serialized form.


Field Summary
protected  boolean clientMode
           
static byte[] LAST_MIGRATION_KEY
           
protected  java.util.UUID lastVersion
           
static java.lang.String MIGRATIONS_CF
           
static byte[] MIGRATIONS_KEY
           
protected  java.util.UUID newVersion
           
protected  RowMutation rm
           
static java.lang.String SCHEMA_CF
           
 
Constructor Summary
protected Migration()
          Subclasses must have a matching constructor
 
Method Summary
 void announce()
           
 void apply()
          apply changes
 void beforeApplyModels()
          override this to perform logic before writing the migration or applying it.
static Migration deserialize(byte[] bytes)
           
static java.util.UUID getLastMigrationId()
           
static java.util.Collection<IColumn> getLocalMigrations(java.util.UUID start, java.util.UUID end)
          load serialized migrations.
 java.util.UUID getVersion()
           
 byte[] serialize()
           
abstract  void subdeflate(org.apache.cassandra.db.migration.avro.Migration mi)
          Deflate this Migration into an Avro object.
abstract  void subinflate(org.apache.cassandra.db.migration.avro.Migration mi)
          Inflate this Migration from an Avro object: called after the required no-arg constructor.
static byte[] toUTF8Bytes(java.util.UUID version)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MIGRATIONS_CF

public static final java.lang.String MIGRATIONS_CF
See Also:
Constant Field Values

SCHEMA_CF

public static final java.lang.String SCHEMA_CF
See Also:
Constant Field Values

MIGRATIONS_KEY

public static final byte[] MIGRATIONS_KEY

LAST_MIGRATION_KEY

public static final byte[] LAST_MIGRATION_KEY

rm

protected RowMutation rm

newVersion

protected java.util.UUID newVersion

lastVersion

protected java.util.UUID lastVersion

clientMode

protected transient boolean clientMode
Constructor Detail

Migration

protected Migration()
Subclasses must have a matching constructor

Method Detail

beforeApplyModels

public void beforeApplyModels()
override this to perform logic before writing the migration or applying it. defaults to nothing.


apply

public final void apply()
                 throws java.io.IOException,
                        ConfigurationException
apply changes

Throws:
java.io.IOException
ConfigurationException

announce

public final void announce()

getLastMigrationId

public static java.util.UUID getLastMigrationId()

subdeflate

public abstract void subdeflate(org.apache.cassandra.db.migration.avro.Migration mi)
Deflate this Migration into an Avro object.


subinflate

public abstract void subinflate(org.apache.cassandra.db.migration.avro.Migration mi)
Inflate this Migration from an Avro object: called after the required no-arg constructor.


getVersion

public java.util.UUID getVersion()

serialize

public byte[] serialize()
                 throws java.io.IOException
Throws:
java.io.IOException

deserialize

public static Migration deserialize(byte[] bytes)
                             throws java.io.IOException
Throws:
java.io.IOException

getLocalMigrations

public static java.util.Collection<IColumn> getLocalMigrations(java.util.UUID start,
                                                               java.util.UUID end)
load serialized migrations.


toUTF8Bytes

public static byte[] toUTF8Bytes(java.util.UUID version)


Copyright © 2010 The Apache Software Foundation