Expand description
§rad-rs
- A high-level wrapper library for talking to Ceph RADOS clusters.
Only certain features are currently available, mainly writing and reading to RADOS objects, as well as a limited set of other operations (object stats, for example.) However, the operations that are provided are supplied in an idiomatic, Rusty fashion, using the futures library for asynchronous operations.
Missing functionality includes MON/OSD/PGS commands.
Current features:
- Read, write, full-write, append
- Automatic
rados_shutdown
on drop of the reference-countedRadosCluster
type - Asynchronous read/write/etc. using futures
§Examples
§Connecting to a cluster
use std::path::Path;
use rad::ConnectionBuilder;
let cluster = ConnectionBuilder::with_user("admin")?
.read_conf_file(Path::new("/etc/ceph.conf"))?
.conf_set("keyring", "/etc/ceph.client.admin.keyring")?
.connect()?;
§Synchronous cluster operations
use std::fs::File;
use std::io::Read;
use std::path::Path;
use rad::ConnectionBuilder;
let mut cluster = ConnectionBuilder::with_user("admin")?
.read_conf_file(Path::new("/etc/ceph.conf"))?
.conf_set("keyring", "/etc/ceph.client.admin.keyring")?
.connect()?;
// Read in bytes from some file to send to the cluster.
let mut file = File::open("/path/to/file")?;
let mut bytes = Vec::new();
file.read_to_end(&mut bytes)?;
let mut pool = cluster.get_pool_context("rbd")?;
pool.write_full("object-name", &bytes)?;
// Our file is now in the cluster! We can check for its existence:
assert!(pool.exists("object-name")?);
// And we can also check that it contains the bytes we wrote to it.
let mut bytes_from_cluster = vec![0u8; bytes.len()];
let bytes_read = pool.read("object-name", &mut bytes_from_cluster, 0)?;
assert_eq!(bytes_read, bytes_from_cluster.len());
assert!(bytes_from_cluster == bytes);
§Asynchronous cluster I/O
use std::path::Path;
use std::io::Read;
use futures::prelude::*;
use futures::stream;
use rand::{Rng, SeedableRng, XorShiftRng};
use rad::ConnectionBuilder;
const NUM_OBJECTS: usize = 8;
let mut cluster = ConnectionBuilder::with_user("admin")?
.read_conf_file(Path::new("/etc/ceph.conf"))?
.conf_set("keyring", "/etc/ceph.client.admin.keyring")?
.connect()?;
let mut pool = cluster.get_pool_context("rbd")?;
stream::iter_ok((0..NUM_OBJECTS)
.map(|i| {
let bytes = XorShiftRng::from_seed([i as u32 + 1, 2, 3, 4])
.gen_iter::<u8>()
.take(1 << 16)
.collect::<Vec<u8>>();
let name = format!("object-{}", i);
pool.write_full_async(&name, &bytes)
}))
.buffer_unordered(NUM_OBJECTS)
.collect()
.wait()?;
Re-exports§
pub use rados::ConnectionBuilder;
pub use rados::Connection;
pub use rados::Context;
pub use rados::Stat;
pub use errors::*;
Modules§
- Wrappers for Ceph cluster connections, Ceph I/O contexts, and associated operations.
Macros§
Traits§
- An unsafe marker trait for types that deref to a stable address, even when moved. For example, this is implemented by Box, Vec, Rc, Arc and String, among others. Even when a Box is moved, the underlying storage remains at a fixed location.