Title: Issue · GitHub
Open Graph Title: Issue · googleapis/python-spanner
X Title: Issue · googleapis/python-spanner
Description: This library has moved to https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-spanner - Issue · googleapis/python-spanner
Open Graph Description: This library has moved to https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-spanner - Issue · googleapis/python-spanner
X Description: This library has moved to https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-spanner - Issue · googleapis/python-spanner
Opengraph URL: https://github.com/googleapis/python-spanner
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add custom retry and timeout options for partition reads and queries","articleBody":"I am building an application in Apache Beam and Python that runs in Google DataFlow. I am using the `ReadFromSpanner` method in `apache_beam.io.gcp.experimental.spannerio`. This works for most of my Spanner tables but the really large ones that are \u003e40m rows tend to fail due to the following error:\r\n\r\n```\r\nTraceback (most recent call last):\r\n File \"/usr/local/lib/python3.8/site-packages/dataflow_worker/batchworker.py\", line 649, in do_work\r\n work_executor.execute()\r\n File \"/usr/local/lib/python3.8/site-packages/dataflow_worker/executor.py\", line 179, in execute\r\n op.start()\r\n File \"dataflow_worker/shuffle_operations.py\", line 63, in dataflow_worker.shuffle_operations.GroupedShuffleReadOperation.start\r\n File \"dataflow_worker/shuffle_operations.py\", line 64, in dataflow_worker.shuffle_operations.GroupedShuffleReadOperation.start\r\n File \"dataflow_worker/shuffle_operations.py\", line 79, in dataflow_worker.shuffle_operations.GroupedShuffleReadOperation.start\r\n File \"dataflow_worker/shuffle_operations.py\", line 80, in dataflow_worker.shuffle_operations.GroupedShuffleReadOperation.start\r\n File \"dataflow_worker/shuffle_operations.py\", line 84, in dataflow_worker.shuffle_operations.GroupedShuffleReadOperation.start\r\n File \"apache_beam/runners/worker/operations.py\", line 359, in apache_beam.runners.worker.operations.Operation.output\r\n File \"apache_beam/runners/worker/operations.py\", line 221, in apache_beam.runners.worker.operations.SingletonConsumerSet.receive\r\n File \"dataflow_worker/shuffle_operations.py\", line 261, in dataflow_worker.shuffle_operations.BatchGroupAlsoByWindowsOperation.process\r\n File \"dataflow_worker/shuffle_operations.py\", line 268, in dataflow_worker.shuffle_operations.BatchGroupAlsoByWindowsOperation.process\r\n File \"apache_beam/runners/worker/operations.py\", line 359, in apache_beam.runners.worker.operations.Operation.output\r\n File \"apache_beam/runners/worker/operations.py\", line 221, in apache_beam.runners.worker.operations.SingletonConsumerSet.receive\r\n File \"apache_beam/runners/worker/operations.py\", line 718, in apache_beam.runners.worker.operations.DoOperation.process\r\n File \"apache_beam/runners/worker/operations.py\", line 719, in apache_beam.runners.worker.operations.DoOperation.process\r\n File \"apache_beam/runners/common.py\", line 1241, in apache_beam.runners.common.DoFnRunner.process\r\n File \"apache_beam/runners/common.py\", line 1306, in apache_beam.runners.common.DoFnRunner._reraise_augmented\r\n File \"apache_beam/runners/common.py\", line 1239, in apache_beam.runners.common.DoFnRunner.process\r\n File \"apache_beam/runners/common.py\", line 587, in apache_beam.runners.common.SimpleInvoker.invoke_process\r\n File \"apache_beam/runners/common.py\", line 1401, in apache_beam.runners.common._OutputProcessor.process_outputs\r\n File \"apache_beam/runners/worker/operations.py\", line 221, in apache_beam.runners.worker.operations.SingletonConsumerSet.receive\r\n File \"apache_beam/runners/worker/operations.py\", line 718, in apache_beam.runners.worker.operations.DoOperation.process\r\n File \"apache_beam/runners/worker/operations.py\", line 719, in apache_beam.runners.worker.operations.DoOperation.process\r\n File \"apache_beam/runners/common.py\", line 1241, in apache_beam.runners.common.DoFnRunner.process\r\n File \"apache_beam/runners/common.py\", line 1306, in apache_beam.runners.common.DoFnRunner._reraise_augmented\r\n File \"apache_beam/runners/common.py\", line 1239, in apache_beam.runners.common.DoFnRunner.process\r\n File \"apache_beam/runners/common.py\", line 587, in apache_beam.runners.common.SimpleInvoker.invoke_process\r\n File \"apache_beam/runners/common.py\", line 1401, in apache_beam.runners.common._OutputProcessor.process_outputs\r\n File \"apache_beam/runners/worker/operations.py\", line 221, in apache_beam.runners.worker.operations.SingletonConsumerSet.receive\r\n File \"apache_beam/runners/worker/operations.py\", line 718, in apache_beam.runners.worker.operations.DoOperation.process\r\n File \"apache_beam/runners/worker/operations.py\", line 719, in apache_beam.runners.worker.operations.DoOperation.process\r\n File \"apache_beam/runners/common.py\", line 1241, in apache_beam.runners.common.DoFnRunner.process\r\n File \"apache_beam/runners/common.py\", line 1321, in apache_beam.runners.common.DoFnRunner._reraise_augmented\r\n File \"/usr/local/lib/python3.8/site-packages/future/utils/__init__.py\", line 446, in raise_with_traceback\r\n raise exc.with_traceback(traceback)\r\n File \"apache_beam/runners/common.py\", line 1239, in apache_beam.runners.common.DoFnRunner.process\r\n File \"apache_beam/runners/common.py\", line 587, in apache_beam.runners.common.SimpleInvoker.invoke_process\r\n File \"apache_beam/runners/common.py\", line 1374, in apache_beam.runners.common._OutputProcessor.process_outputs\r\n File \"/usr/local/lib/python3.8/site-packages/apache_beam/io/gcp/experimental/spannerio.py\", line 550, in process\r\n for row in read_action(element['partitions']):\r\n File \"/usr/local/lib/python3.8/site-packages/google/cloud/spanner_v1/streamed.py\", line 143, in __iter__\r\n self._consume_next()\r\n File \"/usr/local/lib/python3.8/site-packages/google/cloud/spanner_v1/streamed.py\", line 116, in _consume_next\r\n response = six.next(self._response_iterator)\r\n File \"/usr/local/lib/python3.8/site-packages/google/cloud/spanner_v1/snapshot.py\", line 45, in _restart_on_unavailable\r\n for item in iterator:\r\n File \"/usr/local/lib/python3.8/site-packages/google/api_core/grpc_helpers.py\", line 116, in next\r\n six.raise_from(exceptions.from_grpc_error(exc), exc)\r\n File \"\u003cstring\u003e\", line 3, in raise_from\r\ngoogle.api_core.exceptions.DeadlineExceeded: 504 Deadline Exceeded [while running 'Read from Spanner/Read From Partitions']\r\n```\r\nFrom my understanding this error comes from the `ReadFromSpanner` operation as it's workers have timed out.\r\n\r\nTo solve this I have tried the following:\r\n\r\n- Changed the num_workers and disk_size_gb and added the `--experiments=shuffle_mode=service` flag as suggested in [Google's Common Error Guidance](https://cloud.google.com/dataflow/docs/guides/common-errors#tsg-rpc-timeout)\r\n- Changed the Machine Type from `n1-standard-1` up to `n1-standard-32`\r\n- My latest code is attached below. I am including Transformation for simple data wrangling in the rows.\r\n\r\n```\r\n \"\"\"Set pipeline arguments.\"\"\"\r\n options = PipelineOptions(\r\n region=RUNNER_REGION,\r\n project=RUNNER_PROJECT_ID,\r\n runner=RUNNER,\r\n temp_location=TEMP_LOCATION,\r\n job_name=JOB_NAME,\r\n service_account_email=SA_EMAIL,\r\n setup_file=SETUP_FILE_PATH,\r\n disk_size_gb=500,\r\n num_workers=10,\r\n machine_type=\"n1-standard-2\",\r\n save_main_session=True)\r\n\r\n \"\"\"Build and run the pipeline.\"\"\"\r\n with beam.Pipeline(options=options) as p:\r\n (p\r\n | \"Read from Spanner\" \u003e\u003e ReadFromSpanner(SPANNER_PROJECT_ID, SPANNER_INSTANCE_ID, SPANNER_DB, sql=QUERY)\r\n | \"Transform elements into dictionary\" \u003e\u003e beam.ParDo(Transformation)\r\n | \"Write new records to BQ\" \u003e\u003e WriteToBigQuery(\r\n BIGQUERY_TABLE,\r\n schema=SCHEMA,\r\n write_disposition=beam.io.BigQueryDisposition.WRITE_APPEND,\r\n create_disposition=beam.io.BigQueryDisposition.CREATE_IF_NEEDED)\r\n ) \r\n```\r\nA potential solution is to edit the timeout control; I have seen this being available in Java but not in Python. How can I edit timeout control in Python or is there any other solution to this issue?\r\n","author":{"url":"https://github.com/sebastian-montero","@type":"Person","name":"sebastian-montero"},"datePublished":"2021-03-10T17:44:50.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/261/python-spanner/issues/261"}
| route-pattern | /:user_id/:repository/issues/:id(.:format) |
| route-controller | issues |
| route-action | show |
| fetch-nonce | v2:57d327dd-4919-06ed-44ef-ca5fa7f91a04 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D3A2:12F35E:1F642E2:2D01439:6A4F895D |
| html-safe-nonce | 2efdedbd92e7880af5dcd254762f34fde8bda2b73a200a060a47e09bde817f69 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEM0EyOjEyRjM1RToxRjY0MkUyOjJEMDE0Mzk6NkE0Rjg5NUQiLCJ2aXNpdG9yX2lkIjoiNDMyOTQwNDYwMzI2MDk2MzE2NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 33deb9b6aac1f21240fb2b689927eb14af73d107ddbf4fe72c10c46d3eec1b1e |
| hovercard-subject-tag | repository:226992630 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/googleapis/python-spanner/issues/261 |
| twitter:image | https://opengraph.githubassets.com/3cc54f98105166e25e3650050536d50853f8444ec91dab7fd33ced5df2899749/googleapis/python-spanner |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3cc54f98105166e25e3650050536d50853f8444ec91dab7fd33ced5df2899749/googleapis/python-spanner |
| og:image:alt | This library has moved to https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-spanner - Issue · googleapis/python-spanner |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b92d11c0aa4a77d54ef4af1078b6a15fb5a70a215b30c4ecf28889d5a8e656d9 |
| turbo-cache-control | no-cache |
| go-import | github.com/googleapis/python-spanner git https://github.com/googleapis/python-spanner.git |
| octolytics-dimension-user_id | 16785467 |
| octolytics-dimension-user_login | googleapis |
| octolytics-dimension-repository_id | 226992630 |
| octolytics-dimension-repository_nwo | googleapis/python-spanner |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 226992630 |
| octolytics-dimension-repository_network_root_nwo | googleapis/python-spanner |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4b249b445842943ed31549e027f57a8ade9881ed |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width