iterators don't go outside bounds

main
Ziyang Hu 2 years ago
parent b4e80ab80d
commit 1113e01387

@ -15,6 +15,9 @@
#include "rocksdb/utilities/transaction.h"
#include "rocksdb/utilities/transaction_db.h"
#include "rocksdb/utilities/optimistic_transaction_db.h"
#include "rocksdb/table.h"
#include "rocksdb/filter_policy.h"
#include "rocksdb/slice_transform.h"
typedef std::shared_mutex Lock;
@ -69,6 +72,13 @@ void set_total_order_seek(ReadOptions &options, const bool v) {
options.total_order_seek = v;
}
void set_prefix_same_as_start(ReadOptions &options, const bool v) {
options.prefix_same_as_start = v;
}
void set_auto_prefix_mode(ReadOptions &options, const bool v) {
options.auto_prefix_mode = v;
}
void set_disable_wal(WriteOptions &options, const bool v) {
options.disableWAL = v;
@ -157,6 +167,23 @@ inline std::unique_ptr<Options> new_options() {
return std::make_unique<Options>();
}
inline void set_bloom_filter(Options &options, const double bits_per_key, const bool whole_key_filtering) {
BlockBasedTableOptions table_options;
table_options.filter_policy.reset(NewBloomFilterPolicy(bits_per_key, false));
table_options.whole_key_filtering = whole_key_filtering;
options.table_factory.reset(
NewBlockBasedTableFactory(
table_options));
}
inline void set_capped_prefix_extractor(Options &options, const size_t cap_len) {
options.prefix_extractor.reset(NewCappedPrefixTransform(cap_len));
}
inline void set_fixed_prefix_extractor(Options &options, const size_t prefix_len) {
options.prefix_extractor.reset(NewFixedPrefixTransform(prefix_len));
}
struct IteratorBridge {
mutable std::unique_ptr<Iterator> inner;

@ -87,11 +87,16 @@ mod ffi {
fn set_create_if_missing(o: Pin<&mut Options>, v: bool);
fn set_comparator(o: Pin<&mut Options>, cmp: &RustComparator);
fn set_paranoid_checks(o: Pin<&mut Options>, v: bool);
fn set_bloom_filter(o: Pin<&mut Options>, bits_per_key: f64, whole_key_filtering: bool);
fn set_capped_prefix_extractor(o: Pin<&mut Options>, cap_len: usize);
fn set_fixed_prefix_extractor(o: Pin<&mut Options>, prefix_len: usize);
type ReadOptions;
fn new_read_options() -> UniquePtr<ReadOptions>;
fn set_verify_checksums(o: Pin<&mut ReadOptions>, v: bool);
fn set_total_order_seek(o: Pin<&mut ReadOptions>, v: bool);
fn set_prefix_same_as_start(o: Pin<&mut ReadOptions>, v: bool);
fn set_auto_prefix_mode(o: Pin<&mut ReadOptions>, v: bool);
type WriteOptions;
fn new_write_options() -> UniquePtr<WriteOptions>;
fn set_disable_wal(o: Pin<&mut WriteOptions>, v: bool);

@ -164,6 +164,21 @@ impl OptionsPtr {
set_paranoid_checks(self.pin_mut(), v);
self
}
#[inline]
pub fn set_bloom_filter(&mut self, bits_per_key: f64, whole_key_filtering: bool) -> &mut Self {
set_bloom_filter(self.pin_mut(), bits_per_key, whole_key_filtering);
self
}
#[inline]
pub fn set_capped_prefix_extractor(&mut self, cap_len: usize) -> &mut Self {
set_capped_prefix_extractor(self.pin_mut(), cap_len);
self
}
#[inline]
pub fn set_fixed_prefix_extractor(&mut self, prefix_len: usize) -> &mut Self {
set_fixed_prefix_extractor(self.pin_mut(), prefix_len);
self
}
}
@ -201,6 +216,16 @@ impl ReadOptionsPtr {
set_total_order_seek(self.pin_mut(), v);
self
}
#[inline]
pub fn set_prefix_same_as_start(&mut self, v: bool) -> &mut Self {
set_prefix_same_as_start(self.pin_mut(), v);
self
}
#[inline]
pub fn set_auto_prefix_mode(&mut self, v: bool) -> &mut Self {
set_auto_prefix_mode(self.pin_mut(), v);
self
}
}
pub struct WriteOptionsPtr(UniquePtr<WriteOptions>);

@ -47,7 +47,9 @@ impl Engine {
.increase_parallelism()
.optimize_level_style_compaction()
.set_create_if_missing(true)
.set_paranoid_checks(false);
.set_paranoid_checks(false)
.set_bloom_filter(10., true)
.set_fixed_prefix_extractor(4);
let mut rng = rand::thread_rng();
let uuid_ctx = Context::new(rng.gen());
@ -126,6 +128,9 @@ pub struct Session<'a> {
impl<'a> Session<'a> {
pub fn start(&mut self) -> Result<()> {
self.start_with_total_seek(false)
}
pub fn start_with_total_seek(&mut self, total_seek: bool) -> Result<()> {
self.perm_cf = self.engine.db.default_cf();
assert!(!self.perm_cf.is_null());
self.temp_cf = self.engine.db.get_cf(&self.handle.read().map_err(|_| Poisoned)?.cf_ident).ok_or(SessionErr)?;
@ -139,9 +144,26 @@ impl<'a> Session<'a> {
}
};
let mut r_opts = ReadOptionsPtr::default();
r_opts.set_total_order_seek(true);
let mut rx_opts = ReadOptionsPtr::default();
rx_opts.set_total_order_seek(true);
if total_seek {
r_opts
.set_total_order_seek(true)
.set_prefix_same_as_start(false)
.set_auto_prefix_mode(true);
rx_opts
.set_total_order_seek(true)
.set_prefix_same_as_start(false)
.set_auto_prefix_mode(true);
} else {
r_opts
.set_total_order_seek(false)
.set_prefix_same_as_start(true)
.set_auto_prefix_mode(false);
rx_opts
.set_total_order_seek(false)
.set_prefix_same_as_start(true)
.set_auto_prefix_mode(false);
}
let w_opts = WriteOptionsPtr::default();
let mut wx_opts = WriteOptionsPtr::default();
wx_opts.set_disable_wal(true);

@ -217,9 +217,9 @@ mod tests {
while it.is_valid() {
if let Some((k, v)) = it.pair() {
let k = Tuple::new(k);
if !k.starts_with(&key_prefix) {
break;
}
// if !k.starts_with(&key_prefix) {
// break;
// }
let v = Tuple::new(v);
let tpair = [(k, v)];
match sess.tuple_eval(&where_vals, &tpair).unwrap() {
@ -228,7 +228,9 @@ mod tests {
println!("{}", extracted);
}
Value::Null |
Value::Bool(_) => {}
Value::Bool(_) => {
println!(" Ignore {:?}", &tpair);
}
_ => panic!("Bad type")
}
it.next();

Loading…
Cancel
Save