Skip to content

Commit

Permalink
don't rely on weakref being null, fix blobcache
Browse files Browse the repository at this point in the history
- 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: JuliaLang/julia#13995). Going without that optimization for now.
- fixed an issue where cache eviction was corrupting the cache
  • Loading branch information
tanmaykm committed Mar 17, 2016
1 parent d64bbf1 commit 2cca130
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
12 changes: 4 additions & 8 deletions src/blob.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/cache/blobcache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 2cca130

Please sign in to comment.