ndimiduk commented on code in PR #6066:
URL: https://github.com/apache/hbase/pull/6066#discussion_r1680729486


##########
hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/RegionCoprocessorEnvironment.java:
##########
@@ -26,12 +27,18 @@
 import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.client.Connection;
 import org.apache.hadoop.hbase.client.RegionInfo;
+import org.apache.hadoop.hbase.client.Scan;
 import org.apache.hadoop.hbase.metrics.MetricRegistry;
+import org.apache.hadoop.hbase.quotas.OperationQuota;
+import org.apache.hadoop.hbase.quotas.RpcQuotaManager;
+import org.apache.hadoop.hbase.quotas.RpcThrottlingException;
 import org.apache.hadoop.hbase.regionserver.OnlineRegions;
 import org.apache.hadoop.hbase.regionserver.Region;
 import org.apache.yetus.audience.InterfaceAudience;
 import org.apache.yetus.audience.InterfaceStability;
 
+import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos;

Review Comment:
   Just to check, which protobufs are we exposing to Coprocessor 
implementations, is it the shaded or unshaded module? Do we have an ErrorProne 
check that we always do the right thing?



##########
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionCoprocessorHost.java:
##########
@@ -131,6 +138,12 @@ public RegionEnvironment(final RegionCoprocessor impl, 
final int priority, final
       this.services = services;
       this.metricRegistry =
         
MetricsCoprocessor.createRegistryForRegionCoprocessor(impl.getClass().getName());
+      // lets unit tests through

Review Comment:
   What does this comment mean?



##########
hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionCoprocessorQuotaUsage.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.coprocessor;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseTestingUtil;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Connection;
+import org.apache.hadoop.hbase.client.Get;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.Table;
+import org.apache.hadoop.hbase.quotas.OperationQuota;
+import org.apache.hadoop.hbase.quotas.RpcThrottlingException;
+import org.apache.hadoop.hbase.testclassification.CoprocessorTests;
+import org.apache.hadoop.hbase.testclassification.MediumTests;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category({ MediumTests.class, CoprocessorTests.class })
+public class TestRegionCoprocessorQuotaUsage {
+
+  @ClassRule
+  public static final HBaseClassTestRule CLASS_RULE =
+    HBaseClassTestRule.forClass(TestRegionCoprocessorQuotaUsage.class);
+
+  private static HBaseTestingUtil UTIL = new HBaseTestingUtil();
+  private static TableName TABLE_NAME = 
TableName.valueOf("TestRegionCoprocessorQuotaUsage");
+  private static byte[] CF = Bytes.toBytes("CF");
+  private static byte[] CQ = Bytes.toBytes("CQ");
+  private static Connection CONN;
+  private static Table TABLE;
+  private static AtomicBoolean THROTTLING_OCCURRED = new AtomicBoolean(false);
+
+  public static class MyRegionObserver implements RegionObserver {
+    @Override
+    public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> c, Get 
get,
+      List<Cell> result) throws IOException {
+
+      // For the purposes of this test, we only need to catch a throttle 
happening once, then
+      // let future requests pass through so we don't make this test take any 
longer than necessary
+      if (!THROTTLING_OCCURRED.get()) {
+        try {
+          c.getEnvironment().checkBatchQuota(c.getEnvironment().getRegion(),
+            OperationQuota.OperationType.GET);
+        } catch (RpcThrottlingException e) {
+          THROTTLING_OCCURRED.set(true);
+          throw e;
+        }
+      }
+    }
+  }
+
+  public static class MyCoprocessor implements RegionCoprocessor {
+    private RegionCoprocessorEnvironment env;
+
+    RegionObserver observer = new MyRegionObserver();
+
+    @Override
+    public Optional<RegionObserver> getRegionObserver() {
+      return Optional.of(observer);
+    }
+  }
+
+  @BeforeClass
+  public static void setUp() throws Exception {
+    Configuration conf = UTIL.getConfiguration();
+    conf.setBoolean("hbase.quota.enabled", true);
+    conf.setInt("hbase.quota.default.user.machine.read.num", 2);
+    conf.set("hbase.quota.rate.limiter", 
"org.apache.hadoop.hbase.quotas.FixedIntervalRateLimiter");
+    conf.set("hbase.quota.rate.limiter.refill.interval.ms", "300000");
+    conf.setStrings(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, 
MyCoprocessor.class.getName());
+    UTIL.startMiniCluster(3);
+    byte[][] splitKeys = new byte[8][];
+    for (int i = 111; i < 999; i += 111) {
+      splitKeys[i / 111 - 1] = Bytes.toBytes(String.format("%03d", i));
+    }
+    UTIL.createTable(TABLE_NAME, CF, splitKeys);
+    CONN = UTIL.getConnection();
+    TABLE = CONN.getTable(TABLE_NAME);
+    TABLE.put(new Put(Bytes.toBytes(String.format("%d", 0))).addColumn(CF, CQ, 
Bytes.toBytes(0L)));
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    CONN.close();

Review Comment:
   docstring on `HBaseTestingUtil#getConnection()` says,
   
   ```
     /**
      * Get a shared Connection to the cluster. this method is thread safe.
      * @return A Connection that can be shared. Don't close. Will be closed on 
shutdown of cluster.
      */
   ```



##########
hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionCoprocessorQuotaUsage.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.coprocessor;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseTestingUtil;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Connection;
+import org.apache.hadoop.hbase.client.Get;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.Table;
+import org.apache.hadoop.hbase.quotas.OperationQuota;
+import org.apache.hadoop.hbase.quotas.RpcThrottlingException;
+import org.apache.hadoop.hbase.testclassification.CoprocessorTests;
+import org.apache.hadoop.hbase.testclassification.MediumTests;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category({ MediumTests.class, CoprocessorTests.class })
+public class TestRegionCoprocessorQuotaUsage {
+
+  @ClassRule
+  public static final HBaseClassTestRule CLASS_RULE =
+    HBaseClassTestRule.forClass(TestRegionCoprocessorQuotaUsage.class);
+
+  private static HBaseTestingUtil UTIL = new HBaseTestingUtil();
+  private static TableName TABLE_NAME = 
TableName.valueOf("TestRegionCoprocessorQuotaUsage");
+  private static byte[] CF = Bytes.toBytes("CF");
+  private static byte[] CQ = Bytes.toBytes("CQ");
+  private static Connection CONN;
+  private static Table TABLE;
+  private static AtomicBoolean THROTTLING_OCCURRED = new AtomicBoolean(false);
+
+  public static class MyRegionObserver implements RegionObserver {
+    @Override
+    public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> c, Get 
get,
+      List<Cell> result) throws IOException {
+
+      // For the purposes of this test, we only need to catch a throttle 
happening once, then
+      // let future requests pass through so we don't make this test take any 
longer than necessary
+      if (!THROTTLING_OCCURRED.get()) {
+        try {
+          c.getEnvironment().checkBatchQuota(c.getEnvironment().getRegion(),
+            OperationQuota.OperationType.GET);
+        } catch (RpcThrottlingException e) {
+          THROTTLING_OCCURRED.set(true);
+          throw e;
+        }
+      }
+    }
+  }
+
+  public static class MyCoprocessor implements RegionCoprocessor {
+    private RegionCoprocessorEnvironment env;

Review Comment:
   unsed?



##########
hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/RegionCoprocessorEnvironment.java:
##########
@@ -26,12 +27,18 @@
 import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.client.Connection;
 import org.apache.hadoop.hbase.client.RegionInfo;
+import org.apache.hadoop.hbase.client.Scan;
 import org.apache.hadoop.hbase.metrics.MetricRegistry;
+import org.apache.hadoop.hbase.quotas.OperationQuota;
+import org.apache.hadoop.hbase.quotas.RpcQuotaManager;
+import org.apache.hadoop.hbase.quotas.RpcThrottlingException;
 import org.apache.hadoop.hbase.regionserver.OnlineRegions;
 import org.apache.hadoop.hbase.regionserver.Region;
 import org.apache.yetus.audience.InterfaceAudience;
 import org.apache.yetus.audience.InterfaceStability;
 
+import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos;

Review Comment:
   Or -- do we ever? Browsing through the other coprocessor interfaces and base 
classes, I don't see any protobufs used. Instead, it's all pure Java POJOs.
   
   Should this be `org.apache.hadoop.hbase.client.Action` and that class 
exposed to `IA.LimitedPrivate` ?



##########
hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/RegionCoprocessorEnvironment.java:
##########
@@ -26,12 +27,18 @@
 import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.client.Connection;
 import org.apache.hadoop.hbase.client.RegionInfo;
+import org.apache.hadoop.hbase.client.Scan;
 import org.apache.hadoop.hbase.metrics.MetricRegistry;
+import org.apache.hadoop.hbase.quotas.OperationQuota;
+import org.apache.hadoop.hbase.quotas.RpcQuotaManager;
+import org.apache.hadoop.hbase.quotas.RpcThrottlingException;
 import org.apache.hadoop.hbase.regionserver.OnlineRegions;
 import org.apache.hadoop.hbase.regionserver.Region;
 import org.apache.yetus.audience.InterfaceAudience;
 import org.apache.yetus.audience.InterfaceStability;
 
+import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos;

Review Comment:
   Ah, but this Quota stuff is all up in the RegionServer's business, where 
shaded protobufs are indeed used directly.
   
   I think the question stands, of whether we want to expose the shaded 
protobufs to our coprocessor APIs, or if we need to keep this as a "pure" 
interface.
   
   @apurtell @Apache9 @busbey where do you stand on this question?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to