gcpug/zagane

proposal: spanner.CommitTimestamp check

sinmetal opened this issue · 2 comments

WHAT

Detect that CommitTimestamp contains time.Now () in TIMESTAMP column with allow_commit_timestamp = true

WHY

Unless there are special circumstances, set the commit_timestamp column to
spanner.CommitTimestamp.
If time.Now () is included, Transaction will fail if a future time is set due to the time difference of the execution environment.

It's hard to notice in Test that the time is a few ms in the future, so it would be nice to be able to find it by static analysis.

However, it is difficult to judge whether it is allow_commit_timestamp = true because it is time.Time type in Go source code.
yo will add a new tag to the allow_commit_timestamp column of the generated code.

I can't come up with a good way to determine if a TIMESTAMP column is an allow_commit_timestamp column if I'm still using google-cloud-go 🤔

Error returned from Spanner

spanner: code = "FailedPrecondition", desc = "Cannot write timestamps in the future 2020-04-20T23:38:33.823058386Z > 2020-04-20T23:38:33.821725Z (current time) because the allow_commit_timestamp column option is set to true for column {COLUMN_NAME}, or for a corresponding shared key column in this table's interleaved table hierarchy."

WE NEED THIS FEATURE