Skip to content

Commit

Permalink
TransactionScheduler: Id Generators (#33207)
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge authored Sep 18, 2023
1 parent e860019 commit 86dd18b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
14 changes: 14 additions & 0 deletions core/src/banking_stage/transaction_scheduler/batch_id_generator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use crate::banking_stage::scheduler_messages::TransactionBatchId;

#[derive(Default)]
pub struct BatchIdGenerator {
next_id: u64,
}

impl BatchIdGenerator {
pub fn next(&mut self) -> TransactionBatchId {
let id = self.next_id;
self.next_id = self.next_id.wrapping_sub(1);
TransactionBatchId::new(id)
}
}
6 changes: 6 additions & 0 deletions core/src/banking_stage/transaction_scheduler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ mod transaction_priority_id;
mod transaction_state;
#[allow(dead_code)]
mod transaction_state_container;

#[allow(dead_code)]
mod transaction_id_generator;

#[allow(dead_code)]
mod batch_id_generator;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use crate::banking_stage::scheduler_messages::TransactionId;

/// Simple sequential ID generator for `TransactionId`s.
/// These IDs uniquely identify transactions during the scheduling process.
#[derive(Default)]
pub struct TransactionIdGenerator {
next_id: u64,
}

impl TransactionIdGenerator {
pub fn next(&mut self) -> TransactionId {
let id = self.next_id;
self.next_id = self.next_id.wrapping_add(1);
TransactionId::new(id)
}
}

0 comments on commit 86dd18b

Please sign in to comment.