googleapis / googleapis/ruby-spanner

tx.read() operation shouldn't increment seqno field

Open
#64 0 comments 0 reactions 0 assignees View on GitHub
api: spanner priority: p3 type: cleanup
Dominant language
Ruby
Stars
6
Forks
24
PR merge metrics
No merged PRs in 30d

Description

### Background:
Cloud Spanner uses the [`seqno`](https://github.com/googleapis/googleapis/blob/dd546bf83f7aa6dd24e17d3e83d9a397a6dd680c/google/spanner/v1/spanner.proto#L629-L639) field in DML statements of transactions to identify duplicate or out-of-order requests. This field is ignored for other queries. The value must always be monotonically increasing for every DML operation.

### Problem:
The [`Transaction#read()`](https://github.com/googleapis/ruby-spanner/blob/c6cde4010632724449bc4a653221f94a9c262669/google-cloud-spanner/lib/google/cloud/spanner/transaction.rb#L711) method isn't a DML operation, and doesn't use the `seqno` field. Yet, when the user calls it, the `@seqno` value is auto-incremented. This is because the read query is executed inside the context of [`safe_execute()`](https://github.com/googleapis/ruby-spanner/blob/c6cde4010632724449bc4a653221f94a9c262669/google-cloud-spanner/lib/google/cloud/spanner/transaction.rb#L1169-L1185) block.

While this won't cause any failure, we should avoid incrementing `seqno` for non-DML operations. This might lead to confusing debugging situations in the future, when the value is noticed to jump from `n` to `n + 2` directly (for any n >= 1). This can happen if there are DML operations interleaved with a `.read()` operation.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.