Skip to content

Commit

Permalink
Refactor: context/<store> to store/<store>
Browse files Browse the repository at this point in the history
  • Loading branch information
sdleffler committed Oct 15, 2017
1 parent 5c27df8 commit 46ef073
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 37 deletions.
3 changes: 2 additions & 1 deletion src/bin/utils/read.rs
Expand Up @@ -5,7 +5,8 @@ use futures::prelude::*;

use attaca::context::Context;
use attaca::marshal::{ObjectHash, Object, DataObject};
use attaca::repository::Repository;
use attaca::Repository;
use attaca::Store;

use errors::*;

Expand Down
23 changes: 1 addition & 22 deletions src/context/mod.rs → src/context.rs
@@ -1,13 +1,4 @@
//! # `context` - manage a valid repository.
//!
//! `Context` is the main point of entry for the Attaca API. Important pieces of functionality in
//! this module include:
//!
//! * Creating/using `Context` and `RemoteContext`s.

pub mod empty;
pub mod local;
pub mod remote;

use std::fmt;
use std::path::{Path, PathBuf};
Expand All @@ -26,21 +17,9 @@ use errors::*;
use index::{Index, Cached};
use marshal::{ObjectHash, Object, Marshaller, Hashed, DirTree};
use split::SliceChunker;
use store::{Store, Empty};
use trace::Trace;

pub use context::empty::Empty;
pub use context::local::Local;
pub use context::remote::Remote;


pub trait Store: Send + Sync + Clone + 'static {
type Read: Future<Item = Object, Error = Error> + Send;
type Write: Future<Item = bool, Error = Error> + Send;

fn read_object(&self, object_hash: ObjectHash) -> Self::Read;
fn write_object(&self, hashed: Hashed) -> Self::Write;
}


/// A context for marshalling and local operations on a repository. `RemoteContext`s must be built
/// from a `Context`.
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Expand Up @@ -53,10 +53,12 @@ pub mod index;
pub mod marshal;
pub mod repository;
pub mod split;
pub mod store;
pub mod trace;

pub use errors::*;
pub use repository::Repository;
pub use store::Store;

use std::collections::HashSet;
use std::path::{Path, PathBuf};
Expand Down
2 changes: 1 addition & 1 deletion src/marshal/dir_tree.rs
Expand Up @@ -7,9 +7,9 @@ use futures::future::{self, Either, Loop};
use futures::prelude::*;
use sequence_trie::SequenceTrie;

use context::Store;
use errors::*;
use marshal::{ObjectHash, Object};
use store::Store;


#[derive(Debug)]
Expand Down
5 changes: 3 additions & 2 deletions src/repository.rs
Expand Up @@ -28,10 +28,11 @@ use toml;
use {METADATA_PATH, BLOBS_PATH, CONFIG_PATH, REMOTE_CATALOGS_PATH, LOCAL_CATALOG_PATH, INDEX_PATH,
REFS_PATH};
use catalog::{Registry, Catalog, CatalogTrie};
use context::{Local, Remote, Context};
use context::Context;
use errors::*;
use index::Index;
use marshal::ObjectHash;
use store::{Local, Remote, Ceph};
use trace::Trace;


Expand Down Expand Up @@ -354,7 +355,7 @@ impl Repository {
},
)?;
let local = Local::new(&self.paths, &local_catalog, io_pool);
let remote = Remote::connect(local, &remote_catalog, remote_config, io_pool)?;
let remote = Remote::Ceph(Ceph::connect(local, &remote_catalog, remote_config, io_pool)?);

Ok(Context::new(trace, remote, marshal_pool, io_pool))
}
Expand Down
18 changes: 9 additions & 9 deletions src/context/remote.rs → src/store/ceph.rs
@@ -1,6 +1,6 @@
//! # `remote` - operations on remote repositories.
//!
//! `Remote` contains a `RadosConnection` object, along with a reference to the parent context.
//! `Ceph` contains a `RadosConnection` object, along with a reference to the parent context.
//!
//! At current the only supported remote is a Ceph/RADOS cluster.

Expand All @@ -12,10 +12,10 @@ use owning_ref::OwningRefMut;
use rad::{ConnectionBuilder, Connection};

