summaryrefslogtreecommitdiffstats
path: root/src/indexer/index_writer.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/indexer/index_writer.rs')
-rw-r--r--src/indexer/index_writer.rs29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/indexer/index_writer.rs b/src/indexer/index_writer.rs
index 94961f5..3b4a01e 100644
--- a/src/indexer/index_writer.rs
+++ b/src/indexer/index_writer.rs
@@ -19,6 +19,7 @@ use indexer::doc_opstamp_mapping::DocToOpstampMapping;
use indexer::operation::DeleteOperation;
use indexer::stamper::Stamper;
use indexer::MergePolicy;
+use indexer::Opstamp;
use indexer::SegmentEntry;
use indexer::SegmentWriter;
use postings::compute_table_size;
@@ -99,7 +100,7 @@ pub struct IndexWriter {
delete_queue: DeleteQueue,
stamper: Stamper,
- committed_opstamp: u64,
+ committed_opstamp: Opstamp,
}
/// Open a new index writer. Attempts to acquire a lockfile.
@@ -177,7 +178,7 @@ pub fn compute_deleted_bitset(
segment_reader: &SegmentReader,
delete_cursor: &mut DeleteCursor,
doc_opstamps: &DocToOpstampMapping,
- target_opstamp: u64,
+ target_opstamp: Opstamp,
) -> Result<bool> {
let mut might_have_changed = false;
@@ -219,7 +220,7 @@ pub fn compute_deleted_bitset(
pub fn advance_deletes(
mut segment: Segment,
segment_entry: &mut SegmentEntry,
- target_opstamp: u64,
+ target_opstamp: Opstamp,
) -> Result<()> {
{
if segment_entry.meta().delete_opstamp() == Some(target_opstamp) {
@@ -299,11 +300,11 @@ fn index_documents(
// the worker thread.
assert!(num_docs > 0);
- let doc_opstamps: Vec<u64> = segment_writer.finalize()?;
+ let doc_opstamps: Vec<Opstamp> = segment_writer.finalize()?;
let segment_meta = SegmentMeta::new(segment_id, num_docs);
- let last_docstamp: u64 = *(doc_opstamps.last().unwrap());
+ let last_docstamp: Opstamp = *(doc_opstamps.last().unwrap());
let delete_bitset_opt = if delete_cursor.get().is_some() {
let doc_to_opstamps = DocToOpstampMapping::from(doc_opstamps);
@@ -494,7 +495,7 @@ impl IndexWriter {
/// state as it was after the last commit.
///
/// The opstamp at the last commit is returned.
- pub fn rollback(&mut self) -> Result<()> {
+ pub fn rollback(&mut self) -> Result<Opstamp> {
info!("Rolling back to opstamp {}", self.committed_opstamp);
// marks the segment updater as killed. From now on, all
@@ -529,7 +530,7 @@ impl IndexWriter {
// was dropped with the index_writer.
for _ in document_receiver.clone() {}
- Ok(())
+ Ok(self.committed_opstamp)
}
/// Prepares a commit.
@@ -567,7 +568,7 @@ impl IndexWriter {
info!("Preparing commit");
// this will drop the current document channel
- // and recreate a new one channels.
+ // and recreate a new one.
self.recreate_document_channel();
let former_workers_join_handle = mem::replace(&mut self.workers_join_handle, Vec::new());
@@ -601,7 +602,7 @@ impl IndexWriter {
/// Commit returns the `opstamp` of the last document
/// that made it in the commit.
///
- pub fn commit(&mut self) -> Result<u64> {
+ pub fn commit(&mut self) -> Result<Opstamp> {
self.prepare_commit()?.commit()
}
@@ -617,7 +618,7 @@ impl IndexWriter {
///
/// Like adds, the deletion itself will be visible
/// only after calling `commit()`.
- pub fn delete_term(&mut self, term: Term) -> u64 {
+ pub fn delete_term(&mut self, term: Term) -> Opstamp {
let opstamp = self.stamper.stamp();
let delete_operation = DeleteOperation { opstamp, term };
self.delete_queue.push(delete_operation);
@@ -631,7 +632,7 @@ impl IndexWriter {
///
/// This is also the opstamp of the commit that is currently
/// available for searchers.
- pub fn commit_opstamp(&self) -> u64 {
+ pub fn commit_opstamp(&self) -> Opstamp {
self.committed_opstamp
}
@@ -645,7 +646,7 @@ impl IndexWriter {
///
/// Currently it represents the number of documents that
/// have been added since the creation of the index.
- pub fn add_document(&mut self, document: Document) -> u64 {
+ pub fn add_document(&mut self, document: Document) -> Opstamp {
let opstamp = self.stamper.stamp();
let add_operation = AddOperation { opstamp, document };
let send_result = self.operation_sender.send(vec![add_operation]);
@@ -662,7 +663,7 @@ impl IndexWriter {
/// The total number of stamps generated by this method is `count + 1`;
/// each operation gets a stamp from the `stamps` iterator and `last_opstamp`
/// is for the batch itself.
- fn get_batch_opstamps(&mut self, count: u64) -> (u64, Range<u64>) {
+ fn get_batch_opstamps(&mut self, count: Opstamp) -> (Opstamp, Range<Opstamp>) {
let Range { start, end } = self.stamper.stamps(count + 1u64);
let last_opstamp = end - 1;
let stamps = Range {
@@ -688,7 +689,7 @@ impl IndexWriter {
/// Like adds and deletes (see `IndexWriter.add_document` and
/// `IndexWriter.delete_term`), the changes made by calling `run` will be
/// visible to readers only after calling `commit()`.
- pub fn run(&mut self, user_operations: Vec<UserOperation>) -> u64 {
+ pub fn run(&mut self, user_operations: Vec<UserOperation>) -> Opstamp {
let count = user_operations.len() as u64;
if count == 0 {
return self.stamper.stamp();