GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: increase default number of channels when gRPC-GCP channel pool is enabled by harshachinta · Pull Request #1997 · googleapis/java-spanner

This repository was archived by the owner on Aug 30, 2026. It is now read-only.

feat: increase default number of channels when gRPC-GCP channel pool is enabled #1997

Merged
rajatbhatta merged 19 commits into googleapis:main from harshachinta:main
Oct 19, 2022

Uh oh!

There was an error while loading. Please reload this page.

Merged

feat: increase default number of channels when gRPC-GCP channel pool is enabled #1997

Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
4b44b1a
increase default number of channels when grpc-gcp channel pool is ena…
harshachinta Sep 6, 2022
34d7623
Merge remote-tracking branch 'origin/main'
harshachinta Sep 6, 2022
860462a
add java file header
harshachinta Sep 6, 2022
f2e2d8f
increase default number of channels when grpc-gcp channel pool is ena…
harshachinta Sep 6, 2022
15e3155
fix lint issue
harshachinta Sep 6, 2022
7a3ed3c
fix lint issue
harshachinta Sep 6, 2022
1449429
code fixes
harshachinta Sep 7, 2022
5f516cb
Update google-cloud-spanner/src/main/java/com/google/cloud/spanner/Sp…
rajatbhatta Sep 7, 2022
afec666
Update google-cloud-spanner/src/main/java/com/google/cloud/spanner/Sp…
rajatbhatta Sep 7, 2022
1fe3d48
lint fixes
harshachinta Sep 8, 2022
60cfa2a
Merge remote-tracking branch 'origin/main'
harshachinta Sep 8, 2022
e68b2f5
Modify comments for better code readability
harshachinta Oct 6, 2022
a334e09
lint fix
harshachinta Oct 6, 2022
27962ea
add test to verify default num of channels when gRPC-GCP is not enabled
harshachinta Oct 11, 2022
68e72d4
Add tests to verify number of channels and the instances created
harshachinta Oct 18, 2022
33682fc
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Oct 18, 2022
faa74ed
code refactoring for setting the default numChannels
harshachinta Oct 19, 2022
3d81b1f
Merge remote-tracking branch 'origin/main'
harshachinta Oct 19, 2022
a88d4e3
lint fix
harshachinta Oct 19, 2022
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

6 changes: 3 additions & 3 deletions 6 README.md
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ If you are using Maven without BOM, add this to your dependencies:
If you are using Gradle 5.x or later, add this to your dependencies:

```Groovy
implementation platform('com.google.cloud:libraries-bom:26.1.1')
implementation platform('com.google.cloud:libraries-bom:26.1.3')

implementation 'com.google.cloud:google-cloud-spanner'
```
If you are using Gradle without BOM, add this to your dependencies:

```Groovy
implementation 'com.google.cloud:google-cloud-spanner:6.29.1'
implementation 'com.google.cloud:google-cloud-spanner:6.31.2'
```

If you are using SBT, add this to your dependencies:

```Scala
libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.29.1"
libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.31.2"
```

## Authentication
Expand Down
18 changes: 14 additions & 4 deletions 18 google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public class SpannerOptions extends ServiceOptions<Spanner, SpannerOptions> {
"https://www.googleapis.com/auth/spanner.admin",
"https://www.googleapis.com/auth/spanner.data");
private static final int MAX_CHANNELS = 256;
@VisibleForTesting static final int DEFAULT_CHANNELS = 4;
// Set the default number of channels to GRPC_GCP_ENABLED_DEFAULT_CHANNELS when gRPC-GCP extension
// is enabled, to make sure there are sufficient channels available to move the sessions to a
// different channel if a network connection in a particular channel fails.
@VisibleForTesting static final int GRPC_GCP_ENABLED_DEFAULT_CHANNELS = 8;
private final TransportChannelProvider channelProvider;

@SuppressWarnings("rawtypes")
Expand Down Expand Up @@ -669,8 +674,7 @@ public static class Builder

private GrpcInterceptorProvider interceptorProvider;

/** By default, we create 4 channels per {@link SpannerOptions} */
private int numChannels = 4;
private Integer numChannels;

private String transportChannelExecutorThreadNameFormat = "Cloud-Spanner-TransportChannel-%d";

Expand Down Expand Up @@ -1122,8 +1126,7 @@ public Builder setHost(String host) {

/** Enables gRPC-GCP extension with the default settings. */
public Builder enableGrpcGcpExtension() {
this.grpcGcpExtensionEnabled = true;
return this;
return this.enableGrpcGcpExtension(null);
}
Comment thread
harshachinta marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.


/**
Expand All @@ -1133,6 +1136,9 @@ public Builder enableGrpcGcpExtension() {
public Builder enableGrpcGcpExtension(GcpManagedChannelOptions options) {
this.grpcGcpExtensionEnabled = true;
this.grpcGcpOptions = options;
if (this.numChannels == null) {
this.numChannels = GRPC_GCP_ENABLED_DEFAULT_CHANNELS;
}
Comment thread Outdated

@olavloite olavloite Oct 19, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Remove this and instead assign the default number of channels in the build method for both GCP enabled and disabled. (See also below)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
return this;
}

Expand Down Expand Up @@ -1166,6 +1172,10 @@ public SpannerOptions build() {
// As we are using plain text, we should never send any credentials.
this.setCredentials(NoCredentials.getInstance());
}
if (this.numChannels == null) {
this.numChannels = DEFAULT_CHANNELS;
Comment thread Outdated

@olavloite olavloite Oct 19, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

this.num

Suggested change
this.numChannels = DEFAULT_CHANNELS;
this.numChannels = this.grpcGcpExtensionEnabled ? GRPC_GCP_ENABLED_DEFAULT_CHANNELS : DEFAULT_CHANNELS;

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@harshachinta harshachinta Oct 19, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks for the suggestion @olavloite. This makes it more readable than the previous one.
I have made the changes in the recent commit.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
}

return new SpannerOptions(this);
}
}
Expand Down
69 changes: 69 additions & 0 deletions 69 google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpannerOptionsTest.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -918,4 +919,72 @@ public void testCustomAsyncExecutorProvider() {
.build();
assertSame(service, options.getAsyncExecutorProvider().getExecutor());
}

@Test
public void testDefaultNumChannelsWithGrpcGcpExtensionEnabled() {
SpannerOptions options =
SpannerOptions.newBuilder().setProjectId("test-project").enableGrpcGcpExtension().build();

assertEquals(SpannerOptions.GRPC_GCP_ENABLED_DEFAULT_CHANNELS, options.getNumChannels());
}

@Test
public void testDefaultNumChannelsWithGrpcGcpExtensionDisabled() {
SpannerOptions options = SpannerOptions.newBuilder().setProjectId("test-project").build();

assertEquals(SpannerOptions.DEFAULT_CHANNELS, options.getNumChannels());
}

@Test
public void testNumChannelsWithGrpcGcpExtensionEnabled() {
// Set number of channels explicitly, before enabling gRPC-GCP channel pool in SpannerOptions
// builder.
int numChannels = 5;
Comment thread
harshachinta marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread
harshachinta marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

SpannerOptions options1 =
SpannerOptions.newBuilder()
.setProjectId("test-project")
.setNumChannels(numChannels)
.enableGrpcGcpExtension()
.build();

assertEquals(numChannels, options1.getNumChannels());

// Set number of channels explicitly, after enabling gRPC-GCP channel pool in SpannerOptions
// builder.
SpannerOptions options2 =
SpannerOptions.newBuilder()
.setProjectId("test-project")
.enableGrpcGcpExtension()
.setNumChannels(numChannels)
.build();

assertEquals(numChannels, options2.getNumChannels());
}

@Test
public void checkCreatedInstanceWhenGrpcGcpExtensionDisabled() {
SpannerOptions options = SpannerOptions.newBuilder().setProjectId("test-project").build();
SpannerOptions options1 = options.toBuilder().build();
assertEquals(false, options.isGrpcGcpExtensionEnabled());
assertEquals(options.isGrpcGcpExtensionEnabled(), options1.isGrpcGcpExtensionEnabled());

Spanner spanner1 = options.getService();
Spanner spanner2 = options1.getService();

assertNotSame(spanner1, spanner2);
}

@Test
public void checkCreatedInstanceWhenGrpcGcpExtensionEnabled() {
SpannerOptions options =
SpannerOptions.newBuilder().setProjectId("test-project").enableGrpcGcpExtension().build();
SpannerOptions options1 = options.toBuilder().build();
assertEquals(true, options.isGrpcGcpExtensionEnabled());
assertEquals(options.isGrpcGcpExtensionEnabled(), options1.isGrpcGcpExtensionEnabled());

Spanner spanner1 = options.getService();
Spanner spanner2 = options1.getService();

assertNotSame(spanner1, spanner2);
}
}
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.