@@ -26,8 +26,8 @@ pub mod memory;
2626mod spill;
2727
2828use crate :: app:: {
29- PartitionedUId , PurgeDataContext , ReadingIndexViewContext , ReadingViewContext ,
30- RegisterAppContext , ReleaseTicketContext , RequireBufferContext , WritingViewContext ,
29+ PurgeDataContext , ReadingIndexViewContext , ReadingViewContext , RegisterAppContext ,
30+ ReleaseTicketContext , RequireBufferContext , WritingViewContext ,
3131} ;
3232use crate :: config:: { Config , StorageType } ;
3333use crate :: error:: WorkerError ;
@@ -38,12 +38,12 @@ use std::fmt::{Display, Formatter};
3838use crate :: util:: now_timestamp_as_sec;
3939use anyhow:: Result ;
4040use async_trait:: async_trait;
41- use bytes:: Bytes ;
41+ use bytes:: { BufMut , Bytes , BytesMut } ;
4242
4343use crate :: composed_bytes:: ComposedBytes ;
4444use crate :: runtime:: manager:: RuntimeManager ;
45- use crate :: store:: mem:: buffer:: BatchMemoryBlock ;
4645use crate :: store:: spill:: SpillWritingViewContext ;
46+ use crate :: store:: BytesWrapper :: { Composed , Direct } ;
4747use std:: sync:: Arc ;
4848
4949#[ derive( Debug ) ]
@@ -248,6 +248,53 @@ pub trait Store {
248248 async fn name ( & self ) -> StorageType ;
249249
250250 async fn spill_insert ( & self , ctx : SpillWritingViewContext ) -> Result < ( ) , WorkerError > ;
251+
252+ fn generate_shuffle_file_format (
253+ & self ,
254+ blocks : Vec < & Block > ,
255+ offset : i64 ,
256+ ) -> Result < ShuffleFileFormat > {
257+ let mut offset = offset;
258+
259+ let mut index_bytes_holder = BytesMut :: new ( ) ;
260+ let mut data_chain = Vec :: with_capacity ( blocks. len ( ) ) ;
261+
262+ let mut total_size = 0 ;
263+ for block in blocks {
264+ let block_id = block. block_id ;
265+ let length = block. length ;
266+ let uncompress_len = block. uncompress_length ;
267+ let task_attempt_id = block. task_attempt_id ;
268+ let crc = block. crc ;
269+
270+ total_size += length as usize ;
271+
272+ index_bytes_holder. put_i64 ( offset) ;
273+ index_bytes_holder. put_i32 ( length) ;
274+ index_bytes_holder. put_i32 ( uncompress_len) ;
275+ index_bytes_holder. put_i64 ( crc) ;
276+ index_bytes_holder. put_i64 ( block_id) ;
277+ index_bytes_holder. put_i64 ( task_attempt_id) ;
278+
279+ let data = & block. data ;
280+ data_chain. push ( data. clone ( ) ) ;
281+ offset += length as i64 ;
282+ }
283+
284+ Ok ( ShuffleFileFormat {
285+ data : Composed ( ComposedBytes :: from ( data_chain, total_size) ) ,
286+ index : Direct ( index_bytes_holder. into ( ) ) ,
287+ len : total_size,
288+ offset,
289+ } )
290+ }
291+ }
292+
293+ pub struct ShuffleFileFormat {
294+ data : BytesWrapper ,
295+ index : BytesWrapper ,
296+ len : usize ,
297+ offset : i64 ,
251298}
252299
253300pub trait Persistent { }
0 commit comments