Google Cloud Spanner C++ Client 2.13.0
A C++ Client Library for Google Cloud Spanner
Loading...
Searching...
No Matches
options.h
1// Copyright 2021 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_OPTIONS_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_OPTIONS_H
17
18/**
19 * @file
20 *
21 * This file defines options to be used with instances of
22 * `google::cloud::Options`. By convention options are named with an "Option"
23 * suffix. As the name would imply, all options are optional, and leaving them
24 * unset will result in a reasonable default being chosen.
25 *
26 * Not all options are meaningful to all functions that accept a
27 * `google::cloud::Options` instance. Each function that accepts a
28 * `google::cloud::Options` should document which options it expects. This is
29 * typically done by indicating lists of options using "OptionList" aliases.
30 * For example, a function may indicate that users may set any option in
31 * `SpannerPolicyOptionList`.
32 *
33 * @note Unrecognized options are allowed and will be ignored. To debug issues
34 * with options set `GOOGLE_CLOUD_CPP_ENABLE_CLOG=yes` in the environment
35 * and unexpected options will be logged.
36 *
37 * @see `google::cloud::CommonOptionList`
38 * @see `google::cloud::GrpcOptionList`
39 */
40
41#include "google/cloud/spanner/backoff_policy.h"
42#include "google/cloud/spanner/internal/session.h"
43#include "google/cloud/spanner/polling_policy.h"
44#include "google/cloud/spanner/request_priority.h"
45#include "google/cloud/spanner/retry_policy.h"
46#include "google/cloud/spanner/version.h"
47#include "google/cloud/options.h"
48#include <chrono>
49#include <cstddef>
50#include <cstdint>
51#include <map>
52#include <memory>
53
54namespace google {
55namespace cloud {
56namespace spanner {
57GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
58
59/**
60 * Option for `google::cloud::Options` to set a `spanner::RetryPolicy`.
61 *
62 * @ingroup spanner-options
63 */
65 using Type = std::shared_ptr<spanner::RetryPolicy>;
66};
67
68/**
69 * Option for `google::cloud::Options` to set a `spanner::BackoffPolicy`.
70 *
71 * @ingroup spanner-options
72 */
74 using Type = std::shared_ptr<spanner::BackoffPolicy>;
75};
76
77/**
78 * Option for `google::cloud::Options` to set a `spanner::PollingPolicy`.
79 *
80 * @ingroup spanner-options
81 */
83 using Type = std::shared_ptr<spanner::PollingPolicy>;
84};
85
86/**
87 * List of all "policy" options.
88 */
89using SpannerPolicyOptionList =
92
93/**
94 * Control "route to leader region" headers.
95 *
96 * Unless this option is present and `false` the client library will send
97 * headers that route the request to the leader region.
98 *
99 * @see https://cloud.google.com/spanner/docs/instance-configurations
100 * for more information on multi-regional spanner instances and the role of
101 * leader regions.
102 *
103 * @ingroup spanner-options
104 */
105struct RouteToLeaderOption {
106 using Type = bool;
107};
108
109/**
110 * Option for `google::cloud::Options` to set the database role used for
111 * session creation.
112 *
113 * @ingroup spanner-options
114 */
116 using Type = std::string;
117};
118
119/**
120 * Option for `google::cloud::Options` to set the minimum number of sessions to
121 * keep in the pool.
122 *
123 * Values <= 0 are treated as 0.
124 * This value will effectively be reduced if it exceeds the overall limit on
125 * the number of sessions (`max_sessions_per_channel` * number of channels).
126 *
127 * @ingroup spanner-options
128 */
130 using Type = int;
131};
132
133/**
134 * Option for `google::cloud::Options` to set the maximum number of sessions to
135 * create on each channel.
136 *
137 * Values <= 1 are treated as 1.
138 *
139 * @ingroup spanner-options
140 */
142 using Type = int;
143};
144
145/**
146 * Option for `google::cloud::Options` to set the maximum number of sessions to
147 * keep in the pool in an idle state.
148 *
149 * Values <= 0 are treated as 0.
150 *
151 * @ingroup spanner-options
152 */
154 using Type = int;
155};
156
157/// Action to take when the session pool is exhausted.
158enum class ActionOnExhaustion { kBlock, kFail };
159/**
160 * Option for `google::cloud::Options` to set the action to take when
161 * attempting to allocate a session when the pool is exhausted.
162 *
163 * @ingroup spanner-options
164 */
166 using Type = spanner::ActionOnExhaustion;
167};
168
169/**
170 * Option for `google::cloud::Options` to set the interval at which we refresh
171 * sessions so they don't get collected by the backend GC.
172 *
173 * The GC collects objects older than 60 minutes, so any duration
174 * below that (less some slack to allow the calls to be made to refresh the
175 * sessions) should suffice.
176 *
177 * @ingroup spanner-options
178 */
180 using Type = std::chrono::seconds;
181};
182
183/**
184 * Option for `google::cloud::Options` to set the labels used when creating
185 * sessions within the pool.
186 *
187 * * Label keys must match `[a-z]([-a-z0-9]{0,61}[a-z0-9])?`.
188 * * Label values must match `([a-z]([-a-z0-9]{0,61}[a-z0-9])?)?`.
189 * * The maximum number of labels is 64.
190 *
191 * @ingroup spanner-options
192 */
194 using Type = std::map<std::string, std::string>;
195};
196
197/**
198 * List of all SessionPool options. Pass to `spanner::MakeConnection()`.
199 */
200using SessionPoolOptionList = OptionList<
205
206/**
207 * Option for `google::cloud::Options` to set the optimizer version used in an
208 * SQL query.
209 *
210 * @ingroup spanner-options
211 */
213 using Type = std::string;
214};
215
216/**
217 * Option for `google::cloud::Options` to set the optimizer statistics package
218 * used in an SQL query.
219 *
220 * @ingroup spanner-options
221 */
223 using Type = std::string;
224};
225
226/**
227 * Option for `google::cloud::Options` to set a `spanner::RequestPriority`.
228 *
229 * @ingroup spanner-options
230 */
232 using Type = spanner::RequestPriority;
233};
234
235/**
236 * Option for `google::cloud::Options` to set a per-request tag.
237 *
238 * @ingroup spanner-options
239 */
240struct RequestTagOption {
241 using Type = std::string;
242};
243
244/**
245 * Option for `google::cloud::Options` to set the name of an index on a
246 * database table. This index is used instead of the table primary key when
247 * interpreting the `KeySet` and sorting result rows.
248 *
249 * @ingroup spanner-options
250 */
251struct ReadIndexNameOption {
252 using Type = std::string;
253};
254
255/**
256 * Option for `google::cloud::Options` to set a limit on the number of rows
257 * to yield from `Client::Read()`. There is no limit when the option is unset,
258 * or when it is set to 0.
259 *
260 * @ingroup spanner-options
261 */
262struct ReadRowLimitOption {
263 using Type = std::int64_t;
264};
265
266/**
267 * Option for `google::cloud::Options` to set a limit on how much data will
268 * be buffered to guarantee resumability of a streaming read or SQL query.
269 * If the limit is exceeded, and the stream is subsequently interrupted before
270 * a new resumption point can be established, the read/query will fail.
271 *
272 * @ingroup spanner-options
273 */
275 using Type = std::size_t;
276};
277
278/**
279 * Option for `google::cloud::Options` to set the desired partition size to
280 * be generated by `Client::PartitionRead()` or `PartitionQuery()`.
281 *
282 * The default for this option is currently 1 GiB. This is only a hint. The
283 * actual size of each partition may be smaller or larger than this request.
284 *
285 * @ingroup spanner-options
286 */
287struct PartitionSizeOption {
288 using Type = std::int64_t;
289};
290
291/**
292 * Option for `google::cloud::Options` to set the desired maximum number of
293 * partitions to return from `Client::PartitionRead()` or `PartitionQuery()`.
294 *
295 * For example, this may be set to the number of workers available. The
296 * default for this option is currently 10,000. The maximum value is
297 * currently 200,000. This is only a hint. The actual number of partitions
298 * returned may be smaller or larger than this request.
299 *
300 * @ingroup spanner-options
301 */
303 using Type = std::int64_t;
304};
305
306/**
307 * Option for `google::cloud::Options` to use "data boost" in the
308 * partitions returned from `Client::PartitionRead()` or `PartitionQuery()`.
309 *
310 * If true, the requests from the subsequent partitioned `Client::Read()`
311 * and `Client::ExecuteQuery()` calls will be executed using the independent
312 * compute resources of Cloud Spanner Data Boost.
313 *
314 * @ingroup spanner-options
315 */
317 using Type = bool;
318};
319
320/**
321 * Option for `google::cloud::Options` to set a per-transaction tag.
322 *
323 * @ingroup spanner-options
324 */
326 using Type = std::string;
327};
328
329/**
330 * Option for `google::cloud::Options` to return additional statistics
331 * about the committed transaction in a `spanner::CommitResult`.
332 *
333 * @ingroup spanner-options
334 */
336 using Type = bool;
337};
338
339/**
340 * List of Request options for `client::ExecuteBatchDml()`.
341 */
342using RequestOptionList = OptionList<RequestPriorityOption, RequestTagOption>;
343
344GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
345} // namespace spanner
346} // namespace cloud
347} // namespace google
348
349#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_OPTIONS_H
Contains all the Cloud Spanner C++ client types and functions.
Definition: backoff_policy.h:23
ActionOnExhaustion
Action to take when the session pool is exhausted.
Definition: options.h:158
RequestPriority
Definition: request_priority.h:26
Option for google::cloud::Options to return additional statistics about the committed transaction in ...
Definition: options.h:335
Option for google::cloud::Options to use "data boost" in the partitions returned from Client::Partiti...
Definition: options.h:316
Option for google::cloud::Options to set the desired partition size to be generated by Client::Partit...
Definition: options.h:287
Option for google::cloud::Options to set the desired maximum number of partitions to return from Clie...
Definition: options.h:302
Option for google::cloud::Options to set the optimizer statistics package used in an SQL query.
Definition: options.h:222
Option for google::cloud::Options to set the optimizer version used in an SQL query.
Definition: options.h:212
Option for google::cloud::Options to set the name of an index on a database table.
Definition: options.h:251
Option for google::cloud::Options to set a limit on the number of rows to yield from Client::Read().
Definition: options.h:262
Option for google::cloud::Options to set a spanner::RequestPriority.
Definition: options.h:231
Option for google::cloud::Options to set a per-request tag.
Definition: options.h:240
Control "route to leader region" headers.
Definition: options.h:105
Option for google::cloud::Options to set the database role used for session creation.
Definition: options.h:115
Option for google::cloud::Options to set the action to take when attempting to allocate a session whe...
Definition: options.h:165
Option for google::cloud::Options to set the interval at which we refresh sessions so they don't get ...
Definition: options.h:179
Option for google::cloud::Options to set the labels used when creating sessions within the pool.
Definition: options.h:193
Option for google::cloud::Options to set the maximum number of sessions to keep in the pool in an idl...
Definition: options.h:153
Option for google::cloud::Options to set the maximum number of sessions to create on each channel.
Definition: options.h:141
Option for google::cloud::Options to set the minimum number of sessions to keep in the pool.
Definition: options.h:129
Option for google::cloud::Options to set a spanner::BackoffPolicy.
Definition: options.h:73
Option for google::cloud::Options to set a spanner::PollingPolicy.
Definition: options.h:82
Option for google::cloud::Options to set a spanner::RetryPolicy.
Definition: options.h:64
Option for google::cloud::Options to set a limit on how much data will be buffered to guarantee resum...
Definition: options.h:274
Option for google::cloud::Options to set a per-transaction tag.
Definition: options.h:325