use catalog::Catalog;
use context::{Store, Local};
use errors::*;
use marshal::{Hashed, ObjectHash, Object};
use repository::RemoteCfg;
use store::{Store, Local};


/// The type of a remote repository.
Expand All @@ -24,23 +24,23 @@ use repository::RemoteCfg;
// when the remote already contains them.
// TODO: Make the act of writing an object asynchronous - return a future instead of a `Result.
#[derive(Clone)]
pub struct Remote {
pub struct Ceph {
local: Local,

io_pool: CpuPool,

catalog: Catalog,
inner: Arc<RemoteInner>,
inner: Arc<CephInner>,
}


struct RemoteInner {
struct CephInner {
conn: Mutex<Connection>,
pool: String,
}


impl Remote {
impl Ceph {
/// Connect to a remote repository, given appropriate configuration data.
pub fn connect(
local: Local,
Expand Down Expand Up @@ -72,13 +72,13 @@ impl Remote {

let pool = remote_config.object_store.pool.clone();

Ok(Remote {
Ok(Ceph {
local,

io_pool: io_pool.clone(),

catalog: remote_catalog.clone(),
inner: Arc::new(RemoteInner { conn, pool }),
inner: Arc::new(CephInner { conn, pool }),
})
}

Expand Down Expand Up @@ -170,7 +170,7 @@ impl Remote {
}


impl Store for Remote {
impl Store for Ceph {
type Read = Box<Future<Item = Object, Error = Error> + Send>;
type Write = Box<Future<Item = bool, Error = Error> + Send>;

Expand Down
2 changes: 1 addition & 1 deletion src/context/empty.rs → src/store/empty.rs
@@ -1,8 +1,8 @@
use futures::future::{self, FutureResult};

use context::Store;
use errors::*;
use marshal::{Object, ObjectHash, Hashed};
use store::Store;


#[derive(Debug, Clone, Copy)]
Expand Down
2 changes: 1 addition & 1 deletion src/context/local.rs → src/store/local.rs
Expand Up @@ -18,10 +18,10 @@ use stable_deref_trait::StableDeref;

use arc_slice;
use catalog::{Catalog, CatalogLock};
use context::Store;
use errors::*;
use marshal::{Hashed, ObjectHash, Object};
use repository::Paths;
use store::Store;


pub struct LocalBufferFactory {
Expand Down
79 changes: 79 additions & 0 deletions src/store/mod.rs
@@ -0,0 +1,79 @@
use futures::prelude::*;

use errors::*;
use marshal::{ObjectHash, Hashed, Object};

mod ceph;
mod empty;
mod local;

pub use self::ceph::Ceph;
pub use self::empty::Empty;
pub use self::local::Local;


pub trait Store: Send + Sync + Clone + 'static {
type Read: Future<Item = Object, Error = Error> + Send;
type Write: Future<Item = bool, Error = Error> + Send;

fn read_object(&self, object_hash: ObjectHash) -> Self::Read;
fn write_object(&self, hashed: Hashed) -> Self::Write;
}


pub enum RemoteRead {
Ceph(<Ceph as Store>::Read),
}


impl Future for RemoteRead {
type Item = Object;
type Error = Error;

fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
match *self {
RemoteRead::Ceph(ref mut ceph) => ceph.poll(),
}
}
}


pub enum RemoteWrite {
Ceph(<Ceph as Store>::Write),
}


impl Future for RemoteWrite {
type Item = bool;
type Error = Error;

fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
match *self {
RemoteWrite::Ceph(ref mut ceph) => ceph.poll(),
}
}
}


#[derive(Clone)]
pub enum Remote {
Ceph(Ceph),
}


impl Store for Remote {
type Read = RemoteRead;
type Write = RemoteWrite;

fn read_object(&self, object_hash: ObjectHash) -> Self::Read {
match *self {
Remote::Ceph(ref ceph) => RemoteRead::Ceph(ceph.read_object(object_hash)),
}
}

fn write_object(&self, hashed: Hashed) -> Self::Write {
match *self {
Remote::Ceph(ref ceph) => RemoteWrite::Ceph(ceph.write_object(hashed)),
}
}
}

0 comments on commit 46ef073

Please sign in to comment.