Skip to content

Commit 4b4d971

Browse files
committed
Update shaded JCTools queue due to live-lock (fixes #127)
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.
1 parent 260ec05 commit 4b4d971

File tree

16 files changed

+1067
-423
lines changed

16 files changed

+1067
-423
lines changed

caffeine/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ dependencies {
4141
jmh benchmark_libraries.infinispan
4242
jmh benchmark_libraries.jackrabbit
4343
jmh benchmark_libraries.elastic_search
44-
jmh benchmark_libraries.jctools_experimental
4544
jmh benchmark_libraries.concurrentlinkedhashmap
4645

4746
javaPoetCompile libraries.guava

caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/Specifications.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ public final class Specifications {
9999
public static final TypeName WRITE_ORDER_DEQUE = ParameterizedTypeName.get(
100100
ClassName.get(PACKAGE_NAME, "WriteOrderDeque"), NODE);
101101

102-
public static final ClassName WRITE_QUEUE_TYPE = ClassName.get(PACKAGE_NAME, "WriteBuffer");
102+
public static final ClassName WRITE_QUEUE_TYPE =
103+
ClassName.get(PACKAGE_NAME, "MpscGrowableArrayQueue");
103104
public static final TypeName WRITE_QUEUE = ParameterizedTypeName.get(
104105
WRITE_QUEUE_TYPE, ClassName.get(Runnable.class));
105106

caffeine/src/main/java/com/github/benmanes/caffeine/base/UnsafeAccess.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
*
3030
* @author [email protected] (Ben Manes)
3131
*/
32+
@SuppressWarnings("restriction")
3233
public final class UnsafeAccess {
3334
static final String ANDROID = "THE_ONE";
3435
static final String OPEN_JDK = "theUnsafe";

caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ protected boolean buffersWrites() {
235235
return false;
236236
}
237237

238-
protected WriteBuffer<Runnable> writeBuffer() {
238+
protected MpscGrowableArrayQueue<Runnable> writeBuffer() {
239239
throw new UnsupportedOperationException();
240240
}
241241

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

0 commit comments

Comments
 (0)