[Catalog] Fix locking issues + identify problem in MappingValue #9523
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.
The test this adds is skipped because it's not entirely fixed by this PR.
The issues fixed by this PR were found through the test, but there is a bigger underlying problem that needs more thought.
To summarize the issues fixed by this PR:
When we read from a catalog, we need to grab the CatalogSet's
catalog_lock
, even when we already have the Catalog'swrite_lock
.The issue that isn't fixed is that
DeleteMapping
is too eager, it deletes mappings too eagerly, I think we need a refcount similar to what we do forEntryValue
<->EntryIndex
so we can be aware that there are other transactions that make use of the mapping.The issue highlighted by the added test is that sometimes this could result in a crash.
When we grab a reference to a CatalogEntry and that entry is subsequently deleted after we release the lock, we're holding random memory.
When I comment out the
DeleteMapping
call I can not reproduce this crashI've also tried taking out the DeleteMapping and moving it into
CommitState::CommitEntry
so it only happens when the transaction is successful, but that still didn't fix it.