Google Cloud Storage C++ Client 2.13.0
A C++ Client Library for Google Cloud Storage
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_STORAGE_OPTIONS_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_OPTIONS_H
17
18#include "google/cloud/storage/idempotency_policy.h"
19#include "google/cloud/storage/oauth2/credentials.h"
20#include "google/cloud/storage/retry_policy.h"
21#include "google/cloud/storage/version.h"
22#include "google/cloud/backoff_policy.h"
23#include "google/cloud/credentials.h"
24#include "google/cloud/options.h"
25#include <chrono>
26#include <cstdint>
27#include <memory>
28#include <string>
29
30namespace google {
31namespace cloud {
32namespace storage_experimental {
33GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
34
35/**
36 * Set the HTTP version used by the client.
37 *
38 * If this option is not provided, or is set to `default` then the library uses
39 * [libcurl's default], typically HTTP/2 with SSL. Possible settings include:
40 * - "1.0": use HTTP/1.0, this is not recommended as would require a new
41 * connection for each request.
42 * - "1.1": use HTTP/1.1, this may be useful when the overhead of HTTP/2 is
43 * unacceptable. Note that this may require additional connections.
44 * - "2TLS": use HTTP/2 with TLS
45 * - "2.0": use HTTP/2 with our without TLS.
46 *
47 * [libcurl's default]: https://curl.se/libcurl/c/CURLOPT_HTTP_VERSION.html
48 *
49 * @ingroup storage-options
50 */
51struct HttpVersionOption {
52 using Type = std::string;
53};
54
55GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
56} // namespace storage_experimental
57
58namespace storage {
59GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
60namespace internal {
61/// This is only intended for testing against staging or development versions
62/// of the service. It is not for public use.
63struct TargetApiVersionOption {
64 using Type = std::string;
65};
66
67/// This is only intended for testing. It is not for public use.
68struct CAPathOption {
69 using Type = std::string;
70};
71
72/// This is only intended for testing of the library. Not for public use.
73struct UseRestClientOption {
74 using Type = bool;
75};
76
77} // namespace internal
78
79/**
80 * Configure the REST endpoint for the GCS client library.
81 *
82 * @ingroup storage-options
83 */
84struct RestEndpointOption {
85 using Type = std::string;
86};
87
88/**
89 * Configure the IAM endpoint for the GCS client library.
90 *
91 * @ingroup storage-options
92 */
93struct IamEndpointOption {
94 using Type = std::string;
95};
96
97/**
98 * Configure oauth2::Credentials for the GCS client library.
99 *
100 * @ingroup storage-options
101 *
102 * @deprecated prefer using `google::cloud::UnifiedCredentialsOption` and the
103 * unified credentials documented in @ref guac
104 */
106 using Type = std::shared_ptr<oauth2::Credentials>;
107};
108
109/**
110 * Set the Google Cloud Platform project id.
111 *
112 * @ingroup storage-options
113 */
114struct ProjectIdOption {
115 using Type = std::string;
116};
117
118/**
119 * Set the maximum connection pool size.
120 *
121 * The C++ client library uses this value to limit the growth of the
122 * connection pool. Once an operation (a RPC or a download) completes the
123 * connection used for that operation is returned to the pool. If the pool is
124 * full one or more connections are released. Otherwise, the connection is
125 * cached for use in following RPCs or downloads.
126 *
127 * @note Setting this value to 0 disables connection pooling.
128 *
129 * @warning The behavior of the connection pool may change in the future, only
130 * the maximum number of handles in use can be controlled by the application.
131 * The information about which handles are released and when is for
132 * informational purposes only.
133 *
134 * The library does not create connections proactively, setting a high value
135 * may result in very few connections if your application does not need them.
136 * The library may create more connections than this option configures, for
137 * example if your application requests many simultaneous downloads. When the
138 * pool is full, the library typically releases older connections first, and
139 * tries to reuse newer connections if they are available. The library may
140 * release more than one connection when the pool becomes full.
141 *
142 * @ingroup storage-options
143 */
145 using Type = std::size_t;
146};
147
148/**
149 * Control the formatted I/O download buffer.
150 *
151 * When using formatted I/O operations (typically `operator>>(std::istream&...)`
152 * this option controls the size of the in-memory buffer kept to satisfy any I/O
153 * requests.
154 *
155 * Applications seeking optimal performance for downloads should avoid
156 * formatted I/O, and prefer using `std::istream::read()`. This option has no
157 * effect in that case.
158 *
159 * @ingroup storage-options
160 */
162 using Type = std::size_t;
163};
164
165/**
166 * Control the formatted I/O upload buffer.
167 *
168 * When using formatted I/O operations (typically `operator<<(std::istream&...)`
169 * this option controls the size of the in-memory buffer kept before a chunk is
170 * uploaded. Note that GCS only accepts chunks in multiples of 256KiB, so this
171 * option is always rounded up to the next such multiple.
172 *
173 * Applications seeking optimal performance for downloads should avoid
174 * formatted I/O, and prefer using `std::istream::write()`. This option has no
175 * effect in that case.
176 *
177 * @ingroup storage-options
178 */
180 using Type = std::size_t;
181};
182
183/**
184 * Defines the threshold to switch from simple to resumable uploads for files.
185 *
186 * When uploading small files the faster approach is to use a simple upload. For
187 * very large files this is not feasible, as the whole file may not fit in
188 * memory (we are ignoring memory mapped files in this discussion). The library
189 * automatically switches to resumable upload for files larger than this
190 * threshold.
191 *
192 * @ingroup storage-options
193 */
195 using Type = std::size_t;
196};
197
198/**
199 * Disables automatic OpenSSL locking.
200 *
201 * With older versions of OpenSSL any locking must be provided by locking
202 * callbacks in the application or intermediate libraries. The C++ client
203 * library automatically provides the locking callbacks. If your application
204 * already provides such callbacks, and you prefer to use them, set this option
205 * to `false`.
206 *
207 * @note This option is only useful for applications linking against
208 * OpenSSL 1.0.2.
209 */
211 using Type = bool;
212};
213
214/**
215 * Disables automatic OpenSSL sigpipe handler.
216 *
217 * With some versions of OpenSSL it might be necessary to setup a SIGPIPE
218 * handler. If your application already provides such a handler, set this option
219 * to `false` to disable the handler in the GCS C++ client library.
220 */
222 using Type = bool;
223};
224
225/**
226 * Control the maximum socket receive buffer.
227 *
228 * The default is to let the operating system pick a value. Applications that
229 * perform multiple downloads in parallel may need to use smaller receive
230 * buffers to avoid exhausting the OS resources dedicated to TCP buffers.
231 */
233 using Type = std::size_t;
234};
235
236/**
237 * Control the maximum socket send buffer.
238 *
239 * The default is to let the operating system pick a value, this is almost
240 * always a good choice.
241 */
243 using Type = std::size_t;
244};
245
246/**
247 * Sets the transfer stall timeout.
248 *
249 * If a transfer (upload, download, or request) *stalls*, i.e., no bytes are
250 * sent or received for a significant period, it may be better to restart the
251 * transfer as this may indicate a network glitch. For downloads the
252 * google::cloud::storage::DownloadStallTimeoutOption takes precedence.
253 *
254 * For large requests (e.g. downloads in the GiB to TiB range) this is a better
255 * configuration parameter than a simple timeout, as the transfers will take
256 * minutes or hours to complete. Relying on a timeout value for them would not
257 * work, as the timeout would be too large to be useful. For small requests,
258 * this is as effective as a timeout parameter, but maybe unfamiliar and thus
259 * harder to reason about.
260 *
261 * @ingroup storage-options
262 */
264 using Type = std::chrono::seconds;
265};
266
267/**
268 * The minimum accepted bytes/second transfer rate.
269 *
270 * If the average rate is below this value for the `TransferStallTimeoutOption`
271 * then the transfer is aborted.
272 *
273 * @ingroup storage-options
274 */
276 using Type = std::int32_t;
277};
278
279/**
280 * Sets the download stall timeout.
281 *
282 * If a download *stalls*, i.e., no bytes are received for a significant period,
283 * it may be better to restart the download as this may indicate a network
284 * glitch.
285 *
286 * For large requests (e.g. downloads in the GiB to TiB range) this is a better
287 * configuration parameter than a simple timeout, as the transfers will take
288 * minutes or hours to complete. Relying on a timeout value for them would not
289 * work, as the timeout would be too large to be useful. For small requests,
290 * this is as effective as a timeout parameter, but maybe unfamiliar and thus
291 * harder to reason about.
292 *
293 * @ingroup storage-options
294 */
296 using Type = std::chrono::seconds;
297};
298
299/**
300 * The minimum accepted bytes/second download rate.
301 *
302 * If the average rate is below this value for the `DownloadStallTimeoutOption`
303 * then the download is aborted.
304 *
305 * @ingroup storage-options
306 */
308 using Type = std::int32_t;
309};
310
311/**
312 * Set the retry policy for a GCS client.
313 *
314 * @ingroup storage-options
315 */
316struct RetryPolicyOption {
317 using Type = std::shared_ptr<RetryPolicy>;
318};
319
320/**
321 * Set the backoff policy for a GCS client.
322 *
323 * @ingroup storage-options
324 */
325struct BackoffPolicyOption {
326 using Type = std::shared_ptr<BackoffPolicy>;
327};
328
329/**
330 * Set the idempotency policy for a GCS client.
331 *
332 * @ingroup storage-options
333 */
335 using Type = std::shared_ptr<IdempotencyPolicy>;
336};
337
338/// The complete list of options accepted by `storage::Client`.
339using ClientOptionList = ::google::cloud::OptionList<
348
349GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
350} // namespace storage
351} // namespace cloud
352} // namespace google
353
354#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_OPTIONS_H
Define the interface for the idempotency policy.
Definition: idempotency_policy.h:58
Interface for OAuth 2.0 credentials used to access Google Cloud services.
Definition: credentials.h:47
Authentication components for Google Cloud Storage.
Definition: anonymous_credentials.h:26
Contains experimental features for the GCS C++ Client Library.
Definition: async_client.h:27
Contains all the Google Cloud Storage C++ client APIs.
Definition: auto_finalize.h:24
Set the backoff policy for a GCS client.
Definition: options.h:325
Set the maximum connection pool size.
Definition: options.h:144
Control the formatted I/O download buffer.
Definition: options.h:161
The minimum accepted bytes/second download rate.
Definition: options.h:307
Sets the download stall timeout.
Definition: options.h:295
Disables automatic OpenSSL sigpipe handler.
Definition: options.h:221
Disables automatic OpenSSL locking.
Definition: options.h:210
Configure the IAM endpoint for the GCS client library.
Definition: options.h:93
Set the idempotency policy for a GCS client.
Definition: options.h:334
Control the maximum socket receive buffer.
Definition: options.h:232
Control the maximum socket send buffer.
Definition: options.h:242
Defines the threshold to switch from simple to resumable uploads for files.
Definition: options.h:194
Configure oauth2::Credentials for the GCS client library.
Definition: options.h:105
Set the Google Cloud Platform project id.
Definition: options.h:114
Configure the REST endpoint for the GCS client library.
Definition: options.h:84
Set the retry policy for a GCS client.
Definition: options.h:316
The minimum accepted bytes/second transfer rate.
Definition: options.h:275
Sets the transfer stall timeout.
Definition: options.h:263
Control the formatted I/O upload buffer.
Definition: options.h:179
Set the HTTP version used by the client.
Definition: options.h:51