class Replace(Step):
    """\"Replace\" operation"""

    TAG = 16
    ARGS = ('key', protocol.STRING), \
           ('wanted', protocol.Option(protocol.STRING))

    def __init__(self, key, wanted):
        super(Replace, self).__init__(key, wanted)

        self._key = key
        self._wanted = wanted

    key = property(operator.attrgetter('_key'),
                   doc=utils.format_doc('''
Key for which the value needs to be replaced

:type: :class:`str`
'''))
    wanted = property(operator.attrgetter('_wanted'),
                      doc=utils.format_doc('''
Value to set the key to or None to delete the key

:type: :class:`str` or :data:`None`
'''))
class Assert(Step):
    '''"Assert" operation'''

    TAG = 8
    ARGS = ('key', protocol.STRING), \
        ('value', protocol.Option(protocol.STRING)),

    def __init__(self, key, value):
        super(Assert, self).__init__(key, value)

        self._key = key
        self._value = value

    key = property(operator.attrgetter('_key'),
                   doc=utils.format_doc('''
            Key for which to assert the given value

            :type: :class:`str`
        '''))
    value = property(operator.attrgetter('_value'),
                     doc=utils.format_doc('''
            Expected value

            :type: :class:`str` or :data:`None`
        '''))
class Sequence(Step):
    '''"Sequence" operation

    This is a container for a list of other operations.
    '''

    TAG = 5
    ARGS = ()

    def __init__(self, steps):
        super(Sequence, self).__init__()

        self._steps = steps

    steps = property(operator.attrgetter('_steps'),
                     doc=utils.format_doc('''
            Sequence steps

            :type: iterable of :class:`Step`
        '''))

    def serialize(self):
        for bytes_ in protocol.UINT32.serialize(self.TAG):
            yield bytes_

        for bytes_ in protocol.UINT32.serialize(len(self.steps)):
            yield bytes_

        for step in self.steps:
            for bytes_ in step.serialize():
                yield bytes_
示例#4
0
class FlushStore(protocol.Message):
    '''"flush_store" message'''

    __slots__ = ()

    TAG = 0x0042 | protocol.Message.MASK
    ARGS = ()
    RETURN_TYPE = protocol.UNIT

    DOC = utils.format_doc('''
        Send a "flush_store" command to the server

        This method instructs a node to flush its store to disk.
    ''')
class Set(Step):
    '''"Set" operation'''

    TAG = 1
    ARGS = ('key', protocol.STRING), ('value', protocol.STRING),

    def __init__(self, key, value):
        super(Set, self).__init__(key, value)

        self._key = key
        self._value = value

    key = property(operator.attrgetter('_key'),
                   doc=utils.format_doc('''
            Key to set

            :type: :class:`str`
        '''))
    value = property(operator.attrgetter('_value'),
                     doc=utils.format_doc('''
            Value to set

            :type: :class:`str`
        '''))
示例#6
0
class DefragDB(protocol.Message):
    '''"defrag_db" message'''

    __slots__ = ()

    TAG = 0x0026 | protocol.Message.MASK
    ARGS = ()
    RETURN_TYPE = protocol.UNIT

    DOC = utils.format_doc('''
        Send a "defrag_db" command to the server

        This method will trigger defragmentation of the store on the node this
        comamand is sent to.

        :note: This only works on slave nodes
    ''')
示例#7
0
class GetNurseryConfig(protocol.Message):
    '''"get_nursery_config" message'''

    __slots__ = ()

    TAG = 0x0020 | protocol.Message.MASK
    ARGS = ()
    RETURN_TYPE = NURSERY_CONFIG

    DOC = utils.format_doc('''
        Send a "get_nursery_config" command to the server

        This method returns Arakoon Nursery configuration settings.

        :return: Nursery configuration
        :rtype: `NurseryConfig`
    ''')
