HBASE-17176 Reuse the builder in RequestConverter (ChiaPing Tsai)
This commit is contained in:
parent
01d3473bf0
commit
219d8a1b71
|
@ -560,11 +560,16 @@ 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());
|
||||||
|
if (!familyPaths.isEmpty()) {
|
||||||
|
ClientProtos.BulkLoadHFileRequest.FamilyPath.Builder pathBuilder
|
||||||
|
= ClientProtos.BulkLoadHFileRequest.FamilyPath.newBuilder();
|
||||||
for(Pair<byte[], String> el: familyPaths) {
|
for(Pair<byte[], String> el: familyPaths) {
|
||||||
protoFamilyPaths.add(ClientProtos.BulkLoadHFileRequest.FamilyPath.newBuilder()
|
protoFamilyPaths.add(pathBuilder
|
||||||
.setFamily(UnsafeByteOperations.unsafeWrap(el.getFirst()))
|
.setFamily(UnsafeByteOperations.unsafeWrap(el.getFirst()))
|
||||||
.setPath(el.getSecond()).build());
|
.setPath(el.getSecond()).build());
|
||||||
}
|
}
|
||||||
|
pathBuilder.clear();
|
||||||
|
}
|
||||||
|
|
||||||
BulkLoadHFileRequest.Builder request =
|
BulkLoadHFileRequest.Builder request =
|
||||||
ClientProtos.BulkLoadHFileRequest.newBuilder()
|
ClientProtos.BulkLoadHFileRequest.newBuilder()
|
||||||
|
@ -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();
|
||||||
|
for (Pair<HRegionInfo, List<ServerName>> pair : updateRegionInfos) {
|
||||||
builder.setRegion(HRegionInfo.convert(pair.getFirst()));
|
builder.setRegion(HRegionInfo.convert(pair.getFirst()));
|
||||||
for (ServerName server : pair.getSecond()) {
|
for (ServerName server : pair.getSecond()) {
|
||||||
builder.addFavoredNodes(ProtobufUtil.toServerName(server));
|
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