Skip to content

Add proper transaction support by using a BigQuery session#13

Draft
ZimbiX wants to merge 1 commit intomasterfrom
use-sessions
Draft

Add proper transaction support by using a BigQuery session#13
ZimbiX wants to merge 1 commit intomasterfrom
use-sessions

Conversation

@ZimbiX
Copy link
Owner

@ZimbiX ZimbiX commented Mar 21, 2022

Contributes to #11 and #12.

Replaces transaction query buffering with actual transaction support. And introduces Sequel::Model support.

Currently this uses the one session for every query, but the docs say that prevents concurrency. They also say a session gets deleted after 7 days (or 24 hours of inactivity), which I think would mean that limiting the use of the single session to transactions would cause still problems for an app with greater uptime than that. I think I need to make it create a new session at the start of each top-level transaction, and stop using the session at the end of it.

Sequel::Model:

The implementation of #schema_parse_table was incomplete, and so was preventing a Sequel model from being defined (it inspects the table schema). However, it seems that the method isn't actually essential (or at least, isn't anymore?). I don't recall what necessitated implementing it, but removing it does let a Sequel model be defined successfully. For better support, this should probably be added back later with a full implementation.

Note that saving a Sequel model also does work now, but isn't error-free yet:

Sequel::Error: can't express [] as a SQL literal
from /home/brendan/Projects/sequel/lib/sequel/dataset/sql.rb:1319:in `literal_other_append'

#transaction works now, but manually running begin probably doesn't, since it lacks the ; select 1 workaround: googleapis/google-cloud-ruby#9617 (comment).

Todo:

  • Fix saving a Sequel model
  • Use a new session for each top-level transaction
  • Don't use a session outside a transaction
  • Update the readme regarding transactions
  • Support manually running begin
  • Consider other transaction isolation levels

Contributes to #11 and #12.

Currently this uses the one session for every query, but the docs say that prevents concurrency. They also say a session gets deleted after 24 hours, which I think would mean that limiting the use of the single session to transactions would cause still problems for an app with greater uptime than that. I think I need to make it create a new session at the start of each top-level transaction, and stop using the session at the end of it.

Sequel::Model:

The implementation of `#schema_parse_table` was incomplete, and so was preventing a Sequel model from being defined (it inspects the table schema). However, it seems that the method isn't actually essential (or at least, isn't anymore?). I don't recall what necessitated implementing it, but removing it does let a Sequel model be defined successfully. For better support, this should probably be added back later with a full implementation.

Note that saving a Sequel model also does work now, but isn't error-free yet:

```
Sequel::Error: can't express [] as a SQL literal
from /home/brendan/Projects/sequel/lib/sequel/dataset/sql.rb:1319:in `literal_other_append'
```

`#transaction` works now, but manually running `begin` probably doesn't, since it lacks the `; select 1` workaround: googleapis/google-cloud-ruby#9617 (comment).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant