コード例 #1
0
    def state_from_tr_bson(cls, doc):
        r"""
        >>> from common.typed_uuids import DatasetUUID, MessageUUID, PeerUUID

        >>> # No optional arguments
        >>> Transaction.state_from_tr_bson({
        ...     'src': UUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'),
        ...     'state': {'dataset_uuid':
        ...                   UUID('cf9a54b1-1239-48de-9b25-d7fa927db125')},
        ...     'uuid': UUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'),
        ...     'dst': UUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'),
        ...     'type': 'BACKUP',
        ...     'ts': datetime(2012, 9, 26, 14, 29, 48, 877434)
        ... })  # doctest:+ELLIPSIS,+NORMALIZE_WHITESPACE
        BackupTransactionState_Node(tr_start_time=....datetime(2012, 9, 26,
                                                               14, 29, 48,
                                                               877434),
            tr_uuid=MessageUUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'),
            tr_src_uuid=PeerUUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'),
            tr_dst_uuid=PeerUUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'),
            dataset_uuid=DatasetUUID('cf9a54b1-1239-48de-9b25-d7fa927db125'))

        >>> # All optional arguments
        >>> Transaction.state_from_tr_bson({
        ...     'src': UUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'),
        ...     'state': {'dataset_uuid':
        ...                   UUID('cf9a54b1-1239-48de-9b25-d7fa927db125')},
        ...     'uuid': UUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'),
        ...     'parent': UUID('a096cf37-dc4f-4d0e-9488-da50443c8c40'),
        ...     'dst': UUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'),
        ...     'wake_up_ts': datetime(2012, 10, 3, 12, 31, 8, 279807),
        ...     'type': 'BACKUP',
        ...     'ts': datetime(2012, 9, 26, 14, 29, 48, 877434)
        ... })  # doctest:+ELLIPSIS,+NORMALIZE_WHITESPACE
        BackupTransactionState_Node(tr_start_time=....datetime(2012, 9, 26,
                                                               14, 29, 48,
                                                               877434),
            tr_uuid=MessageUUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'),
            tr_src_uuid=PeerUUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'),
            tr_dst_uuid=PeerUUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'),
            dataset_uuid=DatasetUUID('cf9a54b1-1239-48de-9b25-d7fa927db125'))

        @type: NodeTransactionState
        """
        assert cls.validate_schema(doc), repr(doc)

        state_class = \
            transaction_states.TRANSACTION_STATE_CLASS_BY_NAME[doc['type']]

        assert state_class.validate_schema(doc['state']), repr(doc)

        return state_class.from_bson(doc['state'])(
            tr_start_time=doc['ts'],
            tr_uuid=TransactionUUID.safe_cast_uuid(doc['uuid']),
            tr_src_uuid=PeerUUID.safe_cast_uuid(doc['src']),
            tr_dst_uuid=PeerUUID.safe_cast_uuid(doc['dst']))
コード例 #2
0
ファイル: transactions.py プロジェクト: shvar/redfs
    def state_from_tr_bson(cls, doc):
        r"""
        >>> from common.typed_uuids import DatasetUUID, MessageUUID, PeerUUID

        >>> # No optional arguments
        >>> Transaction.state_from_tr_bson({
        ...     'src': UUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'),
        ...     'state': {'dataset_uuid':
        ...                   UUID('cf9a54b1-1239-48de-9b25-d7fa927db125')},
        ...     'uuid': UUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'),
        ...     'dst': UUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'),
        ...     'type': 'BACKUP',
        ...     'ts': datetime(2012, 9, 26, 14, 29, 48, 877434)
        ... })  # doctest:+ELLIPSIS,+NORMALIZE_WHITESPACE
        BackupTransactionState_Node(tr_start_time=....datetime(2012, 9, 26,
                                                               14, 29, 48,
                                                               877434),
            tr_uuid=MessageUUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'),
            tr_src_uuid=PeerUUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'),
            tr_dst_uuid=PeerUUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'),
            dataset_uuid=DatasetUUID('cf9a54b1-1239-48de-9b25-d7fa927db125'))

        >>> # All optional arguments
        >>> Transaction.state_from_tr_bson({
        ...     'src': UUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'),
        ...     'state': {'dataset_uuid':
        ...                   UUID('cf9a54b1-1239-48de-9b25-d7fa927db125')},
        ...     'uuid': UUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'),
        ...     'parent': UUID('a096cf37-dc4f-4d0e-9488-da50443c8c40'),
        ...     'dst': UUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'),
        ...     'wake_up_ts': datetime(2012, 10, 3, 12, 31, 8, 279807),
        ...     'type': 'BACKUP',
        ...     'ts': datetime(2012, 9, 26, 14, 29, 48, 877434)
        ... })  # doctest:+ELLIPSIS,+NORMALIZE_WHITESPACE
        BackupTransactionState_Node(tr_start_time=....datetime(2012, 9, 26,
                                                               14, 29, 48,
                                                               877434),
            tr_uuid=MessageUUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'),
            tr_src_uuid=PeerUUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'),
            tr_dst_uuid=PeerUUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'),
            dataset_uuid=DatasetUUID('cf9a54b1-1239-48de-9b25-d7fa927db125'))

        @type: NodeTransactionState
        """
        assert cls.validate_schema(doc), repr(doc)

        state_class = \
            transaction_states.TRANSACTION_STATE_CLASS_BY_NAME[doc['type']]

        assert state_class.validate_schema(doc['state']), repr(doc)

        return state_class.from_bson(doc['state'])(
                   tr_start_time=doc['ts'],
                   tr_uuid=TransactionUUID.safe_cast_uuid(doc['uuid']),
                   tr_src_uuid=PeerUUID.safe_cast_uuid(doc['src']),
                   tr_dst_uuid=PeerUUID.safe_cast_uuid(doc['dst']))
コード例 #3
0
    def from_bson(cls, doc):
        r"""
        >>> from common.typed_uuids import DatasetUUID, MessageUUID, PeerUUID

        >>> # No optional arguments
        >>> Transaction.from_bson({
        ...     'src': UUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'),
        ...     'state': {'dataset_uuid':
        ...                   UUID('cf9a54b1-1239-48de-9b25-d7fa927db125')},
        ...     'uuid': UUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'),
        ...     'dst': UUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'),
        ...     'type': 'BACKUP',
        ...     'ts': datetime(2012, 9, 26, 14, 29, 48, 877434)
        ... })() # doctest:+ELLIPSIS,+NORMALIZE_WHITESPACE
        Transaction(_id=None,
            type_='BACKUP',
            uuid=MessageUUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'),
            src=PeerUUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'),
            dst=PeerUUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'),
            ts=datetime.datetime(2012, 9, 26, 14, 29, 48, 877434),
            state=BackupTransactionState_Node(tr_start_time=....datetime(2012,
                                                    9, 26, 14, 29, 48, 877434),
                tr_uuid=MessageUUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'),
                tr_src_uuid=PeerUUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'),
                tr_dst_uuid=PeerUUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'),
                dataset_uuid=DatasetUUID('cf9a54b1-...-d7fa927db125')))

        >>> # All optional arguments
        >>> Transaction.from_bson({
        ...     'src': UUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'),
        ...     'state': {'dataset_uuid':
        ...                   UUID('cf9a54b1-1239-48de-9b25-d7fa927db125')},
        ...     'uuid': UUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'),
        ...     'parent': UUID('a096cf37-dc4f-4d0e-9488-da50443c8c40'),
        ...     'dst': UUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'),
        ...     'wake_up_ts': datetime(2012, 10, 3, 12, 31, 8, 279807),
        ...     'type': 'BACKUP',
        ...     'ts': datetime(2012, 9, 26, 14, 29, 48, 877434)
        ... })() # doctest:+ELLIPSIS,+NORMALIZE_WHITESPACE
        Transaction(_id=None,
            type_='BACKUP',
            uuid=MessageUUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'),
            src=PeerUUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'),
            dst=PeerUUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'),
            ts=datetime.datetime(2012, 9, 26, 14, 29, 48, 877434),
            state=Backup...State_Node(tr_start_time=....datetime(2012, 9, 26,
                                                                 14, 29, 48,
                                                                 877434),
                tr_uuid=MessageUUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'),
                tr_src_uuid=PeerUUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'),
                tr_dst_uuid=PeerUUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'),
                dataset_uuid=DatasetUUID('cf9a54b1-1239-...-d7fa927db125')),
            parent=UUID('a096cf37-dc4f-4d0e-9488-da50443c8c40'),
            wake_up_ts=datetime.datetime(2012, 10, 3, 12, 31, 8, 279807))

        @rtype: Transaction
        """
        assert cls.validate_schema(doc), repr(doc)

        state = cls.state_from_tr_bson(doc)

        return partial(
            super(Transaction, cls).from_bson(doc),
            type_=state.tr_type,
            uuid=TransactionUUID.safe_cast_uuid(state.tr_uuid),
            src=PeerUUID.safe_cast_uuid(state.tr_src_uuid),
            dst=PeerUUID.safe_cast_uuid(state.tr_dst_uuid),
            ts=state.tr_start_time,
            state=state,
            # Optional
            parent=doc.get('parent'),
            wake_up_ts=doc.get('wake_up_ts'))
