add storage module for retaining messages in kv store #9
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.
As a first step towards implementing message durability, this PR adds a module,
storage
, that allows saving a single message per topic. It contains aStorage
trait and a KV Store based implementation.The module is not used anywhere yet, but the plan is to use it to:
KV item metadata is used to keep a version and an optional expiration time. The version consists of a generation number (randomly generated) and a sequence number (strictly increasing); these values will be needed to implement ordered & reliable message delivery. The expiration time maintained in the metadata allows us to treat the item's content as expired even if the item itself persists. This is mainly useful for when a topic's message expires and is later replaced by a new message, we can reuse the generation/sequence.
Writing to KV Store is limited to 1 write/second per key. This module attempts to work around this slightly, by retrying a few times if a write fails. This way, serial writes to the same topic from a single writer should not encounter write-rate errors and instead may experience a backpressure effect. However, multiple writes in parallel to the same topic could result in errors due to the write-rate.