Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/bin/roodb_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async fn main() {
let storage: Arc<dyn StorageEngine> = match LsmEngine::open(io_factory, storage_config).await {
Ok(engine) => Arc::new(engine),
Err(e) => {
eprintln!("ERROR: Failed to open storage: {}", e);
eprintln!("ERROR: Failed to open storage: {e}");
std::process::exit(3);
}
};
Expand All @@ -58,7 +58,7 @@ async fn main() {
// Continue with initialization
}
Err(e) => {
eprintln!("ERROR: Failed to check initialization status: {}", e);
eprintln!("ERROR: Failed to check initialization status: {e}");
let _ = storage.close().await;
std::process::exit(3);
}
Expand All @@ -71,12 +71,12 @@ async fn main() {
let password = match config.determine_password() {
Ok(p) => p,
Err(InitError::Config(msg)) => {
eprintln!("ERROR: {}", msg);
eprintln!("ERROR: {msg}");
let _ = storage.close().await;
std::process::exit(2);
}
Err(e) => {
eprintln!("ERROR: {}", e);
eprintln!("ERROR: {e}");
let _ = storage.close().await;
std::process::exit(2);
}
Expand All @@ -89,15 +89,15 @@ async fn main() {
eprintln!("Root user 'root'@'%' created with ALL PRIVILEGES");
}
Err(e) => {
eprintln!("ERROR: Failed to initialize database: {}", e);
eprintln!("ERROR: Failed to initialize database: {e}");
let _ = storage.close().await;
std::process::exit(3);
}
}

// Close storage
if let Err(e) = storage.close().await {
eprintln!("WARNING: Failed to close storage cleanly: {}", e);
eprintln!("WARNING: Failed to close storage cleanly: {e}");
}

std::process::exit(0);
Expand Down
19 changes: 11 additions & 8 deletions src/catalog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,15 @@ pub enum CatalogError {
impl std::fmt::Display for CatalogError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
CatalogError::TableExists(name) => write!(f, "Table '{}' already exists", name),
CatalogError::TableNotFound(name) => write!(f, "Table '{}' not found", name),
CatalogError::IndexExists(name) => write!(f, "Index '{}' already exists", name),
CatalogError::IndexNotFound(name) => write!(f, "Index '{}' not found", name),
CatalogError::TableExists(name) => write!(f, "Table '{name}' already exists"),
CatalogError::TableNotFound(name) => write!(f, "Table '{name}' not found"),
CatalogError::IndexExists(name) => write!(f, "Index '{name}' already exists"),
CatalogError::IndexNotFound(name) => write!(f, "Index '{name}' not found"),
CatalogError::ColumnNotFound(table, col) => {
write!(f, "Column '{}' not found in table '{}'", col, table)
write!(f, "Column '{col}' not found in table '{table}'")
}
CatalogError::InvalidName(msg) => write!(f, "Invalid name: {}", msg),
CatalogError::InvalidConstraint(msg) => write!(f, "Invalid constraint: {}", msg),
CatalogError::InvalidName(msg) => write!(f, "Invalid name: {msg}"),
CatalogError::InvalidConstraint(msg) => write!(f, "Invalid constraint: {msg}"),
}
}
}
Expand Down Expand Up @@ -384,7 +384,10 @@ impl Catalog {

/// List all table names
pub fn list_tables(&self) -> Vec<&str> {
self.tables.keys().map(|s| s.as_str()).collect()
self.tables
.keys()
.map(std::string::String::as_str)
.collect()
}

/// Get all table names as a HashSet (for efficient duplicate checking)
Expand Down
30 changes: 20 additions & 10 deletions src/catalog/system_tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ pub fn table_def_to_columns_rows(def: &TableDef) -> Vec<Row> {
Datum::Bool(col.nullable),
col.default
.as_ref()
.map(|d| Datum::String(d.clone()))
.unwrap_or(Datum::Null),
.map_or(Datum::Null, |d| Datum::String(d.clone())),
Datum::Bool(col.auto_increment),
])
})
Expand All @@ -188,7 +187,7 @@ pub fn data_type_to_string(dt: &DataType) -> String {
DataType::BigInt => "BIGINT".to_string(),
DataType::Float => "FLOAT".to_string(),
DataType::Double => "DOUBLE".to_string(),
DataType::Varchar(n) => format!("VARCHAR({})", n),
DataType::Varchar(n) => format!("VARCHAR({n})"),
DataType::Text => "TEXT".to_string(),
DataType::Blob => "BLOB".to_string(),
DataType::Timestamp => "TIMESTAMP".to_string(),
Expand Down Expand Up @@ -257,10 +256,10 @@ pub fn table_def_to_constraints_rows(def: &TableDef) -> Vec<Row> {
Datum::String(def.name.clone()),
Datum::Int(ordinal as i64),
Datum::String(constraint_type.to_string()),
columns.map(Datum::String).unwrap_or(Datum::Null),
ref_table.map(Datum::String).unwrap_or(Datum::Null),
ref_columns.map(Datum::String).unwrap_or(Datum::Null),
check_expr.map(Datum::String).unwrap_or(Datum::Null),
columns.map_or(Datum::Null, Datum::String),
ref_table.map_or(Datum::Null, Datum::String),
ref_columns.map_or(Datum::Null, Datum::String),
check_expr.map_or(Datum::Null, Datum::String),
])
})
.collect()
Expand All @@ -287,7 +286,11 @@ pub fn rows_to_constraints(constraint_rows: &[Row]) -> Vec<Constraint> {
};

