@@ -87,7 +87,7 @@ public class TestRequestAttributes {
87
87
ROW_KEY_TO_REQUEST_ATTRIBUTES .put (ROW_KEY5 , addRandomRequestAttributes ());
88
88
ROW_KEY_TO_REQUEST_ATTRIBUTES .put (ROW_KEY6 , addRandomRequestAttributes ());
89
89
ROW_KEY_TO_REQUEST_ATTRIBUTES .put (ROW_KEY7 , addRandomRequestAttributes ());
90
- ROW_KEY_TO_REQUEST_ATTRIBUTES .put (ROW_KEY8 , new HashMap <>());
90
+ ROW_KEY_TO_REQUEST_ATTRIBUTES .put (ROW_KEY8 , new HashMap <String , byte [] >());
91
91
}
92
92
private static final ExecutorService EXECUTOR_SERVICE = Executors .newFixedThreadPool (100 );
93
93
private static final byte [] FAMILY = Bytes .toBytes ("0" );
@@ -316,20 +316,26 @@ public Optional<RegionObserver> getRegionObserver() {
316
316
@ Override
317
317
public void preGetOp (ObserverContext <RegionCoprocessorEnvironment > c , Get get ,
318
318
List <Cell > result ) throws IOException {
319
- validateRequestAttributes (getRequestAttributesForRowKey (get .getRow ()));
319
+ if (!isValidRequestAttributes (getRequestAttributesForRowKey (get .getRow ()))) {
320
+ throw new IOException ("Incorrect request attributes" );
321
+ }
320
322
}
321
323
322
324
@ Override
323
325
public boolean preScannerNext (ObserverContext <RegionCoprocessorEnvironment > c ,
324
326
InternalScanner s , List <Result > result , int limit , boolean hasNext ) throws IOException {
325
- validateRequestAttributes (REQUEST_ATTRIBUTES_SCAN );
327
+ if (!isValidRequestAttributes (REQUEST_ATTRIBUTES_SCAN )) {
328
+ throw new IOException ("Incorrect request attributes" );
329
+ }
326
330
return hasNext ;
327
331
}
328
332
329
333
@ Override
330
334
public void prePut (ObserverContext <RegionCoprocessorEnvironment > c , Put put , WALEdit edit )
331
335
throws IOException {
332
- validateRequestAttributes (getRequestAttributesForRowKey (put .getRow ()));
336
+ if (!isValidRequestAttributes (getRequestAttributesForRowKey (put .getRow ()))) {
337
+ throw new IOException ("Incorrect request attributes" );
338
+ }
333
339
}
334
340
335
341
private Map <String , byte []> getRequestAttributesForRowKey (byte [] rowKey ) {
@@ -341,20 +347,21 @@ private Map<String, byte[]> getRequestAttributesForRowKey(byte[] rowKey) {
341
347
return null ;
342
348
}
343
349
344
- private void validateRequestAttributes (Map <String , byte []> requestAttributes ) {
350
+ private boolean isValidRequestAttributes (Map <String , byte []> requestAttributes ) {
345
351
RpcCall rpcCall = RpcServer .getCurrentCall ().get ();
346
352
Map <String , byte []> attrs = rpcCall .getRequestAttributes ();
347
353
if (attrs .size () != requestAttributes .size ()) {
348
- return ;
354
+ return false ;
349
355
}
350
356
for (Map .Entry <String , byte []> attr : attrs .entrySet ()) {
351
357
if (!requestAttributes .containsKey (attr .getKey ())) {
352
- return ;
358
+ return false ;
353
359
}
354
360
if (!Arrays .equals (requestAttributes .get (attr .getKey ()), attr .getValue ())) {
355
- return ;
361
+ return false ;
356
362
}
357
363
}
364
+ return true ;
358
365
}
359
366
}
360
367
}
0 commit comments