You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by GitBox <gi...@apache.org> on 2022/09/15 15:00:30 UTC

[GitHub] [hbase] Apache9 commented on a diff in pull request #4720: HBASE-27315 Add timeout to JavaRegexEngine

Apache9 commented on code in PR #4720:
URL: https://github.com/apache/hbase/pull/4720#discussion_r972103667


##########
hbase-client/src/main/java/org/apache/hadoop/hbase/filter/TimeoutCharSequence.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.filter;
+
+import org.apache.hadoop.hbase.DoNotRetryUncheckedIOException;
+import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
+import org.apache.hadoop.util.StringUtils;
+
+/**
+ * It checks whether the timeout has been exceeded whenever the charAt method is called.
+ */
+class TimeoutCharSequence implements CharSequence {
+  private final CharSequence value;
+  private final long startMillis;
+  private final long timeoutMillis;
+
+  /**
+   * Initialize a TimeoutCharSequence.
+   * @param value         the original data
+   * @param startMillis   time the operation started (ms)
+   * @param timeoutMillis the timeout (ms)
+   */
+  TimeoutCharSequence(CharSequence value, long startMillis, long timeoutMillis) {
+    this.value = value;
+    this.startMillis = startMillis;
+    this.timeoutMillis = timeoutMillis;
+  }
+
+  @Override
+  public int length() {
+    return value.length();
+  }
+
+  @Override
+  public char charAt(int index) {
+    final long diff = EnvironmentEdgeManager.currentTime() - startMillis;

Review Comment:
   The implementation is a bit tricky... And will this slow down the normal process? As we will do a System.currentTimeMillis call every time when we want to get a char...



-- 
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: issues-unsubscribe@hbase.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org