From 9bb3d64aaaa36767cc6310770414aa56a93413b4 Mon Sep 17 00:00:00 2001 From: Ziyang Hu Date: Sun, 10 Jul 2022 18:45:32 +0800 Subject: [PATCH] tests fail --- cozorocks/src/bridge/tx.rs | 1 + cozorocks/src/tests.rs | 2 +- src/data/encode.rs | 7 ++----- src/tests.rs | 10 +++++----- src/transact/attr.rs | 2 +- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/cozorocks/src/bridge/tx.rs b/cozorocks/src/bridge/tx.rs index 4860e34e..be2cba69 100644 --- a/cozorocks/src/bridge/tx.rs +++ b/cozorocks/src/bridge/tx.rs @@ -170,5 +170,6 @@ impl Tx { IterBuilder { inner: self.inner.pin_mut().iterator(), } + .auto_prefix_mode(true) } } diff --git a/cozorocks/src/tests.rs b/cozorocks/src/tests.rs index f6b77d09..613fc20a 100644 --- a/cozorocks/src/tests.rs +++ b/cozorocks/src/tests.rs @@ -44,7 +44,7 @@ fn creation() { ); assert!(tx.get("bye".as_bytes(), false).unwrap().is_none()); - let mut it = tx.iterator().total_order_seek(true).start(); + let mut it = tx.iterator().start(); it.seek_to_start(); while let Some((k, v)) = it.pair().unwrap() { let mut res = String::from_utf8_lossy(k); diff --git a/src/data/encode.rs b/src/data/encode.rs index d4338151..aec60da1 100644 --- a/src/data/encode.rs +++ b/src/data/encode.rs @@ -65,21 +65,18 @@ impl EncodedVec { format!("{:?}{}", tx, op) } } - StorageTag::AttrById => { + StorageTag::AttrById | StorageTag::UniqueAttrById | StorageTag::UniqueAttrByKeyword => { let op = StoreOp::try_from(data[0]).unwrap(); if data.len() <= 1 { op.to_string() } else { - format!("{}{:?}", op, Attribute::decode(&data[1..]).unwrap()) + format!("{}{:?}", op, Attribute::decode(&data[VEC_SIZE_8..]).unwrap()) } } StorageTag::Tx => format!("{:?}", TxLog::decode(data).unwrap()), StorageTag::UniqueEntity | StorageTag::UniqueAttrValue => { format!("{:?}", TxId::from_bytes(data)) } - StorageTag::UniqueAttrById | StorageTag::UniqueAttrByKeyword => { - format!("{:?}", TxId::from_bytes(data)) - } } } } diff --git a/src/tests.rs b/src/tests.rs index 99d08600..79a1f950 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,6 +1,6 @@ use crate::data::attr::{Attribute, AttributeCardinality, AttributeIndex, AttributeTyping}; use crate::data::encode::EncodedVec; -use crate::data::id::{AttrId, EntityId}; +use crate::data::id::{AttrId, EntityId, Validity}; use crate::data::keyword::Keyword; use crate::data::value::Value; use crate::Db; @@ -21,8 +21,9 @@ fn test_send_sync(_: &T) {} fn creation() { let db = create_db("_test_db"); test_send_sync(&db); + let current_validity = Validity::current(); let session = db.new_session().unwrap(); - let mut tx = session.transact(None).unwrap(); + let mut tx = session.transact().unwrap(); assert_eq!( 0, tx.all_attrs() @@ -48,7 +49,7 @@ fn creation() { .attr_by_kw(&Keyword::try_from("hello/world").unwrap()) .unwrap() .unwrap(); - tx.new_triple(EntityId(1), &attr, &Value::Int(98765)) + tx.new_triple(EntityId(1), &attr, &Value::Int(98765), current_validity) .unwrap(); tx.commit_tx("haah", false).unwrap(); @@ -64,7 +65,7 @@ fn creation() { .unwrap(); tx.commit_tx("oops", false).unwrap(); - let mut tx = session.transact(None).unwrap(); + let mut tx = session.transact().unwrap(); let world_found = tx .attr_by_kw(&Keyword::try_from("hello/world").unwrap()) .unwrap(); @@ -82,7 +83,6 @@ fn creation() { } dbg!(&session); - dbg!(tx.r_tx_id); let mut it = session.total_iter(); while let Some((k, v)) = it.pair().unwrap() { diff --git a/src/transact/attr.rs b/src/transact/attr.rs index 66c262b6..ee20f17c 100644 --- a/src/transact/attr.rs +++ b/src/transact/attr.rs @@ -17,7 +17,7 @@ impl SessionTx { return Ok(res.clone()); } - let anchor = encode_attr_by_id(aid, TxId::MAX_USER); + let anchor = encode_unique_attr_by_id(aid); Ok(match self.tx.get(&anchor, false)? { None => { self.attr_by_id_cache.insert(aid, None);