Replication strategy that simply chooses consecutive nodes in the ring for replicas
Replication strategy that puts a number of replicas in each datacenter
Original replication strategy for putting a number of replicas in each datacenter. This was originally called ‘RackAwareStrategy’.
A secondary index type where each indexed value receives its own row
Lets you examine and modify schema definitions as well as get basic information about the cluster.
This class is mainly designed to be used manually in a python shell, not as part of a program, although it can be used that way.
All operations which modify a keyspace or column family definition will block until the cluster reports that all nodes have accepted the modification.
Example Usage:
>>> from pycassa.system_manager import *
>>> sys = SystemManager('192.168.10.2:9160')
>>> sys.create_keyspace('TestKeyspace', SIMPLE_STRATEGY, {'replication_factor': '1'})
>>> sys.create_column_family('TestKeyspace', 'TestCF', super=False,
... comparator_type=LONG_TYPE)
>>> sys.alter_column_family('TestKeyspace', 'TestCF', key_cache_size=42, gc_grace_seconds=1000)
>>> sys.drop_keyspace('TestKeyspace')
>>> sys.close()
Closes the underlying connection
Returns a raw description of the keyspace, which is more useful for use in programs than describe_keyspace().
If use_dict_for_col_metadata is True, the CfDef’s column_metadata will be stored as a dictionary where the keys are column names instead of a list.
Returns a dictionary of the form {column_family_name: CfDef}
Gets a keyspace’s properties.
Returns a dict with ‘strategy_class’ and ‘strategy_options’ as keys.
Returns a list of all keyspace names.
Describes the Cassandra cluster
Gives the cluster name
Gives the server’s API version
Lists what schema version each node has
Gives the partitioner that the cluster is using
Gives the snitch that the cluster is using
Creates a new keyspace. Column families may be added to this keyspace after it is created using create_column_family().
replication_strategy determines how replicas are chosen for this keyspace. The strategies that Cassandra provides by default are available as SIMPLE_STRATEGY, NETWORK_TOPOLOGY_STRATEGY, and OLD_NETWORK_TOPOLOGY_STRATEGY.
strategy_options is a dictionary of strategy options. For NetworkTopologyStrategy, the dictionary should look like {'Datacenter1': '2', 'Datacenter2': '1'}. This maps each datacenter (as defined in a Cassandra property file) to a replica count. For SimpleStrategy, you can specify the replication factor as follows: {'replication_factor': '1'}.
Example Usage:
>>> from pycassa.system_manager import *
>>> sys = SystemManager('192.168.10.2:9160')
>>> # Create a SimpleStrategy keyspace
>>> sys.create_keyspace('SimpleKS', SIMPLE_STRATEGY, {'replication_factor': '1'})
>>> # Create a NetworkTopologyStrategy keyspace
>>> sys.create_keyspace('NTS_KS', NETWORK_TOPOLOGY_STRATEGY, {'DC1': '2', 'DC2': '1'})
>>> sys.close()
Alters an existing keyspace.
Warning
Don’t use this unless you know what you are doing.
Parameters are the same as for create_keyspace().
Drops a keyspace from the cluster.
Creates a new column family in a given keyspace. If a value is not supplied for any of optional parameters, Cassandra will use a reasonable default value.
keyspace should be the name of the keyspace the column family will be created in. name gives the name of the column family.
Alters an existing column family.
Parameter meanings are the same as for create_column_family().
Drops a column family from the keyspace.
Sets a data type for the value of a specific column.
value_type is a string that determines what type the column value will be. By default, LONG_TYPE, INT_TYPE, ASCII_TYPE, UTF8_TYPE, TIME_UUID_TYPE, LEXICAL_UUID_TYPE and BYTES_TYPE are provided. Custom types may be used as well by providing the class name; if the custom comparator class is not in org.apache.cassandra.db.marshal, the fully qualified class name must be given.
For super column families, this sets the subcolumn value type for any subcolumn named column, regardless of the super column name.
Creates an index on a column.
This allows efficient for index usage via get_indexed_slices()
column specifies what column to index, and value_type is a string that describes that column’s value’s data type; see alter_column() for a full description of value_type.
index_type determines how the index will be stored internally. Currently, KEYS_INDEX is the only option. index_name is an optional name for the index.
Example Usage:
>>> from pycassa.system_manager import *
>>> sys = SystemManager('192.168.2.10:9160')
>>> sys.create_index('Keyspace1', 'Standard1', 'birthdate', LONG_TYPE, index_name='bday_index')
>>> sys.close
Drops an index on a column.