Skip to content

Commit b48d5af

Browse files
committed
fix(storage/p2): Document RocksDB read-your-writes limitation on upsert
1 parent 3e67402 commit b48d5af

File tree

1 file changed

+12
-0
lines changed
  • crates/storage/db/src/implementation/rocksdb

1 file changed

+12
-0
lines changed

crates/storage/db/src/implementation/rocksdb/cursor.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,18 @@ impl<K: TransactionKind, T: Table> DbCursorRO<T> for Cursor<K, T> {
268268
}
269269

270270
impl<T: Table> DbCursorRW<T> for Cursor<RW, T> {
271+
/// Insert or update a key-value pair in the database.
272+
///
273+
/// # Read-Your-Writes Limitation (GRETH-014)
274+
///
275+
/// Writes are buffered in a `WriteBatch` and are **not visible to subsequent
276+
/// read operations** (`seek`, `current`, `get`) on the same cursor within the
277+
/// same transaction. Reads always query the live RocksDB state, which does not
278+
/// include uncommitted batch writes.
279+
///
280+
/// Callers must not rely on read-your-writes semantics within a single cursor.
281+
/// If you write a key and then immediately seek to it, you will observe the
282+
/// **old value** (or "not found") until the batch is committed.
271283
fn upsert(&mut self, key: T::Key, value: &T::Value) -> Result<(), DatabaseError> {
272284
let cf_handle = get_cf_handle::<T>(&self.db)?;
273285
let encoded_key = key.encode();

0 commit comments

Comments
 (0)