Ejemplo n.º 1
0
    def create_column_family(self, keyspace, name, column_validation_classes=None, **cf_kwargs):

        """
        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.
        """

        self._conn.set_keyspace(keyspace)
        cfdef = CfDef()
        cfdef.keyspace = keyspace
        cfdef.name = name

        if cf_kwargs.pop('super', False):
            cf_kwargs.setdefault('column_type', 'Super')

        for k, v in cf_kwargs.iteritems():
            v = self._convert_class_attrs(k, v)
            setattr(cfdef, k, v)

        if column_validation_classes:
            for (colname, value_type) in column_validation_classes.items():
                cfdef = self._alter_column_cfdef(cfdef, colname, value_type)

        self._system_add_column_family(cfdef)
Ejemplo n.º 2
0
    def create_column_family(self,
                             keyspace,
                             name,
                             super=False,
                             comparator_type=None,
                             subcomparator_type=None,
                             key_cache_size=None,
                             row_cache_size=None,
                             gc_grace_seconds=None,
                             read_repair_chance=None,
                             default_validation_class=None,
                             min_compaction_threshold=None,
                             max_compaction_threshold=None,
                             key_cache_save_period_in_seconds=None,
                             row_cache_save_period_in_seconds=None,
                             memtable_flush_after_mins=None,
                             memtable_throughput_in_mb=None,
                             memtable_operations_in_millions=None,
                             comment=None):
        """
        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.

        :param str keyspace: what keyspace the column family will be created in

        :param str name: the name of the column family

        :param bool super: Whether or not this column family is a super column family

        :param str comparator_type: What type the column names will be, which affects
          their sort order.  By default, :const:`LONG_TYPE`, :const:`INT_TYPE`,
          :const:`ASCII_TYPE`, :const:`UTF8_TYPE`, :const:`TIME_UUID_TYPE`,
          :const:`LEXICAL_UUID_TYPE` and :const:`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.

        :param str subcomparator_type: Like `comparator_type`, but if the column family
          is a super column family, this applies to the type of the subcolumn names

        :param key_cache_size: The size of the key cache, either in a percentage of
          total keys (0.15, for example) or in an absolute number of
          keys (20000, for example).

        :param float row_cache_size: Same as `key_cache_size`, but for the row cache

        :param int gc_grace_seconds: Number of seconds before tombstones are removed

        :param float read_repair_chance: probability of a read repair occuring

        :param str default_validation_class: the data type for all column values in the CF.
          the choices for this are the same as for `comparator_type`.

        :param int min_compaction_threshold: Number of similarly sized SSTables that must
          be present before a minor compaction is scheduled. Setting to 0 disables minor
          compactions.

        :param int max_compaction_threshold: Number of similarly sized SSTables that must
          be present before a minor compaction is performed immediately. Setting to 0
          disables minor compactions.

        :param int key_cache_save_period_in_seconds: How often the key cache should
          be saved; this helps to avoid a cold cache on restart

        :param int row_cache_save_period_in_seconds: How often the row cache should
          be saved; this helps to avoid a cold cache on restart

        :param int memtable_flush_after_mins: Memtables are flushed when they reach this age

        :param int memtable_throughput_in_mb: Memtables are flushed when this many MBs have
          been written to them

        :param int memtable_operations_in_millions: Memtables are flushed when this many million
          operations have been performed on them

        :param str comment: A human readable description

        """

        self._conn.set_keyspace(keyspace)
        cfdef = CfDef()
        cfdef.keyspace = keyspace
        cfdef.name = name

        if super:
            cfdef.column_type = 'Super'

        if comparator_type is not None:
            if comparator_type.find('.') == -1:
                cfdef.comparator_type = 'org.apache.cassandra.db.marshal.%s' % comparator_type
            else:
                cfdef.comparator_type = comparator_type

        if subcomparator_type is not None:
            if cfdef.column_type != 'Super':
                self._raise_ire(
                    'subcomparator_type may only be used for super column families'
                )
            if subcomparator_type.find('.') == -1:
                cfdef.subcomparator_type = 'org.apache.cassandra.db.marshal.%s' % subcomparator_type
            else:
                cfdef.subcomparator_type = subcomparator_type

        if default_validation_class is not None:
            if default_validation_class.find('.') == -1:
                cfdef.default_validation_class = 'org.apache.cassandra.db.marshal.%s' % default_validation_class
            else:
                cfdef.default_validation_class = default_validation_class

        if comment is not None:
            cfdef.comment = comment

        self._cfdef_assign(key_cache_size, cfdef, 'key_cache_size')
        self._cfdef_assign(row_cache_size, cfdef, 'row_cache_size')
        self._cfdef_assign(gc_grace_seconds, cfdef, 'gc_grace_seconds')
        self._cfdef_assign(read_repair_chance, cfdef, 'read_repair_chance')
        self._cfdef_assign(min_compaction_threshold, cfdef,
                           'min_compaction_threshold')
        self._cfdef_assign(max_compaction_threshold, cfdef,
                           'max_compaction_threshold')
        self._cfdef_assign(key_cache_save_period_in_seconds, cfdef,
                           'key_cache_save_period_in_seconds')
        self._cfdef_assign(row_cache_save_period_in_seconds, cfdef,
                           'row_cache_save_period_in_seconds')
        self._cfdef_assign(memtable_flush_after_mins, cfdef,
                           'memtable_flush_after_mins')
        self._cfdef_assign(memtable_throughput_in_mb, cfdef,
                           'memtable_throughput_in_mb')
        self._cfdef_assign(memtable_operations_in_millions, cfdef,
                           'memtable_operations_in_millions')

        self._system_add_column_family(cfdef)
Ejemplo n.º 3
0
    def create_column_family(self,
                             keyspace,
                             name,
                             super=False,
                             comparator_type=None,
                             subcomparator_type=None,
                             key_cache_size=None,
                             row_cache_size=None,
                             gc_grace_seconds=None,
                             read_repair_chance=None,
                             default_validation_class=None,
                             key_validation_class=None,
                             min_compaction_threshold=None,
                             max_compaction_threshold=None,
                             key_cache_save_period_in_seconds=None,
                             row_cache_save_period_in_seconds=None,
                             replicate_on_write=None,
                             merge_shards_chance=None,
                             row_cache_provider=None,
                             key_alias=None,
                             compaction_strategy=None,
                             compaction_strategy_options=None,
                             row_cache_keys_to_save=None,
                             compression_options=None,
                             comment=None):
        """
        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.

        :param str keyspace: what keyspace the column family will be created in

        :param str name: the name of the column family

        :param bool super: Whether or not this column family is a super column family

        :param str comparator_type: What type the column names will be, which affects
          their sort order.  By default, :const:`LONG_TYPE`, :const:`INT_TYPE`,
          :const:`ASCII_TYPE`, :const:`UTF8_TYPE`, :const:`TIME_UUID_TYPE`,
          :const:`LEXICAL_UUID_TYPE` and :const:`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.

        :param str subcomparator_type: Like `comparator_type`, but if the column family
          is a super column family, this applies to the type of the subcolumn names

        :param key_cache_size: The size of the key cache, either in a percentage of
          total keys (0.15, for example) or in an absolute number of
          keys (20000, for example).

        :param float row_cache_size: Same as `key_cache_size`, but for the row cache

        :param int gc_grace_seconds: Number of seconds before tombstones are removed

        :param float read_repair_chance: probability of a read repair occuring

        :param str default_validation_class: the data type for all column values in the CF.
          The choices for this are the same as for `comparator_type`.

        :param str key_validation_class: the data type for row keys in the CF. The choices
          for this are the same as for `comparator_type`.

        :param int min_compaction_threshold: Number of similarly sized SSTables that must
          be present before a minor compaction is scheduled. Setting to 0 disables minor
          compactions.

        :param int max_compaction_threshold: Number of similarly sized SSTables that must
          be present before a minor compaction is performed immediately. Setting to 0
          disables minor compactions.

        :param int key_cache_save_period_in_seconds: How often the key cache should
          be saved; this helps to avoid a cold cache on restart

        :param int row_cache_save_period_in_seconds: How often the row cache should
          be saved; this helps to avoid a cold cache on restart

        :param bool replicate_on_write: Whether counter operations are replicated at write-time.
          This should almost always be True.

        :param float merge_shards_chance: The probability that counter shards will be merged.

        :param str row_cache_provider: The class that will be used to store the row cache.
          Defaults to ``org.apache.cassandra.cache.ConcurrentLinkedHashCacheProvider``.

        :param key_alias: A "column name" to be used for the row key. This currently only
          matters for CQL. The default is "KEY".

        :param compaction_strategy: The name of the compaction strategy. Choices include
          TieredCompactionStrategy and LeveledCompactionStrategy.

        :param compaction_strategy_options: A ``dict`` of options for the compaction
          strategy.

        :param row_cache_keys_to_save: A list of keys to be saved in the row cache. The
          default of ``None`` allows any row to be cached.

        :param compression_options: A ``dict`` of options for compression. Available
          keys include "sstable_compression", which may be ``None`` for no compression,
          "SnappyCompressor", "DeflateCompressor", or a custom compressor, and
          "chunk_length_kb", which must be a power of 2.

        :param str comment: A human readable description

        """

        self._conn.set_keyspace(keyspace)
        cfdef = CfDef()
        cfdef.keyspace = keyspace
        cfdef.name = name

        if super:
            cfdef.column_type = 'Super'

        cfdef.comparator_type = self._qualify_type_class(comparator_type)
        cfdef.subcomparator_type = self._qualify_type_class(subcomparator_type)
        cfdef.default_validation_class = self._qualify_type_class(
            default_validation_class)
        cfdef.key_validation_class = self._qualify_type_class(
            key_validation_class)

        cfdef.replicate_on_write = replicate_on_write
        cfdef.comment = comment
        cfdef.key_alias = key_alias
        if row_cache_provider:
            cfdef.row_cache_provider = row_cache_provider

        self._cfdef_assign(key_cache_size, cfdef, 'key_cache_size')
        self._cfdef_assign(row_cache_size, cfdef, 'row_cache_size')
        self._cfdef_assign(gc_grace_seconds, cfdef, 'gc_grace_seconds')
        self._cfdef_assign(read_repair_chance, cfdef, 'read_repair_chance')
        self._cfdef_assign(min_compaction_threshold, cfdef,
                           'min_compaction_threshold')
        self._cfdef_assign(max_compaction_threshold, cfdef,
                           'max_compaction_threshold')
        self._cfdef_assign(key_cache_save_period_in_seconds, cfdef,
                           'key_cache_save_period_in_seconds')
        self._cfdef_assign(row_cache_save_period_in_seconds, cfdef,
                           'row_cache_save_period_in_seconds')
        self._cfdef_assign(merge_shards_chance, cfdef, 'merge_shards_chance')
        self._cfdef_assign(compaction_strategy, cfdef, 'compaction_strategy')
        self._cfdef_assign(compaction_strategy_options, cfdef,
                           'compaction_strategy_options')
        self._cfdef_assign(row_cache_keys_to_save, cfdef,
                           'row_cache_keys_to_save')
        self._cfdef_assign(compression_options, cfdef, 'compression_options')
        self._system_add_column_family(cfdef)