001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.ipc; 019 020import java.net.InetAddress; 021import java.security.cert.X509Certificate; 022import java.util.Optional; 023import org.apache.hadoop.hbase.security.User; 024import org.apache.yetus.audience.InterfaceAudience; 025 026import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.VersionInfo; 027 028/** 029 * Interface of all necessary to carry out a RPC service invocation on the server. This interface 030 * focus on the information needed or obtained during the actual execution of the service method. 031 */ 032@InterfaceAudience.Private 033public interface RpcCallContext { 034 /** 035 * Check if the caller who made this IPC call has disconnected. If called from outside the context 036 * of IPC, this does nothing. 037 * @return < 0 if the caller is still connected. The time in ms since the disconnection 038 * otherwise 039 */ 040 long disconnectSince(); 041 042 /** 043 * If the client connected and specified a codec to use, then we will use this codec making 044 * cellblocks to return. If the client did not specify a codec, we assume it does not support 045 * cellblocks and will return all content protobuf'd (though it makes our serving slower). We need 046 * to ask this question per call because a server could be hosting both clients that support 047 * cellblocks while fielding requests from clients that do not. 048 * @return True if the client supports cellblocks, else return all content in pb 049 */ 050 boolean isClientCellBlockSupported(); 051 052 /** 053 * Returns the user credentials associated with the current RPC request or not present if no 054 * credentials were provided. 055 * @return A User 056 */ 057 Optional<User> getRequestUser(); 058 059 /** Returns Current request's user name or not present if none ongoing. */ 060 default Optional<String> getRequestUserName() { 061 return getRequestUser().map(User::getShortName); 062 } 063 064 /** 065 * Returns the TLS certificate(s) that the client presented to this HBase server when making its 066 * connection. TLS is orthogonal to Kerberos, so this is unrelated to 067 * {@link RpcCallContext#getRequestUser()}. Both, one, or neither may be present. 068 */ 069 Optional<X509Certificate[]> getClientCertificateChain(); 070 071 /** Returns Address of remote client in this call */ 072 InetAddress getRemoteAddress(); 073 074 /** Returns the client version info, or null if the information is not present */ 075 VersionInfo getClientVersionInfo(); 076 077 /** 078 * Sets a callback which has to be executed at the end of this RPC call. Such a callback is an 079 * optional one for any Rpc call. 080 */ 081 void setCallBack(RpcCallback callback); 082 083 boolean isRetryImmediatelySupported(); 084 085 /** 086 * The size of response cells that have been accumulated so far. This along with the corresponding 087 * increment call is used to ensure that multi's or scans dont get too excessively large 088 */ 089 long getResponseCellSize(); 090 091 /** 092 * Add on the given amount to the retained cell size. This is not thread safe and not synchronized 093 * at all. If this is used by more than one thread then everything will break. Since this is 094 * called for every row synchronization would be too onerous. 095 */ 096 void incrementResponseCellSize(long cellSize); 097 098 /** 099 * Get the number of block bytes scanned by the current call. In order to serve a response, 1 or 100 * more lower level blocks must be loaded (from disk or cache) and scanned for the requested 101 * cells. This value includes the total block size for each block loaded for the request. 102 */ 103 long getBlockBytesScanned(); 104 105 /** 106 * Increment the number of block bytes scanned by the current call. See 107 * {@link #getBlockBytesScanned()} for details. 108 */ 109 void incrementBlockBytesScanned(long blockSize); 110 111 long getResponseExceptionSize(); 112 113 void incrementResponseExceptionSize(long exceptionSize); 114}