File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11[package ]
22name = " klickhouse"
3- version = " 0.15.2 "
3+ version = " 0.15.3 "
44authors = [" Protryon <max.bruce12@gmail.com>" ]
55edition = " 2024"
66license = " MIT OR Apache-2.0"
Original file line number Diff line number Diff line change @@ -179,6 +179,7 @@ pub struct ClusterMigration {
179179 client : Client ,
180180 cluster_name : String ,
181181 database : String ,
182+ do_lock : bool ,
182183}
183184
184185impl ClusterMigration {
@@ -187,8 +188,14 @@ impl ClusterMigration {
187188 client,
188189 cluster_name,
189190 database,
191+ do_lock : true ,
190192 }
191193 }
194+
195+ pub fn without_lock ( mut self ) -> Self {
196+ self . do_lock = false ;
197+ self
198+ }
192199}
193200
194201#[ async_trait:: async_trait]
@@ -201,15 +208,19 @@ impl AsyncTransaction for ClusterMigration {
201208 let lock = ClickhouseLock :: new ( self . client . clone ( ) , "refinery_exec" )
202209 . with_cluster ( & self . cluster_name ) ;
203210 let start = Instant :: now ( ) ;
204- let handle = loop {
205- if let Some ( handle) = lock. try_lock ( ) . await ? {
206- break handle;
207- } else {
208- tokio:: time:: sleep ( Duration :: from_millis ( 250 ) ) . await ;
209- if start. elapsed ( ) > Duration :: from_secs ( 60 ) {
210- lock. reset ( ) . await ?;
211+ let handle = if self . do_lock {
212+ Some ( loop {
213+ if let Some ( handle) = lock. try_lock ( ) . await ? {
214+ break handle;
215+ } else {
216+ tokio:: time:: sleep ( Duration :: from_millis ( 250 ) ) . await ;
217+ if start. elapsed ( ) > Duration :: from_secs ( 60 ) {
218+ lock. reset ( ) . await ?;
219+ }
211220 }
212- }
221+ } )
222+ } else {
223+ None
213224 } ;
214225 let mut n = 0 ;
215226 for query in queries {
@@ -224,7 +235,9 @@ impl AsyncTransaction for ClusterMigration {
224235 Client :: execute ( & self . client , query) . await ?;
225236 }
226237 }
227- handle. unlock ( ) . await ?;
238+ if let Some ( handle) = handle {
239+ handle. unlock ( ) . await ?;
240+ }
228241 Ok ( n)
229242 }
230243}
You can’t perform that action at this time.
0 commit comments