xcangCRM commented on a change in pull request #754: HBASE-22978 : Online slow
response log
URL: https://github.com/apache/hbase/pull/754#discussion_r358517762
##########
File path:
hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/ProtobufUtil.java
##########
@@ -2205,6 +2216,57 @@ private static String getStringForByteString(ByteString
bs) {
return Bytes.toStringBinary(bs.toByteArray());
}
+ /**
+ * Return SlowLogParams to maintain recent online slowlog responses
+ *
+ * @param message Message object {@link Message}
+ * @return SlowLogParams with regionName(for filter queries) and params
+ */
+ public static SlowLogParams getSlowLogParams(Message message) {
+ if (message == null) {
+ return null;
+ }
+ if (message instanceof ScanRequest) {
+ ScanRequest scanRequest = (ScanRequest) message;
+ String regionName =
getStringForByteString(scanRequest.getRegion().getValue());
+ String params = TextFormat.shortDebugString(message);
+ return new SlowLogParams(regionName, params);
+ } else if (message instanceof MutationProto) {
+ MutationProto mutationProto = (MutationProto) message;
+ String params = "type= " + mutationProto.getMutateType().toString();
+ return new SlowLogParams(StringUtils.EMPTY, params);
+ } else if (message instanceof GetRequest) {
+ GetRequest getRequest = (GetRequest) message;
+ String regionName =
getStringForByteString(getRequest.getRegion().getValue());
+ String params = "region= " + regionName + ", row= "
+ + getStringForByteString(getRequest.getGet().getRow());
+ return new SlowLogParams(regionName, params);
+ } else if (message instanceof MultiRequest) {
+ MultiRequest multiRequest = (MultiRequest) message;
+ int actionsCount = multiRequest.getRegionActionList()
+ .stream()
+ .mapToInt(ClientProtos.RegionAction::getActionCount)
+ .sum();
+ RegionAction actions = multiRequest.getRegionActionList().get(0);
+ String regionName =
getStringForByteString(actions.getRegion().getValue());
+ String params = "region= " + regionName + ", for " + actionsCount + "
action(s)";
+ return new SlowLogParams(regionName, params);
+ } else if (message instanceof MutateRequest) {
+ MutateRequest mutateRequest = (MutateRequest) message;
+ String regionName =
getStringForByteString(mutateRequest.getRegion().getValue());
+ String params = "region= " + regionName;
+ return new SlowLogParams(regionName, params);
+ } else if (message instanceof CoprocessorServiceRequest) {
+ CoprocessorServiceRequest coprocessorServiceRequest =
(CoprocessorServiceRequest) message;
+ String params = "coprocessorService= "
+ + coprocessorServiceRequest.getCall().getServiceName()
+ + ":" + coprocessorServiceRequest.getCall().getMethodName();
+ return new SlowLogParams(StringUtils.EMPTY, params);
+ }
Review comment:
should you handle the case that message is not type of either one checked
above?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services