HBASE-17176 Reuse the builder in RequestConverter (ChiaPing Tsai)
This commit is contained in:
parent
01d3473bf0
commit
219d8a1b71
|
@ -560,10 +560,15 @@ public final class RequestConverter {
|
||||||
|
|
||||||
List<ClientProtos.BulkLoadHFileRequest.FamilyPath> protoFamilyPaths =
|
List<ClientProtos.BulkLoadHFileRequest.FamilyPath> protoFamilyPaths =
|
||||||
new ArrayList<ClientProtos.BulkLoadHFileRequest.FamilyPath>(familyPaths.size());
|
new ArrayList<ClientProtos.BulkLoadHFileRequest.FamilyPath>(familyPaths.size());
|
||||||
for(Pair<byte[], String> el: familyPaths) {
|
if (!familyPaths.isEmpty()) {
|
||||||
protoFamilyPaths.add(ClientProtos.BulkLoadHFileRequest.FamilyPath.newBuilder()
|
ClientProtos.BulkLoadHFileRequest.FamilyPath.Builder pathBuilder
|
||||||
.setFamily(UnsafeByteOperations.unsafeWrap(el.getFirst()))
|
= ClientProtos.BulkLoadHFileRequest.FamilyPath.newBuilder();
|
||||||
.setPath(el.getSecond()).build());
|
for(Pair<byte[], String> el: familyPaths) {
|
||||||
|
protoFamilyPaths.add(pathBuilder
|
||||||
|
.setFamily(UnsafeByteOperations.unsafeWrap(el.getFirst()))
|
||||||
|
.setPath(el.getSecond()).build());
|
||||||
|
}
|
||||||
|
pathBuilder.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
BulkLoadHFileRequest.Builder request =
|
BulkLoadHFileRequest.Builder request =
|
||||||
|
@ -594,6 +599,7 @@ public final class RequestConverter {
|
||||||
final List<Action> actions, final RegionAction.Builder regionActionBuilder,
|
final List<Action> actions, final RegionAction.Builder regionActionBuilder,
|
||||||
final ClientProtos.Action.Builder actionBuilder,
|
final ClientProtos.Action.Builder actionBuilder,
|
||||||
final MutationProto.Builder mutationBuilder) throws IOException {
|
final MutationProto.Builder mutationBuilder) throws IOException {
|
||||||
|
ClientProtos.CoprocessorServiceCall.Builder cpBuilder = null;
|
||||||
for (Action action: actions) {
|
for (Action action: actions) {
|
||||||
Row row = action.getAction();
|
Row row = action.getAction();
|
||||||
actionBuilder.clear();
|
actionBuilder.clear();
|
||||||
|
@ -620,9 +626,13 @@ public final class RequestConverter {
|
||||||
org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString value =
|
org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString value =
|
||||||
org.apache.hadoop.hbase.shaded.com.google.protobuf.UnsafeByteOperations.unsafeWrap(
|
org.apache.hadoop.hbase.shaded.com.google.protobuf.UnsafeByteOperations.unsafeWrap(
|
||||||
exec.getRequest().toByteArray());
|
exec.getRequest().toByteArray());
|
||||||
|
if (cpBuilder == null) {
|
||||||
|
cpBuilder = ClientProtos.CoprocessorServiceCall.newBuilder();
|
||||||
|
} else {
|
||||||
|
cpBuilder.clear();
|
||||||
|
}
|
||||||
regionActionBuilder.addAction(actionBuilder.setServiceCall(
|
regionActionBuilder.addAction(actionBuilder.setServiceCall(
|
||||||
ClientProtos.CoprocessorServiceCall.newBuilder()
|
cpBuilder.setRow(UnsafeByteOperations.unsafeWrap(exec.getRow()))
|
||||||
.setRow(UnsafeByteOperations.unsafeWrap(exec.getRow()))
|
|
||||||
.setServiceName(exec.getMethod().getService().getFullName())
|
.setServiceName(exec.getMethod().getService().getFullName())
|
||||||
.setMethodName(exec.getMethod().getName())
|
.setMethodName(exec.getMethod().getName())
|
||||||
.setRequest(value)));
|
.setRequest(value)));
|
||||||
|
@ -657,7 +667,8 @@ public final class RequestConverter {
|
||||||
final ClientProtos.Action.Builder actionBuilder,
|
final ClientProtos.Action.Builder actionBuilder,
|
||||||
final MutationProto.Builder mutationBuilder) throws IOException {
|
final MutationProto.Builder mutationBuilder) throws IOException {
|
||||||
RegionAction.Builder builder = getRegionActionBuilderWithRegion(
|
RegionAction.Builder builder = getRegionActionBuilderWithRegion(
|
||||||
RegionAction.newBuilder(), regionName);
|
regionActionBuilder, regionName);
|
||||||
|
ClientProtos.CoprocessorServiceCall.Builder cpBuilder = null;
|
||||||
for (Action action: actions) {
|
for (Action action: actions) {
|
||||||
Row row = action.getAction();
|
Row row = action.getAction();
|
||||||
actionBuilder.clear();
|
actionBuilder.clear();
|
||||||
|
@ -703,9 +714,13 @@ public final class RequestConverter {
|
||||||
org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString value =
|
org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString value =
|
||||||
org.apache.hadoop.hbase.shaded.com.google.protobuf.UnsafeByteOperations.unsafeWrap(
|
org.apache.hadoop.hbase.shaded.com.google.protobuf.UnsafeByteOperations.unsafeWrap(
|
||||||
exec.getRequest().toByteArray());
|
exec.getRequest().toByteArray());
|
||||||
|
if (cpBuilder == null) {
|
||||||
|
cpBuilder = ClientProtos.CoprocessorServiceCall.newBuilder();
|
||||||
|
} else {
|
||||||
|
cpBuilder.clear();
|
||||||
|
}
|
||||||
builder.addAction(actionBuilder.setServiceCall(
|
builder.addAction(actionBuilder.setServiceCall(
|
||||||
ClientProtos.CoprocessorServiceCall.newBuilder()
|
cpBuilder.setRow(UnsafeByteOperations.unsafeWrap(exec.getRow()))
|
||||||
.setRow(UnsafeByteOperations.unsafeWrap(exec.getRow()))
|
|
||||||
.setServiceName(exec.getMethod().getService().getFullName())
|
.setServiceName(exec.getMethod().getService().getFullName())
|
||||||
.setMethodName(exec.getMethod().getName())
|
.setMethodName(exec.getMethod().getName())
|
||||||
.setRequest(value)));
|
.setRequest(value)));
|
||||||
|
@ -856,13 +871,16 @@ public final class RequestConverter {
|
||||||
public static UpdateFavoredNodesRequest buildUpdateFavoredNodesRequest(
|
public static UpdateFavoredNodesRequest buildUpdateFavoredNodesRequest(
|
||||||
final List<Pair<HRegionInfo, List<ServerName>>> updateRegionInfos) {
|
final List<Pair<HRegionInfo, List<ServerName>>> updateRegionInfos) {
|
||||||
UpdateFavoredNodesRequest.Builder ubuilder = UpdateFavoredNodesRequest.newBuilder();
|
UpdateFavoredNodesRequest.Builder ubuilder = UpdateFavoredNodesRequest.newBuilder();
|
||||||
for (Pair<HRegionInfo, List<ServerName>> pair : updateRegionInfos) {
|
if (updateRegionInfos != null && !updateRegionInfos.isEmpty()) {
|
||||||
RegionUpdateInfo.Builder builder = RegionUpdateInfo.newBuilder();
|
RegionUpdateInfo.Builder builder = RegionUpdateInfo.newBuilder();
|
||||||
builder.setRegion(HRegionInfo.convert(pair.getFirst()));
|
for (Pair<HRegionInfo, List<ServerName>> pair : updateRegionInfos) {
|
||||||
for (ServerName server : pair.getSecond()) {
|
builder.setRegion(HRegionInfo.convert(pair.getFirst()));
|
||||||
builder.addFavoredNodes(ProtobufUtil.toServerName(server));
|
for (ServerName server : pair.getSecond()) {
|
||||||
}
|
builder.addFavoredNodes(ProtobufUtil.toServerName(server));
|
||||||
ubuilder.addUpdateInfo(builder.build());
|
}
|
||||||
|
ubuilder.addUpdateInfo(builder.build());
|
||||||
|
builder.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ubuilder.build();
|
return ubuilder.build();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue