Trait tantivy::directory::Directory [−][src]
Write-once read many (WORM) abstraction for where tantivy's data should be stored.
There are currently two implementations of Directory
- The
MMapDirectory
, this should be your default choice. - The
RAMDirectory
, which should be used mostly for tests.
Required methods
fn get_file_handle(
&self,
path: &Path
) -> Result<Box<dyn FileHandle>, OpenReadError>
[src]
&self,
path: &Path
) -> Result<Box<dyn FileHandle>, OpenReadError>
Opens a file and returns a boxed FileHandle
.
Users of Directory
should typically call Directory::open_read(...)
,
while Directory
implementor should implement get_file_handle()
.
fn delete(&self, path: &Path) -> Result<(), DeleteError>
[src]
Removes a file
Removing a file will not affect an eventual existing FileSlice pointing to it.
Removing a nonexistent file, yields a
DeleteError::DoesNotExist
.
fn exists(&self, path: &Path) -> Result<bool, OpenReadError>
[src]
Returns true iff the file exists
fn open_write(&self, path: &Path) -> Result<WritePtr, OpenWriteError>
[src]
Opens a writer for the virtual file associated with a Path.
Right after this call, the file should be created
and any subsequent call to open_read
for the
same path should return a FileSlice
.
Write operations may be aggressively buffered.
The client of this trait is responsible for calling flush
to ensure that subsequent read
operations
will take into account preceding write
operations.
Flush operation should also be persistent.
The user shall not rely on Drop
triggering flush
.
Note that RAMDirectory
will panic! if flush
was not called.
The file may not previously exist.
fn atomic_read(&self, path: &Path) -> Result<Vec<u8>, OpenReadError>
[src]
Reads the full content file that has been written using atomic_write.
This should only be used for small files.
You should only use this to read files create with Directory::atomic_write.
fn atomic_write(&self, path: &Path, data: &[u8]) -> Result<()>
[src]
Atomically replace the content of a file with data.
This calls ensure that reads can never observe a partially written file.
The file may or may not previously exist.
fn watch(&self, watch_callback: WatchCallback) -> Result<WatchHandle>
[src]
Registers a callback that will be called whenever a change on the meta.json
using the atomic_write
API is detected.
The behavior when using .watch()
on a file using Directory::open_write is, on the other
hand, undefined.
The file will be watched for the lifetime of the returned WatchHandle
. The caller is
required to keep it.
It does not override previous callbacks. When the file is modified, all callback that are
registered (and whose WatchHandle
is still alive) are triggered.
Internally, tantivy only uses this API to detect new commits to implement the
OnCommit
ReloadPolicy
. Not implementing watch in a Directory
only prevents the
OnCommit
ReloadPolicy
to work properly.
Provided methods
fn open_read(&self, path: &Path) -> Result<FileSlice, OpenReadError>
[src]
Once a virtual file is open, its data may not change.
Specifically, subsequent writes or flushes should
have no effect on the returned FileSlice
object.
You should only use this to read files create with Directory::open_write.
fn acquire_lock(&self, lock: &Lock) -> Result<DirectoryLock, LockError>
[src]
Acquire a lock in the given directory.
The method is blocking or not depending on the Lock
object.
Implementors
impl Directory for ManagedDirectory
[src]
fn get_file_handle(
&self,
path: &Path
) -> Result<Box<dyn FileHandle>, OpenReadError>
[src]
&self,
path: &Path
) -> Result<Box<dyn FileHandle>, OpenReadError>
fn open_read(&self, path: &Path) -> Result<FileSlice, OpenReadError>
[src]
fn open_write(&self, path: &Path) -> Result<WritePtr, OpenWriteError>
[src]
fn atomic_write(&self, path: &Path, data: &[u8]) -> Result<()>
[src]
fn atomic_read(&self, path: &Path) -> Result<Vec<u8>, OpenReadError>
[src]
fn delete(&self, path: &Path) -> Result<(), DeleteError>
[src]
fn exists(&self, path: &Path) -> Result<bool, OpenReadError>
[src]
fn acquire_lock(&self, lock: &Lock) -> Result<DirectoryLock, LockError>
[src]
fn watch(&self, watch_callback: WatchCallback) -> Result<WatchHandle>
[src]
impl Directory for MmapDirectory
[src]
fn get_file_handle(
&self,
path: &Path
) -> Result<Box<dyn FileHandle>, OpenReadError>
[src]
&self,
path: &Path
) -> Result<Box<dyn FileHandle>, OpenReadError>
fn delete(&self, path: &Path) -> Result<(), DeleteError>
[src]
Any entry associated to the path in the mmap will be removed before the file is deleted.
fn exists(&self, path: &Path) -> Result<bool, OpenReadError>
[src]
fn open_write(&self, path: &Path) -> Result<WritePtr, OpenWriteError>
[src]
fn atomic_read(&self, path: &Path) -> Result<Vec<u8>, OpenReadError>
[src]
fn atomic_write(&self, path: &Path, content: &[u8]) -> Result<()>
[src]
fn acquire_lock(&self, lock: &Lock) -> Result<DirectoryLock, LockError>
[src]
fn watch(&self, watch_callback: WatchCallback) -> Result<WatchHandle>
[src]
impl Directory for RAMDirectory
[src]
fn get_file_handle(
&self,
path: &Path
) -> Result<Box<dyn FileHandle>, OpenReadError>
[src]
&self,
path: &Path
) -> Result<Box<dyn FileHandle>, OpenReadError>