mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-01-07 09:32:54 +00:00
* Removes all usage of block_on, and use a oneshot channel instead. Calling `block_on` panics in certain context. For instance, it panics when it is called in a the context of another call to block. Using it in tantivy is unnecessary. We replace it by a thin wrapper around a oneshot channel that supports both async/sync. * Removing needless uses of async in the API. Co-authored-by: PSeitz <PSeitz@users.noreply.github.com>
53 lines
1.4 KiB
Rust
53 lines
1.4 KiB
Rust
use super::IndexWriter;
|
|
use crate::{FutureResult, Opstamp};
|
|
|
|
/// A prepared commit
|
|
pub struct PreparedCommit<'a> {
|
|
index_writer: &'a mut IndexWriter,
|
|
payload: Option<String>,
|
|
opstamp: Opstamp,
|
|
}
|
|
|
|
impl<'a> PreparedCommit<'a> {
|
|
pub(crate) fn new(index_writer: &'a mut IndexWriter, opstamp: Opstamp) -> PreparedCommit<'_> {
|
|
PreparedCommit {
|
|
index_writer,
|
|
payload: None,
|
|
opstamp,
|
|
}
|
|
}
|
|
|
|
/// Returns the opstamp associated to the prepared commit.
|
|
pub fn opstamp(&self) -> Opstamp {
|
|
self.opstamp
|
|
}
|
|
|
|
/// Adds an arbitrary payload to the commit.
|
|
pub fn set_payload(&mut self, payload: &str) {
|
|
self.payload = Some(payload.to_string())
|
|
}
|
|
|
|
/// Rollbacks any change.
|
|
pub fn abort(self) -> crate::Result<Opstamp> {
|
|
self.index_writer.rollback()
|
|
}
|
|
|
|
/// Proceeds to commit.
|
|
/// See `.commit_future()`.
|
|
pub fn commit(self) -> crate::Result<Opstamp> {
|
|
self.commit_future().wait()
|
|
}
|
|
|
|
/// Proceeds to commit.
|
|
///
|
|
/// Unfortunately, contrary to what `PrepareCommit` may suggests,
|
|
/// this operation is not at all really light.
|
|
/// At this point deletes have not been flushed yet.
|
|
pub fn commit_future(self) -> FutureResult<Opstamp> {
|
|
info!("committing {}", self.opstamp);
|
|
self.index_writer
|
|
.segment_updater()
|
|
.schedule_commit(self.opstamp, self.payload)
|
|
}
|
|
}
|