-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Snapshots #145
Comments
Are you referring to stale reads? They are supported. |
That feature is great, and will cover most use cases, but a snapshot, unlike a standard single instance read only transaction, creates a read only transaction that you can use multiple times in a request. It's not essential, but just like you seem to have made provision for other queries to use either the base database object, or a transaction object, it would also be good to have a way for a set of queries to use a snapshot that remains consistent across the handling of a method that contains multiple reads, even if data is modified in between the different reads Heres the docs about snapshot - https://cloud.google.com/spanner/docs/samples/spanner-read-only-transaction#code-sample |
Ah, I see. I've never really had any use for such a case so it's not implemented. I can put it on the TODO but implementing it seems a bit challenging, so I can't guarantee that it will get implemented anytime soon. |
Understandable, its not critical to have in most cases, but good to flag it for the future |
@taka-oyama I just want to bump this after further investigation. It appears that while the existing The primary reason is locking. From the docs here https://cloud.google.com/spanner/docs/timestamp-bounds#timestamp_bound_types
Even with timestamp bounds - there is still potential for locking of other read-write transactions. On the other hand, snapshots take no locks and never block other transactions. In view of this, it is critical they be implemented |
I found that simply adding this to public function snapshot($options = [], Closure $callback)
{
if($this->currentTransaction)
throw new Exception('Cant run a snapshot in the middle of a transaction');
$this->currentTransaction = $this->getSpannerDatabase()->snapshot($options);
$result = $callback();
$this->currentTransaction = null;
return $result;
} And then updating the typing of trait ManagesTransactions
{
/**
* @var Transaction|Snapshot|null
*/
protected Transaction|Snapshot|null $currentTransaction = null; Is sufficient to make a simple way to call a snapshot query in a closure like this $conn->snapshot(['exactStaleness' => new Duration(15)], function() {
return Model::all();
}); |
Was there a specific case where it did block? There is a bug in the current code that causes the staleness to be ignored when inside a read-write transaction. |
Btw, if you enable data boost in your query, that's using snapshot in the background would this solve your case? |
This has been fixed in |
This is not viable since databoost queries are incredibly limited in what kind of queries you can run, due to the requirements of being root partionable etc |
No, there wasnt a specific case but in a high load application, it is an unacceptable risk, snapshots were designed for read only analytics queries that do not lock rows and are the correct way to run read only queries for optimal performance |
I couldn't find any mention about snapshots not locking in the docs but I finally found details on snapshot transaction in the API reference.
|
|
|
I see that snapshot read only transactions are unsupported. Was this based on it not being important for most use cases, or is it too difficult to implement?
Or perhaps is it planned for future versions?
The text was updated successfully, but these errors were encountered: