@@ -49,6 +49,7 @@ use crate::compiler::PreprocessorCacheEntry;
4949use crate :: config:: Config ;
5050use crate :: config:: { self , CacheType , PreprocessorCacheModeConfig } ;
5151use async_trait:: async_trait;
52+ use bytes:: Bytes ;
5253
5354use std:: io;
5455use std:: sync:: Arc ;
@@ -77,14 +78,14 @@ pub trait Storage: Send + Sync {
7778 /// Get raw serialized cache entry bytes by `key` (for multi-level backfill).
7879 /// Returns `None` if the entry is not found, or if the implementation doesn't support raw access.
7980 /// This is used by multi-level caches to backfill faster levels.
80- async fn get_raw ( & self , _key : & str ) -> Result < Option < Vec < u8 > > > {
81+ async fn get_raw ( & self , _key : & str ) -> Result < Option < Bytes > > {
8182 Ok ( None )
8283 }
8384
8485 /// Put raw serialized cache entry bytes under `key` (for multi-level backfill).
8586 /// Returns an error if the implementation doesn't support raw access.
8687 /// This is used by multi-level caches to backfill faster levels.
87- async fn put_raw ( & self , _key : & str , _data : Vec < u8 > ) -> Result < Duration > {
88+ async fn put_raw ( & self , _key : & str , _data : Bytes ) -> Result < Duration > {
8889 Err ( anyhow ! ( "put_raw not implemented for this storage backend" ) )
8990 }
9091
@@ -220,7 +221,7 @@ impl Storage for RemoteStorage {
220221 trace ! ( "RemoteStorage::put({})" , key) ;
221222 // Delegate to put_raw after serializing the entry
222223 let data = entry. finish ( ) ?;
223- self . put_raw ( key, data) . await
224+ self . put_raw ( key, data. into ( ) ) . await
224225 }
225226
226227 async fn check ( & self ) -> Result < CacheMode > {
@@ -297,18 +298,17 @@ impl Storage for RemoteStorage {
297298 & self . basedirs
298299 }
299300
300- /// Get raw bytes from remote storage without any transformations .
301+ /// Get raw bytes from remote storage for multi-level backfill .
301302 ///
302- /// Uses `to_vec()` instead of `to_bytes()` to preserve raw data unchanged.
303- /// This is critical for multi-level caching: when backfilling from remote to local,
304- /// we need the exact bytes without OpenDAL layer transformations (e.g., decompression).
305- /// If compression layers are configured, `to_bytes()` would decompress the data,
306- /// which would corrupt the cache entry when written to another level.
307- async fn get_raw ( & self , key : & str ) -> Result < Option < Vec < u8 > > > {
303+ /// Unlike `get()` which parses bytes into `CacheRead` (a `ZipArchive<Box<dyn ReadSeek>>`),
304+ /// this returns the raw bytes without parsing. `CacheRead` is a one-way transformation —
305+ /// there is no way to extract the original bytes back from the parsed ZIP archive.
306+ /// For backfill we need the raw bytes to write directly to another cache level.
307+ async fn get_raw ( & self , key : & str ) -> Result < Option < Bytes > > {
308308 trace ! ( "opendal::Operator::get_raw({})" , key) ;
309309 match self . operator . read ( & normalize_key ( key) ) . await {
310310 Ok ( res) => {
311- let data = res. to_vec ( ) ;
311+ let data = res. to_bytes ( ) ;
312312 trace ! (
313313 "opendal::Operator::get_raw({}): Found {} bytes" ,
314314 key,
@@ -328,12 +328,12 @@ impl Storage for RemoteStorage {
328328 }
329329 }
330330
331- /// Write raw bytes to remote storage.
331+ /// Write raw bytes to remote storage for multi-level backfill .
332332 ///
333- /// This is the primitive write operation used by both `put() ` and multi-level backfill.
334- /// For backfill operations, raw bytes are passed directly from one cache level to another
335- /// to preserve the exact data format (including any compression applied by OpenDAL layers) .
336- async fn put_raw ( & self , key : & str , data : Vec < u8 > ) -> Result < Duration > {
333+ /// Unlike `put()` which takes a `CacheWrite ` and serializes it, this writes
334+ /// pre-serialized bytes directly. Paired with `get_raw()` for efficient
335+ /// level-to-level data transfer without a deserialize/reserialize round-trip .
336+ async fn put_raw ( & self , key : & str , data : Bytes ) -> Result < Duration > {
337337 trace ! ( "opendal::Operator::put_raw({}, {} bytes)" , key, data. len( ) ) ;
338338 let start = std:: time:: Instant :: now ( ) ;
339339
0 commit comments