Skip to content

Commit

Permalink
[storage] TransactionStore::get_write_sets
Browse files Browse the repository at this point in the history
  • Loading branch information
msmouse authored and aptos-bot committed May 11, 2022
1 parent e75ef65 commit dd64d7d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
39 changes: 39 additions & 0 deletions storage/aptosdb/src/transaction_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,45 @@ impl TransactionStore {
})
}

/// Get write sets in `[begin_version, end_version)` half-open range.
///
/// N.b. an empty `Vec` is returned when `begin_version == end_version`
pub fn get_write_sets(
&self,
begin_version: Version,
end_version: Version,
) -> Result<Vec<WriteSet>> {
if begin_version == end_version {
return Ok(Vec::new());
}
ensure!(
begin_version < end_version,
"begin_version {} >= end_version {}",
begin_version,
end_version
);

let mut iter = self.db.iter::<WriteSetSchema>(Default::default())?;
iter.seek(&begin_version)?;

let mut ret = Vec::with_capacity((end_version - begin_version) as usize);
for current_version in begin_version..end_version {
let (version, write_set) = iter
.next()
.transpose()?
.ok_or_else(|| format_err!("Write set missing for version {}", current_version))?;
ensure!(
version == current_version,
"Write set missing for version {}, got version {}",
current_version,
version,
);
ret.push(write_set);
}

Ok(ret)
}

/// Get the first version that write set starts existent.
pub fn get_first_write_set_version(&self) -> Result<Option<Version>> {
let mut iter = self.db.iter::<WriteSetSchema>(Default::default())?;
Expand Down
1 change: 1 addition & 0 deletions storage/aptosdb/src/transaction_store/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ proptest! {
store.put_write_set(ver as Version, ws, &mut cs).unwrap();
}
store.db.write_schemas(cs.batch).unwrap();
assert_eq!(store.get_write_sets(0, write_sets.len() as Version).unwrap(), write_sets);

assert_eq!(store.get_first_txn_version().unwrap(), Some(0));
assert_eq!(store.get_first_write_set_version().unwrap(), Some(0));
Expand Down

0 comments on commit dd64d7d

Please sign in to comment.