Skip to content
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

sql: AS OF SYSTEM TIME transactions don't keep their timestamp across restarts #45540

Open
andreimatei opened this issue Feb 28, 2020 · 2 comments
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-kv KV Team
Projects

Comments

@andreimatei
Copy link
Contributor

andreimatei commented Feb 28, 2020

If one restarts an AS OF SYSTEM TIME transaction, the timestamp after the restart should be what it was before the restart. Unfortunately, that's not what happens when restarting the transaction after an error (either after a retriable error or a non-retriable one); the transaction's timestamp becomes current. Retriable errors are not supposed to happen for these transactions since they have no uncertainty and they're supposed to be read-only. But that leaves the non-retriable errors - executing a rollback to savepoint cockroach_restart after such an error wipes out the historical attributes of the txn.

Check out the proof pudding below - notice how the cluster_logical_timestamp() changes.

This is because of how we restart the transaction - we fail to provide a "historicalTimestamp" for the new txn:

payload := makeEventTxnStartPayload(
ex.state.priority, rwMode, ex.state.sqlTimestamp,
nil /* historicalTimestamp */, ex.transitionCtx)

Ironically, we even have a test for this specific case:

evPayload: makeEventTxnStartPayload(pri, tree.ReadOnly, now.GoTime(),

Amusingly, the test mocks out the very thing that it ought to be testing - the event generation.

I think the upcoming savepoints code will fix this for the non-retriable error case because, in the case discussed, we're not going to be creating a new transaction any more. We're actually going to be rolling back the existing transaction, so all its attributes should naturally stay in place.

Repro:

root@:26257/defaultdb> BEGIN AS OF SYSTEM TIME '-1h';
Now adding input for a multi-line SQL transaction client-side (smart_prompt enabled).
Press Enter two times to send the SQL text collected so far to the server, or Ctrl+C to cancel.
You can also use \show to display the statements entered so far.
                    ->
BEGIN

Time: 169µs

root@:26257/defaultdb  OPEN> savepoint cockroach_restart;
SAVEPOINT

root@:26257/defaultdb  OPEN> select cluster_logical_timestamp();
    cluster_logical_timestamp
----------------------------------
  1582918814760951000.0000000000
(1 row)

root@:26257/defaultdb  OPEN> select crdb_internal.force_error('a','b');
ERROR: b
SQLSTATE: a
root@:26257/? ERROR> rollback to savepoint cockroach_restart;
ROLLBACK

root@:26257/defaultdb  OPEN> select cluster_logical_timestamp();
    cluster_logical_timestamp
----------------------------------
  1582922445591281000.0000000000
(1 row)

cc @ajwerner @knz

Jira issue: CRDB-5147

@andreimatei andreimatei added the C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. label Feb 28, 2020
@andreimatei andreimatei self-assigned this Feb 28, 2020
@jordanlewis jordanlewis added this to Incoming in KV via automation Apr 21, 2020
@ajwerner
Copy link
Contributor

@andreimatei what's the status on this guy? Does it even matter? I could be more offended by this. I'm tempted to close and let this document the situation should anybody stumble into it again.

@andreimatei
Copy link
Contributor Author

The sequence above works fine now. It appears to still be broken in case of retriable errors (but not non-retriable ones). AOST transactions shouldn't get any retriable errors though (being r/o with no uncertainty); I've injected one with force_retry() to check.
So I think we're pretty good.

@lunevalex lunevalex moved this from Incoming to Transactions in KV Jul 14, 2020
@lunevalex lunevalex moved this from Transactions to Cold storage in KV Apr 23, 2021
@jlinder jlinder added the T-kv KV Team label Jun 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-kv KV Team
Projects
KV
On Hold
Development

No branches or pull requests

3 participants