Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for max commit delay #1050

Merged
merged 32 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ac25604
proto generation
nginsberg-google Nov 22, 2023
891d800
max commit delay
nginsberg-google Nov 22, 2023
5a1a797
Fix some errors
nginsberg-google Dec 5, 2023
bb78bdf
Merge branch 'googleapis:main' into max-commit-delay2
nginsberg-google Dec 5, 2023
9fb4162
Unit tests
nginsberg-google Dec 5, 2023
7c88b09
regenerate proto changes
nginsberg-google Dec 5, 2023
cd0f278
Fix unit tests
nginsberg-google Dec 5, 2023
680cb40
Finish test_transaction.py
nginsberg-google Dec 5, 2023
4f7044d
Finish test_batch.py
nginsberg-google Dec 5, 2023
f71f86e
Formatting
nginsberg-google Dec 5, 2023
3c7dd7b
Cleanup
nginsberg-google Dec 5, 2023
5c2b85e
Merge branch 'main' into max-commit-delay2
harshachinta Jan 3, 2024
30f2793
Merge branch 'main' into max-commit-delay2
nginsberg-google Jan 22, 2024
e156c86
Fix merge conflict
nginsberg-google Jan 22, 2024
ca6e352
Add optional=True
nginsberg-google Jan 22, 2024
18d4c0c
Remove optional=True, try calling HasField.
nginsberg-google Jan 23, 2024
1a44475
Update HasField to be called on the protobuf.
nginsberg-google Jan 23, 2024
5e2476e
Update to timedelta.duration instead of an int.
nginsberg-google Jan 23, 2024
5a39a2d
Cleanup
nginsberg-google Jan 23, 2024
04b73dd
Changes from Sri to pipe value to top-level funcitons and to add inte…
nginsberg-google Jan 24, 2024
3ca55e1
Run nox -s blacken
nginsberg-google Jan 24, 2024
ad55fa7
Merge branch 'main' into max-commit-delay2
harshachinta Jan 25, 2024
50f0285
Merge branch 'main' into max-commit-delay2
harshachinta Jan 28, 2024
2a44ed9
feat(spanner): remove unused imports and add line
harshachinta Jan 28, 2024
8d8c6ae
feat(spanner): add empty line in python docs
harshachinta Jan 28, 2024
2c5d78f
Merge branch 'main' into max-commit-delay2
nginsberg-google Jan 30, 2024
814c69b
Update comment with valid values.
nginsberg-google Jan 30, 2024
8532a3a
Merge branch 'main' into max-commit-delay2
harshachinta Jan 30, 2024
3bc0398
Update comment with valid values.
nginsberg-google Jan 30, 2024
6093d08
feat(spanner): fix lint
harshachinta Jan 30, 2024
80d25e8
Merge branch 'main' into max-commit-delay2
harshachinta Feb 2, 2024
ac46411
feat(spanner): rever nox file changes
harshachinta Feb 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
regenerate proto changes
  • Loading branch information
nginsberg-google committed Dec 5, 2023
commit 7c88b09094c415578808c32511b32a3f853c5aeb
4 changes: 3 additions & 1 deletion google/cloud/spanner_v1/batch.py
Expand Up @@ -147,7 +147,9 @@ def _check_state(self):
if self.committed is not None:
raise ValueError("Batch already committed")

def commit(self, return_commit_stats=False, request_options=None, max_commit_delay_ms=None):
def commit(
self, return_commit_stats=False, request_options=None, max_commit_delay_ms=None
nginsberg-google marked this conversation as resolved.
Show resolved Hide resolved
):
"""Commit mutations to the database.

:type return_commit_stats: bool
Expand Down
4 changes: 3 additions & 1 deletion google/cloud/spanner_v1/transaction.py
Expand Up @@ -181,7 +181,9 @@ def rollback(self):
self.rolled_back = True
del self._session._transaction

def commit(self, return_commit_stats=False, request_options=None, max_commit_delay_ms=None):
def commit(
self, return_commit_stats=False, request_options=None, max_commit_delay_ms=None
):
"""Commit mutations to the database.

:type return_commit_stats: bool
Expand Down
10 changes: 3 additions & 7 deletions google/cloud/spanner_v1/types/spanner.py
Expand Up @@ -1436,13 +1436,8 @@ class CommitRequest(proto.Message):
[CommitResponse][google.spanner.v1.CommitResponse.commit_stats].
Default value is ``false``.
max_commit_delay (google.protobuf.duration_pb2.Duration):
The amount of latency this request is willing
to incur in order to improve throughput. If this
field is not set, Spanner assumes requests are
relatively latency sensitive and automatically
determines an appropriate delay time. You can
specify a batching delay value between 0 and 500
ms.

This field is a member of `oneof`_ ``_max_commit_delay``.
request_options (google.cloud.spanner_v1.types.RequestOptions):
Common options for this request.
"""
Expand Down Expand Up @@ -1474,6 +1469,7 @@ class CommitRequest(proto.Message):
max_commit_delay: duration_pb2.Duration = proto.Field(
proto.MESSAGE,
number=8,
optional=True,
message=duration_pb2.Duration,
)
request_options: "RequestOptions" = proto.Field(
Expand Down
19 changes: 15 additions & 4 deletions tests/unit/test_transaction.py
Expand Up @@ -346,7 +346,11 @@ def test_commit_w_other_error(self):
)

def _commit_helper(
self, mutate=True, return_commit_stats=False, request_options=None, max_commit_delay_ms=None
self,
mutate=True,
return_commit_stats=False,
request_options=None,
max_commit_delay_ms=None,
):
import datetime
from google.cloud.spanner_v1 import CommitResponse
Expand All @@ -372,13 +376,20 @@ def _commit_helper(
transaction.commit(
return_commit_stats=return_commit_stats,
request_options=request_options,
max_commit_delay_ms=max_commit_delay_ms
max_commit_delay_ms=max_commit_delay_ms,
)

self.assertEqual(transaction.committed, now)
self.assertIsNone(session._transaction)

session_id, mutations, txn_id, actual_request_options, max_commit_delay, metadata = api._committed
(
session_id,
mutations,
txn_id,
actual_request_options,
max_commit_delay,
metadata,
) = api._committed

if request_options is None:
expected_request_options = RequestOptions(
Expand Down Expand Up @@ -950,7 +961,7 @@ def commit(
request.transaction_id,
request.request_options,
request.max_commit_delay,
# None,
# None,
metadata,
)
return self._commit_response