From 10eec81e09695e0ba6b8ca36b8a866d66d0d9dd7 Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Mon, 16 Sep 2013 21:05:35 +0000 Subject: [PATCH] HBASE-9541 icv fails w/ npe if client does not support cellblocks git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1523812 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/hadoop/hbase/client/HTable.java | 15 +++++- .../org/apache/hadoop/hbase/CellUtil.java | 4 +- .../hbase/regionserver/HRegionServer.java | 52 +++++++++++-------- 3 files changed, 47 insertions(+), 24 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java index a649e621786..da53bec7811 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java @@ -1617,4 +1617,17 @@ public class HTable implements HTableInterface { return operationTimeout; } -} + /** + * Run basic test. + * @param args Pass table name and row and will get the content. + * @throws IOException + */ + public static void main(String[] args) throws IOException { + HTable t = new HTable(HBaseConfiguration.create(), args[0]); + try { + System.out.println(t.get(new Get(Bytes.toBytes(args[1])))); + } finally { + t.close(); + } + } +} \ No newline at end of file diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java index 0f2b753c859..7728b7d211a 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java @@ -150,9 +150,9 @@ public final class CellUtil { * @param cellScannerables * @return CellScanner interface over cellIterables */ - public static CellScanner createCellScanner(final List cellScannerables) { + public static CellScanner createCellScanner(final List cellScannerables) { return new CellScanner() { - private final Iterator iterator = cellScannerables.iterator(); + private final Iterator iterator = cellScannerables.iterator(); private CellScanner cellScanner = null; @Override diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index 3794fedd6d1..56c844ccedc 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -875,7 +875,7 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa mxBean = null; } if (this.thriftServer != null) this.thriftServer.shutdown(); - this.leases.closeAfterLeasesExpire(); + if (this.leases != null) this.leases.closeAfterLeasesExpire(); this.rpcServer.stop(); if (this.splitLogWorker != null) { splitLogWorker.stop(); @@ -2785,7 +2785,8 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa if (existence != null) { builder.setExists(existence.booleanValue()); } else if (r != null) { - builder.setResult(ProtobufUtil.toResult(r)); + ClientProtos.Result pbr = ProtobufUtil.toResult(r); + builder.setResult(pbr); } return builder.build(); } catch (IOException ie) { @@ -2810,8 +2811,7 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa requestCount.add(request.getGetCount()); HRegion region = getRegion(request.getRegion()); MultiGetResponse.Builder builder = MultiGetResponse.newBuilder(); - for (ClientProtos.Get get: request.getGetList()) - { + for (ClientProtos.Get get: request.getGetList()) { Boolean existence = null; Result r = null; if (request.getClosestRowBefore()) { @@ -2947,16 +2947,8 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa throw new DoNotRetryIOException( "Unsupported mutate type: " + type.name()); } - CellScannable cellsToReturn = null; - if (processed != null) { - builder.setProcessed(processed.booleanValue()); - } else if (r != null) { - builder.setResult(ProtobufUtil.toResultNoData(r)); - cellsToReturn = r; - } - if (controller != null && cellsToReturn != null) { - controller.setCellScanner(cellsToReturn.cellScanner()); - } + if (processed != null) builder.setProcessed(processed.booleanValue()); + addResult(builder, r, controller); return builder.build(); } catch (IOException ie) { checkFileSystem(); @@ -2964,6 +2956,27 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa } } + + /** + * @return True if current call supports cellblocks + */ + private boolean isClientCellBlockSupport() { + RpcCallContext context = RpcServer.getCurrentCall(); + return context != null && context.isClientCellBlockSupport(); + } + + private void addResult(final MutateResponse.Builder builder, + final Result result, final PayloadCarryingRpcController rpcc) { + if (result == null) return; + if (isClientCellBlockSupport()) { + builder.setResult(ProtobufUtil.toResultNoData(result)); + rpcc.setCellScanner(result.cellScanner()); + } else { + ClientProtos.Result pbr = ProtobufUtil.toResult(result); + builder.setResult(pbr); + } + } + // // remote scanner interface // @@ -3148,7 +3161,7 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa moreResults = false; results = null; } else { - formatResults(builder, results, controller); + addResults(builder, results, controller); } } finally { // We're done. On way out re-add the above removed lease. @@ -3196,18 +3209,15 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa } } - private void formatResults(final ScanResponse.Builder builder, final List results, + private void addResults(final ScanResponse.Builder builder, final List results, final RpcController controller) { if (results == null || results.isEmpty()) return; - RpcCallContext context = RpcServer.getCurrentCall(); - if (context != null && context.isClientCellBlockSupport()) { - List cellScannables = new ArrayList(results.size()); + if (isClientCellBlockSupport()) { for (Result res : results) { - cellScannables.add(res); builder.addCellsPerResult(res.size()); } ((PayloadCarryingRpcController)controller). - setCellScanner(CellUtil.createCellScanner(cellScannables)); + setCellScanner(CellUtil.createCellScanner(results)); } else { for (Result res: results) { ClientProtos.Result pbr = ProtobufUtil.toResult(res);