Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(storage-manager): implement cache for History::Latest #1454

Merged
merged 1 commit into from
Sep 19, 2024

Conversation

J-Loudet
Copy link
Contributor

The changes introduced in #1367 were actually redundant (and incomplete): the method is_latest was checking that a received Sample was more recent than what is currently stored.

This commit removes the redundant checks and implements a correct caching strategy by leveraging both approaches. The changes consist mostly in:

  1. Changing the outer test by continuing early if the Sample is detected as deleted. This allows lowering the overall indentation of the process_sample method by one level.
  2. Modifying the behaviour of the is_latest method to check the cache first and only query the Storage if there is a cache miss.

To help make potential concurrency issues visible, the method is_latest was renamed to guard_cache_if_latest as the lock on the Cache should only be released when the Sample has been processed and the Cache updated.

Additionally, the cache is filled at initialisation.

The read_cost configuration parameter was removed as it was not used and made obsolete with this change.

  • plugins/zenoh-backend-example/src/lib.rs:

  • plugins/zenoh-backend-traits/src/lib.rs:

  • plugins/zenoh-plugin-storage-manager/src/memory_backend/mod.rs: removed the obsolete read_cost parameter.

  • plugins/zenoh-plugin-storage-manager/src/storages_mgt/mod.rs:

    • Populate the Cache at initialisation.
    • Updated the call to StorageService::start to also pass the Cache.
  • plugins/zenoh-plugin-storage-manager/src/storages_mgt/service.rs

    • Updated the call to StorageService::start to also pass the Cache.
    • "Reversed" the logic when checking if a Sample is deleted: if it is continue to the next one. This allows reducing the indentation level.
    • Keep the guard over the cache if a Sample is more recent and only release it once it has been updated (after the Sample has been successfully processed).

Copy link

PR missing one of the required labels: {'internal', 'documentation', 'new feature', 'bug', 'breaking-change', 'dependencies', 'enhancement'}

@J-Loudet J-Loudet added the enhancement Existing things could work better label Sep 19, 2024
The changes introduced in #1367 were actually redundant (and
incomplete): the method `is_latest` was checking that a received Sample
was more recent than what is currently stored.

This commit removes the redundant checks and implements a correct
caching strategy by leveraging both approaches. The changes consist
mostly in:
1. Changing the outer test by continuing early if the Sample is detected
   as deleted. This allows lowering the overall indentation of the
   `process_sample` method by one level.
2. Modifying the behaviour of the `is_latest` method to check the cache
   first and only query the Storage if there is a cache miss.

To help make potential concurrency issues visible, the method
`is_latest` was renamed to `guard_cache_if_latest` as the lock on the
Cache should only be released when the Sample has been processed *and*
the Cache updated.

Additionally, the cache is filled at initialisation.

The `read_cost` configuration parameter was removed as it was not used
and made obsolete with this change.

* plugins/zenoh-backend-example/src/lib.rs:
* plugins/zenoh-backend-traits/src/lib.rs:
* plugins/zenoh-plugin-storage-manager/src/memory_backend/mod.rs:
  removed the obsolete `read_cost` parameter.

* plugins/zenoh-plugin-storage-manager/src/storages_mgt/mod.rs:
  - Populate the Cache at initialisation.
  - Updated the call to `StorageService::start` to also pass the Cache.

* plugins/zenoh-plugin-storage-manager/src/storages_mgt/service.rs
  - Updated the call to `StorageService::start` to also pass the Cache.
  - "Reversed" the logic when checking if a Sample is deleted: if it is
    continue to the next one. This allows reducing the indentation
    level.
  - Keep the guard over the cache if a Sample is more recent and only
    release it once it has been updated (after the Sample has been
    successfully processed).

Signed-off-by: Julien Loudet <[email protected]>
@J-Loudet J-Loudet force-pushed the refactor/storage-manager/cache-latest branch from 2bb5cb3 to 3295c82 Compare September 19, 2024 15:59
@Charles-Schleich
Copy link
Member

@J-Loudet, Cache implementation looks good.

@J-Loudet
Copy link
Contributor Author

@J-Loudet J-Loudet merged commit 1a1bbbb into main Sep 19, 2024
24 checks passed
@J-Loudet J-Loudet deleted the refactor/storage-manager/cache-latest branch September 24, 2024 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Existing things could work better
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants