Skip to content

Commit 2e85bc6

Browse files
authored
Merge branch 'master' into cmek-support
2 parents 514e675 + 87789c9 commit 2e85bc6

File tree

25 files changed

+350
-79
lines changed

25 files changed

+350
-79
lines changed

.github/sync-repo-settings.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# https://github.com/googleapis/repo-automation-bots/tree/master/packages/sync-repo-settings
2+
# Rules for master branch protection
3+
branchProtectionRules:
4+
# Identifies the protection rule pattern. Name of the branch to be protected.
5+
# Defaults to `master`
6+
- pattern: master
7+
requiredStatusCheckContexts:
8+
- 'Kokoro'
9+
- 'cla/google'
10+
- 'Samples - Lint'
11+
- 'Samples - Python 3.6'
12+
- 'Samples - Python 3.7'
13+
- 'Samples - Python 3.8'

google/cloud/spanner_admin_database_v1/services/database_admin/transports/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
_transport_registry["grpc"] = DatabaseAdminGrpcTransport
2929
_transport_registry["grpc_asyncio"] = DatabaseAdminGrpcAsyncIOTransport
3030

31-
3231
__all__ = (
3332
"DatabaseAdminTransport",
3433
"DatabaseAdminGrpcTransport",

google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ def __init__(
158158
ssl_credentials=ssl_credentials,
159159
scopes=scopes or self.AUTH_SCOPES,
160160
quota_project_id=quota_project_id,
161+
options=[
162+
("grpc.max_send_message_length", -1),
163+
("grpc.max_receive_message_length", -1),
164+
],
161165
)
162166
self._ssl_channel_credentials = ssl_credentials
163167
else:
@@ -176,9 +180,14 @@ def __init__(
176180
ssl_credentials=ssl_channel_credentials,
177181
scopes=scopes or self.AUTH_SCOPES,
178182
quota_project_id=quota_project_id,
183+
options=[
184+
("grpc.max_send_message_length", -1),
185+
("grpc.max_receive_message_length", -1),
186+
],
179187
)
180188

181189
self._stubs = {} # type: Dict[str, Callable]
190+
self._operations_client = None
182191

183192
# Run the base constructor.
184193
super().__init__(
@@ -202,7 +211,7 @@ def create_channel(
202211
) -> grpc.Channel:
203212
"""Create and return a gRPC channel object.
204213
Args:
205-
address (Optionsl[str]): The host for the channel to use.
214+
address (Optional[str]): The host for the channel to use.
206215
credentials (Optional[~.Credentials]): The
207216
authorization credentials to attach to requests. These
208217
credentials identify this application to the service. If
@@ -249,13 +258,11 @@ def operations_client(self) -> operations_v1.OperationsClient:
249258
client.
250259
"""
251260
# Sanity check: Only create a new client if we do not already have one.
252-
if "operations_client" not in self.__dict__:
253-
self.__dict__["operations_client"] = operations_v1.OperationsClient(
254-
self.grpc_channel
255-
)
261+
if self._operations_client is None:
262+
self._operations_client = operations_v1.OperationsClient(self.grpc_channel)
256263

257264
# Return the client from cache.
258-
return self.__dict__["operations_client"]
265+
return self._operations_client
259266

260267
@property
261268
def list_databases(

google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc_asyncio.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ def __init__(
203203
ssl_credentials=ssl_credentials,
204204
scopes=scopes or self.AUTH_SCOPES,
205205
quota_project_id=quota_project_id,
206+
options=[
207+
("grpc.max_send_message_length", -1),
208+
("grpc.max_receive_message_length", -1),
209+
],
206210
)
207211
self._ssl_channel_credentials = ssl_credentials
208212
else:
@@ -221,6 +225,10 @@ def __init__(
221225
ssl_credentials=ssl_channel_credentials,
222226
scopes=scopes or self.AUTH_SCOPES,
223227
quota_project_id=quota_project_id,
228+
options=[
229+
("grpc.max_send_message_length", -1),
230+
("grpc.max_receive_message_length", -1),
231+
],
224232
)
225233

226234
# Run the base constructor.
@@ -234,6 +242,7 @@ def __init__(
234242
)
235243

236244
self._stubs = {}
245+
self._operations_client = None
237246

238247
@property
239248
def grpc_channel(self) -> aio.Channel:
@@ -253,13 +262,13 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient:
253262
client.
254263
"""
255264
# Sanity check: Only create a new client if we do not already have one.
256-
if "operations_client" not in self.__dict__:
257-
self.__dict__["operations_client"] = operations_v1.OperationsAsyncClient(
265+
if self._operations_client is None:
266+
self._operations_client = operations_v1.OperationsAsyncClient(
258267
self.grpc_channel
259268
)
260269

261270
# Return the client from cache.
262-
return self.__dict__["operations_client"]
271+
return self._operations_client
263272

264273
@property
265274
def list_databases(

google/cloud/spanner_admin_database_v1/types/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@
5353
RestoreDatabaseEncryptionConfig,
5454
RestoreDatabaseMetadata,
5555
OptimizeRestoredDatabaseMetadata,
56+
RestoreSourceType,
5657
)
5758

58-
5959
__all__ = (
6060
"OperationProgress",
6161
"EncryptionConfig",
@@ -90,4 +90,5 @@
9090
"RestoreDatabaseEncryptionConfig",
9191
"RestoreDatabaseMetadata",
9292
"OptimizeRestoredDatabaseMetadata",
93+
"RestoreSourceType",
9394
)

google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
_transport_registry["grpc"] = InstanceAdminGrpcTransport
2929
_transport_registry["grpc_asyncio"] = InstanceAdminGrpcAsyncIOTransport
3030

31-
3231
__all__ = (
3332
"InstanceAdminTransport",
3433
"InstanceAdminGrpcTransport",

google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ def __init__(
171171
ssl_credentials=ssl_credentials,
172172
scopes=scopes or self.AUTH_SCOPES,
173173
quota_project_id=quota_project_id,
174+
options=[
175+
("grpc.max_send_message_length", -1),
176+
("grpc.max_receive_message_length", -1),
177+
],
174178
)
175179
self._ssl_channel_credentials = ssl_credentials
176180
else:
@@ -189,9 +193,14 @@ def __init__(
189193
ssl_credentials=ssl_channel_credentials,
190194
scopes=scopes or self.AUTH_SCOPES,
191195
quota_project_id=quota_project_id,
196+
options=[
197+
("grpc.max_send_message_length", -1),
198+
("grpc.max_receive_message_length", -1),
199+
],
192200
)
193201

194202
self._stubs = {} # type: Dict[str, Callable]
203+
self._operations_client = None
195204

196205
# Run the base constructor.
197206
super().__init__(
@@ -215,7 +224,7 @@ def create_channel(
215224
) -> grpc.Channel:
216225
"""Create and return a gRPC channel object.
217226
Args:
218-
address (Optionsl[str]): The host for the channel to use.
227+
address (Optional[str]): The host for the channel to use.
219228
credentials (Optional[~.Credentials]): The
220229
authorization credentials to attach to requests. These
221230
credentials identify this application to the service. If
@@ -262,13 +271,11 @@ def operations_client(self) -> operations_v1.OperationsClient:
262271
client.
263272
"""
264273
# Sanity check: Only create a new client if we do not already have one.
265-
if "operations_client" not in self.__dict__:
266-
self.__dict__["operations_client"] = operations_v1.OperationsClient(
267-
self.grpc_channel
268-
)
274+
if self._operations_client is None:
275+
self._operations_client = operations_v1.OperationsClient(self.grpc_channel)
269276

270277
# Return the client from cache.
271-
return self.__dict__["operations_client"]
278+
return self._operations_client
272279

273280
@property
274281
def list_instance_configs(

google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc_asyncio.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ def __init__(
216216
ssl_credentials=ssl_credentials,
217217
scopes=scopes or self.AUTH_SCOPES,
218218
quota_project_id=quota_project_id,
219+
options=[
220+
("grpc.max_send_message_length", -1),
221+
("grpc.max_receive_message_length", -1),
222+
],
219223
)
220224
self._ssl_channel_credentials = ssl_credentials
221225
else:
@@ -234,6 +238,10 @@ def __init__(
234238
ssl_credentials=ssl_channel_credentials,
235239
scopes=scopes or self.AUTH_SCOPES,
236240
quota_project_id=quota_project_id,
241+
options=[
242+
("grpc.max_send_message_length", -1),
243+
("grpc.max_receive_message_length", -1),
244+
],
237245
)
238246

239247
# Run the base constructor.
@@ -247,6 +255,7 @@ def __init__(
247255
)
248256

249257
self._stubs = {}
258+
self._operations_client = None
250259

251260
@property
252261
def grpc_channel(self) -> aio.Channel:
@@ -266,13 +275,13 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient:
266275
client.
267276
"""
268277
# Sanity check: Only create a new client if we do not already have one.
269-
if "operations_client" not in self.__dict__:
270-
self.__dict__["operations_client"] = operations_v1.OperationsAsyncClient(
278+
if self._operations_client is None:
279+
self._operations_client = operations_v1.OperationsAsyncClient(
271280
self.grpc_channel
272281
)
273282

274283
# Return the client from cache.
275-
return self.__dict__["operations_client"]
284+
return self._operations_client
276285

277286
@property
278287
def list_instance_configs(

google/cloud/spanner_admin_instance_v1/types/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
UpdateInstanceMetadata,
3333
)
3434

35-
3635
__all__ = (
3736
"ReplicaInfo",
3837
"InstanceConfig",

google/cloud/spanner_dbapi/connection.py

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
from google.cloud import spanner_v1 as spanner
2323
from google.cloud.spanner_v1.session import _get_retry_delay
2424

25+
from google.cloud.spanner_dbapi._helpers import _execute_insert_heterogenous
26+
from google.cloud.spanner_dbapi._helpers import _execute_insert_homogenous
27+
from google.cloud.spanner_dbapi._helpers import parse_insert
2528
from google.cloud.spanner_dbapi.checksum import _compare_checksums
2629
from google.cloud.spanner_dbapi.checksum import ResultsChecksum
2730
from google.cloud.spanner_dbapi.cursor import Cursor
@@ -82,7 +85,7 @@ def autocommit(self, value):
8285
:type value: bool
8386
:param value: New autocommit mode state.
8487
"""
85-
if value and not self._autocommit:
88+
if value and not self._autocommit and self.inside_transaction:
8689
self.commit()
8790

8891
self._autocommit = value
@@ -96,6 +99,19 @@ def database(self):
9699
"""
97100
return self._database
98101

102+
@property
103+
def inside_transaction(self):
104+
"""Flag: transaction is started.
105+
106+
Returns:
107+
bool: True if transaction begun, False otherwise.
108+
"""
109+
return (
110+
self._transaction
111+
and not self._transaction.committed
112+
and not self._transaction.rolled_back
113+
)
114+
99115
@property
100116
def instance(self):
101117
"""Instance to which this connection relates.
@@ -191,11 +207,7 @@ def transaction_checkout(self):
191207
:returns: A Cloud Spanner transaction object, ready to use.
192208
"""
193209
if not self.autocommit:
194-
if (
195-
not self._transaction
196-
or self._transaction.committed
197-
or self._transaction.rolled_back
198-
):
210+
if not self.inside_transaction:
199211
self._transaction = self._session_checkout().transaction()
200212
self._transaction.begin()
201213

@@ -216,11 +228,7 @@ def close(self):
216228
The connection will be unusable from this point forward. If the
217229
connection has an active transaction, it will be rolled back.
218230
"""
219-
if (
220-
self._transaction
221-
and not self._transaction.committed
222-
and not self._transaction.rolled_back
223-
):
231+
if self.inside_transaction:
224232
self._transaction.rollback()
225233

226234
if self._own_pool:
@@ -235,7 +243,7 @@ def commit(self):
235243
"""
236244
if self._autocommit:
237245
warnings.warn(AUTOCOMMIT_MODE_WARNING, UserWarning, stacklevel=2)
238-
elif self._transaction:
246+
elif self.inside_transaction:
239247
try:
240248
self._transaction.commit()
241249
self._release_session()
@@ -291,6 +299,24 @@ def run_statement(self, statement, retried=False):
291299
if not retried:
292300
self._statements.append(statement)
293301

302+
if statement.is_insert:
303+
parts = parse_insert(statement.sql, statement.params)
304+
305+
if parts.get("homogenous"):
306+
_execute_insert_homogenous(transaction, parts)
307+
return (
308+
iter(()),
309+
ResultsChecksum() if retried else statement.checksum,
310+
)
311+
else:
312+
_execute_insert_heterogenous(
313+
transaction, parts.get("sql_params_list"),
314+
)
315+
return (
316+
iter(()),
317+
ResultsChecksum() if retried else statement.checksum,
318+
)
319+
294320
return (
295321
transaction.execute_sql(
296322
statement.sql, statement.params, param_types=statement.param_types,

0 commit comments

Comments
 (0)