-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
internal/client: SystemConfigTrigger() fails to gossip configuration changes if EndTransaction is not executed on system range #7570
Comments
Commit adds three new event log types: + "Alter Table", logged for every ALTER TABLE DDL statement. + "Finish Schema Change", logged when an asynchronous schema change is completed. + "Reverse Schema Change", logged when an asynchronous schema change encounters an error (such as a constraint violation during backfill) and is rolled back. This Commit encountered an interesting, perhaps unintended effect with `SystemConfigTrigger`: in a "mixed" transaction which updates both system and non-system keys, the system changes will only be gossiped if the transaction record is located on the system range. In other words, "mixed" transactions will only work correctly if the system keys are modified first. Issue cockroachdb#7570 had been logged to track this unexpected behavior; this commit has also added a number of comments and a logged error to address this.
Why does |
Related: #2502. |
It would be less error prone to move the burden of knowing when to gossip the system config table to the server. We know how to extract the table ID from any key and do so to look up zone configs outside of |
I think it's more reliable to do what I suggest above because the issue depends on the history of the transaction prior to doing system config stuff, and so we're far more likely to catch this early, for example the following code txn := something // with some unknown history
txn.SetSystemConfigTrigger()
txn.Put(system-config-key, "something")
txn.Commit() will work fine with what you're suggesting except when |
You're correct. I can't think of any easy way to deal with transactions for which the transaction key does not lie on the system config range. We can't rely on intent resolution happening in any deterministic time frame. |
Commit adds three new event log types: + "Alter Table", logged for every ALTER TABLE DDL statement. + "Finish Schema Change", logged when an asynchronous schema change is completed. + "Reverse Schema Change", logged when an asynchronous schema change encounters an error (such as a constraint violation during backfill) and is rolled back. This Commit encountered an interesting, perhaps unintended effect with `SystemConfigTrigger`: in a "mixed" transaction which updates both system and non-system keys, the system changes will only be gossiped if the transaction record is located on the system range. In other words, "mixed" transactions will only work correctly if the system keys are modified first. Issue cockroachdb#7570 had been logged to track this unexpected behavior; this commit has also added a number of comments and a logged error to address this.
Not all schema changes require extra work after executing in a transaction. For example CREATE TABLE with foreign keys goes into effect immediately. This change affects schema changes that require extra work to complete after the transaction they are in is committed. e.g. CREATE INDEX, DROP TABLE, etc. This change affects these types of schema changes in the following way: 1. any statement in the same txn, following a schema change that requires further work, is disallowed. Since the schema change is not really complete, running such a statement makes no sense. 2. A schema change that requires further work is allowed at the end of a transaction IIF the preceeding statements in the transaction are READ_ONLY. This is because the schema change needs to anchor the transaction on the system range, and it is unable to do so thanks to cockroachdb#7570 fixes cockroachdb#14280
Not all schema changes require extra work after executing in a transaction. For example CREATE TABLE without foreign keys goes into effect immediately. This change affects schema changes that require extra work after the transaction they are in is committed. e.g. CREATE INDEX, DROP TABLE, etc. This change affects these types of schema changes in the following way: 1. any statement in the same txn following a schema change that requires further work, is disallowed. Since the schema change is not really complete, running a statement after it makes no sense. 2. A schema change that requires further work is allowed at the end of a transaction IIF the preceeding statements in the transaction are READ_ONLY. This is because the schema change needs to anchor the transaction on the system range, and it is unable to do so thanks to cockroachdb#7570 fixes cockroachdb#14280
Looks like the reasonable thing here is to fail |
Note that since this issue was filed we've adjusted the |
👍 thanks for the heads up. |
client.Transaction
has a settingSystemConfigTrigger()
, which is set whenever the SystemDB is modified (for example, when adding a new table). This has the effect of immediately gossiping the new system configuration when the transaction is committed (during EndTransaction command).However, this will only work if the EndTransaction command is executed on the range containing SystemDB; in the case of a "mixed" transaction which updates both SystemDB and other non-system tables, the new configuration will only be gossiped if the transaction record is located on the SystemDB range. Note that this situation currently depends on the first key modified in a transaction; if the first key modified is in the SystemDB then it works correct, otherwise it will fail.
Note that the configuration change is eventually gossiped whenever the leader lease for the SystemDB range is refreshed or changed.
I have added an log.Errorc() message which occurs when
SystemConfigTrigger
is set for an EndTransaction statement that executes on a non-system range; this should allow us to discover any other situations where this is occurring. I have also added comment explanations onSetSystemConfigTrigger()
, and inreplica.runCommitTrigger
.This issue is to track any additional documentation or functionality changes needed to address this unexpected behavior.
The text was updated successfully, but these errors were encountered: