sigh guess i'm doing a connection pool

This commit is contained in:
Michael Zhang 2021-11-01 21:31:15 -05:00
parent 2f65f2173f
commit 449b71d41b
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
8 changed files with 94 additions and 11 deletions

48
Cargo.lock generated
View file

@ -228,6 +228,20 @@ version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccaeedb56da03b09f598226e25e80088cb4cd25f316e6e4df7d695f0feeb1403" checksum = "ccaeedb56da03b09f598226e25e80088cb4cd25f316e6e4df7d695f0feeb1403"
[[package]]
name = "crossbeam"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ae5588f6b3c3cb05239e90bd110f257254aecd01e4635400391aeae07497845"
dependencies = [
"cfg-if",
"crossbeam-channel",
"crossbeam-deque",
"crossbeam-epoch",
"crossbeam-queue",
"crossbeam-utils",
]
[[package]] [[package]]
name = "crossbeam-channel" name = "crossbeam-channel"
version = "0.5.1" version = "0.5.1"
@ -238,6 +252,30 @@ dependencies = [
"crossbeam-utils", "crossbeam-utils",
] ]
[[package]]
name = "crossbeam-deque"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e"
dependencies = [
"cfg-if",
"crossbeam-epoch",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-epoch"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd"
dependencies = [
"cfg-if",
"crossbeam-utils",
"lazy_static",
"memoffset",
"scopeguard",
]
[[package]] [[package]]
name = "crossbeam-queue" name = "crossbeam-queue"
version = "0.3.2" version = "0.3.2"
@ -880,6 +918,15 @@ version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
[[package]]
name = "memoffset"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9"
dependencies = [
"autocfg",
]
[[package]] [[package]]
name = "minimal-lexical" name = "minimal-lexical"
version = "0.1.4" version = "0.1.4"
@ -1048,6 +1095,7 @@ dependencies = [
"bitflags", "bitflags",
"bytes", "bytes",
"chrono", "chrono",
"crossbeam",
"derivative", "derivative",
"derive_builder", "derive_builder",
"format-bytes", "format-bytes",

View file

@ -22,4 +22,5 @@ CREATE TABLE "messages" (
"bcc" JSON, "bcc" JSON,
"in_reply_to" TEXT, "in_reply_to" TEXT,
"message_id" TEXT, "message_id" TEXT,
"mbox" BLOB
); );

View file

@ -12,6 +12,8 @@ extern crate derivative;
pub mod config; pub mod config;
pub mod mail; pub mod mail;
use std::path::PathBuf;
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use clap::Parser; use clap::Parser;
use futures::future::FutureExt; use futures::future::FutureExt;
@ -30,15 +32,15 @@ type ExitListener = oneshot::Receiver<()>;
/// panorama components over Unix sockets. /// panorama components over Unix sockets.
#[derive(Debug, Parser)] #[derive(Debug, Parser)]
struct Options { struct Options {
// /// Config file path (defaults to XDG) /// Config file path (defaults to XDG)
// #[clap(long = "config", short = 'c')] #[clap(long = "config", short = 'c')]
// config_file: Option<PathBuf>, config_file: Option<PathBuf>,
/// Verbose mode (-v, -vv, -vvv, etc) /// Verbose mode (-v, -vv, -vvv, etc)
#[clap(short = 'v', long = "verbose", parse(from_occurrences))] #[clap(short = 'v', long = "verbose", parse(from_occurrences))]
verbose: usize, verbose: usize,
} }
#[tokio::main]
pub async fn run() -> Result<()> { pub async fn run() -> Result<()> {
let opt = Options::parse(); let opt = Options::parse();

View file

@ -10,13 +10,13 @@ pub struct MailStore {
impl MailStore { impl MailStore {
/// Creates a new store tied to a SQLite database. /// Creates a new store tied to a SQLite database.
pub async fn open(uri: impl AsRef<str>) -> Result<Self> { pub async fn open(uri: impl AsRef<str>) -> Result<Self> {
let pool = SqlitePoolOptions::new().connect(uri.as_ref()).await?; let uri = uri.as_ref();
let pool = SqlitePoolOptions::new().connect(uri).await?;
// run migrations, if available // run migrations, if available
MIGRATOR MIGRATOR.run(&pool).await.with_context(|| {
.run(&pool) format!("could not run migrations on the pool at {}", uri)
.await })?;
.context("could not run migrations on the pool")?;
Ok(MailStore { pool }) Ok(MailStore { pool })
} }

View file

@ -1,4 +1,4 @@
use anyhow::Result; use anyhow::Result;
#[tokio::main] #[tokio::main]
async fn main() -> Result<()> { panorama_daemon::run() } async fn main() -> Result<()> { panorama_daemon::run().await }

View file

@ -13,8 +13,9 @@ readme = "README.md"
workspace = ".." workspace = ".."
[features] [features]
default = ["rfc2177", "rfc6154"] default = ["pool", "rfc2177", "rfc6154"]
low-level = [] low-level = []
pool = ["crossbeam"]
rfc2087 = [] # quota rfc2087 = [] # quota
rfc2177 = [] # idle rfc2177 = [] # idle
rfc4315 = [] # uidplus rfc4315 = [] # uidplus
@ -40,6 +41,8 @@ tokio-util = { version = "0.6.8", features = ["codec"] }
webpki-roots = "0.22.1" webpki-roots = "0.22.1"
panorama-proto-common = { path = "../proto-common" } panorama-proto-common = { path = "../proto-common" }
crossbeam = { version = "0.8.1", optional = true }
# for fuzzing # for fuzzing
arbitrary = { version = "1.0.2", optional = true, features = ["derive"] } arbitrary = { version = "1.0.2", optional = true, features = ["derive"] }

View file

@ -21,12 +21,14 @@ pub mod response_stream;
mod client; mod client;
mod codec; mod codec;
mod inner; mod inner;
mod pool;
mod tls; mod tls;
pub use self::client::{ pub use self::client::{
ClientAuthenticated, ClientUnauthenticated, Config, ConfigBuilder, ClientAuthenticated, ClientUnauthenticated, Config, ConfigBuilder,
}; };
pub use self::codec::{ImapCodec, TaggedCommand}; pub use self::codec::{ImapCodec, TaggedCommand};
pub use self::pool::ImapPool;
#[cfg(feature = "low-level")] #[cfg(feature = "low-level")]
pub use self::inner::Inner; pub use self::inner::Inner;

27
imap/src/client/pool.rs Normal file
View file

@ -0,0 +1,27 @@
use std::sync::Arc;
use crossbeam::queue::ArrayQueue;
use super::{ClientAuthenticated, Config};
#[derive(Clone)]
pub struct ImapPool(Arc<InnerPool>);
impl ImapPool {
pub fn new(config: Config) -> Self {
let inner = InnerPool {
config,
connections: ArrayQueue::new(10),
};
ImapPool(Arc::new(inner))
}
}
struct InnerPool {
config: Config,
connections: ArrayQueue<ClientAuthenticated>,
}
impl InnerPool {
pub fn connect() {}
}