diff --git a/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift/IncrementCoalescer.java b/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift/IncrementCoalescer.java index 122675c67f1..0649b26e25e 100644 --- a/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift/IncrementCoalescer.java +++ b/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift/IncrementCoalescer.java @@ -15,7 +15,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.hadoop.hbase.thrift; import java.io.IOException; @@ -35,7 +34,6 @@ import org.apache.hadoop.hbase.thrift.generated.TIncrement; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Threads; import org.apache.hadoop.metrics2.util.MBeans; -import org.apache.thrift.TException; import org.apache.yetus.audience.InterfaceAudience; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,7 +49,6 @@ import org.slf4j.LoggerFactory; */ @InterfaceAudience.Private public class IncrementCoalescer implements IncrementCoalescerMBean { - /** * Used to identify a cell that will be incremented. * @@ -82,10 +79,6 @@ public class IncrementCoalescer implements IncrementCoalescerMBean { return rowKey; } - public void setRowKey(byte[] rowKey) { - this.rowKey = rowKey; - } - public byte[] getFamily() { return family; } @@ -119,13 +112,19 @@ public class IncrementCoalescer implements IncrementCoalescerMBean { if (obj == null) return false; if (getClass() != obj.getClass()) return false; FullyQualifiedRow other = (FullyQualifiedRow) obj; - if (!Arrays.equals(family, other.family)) return false; - if (!Arrays.equals(qualifier, other.qualifier)) return false; - if (!Arrays.equals(rowKey, other.rowKey)) return false; - if (!Arrays.equals(table, other.table)) return false; - return true; - } + if (!Arrays.equals(family, other.family)) { + return false; + } + if (!Arrays.equals(qualifier, other.qualifier)) { + return false; + } + if (!Arrays.equals(rowKey, other.rowKey)) { + return false; + } + + return Arrays.equals(table, other.table); + } } private final LongAdder failedIncrements = new LongAdder(); @@ -139,9 +138,8 @@ public class IncrementCoalescer implements IncrementCoalescerMBean { private int maxQueueSize = 500000; private static final int CORE_POOL_SIZE = 1; - private static final Logger LOG = LoggerFactory.getLogger(FullyQualifiedRow.class); + private static final Logger LOG = LoggerFactory.getLogger(IncrementCoalescer.class); - @SuppressWarnings("deprecation") public IncrementCoalescer(ThriftHBaseServiceHandler hand) { this.handler = hand; LinkedBlockingQueue queue = new LinkedBlockingQueue<>(); @@ -151,7 +149,7 @@ public class IncrementCoalescer implements IncrementCoalescerMBean { MBeans.register("thrift", "Thrift", this); } - public boolean queueIncrement(TIncrement inc) throws TException { + public boolean queueIncrement(TIncrement inc) { if (!canQueue()) { failedIncrements.increment(); return false; @@ -159,7 +157,7 @@ public class IncrementCoalescer implements IncrementCoalescerMBean { return internalQueueTincrement(inc); } - public boolean queueIncrements(List incs) throws TException { + public boolean queueIncrements(List incs) { if (!canQueue()) { failedIncrements.increment(); return false; @@ -172,7 +170,7 @@ public class IncrementCoalescer implements IncrementCoalescerMBean { } - private boolean internalQueueTincrement(TIncrement inc) throws TException { + private boolean internalQueueTincrement(TIncrement inc) { byte[][] famAndQf = CellUtil.parseColumn(inc.getColumn()); if (famAndQf.length != 2) return false; @@ -182,7 +180,7 @@ public class IncrementCoalescer implements IncrementCoalescerMBean { @SuppressWarnings("FutureReturnValueIgnored") private boolean internalQueueIncrement(byte[] tableName, byte[] rowKey, byte[] fam, - byte[] qual, long ammount) throws TException { + byte[] qual, long ammount) { int countersMapSize = countersMap.size(); @@ -199,7 +197,7 @@ public class IncrementCoalescer implements IncrementCoalescerMBean { Long value = countersMap.remove(key); if (value == null) { // There was nothing there, create a new value - value = Long.valueOf(currentAmount); + value = currentAmount; } else { value += currentAmount; successfulCoalescings.increment(); @@ -232,39 +230,36 @@ public class IncrementCoalescer implements IncrementCoalescerMBean { } private Callable createIncCallable() { - return new Callable() { - @Override - public Integer call() throws Exception { - int failures = 0; - Set keys = countersMap.keySet(); - for (FullyQualifiedRow row : keys) { - Long counter = countersMap.remove(row); - if (counter == null) { - continue; + return () -> { + int failures = 0; + Set keys = countersMap.keySet(); + for (FullyQualifiedRow row : keys) { + Long counter = countersMap.remove(row); + if (counter == null) { + continue; + } + Table table = null; + try { + table = handler.getTable(row.getTable()); + if (failures > 2) { + throw new IOException("Auto-Fail rest of ICVs"); } - Table table = null; - try { - table = handler.getTable(row.getTable()); - if (failures > 2) { - throw new IOException("Auto-Fail rest of ICVs"); - } - table.incrementColumnValue(row.getRowKey(), row.getFamily(), row.getQualifier(), - counter); - } catch (IOException e) { - // log failure of increment - failures++; - LOG.error("FAILED_ICV: " + Bytes.toString(row.getTable()) + ", " - + Bytes.toStringBinary(row.getRowKey()) + ", " - + Bytes.toStringBinary(row.getFamily()) + ", " - + Bytes.toStringBinary(row.getQualifier()) + ", " + counter, e); - } finally{ - if(table != null){ - table.close(); - } + table.incrementColumnValue(row.getRowKey(), row.getFamily(), row.getQualifier(), + counter); + } catch (IOException e) { + // log failure of increment + failures++; + LOG.error("FAILED_ICV: " + Bytes.toString(row.getTable()) + ", " + + Bytes.toStringBinary(row.getRowKey()) + ", " + + Bytes.toStringBinary(row.getFamily()) + ", " + + Bytes.toStringBinary(row.getQualifier()) + ", " + counter, e); + } finally{ + if(table != null){ + table.close(); } } - return failures; } + return failures; }; } @@ -369,5 +364,4 @@ public class IncrementCoalescer implements IncrementCoalescerMBean { public long getCountersMapSize() { return countersMap.size(); } - } diff --git a/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftSpnegoHttpFallbackServer.java b/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftSpnegoHttpFallbackServer.java index 0d11215d40d..a1334a4ef13 100644 --- a/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftSpnegoHttpFallbackServer.java +++ b/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftSpnegoHttpFallbackServer.java @@ -38,7 +38,6 @@ import org.apache.hadoop.hbase.security.HBaseKerberosUtils; import org.apache.hadoop.hbase.testclassification.ClientTests; import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.thrift.generated.Hbase; -import org.apache.hadoop.hbase.util.TableDescriptorChecker; import org.apache.hadoop.security.authentication.util.KerberosName; import org.apache.http.HttpHeaders; import org.apache.http.auth.AuthSchemeProvider; @@ -212,29 +211,26 @@ public class TestThriftSpnegoHttpFallbackServer extends TestThriftHttpServer { // The name of the principal final String clientPrincipalName = clientPrincipals.iterator().next().getName(); - return Subject.doAs(clientSubject, new PrivilegedExceptionAction() { - @Override - public CloseableHttpClient run() throws Exception { - // Logs in with Kerberos via GSS - GSSManager gssManager = GSSManager.getInstance(); - // jGSS Kerberos login constant - Oid oid = new Oid("1.2.840.113554.1.2.2"); - GSSName gssClient = gssManager.createName(clientPrincipalName, GSSName.NT_USER_NAME); - GSSCredential credential = gssManager.createCredential(gssClient, - GSSCredential.DEFAULT_LIFETIME, oid, GSSCredential.INITIATE_ONLY); + return Subject.doAs(clientSubject, (PrivilegedExceptionAction) () -> { + // Logs in with Kerberos via GSS + GSSManager gssManager = GSSManager.getInstance(); + // jGSS Kerberos login constant + Oid oid = new Oid("1.2.840.113554.1.2.2"); + GSSName gssClient = gssManager.createName(clientPrincipalName, GSSName.NT_USER_NAME); + GSSCredential credential = gssManager.createCredential(gssClient, + GSSCredential.DEFAULT_LIFETIME, oid, GSSCredential.INITIATE_ONLY); - Lookup authRegistry = RegistryBuilder.create() - .register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(true, true)) - .build(); + Lookup authRegistry = RegistryBuilder.create() + .register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(true, true)) + .build(); - BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); - credentialsProvider.setCredentials(AuthScope.ANY, new KerberosCredentials(credential)); + BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); + credentialsProvider.setCredentials(AuthScope.ANY, new KerberosCredentials(credential)); - return HttpClients.custom() - .setDefaultAuthSchemeRegistry(authRegistry) - .setDefaultCredentialsProvider(credentialsProvider) - .build(); - } + return HttpClients.custom() + .setDefaultAuthSchemeRegistry(authRegistry) + .setDefaultCredentialsProvider(credentialsProvider) + .build(); }); } } diff --git a/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftSpnegoHttpServer.java b/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftSpnegoHttpServer.java index f126da1965d..3206b54de5a 100644 --- a/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftSpnegoHttpServer.java +++ b/hbase-thrift/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftSpnegoHttpServer.java @@ -38,7 +38,6 @@ import org.apache.hadoop.hbase.security.HBaseKerberosUtils; import org.apache.hadoop.hbase.testclassification.ClientTests; import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.thrift.generated.Hbase; -import org.apache.hadoop.hbase.util.TableDescriptorChecker; import org.apache.hadoop.security.authentication.util.KerberosName; import org.apache.http.HttpHeaders; import org.apache.http.auth.AuthSchemeProvider; @@ -211,29 +210,26 @@ public class TestThriftSpnegoHttpServer extends TestThriftHttpServer { // The name of the principal final String clientPrincipalName = clientPrincipals.iterator().next().getName(); - return Subject.doAs(clientSubject, new PrivilegedExceptionAction() { - @Override - public CloseableHttpClient run() throws Exception { - // Logs in with Kerberos via GSS - GSSManager gssManager = GSSManager.getInstance(); - // jGSS Kerberos login constant - Oid oid = new Oid("1.2.840.113554.1.2.2"); - GSSName gssClient = gssManager.createName(clientPrincipalName, GSSName.NT_USER_NAME); - GSSCredential credential = gssManager.createCredential(gssClient, - GSSCredential.DEFAULT_LIFETIME, oid, GSSCredential.INITIATE_ONLY); + return Subject.doAs(clientSubject, (PrivilegedExceptionAction) () -> { + // Logs in with Kerberos via GSS + GSSManager gssManager = GSSManager.getInstance(); + // jGSS Kerberos login constant + Oid oid = new Oid("1.2.840.113554.1.2.2"); + GSSName gssClient = gssManager.createName(clientPrincipalName, GSSName.NT_USER_NAME); + GSSCredential credential = gssManager.createCredential(gssClient, + GSSCredential.DEFAULT_LIFETIME, oid, GSSCredential.INITIATE_ONLY); - Lookup authRegistry = RegistryBuilder.create() - .register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(true, true)) - .build(); + Lookup authRegistry = RegistryBuilder.create() + .register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(true, true)) + .build(); - BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); - credentialsProvider.setCredentials(AuthScope.ANY, new KerberosCredentials(credential)); + BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); + credentialsProvider.setCredentials(AuthScope.ANY, new KerberosCredentials(credential)); - return HttpClients.custom() - .setDefaultAuthSchemeRegistry(authRegistry) - .setDefaultCredentialsProvider(credentialsProvider) - .build(); - } + return HttpClients.custom() + .setDefaultAuthSchemeRegistry(authRegistry) + .setDefaultCredentialsProvider(credentialsProvider) + .build(); }); } }