Verify tool: fix worklist sorting bug
authorJakob Cornell <jakob+gpg@jcornell.net>
Mon, 18 Apr 2022 18:01:57 +0000 (13:01 -0500)
committerJakob Cornell <jakob+gpg@jcornell.net>
Mon, 18 Apr 2022 18:01:57 +0000 (13:01 -0500)
disk_jumble/src/disk_jumble/verify.py

index 2e4d708f12ded284100eed2962c0d7cafd18c191..d10fb0bf5608b2fe5ddbacad9d9946fbdd065477 100644 (file)
@@ -48,6 +48,10 @@ class _Run:
        hash: bytes
 
 
+def _run_sort_key(run: _Run):
+       return run.block_ranges[0].start
+
+
 @dataclass
 class _V1Run(_Run):
        piece_length: int  # for the entity overall
@@ -173,7 +177,7 @@ def _get_v1_worklist(conn, disk_id: int, target_ranges: List[NumericRange]) -> L
                        if sum(map(len, run.block_ranges)) == math.ceil(run_length / BLOCK_SIZE):
                                runs.append(run)
 
-       runs.sort(key = lambda r: r.block_ranges)
+       runs.sort(key = _run_sort_key)
        return runs
 
 
@@ -284,7 +288,7 @@ def _do_verify(conn, disk_id: int, target_ranges: Optional[List[range]], disk_fi
        worklist = list(heapq.merge(
                _get_v1_worklist(conn, disk_id, pg_target_ranges),
                _get_v2_worklist(conn, disk_id, pg_target_ranges),
-               key = lambda run: run.block_ranges,
+               key = _run_sort_key,
        ))
 
        if target_ranges is not None: