Skip to content

Commit

Permalink
Merge pull request #1146 from pantonov/tt-genid
Browse files Browse the repository at this point in the history
Added TransactionalTree::generate_id()
  • Loading branch information
spacejam authored Aug 22, 2020
2 parents 24ed477 + 131cb04 commit c8578a0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ impl Context {
/// a blocking flush to fsync the latest counter, ensuring
/// that we will never give out the same counter twice.
pub fn generate_id(&self) -> Result<u64> {
self.pagecache.generate_id()
let _cc = concurrency_control::read();
self.pagecache.generate_id_inner()
}

pub(crate) fn pin_log(&self, guard: &Guard) -> Result<RecoveryGuard<'_>> {
Expand Down
3 changes: 1 addition & 2 deletions src/pagecache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1793,8 +1793,7 @@ impl PageCache {
/// previous persisted counter wasn't synced to disk yet, we will do
/// a blocking flush to fsync the latest counter, ensuring
/// that we will never give out the same counter twice.
pub(crate) fn generate_id(&self) -> Result<u64> {
let _cc = concurrency_control::read();
pub(crate) fn generate_id_inner(&self) -> Result<u64> {
let ret = self.idgen.fetch_add(1, Release);

trace!("generating ID {}", ret);
Expand Down
14 changes: 14 additions & 0 deletions src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,20 @@ impl TransactionalTree {
*self.flush_on_commit.borrow_mut() = true;
}

/// Generate a monotonic ID. Not guaranteed to be
/// contiguous or idempotent, can produce different values in the
/// same transaction in case of conflicts.
/// Written to disk every `idgen_persist_interval`
/// operations, followed by a blocking flush. During recovery, we
/// take the last recovered generated ID and add 2x
/// the `idgen_persist_interval` to it. While persisting, if the
/// previous persisted counter wasn't synced to disk yet, we will do
/// a blocking flush to fsync the latest counter, ensuring
/// that we will never give out the same counter twice.
pub fn generate_id(&self) -> Result<u64> {
self.tree.context.pagecache.generate_id_inner()
}

fn unstage(&self) {
unimplemented!()
}
Expand Down

0 comments on commit c8578a0

Please sign in to comment.