0
0
mirror of https://github.com/tursodatabase/libsql.git synced 2025-06-15 10:33:03 +00:00

rename State to TxnStatus

This commit is contained in:
ad hoc
2023-10-31 15:27:15 +01:00
parent 3ea8d5eb4c
commit e82aa175a1
3 changed files with 19 additions and 23 deletions
libsql-server/src

@ -5,7 +5,7 @@ use std::sync::Arc;
use metrics::histogram;
use parking_lot::{Mutex, RwLock};
use rusqlite::{DatabaseName, ErrorCode, OpenFlags, StatementStatus};
use rusqlite::{DatabaseName, ErrorCode, OpenFlags, StatementStatus, TransactionState};
use sqld_libsql_bindings::wal_hook::{TransparentMethods, WalMethodsHook};
use tokio::sync::{watch, Notify};
use tokio::time::{Duration, Instant};
@ -294,7 +294,7 @@ struct TxnSlot<T: WalHook> {
/// is stolen.
conn: Arc<Mutex<Connection<T>>>,
/// Time at which the transaction can be stolen
timeout_at: tokio::time::Instant,
created_at: tokio::time::Instant,
/// The transaction lock was stolen
is_stolen: AtomicBool,
}
@ -621,7 +621,7 @@ impl<W: WalHook> Connection<W> {
let blocked = match query.stmt.kind {
StmtKind::Read | StmtKind::TxnBegin | StmtKind::Other => config.block_reads,
StmtKind::Write => config.block_reads || config.block_writes,
StmtKind::TxnEnd => false,
StmtKind::TxnEnd | StmtKind::Release | StmtKind::Savepoint => false,
};
if blocked {
return Err(Error::Blocked(config.block_reason.clone()));

@ -37,7 +37,7 @@ use crate::http::user::types::HttpQuery;
use crate::namespace::{MakeNamespace, NamespaceStore};
use crate::net::Accept;
use crate::query::{self, Query};
use crate::query_analysis::{predict_final_state, State, Statement};
use crate::query_analysis::{predict_final_state, TxnStatus, Statement};
use crate::query_result_builder::QueryResultBuilder;
use crate::rpc::proxy::rpc::proxy_server::{Proxy, ProxyServer};
use crate::rpc::replication_log::rpc::replication_log_server::ReplicationLog;
@ -108,15 +108,15 @@ fn parse_queries(queries: Vec<QueryObject>) -> crate::Result<Vec<Query>> {
));
}
match predict_final_state(State::Init, out.iter().map(|q| &q.stmt)) {
State::Txn => {
match predict_final_state(TxnStatus::Init, out.iter().map(|q| &q.stmt)) {
TxnStatus::Txn => {
return Err(Error::QueryError(
"interactive transaction not allowed in HTTP queries".to_string(),
))
}
State::Init => (),
TxnStatus::Init => (),
// maybe we should err here, but let's sqlite deal with that.
State::Invalid => (),
TxnStatus::Invalid => (),
}
Ok(out)

@ -201,7 +201,7 @@ impl StmtKind {
/// The state of a transaction for a series of statement
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum State {
pub enum TxnStatus {
/// The txn in an opened state
Txn,
/// The txn in a closed state
@ -210,20 +210,20 @@ pub enum State {
Invalid,
}
impl State {
impl TxnStatus {
pub fn step(&mut self, kind: StmtKind) {
*self = match (*self, kind) {
(State::Txn, StmtKind::TxnBegin) | (State::Init, StmtKind::TxnEnd) => State::Invalid,
(State::Txn, StmtKind::TxnEnd) => State::Init,
(TxnStatus::Txn, StmtKind::TxnBegin) | (TxnStatus::Init, StmtKind::TxnEnd) => TxnStatus::Invalid,
(TxnStatus::Txn, StmtKind::TxnEnd) => TxnStatus::Init,
(state, StmtKind::Other | StmtKind::Write | StmtKind::Read) => state,
(State::Invalid, _) => State::Invalid,
(State::Init, StmtKind::TxnBegin) => State::Txn,
_ => State::Invalid,
(TxnStatus::Invalid, _) => TxnStatus::Invalid,
(TxnStatus::Init, StmtKind::TxnBegin) => TxnStatus::Txn,
_ => TxnStatus::Invalid,
};
}
pub fn reset(&mut self) {
*self = State::Init
*self = TxnStatus::Init
}
}
@ -307,11 +307,7 @@ impl Statement {
pub fn is_read_only(&self) -> bool {
matches!(
self.kind,
StmtKind::Read
| StmtKind::TxnEnd
| StmtKind::TxnBegin
| StmtKind::Release
| StmtKind::Savepoint
StmtKind::Read | StmtKind::TxnEnd | StmtKind::TxnBegin
)
}
}
@ -319,9 +315,9 @@ impl Statement {
/// Given a an initial state and an array of queries, attempts to predict what the final state will
/// be
pub fn predict_final_state<'a>(
mut state: State,
mut state: TxnStatus,
stmts: impl Iterator<Item = &'a Statement>,
) -> State {
) -> TxnStatus {
for stmt in stmts {
state.step(stmt.kind);
}