From ce2019ceba6a7bc1b7a276ec2609e17ab51a0d2d Mon Sep 17 00:00:00 2001 From: Jakob Cornell Date: Wed, 20 Apr 2022 18:57:08 -0500 Subject: [PATCH] Fix verify v2 hash offset computation bug, refactor query --- disk_jumble/src/disk_jumble/verify.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/disk_jumble/src/disk_jumble/verify.py b/disk_jumble/src/disk_jumble/verify.py index b5217f4..e2c736d 100644 --- a/disk_jumble/src/disk_jumble/verify.py +++ b/disk_jumble/src/disk_jumble/verify.py @@ -221,11 +221,12 @@ def _get_v2_worklist(conn, disk_id: int, target_ranges: List[NumericRange]) -> L from diskjumble.slab where disk_id = %(disk_id)s ), - joined as ( + with_hashes as ( select entity_id, entity.length, entity_blocks, slab_plus.disk_blocks, crypt_key, hashes, + elh.block_range as elh_range, entity_blocks * elh.block_range as check_erange from public.entityv2_leaf_hashes elh @@ -233,20 +234,16 @@ def _get_v2_worklist(conn, disk_id: int, target_ranges: List[NumericRange]) -> L left outer join public.entity using (entity_id) ), filtered as ( - select * from joined where not isempty(check_erange) + select *, generate_series(lower(check_erange), upper(check_erange) - 1) as piece_num + from (select * from with_hashes where not isempty(check_erange)) ), exploded as ( select - entity_id, - length, - generate_series(lower(check_erange), upper(check_erange) - 1) as piece_num, - ( - generate_series(lower(check_erange), upper(check_erange) - 1) - - lower(entity_blocks) + lower(disk_blocks) - ) as block, + entity_id, length, piece_num, + piece_num - lower(entity_blocks) + lower(disk_blocks) as block, substring( hashes, - generate_series(lower(check_erange), upper(check_erange) - 1)::integer * 32 + 1, + (piece_num - lower(elh_range))::integer * 32 + 1, 32 ) as hash, crypt_key @@ -311,6 +308,7 @@ def _do_verify(conn, disk_id: int, target_ranges: List[range], disk_file: io.Buf else: hasher = hashlib.sha256() entity_off = run.piece_num * BLOCK_SIZE + assert len(run.hash) == hasher.digest_size, "incorrect validation hash length" try: for range_ in run.block_ranges: -- 2.30.2