incomplete_edge as (
-- join up incomplete piece info and precompute where the hasher left off within the entity
select
- verify_id, seq, entity_id, hasher_state,
+ verify_id, seq, slab.entity_id, hasher_state,
entity_offset + (upper(c.disk_sectors) - lower(slab.disk_sectors)) * sector_size as end_off
from
diskjumble.verify_piece_incomplete
where seq >= all (select seq from diskjumble.verify_piece_content where verify_id = p.verify_id)
)
select
- slab_id, disk_id, disk_sectors, entity_id, entity_offset, crypt_key, verify_id, seq, end_off,
+ slab_id, disk_id, disk_sectors, slab.entity_id, entity_offset, crypt_key, verify_id, seq, end_off,
hasher_state
from
diskjumble.slab
natural left join diskjumble.disk
left join incomplete_edge on
incomplete_edge.entity_id = slab.entity_id
- and incomplete_edge.end_off % sector_size == 0
+ and incomplete_edge.end_off %% sector_size = 0
and incomplete_edge.end_off <@ int8range(
slab.entity_offset,
slab.entity_offset + (upper(disk_sectors) - lower(disk_sectors)) * sector_size
)
where disk_id = %s
- order by entity_id, entity_offset, slab_id
+ order by slab.entity_id, entity_offset, slab_id
;
"""
with self.conn.cursor() as cursor:
yield (slab, hasher_ref)
- def get_torrent_info(self, disk_id: int) -> Mapping[bytes, bytes]:
+ def get_torrent_info(self, disk_id: int) -> Iterable[tuple[bytes, bytes]]:
stmt = """
with hashed as (
select digest(info, 'sha1') as info_hash, info
with self.conn.cursor() as cursor:
cursor.execute(stmt, (disk_id,))
for (info_hash, info) in cursor:
- yield (info_hash, info)
+ yield (bytes(info_hash), bytes(info))
def insert_verify_piece(self, ts: dt.datetime, entity_id: bytes, piece_num: int) -> int:
"""Insert new verify piece, returning the ID of the inserted row."""