From 43c9a5b229ea472fe34c78f5dc76cff73fb5f16d Mon Sep 17 00:00:00 2001 From: xuqinya Date: Mon, 17 Dec 2018 08:10:48 +0800 Subject: [PATCH] HBASE-21592 quota.addGetResult(r) throw NPE --- .../hadoop/hbase/regionserver/RSRpcServices.java | 3 ++- .../hadoop/hbase/quotas/TestQuotaThrottle.java | 27 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) 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 df84dcf57f..d5587accad 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 @@ -2570,7 +2570,8 @@ public class RSRpcServices implements HBaseRPCErrorHandler, } builder.setResult(pbr); } - if (r != null) { + //r.cells is null when an table.exists(get) call + if (r != null && r.rawCells() != null) { quota.addGetResult(r); } return builder.build(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestQuotaThrottle.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestQuotaThrottle.java index e506a083ff..d0d861bf78 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestQuotaThrottle.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestQuotaThrottle.java @@ -18,7 +18,9 @@ package org.apache.hadoop.hbase.quotas; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import java.io.IOException; import java.util.Objects; import java.util.concurrent.TimeUnit; import org.apache.hadoop.hbase.HBaseClassTestRule; @@ -553,6 +555,31 @@ public class TestQuotaThrottle { triggerTableCacheRefresh(true, TABLE_NAMES[0]); } + @Test + public void testTableExistsGetThrottle() throws Exception { + final Admin admin = TEST_UTIL.getAdmin(); + + // Add throttle quota + admin.setQuota(QuotaSettingsFactory.throttleTable(TABLE_NAMES[0], + ThrottleType.REQUEST_NUMBER, 100, TimeUnit.MINUTES)); + triggerTableCacheRefresh(false, TABLE_NAMES[0]); + + Table table = TEST_UTIL.getConnection().getTable(TABLE_NAMES[0]); + IOException t = null; + try { + // An exists call when having throttle quota. + table.exists(new Get(Bytes.toBytes("abc"))); + } catch (IOException e) { + // I expect this exception. + LOG.error("Got expected exception", e); + t = e; + } + assertTrue(t == null); + + admin.setQuota(QuotaSettingsFactory.unthrottleTable(TABLE_NAMES[0])); + triggerTableCacheRefresh(true, TABLE_NAMES[0]); + } + private int doPuts(int maxOps, final Table... tables) throws Exception { return doPuts(maxOps, -1, tables); } -- 2.13.5 (Apple Git-94)