Struct shardio::ShardWriter [−][src]
Write a stream data items of type T
to disk, in the sort order defined by S
.
Data is buffered up to item_buffer_size
items, then sorted, block compressed and written to disk.
When the ShardWriter is dropped or has finish()
called on it, it will
flush remaining items to disk, write an index of the chunk data and close the file.
The get_sender()
methods returns a ShardSender
that must be used to send items to the writer.
You must close each ShardSender by dropping it or calling its finish()
method, or data may be lost.
The ShardSender
must be dropped/finished prior to callinng SharWriter::finish
or dropping the shard writer.
Sorting
Items are sorted according to the Ord
implementation of type S::Key
. Type S
, implementing the SortKey
trait
maps items of type T
to their sort key of type S::Key
. By default the sort key is the data item itself, and the
the DefaultSort
implementation of SortKey
is the identity function.
Implementations
impl<T, S> ShardWriter<T, S> where
T: 'static + Send + Serialize,
S: SortKey<T>,
<S as SortKey<T>>::Key: 'static + Send + Ord + Serialize + Clone,
[src]
T: 'static + Send + Serialize,
S: SortKey<T>,
<S as SortKey<T>>::Key: 'static + Send + Ord + Serialize + Clone,
pub fn new<P: AsRef<Path>>(
path: P,
sender_buffer_size: usize,
disk_chunk_size: usize,
item_buffer_size: usize
) -> Result<ShardWriter<T, S>, Error>
[src]
path: P,
sender_buffer_size: usize,
disk_chunk_size: usize,
item_buffer_size: usize
) -> Result<ShardWriter<T, S>, Error>
Create a writer for storing data items of type T
.
Arguments
path
- Path to newly created output filesender_buffer_size
- number of items to buffer on the sending thread before transferring data to the writer. Each transfer to the writer requires one channel send, and one allocation. Set to ~16 or 32 it you’re sending items very rapidly (>100k/s).disk_chunk_size
- Number of items to store in each chunk on disk. Controls the tradeoff between indexing overhead and the granularity of reads into the sorted dataset. When reading, shardio must iterate from the start of a chunk to access an item.item_buffer_size
- Number of items to buffer before sorting, chunking and writing items to disk. More buffering causes each chunk to cover a smaller interval of key space (allowing for more efficient reading), but requires more memory.
pub fn get_sender(&self) -> ShardSender<T, S>
[src]
Get a ShardSender
. It can be sent to another thread that is generating data.
pub fn finish(&mut self) -> Result<usize, Error>
[src]
Call finish if you want to detect errors in the writer IO.
Trait Implementations
impl<T, S> Drop for ShardWriter<T, S> where
S: SortKey<T>,
<S as SortKey<T>>::Key: 'static + Send + Ord + Serialize + Clone,
T: Send + Serialize,
[src]
S: SortKey<T>,
<S as SortKey<T>>::Key: 'static + Send + Ord + Serialize + Clone,
T: Send + Serialize,
Auto Trait Implementations
impl<T, S> RefUnwindSafe for ShardWriter<T, S> where
S: RefUnwindSafe,
S: RefUnwindSafe,
impl<T, S> Send for ShardWriter<T, S> where
S: Send,
S: Send,
impl<T, S> Sync for ShardWriter<T, S> where
S: Sync,
S: Sync,
impl<T, S> Unpin for ShardWriter<T, S> where
S: Unpin,
S: Unpin,
impl<T, S> UnwindSafe for ShardWriter<T, S> where
S: UnwindSafe,
S: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,