issue/43 deletes

merge not working
only updating uncommitted
This commit is contained in:
Paul Masurel
2017-02-05 19:01:06 +09:00
parent 0820992141
commit e12fc4bb09
17 changed files with 185 additions and 241 deletions

View File

@@ -208,8 +208,8 @@ impl Index {
/// Return a segment object given a `segment_id`
///
/// The segment may or may not exist.
pub fn segment(&self, segment_id: SegmentId, commit_opstamp: u64) -> Segment {
create_segment(self.clone(), segment_id, commit_opstamp)
pub fn segment(&self, segment_id: SegmentId, opstamp: u64) -> Segment {
create_segment(self.clone(), segment_id, opstamp)
}
/// Return a reference to the index directory.

View File

@@ -16,7 +16,7 @@ use directory::error::{FileError, OpenWriteError};
pub struct Segment {
index: Index,
segment_id: SegmentId,
commit_opstamp: u64,
opstamp: u64,
}
impl fmt::Debug for Segment {
@@ -28,11 +28,11 @@ impl fmt::Debug for Segment {
/// Creates a new segment given an `Index` and a `SegmentId`
///
/// The function is here to make it private outside `tantivy`.
pub fn create_segment(index: Index, segment_id: SegmentId, commit_opstamp: u64) -> Segment {
pub fn create_segment(index: Index, segment_id: SegmentId, opstamp: u64) -> Segment {
Segment {
index: index,
segment_id: segment_id,
commit_opstamp: commit_opstamp,
opstamp: opstamp,
}
}
@@ -43,8 +43,8 @@ impl Segment {
self.index.schema()
}
pub fn commit_opstamp(&self) -> u64 {
self.commit_opstamp
pub fn opstamp(&self) -> u64 {
self.opstamp
}
/// Returns the segment's id.
@@ -52,12 +52,21 @@ impl Segment {
self.segment_id
}
pub fn with_opstamp(&self, opstamp: u64) -> Segment {
Segment {
index: self.index.clone(),
segment_id: self.segment_id.clone(),
opstamp: opstamp,
}
}
/// Returns the relative path of a component of our segment.
///
/// It just joins the segment id with the extension
/// associated to a segment component.
pub fn relative_path(&self, component: SegmentComponent) -> PathBuf {
self.segment_id.relative_path(component)
let path_suffix = component.path_suffix(self.opstamp);
PathBuf::from(self.segment_id.uuid_string() + &*path_suffix)
}
/// Open one of the component file for read.

View File

@@ -7,14 +7,12 @@ pub enum SegmentComponent {
FIELDNORMS,
TERMS,
STORE,
DELETE(u64), //< The argument here is an opstamp.
// All of the deletes with an opstamp smaller or equal
// to this opstamp have been taken in account.
DELETE
}
impl SegmentComponent {
pub fn path_suffix(&self)-> String {
pub fn path_suffix(&self, opstamp: u64)-> String {
match *self {
SegmentComponent::POSITIONS => ".pos".to_string(),
SegmentComponent::INFO => ".info".to_string(),
@@ -23,9 +21,7 @@ impl SegmentComponent {
SegmentComponent::STORE => ".store".to_string(),
SegmentComponent::FASTFIELDS => ".fast".to_string(),
SegmentComponent::FIELDNORMS => ".fieldnorm".to_string(),
SegmentComponent::DELETE(opstamp) => {
format!(".{}.del", opstamp)
}
SegmentComponent::DELETE => {format!(".{}.del", opstamp)},
}
}
}

View File

@@ -48,11 +48,6 @@ impl SegmentId {
pub fn uuid_string(&self,) -> String {
self.0.simple().to_string()
}
pub fn relative_path(&self, component: SegmentComponent) -> PathBuf {
let filename = self.uuid_string() + &*component.path_suffix();
PathBuf::from(filename)
}
}
impl Encodable for SegmentId {

View File

@@ -147,7 +147,7 @@ impl SegmentReader {
.unwrap_or_else(|_| ReadOnlySource::empty());
// TODO 0u64
let delete_data_res = segment.open_read(SegmentComponent::DELETE(segment.commit_opstamp()));
let delete_data_res = segment.open_read(SegmentComponent::DELETE);
let delete_bitset;
if let Err(FileError::FileDoesNotExist(_)) = delete_data_res {
delete_bitset = DeleteBitSet::empty();
@@ -262,6 +262,10 @@ impl SegmentReader {
pub fn segment_id(&self) -> SegmentId {
self.segment_id
}
pub fn is_deleted(&self, doc: DocId) -> bool {
self.delete_bitset.is_deleted(doc)
}
}