class DeletePrefix(Step):
    '''"DeletePrefix" operation'''

    TAG = 14
    ARGS = ('prefix', protocol.STRING),

    def __init__(self, prefix):
        super(DeletePrefix, self).__init__(prefix)

        self._prefix = prefix

    prefix = property(operator.attrgetter('_prefix'),
                      doc=utils.format_doc('''
            prefix to delete

            :type: :class:`str`
        '''))
class Delete(Step):
    '''"Delete" operation'''

    TAG = 2
    ARGS = ('key', protocol.STRING),

    def __init__(self, key):
        super(Delete, self).__init__(key)

        self._key = key

    key = property(operator.attrgetter('_key'),
                   doc=utils.format_doc('''
            Key to delete

            :type: :class:`str`
        '''))
class AssertExists(Step):
    '''"AssertExists" operation'''

    TAG = 15
    ARGS = ('key', protocol.STRING),

    def __init__(self, key):
        super(AssertExists, self).__init__(key)

        self._key = key

    key = property(operator.attrgetter('_key'),
                   doc=utils.format_doc('''
            Key to check

            :type: :class:`str`
        '''))
示例#11
0
class DropMaster(protocol.Message):
    '''"drop_master" message'''

    __slots__ = ()

    TAG = 0x0030 | protocol.Message.MASK
    ARGS = ()
    RETURN_TYPE = protocol.UNIT

    DOC = utils.format_doc('''
        Send a "drop_master" command to the server

        This method instructs a node to drop its master role, if possible.
        When the call returns successfully, the node was no longer master, but
        could have gained the master role already in-between.

        :note: This doesn't work in a single-node environment
    ''')
示例#12
0
class CollapseTlogs(protocol.Message):
    '''"collapse_tlogs" message'''

    __slots__ = '_count',

    TAG = 0x0014 | protocol.Message.MASK
    ARGS = ('count', protocol.INT32),
    RETURN_TYPE = None  # Hack to work around irregular return type

    DOC = utils.format_doc('''
        Send a "collapse_tlogs" command to the server

        This method instructs a node to collapse its *TLOG* collection by
        constructing a *head* database and removing superfluous *TLOG* files.

        The number of *TLOG* files to keep should be passed as a parameter.

        :param count: Number of *TLOG* files to keep
        :type count: :class:`int`
        :return: For every *TLOG*, the time it took to collapse it
        :rtype: `[int]`
    ''')

    def __init__(self, count):
        self._count = count

    count = property(operator.attrgetter('_count'))

    def receive(self):  #pylint: disable=R0912
        self.RETURN_TYPE = protocol.INT32  #pylint: disable=C0103

        count_receiver = protocol.Message.receive(self)
        request = count_receiver.next()

        while isinstance(request, protocol.Request):
            value = yield request
            request = count_receiver.send(value)

        if not isinstance(request, protocol.Result):
            raise TypeError

        count = request.value

        result = [None] * count

        for idx in xrange(count):
            success_receiver = protocol.INT32.receive()
            request = success_receiver.next()

            while isinstance(request, protocol.Request):
                value = yield request
                request = success_receiver.send(value)

            if not isinstance(request, protocol.Result):
                raise TypeError

            success = request.value

            if success == 0:
                time_receiver = protocol.INT64.receive()
                request = time_receiver.next()

                while isinstance(request, protocol.Request):
                    value = yield request
                    request = time_receiver.send(value)

                if not isinstance(request, protocol.Result):
                    raise TypeError

                time = request.value
                result[idx] = time
            else:
                message_receiver = protocol.STRING.receive()
                request = message_receiver.next()

                while isinstance(request, protocol.Request):
                    value = yield request
                    request = message_receiver.send(value)

                if not isinstance(request, protocol.Result):
                    raise TypeError

                message = request.value

                if success in errors.ERROR_MAP:
                    raise errors.ERROR_MAP[success](message)
                else:
                    raise errors.ArakoonError(
                        'Unknown error code 0x%x, server said: %s' % \
                            (success, message))

        yield protocol.Result(result)