-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(server): Make DbSlice consumer an interface #7253
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,6 +84,24 @@ class DbSlice { | |
| void operator=(const DbSlice&) = delete; | ||
|
|
||
| public: | ||
| // Consumer of bucket change events than can be registered inside the slice. | ||
| // It also includes additional methods for interfacing with snapshots and migrations. | ||
| struct ChangeConsumerInterface { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. src/server/db_slice.h:89: Severity: low 🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage. |
||
| // Called before a specific bucket (or set of buckets) will be mutated | ||
| virtual void OnChange(DbIndex, const ChangeReq&) = 0; | ||
|
|
||
| // Should return true if any bucket is mid-serialization | ||
| virtual bool IsAnyBucketBlocked() const { | ||
| return false; | ||
| } | ||
|
|
||
| // Should wait for IsAnyBucketBlocked to return false | ||
| virtual void UnblockAllBuckets() const { | ||
| } | ||
|
|
||
| uint64_t snapshot_version_ = 0; | ||
| }; | ||
|
|
||
| // Auto-laundering iterator wrapper. Laundering means re-finding keys if they moved between | ||
| // buckets. | ||
| template <typename T> class IteratorT { | ||
|
|
@@ -393,7 +411,8 @@ class DbSlice { | |
| //! Registers the callback to be called for each change. | ||
| //! Returns the registration id which is also the unique version of the dbslice | ||
| //! at a time of the call. | ||
| uint64_t RegisterOnChange(ChangeCallback cb); | ||
| void RegisterOnChange(ChangeConsumerInterface* consumer); | ||
| void UnregisterOnChange(ChangeConsumerInterface* consumer); | ||
|
|
||
| bool HasRegisteredCallbacks() const { | ||
| return !change_cb_.empty(); | ||
|
|
@@ -402,9 +421,6 @@ class DbSlice { | |
| // Call registered callbacks with version less than upper_bound. | ||
| void FlushChangeToEarlierCallbacks(DbIndex db_ind, Iterator it, uint64_t upper_bound); | ||
|
|
||
| //! Unregisters the callback. | ||
| void UnregisterOnChange(uint64_t id); | ||
|
|
||
| struct DeleteExpiredStats { | ||
| uint32_t deleted = 0; // number of deleted items due to expiry. | ||
| uint32_t deleted_bytes = 0; // total bytes of deleted items. | ||
|
|
@@ -483,13 +499,12 @@ class DbSlice { | |
| // if it's not empty and not EX. | ||
| void SetNotifyKeyspaceEvents(std::string_view notify_keyspace_events); | ||
|
|
||
| bool WillBlockOnJournalWrite() const { | ||
| return serialization_latch_.IsBlocked(); | ||
| } | ||
| // Returns true if any registered snapshot is blocked on bucket serialiazion (big value, delayed) | ||
| // and thus might reject the journal change | ||
| bool WillBlockOnJournalWrite() const; | ||
|
|
||
| LocalLatch* GetLatch() { | ||
| return &serialization_latch_; | ||
| } | ||
| // Block and wait for WillBlockOnJournalWrite to become false | ||
| void WaitForUnblockedJournalWrites() const; | ||
|
|
||
| void StartSampleTopK(DbIndex db_ind, uint32_t min_freq); | ||
|
|
||
|
|
@@ -521,7 +536,8 @@ class DbSlice { | |
| PrimeValue obj, uint64_t expire_at_ms, | ||
| bool force_update); | ||
|
|
||
| void FlushSlotsFb(const cluster::SlotSet& slot_ids, uint64_t next_version, uint64_t cb_id); | ||
| void FlushSlotsFb(const cluster::SlotSet& slot_ids, uint64_t next_version, | ||
| ChangeConsumerInterface* consumer); | ||
| util::fb2::Fiber FlushDbIndexes(const std::vector<DbIndex>& indexes); | ||
|
|
||
| // Invalidate all watched keys in database. Used on FLUSH. | ||
|
|
@@ -565,11 +581,6 @@ class DbSlice { | |
|
|
||
| void CallChangeCallbacks(DbIndex id, const ChangeReq& cr) const; | ||
|
|
||
| // We need this because registered callbacks might yield and when they do so we want | ||
| // to avoid Heartbeat or Flushing the db. | ||
| // This latch protects us against this case. | ||
| mutable LocalLatch serialization_latch_; | ||
|
|
||
| ShardId shard_id_; | ||
| uint8_t cache_mode_ : 1; | ||
|
|
||
|
|
@@ -608,7 +619,8 @@ class DbSlice { | |
| mutable absl::flat_hash_set<uint64_t, FpHasher> uniq_fps_; | ||
|
|
||
| // ordered from the smallest to largest version. | ||
| std::list<std::pair<uint64_t, ChangeCallback>> change_cb_; | ||
| std::list<ChangeConsumerInterface*> change_cb_; | ||
| mutable LocalLatch change_cb_latch_; | ||
|
|
||
| // Used in temporary computations in Find item and CbFinish | ||
| // This set is used to hold fingerprints of key accessed during the run of | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.