Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(db) manage composite cache_key values internally
The Plugins entity has a particular case of a composite uniqueness constraint involving nullable values, which isn't natively supported by either Postgres or Cassandra. The old DAO performed filtered searches on these composite-unique entries in two places: when using the cache_key values to validate the uniqueness of a plugin and in the plugins iterator. This had two problems: 1. To perform the composite uniqueness check, the old schema library gave full DAO access to the self-check function, which then performed a filtered search. 2. The old-DAO semantics of the filtered search were suboptimal, because it did an overly general search and then filtered out the undesired values in a loop. This added extra computation to the plugin iterator. The new approach generates the unique cache_key string as an internal field in the database, which can be unique-tested for in the usual way (solving problem 1) and also be searched for precisely (solving problem 2). For uniqueness check, in Postgres it uses native UNIQUE. For Cassandra, the implementation is pretty much the same as the other uniqueness checks. The management of a hidden column in those strategies is similar to that of the ttl field for Postgres. There is one interesting gotcha, which is how to keep it up-to-date on partial updates. There is no other alternative than doing read-before-write, but we need to do this for partial updates of Plugin config field too, so this uses the general mechanism between schema and generic DAO to determine "do I need a read-before-write on this update" (currently, the two situations that will trigger a read-before-write at the generic DAO level are updates of nested records and updates of composite cache-key fields). At this point, this mechanism will only be useful for the Plugins entity and we don't see it getting more widespread use in the future. We expect that if this composite-uniqueness restriction is dropped from Plugins, then this composite-cache-key handling mechanism will be able to be dropped from the DAO as well.
- Loading branch information
Showing
4 changed files
with
281 additions
and
98 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Oops, something went wrong.