Skip to content

Comments

Use ordered array instead of heap for sb.endpoints#2103

Merged
ctelfer merged 2 commits intomoby:masterfrom
cziebuhr:2093-iface_order
May 30, 2018
Merged

Use ordered array instead of heap for sb.endpoints#2103
ctelfer merged 2 commits intomoby:masterfrom
cziebuhr:2093-iface_order

Conversation

@cziebuhr
Copy link
Contributor

@cziebuhr cziebuhr commented Mar 8, 2018

Fix order of endpoints when there are more than two. See #2093 for details.

@codecov-io
Copy link

codecov-io commented Mar 8, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@2bf6330). Click here to learn what that means.
The diff coverage is 84.61%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #2103   +/-   ##
=========================================
  Coverage          ?   40.51%           
=========================================
  Files             ?      139           
  Lines             ?    22347           
  Branches          ?        0           
=========================================
  Hits              ?     9053           
  Misses            ?    11962           
  Partials          ?     1332
Impacted Files Coverage Δ
resolver.go 36.64% <0%> (ø)
sandbox_store.go 32.93% <0%> (ø)
endpoint.go 53.8% <100%> (ø)
controller.go 36.65% <100%> (ø)
sandbox.go 45.63% <95.23%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2bf6330...056f8ec. Read the comment docs.

@abhi
Copy link
Contributor

abhi commented Mar 14, 2018

@cziebuhr Thank you for raising the PR. The solution looks reasonable to me. Please allow us sometime to review the PR and get back.

Copy link
Contributor

@ctelfer ctelfer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
@cziebuhr
Copy link
Contributor Author

PR has been updated

@ctelfer
Copy link
Contributor

ctelfer commented Mar 25, 2018

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.

@selansen
Copy link
Contributor

I just took a look at the changes. LGTM. WRT option b, I suggest we make separate PR.

Copy link
Contributor

@ctelfer ctelfer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ctelfer
Copy link
Contributor

ctelfer commented Mar 27, 2018

Re: part b) -- agree that a separate PR would be fine. The larger question is going to be how to expose this in moby...

@ctelfer ctelfer merged commit 056f8ec into moby:master May 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants