hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [01/30] hbase git commit: HBASE-18122 Scanner id should include ServerName of region server [Forced Update!]
Date Wed, 31 May 2017 16:31:30 GMT
Repository: hbase
Updated Branches:
  refs/heads/HBASE-14614 fc144d450 -> e76e8eb8e (forced update)


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/9cf1a08c
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/9cf1a08c
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/9cf1a08c

Branch: refs/heads/HBASE-14614
Commit: 9cf1a08c53b4d3416e10c2b725cbc3abda07590c
Parents: d547feac
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 13:57:05 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/9cf1a08c/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 1f3fede..0efbbaa 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
@@ -274,7 +274,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
@@ -1353,6 +1353,7 @@ public class RSRpcServices implements HBaseRPCErrorHandler,
   }
 
   void start() {
+    this.scannerIdGenerator = new ScannerIdGenerator(this.regionServer.serverName);
     rpcServer.start();
   }
 
@@ -2871,7 +2872,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.setMvccReadPoint(scanner.getMvccReadPoint());
     builder.setTtl(scannerLeaseTimeoutPeriod);

http://git-wip-us.apache.org/repos/asf/hbase/blob/9cf1a08c/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