Use ordered array instead of heap for sb.endpoints#2103
Conversation
d047825 to
04e668b
Compare
Codecov Report
@@ Coverage Diff @@
## master #2103 +/- ##
=========================================
Coverage ? 40.51%
=========================================
Files ? 139
Lines ? 22347
Branches ? 0
=========================================
Hits ? 9053
Misses ? 11962
Partials ? 1332
Continue to review full report at Codecov.
|
|
@cziebuhr Thank you for raising the PR. The solution looks reasonable to me. Please allow us sometime to review the PR and get back. |
ctelfer
left a comment
There was a problem hiding this comment.
Overall this looks like a reasonable approach to me. I have just a few comments regarding locking.
Also, should we have a unit test to check that the order is as expected?
| sb.Lock() | ||
| sb.removeEndpoint(ep) | ||
| sb.Unlock() | ||
| } |
There was a problem hiding this comment.
Rather than removing the sandbox locking from sandbox.removeEndpoint() why not have sandbox.addEndpoint() lock like the rest of the sandbox methods that iterate over the endpoint set? Is there a reason for add/remove to be separated out? If not, please put the locking within the method.
| heap.Push(&sb.endpoints, ep) | ||
| sb.addEndpoint(ep) | ||
| } | ||
|
|
There was a problem hiding this comment.
Unless there is a reason to not keep the sandbox locking within the methods (see above), then one should acquire the sandbox lock before ranging over the endpoints at the end of this function. Alternately, one could just range over sb.getConnectedEndpoints(). Overall, it probably won't matter based on how this function gets used.
I would have put this comment closer to the actual source line, but given that it is not near a modification github won't let me.
There was a problem hiding this comment.
I generally agree, it's better to have the lock inside the functions. It didn't work for me because clearNetworkResources already acquired a lock when calling sb.removeEndpoint and go doesn't seem to like double locking. I wasn't sure if unlocking and relocking around calling sb.removeEndpoint is an option.
There was a problem hiding this comment.
Ah, I see. Suggest the following then. Still lock in removeEndpoint(), but have it wrap a method removeEndpointRaw() (rename as desired) that does the real work. Call the latter within the sandbox methods (clearNetworkResources()) and the former outside of sandbox methods (e.g. in sbJoin, sandboxCleanup()). So removeEndpoint() would look something like this:
func (sb *sandbox) removeEndpoint(ep *endpoint) {
sb.Lock()
defer sb.Unlock()
return sb.removeEndpointRaw(ep)
}and with removeEndpointRaw() would look like removeEndpoint() does in your patch. Makes sense?
There was a problem hiding this comment.
Will change the code tomorrow. As a side-effect we then also do locking when calling sb.addEndpoint from sandbox_store.go, which I assume should be fine.
Do you have any objections on #2093 b) and c)?
Signed-off-by: Christoph Ziebuhr <[email protected]>
Signed-off-by: Christoph Ziebuhr <[email protected]>
cf1456b to
056f8ec
Compare
|
PR has been updated |
|
Hey. Sorry for the delayed response. Needed to do some background research as I wasn't familiar with this section of the code. First, the changes LGTM. Thanks! Second, w.r.t. #2093 .. I have updated my answer in the issue there, but the short answer is that in the case of b) I think that the current comparison is stable/consistent, but may not match what we would want and in the case of c) yes, we need work there. We could possibly address point b) in the same patch by altering the new endpoint.Less() function to consider priority first. (see discussion there) Or we could make that a separate PR. I could see arguments for both. |
|
I just took a look at the changes. LGTM. WRT option b, I suggest we make separate PR. |
|
Re: part b) -- agree that a separate PR would be fine. The larger question is going to be how to expose this in moby... |
Fix order of endpoints when there are more than two. See #2093 for details.