HBASE-18122 Scanner id should include ServerName of region server

This commit is contained in:
Phil Yang 2017-05-31 13:57:05 +08:00
parent d547feac6b
commit 9cf1a08c53
2 changed files with 54 additions and 2 deletions

View File

@ -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);

View File

@ -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;
}
}