@@ -63,6 +63,8 @@ use crate::{
63
63
proxy:: Proxy ,
64
64
Builder as ConnBuilder ,
65
65
} ,
66
+ runtime,
67
+ runtime:: RuntimeRef ,
66
68
serde_obkv:: value:: Value ,
67
69
util:: {
68
70
assert_not_empty, current_time_millis, duration_to_millis, millis_to_secs,
@@ -193,19 +195,22 @@ struct ObTableClientInner {
193
195
closed : AtomicBool ,
194
196
status_mutex : Lock ,
195
197
196
- //ServerAddr(all) -> ObTableConnection
198
+ // Client Runtimes
199
+ runtimes : RuntimesRef ,
200
+
201
+ // ServerAddr(all) -> ObTableConnection
197
202
table_roster : RwLock < HashMap < ObServerAddr , Arc < ObTable > > > ,
198
203
server_roster : ServerRoster ,
199
204
running_mode : RunningMode ,
200
- //TableName -> TableEntry
205
+ // TableName -> TableEntry
201
206
table_locations : RwLock < HashMap < String , Arc < TableEntry > > > ,
202
207
table_mutexs : RwLock < HashMap < String , Arc < Lock > > > ,
203
- //TableName -> rowKey element
208
+ // TableName -> rowKey element
204
209
table_row_key_element : RwLock < HashMap < String , HashMap < String , i32 > > > ,
205
210
connection_pools : RwLock < HashMap < ObServerAddr , Arc < ConnPool > > > ,
206
211
207
212
_retry_on_change_master : bool ,
208
- //TableName -> failure counter
213
+ // TableName -> failure counter
209
214
table_continuous_failures : RwLock < HashMap < String , Arc < AtomicUsize > > > ,
210
215
211
216
refresh_metadata_mutex : Lock ,
@@ -231,6 +236,7 @@ impl ObTableClientInner {
231
236
database : String ,
232
237
running_mode : RunningMode ,
233
238
config : ClientConfig ,
239
+ runtimes : Arc < ObClientRuntimes > ,
234
240
) -> Result < Self > {
235
241
let conn_init_thread_num = config. conn_init_thread_num ;
236
242
let ocp_manager =
@@ -250,6 +256,7 @@ impl ObTableClientInner {
250
256
datasource_name : "" . to_owned ( ) ,
251
257
running_mode,
252
258
config : config. clone ( ) ,
259
+ runtimes,
253
260
254
261
location : ObTableLocation :: new ( config) ,
255
262
initialized : AtomicBool :: new ( false ) ,
@@ -444,7 +451,7 @@ impl ObTableClientInner {
444
451
result. push ( ( part_id, table. clone ( ) ) ) ;
445
452
continue ;
446
453
}
447
- //Table not found, try to refresh it and retry get it again.
454
+ // Table not found, try to refresh it and retry get it again.
448
455
warn ! ( "ObTableClientInner::get_tables can not get ob table by address {:?} so that will sync refresh metadata." ,
449
456
replica_location. addr( ) ) ;
450
457
self . sync_refresh_metadata ( ) ?;
@@ -599,7 +606,9 @@ impl ObTableClientInner {
599
606
. tenant_name ( & self . tenant_name )
600
607
. user_name ( & self . user_name )
601
608
. database_name ( & self . database )
602
- . password ( & self . password ) ;
609
+ . password ( & self . password )
610
+ . runtimes ( self . runtimes . clone ( ) )
611
+ . sender_channel_size ( self . config . max_inflight_reqs_per_conn ) ;
603
612
604
613
let pool = Arc :: new (
605
614
ConnPoolBuilder :: new ( )
@@ -895,15 +904,15 @@ impl ObTableClientInner {
895
904
refresh : bool ,
896
905
blocking : bool ,
897
906
) -> Result < Arc < TableEntry > > {
898
- //Attempt to retrieve it from cache, avoid locking.
907
+ // Attempt to retrieve it from cache, avoid locking.
899
908
if let Some ( table_entry) = self . get_table_entry_from_cache ( table_name) {
900
909
//If the refresh is false indicates that user tolerate not the latest data
901
910
if !refresh || !self . need_refresh_table_entry ( & table_entry) {
902
911
return Ok ( table_entry) ;
903
912
}
904
913
}
905
914
906
- //Table entry is none or not refresh
915
+ // Table entry is none or not refresh
907
916
let table_mutex = {
908
917
let table_mutexs = self . table_mutexs . rl ( ) ;
909
918
match table_mutexs. get ( table_name) {
@@ -1477,9 +1486,57 @@ impl Drop for ObTableClientInner {
1477
1486
}
1478
1487
}
1479
1488
1489
+ pub type RuntimesRef = Arc < ObClientRuntimes > ;
1490
+
1491
+ /// OBKV Table Runtime
1492
+ #[ derive( Clone , Debug ) ]
1493
+ pub struct ObClientRuntimes {
1494
+ /// Runtime for connection to read data
1495
+ pub reader_runtime : RuntimeRef ,
1496
+ /// Runtime for connection to write data
1497
+ pub writer_runtime : RuntimeRef ,
1498
+ /// Runtime for some other tasks
1499
+ pub default_runtime : RuntimeRef ,
1500
+ }
1501
+
1502
+ impl ObClientRuntimes {
1503
+ pub fn test_default ( ) -> ObClientRuntimes {
1504
+ ObClientRuntimes {
1505
+ reader_runtime : Arc :: new ( build_runtime ( "ob-conn-reader" , 1 ) ) ,
1506
+ writer_runtime : Arc :: new ( build_runtime ( "ob-conn-writer" , 1 ) ) ,
1507
+ default_runtime : Arc :: new ( build_runtime ( "ob-default" , 1 ) ) ,
1508
+ }
1509
+ }
1510
+ }
1511
+
1512
+ fn build_runtime ( name : & str , threads_num : usize ) -> runtime:: Runtime {
1513
+ runtime:: Builder :: default ( )
1514
+ . worker_threads ( threads_num)
1515
+ . thread_name ( name)
1516
+ . enable_all ( )
1517
+ . build ( )
1518
+ . expect ( "Failed to create runtime" )
1519
+ }
1520
+
1521
+ fn build_obkv_runtimes ( config : & ClientConfig ) -> ObClientRuntimes {
1522
+ ObClientRuntimes {
1523
+ reader_runtime : Arc :: new ( build_runtime (
1524
+ "ob-conn-reader" ,
1525
+ config. conn_reader_thread_num ,
1526
+ ) ) ,
1527
+ writer_runtime : Arc :: new ( build_runtime (
1528
+ "ob-conn-writer" ,
1529
+ config. conn_writer_thread_num ,
1530
+ ) ) ,
1531
+ default_runtime : Arc :: new ( build_runtime ( "ob-default" , config. default_thread_num ) ) ,
1532
+ }
1533
+ }
1534
+
1480
1535
/// OBKV Table client
1481
1536
#[ derive( Clone ) ]
1537
+ #[ allow( dead_code) ]
1482
1538
pub struct ObTableClient {
1539
+ runtimes : Arc < ObClientRuntimes > ,
1483
1540
inner : Arc < ObTableClientInner > ,
1484
1541
refresh_thread_pool : Arc < ScheduledThreadPool > ,
1485
1542
}
@@ -2326,8 +2383,10 @@ impl Builder {
2326
2383
pub fn build ( self ) -> Result < ObTableClient > {
2327
2384
assert_not_empty ( & self . param_url , "Blank param url" ) ;
2328
2385
assert_not_empty ( & self . full_user_name , "Blank full user name" ) ;
2386
+ let runtimes = Arc :: new ( build_obkv_runtimes ( & self . config ) ) ;
2329
2387
2330
2388
Ok ( ObTableClient {
2389
+ runtimes : runtimes. clone ( ) ,
2331
2390
inner : Arc :: new ( ObTableClientInner :: internal_new (
2332
2391
self . param_url ,
2333
2392
self . full_user_name ,
@@ -2338,6 +2397,7 @@ impl Builder {
2338
2397
self . database ,
2339
2398
self . running_mode ,
2340
2399
self . config ,
2400
+ runtimes,
2341
2401
) ?) ,
2342
2402
refresh_thread_pool : Arc :: new (
2343
2403
ScheduledThreadPool :: builder ( )
0 commit comments