-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TransactionScheduler: Id Generators (#33207)
- Loading branch information
Showing
3 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
core/src/banking_stage/transaction_scheduler/batch_id_generator.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
core/src/banking_stage/transaction_scheduler/transaction_id_generator.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |