fixes regression in Schema Watch led schema caching #1684
Merged
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.
Initialization of schema watch happens via the
UnwrappableDatastore
interface. Given the various proxies built around thedatastore.Datastore
interface, we came up with the notion ofUnwrappableDatastore
to be able to extract a particular type from the proxy chain.The way this is correctly done is by unwrapping in a loop until the type is found. This was unfortunately not done in the Schema Watch initialization logic, which assumed the position of the actual underlying datastore at a specific level.
With the introduction of the datastore deduplication proxy in #1610, the proxy chain changed, and the assumed order became incorrect, making the initialization logic unable to find an instance of the
SchemaWatchableDatastore
, even though it was there. As a consequence, the logic fell back to JIT caching strategy.This means schema watch-led caching is broken since the 1.27.0 release, but only for CRDB users: The Spanner datastore is not subject to this bug because the CRDB datastore has one extra proxy layer and the code as it was initially was able to check for the target interface in the immediate level and the next unwrapped level.
This replaces every bespoke piece of code handling the unwrapping logic with a new function that does this correctly and more conveniently, sparing duplicate code and being more concise.