Fixes Storage::contains_str

Takes care of the counter if not a key might be removed after the next compaction even if assumed to be contained
pull/171/head
Tpt 3 years ago
parent a7a0b7bbf3
commit 5da9fd4f14
  1. 11
      lib/src/sparql/dataset.rs
  2. 2
      lib/src/sparql/update.rs
  3. 7
      lib/src/storage/mod.rs

@ -6,6 +6,7 @@ use crate::storage::numeric_encoder::{
}; };
use crate::storage::Storage; use crate::storage::Storage;
use std::cell::RefCell; use std::cell::RefCell;
use std::collections::hash_map::Entry;
use std::collections::HashMap; use std::collections::HashMap;
use std::convert::Infallible; use std::convert::Infallible;
use std::iter::empty; use std::iter::empty;
@ -151,13 +152,11 @@ impl DatasetView {
} }
pub fn insert_str(&self, key: &StrHash, value: &str) { pub fn insert_str(&self, key: &StrHash, value: &str) {
if matches!(self.storage.contains_str(key), Ok(true)) { if let Entry::Vacant(e) = self.extra.borrow_mut().entry(*key) {
return; if !matches!(self.storage.contains_str(key), Ok(true)) {
e.insert(value.to_owned());
}
} }
self.extra
.borrow_mut()
.entry(*key)
.or_insert_with(|| value.to_owned());
} }
} }

@ -134,12 +134,14 @@ impl<'a> SimpleUpdateEvaluator<'a> {
Self::convert_ground_quad_pattern(quad, &variables, &tuple, &dataset)? Self::convert_ground_quad_pattern(quad, &variables, &tuple, &dataset)?
{ {
self.storage.remove(quad.as_ref())?; self.storage.remove(quad.as_ref())?;
if !insert.is_empty() {
// Hack to make sure the triple terms are still available for an insert // Hack to make sure the triple terms are still available for an insert
dataset.encode_term(quad.subject.as_ref()); dataset.encode_term(quad.subject.as_ref());
dataset.encode_term(quad.predicate.as_ref()); dataset.encode_term(quad.predicate.as_ref());
dataset.encode_term(quad.object.as_ref()); dataset.encode_term(quad.object.as_ref());
} }
} }
}
for quad in insert { for quad in insert {
if let Some(quad) = if let Some(quad) =
Self::convert_quad_pattern(quad, &variables, &tuple, &dataset, &mut bnodes)? Self::convert_quad_pattern(quad, &variables, &tuple, &dataset, &mut bnodes)?

@ -811,7 +811,12 @@ impl Storage {
} }
pub fn contains_str(&self, key: &StrHash) -> std::io::Result<bool> { pub fn contains_str(&self, key: &StrHash) -> std::io::Result<bool> {
self.db.contains_key(&self.id2str_cf, &key.to_be_bytes()) Ok(self
.db
.get(&self.id2str_cf, &key.to_be_bytes())?
.map_or(false, |v| {
i32::from_be_bytes(v[..4].try_into().unwrap()) > 0
}))
} }
} }

Loading…
Cancel
Save