let columns = match &row.values()[3] {
Datum::String(s) => Some(s.split(',').map(|s| s.to_string()).collect::<Vec<_>>()),
Datum::String(s) => Some(
s.split(',')
.map(std::string::ToString::to_string)
.collect::<Vec<_>>(),
),
Datum::Null => None,
_ => return None,
};
Expand All @@ -299,7 +302,11 @@ pub fn rows_to_constraints(constraint_rows: &[Row]) -> Vec<Constraint> {
};

let ref_columns = match &row.values()[5] {
Datum::String(s) => Some(s.split(',').map(|s| s.to_string()).collect::<Vec<_>>()),
Datum::String(s) => Some(
s.split(',')
.map(std::string::ToString::to_string)
.collect::<Vec<_>>(),
),
Datum::Null => None,
_ => return None,
};
Expand Down Expand Up @@ -411,7 +418,10 @@ pub fn row_to_index_def(row: &Row) -> Option<IndexDef> {
_ => return None,
};

let columns: Vec<String> = columns_str.split(',').map(|s| s.to_string()).collect();
let columns: Vec<String> = columns_str
.split(',')
.map(std::string::ToString::to_string)
.collect();

let mut def = IndexDef::new(index_name, table_name, columns);
if is_unique {
Expand Down
82 changes: 34 additions & 48 deletions src/executor/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl Executor for CreateUser {
.storage
.scan(Some(&prefix), Some(&end))
.await
.map_err(|e| ExecutorError::Internal(format!("Storage error: {}", e)))?;
.map_err(|e| ExecutorError::Internal(format!("Storage error: {e}")))?;

for (_key, value) in rows {
let row = super::encoding::decode_row(&value)?;
Expand Down Expand Up @@ -155,7 +155,7 @@ impl Executor for CreateUser {
self.raft_node
.propose_changes(changeset)
.await
.map_err(|e| ExecutorError::Internal(format!("Raft error: {}", e)))?;
.map_err(|e| ExecutorError::Internal(format!("Raft error: {e}")))?;

// Store change for take_changes
self.changes
Expand Down Expand Up @@ -234,7 +234,7 @@ impl Executor for DropUser {
.storage
.scan(Some(&prefix), Some(&end))
.await
.map_err(|e| ExecutorError::Internal(format!("Storage error: {}", e)))?;
.map_err(|e| ExecutorError::Internal(format!("Storage error: {e}")))?;

let mut found = false;
let mut changeset = ChangeSet::new(0);
Expand Down Expand Up @@ -272,7 +272,7 @@ impl Executor for DropUser {
.storage
.scan(Some(&grant_prefix), Some(&grant_end))
.await
.map_err(|e| ExecutorError::Internal(format!("Storage error: {}", e)))?;
.map_err(|e| ExecutorError::Internal(format!("Storage error: {e}")))?;

for (key, value) in grant_rows {
let row = super::encoding::decode_row(&value)?;
Expand All @@ -290,11 +290,11 @@ impl Executor for DropUser {
self.raft_node
.propose_changes(changeset)
.await
.map_err(|e| ExecutorError::Internal(format!("Raft error: {}", e)))?;
.map_err(|e| ExecutorError::Internal(format!("Raft error: {e}")))?;
}

self.done = true;
Ok(Some(Row::new(vec![Datum::Int(if found { 1 } else { 0 })])))
Ok(Some(Row::new(vec![Datum::Int(i64::from(found))])))
}

async fn close(&mut self) -> ExecutorResult<()> {
Expand Down Expand Up @@ -366,7 +366,7 @@ impl Executor for AlterUser {
.storage
.scan(Some(&prefix), Some(&end))
.await
.map_err(|e| ExecutorError::Internal(format!("Storage error: {}", e)))?;
.map_err(|e| ExecutorError::Internal(format!("Storage error: {e}")))?;

let mut found_key = None;
let mut found_row = None;
Expand All @@ -384,15 +384,12 @@ impl Executor for AlterUser {
}
}

let (key, old_row) = match (found_key, found_row) {
(Some(k), Some(r)) => (k, r),
_ => {
return Err(ExecutorError::Internal(format!(
"User '{}@{}' does not exist",
self.username,
self.host.as_str()
)));
}
let (Some(key), Some(old_row)) = (found_key, found_row) else {
return Err(ExecutorError::Internal(format!(
"User '{}@{}' does not exist",
self.username,
self.host.as_str()
)));
};

// Build updated row with new password hash
Expand Down Expand Up @@ -421,7 +418,7 @@ impl Executor for AlterUser {
self.raft_node
.propose_changes(changeset)
.await
.map_err(|e| ExecutorError::Internal(format!("Raft error: {}", e)))?;
.map_err(|e| ExecutorError::Internal(format!("Raft error: {e}")))?;

self.done = true;
Ok(Some(Row::new(vec![Datum::Int(1)])))
Expand Down Expand Up @@ -496,7 +493,7 @@ impl Executor for SetPassword {
.storage
.scan(Some(&prefix), Some(&end))
.await
.map_err(|e| ExecutorError::Internal(format!("Storage error: {}", e)))?;
.map_err(|e| ExecutorError::Internal(format!("Storage error: {e}")))?;

let mut found_key = None;
let mut found_row = None;
Expand All @@ -514,15 +511,12 @@ impl Executor for SetPassword {
}
}

let (key, old_row) = match (found_key, found_row) {
(Some(k), Some(r)) => (k, r),
_ => {
return Err(ExecutorError::Internal(format!(
"User '{}@{}' does not exist",
self.username,
self.host.as_str()
)));
}
let (Some(key), Some(old_row)) = (found_key, found_row) else {
return Err(ExecutorError::Internal(format!(
"User '{}@{}' does not exist",
self.username,
self.host.as_str()
)));
};

// Build updated row with new password hash
Expand All @@ -548,7 +542,7 @@ impl Executor for SetPassword {
self.raft_node
.propose_changes(changeset)
.await
.map_err(|e| ExecutorError::Internal(format!("Raft error: {}", e)))?;
.map_err(|e| ExecutorError::Internal(format!("Raft error: {e}")))?;

self.done = true;
Ok(Some(Row::new(vec![Datum::Int(1)])))
Expand Down Expand Up @@ -675,7 +669,7 @@ impl Executor for Grant {
self.raft_node
.propose_changes(changeset)
.await
.map_err(|e| ExecutorError::Internal(format!("Raft error: {}", e)))?;
.map_err(|e| ExecutorError::Internal(format!("Raft error: {e}")))?;

self.done = true;
Ok(Some(Row::new(vec![Datum::Int(count)])))
Expand Down Expand Up @@ -741,11 +735,11 @@ impl Revoke {
match (&self.object, object_type.as_deref()) {
(PrivilegeObject::Global, Some("GLOBAL")) => true,
(PrivilegeObject::Database(db), Some("DATABASE")) => {
db_name.as_ref().map(|d| d == db).unwrap_or(false)
db_name.as_ref().is_some_and(|d| d == db)
}
(PrivilegeObject::Table { database, table }, Some("TABLE")) => {
db_name.as_ref().map(|d| d == database).unwrap_or(false)
&& table_name.as_ref().map(|t| t == table).unwrap_or(false)
db_name.as_ref().is_some_and(|d| d == database)
&& table_name.as_ref().is_some_and(|t| t == table)
}
_ => false,
}
Expand Down Expand Up @@ -786,7 +780,7 @@ impl Executor for Revoke {
.storage
.scan(Some(&prefix), Some(&end))
.await
.map_err(|e| ExecutorError::Internal(format!("Storage error: {}", e)))?;
.map_err(|e| ExecutorError::Internal(format!("Storage error: {e}")))?;

let mut changeset = ChangeSet::new(0);
let mut count = 0;
Expand All @@ -799,19 +793,14 @@ impl Executor for Revoke {
let grantee_host = get_string(row.get_opt(1));
let privilege = get_string(row.get_opt(3));

if grantee
.as_ref()
.map(|g| g == &self.grantee)
.unwrap_or(false)
if grantee.as_ref().is_some_and(|g| g == &self.grantee)
&& grantee_host
.as_deref()
.map(|h| h == self.grantee_host.as_str())
.unwrap_or(false)
.is_some_and(|h| h == self.grantee_host.as_str())
&& self.matches_object(&row)
&& privilege
.as_ref()
.map(|p| privs_to_revoke.contains(p))
.unwrap_or(false)
.is_some_and(|p| privs_to_revoke.contains(p))
{
changeset.push(RowChange::delete(SYSTEM_GRANTS, key.clone()));
self.changes.push(RowChange::delete(SYSTEM_GRANTS, key));
Expand All @@ -823,7 +812,7 @@ impl Executor for Revoke {
self.raft_node
.propose_changes(changeset)
.await
.map_err(|e| ExecutorError::Internal(format!("Raft error: {}", e)))?;
.map_err(|e| ExecutorError::Internal(format!("Raft error: {e}")))?;
}

self.done = true;
Expand Down Expand Up @@ -888,7 +877,7 @@ impl Executor for ShowGrants {
.storage
.scan(Some(&prefix), Some(&end))
.await
.map_err(|e| ExecutorError::Internal(format!("Storage error: {}", e)))?;
.map_err(|e| ExecutorError::Internal(format!("Storage error: {e}")))?;

for (_key, value) in rows {
let row = super::encoding::decode_row(&value)?;
Expand All @@ -898,11 +887,8 @@ impl Executor for ShowGrants {

// Check if this grant is for the requested user
if let Some((ref username, ref host)) = self.for_user {
if grantee.as_ref().map(|g| g != username).unwrap_or(true)
|| grantee_host
.as_deref()
.map(|h| h != host.as_str())
.unwrap_or(true)
if (grantee.as_ref() != Some(username))
|| grantee_host.as_deref().is_none_or(|h| h != host.as_str())
{
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/executor/datum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Datum {
match self {
Datum::Int(i) => Some(*i),
Datum::Float(f) => Some(*f as i64),
Datum::Bool(b) => Some(if *b { 1 } else { 0 }),
Datum::Bool(b) => Some(i64::from(*b)),
Datum::Null => None,
_ => None,
}
Expand Down Expand Up @@ -125,7 +125,7 @@ impl Datum {
Literal::String(s) => Datum::String(s.clone()),
Literal::Blob(b) => Datum::Bytes(b.clone()),
Literal::Placeholder(i) => {
panic!("Unsubstituted placeholder ?{} in plan execution", i)
panic!("Unsubstituted placeholder ?{i} in plan execution")
}
}
}
Expand Down
Loading