From f78284685fc533230a0395d297ebacff32632396 Mon Sep 17 00:00:00 2001 From: xuqinya Date: Tue, 18 Dec 2018 08:19:47 +0800 Subject: [PATCH] HBASE-21592 quota.addGetResult(r) throw NPE Signed-off-by: huzheng --- .../hbase/regionserver/RSRpcServices.java | 3 ++- .../hadoop/hbase/quotas/TestQuotaThrottle.java | 17 +++++++++++++++++ 2 files changed, 19 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 31df37a5fa6..f788a86f47b 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 @@ -2571,7 +2571,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 e506a083ff5..c0694031489 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 @@ -553,6 +553,23 @@ 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]); + // An exists call when having throttle quota + table.exists(new Get(Bytes.toBytes("abc"))); + + 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); }