resource_manager.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:intel-manager-for-lustre 作者: intel-hpdd 项目源码 文件源码
def _cull_lost_resources(self, session, reported_resources):
        # Must be run in a transaction to avoid leaving invalid things in the DB on failure.
        assert transaction.is_managed()

        reported_scoped_resources = []
        reported_global_resources = []
        for r in reported_resources:
            if isinstance(r._meta.identifier, BaseScopedId):
                reported_scoped_resources.append(session.local_id_to_global_id[r._handle])
            else:
                reported_global_resources.append(session.local_id_to_global_id[r._handle])

        # This generator re-runs the query on every loop iteration in order
        # to handle situations where resources returned by the query are
        # deleted as dependents of prior resources (HYD-3659).
        def iterate_lost_resources(query):
            loops_remaining = len(query())
            while loops_remaining:
                loops_remaining -= 1
                rs = query()
                if len(rs):
                    yield rs[0]
                else:
                    raise StopIteration()

            # If the list of lost items grew, don't continue looping.
            # Just bail out and the next scan will get them.
            if loops_remaining <= 0:
                raise StopIteration()

        # Look for scoped resources which were at some point reported by
        # this scannable_id, but are missing this time around.
        lost_scoped_resources = lambda: StorageResourceRecord.objects.filter(
                  ~Q(pk__in = reported_scoped_resources),
                  storage_id_scope = session.scannable_id)
        for r in iterate_lost_resources(lost_scoped_resources):
            self._delete_resource(r)

        # Look for globalid resources which were at some point reported by
        # this scannable_id, but are missing this time around.
        lost_global_resources = lambda: StorageResourceRecord.objects.filter(
                    ~Q(pk__in = reported_global_resources),
                    reported_by = session.scannable_id)
        for reportee in iterate_lost_resources(lost_global_resources):
            reportee.reported_by.remove(session.scannable_id)
            if not reportee.reported_by.count():
                self._delete_resource(reportee)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号