Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/voldemort/voldemort
Browse files Browse the repository at this point in the history
  • Loading branch information
readams committed Jun 10, 2009
2 parents e9fc39b + 679e1d5 commit a180f39
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/java/voldemort/store/stats/RequestCounter.java
Expand Up @@ -60,18 +60,28 @@ public int getDuration() {
}

private Accumulator getValidAccumulator() {

Accumulator accum = values.get();
long now = System.currentTimeMillis();
if(now - accum.startTimeMS > durationMS) {
Accumulator newWithTotal = accum.newWithTotal();
while(true) {
if(values.compareAndSet(accum, newWithTotal)) {
return newWithTotal;
}
}
} else {

/*
* if still in the window, just return it
*/
if(now - accum.startTimeMS <= durationMS) {
return accum;
}

/*
* try to set. if we fail, then someone else set it, so just return that new one
*/

Accumulator newWithTotal = accum.newWithTotal();

if(values.compareAndSet(accum, newWithTotal)) {
return newWithTotal;
}

return values.get();
}

/*
Expand Down

0 comments on commit a180f39

Please sign in to comment.