Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Jun 8, 2026. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 103
feat: add support to log commit stats#205
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a5a680c
feat: add support for logging commit stats
larkee d6e6db4
test: add commit stats to CommitResponse
larkee 6b97f72
style: fix lint errors
larkee ca867a8
refactor: remove log formatting
larkee b2bf238
test: update info arg assertions
larkee 507a4ec
docs: document logger param
larkee 11f62bc
refactor: pass CommitStats via extra kwarg
larkee 3dae32a
fix: ensure logger is unused if commit fails
larkee 06182d2
Merge branch 'master' into commit-stats
larkee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -21,6 +21,7 @@ | ||
| _merge_query_options, | ||
| _metadata_with_prefix, | ||
| ) | ||
| from google.cloud.spanner_v1 import CommitRequest | ||
| from google.cloud.spanner_v1 import ExecuteBatchDmlRequest | ||
| from google.cloud.spanner_v1 import ExecuteSqlRequest | ||
| from google.cloud.spanner_v1 import TransactionSelector | ||
| @@ -42,6 +43,7 @@ class Transaction(_SnapshotBase, _BatchBase): | ||
| committed = None | ||
| """Timestamp at which the transaction was successfully committed.""" | ||
| rolled_back = False | ||
| commit_stats = None | ||
| _multi_use = True | ||
| _execute_sql_count = 0 | ||
| @@ -119,9 +121,13 @@ def rollback(self): | ||
| self.rolled_back = True | ||
| del self._session._transaction | ||
| def commit(self): | ||
| def commit(self, return_commit_stats=False): | ||
| """Commit mutations to the database. | ||
| :type return_commit_stats: bool | ||
| :param return_commit_stats: | ||
| If true, the response will return commit stats which can be accessed though commit_stats. | ||
| :rtype: datetime | ||
| :returns: timestamp of the committed changes. | ||
| :raises ValueError: if there are no mutations to commit. | ||
| @@ -132,14 +138,17 @@ def commit(self): | ||
| api = database.spanner_api | ||
| metadata = _metadata_with_prefix(database.name) | ||
| trace_attributes = {"num_mutations": len(self._mutations)} | ||
| request = CommitRequest( | ||
| session=self._session.name, | ||
| mutations=self._mutations, | ||
| transaction_id=self._transaction_id, | ||
| return_commit_stats=return_commit_stats, | ||
| ) | ||
| with trace_call("CloudSpanner.Commit", self._session, trace_attributes): | ||
| response = api.commit( | ||
| session=self._session.name, | ||
| mutations=self._mutations, | ||
| transaction_id=self._transaction_id, | ||
| metadata=metadata, | ||
| ) | ||
| response = api.commit(request=request, metadata=metadata,) | ||
| self.committed = response.commit_timestamp | ||
| if return_commit_stats: | ||
| self.commit_stats = response.commit_stats | ||
skuruppu marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| del self._session._transaction | ||
| return self.committed | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.