Skip to content

Commit

Permalink
HBASE-27553 Add row param to mutation slow logs (apache#5328)
Browse files Browse the repository at this point in the history
Signed-off-by: Duo Zhang <zhangduo@apache.org>
Signed-off-by: Bryan Beaudreault <bbeaudreault@apache.org>
  • Loading branch information
rmdmattingly authored and bbeaudreault committed Jul 24, 2023
1 parent 2d32e6d commit 18f1b81
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2113,7 +2113,8 @@ public static SlowLogParams getSlowLogParams(Message message, boolean slowLogSca
}
} else if (message instanceof MutationProto) {
MutationProto mutationProto = (MutationProto) message;
String params = "type= " + mutationProto.getMutateType().toString();
String params = "type= " + mutationProto.getMutateType().toString() + ", row= "
+ getStringForByteString(mutationProto.getRow());
return new SlowLogParams(params);
} else if (message instanceof GetRequest) {
GetRequest getRequest = (GetRequest) message;
Expand All @@ -2132,7 +2133,8 @@ public static SlowLogParams getSlowLogParams(Message message, boolean slowLogSca
} else if (message instanceof MutateRequest) {
MutateRequest mutateRequest = (MutateRequest) message;
String regionName = getStringForByteString(mutateRequest.getRegion().getValue());
String params = "region= " + regionName;
String params = "region= " + regionName + ", row= "
+ getStringForByteString(mutateRequest.getMutation().getRow());
return new SlowLogParams(regionName, params);
} else if (message instanceof CoprocessorServiceRequest) {
CoprocessorServiceRequest coprocessorServiceRequest = (CoprocessorServiceRequest) message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Increment;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.SlowLogParams;
import org.apache.hadoop.hbase.io.TimeRange;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
Expand All @@ -62,6 +63,7 @@
import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto.ColumnValue.QualifierValue;
import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto.DeleteType;
import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto.MutationType;
import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos;
import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.NameBytesPair;
import org.apache.hadoop.hbase.shaded.protobuf.generated.LockServiceProtos;
import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos;
Expand Down Expand Up @@ -574,4 +576,32 @@ public void testTagEncodeTrueDecodeFalse() {
List<Tag> decodedTags = PrivateCellUtil.getTags(decodedCell);
assertEquals(0, decodedTags.size());
}

@Test
public void testSlowLogParamsMutationProto() {
MutationProto mutationProto =
ClientProtos.MutationProto.newBuilder().setRow(ByteString.copyFromUtf8("row123")).build();

SlowLogParams slowLogParams = ProtobufUtil.getSlowLogParams(mutationProto, false);

assertTrue(slowLogParams.getParams()
.contains(Bytes.toStringBinary(mutationProto.getRow().toByteArray())));
}

@Test
public void testSlowLogParamsMutateRequest() {
MutationProto mutationProto =
ClientProtos.MutationProto.newBuilder().setRow(ByteString.copyFromUtf8("row123")).build();
ClientProtos.MutateRequest mutateRequest =
ClientProtos.MutateRequest.newBuilder().setMutation(mutationProto)
.setRegion(HBaseProtos.RegionSpecifier.newBuilder()
.setType(HBaseProtos.RegionSpecifier.RegionSpecifierType.REGION_NAME)
.setValue(ByteString.EMPTY).build())
.build();

SlowLogParams slowLogParams = ProtobufUtil.getSlowLogParams(mutateRequest, false);

assertTrue(slowLogParams.getParams()
.contains(Bytes.toStringBinary(mutationProto.getRow().toByteArray())));
}
}

0 comments on commit 18f1b81

Please sign in to comment.