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
max commit delay
  • Loading branch information
nginsberg-google committed Nov 22, 2023
commit 891d80073e4eb14fb4ca14993525be2d3a542a81
11 changes: 10 additions & 1 deletion google/cloud/spanner_v1/batch.py
Expand Up @@ -30,6 +30,7 @@
from google.cloud.spanner_v1._helpers import _retry
from google.cloud.spanner_v1._helpers import _check_rst_stream_error
from google.api_core.exceptions import InternalServerError
from google.protobuf.duration_pb2 import Duration


class _BatchBase(_SessionWrapper):
Expand Down Expand Up @@ -145,7 +146,7 @@ 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):
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 All @@ -158,6 +159,9 @@ def commit(self, return_commit_stats=False, request_options=None):
(Optional) Common options for this request.
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.spanner_v1.types.RequestOptions`.
:param max_commit_delay_ms:
(Optional) The amount of latency this request is willing to incur
in order to improve throughput.

:rtype: datetime
:returns: timestamp of the committed changes.
Expand All @@ -182,11 +186,16 @@ def commit(self, return_commit_stats=False, request_options=None):
# Request tags are not supported for commit requests.
request_options.request_tag = None

Duration max_commit_delay = None
if max_commit_delay_ms is not None:
max_commit_delay.nanos = 1000000 * [max_commit_delay_ms]

request = CommitRequest(
session=self._session.name,
mutations=self._mutations,
single_use_transaction=txn_options,
return_commit_stats=return_commit_stats,
max_commit_delay=max_commit_delay,
nginsberg-google marked this conversation as resolved.
Show resolved Hide resolved
request_options=request_options,
)
with trace_call("CloudSpanner.Commit", self._session, trace_attributes):
Expand Down
12 changes: 11 additions & 1 deletion google/cloud/spanner_v1/transaction.py
Expand Up @@ -36,6 +36,7 @@
from google.cloud.spanner_v1 import RequestOptions
from google.api_core import gapic_v1
from google.api_core.exceptions import InternalServerError
from google.protobuf.duration_pb2 import Duration


class Transaction(_SnapshotBase, _BatchBase):
Expand Down Expand Up @@ -180,7 +181,7 @@ def rollback(self):
self.rolled_back = True
del self._session._transaction

def commit(self, return_commit_stats=False, request_options=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 All @@ -193,6 +194,10 @@ def commit(self, return_commit_stats=False, request_options=None):
(Optional) Common options for this request.
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.spanner_v1.types.RequestOptions`.
:param max_commit_delay_ms:
(Optional) The amount of latency this request is willing to incur
in order to improve throughput.
:class:`~google.cloud.spanner_v1.types.MaxCommitDelay`.

:rtype: datetime
:returns: timestamp of the committed changes.
Expand Down Expand Up @@ -223,11 +228,16 @@ def commit(self, return_commit_stats=False, request_options=None):
# Request tags are not supported for commit requests.
request_options.request_tag = None

Duration max_commit_delay = None
if max_commit_delay_ms is not None:
max_commit_delay.nanos = 1000000 * [max_commit_delay_ms]

request = CommitRequest(
session=self._session.name,
mutations=self._mutations,
transaction_id=self._transaction_id,
return_commit_stats=return_commit_stats,
max_commit_delay=max_commit_delay,
request_options=request_options,
)
with trace_call("CloudSpanner.Commit", self._session, trace_attributes):
Expand Down