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
Conversation
Address: fixIpv6Address(address), | ||
Tags: tags, | ||
}}, | ||
// We don't know the mongod's ability to use a correct IPv6 addr format |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this 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{ |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 :=
.
There was a problem hiding this comment.
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>") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: func formatIPv6AddressWithBrackets
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this 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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: func formatIPv6AddressWithoutBrackets
.
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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?
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
root := newServer(c) | ||
defer root.Destroy() | ||
dialAndTestInitiate(c, root, ipv6GetAddr(root)) | ||
|
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 ....
There was a problem hiding this 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.
@jameinel Your issue is now fixed too, so I'll |
|
Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju-replicaset |
MongoDB of versions greater than 2.7.4 can use the correct bracketed
IPv6 format ([addr]:port). This change adds support for that format.