-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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: prepared statement with AS OF SYSTEM TIME can create txn atomicity violation #68216
Comments
Related to cockroachdb#68216. Previously, running `crdb_internal.show_create_all_tables` in an existing explicit transaction would crash for the reasons discussed in cockroachdb#68216. This should not have crashed, but this also revealed that the internal executor in the `showCreateAllTablesGenerator` was a little confused. It was issuing AS OF SYSTEM TIME queries, but also supplying its parent transaction. So it wanted to execute in the context of its parent transaction, but also to run at a very specific timestamp - contradictory desires. This commit fixes this by removing the transactions from these uses of the internal executor and letting the internal executor queries run at their fixed timestamp. An alternative to this is to do away with the non-transactional nature of `showCreateAllTablesGenerator`. I don't understand why it is using its own timestamp and issuing AS OF SYSTEM TIME queries at all, instead of just using its parent transaction. But this all seems so deliberate that I imagine there was a good reason to build it this way. Example crash: ``` ➜ ./cockroach demo --insecure > BEGIN; OPEN> SELECT count(*) FROM rides; count --------- 500 OPEN> SELECT crdb_internal.show_create_all_tables('movr'); ERROR: internal error: crdb_internal.show_create_all_tables: unexpected batch read timestamp: 1627529007.202325000,0. Expected refreshed timestamp: 1627528898.793460000,0. ba: Scan [/Table/3/1,/Table/3/2), [txn: 3565aed1]. txn: "sql txn" meta={id=3565aed1 pri=0.05136598 epo=0 ts=1627529007.202325000,0 min=1627528898.793460000,0 seq=0} lock=false stat=PENDING rts=1627529007.202325000,0 wto=false gul=1627529007.202325000,0 SQLSTATE: XX000 DETAIL: stack trace: github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord/txn_interceptor_span_refresher.go:160: SendLocked() github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord/txn_interceptor_pipeliner.go:285: SendLocked() github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord/txn_interceptor_seq_num_allocator.go:105: SendLocked() github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord/txn_interceptor_heartbeater.go:240: SendLocked() github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord/txn_coord_sender.go:513: Send() github.com/cockroachdb/cockroach/pkg/kv/db.go:831: sendUsingSender() github.com/cockroachdb/cockroach/pkg/kv/txn.go:982: Send() github.com/cockroachdb/cockroach/pkg/kv/db.go:742: sendAndFill() github.com/cockroachdb/cockroach/pkg/kv/txn.go:635: Run() github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkv/catalogkv.go:281: getAllDescriptorsAndMaybeNamespaceEntriesUnvalidated() github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkv/catalogkv.go:343: GetAllDescriptors() github.com/cockroachdb/cockroach/pkg/sql/catalog/descs/kv_descriptors.go:265: getAllDescriptors() github.com/cockroachdb/cockroach/pkg/sql/catalog/descs/collection.go:270: GetAllDescriptors() github.com/cockroachdb/cockroach/pkg/sql/information_schema.go:2335: forEachTableDescWithTableLookupInternal() github.com/cockroachdb/cockroach/pkg/sql/information_schema.go:2289: forEachTableDescWithTableLookup() github.com/cockroachdb/cockroach/pkg/sql/pg_catalog.go:964: func1() github.com/cockroachdb/cockroach/pkg/sql/virtual_schema.go:533: 1() github.com/cockroachdb/cockroach/pkg/sql/virtual_table.go:120: func3() github.com/cockroachdb/cockroach/pkg/util/stop/stopper.go:442: func2() runtime/asm_amd64.s:1371: goexit() HINT: You have encountered an unexpected error. Please check the public issue tracker to check whether this problem is already tracked. If you cannot find it there, please report the error with details by creating a new issue. If you would rather not post publicly, please contact us directly using the support form. We appreciate your feedback. ```
Related to cockroachdb#68216. Previously, running `crdb_internal.show_create_all_tables` in an existing explicit transaction would crash for the reasons discussed in cockroachdb#68216. This should not have crashed, but this also revealed that the internal executor in the `showCreateAllTablesGenerator` was a little confused. It was issuing AS OF SYSTEM TIME queries, but also supplying its parent transaction. So it wanted to execute in the context of its parent transaction, but also to run at a very specific timestamp - contradictory desires. This commit fixes this by removing the AS OF SYSTEM TIME clauses from the internal executor queries. This has the effect of making this builtin transactional. Example crash: ``` ➜ ./cockroach demo --insecure > BEGIN; OPEN> SELECT count(*) FROM rides; count --------- 500 OPEN> SELECT crdb_internal.show_create_all_tables('movr'); ERROR: internal error: crdb_internal.show_create_all_tables: unexpected batch read timestamp: 1627529007.202325000,0. Expected refreshed timestamp: 1627528898.793460000,0. ba: Scan [/Table/3/1,/Table/3/2), [txn: 3565aed1]. txn: "sql txn" meta={id=3565aed1 pri=0.05136598 epo=0 ts=1627529007.202325000,0 min=1627528898.793460000,0 seq=0} lock=false stat=PENDING rts=1627529007.202325000,0 wto=false gul=1627529007.202325000,0 SQLSTATE: XX000 DETAIL: stack trace: github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord/txn_interceptor_span_refresher.go:160: SendLocked() github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord/txn_interceptor_pipeliner.go:285: SendLocked() github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord/txn_interceptor_seq_num_allocator.go:105: SendLocked() github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord/txn_interceptor_heartbeater.go:240: SendLocked() github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord/txn_coord_sender.go:513: Send() github.com/cockroachdb/cockroach/pkg/kv/db.go:831: sendUsingSender() github.com/cockroachdb/cockroach/pkg/kv/txn.go:982: Send() github.com/cockroachdb/cockroach/pkg/kv/db.go:742: sendAndFill() github.com/cockroachdb/cockroach/pkg/kv/txn.go:635: Run() github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkv/catalogkv.go:281: getAllDescriptorsAndMaybeNamespaceEntriesUnvalidated() github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkv/catalogkv.go:343: GetAllDescriptors() github.com/cockroachdb/cockroach/pkg/sql/catalog/descs/kv_descriptors.go:265: getAllDescriptors() github.com/cockroachdb/cockroach/pkg/sql/catalog/descs/collection.go:270: GetAllDescriptors() github.com/cockroachdb/cockroach/pkg/sql/information_schema.go:2335: forEachTableDescWithTableLookupInternal() github.com/cockroachdb/cockroach/pkg/sql/information_schema.go:2289: forEachTableDescWithTableLookup() github.com/cockroachdb/cockroach/pkg/sql/pg_catalog.go:964: func1() github.com/cockroachdb/cockroach/pkg/sql/virtual_schema.go:533: 1() github.com/cockroachdb/cockroach/pkg/sql/virtual_table.go:120: func3() github.com/cockroachdb/cockroach/pkg/util/stop/stopper.go:442: func2() runtime/asm_amd64.s:1371: goexit() HINT: You have encountered an unexpected error. Please check the public issue tracker to check whether this problem is already tracked. If you cannot find it there, please report the error with details by creating a new issue. If you would rather not post publicly, please contact us directly using the support form. We appreciate your feedback. ```
Related to cockroachdb#68216. Previously, running `crdb_internal.show_create_all_tables` in an existing explicit transaction would crash for the reasons discussed in cockroachdb#68216. This should not have crashed, but this also revealed that the internal executor in the `showCreateAllTablesGenerator` was a little confused. It was issuing AS OF SYSTEM TIME queries, but also supplying its parent transaction. So it wanted to execute in the context of its parent transaction, but also to run at a very specific timestamp - contradictory desires. This commit fixes this by removing the transactions from these uses of the internal executor and letting the internal executor queries run at their fixed timestamp. An alternative to this is to do away with the non-transactional nature of `showCreateAllTablesGenerator`. I don't understand why it is using its own timestamp and issuing AS OF SYSTEM TIME queries at all, instead of just using its parent transaction. But this all seems so deliberate that I imagine there was a good reason to build it this way. Example crash: ``` ➜ ./cockroach demo --insecure > BEGIN; OPEN> SELECT count(*) FROM rides; count --------- 500 OPEN> SELECT crdb_internal.show_create_all_tables('movr'); ERROR: internal error: crdb_internal.show_create_all_tables: unexpected batch read timestamp: 1627529007.202325000,0. Expected refreshed timestamp: 1627528898.793460000,0. ba: Scan [/Table/3/1,/Table/3/2), [txn: 3565aed1]. txn: "sql txn" meta={id=3565aed1 pri=0.05136598 epo=0 ts=1627529007.202325000,0 min=1627528898.793460000,0 seq=0} lock=false stat=PENDING rts=1627529007.202325000,0 wto=false gul=1627529007.202325000,0 SQLSTATE: XX000 DETAIL: stack trace: github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord/txn_interceptor_span_refresher.go:160: SendLocked() github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord/txn_interceptor_pipeliner.go:285: SendLocked() github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord/txn_interceptor_seq_num_allocator.go:105: SendLocked() github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord/txn_interceptor_heartbeater.go:240: SendLocked() github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord/txn_coord_sender.go:513: Send() github.com/cockroachdb/cockroach/pkg/kv/db.go:831: sendUsingSender() github.com/cockroachdb/cockroach/pkg/kv/txn.go:982: Send() github.com/cockroachdb/cockroach/pkg/kv/db.go:742: sendAndFill() github.com/cockroachdb/cockroach/pkg/kv/txn.go:635: Run() github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkv/catalogkv.go:281: getAllDescriptorsAndMaybeNamespaceEntriesUnvalidated() github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkv/catalogkv.go:343: GetAllDescriptors() github.com/cockroachdb/cockroach/pkg/sql/catalog/descs/kv_descriptors.go:265: getAllDescriptors() github.com/cockroachdb/cockroach/pkg/sql/catalog/descs/collection.go:270: GetAllDescriptors() github.com/cockroachdb/cockroach/pkg/sql/information_schema.go:2335: forEachTableDescWithTableLookupInternal() github.com/cockroachdb/cockroach/pkg/sql/information_schema.go:2289: forEachTableDescWithTableLookup() github.com/cockroachdb/cockroach/pkg/sql/pg_catalog.go:964: func1() github.com/cockroachdb/cockroach/pkg/sql/virtual_schema.go:533: 1() github.com/cockroachdb/cockroach/pkg/sql/virtual_table.go:120: func3() github.com/cockroachdb/cockroach/pkg/util/stop/stopper.go:442: func2() runtime/asm_amd64.s:1371: goexit() HINT: You have encountered an unexpected error. Please check the public issue tracker to check whether this problem is already tracked. If you cannot find it there, please report the error with details by creating a new issue. If you would rather not post publicly, please contact us directly using the support form. We appreciate your feedback. ```
68217: sql: fix show_create_all_tables in explicit transactions r=nvanbenschoten a=nvanbenschoten Related to #68216. Previously, running `crdb_internal.show_create_all_tables` in an existing explicit transaction would crash for the reasons discussed in #68216. This should not have crashed but it should have thrown an error. This revealed that the internal executor in the `showCreateAllTablesGenerator` was a little confused. It was issuing AS OF SYSTEM TIME queries, but also supplying its parent transaction. So it wanted to execute in the context of its parent transaction, but also to run at a very specific timestamp - contradictory desires. This commit fixes this by removing the AS OF SYSTEM TIME clauses from the internal executor queries. This has the effect of making this builtin transactional. Example crash: ``` ➜ ./cockroach demo --insecure > BEGIN; OPEN> SELECT count(*) FROM rides; count --------- 500 OPEN> SELECT crdb_internal.show_create_all_tables('movr'); ERROR: internal error: crdb_internal.show_create_all_tables: unexpected batch read timestamp: 1627529007.202325000,0. Expected refreshed timestamp: 1627528898.793460000,0. ba: Scan [/Table/3/1,/Table/3/2), [txn: 3565aed1]. txn: "sql txn" meta={id=3565aed1 pri=0.05136598 epo=0 ts=1627529007.202325000,0 min=1627528898.793460000,0 seq=0} lock=false stat=PENDING rts=1627529007.202325000,0 wto=false gul=1627529007.202325000,0 SQLSTATE: XX000 DETAIL: stack trace: github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord/txn_interceptor_span_refresher.go:160: SendLocked() github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord/txn_interceptor_pipeliner.go:285: SendLocked() github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord/txn_interceptor_seq_num_allocator.go:105: SendLocked() github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord/txn_interceptor_heartbeater.go:240: SendLocked() github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord/txn_coord_sender.go:513: Send() github.com/cockroachdb/cockroach/pkg/kv/db.go:831: sendUsingSender() github.com/cockroachdb/cockroach/pkg/kv/txn.go:982: Send() github.com/cockroachdb/cockroach/pkg/kv/db.go:742: sendAndFill() github.com/cockroachdb/cockroach/pkg/kv/txn.go:635: Run() github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkv/catalogkv.go:281: getAllDescriptorsAndMaybeNamespaceEntriesUnvalidated() github.com/cockroachdb/cockroach/pkg/sql/catalog/catalogkv/catalogkv.go:343: GetAllDescriptors() github.com/cockroachdb/cockroach/pkg/sql/catalog/descs/kv_descriptors.go:265: getAllDescriptors() github.com/cockroachdb/cockroach/pkg/sql/catalog/descs/collection.go:270: GetAllDescriptors() github.com/cockroachdb/cockroach/pkg/sql/information_schema.go:2335: forEachTableDescWithTableLookupInternal() github.com/cockroachdb/cockroach/pkg/sql/information_schema.go:2289: forEachTableDescWithTableLookup() github.com/cockroachdb/cockroach/pkg/sql/pg_catalog.go:964: func1() github.com/cockroachdb/cockroach/pkg/sql/virtual_schema.go:533: 1() github.com/cockroachdb/cockroach/pkg/sql/virtual_table.go:120: func3() github.com/cockroachdb/cockroach/pkg/util/stop/stopper.go:442: func2() runtime/asm_amd64.s:1371: goexit() HINT: You have encountered an unexpected error. Please check the public issue tracker to check whether this problem is already tracked. If you cannot find it there, please report the error with details by creating a new issue. If you would rather not post publicly, please contact us directly using the support form. We appreciate your feedback. ``` Co-authored-by: Nathan VanBenschoten <[email protected]>
This commit asserts that a transaction has not been used to read or to write by the time that `SetFixedTimestamp` is called on it. This was extracted from cockroachdb#68194 and modified to return an error from `SetFixedTimestamp` on misuse instead of fatal-ing. This provides a sufficient, temporary backstop for cockroachdb#68216 until the conn executor logic is fixed: ``` [email protected]:26257/movr> create table t (x int); CREATE TABLE [email protected]:26257/movr> insert into t values (1); INSERT 1 [email protected]:26257/movr> select crdb_internal_mvcc_timestamp, * from t; crdb_internal_mvcc_timestamp | x ---------------------------------+---- 1628094563935439000.0000000000 | 1 (1 row) [email protected]:26257/movr> begin as of system time (1628094563935439000.0000000000-1)::string; BEGIN [email protected]:26257/movr OPEN> select * from t; x ----- (0 rows) [email protected]:26257/movr OPEN> prepare y as select * from t as of system time 1628094563935439000.0000000000; ERROR: internal error: cannot set fixed timestamp, txn "sql txn" meta={id=e5e81c19 pri=0.01517572 epo=0 ts=1628094563.935438999,0 min=1628094563.935438999,0 seq=0} lock=false stat=PENDING rts=1628094563.935438999,0 wto=false gul=1628094563.935438999,0 already performed reads SQLSTATE: XX000 DETAIL: stack trace: github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord/txn_coord_sender.go:1016: SetFixedTimestamp() github.com/cockroachdb/cockroach/pkg/kv/txn.go:1200: SetFixedTimestamp() github.com/cockroachdb/cockroach/pkg/sql/conn_executor_prepare.go:278: populatePrepared() github.com/cockroachdb/cockroach/pkg/sql/conn_executor_prepare.go:220: func1() github.com/cockroachdb/cockroach/pkg/sql/conn_executor_prepare.go:226: prepare() github.com/cockroachdb/cockroach/pkg/sql/conn_executor_prepare.go:112: addPreparedStmt() github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:570: execStmtInOpenState() github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:126: execStmt() github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1626: func1() github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1628: execCmd() github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1550: run() github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:627: ServeConn() github.com/cockroachdb/cockroach/pkg/sql/pgwire/conn.go:645: func1() runtime/asm_amd64.s:1371: goexit() HINT: You have encountered an unexpected error. Please check the public issue tracker to check whether this problem is already tracked. If you cannot find it there, please report the error with details by creating a new issue. If you would rather not post publicly, please contact us directly using the support form. We appreciate your feedback. [email protected]:26257/? ERROR> ```
#68426 provides enough of a backstop for this so that it is no longer high severity. |
This commit asserts that a transaction has not been used to read or to write by the time that `SetFixedTimestamp` is called on it. This was extracted from cockroachdb#68194 and modified to return an error from `SetFixedTimestamp` on misuse instead of fatal-ing. This provides a sufficient, temporary backstop for cockroachdb#68216 until the conn executor logic is fixed: ``` [email protected]:26257/movr> create table t (x int); CREATE TABLE [email protected]:26257/movr> insert into t values (1); INSERT 1 [email protected]:26257/movr> select crdb_internal_mvcc_timestamp, * from t; crdb_internal_mvcc_timestamp | x ---------------------------------+---- 1628094563935439000.0000000000 | 1 (1 row) [email protected]:26257/movr> begin as of system time (1628094563935439000.0000000000-1)::string; BEGIN [email protected]:26257/movr OPEN> select * from t; x ----- (0 rows) [email protected]:26257/movr OPEN> prepare y as select * from t as of system time 1628094563935439000.0000000000; ERROR: internal error: cannot set fixed timestamp, txn "sql txn" meta={id=e5e81c19 pri=0.01517572 epo=0 ts=1628094563.935438999,0 min=1628094563.935438999,0 seq=0} lock=false stat=PENDING rts=1628094563.935438999,0 wto=false gul=1628094563.935438999,0 already performed reads SQLSTATE: XX000 DETAIL: stack trace: github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord/txn_coord_sender.go:1016: SetFixedTimestamp() github.com/cockroachdb/cockroach/pkg/kv/txn.go:1200: SetFixedTimestamp() github.com/cockroachdb/cockroach/pkg/sql/conn_executor_prepare.go:278: populatePrepared() github.com/cockroachdb/cockroach/pkg/sql/conn_executor_prepare.go:220: func1() github.com/cockroachdb/cockroach/pkg/sql/conn_executor_prepare.go:226: prepare() github.com/cockroachdb/cockroach/pkg/sql/conn_executor_prepare.go:112: addPreparedStmt() github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:570: execStmtInOpenState() github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:126: execStmt() github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1626: func1() github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1628: execCmd() github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1550: run() github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:627: ServeConn() github.com/cockroachdb/cockroach/pkg/sql/pgwire/conn.go:645: func1() runtime/asm_amd64.s:1371: goexit() HINT: You have encountered an unexpected error. Please check the public issue tracker to check whether this problem is already tracked. If you cannot find it there, please report the error with details by creating a new issue. If you would rather not post publicly, please contact us directly using the support form. We appreciate your feedback. [email protected]:26257/? ERROR> ```
67866: sql: implement SQL Stats flush logic r=Azhng a=Azhng Previous PR: #67805 Next Chained PR: #67090 ## First Commit sql: remove `count` from stmt/txn stats system table Previously, system.statement_statistics and system.transaction_statistics table includes a `count` column that corresponds to `roachpb.StatementStatistics.Count` and `roachpb.TransactionStatistics.Count` fields respectively. The objective for that column is to make `INSERT ON CONFLICT DO UPDATE` style query easy. However, since early prototyping have shown that `INSERT ON CONFLICT DO UPDATE` style statement is quite inefficient, the SQL Stats flush mechanism will be implemented using separate queries INSERT and UPDATE statements. This column is no longer userful and it would require special handling. Removing this column simplifies the flush logic and removes the need for special handlings. Release note (sql change): count column is removed from system.statement_statistics and system.transaction_statistics tables. ## Second Commit sql: implement persistedsqlstats flush logic This commit implements the initial flush logic of the persisted sql stats subsystem. Release note: None 68426: kv: assert txn unused in SetFixedTimestamp r=nvanbenschoten a=nvanbenschoten This commit asserts that a transaction has not been used to read or to write by the time that `SetFixedTimestamp` is called on it. This was extracted from #68194 and modified to return an error from `SetFixedTimestamp` on misuse instead of fatal-ing. This provides a sufficient, temporary backstop for #68216 until the conn executor logic is fixed: ``` [email protected]:26257/movr> create table t (x int); CREATE TABLE [email protected]:26257/movr> insert into t values (1); INSERT 1 [email protected]:26257/movr> select crdb_internal_mvcc_timestamp, * from t; crdb_internal_mvcc_timestamp | x ---------------------------------+---- 1628094563935439000.0000000000 | 1 (1 row) [email protected]:26257/movr> begin as of system time (1628094563935439000.0000000000-1)::string; BEGIN [email protected]:26257/movr OPEN> select * from t; x ----- (0 rows) [email protected]:26257/movr OPEN> prepare y as select * from t as of system time 1628094563935439000.0000000000; ERROR: internal error: cannot set fixed timestamp, txn "sql txn" meta={id=e5e81c19 pri=0.01517572 epo=0 ts=1628094563.935438999,0 min=1628094563.935438999,0 seq=0} lock=false stat=PENDING rts=1628094563.935438999,0 wto=false gul=1628094563.935438999,0 already performed reads SQLSTATE: XX000 DETAIL: stack trace: github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord/txn_coord_sender.go:1016: SetFixedTimestamp() github.com/cockroachdb/cockroach/pkg/kv/txn.go:1200: SetFixedTimestamp() github.com/cockroachdb/cockroach/pkg/sql/conn_executor_prepare.go:278: populatePrepared() github.com/cockroachdb/cockroach/pkg/sql/conn_executor_prepare.go:220: func1() github.com/cockroachdb/cockroach/pkg/sql/conn_executor_prepare.go:226: prepare() github.com/cockroachdb/cockroach/pkg/sql/conn_executor_prepare.go:112: addPreparedStmt() github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:570: execStmtInOpenState() github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:126: execStmt() github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1626: func1() github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1628: execCmd() github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1550: run() github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:627: ServeConn() github.com/cockroachdb/cockroach/pkg/sql/pgwire/conn.go:645: func1() runtime/asm_amd64.s:1371: goexit() HINT: You have encountered an unexpected error. Please check the public issue tracker to check whether this problem is already tracked. If you cannot find it there, please report the error with details by creating a new issue. If you would rather not post publicly, please contact us directly using the support form. We appreciate your feedback. [email protected]:26257/? ERROR> ``` 68442: kv: include RangeID in rangefeed goroutine stacks r=nvanbenschoten a=nvanbenschoten This commit includes the RangeID in each of a rangefeed processor and its registations' associated goroutine stacks. This is a cheap and easy way to get better observability into the ranges that have active rangefeeds. It also tells us where those goroutines are spending their time. This will also become easier to use in Go 1.17, which improved the format of stack traces. 68443: parser: add VIRTUAL syntax to help r=RaduBerinde a=rafiss Release note: None Co-authored-by: Azhng <[email protected]> Co-authored-by: Nathan VanBenschoten <[email protected]> Co-authored-by: Rafi Shamim <[email protected]>
This commit asserts that a transaction has not been used to read or to write by the time that `SetFixedTimestamp` is called on it. This was extracted from cockroachdb#68194 and modified to return an error from `SetFixedTimestamp` on misuse instead of fatal-ing. This provides a sufficient, temporary backstop for cockroachdb#68216 until the conn executor logic is fixed: ``` [email protected]:26257/movr> create table t (x int); CREATE TABLE [email protected]:26257/movr> insert into t values (1); INSERT 1 [email protected]:26257/movr> select crdb_internal_mvcc_timestamp, * from t; crdb_internal_mvcc_timestamp | x ---------------------------------+---- 1628094563935439000.0000000000 | 1 (1 row) [email protected]:26257/movr> begin as of system time (1628094563935439000.0000000000-1)::string; BEGIN [email protected]:26257/movr OPEN> select * from t; x ----- (0 rows) [email protected]:26257/movr OPEN> prepare y as select * from t as of system time 1628094563935439000.0000000000; ERROR: internal error: cannot set fixed timestamp, txn "sql txn" meta={id=e5e81c19 pri=0.01517572 epo=0 ts=1628094563.935438999,0 min=1628094563.935438999,0 seq=0} lock=false stat=PENDING rts=1628094563.935438999,0 wto=false gul=1628094563.935438999,0 already performed reads SQLSTATE: XX000 DETAIL: stack trace: github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord/txn_coord_sender.go:1016: SetFixedTimestamp() github.com/cockroachdb/cockroach/pkg/kv/txn.go:1200: SetFixedTimestamp() github.com/cockroachdb/cockroach/pkg/sql/conn_executor_prepare.go:278: populatePrepared() github.com/cockroachdb/cockroach/pkg/sql/conn_executor_prepare.go:220: func1() github.com/cockroachdb/cockroach/pkg/sql/conn_executor_prepare.go:226: prepare() github.com/cockroachdb/cockroach/pkg/sql/conn_executor_prepare.go:112: addPreparedStmt() github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:570: execStmtInOpenState() github.com/cockroachdb/cockroach/pkg/sql/conn_executor_exec.go:126: execStmt() github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1626: func1() github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1628: execCmd() github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:1550: run() github.com/cockroachdb/cockroach/pkg/sql/conn_executor.go:627: ServeConn() github.com/cockroachdb/cockroach/pkg/sql/pgwire/conn.go:645: func1() runtime/asm_amd64.s:1371: goexit() HINT: You have encountered an unexpected error. Please check the public issue tracker to check whether this problem is already tracked. If you cannot find it there, please report the error with details by creating a new issue. If you would rather not post publicly, please contact us directly using the support form. We appreciate your feedback. [email protected]:26257/? ERROR> ```
@nvanbenschoten We don't fully understand. Should we be disallowing prepared queries with AOST? |
I don't think we should be disallowing prepared queries with AOST, but I also don't think I've fully wrapped my head around why we're setting a fixed timestamp on the active transaction when doing so. Is this because we use the transaction during planning of the prepared statement, and we need to plan the query with the correct schema immediately at prepare time, instead of at execution time? Regardless of the reason, I think we need some kind of check like we have for query execution that prevents inconsistent AOST timestamps in explicit transactions: cockroach/pkg/sql/conn_executor_exec.go Lines 614 to 619 in b365f26
As of #68426, we have that check, but it's in the form of an internal error. |
I'm not sure why we set it. Perhaps indeed the idea was that we want to use the schema as of that time (though we should be re-resolving all datasources so it's not a correctness issue). There is also the somewhat related issue of allowing the AOST value to be a placeholder #30955 |
Indeed the idea is to resolve the schema as of that timestamp. I think maybe what we'd want to do is set it explicitly if that timestamp is an exact value and not set it to anything if the timestamp is one of the allowed function calls. |
I can't reproduce. I'm pretty sure 9fdb39b fixes this. |
In 078c58a, we added an assertion that transaction timestamps are not manually set using the
(*Txn).SetFixedTimestamp
API after a transaction has already been used. This would be very unsafe, as it would allow transactions to silently change timestamps and violate atomicity. It turns out that we do hit this assertion, which revealed that something was wrong.The good news is that even without the assertion, we don't seem to be silently violating atomicity in these cases, as another assertion in KV notices the changed txn timestamp. The bad news is that this is possible to hit thanks to the unchecked use of
SetFixedTimestamp
during statement preparation.Jira issue: CRDB-8932
The text was updated successfully, but these errors were encountered: