1616// under the License.
1717
1818use std:: collections:: HashMap ;
19+ use std:: fmt:: { self , Debug } ;
1920use std:: future:: Future ;
2021use std:: ops:: Deref ;
2122use std:: pin:: Pin ;
@@ -24,16 +25,18 @@ use std::task::{Context, Poll};
2425
2526use futures:: channel:: mpsc:: { channel, Sender } ;
2627use futures:: StreamExt ;
28+ use waker_set:: WakerSet ;
2729
2830use crate :: runtime:: spawn;
2931use crate :: scan:: { DeleteFileContext , FileScanTaskDeleteFile } ;
3032use crate :: spec:: { DataContentType , DataFile , Struct } ;
3133use crate :: { Error , ErrorKind , Result } ;
3234
3335/// Index of delete files
34- #[ derive( Clone , Debug ) ]
36+ #[ derive( Clone ) ]
3537pub ( crate ) struct DeleteFileIndex {
3638 state : Arc < RwLock < DeleteFileIndexState > > ,
39+ waker_set : Arc < WakerSet > ,
3740}
3841
3942#[ derive( Debug ) ]
@@ -42,6 +45,15 @@ enum DeleteFileIndexState {
4245 Populated ( PopulatedDeleteFileIndex ) ,
4346}
4447
48+ impl Debug for DeleteFileIndex {
49+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
50+ f. debug_struct ( "DeleteFileIndex" )
51+ . field ( "state" , & self . state )
52+ . field ( "waker_set" , & "<No Debug>" )
53+ . finish ( )
54+ }
55+ }
56+
4557#[ derive( Debug ) ]
4658struct PopulatedDeleteFileIndex {
4759 #[ allow( dead_code) ]
@@ -59,22 +71,28 @@ impl DeleteFileIndex {
5971 pub ( crate ) fn new ( ) -> ( DeleteFileIndex , Sender < DeleteFileContext > ) {
6072 // TODO: what should the channel limit be?
6173 let ( tx, rx) = channel ( 10 ) ;
74+ let waker_set = Arc :: new ( WakerSet :: new ( ) ) ;
6275 let state = Arc :: new ( RwLock :: new ( DeleteFileIndexState :: Populating ) ) ;
6376 let delete_file_stream = rx. boxed ( ) ;
6477
6578 spawn ( {
6679 let state = state. clone ( ) ;
80+ let waker_set = waker_set. clone ( ) ;
6781 async move {
6882 let delete_files = delete_file_stream. collect :: < Vec < _ > > ( ) . await ;
6983
7084 let populated_delete_file_index = PopulatedDeleteFileIndex :: new ( delete_files) ;
7185
72- let mut guard = state. write ( ) . unwrap ( ) ;
73- * guard = DeleteFileIndexState :: Populated ( populated_delete_file_index) ;
86+ {
87+ let mut guard = state. write ( ) . unwrap ( ) ;
88+ * guard = DeleteFileIndexState :: Populated ( populated_delete_file_index) ;
89+ }
90+
91+ waker_set. notify_all ( ) ;
7492 }
7593 } ) ;
7694
77- ( DeleteFileIndex { state } , tx)
95+ ( DeleteFileIndex { state, waker_set } , tx)
7896 }
7997
8098 /// Gets all the delete files that apply to the specified data file.
@@ -89,6 +107,7 @@ impl DeleteFileIndex {
89107 state : self . state . clone ( ) ,
90108 data_file,
91109 seq_num,
110+ waker_set : self . waker_set . clone ( ) ,
92111 }
93112 }
94113}
@@ -99,7 +118,7 @@ impl PopulatedDeleteFileIndex {
99118 ///
100119 /// 1. The partition information is extracted from each delete file's manifest entry.
101120 /// 2. If the partition is empty and the delete file is not a positional delete,
102- /// it is added to the `global_delees ` vector
121+ /// it is added to the `global_deletes ` vector
103122 /// 3. Otherwise, the delete file is added to one of two hash maps based on its content type.
104123 fn new ( files : Vec < DeleteFileContext > ) -> PopulatedDeleteFileIndex {
105124 let mut eq_deletes_by_partition: HashMap < Struct , Vec < Arc < DeleteFileContext > > > =
@@ -199,18 +218,22 @@ pub(crate) struct DeletesForDataFile<'a> {
199218 state : Arc < RwLock < DeleteFileIndexState > > ,
200219 data_file : & ' a DataFile ,
201220 seq_num : Option < i64 > ,
221+ waker_set : Arc < WakerSet > ,
202222}
203223
204224impl Future for DeletesForDataFile < ' _ > {
205225 type Output = Result < Vec < FileScanTaskDeleteFile > > ;
206226
207- fn poll ( self : Pin < & mut Self > , _cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
227+ fn poll ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
208228 match self . state . try_read ( ) {
209229 Ok ( guard) => match guard. deref ( ) {
210230 DeleteFileIndexState :: Populated ( idx) => Poll :: Ready ( Ok (
211231 idx. get_deletes_for_data_file ( self . data_file , self . seq_num )
212232 ) ) ,
213- _ => Poll :: Pending ,
233+ _ => {
234+ self . waker_set . insert ( cx) ;
235+ Poll :: Pending
236+ }
214237 } ,
215238 Err ( err) => Poll :: Ready ( Err ( Error :: new ( ErrorKind :: Unexpected , err. to_string ( ) ) ) ) ,
216239 }
0 commit comments