|
@@ -29,15 +29,15 @@ pub struct Cursor<'a> {
|
|
/// Reference to the namespace to use to query the secondary index. If none
|
|
/// Reference to the namespace to use to query the secondary index. If none
|
|
/// is given the secondary_index_iterator must be constructed outside this
|
|
/// is given the secondary_index_iterator must be constructed outside this
|
|
/// wrapper.
|
|
/// wrapper.
|
|
- namespace: Option<Arc<BoundColumnFamily<'a>>>,
|
|
|
|
|
|
+ index: Option<Arc<BoundColumnFamily<'a>>>,
|
|
/// The current secondary index iterator. If none is given the iterator will
|
|
/// The current secondary index iterator. If none is given the iterator will
|
|
/// try to create one using the namespace property and the first prefix from
|
|
/// try to create one using the namespace property and the first prefix from
|
|
/// prefixes (it will also be copied to current_prefix)
|
|
/// prefixes (it will also be copied to current_prefix)
|
|
- secondary_index_iterator: Option<DBIteratorWithThreadMode<'a, DB>>,
|
|
|
|
|
|
+ index_iterator: Option<DBIteratorWithThreadMode<'a, DB>>,
|
|
|
|
+ /// Index key or prefix to iterate over in the index
|
|
|
|
+ index_keys: VecDeque<Vec<u8>>,
|
|
/// The current prefix to load
|
|
/// The current prefix to load
|
|
- current_prefix: Vec<u8>,
|
|
|
|
- /// Prefixes
|
|
|
|
- prefixes: VecDeque<Vec<u8>>,
|
|
|
|
|
|
+ current_index_key: Vec<u8>,
|
|
/// Limit of events to return, None means nothing
|
|
/// Limit of events to return, None means nothing
|
|
limit: Option<usize>,
|
|
limit: Option<usize>,
|
|
/// Amount of events returned
|
|
/// Amount of events returned
|
|
@@ -49,7 +49,7 @@ pub struct Cursor<'a> {
|
|
impl<'a> Cursor<'a> {
|
|
impl<'a> Cursor<'a> {
|
|
pub fn new(
|
|
pub fn new(
|
|
db: &'a RocksDb,
|
|
db: &'a RocksDb,
|
|
- namespace: Option<Arc<BoundColumnFamily<'a>>>,
|
|
|
|
|
|
+ index: Option<Arc<BoundColumnFamily<'a>>>,
|
|
prefixes: Vec<Vec<u8>>,
|
|
prefixes: Vec<Vec<u8>>,
|
|
filter: Option<EventFilter>,
|
|
filter: Option<EventFilter>,
|
|
secondary_index_iterator: Option<DBIteratorWithThreadMode<'a, DB>>,
|
|
secondary_index_iterator: Option<DBIteratorWithThreadMode<'a, DB>>,
|
|
@@ -57,10 +57,10 @@ impl<'a> Cursor<'a> {
|
|
) -> Self {
|
|
) -> Self {
|
|
Self {
|
|
Self {
|
|
db,
|
|
db,
|
|
- namespace,
|
|
|
|
- secondary_index_iterator,
|
|
|
|
- current_prefix: Vec::new(),
|
|
|
|
- prefixes: prefixes.into(),
|
|
|
|
|
|
+ index,
|
|
|
|
+ index_iterator: secondary_index_iterator,
|
|
|
|
+ current_index_key: Vec::new(),
|
|
|
|
+ index_keys: prefixes.into(),
|
|
filter,
|
|
filter,
|
|
limit,
|
|
limit,
|
|
returned: 0,
|
|
returned: 0,
|
|
@@ -71,14 +71,14 @@ impl<'a> Cursor<'a> {
|
|
/// secondary index. If no prefix is available from prefixes the functions
|
|
/// secondary index. If no prefix is available from prefixes the functions
|
|
/// return None, signalling upstream the are no more results
|
|
/// return None, signalling upstream the are no more results
|
|
fn select_next_prefix_using_secondary_index(&mut self) -> Option<()> {
|
|
fn select_next_prefix_using_secondary_index(&mut self) -> Option<()> {
|
|
- self.secondary_index_iterator = None;
|
|
|
|
- let prefix = self.prefixes.pop_front()?;
|
|
|
|
- self.secondary_index_iterator = Some(
|
|
|
|
|
|
+ self.index_iterator = None;
|
|
|
|
+ let prefix = self.index_keys.pop_front()?;
|
|
|
|
+ self.index_iterator = Some(
|
|
self.db
|
|
self.db
|
|
.db
|
|
.db
|
|
- .prefix_iterator_cf(self.namespace.as_ref()?, prefix.clone()),
|
|
|
|
|
|
+ .prefix_iterator_cf(self.index.as_ref()?, prefix.clone()),
|
|
);
|
|
);
|
|
- self.current_prefix = prefix;
|
|
|
|
|
|
+ self.current_index_key = prefix;
|
|
Some(())
|
|
Some(())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -104,15 +104,15 @@ impl<'a> Stream for Cursor<'a> {
|
|
return Poll::Ready(Some(event));
|
|
return Poll::Ready(Some(event));
|
|
}
|
|
}
|
|
FutureValue::Pending => return Poll::Pending,
|
|
FutureValue::Pending => return Poll::Pending,
|
|
- FutureValue::FoundNotMatch | FutureValue::Ended => {}
|
|
|
|
|
|
+ _ => {}
|
|
}
|
|
}
|
|
|
|
|
|
loop {
|
|
loop {
|
|
- let secondary_index = if let Some(iterator) = this.secondary_index_iterator.as_mut() {
|
|
|
|
|
|
+ let secondary_index = if let Some(iterator) = this.index_iterator.as_mut() {
|
|
iterator
|
|
iterator
|
|
- } else if this.namespace.is_some() {
|
|
|
|
|
|
+ } else if this.index.is_some() {
|
|
let _ = this.select_next_prefix_using_secondary_index();
|
|
let _ = this.select_next_prefix_using_secondary_index();
|
|
- if let Some(iterator) = this.secondary_index_iterator.as_mut() {
|
|
|
|
|
|
+ if let Some(iterator) = this.index_iterator.as_mut() {
|
|
iterator
|
|
iterator
|
|
} else {
|
|
} else {
|
|
return Poll::Ready(None);
|
|
return Poll::Ready(None);
|
|
@@ -121,7 +121,7 @@ impl<'a> Stream for Cursor<'a> {
|
|
// No secondary index is used to query, this means the query is
|
|
// No secondary index is used to query, this means the query is
|
|
// using the ID filter, so it is more efficient to use the
|
|
// using the ID filter, so it is more efficient to use the
|
|
// primary index to prefetch events that may satisfy the query
|
|
// primary index to prefetch events that may satisfy the query
|
|
- return if let Some(prefix) = this.prefixes.pop_front() {
|
|
|
|
|
|
+ return if let Some(prefix) = this.index_keys.pop_front() {
|
|
this.future_event = Some(db.get_event(prefix));
|
|
this.future_event = Some(db.get_event(prefix));
|
|
match check_future_call(&mut this.future_event, &this.filter, cx) {
|
|
match check_future_call(&mut this.future_event, &this.filter, cx) {
|
|
FutureValue::Found(event) => {
|
|
FutureValue::Found(event) => {
|
|
@@ -129,7 +129,7 @@ impl<'a> Stream for Cursor<'a> {
|
|
Poll::Ready(Some(event))
|
|
Poll::Ready(Some(event))
|
|
}
|
|
}
|
|
FutureValue::Pending => Poll::Pending,
|
|
FutureValue::Pending => Poll::Pending,
|
|
- FutureValue::FoundNotMatch | FutureValue::Ended => continue,
|
|
|
|
|
|
+ _ => continue,
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
Poll::Ready(None)
|
|
Poll::Ready(None)
|
|
@@ -138,7 +138,7 @@ impl<'a> Stream for Cursor<'a> {
|
|
|
|
|
|
return match secondary_index.next() {
|
|
return match secondary_index.next() {
|
|
Some(Ok((key, value))) => {
|
|
Some(Ok((key, value))) => {
|
|
- if !key.starts_with(&this.current_prefix) {
|
|
|
|
|
|
+ if !key.starts_with(&this.current_index_key) {
|
|
let _ = this.select_next_prefix_using_secondary_index();
|
|
let _ = this.select_next_prefix_using_secondary_index();
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
@@ -150,7 +150,7 @@ impl<'a> Stream for Cursor<'a> {
|
|
Poll::Ready(Some(event))
|
|
Poll::Ready(Some(event))
|
|
}
|
|
}
|
|
FutureValue::Pending => Poll::Pending,
|
|
FutureValue::Pending => Poll::Pending,
|
|
- FutureValue::FoundNotMatch | FutureValue::Ended => continue,
|
|
|
|
|
|
+ _ => continue,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Some(Err(err)) => {
|
|
Some(Err(err)) => {
|