@@ -118,21 +118,75 @@ pub const OUTPUT_SWEEPER_PERSISTENCE_KEY: &str = "output_sweeper";
118118/// updates applied to be current) with another implementation.
119119pub const MONITOR_UPDATING_PERSISTER_PREPEND_SENTINEL : & [ u8 ] = & [ 0xFF ; 2 ] ;
120120
121- /// A synchronous version of the [`KVStore`] trait.
121+ /// Provides an interface that allows storage and retrieval of persisted values that are associated
122+ /// with given keys.
123+ ///
124+ /// In order to avoid collisions the key space is segmented based on the given `primary_namespace`s
125+ /// and `secondary_namespace`s. Implementations of this trait are free to handle them in different
126+ /// ways, as long as per-namespace key uniqueness is asserted.
127+ ///
128+ /// Keys and namespaces are required to be valid ASCII strings in the range of
129+ /// [`KVSTORE_NAMESPACE_KEY_ALPHABET`] and no longer than [`KVSTORE_NAMESPACE_KEY_MAX_LEN`]. Empty
130+ /// primary namespaces and secondary namespaces (`""`) are assumed to be a valid, however, if
131+ /// `primary_namespace` is empty, `secondary_namespace` is required to be empty, too. This means
132+ /// that concerns should always be separated by primary namespace first, before secondary
133+ /// namespaces are used. While the number of primary namespaces will be relatively small and is
134+ /// determined at compile time, there may be many secondary namespaces per primary namespace. Note
135+ /// that per-namespace uniqueness needs to also hold for keys *and* namespaces in any given
136+ /// namespace, i.e., conflicts between keys and equally named
137+ /// primary namespaces/secondary namespaces must be avoided.
138+ ///
139+ /// **Note:** Users migrating custom persistence backends from the pre-v0.0.117 `KVStorePersister`
140+ /// interface can use a concatenation of `[{primary_namespace}/[{secondary_namespace}/]]{key}` to
141+ /// recover a `key` compatible with the data model previously assumed by `KVStorePersister::persist`.
142+ ///
143+ /// For an asynchronous version of this trait, see [`KVStore`].
144+ // Note that updates to documentation on this trait should be copied to the asynchronous version.
122145pub trait KVStoreSync {
123- /// A synchronous version of the [`KVStore::read`] method.
146+ /// Returns the data stored for the given `primary_namespace`, `secondary_namespace`, and
147+ /// `key`.
148+ ///
149+ /// Returns an [`ErrorKind::NotFound`] if the given `key` could not be found in the given
150+ /// `primary_namespace` and `secondary_namespace`.
151+ ///
152+ /// [`ErrorKind::NotFound`]: io::ErrorKind::NotFound
124153 fn read (
125154 & self , primary_namespace : & str , secondary_namespace : & str , key : & str ,
126155 ) -> Result < Vec < u8 > , io:: Error > ;
127- /// A synchronous version of the [`KVStore::write`] method.
156+ /// Persists the given data under the given `key`.
157+ ///
158+ /// Will create the given `primary_namespace` and `secondary_namespace` if not already present in the store.
128159 fn write (
129160 & self , primary_namespace : & str , secondary_namespace : & str , key : & str , buf : Vec < u8 > ,
130161 ) -> Result < ( ) , io:: Error > ;
131- /// A synchronous version of the [`KVStore::remove`] method.
162+ /// Removes any data that had previously been persisted under the given `key`.
163+ ///
164+ /// If the `lazy` flag is set to `true`, the backend implementation might choose to lazily
165+ /// remove the given `key` at some point in time after the method returns, e.g., as part of an
166+ /// eventual batch deletion of multiple keys. As a consequence, subsequent calls to
167+ /// [`KVStoreSync::list`] might include the removed key until the changes are actually persisted.
168+ ///
169+ /// Note that while setting the `lazy` flag reduces the I/O burden of multiple subsequent
170+ /// `remove` calls, it also influences the atomicity guarantees as lazy `remove`s could
171+ /// potentially get lost on crash after the method returns. Therefore, this flag should only be
172+ /// set for `remove` operations that can be safely replayed at a later time.
173+ ///
174+ /// All removal operations must complete in a consistent total order with [`Self::write`]s
175+ /// to the same key. Whether a removal operation is `lazy` or not, [`Self::write`] operations
176+ /// to the same key which occur before a removal completes must cancel/overwrite the pending
177+ /// removal.
178+ ///
179+ /// Returns successfully if no data will be stored for the given `primary_namespace`,
180+ /// `secondary_namespace`, and `key`, independently of whether it was present before its
181+ /// invokation or not.
132182 fn remove (
133183 & self , primary_namespace : & str , secondary_namespace : & str , key : & str , lazy : bool ,
134184 ) -> Result < ( ) , io:: Error > ;
135- /// A synchronous version of the [`KVStore::list`] method.
185+ /// Returns a list of keys that are stored under the given `secondary_namespace` in
186+ /// `primary_namespace`.
187+ ///
188+ /// Returns the keys in arbitrary order, so users requiring a particular order need to sort the
189+ /// returned keys. Returns an empty list if `primary_namespace` or `secondary_namespace` is unknown.
136190 fn list (
137191 & self , primary_namespace : & str , secondary_namespace : & str ,
138192 ) -> Result < Vec < String > , io:: Error > ;
@@ -215,7 +269,10 @@ where
215269/// interface can use a concatenation of `[{primary_namespace}/[{secondary_namespace}/]]{key}` to
216270/// recover a `key` compatible with the data model previously assumed by `KVStorePersister::persist`.
217271///
272+ /// For a synchronous version of this trait, see [`KVStoreSync`].
273+ ///
218274/// This is not exported to bindings users as async is only supported in Rust.
275+ // Note that updates to documentation on this trait should be copied to the synchronous version.
219276pub trait KVStore {
220277 /// Returns the data stored for the given `primary_namespace`, `secondary_namespace`, and
221278 /// `key`.
0 commit comments