diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Classes.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Classes.java
index 2366dafc17b..c52a09c8a6f 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Classes.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Classes.java
@@ -17,7 +17,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.hadoop.hbase.util;
import org.apache.yetus.audience.InterfaceAudience;
@@ -31,7 +30,7 @@ public class Classes {
/**
* Equivalent of {@link Class#forName(String)} which also returns classes for
* primitives like boolean, etc.
- *
+ *
* @param className
* The name of the class to retrieve. Can be either a normal class or
* a primitive class.
@@ -64,10 +63,10 @@ public class Classes {
return valueType;
}
- public static String stringify(Class[] classes) {
+ public static String stringify(Class>[] classes) {
StringBuilder buf = new StringBuilder();
if (classes != null) {
- for (Class c : classes) {
+ for (Class> c : classes) {
if (buf.length() > 0) {
buf.append(",");
}
@@ -78,4 +77,9 @@ public class Classes {
}
return buf.toString();
}
+
+ @SuppressWarnings("unchecked")
+ public static Class cast(Class> clazz) {
+ return (Class) clazz;
+ }
}
diff --git a/hbase-endpoint/src/main/java/org/apache/hadoop/hbase/coprocessor/Export.java b/hbase-endpoint/src/main/java/org/apache/hadoop/hbase/coprocessor/Export.java
index 667f7a3dfa3..a00af0f9a17 100644
--- a/hbase-endpoint/src/main/java/org/apache/hadoop/hbase/coprocessor/Export.java
+++ b/hbase-endpoint/src/main/java/org/apache/hadoop/hbase/coprocessor/Export.java
@@ -453,10 +453,7 @@ public class Export extends ExportProtos.ExportService implements RegionCoproces
}
private static User getActiveUser(final UserProvider userProvider, final Token userToken) throws IOException {
- User user = RpcServer.getRequestUser();
- if (user == null) {
- user = userProvider.getCurrent();
- }
+ User user = RpcServer.getRequestUser().orElse(userProvider.getCurrent());
if (user == null && userToken != null) {
LOG.warn("No found of user credentials, but a token was got from user request");
} else if (user != null && userToken != null) {
diff --git a/hbase-endpoint/src/test/java/org/apache/hadoop/hbase/coprocessor/ProtobufCoprocessorService.java b/hbase-endpoint/src/test/java/org/apache/hadoop/hbase/coprocessor/ProtobufCoprocessorService.java
index c69baeeef18..6fc4eb9886a 100644
--- a/hbase-endpoint/src/test/java/org/apache/hadoop/hbase/coprocessor/ProtobufCoprocessorService.java
+++ b/hbase-endpoint/src/test/java/org/apache/hadoop/hbase/coprocessor/ProtobufCoprocessorService.java
@@ -79,8 +79,8 @@ public class ProtobufCoprocessorService extends TestRpcServiceProtos.TestProtobu
@Override
public void addr(RpcController controller, EmptyRequestProto request,
RpcCallback done) {
- done.run(AddrResponseProto.newBuilder().setAddr(RpcServer.getRemoteAddress().getHostAddress())
- .build());
+ done.run(AddrResponseProto.newBuilder()
+ .setAddr(RpcServer.getRemoteAddress().get().getHostAddress()).build());
}
@Override
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/client/VersionInfoUtil.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/client/VersionInfoUtil.java
index 1866c209e85..95984de1845 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/client/VersionInfoUtil.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/client/VersionInfoUtil.java
@@ -71,8 +71,7 @@ public final class VersionInfoUtil {
* @return the versionInfo extracted from the current RpcCallContext
*/
private static HBaseProtos.VersionInfo getCurrentClientVersionInfo() {
- RpcCallContext call = RpcServer.getCurrentCall();
- return call != null ? call.getClientVersionInfo() : null;
+ return RpcServer.getCurrentCall().map(RpcCallContext::getClientVersionInfo).orElse(null);
}
/**
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/CoprocessorHost.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/CoprocessorHost.java
index da07c40a698..07e5a3a0ccc 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/CoprocessorHost.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/CoprocessorHost.java
@@ -549,7 +549,7 @@ public abstract class CoprocessorHost observerGetter;
ObserverOperation(ObserverGetter observerGetter) {
- this(observerGetter, RpcServer.getRequestUser());
+ this(observerGetter, RpcServer.getRequestUser().orElse(null));
}
ObserverOperation(ObserverGetter observerGetter, User user) {
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/ObserverContext.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/ObserverContext.java
index 0192ea37680..3110abc7360 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/ObserverContext.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/ObserverContext.java
@@ -1,5 +1,4 @@
/*
- *
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -16,16 +15,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.hadoop.hbase.coprocessor;
-import edu.umd.cs.findbugs.annotations.Nullable;
-import org.apache.yetus.audience.InterfaceAudience;
-import org.apache.yetus.audience.InterfaceStability;
+import java.util.Optional;
+
+import com.google.common.annotations.VisibleForTesting;
import org.apache.hadoop.hbase.CoprocessorEnvironment;
import org.apache.hadoop.hbase.HBaseInterfaceAudience;
import org.apache.hadoop.hbase.ipc.RpcServer;
import org.apache.hadoop.hbase.security.User;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.apache.yetus.audience.InterfaceStability;
/**
* Carries the execution state for a given invocation of an Observer coprocessor
@@ -43,8 +43,9 @@ public class ObserverContext {
private E env;
private boolean bypass;
private boolean complete;
- private User caller;
+ private final User caller;
+ @InterfaceAudience.Private
public ObserverContext(User caller) {
this.caller = caller;
}
@@ -53,6 +54,7 @@ public class ObserverContext {
return env;
}
+ @InterfaceAudience.Private
public void prepare(E env) {
this.env = env;
}
@@ -97,58 +99,30 @@ public class ObserverContext {
}
/**
- * Returns the active user for the coprocessor call.
- * If an explicit {@code User} instance was provided to the constructor, that will be returned,
- * otherwise if we are in the context of an RPC call, the remote user is used. May return null
- * if the execution is outside of an RPC context.
+ * Returns the active user for the coprocessor call. If an explicit {@code User} instance was
+ * provided to the constructor, that will be returned, otherwise if we are in the context of an
+ * RPC call, the remote user is used. May not be present if the execution is outside of an RPC
+ * context.
*/
- @Nullable
- public User getCaller() {
- return caller;
+ public Optional getCaller() {
+ return Optional.ofNullable(caller);
}
/**
- * Instantiates a new ObserverContext instance if the passed reference is
- * null and sets the environment in the new or existing instance.
- * This allows deferring the instantiation of a ObserverContext until it is
- * actually needed.
- *
- * @param env The coprocessor environment to set
- * @param context An existing ObserverContext instance to use, or null
- * to create a new instance
+ * Instantiates a new ObserverContext instance if the passed reference is null and
+ * sets the environment in the new or existing instance. This allows deferring the instantiation
+ * of a ObserverContext until it is actually needed.
* @param The environment type for the context
+ * @param env The coprocessor environment to set
* @return An instance of ObserverContext with the environment set
*/
@Deprecated
+ @InterfaceAudience.Private
+ @VisibleForTesting
// TODO: Remove this method, ObserverContext should not depend on RpcServer
- public static ObserverContext createAndPrepare(
- E env, ObserverContext< E> context) {
- if (context == null) {
- context = new ObserverContext<>(RpcServer.getRequestUser());
- }
- context.prepare(env);
- return context;
- }
-
- /**
- * Instantiates a new ObserverContext instance if the passed reference is
- * null and sets the environment in the new or existing instance.
- * This allows deferring the instantiation of a ObserverContext until it is
- * actually needed.
- *
- * @param env The coprocessor environment to set
- * @param context An existing ObserverContext instance to use, or null
- * to create a new instance
- * @param user The requesting caller for the execution context
- * @param The environment type for the context
- * @return An instance of ObserverContext with the environment set
- */
- public static ObserverContext createAndPrepare(
- E env, ObserverContext context, User user) {
- if (context == null) {
- context = new ObserverContext<>(user);
- }
- context.prepare(env);
- return context;
+ public static ObserverContext createAndPrepare(E env) {
+ ObserverContext ctx = new ObserverContext<>(RpcServer.getRequestUser().orElse(null));
+ ctx.prepare(env);
+ return ctx;
}
}
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/CallRunner.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/CallRunner.java
index a8d220802b8..d4fc70624ed 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/CallRunner.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/CallRunner.java
@@ -19,6 +19,7 @@ package org.apache.hadoop.hbase.ipc;
import java.net.InetSocketAddress;
import java.nio.channels.ClosedChannelException;
+import java.util.Optional;
import org.apache.hadoop.hbase.CallDroppedException;
import org.apache.hadoop.hbase.CellScanner;
@@ -107,9 +108,9 @@ public class CallRunner {
this.status.setStatus("Setting up call");
this.status.setConnection(call.getRemoteAddress().getHostAddress(), call.getRemotePort());
if (RpcServer.LOG.isTraceEnabled()) {
- User remoteUser = call.getRequestUser();
+ Optional remoteUser = call.getRequestUser();
RpcServer.LOG.trace(call.toShortString() + " executing as " +
- ((remoteUser == null) ? "NULL principal" : remoteUser.getName()));
+ (remoteUser.isPresent() ? "NULL principal" : remoteUser.get().getName()));
}
Throwable errorThrowable = null;
String error = null;
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcCallContext.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcCallContext.java
index df3befdac60..6a4d3a29a52 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcCallContext.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcCallContext.java
@@ -18,6 +18,7 @@
package org.apache.hadoop.hbase.ipc;
import java.net.InetAddress;
+import java.util.Optional;
import org.apache.yetus.audience.InterfaceAudience;
import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.VersionInfo;
@@ -48,16 +49,18 @@ public interface RpcCallContext {
boolean isClientCellBlockSupported();
/**
- * Returns the user credentials associated with the current RPC request or
- * null if no credentials were provided.
+ * Returns the user credentials associated with the current RPC request or not present if no
+ * credentials were provided.
* @return A User
*/
- User getRequestUser();
+ Optional getRequestUser();
/**
- * @return Current request's user name or null if none ongoing.
+ * @return Current request's user name or not present if none ongoing.
*/
- String getRequestUserName();
+ default Optional getRequestUserName() {
+ return getRequestUser().map(User::getShortName);
+ }
/**
* @return Address of remote client in this call
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java
index 22a0cf2a514..36d383a3e4f 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java
@@ -20,8 +20,6 @@ package org.apache.hadoop.hbase.ipc;
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION;
-import org.apache.hadoop.hbase.shaded.com.google.common.annotations.VisibleForTesting;
-
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
@@ -35,6 +33,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Optional;
import java.util.concurrent.atomic.LongAdder;
import org.apache.commons.logging.Log;
@@ -46,8 +45,6 @@ import org.apache.hadoop.hbase.DoNotRetryIOException;
import org.apache.hadoop.hbase.HBaseInterfaceAudience;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.Server;
-import org.apache.yetus.audience.InterfaceAudience;
-import org.apache.yetus.audience.InterfaceStability;
import org.apache.hadoop.hbase.conf.ConfigurationObserver;
import org.apache.hadoop.hbase.exceptions.RequestTooBigException;
import org.apache.hadoop.hbase.io.ByteBufferPool;
@@ -62,6 +59,18 @@ import org.apache.hadoop.hbase.security.SaslUtil.QualityOfProtection;
import org.apache.hadoop.hbase.security.User;
import org.apache.hadoop.hbase.security.UserProvider;
import org.apache.hadoop.hbase.security.token.AuthenticationTokenSecretManager;
+import org.apache.hadoop.hbase.util.Pair;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.security.authorize.AuthorizationException;
+import org.apache.hadoop.security.authorize.PolicyProvider;
+import org.apache.hadoop.security.authorize.ServiceAuthorizationManager;
+import org.apache.hadoop.security.token.SecretManager;
+import org.apache.hadoop.security.token.TokenIdentifier;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.apache.yetus.audience.InterfaceStability;
+import org.codehaus.jackson.map.ObjectMapper;
+
+import org.apache.hadoop.hbase.shaded.com.google.common.annotations.VisibleForTesting;
import org.apache.hadoop.hbase.shaded.com.google.protobuf.BlockingService;
import org.apache.hadoop.hbase.shaded.com.google.protobuf.Descriptors.MethodDescriptor;
import org.apache.hadoop.hbase.shaded.com.google.protobuf.Message;
@@ -70,14 +79,6 @@ import org.apache.hadoop.hbase.shaded.com.google.protobuf.TextFormat;
import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos;
import org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.ConnectionHeader;
-import org.apache.hadoop.hbase.util.Pair;
-import org.apache.hadoop.security.UserGroupInformation;
-import org.apache.hadoop.security.authorize.AuthorizationException;
-import org.apache.hadoop.security.authorize.PolicyProvider;
-import org.apache.hadoop.security.authorize.ServiceAuthorizationManager;
-import org.apache.hadoop.security.token.SecretManager;
-import org.apache.hadoop.security.token.TokenIdentifier;
-import org.codehaus.jackson.map.ObjectMapper;
/**
* An RPC server that hosts protobuf described Services.
@@ -678,8 +679,8 @@ public abstract class RpcServer implements RpcServerInterface,
* call.
* @return An RpcCallContext backed by the currently ongoing call (gotten from a thread local)
*/
- public static RpcCall getCurrentCall() {
- return CurCall.get();
+ public static Optional getCurrentCall() {
+ return Optional.ofNullable(CurCall.get());
}
public static boolean isInRpcCallContext() {
@@ -687,13 +688,13 @@ public abstract class RpcServer implements RpcServerInterface,
}
/**
- * Returns the user credentials associated with the current RPC request or
- * null if no credentials were provided.
+ * Returns the user credentials associated with the current RPC request or not present if no
+ * credentials were provided.
* @return A User
*/
- public static User getRequestUser() {
- RpcCallContext ctx = getCurrentCall();
- return ctx == null? null: ctx.getRequestUser();
+ public static Optional getRequestUser() {
+ Optional ctx = getCurrentCall();
+ return ctx.isPresent() ? ctx.get().getRequestUser() : Optional.empty();
}
/**
@@ -704,19 +705,17 @@ public abstract class RpcServer implements RpcServerInterface,
/**
* Returns the username for any user associated with the current RPC
- * request or null if no user is set.
+ * request or not present if no user is set.
*/
- public static String getRequestUserName() {
- User user = getRequestUser();
- return user == null? null: user.getShortName();
+ public static Optional getRequestUserName() {
+ return getRequestUser().map(User::getShortName);
}
/**
* @return Address of remote client if a request is ongoing, else null
*/
- public static InetAddress getRemoteAddress() {
- RpcCallContext ctx = getCurrentCall();
- return ctx == null? null: ctx.getRemoteAddress();
+ public static Optional getRemoteAddress() {
+ return getCurrentCall().map(RpcCall::getRemoteAddress);
}
/**
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/ServerCall.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/ServerCall.java
index 2baba9ff606..60fe30e954b 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/ServerCall.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/ServerCall.java
@@ -22,6 +22,7 @@ import java.net.InetAddress;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
import org.apache.hadoop.hbase.CellScanner;
import org.apache.hadoop.hbase.DoNotRetryIOException;
@@ -82,7 +83,7 @@ abstract class ServerCall implements RpcCall, Rpc
protected ByteBufferListOutputStream cellBlockStream = null;
protected CallCleanup reqCleanup = null;
- protected User user;
+ protected final User user;
protected final InetAddress remoteAddress;
protected RpcCallback rpcCallback;
@@ -110,10 +111,14 @@ abstract class ServerCall implements RpcCall, Rpc
this.isError = false;
this.size = size;
this.tinfo = tinfo;
- this.user = connection == null ? null : connection.user; // FindBugs: NP_NULL_ON_SOME_PATH
+ if (connection != null) {
+ this.user = connection.user;
+ this.retryImmediatelySupported = connection.retryImmediatelySupported;
+ } else {
+ this.user = null;
+ this.retryImmediatelySupported = false;
+ }
this.remoteAddress = remoteAddress;
- this.retryImmediatelySupported =
- connection == null ? false : connection.retryImmediatelySupported;
this.timeout = timeout;
this.deadline = this.timeout > 0 ? this.receiveTime + this.timeout : Long.MAX_VALUE;
this.reservoir = reservoir;
@@ -432,14 +437,8 @@ abstract class ServerCall implements RpcCall, Rpc
}
@Override
- public User getRequestUser() {
- return user;
- }
-
- @Override
- public String getRequestUserName() {
- User user = getRequestUser();
- return user == null? null: user.getShortName();
+ public Optional getRequestUser() {
+ return Optional.ofNullable(user);
}
@Override
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/SimpleRpcScheduler.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/SimpleRpcScheduler.java
index 2c5d4b2acfd..f40959ae591 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/SimpleRpcScheduler.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/SimpleRpcScheduler.java
@@ -154,7 +154,8 @@ public class SimpleRpcScheduler extends RpcScheduler implements ConfigurationObs
@Override
public boolean dispatch(CallRunner callTask) throws InterruptedException {
RpcCall call = callTask.getRpcCall();
- int level = priority.getPriority(call.getHeader(), call.getParam(), call.getRequestUser());
+ int level = priority.getPriority(call.getHeader(), call.getParam(),
+ call.getRequestUser().orElse(null));
if (level == HConstants.PRIORITY_UNSET) {
level = HConstants.NORMAL_QOS;
}
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/MasterProcedureEnv.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/MasterProcedureEnv.java
index fe3b9b403d5..f294f57b621 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/MasterProcedureEnv.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/MasterProcedureEnv.java
@@ -110,11 +110,7 @@ public class MasterProcedureEnv implements ConfigurationObserver {
}
public User getRequestUser() {
- User user = RpcServer.getRequestUser();
- if (user == null) {
- user = Superusers.getSystemUser();
- }
- return user;
+ return RpcServer.getRequestUser().orElse(Superusers.getSystemUser());
}
public MasterServices getMasterServices() {
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotManager.java
index 7bd069ba64a..20a4f39935e 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotManager.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotManager.java
@@ -41,8 +41,6 @@ import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.MetaTableAccessor;
import org.apache.hadoop.hbase.Stoppable;
import org.apache.hadoop.hbase.TableName;
-import org.apache.yetus.audience.InterfaceAudience;
-import org.apache.yetus.audience.InterfaceStability;
import org.apache.hadoop.hbase.client.TableDescriptor;
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.apache.hadoop.hbase.client.TableState;
@@ -65,13 +63,8 @@ import org.apache.hadoop.hbase.procedure.ProcedureCoordinator;
import org.apache.hadoop.hbase.procedure.ProcedureCoordinatorRpcs;
import org.apache.hadoop.hbase.procedure.ZKProcedureCoordinator;
import org.apache.hadoop.hbase.procedure2.ProcedureExecutor;
-import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
-import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.NameStringPair;
-import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.ProcedureDescription;
import org.apache.hadoop.hbase.security.AccessDeniedException;
import org.apache.hadoop.hbase.security.User;
-import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription;
-import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription.Type;
import org.apache.hadoop.hbase.snapshot.ClientSnapshotDescriptionUtils;
import org.apache.hadoop.hbase.snapshot.HBaseSnapshotException;
import org.apache.hadoop.hbase.snapshot.RestoreSnapshotException;
@@ -87,8 +80,16 @@ import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.FSUtils;
import org.apache.hadoop.hbase.util.KeyLocker;
import org.apache.hadoop.hbase.util.NonceKey;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.apache.yetus.audience.InterfaceStability;
import org.apache.zookeeper.KeeperException;
+import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
+import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.NameStringPair;
+import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.ProcedureDescription;
+import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription;
+import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription.Type;
+
/**
* This class manages the procedure of taking and restoring snapshots. There is only one
* SnapshotManager for the master.
@@ -586,10 +587,11 @@ public class SnapshotManager extends MasterProcedureManager implements Stoppable
if (!snapshot.hasVersion()) {
builder.setVersion(SnapshotDescriptionUtils.SNAPSHOT_LAYOUT_VERSION);
}
- User user = RpcServer.getRequestUser();
- if (User.isHBaseSecurityEnabled(master.getConfiguration()) && user != null) {
- builder.setOwner(user.getShortName());
- }
+ RpcServer.getRequestUser().ifPresent(user -> {
+ if (User.isHBaseSecurityEnabled(master.getConfiguration())) {
+ builder.setOwner(user.getShortName());
+ }
+ });
snapshot = builder.build();
// call pre coproc hook
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/RegionServerRpcQuotaManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/RegionServerRpcQuotaManager.java
index f51e605d260..69253d7306d 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/RegionServerRpcQuotaManager.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/RegionServerRpcQuotaManager.java
@@ -176,13 +176,7 @@ public class RegionServerRpcQuotaManager {
private OperationQuota checkQuota(final Region region,
final int numWrites, final int numReads, final int numScans)
throws IOException, ThrottlingException {
- User user = RpcServer.getRequestUser();
- UserGroupInformation ugi;
- if (user != null) {
- ugi = user.getUGI();
- } else {
- ugi = User.getCurrent().getUGI();
- }
+ UserGroupInformation ugi = RpcServer.getRequestUser().orElse(User.getCurrent()).getUGI();
TableName table = region.getTableDescriptor().getTableName();
OperationQuota quota = getQuota(ugi, table);
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
index 80c043379f0..2d35fb96a72 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
@@ -135,7 +135,6 @@ import org.apache.hadoop.hbase.io.hfile.HFile;
import org.apache.hadoop.hbase.ipc.CallerDisconnectedException;
import org.apache.hadoop.hbase.ipc.CoprocessorRpcUtils;
import org.apache.hadoop.hbase.ipc.RpcCall;
-import org.apache.hadoop.hbase.ipc.RpcCallContext;
import org.apache.hadoop.hbase.ipc.RpcServer;
import org.apache.hadoop.hbase.monitoring.MonitoredTask;
import org.apache.hadoop.hbase.monitoring.TaskMonitor;
@@ -5375,12 +5374,15 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi
int timeout = rowLockWaitDuration;
boolean reachDeadlineFirst = false;
- RpcCall call = RpcServer.getCurrentCall();
- if (call != null && call.getDeadline() < Long.MAX_VALUE) {
- int timeToDeadline = (int)(call.getDeadline() - System.currentTimeMillis());
- if (timeToDeadline <= this.rowLockWaitDuration) {
- reachDeadlineFirst = true;
- timeout = timeToDeadline;
+ Optional call = RpcServer.getCurrentCall();
+ if (call.isPresent()) {
+ long deadline = call.get().getDeadline();
+ if (deadline < Long.MAX_VALUE) {
+ int timeToDeadline = (int) (deadline - System.currentTimeMillis());
+ if (timeToDeadline <= this.rowLockWaitDuration) {
+ reachDeadlineFirst = true;
+ timeout = timeToDeadline;
+ }
}
}
@@ -6085,7 +6087,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi
if (scannerContext == null) {
throw new IllegalArgumentException("Scanner context cannot be null");
}
- RpcCallContext rpcCall = RpcServer.getCurrentCall();
+ Optional rpcCall = RpcServer.getCurrentCall();
// Save the initial progress from the Scanner context in these local variables. The progress
// may need to be reset a few times if rows are being filtered out so we save the initial
@@ -6110,13 +6112,12 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi
} else {
scannerContext.clearProgress();
}
-
- if (rpcCall != null) {
+ if (rpcCall.isPresent()) {
// If a user specifies a too-restrictive or too-slow scanner, the
// client might time out and disconnect while the server side
// is still processing the request. We should abort aggressively
// in that case.
- long afterTime = rpcCall.disconnectSince();
+ long afterTime = rpcCall.get().disconnectSince();
if (afterTime >= 0) {
throw new CallerDisconnectedException(
"Aborting on region " + getRegionInfo().getRegionNameAsString() + ", call " +
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
index f69695aa0d3..16895bf96ce 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
@@ -2112,7 +2112,7 @@ public class HRegionServer extends HasThread implements
@Override
public void stop(final String msg) {
- stop(msg, false, RpcServer.getRequestUser());
+ stop(msg, false, RpcServer.getRequestUser().orElse(null));
}
/**
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java
index dba314dc4f9..70b34751785 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java
@@ -1547,11 +1547,11 @@ public class RSRpcServices implements HBaseRPCErrorHandler,
// Quota support is enabled, the requesting user is not system/super user
// and a quota policy is enforced that disables compactions.
if (QuotaUtil.isQuotaEnabled(getConfiguration()) &&
- !Superusers.isSuperUser(RpcServer.getRequestUser()) &&
- this.regionServer.getRegionServerSpaceQuotaManager().areCompactionsDisabled(
- region.getTableDescriptor().getTableName())) {
- throw new DoNotRetryIOException("Compactions on this region are "
- + "disabled due to a space quota violation.");
+ !Superusers.isSuperUser(RpcServer.getRequestUser().orElse(null)) &&
+ this.regionServer.getRegionServerSpaceQuotaManager()
+ .areCompactionsDisabled(region.getTableDescriptor().getTableName())) {
+ throw new DoNotRetryIOException(
+ "Compactions on this region are " + "disabled due to a space quota violation.");
}
region.startRegionOperation(Operation.COMPACT_REGION);
LOG.info("Compacting " + region.getRegionInfo().getRegionNameAsString());
@@ -1586,10 +1586,10 @@ public class RSRpcServices implements HBaseRPCErrorHandler,
String log = "User-triggered " + (major ? "major " : "") + "compaction" + familyLogMsg;
if (family != null) {
regionServer.compactSplitThread.requestCompaction(region, store, log, Store.PRIORITY_USER,
- CompactionLifeCycleTracker.DUMMY, RpcServer.getRequestUser());
+ CompactionLifeCycleTracker.DUMMY, RpcServer.getRequestUser().orElse(null));
} else {
regionServer.compactSplitThread.requestCompaction(region, log, Store.PRIORITY_USER,
- CompactionLifeCycleTracker.DUMMY, RpcServer.getRequestUser());
+ CompactionLifeCycleTracker.DUMMY, RpcServer.getRequestUser().orElse(null));
}
return CompactRegionResponse.newBuilder().build();
} catch (IOException ie) {
@@ -2407,7 +2407,7 @@ public class RSRpcServices implements HBaseRPCErrorHandler,
ClientProtos.Get get = request.getGet();
Boolean existence = null;
Result r = null;
- RpcCallContext context = RpcServer.getCurrentCall();
+ RpcCallContext context = RpcServer.getCurrentCall().orElse(null);
quota = getRpcQuotaManager().checkQuota(region, OperationQuota.OperationType.GET);
Get clientGet = ProtobufUtil.toGet(get);
@@ -2558,7 +2558,7 @@ public class RSRpcServices implements HBaseRPCErrorHandler,
RegionActionResult.Builder regionActionResultBuilder = RegionActionResult.newBuilder();
Boolean processed = null;
RegionScannersCloseCallBack closeCallBack = null;
- RpcCallContext context = RpcServer.getCurrentCall();
+ RpcCallContext context = RpcServer.getCurrentCall().orElse(null);
this.rpcMultiRequestCount.increment();
this.requestCount.increment();
Map regionStats = new HashMap<>(request
@@ -2689,7 +2689,7 @@ public class RSRpcServices implements HBaseRPCErrorHandler,
HBaseRpcController controller = (HBaseRpcController)rpcc;
CellScanner cellScanner = controller != null ? controller.cellScanner() : null;
OperationQuota quota = null;
- RpcCallContext context = RpcServer.getCurrentCall();
+ RpcCallContext context = RpcServer.getCurrentCall().orElse(null);
ActivePolicyEnforcement spaceQuotaEnforcement = null;
MutationType type = null;
long before = EnvironmentEdgeManager.currentTime();
@@ -3269,7 +3269,7 @@ public class RSRpcServices implements HBaseRPCErrorHandler,
} else {
rows = closeScanner ? 0 : 1;
}
- RpcCallContext context = RpcServer.getCurrentCall();
+ RpcCallContext context = RpcServer.getCurrentCall().orElse(null);
// now let's do the real scan.
long maxQuotaResultSize = Math.min(maxScannerResultSize, quota.getReadAvailable());
RegionScanner scanner = rsh.s;
@@ -3281,7 +3281,7 @@ public class RSRpcServices implements HBaseRPCErrorHandler,
} else {
limitOfRows = -1;
}
- MutableObject lastBlock = new MutableObject();
+ MutableObject