Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(storage-manager): Replication supports Wildcard Updates
This commit adds support for Wildcard Updates (be it Delete or Put) when aligning replicated Storage. To make this feature possible the following changes were made: - A new enumeration `Action` was introduced. This enumeration builds on top of `SampleKind` and adds two variants: `WildcardPut` and `WildcardDelete`, each of these variants contains their full key expression. We track the full key expression to not have to deal with `Option` and the `strip_prefix`: there are cases where the `strip_prefix` cannot be removed from a Wildcard Update — yet the Wildcard Update should be recorded. For instance, if a storage subscribes to "test/replication/**" and has its strip prefix set to "test/replication", a delete on "test/**" should be recorded while the `strip_prefix` cannot be removed. - The `Event` and `EventMetadata` structures were reworked to avoid repetitions and to prevent modifications without updating the Fingerprint. - The keys of the Bloom Filter, `LogLatest` and `LatestUpdates` was changed from `Option<OwnedKeyExpr>` to the new structure `LogLatestKey`. This is because we need to remember, for Wildcard Updates, the last Put and the last Delete on the exact same key expression. This modification impacted many parts of the code base, the signature of many functions that were accepting a key expression and a Timestamp now requires an `Event` such that we can generate the associated `LogLatestKey` -- through the dedicated method `log_key()`. - In addition to the change above, and to still support keeping track of the last Put and last Delete on the same Wildcard Update, the `tombstones` and `wildcard_updates` fields of the `StorageService` were, respectively, renamed `wildcard_deletes` and `wildcard_puts`. The purpose of the former `tombstones` was changed to keep track of the Wildcard Delete. As a consequence the `is_deleted` method was removed. This futuristic deletion check will however still be performed, by checking the `wildcard_deletes`. - As a consequence of the change above, the logic of the method `overriding_wild_update` was completely reworked: the check for an overriding Wildcard Delete is different to the check for an overriding Wildcard Put. Plus, they don't apply to all `Action`. - The `LogLatest`, `Interval` and `SubInterval` structures now have the the method `remove_events_overridden_by_wildcard_update`: this method removes all the Events that are impacted by a Wildcard Update and updates the Fingerprint of the impacted Interval / SubInterval. - The core `Replication` structure now keeps an `Arc` over the `StorageService` such that it can add Wildcard Updates to it when it receives some. - The visibility of the following field / structures were changed to `pub(crate)` such that the Replication can access them: - The `Update` structure that contains the payload and timestamp associated with a Wildcard Update. - The `configuration`, `wildcard_puts`, and `wildcard_deletes` fields of the `StorageService` structure. - The signature of the method `register_wildcard_update` was changed: it no longer extracts all the metadata from the `sample` argument as, when called from the Replication Aligner, these values are not "correct" (they are linked to a reply and not to the contained payload). * plugins/zenoh-plugin-storage-manager/src/replication/classification.rs: - Added the method `remove_events_overridden_by_wildcard_update` to the `Interval` and `SubInterval` structures. - Added the method `remove_event` to the `Interval` and `SubInterval` structures. - Updated the keys of the Hash-based structures to use the `LogLatestKey` instead of an `Option<OwnedKeyExpr>`. - Updated methods to pass an `&EventMetadata` or `&Event` to be able to obtain their `LogLatestKey`. * plugins/zenoh-plugin-storage-manager/src/replication/configuration.rs: added the `prefix` accessor. * plugins/zenoh-plugin-storage-manager/src/replication/core.rs: - Changed the `Replication` structure to keep track of the `StorageService`. The latter is used to access and add/remove Wildcard Updates. - Added the method `remove_events_overridden_by_wildcard_updates` that takes a `HashMap` as this logic is shared for the latest cache and the Replication Log. * plugins/zenoh-plugin-storage-manager/src/replication/core/aligner_query.rs: updated the `reply_event_retrieval` method to handle Wildcard Updates. * plugins/zenoh-plugin-storage-manager/src/replication/core/aligner_reply.rs: - Added some traces to ease debugging. - Added the method `needs_further_processing` that, given an EventMetadata, checks if it needs to be processed, processes it if it can and otherwise returns true -- indicating that further processing is needed. - Added the method `apply_wildcard_update` that applies a Wildcard Update. - Added the method `is_overridden_by_wildcard_update` that checks if there is a Wildcard Update that overrides the provided key expression for the provided timestamp. - Added the method `store_event_overridden_by_wildcard_update` that overrides the provided EventMetadata with the Wildcard Update and stores the result. * plugins/zenoh-plugin-storage-manager/src/replication/log.rs: - Added the `Action` enumeration. - Added the `ActionKind` enumeration. - Added the `LogLatestKey` structure. - Reworked the `Event` and `EventMetadata` structures. - Added the method `remove_events_overridden_by_wildcard_update` to the `LogLatest` structure. * plugins/zenoh-plugin-storage-manager/src/replication/mod.rs: make the `Action` and `LogLatestKey` visible from the `replication` module. * plugins/zenoh-plugin-storage-manager/src/replication/service.rs: changed the `spawn_start` function to take an `Arc<StorageService>` instead of a reference. * plugins/zenoh-plugin-storage-manager/src/replication/tests/classification.test.rs: updated unit tests due to changes on the methods tested. * plugins/zenoh-plugin-storage-manager/src/replication/tests/log.test.rs: added new unit tests to ensure that the generation of an Event happens as expected. * plugins/zenoh-plugin-storage-manager/src/storages_mgt/mod.rs: wrap the `StorageService` inside of an `Arc` such that the `Replication` can use it in its tasks. * plugins/zenoh-plugin-storage-manager/src/storages_mgt/service.rs: - Changed the visibility of the `Update` structure to `pub(crate)` and added accessors. - Changed the visibility of the `configuration` and `wildcard_updates` fields of the `StorageService` structure to `pub(crate)` as the `Replication` uses them when dealing with Wildcard Updates. - Changed the signature of the method `register_wildcard_update` to not extract the metadata from the `Sample` -- as the values are not correct when processing an Alignment reply. - Changed the visibility of the methods `register_wildcard_update` and `overriding_wild_update` to `pub(crate)` as they are used by the Replication to deal with Wildcard Updates. - Reworked the logic of the `overriding_wild_update` to handle Wildcard Delete and Wildcard Put separately. In addition, this method no longer queries the database every time an overriding Wildcard Update is found. - Reworked the `register_wildcard_update` method. - Removed the `mark_tombstone` method. Signed-off-by: Julien Loudet <julien.loudet@zettascale.tech>
- Loading branch information