Add IPv6 address support for mongodb > 2.7.4 #3

Merged
merged 1 commit into from Nov 25, 2016

Conversation

Projects
None yet
5 participants
Contributor

macgreagoir commented Nov 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.

replicaset.go
- Address: fixIpv6Address(address),
- Tags: tags,
- }},
+ // We don't know the mongod's ability to use a correct IPv6 addr format
@frobware

frobware Nov 23, 2016

Drop "know the" for "know".

replicaset.go
- }},
+ // 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.
@frobware

frobware Nov 23, 2016

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

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.

replicaset.go
+ // 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

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.

replicaset.go
var err error
+ logger.Infof("Initiating replicaset with config %#v", cfg)
@jameinel

jameinel Nov 23, 2016

Owner

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

replicaset.go
+ time.Sleep(initiateAttemptDelay)
+ continue
+ }
+ break Initiate
@jameinel

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

frobware Nov 23, 2016

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

replicaset_test.go
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

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.

@frobware

frobware Nov 23, 2016

What changed that we can no longer run the tests?

@macgreagoir

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.

replicaset.go
}
- logger.Infof("Initiating replicaset with config %#v", cfg)
+
var err error
@frobware

frobware Nov 23, 2016

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

@macgreagoir

macgreagoir Nov 23, 2016

Contributor

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

replicaset.go
-// 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

frobware Nov 23, 2016

suggestion: func formatIPv6AddressWithBrackets.

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

replicaset.go
-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 {
@frobware

frobware Nov 23, 2016

suggestion: func formatIPv6AddressWithoutBrackets.

@macgreagoir

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.

replicaset_test.go
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

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.

@frobware

frobware Nov 23, 2016

What changed that we can no longer run the tests?

@macgreagoir

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.

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

replicaset.go
- err = monotonicSession.Run(bson.D{{"replSetInitiate", cfg}}, nil)
- if err != nil && err.Error() == rsMembersUnreachableError {
+ err = attemptInitiate(monotonicSession, cfg)
+ if err != nil {
@jameinel

jameinel Nov 24, 2016

Owner

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

Otherwise this is triggering maxInitiateAttempts always.

@macgreagoir

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.

LGTM, subject to fixing the "else" stmt.

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

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

macgreagoir Nov 24, 2016

Contributor

I've very recently added the else for clarity around the early return on success.

@hoenirvili

hoenirvili Nov 24, 2016

Collaborator

@frobware @jameinel what are your thoughts about this?

replicaset_test.go
root := newServer(c)
defer root.Destroy()
dialAndTestInitiate(c, root, ipv6GetAddr(root))
+
@frobware

frobware Nov 24, 2016

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

replicaset_test.go
@@ -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)
@frobware

frobware Nov 24, 2016

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
@frobware

frobware Nov 25, 2016

of interface. Insert expects a ....

Minor commentary fix up in loaddata. but LGTM.

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

macgreagoir commented Nov 25, 2016

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

Contributor

macgreagoir commented Nov 25, 2016

$$merge$$

Contributor

jujubot commented Nov 25, 2016

@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