Skip to content

Commit

Permalink
Adding the section on dangling sessions to the bigquery page
Browse files Browse the repository at this point in the history
	modified:   docs/sdk/resources/persisting-data/bigquery.md
  • Loading branch information
abernatskiy committed Dec 19, 2024
1 parent 23fa9b5 commit 8b5f5a3
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions docs/sdk/resources/persisting-data/bigquery.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,44 @@ deploy:
## Examples
An end-to-end example geared towards local runs can be found in [this repo](https://github.com/subsquid-labs/squid-bigquery-example). Look at [this branch](https://github.com/subsquid-labs/squid-bigquery-example/tree/cloud-secrets) for an example of a squid made for deployment to SQD Cloud.
## Troubleshooting
### Transaction is aborted due to concurrent update
This means that your project has an open [session](https://cloud.google.com/bigquery/docs/sessions-intro) that is updating some of the tables used by the squid.
Most commonly, the session is left by a squid itself after an unclean termination. You have two options:
1. If you are not sure if your squid is the only app that uses sessions to access your BigQuery project, find the faulty session manually and terminate it. See [Get a list of your active sessions](https://cloud.google.com/bigquery/docs/sessions-get-ids#list_active) and [Terminate a session by ID](https://cloud.google.com/bigquery/docs/sessions-terminating#terminate_a_session_by_id).
2. **DANGEROUS** If you are absolutely certain that the squid is the only app that uses sessions to access your BigQuery project, you can terminate all the dangling sessions by running
```sql
FOR session in (
SELECT
session_id,
MAX(creation_time) AS last_modified_time,
FROM `region-us`.INFORMATION_SCHEMA.SESSIONS_BY_PROJECT
WHERE
session_id IS NOT NULL
AND is_active
GROUP BY session_id
ORDER BY last_modified_time DESC
)
DO
CALL BQ.ABORT_SESSION(session.session_id);
END FOR;
```
Replace `region-us` with your dataset's region in the code above.

You can also enable `abortAllProjectSessionsOnStartup` and supply `datasetRegion` in your database config to perform this operation at startup:
```ts
const db = new Database({
// ...
abortAllProjectSessionsOnStartup: true,
datasetRegion: 'region-us'.
})
```

This method **will** cause data loss if, at the moment when the squid starts, some other app happens to be writing data anywhere in the project using the sessions mechanism.

0 comments on commit 8b5f5a3

Please sign in to comment.