Skip to content

Commit f246159

Browse files
authored
Merge pull request #3951 from TheBlueMatt/2025-07-write-async-reqs
Clarify persistence order requirements for async persistence
2 parents 479c5c7 + a354995 commit f246159

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

lightning/src/util/persist.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,21 @@ pub trait KVStore {
215215
fn read(
216216
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
217217
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, io::Error>> + 'static + Send>>;
218-
/// Persists the given data under the given `key`. Note that the order of multiple writes calls needs to be retained
219-
/// when persisting asynchronously. One possible way to accomplish this is by assigning a version number to each
220-
/// write before returning the future, and then during asynchronous execution, ensuring that the writes are executed in
221-
/// the correct order.
218+
/// Persists the given data under the given `key`.
219+
///
220+
/// The order of multiple writes to the same key needs to be retained while persisting
221+
/// asynchronously. In other words, if two writes to the same key occur, the state (as seen by
222+
/// [`Self::read`]) must either see the first write then the second, or only ever the second,
223+
/// no matter when the futures complete (and must always contain the second write once the
224+
/// second future completes). The state should never contain the first write after the second
225+
/// write's future completes, nor should it contain the second write, then contain the first
226+
/// write at any point thereafter (even if the second write's future hasn't yet completed).
227+
///
228+
/// One way to ensure this requirement is met is by assigning a version number to each write
229+
/// before returning the future, and then during asynchronous execution, ensuring that the
230+
/// writes are executed in the correct order.
231+
///
232+
/// Note that no ordering requirements exist for writes to different keys.
222233
///
223234
/// Will create the given `primary_namespace` and `secondary_namespace` if not already present in the store.
224235
fn write(

0 commit comments

Comments
 (0)