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

HELP-58644 Add RequireNew session option #13

Merged

Conversation

prestonvasquez
Copy link

@prestonvasquez prestonvasquez commented Apr 29, 2024

HELP-58644

Using a snapshot read concern with atClusterTime on a session may result in selecting a server from the server session pool created before atClusterTime, causing a WriteConflict. Due to this potential issue and the fact that it is only possible as of commit b79a739, the Go Driver does not intend to officially support this use case. As a workaround that avoids nondeterministically tearing down the pool (see here for context), the Go Driver team suggests creating a new session every time this scenario arises.

@prestonvasquez prestonvasquez marked this pull request as draft April 29, 2024 22:23
@prestonvasquez prestonvasquez changed the title HELP-58644 Add RequireNew session option HELP-58644 (POC) Add RequireNew session option Apr 29, 2024
@prestonvasquez prestonvasquez marked this pull request as ready for review April 29, 2024 22:23
@kmorkos
Copy link

kmorkos commented Apr 30, 2024

Testing this branch out locally to confirm it resolves the write conflicts. Will report back shortly

EDIT: confirmed that this works!

@prestonvasquez I noticed that we're actually currently using a release forked off of 1.12.1 - https://github.com/10gen/baas/blob/5d7540e0a8343c659a86c9417f60624634b12a1b/go.mod#L471
Do you mind updating this PR to merge into the release/v1.12.1-baas branch instead?

@prestonvasquez prestonvasquez changed the base branch from v1.13.1-baas to release/v1.12.1-baas April 30, 2024 15:23
@prestonvasquez prestonvasquez changed the base branch from release/v1.12.1-baas to v1.13.1-baas April 30, 2024 15:23
mongo/options/sessionoptions.go Outdated Show resolved Hide resolved
@kmorkos kmorkos changed the base branch from v1.13.1-baas to release/v1.12.1-baas April 30, 2024 15:30
@kmorkos kmorkos changed the base branch from release/v1.12.1-baas to v1.13.1-baas April 30, 2024 15:30
@prestonvasquez prestonvasquez changed the base branch from v1.13.1-baas to release/v1.12.1-baas April 30, 2024 15:41
@@ -230,7 +234,12 @@ func NewClientSession(pool *Pool, clientID uuid.UUID, opts ...*ClientOptions) (*
// SetServer will check out a session from the client session pool.
func (c *Client) SetServer() error {
var err error
c.Server, err = c.pool.GetSession()
if c.RequireNew {
c.Server, err = newServerSession()

Choose a reason for hiding this comment

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

Can we pass the flag to the pool to alter the behavior there? So users can use the session identically regardless of future changes in the pool.

Copy link
Author

Choose a reason for hiding this comment

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

Could you elaborate on this?

Choose a reason for hiding this comment

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

Same concern as Matt's underneath. Will join the discussion in his thread.

@@ -230,7 +234,12 @@ func NewClientSession(pool *Pool, clientID uuid.UUID, opts ...*ClientOptions) (*
// SetServer will check out a session from the client session pool.
func (c *Client) SetServer() error {
var err error
c.Server, err = c.pool.GetSession()
if c.RequireNew {
c.Server, err = newServerSession()

Choose a reason for hiding this comment

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

The session.Server created here will be returned to the pool when EndSession is called. To allow the CheckedOut counter to track this new checked-out session, we should call Pool.createServerSession here instead.

Suggested change
c.Server, err = newServerSession()
c.Server, err = c.pool.createServerSession()

Alternatively, if there's concern about pooling these sessions in the Go Driver, we need to find a way to bypass the pool when we end the session.

Will pooling these new sessions in the Go Driver create any issues?

Copy link
Author

Choose a reason for hiding this comment

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

Good catch, suggest marking the server as dirty when requesting a new server.

Copy link

@matthewdale matthewdale left a comment

Choose a reason for hiding this comment

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

Looks good! 👍

@prestonvasquez prestonvasquez changed the title HELP-58644 (POC) Add RequireNew session option HELP-58644 Add RequireNew session option May 3, 2024
@kmorkos kmorkos merged commit f6b6041 into mongodb-forks:release/v1.12.1-baas May 6, 2024
wlihui7 pushed a commit that referenced this pull request Jul 5, 2024
* HELP-58644 Add RequireNew option

* HELP-58644 Update field comment

* HELP-58644 Clarify RequireNew usage

* HELP-58644 Mark single-checkout servers as dirty

(cherry picked from commit f6b6041)
wlihui7 pushed a commit that referenced this pull request Jul 5, 2024
* HELP-58644 Add RequireNew option

* HELP-58644 Update field comment

* HELP-58644 Clarify RequireNew usage

* HELP-58644 Mark single-checkout servers as dirty

(cherry picked from commit f6b6041)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants