HDFS-4029. GenerationStamp should use an AtomicLong. Contributed by Eli Collins
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1399096 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
24015b7684
commit
a258263ecf
|
@ -394,6 +394,8 @@ Release 2.0.3-alpha - Unreleased
|
||||||
HDFS-2946. HA: Put a cap on the number of completed edits files retained
|
HDFS-2946. HA: Put a cap on the number of completed edits files retained
|
||||||
by the NN. (atm)
|
by the NN. (atm)
|
||||||
|
|
||||||
|
HDFS-4029. GenerationStamp should use an AtomicLong. (eli)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.hadoop.hdfs.server.common;
|
package org.apache.hadoop.hdfs.server.common;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
import org.apache.hadoop.classification.InterfaceAudience;
|
import org.apache.hadoop.classification.InterfaceAudience;
|
||||||
|
|
||||||
/****************************************************************
|
/****************************************************************
|
||||||
|
@ -35,7 +37,7 @@ public class GenerationStamp implements Comparable<GenerationStamp> {
|
||||||
*/
|
*/
|
||||||
public static final long GRANDFATHER_GENERATION_STAMP = 0;
|
public static final long GRANDFATHER_GENERATION_STAMP = 0;
|
||||||
|
|
||||||
private volatile long genstamp;
|
private AtomicLong genstamp = new AtomicLong();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance, initialized to FIRST_VALID_STAMP.
|
* Create a new instance, initialized to FIRST_VALID_STAMP.
|
||||||
|
@ -48,35 +50,36 @@ public class GenerationStamp implements Comparable<GenerationStamp> {
|
||||||
* Create a new instance, initialized to the specified value.
|
* Create a new instance, initialized to the specified value.
|
||||||
*/
|
*/
|
||||||
GenerationStamp(long stamp) {
|
GenerationStamp(long stamp) {
|
||||||
this.genstamp = stamp;
|
genstamp.set(stamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current generation stamp
|
* Returns the current generation stamp
|
||||||
*/
|
*/
|
||||||
public long getStamp() {
|
public long getStamp() {
|
||||||
return this.genstamp;
|
return genstamp.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the current generation stamp
|
* Sets the current generation stamp
|
||||||
*/
|
*/
|
||||||
public void setStamp(long stamp) {
|
public void setStamp(long stamp) {
|
||||||
this.genstamp = stamp;
|
genstamp.set(stamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* First increments the counter and then returns the stamp
|
* First increments the counter and then returns the stamp
|
||||||
*/
|
*/
|
||||||
public synchronized long nextStamp() {
|
public long nextStamp() {
|
||||||
this.genstamp++;
|
return genstamp.incrementAndGet();
|
||||||
return this.genstamp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // Comparable
|
@Override // Comparable
|
||||||
public int compareTo(GenerationStamp that) {
|
public int compareTo(GenerationStamp that) {
|
||||||
return this.genstamp < that.genstamp ? -1 :
|
long stamp1 = this.genstamp.get();
|
||||||
this.genstamp > that.genstamp ? 1 : 0;
|
long stamp2 = that.genstamp.get();
|
||||||
|
return stamp1 < stamp2 ? -1 :
|
||||||
|
stamp1 > stamp2 ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override // Object
|
@Override // Object
|
||||||
|
@ -89,6 +92,7 @@ public class GenerationStamp implements Comparable<GenerationStamp> {
|
||||||
|
|
||||||
@Override // Object
|
@Override // Object
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return (int) (genstamp^(genstamp>>>32));
|
long stamp = genstamp.get();
|
||||||
|
return (int) (stamp^(stamp>>>32));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue