Ejemplo n.º 1
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_throughput_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:`INTEGER_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 int or float 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 int or 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_in_seconds: How often the key cache should be saved; this
          helps to avoid a cold cache on restart

        :param int row_cache_save_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_throughput_in_mb: Memtables are flushed when this many 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 subcomparator_type.find('.') == -1:
                cfdef.subcomparator_type = 'org.apache.cassandra.db.marshal.%s' % subcomparator_type
            else:
                cfdef.subcomparator_type = subcomparator_type

        if key_cache_size is not None:
            if key_cache_size < 0:
                ire = InvalidRequestException()
                ire.why = 'key_cache_size must be non-negative'
                raise ire
            cfdef.key_cache_size = key_cache_size

        if row_cache_size is not None:
            if row_cache_size < 0:
                ire = InvalidRequestException()
                ire.why = 'row_cache_size must be non-negative'
                raise ire
            cfdef.row_cache_size = row_cache_size

        if gc_grace_seconds is not None:
            if gc_grace_seconds < 0:
                ire = InvalidRequestException()
                ire.why = 'gc_grace_seconds must be non-negative'
                raise ire
            cfdef.gc_grace_seconds = gc_grace_seconds

        if read_repair_chance is not None:
            if read_repair_chance < 0:
                ire = InvalidRequestException()
                ire.why = 'read_repair_chance must be non-negative'
                raise ire
            cfdef.read_repair_chance = read_repair_chance

        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 min_compaction_threshold is not None:
            if min_compaction_threshold < 0:
                ire = InvalidRequestException()
                ire.why = 'min_compaction_threshold must be non-negative'
                raise ire
            cfdef.min_compaction_threshold = min_compaction_threshold

        if max_compaction_threshold is not None:
            if max_compaction_threshold < 0:
                ire = InvalidRequestException()
                ire.why = 'max_compaction_threshold must be non-negative'
                raise ire
            cfdef.max_compaction_threshold = max_compaction_threshold

        if key_cache_save_period_in_seconds is not None:
            if key_cache_save_period_in_seconds < 0:
                ire = InvalidRequestException()
                ire.why = 'key_cache_save_period_in_seconds must be non-negative'
                raise ire
            cfdef.key_cache_save_period_in_seconds = key_cache_save_period_in_seconds

        if row_cache_save_period_in_seconds is not None:
            if row_cache_save_period_in_seconds < 0:
                ire = InvalidRequestException()
                ire.why = 'row_cache_save_period_in_seconds must be non-negative'
                raise ire
            cfdef.row_cache_save_period_in_seconds = row_cache_save_period_in_seconds

        if memtable_flush_after_mins is not None:
            if memtable_flush_after_mins < 0:
                ire = InvalidRequestException()
                ire.why = 'memtable_flush_after_mins must be non-negative'
                raise ire
            cfdef.memtable_flush_after_mins = memtable_flush_after_mins

        if memtable_throughput_in_mb is not None:
            if memtable_throughput_in_mb < 0:
                ire = InvalidRequestException()
                ire.why = 'memtable_throughput_in_mb must be non-negative'
                raise ire
            cfdef.memtable_throughput_in_mb = memtable_throughput_in_mb

        if memtable_throughput_in_millions is not None:
            if memtable_throughput_in_millions < 0:
                ire = InvalidRequestException()
                ire.why = 'memtable_throughput_in_millions must be non-negative'
                raise ire
            cfdef.memtable_throughput_in_millions = memtable_throughput_in_millions

        if comment is not None:
            cfdef.comment = comment

        self._system_add_column_family(cfdef)