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
This commit is contained in:
Michael Stack 2013-09-16 21:05:35 +00:00
parent 2ee04ae2cf
commit 10eec81e09
3 changed files with 47 additions and 24 deletions

View File

@ -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();
}
}
}

View File

@ -150,9 +150,9 @@ public final class CellUtil {
* @param cellScannerables
* @return CellScanner interface over <code>cellIterables</code>
*/
public static CellScanner createCellScanner(final List<CellScannable> cellScannerables) {
public static CellScanner createCellScanner(final List<? extends CellScannable> cellScannerables) {
return new CellScanner() {
private final Iterator<CellScannable> iterator = cellScannerables.iterator();
private final Iterator<? extends CellScannable> iterator = cellScannerables.iterator();
private CellScanner cellScanner = null;
@Override

View File

@ -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<Result> results,
private void addResults(final ScanResponse.Builder builder, final List<Result> results,
final RpcController controller) {
if (results == null || results.isEmpty()) return;
RpcCallContext context = RpcServer.getCurrentCall();
if (context != null && context.isClientCellBlockSupport()) {
List<CellScannable> cellScannables = new ArrayList<CellScannable>(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);