Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.

chore: support for common interface to get a session to support multiplexed session#2204

Merged
gcf-merge-on-green[bot] merged 12 commits intomainfrom
get-session-class
Dec 27, 2024
Merged

chore: support for common interface to get a session to support multiplexed session#2204
gcf-merge-on-green[bot] merged 12 commits intomainfrom
get-session-class

Conversation

@alkatrivedi
Copy link
Copy Markdown
Contributor

@alkatrivedi alkatrivedi commented Dec 12, 2024

This PR contains the common interface class SessionFactory which will be responsible for the creation of the Session Pool and the Multiplexed Session(if the env variable would be set to true) upon client initialization.

This PR also contains the getSession method which will return the session(multiplexed/regular) based upon the env variable value.

@alkatrivedi alkatrivedi requested review from a team December 12, 2024 02:32
@product-auto-label product-auto-label bot added size: l Pull request size is large. api: spanner Issues related to the googleapis/nodejs-spanner API. labels Dec 12, 2024
@alkatrivedi alkatrivedi force-pushed the get-session-class branch 4 times, most recently from bddd1d4 to 421a5a1 Compare December 16, 2024 09:25
@alkatrivedi alkatrivedi force-pushed the get-session-class branch 3 times, most recently from 21394ef to 3730a8a Compare December 19, 2024 17:07
@alkatrivedi alkatrivedi added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Dec 19, 2024
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Dec 19, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 19, 2024
@alkatrivedi alkatrivedi added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Dec 20, 2024
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Dec 20, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 20, 2024
@alkatrivedi alkatrivedi force-pushed the get-session-class branch 3 times, most recently from e24245d to be238ed Compare December 21, 2024 08:12
@alkatrivedi alkatrivedi added the owlbot:run Add this label to trigger the Owlbot post processor. label Dec 21, 2024
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Dec 21, 2024
@alkatrivedi alkatrivedi added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Dec 21, 2024
@alkatrivedi alkatrivedi force-pushed the get-session-class branch 2 times, most recently from a5fa3d0 to 4024beb Compare December 26, 2024 10:56
@alkatrivedi alkatrivedi added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Dec 26, 2024
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Dec 26, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 26, 2024
Comment on lines +96 to +122
/**
* Retrieves the session, either the regular session or the multiplexed session based upon the environment varibale
* If the environment variable GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS is set to `true` the method will attempt to
* retrieve the multiplexed session. Otherwise it will retrieve the session from the pool.
*
* The session is returned asynchronously via the provided callback, which will receive either an error or the session object.
* @param callback
*/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
/**
* Retrieves the session, either the regular session or the multiplexed session based upon the environment varibale
* If the environment variable GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS is set to `true` the method will attempt to
* retrieve the multiplexed session. Otherwise it will retrieve the session from the pool.
*
* The session is returned asynchronously via the provided callback, which will receive either an error or the session object.
* @param callback
*/
/**
* Retrieves a session, either a regular session or a multiplexed session, based on the environment variable configuration.
*
* If the environment variable `GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS` is set to `true`, the method will attempt to
* retrieve a multiplexed session. Otherwise, it will retrieve a session from the regular pool.
*
* @param {GetSessionCallback} callback The callback function.
*/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines +114 to +138
/**
* Returns the SessionPoolInterface used by the current instance, which provide access to the session pool
* for obtaining database sessions.
*
* @returns {SessionPoolInterface} The session pool used by current instance.
* This object allows interaction with the pool for acquiring and managing sessions.
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
/**
* Returns the SessionPoolInterface used by the current instance, which provide access to the session pool
* for obtaining database sessions.
*
* @returns {SessionPoolInterface} The session pool used by current instance.
* This object allows interaction with the pool for acquiring and managing sessions.
*/
/**
* Returns the regular session pool object.
*
* @returns {SessionPoolInterface} The session pool used by current instance.
*/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

* @throws {Error} Throws an error if the session is invalid or cannot be released.
*/
release(session: Session): void {
if (!this.isMuxCreated) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

isMultiplexedEnabled

Suggested change
if (!this.isMuxCreated) {
if (!this.isMultiplexedEnabled) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines +126 to +153
/**
* Releases the session back to the pool.
*
* This method is used to return the session back to the pool after it is no longer needed.
*
* It only performs the operation if the Multiplexed Session is disabled which is controlled via the
* env variable GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS.
*
* @param session The session to be released. This should be an instance of `Session` that was previously
* acquired from the session pool.
*
* @throws {Error} Throws an error if the session is invalid or cannot be released.
*/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
/**
* Releases the session back to the pool.
*
* This method is used to return the session back to the pool after it is no longer needed.
*
* It only performs the operation if the Multiplexed Session is disabled which is controlled via the
* env variable GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS.
*
* @param session The session to be released. This should be an instance of `Session` that was previously
* acquired from the session pool.
*
* @throws {Error} Throws an error if the session is invalid or cannot be released.
*/
/**
* Releases a session back to the session pool.
*
* This method returns a session to the pool after it is no longer needed.
* It is a no-op for multiplexed sessions.
*
* @param {Session} session - The session to be released. This should be an instance of `Session` that was
* previously acquired from the session pool.
*
* @throws {Error} If the session is invalid or cannot be released.
*/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

import {ReleaseError} from '../src/session-pool';

describe('SessionFactory', () => {
process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS = 'true';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we initialize this in before block and clear in after block

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we need to keep this in after block so that others test which will be running after this test don't fail on because of the change in env configuration

assert.strictEqual(openStub.callCount, 1);
});

describe('when env GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS is enabled', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
describe('when env GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS is enabled', () => {
describe('when GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS is enabled', () => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

});

describe('getSession', () => {
describe('for regular session', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
describe('for regular session', () => {
describe('when GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS is disabled', () => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS = 'false';
});

it('should return the regular session if GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS env is disabled', done => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
it('should return the regular session if GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS env is disabled', done => {
it('should retrieve a regular session from the pool', done => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

});
});

it('should return the error from getSession if GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS env is disabled and regular session creation get failed', done => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
it('should return the error from getSession if GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS env is disabled and regular session creation get failed', done => {
it('should propagate errors when regular session retrieval fails', done => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I have given a few examples on how the test cases should be named. Please updated others as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

modified other tests as well

@alkatrivedi alkatrivedi added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Dec 26, 2024
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Dec 26, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 27, 2024
surbhigarg92 and others added 6 commits December 27, 2024 12:30
* e2eTracing

* context propagation

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* Add end to end tracing header and refactore resource header

* Add end to end tracing header and refactore resource header

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
…taleness (#2207)

* chore: integration test fix

* chore: Improve error message for Read-only transaction with bounded staleness

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* review comments

* review comments

* review comment

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
@product-auto-label product-auto-label bot added size: xl Pull request size is extra large. and removed size: l Pull request size is large. labels Dec 27, 2024
@product-auto-label product-auto-label bot added size: l Pull request size is large. and removed size: xl Pull request size is extra large. labels Dec 27, 2024
@alkatrivedi alkatrivedi added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Dec 27, 2024
*
* @param {Database} database Database object.
* @param {String} name Name of the database.
* @param {SessionPoolOptions|SessionPoolInterface} options Session pool
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SessionPoolConstructor right

Suggested change
* @param {SessionPoolOptions|SessionPoolInterface} options Session pool
* @param {SessionPoolOptions| SessionPoolConstructor} options Session pool

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please let me know if my understanding is incorrect ?

Copy link
Copy Markdown
Contributor Author

@alkatrivedi alkatrivedi Dec 27, 2024

Choose a reason for hiding this comment

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

Since, the SessionPoolConstructor is eventually creating SessionPoolInterface object, hence we can keep SessionPoolInterface here in the documentation

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: spanner Issues related to the googleapis/nodejs-spanner API. size: l Pull request size is large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants