Repository navigation
Conversation
Multi-region Spanner databases pin write leadership close to primary application traffic via ALTER DATABASE ... SET OPTIONS (default_leader). Add spanner_create_database_with_default_leader.
|
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new script and corresponding tests to create a Spanner database with an explicit default leader configuration. The feedback recommends safely retrieving the SPANNER_MR_INSTANCE_ID environment variable in the live integration test and skipping the test if it is missing, preventing potential KeyError crashes.
| def test_create_database_with_default_leader_live( | ||
| capsys: pytest.CaptureFixture[str], | ||
| ) -> None: | ||
| mr_instance = os.environ["SPANNER_MR_INSTANCE_ID"] |
There was a problem hiding this comment.
Accessing os.environ["SPANNER_MR_INSTANCE_ID"] directly will raise a KeyError if the environment variable is not set, which can crash the test suite ungracefully. Since this environment variable is not validated in conftest.py, we should safely retrieve it and skip the test if it is missing.
| mr_instance = os.environ["SPANNER_MR_INSTANCE_ID"] | |
| mr_instance = os.environ.get("SPANNER_MR_INSTANCE_ID") | |
| if not mr_instance: | |
| pytest.skip("SPANNER_MR_INSTANCE_ID environment variable not set") |
There was a problem hiding this comment.
Good catch, done: the live test now checks for its required environment variables up front and skips with a clear message when one is missing, instead of failing with a KeyError (eb1a8fa).
…_default_leader Problem: multi-line SQL and DDL statements were written as adjacent string fragments. That style is easy to get wrong (a missing trailing space joins two SQL tokens) and is harder to read than the statement itself, and the samples in this set mixed it with triple-quoted SQL. Solution: write each multi-line statement as a single triple-quoted string, matching the layout already used by the other samples. Only whitespace between SQL tokens changes; the statements are otherwise identical. Files updated: - spanner/database_admin/src/spanner_database_admin/create_database_with_default_leader.py
…t_leader Problem: review of this sample identified correctness and robustness improvements in the sample and its tests. Solution: apply the accepted review suggestions and extend the tests to cover the updated behavior. Details are in the review thread replies. Files updated: - spanner/database_admin/tests/create_database_with_default_leader_test.py
Description
Adds
spanner_create_database_with_default_leadercreating a multi-region database with an explicitdefault_leaderoption.Checklist
Testing
Compliance & Style
spanner/, which the default repository owners cover.Post-Approval Actions