Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Remove usage of nested lmdb transaction #1084

Merged
merged 1 commit into from
Feb 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions dozer-cache/src/cache/lmdb/indexer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::errors::{CacheError, IndexError};
use dozer_storage::lmdb::{RwTransaction, Transaction};
use dozer_storage::lmdb::RwTransaction;
use dozer_types::{
parking_lot::RwLock,
types::{Field, IndexDefinition, Record, Schema},
Expand All @@ -18,18 +18,14 @@ pub struct Indexer {
impl Indexer {
pub fn build_indexes(
&self,
parent_txn: &mut RwTransaction,
txn: &mut RwTransaction,
record: &Record,
schema: &Schema,
secondary_indexes: &[IndexDefinition],
id: [u8; 8],
) -> Result<(), CacheError> {
let schema_id = schema.identifier.ok_or(CacheError::SchemaHasNoIdentifier)?;

let mut txn = parent_txn
.begin_nested_txn()
.map_err(|e| CacheError::Internal(Box::new(e)))?;

if secondary_indexes.is_empty() {
return Err(CacheError::Index(IndexError::MissingSecondaryIndexes));
}
Expand All @@ -43,19 +39,17 @@ impl Indexer {
match index {
IndexDefinition::SortedInverted(fields) => {
let secondary_key = Self::_build_index_sorted_inverted(fields, &record.values);
db.insert(&mut txn, &secondary_key, id)?;
db.insert(txn, &secondary_key, id)?;
}
IndexDefinition::FullText(field_index) => {
for secondary_key in
Self::_build_indices_full_text(*field_index, &record.values)?
{
db.insert(&mut txn, &secondary_key, id)?;
db.insert(txn, &secondary_key, id)?;
}
}
}
}
txn.commit()
.map_err(|e| CacheError::Internal(Box::new(e)))?;
Ok(())
}

Expand Down