Skip to content

Conversation

matthewdale
Copy link
Collaborator

@matthewdale matthewdale commented Aug 22, 2025

GODRIVER-3612

Summary

Add an internal-only API mongo.NewSessionWithLSID that returns a *Session for the specified Client and session ID document.

Background & Motivation

Copy link
Contributor

API Change Report

No changes found!

Copy link
Contributor

mongodb-drivers-pr-bot bot commented Aug 22, 2025

🧪 Performance Results

Commit SHA: 03adad0

The following benchmark tests for version 68b22835a327320007f01f24 had statistically significant changes (i.e., |z-score| > 1.96):

Benchmark Measurement % Change Patch Value Stable Region H-Score Z-Score
BenchmarkBSONFlatDocumentEncoding ns_per_op 4.9834 16422.0000 Avg: 15642.4688
Med: 15600.5000
Stdev: 383.4528
0.7308 2.0329
BenchmarkBSONDeepDocumentDecoding total_bytes_allocated -2.5139 245528776.0000 Avg: 251860213.4194
Med: 252330328.0000
Stdev: 3023314.2474
0.7329 -2.0942
BenchmarkBSONDeepDocumentDecoding total_mem_allocs -2.4551 11305294.0000 Avg: 11589832.4194
Med: 11611115.0000
Stdev: 138499.4358
0.7275 -2.0544
BenchmarkLargeDocInsertOne allocated_bytes_per_op -0.2863 5643.0000 Avg: 5659.2000
Med: 5660.0000
Stdev: 6.1085
0.8134 -2.6520
BenchmarkBSONDeepDocumentDecoding allocated_bytes_per_op -0.0609 15094.0000 Avg: 15103.1935
Med: 15104.0000
Stdev: 2.3723
0.9183 -3.8753

For a comprehensive view of all microbenchmark results for this PR's commit, please check out the Evergreen perf task for this patch.

@matthewdale matthewdale force-pushed the godriver3612-session-with-id branch from bc7a505 to 9eb374b Compare August 22, 2025 18:47
@matthewdale matthewdale added review-priority-normal Medium Priority PR for Review: within 1 business day feature ignore-for-release labels Aug 27, 2025
@matthewdale matthewdale marked this pull request as ready for review August 27, 2025 01:47
@Copilot Copilot AI review requested due to automatic review settings August 27, 2025 01:47
@matthewdale matthewdale requested a review from a team as a code owner August 27, 2025 01:47
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds an internal-only API mongo.NewSessionWithID that creates a *Session for a specified Client and session ID document. This API is intended for internal use cases where specific session IDs need to be used rather than letting the driver generate them automatically.

  • Introduces NewSessionWithID function that constructs sessions with custom session ID documents
  • Implements build tag protection (//go:build mongointernal) to restrict usage to internal builds only
  • Updates CI configuration to enable the mongointernal build tag in tests

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
mongo/mongointernal.go Implements the new NewSessionWithID API with proper documentation and build tag restrictions
internal/integration/mongointernal_test.go Adds comprehensive tests covering both successful usage and expected panic behavior
.evergreen/config.yml Updates CI build tags to include mongointernal for proper test execution

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@matthewdale matthewdale requested review from prestonvasquez and removed request for qingyang-hu August 27, 2025 01:48
Copy link
Member

@prestonvasquez prestonvasquez left a comment

Choose a reason for hiding this comment

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

I'm concerned about users using session.Client methods that involve a pool. Or worse, maintainers adding a new method to session.Client that requires accessing the pool and forgetting to document that behavior for NewSessionWithID.

I've created GODRIVER-3649 to follow up on this in 3.0.

//
// NewSessionWithID is intended only for internal use and may be changed or
// removed at any time.
func NewSessionWithID(client *Client, sessionID bson.Raw) *Session {
Copy link
Member

@prestonvasquez prestonvasquez Aug 28, 2025

Choose a reason for hiding this comment

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

[nit] Suggest renaming this function to NewSessionWithLSID

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Renamed.

// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

//go:build mongointernal
Copy link
Member

@prestonvasquez prestonvasquez Aug 28, 2025

Choose a reason for hiding this comment

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

[non-blocking] Should we name this mongointernal_lsid to keep it separate from any future code we may want to gate behind a mongointernal build tag?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm concerned too many build tags will become a maintenance headache, both for us and for the internal teams who use the Go Driver. I'm assuming that an app that uses one internal-only API may need to use many internal-only APIs, and keeping track of a list of build tags may become onerous.

Is there a scenario you're thinking of where it's better to have more granular build tags?

Copy link
Member

Choose a reason for hiding this comment

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

Is there a scenario you're thinking of where it's better to have more granular build tags?

No, and the more I think about it it seems unlikely that we will need to use mongointernal often.

mt.Parallel()

sessionID := bson.Raw(bsoncore.NewDocumentBuilder().
AppendBinary("id", 4, []byte{}).
Copy link
Member

@prestonvasquez prestonvasquez Aug 28, 2025

Choose a reason for hiding this comment

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

[nit] Suggest using a valid 16-byte UUID to ensure the panic is due to the session being unpooled and not an invalid LSID.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated.

// subtype 4).
//
// Sessions returned by NewSessionWithID are never added to the driver's session
// pool. Calling EndSession on a Session returned by NewSessionWithID will
Copy link
Member

@prestonvasquez prestonvasquez Aug 28, 2025

Choose a reason for hiding this comment

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

[non-blocking] We should include SetServer as API that will panic. I'm not sure why anyone would use it and AFAIK it's only use case happens for implicit sessions, but it's still possible:

sess.Client().SetSrerver() // will panic 

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added note that ClientSession().SetServer() will panic and a test to confirm it does.

@matthewdale matthewdale changed the title GODRIVER-3612 Add an internal-only NewSessionWithID API. GODRIVER-3612 Add an internal-only NewSessionWithLSID API. Aug 29, 2025
prestonvasquez
prestonvasquez previously approved these changes Aug 30, 2025
@matthewdale matthewdale enabled auto-merge (squash) September 2, 2025 16:53
@matthewdale matthewdale changed the base branch from master to release/1.17 September 2, 2025 16:55
@matthewdale matthewdale dismissed prestonvasquez’s stale review September 2, 2025 16:55

The base branch was changed.

@matthewdale matthewdale changed the base branch from release/1.17 to master September 2, 2025 17:08
@matthewdale
Copy link
Collaborator Author

I just realized this needs to target release/1.17. I've created #2183 for that.

@matthewdale matthewdale changed the title GODRIVER-3612 Add an internal-only NewSessionWithLSID API. GODRIVER-3612 Add an internal-only NewSessionWithLSID API (v2) Sep 3, 2025
@matthewdale matthewdale merged commit b79c3f6 into mongodb:master Sep 4, 2025
36 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature ignore-for-release review-priority-normal Medium Priority PR for Review: within 1 business day

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants