Class SpannerOptions.Builder
- Enclosing class:
- SpannerOptions
SpannerOptions instances.-
Field Summary
Fields inherited from class com.google.cloud.ServiceOptions.Builder
credentials -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Disables automatic retries of administrative requests that fail if the https://cloud.google.com/spanner/quotas#administrative_limits have been exceeded.Disables gRPC-GCP extension.Disable leader aware routing.Enables gRPC-GCP extension with the default settings.enableGrpcGcpExtension(com.google.cloud.grpc.GcpManagedChannelOptions options) Enables gRPC-GCP extension and uses provided options for configuration.Enable leader aware routing.Returns theDatabaseAdminStubSettings.Builderthat will be used to build theSpannerRpc.Returns theInstanceAdminStubSettings.Builderthat will be used to build theSpannerRpc.Returns theSpannerStubSettings.Builderthat will be used to build theSpannerRpc.Sets theExecutorProviderto use for high-level async calls that need an executor, such as fetching results for anAsyncResultSet.Instructs the client library to automatically throttle the number of administrative requests if the rate of administrative requests generated by thisSpannerinstance will exceed the administrative limits Cloud Spanner.setCallCredentialsProvider(SpannerOptions.CallCredentialsProvider callCredentialsProvider) Sets aSpannerOptions.CallCredentialsProviderthat can deliverCallCredentialsto use on a per-gRPC basis.setChannelConfigurator(com.google.api.core.ApiFunction<io.grpc.ManagedChannelBuilder, io.grpc.ManagedChannelBuilder> channelConfigurator) Sets anApiFunctionthat will be used to configure the transport channel.setChannelProvider(com.google.api.gax.rpc.TransportChannelProvider channelProvider) Sets theChannelProvider.setClientLibToken(String clientLibToken) setCompressorName(String compressorName) Sets the compression to use for all gRPC calls.setDatabaseRole(String databaseRole) Sets the database role that should be used for connections that are created by this instance.setDecodeMode(DecodeMode decodeMode) Specifies how values that are returned from a query should be decoded and converted from protobuf values into plain Java objects.setDefaultQueryOptions(DatabaseId database, ExecuteSqlRequest.QueryOptions defaultQueryOptions) Sets the defaultExecuteSqlRequest.QueryOptionsthat will be used for all queries on the specified database.setDirectedReadOptions(DirectedReadOptions directedReadOptions) Sets theOptions.DirectedReadOptionthat specify which replicas or regions should be used for non-transactional reads or queries.setEmulatorHost(String emulatorHost) Sets the host of an emulator to use.setEnableApiTracing(boolean enableApiTracing) Creates and sets anApiTracerfor the RPCs that are executed by this client.setEnableExtendedTracing(boolean enableExtendedTracing) Sets whether to enable extended OpenTelemetry tracing.setInterceptorProvider(com.google.api.gax.grpc.GrpcInterceptorProvider interceptorProvider) Sets theGrpcInterceptorProvider.setNumChannels(int numChannels) Sets the number of gRPC channels to use.setOpenTelemetry(io.opentelemetry.api.OpenTelemetry openTelemetry) Sets OpenTelemetry object to be used for Spanner Metrics and Traces.setPartitionedDmlTimeout(org.threeten.bp.Duration timeout) Sets a timeout specifically for Partitioned DML statements executed throughDatabaseClient.executePartitionedUpdate(Statement, UpdateOption...).setPrefetchChunks(int prefetchChunks) Specifying this will allow the client to prefetch up toprefetchChunksPartialResultSetchunks for each read and query.setRetrySettings(com.google.api.gax.retrying.RetrySettings retrySettings) SpannerOptions.Builderdoes not support global retry settings, as it creates three different gRPC clients:Spanner,DatabaseAdminClientandInstanceAdminClient.setSessionLabels(Map<String, String> sessionLabels) Sets the labels to add to all Sessions created in this client.setSessionPoolOption(SessionPoolOptions sessionPoolOptions) Sets the options for managing the session pool.Instructs the client library to track the first request of each read/write transaction.setTransportOptions(com.google.cloud.TransportOptions transportOptions) protected SpannerOptions.BuildersetUseVirtualThreads(boolean useVirtualThreads) Enables/disables the use of virtual threads for the gRPC executor.Methods inherited from class com.google.cloud.ServiceOptions.Builder
self, setApiTracerFactory, setClock, setCredentials, setHeaderProvider, setProjectId, setQuotaProjectId, setServiceFactory, setServiceRpcFactory, setUniverseDomain
-
Constructor Details
-
Builder
protected Builder()
-
-
Method Details
-
setTransportOptions
public SpannerOptions.Builder setTransportOptions(com.google.cloud.TransportOptions transportOptions) - Overrides:
setTransportOptionsin classcom.google.cloud.ServiceOptions.Builder<Spanner,SpannerOptions, SpannerOptions.Builder>
-
getAllowedClientLibTokens
- Overrides:
getAllowedClientLibTokensin classcom.google.cloud.ServiceOptions.Builder<Spanner,SpannerOptions, SpannerOptions.Builder>
-
setClientLibToken
- Overrides:
setClientLibTokenin classcom.google.cloud.ServiceOptions.Builder<Spanner,SpannerOptions, SpannerOptions.Builder>
-
setChannelProvider
public SpannerOptions.Builder setChannelProvider(com.google.api.gax.rpc.TransportChannelProvider channelProvider) Sets theChannelProvider.GapicSpannerRpcwould create a default one if none is provided.Setting a custom
TransportChannelProvideralso overrides any other settings that affect the default channel provider. These must be set manually on the customTransportChannelProviderinstead of onSpannerOptions. The settings ofSpannerOptionsthat have no effect if you set a customTransportChannelProviderare:setChannelConfigurator(ApiFunction)setHost(String)setNumChannels(int)setInterceptorProvider(GrpcInterceptorProvider)ServiceOptions.Builder.setHeaderProvider(com.google.api.gax.rpc.HeaderProvider)
-
setChannelConfigurator
public SpannerOptions.Builder setChannelConfigurator(com.google.api.core.ApiFunction<io.grpc.ManagedChannelBuilder, io.grpc.ManagedChannelBuilder> channelConfigurator) Sets anApiFunctionthat will be used to configure the transport channel. This will only be used if no customTransportChannelProviderhas been set. -
setInterceptorProvider
public SpannerOptions.Builder setInterceptorProvider(com.google.api.gax.grpc.GrpcInterceptorProvider interceptorProvider) Sets theGrpcInterceptorProvider.GapicSpannerRpcwould create a default one if none is provided. -
setNumChannels
Sets the number of gRPC channels to use. By default 4 channels are created perSpannerOptions. -
setSessionPoolOption
Sets the options for managing the session pool. If not specified then the defaultSessionPoolOptionsis used. -
setDatabaseRole
Sets the database role that should be used for connections that are created by this instance. The database role that is used determines the access permissions that a connection has. This can for example be used to create connections that are only permitted to access certain tables. -
setSessionLabels
Sets the labels to add to all Sessions created in this client.- Parameters:
sessionLabels- Map from label key to label value. Label key and value cannot be null. For more information on valid syntax see api docs .
-
setRetrySettings
public SpannerOptions.Builder setRetrySettings(com.google.api.gax.retrying.RetrySettings retrySettings) SpannerOptions.Builderdoes not support global retry settings, as it creates three different gRPC clients:Spanner,DatabaseAdminClientandInstanceAdminClient. Instead of calling this method, you should set specificRetrySettingsfor each of the underlying gRPC clients by calling respectivelygetSpannerStubSettingsBuilder(),getDatabaseAdminStubSettingsBuilder()orgetInstanceAdminStubSettingsBuilder().- Overrides:
setRetrySettingsin classcom.google.cloud.ServiceOptions.Builder<Spanner,SpannerOptions, SpannerOptions.Builder>
-
getSpannerStubSettingsBuilder
Returns theSpannerStubSettings.Builderthat will be used to build theSpannerRpc. Use this to set customRetrySettingsfor individual gRPC methods.The library will automatically use the defaults defined in
SpannerStubSettingsif no custom settings are set. The defaults are the same as the defaults that are used bySpannerSettings, and are generated from the file spanner_gapic.yaml. Retries are configured for idempotent methods but not for non-idempotent methods.You can set the same
RetrySettingsfor all unary methods by calling this:builder .getSpannerStubSettingsBuilder() .applyToAllUnaryMethods( new ApiFunction<UnaryCallSettings.Builder<?, ?>, Void>() { public Void apply(Builder<?, ?> input) { input.setRetrySettings(retrySettings); return null; } }); -
getInstanceAdminStubSettingsBuilder
Returns theInstanceAdminStubSettings.Builderthat will be used to build theSpannerRpc. Use this to set customRetrySettingsfor individual gRPC methods.The library will automatically use the defaults defined in
InstanceAdminStubSettingsif no custom settings are set. The defaults are the same as the defaults that are used byInstanceAdminSettings, and are generated from the file spanner_admin_instance_gapic.yaml. Retries are configured for idempotent methods but not for non-idempotent methods.You can set the same
RetrySettingsfor all unary methods by calling this:builder .getInstanceAdminStubSettingsBuilder() .applyToAllUnaryMethods( new ApiFunction<UnaryCallSettings.Builder<?, ?>, Void>() { public Void apply(Builder<?, ?> input) { input.setRetrySettings(retrySettings); return null; } }); -
getDatabaseAdminStubSettingsBuilder
Returns theDatabaseAdminStubSettings.Builderthat will be used to build theSpannerRpc. Use this to set customRetrySettingsfor individual gRPC methods.The library will automatically use the defaults defined in
DatabaseAdminStubSettingsif no custom settings are set. The defaults are the same as the defaults that are used byDatabaseAdminSettings, and are generated from the file spanner_admin_database_gapic.yaml. Retries are configured for idempotent methods but not for non-idempotent methods.You can set the same
RetrySettingsfor all unary methods by calling this:builder .getDatabaseAdminStubSettingsBuilder() .applyToAllUnaryMethods( new ApiFunction<UnaryCallSettings.Builder<?, ?>, Void>() { public Void apply(Builder<?, ?> input) { input.setRetrySettings(retrySettings); return null; } }); -
setPartitionedDmlTimeout
Sets a timeout specifically for Partitioned DML statements executed throughDatabaseClient.executePartitionedUpdate(Statement, UpdateOption...). The default is 2 hours. -
setAutoThrottleAdministrativeRequests
Instructs the client library to automatically throttle the number of administrative requests if the rate of administrative requests generated by thisSpannerinstance will exceed the administrative limits Cloud Spanner. The default behavior is to not throttle any requests. If the limit is exceeded, Cloud Spanner will return a RESOURCE_EXHAUSTED error. More information on the administrative limits can be found here: https://cloud.google.com/spanner/quotas#administrative_limits. Setting this option is not a guarantee that the rate will never be exceeded, as this option will only throttle requests coming from this client. Additional requests from other clients could still cause the limit to be exceeded. -
disableAdministrativeRequestRetries
Disables automatic retries of administrative requests that fail if the https://cloud.google.com/spanner/quotas#administrative_limits have been exceeded. You should disable these retries if you intend to handle these errors in your application. -
setTrackTransactionStarter
Instructs the client library to track the first request of each read/write transaction. This statement will include a BeginTransaction option and will return a transaction id as part of its result. All other statements in the same transaction must wait for this first statement to finish before they can proceed. By setting this option the client library will throw aSpannerExceptionwithErrorCode.DEADLINE_EXCEEDEDfor any subsequent statement that has waited for at least 60 seconds for the first statement to return a transaction id, including the stacktrace of the initial statement that should have returned a transaction id. -
setDefaultQueryOptions
public SpannerOptions.Builder setDefaultQueryOptions(DatabaseId database, ExecuteSqlRequest.QueryOptions defaultQueryOptions) Sets the defaultExecuteSqlRequest.QueryOptionsthat will be used for all queries on the specified database. Query options can also be specified on a per-query basis and as environment variables. The precedence of these settings are:- Query options for a specific query
- Environment variables
- These default query options
Options.QueryOptionvalue that is used for a query is determined individually based on the above precedence. If for example a value forExecuteSqlRequest.QueryOptions.getOptimizerVersion()is specified in an environment variable and a value forExecuteSqlRequest.QueryOptions.getOptimizerStatisticsPackage()is specified for a specific query, both values will be used for the specific query. Environment variables are only read during the initialization of aSpannerOptionsinstance. Changing an environment variable after initializing aSpannerOptionsinstance will not have any effect on that instance. -
setCallCredentialsProvider
public SpannerOptions.Builder setCallCredentialsProvider(SpannerOptions.CallCredentialsProvider callCredentialsProvider) Sets aSpannerOptions.CallCredentialsProviderthat can deliverCallCredentialsto use on a per-gRPC basis. -
setCompressorName
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1704") public SpannerOptions.Builder setCompressorName(@Nullable String compressorName) Sets the compression to use for all gRPC calls. The compressor must be a valid name known in theCompressorRegistry. This will enable compression both from the client to the server and from the server to the client.Supported values are:
- gzip: Enable gzip compression
- identity: Disable compression
null: Use default compression
-
setAsyncExecutorProvider
public SpannerOptions.Builder setAsyncExecutorProvider(SpannerOptions.CloseableExecutorProvider provider) Sets theExecutorProviderto use for high-level async calls that need an executor, such as fetching results for anAsyncResultSet.Async methods will use a sensible default if no custom
ExecutorProviderhas been set. The defaultExecutorProvideruses a cached thread pool containing a maximum of 8 threads. The pool is lazily initialized and will not create any threads if the user application does not use any async methods. It will also scale down the thread usage if the async load allows for that.Call
SpannerOptions.createAsyncExecutorProvider(int, long, TimeUnit)to create a provider with a custom pool size or callSpannerOptions.FixedCloseableExecutorProvider.create(ScheduledExecutorService)to create aSpannerOptions.CloseableExecutorProviderfrom a standard JavaScheduledExecutorService. -
setDirectedReadOptions
Sets theOptions.DirectedReadOptionthat specify which replicas or regions should be used for non-transactional reads or queries.DirectedReadOptions set at the request level will take precedence over the options set using this method.
An example below of how
DirectedReadOptionscan be constructed by including a replica.DirectedReadOptions.newBuilder() .setIncludeReplicas( IncludeReplicas.newBuilder() .addReplicaSelections( ReplicaSelection.newBuilder().setLocation("us-east1").build())) .build(); } -
setPrefetchChunks
Specifying this will allow the client to prefetch up toprefetchChunksPartialResultSetchunks for each read and query. The data size of each chunk depends on the server implementation but a good rule of thumb is that each chunk will be up to 1 MiB. Larger values reduce the likelihood of blocking while consuming results at the cost of greater memory consumption.prefetchChunksshould be greater than 0. To get good performance choose a value that is large enough to allow buffering of chunks for an entire row. Apart from the buffered chunks, there can be at most one more row buffered in the client. This can be overridden on a per read/query basis byOptions.prefetchChunks(). If unspecified, we will use a default value (currently 4). -
setDecodeMode
Specifies how values that are returned from a query should be decoded and converted from protobuf values into plain Java objects. -
setHost
- Overrides:
setHostin classcom.google.cloud.ServiceOptions.Builder<Spanner,SpannerOptions, SpannerOptions.Builder>
-
enableGrpcGcpExtension
Enables gRPC-GCP extension with the default settings. Do not set GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS to true in combination with this option, as Multiplexed sessions are not supported for gRPC-GCP. -
enableGrpcGcpExtension
public SpannerOptions.Builder enableGrpcGcpExtension(com.google.cloud.grpc.GcpManagedChannelOptions options) Enables gRPC-GCP extension and uses provided options for configuration. The metric registry and default Spanner metric labels will be added automatically. Do not set GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS to true in combination with this option, as Multiplexed sessions are not supported for gRPC-GCP. -
disableGrpcGcpExtension
Disables gRPC-GCP extension. -
setEmulatorHost
Sets the host of an emulator to use. By default the value is read from an environment variable. If the environment variable is not set, this will benull. -
setOpenTelemetry
Sets OpenTelemetry object to be used for Spanner Metrics and Traces. GlobalOpenTelemetry will be used as fallback if this options is not set. -
enableLeaderAwareRouting
Enable leader aware routing. Leader aware routing would route all requests in RW/PDML transactions to the leader region. -
disableLeaderAwareRouting
Disable leader aware routing. Disabling leader aware routing would route all requests in RW/PDML transactions to any region. -
disableDirectPath
-
setUseVirtualThreads
Enables/disables the use of virtual threads for the gRPC executor. Setting this option only has any effect on Java 21 and higher. In all other cases, the option will be ignored. -
setEnableApiTracing
Creates and sets anApiTracerfor the RPCs that are executed by this client. Enabling this creates traces for each individual RPC execution, including events/annotations when an RPC is retried or fails. The traces are only exported if an OpenTelemetry or OpenCensus trace exporter has been configured for the client. -
setEnableExtendedTracing
Sets whether to enable extended OpenTelemetry tracing. Enabling this option will add the following additional attributes to the traces that are generated by the client:- db.statement: Contains the SQL statement that is being executed.
- thread.name: The name of the thread that executes the statement.
-
build
- Specified by:
buildin classcom.google.cloud.ServiceOptions.Builder<Spanner,SpannerOptions, SpannerOptions.Builder>
-