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

Add IPv6 address support for mongodb > 2.7.4 #3

Merged
merged 1 commit into from Nov 25, 2016

Conversation

macgreagoir
Copy link
Contributor

MongoDB of versions greater than 2.7.4 can use the correct bracketed
IPv6 format ([addr]:port). This change adds support for that format.

Address: fixIpv6Address(address),
Tags: tags,
}},
// We don't know the mongod's ability to use a correct IPv6 addr format

Choose a reason for hiding this comment

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

Drop "know the" for "know".

}},
// We don't know the mongod's ability to use a correct IPv6 addr format
// until the server is started, but we need to know before we can start
// it. Try the older, incorrect format if the correct format fails.

Choose a reason for hiding this comment

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

Try the older, incorrect format, if the correct format fails.

Copy link
Member

@jameinel jameinel left a comment

Choose a reason for hiding this comment

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

Overall I think there are a couple tweaks. I question if we really want to support <=2.6 anymore, but if it isn't hard to do so, we can go with this. One question it raises is why the Initiate failed, given we already had a loop there, it could easily be failing for reasons that aren't the IPv6 address string.

// We don't know the mongod's ability to use a correct IPv6 addr format
// until the server is started, but we need to know before we can start
// it. Try the older, incorrect format if the correct format fails.
cfg := []Config{
Copy link
Member

Choose a reason for hiding this comment

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

configs ? something plural is probably useful since its now a list.

I also wonder if we really want this, or if it would be better to just always use the proper IPv6 form, and drop support for 2.4 + IPv6.

var err error
logger.Infof("Initiating replicaset with config %#v", cfg)
Copy link
Member

Choose a reason for hiding this comment

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

should this actually be moved into the loop so we only report 1 config at a time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

time.Sleep(initiateAttemptDelay)
continue
}
break Initiate
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if using labels and break is clearer than a boolean "successful". Or if we'd actually like to pull this out into a separate function and just have that "return".

It does feel like this overall function is getting a little bit big.

Choose a reason for hiding this comment

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

Agreed. I actually pulled the change locally to make sure I understood the exit conditions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

assertAddRemoveSet(c, root, ipv6GetAddr)
}

func (s *MongoIPV6Suite) TestAddressFixing(c *gc.C) {
c.Skip("Skipping test until rewritten for good and bad IPv6 addr formats")
Copy link
Member

Choose a reason for hiding this comment

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

can you add a comment as to why this isn't working right now? Maybe just explain directly, but a comment lets someone else come back to address it.

Choose a reason for hiding this comment

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

What changed that we can no longer run the tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In fact, I'm not sure we now need to skip this, with the fix in the Initiate function. Thanks for the catch.

}
logger.Infof("Initiating replicaset with config %#v", cfg)

var err error

Choose a reason for hiding this comment

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

This can go inside the for loop as err :=.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the var eventually returned by the function, so I think we need it in this higher scope.

// Turn "bad format" ipv6 addresses ("::1:port"), that mongo uses, into good
// format addresses ("[::1]:port").
func unFixIpv6Address(address string) string {
// unBreakIpv6Address turns the "bad format" IPv6 addresses ("<addr>:<port>")

Choose a reason for hiding this comment

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

suggestion: func formatIPv6AddressWithBrackets.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link

@frobware frobware left a comment

Choose a reason for hiding this comment

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

It would be good if we could simplify the loop that now has a label.

func fixIpv6Address(address string) string {
// breakIpv6Address turns correctly formatted IPv6 addresses into the "bad
// format" (without brackets around the address) that mongo <2.7 require use.
func breakIpv6Address(address string) string {

Choose a reason for hiding this comment

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

suggestion: func formatIPv6AddressWithoutBrackets.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough. formatIPv6AddressWith{,out}Brackets are potentially harder to read for their length and difference in the middle (not start) of the names, but certainly more descriptive.

assertAddRemoveSet(c, root, ipv6GetAddr)
}

func (s *MongoIPV6Suite) TestAddressFixing(c *gc.C) {
c.Skip("Skipping test until rewritten for good and bad IPv6 addr formats")

Choose a reason for hiding this comment

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

What changed that we can no longer run the tests?

Copy link
Member

@jameinel jameinel left a comment

Choose a reason for hiding this comment

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

LGTM, subject to fixing the "break" out of the for loop.

err = monotonicSession.Run(bson.D{{"replSetInitiate", cfg}}, nil)
if err != nil && err.Error() == rsMembersUnreachableError {
err = attemptInitiate(monotonicSession, cfg)
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

I think this becomes
if err != nil {
time.Sleep()
} else {
break
}

Otherwise this is triggering maxInitiateAttempts always.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cheers. In fact, else } break is probably more readable than the continue and fall through to break used in other parts of the function, so I'll fix this missing break and update the other uses.

Copy link

@hoenirvili hoenirvili left a comment

Choose a reason for hiding this comment

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

LGTM, subject to fixing the "else" stmt.

err = monotonicSession.Run(bson.D{{"replSetInitiate", c}}, nil)
if err != nil {
logger.Infof("Unsuccessful attempt to initiate replicaset: %v", err)
} else {

Choose a reason for hiding this comment

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

I think you should remove the else and make it like this.

 if err = monotonicSession.Run(bson.D{{"replSetInitiate", c}}, nil); err != nil {
     logger.Infof("Unsuccessful attempt to initiate replicaset: %v", err)
 }
return nil
// code

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've very recently added the else for clarity around the early return on success.

Choose a reason for hiding this comment

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

@frobware @jameinel what are your thoughts about this?

root := newServer(c)
defer root.Destroy()
dialAndTestInitiate(c, root, ipv6GetAddr(root))

Choose a reason for hiding this comment

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

Drop the blank line. The fewer lines I have to review, the quicker I can review. 👍

@@ -127,7 +139,7 @@ func loadData(session *mgo.Session, c *gc.C) {
}

for col := 0; col < 10; col++ {
foos := make([]foo, 10000)
foos := make([]interface{}, 10000)

Choose a reason for hiding this comment

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

This change seems unnecessary. I tried this locally and it runs/tests OK.

@@ -127,7 +139,13 @@ func loadData(session *mgo.Session, c *gc.C) {
}

for col := 0; col < 10; col++ {
foos := make([]foo, 10000)
// Testing with mongodb3.2 showed the need to make foos a slice
// if interface{} (Insert expects a slice not an empty

Choose a reason for hiding this comment

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

of interface. Insert expects a ....

Copy link

@frobware frobware left a comment

Choose a reason for hiding this comment

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

Minor commentary fix up in loaddata. but LGTM.

MongoDB of versions greater than 2.7.4 can use the correct bracketed
IPv6 format ([addr]:port). This change adds support for that format.
@macgreagoir
Copy link
Contributor Author

@jameinel Your issue is now fixed too, so I'll $$merge$$

@macgreagoir
Copy link
Contributor Author

$$merge$$

@jujubot
Copy link
Contributor

jujubot commented Nov 25, 2016

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju-replicaset

@jujubot jujubot merged commit 6b5becf into juju:master Nov 25, 2016
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.

None yet

5 participants