Simplify moar
This commit is contained in:
parent
7f3ec69cf6
commit
07490efc28
14 changed files with 261 additions and 1061 deletions
51
src/lib.rs
51
src/lib.rs
|
|
@ -1,60 +1,31 @@
|
|||
pub mod config;
|
||||
pub mod db;
|
||||
pub mod error;
|
||||
pub mod hasher;
|
||||
pub mod health;
|
||||
pub mod server;
|
||||
pub mod rebalance;
|
||||
pub mod rebuild;
|
||||
pub mod volume;
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
/// Build the axum Router with all state wired up. Returns the router and
|
||||
/// a handle to the writer (caller must keep it alive).
|
||||
pub async fn build_app(config: config::Config) -> axum::Router {
|
||||
let db_path = &config.database.path;
|
||||
pub struct Args {
|
||||
pub db_path: String,
|
||||
pub volumes: Vec<String>,
|
||||
pub replicas: usize,
|
||||
}
|
||||
|
||||
if let Some(parent) = std::path::Path::new(db_path).parent() {
|
||||
pub fn build_app(args: &Args) -> axum::Router {
|
||||
if let Some(parent) = std::path::Path::new(&args.db_path).parent() {
|
||||
std::fs::create_dir_all(parent).unwrap_or_else(|e| {
|
||||
eprintln!("Failed to create database directory: {e}");
|
||||
std::process::exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
let writer = db::WriterHandle::new(db_path);
|
||||
|
||||
let num_readers = std::thread::available_parallelism()
|
||||
.map(|n| n.get())
|
||||
.unwrap_or(4);
|
||||
let reads = db::ReadPool::new(db_path, num_readers);
|
||||
|
||||
let volume_urls = config.volume_urls();
|
||||
let ring = Arc::new(RwLock::new(hasher::Ring::new(
|
||||
&volume_urls,
|
||||
config.server.virtual_nodes,
|
||||
)));
|
||||
|
||||
let volume_client = volume::VolumeClient::new();
|
||||
|
||||
let healthy_volumes: health::HealthyVolumes =
|
||||
Arc::new(RwLock::new(HashSet::from_iter(volume_urls.clone())));
|
||||
|
||||
health::spawn_health_checker(
|
||||
volume_client.clone(),
|
||||
volume_urls,
|
||||
healthy_volumes.clone(),
|
||||
);
|
||||
|
||||
let state = server::AppState {
|
||||
writer,
|
||||
reads,
|
||||
ring,
|
||||
volume_client,
|
||||
healthy_volumes,
|
||||
config: Arc::new(config),
|
||||
db: db::Db::new(&args.db_path),
|
||||
volumes: Arc::new(args.volumes.clone()),
|
||||
replicas: args.replicas,
|
||||
http: reqwest::Client::new(),
|
||||
};
|
||||
|
||||
axum::Router::new()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue