Don’t use writeable TiKV transactions when we don’t need to
This commit is contained in:
parent
58591f82dc
commit
906b969b90
1 changed files with 10 additions and 2 deletions
|
@ -35,7 +35,11 @@ impl Datastore {
|
||||||
match lock {
|
match lock {
|
||||||
false => {
|
false => {
|
||||||
// Set the behaviour when dropping an unfinished transaction
|
// Set the behaviour when dropping an unfinished transaction
|
||||||
let opt = TransactionOptions::new_optimistic().drop_check(CheckLevel::Warn);
|
let mut opt = TransactionOptions::new_optimistic().drop_check(CheckLevel::Warn);
|
||||||
|
// Set this transaction as read only if possible
|
||||||
|
if !write {
|
||||||
|
opt = opt.read_only();
|
||||||
|
}
|
||||||
// Create a new optimistic transaction
|
// Create a new optimistic transaction
|
||||||
match self.db.begin_with_options(opt).await {
|
match self.db.begin_with_options(opt).await {
|
||||||
Ok(tx) => Ok(Transaction {
|
Ok(tx) => Ok(Transaction {
|
||||||
|
@ -48,7 +52,11 @@ impl Datastore {
|
||||||
}
|
}
|
||||||
true => {
|
true => {
|
||||||
// Set the behaviour when dropping an unfinished transaction
|
// Set the behaviour when dropping an unfinished transaction
|
||||||
let opt = TransactionOptions::new_pessimistic().drop_check(CheckLevel::Warn);
|
let mut opt = TransactionOptions::new_pessimistic().drop_check(CheckLevel::Warn);
|
||||||
|
// Set this transaction as read only if possible
|
||||||
|
if !write {
|
||||||
|
opt = opt.read_only();
|
||||||
|
}
|
||||||
// Create a new pessimistic transaction
|
// Create a new pessimistic transaction
|
||||||
match self.db.begin_with_options(opt).await {
|
match self.db.begin_with_options(opt).await {
|
||||||
Ok(tx) => Ok(Transaction {
|
Ok(tx) => Ok(Transaction {
|
||||||
|
|
Loading…
Reference in a new issue