> On Feb. 6, 2014, 11:41 p.m., Ben Mahler wrote:
> > 3rdparty/libprocess/3rdparty/stout/tests/os/signals_tests.cpp, lines 21-22
> > <https://reviews.apache.org/r/17685/diff/2/?file=470396#file470396line21>
> >
> >     Why this change? (Maybe add a note)

Oops, this slipped into this review. I've removed it as it's stout and not 
libprocess.


> On Feb. 6, 2014, 11:41 p.m., Ben Mahler wrote:
> > 3rdparty/libprocess/include/process/collect.hpp, line 64
> > <https://reviews.apache.org/r/17685/diff/2/?file=470397#file470397line64>
> >
> >     This looks like a bug, the future will remain pending since the Promise 
> > is not discarded!

Ah yes, I had originally made ~Promise discard the future which covered these 
cases (in fact, these cases were what motivated the discard in ~Promise). 
Ultimately I removed the discard in ~Promise (made it a TODO) but neglected 
these cases. Thanks!


> On Feb. 6, 2014, 11:41 p.m., Ben Mahler wrote:
> > 3rdparty/libprocess/include/process/future.hpp, lines 109-110
> > <https://reviews.apache.org/r/17685/diff/2/?file=470399#file470399line109>
> >
> >     We should really have documentation for the discard semantics you 
> > describe in this change!

Added comments above 'bool discard()' instead which explains both 'hasDiscard' 
and 'isDiscarded'.


> On Feb. 6, 2014, 11:41 p.m., Ben Mahler wrote:
> > 3rdparty/libprocess/include/process/future.hpp, lines 138-142
> > <https://reviews.apache.org/r/17685/diff/2/?file=470399#file470399line138>
> >
> >     What if users want to pass in an lvalue? Should we not be providing the 
> > overload for that? (Rather than having the const& only for C++03).

I added some more overloads (as many as onDiscarded).


> On Feb. 6, 2014, 11:41 p.m., Ben Mahler wrote:
> > 3rdparty/libprocess/include/process/future.hpp, lines 434-440
> > <https://reviews.apache.org/r/17685/diff/2/?file=470399#file470399line434>
> >
> >     Why does this need to be public? (Maybe add a comment).


> On Feb. 6, 2014, 11:41 p.m., Ben Mahler wrote:
> > 3rdparty/libprocess/include/process/future.hpp, lines 634-640
> > <https://reviews.apache.org/r/17685/diff/2/?file=470399#file470399line634>
> >
> >     We should kill this comment now.

This comment is not about the discard semantics but about the semantics of 
association and thus is still really important. Ultimately it would be nice to 
accomplish what this comment is suggesting (for performance and correctness 
reasons) so I'm going to leave it as it reads.


> On Feb. 6, 2014, 11:41 p.m., Ben Mahler wrote:
> > 3rdparty/libprocess/include/process/future.hpp, lines 643-648
> > <https://reviews.apache.org/r/17685/diff/2/?file=470399#file470399line643>
> >
> >     It seems useful to comment on the propagation flow 'downwards' and 
> > 'upwards' and explicitly call out the relationship between:
> >     
> >     1. Promise::associate
> >     
> >     vs.
> >     
> >     2. Promise::set, Promise::fail, Promise::discard
> >     
> >     We should not call something from 1 after 2, or something from 2 after 
> > 1. (This TODO only addresses 2 after 1, right?).

The code already keeps us from doing an associate if a set, fail, or discard 
has already occurred by doing an 'f.isPending()' check at the top of this 
function. That is, you can't "call something from 1 after 2" because the code 
doesn't allow it (full disclosure: unless you've got two threads racing to call 
Promise::associate and Promise::set/fail/discard concurrently, in which case 
you have a lot of other problems in the code: Promise is explicitly not 
copyable to discourage these semantics, and while we use shared_ptr with 
Promise numerous places they are all effectively Owned). So in summary, yes, 
this comment only addresses 2 after 1, because the code address 1 after 2.


> On Feb. 6, 2014, 11:41 p.m., Ben Mahler wrote:
> > 3rdparty/libprocess/include/process/future.hpp, lines 650-653
> > <https://reviews.apache.org/r/17685/diff/2/?file=470399#file470399line650>
> >
> >     We understood this part, but can you add a little note around why an 
> > onDiscard of 'future' is not propagated here for posterity?

Sure! I added the comment up above near the 'f.onDiscard'.


> On Feb. 6, 2014, 11:41 p.m., Ben Mahler wrote:
> > 3rdparty/libprocess/src/process.cpp, lines 1627-1628
> > <https://reviews.apache.org/r/17685/diff/2/?file=470401#file470401line1627>
> >
> >     It doesn't look like this discard will be noticed by those holding the 
> > Promise for this, and hence the response will never transition out of 
> > pending. Can you double check this?

Why wouldn't the discard be noticed? We have the future here not the promise, 
and discard from the promise will propagate even through an associate (if that 
was your concern). I did notice, however, that there was a race cleaning up the 
pipes from a Response, so I fixed that and left this issue opened.


> On Feb. 6, 2014, 11:41 p.m., Ben Mahler wrote:
> > 3rdparty/libprocess/src/process.cpp, lines 3580-3582
> > <https://reviews.apache.org/r/17685/diff/2/?file=470401#file470401line3580>
> >
> >     Can you add a comment about the cycle you're breaking here (with 
> > WeakFuture)?

There wasn't one in particular, I just like the idea of using WeakFuture in 
these circumstances where propagating discard is really best effort as it's 
more robust to code changes (where, for example, a cycle is introduced that is 
not accounted for).


> On Feb. 6, 2014, 11:41 p.m., Ben Mahler wrote:
> > 3rdparty/libprocess/src/process.cpp, line 3618
> > <https://reviews.apache.org/r/17685/diff/2/?file=470401#file470401line3618>
> >
> >     We're thinking we can avoid the friend function by having a wrapper 
> > continuation for discard that takes a 'Shared' promise, and we also pass a 
> > 'Shared' promise in the watcher data. This avoids the issue with the 
> > promise being deleted by the watcher.
> >     
> >     Does this make sense?

I had tried this approach before but I didn't like the idea of actually 
_sharing_ a Promise via a shared_ptr. Other uses of shared_ptr with Promise are 
supposed to be "owned/unique" (i.e., there won't be the possibility of two 
threads accessing the Promise* at the same time).


> On Feb. 6, 2014, 11:41 p.m., Ben Mahler wrote:
> > 3rdparty/libprocess/src/process.cpp, line 3838
> > <https://reviews.apache.org/r/17685/diff/2/?file=470401#file470401line3838>
> >
> >     Shouldn't this avoid the call to io::write if 
> > promise->future().hasDiscard() is true? (This is basically the same check 
> > you're doing for the io::read call).
> >     
> >     We thought, maybe you wanted to write anything you've read, which 
> > essentially keeps splice somewhat consistent (avoiding dropping any read 
> > data). But, this doesn't seem satisfied in the code here anyway, since the 
> > write future would immediately be discarded. This means the write operation 
> > might stop before writing the read data.

Yes, I like the semantics of always trying to write what you read! Fixed.


> On Feb. 6, 2014, 11:41 p.m., Ben Mahler wrote:
> > 3rdparty/libprocess/src/tests/io_tests.cpp, lines 279-280
> > <https://reviews.apache.org/r/17685/diff/2/?file=470403#file470403line279>
> >
> >     Maybe spell out that you're expecting a failure in the 128 byte 
> > equality check if the second io::write was not successfully discarded?

I refactored it to just read until 'data.size()'.


> On Feb. 6, 2014, 11:41 p.m., Ben Mahler wrote:
> > 3rdparty/libprocess/src/tests/process_tests.cpp, lines 381-396
> > <https://reviews.apache.org/r/17685/diff/2/?file=470404#file470404line381>
> >
> >     Maybe some comments? :)

Interestingly enough, this test does not add any value over the tests above, so 
I've killed it (and discard5).


> On Feb. 6, 2014, 11:41 p.m., Ben Mahler wrote:
> > 3rdparty/libprocess/src/process.cpp, line 3485
> > <https://reviews.apache.org/r/17685/diff/2/?file=470401#file470401line3485>
> >
> >     Re: discard vs discarded
> >     
> >     Consider:
> >     // Stop polling if a discard occurs on our future.

Done.


- Benjamin


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/17685/#review33824
-----------------------------------------------------------


On Feb. 5, 2014, 11:40 p.m., Benjamin Hindman wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/17685/
> -----------------------------------------------------------
> 
> (Updated Feb. 5, 2014, 11:40 p.m.)
> 
> 
> Review request for mesos, Adam B, Ben Mahler, Ian Downes, Jie Yu, Niklas 
> Nielsen, TILL TOENSHOFF, Vinod Kone, and Jiang Yan Xu.
> 
> 
> Repository: mesos-git
> 
> 
> Description
> -------
> 
> Previously, invoking Future::discard caused a future to transition
> into the DISCARDED state which meant that any callbacks associated wit
> such a transition (i.e., Future::onAny, Future::onDiscarded) got
> executed _even if the computation associated with the future had not
> yet completed_! This meant certain patterns where difficult if not all
> together impossible. Consider:
>     
>   ExpensiveResource* resource = new ExpensiveResource();
>     
>   Future<int> future = function()
>     .then([=] () { ... *resource ...; })
>     .onDiscarded([=] () { delete resource; });
>     
>   future.discard();
>     
> In the above code, it's possible that the onDiscarded lambda would
> execute _concurrently_ with the lambda in the then! With the new
> semantics, a discard is more advisorial: rather than transition a
> future it instead allows a subsequent computation to decide whether or
> not to cancel (or even begin) some computation. For example, the
> Future::then implementation uses the "discard" information to decide
> whether or not to execute the next lambda after the previous future
> has been satisfied.
>     
> A few new helpers have been added to support this refactor:
>     
>   Future::onDiscard(callback):
>     
>     Adds a callback for when Future::discard was executed on this future.
>     
>   Future::hasDiscard():
>     
>     Checks to see if Future::discard was executed on this future.
>     
>   Promise::discard():
>     
>     Transitions this promises underlying future to DISCARDED.
> 
> 
> Diffs
> -----
> 
>   3rdparty/libprocess/3rdparty/stout/tests/os/signals_tests.cpp 
> 66caa0490189cb1aff3af1631fbcf7150658b6cc 
>   3rdparty/libprocess/include/process/collect.hpp 
> ff8ab341a588d26f9678aea7f53e892d292725ec 
>   3rdparty/libprocess/include/process/deferred.hpp 
> a25080f7cfc164108e89660d4c38de8b290aee02 
>   3rdparty/libprocess/include/process/future.hpp 
> aaf17af2eef0f1bf7062aa04469f1fa27bb4cfbe 
>   3rdparty/libprocess/include/process/protobuf.hpp 
> 7500601026a58c95325ffe4410a161d59ff7817e 
>   3rdparty/libprocess/src/process.cpp 
> 2e7764a8e0badec704b8610f3f72f0bd16cc9612 
>   3rdparty/libprocess/src/tests/http_tests.cpp 
> 62ab64d81c11ab7260620c91100b7e1f29b81e33 
>   3rdparty/libprocess/src/tests/io_tests.cpp 
> eab786432debf06615572c4486cdf08bac91d927 
>   3rdparty/libprocess/src/tests/process_tests.cpp 
> be288c353dce78ef641708646979e2e4f3f2c504 
> 
> Diff: https://reviews.apache.org/r/17685/diff/
> 
> 
> Testing
> -------
> 
> make check
> 
> 
> Thanks,
> 
> Benjamin Hindman
> 
>

Reply via email to