|
|
@ -206,7 +206,7 @@ public final class DfsBlockCache { |
|
|
|
blockSizeShift = Integer.numberOfTrailingZeros(blockSize); |
|
|
|
blockSizeShift = Integer.numberOfTrailingZeros(blockSize); |
|
|
|
|
|
|
|
|
|
|
|
clockLock = new ReentrantLock(true /* fair */); |
|
|
|
clockLock = new ReentrantLock(true /* fair */); |
|
|
|
clockHand = new Ref<Object>(null, -1, 0, null); |
|
|
|
clockHand = new Ref<Object>(new DfsPackKey(), -1, 0, null); |
|
|
|
clockHand.next = clockHand; |
|
|
|
clockHand.next = clockHand; |
|
|
|
|
|
|
|
|
|
|
|
readAheadLimit = cfg.getReadAheadLimit(); |
|
|
|
readAheadLimit = cfg.getReadAheadLimit(); |
|
|
@ -389,6 +389,7 @@ public final class DfsBlockCache { |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
private void reserveSpace(int reserve) { |
|
|
|
private void reserveSpace(int reserve) { |
|
|
|
clockLock.lock(); |
|
|
|
clockLock.lock(); |
|
|
|
|
|
|
|
try { |
|
|
|
long live = liveBytes + reserve; |
|
|
|
long live = liveBytes + reserve; |
|
|
|
if (maxBytes < live) { |
|
|
|
if (maxBytes < live) { |
|
|
|
Ref prev = clockHand; |
|
|
|
Ref prev = clockHand; |
|
|
@ -418,8 +419,10 @@ public final class DfsBlockCache { |
|
|
|
clockHand = prev; |
|
|
|
clockHand = prev; |
|
|
|
} |
|
|
|
} |
|
|
|
liveBytes = live; |
|
|
|
liveBytes = live; |
|
|
|
|
|
|
|
} finally { |
|
|
|
clockLock.unlock(); |
|
|
|
clockLock.unlock(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void creditSpace(int credit) { |
|
|
|
private void creditSpace(int credit) { |
|
|
|
clockLock.lock(); |
|
|
|
clockLock.lock(); |
|
|
@ -429,14 +432,17 @@ public final class DfsBlockCache { |
|
|
|
|
|
|
|
|
|
|
|
private void addToClock(Ref ref, int credit) { |
|
|
|
private void addToClock(Ref ref, int credit) { |
|
|
|
clockLock.lock(); |
|
|
|
clockLock.lock(); |
|
|
|
|
|
|
|
try { |
|
|
|
if (credit != 0) |
|
|
|
if (credit != 0) |
|
|
|
liveBytes -= credit; |
|
|
|
liveBytes -= credit; |
|
|
|
Ref ptr = clockHand; |
|
|
|
Ref ptr = clockHand; |
|
|
|
ref.next = ptr.next; |
|
|
|
ref.next = ptr.next; |
|
|
|
ptr.next = ref; |
|
|
|
ptr.next = ref; |
|
|
|
clockHand = ref; |
|
|
|
clockHand = ref; |
|
|
|
|
|
|
|
} finally { |
|
|
|
clockLock.unlock(); |
|
|
|
clockLock.unlock(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void put(DfsBlock v) { |
|
|
|
void put(DfsBlock v) { |
|
|
|
put(v.pack, v.start, v.size(), v); |
|
|
|
put(v.pack, v.start, v.size(), v); |
|
|
|