Skip to content

Add support to MaxStalenessSeconds in ReadPreference - #271

Open
wpjunior wants to merge 3 commits into
globalsign:developmentfrom
wpjunior:MaxStalenessSeconds
Open

Add support to MaxStalenessSeconds in ReadPreference#271
wpjunior wants to merge 3 commits into
globalsign:developmentfrom
wpjunior:MaxStalenessSeconds

Conversation

@wpjunior

@wpjunior wpjunior commented Sep 23, 2018

Copy link
Copy Markdown

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

@domodwyer domodwyer left a comment

Copy link
Copy Markdown

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.

Comment thread session.go
Comment thread session.go
}
case "maxStalenessSeconds":
maxStalenessSeconds, err = strconv.Atoi(opt.value)
if err != nil {

Copy link
Copy Markdown

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
Copy Markdown
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.

Comment thread session.go

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

Copy link
Copy Markdown

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.

Comment thread session.go
Mode Mode

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

Copy link
Copy Markdown

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
Copy Markdown
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.

Comment thread session.go
if err != nil {
return nil, errors.New("bad value for maxPoolSize: " + opt.value)
}
case "maxStalenessSeconds":

Copy link
Copy Markdown

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
Copy Markdown

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
Copy Markdown
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.

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

Copy link
Copy Markdown

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.

Comment thread session.go
// 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
Copy Markdown

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 ?

Comment thread session.go
if err != nil {
return nil, errors.New("bad value for maxPoolSize: " + opt.value)
}
case "maxStalenessSeconds":

Copy link
Copy Markdown

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
@wpjunior
wpjunior force-pushed the MaxStalenessSeconds branch from 39ae9df to 7bf893d Compare October 7, 2018 14:48

@eminano eminano left a comment

Copy link
Copy Markdown

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

wpjunior commented Dec 2, 2018

Copy link
Copy Markdown
Author

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
Copy Markdown

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