Conversation
Contributor
Author
|
jenkins please test branch @dbaas3.0 |
Contributor
|
@msirek , this was a great description of the issue and the fix. Thanks for taking the time to clearly explain it! |
Contributor
Author
|
jenkins please test branch @dbaas3.0 |
martinrupp
approved these changes
Jul 20, 2021
Contributor
Contributor
Author
|
jenkins please test branch @dbaas3.0 |
Contributor
Contributor
Author
|
jenkins please test branch @dbaas3.0 |
jyuanca
approved these changes
Jul 21, 2021
Contributor
Contributor
Author
|
jenkins please test branch @dbaas3.0 |
Contributor
|
TEST SUCCEEDED +1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Short Description
A DML statement run in NSDS which fires a trigger may corrupt data dictionary dependencies. Subsequent DDL statements, such as TRUNCATE involving trigger tables corrupts the trigger, which may cause trigger rows to be written to the wrong table and/or be written incorrectly.
Long Description
Whenever a trigger needs recompilation due to some dictionary modification which the trigger may depend on, it is marked as invalid in the sys.sysstatements system table. For example, if the target table of the trigger is altered or another trigger is added to the same target table, the previous trigger is marked invalid. The next statement which fires the trigger causes recompilation of the trigger. First BasicDependencyManager.clearDependencies is called to remove the row in sys.sysdepends for the old version of the trigger SPSDecriptor. Then GenericTriggerExecutor.compile is called to build the new trigger SPSDecriptor and store a persistent representation of it in sys.sysstatements. Then BasicDependencyManager.addDependency is called to add the UUID of the new SPSDecriptor in sys.sysdepends, so that future DDLs know which stored statement to invalidate or clear.
The problem is that DB-6516 added a check in the addDependency method, called canUseDependencyManager, to skip adding the dependency if running NSDS. This causes any future DDL statements to not detect the trigger dependency and not recompile the trigger. When a truncate is done on the table, this should invalidate the trigger because the new table will have a new conglomerate number, but the old trigger statement still refers to the old conglomerate. When the trigger is later fired, it writes rows into a defunct table. This shows up as rows simply not appearing in the proper target table, as they are supposed to, or sometimes we hit a duplicate primary key violation, because the old table, invisible to the user, still exists in HBase, and still has rows in it (if Vacuum has not been run).
DB-6516 was trying to avoid memory leaks in the in-memory dependency manager because anything addDependency adds to the DependencyManager in NSDS was not getting released. However, if both the provider (TableDescriptor) and the dependent (SPSDescriptor) are persistent, then addDependency writes to the sys.sysdepends table and not the in-memory DependencyManager. We never want to skip writing persistent dependencies, so, the fix is to have canUseDependencyManager return true when the dependency is to be written to disk, no matter if we are running on NSDS or not.
How to test