36
36
import com .alipay .oceanbase .rpc .protocol .payload .impl .execute .syncquery .ObTableQueryAsyncRequest ;
37
37
import com .alipay .oceanbase .rpc .stream .ObTableClientQueryAsyncStreamResult ;
38
38
import com .alipay .oceanbase .rpc .stream .ObTableClientQueryStreamResult ;
39
+ import com .alipay .oceanbase .rpc .table .ObHBaseParams ;
40
+ import com .alipay .oceanbase .rpc .table .ObKVParams ;
39
41
import com .alipay .sofa .common .thread .SofaThreadPoolExecutor ;
40
42
41
43
import com .google .protobuf .Descriptors ;
@@ -99,6 +101,11 @@ public class OHTable implements HTableInterface {
99
101
*/
100
102
private int operationTimeout ;
101
103
104
+ /**
105
+ * timeout for each rpc request
106
+ */
107
+ private int rpcTimeout ;
108
+
102
109
/**
103
110
* if the <code>Get</code> executing pool is specified by user cleanupPoolOnClose will be false ,
104
111
* which means that user is responsible for the pool
@@ -165,6 +172,8 @@ public class OHTable implements HTableInterface {
165
172
*/
166
173
private final Configuration configuration ;
167
174
175
+ private int scannerTimeout ;
176
+
168
177
/**
169
178
* Creates an object to access a HBase table.
170
179
* Shares oceanbase table obTableClient and other resources with other OHTable instances
@@ -290,7 +299,7 @@ public OHTable(TableName tableName, Connection connection,
290
299
} else {
291
300
this .cleanupPoolOnClose = false ;
292
301
}
293
-
302
+ this . rpcTimeout = connectionConfig . getRpcTimeout ();
294
303
this .operationTimeout = connectionConfig .getOperationTimeout ();
295
304
this .operationExecuteInPool = this .configuration .getBoolean (
296
305
HBASE_CLIENT_OPERATION_EXECUTE_IN_POOL ,
@@ -338,6 +347,12 @@ private void finishSetUp() {
338
347
checkArgument (configuration != null , "configuration is null." );
339
348
checkArgument (tableName != null , "tableNameString is null." );
340
349
checkArgument (tableNameString != null , "tableNameString is null." );
350
+ this .scannerTimeout = HBaseConfiguration .getInt (configuration ,
351
+ HConstants .HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD ,
352
+ HConstants .HBASE_REGIONSERVER_LEASE_PERIOD_KEY ,
353
+ HConstants .DEFAULT_HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD );
354
+ this .rpcTimeout = configuration .getInt (HConstants .HBASE_RPC_TIMEOUT_KEY ,
355
+ HConstants .DEFAULT_HBASE_RPC_TIMEOUT );
341
356
this .operationTimeout = this .configuration .getInt (
342
357
HConstants .HBASE_CLIENT_OPERATION_TIMEOUT ,
343
358
HConstants .DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT );
@@ -390,13 +405,29 @@ public boolean exists(Get get) throws IOException {
390
405
}
391
406
392
407
@ Override
393
- public boolean [] existsAll (List <Get > list ) throws IOException {
394
- throw new FeatureNotSupportedException ("not supported yet." );
408
+ public boolean [] existsAll (List <Get > gets ) throws IOException {
409
+ if (gets .isEmpty ()) {
410
+ return new boolean [] {};
411
+ }
412
+ if (gets .size () == 1 ) {
413
+ return new boolean [] { exists (gets .get (0 )) };
414
+ }
415
+ Result [] r = get (gets );
416
+ boolean [] ret = new boolean [r .length ];
417
+ for (int i = 0 ; i < gets .size (); ++i ) {
418
+ ret [i ] = exists (gets .get (i ));
419
+ }
420
+ return ret ;
395
421
}
396
422
397
423
@ Override
398
424
public Boolean [] exists (List <Get > gets ) throws IOException {
399
- throw new FeatureNotSupportedException ("not supported yet'" );
425
+ boolean [] results = existsAll (gets );
426
+ Boolean [] objectResults = new Boolean [results .length ];
427
+ for (int i = 0 ; i < results .length ; ++i ) {
428
+ objectResults [i ] = results [i ];
429
+ }
430
+ return objectResults ;
400
431
}
401
432
402
433
@ Override
@@ -478,8 +509,18 @@ public Result call() throws IOException {
478
509
|| get .getFamilyMap ().keySet ().size () == 0 ) {
479
510
filter = buildObHTableFilter (get .getFilter (), get .getTimeRange (),
480
511
get .getMaxVersions (), null );
481
- obTableQuery = buildObTableQuery (filter , get .getRow (), true , get .getRow (),
482
- true );
512
+ if (get .isClosestRowBefore ()) {
513
+ Scan scan = new Scan ();
514
+ scan .setStartRow (get .getRow ());
515
+ scan .setCaching (1 );
516
+ scan .setReversed (true );
517
+ obTableQuery = buildObTableQuery (filter , scan );
518
+ obTableQuery .setObKVParams (buildOBKVParams (scan ));
519
+ } else {
520
+ obTableQuery = buildObTableQuery (filter , get .getRow (), true ,
521
+ get .getRow (), true );
522
+ obTableQuery .setObKVParams (buildOBKVParams (get ));
523
+ }
483
524
request = buildObTableQueryRequest (obTableQuery ,
484
525
getTargetTableName (tableNameString ));
485
526
@@ -492,10 +533,17 @@ public Result call() throws IOException {
492
533
family = entry .getKey ();
493
534
filter = buildObHTableFilter (get .getFilter (), get .getTimeRange (),
494
535
get .getMaxVersions (), entry .getValue ());
495
-
496
- obTableQuery = buildObTableQuery (filter , get .getRow (), true ,
497
- get .getRow (), true );
498
-
536
+ if (get .isClosestRowBefore ()) {
537
+ Scan scan = new Scan (get .getRow ());
538
+ scan .setCaching (1 );
539
+ scan .setReversed (true );
540
+ obTableQuery = buildObTableQuery (filter , scan );
541
+ obTableQuery .setObKVParams (buildOBKVParams (scan ));
542
+ } else {
543
+ obTableQuery = buildObTableQuery (filter , get .getRow (), true ,
544
+ get .getRow (), true );
545
+ obTableQuery .setObKVParams (buildOBKVParams (get ));
546
+ }
499
547
request = buildObTableQueryRequest (obTableQuery ,
500
548
getTargetTableName (tableNameString , Bytes .toString (family )));
501
549
clientQueryStreamResult = (ObTableClientQueryStreamResult ) obTableClient
@@ -661,6 +709,28 @@ private void validatePut(Put put) {
661
709
}
662
710
}
663
711
712
+ private ObKVParams buildOBKVParams (final Scan scan ) {
713
+ ObKVParams obKVParams = new ObKVParams ();
714
+ ObHBaseParams obHBaseParams = new ObHBaseParams ();
715
+ if (scan != null ) {
716
+ obHBaseParams .setCaching (scan .getCaching ());
717
+ obHBaseParams .setCallTimeout (scannerTimeout );
718
+ obHBaseParams .setCacheBlock (scan .isGetScan ());
719
+ obHBaseParams .setAllowPartialResults (scan .getAllowPartialResults ());
720
+ }
721
+ obKVParams .setObParamsBase (obHBaseParams );
722
+ return obKVParams ;
723
+ }
724
+
725
+ private ObKVParams buildOBKVParams (final Get get ) {
726
+ ObKVParams obKVParams = new ObKVParams ();
727
+ ObHBaseParams obHBaseParams = new ObHBaseParams ();
728
+ obHBaseParams .setCheckExistenceOnly (get .isCheckExistenceOnly ());
729
+ obHBaseParams .setCacheBlock (get .getCacheBlocks ());
730
+ obKVParams .setObParamsBase (obHBaseParams );
731
+ return obKVParams ;
732
+ }
733
+
664
734
/**
665
735
* 例如当 key="key001", family = "family", c1="a" 时,才执行 put 操作,该命令是原子的
666
736
* @param row row
@@ -1202,22 +1272,22 @@ public void setOperationTimeout(int operationTimeout) {
1202
1272
(this .operationTimeout != HConstants .DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT ));
1203
1273
}
1204
1274
1205
- // todo
1206
1275
@ Override
1207
1276
public int getOperationTimeout () {
1208
- throw new FeatureNotSupportedException ( "not supported yet." ) ;
1277
+ return operationTimeout ;
1209
1278
}
1210
1279
1211
1280
//todo
1212
1281
@ Override
1213
- public void setRpcTimeout (int i ) {
1214
- throw new FeatureNotSupportedException ("not supported yet." );
1282
+ public void setRpcTimeout (int rpcTimeout ) {
1283
+ this .rpcTimeout = rpcTimeout ;
1284
+ obTableClient .setRpcExecuteTimeout (rpcTimeout );
1215
1285
}
1216
1286
1217
1287
// todo
1218
1288
@ Override
1219
1289
public int getRpcTimeout () {
1220
- throw new FeatureNotSupportedException ( "not supported yet." ) ;
1290
+ return this . rpcTimeout ;
1221
1291
}
1222
1292
1223
1293
public void setRuntimeBatchExecutor (ExecutorService runtimeBatchExecutor ) {
@@ -1376,7 +1446,6 @@ private ObTableQuery buildObTableQuery(ObHTableFilter filter, byte[] start,
1376
1446
obTableQuery .addSelectColumn (column );
1377
1447
}
1378
1448
obTableQuery .addKeyRange (obNewRange );
1379
-
1380
1449
return obTableQuery ;
1381
1450
}
1382
1451
@@ -1391,16 +1460,18 @@ private ObTableQuery buildObTableQuery(ObHTableFilter filter, final Scan scan) {
1391
1460
if (scan .isReversed ()) {
1392
1461
obTableQuery = buildObTableQuery (filter , scan .getStopRow (), false , scan .getStartRow (),
1393
1462
true );
1463
+ obTableQuery .setScanOrder (ObScanOrder .Reverse );
1394
1464
} else {
1395
1465
obTableQuery = buildObTableQuery (filter , scan .getStartRow (), true , scan .getStopRow (),
1396
1466
false );
1397
1467
}
1398
- if (scan .isReversed ()) { // reverse scan 时设置为逆序
1399
- obTableQuery .setScanOrder (ObScanOrder .Reverse );
1400
- }
1401
1468
if (scan .getBatch () > 0 ) {
1402
1469
obTableQuery .setBatchSize (scan .getBatch ());
1403
1470
}
1471
+ obTableQuery .setMaxResultSize (scan .getMaxResultSize () > 0 ? scan .getMaxResultSize ()
1472
+ : configuration .getLong (HConstants .HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE_KEY ,
1473
+ HConstants .DEFAULT_HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE ));
1474
+ obTableQuery .setObKVParams (buildOBKVParams (scan ));
1404
1475
return obTableQuery ;
1405
1476
}
1406
1477
0 commit comments