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 support to MaxStalenessSeconds in ReadPreference #271

Open
wants to merge 3 commits into
base: development
Choose a base branch
from

Conversation

wpjunior
Copy link

@wpjunior wpjunior commented Sep 23, 2018

from #270

@wpjunior wpjunior force-pushed the MaxStalenessSeconds branch 4 times, most recently from 268d296 to ad7fb14 Compare September 23, 2018 22:38
@wpjunior wpjunior changed the title WIP: add support to MaxStalenessSeconds in ReadPreference Add support to MaxStalenessSeconds in ReadPreference Sep 23, 2018
Copy link

@domodwyer domodwyer left a comment

Choose a reason for hiding this comment

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

Is there any way to add functional tests for this, beyond the config parsing? Seems like there might be a few edge cases.

session.go Show resolved Hide resolved
@@ -390,6 +391,11 @@ func ParseURL(url string) (*DialInfo, error) {
if err != nil {
return nil, errors.New("bad value for maxPoolSize: " + opt.value)
}
case "maxStalenessSeconds":
maxStalenessSeconds, err = strconv.Atoi(opt.value)
if err != nil {

Choose a reason for hiding this comment

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

I think this would need the maxStalenessSeconds >= 0 check to compliment the SetMaxStalenessSeconds() behaviour?

Copy link
Author

Choose a reason for hiding this comment

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

thanks @domodwyer, I've added you recommendation.

@@ -2190,6 +2204,22 @@ func (s *Session) SetPoolTimeout(timeout time.Duration) {
s.m.Unlock()
}

// SetMaxStalenessSeconds set the maximum of seconds of replication lag from secondaries
//
// Relevant documentation:

Choose a reason for hiding this comment

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

It might be worth including that if seconds > 90 it's currently expected to receive an error from mongodb:

You must specify a maxStalenessSeconds value of 90 seconds or longer: specifying a smaller maxStalenessSeconds value will raise an error.

@@ -679,6 +689,9 @@ type ReadPreference struct {
// Mode determines the consistency of results. See Session.SetMode.
Mode Mode

// MaxStalenessSeconds specify a maximum replication lag, or “staleness” in seconds, for reads from secondaries.
MaxStalenessSeconds int

Choose a reason for hiding this comment

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

Is this missing an omitempty tag? I imagine you don't want to send maxStalenessSeconds: 0 with every request if it was not set by the user.

Copy link
Author

Choose a reason for hiding this comment

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

hi @domodwyer, the wire information is sent by socket.go(line: 131), I suppose that tag is not necessary here, thanks.

@@ -390,6 +391,11 @@ func ParseURL(url string) (*DialInfo, error) {
if err != nil {
return nil, errors.New("bad value for maxPoolSize: " + opt.value)
}
case "maxStalenessSeconds":
Copy link

Choose a reason for hiding this comment

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

According to the documentation maxStalenessSeconds is not compatible with mode primary, so maybe you could add that restriction to the existing check below (line 460).

Copy link

Choose a reason for hiding this comment

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

Also, could you please add description of this parameter to the Dial method documentation (i.e. https://godoc.org/github.com/globalsign/mgo#Dial)

Copy link
Author

Choose a reason for hiding this comment

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

thanks @eminano and @szank, could you see my commits updates ?, I committed some changes.

session.go Outdated
//
func (s *Session) SetMaxStalenessSeconds(seconds int) {
s.m.Lock()
if seconds > -1 {
Copy link

Choose a reason for hiding this comment

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

The documentation states you must specify a maxStalenessSeconds value of 90 seconds or longer (smaller values will raise an error). Since you're doing a validity check here it might be worth checking that as well.

@@ -679,6 +689,9 @@ type ReadPreference struct {
// Mode determines the consistency of results. See Session.SetMode.
Mode Mode

// MaxStalenessSeconds specify a maximum replication lag, or “staleness” in seconds, for reads from secondaries.
Copy link

Choose a reason for hiding this comment

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

Could you please add a comment stating that this option is supported in mongo >= 3.4 only ?

@@ -390,6 +391,11 @@ func ParseURL(url string) (*DialInfo, error) {
if err != nil {
return nil, errors.New("bad value for maxPoolSize: " + opt.value)
}
case "maxStalenessSeconds":
Copy link

Choose a reason for hiding this comment

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

Also, could you please add description of this parameter to the Dial method documentation (i.e. https://godoc.org/github.com/globalsign/mgo#Dial)

@wpjunior wpjunior force-pushed the MaxStalenessSeconds branch 4 times, most recently from 67ff921 to 39ae9df Compare October 7, 2018 12:53
Copy link

@eminano eminano left a comment

Choose a reason for hiding this comment

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

As @domodwyer mentioned previously, is it possible to add functional tests for this?

@wpjunior
Copy link
Author

wpjunior commented Dec 2, 2018

Hi @eminano, would you check the possibility to approve this MR ?, this scenario is too hard to create an integration test.

Thanks =)

@wangke1020
Copy link

It seems the changes only pass a ReadPreference params to server and did not select proper servers, so at my guess the driver will not work with mongo replset but sharding cluster.
According to https://github.com/mongodb/specifications/blob/master/source/max-staleness/max-staleness.rst#client, server selection should be implemented in client side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants