From 2cca1301391b54e625db88807590849dd3e104bc Mon Sep 17 00:00:00 2001 From: tan Date: Thu, 17 Mar 2016 16:43:46 +0530 Subject: [PATCH] don't rely on weakref being null, fix blobcache - Checking weakref value to be null as an indicator of gc is not reliable. We probably need a finalizer for that, but all finalizers don't get called immediately at the moment (ref: https://github.com/JuliaLang/julia/pull/13995). Going without that optimization for now. - fixed an issue where cache eviction was corrupting the cache --- src/blob.jl | 12 ++++-------- src/cache/blobcache.jl | 4 ++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/blob.jl b/src/blob.jl index a2883c1..049474b 100644 --- a/src/blob.jl +++ b/src/blob.jl @@ -315,8 +315,7 @@ function load_local(collid::UUID, blob::UUID) end function load_local{T}(coll::BlobCollection, blob::Blob{T}) if !haskey(coll.cache, blob.id) - val = blob.data.value - (val == nothing) && (val = load(blob.metadata, coll.reader)) + val = load(blob.metadata, coll.reader) blob.data.value = coll.cache[blob.id] = val blob.locality = locality(coll.reader, coll.nodemap) end @@ -328,12 +327,9 @@ load(coll::BlobCollection, blobid::UUID) = load(coll, coll.blobs[blobid]) load{T,L<:WeakLocality}(coll::BlobCollection, blob::Blob{T,L}) = load_local(coll, blob) function load{T,L<:StrongLocality}(coll::BlobCollection, blob::Blob{T,L}) if !haskey(coll.cache, blob.id) - val = blob.data.value - if val == nothing - # select a node from blob's local nodes - fetchfrom = select_local(coll, blob) - val = (fetchfrom == myid()) ? load_local(coll.id, blob.id) : remotecall_fetch(load_local, fetchfrom, coll.id, blob.id) - end + # select a node from blob's local nodes + fetchfrom = select_local(coll, blob) + val = (fetchfrom == myid()) ? load_local(coll.id, blob.id) : remotecall_fetch(load_local, fetchfrom, coll.id, blob.id) blob.data.value = coll.cache[blob.id] = val end (coll.cache[blob.id])::T diff --git a/src/cache/blobcache.jl b/src/cache/blobcache.jl index 78fa2b1..626660b 100644 --- a/src/cache/blobcache.jl +++ b/src/cache/blobcache.jl @@ -93,7 +93,7 @@ function Base.setindex!{K, V}(lru::LRU{K, V}, v, key) end while lru.isfull(lru) - rm = pop!(lru.q) + rm = last(lru.q) delete!(lru, rm.k) end @@ -104,7 +104,7 @@ function Base.resize!(lru::LRU, n::Int) n < 0 && error("size must be a positive integer") lru.maxsize = n while lru.isfull(lru) - rm = pop!(lru.q) + rm = last(lru.q) delete!(lru, rm.k) end return lru