[][src]Struct asuran::repository::backend::multifile::segment::InternalSegmentHandler

struct InternalSegmentHandler {
    current_segment: Option<SegmentPair<LockedFile>>,
    highest_segment: u64,
    size_limit: u64,
    ro_segment_cache: LruCache<u64, SegmentPair<File>>,
    path: PathBuf,
    segments_per_directory: u64,
    chunk_settings: ChunkSettings,
    key: Key,

An internal struct for handling the state of the segments

Maintains a handle to the currently being written segment, and will keep it up to date as the data outgrows its file size limits

Will keep a cache of handles to files being read, to decrease the number of system calls needed


  1. Implement an optional ARC cache, this could be useful for speeding up restores on highly duplicated datasets
  2. Swtich ro_segment_cache to an ARC


current_segment: Option<SegmentPair<LockedFile>>

The segment we are currently writing too, if it exists

highest_segment: u64

The ID of the highest segment we have encountered

size_limit: u64

The size limit of each segment, in bytes

At the moment, this is a soft size limit, the segment will be closed after the first write that exceeds it completes

ro_segment_cache: LruCache<u64, SegmentPair<File>>

An LRU cache of recently used segements, opened in RO mode

path: PathBuf

The path of the segment directory

segments_per_directory: u64

The number of segments per directory

chunk_settings: ChunkSettings

The chunk settings used for encrypting headers

key: Key

They key used for encrypting/decrypting headers


impl InternalSegmentHandler[src]

fn open(
    repository_path: impl AsRef<Path>,
    size_limit: u64,
    segments_per_directory: u64,
    chunk_settings: ChunkSettings,
    key: Key
) -> Result<InternalSegmentHandler>

Opens up a segment handler

Will create the directory if it does not exist

Note: the repository_path is the path of the root folder of the repository, not the data folder

Will default to a cache size of 100 file handles.

This implementation is not thread safe, please see SegmentHandler for a thread safe implementation on top of this


  1. The data folder does not exist and creating it failed


Any filenames in the data directory contain non-utf8 characters


  1. This function currently recursively walks the entire data directory to find the highest numbered segment, when we can skip the recursion and only inspect the highest numbered segment folder, and still have correct behavior

fn open_segement_read(
    &mut self,
    segment_id: u64
) -> Result<&mut SegmentPair<File>>

Open a segement for reading

Since we do not syncronize reads, and modification of existing data is forbidden as long as any instance holds a valid read lock, we do not need to worry about syncronization and simply open it as a read only file handle

This method will first attempt to pull the segement out of the cache, and failing that, open it the file and inser it into the cache


  1. The segment or the folder containing it does not exist
  2. Some IO error (such as lack of permissions) occurs opening the file

fn segment_exists(&self, segment_id: u64) -> bool[src]

Tests if a segment exists or not

fn open_segment_write(&mut self) -> Result<&mut SegmentPair<LockedFile>>[src]

Returns the currently active writing segment

Will create/open a new one if there is not currently one open


  1. Some IO error prevents the creation of a new segment file
  2. We need to create a new segement folder, but a file with that name exists in the data directory
  3. We need to create a new segement, but some other instance beats us to the punch and the new name we have chosen gets created and locked while we are running

fn read_chunk(&mut self, location: SegmentDescriptor) -> Result<Chunk>[src]

Attempts to read a chunk from its associated segment

fn write_chunk(&mut self, chunk: Chunk) -> Result<SegmentDescriptor>[src]

Attempts to write a chunk

Will close out the current segment if the size, after the write completes, execeds the max size

fn flush(&mut self) -> Result<()>[src]

Flushes the changes to the current segment

Auto Trait Implementations

impl RefUnwindSafe for InternalSegmentHandler

impl Send for InternalSegmentHandler

impl Sync for InternalSegmentHandler

impl Unpin for InternalSegmentHandler

impl UnwindSafe for InternalSegmentHandler

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized

impl<T> Borrow<T> for T where
    T: ?Sized

impl<T> BorrowMut<T> for T where
    T: ?Sized

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<T> WithSubscriber for T[src]