From 906b969b904071db016112fb6de097b6492e9532 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Tue, 30 Aug 2022 22:35:29 +0100 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20use=20writeable=20TiKV=20transa?= =?UTF-8?q?ctions=20when=20we=20don=E2=80=99t=20need=20to?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/src/kvs/tikv/mod.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/src/kvs/tikv/mod.rs b/lib/src/kvs/tikv/mod.rs index 7ea9a6da..5fed5770 100644 --- a/lib/src/kvs/tikv/mod.rs +++ b/lib/src/kvs/tikv/mod.rs @@ -35,7 +35,11 @@ impl Datastore { match lock { false => { // 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 match self.db.begin_with_options(opt).await { Ok(tx) => Ok(Transaction { @@ -48,7 +52,11 @@ impl Datastore { } true => { // 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 match self.db.begin_with_options(opt).await { Ok(tx) => Ok(Transaction {