hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yangzhe1...@apache.org
Subject hbase git commit: HBASE-18122 Scanner id should include ServerName of region server
Date Wed, 31 May 2017 06:05:43 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1.3 2277c2b63 -> ae7b63139


HBASE-18122 Scanner id should include ServerName of region server


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/ae7b6313
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/ae7b6313
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/ae7b6313

Branch: refs/heads/branch-1.3
Commit: ae7b63139916c56218b6b47f0acc41ab98078415
Parents: 2277c2b
Author: Phil Yang <yangzhe1991@apache.org>
Authored: Wed May 31 13:57:05 2017 +0800
Committer: Phil Yang <yangzhe1991@apache.org>
Committed: Wed May 31 14:04:26 2017 +0800

----------------------------------------------------------------------
 .../hbase/regionserver/RSRpcServices.java       |  5 +-
 .../hbase/regionserver/ScannerIdGenerator.java  | 51 ++++++++++++++++++++
 2 files changed, 54 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/ae7b6313/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java
----------------------------------------------------------------------
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 d37a287..23b347a 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
@@ -250,7 +250,7 @@ public class RSRpcServices implements HBaseRPCErrorHandler,
   // The reference to the priority extraction function
   private final PriorityFunction priority;
 
-  private final AtomicLong scannerIdGen = new AtomicLong(0L);
+  private ScannerIdGenerator scannerIdGenerator;
   private final ConcurrentMap<String, RegionScannerHolder> scanners = new ConcurrentHashMap<>();
   // Hold the name of a closed scanner for a while. This is used to keep compatible for old
clients
   // which may send next or close request to a region scanner which has already been exhausted.
The
@@ -1170,6 +1170,7 @@ public class RSRpcServices implements HBaseRPCErrorHandler,
   }
 
   void start() {
+    this.scannerIdGenerator = new ScannerIdGenerator(this.regionServer.serverName);
     rpcServer.start();
   }
 
@@ -2502,7 +2503,7 @@ public class RSRpcServices implements HBaseRPCErrorHandler,
     if (region.getCoprocessorHost() != null) {
       scanner = region.getCoprocessorHost().postScannerOpen(scan, scanner);
     }
-    long scannerId = this.scannerIdGen.incrementAndGet();
+    long scannerId = scannerIdGenerator.generateNewScannerId();
     builder.setScannerId(scannerId);
     builder.setTtl(scannerLeaseTimeoutPeriod);
     String scannerName = String.valueOf(scannerId);

http://git-wip-us.apache.org/repos/asf/hbase/blob/ae7b6313/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ScannerIdGenerator.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ScannerIdGenerator.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ScannerIdGenerator.java
new file mode 100644
index 0000000..c639556
--- /dev/null
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ScannerIdGenerator.java
@@ -0,0 +1,51 @@
+/**
+ *
+ * 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.regionserver;
+
+import com.google.common.hash.Hashing;
+
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.classification.InterfaceAudience;
+import org.apache.hadoop.hbase.util.Bytes;
+
+/**
+ * Generate a new style scanner id to prevent collision with previous started server or other
RSs.
+ * We have 64 bits to use.
+ * The first 32 bits are MurmurHash32 of ServerName string "host,port,ts".
+ * The ServerName contains both host, port, and start timestamp so it can prevent collision.
+ * The lowest 32bit is generated by atomic int.
+ */
+@InterfaceAudience.Private
+public class ScannerIdGenerator {
+
+  private final long serverNameHash;
+  private final AtomicInteger scannerIdGen = new AtomicInteger(0);
+
+  public ScannerIdGenerator(ServerName serverName) {
+    this.serverNameHash = (long)Hashing.murmur3_32().hashString(serverName.toString()).asInt()
<< 32;
+  }
+
+  public long generateNewScannerId() {
+    return (scannerIdGen.incrementAndGet() & 0x00000000FFFFFFFFL) | serverNameHash;
+  }
+
+}


Mime
View raw message