Skip to content

Commit

Permalink
Update shaded JCTools queue due to live-lock (fixes #127)
Browse files Browse the repository at this point in the history
In #127, a live-lock occurs in the write buffer due to a race when the
consumer tries to transition to the last buffer. This is a shaded copy
of JCTools' MpscGrowableLinkedArrayQueue and fixed in 2.0 (see
JCTools/JCTools#135). This is a difficult to
reproduce bug, except for the reporter due to having thousands of
instances on a loaded system.

The shaded copy is more verbose than the previous one, but that is to
minimize the divergency and introducing bugs by cutting too deep.

Updating to Guava 20 required minor changes due to that cache now
supporting write-through entries. The adapter now mirrors the new
behavior.

Thanks to everyones patience and help in fixing the bug.
  • Loading branch information
ben-manes committed Oct 30, 2016
1 parent 260ec05 commit 4b4d971
Show file tree
Hide file tree
Showing 16 changed files with 1,067 additions and 423 deletions.
1 change: 0 additions & 1 deletion caffeine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ dependencies {
jmh benchmark_libraries.infinispan
jmh benchmark_libraries.jackrabbit
jmh benchmark_libraries.elastic_search
jmh benchmark_libraries.jctools_experimental
jmh benchmark_libraries.concurrentlinkedhashmap

javaPoetCompile libraries.guava
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public final class Specifications {
public static final TypeName WRITE_ORDER_DEQUE = ParameterizedTypeName.get(
ClassName.get(PACKAGE_NAME, "WriteOrderDeque"), NODE);

public static final ClassName WRITE_QUEUE_TYPE = ClassName.get(PACKAGE_NAME, "WriteBuffer");
public static final ClassName WRITE_QUEUE_TYPE =
ClassName.get(PACKAGE_NAME, "MpscGrowableArrayQueue");
public static final TypeName WRITE_QUEUE = ParameterizedTypeName.get(
WRITE_QUEUE_TYPE, ClassName.get(Runnable.class));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*
* @author ben.manes@gmail.com (Ben Manes)
*/
@SuppressWarnings("restriction")
public final class UnsafeAccess {
static final String ANDROID = "THE_ONE";
static final String OPEN_JDK = "theUnsafe";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ protected boolean buffersWrites() {
return false;
}

protected WriteBuffer<Runnable> writeBuffer() {
protected MpscGrowableArrayQueue<Runnable> writeBuffer() {
throw new UnsupportedOperationException();
}

Expand Down Expand Up @@ -634,6 +634,7 @@ void evictFromMain(int candidates) {
* @param victimKey the key for the entry chosen by the eviction policy for replacement
* @return if the candidate should be admitted and the victim ejected
*/
@GuardedBy("evictionLock")
boolean admit(K candidateKey, K victimKey) {
int victimFreq = frequencySketch().frequency(victimKey);
int candidateFreq = frequencySketch().frequency(candidateKey);
Expand Down
Loading

0 comments on commit 4b4d971

Please sign in to comment.