No need to store the actual error on the executor

This commit is contained in:
Tobie Morgan Hitchcock 2022-05-01 10:35:26 +01:00
parent d5fab4fbf0
commit 1697beda9c

View file

@ -15,8 +15,8 @@ use std::sync::Arc;
use trice::Instant; use trice::Instant;
pub struct Executor { pub struct Executor {
err: bool,
kvs: Store, kvs: Store,
err: Option<Error>,
txn: Option<Transaction>, txn: Option<Transaction>,
} }
@ -25,7 +25,7 @@ impl Executor {
Executor { Executor {
kvs, kvs,
txn: None, txn: None,
err: None, err: false,
} }
} }
@ -44,8 +44,8 @@ impl Executor {
self.txn = Some(Arc::new(Mutex::new(v))); self.txn = Some(Arc::new(Mutex::new(v)));
true true
} }
Err(e) => { Err(_) => {
self.err = Some(e); self.err = true;
false false
} }
}, },
@ -56,19 +56,19 @@ impl Executor {
if local { if local {
if let Some(txn) = self.txn.as_ref() { if let Some(txn) = self.txn.as_ref() {
match &self.err { match &self.err {
Some(_) => { true => {
let txn = txn.clone(); let txn = txn.clone();
let mut txn = txn.lock().await; let mut txn = txn.lock().await;
if let Err(e) = txn.cancel().await { if txn.cancel().await.is_err() {
self.err = Some(e); self.err = true;
} }
self.txn = None; self.txn = None;
} }
None => { false => {
let txn = txn.clone(); let txn = txn.clone();
let mut txn = txn.lock().await; let mut txn = txn.lock().await;
if let Err(e) = txn.commit().await { if txn.commit().await.is_err() {
self.err = Some(e); self.err = true;
} }
self.txn = None; self.txn = None;
} }
@ -83,8 +83,8 @@ impl Executor {
Some(txn) => { Some(txn) => {
let txn = txn.clone(); let txn = txn.clone();
let mut txn = txn.lock().await; let mut txn = txn.lock().await;
if let Err(e) = txn.cancel().await { if txn.cancel().await.is_err() {
self.err = Some(e); self.err = true;
} }
self.txn = None; self.txn = None;
} }
@ -105,7 +105,7 @@ impl Executor {
fn buf_commit(&self, v: Response) -> Response { fn buf_commit(&self, v: Response) -> Response {
match &self.err { match &self.err {
Some(_) => Response { true => Response {
sql: v.sql, sql: v.sql,
time: v.time, time: v.time,
status: Status::Err, status: Status::Err,
@ -135,7 +135,7 @@ impl Executor {
debug!("Executing: {}", stm); debug!("Executing: {}", stm);
// Reset errors // Reset errors
if self.txn.is_none() { if self.txn.is_none() {
self.err = None; self.err = false;
} }
// Get the statement start time // Get the statement start time
let now = Instant::now(); let now = Instant::now();
@ -232,9 +232,9 @@ impl Executor {
// Process all other normal statements // Process all other normal statements
_ => match self.err { _ => match self.err {
// This transaction has failed // This transaction has failed
Some(_) => Err(Error::QueryNotExecuted), true => Err(Error::QueryNotExecuted),
// Compute the statement normally // Compute the statement normally
None => { false => {
// Create a transaction // Create a transaction
let loc = self.begin().await; let loc = self.begin().await;
// Specify statement timeout // Specify statement timeout
@ -291,8 +291,8 @@ impl Executor {
detail: Some(format!("{}", e)), detail: Some(format!("{}", e)),
result: None, result: None,
}; };
// Keep the error // Mark the error
self.err = Some(e); self.err = true;
// Return // Return
res res
} }