Skip to content

serialize map access #97

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

Merged
merged 1 commit into from
Oct 5, 2017
Merged

serialize map access #97

merged 1 commit into from
Oct 5, 2017

Conversation

rchirakk
Copy link
Contributor

@rchirakk rchirakk commented Oct 2, 2017

Signed-off-by: Ranjith [email protected]

@@ -105,6 +105,9 @@ func (self *OFSwitch) DefaultTable() *Table {

// Return a output graph element for the port
func (self *OFSwitch) OutputPort(portNo uint32) (*Output, error) {
self.portMux.Lock()
defer self.portMux.Unlock()

if self.outputPorts[portNo] != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we change this to the more standard:

if value, ok := self.outputPorts[portNo]; ok {
  return value, nil
}

😄 ?

@@ -35,6 +36,7 @@ type OFSwitch struct {
dropAction *Output
sendToCtrler *Output
normalLookup *Output
portMux sync.Mutex
outputPorts map[uint32]*Output
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Good idea!

Go actually has a build in concurrent map now: https://golang.org/pkg/sync/#Map

(but we can't use it until we're compiling with 1.9)

Copy link
Contributor

Choose a reason for hiding this comment

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

@rchirakk: This is a good idea. Can you modify the code to use the concurrent map, please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

didn't use concurrent map because

  1. to keep the change to minimum.
  2. concurrent map requires string as key
  3. concurrent map is implemented as 32 maps with mutex, overkill for this case.

Copy link
Contributor

Choose a reason for hiding this comment

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

@rchirakk: That makes sense. Thank you.

@unclejack
Copy link
Contributor

@rchirakk: Can you write a test which triggers the issue you've discovered, please?

@rchirakk
Copy link
Contributor Author

rchirakk commented Oct 3, 2017

@unclejack it was detected in CI contiv/netplugin#972
I think this was one of the cases missed from earlier commit.

@unclejack
Copy link
Contributor

@rchirakk: Ok, I'll take another look tomorrow.

Signed-off-by: Ranjith <[email protected]>
@rchirakk
Copy link
Contributor Author

rchirakk commented Oct 4, 2017

@srampal @gkvijay PTAL

Copy link
Contributor

@unclejack unclejack left a comment

Choose a reason for hiding this comment

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

LGTM

@kahou82
Copy link
Member

kahou82 commented Oct 5, 2017

👍

@dseevr dseevr requested a review from a team October 5, 2017 00:49
@gkvijay gkvijay merged commit 17e8080 into contiv:master Oct 5, 2017
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