@@ -90,20 +90,12 @@ impl WriterClient {
9090 let table_path = & record. table_path ;
9191 let cluster = self . metadata . get_cluster ( ) ;
9292
93- let bucket_assigner = {
94- if let Some ( assigner) = self . bucket_assigners . get ( table_path) {
95- assigner. clone ( )
96- } else {
97- let assigner = Arc :: new ( Self :: create_bucket_assigner ( table_path. as_ref ( ) ) ) ;
98- self . bucket_assigners
99- . insert ( table_path. as_ref ( ) . clone ( ) , assigner. clone ( ) ) ;
100- assigner
101- }
102- } ;
93+ let ( bucket_assigner, bucket_id) = self . assign_bucket ( table_path) ;
10394
104- let bucket_id = bucket_assigner. assign_bucket ( None , & cluster) ;
105-
106- let mut result = self . accumulate . append ( record, 1 , & cluster, true ) . await ?;
95+ let mut result = self
96+ . accumulate
97+ . append ( record, bucket_id, & cluster, true )
98+ . await ?;
10799
108100 if result. abort_record_for_new_batch {
109101 let prev_bucket_id = bucket_id;
@@ -121,6 +113,21 @@ impl WriterClient {
121113
122114 Ok ( result. result_handle . expect ( "result_handle should exist" ) )
123115 }
116+ fn assign_bucket ( & self , table_path : & Arc < TablePath > ) -> ( Arc < Box < dyn BucketAssigner > > , i32 ) {
117+ let cluster = self . metadata . get_cluster ( ) ;
118+ let bucket_assigner = {
119+ if let Some ( assigner) = self . bucket_assigners . get ( table_path) {
120+ assigner. clone ( )
121+ } else {
122+ let assigner = Arc :: new ( Self :: create_bucket_assigner ( table_path. as_ref ( ) ) ) ;
123+ self . bucket_assigners
124+ . insert ( table_path. as_ref ( ) . clone ( ) , assigner. clone ( ) ) ;
125+ assigner
126+ }
127+ } ;
128+ let bucket_id = bucket_assigner. assign_bucket ( None , & cluster) ;
129+ ( bucket_assigner, bucket_id)
130+ }
124131
125132 pub async fn close ( self ) -> Result < ( ) > {
126133 self . shutdown_tx
0 commit comments