コード例 #4
0
    def restore_dataset_to_lacking_hosts(self, me, host, ds_uuid):
        """
        Given a dataset (its UUID), restore it to every host which lacks it
        (if it is a sync dataset.).

        @param me: my node
        @type me: Node

        @param host: host which just completed the backup and is going
            to restore the data, or C{None} if not applicable.
        @type host: Host, NoneType

        @type ds_uuid: DatasetUUID
        """
        logger.debug('Restoring DS %s to all lacking hosts (if needed), '
                         'except %r',
                     ds_uuid, host)

        with db.RDB() as rdbw:
            # If the dataset is non-syncing, _host_uuids_to_restore
            # will be empty.
            host_uuid = host.uuid if host else None
            _host_uuids_to_restore = \
                TrustedQueries.TrustedDatasets \
                              .get_host_uuids_lacking_sync_dataset(
                                   ds_uuid, rdbw=rdbw)

            # But, if we have a host that definitely just completed the backup,
            # we can filter it out.
            # At the same step, we eagerly evaluate it, so we can get out
            # of RDB wrapper.
            host_uuids_to_restore = list(_host_uuids_to_restore) \
                                        if host_uuid is None \
                                        else [u for u in _host_uuids_to_restore
                                                if u != host_uuid]

        if host_uuids_to_restore:
            logger.debug('Will probably restore dataset %s to %r',
                         ds_uuid, host_uuids_to_restore)

            for restore_host_uuid in host_uuids_to_restore:
                restore_host_uuid = \
                    PeerUUID.safe_cast_uuid(restore_host_uuid)
                if self.__known_hosts.is_peer_alive(restore_host_uuid):
                    logger.debug('Restoring dataset %s to host %r',
                                 ds_uuid, restore_host_uuid)
                    r_tr = self.__app.tr_manager.create_new_transaction(
                               name='RESTORE',
                               src=me,
                               dst=self.__known_hosts[restore_host_uuid],
                               parent=None,
                               # RESTORE-specific
                               ds_uuid=ds_uuid,
                               # None means "all files"
                               file_paths_for_basedirs=None,
                               wr_uuid=None)
                else:
                    logger.debug("Could've restored dataset %s to host %r, "
                                     'but the host is not alive',
                                 ds_uuid, restore_host_uuid)
        else:
            logger.debug('Dataset %s is likely not auto-syncable', ds_uuid)
コード例 #5
0
ファイル: transactions.py プロジェクト: shvar/redfs
    def from_bson(cls, doc):
        r"""
        >>> from common.typed_uuids import DatasetUUID, MessageUUID, PeerUUID

        >>> # No optional arguments
        >>> Transaction.from_bson({
        ...     'src': UUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'),
        ...     'state': {'dataset_uuid':
        ...                   UUID('cf9a54b1-1239-48de-9b25-d7fa927db125')},
        ...     'uuid': UUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'),
        ...     'dst': UUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'),
        ...     'type': 'BACKUP',
        ...     'ts': datetime(2012, 9, 26, 14, 29, 48, 877434)
        ... })() # doctest:+ELLIPSIS,+NORMALIZE_WHITESPACE
        Transaction(_id=None,
            type_='BACKUP',
            uuid=MessageUUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'),
            src=PeerUUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'),
            dst=PeerUUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'),
            ts=datetime.datetime(2012, 9, 26, 14, 29, 48, 877434),
            state=BackupTransactionState_Node(tr_start_time=....datetime(2012,
                                                    9, 26, 14, 29, 48, 877434),
                tr_uuid=MessageUUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'),
                tr_src_uuid=PeerUUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'),
                tr_dst_uuid=PeerUUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'),
                dataset_uuid=DatasetUUID('cf9a54b1-...-d7fa927db125')))

        >>> # All optional arguments
        >>> Transaction.from_bson({
        ...     'src': UUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'),
        ...     'state': {'dataset_uuid':
        ...                   UUID('cf9a54b1-1239-48de-9b25-d7fa927db125')},
        ...     'uuid': UUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'),
        ...     'parent': UUID('a096cf37-dc4f-4d0e-9488-da50443c8c40'),
        ...     'dst': UUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'),
        ...     'wake_up_ts': datetime(2012, 10, 3, 12, 31, 8, 279807),
        ...     'type': 'BACKUP',
        ...     'ts': datetime(2012, 9, 26, 14, 29, 48, 877434)
        ... })() # doctest:+ELLIPSIS,+NORMALIZE_WHITESPACE
        Transaction(_id=None,
            type_='BACKUP',
            uuid=MessageUUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'),
            src=PeerUUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'),
            dst=PeerUUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'),
            ts=datetime.datetime(2012, 9, 26, 14, 29, 48, 877434),
            state=Backup...State_Node(tr_start_time=....datetime(2012, 9, 26,
                                                                 14, 29, 48,
                                                                 877434),
                tr_uuid=MessageUUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'),
                tr_src_uuid=PeerUUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'),
                tr_dst_uuid=PeerUUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'),
                dataset_uuid=DatasetUUID('cf9a54b1-1239-...-d7fa927db125')),
            parent=UUID('a096cf37-dc4f-4d0e-9488-da50443c8c40'),
            wake_up_ts=datetime.datetime(2012, 10, 3, 12, 31, 8, 279807))

        @rtype: Transaction
        """
        assert cls.validate_schema(doc), repr(doc)

        state = cls.state_from_tr_bson(doc)

        return partial(super(Transaction, cls).from_bson(doc),
                       type_=state.tr_type,
                       uuid=TransactionUUID.safe_cast_uuid(state.tr_uuid),
                       src=PeerUUID.safe_cast_uuid(state.tr_src_uuid),
                       dst=PeerUUID.safe_cast_uuid(state.tr_dst_uuid),
                       ts=state.tr_start_time,
                       state=state,
                         # Optional
                       parent=doc.get('parent'),
                       wake_up_ts=doc.get('wake_up_ts'))