@@ -570,6 +570,15 @@ def _coalesce_chunks(
570
570
self ,
571
571
chunks : list [_ChunkCoordsByteSlice ],
572
572
) -> list [list [_ChunkCoordsByteSlice ]]:
573
+ """
574
+ Combine chunks from a single shard into groups that should be read together
575
+ in a single request.
576
+
577
+ Respects the following configuration options:
578
+ - `sharding.read.coalesce_max_gap_bytes`: The maximum gap between
579
+ chunks to coalesce into a single group.
580
+ - `sharding.read.coalesce_max_bytes`: The maximum number of bytes in a group.
581
+ """
573
582
max_gap_bytes = config .get ("sharding.read.coalesce_max_gap_bytes" )
574
583
coalesce_max_bytes = config .get ("sharding.read.coalesce_max_bytes" )
575
584
@@ -602,17 +611,23 @@ async def _get_group_bytes(
602
611
group_start = group [0 ].byte_slice .start
603
612
group_end = group [- 1 ].byte_slice .stop
604
613
614
+ # A single call to retrieve the bytes for the entire group.
605
615
group_bytes = await byte_getter .get (
606
616
prototype = prototype ,
607
617
byte_range = RangeByteRequest (group_start , group_end ),
608
618
)
609
619
if group_bytes is None :
610
620
return {}
611
621
622
+ # Extract the bytes corresponding to each chunk in group from group_bytes.
612
623
shard_dict = {}
613
624
for chunk in group :
614
- s = slice (chunk .byte_slice .start - group_start , chunk .byte_slice .stop - group_start )
615
- shard_dict [chunk .coords ] = group_bytes [s ]
625
+ chunk_slice = slice (
626
+ chunk .byte_slice .start - group_start ,
627
+ chunk .byte_slice .stop - group_start ,
628
+ )
629
+ shard_dict [chunk .coords ] = group_bytes [chunk_slice ]
630
+
616
631
return shard_dict
617
632
618
633
async def _encode_single (
0 commit comments