Merge changes Ibb3467f7,I2af99903
* changes: Always use try/finally around DfsBlockCache.clockLock DfsBlockCache: Fix NPE when evicting empty cell
This commit is contained in:
commit
c0392381ee
|
@ -206,7 +206,7 @@ else if (eb < 4)
|
|||
blockSizeShift = Integer.numberOfTrailingZeros(blockSize);
|
||||
|
||||
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;
|
||||
|
||||
readAheadLimit = cfg.getReadAheadLimit();
|
||||
|
@ -389,6 +389,7 @@ DfsBlock getOrLoad(DfsPackFile pack, long position, DfsReader ctx)
|
|||
@SuppressWarnings("unchecked")
|
||||
private void reserveSpace(int reserve) {
|
||||
clockLock.lock();
|
||||
try {
|
||||
long live = liveBytes + reserve;
|
||||
if (maxBytes < live) {
|
||||
Ref prev = clockHand;
|
||||
|
@ -418,8 +419,10 @@ private void reserveSpace(int reserve) {
|
|||
clockHand = prev;
|
||||
}
|
||||
liveBytes = live;
|
||||
} finally {
|
||||
clockLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private void creditSpace(int credit) {
|
||||
clockLock.lock();
|
||||
|
@ -429,14 +432,17 @@ private void creditSpace(int credit) {
|
|||
|
||||
private void addToClock(Ref ref, int credit) {
|
||||
clockLock.lock();
|
||||
try {
|
||||
if (credit != 0)
|
||||
liveBytes -= credit;
|
||||
Ref ptr = clockHand;
|
||||
ref.next = ptr.next;
|
||||
ptr.next = ref;
|
||||
clockHand = ref;
|
||||
} finally {
|
||||
clockLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
void put(DfsBlock v) {
|
||||
put(v.pack, v.start, v.size(), v);
|
||||
|
|
Loading…
Reference in New Issue