Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release Futures by sending del msgs when fetched #23172

Merged
merged 1 commit into from
Aug 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions base/distributed/remotecall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -473,16 +473,11 @@ end
wait(r::Future) = (!isnull(r.v) && return r; call_on_owner(wait_ref, r, myid()); r)
wait(r::RemoteChannel, args...) = (call_on_owner(wait_ref, r, myid(), args...); r)

function fetch_future(rid, callee)
rv = lookup_ref(rid)
v = fetch(rv.c)
del_client(rid, callee)
v
end
function fetch(r::Future)
!isnull(r.v) && return get(r.v)
v=call_on_owner(fetch_future, r, myid())
v=call_on_owner(fetch_ref, r)
r.v=v
send_del_client(r)
v
end

Expand Down
4 changes: 0 additions & 4 deletions base/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1668,7 +1668,6 @@ precompile(Tuple{typeof(Base.isempty), Base.IntSet})
precompile(Tuple{typeof(Base.any), Base.BitArray{1}})
precompile(Tuple{typeof(Base.uvfinalize), Base.PipeEndpoint})
precompile(Tuple{typeof(Base.uvfinalize), Base.Process})
precompile(Tuple{getfield(Base.Distributed, Symbol("#kw##remotecall_fetch")), Array{Any, 1}, typeof(Base.Distributed.remotecall_fetch), typeof(Base.Distributed.fetch_future), Base.Distributed.Worker, Base.Distributed.RRID, Int64})
precompile(Tuple{getfield(Base.Distributed, Symbol("#kw##remotecall_fetch")), Array{Any, 1}, typeof(Base.Distributed.remotecall_fetch), typeof(Base.open), Base.Distributed.LocalProcess, typeof(Base.read), String})
precompile(Tuple{getfield(Base.Distributed, Symbol("#kw##remotecall_fetch")), Array{Any, 1}, typeof(Base.Distributed.remotecall_fetch), typeof(Base.open), Base.Distributed.Worker, typeof(Base.read), String})
precompile(Tuple{getfield(Base.Distributed, Symbol("#kw##remote_do")), Array{Any, 1}, typeof(Base.Distributed.remote_do), typeof(Base.exit), Base.Distributed.Worker})
Expand Down Expand Up @@ -1699,10 +1698,7 @@ precompile(Tuple{typeof(Base.compilecache), String})
precompile(Tuple{typeof(Base.copy!), Array{Tuple{String, Float64}, 1}, Int64, Array{Tuple{String, Float64}, 1}, Int64, Int64})
precompile(Tuple{typeof(Base.create_expr_cache), String, String, Array{Any, 1}})
precompile(Tuple{typeof(Base._delete!), Base.Dict{Symbol, Base.Condition}, Int64})
precompile(Tuple{typeof(Base.Distributed.call_on_owner), typeof(Base.Distributed.fetch_future), Base.Distributed.Future, Int64})
precompile(Tuple{typeof(Base.Distributed.fetch_future), Base.Distributed.RRID, Int64})
precompile(Tuple{typeof(Base.Distributed.flush_gc_msgs), Base.Distributed.Worker})
precompile(Tuple{typeof(Base.Distributed.remotecall_fetch), typeof(Base.Distributed.fetch_future), Base.Distributed.Worker, Base.Distributed.RRID, Int64})
precompile(Tuple{typeof(Base.Distributed.remote_do), typeof(Base.exit), Base.Distributed.Worker})
precompile(Tuple{typeof(Base.Distributed.send_del_client), Base.Distributed.Future})
precompile(Tuple{typeof(Base.Distributed.send_msg), Base.Distributed.Worker, Base.Distributed.MsgHeader, Base.Distributed.CallMsg{:call}})
Expand Down
31 changes: 25 additions & 6 deletions test/distributed_exec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ function test_futures_dgc(id)
@test isnull(f.v) == true
@test fetch(f) == id
@test isnull(f.v) == false
yield(); # flush gc msgs
@test remotecall_fetch(k->(yield();haskey(Base.Distributed.PGRP.refs, k)), id, fid) == false


Expand All @@ -112,14 +113,14 @@ function test_futures_dgc(id)
@test remotecall_fetch(k->(yield();haskey(Base.Distributed.PGRP.refs, k)), id, fid) == true
@test isnull(f.v) == true
finalize(f)
Base.Distributed.flush_gc_msgs()
yield(); # flush gc msgs
@test remotecall_fetch(k->(yield();haskey(Base.Distributed.PGRP.refs, k)), id, fid) == false
end

test_futures_dgc(id_me)
test_futures_dgc(id_other)

# if sent to another worker, it should not be deleted till the other worker has fetched.
# if sent to another worker, it should not be deleted till all references are fetched.
wid1 = workers()[1]
wid2 = workers()[2]
f = remotecall(myid, wid1)
Expand All @@ -130,7 +131,8 @@ put!(fstore, f)

@test fetch(f) == wid1
@test remotecall_fetch(k->haskey(Base.Distributed.PGRP.refs, k), wid1, fid) == true
remotecall_fetch(r->fetch(fetch(r)), wid2, fstore)
remotecall_fetch(r->(fetch(fetch(r)); yield()), wid2, fstore)
sleep(0.5) # to ensure that wid2 gc messages have been executed on wid1
@test remotecall_fetch(k->haskey(Base.Distributed.PGRP.refs, k), wid1, fid) == false

# put! should release remote reference since it would have been cached locally
Expand Down Expand Up @@ -182,7 +184,7 @@ function test_remoteref_dgc(id)
@test fetch(rr) == :OK
@test remotecall_fetch(k->(yield();haskey(Base.Distributed.PGRP.refs, k)), id, rrid) == true
finalize(rr)
Base.Distributed.flush_gc_msgs()
yield(); # flush gc msgs
@test remotecall_fetch(k->(yield();haskey(Base.Distributed.PGRP.refs, k)), id, rrid) == false
end
test_remoteref_dgc(id_me)
Expand All @@ -198,12 +200,29 @@ fstore = RemoteChannel(wid2)
put!(fstore, rr)

@test remotecall_fetch(k->haskey(Base.Distributed.PGRP.refs, k), wid1, rrid) == true
finalize(rr); Base.Distributed.flush_gc_msgs() # finalize locally
finalize(rr) # finalize locally
yield(); # flush gc msgs
@test remotecall_fetch(k->haskey(Base.Distributed.PGRP.refs, k), wid1, rrid) == true
remotecall_fetch(r->(finalize(take!(r)); Base.Distributed.flush_gc_msgs(); nothing), wid2, fstore) # finalize remotely
remotecall_fetch(r->(finalize(take!(r)); yield(); nothing), wid2, fstore) # finalize remotely
sleep(0.5) # to ensure that wid2 messages have been executed on wid1
@test remotecall_fetch(k->haskey(Base.Distributed.PGRP.refs, k), wid1, rrid) == false

# Tests for issue #23109 - should not hang.
f = @spawn rand(1,1)
@sync begin
for _ in 1:10
@async fetch(f)
end
end

wid1,wid2 = workers()[1:2]
f = @spawnat wid1 rand(1,1)
@sync begin
@async fetch(f)
@async remotecall_fetch(()->fetch(f), wid2)
end


@test fetch(@spawnat id_other myid()) == id_other
@test (@fetchfrom id_other myid()) == id_other

Expand Down