Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
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 |
| - }}, | ||
| + // 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. |
jameinel
reviewed
Nov 23, 2016
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{ |
jameinel
Nov 23, 2016
Owner
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) |
jameinel
Nov 23, 2016
Owner
should this actually be moved into the loop so we only report 1 config at a time?
| + time.Sleep(initiateAttemptDelay) | ||
| + continue | ||
| + } | ||
| + break Initiate |
jameinel
Nov 23, 2016
Owner
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.
frobware
Nov 23, 2016
Agreed. I actually pulled the change locally to make sure I understood the exit conditions.
| assertAddRemoveSet(c, root, ipv6GetAddr) | ||
| } | ||
| func (s *MongoIPV6Suite) TestAddressFixing(c *gc.C) { | ||
| + c.Skip("Skipping test until rewritten for good and bad IPv6 addr formats") |
jameinel
Nov 23, 2016
Owner
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.
macgreagoir
Nov 23, 2016
Contributor
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 |
macgreagoir
Nov 23, 2016
Contributor
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>") |
frobware
suggested changes
Nov 23, 2016
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 { |
macgreagoir
Nov 23, 2016
Contributor
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") |
jameinel
Nov 23, 2016
Owner
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.
macgreagoir
Nov 23, 2016
Contributor
In fact, I'm not sure we now need to skip this, with the fix in the Initiate function. Thanks for the catch.
jameinel
requested changes
Nov 24, 2016
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 { |
jameinel
Nov 24, 2016
Owner
I think this becomes
if err != nil {
time.Sleep()
} else {
break
}
Otherwise this is triggering maxInitiateAttempts always.
macgreagoir
Nov 24, 2016
Contributor
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.
| + err = monotonicSession.Run(bson.D{{"replSetInitiate", c}}, nil) | ||
| + if err != nil { | ||
| + logger.Infof("Unsuccessful attempt to initiate replicaset: %v", err) | ||
| + } else { |
hoenirvili
Nov 24, 2016
Collaborator
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
macgreagoir
Nov 24, 2016
Contributor
I've very recently added the else for clarity around the early return on success.
| root := newServer(c) | ||
| defer root.Destroy() | ||
| dialAndTestInitiate(c, root, ipv6GetAddr(root)) | ||
| + |
frobware
Nov 24, 2016
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) |
| @@ -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 |
frobware
approved these changes
Nov 25, 2016
Minor commentary fix up in loaddata. but LGTM.
|
@jameinel Your issue is now fixed too, so I'll $$merge$$ |
|
$$merge$$ |
|
Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju-replicaset |
macgreagoir commentedNov 22, 2016
MongoDB of versions greater than 2.7.4 can use the correct bracketed
IPv6 format ([addr]:port). This change adds support for that format.