@@ -25,6 +25,7 @@ use tokio::sync::Mutex as AsyncMutex;
2525
2626use super :: opendal:: OpenDalStorage ;
2727use super :: refreshable_accessor:: RefreshableAccessor ;
28+ use crate :: catalog:: TableIdent ;
2829use crate :: io:: file_io:: Extensions ;
2930use crate :: io:: { StorageCredential , StorageCredentialsLoader } ;
3031use crate :: { Error , ErrorKind , Result } ;
@@ -52,6 +53,9 @@ pub struct RefreshableOpenDalStorage {
5253 /// Metadata location passed to `load_credentials`
5354 location : String ,
5455
56+ /// Table identifier passed to `load_credentials`
57+ table_ident : TableIdent ,
58+
5559 /// Cached AccessorInfo (created lazily from first operator)
5660 cached_info : Mutex < Option < Arc < AccessorInfo > > > ,
5761
@@ -88,6 +92,7 @@ impl RefreshableOpenDalStorage {
8892 credentials_loader : Arc < dyn StorageCredentialsLoader > ,
8993 initial_credentials : Option < StorageCredential > ,
9094 location : String ,
95+ table_ident : TableIdent ,
9196 extensions : Extensions ,
9297 ) -> Result < Self > {
9398 // Build initial inner_storage from base_props + initial_credentials
@@ -104,6 +109,7 @@ impl RefreshableOpenDalStorage {
104109 credentials_loader,
105110 extensions,
106111 location,
112+ table_ident,
107113 cached_info : Mutex :: new ( None ) ,
108114 credential_version : AtomicU64 :: new ( 0 ) ,
109115 refresh_lock : AsyncMutex :: new ( ( ) ) ,
@@ -197,7 +203,7 @@ impl RefreshableOpenDalStorage {
197203 // We are the one who should call the loader
198204 let new_creds = self
199205 . credentials_loader
200- . load_credentials ( & self . location )
206+ . load_credentials ( & self . table_ident , & self . location )
201207 . await ?;
202208 self . do_refresh ( new_creds) ?;
203209 Ok ( self . credential_version . load ( Ordering :: Acquire ) )
@@ -212,6 +218,7 @@ pub struct RefreshableOpenDalStorageBuilder {
212218 credentials_loader : Option < Arc < dyn StorageCredentialsLoader > > ,
213219 initial_credentials : Option < StorageCredential > ,
214220 location : String ,
221+ table_ident : Option < TableIdent > ,
215222 extensions : Extensions ,
216223}
217224
@@ -251,6 +258,12 @@ impl RefreshableOpenDalStorageBuilder {
251258 self
252259 }
253260
261+ /// Set the table identifier passed to `load_credentials`
262+ pub fn table_ident ( mut self , table_ident : TableIdent ) -> Self {
263+ self . table_ident = Some ( table_ident) ;
264+ self
265+ }
266+
254267 /// Set the extensions
255268 pub fn extensions ( mut self , extensions : Extensions ) -> Self {
256269 self . extensions = extensions;
@@ -268,6 +281,8 @@ impl RefreshableOpenDalStorageBuilder {
268281 } ) ?,
269282 self . initial_credentials ,
270283 self . location ,
284+ self . table_ident
285+ . ok_or_else ( || Error :: new ( ErrorKind :: DataInvalid , "table_ident is required" ) ) ?,
271286 self . extensions ,
272287 ) ?) )
273288 }
@@ -278,6 +293,7 @@ mod tests {
278293 use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
279294
280295 use super :: * ;
296+ use crate :: NamespaceIdent ;
281297 use crate :: io:: StorageCredential ;
282298
283299 // --- Test helpers ---
@@ -288,7 +304,11 @@ mod tests {
288304
289305 #[ async_trait:: async_trait]
290306 impl StorageCredentialsLoader for SimpleLoader {
291- async fn load_credentials ( & self , _location : & str ) -> Result < StorageCredential > {
307+ async fn load_credentials (
308+ & self ,
309+ _table_ident : & TableIdent ,
310+ _location : & str ,
311+ ) -> Result < StorageCredential > {
292312 Ok ( StorageCredential {
293313 prefix : "memory:/refreshed/" . to_string ( ) ,
294314 config : HashMap :: from ( [ ( "refreshed_key" . to_string ( ) , "refreshed_val" . to_string ( ) ) ] ) ,
@@ -322,7 +342,11 @@ mod tests {
322342
323343 #[ async_trait:: async_trait]
324344 impl StorageCredentialsLoader for TrackingRefreshLoader {
325- async fn load_credentials ( & self , _location : & str ) -> Result < StorageCredential > {
345+ async fn load_credentials (
346+ & self ,
347+ _table_ident : & TableIdent ,
348+ _location : & str ,
349+ ) -> Result < StorageCredential > {
326350 let n = self . call_count . fetch_add ( 1 , Ordering :: SeqCst ) + 1 ;
327351 Ok ( StorageCredential {
328352 prefix : format ! ( "memory:/refresh-{n}/" ) ,
@@ -331,13 +355,21 @@ mod tests {
331355 }
332356 }
333357
358+ fn test_table_ident ( ) -> TableIdent {
359+ TableIdent :: new (
360+ NamespaceIdent :: new ( "test_ns" . to_string ( ) ) ,
361+ "test_table" . to_string ( ) ,
362+ )
363+ }
364+
334365 fn build_memory_refreshable (
335366 loader : Arc < dyn StorageCredentialsLoader > ,
336367 ) -> Arc < RefreshableOpenDalStorage > {
337368 RefreshableOpenDalStorageBuilder :: new ( )
338369 . scheme ( "memory" . to_string ( ) )
339370 . base_props ( HashMap :: new ( ) )
340371 . credentials_loader ( loader)
372+ . table_ident ( test_table_ident ( ) )
341373 . build ( )
342374 . expect ( "Failed to build RefreshableOpenDalStorage for memory" )
343375 }
@@ -346,7 +378,7 @@ mod tests {
346378 async fn refresh ( storage : & RefreshableOpenDalStorage ) -> Result < ( ) > {
347379 let new_creds = storage
348380 . credentials_loader
349- . load_credentials ( & storage. location )
381+ . load_credentials ( & storage. table_ident , & storage . location )
350382 . await ?;
351383 storage. do_refresh ( new_creds)
352384 }
0 commit comments