Skip to content

Commit

Permalink
refactor: primary_key_or
Browse files Browse the repository at this point in the history
Signed-off-by: ekexium <[email protected]>
  • Loading branch information
ekexium committed Apr 15, 2021
1 parent 624a53b commit 2e10ab9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
15 changes: 6 additions & 9 deletions src/transaction/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ impl InnerBuffer {
self.entry_map.insert(key, entry);
}

pub fn get_primary_key_or_insert(&mut self, key: &Key) -> &Key {
self.primary_key.get_or_insert(key.clone())
/// Set the primary key if it is not set
pub fn primary_key_or(&mut self, key: &Key) {
self.primary_key.get_or_insert(key.clone());
}
}

Expand All @@ -49,13 +50,9 @@ impl Buffer {
self.inner.lock().await.primary_key.clone()
}

/// Get the primary key of the buffer, if not exists, use `key` as the primary key.
pub async fn get_primary_key_or_insert(&self, key: &Key) -> Key {
self.inner
.lock()
.await
.get_primary_key_or_insert(key)
.clone()
/// Set the primary key if it is not set
pub async fn primary_key_or(&self, key: &Key) {
self.inner.lock().await.primary_key_or(key);
}

/// Get a value from the buffer.
Expand Down
2 changes: 1 addition & 1 deletion src/transaction/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ impl<PdC: PdClient> Transaction<PdC> {
let pairs = plan.execute().await;

// primary key will be set here if needed
self.buffer.get_primary_key_or_insert(&first_key).await;
self.buffer.primary_key_or(&first_key).await;

self.start_auto_heartbeat().await;

Expand Down

0 comments on commit 2e10ab9

Please sign in to comment.