@@ -2,17 +2,19 @@ use std::collections::VecDeque;
22use std:: io;
33use std:: io:: ErrorKind ;
44use std:: pin:: Pin ;
5- use std:: sync:: { Arc , RwLock } ;
5+ use std:: sync:: Arc ;
66use std:: task:: { Context , Poll , Waker } ;
77
88use futures:: Stream ;
99use futures_util:: future:: BoxFuture ;
1010use futures_util:: { FutureExt , StreamExt } ;
1111use vortex_array:: ArrayData ;
12- use vortex_error:: { vortex_err, vortex_panic , VortexExpect , VortexResult } ;
12+ use vortex_error:: { vortex_err, VortexExpect , VortexResult } ;
1313use vortex_io:: { Dispatch , IoDispatcher , VortexReadAt , VortexReadRanges } ;
1414
15- use crate :: { LayoutMessageCache , LayoutReader , Message , MessageLocator , PollRead , RowMask } ;
15+ use crate :: {
16+ LayoutMessageCache , LayoutReader , Message , MessageCache , MessageLocator , PollRead , RowMask ,
17+ } ;
1618
1719const NUM_TO_COALESCE : usize = 8 ;
1820
@@ -21,7 +23,11 @@ pub(crate) trait ReadMasked {
2123
2224 /// Read a Layout into a `V`, applying the given bitmask. Only entries corresponding to positions
2325 /// where mask is `true` will be included in the output.
24- fn read_masked ( & self , mask : & RowMask ) -> VortexResult < Option < PollRead < Self :: Value > > > ;
26+ fn read_masked (
27+ & self ,
28+ mask : & RowMask ,
29+ msgs : & dyn MessageCache ,
30+ ) -> VortexResult < Option < PollRead < Self :: Value > > > ;
2531}
2632
2733/// Read an array with a [`RowMask`].
@@ -39,8 +45,12 @@ impl ReadMasked for ReadArray {
3945 type Value = ArrayData ;
4046
4147 /// Read given mask out of the reader
42- fn read_masked ( & self , mask : & RowMask ) -> VortexResult < Option < PollRead < ArrayData > > > {
43- self . layout . poll_read ( mask)
48+ fn read_masked (
49+ & self ,
50+ mask : & RowMask ,
51+ msgs : & dyn MessageCache ,
52+ ) -> VortexResult < Option < PollRead < ArrayData > > > {
53+ self . layout . poll_read ( mask, msgs)
4454 }
4555}
4656
@@ -58,7 +68,7 @@ pub struct BufferedLayoutReader<R, S, V, RM> {
5868 queued : VecDeque < RowMaskState < V > > ,
5969 io_read : VortexReadRanges < R > ,
6070 dispatcher : Arc < IoDispatcher > ,
61- cache : Arc < RwLock < LayoutMessageCache > > ,
71+ msgs : LayoutMessageCache ,
6272}
6373
6474impl < R , S , V , RM > BufferedLayoutReader < R , S , V , RM >
7282 dispatcher : Arc < IoDispatcher > ,
7383 read_masks : S ,
7484 row_mask_reader : RM ,
75- cache : Arc < RwLock < LayoutMessageCache > > ,
85+ msgs : LayoutMessageCache ,
7686 ) -> Self {
7787 Self {
7888 read_masks,
@@ -81,18 +91,13 @@ where
8191 queued : VecDeque :: new ( ) ,
8292 io_read : VortexReadRanges :: new ( read, dispatcher. clone ( ) , 1 << 20 ) ,
8393 dispatcher,
84- cache ,
94+ msgs ,
8595 }
8696 }
8797
88- fn store_messages ( & self , messages : Vec < Message > ) {
89- let mut write_cache_guard = self
90- . cache
91- . write ( )
92- . unwrap_or_else ( |poison| vortex_panic ! ( "Failed to write to message cache: {poison}" ) ) ;
93- for Message ( message_id, buf) in messages {
94- write_cache_guard. set ( message_id, buf) ;
95- }
98+ fn store_messages ( & mut self , messages : Vec < Message > ) {
99+ self . msgs
100+ . set_many ( messages. into_iter ( ) . map ( |msg| ( msg. 0 , msg. 1 ) ) )
96101 }
97102
98103 fn gather_read_messages (
@@ -106,7 +111,9 @@ where
106111 for queued_res in self . queued . iter_mut ( ) {
107112 match queued_res {
108113 RowMaskState :: Pending ( pending_mask) => {
109- if let Some ( pending_read) = self . row_mask_reader . read_masked ( pending_mask) ? {
114+ if let Some ( pending_read) =
115+ self . row_mask_reader . read_masked ( pending_mask, & self . msgs ) ?
116+ {
110117 match pending_read {
111118 PollRead :: ReadMore ( m) => {
112119 to_read. extend ( m) ;
@@ -129,7 +136,9 @@ where
129136 while read_more_count < NUM_TO_COALESCE {
130137 match self . read_masks . poll_next_unpin ( cx) {
131138 Poll :: Ready ( Some ( Ok ( next_mask) ) ) => {
132- if let Some ( read_result) = self . row_mask_reader . read_masked ( & next_mask) ? {
139+ if let Some ( read_result) =
140+ self . row_mask_reader . read_masked ( & next_mask, & self . msgs ) ?
141+ {
133142 match read_result {
134143 PollRead :: ReadMore ( m) => {
135144 self . queued . push_back ( RowMaskState :: Pending ( next_mask) ) ;
0 commit comments