HBASE-10663 Some code cleanup of class Leases and ScannerListener.leaseExpired
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1575451 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e2c671183e
commit
7f95fccd06
|
@ -2497,7 +2497,8 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa
|
||||||
+ s.getRegionInfo().getRegionNameAsString(), e);
|
+ s.getRegionInfo().getRegionNameAsString(), e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG.info("Scanner " + this.scannerName + " lease expired");
|
LOG.warn("Scanner " + this.scannerName + " lease expired, but no related" +
|
||||||
|
" scanner found, hence no chance to close that related scanner!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.apache.hadoop.hbase.regionserver;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.hadoop.classification.InterfaceAudience;
|
import org.apache.hadoop.classification.InterfaceAudience;
|
||||||
|
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
|
||||||
import org.apache.hadoop.hbase.util.HasThread;
|
import org.apache.hadoop.hbase.util.HasThread;
|
||||||
|
|
||||||
import java.util.ConcurrentModificationException;
|
import java.util.ConcurrentModificationException;
|
||||||
|
@ -132,7 +133,7 @@ public class Leases extends HasThread {
|
||||||
* Shuts down this lease instance when all outstanding leases expire.
|
* Shuts down this lease instance when all outstanding leases expire.
|
||||||
* Like {@link #close()} but rather than violently end all leases, waits
|
* Like {@link #close()} but rather than violently end all leases, waits
|
||||||
* first on extant leases to finish. Use this method if the lease holders
|
* first on extant leases to finish. Use this method if the lease holders
|
||||||
* could loose data, leak locks, etc. Presumes client has shutdown
|
* could lose data, leak locks, etc. Presumes client has shutdown
|
||||||
* allocation of new leases.
|
* allocation of new leases.
|
||||||
*/
|
*/
|
||||||
public void closeAfterLeasesExpire() {
|
public void closeAfterLeasesExpire() {
|
||||||
|
@ -151,7 +152,7 @@ public class Leases extends HasThread {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtain a lease.
|
* Create a lease and insert it to the map of leases.
|
||||||
*
|
*
|
||||||
* @param leaseName name of the lease
|
* @param leaseName name of the lease
|
||||||
* @param leaseTimeoutPeriod length of the lease in milliseconds
|
* @param leaseTimeoutPeriod length of the lease in milliseconds
|
||||||
|
@ -172,10 +173,10 @@ public class Leases extends HasThread {
|
||||||
if (this.stopRequested) {
|
if (this.stopRequested) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
lease.resetExpirationTime();
|
|
||||||
if (leases.containsKey(lease.getLeaseName())) {
|
if (leases.containsKey(lease.getLeaseName())) {
|
||||||
throw new LeaseStillHeldException(lease.getLeaseName());
|
throw new LeaseStillHeldException(lease.getLeaseName());
|
||||||
}
|
}
|
||||||
|
lease.resetExpirationTime();
|
||||||
leases.put(lease.getLeaseName(), lease);
|
leases.put(lease.getLeaseName(), lease);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,10 +187,11 @@ public class Leases extends HasThread {
|
||||||
* @throws LeaseException
|
* @throws LeaseException
|
||||||
*/
|
*/
|
||||||
public void renewLease(final String leaseName) throws LeaseException {
|
public void renewLease(final String leaseName) throws LeaseException {
|
||||||
|
if (this.stopRequested) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Lease lease = leases.get(leaseName);
|
Lease lease = leases.get(leaseName);
|
||||||
// We need to check to see if the remove is successful as the poll in the run()
|
|
||||||
// method could have completed between the get and the remove which will result
|
|
||||||
// in a corrupt leaseQueue.
|
|
||||||
if (lease == null ) {
|
if (lease == null ) {
|
||||||
throw new LeaseException("lease '" + leaseName +
|
throw new LeaseException("lease '" + leaseName +
|
||||||
"' does not exist or has already expired");
|
"' does not exist or has already expired");
|
||||||
|
@ -208,8 +210,8 @@ public class Leases extends HasThread {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove named lease.
|
* Remove named lease.
|
||||||
* Lease is removed from the list of leases and removed from the delay queue.
|
* Lease is removed from the map of leases.
|
||||||
* Lease can be resinserted using {@link #addLease(Lease)}
|
* Lease can be reinserted using {@link #addLease(Lease)}
|
||||||
*
|
*
|
||||||
* @param leaseName name of lease
|
* @param leaseName name of lease
|
||||||
* @throws org.apache.hadoop.hbase.regionserver.LeaseException
|
* @throws org.apache.hadoop.hbase.regionserver.LeaseException
|
||||||
|
@ -224,7 +226,7 @@ public class Leases extends HasThread {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thrown if we are asked create a lease but lease on passed name already
|
* Thrown if we are asked to create a lease but lease on passed name already
|
||||||
* exists.
|
* exists.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
|
@ -288,7 +290,7 @@ public class Leases extends HasThread {
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getDelay(TimeUnit unit) {
|
public long getDelay(TimeUnit unit) {
|
||||||
return unit.convert(this.expirationTime - System.currentTimeMillis(),
|
return unit.convert(this.expirationTime - EnvironmentEdgeManager.currentTimeMillis(),
|
||||||
TimeUnit.MILLISECONDS);
|
TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,7 +305,7 @@ public class Leases extends HasThread {
|
||||||
* Resets the expiration time of the lease.
|
* Resets the expiration time of the lease.
|
||||||
*/
|
*/
|
||||||
public void resetExpirationTime() {
|
public void resetExpirationTime() {
|
||||||
this.expirationTime = System.currentTimeMillis() + this.leaseTimeoutPeriod;
|
this.expirationTime = EnvironmentEdgeManager.currentTimeMillis() + this.leaseTimeoutPeriod;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue