Skip to content

Commit

Permalink
Add timestamp support u64::MAX
Browse files Browse the repository at this point in the history
Signed-off-by: yongman <[email protected]>
  • Loading branch information
yongman committed Aug 22, 2022
1 parent 027a7df commit 54b41f1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,24 @@ pub trait TimestampExt: Sized {

impl TimestampExt for Timestamp {
fn version(&self) -> u64 {
if self.physical == i64::MAX && self.logical == i64::MAX {
return u64::MAX;
}

((self.physical << PHYSICAL_SHIFT_BITS) + self.logical)
.try_into()
.expect("Overflow converting timestamp to version")
}

fn from_version(version: u64) -> Self {
if version == u64::MAX {
return Self {
physical: i64::MAX,
logical: i64::MAX,
suffix_bits: 0,
};
}

let version = version as i64;
Self {
physical: version >> PHYSICAL_SHIFT_BITS,
Expand All @@ -41,7 +53,7 @@ impl TimestampExt for Timestamp {
}

fn try_from_version(version: u64) -> Option<Self> {
if version == 0 {
if version == 0 || (version >= i64::MAX as u64 && version != u64::MAX) {
None
} else {
Some(Self::from_version(version))
Expand Down
6 changes: 5 additions & 1 deletion src/transaction/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,11 @@ impl Client {
Ok(res)
}

fn new_transaction(&self, timestamp: Timestamp, options: TransactionOptions) -> Transaction {
pub fn new_transaction(
&self,
timestamp: Timestamp,
options: TransactionOptions,
) -> Transaction {
let logger = self.logger.new(o!("child" => 1));
Transaction::new(timestamp, self.pd.clone(), options, logger)
}
Expand Down

0 comments on commit 54b41f1

Please sign in to comment.